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