]> git.saurik.com Git - wxWidgets.git/blob - src/os2/dcmemory.cpp
Fixed Tim's patch so it will compile when using a Python version < 2.0
[wxWidgets.git] / src / os2 / dcmemory.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dcmemory.cpp
3 // Purpose: wxMemoryDC class
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/14/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/utils.h"
17 #endif
18
19 #include "wx/os2/private.h"
20
21 #include "wx/dcmemory.h"
22
23 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC)
24
25 /////////////////////////////////////////////////////////////////////////////
26 // Memory DC
27 /////////////////////////////////////////////////////////////////////////////
28
29 wxMemoryDC::wxMemoryDC(void)
30 {
31 ERRORID vError;
32 wxString sError;
33 HDC hDC;
34 HPS hPS;
35 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
36 SIZEL vSize = {0, 0};
37
38 //
39 // Create a memory device context
40 //
41 hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
42 if (hDC != DEV_ERROR)
43 {
44 hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
45 if (hPS != GPI_ERROR)
46 {
47 m_hPS = hPS;
48 m_hDC = hDC;
49 m_ok = TRUE;
50 m_bOwnsDC = TRUE;
51 SetBrush(*wxWHITE_BRUSH);
52 SetPen(*wxBLACK_PEN);
53 if (!::GpiCreateLogColorTable( m_hPS
54 ,0L
55 ,LCOLF_CONSECRGB
56 ,0L
57 ,(LONG)wxTheColourDatabase->m_nSize
58 ,(PLONG)wxTheColourDatabase->m_palTable
59 ))
60 {
61 vError = ::WinGetLastError(vHabmain);
62 sError = wxPMErrorToStr(vError);
63 wxLogError("Unable to set current color table. Error: %s\n", sError);
64 }
65 //
66 // Set the color table to RGB mode
67 //
68 if (!::GpiCreateLogColorTable( m_hPS
69 ,0L
70 ,LCOLF_RGB
71 ,0L
72 ,0L
73 ,NULL
74 ))
75 {
76 vError = ::WinGetLastError(vHabmain);
77 sError = wxPMErrorToStr(vError);
78 wxLogError("Unable to set current color table. Error: %s\n", sError);
79 }
80 }
81 else
82 {
83 m_hPS = NULLHANDLE;
84 m_hDC = NULLHANDLE;
85 m_ok = FALSE;
86 m_bOwnsDC = FALSE;
87 }
88 }
89 else
90 {
91 m_hPS = NULLHANDLE;
92 m_hDC = NULLHANDLE;
93 m_ok = FALSE;
94 m_bOwnsDC = FALSE;
95 }
96 } // end of wxMemoryDC::wxMemoryDC
97
98 wxMemoryDC::wxMemoryDC(
99 wxDC* pOldDC
100 )
101 {
102 HDC hDC;
103 HPS hPS;
104 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
105 SIZEL vSize = {0, 0};
106
107 pOldDC->BeginDrawing();
108
109 //
110 // Create a memory device context
111 //
112 hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, GetHdcOf(*pOldDC));
113 if (hDC != DEV_ERROR)
114 {
115 hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
116 if (hPS != GPI_ERROR)
117 {
118 m_hPS = hPS;
119 m_hDC = hDC;
120 m_ok = TRUE;
121 m_bOwnsDC = TRUE;
122 pOldDC->EndDrawing();
123 SetBrush(*wxWHITE_BRUSH);
124 SetPen(*wxBLACK_PEN);
125 }
126 else
127 {
128 pOldDC->EndDrawing();
129 m_hPS = NULLHANDLE;
130 m_hDC = NULLHANDLE;
131 m_ok = FALSE;
132 m_bOwnsDC = FALSE;
133 }
134 }
135 else
136 {
137 pOldDC->EndDrawing();
138 m_hPS = NULLHANDLE;
139 m_hDC = NULLHANDLE;
140 m_ok = FALSE;
141 m_bOwnsDC = FALSE;
142 }
143 } // end of wxMemoryDC::wxMemoryDC
144
145 wxMemoryDC::~wxMemoryDC()
146 {
147 m_vSelectedBitmap.SetSelectedInto(NULL);
148 if (m_hPS != NULLHANDLE)
149 ::GpiDestroyPS(m_hPS);
150 if (m_hDC != NULLHANDLE)
151 ::DevCloseDC(m_hDC);
152 } // end of wxMemoryDC::~wxMemoryDC
153
154 void wxMemoryDC::SelectObject(
155 const wxBitmap& rBitmap
156 )
157 {
158 //
159 // Select old bitmap out of the device context
160 //
161 if (m_hOldBitmap)
162 {
163 ::GpiSetBitmap(m_hPS, NULLHANDLE);
164 if (m_vSelectedBitmap.Ok())
165 {
166 m_vSelectedBitmap.SetSelectedInto(NULL);
167 m_vSelectedBitmap = wxNullBitmap;
168 }
169 }
170
171 //
172 // Check for whether the bitmap is already selected into a device context
173 //
174 wxCHECK_RET( !rBitmap.GetSelectedInto() ||
175 (rBitmap.GetSelectedInto() == this),
176 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
177
178 m_vSelectedBitmap = rBitmap;
179
180 WXHBITMAP hBmp = m_vSelectedBitmap.GetHBITMAP();
181
182 if (!hBmp)
183 return;
184
185 m_vSelectedBitmap.SetSelectedInto(this);
186 hBmp = (WXHBITMAP)::GpiSetBitmap(m_hPS, (HBITMAP)hBmp);
187
188 if (hBmp == HBM_ERROR)
189 {
190 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
191 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
192 }
193 else if (!m_hOldBitmap)
194 {
195 m_hOldBitmap = hBmp;
196 }
197 } // end of wxMemoryDC::SelectObject
198
199 void wxMemoryDC::DoGetSize(
200 int* pWidth
201 , int* pHeight
202 ) const
203 {
204 if (!m_vSelectedBitmap.Ok())
205 {
206 *pWidth = 0;
207 *pHeight = 0;
208 return;
209 }
210 *pWidth = m_vSelectedBitmap.GetWidth();
211 *pHeight = m_vSelectedBitmap.GetHeight();
212 } // end of wxMemoryDC::DoGetSize
213
214