]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/brush.cpp
wx_USEIOSTREAMH changes
[wxWidgets.git] / src / gtk / brush.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: brush.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifdef __GNUG__
12#pragma implementation "brush.h"
13#endif
14
15#include "wx/brush.h"
16
17//-----------------------------------------------------------------------------
18// wxBrush
19//-----------------------------------------------------------------------------
20
21class wxBrushRefData: public wxObjectRefData
22{
23 public:
24
25 wxBrushRefData(void);
26 wxBrushRefData( const wxBrushRefData& data );
27
28 int m_style;
29 wxBitmap m_stipple;
30 wxColour m_colour;
31};
32
33wxBrushRefData::wxBrushRefData(void)
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(void)
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 wxString &colourName, int style )
66{
67 m_refData = new wxBrushRefData();
68 M_BRUSHDATA->m_style = style;
69 M_BRUSHDATA->m_colour = colourName;
70
71 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
72}
73
74wxBrush::wxBrush( const wxBitmap &stippleBitmap )
75{
76 m_refData = new wxBrushRefData();
77 M_BRUSHDATA->m_style = wxSTIPPLE;
78 M_BRUSHDATA->m_colour = *wxBLACK;
79 M_BRUSHDATA->m_stipple = stippleBitmap;
80
81 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
82}
83
84wxBrush::wxBrush( const wxBrush &brush )
85{
86 Ref( brush );
87
88 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
89}
90
91wxBrush::wxBrush( const wxBrush *brush )
92{
93 if (brush) Ref( *brush );
94
95 if (wxTheBrushList) wxTheBrushList->Append( this );
96}
97
98wxBrush::~wxBrush(void)
99{
100 if (wxTheBrushList) wxTheBrushList->RemoveBrush( this );
101}
102
103wxBrush& wxBrush::operator = ( const wxBrush& brush )
104{
105 if (*this == brush) return (*this);
106 Ref( brush );
107 return *this;
108}
109
110bool wxBrush::operator == ( const wxBrush& brush )
111{
112 return m_refData == brush.m_refData;
113}
114
115bool wxBrush::operator != ( const wxBrush& brush )
116{
117 return m_refData != brush.m_refData;
118}
119
120bool wxBrush::Ok(void) const
121{
122 return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
123}
124
125int wxBrush::GetStyle(void) const
126{
127 if (m_refData == NULL)
128 {
129 wxFAIL_MSG( "invalid brush" );
130 return 0;
131 }
132
133 return M_BRUSHDATA->m_style;
134}
135
136wxColour &wxBrush::GetColour(void) const
137{
138 if (m_refData == NULL)
139 {
140 wxFAIL_MSG( "invalid brush" );
141 return wxNullColour;
142 }
143
144 return M_BRUSHDATA->m_colour;
145}
146
147wxBitmap *wxBrush::GetStipple(void) const
148{
149 if (m_refData == NULL)
150 {
151 wxFAIL_MSG( "invalid brush" );
152 return &wxNullBitmap;
153 }
154
155 return &M_BRUSHDATA->m_stipple;
156}
157
158void wxBrush::SetColour( const wxColour& col )
159{
160 Unshare();
161 M_BRUSHDATA->m_colour = col;
162}
163
164void wxBrush::SetColour( const wxString& col )
165{
166 Unshare();
167 M_BRUSHDATA->m_colour = col;
168}
169
170void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
171{
172 Unshare();
173 M_BRUSHDATA->m_colour.Set( r, g, b );
174}
175
176void wxBrush::SetStyle( int style )
177{
178 Unshare();
179 M_BRUSHDATA->m_style = style;
180}
181
182void wxBrush::SetStipple( const wxBitmap& stipple )
183{
184 Unshare();
185 M_BRUSHDATA->m_stipple = stipple;
186}
187
188void wxBrush::Unshare(void)
189{
190 if (!m_refData)
191 {
192 m_refData = new wxBrushRefData();
193 }
194 else
195 {
196 wxBrushRefData* ref = new wxBrushRefData( *(wxBrushRefData*)m_refData );
197 UnRef();
198 m_refData = ref;
199 }
200}
201