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