]>
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
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #include "wx/dcmemory.h"
15 #include "wx/os2/dcmemory.h"
23 #include "wx/os2/private.h"
25 IMPLEMENT_ABSTRACT_CLASS(wxMemoryDCImpl
, wxPMDCImpl
)
27 /////////////////////////////////////////////////////////////////////////////
29 /////////////////////////////////////////////////////////////////////////////
31 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC
*owner
)
34 CreateCompatible(NULL
);
38 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC
*owner
, wxBitmap
& bitmap
)
41 CreateCompatible(NULL
);
46 wxMemoryDCImpl::wxMemoryDCImpl( wxMemoryDC
*owner
, wxDC
*pOldDC
)
49 wxCHECK_RET( pOldDC
, wxT("NULL dc in wxMemoryDC ctor") );
51 CreateCompatible(pOldDC
);
53 } // end of wxMemoryDC::wxMemoryDC
55 void wxMemoryDCImpl::Init()
59 SetBrush(*wxWHITE_BRUSH
);
62 // the background mode is only used for text background and is set in
63 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
64 ::GpiSetBackMix( GetHPS(), BM_LEAVEALONE
);
66 memset(&m_vRclPaint
, 0, sizeof(m_vRclPaint
));
67 } // end of wxMemoryDC::Init
69 bool wxMemoryDCImpl::CreateCompatible( wxDC
* WXUNUSED(pDC
) )
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 wxWidgets 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 wxMemoryDCImpl::DoSelect(
132 const wxBitmap
& rBitmap
136 // Select old bitmap out of the device context
140 ::GpiSetBitmap(m_hPS
, NULLHANDLE
);
141 if (m_vSelectedBitmap
.IsOk())
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() == GetOwner()),
153 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
155 WXHBITMAP hBmp
= rBitmap
.GetHBITMAP();
160 // Bmps drawn to are upside down, so flip it before committing
162 POINTL vPoint
[4] = { {0, m_vSelectedBitmap
.GetHeight()}
163 ,{m_vSelectedBitmap
.GetWidth(), 0}
165 ,{m_vSelectedBitmap
.GetWidth(), m_vSelectedBitmap
.GetHeight()}
176 m_vSelectedBitmap
.SetSelectedInto(NULL
);
179 m_vSelectedBitmap
= rBitmap
;
185 m_hOldBitmap
= (WXHBITMAP
)::GpiSetBitmap(m_hPS
, NULLHANDLE
);
188 m_vSelectedBitmap
.SetSelectedInto(GetOwner());
189 m_hOldBitmap
= (WXHBITMAP
)::GpiSetBitmap(m_hPS
, (HBITMAP
)hBmp
);
191 if (m_hOldBitmap
== HBM_ERROR
)
193 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
194 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
196 } // end of wxMemoryDC::SelectObject
198 void wxMemoryDCImpl::DoGetSize(
203 if (!m_vSelectedBitmap
.IsOk())
209 *pWidth
= m_vSelectedBitmap
.GetWidth();
210 *pHeight
= m_vSelectedBitmap
.GetHeight();
211 } // end of wxMemoryDC::DoGetSize