]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: brush.cpp | |
3 | // Purpose: wxBrush | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
e9576ca5 SC |
9 | // Licence: wxWindows licence |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "brush.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/setup.h" | |
17 | #include "wx/utils.h" | |
18 | #include "wx/brush.h" | |
19 | ||
76a5e5d2 SC |
20 | #include "wx/mac/private.h" |
21 | ||
2f1ae414 | 22 | #if !USE_SHARED_LIBRARIES |
e9576ca5 | 23 | IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject) |
2f1ae414 | 24 | #endif |
e9576ca5 | 25 | |
76a5e5d2 SC |
26 | class WXDLLEXPORT wxBrushRefData: public wxGDIRefData |
27 | { | |
28 | friend class WXDLLEXPORT wxBrush; | |
29 | public: | |
30 | wxBrushRefData(); | |
31 | wxBrushRefData(const wxBrushRefData& data); | |
32 | ~wxBrushRefData(); | |
33 | ||
34 | protected: | |
35 | wxMacBrushKind m_macBrushKind ; | |
36 | int m_style; | |
37 | wxBitmap m_stipple ; | |
38 | wxColour m_colour; | |
39 | ||
40 | ThemeBrush m_macThemeBrush ; | |
41 | ||
42 | ThemeBackgroundKind m_macThemeBackground ; | |
43 | Rect m_macThemeBackgroundExtent ; | |
44 | }; | |
45 | ||
46 | #define M_BRUSHDATA ((wxBrushRefData *)m_refData) | |
47 | ||
e9576ca5 | 48 | wxBrushRefData::wxBrushRefData() |
d84afea9 | 49 | : m_style(wxSOLID) |
e9576ca5 | 50 | { |
7d9d1fd7 | 51 | m_macBrushKind = kwxMacBrushColour ; |
e9576ca5 SC |
52 | } |
53 | ||
54 | wxBrushRefData::wxBrushRefData(const wxBrushRefData& data) | |
d84afea9 GD |
55 | : wxGDIRefData() |
56 | , m_style(data.m_style) | |
e9576ca5 | 57 | { |
e9576ca5 SC |
58 | m_stipple = data.m_stipple; |
59 | m_colour = data.m_colour; | |
7d9d1fd7 | 60 | m_macBrushKind = data.m_macBrushKind ; |
1dcbbdcf | 61 | m_macThemeBrush = data.m_macThemeBrush ; |
7d9d1fd7 SC |
62 | m_macThemeBackground = data.m_macThemeBackground ; |
63 | m_macThemeBackgroundExtent = data.m_macThemeBackgroundExtent ; | |
e9576ca5 SC |
64 | } |
65 | ||
66 | wxBrushRefData::~wxBrushRefData() | |
67 | { | |
e9576ca5 SC |
68 | } |
69 | ||
70 | // Brushes | |
71 | wxBrush::wxBrush() | |
72 | { | |
e9576ca5 SC |
73 | } |
74 | ||
75 | wxBrush::~wxBrush() | |
76 | { | |
e9576ca5 SC |
77 | } |
78 | ||
79 | wxBrush::wxBrush(const wxColour& col, int Style) | |
80 | { | |
81 | m_refData = new wxBrushRefData; | |
82 | ||
83 | M_BRUSHDATA->m_colour = col; | |
84 | M_BRUSHDATA->m_style = Style; | |
85 | ||
86 | RealizeResource(); | |
e9576ca5 SC |
87 | } |
88 | ||
89 | wxBrush::wxBrush(const wxBitmap& stipple) | |
90 | { | |
91 | m_refData = new wxBrushRefData; | |
92 | ||
2b65eb68 | 93 | M_BRUSHDATA->m_colour = *wxBLACK; |
e9576ca5 | 94 | M_BRUSHDATA->m_stipple = stipple; |
2b65eb68 SC |
95 | |
96 | if (M_BRUSHDATA->m_stipple.GetMask()) | |
97 | M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; | |
98 | else | |
99 | M_BRUSHDATA->m_style = wxSTIPPLE; | |
e9576ca5 SC |
100 | |
101 | RealizeResource(); | |
e9576ca5 SC |
102 | } |
103 | ||
1dcbbdcf SC |
104 | wxBrush::wxBrush(ThemeBrush macThemeBrush ) |
105 | { | |
106 | m_refData = new wxBrushRefData; | |
107 | ||
7d9d1fd7 | 108 | M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme; |
1dcbbdcf SC |
109 | M_BRUSHDATA->m_macThemeBrush = macThemeBrush; |
110 | ||
111 | RealizeResource(); | |
112 | } | |
e9576ca5 SC |
113 | void wxBrush::Unshare() |
114 | { | |
115 | // Don't change shared data | |
116 | if (!m_refData) | |
117 | { | |
118 | m_refData = new wxBrushRefData(); | |
119 | } | |
120 | else | |
121 | { | |
122 | wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData); | |
123 | UnRef(); | |
124 | m_refData = ref; | |
125 | } | |
126 | } | |
127 | ||
128 | void wxBrush::SetColour(const wxColour& col) | |
129 | { | |
130 | Unshare(); | |
7d9d1fd7 | 131 | M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour; |
e9576ca5 SC |
132 | M_BRUSHDATA->m_colour = col; |
133 | ||
134 | RealizeResource(); | |
135 | } | |
136 | ||
137 | void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b) | |
138 | { | |
139 | Unshare(); | |
140 | ||
7d9d1fd7 | 141 | M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour; |
e9576ca5 SC |
142 | M_BRUSHDATA->m_colour.Set(r, g, b); |
143 | ||
144 | RealizeResource(); | |
145 | } | |
146 | ||
147 | void wxBrush::SetStyle(int Style) | |
148 | { | |
149 | Unshare(); | |
150 | ||
7d9d1fd7 | 151 | M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour; |
e9576ca5 SC |
152 | M_BRUSHDATA->m_style = Style; |
153 | ||
154 | RealizeResource(); | |
155 | } | |
156 | ||
157 | void wxBrush::SetStipple(const wxBitmap& Stipple) | |
158 | { | |
159 | Unshare(); | |
160 | ||
7d9d1fd7 | 161 | M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour; |
e9576ca5 SC |
162 | M_BRUSHDATA->m_stipple = Stipple; |
163 | ||
164 | RealizeResource(); | |
165 | } | |
166 | ||
1dcbbdcf SC |
167 | void wxBrush::SetMacTheme(ThemeBrush macThemeBrush) |
168 | { | |
169 | Unshare(); | |
170 | ||
7d9d1fd7 | 171 | M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme; |
1dcbbdcf SC |
172 | M_BRUSHDATA->m_macThemeBrush = macThemeBrush; |
173 | ||
174 | RealizeResource(); | |
175 | } | |
176 | ||
76a5e5d2 | 177 | void wxBrush::SetMacThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent) |
1dcbbdcf SC |
178 | { |
179 | Unshare(); | |
180 | ||
7d9d1fd7 | 181 | M_BRUSHDATA->m_macBrushKind = kwxMacBrushThemeBackground; |
1dcbbdcf | 182 | M_BRUSHDATA->m_macThemeBackground = macThemeBackground; |
76a5e5d2 | 183 | M_BRUSHDATA->m_macThemeBackgroundExtent = *(Rect*)extent ; |
1dcbbdcf SC |
184 | RealizeResource(); |
185 | } | |
186 | ||
e9576ca5 SC |
187 | bool wxBrush::RealizeResource() |
188 | { | |
519cb848 | 189 | return TRUE; |
e9576ca5 SC |
190 | } |
191 | ||
76a5e5d2 | 192 | unsigned long wxBrush::GetMacThemeBackground( WXRECTPTR extent) const |
7d9d1fd7 SC |
193 | { |
194 | if ( M_BRUSHDATA && M_BRUSHDATA->m_macBrushKind == kwxMacBrushThemeBackground ) | |
195 | { | |
196 | if ( extent ) | |
76a5e5d2 | 197 | *(Rect*)extent = M_BRUSHDATA->m_macThemeBackgroundExtent ; |
7d9d1fd7 SC |
198 | return M_BRUSHDATA->m_macThemeBackground ; |
199 | } | |
200 | else | |
201 | { | |
202 | return 0 ; | |
203 | } | |
204 | } | |
205 | ||
76a5e5d2 SC |
206 | short wxBrush::GetMacTheme() const |
207 | { | |
208 | return (M_BRUSHDATA ? ( M_BRUSHDATA->m_macBrushKind == kwxMacBrushTheme ? M_BRUSHDATA->m_macThemeBrush : kThemeBrushBlack) : kThemeBrushBlack); | |
209 | }; | |
210 | ||
211 | wxColour& wxBrush::GetColour() const | |
212 | { return (M_BRUSHDATA ? M_BRUSHDATA->m_colour : wxNullColour); }; | |
213 | ||
214 | int wxBrush::GetStyle() const | |
215 | { | |
216 | return (M_BRUSHDATA ? M_BRUSHDATA->m_style : 0); | |
217 | }; | |
218 | ||
219 | wxBitmap *wxBrush::GetStipple() const | |
220 | { | |
221 | return (M_BRUSHDATA ? & M_BRUSHDATA->m_stipple : 0); | |
222 | }; | |
223 | ||
224 | wxMacBrushKind wxBrush::MacGetBrushKind() const | |
225 | { | |
226 | return (M_BRUSHDATA ? M_BRUSHDATA->m_macBrushKind : kwxMacBrushColour); | |
227 | }; |