]> git.saurik.com Git - wxWidgets.git/blob - src/os2/brush.cpp
Include wx/dynarray.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / os2 / brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/brush.cpp
3 // Purpose: wxBrush
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/13/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 <stdio.h>
17 #include "wx/list.h"
18 #include "wx/utils.h"
19 #include "wx/app.h"
20 #include "wx/brush.h"
21 #include "wx/log.h"
22 #endif
23
24 #include "wx/os2/private.h"
25
26 #include "assert.h"
27
28 IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
29
30 wxBrushRefData::wxBrushRefData()
31 {
32 m_nStyle = wxSOLID;
33 m_hBrush = 0;
34 memset(&m_vBundle, '\0', sizeof(AREABUNDLE));
35 } // end of wxBrushRefData::wxBrushRefData
36
37 wxBrushRefData::wxBrushRefData(
38 const wxBrushRefData& rData
39 )
40 {
41 m_nStyle = rData.m_nStyle;
42 m_vStipple = rData.m_vStipple;
43 m_vColour = rData.m_vColour;
44 m_hBrush = 0;
45 memcpy(&m_vBundle, &rData.m_vBundle, sizeof(AREABUNDLE));
46 } // end of wxBrushRefData::wxBrushRefData
47
48 wxBrushRefData::~wxBrushRefData()
49 {
50 } // end of wxBrushRefData::~wxBrushRefData
51
52 //
53 // Brushes
54 //
55 wxBrush::wxBrush()
56 {
57 } // end of wxBrush::wxBrush
58
59 wxBrush::~wxBrush()
60 {
61 } // end of wxBrush::~wxBrush
62
63 wxBrush::wxBrush(
64 const wxColour& rColour
65 , int nStyle
66 )
67 {
68 m_refData = new wxBrushRefData;
69
70 M_BRUSHDATA->m_vColour = rColour;
71 M_BRUSHDATA->m_nStyle = nStyle;
72 M_BRUSHDATA->m_hBrush = 0;
73 memset(&M_BRUSHDATA->m_vBundle, '\0', sizeof(AREABUNDLE));
74
75 RealizeResource();
76 } // end of wxBrush::wxBrush
77
78 wxBrush::wxBrush(
79 const wxBitmap& rStipple
80 )
81 {
82 m_refData = new wxBrushRefData;
83
84 M_BRUSHDATA->m_nStyle = wxSTIPPLE;
85 M_BRUSHDATA->m_vStipple = rStipple;
86 M_BRUSHDATA->m_hBrush = 0;
87 memset(&M_BRUSHDATA->m_vBundle, '\0', sizeof(AREABUNDLE));
88
89 RealizeResource();
90 } // end of wxBrush::wxBrush
91
92 bool wxBrush::RealizeResource()
93 {
94 bool bOk;
95 ERRORID vError;
96 wxString sError;
97
98 if (M_BRUSHDATA && M_BRUSHDATA->m_hBrush == 0L)
99 {
100 SIZEL vSize = {0, 0};
101 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
102 HDC hDC = ::DevOpenDC( vHabmain
103 ,OD_MEMORY
104 ,"*"
105 ,5L
106 ,(PDEVOPENDATA)&vDop
107 ,NULLHANDLE
108 );
109 M_BRUSHDATA->m_hBrush = (WXHPEN)::GpiCreatePS( vHabmain
110 ,hDC
111 ,&vSize
112 ,PU_PELS | GPIT_MICRO | GPIA_ASSOC
113 );
114 }
115 if (M_BRUSHDATA)
116 {
117 //
118 // Set the color table to RGB mode
119 //
120 if (!::GpiCreateLogColorTable( (HPS)M_BRUSHDATA->m_hBrush
121 ,0L
122 ,LCOLF_RGB
123 ,0L
124 ,0L
125 ,NULL
126 ))
127 {
128 vError = ::WinGetLastError(vHabmain);
129 sError = wxPMErrorToStr(vError);
130 wxLogError(_T("Unable to set current color table to RGB mode. Error: %s\n"), sError.c_str());
131 return false;
132 }
133
134 if (M_BRUSHDATA->m_nStyle==wxTRANSPARENT)
135 {
136 return true;
137 }
138 COLORREF vPmColour = 0L;
139
140 vPmColour = M_BRUSHDATA->m_vColour.GetPixel() ;
141
142 M_BRUSHDATA->m_vBundle.usSet = LCID_DEFAULT;
143 switch (M_BRUSHDATA->m_nStyle)
144 {
145 case wxTRANSPARENT:
146 M_BRUSHDATA->m_hBrush = NULL; // Must always select a suitable background brush
147 break; // - could choose white always for a quick solution
148
149 case wxBDIAGONAL_HATCH:
150 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_DIAG3;
151 break;
152
153 case wxCROSSDIAG_HATCH:
154 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_DIAGHATCH;
155 break;
156
157 case wxFDIAGONAL_HATCH:
158 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_DIAG1;
159 break;
160
161 case wxCROSS_HATCH:
162 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_HATCH;
163 break;
164
165 case wxHORIZONTAL_HATCH:
166 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_HORIZ;
167 break;
168
169 case wxVERTICAL_HATCH:
170 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_VERT;
171 break;
172
173 case wxSTIPPLE:
174 if (M_BRUSHDATA->m_vStipple.Ok())
175 {
176 ::GpiSetBitmapId( M_BRUSHDATA->m_hBrush
177 ,(USHORT)M_BRUSHDATA->m_vStipple.GetHBITMAP()
178 ,(USHORT)M_BRUSHDATA->m_vStipple.GetId()
179 );
180 ::GpiSetPatternSet( M_BRUSHDATA->m_hBrush
181 ,(USHORT)M_BRUSHDATA->m_vStipple.GetId()
182 );
183 }
184 else
185 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_SOLID;
186 break ;
187
188 case wxSOLID:
189 default:
190 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_SOLID;
191 break;
192 }
193 #ifdef WXDEBUG_CREATE
194 if (M_BRUSHDATA->m_hBrush==NULL) wxError("Cannot create brush","Internal error") ;
195 #endif
196 M_BRUSHDATA->m_vBundle.lColor = vPmColour;
197 M_BRUSHDATA->m_vBundle.lBackColor = RGB_WHITE;
198 M_BRUSHDATA->m_vBundle.usMixMode = FM_OVERPAINT;
199 M_BRUSHDATA->m_vBundle.usBackMixMode = BM_OVERPAINT;
200
201 bOk = (bool)::GpiSetAttrs( M_BRUSHDATA->m_hBrush
202 ,PRIM_AREA
203 ,ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE |
204 ABB_SET | ABB_SYMBOL
205 ,ABB_REF_POINT
206 ,&M_BRUSHDATA->m_vBundle
207 );
208 if (!bOk)
209 {
210 vError = ::WinGetLastError(vHabmain);
211 sError = wxPMErrorToStr(vError);
212 wxLogError(_T("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n"), sError.c_str());
213 }
214 return bOk;
215 }
216 return false;
217 } // end of wxBrush::RealizeResource
218
219 WXHANDLE wxBrush::GetResourceHandle()
220 {
221 if (!M_BRUSHDATA)
222 return 0;
223 return (WXHANDLE)M_BRUSHDATA->m_hBrush;
224 } // end of wxBrush::GetResourceHandle
225
226 bool wxBrush::FreeResource( bool WXUNUSED(bForce) )
227 {
228 if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush != 0))
229 {
230 M_BRUSHDATA->m_hBrush = 0;
231 return true;
232 }
233 else return false;
234 } // end of wxBrush::FreeResource
235
236 bool wxBrush::IsFree() const
237 {
238 return (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0));
239 } // end of wxBrush::IsFree
240
241 void wxBrush::Unshare()
242 {
243 //
244 // Don't change shared data
245 //
246 if (!m_refData)
247 {
248 m_refData = new wxBrushRefData();
249 }
250 else
251 {
252 wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
253 UnRef();
254 m_refData = ref;
255 }
256 } // end of wxBrush::Unshare
257
258 void wxBrush::SetColour( const wxColour& rColour )
259 {
260 Unshare();
261 M_BRUSHDATA->m_vColour = rColour;
262 RealizeResource();
263 }
264
265 void wxBrush::SetColour(unsigned char cRed, unsigned char cGreen, unsigned char cBlue)
266 {
267 Unshare();
268 M_BRUSHDATA->m_vColour.Set( cRed, cGreen, cBlue );
269 RealizeResource();
270 } // end of wxBrush::SetColour
271
272 void wxBrush::SetStyle(int nStyle)
273 {
274 Unshare();
275 M_BRUSHDATA->m_nStyle = nStyle;
276 RealizeResource();
277 } // end of wxBrush::SetStyle
278
279 void wxBrush::SetStipple(
280 const wxBitmap& rStipple
281 )
282 {
283 Unshare();
284 M_BRUSHDATA->m_vStipple = rStipple;
285 RealizeResource();
286 } // end of wxBrush::SetStipple
287
288 void wxBrush::SetPS(
289 HPS hPS
290 )
291 {
292 Unshare();
293 if (M_BRUSHDATA->m_hBrush)
294 ::GpiDestroyPS(M_BRUSHDATA->m_hBrush);
295 M_BRUSHDATA->m_hBrush = hPS;
296 RealizeResource();
297 } // end of WxWinGdi_CPen::SetPS