]>
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 #if !USE_SHARED_LIBRARIES
29 IMPLEMENT_DYNAMIC_CLASS(wxBrush
, wxGDIObject
)
32 wxBrushRefData::wxBrushRefData()
38 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& data
)
40 m_style
= data
.m_style
;
41 m_stipple
= data
.m_stipple
;
42 m_colour
= data
.m_colour
;
46 wxBrushRefData::~wxBrushRefData()
55 wxTheBrushList
->AddBrush(this);
61 wxTheBrushList
->RemoveBrush(this);
64 wxBrush::wxBrush(const wxColour
& col
, int Style
)
66 m_refData
= new wxBrushRefData
;
68 M_BRUSHDATA
->m_colour
= col
;
69 M_BRUSHDATA
->m_style
= Style
;
70 M_BRUSHDATA
->m_hBrush
= 0;
75 wxTheBrushList
->AddBrush(this);
78 wxBrush::wxBrush(const wxBitmap
& stipple
)
80 m_refData
= new wxBrushRefData
;
82 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
83 M_BRUSHDATA
->m_stipple
= stipple
;
84 M_BRUSHDATA
->m_hBrush
= 0;
89 wxTheBrushList
->AddBrush(this);
92 bool wxBrush::RealizeResource(void)
96 if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0))
98 if (M_BRUSHDATA->m_style==wxTRANSPARENT)
100 M_BRUSHDATA->m_hBrush = (WXHBRUSH) ::GetStockObject(NULL_BRUSH);
103 COLORREF ms_colour = 0 ;
105 ms_colour = M_BRUSHDATA->m_colour.GetPixel() ;
107 switch (M_BRUSHDATA->m_style)
110 // Don't reset cbrush, wxTRANSPARENT is handled by wxBrush::SelectBrush()
111 // this could save (many) time if frequently switching from
112 // wxSOLID to wxTRANSPARENT, because Create... is not always called!!
114 // NB August 95: now create and select a Null brush instead.
115 // This could be optimized as above.
117 M_BRUSHDATA->m_hBrush = NULL; // Must always select a suitable background brush
118 // - could choose white always for a quick solution
121 case wxBDIAGONAL_HATCH:
122 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_BDIAGONAL,ms_colour) ;
125 case wxCROSSDIAG_HATCH:
126 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_DIAGCROSS,ms_colour) ;
129 case wxFDIAGONAL_HATCH:
130 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_FDIAGONAL,ms_colour) ;
134 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_CROSS,ms_colour) ;
137 case wxHORIZONTAL_HATCH:
138 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_HORIZONTAL,ms_colour) ;
141 case wxVERTICAL_HATCH:
142 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_VERTICAL,ms_colour) ;
146 if (M_BRUSHDATA->m_stipple.Ok())
147 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreatePatternBrush((HBITMAP) M_BRUSHDATA->m_stipple.GetHBITMAP()) ;
149 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
154 M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
157 #ifdef WXDEBUG_CREATE
158 if (M_BRUSHDATA->m_hBrush==NULL) wxError("Cannot create brush","Internal error") ;
168 WXHANDLE
wxBrush::GetResourceHandle(void)
170 return (WXHANDLE
) M_BRUSHDATA
->m_hBrush
;
173 bool wxBrush::FreeResource(bool WXUNUSED(force
))
175 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
!= 0))
177 // TODO DeleteObject((HBRUSH) M_BRUSHDATA->m_hBrush);
178 M_BRUSHDATA
->m_hBrush
= 0;
184 bool wxBrush::IsFree() const
186 return (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0));
189 void wxBrush::Unshare()
191 // Don't change shared data
194 m_refData
= new wxBrushRefData();
198 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
204 void wxBrush::SetColour(const wxColour
& col
)
208 M_BRUSHDATA
->m_colour
= col
;
213 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
217 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
222 void wxBrush::SetStyle(int Style
)
226 M_BRUSHDATA
->m_style
= Style
;
231 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
235 M_BRUSHDATA
->m_stipple
= Stipple
;