]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/brush.cpp
1. suppressed some messages from HasEntry()/HasKeys()
[wxWidgets.git] / src / gtk1 / brush.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: brush.cpp
3// Purpose:
4// Author: Robert Roebling
f96aa4d9 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
c801d85f
KB
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
20class wxBrushRefData: public wxObjectRefData
21{
22 public:
23
24 wxBrushRefData(void);
e55ad60e
RR
25 wxBrushRefData( const wxBrushRefData& data );
26
c801d85f
KB
27 int m_style;
28 wxBitmap m_stipple;
29 wxColour m_colour;
30};
31
32wxBrushRefData::wxBrushRefData(void)
33{
34 m_style = 0;
ff7b1510 35}
c801d85f 36
e55ad60e
RR
37wxBrushRefData::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
c801d85f
KB
44//-----------------------------------------------------------------------------
45
46#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
47
48IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
49
50wxBrush::wxBrush(void)
51{
52 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
ff7b1510 53}
c801d85f 54
debe6624 55wxBrush::wxBrush( const wxColour &colour, int style )
c801d85f
KB
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 );
ff7b1510 62}
c801d85f 63
c801d85f
KB
64wxBrush::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 );
ff7b1510 72}
c801d85f
KB
73
74wxBrush::wxBrush( const wxBrush &brush )
75{
76 Ref( brush );
77
78 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
ff7b1510 79}
c801d85f
KB
80
81wxBrush::wxBrush( const wxBrush *brush )
82{
83 if (brush) Ref( *brush );
84
85 if (wxTheBrushList) wxTheBrushList->Append( this );
ff7b1510 86}
c801d85f
KB
87
88wxBrush::~wxBrush(void)
89{
90 if (wxTheBrushList) wxTheBrushList->RemoveBrush( this );
ff7b1510 91}
c801d85f
KB
92
93wxBrush& wxBrush::operator = ( const wxBrush& brush )
94{
95 if (*this == brush) return (*this);
96 Ref( brush );
97 return *this;
ff7b1510 98}
c801d85f
KB
99
100bool wxBrush::operator == ( const wxBrush& brush )
101{
102 return m_refData == brush.m_refData;
ff7b1510 103}
c801d85f
KB
104
105bool wxBrush::operator != ( const wxBrush& brush )
106{
107 return m_refData != brush.m_refData;
ff7b1510 108}
c801d85f
KB
109
110bool wxBrush::Ok(void) const
111{
112 return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
ff7b1510 113}
c801d85f
KB
114
115int wxBrush::GetStyle(void) const
116{
e55ad60e
RR
117 if (m_refData == NULL)
118 {
119 wxFAIL_MSG( "invalid brush" );
120 return 0;
121 }
122
c801d85f 123 return M_BRUSHDATA->m_style;
ff7b1510 124}
c801d85f
KB
125
126wxColour &wxBrush::GetColour(void) const
127{
e55ad60e
RR
128 if (m_refData == NULL)
129 {
130 wxFAIL_MSG( "invalid brush" );
131 return wxNullColour;
132 }
133
c801d85f 134 return M_BRUSHDATA->m_colour;
ff7b1510 135}
c801d85f
KB
136
137wxBitmap *wxBrush::GetStipple(void) const
138{
e55ad60e
RR
139 if (m_refData == NULL)
140 {
141 wxFAIL_MSG( "invalid brush" );
142 return &wxNullBitmap;
143 }
144
c801d85f 145 return &M_BRUSHDATA->m_stipple;
ff7b1510 146}
c801d85f 147
e55ad60e
RR
148void wxBrush::SetColour( const wxColour& col )
149{
150 Unshare();
151 M_BRUSHDATA->m_colour = col;
152}
153
e55ad60e
RR
154void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
155{
156 Unshare();
157 M_BRUSHDATA->m_colour.Set( r, g, b );
158}
159
160void wxBrush::SetStyle( int style )
161{
162 Unshare();
163 M_BRUSHDATA->m_style = style;
164}
165
166void wxBrush::SetStipple( const wxBitmap& stipple )
167{
168 Unshare();
169 M_BRUSHDATA->m_stipple = stipple;
170}
171
172void wxBrush::Unshare(void)
173{
174 if (!m_refData)
175 {
176 m_refData = new wxBrushRefData();
177 }
178 else
179 {
180 wxBrushRefData* ref = new wxBrushRefData( *(wxBrushRefData*)m_refData );
181 UnRef();
182 m_refData = ref;
183 }
184}
c801d85f 185