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