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