DC updates and an associated .Def file update
[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 CreateCompatible(NULL);
32 Init();
33 } // end of wxMemoryDC::wxMemoryDC
34
35 wxMemoryDC::wxMemoryDC(
36 wxDC* pOldDC
37 )
38 {
39 pOldDC->BeginDrawing();
40 CreateCompatible(pOldDC);
41 pOldDC->EndDrawing();
42 Init();
43 } // end of wxMemoryDC::wxMemoryDC
44
45 void wxMemoryDC::Init()
46 {
47 if (m_ok)
48 {
49 SetBrush(*wxWHITE_BRUSH);
50 SetPen(*wxBLACK_PEN);
51
52 // the background mode is only used for text background and is set in
53 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
54 ::GpiSetBackMix( GetHPS(), BM_LEAVEALONE );
55 }
56 } // end of wxMemoryDC::Init
57
58 bool wxMemoryDC::CreateCompatible(
59 wxDC* pDC
60 )
61 {
62 HDC hDC;
63 HPS hPS;
64 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
65 SIZEL vSize = {0, 0};
66
67 //
68 // Create a memory device context
69 //
70 hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
71 if (hDC != DEV_ERROR)
72 {
73 hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
74 if (hPS != GPI_ERROR)
75 {
76 m_hPS = hPS;
77 m_hDC = hDC;
78 m_ok = TRUE;
79 m_bOwnsDC = TRUE;
80 //
81 // Set the wxWindows color table
82 //
83 ::GpiCreateLogColorTable( m_hPS
84 ,0L
85 ,LCOLF_CONSECRGB
86 ,0L
87 ,(LONG)wxTheColourDatabase->m_nSize
88 ,(PLONG)wxTheColourDatabase->m_palTable
89 );
90 ::GpiCreateLogColorTable( m_hPS
91 ,0L
92 ,LCOLF_RGB
93 ,0L
94 ,0L
95 ,NULL
96 );
97 }
98 else
99 {
100 m_hPS = NULLHANDLE;
101 m_hDC = NULLHANDLE;
102 m_ok = FALSE;
103 m_bOwnsDC = FALSE;
104 }
105 }
106 else
107 {
108 m_hPS = NULLHANDLE;
109 m_hDC = NULLHANDLE;
110 m_ok = FALSE;
111 m_bOwnsDC = FALSE;
112 }
113
114 //
115 // As we created the DC, we must delete it in the dtor
116 //
117 m_bOwnsDC = TRUE;
118 m_ok = m_hDC != 0;
119 return m_ok;
120 } // end of wxMemoryDC::CreateCompatible
121
122 void wxMemoryDC::SelectObject(
123 const wxBitmap& rBitmap
124 )
125 {
126 //
127 // Select old bitmap out of the device context
128 //
129 if (m_hOldBitmap)
130 {
131 ::GpiSetBitmap(m_hPS, NULLHANDLE);
132 if (m_vSelectedBitmap.Ok())
133 {
134 m_vSelectedBitmap.SetSelectedInto(NULL);
135 m_vSelectedBitmap = wxNullBitmap;
136 }
137 }
138
139 //
140 // Check for whether the bitmap is already selected into a device context
141 //
142 wxCHECK_RET( !rBitmap.GetSelectedInto() ||
143 (rBitmap.GetSelectedInto() == this),
144 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
145
146 m_vSelectedBitmap = rBitmap;
147
148 WXHBITMAP hBmp = m_vSelectedBitmap.GetHBITMAP();
149
150 if (!hBmp)
151 return;
152
153 m_vSelectedBitmap.SetSelectedInto(this);
154 hBmp = (WXHBITMAP)::GpiSetBitmap(m_hPS, (HBITMAP)hBmp);
155
156 if (hBmp == HBM_ERROR)
157 {
158 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
159 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
160 }
161 else if (!m_hOldBitmap)
162 {
163 m_hOldBitmap = hBmp;
164 }
165 } // end of wxMemoryDC::SelectObject
166
167 void wxMemoryDC::DoGetSize(
168 int* pWidth
169 , int* pHeight
170 ) const
171 {
172 if (!m_vSelectedBitmap.Ok())
173 {
174 *pWidth = 0;
175 *pHeight = 0;
176 return;
177 }
178 *pWidth = m_vSelectedBitmap.GetWidth();
179 *pHeight = m_vSelectedBitmap.GetHeight();
180 } // end of wxMemoryDC::DoGetSize
181
182 void wxMemoryDC::DoDrawRectangle(
183 wxCoord vX
184 , wxCoord vY
185 , wxCoord vWidth
186 , wxCoord vHeight
187 )
188 {
189 wxDC::DoDrawRectangle(vX, vY, vWidth, vHeight);
190 } // end of wxMemoryDC::DoDrawRectangle