]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/brush.cpp
wx_USEIOSTREAMH changes
[wxWidgets.git] / src / gtk / brush.cpp
CommitLineData
c801d85f
KB
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);
e55ad60e
RR
26 wxBrushRefData( const wxBrushRefData& data );
27
c801d85f
KB
28 int m_style;
29 wxBitmap m_stipple;
30 wxColour m_colour;
31};
32
33wxBrushRefData::wxBrushRefData(void)
34{
35 m_style = 0;
ff7b1510 36}
c801d85f 37
e55ad60e
RR
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
c801d85f
KB
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 );
ff7b1510 54}
c801d85f 55
debe6624 56wxBrush::wxBrush( const wxColour &colour, int style )
c801d85f
KB
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 );
ff7b1510 63}
c801d85f 64
debe6624 65wxBrush::wxBrush( const wxString &colourName, int style )
c801d85f
KB
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 );
ff7b1510 72}
c801d85f
KB
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 );
ff7b1510 82}
c801d85f
KB
83
84wxBrush::wxBrush( const wxBrush &brush )
85{
86 Ref( brush );
87
88 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
ff7b1510 89}
c801d85f
KB
90
91wxBrush::wxBrush( const wxBrush *brush )
92{
93 if (brush) Ref( *brush );
94
95 if (wxTheBrushList) wxTheBrushList->Append( this );
ff7b1510 96}
c801d85f
KB
97
98wxBrush::~wxBrush(void)
99{
100 if (wxTheBrushList) wxTheBrushList->RemoveBrush( this );
ff7b1510 101}
c801d85f
KB
102
103wxBrush& wxBrush::operator = ( const wxBrush& brush )
104{
105 if (*this == brush) return (*this);
106 Ref( brush );
107 return *this;
ff7b1510 108}
c801d85f
KB
109
110bool wxBrush::operator == ( const wxBrush& brush )
111{
112 return m_refData == brush.m_refData;
ff7b1510 113}
c801d85f
KB
114
115bool wxBrush::operator != ( const wxBrush& brush )
116{
117 return m_refData != brush.m_refData;
ff7b1510 118}
c801d85f
KB
119
120bool wxBrush::Ok(void) const
121{
122 return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
ff7b1510 123}
c801d85f
KB
124
125int wxBrush::GetStyle(void) const
126{
e55ad60e
RR
127 if (m_refData == NULL)
128 {
129 wxFAIL_MSG( "invalid brush" );
130 return 0;
131 }
132
c801d85f 133 return M_BRUSHDATA->m_style;
ff7b1510 134}
c801d85f
KB
135
136wxColour &wxBrush::GetColour(void) const
137{
e55ad60e
RR
138 if (m_refData == NULL)
139 {
140 wxFAIL_MSG( "invalid brush" );
141 return wxNullColour;
142 }
143
c801d85f 144 return M_BRUSHDATA->m_colour;
ff7b1510 145}
c801d85f
KB
146
147wxBitmap *wxBrush::GetStipple(void) const
148{
e55ad60e
RR
149 if (m_refData == NULL)
150 {
151 wxFAIL_MSG( "invalid brush" );
152 return &wxNullBitmap;
153 }
154
c801d85f 155 return &M_BRUSHDATA->m_stipple;
ff7b1510 156}
c801d85f 157
e55ad60e
RR
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}
c801d85f 201