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