]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/dcmemory.cpp
a0aeef01b21046e3015c569ef676819576212b51
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"
19 #include "wx/os2/private.h"
21 #include "wx/dcmemory.h"
23 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC
, wxDC
)
25 /////////////////////////////////////////////////////////////////////////////
27 /////////////////////////////////////////////////////////////////////////////
29 wxMemoryDC::wxMemoryDC(void)
35 DEVOPENSTRUC vDOP
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
39 // Create a memory device context
41 hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
);
44 hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
51 SetBrush(*wxWHITE_BRUSH
);
53 if (!::GpiCreateLogColorTable( m_hPS
57 ,(LONG
)wxTheColourDatabase
->m_nSize
58 ,(PLONG
)wxTheColourDatabase
->m_palTable
61 vError
= ::WinGetLastError(vHabmain
);
62 sError
= wxPMErrorToStr(vError
);
63 wxLogError("Unable to set current color table. Error: %s\n", sError
);
66 // Set the color table to RGB mode
68 if (!::GpiCreateLogColorTable( m_hPS
76 vError
= ::WinGetLastError(vHabmain
);
77 sError
= wxPMErrorToStr(vError
);
78 wxLogError("Unable to set current color table. Error: %s\n", sError
);
96 } // end of wxMemoryDC::wxMemoryDC
98 wxMemoryDC::wxMemoryDC(
104 DEVOPENSTRUC vDOP
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
105 SIZEL vSize
= {0, 0};
107 pOldDC
->BeginDrawing();
110 // Create a memory device context
112 hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, GetHdcOf(*pOldDC
));
113 if (hDC
!= DEV_ERROR
)
115 hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
116 if (hPS
!= GPI_ERROR
)
122 pOldDC
->EndDrawing();
123 SetBrush(*wxWHITE_BRUSH
);
124 SetPen(*wxBLACK_PEN
);
128 pOldDC
->EndDrawing();
137 pOldDC
->EndDrawing();
143 } // end of wxMemoryDC::wxMemoryDC
145 wxMemoryDC::~wxMemoryDC()
147 if (m_hPS
!= NULLHANDLE
)
148 ::GpiDestroyPS(m_hPS
);
149 if (m_hDC
!= NULLHANDLE
)
151 } // end of wxMemoryDC::~wxMemoryDC
153 void wxMemoryDC::SelectObject(
154 const wxBitmap
& rBitmap
158 // Select old bitmap out of the device context
162 ::GpiSetBitmap(m_hPS
, NULLHANDLE
);
163 if (m_vSelectedBitmap
.Ok())
165 m_vSelectedBitmap
.SetSelectedInto(NULL
);
166 m_vSelectedBitmap
= wxNullBitmap
;
171 // Check for whether the bitmap is already selected into a device context
173 wxCHECK_RET( !rBitmap
.GetSelectedInto() ||
174 (rBitmap
.GetSelectedInto() == this),
175 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
177 m_vSelectedBitmap
= rBitmap
;
179 WXHBITMAP hBmp
= m_vSelectedBitmap
.GetHBITMAP();
184 m_vSelectedBitmap
.SetSelectedInto(this);
185 hBmp
= (WXHBITMAP
)::GpiSetBitmap(m_hPS
, (HBITMAP
)hBmp
);
187 if (hBmp
== HBM_ERROR
)
189 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
190 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
192 else if (!m_hOldBitmap
)
196 } // end of wxMemoryDC::SelectObject
198 void wxMemoryDC::DoGetSize(
203 if (!m_vSelectedBitmap
.Ok())
209 *pWidth
= m_vSelectedBitmap
.GetWidth();
210 *pHeight
= m_vSelectedBitmap
.GetHeight();
211 } // end of wxMemoryDC::DoGetSize