]>
Commit | Line | Data |
---|---|---|
83df96d6 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dcmemory.cpp | |
3 | // Purpose: wxMemoryDC class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "dcmemory.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/dcmemory.h" | |
17 | #include "wx/settings.h" | |
18 | #include "wx/utils.h" | |
19 | ||
20 | #ifdef __VMS__ | |
21 | #pragma message disable nosimpint | |
22 | #endif | |
83df96d6 JS |
23 | #ifdef __VMS__ |
24 | #pragma message enable nosimpint | |
25 | #endif | |
26 | ||
7266b672 | 27 | #include "wx/x11/private.h" |
83df96d6 JS |
28 | |
29 | //----------------------------------------------------------------------------- | |
30 | // wxMemoryDC | |
31 | //----------------------------------------------------------------------------- | |
32 | ||
33 | IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxWindowDC) | |
34 | ||
35 | wxMemoryDC::wxMemoryDC(void) | |
36 | { | |
37 | m_ok = TRUE; | |
38 | m_display = wxGetDisplay(); | |
39 | ||
40 | Display* display = (Display*) m_display; | |
41 | ||
42 | XGCValues gcvalues; | |
43 | gcvalues.foreground = BlackPixel (display, DefaultScreen (display)); | |
44 | gcvalues.background = WhitePixel (display, DefaultScreen (display)); | |
45 | gcvalues.graphics_exposures = False; | |
46 | gcvalues.subwindow_mode = IncludeInferiors; | |
47 | gcvalues.line_width = 1; | |
48 | m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)), | |
49 | GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode, | |
50 | &gcvalues); | |
51 | ||
52 | m_backgroundPixel = (int) gcvalues.background; | |
53 | ||
54 | // Get the current Font so we can set it back later | |
55 | XGCValues valReturn; | |
56 | XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn); | |
57 | m_oldFont = (WXFont) valReturn.font; | |
58 | SetBrush (* wxWHITE_BRUSH); | |
59 | SetPen (* wxBLACK_PEN); | |
60 | SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
61 | }; | |
62 | ||
63 | wxMemoryDC::wxMemoryDC( wxDC* dc ) | |
64 | { | |
65 | m_ok = TRUE; | |
66 | if (dc && dc->IsKindOf(CLASSINFO(wxWindowDC))) | |
67 | m_display = ((wxWindowDC*)dc)->GetDisplay(); | |
68 | else | |
69 | m_display = wxGetDisplay(); | |
70 | ||
71 | Display* display = (Display*) m_display; | |
72 | ||
73 | XGCValues gcvalues; | |
74 | gcvalues.foreground = BlackPixel (display, DefaultScreen (display)); | |
75 | gcvalues.background = WhitePixel (display, DefaultScreen (display)); | |
76 | gcvalues.graphics_exposures = False; | |
77 | gcvalues.subwindow_mode = IncludeInferiors; | |
78 | gcvalues.line_width = 1; | |
79 | m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)), | |
80 | GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode, | |
81 | &gcvalues); | |
82 | ||
83 | m_backgroundPixel = (int) gcvalues.background; | |
84 | ||
85 | // Get the current Font so we can set it back later | |
86 | XGCValues valReturn; | |
87 | XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn); | |
88 | m_oldFont = (WXFont) valReturn.font; | |
89 | SetBrush (* wxWHITE_BRUSH); | |
90 | SetPen (* wxBLACK_PEN); | |
91 | }; | |
92 | ||
93 | wxMemoryDC::~wxMemoryDC(void) | |
94 | { | |
95 | }; | |
96 | ||
97 | void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) | |
98 | { | |
99 | m_bitmap = bitmap; | |
100 | ||
101 | if (m_gc) | |
102 | XFreeGC((Display*) m_display, (GC) m_gc); | |
103 | m_gc = (WXGC) NULL; | |
104 | ||
105 | if (m_bitmap.Ok() && (bitmap.GetDisplay() == m_display)) | |
106 | { | |
107 | m_pixmap = m_bitmap.GetPixmap(); | |
108 | Display* display = (Display*) m_display; | |
109 | ||
110 | XGCValues gcvalues; | |
111 | gcvalues.foreground = BlackPixel (display, DefaultScreen (display)); | |
112 | gcvalues.background = WhitePixel (display, DefaultScreen (display)); | |
113 | gcvalues.graphics_exposures = False; | |
114 | gcvalues.subwindow_mode = IncludeInferiors; | |
115 | gcvalues.line_width = 1; | |
116 | m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)), | |
117 | GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode, | |
118 | &gcvalues); | |
119 | ||
120 | m_backgroundPixel = (int) gcvalues.background; | |
121 | ||
122 | // Get the current Font so we can set it back later | |
123 | XGCValues valReturn; | |
124 | XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn); | |
125 | m_oldFont = (WXFont) valReturn.font; | |
126 | ||
127 | bool oldOpt = GetOptimization(); | |
128 | SetOptimization(FALSE); | |
129 | ||
130 | SetBrush (* wxWHITE_BRUSH); | |
131 | SetPen (* wxBLACK_PEN); | |
132 | ||
133 | SetOptimization(oldOpt); | |
134 | ||
135 | m_ok = TRUE; | |
136 | } | |
137 | else | |
138 | { | |
139 | m_ok = FALSE; | |
140 | m_pixmap = (WXPixmap) 0; | |
141 | }; | |
142 | }; | |
143 | ||
144 | void wxMemoryDC::DoGetSize( int *width, int *height ) const | |
145 | { | |
146 | if (m_bitmap.Ok()) | |
147 | { | |
148 | if (width) (*width) = m_bitmap.GetWidth(); | |
149 | if (height) (*height) = m_bitmap.GetHeight(); | |
150 | } | |
151 | else | |
152 | { | |
153 | if (width) (*width) = 0; | |
154 | if (height) (*height) = 0; | |
155 | }; | |
156 | }; | |
157 | ||
158 |