]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/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 wxBitmap
&stippleBitmap
)
67 m_refData
= new wxBrushRefData();
68 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
69 M_BRUSHDATA
->m_colour
= *wxBLACK
;
70 M_BRUSHDATA
->m_stipple
= stippleBitmap
;
72 if (wxTheBrushList
) wxTheBrushList
->AddBrush( this );
75 wxBrush::wxBrush( const wxBrush
&brush
)
79 if (wxTheBrushList
) wxTheBrushList
->AddBrush( this );
82 wxBrush::wxBrush( const wxBrush
*brush
)
84 if (brush
) Ref( *brush
);
86 if (wxTheBrushList
) wxTheBrushList
->Append( this );
89 wxBrush::~wxBrush(void)
91 if (wxTheBrushList
) wxTheBrushList
->RemoveBrush( this );
94 wxBrush
& wxBrush::operator = ( const wxBrush
& brush
)
96 if (*this == brush
) return (*this);
101 bool wxBrush::operator == ( const wxBrush
& brush
)
103 return m_refData
== brush
.m_refData
;
106 bool wxBrush::operator != ( const wxBrush
& brush
)
108 return m_refData
!= brush
.m_refData
;
111 bool wxBrush::Ok(void) const
113 return ((m_refData
) && M_BRUSHDATA
->m_colour
.Ok());
116 int wxBrush::GetStyle(void) const
118 if (m_refData
== NULL
)
120 wxFAIL_MSG( "invalid brush" );
124 return M_BRUSHDATA
->m_style
;
127 wxColour
&wxBrush::GetColour(void) const
129 if (m_refData
== NULL
)
131 wxFAIL_MSG( "invalid brush" );
135 return M_BRUSHDATA
->m_colour
;
138 wxBitmap
*wxBrush::GetStipple(void) const
140 if (m_refData
== NULL
)
142 wxFAIL_MSG( "invalid brush" );
143 return &wxNullBitmap
;
146 return &M_BRUSHDATA
->m_stipple
;
149 void wxBrush::SetColour( const wxColour
& col
)
152 M_BRUSHDATA
->m_colour
= col
;
155 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b
)
158 M_BRUSHDATA
->m_colour
.Set( r
, g
, b
);
161 void wxBrush::SetStyle( int style
)
164 M_BRUSHDATA
->m_style
= style
;
167 void wxBrush::SetStipple( const wxBitmap
& stipple
)
170 M_BRUSHDATA
->m_stipple
= stipple
;
173 void wxBrush::Unshare(void)
177 m_refData
= new wxBrushRefData();
181 wxBrushRefData
* ref
= new wxBrushRefData( *(wxBrushRefData
*)m_refData
);