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