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