]>
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 wxBitmap
& stipple
)
89 m_refData
= new wxBrushRefData
;
91 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
92 M_BRUSHDATA
->m_stipple
= stipple
;
93 M_BRUSHDATA
->m_hBrush
= 0;
98 wxTheBrushList
->AddBrush(this);
101 bool wxBrush::RealizeResource(void)
103 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0))
105 if (M_BRUSHDATA
->m_style
==wxTRANSPARENT
)
107 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) ::GetStockObject(NULL_BRUSH
);
110 COLORREF ms_colour
= 0 ;
112 ms_colour
= M_BRUSHDATA
->m_colour
.GetPixel() ;
114 switch (M_BRUSHDATA
->m_style
)
117 // Don't reset cbrush, wxTRANSPARENT is handled by wxBrush::SelectBrush()
118 // this could save (many) time if frequently switching from
119 // wxSOLID to wxTRANSPARENT, because Create... is not always called!!
121 // NB August 95: now create and select a Null brush instead.
122 // This could be optimized as above.
124 M_BRUSHDATA->m_hBrush = NULL; // Must always select a suitable background brush
125 // - could choose white always for a quick solution
128 case wxBDIAGONAL_HATCH
:
129 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_BDIAGONAL
,ms_colour
) ;
131 case wxCROSSDIAG_HATCH
:
132 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_DIAGCROSS
,ms_colour
) ;
134 case wxFDIAGONAL_HATCH
:
135 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_FDIAGONAL
,ms_colour
) ;
138 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_CROSS
,ms_colour
) ;
140 case wxHORIZONTAL_HATCH
:
141 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_HORIZONTAL
,ms_colour
) ;
143 case wxVERTICAL_HATCH
:
144 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateHatchBrush(HS_VERTICAL
,ms_colour
) ;
147 if (M_BRUSHDATA
->m_stipple
.Ok())
148 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreatePatternBrush((HBITMAP
) M_BRUSHDATA
->m_stipple
.GetHBITMAP()) ;
150 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateSolidBrush(ms_colour
) ;
154 M_BRUSHDATA
->m_hBrush
= (WXHBRUSH
) CreateSolidBrush(ms_colour
) ;
157 #ifdef WXDEBUG_CREATE
158 if (M_BRUSHDATA
->m_hBrush
==NULL
) wxError("Cannot create brush","Internal error") ;
166 WXHANDLE
wxBrush::GetResourceHandle(void)
168 return (WXHANDLE
) M_BRUSHDATA
->m_hBrush
;
171 bool wxBrush::FreeResource(bool WXUNUSED(force
))
173 if (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
!= 0))
175 DeleteObject((HBRUSH
) M_BRUSHDATA
->m_hBrush
);
176 M_BRUSHDATA
->m_hBrush
= 0;
182 bool wxBrush::IsFree(void)
184 return (M_BRUSHDATA
&& (M_BRUSHDATA
->m_hBrush
== 0));
187 void wxBrush::Unshare()
189 // Don't change shared data
192 m_refData
= new wxBrushRefData();
196 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
203 void wxBrush::SetColour(const wxColour
& col
)
207 M_BRUSHDATA
->m_colour
= col
;
212 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
216 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
221 void wxBrush::SetStyle(int Style
)
225 M_BRUSHDATA
->m_style
= Style
;
230 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
234 M_BRUSHDATA
->m_stipple
= Stipple
;