]> git.saurik.com Git - wxWidgets.git/blame - src/os2/brush.cpp
Fix horizontal mouse wheel scrolling in wxGTK.
[wxWidgets.git] / src / os2 / brush.cpp
CommitLineData
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
37f214d5 7// Copyright: (c) David Webster
65571936 8// Licence: wxWindows licence
0e320a79
DW
9/////////////////////////////////////////////////////////////////////////////
10
37f214d5
DW
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
0e320a79 13
37f214d5 14#ifndef WX_PRECOMP
8ecff181
WS
15 #include <stdio.h>
16 #include "wx/list.h"
17 #include "wx/utils.h"
18 #include "wx/app.h"
19 #include "wx/brush.h"
20 #include "wx/log.h"
37f214d5
DW
21#endif
22
23#include "wx/os2/private.h"
24
1aca6611
SN
25class WXDLLEXPORT wxBrushRefData: public wxGDIRefData
26{
27 friend class WXDLLIMPEXP_FWD_CORE wxBrush;
28public:
29 wxBrushRefData(const wxColour& colour = wxNullColour, wxBrushStyle style = wxBRUSHSTYLE_SOLID);
30 wxBrushRefData(const wxBitmap& stipple);
31 wxBrushRefData(const wxBrushRefData& rData);
32 virtual ~wxBrushRefData();
33
34 bool operator == (const wxBrushRefData& data) const
35 {
36 return (m_nStyle == data.m_nStyle &&
37 m_vStipple.IsSameAs(data.m_vStipple) &&
38 m_vColour == data.m_vColour);
39 }
40
41protected:
42 wxBrushStyle m_nStyle;
43 wxBitmap m_vStipple;
44 wxColour m_vColour;
45 WXHBRUSH m_hBrush; // in OS/2 GPI this will be the PS the pen is associated with
46 AREABUNDLE m_vBundle;
47};
48
49#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
50
51// ============================================================================
52// wxBrushRefData implementation
53// ============================================================================
0e320a79 54
0e320a79 55IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
0e320a79 56
1aca6611
SN
57// ----------------------------------------------------------------------------
58// wxBrushRefData ctors/dtor
59// ----------------------------------------------------------------------------
60
61wxBrushRefData::wxBrushRefData(const wxColour& colour, wxBrushStyle style)
62 : m_vColour(colour)
0e320a79 63{
1aca6611 64 m_nStyle = style;
37f214d5 65 m_hBrush = 0;
15f03b25
DW
66 memset(&m_vBundle, '\0', sizeof(AREABUNDLE));
67} // end of wxBrushRefData::wxBrushRefData
0e320a79 68
1aca6611
SN
69wxBrushRefData::wxBrushRefData(const wxBitmap& stipple)
70{
71 m_vStipple = stipple;
72 m_nStyle = stipple.GetMask() ? wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
73 : wxBRUSHSTYLE_STIPPLE;
74
75 m_hBrush = NULL;
76 memset(&m_vBundle, '\0', sizeof(AREABUNDLE));
77}
78
8ecff181 79wxBrushRefData::wxBrushRefData(const wxBrushRefData& rData)
1aca6611
SN
80 : wxGDIRefData(),
81 m_vStipple(rData.m_vStipple),
82 m_vColour(rData.m_vColour)
0e320a79 83{
15f03b25 84 m_nStyle = rData.m_nStyle;
15f03b25
DW
85 m_hBrush = 0;
86 memcpy(&m_vBundle, &rData.m_vBundle, sizeof(AREABUNDLE));
87} // end of wxBrushRefData::wxBrushRefData
0e320a79
DW
88
89wxBrushRefData::~wxBrushRefData()
90{
15f03b25 91} // end of wxBrushRefData::~wxBrushRefData
0e320a79 92
1aca6611
SN
93// ============================================================================
94// wxBrush implementation
95// ============================================================================
96
97// ----------------------------------------------------------------------------
98// wxBrush ctors/dtor
99// ----------------------------------------------------------------------------
100
0e320a79
DW
101wxBrush::wxBrush()
102{
15f03b25 103} // end of wxBrush::wxBrush
0e320a79
DW
104
105wxBrush::~wxBrush()
106{
15f03b25 107} // end of wxBrush::~wxBrush
0e320a79 108
15f03b25
DW
109wxBrush::wxBrush(
110 const wxColour& rColour
3e6858cd 111, wxBrushStyle nStyle
15f03b25 112)
0e320a79 113{
1aca6611 114 m_refData = new wxBrushRefData(rColour, nStyle);
0e320a79
DW
115
116 RealizeResource();
15f03b25 117} // end of wxBrush::wxBrush
0e320a79 118
ac3688c0
FM
119#if FUTURE_WXWIN_COMPATIBILITY_3_0
120wxBrush::wxBrush(const wxColour& col, int style)
121{
1aca6611 122 m_refData = new wxBrushRefData(col, (wxBrushStyle)style);
ac3688c0
FM
123
124 RealizeResource();
125}
126#endif
127
8ecff181 128wxBrush::wxBrush(const wxBitmap& rStipple)
0e320a79 129{
1aca6611 130 m_refData = new wxBrushRefData(rStipple);
0e320a79
DW
131
132 RealizeResource();
15f03b25 133} // end of wxBrush::wxBrush
0e320a79 134
15f03b25 135bool wxBrush::RealizeResource()
37f214d5 136{
6670f564
WS
137 bool bOk;
138 ERRORID vError;
139 wxString sError;
15f03b25
DW
140
141 if (M_BRUSHDATA && M_BRUSHDATA->m_hBrush == 0L)
37f214d5 142 {
15f03b25
DW
143 SIZEL vSize = {0, 0};
144 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
145 HDC hDC = ::DevOpenDC( vHabmain
146 ,OD_MEMORY
147 ,"*"
148 ,5L
149 ,(PDEVOPENDATA)&vDop
150 ,NULLHANDLE
151 );
152 M_BRUSHDATA->m_hBrush = (WXHPEN)::GpiCreatePS( vHabmain
153 ,hDC
154 ,&vSize
155 ,PU_PELS | GPIT_MICRO | GPIA_ASSOC
156 );
157 }
158 if (M_BRUSHDATA)
159 {
160 //
161 // Set the color table to RGB mode
162 //
163 if (!::GpiCreateLogColorTable( (HPS)M_BRUSHDATA->m_hBrush
164 ,0L
165 ,LCOLF_RGB
166 ,0L
167 ,0L
168 ,NULL
169 ))
170 {
171 vError = ::WinGetLastError(vHabmain);
172 sError = wxPMErrorToStr(vError);
9a83f860 173 wxLogError(wxT("Unable to set current color table to RGB mode. Error: %s\n"), sError.c_str());
46562151 174 return false;
15f03b25
DW
175 }
176
177 if (M_BRUSHDATA->m_nStyle==wxTRANSPARENT)
37f214d5 178 {
6670f564 179 return true;
37f214d5 180 }
15f03b25 181 COLORREF vPmColour = 0L;
37f214d5 182
15f03b25 183 vPmColour = M_BRUSHDATA->m_vColour.GetPixel() ;
37f214d5 184
15f03b25
DW
185 M_BRUSHDATA->m_vBundle.usSet = LCID_DEFAULT;
186 switch (M_BRUSHDATA->m_nStyle)
37f214d5 187 {
15f03b25
DW
188 case wxTRANSPARENT:
189 M_BRUSHDATA->m_hBrush = NULL; // Must always select a suitable background brush
190 break; // - could choose white always for a quick solution
191
37f214d5 192 case wxBDIAGONAL_HATCH:
15f03b25
DW
193 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_DIAG3;
194 break;
37f214d5
DW
195
196 case wxCROSSDIAG_HATCH:
15f03b25
DW
197 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_DIAGHATCH;
198 break;
37f214d5
DW
199
200 case wxFDIAGONAL_HATCH:
15f03b25
DW
201 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_DIAG1;
202 break;
37f214d5
DW
203
204 case wxCROSS_HATCH:
15f03b25
DW
205 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_HATCH;
206 break;
37f214d5
DW
207
208 case wxHORIZONTAL_HATCH:
15f03b25
DW
209 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_HORIZ;
210 break;
37f214d5
DW
211
212 case wxVERTICAL_HATCH:
15f03b25
DW
213 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_VERT;
214 break;
37f214d5
DW
215
216 case wxSTIPPLE:
a1b806b9 217 if (M_BRUSHDATA->m_vStipple.IsOk())
15f03b25
DW
218 {
219 ::GpiSetBitmapId( M_BRUSHDATA->m_hBrush
220 ,(USHORT)M_BRUSHDATA->m_vStipple.GetHBITMAP()
221 ,(USHORT)M_BRUSHDATA->m_vStipple.GetId()
222 );
223 ::GpiSetPatternSet( M_BRUSHDATA->m_hBrush
224 ,(USHORT)M_BRUSHDATA->m_vStipple.GetId()
225 );
226 }
37f214d5 227 else
15f03b25 228 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_SOLID;
37f214d5
DW
229 break ;
230
231 case wxSOLID:
232 default:
15f03b25 233 M_BRUSHDATA->m_vBundle.usSymbol = PATSYM_SOLID;
37f214d5
DW
234 break;
235 }
236#ifdef WXDEBUG_CREATE
237 if (M_BRUSHDATA->m_hBrush==NULL) wxError("Cannot create brush","Internal error") ;
238#endif
15f03b25 239 M_BRUSHDATA->m_vBundle.lColor = vPmColour;
8d854fa9 240 M_BRUSHDATA->m_vBundle.lBackColor = RGB_WHITE;
15f03b25
DW
241 M_BRUSHDATA->m_vBundle.usMixMode = FM_OVERPAINT;
242 M_BRUSHDATA->m_vBundle.usBackMixMode = BM_OVERPAINT;
243
6670f564
WS
244 bOk = (bool)::GpiSetAttrs( M_BRUSHDATA->m_hBrush
245 ,PRIM_AREA
246 ,ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE |
c9ab2da6
SN
247 ABB_SET | ABB_SYMBOL | ABB_REF_POINT
248 ,ABB_SET | ABB_SYMBOL | ABB_REF_POINT
6670f564
WS
249 ,&M_BRUSHDATA->m_vBundle
250 );
15f03b25
DW
251 if (!bOk)
252 {
253 vError = ::WinGetLastError(vHabmain);
254 sError = wxPMErrorToStr(vError);
9a83f860 255 wxLogError(wxT("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n"), sError.c_str());
15f03b25
DW
256 }
257 return bOk;
37f214d5 258 }
46562151 259 return false;
15f03b25 260} // end of wxBrush::RealizeResource
37f214d5 261
1aca6611
SN
262// ----------------------------------------------------------------------------
263// wxBrush accessors
264// ----------------------------------------------------------------------------
265
266wxColour wxBrush::GetColour() const
267{
a1b806b9 268 wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid brush") );
1aca6611
SN
269
270 return M_BRUSHDATA->m_vColour;
271}
272
273wxBrushStyle wxBrush::GetStyle() const
274{
a1b806b9 275 wxCHECK_MSG( IsOk(), wxBRUSHSTYLE_INVALID, wxT("invalid brush") );
1aca6611
SN
276
277 return M_BRUSHDATA->m_nStyle;
278}
279
280wxBitmap *wxBrush::GetStipple() const
281{
a1b806b9 282 wxCHECK_MSG( IsOk(), NULL, wxT("invalid brush") );
1aca6611
SN
283
284 return &(M_BRUSHDATA->m_vStipple);
285}
286
287int wxBrush::GetPS() const
288{
a1b806b9 289 wxCHECK_MSG( IsOk(), 0, wxT("invalid brush") );
1aca6611
SN
290
291 return M_BRUSHDATA->m_hBrush;
292}
293
17b1d76b 294WXHANDLE wxBrush::GetResourceHandle() const
37f214d5 295{
a1b806b9 296 wxCHECK_MSG( IsOk(), 0, wxT("invalid brush") );
1aca6611 297
15f03b25
DW
298 return (WXHANDLE)M_BRUSHDATA->m_hBrush;
299} // end of wxBrush::GetResourceHandle
300
6670f564 301bool wxBrush::FreeResource( bool WXUNUSED(bForce) )
37f214d5
DW
302{
303 if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush != 0))
304 {
37f214d5 305 M_BRUSHDATA->m_hBrush = 0;
6670f564 306 return true;
37f214d5 307 }
46562151 308 else return false;
15f03b25 309} // end of wxBrush::FreeResource
37f214d5
DW
310
311bool wxBrush::IsFree() const
312{
313 return (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0));
15f03b25 314} // end of wxBrush::IsFree
37f214d5 315
1aca6611
SN
316// ----------------------------------------------------------------------------
317// wxBrush setters
318// ----------------------------------------------------------------------------
319
46562151 320void wxBrush::SetColour( const wxColour& rColour )
0e320a79 321{
4b3f61d1 322 AllocExclusive();
15f03b25 323 M_BRUSHDATA->m_vColour = rColour;
0e320a79
DW
324 RealizeResource();
325}
326
1a1498c0 327void wxBrush::SetColour(unsigned char cRed, unsigned char cGreen, unsigned char cBlue)
0e320a79 328{
4b3f61d1 329 AllocExclusive();
46562151 330 M_BRUSHDATA->m_vColour.Set( cRed, cGreen, cBlue );
0e320a79 331 RealizeResource();
15f03b25 332} // end of wxBrush::SetColour
0e320a79 333
3e6858cd 334void wxBrush::SetStyle(wxBrushStyle nStyle)
0e320a79 335{
4b3f61d1 336 AllocExclusive();
15f03b25 337 M_BRUSHDATA->m_nStyle = nStyle;
0e320a79 338 RealizeResource();
15f03b25 339} // end of wxBrush::SetStyle
0e320a79 340
15f03b25
DW
341void wxBrush::SetStipple(
342 const wxBitmap& rStipple
343)
0e320a79 344{
4b3f61d1 345 AllocExclusive();
15f03b25
DW
346 M_BRUSHDATA->m_vStipple = rStipple;
347 RealizeResource();
348} // end of wxBrush::SetStipple
0e320a79 349
15f03b25
DW
350void wxBrush::SetPS(
351 HPS hPS
352)
353{
4b3f61d1 354 AllocExclusive();
15f03b25
DW
355 if (M_BRUSHDATA->m_hBrush)
356 ::GpiDestroyPS(M_BRUSHDATA->m_hBrush);
357 M_BRUSHDATA->m_hBrush = hPS;
0e320a79 358 RealizeResource();
15f03b25 359} // end of WxWinGdi_CPen::SetPS
7aa920b5 360
1aca6611
SN
361// ----------------------------------------------------------------------------
362// wxBrush house keeping stuff
363// ----------------------------------------------------------------------------
7aa920b5
VZ
364
365bool wxBrush::operator == (
366 const wxBrush& brush
367) const
368{
369 if (m_refData == brush.m_refData) return true;
370
371 if (!m_refData || !brush.m_refData) return false;
372
373 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
374} // end of wxBrush::operator ==
375
4b3f61d1
SN
376wxGDIRefData *wxBrush::CreateGDIRefData() const
377{
378 return new wxBrushRefData;
379}
380
381wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const
382{
383 return new wxBrushRefData(*(const wxBrushRefData *)data);
384}