]> git.saurik.com Git - wxWidgets.git/blob - src/os2/dcmemory.cpp
Test commit
[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 CreateCompatible(pOldDC);
42 Init();
43 } // end of wxMemoryDC::wxMemoryDC
44
45 void wxMemoryDC::Init()
46 {
47 if (m_ok)
48 {
49 SetBrush(*wxWHITE_BRUSH);
50 SetPen(*wxBLACK_PEN);
51
52 // the background mode is only used for text background and is set in
53 // DrawText() to OPAQUE as required, otherwise always TRANSPARENT
54 ::GpiSetBackMix( GetHPS(), BM_LEAVEALONE );
55 }
56 memset(&m_vRclPaint, 0, sizeof(m_vRclPaint));
57 } // end of wxMemoryDC::Init
58
59 bool wxMemoryDC::CreateCompatible( wxDC* WXUNUSED(pDC) )
60 {
61 HDC hDC;
62 HPS hPS;
63 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
64 SIZEL vSize = {0, 0};
65
66 //
67 // Create a memory device context
68 //
69 hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
70 if (hDC != DEV_ERROR)
71 {
72 hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
73 if (hPS != GPI_ERROR)
74 {
75 m_hPS = hPS;
76 m_hDC = hDC;
77 m_ok = true;
78 m_bOwnsDC = true;
79 //
80 // Set the wxWidgets color table
81 //
82 ::GpiCreateLogColorTable( m_hPS
83 ,0L
84 ,LCOLF_CONSECRGB
85 ,0L
86 ,(LONG)wxTheColourDatabase->m_nSize
87 ,(PLONG)wxTheColourDatabase->m_palTable
88 );
89 ::GpiCreateLogColorTable( m_hPS
90 ,0L
91 ,LCOLF_RGB
92 ,0L
93 ,0L
94 ,NULL
95 );
96 }
97 else
98 {
99 m_hPS = NULLHANDLE;
100 m_hDC = NULLHANDLE;
101 m_ok = FALSE;
102 m_bOwnsDC = FALSE;
103 }
104 }
105 else
106 {
107 m_hPS = NULLHANDLE;
108 m_hDC = NULLHANDLE;
109 m_ok = FALSE;
110 m_bOwnsDC = FALSE;
111 }
112
113 //
114 // As we created the DC, we must delete it in the dtor
115 //
116 m_bOwnsDC = true;
117 m_ok = m_hDC != 0;
118 return m_ok;
119 } // end of wxMemoryDC::CreateCompatible
120
121 void wxMemoryDC::SelectObject(
122 const wxBitmap& rBitmap
123 )
124 {
125 //
126 // Select old bitmap out of the device context
127 //
128 if (m_hOldBitmap)
129 {
130 ::GpiSetBitmap(m_hPS, NULLHANDLE);
131 if (m_vSelectedBitmap.Ok())
132 {
133 m_vSelectedBitmap.SetSelectedInto(NULL);
134 m_vSelectedBitmap = wxNullBitmap;
135 }
136 }
137
138 //
139 // Check for whether the bitmap is already selected into a device context
140 //
141 wxCHECK_RET( !rBitmap.GetSelectedInto() ||
142 (rBitmap.GetSelectedInto() == this),
143 wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") );
144
145 WXHBITMAP hBmp = rBitmap.GetHBITMAP();
146
147 if (!hBmp)
148 {
149 //
150 // Bmps drawn to are upside down, so flip it before committing
151 //
152 POINTL vPoint[4] = { {0, m_vSelectedBitmap.GetHeight()}
153 ,{m_vSelectedBitmap.GetWidth(), 0}
154 ,{0, 0}
155 ,{m_vSelectedBitmap.GetWidth(), m_vSelectedBitmap.GetHeight()}
156 };
157
158
159 ::GpiBitBlt( m_hPS
160 ,m_hPS
161 ,4
162 ,vPoint
163 ,ROP_SRCCOPY
164 ,BBO_IGNORE
165 );
166 m_vSelectedBitmap.SetSelectedInto(NULL);
167 }
168 m_vSelectedBitmap = rBitmap;
169
170
171 if (!hBmp)
172 {
173
174 m_hOldBitmap = (WXHBITMAP)::GpiSetBitmap(m_hPS, NULLHANDLE);
175 return;
176 }
177 m_vSelectedBitmap.SetSelectedInto(this);
178 m_hOldBitmap = (WXHBITMAP)::GpiSetBitmap(m_hPS, (HBITMAP)hBmp);
179
180 if (m_hOldBitmap == HBM_ERROR)
181 {
182 wxLogLastError(wxT("SelectObject(memDC, bitmap)"));
183 wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC"));
184 }
185 } // end of wxMemoryDC::SelectObject
186
187 void wxMemoryDC::DoGetSize(
188 int* pWidth
189 , int* pHeight
190 ) const
191 {
192 if (!m_vSelectedBitmap.Ok())
193 {
194 *pWidth = 0;
195 *pHeight = 0;
196 return;
197 }
198 *pWidth = m_vSelectedBitmap.GetWidth();
199 *pHeight = m_vSelectedBitmap.GetHeight();
200 } // end of wxMemoryDC::DoGetSize