]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/dcmemory.cpp
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 /////////////////////////////////////////////////////////////////////////////
29 /////////////////////////////////////////////////////////////////////////////
31 wxMemoryDC::wxMemoryDC(void)
33 CreateCompatible(NULL
);
35 } // end of wxMemoryDC::wxMemoryDC
37 wxMemoryDC::wxMemoryDC(
41 CreateCompatible(pOldDC
);
43 } // end of wxMemoryDC::wxMemoryDC
45 void wxMemoryDC::Init()
49 SetBrush(*wxWHITE_BRUSH
);
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
);
56 memset(&m_vRclPaint
, 0, sizeof(m_vRclPaint
));
57 } // end of wxMemoryDC::Init
59 bool wxMemoryDC::CreateCompatible( wxDC
* WXUNUSED(pDC
) )
63 DEVOPENSTRUC vDOP
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
67 // Create a memory device context
69 hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
72 hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
80 // Set the wxWidgets color table
82 ::GpiCreateLogColorTable( m_hPS
86 ,(LONG
)wxTheColourDatabase
->m_nSize
87 ,(PLONG
)wxTheColourDatabase
->m_palTable
89 ::GpiCreateLogColorTable( m_hPS
114 // As we created the DC, we must delete it in the dtor
119 } // end of wxMemoryDC::CreateCompatible
121 void wxMemoryDC::SelectObject(
122 const wxBitmap
& rBitmap
126 // Select old bitmap out of the device context
130 ::GpiSetBitmap(m_hPS
, NULLHANDLE
);
131 if (m_vSelectedBitmap
.Ok())
133 m_vSelectedBitmap
.SetSelectedInto(NULL
);
134 m_vSelectedBitmap
= wxNullBitmap
;
139 // Check for whether the bitmap is already selected into a device context
141 wxCHECK_RET( !rBitmap
.GetSelectedInto() ||
142 (rBitmap
.GetSelectedInto() == this),
143 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
145 WXHBITMAP hBmp
= rBitmap
.GetHBITMAP();
150 // Bmps drawn to are upside down, so flip it before committing
152 POINTL vPoint
[4] = { {0, m_vSelectedBitmap
.GetHeight()}
153 ,{m_vSelectedBitmap
.GetWidth(), 0}
155 ,{m_vSelectedBitmap
.GetWidth(), m_vSelectedBitmap
.GetHeight()}
166 m_vSelectedBitmap
.SetSelectedInto(NULL
);
168 m_vSelectedBitmap
= rBitmap
;
174 m_hOldBitmap
= (WXHBITMAP
)::GpiSetBitmap(m_hPS
, NULLHANDLE
);
177 m_vSelectedBitmap
.SetSelectedInto(this);
178 m_hOldBitmap
= (WXHBITMAP
)::GpiSetBitmap(m_hPS
, (HBITMAP
)hBmp
);
180 if (m_hOldBitmap
== HBM_ERROR
)
182 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
183 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
185 } // end of wxMemoryDC::SelectObject
187 void wxMemoryDC::DoGetSize(
192 if (!m_vSelectedBitmap
.Ok())
198 *pWidth
= m_vSelectedBitmap
.GetWidth();
199 *pHeight
= m_vSelectedBitmap
.GetHeight();
200 } // end of wxMemoryDC::DoGetSize