]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/brush.cpp
Listctrl updates
[wxWidgets.git] / src / gtk1 / brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: brush.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation "brush.h"
12 #endif
13
14 #include "wx/brush.h"
15
16 //-----------------------------------------------------------------------------
17 // wxBrush
18 //-----------------------------------------------------------------------------
19
20 class wxBrushRefData: public wxObjectRefData
21 {
22 public:
23
24 wxBrushRefData(void);
25 wxBrushRefData( const wxBrushRefData& data );
26
27 int m_style;
28 wxBitmap m_stipple;
29 wxColour m_colour;
30 };
31
32 wxBrushRefData::wxBrushRefData(void)
33 {
34 m_style = 0;
35 }
36
37 wxBrushRefData::wxBrushRefData( const wxBrushRefData& data )
38 {
39 m_style = data.m_style;
40 m_stipple = data.m_stipple;
41 m_colour = data.m_colour;
42 }
43
44 //-----------------------------------------------------------------------------
45
46 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
47
48 IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
49
50 wxBrush::wxBrush(void)
51 {
52 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
53 }
54
55 wxBrush::wxBrush( const wxColour &colour, int style )
56 {
57 m_refData = new wxBrushRefData();
58 M_BRUSHDATA->m_style = style;
59 M_BRUSHDATA->m_colour = colour;
60
61 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
62 }
63
64 wxBrush::wxBrush( const wxBitmap &stippleBitmap )
65 {
66 m_refData = new wxBrushRefData();
67 M_BRUSHDATA->m_style = wxSTIPPLE;
68 M_BRUSHDATA->m_colour = *wxBLACK;
69 M_BRUSHDATA->m_stipple = stippleBitmap;
70
71 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
72 }
73
74 wxBrush::wxBrush( const wxBrush &brush )
75 {
76 Ref( brush );
77
78 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
79 }
80
81 wxBrush::wxBrush( const wxBrush *brush )
82 {
83 if (brush) Ref( *brush );
84
85 if (wxTheBrushList) wxTheBrushList->Append( this );
86 }
87
88 wxBrush::~wxBrush(void)
89 {
90 if (wxTheBrushList) wxTheBrushList->RemoveBrush( this );
91 }
92
93 wxBrush& wxBrush::operator = ( const wxBrush& brush )
94 {
95 if (*this == brush) return (*this);
96 Ref( brush );
97 return *this;
98 }
99
100 bool wxBrush::operator == ( const wxBrush& brush )
101 {
102 return m_refData == brush.m_refData;
103 }
104
105 bool wxBrush::operator != ( const wxBrush& brush )
106 {
107 return m_refData != brush.m_refData;
108 }
109
110 bool wxBrush::Ok(void) const
111 {
112 return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
113 }
114
115 int wxBrush::GetStyle(void) const
116 {
117 if (m_refData == NULL)
118 {
119 wxFAIL_MSG( "invalid brush" );
120 return 0;
121 }
122
123 return M_BRUSHDATA->m_style;
124 }
125
126 wxColour &wxBrush::GetColour(void) const
127 {
128 if (m_refData == NULL)
129 {
130 wxFAIL_MSG( "invalid brush" );
131 return wxNullColour;
132 }
133
134 return M_BRUSHDATA->m_colour;
135 }
136
137 wxBitmap *wxBrush::GetStipple(void) const
138 {
139 if (m_refData == NULL)
140 {
141 wxFAIL_MSG( "invalid brush" );
142 return &wxNullBitmap;
143 }
144
145 return &M_BRUSHDATA->m_stipple;
146 }
147
148 void wxBrush::SetColour( const wxColour& col )
149 {
150 Unshare();
151 M_BRUSHDATA->m_colour = col;
152 }
153
154 void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
155 {
156 Unshare();
157 M_BRUSHDATA->m_colour.Set( r, g, b );
158 }
159
160 void wxBrush::SetStyle( int style )
161 {
162 Unshare();
163 M_BRUSHDATA->m_style = style;
164 }
165
166 void wxBrush::SetStipple( const wxBitmap& stipple )
167 {
168 Unshare();
169 M_BRUSHDATA->m_stipple = stipple;
170 }
171
172 void wxBrush::Unshare(void)
173 {
174 if (!m_refData)
175 {
176 m_refData = new wxBrushRefData();
177 }
178 else
179 {
180 wxBrushRefData* ref = new wxBrushRefData( *(wxBrushRefData*)m_refData );
181 UnRef();
182 m_refData = ref;
183 }
184 }
185