]> git.saurik.com Git - wxWidgets.git/blob - src/x11/brush.cpp
removed gtk.h include
[wxWidgets.git] / src / x11 / brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/x11/brush.cpp
3 // Purpose: wxBrush
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "brush.h"
14 #endif
15
16 #include "wx/setup.h"
17 #include "wx/utils.h"
18 #include "wx/brush.h"
19 #include "wx/bitmap.h"
20 #include "wx/colour.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 {
36 m_style = data.m_style;
37 m_stipple = data.m_stipple;
38 m_colour = data.m_colour;
39 }
40
41 bool operator == (const wxBrushRefData& data) const
42 {
43 return (m_style == data.m_style &&
44 m_stipple == data.m_stipple &&
45 m_colour == data.m_colour);
46 }
47
48 int m_style;
49 wxColour m_colour;
50 wxBitmap m_stipple;
51 };
52
53 //-----------------------------------------------------------------------------
54
55 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
56
57 IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
58
59 wxBrush::wxBrush( const wxColour &colour, int style )
60 {
61 m_refData = new wxBrushRefData();
62 M_BRUSHDATA->m_style = style;
63 M_BRUSHDATA->m_colour = colour;
64 }
65
66 wxBrush::wxBrush( const wxBitmap &stippleBitmap )
67 {
68 m_refData = new wxBrushRefData();
69 M_BRUSHDATA->m_colour = *wxBLACK;
70
71 M_BRUSHDATA->m_stipple = stippleBitmap;
72
73 if (M_BRUSHDATA->m_stipple.GetMask())
74 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
75 else
76 M_BRUSHDATA->m_style = wxSTIPPLE;
77 }
78
79 wxBrush::~wxBrush()
80 {
81 // m_refData unrefed in ~wxObject
82 }
83
84 wxObjectRefData *wxBrush::CreateRefData() const
85 {
86 return new wxBrushRefData;
87 }
88
89 wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
90 {
91 return new wxBrushRefData(*(wxBrushRefData *)data);
92 }
93
94 bool wxBrush::operator == ( const wxBrush& brush ) const
95 {
96 if (m_refData == brush.m_refData) return TRUE;
97
98 if (!m_refData || !brush.m_refData) return FALSE;
99
100 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
101 }
102
103 int wxBrush::GetStyle() const
104 {
105 if (m_refData == NULL)
106 {
107 wxFAIL_MSG( wxT("invalid brush") );
108 return 0;
109 }
110
111 return M_BRUSHDATA->m_style;
112 }
113
114 wxColour &wxBrush::GetColour() const
115 {
116 if (m_refData == NULL)
117 {
118 wxFAIL_MSG( wxT("invalid brush") );
119 return wxNullColour;
120 }
121
122 return M_BRUSHDATA->m_colour;
123 }
124
125 wxBitmap *wxBrush::GetStipple() const
126 {
127 if (m_refData == NULL)
128 {
129 wxFAIL_MSG( wxT("invalid brush") );
130 return &wxNullBitmap;
131 }
132
133 return &M_BRUSHDATA->m_stipple;
134 }
135
136 void wxBrush::SetColour( const wxColour& col )
137 {
138 AllocExclusive();
139
140 M_BRUSHDATA->m_colour = col;
141 }
142
143 void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
144 {
145 AllocExclusive();
146
147 M_BRUSHDATA->m_colour.Set( r, g, b );
148 }
149
150 void wxBrush::SetStyle( int style )
151 {
152 AllocExclusive();
153
154 M_BRUSHDATA->m_style = style;
155 }
156
157 void wxBrush::SetStipple( const wxBitmap& stipple )
158 {
159 AllocExclusive();
160
161 M_BRUSHDATA->m_stipple = stipple;
162 if (M_BRUSHDATA->m_stipple.GetMask())
163 {
164 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
165 }
166 else
167 {
168 M_BRUSHDATA->m_style = wxSTIPPLE;
169 }
170 }