]>
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 wxBrush::wxBrush(const wxBitmap
& rStipple
)
78 m_refData
= new wxBrushRefData
;
80 M_BRUSHDATA
->m_nStyle
= wxSTIPPLE
;
81 M_BRUSHDATA
->m_vStipple
= rStipple
;
82 M_BRUSHDATA
->m_hBrush
= 0;
83 memset(&M_BRUSHDATA
->m_vBundle
, '\0', sizeof(AREABUNDLE
));
86 } // end of wxBrush::wxBrush
88 bool wxBrush::RealizeResource()
94 if (M_BRUSHDATA
&& M_BRUSHDATA
->m_hBrush
== 0L)
97 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
98 HDC hDC
= ::DevOpenDC( vHabmain
105 M_BRUSHDATA
->m_hBrush
= (WXHPEN
)::GpiCreatePS( vHabmain
108 ,PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
114 // Set the color table to RGB mode
116 if (!::GpiCreateLogColorTable( (HPS
)M_BRUSHDATA
->m_hBrush
124 vError
= ::WinGetLastError(vHabmain
);
125 sError
= wxPMErrorToStr(vError
);
126 wxLogError(_T("Unable to set current color table to RGB mode. Error: %s\n"), sError
.c_str());
130 if (M_BRUSHDATA
->m_nStyle
==wxTRANSPARENT
)
134 COLORREF vPmColour
= 0L;
136 vPmColour
= M_BRUSHDATA
->m_vColour
.GetPixel() ;
138 M_BRUSHDATA
->m_vBundle
.usSet
= LCID_DEFAULT
;
139 switch (M_BRUSHDATA
->m_nStyle
)
142 M_BRUSHDATA
->m_hBrush
= NULL
; // Must always select a suitable background brush
143 break; // - could choose white always for a quick solution
145 case wxBDIAGONAL_HATCH
:
146 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_DIAG3
;
149 case wxCROSSDIAG_HATCH
:
150 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_DIAGHATCH
;
153 case wxFDIAGONAL_HATCH
:
154 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_DIAG1
;
158 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_HATCH
;
161 case wxHORIZONTAL_HATCH
:
162 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_HORIZ
;
165 case wxVERTICAL_HATCH
:
166 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_VERT
;
170 if (M_BRUSHDATA
->m_vStipple
.Ok())
172 ::GpiSetBitmapId( M_BRUSHDATA
->m_hBrush
173 ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetHBITMAP()
174 ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetId()
176 ::GpiSetPatternSet( M_BRUSHDATA
->m_hBrush
177 ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetId()
181 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_SOLID
;
186 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_SOLID
;
189 #ifdef WXDEBUG_CREATE
190 if (M_BRUSHDATA
->m_hBrush
==NULL
) wxError("Cannot create brush","Internal error") ;
192 M_BRUSHDATA
->m_vBundle
.lColor
= vPmColour
;
193 M_BRUSHDATA
->m_vBundle
.lBackColor
= RGB_WHITE
;
194 M_BRUSHDATA
->m_vBundle
.usMixMode
= FM_OVERPAINT
;
195 M_BRUSHDATA
->m_vBundle
.usBackMixMode
= BM_OVERPAINT
;
197 bOk
= (bool)::GpiSetAttrs( M_BRUSHDATA
->m_hBrush
199 ,ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
|
200 ABB_SET
| ABB_SYMBOL
| ABB_REF_POINT
201 ,ABB_SET
| ABB_SYMBOL
| ABB_REF_POINT
202 ,&M_BRUSHDATA
->m_vBundle
206 vError
= ::WinGetLastError(vHabmain
);
207 sError
= wxPMErrorToStr(vError
);
208 wxLogError(_T("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n"), sError
.c_str());
213 } // end of wxBrush::RealizeResource
215 WXHANDLE
wxBrush::GetResourceHandle() const
219 return (WXHANDLE
)M_BRUSHDATA
->m_hBrush
;
220 } // end of wxBrush::GetResourceHandle
222 bool wxBrush::FreeResource( bool WXUNUSED(bForce
) )
224 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
!= 0))
226 M_BRUSHDATA
->m_hBrush
= 0;
230 } // end of wxBrush::FreeResource
232 bool wxBrush::IsFree() const
234 return (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0));
235 } // end of wxBrush::IsFree
237 void wxBrush::SetColour( const wxColour
& rColour
)
240 M_BRUSHDATA
->m_vColour
= rColour
;
244 void wxBrush::SetColour(unsigned char cRed
, unsigned char cGreen
, unsigned char cBlue
)
247 M_BRUSHDATA
->m_vColour
.Set( cRed
, cGreen
, cBlue
);
249 } // end of wxBrush::SetColour
251 void wxBrush::SetStyle(int nStyle
)
254 M_BRUSHDATA
->m_nStyle
= nStyle
;
256 } // end of wxBrush::SetStyle
258 void wxBrush::SetStipple(
259 const wxBitmap
& rStipple
263 M_BRUSHDATA
->m_vStipple
= rStipple
;
265 } // end of wxBrush::SetStipple
272 if (M_BRUSHDATA
->m_hBrush
)
273 ::GpiDestroyPS(M_BRUSHDATA
->m_hBrush
);
274 M_BRUSHDATA
->m_hBrush
= hPS
;
276 } // end of WxWinGdi_CPen::SetPS
279 bool wxBrush::operator == (
283 if (m_refData
== brush
.m_refData
) return true;
285 if (!m_refData
|| !brush
.m_refData
) return false;
287 return ( *(wxBrushRefData
*)m_refData
== *(wxBrushRefData
*)brush
.m_refData
);
288 } // end of wxBrush::operator ==
290 wxGDIRefData
*wxBrush::CreateGDIRefData() const
292 return new wxBrushRefData
;
295 wxGDIRefData
*wxBrush::CloneGDIRefData(const wxGDIRefData
*data
) const
297 return new wxBrushRefData(*(const wxBrushRefData
*)data
);