]>
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)
46 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& data
)
48 m_style
= data
.m_style
;
49 m_stipple
= data
.m_stipple
;
50 m_colour
= data
.m_colour
;
54 wxBrushRefData::~wxBrushRefData(void)
57 ::DeleteObject((HBRUSH
) m_hBrush
);
61 wxBrush::wxBrush(void)
64 wxTheBrushList
->AddBrush(this);
70 wxTheBrushList
->RemoveBrush(this);
73 wxBrush::wxBrush(const wxColour
& col
, int Style
)
75 m_refData
= new wxBrushRefData
;
77 M_BRUSHDATA
->m_colour
= col
;
78 M_BRUSHDATA
->m_style
= Style
;
79 M_BRUSHDATA
->m_hBrush
= 0;
84 wxTheBrushList
->AddBrush(this);
87 wxBrush::wxBrush(const wxString
& col
, int Style
)
89 m_refData
= new wxBrushRefData
;
91 M_BRUSHDATA
->m_colour
= col
;
92 M_BRUSHDATA
->m_style
= Style
;
93 M_BRUSHDATA
->m_hBrush
= 0;
98 wxTheBrushList
->AddBrush(this);
101 wxBrush::wxBrush(const wxBitmap
& stipple
)
103 m_refData
= new wxBrushRefData
;
105 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
106 M_BRUSHDATA
->m_stipple
= stipple
;
107 M_BRUSHDATA
->m_hBrush
= 0;
111 if ( wxTheBrushList
)
112 wxTheBrushList
->AddBrush(this);
115 bool wxBrush::RealizeResource(void)
117 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0))
119 if (M_BRUSHDATA
->m_style
==wxTRANSPARENT
)
121 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) ::GetStockObject(NULL_BRUSH
);
124 COLORREF ms_colour
= 0 ;
126 ms_colour
= M_BRUSHDATA
->m_colour
.GetPixel() ;
128 switch (M_BRUSHDATA
->m_style
)
131 // Don't reset cbrush, wxTRANSPARENT is handled by wxBrush::SelectBrush()
132 // this could save (many) time if frequently switching from
133 // wxSOLID to wxTRANSPARENT, because Create... is not always called!!
135 // NB August 95: now create and select a Null brush instead.
136 // This could be optimized as above.
138 M_BRUSHDATA->m_hBrush = NULL; // Must always select a suitable background brush
139 // - could choose white always for a quick solution
142 case wxBDIAGONAL_HATCH
:
143 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_BDIAGONAL
,ms_colour
) ;
145 case wxCROSSDIAG_HATCH
:
146 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_DIAGCROSS
,ms_colour
) ;
148 case wxFDIAGONAL_HATCH
:
149 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_FDIAGONAL
,ms_colour
) ;
152 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_CROSS
,ms_colour
) ;
154 case wxHORIZONTAL_HATCH
:
155 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_HORIZONTAL
,ms_colour
) ;
157 case wxVERTICAL_HATCH
:
158 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_VERTICAL
,ms_colour
) ;
161 if (M_BRUSHDATA
->m_stipple
.Ok())
162 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreatePatternBrush((HBITMAP
) M_BRUSHDATA
->m_stipple
.GetHBITMAP()) ;
164 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateSolidBrush(ms_colour
) ;
168 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateSolidBrush(ms_colour
) ;
171 #ifdef WXDEBUG_CREATE
172 if (M_BRUSHDATA
->m_hBrush
==NULL
) wxError("Cannot create brush","Internal error") ;
180 WXHANDLE
wxBrush::GetResourceHandle(void)
182 return (WXHANDLE
) M_BRUSHDATA
->m_hBrush
;
185 bool wxBrush::FreeResource(bool force
)
187 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
!= 0))
189 DeleteObject((HBRUSH
) M_BRUSHDATA
->m_hBrush
);
190 M_BRUSHDATA
->m_hBrush
= 0;
196 bool wxBrush::IsFree(void)
198 return (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0));
201 void wxBrush::Unshare()
203 // Don't change shared data
206 m_refData
= new wxBrushRefData();
210 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
217 void wxBrush::SetColour(const wxColour
& col
)
221 M_BRUSHDATA
->m_colour
= col
;
226 void wxBrush::SetColour(const wxString
& col
)
230 M_BRUSHDATA
->m_colour
= col
;
235 void wxBrush::SetColour(const unsigned char r
, const unsigned char g
, const unsigned char b
)
239 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
244 void wxBrush::SetStyle(int Style
)
248 M_BRUSHDATA
->m_style
= Style
;
253 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
257 M_BRUSHDATA
->m_stipple
= Stipple
;