]> git.saurik.com Git - wxWidgets.git/blob - src/os2/dcmemory.cpp
forgot to commit - no changes
[wxWidgets.git] / src / os2 / dcmemory.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dcmemory.cpp
3 // Purpose: wxMemoryDC class
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/14/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/utils.h"
17 #include "wx/app.h"
18 #include "wx/log.h"
19 #endif
20
21 #include "wx/os2/private.h"
22
23 #include "wx/dcmemory.h"
24
25 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC)
26
27 /////////////////////////////////////////////////////////////////////////////
28 // Memory DC
29 /////////////////////////////////////////////////////////////////////////////
30
31 wxMemoryDC::wxMemoryDC(void)
32 {
33 CreateCompatible(NULL);
34 Init();
35 } // end of wxMemoryDC::wxMemoryDC
36
37 wxMemoryDC::wxMemoryDC(
38 wxDC* pOldDC
39 )
40 {
41 pOldDC->BeginDrawing();
42 CreateCompatible(pOldDC);
43 pOldDC->EndDrawing();
44 Init();
45 } // end of wxMemoryDC::wxMemoryDC
46
47 void wxMemoryDC::Init()
48 {
49 if (m_ok)
50 {
51 SetBrush(*wxWHITE_BRUSH);
52 SetPen(*wxBLACK_PEN);
53
54 // the background mode is only used for text background and is set in
55 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
56 ::GpiSetBackMix( GetHPS(), BM_LEAVEALONE );
57 }
58 } // end of wxMemoryDC::Init
59
60 bool wxMemoryDC::CreateCompatible(
61 wxDC* pDC
62 )
63 {
64 HDC hDC;
65 HPS hPS;
66 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
67 SIZEL vSize = {0, 0};
68
69 //
70 // Create a memory device context
71 //
72 hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
73 if (hDC != DEV_ERROR)
74 {
75 hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
76 if (hPS != GPI_ERROR)
77 {
78 m_hPS = hPS;
79 m_hDC = hDC;
80 m_ok = TRUE;
81 m_bOwnsDC = TRUE;
82 //
83 // Set the wxWindows color table
84 //
85 ::GpiCreateLogColorTable( m_hPS
86 ,0L
87 ,LCOLF_CONSECRGB
88 ,0L
89 ,(LONG)wxTheColourDatabase->m_nSize
90 ,(PLONG)wxTheColourDatabase->m_palTable
91 );
92 ::GpiCreateLogColorTable( m_hPS
93 ,0L
94 ,LCOLF_RGB
95 ,0L
96 ,0L
97 ,NULL
98 );
99 }
100 else
101 {
102 m_hPS = NULLHANDLE;
103 m_hDC = NULLHANDLE;
104 m_ok = FALSE;
105 m_bOwnsDC = FALSE;
106 }
107 }
108 else
109 {
110 m_hPS = NULLHANDLE;
111 m_hDC = NULLHANDLE;
112 m_ok = FALSE;
113 m_bOwnsDC = FALSE;
114 }
115
116 //
117 // As we created the DC, we must delete it in the dtor
118 //
119 m_bOwnsDC = TRUE;
120 m_ok = m_hDC != 0;
121 return m_ok;
122 } // end of wxMemoryDC::CreateCompatible
123
124 void wxMemoryDC::SelectObject(
125 const wxBitmap& rBitmap
126 )
127 {
128 //
129 // Select old bitmap out of the device context
130 //
131 if (m_hOldBitmap)
132 {
133 ::GpiSetBitmap(m_hPS, NULLHANDLE);
134 if (m_vSelectedBitmap.Ok())
135 {
136 m_vSelectedBitmap.SetSelectedInto(NULL);
137 m_vSelectedBitmap = wxNullBitmap;
138 }
139 }
140
141 //
142 // Check for whether the bitmap is already selected into a device context
143 //
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)") );
147
148 m_vSelectedBitmap = rBitmap;
149
150 WXHBITMAP hBmp = m_vSelectedBitmap.GetHBITMAP();
151
152 if (!hBmp)
153 return;
154
155 m_vSelectedBitmap.SetSelectedInto(this);
156 hBmp = (WXHBITMAP)::GpiSetBitmap(m_hPS, (HBITMAP)hBmp);
157
158 if (hBmp == HBM_ERROR)
159 {
160 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
161 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
162 }
163 else if (!m_hOldBitmap)
164 {
165 m_hOldBitmap = hBmp;
166 }
167 } // end of wxMemoryDC::SelectObject
168
169 void wxMemoryDC::DoGetSize(
170 int* pWidth
171 , int* pHeight
172 ) const
173 {
174 if (!m_vSelectedBitmap.Ok())
175 {
176 *pWidth = 0;
177 *pHeight = 0;
178 return;
179 }
180 *pWidth = m_vSelectedBitmap.GetWidth();
181 *pHeight = m_vSelectedBitmap.GetHeight();
182 } // end of wxMemoryDC::DoGetSize
183
184 void wxMemoryDC::DoDrawRectangle(
185 wxCoord vX
186 , wxCoord vY
187 , wxCoord vWidth
188 , wxCoord vHeight
189 )
190 {
191 wxDC::DoDrawRectangle(vX, vY, vWidth, vHeight);
192 } // end of wxMemoryDC::DoDrawRectangle