]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/brush.cpp
wxMenu::Insert() seems to work, bug in wxMenuBase::Insert() is corrected
[wxWidgets.git] / src / gtk / brush.cpp
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
22 class wxBrushRefData: public wxObjectRefData
23 {
24 public:
25 wxBrushRefData();
26 wxBrushRefData( const wxBrushRefData& data );
27
28 int m_style;
29 wxBitmap m_stipple;
30 wxColour m_colour;
31 };
32
33 wxBrushRefData::wxBrushRefData()
34 {
35 m_style = 0;
36 }
37
38 wxBrushRefData::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
49 IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
50
51 wxBrush::wxBrush()
52 {
53 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
54 }
55
56 wxBrush::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
65 wxBrush::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
75 wxBrush::wxBrush( const wxBrush &brush )
76 {
77 Ref( brush );
78
79 if (wxTheBrushList) wxTheBrushList->AddBrush( this );
80 }
81
82 wxBrush::~wxBrush()
83 {
84 if (wxTheBrushList) wxTheBrushList->RemoveBrush( this );
85 }
86
87 wxBrush& wxBrush::operator = ( const wxBrush& brush )
88 {
89 if (*this == brush) return (*this);
90 Ref( brush );
91 return *this;
92 }
93
94 bool wxBrush::operator == ( const wxBrush& brush )
95 {
96 return m_refData == brush.m_refData;
97 }
98
99 bool wxBrush::operator != ( const wxBrush& brush )
100 {
101 return m_refData != brush.m_refData;
102 }
103
104 bool wxBrush::Ok() const
105 {
106 return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
107 }
108
109 int 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
120 wxColour &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
131 wxBitmap *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
142 void wxBrush::SetColour( const wxColour& col )
143 {
144 Unshare();
145 M_BRUSHDATA->m_colour = col;
146 }
147
148 void 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
154 void wxBrush::SetStyle( int style )
155 {
156 Unshare();
157 M_BRUSHDATA->m_style = style;
158 }
159
160 void wxBrush::SetStipple( const wxBitmap& stipple )
161 {
162 Unshare();
163 M_BRUSHDATA->m_stipple = stipple;
164 }
165
166 void 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