]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/brush.cpp
removed 2nd frame from html test sample; test sample now shows DL,DT,DD support
[wxWidgets.git] / src / gtk1 / brush.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: brush.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "brush.h"
12#endif
13
14#include "wx/brush.h"
15
16#include <gdk/gdk.h>
17
18//-----------------------------------------------------------------------------
19// wxBrush
20//-----------------------------------------------------------------------------
21
22class wxBrushRefData: public wxObjectRefData
23{
24public:
25 wxBrushRefData();
26 wxBrushRefData( const wxBrushRefData& data );
27
28 int m_style;
29 wxBitmap m_stipple;
30 wxColour m_colour;
31};
32
33wxBrushRefData::wxBrushRefData()
34{
35 m_style = 0;
36}
37
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
45//-----------------------------------------------------------------------------
46
47#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
48
49IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
50
51wxBrush::wxBrush()
52{
53 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
54}
55
56wxBrush::wxBrush( const wxColour &colour, int style )
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 );
63}
64
65wxBrush::wxBrush( const wxBitmap &stippleBitmap )
66{
67 m_refData = new wxBrushRefData();
68 M_BRUSHDATA->m_style = wxSTIPPLE;
69 M_BRUSHDATA->m_colour = *wxBLACK;
70 M_BRUSHDATA->m_stipple = stippleBitmap;
71
72 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
73}
74
75wxBrush::wxBrush( const wxBrush &brush )
76{
77 Ref( brush );
78
79 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
80}
81
82wxBrush::~wxBrush()
83{
84 if (wxTheBrushList) wxTheBrushList->RemoveBrush( this );
85}
86
87wxBrush& wxBrush::operator = ( const wxBrush& brush )
88{
89 if (*this == brush) return (*this);
90 Ref( brush );
91 return *this;
92}
93
94bool wxBrush::operator == ( const wxBrush& brush )
95{
96 return m_refData == brush.m_refData;
97}
98
99bool wxBrush::operator != ( const wxBrush& brush )
100{
101 return m_refData != brush.m_refData;
102}
103
104bool wxBrush::Ok() const
105{
106 return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
107}
108
109int wxBrush::GetStyle() const
110{
111 if (m_refData == NULL)
112 {
113 wxFAIL_MSG( wxT("invalid brush") );
114 return 0;
115 }
116
117 return M_BRUSHDATA->m_style;
118}
119
120wxColour &wxBrush::GetColour() const
121{
122 if (m_refData == NULL)
123 {
124 wxFAIL_MSG( wxT("invalid brush") );
125 return wxNullColour;
126 }
127
128 return M_BRUSHDATA->m_colour;
129}
130
131wxBitmap *wxBrush::GetStipple() const
132{
133 if (m_refData == NULL)
134 {
135 wxFAIL_MSG( wxT("invalid brush") );
136 return &wxNullBitmap;
137 }
138
139 return &M_BRUSHDATA->m_stipple;
140}
141
142void wxBrush::SetColour( const wxColour& col )
143{
144 Unshare();
145 M_BRUSHDATA->m_colour = col;
146}
147
148void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
149{
150 Unshare();
151 M_BRUSHDATA->m_colour.Set( r, g, b );
152}
153
154void wxBrush::SetStyle( int style )
155{
156 Unshare();
157 M_BRUSHDATA->m_style = style;
158}
159
160void wxBrush::SetStipple( const wxBitmap& stipple )
161{
162 Unshare();
163 M_BRUSHDATA->m_stipple = stipple;
164}
165
166void wxBrush::Unshare()
167{
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 }
178}
179