]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
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()
36 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& data
)
38 m_style
= data
.m_style
;
39 m_stipple
= data
.m_stipple
;
40 m_colour
= data
.m_colour
;
44 wxBrushRefData::~wxBrushRefData()
53 wxTheBrushList
->AddBrush(this);
59 wxTheBrushList
->RemoveBrush(this);
62 wxBrush::wxBrush(const wxColour
& col
, int Style
)
64 m_refData
= new wxBrushRefData
;
66 M_BRUSHDATA
->m_colour
= col
;
67 M_BRUSHDATA
->m_style
= Style
;
68 M_BRUSHDATA
->m_hBrush
= 0;
73 wxTheBrushList
->AddBrush(this);
76 wxBrush::wxBrush(const wxBitmap
& stipple
)
78 m_refData
= new wxBrushRefData
;
80 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
81 M_BRUSHDATA
->m_stipple
= stipple
;
82 M_BRUSHDATA
->m_hBrush
= 0;
87 wxTheBrushList
->AddBrush(this);
90 bool wxBrush::RealizeResource(void)
94 if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0))
96 if (M_BRUSHDATA->m_style==wxTRANSPARENT)
98 M_BRUSHDATA->m_hBrush = (WXHBRUSH) ::GetStockObject(NULL_BRUSH);
101 COLORREF ms_colour = 0 ;
103 ms_colour = M_BRUSHDATA->m_colour.GetPixel() ;
105 switch (M_BRUSHDATA->m_style)
108 // Don't reset cbrush, wxTRANSPARENT is handled by wxBrush::SelectBrush()
109 // this could save (many) time if frequently switching from
110 // wxSOLID to wxTRANSPARENT, because Create... is not always called!!
112 // NB August 95: now create and select a Null brush instead.
113 // This could be optimized as above.
115 M_BRUSHDATA->m_hBrush = NULL; // Must always select a suitable background brush
116 // - could choose white always for a quick solution
119 case wxBDIAGONAL_HATCH:
120 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_BDIAGONAL,ms_colour) ;
123 case wxCROSSDIAG_HATCH:
124 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_DIAGCROSS,ms_colour) ;
127 case wxFDIAGONAL_HATCH:
128 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_FDIAGONAL,ms_colour) ;
132 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_CROSS,ms_colour) ;
135 case wxHORIZONTAL_HATCH:
136 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_HORIZONTAL,ms_colour) ;
139 case wxVERTICAL_HATCH:
140 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_VERTICAL,ms_colour) ;
144 if (M_BRUSHDATA->m_stipple.Ok())
145 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreatePatternBrush((HBITMAP) M_BRUSHDATA->m_stipple.GetHBITMAP()) ;
147 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
152 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
155 #ifdef WXDEBUG_CREATE
156 if (M_BRUSHDATA->m_hBrush==NULL) wxError("Cannot create brush","Internal error") ;
166 WXHANDLE
wxBrush::GetResourceHandle(void)
168 return (WXHANDLE
) M_BRUSHDATA
->m_hBrush
;
171 bool wxBrush::FreeResource(bool WXUNUSED(force
))
173 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
!= 0))
175 // TODO DeleteObject((HBRUSH) M_BRUSHDATA->m_hBrush);
176 M_BRUSHDATA
->m_hBrush
= 0;
182 bool wxBrush::IsFree() const
184 return (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0));
187 void wxBrush::Unshare()
189 // Don't change shared data
192 m_refData
= new wxBrushRefData();
196 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
202 void wxBrush::SetColour(const wxColour
& col
)
206 M_BRUSHDATA
->m_colour
= col
;
211 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
215 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
220 void wxBrush::SetStyle(int Style
)
224 M_BRUSHDATA
->m_style
= Style
;
229 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
233 M_BRUSHDATA
->m_stipple
= Stipple
;