]>
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"
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 m_vSelectedBitmap
.SetSelectedInto(NULL
);
148 if (m_hPS
!= NULLHANDLE
)
149 ::GpiDestroyPS(m_hPS
);
150 if (m_hDC
!= NULLHANDLE
)
152 } // end of wxMemoryDC::~wxMemoryDC
154 void wxMemoryDC::SelectObject(
155 const wxBitmap
& rBitmap
159 // Select old bitmap out of the device context
163 ::GpiSetBitmap(m_hPS
, NULLHANDLE
);
164 if (m_vSelectedBitmap
.Ok())
166 m_vSelectedBitmap
.SetSelectedInto(NULL
);
167 m_vSelectedBitmap
= wxNullBitmap
;
172 // Check for whether the bitmap is already selected into a device context
174 wxCHECK_RET( !rBitmap
.GetSelectedInto() ||
175 (rBitmap
.GetSelectedInto() == this),
176 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
178 m_vSelectedBitmap
= rBitmap
;
180 WXHBITMAP hBmp
= m_vSelectedBitmap
.GetHBITMAP();
185 m_vSelectedBitmap
.SetSelectedInto(this);
186 hBmp
= (WXHBITMAP
)::GpiSetBitmap(m_hPS
, (HBITMAP
)hBmp
);
188 if (hBmp
== HBM_ERROR
)
190 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
191 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
193 else if (!m_hOldBitmap
)
197 } // end of wxMemoryDC::SelectObject
199 void wxMemoryDC::DoGetSize(
204 if (!m_vSelectedBitmap
.Ok())
210 *pWidth
= m_vSelectedBitmap
.GetWidth();
211 *pHeight
= m_vSelectedBitmap
.GetHeight();
212 } // end of wxMemoryDC::DoGetSize