]> git.saurik.com Git - wxWidgets.git/blob - src/motif/dcmemory.cpp
Fix recreating of wxBitmapComboBox using untyped client data.
[wxWidgets.git] / src / motif / dcmemory.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/dcmemory.cpp
3 // Purpose: wxMemoryDCImpl class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifndef WX_PRECOMP
15 #include "wx/utils.h"
16 #include "wx/settings.h"
17 #include "wx/dcmemory.h"
18 #include "wx/dcclient.h"
19 #endif
20
21 #ifdef __VMS__
22 #pragma message disable nosimpint
23 #endif
24 #include <Xm/Xm.h>
25 #ifdef __VMS__
26 #pragma message enable nosimpint
27 #endif
28
29 #include "wx/motif/private.h"
30 #include "wx/motif/dcmemory.h"
31
32 //-----------------------------------------------------------------------------
33 // wxMemoryDCImpl
34 //-----------------------------------------------------------------------------
35
36 IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl, wxWindowDCImpl)
37
38 void wxMemoryDCImpl::Init()
39 {
40 m_ok = true;
41 m_display = wxGetDisplay();
42
43 Display* display = (Display*) m_display;
44
45 XGCValues gcvalues;
46 gcvalues.foreground = BlackPixel (display, DefaultScreen (display));
47 gcvalues.background = WhitePixel (display, DefaultScreen (display));
48 gcvalues.graphics_exposures = False;
49 gcvalues.subwindow_mode = IncludeInferiors;
50 gcvalues.line_width = 1;
51 m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)),
52 GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode,
53 &gcvalues);
54
55 m_backgroundPixel = gcvalues.background;
56
57 SetBrush (* wxWHITE_BRUSH);
58 SetPen (* wxBLACK_PEN);
59 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
60 }
61
62 wxMemoryDCImpl::wxMemoryDCImpl(wxMemoryDC *owner, wxDC* dc)
63 : wxWindowDCImpl(owner)
64 {
65 m_ok = true;
66 if (dc && dc->IsKindOf(CLASSINFO(wxWindowDC)))
67 m_display = ((wxWindowDCImpl *)dc->GetImpl())->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 = gcvalues.background;
84
85 SetBrush (* wxWHITE_BRUSH);
86 SetPen (* wxBLACK_PEN);
87 }
88
89 wxMemoryDCImpl::~wxMemoryDCImpl(void)
90 {
91 }
92
93 void wxMemoryDCImpl::DoSelect( 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.IsOk() && (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 = 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 wxMemoryDCImpl::DoGetSize( int *width, int *height ) const
130 {
131 if (m_bitmap.IsOk())
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 }