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