]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "brush.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
32 #include "wx/msw/private.h"
36 #if !USE_SHARED_LIBRARIES
37 IMPLEMENT_DYNAMIC_CLASS(wxBrush
, wxGDIObject
)
40 wxBrushRefData::wxBrushRefData(void)
47 wxBrushRefData::~wxBrushRefData(void)
50 ::DeleteObject((HBRUSH
) m_hBrush
);
54 wxBrush::wxBrush(void)
57 wxTheBrushList
->AddBrush(this);
63 wxTheBrushList
->RemoveBrush(this);
66 wxBrush::wxBrush(const wxColour
& col
, const int Style
)
68 m_refData
= new wxBrushRefData
;
70 M_BRUSHDATA
->m_colour
= col
;
71 M_BRUSHDATA
->m_style
= Style
;
72 M_BRUSHDATA
->m_hBrush
= 0;
77 wxTheBrushList
->AddBrush(this);
80 wxBrush::wxBrush(const wxString
& col
, const int Style
)
82 m_refData
= new wxBrushRefData
;
84 M_BRUSHDATA
->m_colour
= col
;
85 M_BRUSHDATA
->m_style
= Style
;
86 M_BRUSHDATA
->m_hBrush
= 0;
91 wxTheBrushList
->AddBrush(this);
94 wxBrush::wxBrush(const wxBitmap
& stipple
)
96 m_refData
= new wxBrushRefData
;
98 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
99 M_BRUSHDATA
->m_stipple
= stipple
;
100 M_BRUSHDATA
->m_hBrush
= 0;
104 if ( wxTheBrushList
)
105 wxTheBrushList
->AddBrush(this);
108 bool wxBrush::RealizeResource(void)
110 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0))
112 if (M_BRUSHDATA
->m_style
==wxTRANSPARENT
)
114 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) ::GetStockObject(NULL_BRUSH
);
117 COLORREF ms_colour
= 0 ;
119 ms_colour
= M_BRUSHDATA
->m_colour
.GetPixel() ;
121 switch (M_BRUSHDATA
->m_style
)
124 // Don't reset cbrush, wxTRANSPARENT is handled by wxBrush::SelectBrush()
125 // this could save (many) time if frequently switching from
126 // wxSOLID to wxTRANSPARENT, because Create... is not always called!!
128 // NB August 95: now create and select a Null brush instead.
129 // This could be optimized as above.
131 M_BRUSHDATA->m_hBrush = NULL; // Must always select a suitable background brush
132 // - could choose white always for a quick solution
135 case wxBDIAGONAL_HATCH
:
136 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_BDIAGONAL
,ms_colour
) ;
138 case wxCROSSDIAG_HATCH
:
139 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_DIAGCROSS
,ms_colour
) ;
141 case wxFDIAGONAL_HATCH
:
142 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_FDIAGONAL
,ms_colour
) ;
145 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_CROSS
,ms_colour
) ;
147 case wxHORIZONTAL_HATCH
:
148 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_HORIZONTAL
,ms_colour
) ;
150 case wxVERTICAL_HATCH
:
151 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_VERTICAL
,ms_colour
) ;
154 if (M_BRUSHDATA
->m_stipple
.Ok())
155 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreatePatternBrush((HBITMAP
) M_BRUSHDATA
->m_stipple
.GetHBITMAP()) ;
157 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateSolidBrush(ms_colour
) ;
161 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateSolidBrush(ms_colour
) ;
165 if (M_BRUSHDATA
->m_hBrush
==NULL
) wxError("Cannot create brush","Internal error") ;
173 WXHANDLE
wxBrush::GetResourceHandle(void)
175 return (WXHANDLE
) M_BRUSHDATA
->m_hBrush
;
178 bool wxBrush::FreeResource(bool force
)
180 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
!= 0))
182 DeleteObject((HBRUSH
) M_BRUSHDATA
->m_hBrush
);
183 M_BRUSHDATA
->m_hBrush
= 0;
190 bool wxBrush::UseResource(void)
192 IncrementResourceUsage();
196 bool wxBrush::ReleaseResource(void)
198 DecrementResourceUsage();
203 bool wxBrush::IsFree(void)
205 return (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0));
208 void wxBrush::SetColour(const wxColour
& col
)
211 m_refData
= new wxBrushRefData
;
213 M_BRUSHDATA
->m_colour
= col
;
219 void wxBrush::SetColour(const wxString
& col
)
222 m_refData
= new wxBrushRefData
;
224 M_BRUSHDATA
->m_colour
= col
;
230 void wxBrush::SetColour(const unsigned char r
, const unsigned char g
, const unsigned char b
)
233 m_refData
= new wxBrushRefData
;
235 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
241 void wxBrush::SetStyle(const int Style
)
244 m_refData
= new wxBrushRefData
;
246 M_BRUSHDATA
->m_style
= Style
;
252 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
255 m_refData
= new wxBrushRefData
;
257 M_BRUSHDATA
->m_stipple
= Stipple
;