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