1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMemoryDC class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/os2/private.h"
23 #include "wx/dcmemory.h"
25 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC
, wxDC
)
27 extern void wxLoadBitmapWithData( HPS hPS
33 /////////////////////////////////////////////////////////////////////////////
35 /////////////////////////////////////////////////////////////////////////////
37 wxMemoryDC::wxMemoryDC(void)
39 CreateCompatible(NULL
);
41 } // end of wxMemoryDC::wxMemoryDC
43 wxMemoryDC::wxMemoryDC(
47 pOldDC
->BeginDrawing();
48 CreateCompatible(pOldDC
);
51 } // end of wxMemoryDC::wxMemoryDC
53 void wxMemoryDC::Init()
57 SetBrush(*wxWHITE_BRUSH
);
60 // the background mode is only used for text background and is set in
61 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
62 ::GpiSetBackMix( GetHPS(), BM_LEAVEALONE
);
64 memset(&m_vRclPaint
, 0, sizeof(m_vRclPaint
));
65 } // end of wxMemoryDC::Init
67 bool wxMemoryDC::CreateCompatible(
73 DEVOPENSTRUC vDOP
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
77 // Create a memory device context
79 hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
82 hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
90 // Set the wxWindows color table
92 ::GpiCreateLogColorTable( m_hPS
96 ,(LONG
)wxTheColourDatabase
->m_nSize
97 ,(PLONG
)wxTheColourDatabase
->m_palTable
99 ::GpiCreateLogColorTable( m_hPS
124 // As we created the DC, we must delete it in the dtor
129 } // end of wxMemoryDC::CreateCompatible
131 void wxMemoryDC::SelectObject(
132 const wxBitmap
& rBitmap
136 // Select old bitmap out of the device context
140 ::GpiSetBitmap(m_hPS
, NULLHANDLE
);
141 if (m_vSelectedBitmap
.Ok())
143 m_vSelectedBitmap
.SetSelectedInto(NULL
);
144 m_vSelectedBitmap
= wxNullBitmap
;
149 // Check for whether the bitmap is already selected into a device context
151 wxCHECK_RET( !rBitmap
.GetSelectedInto() ||
152 (rBitmap
.GetSelectedInto() == this),
153 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
155 m_vSelectedBitmap
= rBitmap
;
157 WXHBITMAP hBmp
= rBitmap
.GetHBITMAP();
162 m_vSelectedBitmap
.SetSelectedInto(this);
163 hBmp
= (WXHBITMAP
)::GpiSetBitmap(m_hPS
, (HBITMAP
)hBmp
);
165 if (hBmp
== HBM_ERROR
)
167 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
168 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
170 else if (!m_hOldBitmap
)
174 } // end of wxMemoryDC::SelectObject
176 void wxMemoryDC::DoGetSize(
181 if (!m_vSelectedBitmap
.Ok())
187 *pWidth
= m_vSelectedBitmap
.GetWidth();
188 *pHeight
= m_vSelectedBitmap
.GetHeight();
189 } // end of wxMemoryDC::DoGetSize
191 void wxMemoryDC::DoDrawRectangle(
198 wxDC::DoDrawRectangle(vX
, vY
, vWidth
, vHeight
);
200 wxLoadBitmapWithData( m_hPS
201 ,(HBITMAP
)m_vSelectedBitmap
.GetHBITMAP()
202 ,m_vSelectedBitmap
.GetWidth()
203 ,m_vSelectedBitmap
.GetHeight()
205 } // end of wxMemoryDC::DoDrawRectangle
207 void wxMemoryDC::DoDrawRoundedRectangle(
215 wxDC::DoDrawRoundedRectangle(vX
, vY
, vWidth
, vHeight
, dRadius
);
217 wxLoadBitmapWithData( m_hPS
218 ,(HBITMAP
)m_vSelectedBitmap
.GetHBITMAP()
219 ,m_vSelectedBitmap
.GetWidth()
220 ,m_vSelectedBitmap
.GetHeight()
222 } // end of wxMemoryDC::DoDrawRoundedRectangle
224 void wxMemoryDC::DoDrawText(
225 const wxString
& rsText
230 wxDC::DoDrawText(rsText
, vX
, vY
);
232 wxLoadBitmapWithData( m_hPS
233 ,(HBITMAP
)m_vSelectedBitmap
.GetHBITMAP()
234 ,m_vSelectedBitmap
.GetWidth()
235 ,m_vSelectedBitmap
.GetHeight()
237 } // end of wxMemoryDC::DoDrawRectangle
239 void wxMemoryDC::DoDrawLine(
246 wxDC::DoDrawLine(vX1
, vY1
, vX2
, vY2
);
248 wxLoadBitmapWithData( m_hPS
249 ,(HBITMAP
)m_vSelectedBitmap
.GetHBITMAP()
250 ,m_vSelectedBitmap
.GetWidth()
251 ,m_vSelectedBitmap
.GetHeight()
253 } // end of wxMemoryDC::DoDrawRoundedRectangle
255 void wxLoadBitmapWithData(
262 BITMAPINFOHEADER2 vHeader
;
266 if (::GpiQueryBitmapInfoHeader(hBitmap
, &vHeader
))
268 unsigned char* pucData
= NULL
;
269 unsigned char* pucBits
;
270 int nBytesPerLine
= nWidth
* 3;
276 vInfo
.cx
= vHeader
.cx
;
277 vInfo
.cy
= vHeader
.cy
;
278 vInfo
.cPlanes
= vHeader
.cPlanes
;
279 vInfo
.cBitCount
= 24;
280 pucData
= (unsigned char*)malloc(nBytesPerLine
* nHeight
);
282 for (int i
= 0; i
< nHeight
; i
++)
284 for (int j
= 0; j
< nWidth
; j
++)
286 vPoint
.x
= j
; vPoint
.y
= i
;
287 lColor
= ::GpiQueryPel(hPS
, &vPoint
);
288 *(pucBits
++) = (unsigned char)lColor
;
289 *(pucBits
++) = (unsigned char)(lColor
>> 8);
290 *(pucBits
++) = (unsigned char)(lColor
>> 16);
293 if ((lScans
= ::GpiSetBitmapBits( hPS
303 vError
= ::WinGetLastError(vHabmain
);
304 sError
= wxPMErrorToStr(vError
);