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