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