get rid of wxClientDC::m_oldFont, it wasn't really used (this fixes crash introduced...
[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 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 SetBrush (* wxWHITE_BRUSH);
86 SetPen (* wxBLACK_PEN);
87 };
88
89 wxMemoryDC::~wxMemoryDC(void)
90 {
91 };
92
93 void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
94 {
95 m_bitmap = bitmap;
96
97 if (m_gc)
98 XFreeGC((Display*) m_display, (GC) m_gc);
99 m_gc = (WXGC) NULL;
100
101 if (m_bitmap.Ok() && (bitmap.GetDisplay() == m_display))
102 {
103 m_pixmap = m_bitmap.GetDrawable();
104 Display* display = (Display*) m_display;
105
106 XGCValues gcvalues;
107 gcvalues.foreground = BlackPixel (display, DefaultScreen (display));
108 gcvalues.background = WhitePixel (display, DefaultScreen (display));
109 gcvalues.graphics_exposures = False;
110 gcvalues.subwindow_mode = IncludeInferiors;
111 gcvalues.line_width = 1;
112 m_gc = (WXGC) XCreateGC (display, (Drawable)m_pixmap/* RootWindow (display, DefaultScreen (display)) */,
113 GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode,
114 &gcvalues);
115
116 m_backgroundPixel = (int) gcvalues.background;
117 m_ok = true;
118
119 SetBrush (* wxWHITE_BRUSH);
120 SetPen (* wxBLACK_PEN);
121 }
122 else
123 {
124 m_ok = false;
125 m_pixmap = (WXPixmap) 0;
126 };
127 };
128
129 void wxMemoryDC::DoGetSize( int *width, int *height ) const
130 {
131 if (m_bitmap.Ok())
132 {
133 if (width) (*width) = m_bitmap.GetWidth();
134 if (height) (*height) = m_bitmap.GetHeight();
135 }
136 else
137 {
138 if (width) (*width) = 0;
139 if (height) (*height) = 0;
140 };
141 };
142
143