]>
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 | 236 | |
46562151 | 237 | void wxBrush::SetColour( const wxColour& rColour ) |
0e320a79 | 238 | { |
4b3f61d1 | 239 | AllocExclusive(); |
15f03b25 | 240 | M_BRUSHDATA->m_vColour = rColour; |
0e320a79 DW |
241 | RealizeResource(); |
242 | } | |
243 | ||
1a1498c0 | 244 | void wxBrush::SetColour(unsigned char cRed, unsigned char cGreen, unsigned char cBlue) |
0e320a79 | 245 | { |
4b3f61d1 | 246 | AllocExclusive(); |
46562151 | 247 | M_BRUSHDATA->m_vColour.Set( cRed, cGreen, cBlue ); |
0e320a79 | 248 | RealizeResource(); |
15f03b25 | 249 | } // end of wxBrush::SetColour |
0e320a79 | 250 | |
46562151 | 251 | void wxBrush::SetStyle(int nStyle) |
0e320a79 | 252 | { |
4b3f61d1 | 253 | AllocExclusive(); |
15f03b25 | 254 | M_BRUSHDATA->m_nStyle = nStyle; |
0e320a79 | 255 | RealizeResource(); |
15f03b25 | 256 | } // end of wxBrush::SetStyle |
0e320a79 | 257 | |
15f03b25 DW |
258 | void wxBrush::SetStipple( |
259 | const wxBitmap& rStipple | |
260 | ) | |
0e320a79 | 261 | { |
4b3f61d1 | 262 | AllocExclusive(); |
15f03b25 DW |
263 | M_BRUSHDATA->m_vStipple = rStipple; |
264 | RealizeResource(); | |
265 | } // end of wxBrush::SetStipple | |
0e320a79 | 266 | |
15f03b25 DW |
267 | void wxBrush::SetPS( |
268 | HPS hPS | |
269 | ) | |
270 | { | |
4b3f61d1 | 271 | AllocExclusive(); |
15f03b25 DW |
272 | if (M_BRUSHDATA->m_hBrush) |
273 | ::GpiDestroyPS(M_BRUSHDATA->m_hBrush); | |
274 | M_BRUSHDATA->m_hBrush = hPS; | |
0e320a79 | 275 | RealizeResource(); |
15f03b25 | 276 | } // end of WxWinGdi_CPen::SetPS |
7aa920b5 VZ |
277 | |
278 | ||
279 | bool wxBrush::operator == ( | |
280 | const wxBrush& brush | |
281 | ) const | |
282 | { | |
283 | if (m_refData == brush.m_refData) return true; | |
284 | ||
285 | if (!m_refData || !brush.m_refData) return false; | |
286 | ||
287 | return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData ); | |
288 | } // end of wxBrush::operator == | |
289 | ||
4b3f61d1 SN |
290 | wxGDIRefData *wxBrush::CreateGDIRefData() const |
291 | { | |
292 | return new wxBrushRefData; | |
293 | } | |
294 | ||
295 | wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const | |
296 | { | |
297 | return new wxBrushRefData(*(const wxBrushRefData *)data); | |
298 | } |