]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/brush.cpp
remove the line for image.h, restore a line commented out by mistake
[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 //-----------------------------------------------------------------------------
17 // wxBrush
18 //-----------------------------------------------------------------------------
19
20 class wxBrushRefData: public wxObjectRefData
21 {
22 public:
23
24 wxBrushRefData();
25 wxBrushRefData( const wxBrushRefData& data );
26
27 int m_style;
28 wxBitmap m_stipple;
29 wxColour m_colour;
30 };
31
32 wxBrushRefData::wxBrushRefData()
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()
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()
82 {
83 if (wxTheBrushList) wxTheBrushList->RemoveBrush( this );
84 }
85
86 wxBrush& wxBrush::operator = ( const wxBrush& brush )
87 {
88 if (*this == brush) return (*this);
89 Ref( brush );
90 return *this;
91 }
92
93 bool wxBrush::operator == ( const wxBrush& brush )
94 {
95 return m_refData == brush.m_refData;
96 }
97
98 bool wxBrush::operator != ( const wxBrush& brush )
99 {
100 return m_refData != brush.m_refData;
101 }
102
103 bool wxBrush::Ok() const
104 {
105 return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
106 }
107
108 int wxBrush::GetStyle() const
109 {
110 if (m_refData == NULL)
111 {
112 wxFAIL_MSG( "invalid brush" );
113 return 0;
114 }
115
116 return M_BRUSHDATA->m_style;
117 }
118
119 wxColour &wxBrush::GetColour() const
120 {
121 if (m_refData == NULL)
122 {
123 wxFAIL_MSG( "invalid brush" );
124 return wxNullColour;
125 }
126
127 return M_BRUSHDATA->m_colour;
128 }
129
130 wxBitmap *wxBrush::GetStipple() const
131 {
132 if (m_refData == NULL)
133 {
134 wxFAIL_MSG( "invalid brush" );
135 return &wxNullBitmap;
136 }
137
138 return &M_BRUSHDATA->m_stipple;
139 }
140
141 void wxBrush::SetColour( const wxColour& col )
142 {
143 Unshare();
144 M_BRUSHDATA->m_colour = col;
145 }
146
147 void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
148 {
149 Unshare();
150 M_BRUSHDATA->m_colour.Set( r, g, b );
151 }
152
153 void wxBrush::SetStyle( int style )
154 {
155 Unshare();
156 M_BRUSHDATA->m_style = style;
157 }
158
159 void wxBrush::SetStipple( const wxBitmap& stipple )
160 {
161 Unshare();
162 M_BRUSHDATA->m_stipple = stipple;
163 }
164
165 void wxBrush::Unshare()
166 {
167 if (!m_refData)
168 {
169 m_refData = new wxBrushRefData();
170 }
171 else
172 {
173 wxBrushRefData* ref = new wxBrushRefData( *(wxBrushRefData*)m_refData );
174 UnRef();
175 m_refData = ref;
176 }
177 }
178