]>
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 IMPLEMENT_DYNAMIC_CLASS(wxBrush
, wxGDIObject
)
38 wxBrushRefData::wxBrushRefData(void)
44 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& data
)
46 m_style
= data
.m_style
;
47 m_stipple
= data
.m_stipple
;
48 m_colour
= data
.m_colour
;
52 wxBrushRefData::~wxBrushRefData(void)
55 ::DeleteObject((HBRUSH
) m_hBrush
);
59 wxBrush::wxBrush(void)
62 wxTheBrushList
->AddBrush(this);
68 wxTheBrushList
->RemoveBrush(this);
71 wxBrush::wxBrush(const wxColour
& col
, int Style
)
73 m_refData
= new wxBrushRefData
;
75 M_BRUSHDATA
->m_colour
= col
;
76 M_BRUSHDATA
->m_style
= Style
;
77 M_BRUSHDATA
->m_hBrush
= 0;
82 wxTheBrushList
->AddBrush(this);
85 wxBrush::wxBrush(const wxBitmap
& stipple
)
87 m_refData
= new wxBrushRefData
;
89 M_BRUSHDATA
->m_stipple
= stipple
;
90 if (M_BRUSHDATA
->m_stipple
.GetMask())
91 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
93 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
95 M_BRUSHDATA
->m_hBrush
= 0;
100 wxTheBrushList
->AddBrush(this);
103 bool wxBrush::RealizeResource(void)
105 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0))
107 if (M_BRUSHDATA
->m_style
==wxTRANSPARENT
)
109 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) ::GetStockObject(NULL_BRUSH
);
112 COLORREF ms_colour
= 0 ;
114 ms_colour
= M_BRUSHDATA
->m_colour
.GetPixel() ;
116 switch (M_BRUSHDATA
->m_style
)
119 // Don't reset cbrush, wxTRANSPARENT is handled by wxBrush::SelectBrush()
120 // this could save (many) time if frequently switching from
121 // wxSOLID to wxTRANSPARENT, because Create... is not always called!!
123 // NB August 95: now create and select a Null brush instead.
124 // This could be optimized as above.
126 M_BRUSHDATA->m_hBrush = NULL; // Must always select a suitable background brush
127 // - could choose white always for a quick solution
130 case wxBDIAGONAL_HATCH
:
131 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_BDIAGONAL
,ms_colour
) ;
133 case wxCROSSDIAG_HATCH
:
134 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_DIAGCROSS
,ms_colour
) ;
136 case wxFDIAGONAL_HATCH
:
137 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_FDIAGONAL
,ms_colour
) ;
140 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_CROSS
,ms_colour
) ;
142 case wxHORIZONTAL_HATCH
:
143 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_HORIZONTAL
,ms_colour
) ;
145 case wxVERTICAL_HATCH
:
146 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_VERTICAL
,ms_colour
) ;
149 if (M_BRUSHDATA
->m_stipple
.Ok())
150 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreatePatternBrush((HBITMAP
) M_BRUSHDATA
->m_stipple
.GetHBITMAP()) ;
152 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateSolidBrush(ms_colour
) ;
154 case wxSTIPPLE_MASK_OPAQUE
:
155 if (M_BRUSHDATA
->m_stipple
.Ok() && M_BRUSHDATA
->m_stipple
.GetMask())
156 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreatePatternBrush((HBITMAP
) M_BRUSHDATA
->m_stipple
.GetMask()->GetMaskBitmap());
158 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateSolidBrush(ms_colour
) ;
162 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateSolidBrush(ms_colour
) ;
165 #ifdef WXDEBUG_CREATE
166 if (M_BRUSHDATA
->m_hBrush
==NULL
) wxError("Cannot create brush","Internal error") ;
174 WXHANDLE
wxBrush::GetResourceHandle(void)
176 return (WXHANDLE
) M_BRUSHDATA
->m_hBrush
;
179 bool wxBrush::FreeResource(bool WXUNUSED(force
))
181 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
!= 0))
183 DeleteObject((HBRUSH
) M_BRUSHDATA
->m_hBrush
);
184 M_BRUSHDATA
->m_hBrush
= 0;
190 bool wxBrush::IsFree() const
192 return (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0));
195 void wxBrush::Unshare()
197 // Don't change shared data
200 m_refData
= new wxBrushRefData();
204 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
211 void wxBrush::SetColour(const wxColour
& col
)
215 M_BRUSHDATA
->m_colour
= col
;
220 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
224 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
229 void wxBrush::SetStyle(int Style
)
233 M_BRUSHDATA
->m_style
= Style
;
238 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
242 M_BRUSHDATA
->m_stipple
= Stipple
;
243 if (M_BRUSHDATA
->m_stipple
.GetMask())
244 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
246 M_BRUSHDATA
->m_style
= wxSTIPPLE
;