]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/dcmemory.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/dcmemory.cpp
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"
15 #include "wx/dcmemory.h"
23 #include "wx/os2/private.h"
25 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC
, wxDC
)
27 /////////////////////////////////////////////////////////////////////////////
29 /////////////////////////////////////////////////////////////////////////////
31 wxMemoryDC::wxMemoryDC( const wxBitmap
& bitmap
)
33 CreateCompatible(NULL
);
38 } // end of wxMemoryDC::wxMemoryDC
40 wxMemoryDC::wxMemoryDC(
44 CreateCompatible(pOldDC
);
46 } // end of wxMemoryDC::wxMemoryDC
48 void wxMemoryDC::Init()
52 SetBrush(*wxWHITE_BRUSH
);
55 // the background mode is only used for text background and is set in
56 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
57 ::GpiSetBackMix( GetHPS(), BM_LEAVEALONE
);
59 memset(&m_vRclPaint
, 0, sizeof(m_vRclPaint
));
60 } // end of wxMemoryDC::Init
62 bool wxMemoryDC::CreateCompatible( wxDC
* WXUNUSED(pDC
) )
66 DEVOPENSTRUC vDOP
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
70 // Create a memory device context
72 hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
75 hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
83 // Set the wxWidgets color table
85 ::GpiCreateLogColorTable( m_hPS
89 ,(LONG
)wxTheColourDatabase
->m_nSize
90 ,(PLONG
)wxTheColourDatabase
->m_palTable
92 ::GpiCreateLogColorTable( m_hPS
117 // As we created the DC, we must delete it in the dtor
122 } // end of wxMemoryDC::CreateCompatible
124 void wxMemoryDC::SelectObject(
125 const wxBitmap
& rBitmap
129 // Select old bitmap out of the device context
133 ::GpiSetBitmap(m_hPS
, NULLHANDLE
);
134 if (m_vSelectedBitmap
.Ok())
136 m_vSelectedBitmap
.SetSelectedInto(NULL
);
137 m_vSelectedBitmap
= wxNullBitmap
;
142 // Check for whether the bitmap is already selected into a device context
144 wxCHECK_RET( !rBitmap
.GetSelectedInto() ||
145 (rBitmap
.GetSelectedInto() == this),
146 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
148 WXHBITMAP hBmp
= rBitmap
.GetHBITMAP();
153 // Bmps drawn to are upside down, so flip it before committing
155 POINTL vPoint
[4] = { {0, m_vSelectedBitmap
.GetHeight()}
156 ,{m_vSelectedBitmap
.GetWidth(), 0}
158 ,{m_vSelectedBitmap
.GetWidth(), m_vSelectedBitmap
.GetHeight()}
169 m_vSelectedBitmap
.SetSelectedInto(NULL
);
171 m_vSelectedBitmap
= rBitmap
;
177 m_hOldBitmap
= (WXHBITMAP
)::GpiSetBitmap(m_hPS
, NULLHANDLE
);
180 m_vSelectedBitmap
.SetSelectedInto(this);
181 m_hOldBitmap
= (WXHBITMAP
)::GpiSetBitmap(m_hPS
, (HBITMAP
)hBmp
);
183 if (m_hOldBitmap
== HBM_ERROR
)
185 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
186 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
188 } // end of wxMemoryDC::SelectObject
190 void wxMemoryDC::DoGetSize(
195 if (!m_vSelectedBitmap
.Ok())
201 *pWidth
= m_vSelectedBitmap
.GetWidth();
202 *pHeight
= m_vSelectedBitmap
.GetHeight();
203 } // end of wxMemoryDC::DoGetSize