]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/brush.cpp
Initialized m_startint in the constructor to avoid cloning of uninitialized value
[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
20e05ffb 16#include <gdk/gdk.h>
83624f79 17
c801d85f
KB
18//-----------------------------------------------------------------------------
19// wxBrush
20//-----------------------------------------------------------------------------
21
22class wxBrushRefData: public wxObjectRefData
23{
58c837a4 24public:
8bbe427f 25 wxBrushRefData();
e55ad60e 26 wxBrushRefData( const wxBrushRefData& data );
8bbe427f 27
c801d85f
KB
28 int m_style;
29 wxBitmap m_stipple;
30 wxColour m_colour;
31};
32
8bbe427f 33wxBrushRefData::wxBrushRefData()
c801d85f 34{
58c837a4 35 m_style = 0;
ff7b1510 36}
c801d85f 37
e55ad60e
RR
38wxBrushRefData::wxBrushRefData( const wxBrushRefData& data )
39{
58c837a4
RR
40 m_style = data.m_style;
41 m_stipple = data.m_stipple;
42 m_colour = data.m_colour;
e55ad60e
RR
43}
44
c801d85f
KB
45//-----------------------------------------------------------------------------
46
47#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
48
49IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
50
8bbe427f 51wxBrush::wxBrush()
c801d85f 52{
58c837a4 53 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
ff7b1510 54}
c801d85f 55
debe6624 56wxBrush::wxBrush( const wxColour &colour, int style )
c801d85f 57{
58c837a4
RR
58 m_refData = new wxBrushRefData();
59 M_BRUSHDATA->m_style = style;
60 M_BRUSHDATA->m_colour = colour;
8bbe427f 61
58c837a4 62 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
ff7b1510 63}
c801d85f 64
c801d85f
KB
65wxBrush::wxBrush( const wxBitmap &stippleBitmap )
66{
58c837a4 67 m_refData = new wxBrushRefData();
58c837a4 68 M_BRUSHDATA->m_colour = *wxBLACK;
e1208c31 69
58c837a4 70 M_BRUSHDATA->m_stipple = stippleBitmap;
e1208c31 71
de2d2cdc 72 if (M_BRUSHDATA->m_stipple.GetMask())
e1208c31
RR
73 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
74 else
75 M_BRUSHDATA->m_style = wxSTIPPLE;
8bbe427f 76
58c837a4 77 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
ff7b1510 78}
c801d85f
KB
79
80wxBrush::wxBrush( const wxBrush &brush )
81{
58c837a4 82 Ref( brush );
c801d85f 83
58c837a4 84 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
ff7b1510 85}
c801d85f 86
8bbe427f 87wxBrush::~wxBrush()
c801d85f 88{
58c837a4 89 if (wxTheBrushList) wxTheBrushList->RemoveBrush( this );
ff7b1510 90}
c801d85f
KB
91
92wxBrush& wxBrush::operator = ( const wxBrush& brush )
93{
58c837a4
RR
94 if (*this == brush) return (*this);
95 Ref( brush );
96 return *this;
ff7b1510 97}
8bbe427f 98
f6bcfd97 99bool wxBrush::operator == ( const wxBrush& brush ) const
c801d85f 100{
58c837a4 101 return m_refData == brush.m_refData;
ff7b1510 102}
c801d85f 103
f6bcfd97 104bool wxBrush::operator != ( const wxBrush& brush ) const
c801d85f 105{
58c837a4 106 return m_refData != brush.m_refData;
ff7b1510 107}
c801d85f 108
8bbe427f 109bool wxBrush::Ok() const
c801d85f 110{
58c837a4 111 return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
ff7b1510 112}
c801d85f 113
8bbe427f 114int wxBrush::GetStyle() const
c801d85f 115{
58c837a4
RR
116 if (m_refData == NULL)
117 {
118 wxFAIL_MSG( wxT("invalid brush") );
119 return 0;
120 }
e55ad60e 121
58c837a4 122 return M_BRUSHDATA->m_style;
ff7b1510 123}
c801d85f 124
8bbe427f 125wxColour &wxBrush::GetColour() const
c801d85f 126{
58c837a4
RR
127 if (m_refData == NULL)
128 {
129 wxFAIL_MSG( wxT("invalid brush") );
130 return wxNullColour;
131 }
8bbe427f 132
58c837a4 133 return M_BRUSHDATA->m_colour;
ff7b1510 134}
c801d85f 135
8bbe427f 136wxBitmap *wxBrush::GetStipple() const
c801d85f 137{
58c837a4
RR
138 if (m_refData == NULL)
139 {
140 wxFAIL_MSG( wxT("invalid brush") );
141 return &wxNullBitmap;
142 }
8bbe427f 143
58c837a4 144 return &M_BRUSHDATA->m_stipple;
ff7b1510 145}
c801d85f 146
e55ad60e
RR
147void wxBrush::SetColour( const wxColour& col )
148{
58c837a4
RR
149 Unshare();
150 M_BRUSHDATA->m_colour = col;
e55ad60e
RR
151}
152
e55ad60e
RR
153void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
154{
58c837a4
RR
155 Unshare();
156 M_BRUSHDATA->m_colour.Set( r, g, b );
e55ad60e
RR
157}
158
159void wxBrush::SetStyle( int style )
160{
58c837a4
RR
161 Unshare();
162 M_BRUSHDATA->m_style = style;
e55ad60e
RR
163}
164
165void wxBrush::SetStipple( const wxBitmap& stipple )
166{
58c837a4
RR
167 Unshare();
168 M_BRUSHDATA->m_stipple = stipple;
de2d2cdc
VZ
169 if (M_BRUSHDATA->m_stipple.GetMask())
170 {
171 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
172 }
173 else
174 {
175 M_BRUSHDATA->m_style = wxSTIPPLE;
176 }
e55ad60e
RR
177}
178
8bbe427f 179void wxBrush::Unshare()
e55ad60e 180{
58c837a4
RR
181 if (!m_refData)
182 {
183 m_refData = new wxBrushRefData();
184 }
185 else
186 {
187 wxBrushRefData* ref = new wxBrushRefData( *(wxBrushRefData*)m_refData );
188 UnRef();
189 m_refData = ref;
190 }
e55ad60e 191}
c801d85f 192