]>
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(
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
57 } // end of wxBrush::wxBrush
61 } // end of wxBrush::~wxBrush
64 const wxColour
& rColour
68 m_refData
= new wxBrushRefData
;
70 M_BRUSHDATA
->m_vColour
= rColour
;
71 M_BRUSHDATA
->m_nStyle
= nStyle
;
72 M_BRUSHDATA
->m_hBrush
= 0;
73 memset(&M_BRUSHDATA
->m_vBundle
, '\0', sizeof(AREABUNDLE
));
76 } // end of wxBrush::wxBrush
79 const wxBitmap
& rStipple
82 m_refData
= new wxBrushRefData
;
84 M_BRUSHDATA
->m_nStyle
= wxSTIPPLE
;
85 M_BRUSHDATA
->m_vStipple
= rStipple
;
86 M_BRUSHDATA
->m_hBrush
= 0;
87 memset(&M_BRUSHDATA
->m_vBundle
, '\0', sizeof(AREABUNDLE
));
90 } // end of wxBrush::wxBrush
92 bool wxBrush::RealizeResource()
98 if (M_BRUSHDATA
&& M_BRUSHDATA
->m_hBrush
== 0L)
100 SIZEL vSize
= {0, 0};
101 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
102 HDC hDC
= ::DevOpenDC( vHabmain
109 M_BRUSHDATA
->m_hBrush
= (WXHPEN
)::GpiCreatePS( vHabmain
112 ,PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
118 // Set the color table to RGB mode
120 if (!::GpiCreateLogColorTable( (HPS
)M_BRUSHDATA
->m_hBrush
128 vError
= ::WinGetLastError(vHabmain
);
129 sError
= wxPMErrorToStr(vError
);
130 wxLogError(_T("Unable to set current color table to RGB mode. Error: %s\n"), sError
.c_str());
134 if (M_BRUSHDATA
->m_nStyle
==wxTRANSPARENT
)
138 COLORREF vPmColour
= 0L;
140 vPmColour
= M_BRUSHDATA
->m_vColour
.GetPixel() ;
142 M_BRUSHDATA
->m_vBundle
.usSet
= LCID_DEFAULT
;
143 switch (M_BRUSHDATA
->m_nStyle
)
146 M_BRUSHDATA
->m_hBrush
= NULL
; // Must always select a suitable background brush
147 break; // - could choose white always for a quick solution
149 case wxBDIAGONAL_HATCH
:
150 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_DIAG3
;
153 case wxCROSSDIAG_HATCH
:
154 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_DIAGHATCH
;
157 case wxFDIAGONAL_HATCH
:
158 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_DIAG1
;
162 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_HATCH
;
165 case wxHORIZONTAL_HATCH
:
166 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_HORIZ
;
169 case wxVERTICAL_HATCH
:
170 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_VERT
;
174 if (M_BRUSHDATA
->m_vStipple
.Ok())
176 ::GpiSetBitmapId( M_BRUSHDATA
->m_hBrush
177 ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetHBITMAP()
178 ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetId()
180 ::GpiSetPatternSet( M_BRUSHDATA
->m_hBrush
181 ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetId()
185 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_SOLID
;
190 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_SOLID
;
193 #ifdef WXDEBUG_CREATE
194 if (M_BRUSHDATA
->m_hBrush
==NULL
) wxError("Cannot create brush","Internal error") ;
196 M_BRUSHDATA
->m_vBundle
.lColor
= vPmColour
;
197 M_BRUSHDATA
->m_vBundle
.lBackColor
= RGB_WHITE
;
198 M_BRUSHDATA
->m_vBundle
.usMixMode
= FM_OVERPAINT
;
199 M_BRUSHDATA
->m_vBundle
.usBackMixMode
= BM_OVERPAINT
;
201 bOk
= (bool)::GpiSetAttrs( M_BRUSHDATA
->m_hBrush
203 ,ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
|
206 ,&M_BRUSHDATA
->m_vBundle
210 vError
= ::WinGetLastError(vHabmain
);
211 sError
= wxPMErrorToStr(vError
);
212 wxLogError(_T("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n"), sError
.c_str());
217 } // end of wxBrush::RealizeResource
219 WXHANDLE
wxBrush::GetResourceHandle()
223 return (WXHANDLE
)M_BRUSHDATA
->m_hBrush
;
224 } // end of wxBrush::GetResourceHandle
226 bool wxBrush::FreeResource( bool WXUNUSED(bForce
) )
228 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
!= 0))
230 M_BRUSHDATA
->m_hBrush
= 0;
234 } // end of wxBrush::FreeResource
236 bool wxBrush::IsFree() const
238 return (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0));
239 } // end of wxBrush::IsFree
241 void wxBrush::Unshare()
244 // Don't change shared data
248 m_refData
= new wxBrushRefData();
252 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
256 } // end of wxBrush::Unshare
258 void wxBrush::SetColour( const wxColour
& rColour
)
261 M_BRUSHDATA
->m_vColour
= rColour
;
265 void wxBrush::SetColour(unsigned char cRed
, unsigned char cGreen
, unsigned char cBlue
)
268 M_BRUSHDATA
->m_vColour
.Set( cRed
, cGreen
, cBlue
);
270 } // end of wxBrush::SetColour
272 void wxBrush::SetStyle(int nStyle
)
275 M_BRUSHDATA
->m_nStyle
= nStyle
;
277 } // end of wxBrush::SetStyle
279 void wxBrush::SetStipple(
280 const wxBitmap
& rStipple
284 M_BRUSHDATA
->m_vStipple
= rStipple
;
286 } // end of wxBrush::SetStipple
293 if (M_BRUSHDATA
->m_hBrush
)
294 ::GpiDestroyPS(M_BRUSHDATA
->m_hBrush
);
295 M_BRUSHDATA
->m_hBrush
= hPS
;
297 } // end of WxWinGdi_CPen::SetPS