]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "brush.h"
17 //-----------------------------------------------------------------------------
19 //-----------------------------------------------------------------------------
21 class wxBrushRefData
: public wxObjectRefData
26 wxBrushRefData( const wxBrushRefData
& data
);
33 wxBrushRefData::wxBrushRefData(void)
38 wxBrushRefData::wxBrushRefData( const wxBrushRefData
& data
)
40 m_style
= data
.m_style
;
41 m_stipple
= data
.m_stipple
;
42 m_colour
= data
.m_colour
;
45 //-----------------------------------------------------------------------------
47 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
49 IMPLEMENT_DYNAMIC_CLASS(wxBrush
,wxGDIObject
)
51 wxBrush::wxBrush(void)
53 if (wxTheBrushList
) wxTheBrushList
->AddBrush( this );
56 wxBrush::wxBrush( const wxColour
&colour
, int style
)
58 m_refData
= new wxBrushRefData();
59 M_BRUSHDATA
->m_style
= style
;
60 M_BRUSHDATA
->m_colour
= colour
;
62 if (wxTheBrushList
) wxTheBrushList
->AddBrush( this );
65 wxBrush::wxBrush( const wxString
&colourName
, int style
)
67 m_refData
= new wxBrushRefData();
68 M_BRUSHDATA
->m_style
= style
;
69 M_BRUSHDATA
->m_colour
= colourName
;
71 if (wxTheBrushList
) wxTheBrushList
->AddBrush( this );
74 wxBrush::wxBrush( const wxBitmap
&stippleBitmap
)
76 m_refData
= new wxBrushRefData();
77 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
78 M_BRUSHDATA
->m_colour
= *wxBLACK
;
79 M_BRUSHDATA
->m_stipple
= stippleBitmap
;
81 if (wxTheBrushList
) wxTheBrushList
->AddBrush( this );
84 wxBrush::wxBrush( const wxBrush
&brush
)
88 if (wxTheBrushList
) wxTheBrushList
->AddBrush( this );
91 wxBrush::wxBrush( const wxBrush
*brush
)
93 if (brush
) Ref( *brush
);
95 if (wxTheBrushList
) wxTheBrushList
->Append( this );
98 wxBrush::~wxBrush(void)
100 if (wxTheBrushList
) wxTheBrushList
->RemoveBrush( this );
103 wxBrush
& wxBrush::operator = ( const wxBrush
& brush
)
105 if (*this == brush
) return (*this);
110 bool wxBrush::operator == ( const wxBrush
& brush
)
112 return m_refData
== brush
.m_refData
;
115 bool wxBrush::operator != ( const wxBrush
& brush
)
117 return m_refData
!= brush
.m_refData
;
120 bool wxBrush::Ok(void) const
122 return ((m_refData
) && M_BRUSHDATA
->m_colour
.Ok());
125 int wxBrush::GetStyle(void) const
127 if (m_refData
== NULL
)
129 wxFAIL_MSG( "invalid brush" );
133 return M_BRUSHDATA
->m_style
;
136 wxColour
&wxBrush::GetColour(void) const
138 if (m_refData
== NULL
)
140 wxFAIL_MSG( "invalid brush" );
144 return M_BRUSHDATA
->m_colour
;
147 wxBitmap
*wxBrush::GetStipple(void) const
149 if (m_refData
== NULL
)
151 wxFAIL_MSG( "invalid brush" );
152 return &wxNullBitmap
;
155 return &M_BRUSHDATA
->m_stipple
;
158 void wxBrush::SetColour( const wxColour
& col
)
161 M_BRUSHDATA
->m_colour
= col
;
164 void wxBrush::SetColour( const wxString
& col
)
167 M_BRUSHDATA
->m_colour
= col
;
170 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b
)
173 M_BRUSHDATA
->m_colour
.Set( r
, g
, b
);
176 void wxBrush::SetStyle( int style
)
179 M_BRUSHDATA
->m_style
= style
;
182 void wxBrush::SetStipple( const wxBitmap
& stipple
)
185 M_BRUSHDATA
->m_stipple
= stipple
;
188 void wxBrush::Unshare(void)
192 m_refData
= new wxBrushRefData();
196 wxBrushRefData
* ref
= new wxBrushRefData( *(wxBrushRefData
*)m_refData
);