1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/brush.cpp
4 // Author: David Webster
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
23 #include "wx/os2/private.h"
25 class WXDLLEXPORT wxBrushRefData
: public wxGDIRefData
27 friend class WXDLLIMPEXP_FWD_CORE wxBrush
;
29 wxBrushRefData(const wxColour
& colour
= wxNullColour
, wxBrushStyle style
= wxBRUSHSTYLE_SOLID
);
30 wxBrushRefData(const wxBitmap
& stipple
);
31 wxBrushRefData(const wxBrushRefData
& rData
);
32 virtual ~wxBrushRefData();
34 bool operator == (const wxBrushRefData
& data
) const
36 return (m_nStyle
== data
.m_nStyle
&&
37 m_vStipple
.IsSameAs(data
.m_vStipple
) &&
38 m_vColour
== data
.m_vColour
);
42 wxBrushStyle m_nStyle
;
45 WXHBRUSH m_hBrush
; // in OS/2 GPI this will be the PS the pen is associated with
49 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
51 // ============================================================================
52 // wxBrushRefData implementation
53 // ============================================================================
55 IMPLEMENT_DYNAMIC_CLASS(wxBrush
, wxGDIObject
)
57 // ----------------------------------------------------------------------------
58 // wxBrushRefData ctors/dtor
59 // ----------------------------------------------------------------------------
61 wxBrushRefData::wxBrushRefData(const wxColour
& colour
, wxBrushStyle style
)
66 memset(&m_vBundle
, '\0', sizeof(AREABUNDLE
));
67 } // end of wxBrushRefData::wxBrushRefData
69 wxBrushRefData::wxBrushRefData(const wxBitmap
& stipple
)
72 m_nStyle
= stipple
.GetMask() ? wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
73 : wxBRUSHSTYLE_STIPPLE
;
76 memset(&m_vBundle
, '\0', sizeof(AREABUNDLE
));
79 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& rData
)
81 m_vStipple(rData
.m_vStipple
),
82 m_vColour(rData
.m_vColour
)
84 m_nStyle
= rData
.m_nStyle
;
86 memcpy(&m_vBundle
, &rData
.m_vBundle
, sizeof(AREABUNDLE
));
87 } // end of wxBrushRefData::wxBrushRefData
89 wxBrushRefData::~wxBrushRefData()
91 } // end of wxBrushRefData::~wxBrushRefData
93 // ============================================================================
94 // wxBrush implementation
95 // ============================================================================
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
103 } // end of wxBrush::wxBrush
107 } // end of wxBrush::~wxBrush
110 const wxColour
& rColour
111 , wxBrushStyle nStyle
114 m_refData
= new wxBrushRefData(rColour
, nStyle
);
117 } // end of wxBrush::wxBrush
119 #if FUTURE_WXWIN_COMPATIBILITY_3_0
120 wxBrush::wxBrush(const wxColour
& col
, int style
)
122 m_refData
= new wxBrushRefData(col
, (wxBrushStyle
)style
);
128 wxBrush::wxBrush(const wxBitmap
& rStipple
)
130 m_refData
= new wxBrushRefData(rStipple
);
133 } // end of wxBrush::wxBrush
135 bool wxBrush::RealizeResource()
141 if (M_BRUSHDATA
&& M_BRUSHDATA
->m_hBrush
== 0L)
143 SIZEL vSize
= {0, 0};
144 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
145 HDC hDC
= ::DevOpenDC( vHabmain
152 M_BRUSHDATA
->m_hBrush
= (WXHPEN
)::GpiCreatePS( vHabmain
155 ,PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
161 // Set the color table to RGB mode
163 if (!::GpiCreateLogColorTable( (HPS
)M_BRUSHDATA
->m_hBrush
171 vError
= ::WinGetLastError(vHabmain
);
172 sError
= wxPMErrorToStr(vError
);
173 wxLogError(wxT("Unable to set current color table to RGB mode. Error: %s\n"), sError
.c_str());
177 if (M_BRUSHDATA
->m_nStyle
==wxTRANSPARENT
)
181 COLORREF vPmColour
= 0L;
183 vPmColour
= M_BRUSHDATA
->m_vColour
.GetPixel() ;
185 M_BRUSHDATA
->m_vBundle
.usSet
= LCID_DEFAULT
;
186 switch (M_BRUSHDATA
->m_nStyle
)
189 M_BRUSHDATA
->m_hBrush
= NULL
; // Must always select a suitable background brush
190 break; // - could choose white always for a quick solution
192 case wxBDIAGONAL_HATCH
:
193 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_DIAG3
;
196 case wxCROSSDIAG_HATCH
:
197 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_DIAGHATCH
;
200 case wxFDIAGONAL_HATCH
:
201 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_DIAG1
;
205 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_HATCH
;
208 case wxHORIZONTAL_HATCH
:
209 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_HORIZ
;
212 case wxVERTICAL_HATCH
:
213 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_VERT
;
217 if (M_BRUSHDATA
->m_vStipple
.IsOk())
219 ::GpiSetBitmapId( M_BRUSHDATA
->m_hBrush
220 ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetHBITMAP()
221 ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetId()
223 ::GpiSetPatternSet( M_BRUSHDATA
->m_hBrush
224 ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetId()
228 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_SOLID
;
233 M_BRUSHDATA
->m_vBundle
.usSymbol
= PATSYM_SOLID
;
236 #ifdef WXDEBUG_CREATE
237 if (M_BRUSHDATA
->m_hBrush
==NULL
) wxError("Cannot create brush","Internal error") ;
239 M_BRUSHDATA
->m_vBundle
.lColor
= vPmColour
;
240 M_BRUSHDATA
->m_vBundle
.lBackColor
= RGB_WHITE
;
241 M_BRUSHDATA
->m_vBundle
.usMixMode
= FM_OVERPAINT
;
242 M_BRUSHDATA
->m_vBundle
.usBackMixMode
= BM_OVERPAINT
;
244 bOk
= (bool)::GpiSetAttrs( M_BRUSHDATA
->m_hBrush
246 ,ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
|
247 ABB_SET
| ABB_SYMBOL
| ABB_REF_POINT
248 ,ABB_SET
| ABB_SYMBOL
| ABB_REF_POINT
249 ,&M_BRUSHDATA
->m_vBundle
253 vError
= ::WinGetLastError(vHabmain
);
254 sError
= wxPMErrorToStr(vError
);
255 wxLogError(wxT("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n"), sError
.c_str());
260 } // end of wxBrush::RealizeResource
262 // ----------------------------------------------------------------------------
264 // ----------------------------------------------------------------------------
266 wxColour
wxBrush::GetColour() const
268 wxCHECK_MSG( IsOk(), wxNullColour
, wxT("invalid brush") );
270 return M_BRUSHDATA
->m_vColour
;
273 wxBrushStyle
wxBrush::GetStyle() const
275 wxCHECK_MSG( IsOk(), wxBRUSHSTYLE_INVALID
, wxT("invalid brush") );
277 return M_BRUSHDATA
->m_nStyle
;
280 wxBitmap
*wxBrush::GetStipple() const
282 wxCHECK_MSG( IsOk(), NULL
, wxT("invalid brush") );
284 return &(M_BRUSHDATA
->m_vStipple
);
287 int wxBrush::GetPS() const
289 wxCHECK_MSG( IsOk(), 0, wxT("invalid brush") );
291 return M_BRUSHDATA
->m_hBrush
;
294 WXHANDLE
wxBrush::GetResourceHandle() const
296 wxCHECK_MSG( IsOk(), 0, wxT("invalid brush") );
298 return (WXHANDLE
)M_BRUSHDATA
->m_hBrush
;
299 } // end of wxBrush::GetResourceHandle
301 bool wxBrush::FreeResource( bool WXUNUSED(bForce
) )
303 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
!= 0))
305 M_BRUSHDATA
->m_hBrush
= 0;
309 } // end of wxBrush::FreeResource
311 bool wxBrush::IsFree() const
313 return (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0));
314 } // end of wxBrush::IsFree
316 // ----------------------------------------------------------------------------
318 // ----------------------------------------------------------------------------
320 void wxBrush::SetColour( const wxColour
& rColour
)
323 M_BRUSHDATA
->m_vColour
= rColour
;
327 void wxBrush::SetColour(unsigned char cRed
, unsigned char cGreen
, unsigned char cBlue
)
330 M_BRUSHDATA
->m_vColour
.Set( cRed
, cGreen
, cBlue
);
332 } // end of wxBrush::SetColour
334 void wxBrush::SetStyle(wxBrushStyle nStyle
)
337 M_BRUSHDATA
->m_nStyle
= nStyle
;
339 } // end of wxBrush::SetStyle
341 void wxBrush::SetStipple(
342 const wxBitmap
& rStipple
346 M_BRUSHDATA
->m_vStipple
= rStipple
;
348 } // end of wxBrush::SetStipple
355 if (M_BRUSHDATA
->m_hBrush
)
356 ::GpiDestroyPS(M_BRUSHDATA
->m_hBrush
);
357 M_BRUSHDATA
->m_hBrush
= hPS
;
359 } // end of WxWinGdi_CPen::SetPS
361 // ----------------------------------------------------------------------------
362 // wxBrush house keeping stuff
363 // ----------------------------------------------------------------------------
365 bool wxBrush::operator == (
369 if (m_refData
== brush
.m_refData
) return true;
371 if (!m_refData
|| !brush
.m_refData
) return false;
373 return ( *(wxBrushRefData
*)m_refData
== *(wxBrushRefData
*)brush
.m_refData
);
374 } // end of wxBrush::operator ==
376 wxGDIRefData
*wxBrush::CreateGDIRefData() const
378 return new wxBrushRefData
;
381 wxGDIRefData
*wxBrush::CloneGDIRefData(const wxGDIRefData
*data
) const
383 return new wxBrushRefData(*(const wxBrushRefData
*)data
);