]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/brush.cpp
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(const wxBrushRefData
& rData
)
39 m_nStyle
= rData
.m_nStyle
;
40 m_vStipple
= rData
.m_vStipple
;
41 m_vColour
= rData
.m_vColour
;
43 memcpy(&m_vBundle
, &rData
.m_vBundle
, sizeof(AREABUNDLE
));
44 } // end of wxBrushRefData::wxBrushRefData
46 wxBrushRefData::~wxBrushRefData()
48 } // end of wxBrushRefData::~wxBrushRefData
55 } // end of wxBrush::wxBrush
59 } // end of wxBrush::~wxBrush
62 const wxColour
& rColour
66 m_refData
= new wxBrushRefData
;
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
));
74 } // end of wxBrush::wxBrush
76 #if FUTURE_WXWIN_COMPATIBILITY_3_0
77 wxBrush::wxBrush(const wxColour
& col
, int style
)
79 m_refData
= new wxBrushRefData
;
81 M_BRUSHDATA
->m_vColour
= col
;
82 M_BRUSHDATA
->m_nStyle
= (wxBrushStyle
)style
;
83 M_BRUSHDATA
->m_hBrush
= 0;
84 memset(&M_BRUSHDATA
->m_vBundle
, '\0', sizeof(AREABUNDLE
));
90 wxBrush::wxBrush(const wxBitmap
& rStipple
)
92 m_refData
= new wxBrushRefData
;
94 M_BRUSHDATA
->m_nStyle
= wxSTIPPLE
;
95 M_BRUSHDATA
->m_vStipple
= rStipple
;
96 M_BRUSHDATA
->m_hBrush
= 0;
97 memset(&M_BRUSHDATA
->m_vBundle
, '\0', sizeof(AREABUNDLE
));
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(_T("Unable to set current color table to RGB mode. Error: %s\n"), sError
.c_str());
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
= RGB_WHITE
;
208 M_BRUSHDATA
->m_vBundle
.usMixMode
= FM_OVERPAINT
;
209 M_BRUSHDATA
->m_vBundle
.usBackMixMode
= BM_OVERPAINT
;
211 bOk
= (bool)::GpiSetAttrs( M_BRUSHDATA
->m_hBrush
213 ,ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
|
214 ABB_SET
| ABB_SYMBOL
| ABB_REF_POINT
215 ,ABB_SET
| ABB_SYMBOL
| ABB_REF_POINT
216 ,&M_BRUSHDATA
->m_vBundle
220 vError
= ::WinGetLastError(vHabmain
);
221 sError
= wxPMErrorToStr(vError
);
222 wxLogError(_T("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n"), sError
.c_str());
227 } // end of wxBrush::RealizeResource
229 WXHANDLE
wxBrush::GetResourceHandle() const
233 return (WXHANDLE
)M_BRUSHDATA
->m_hBrush
;
234 } // end of wxBrush::GetResourceHandle
236 bool wxBrush::FreeResource( bool WXUNUSED(bForce
) )
238 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
!= 0))
240 M_BRUSHDATA
->m_hBrush
= 0;
244 } // end of wxBrush::FreeResource
246 bool wxBrush::IsFree() const
248 return (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0));
249 } // end of wxBrush::IsFree
251 void wxBrush::SetColour( const wxColour
& rColour
)
254 M_BRUSHDATA
->m_vColour
= rColour
;
258 void wxBrush::SetColour(unsigned char cRed
, unsigned char cGreen
, unsigned char cBlue
)
261 M_BRUSHDATA
->m_vColour
.Set( cRed
, cGreen
, cBlue
);
263 } // end of wxBrush::SetColour
265 void wxBrush::SetStyle(wxBrushStyle nStyle
)
268 M_BRUSHDATA
->m_nStyle
= nStyle
;
270 } // end of wxBrush::SetStyle
272 void wxBrush::SetStipple(
273 const wxBitmap
& rStipple
277 M_BRUSHDATA
->m_vStipple
= rStipple
;
279 } // end of wxBrush::SetStipple
286 if (M_BRUSHDATA
->m_hBrush
)
287 ::GpiDestroyPS(M_BRUSHDATA
->m_hBrush
);
288 M_BRUSHDATA
->m_hBrush
= hPS
;
290 } // end of WxWinGdi_CPen::SetPS
293 bool wxBrush::operator == (
297 if (m_refData
== brush
.m_refData
) return true;
299 if (!m_refData
|| !brush
.m_refData
) return false;
301 return ( *(wxBrushRefData
*)m_refData
== *(wxBrushRefData
*)brush
.m_refData
);
302 } // end of wxBrush::operator ==
304 wxGDIRefData
*wxBrush::CreateGDIRefData() const
306 return new wxBrushRefData
;
309 wxGDIRefData
*wxBrush::CloneGDIRefData(const wxGDIRefData
*data
) const
311 return new wxBrushRefData(*(const wxBrushRefData
*)data
);