]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/brush.cpp
Changed system colours for better default display of wxGrid. Please revert
[wxWidgets.git] / src / gtk / 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
RR
68 M_BRUSHDATA->m_colour = *wxBLACK;
69 M_BRUSHDATA->m_stipple = stippleBitmap;
de2d2cdc
VZ
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 }
8bbe427f 78
58c837a4 79 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
ff7b1510 80}
c801d85f
KB
81
82wxBrush::wxBrush( const wxBrush &brush )
83{
58c837a4 84 Ref( brush );
c801d85f 85
58c837a4 86 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
ff7b1510 87}
c801d85f 88
8bbe427f 89wxBrush::~wxBrush()
c801d85f 90{
58c837a4 91 if (wxTheBrushList) wxTheBrushList->RemoveBrush( this );
ff7b1510 92}
c801d85f
KB
93
94wxBrush& wxBrush::operator = ( const wxBrush& brush )
95{
58c837a4
RR
96 if (*this == brush) return (*this);
97 Ref( brush );
98 return *this;
ff7b1510 99}
8bbe427f 100
c801d85f
KB
101bool wxBrush::operator == ( const wxBrush& brush )
102{
58c837a4 103 return m_refData == brush.m_refData;
ff7b1510 104}
c801d85f
KB
105
106bool wxBrush::operator != ( const wxBrush& brush )
107{
58c837a4 108 return m_refData != brush.m_refData;
ff7b1510 109}
c801d85f 110
8bbe427f 111bool wxBrush::Ok() const
c801d85f 112{
58c837a4 113 return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
ff7b1510 114}
c801d85f 115
8bbe427f 116int wxBrush::GetStyle() const
c801d85f 117{
58c837a4
RR
118 if (m_refData == NULL)
119 {
120 wxFAIL_MSG( wxT("invalid brush") );
121 return 0;
122 }
e55ad60e 123
58c837a4 124 return M_BRUSHDATA->m_style;
ff7b1510 125}
c801d85f 126
8bbe427f 127wxColour &wxBrush::GetColour() const
c801d85f 128{
58c837a4
RR
129 if (m_refData == NULL)
130 {
131 wxFAIL_MSG( wxT("invalid brush") );
132 return wxNullColour;
133 }
8bbe427f 134
58c837a4 135 return M_BRUSHDATA->m_colour;
ff7b1510 136}
c801d85f 137
8bbe427f 138wxBitmap *wxBrush::GetStipple() const
c801d85f 139{
58c837a4
RR
140 if (m_refData == NULL)
141 {
142 wxFAIL_MSG( wxT("invalid brush") );
143 return &wxNullBitmap;
144 }
8bbe427f 145
58c837a4 146 return &M_BRUSHDATA->m_stipple;
ff7b1510 147}
c801d85f 148
e55ad60e
RR
149void wxBrush::SetColour( const wxColour& col )
150{
58c837a4
RR
151 Unshare();
152 M_BRUSHDATA->m_colour = col;
e55ad60e
RR
153}
154
e55ad60e
RR
155void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
156{
58c837a4
RR
157 Unshare();
158 M_BRUSHDATA->m_colour.Set( r, g, b );
e55ad60e
RR
159}
160
161void wxBrush::SetStyle( int style )
162{
58c837a4
RR
163 Unshare();
164 M_BRUSHDATA->m_style = style;
e55ad60e
RR
165}
166
167void wxBrush::SetStipple( const wxBitmap& stipple )
168{
58c837a4
RR
169 Unshare();
170 M_BRUSHDATA->m_stipple = stipple;
de2d2cdc
VZ
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 }
e55ad60e
RR
179}
180
8bbe427f 181void wxBrush::Unshare()
e55ad60e 182{
58c837a4
RR
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 }
e55ad60e 193}
c801d85f 194