]>
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"
25 #include "wx/os2/private.h"
29 IMPLEMENT_DYNAMIC_CLASS(wxBrush
, wxGDIObject
)
31 wxBrushRefData::wxBrushRefData()
35 memset(&m_vBundle
, '\0', sizeof(AREABUNDLE
));
36 } // end of wxBrushRefData::wxBrushRefData
38 wxBrushRefData::wxBrushRefData(
39 const wxBrushRefData
& rData
42 m_nStyle
= rData
.m_nStyle
;
43 m_vStipple
= rData
.m_vStipple
;
44 m_vColour
= rData
.m_vColour
;
46 memcpy(&m_vBundle
, &rData
.m_vBundle
, sizeof(AREABUNDLE
));
47 } // end of wxBrushRefData::wxBrushRefData
49 wxBrushRefData::~wxBrushRefData()
51 } // end of wxBrushRefData::~wxBrushRefData
59 wxTheBrushList
->AddBrush(this);
60 } // end of wxBrush::wxBrush
65 wxTheBrushList
->RemoveBrush(this);
66 } // end of wxBrush::~wxBrush
69 const wxColour
& rColour
73 m_refData
= new wxBrushRefData
;
75 M_BRUSHDATA
->m_vColour
= rColour
;
76 M_BRUSHDATA
->m_nStyle
= nStyle
;
77 M_BRUSHDATA
->m_hBrush
= 0;
78 memset(&M_BRUSHDATA
->m_vBundle
, '\0', sizeof(AREABUNDLE
));
83 wxTheBrushList
->AddBrush(this);
84 } // end of wxBrush::wxBrush
87 const wxBitmap
& rStipple
90 m_refData
= new wxBrushRefData
;
92 M_BRUSHDATA
->m_nStyle
= wxSTIPPLE
;
93 M_BRUSHDATA
->m_vStipple
= rStipple
;
94 M_BRUSHDATA
->m_hBrush
= 0;
95 memset(&M_BRUSHDATA
->m_vBundle
, '\0', sizeof(AREABUNDLE
));
100 wxTheBrushList
->AddBrush(this);
101 } // end of wxBrush::wxBrush
103 bool wxBrush::RealizeResource()
109 if (M_BRUSHDATA
&& M_BRUSHDATA
->m_hBrush
== 0L)
111 SIZEL vSize
= {0, 0};
112 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
113 HDC hDC
= ::DevOpenDC( vHabmain
120 M_BRUSHDATA
->m_hBrush
= (WXHPEN
)::GpiCreatePS( vHabmain
123 ,PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
129 // Set the color table to RGB mode
131 if (!::GpiCreateLogColorTable( (HPS
)M_BRUSHDATA
->m_hBrush
139 vError
= ::WinGetLastError(vHabmain
);
140 sError
= wxPMErrorToStr(vError
);
141 wxLogError(_T("Unable to set current color table to RGB mode. Error: %s\n"), sError
.c_str());
145 if (M_BRUSHDATA
->m_nStyle
==wxTRANSPARENT
)
149 COLORREF vPmColour
= 0L;
151 vPmColour
= M_BRUSHDATA
->m_vColour
.GetPixel() ;
153 M_BRUSHDATA
->m_vBundle
.usSet
= LCID_DEFAULT
;
154 switch (M_BRUSHDATA
->m_nStyle
)
157 M_BRUSHDATA
->m_hBrush
= NULL
; // Must always select a suitable background brush
158 break; // - could choose white always for a quick solution
160 case wxBDIAGONAL_HATCH
:
161 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_DIAG3
;
164 case wxCROSSDIAG_HATCH
:
165 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_DIAGHATCH
;
168 case wxFDIAGONAL_HATCH
:
169 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_DIAG1
;
173 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_HATCH
;
176 case wxHORIZONTAL_HATCH
:
177 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_HORIZ
;
180 case wxVERTICAL_HATCH
:
181 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_VERT
;
185 if (M_BRUSHDATA
->m_vStipple
.Ok())
187 ::GpiSetBitmapId( M_BRUSHDATA
->m_hBrush
188 ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetHBITMAP()
189 ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetId()
191 ::GpiSetPatternSet( M_BRUSHDATA
->m_hBrush
192 ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetId()
196 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_SOLID
;
201 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_SOLID
;
204 #ifdef WXDEBUG_CREATE
205 if (M_BRUSHDATA
->m_hBrush
==NULL
) wxError("Cannot create brush","Internal error") ;
207 M_BRUSHDATA
->m_vBundle
.lColor
= vPmColour
;
208 M_BRUSHDATA
->m_vBundle
.lBackColor
= RGB_WHITE
;
209 M_BRUSHDATA
->m_vBundle
.usMixMode
= FM_OVERPAINT
;
210 M_BRUSHDATA
->m_vBundle
.usBackMixMode
= BM_OVERPAINT
;
212 bOk
= (bool)::GpiSetAttrs( M_BRUSHDATA
->m_hBrush
214 ,ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
|
217 ,&M_BRUSHDATA
->m_vBundle
221 vError
= ::WinGetLastError(vHabmain
);
222 sError
= wxPMErrorToStr(vError
);
223 wxLogError(_T("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n"), sError
.c_str());
228 } // end of wxBrush::RealizeResource
230 WXHANDLE
wxBrush::GetResourceHandle()
234 return (WXHANDLE
)M_BRUSHDATA
->m_hBrush
;
235 } // end of wxBrush::GetResourceHandle
237 bool wxBrush::FreeResource( bool WXUNUSED(bForce
) )
239 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
!= 0))
241 M_BRUSHDATA
->m_hBrush
= 0;
245 } // end of wxBrush::FreeResource
247 bool wxBrush::IsFree() const
249 return (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0));
250 } // end of wxBrush::IsFree
252 void wxBrush::Unshare()
255 // Don't change shared data
259 m_refData
= new wxBrushRefData();
263 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
267 } // end of wxBrush::Unshare
269 void wxBrush::SetColour( const wxColour
& rColour
)
272 M_BRUSHDATA
->m_vColour
= rColour
;
276 void wxBrush::SetColour(unsigned char cRed
, unsigned char cGreen
, unsigned char cBlue
)
279 M_BRUSHDATA
->m_vColour
.Set( cRed
, cGreen
, cBlue
);
281 } // end of wxBrush::SetColour
283 void wxBrush::SetStyle(int nStyle
)
286 M_BRUSHDATA
->m_nStyle
= nStyle
;
288 } // end of wxBrush::SetStyle
290 void wxBrush::SetStipple(
291 const wxBitmap
& rStipple
295 M_BRUSHDATA
->m_vStipple
= rStipple
;
297 } // end of wxBrush::SetStipple
304 if (M_BRUSHDATA
->m_hBrush
)
305 ::GpiDestroyPS(M_BRUSHDATA
->m_hBrush
);
306 M_BRUSHDATA
->m_hBrush
= hPS
;
308 } // end of WxWinGdi_CPen::SetPS