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