]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/brush.cpp
typo in IMPLEMENT_DYNAMIC_CLASS fixed
[wxWidgets.git] / src / gtk / brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/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 {
27 m_style = 0;
28 }
29
30 wxBrushRefData( const wxBrushRefData& data )
31 {
32 m_style = data.m_style;
33 m_stipple = data.m_stipple;
34 m_colour = data.m_colour;
35 }
36
37 bool operator == (const wxBrushRefData& data) const
38 {
39 return (m_style == data.m_style &&
40 m_stipple == data.m_stipple &&
41 m_colour == data.m_colour);
42 }
43
44 int m_style;
45 wxColour m_colour;
46 wxBitmap m_stipple;
47 };
48
49 //-----------------------------------------------------------------------------
50
51 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
52
53 IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
54
55 wxBrush::wxBrush( const wxColour &colour, int style )
56 {
57 m_refData = new wxBrushRefData();
58 M_BRUSHDATA->m_style = style;
59 M_BRUSHDATA->m_colour = colour;
60 }
61
62 wxBrush::wxBrush( const wxBitmap &stippleBitmap )
63 {
64 m_refData = new wxBrushRefData();
65 M_BRUSHDATA->m_colour = *wxBLACK;
66
67 M_BRUSHDATA->m_stipple = stippleBitmap;
68
69 if (M_BRUSHDATA->m_stipple.GetMask())
70 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
71 else
72 M_BRUSHDATA->m_style = wxSTIPPLE;
73 }
74
75 wxBrush::~wxBrush()
76 {
77 // m_refData unrefed in ~wxObject
78 }
79
80 wxObjectRefData *wxBrush::CreateRefData() const
81 {
82 return new wxBrushRefData;
83 }
84
85 wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
86 {
87 return new wxBrushRefData(*(wxBrushRefData *)data);
88 }
89
90 bool wxBrush::operator == ( const wxBrush& brush ) const
91 {
92 if (m_refData == brush.m_refData) return TRUE;
93
94 if (!m_refData || !brush.m_refData) return FALSE;
95
96 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
97 }
98
99 int wxBrush::GetStyle() const
100 {
101 if (m_refData == NULL)
102 {
103 wxFAIL_MSG( wxT("invalid brush") );
104 return 0;
105 }
106
107 return M_BRUSHDATA->m_style;
108 }
109
110 wxColour &wxBrush::GetColour() const
111 {
112 if (m_refData == NULL)
113 {
114 wxFAIL_MSG( wxT("invalid brush") );
115 return wxNullColour;
116 }
117
118 return M_BRUSHDATA->m_colour;
119 }
120
121 wxBitmap *wxBrush::GetStipple() const
122 {
123 if (m_refData == NULL)
124 {
125 wxFAIL_MSG( wxT("invalid brush") );
126 return &wxNullBitmap;
127 }
128
129 return &M_BRUSHDATA->m_stipple;
130 }
131
132 void wxBrush::SetColour( const wxColour& col )
133 {
134 AllocExclusive();
135
136 M_BRUSHDATA->m_colour = col;
137 }
138
139 void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
140 {
141 AllocExclusive();
142
143 M_BRUSHDATA->m_colour.Set( r, g, b );
144 }
145
146 void wxBrush::SetStyle( int style )
147 {
148 AllocExclusive();
149
150 M_BRUSHDATA->m_style = style;
151 }
152
153 void wxBrush::SetStipple( const wxBitmap& stipple )
154 {
155 AllocExclusive();
156
157 M_BRUSHDATA->m_stipple = stipple;
158 if (M_BRUSHDATA->m_stipple.GetMask())
159 {
160 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
161 }
162 else
163 {
164 M_BRUSHDATA->m_style = wxSTIPPLE;
165 }
166 }
167