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