]> git.saurik.com Git - wxWidgets.git/blob - src/motif/dcmemory.cpp
include/wx/choice.hpragma warning is only for VC++
[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 #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 #include <Xm/Xm.h>
21
22 #include "wx/motif/private.h"
23
24 //-----------------------------------------------------------------------------
25 // wxMemoryDC
26 //-----------------------------------------------------------------------------
27
28 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxWindowDC)
29
30 wxMemoryDC::wxMemoryDC(void)
31 {
32 m_ok = TRUE;
33 m_display = wxGetDisplay();
34
35 Display* display = (Display*) m_display;
36
37 XGCValues gcvalues;
38 gcvalues.foreground = BlackPixel (display, DefaultScreen (display));
39 gcvalues.background = WhitePixel (display, DefaultScreen (display));
40 gcvalues.graphics_exposures = False;
41 gcvalues.line_width = 1;
42 m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)),
43 GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth,
44 &gcvalues);
45
46 m_backgroundPixel = (int) gcvalues.background;
47
48 // Get the current Font so we can set it back later
49 XGCValues valReturn;
50 XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn);
51 m_oldFont = (WXFont) valReturn.font;
52 SetBrush (* wxWHITE_BRUSH);
53 SetPen (* wxBLACK_PEN);
54 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
55 };
56
57 wxMemoryDC::wxMemoryDC( wxDC* dc )
58 {
59 m_ok = TRUE;
60 if (dc && dc->IsKindOf(CLASSINFO(wxWindowDC)))
61 m_display = ((wxWindowDC*)dc)->GetDisplay();
62 else
63 m_display = wxGetDisplay();
64
65 Display* display = (Display*) m_display;
66
67 XGCValues gcvalues;
68 gcvalues.foreground = BlackPixel (display, DefaultScreen (display));
69 gcvalues.background = WhitePixel (display, DefaultScreen (display));
70 gcvalues.graphics_exposures = False;
71 gcvalues.line_width = 1;
72 m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)),
73 GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth,
74 &gcvalues);
75
76 m_backgroundPixel = (int) gcvalues.background;
77
78 // Get the current Font so we can set it back later
79 XGCValues valReturn;
80 XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn);
81 m_oldFont = (WXFont) valReturn.font;
82 SetBrush (* wxWHITE_BRUSH);
83 SetPen (* wxBLACK_PEN);
84 };
85
86 wxMemoryDC::~wxMemoryDC(void)
87 {
88 };
89
90 void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
91 {
92 m_bitmap = bitmap;
93
94 if (m_gc)
95 XFreeGC((Display*) m_display, (GC) m_gc);
96 m_gc = (WXGC) NULL;
97
98 if (m_bitmap.Ok() && (bitmap.GetDisplay() == m_display))
99 {
100 m_pixmap = m_bitmap.GetPixmap();
101 Display* display = (Display*) m_display;
102
103 XGCValues gcvalues;
104 gcvalues.foreground = BlackPixel (display, DefaultScreen (display));
105 gcvalues.background = WhitePixel (display, DefaultScreen (display));
106 gcvalues.graphics_exposures = False;
107 gcvalues.line_width = 1;
108 m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)),
109 GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth,
110 &gcvalues);
111
112 m_backgroundPixel = (int) gcvalues.background;
113
114 // Get the current Font so we can set it back later
115 XGCValues valReturn;
116 XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn);
117 m_oldFont = (WXFont) valReturn.font;
118
119 bool oldOpt = GetOptimization();
120 SetOptimization(FALSE);
121
122 SetBrush (* wxWHITE_BRUSH);
123 SetPen (* wxBLACK_PEN);
124
125 SetOptimization(oldOpt);
126
127 m_ok = TRUE;
128 }
129 else
130 {
131 m_ok = FALSE;
132 m_pixmap = (WXPixmap) 0;
133 };
134 };
135
136 void wxMemoryDC::DoGetSize( int *width, int *height ) const
137 {
138 if (m_bitmap.Ok())
139 {
140 if (width) (*width) = m_bitmap.GetWidth();
141 if (height) (*height) = m_bitmap.GetHeight();
142 }
143 else
144 {
145 if (width) (*width) = 0;
146 if (height) (*height) = 0;
147 };
148 };
149
150