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