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