]>
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)
67 wxBrush::wxBrush(const wxColour
& col
, int Style
)
69 m_refData
= new wxBrushRefData
;
71 M_BRUSHDATA
->m_colour
= col
;
72 M_BRUSHDATA
->m_style
= Style
;
73 M_BRUSHDATA
->m_hBrush
= 0;
79 wxBrush::wxBrush(const wxBitmap
& stipple
)
81 m_refData
= new wxBrushRefData
;
83 M_BRUSHDATA
->m_stipple
= stipple
;
84 if (M_BRUSHDATA
->m_stipple
.GetMask())
85 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
87 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
89 M_BRUSHDATA
->m_hBrush
= 0;
95 bool wxBrush::RealizeResource(void)
97 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0))
99 if (M_BRUSHDATA
->m_style
==wxTRANSPARENT
)
101 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) ::GetStockObject(NULL_BRUSH
);
104 COLORREF ms_colour
= 0 ;
106 ms_colour
= M_BRUSHDATA
->m_colour
.GetPixel() ;
108 switch (M_BRUSHDATA
->m_style
)
111 // Don't reset cbrush, wxTRANSPARENT is handled by wxBrush::SelectBrush()
112 // this could save (many) time if frequently switching from
113 // wxSOLID to wxTRANSPARENT, because Create... is not always called!!
115 // NB August 95: now create and select a Null brush instead.
116 // This could be optimized as above.
118 M_BRUSHDATA->m_hBrush = NULL; // Must always select a suitable background brush
119 // - could choose white always for a quick solution
122 #ifndef __WXMICROWIN__
123 case wxBDIAGONAL_HATCH
:
124 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_BDIAGONAL
,ms_colour
) ;
126 case wxCROSSDIAG_HATCH
:
127 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
) ;
133 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
) ;
138 case wxVERTICAL_HATCH
:
139 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_VERTICAL
,ms_colour
) ;
142 if (M_BRUSHDATA
->m_stipple
.Ok())
143 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreatePatternBrush((HBITMAP
) M_BRUSHDATA
->m_stipple
.GetHBITMAP()) ;
145 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateSolidBrush(ms_colour
) ;
147 case wxSTIPPLE_MASK_OPAQUE
:
148 if (M_BRUSHDATA
->m_stipple
.Ok() && M_BRUSHDATA
->m_stipple
.GetMask())
149 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreatePatternBrush((HBITMAP
) M_BRUSHDATA
->m_stipple
.GetMask()->GetMaskBitmap());
151 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateSolidBrush(ms_colour
) ;
156 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateSolidBrush(ms_colour
) ;
159 #ifdef WXDEBUG_CREATE
160 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 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
);
205 void wxBrush::SetColour(const wxColour
& col
)
209 M_BRUSHDATA
->m_colour
= col
;
214 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
218 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
223 void wxBrush::SetStyle(int Style
)
227 M_BRUSHDATA
->m_style
= Style
;
232 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
236 M_BRUSHDATA
->m_stipple
= Stipple
;
237 if (M_BRUSHDATA
->m_stipple
.GetMask())
238 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
240 M_BRUSHDATA
->m_style
= wxSTIPPLE
;