]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/brush.cpp
e45a28f3b131888f7626941f14b4afb96344931b
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
24 #include "wx/os2/private.h"
28 IMPLEMENT_DYNAMIC_CLASS(wxBrush
, wxGDIObject
)
30 wxBrushRefData::wxBrushRefData()
34 memset(&m_vBundle
, '\0', sizeof(AREABUNDLE
));
35 } // end of wxBrushRefData::wxBrushRefData
37 wxBrushRefData::wxBrushRefData(
38 const wxBrushRefData
& rData
41 m_nStyle
= rData
.m_nStyle
;
42 m_vStipple
= rData
.m_vStipple
;
43 m_vColour
= rData
.m_vColour
;
45 memcpy(&m_vBundle
, &rData
.m_vBundle
, sizeof(AREABUNDLE
));
46 } // end of wxBrushRefData::wxBrushRefData
48 wxBrushRefData::~wxBrushRefData()
50 } // end of wxBrushRefData::~wxBrushRefData
58 wxTheBrushList
->AddBrush(this);
59 } // end of wxBrush::wxBrush
64 wxTheBrushList
->RemoveBrush(this);
65 } // end of wxBrush::~wxBrush
68 const wxColour
& rColour
72 m_refData
= new wxBrushRefData
;
74 M_BRUSHDATA
->m_vColour
= rColour
;
75 M_BRUSHDATA
->m_nStyle
= nStyle
;
76 M_BRUSHDATA
->m_hBrush
= 0;
77 memset(&M_BRUSHDATA
->m_vBundle
, '\0', sizeof(AREABUNDLE
));
82 wxTheBrushList
->AddBrush(this);
83 } // end of wxBrush::wxBrush
86 const wxBitmap
& rStipple
89 m_refData
= new wxBrushRefData
;
91 M_BRUSHDATA
->m_nStyle
= wxSTIPPLE
;
92 M_BRUSHDATA
->m_vStipple
= rStipple
;
93 M_BRUSHDATA
->m_hBrush
= 0;
94 memset(&M_BRUSHDATA
->m_vBundle
, '\0', sizeof(AREABUNDLE
));
99 wxTheBrushList
->AddBrush(this);
100 } // end of wxBrush::wxBrush
102 bool wxBrush::RealizeResource()
108 if (M_BRUSHDATA
&& M_BRUSHDATA
->m_hBrush
== 0L)
110 SIZEL vSize
= {0, 0};
111 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
112 HDC hDC
= ::DevOpenDC( vHabmain
119 M_BRUSHDATA
->m_hBrush
= (WXHPEN
)::GpiCreatePS( vHabmain
122 ,PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
128 // Set the color table to RGB mode
130 if (!::GpiCreateLogColorTable( (HPS
)M_BRUSHDATA
->m_hBrush
138 vError
= ::WinGetLastError(vHabmain
);
139 sError
= wxPMErrorToStr(vError
);
140 wxLogError("Unable to set current color table to RGB mode. Error: %s\n", sError
);
144 if (M_BRUSHDATA
->m_nStyle
==wxTRANSPARENT
)
148 COLORREF vPmColour
= 0L;
150 vPmColour
= M_BRUSHDATA
->m_vColour
.GetPixel() ;
152 M_BRUSHDATA
->m_vBundle
.usSet
= LCID_DEFAULT
;
153 switch (M_BRUSHDATA
->m_nStyle
)
156 M_BRUSHDATA
->m_hBrush
= NULL
; // Must always select a suitable background brush
157 break; // - could choose white always for a quick solution
159 case wxBDIAGONAL_HATCH
:
160 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_DIAG3
;
163 case wxCROSSDIAG_HATCH
:
164 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_DIAGHATCH
;
167 case wxFDIAGONAL_HATCH
:
168 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_DIAG1
;
172 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_HATCH
;
175 case wxHORIZONTAL_HATCH
:
176 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_HORIZ
;
179 case wxVERTICAL_HATCH
:
180 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_VERT
;
184 if (M_BRUSHDATA
->m_vStipple
.Ok())
186 ::GpiSetBitmapId( M_BRUSHDATA
->m_hBrush
187 ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetHBITMAP()
188 ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetId()
190 ::GpiSetPatternSet( M_BRUSHDATA
->m_hBrush
191 ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetId()
195 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_SOLID
;
200 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_SOLID
;
203 #ifdef WXDEBUG_CREATE
204 if (M_BRUSHDATA
->m_hBrush
==NULL
) wxError("Cannot create brush","Internal error") ;
206 M_BRUSHDATA
->m_vBundle
.lColor
= vPmColour
;
207 M_BRUSHDATA
->m_vBundle
.lBackColor
= CLR_DEFAULT
;
208 M_BRUSHDATA
->m_vBundle
.usMixMode
= FM_OVERPAINT
;
209 M_BRUSHDATA
->m_vBundle
.usBackMixMode
= BM_OVERPAINT
;
211 bOk
= ::GpiSetAttrs( M_BRUSHDATA
->m_hBrush
213 ,ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
|
216 ,&M_BRUSHDATA
->m_vBundle
220 vError
= ::WinGetLastError(vHabmain
);
221 sError
= wxPMErrorToStr(vError
);
222 wxLogError("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n", sError
);
227 } // end of wxBrush::RealizeResource
229 WXHANDLE
wxBrush::GetResourceHandle()
233 return (WXHANDLE
)M_BRUSHDATA
->m_hBrush
;
234 } // end of wxBrush::GetResourceHandle
236 bool wxBrush::FreeResource(
237 bool WXUNUSED(bForce
)
240 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
!= 0))
242 M_BRUSHDATA
->m_hBrush
= 0;
246 } // end of wxBrush::FreeResource
248 bool wxBrush::IsFree() const
250 return (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0));
251 } // end of wxBrush::IsFree
253 void wxBrush::Unshare()
256 // Don't change shared data
260 m_refData
= new wxBrushRefData();
264 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
268 } // end of wxBrush::Unshare
270 void wxBrush::SetColour(
271 const wxColour
& rColour
275 M_BRUSHDATA
->m_vColour
= rColour
;
279 void wxBrush::SetColour(
281 , unsigned char cGreen
282 , unsigned char cBlue
286 M_BRUSHDATA
->m_vColour
.Set( cRed
291 } // end of wxBrush::SetColour
293 void wxBrush::SetStyle(
298 M_BRUSHDATA
->m_nStyle
= nStyle
;
300 } // end of wxBrush::SetStyle
302 void wxBrush::SetStipple(
303 const wxBitmap
& rStipple
307 M_BRUSHDATA
->m_vStipple
= rStipple
;
309 } // end of wxBrush::SetStipple
316 if (M_BRUSHDATA
->m_hBrush
)
317 ::GpiDestroyPS(M_BRUSHDATA
->m_hBrush
);
318 M_BRUSHDATA
->m_hBrush
= hPS
;
320 } // end of WxWinGdi_CPen::SetPS