]>
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 #ifndef __WXMICROWIN__
131 case wxBDIAGONAL_HATCH
:
132 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_BDIAGONAL
,ms_colour
) ;
134 case wxCROSSDIAG_HATCH
:
135 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_DIAGCROSS
,ms_colour
) ;
137 case wxFDIAGONAL_HATCH
:
138 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_FDIAGONAL
,ms_colour
) ;
141 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_CROSS
,ms_colour
) ;
143 case wxHORIZONTAL_HATCH
:
144 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_HORIZONTAL
,ms_colour
) ;
146 case wxVERTICAL_HATCH
:
147 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_VERTICAL
,ms_colour
) ;
150 if (M_BRUSHDATA
->m_stipple
.Ok())
151 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreatePatternBrush((HBITMAP
) M_BRUSHDATA
->m_stipple
.GetHBITMAP()) ;
153 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateSolidBrush(ms_colour
) ;
155 case wxSTIPPLE_MASK_OPAQUE
:
156 if (M_BRUSHDATA
->m_stipple
.Ok() && M_BRUSHDATA
->m_stipple
.GetMask())
157 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreatePatternBrush((HBITMAP
) M_BRUSHDATA
->m_stipple
.GetMask()->GetMaskBitmap());
159 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateSolidBrush(ms_colour
) ;
164 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateSolidBrush(ms_colour
) ;
167 #ifdef WXDEBUG_CREATE
168 if (M_BRUSHDATA
->m_hBrush
==NULL
) wxError("Cannot create brush","Internal error") ;
176 WXHANDLE
wxBrush::GetResourceHandle(void)
178 return (WXHANDLE
) M_BRUSHDATA
->m_hBrush
;
181 bool wxBrush::FreeResource(bool WXUNUSED(force
))
183 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
!= 0))
185 DeleteObject((HBRUSH
) M_BRUSHDATA
->m_hBrush
);
186 M_BRUSHDATA
->m_hBrush
= 0;
192 bool wxBrush::IsFree() const
194 return (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0));
197 void wxBrush::Unshare()
199 // Don't change shared data
202 m_refData
= new wxBrushRefData();
206 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
213 void wxBrush::SetColour(const wxColour
& col
)
217 M_BRUSHDATA
->m_colour
= col
;
222 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
226 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
231 void wxBrush::SetStyle(int Style
)
235 M_BRUSHDATA
->m_style
= Style
;
240 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
244 M_BRUSHDATA
->m_stipple
= Stipple
;
245 if (M_BRUSHDATA
->m_stipple
.GetMask())
246 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
248 M_BRUSHDATA
->m_style
= wxSTIPPLE
;