]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: brush.cpp | |
3 | // Purpose: wxBrush | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
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 | ||
20 | #include "wx/mac/private.h" | |
21 | ||
22 | #if !USE_SHARED_LIBRARIES | |
23 | IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject) | |
24 | #endif | |
25 | ||
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 | ||
48 | wxBrushRefData::wxBrushRefData() | |
49 | : m_style(wxSOLID) | |
50 | { | |
51 | m_macBrushKind = kwxMacBrushColour ; | |
52 | } | |
53 | ||
54 | wxBrushRefData::wxBrushRefData(const wxBrushRefData& data) | |
55 | : wxGDIRefData() | |
56 | , m_style(data.m_style) | |
57 | { | |
58 | m_stipple = data.m_stipple; | |
59 | m_colour = data.m_colour; | |
60 | m_macBrushKind = data.m_macBrushKind ; | |
61 | m_macThemeBrush = data.m_macThemeBrush ; | |
62 | m_macThemeBackground = data.m_macThemeBackground ; | |
63 | m_macThemeBackgroundExtent = data.m_macThemeBackgroundExtent ; | |
64 | } | |
65 | ||
66 | wxBrushRefData::~wxBrushRefData() | |
67 | { | |
68 | } | |
69 | ||
70 | // Brushes | |
71 | wxBrush::wxBrush() | |
72 | { | |
73 | } | |
74 | ||
75 | wxBrush::~wxBrush() | |
76 | { | |
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(); | |
87 | } | |
88 | ||
89 | wxBrush::wxBrush(const wxBitmap& stipple) | |
90 | { | |
91 | m_refData = new wxBrushRefData; | |
92 | ||
93 | M_BRUSHDATA->m_colour = *wxBLACK; | |
94 | M_BRUSHDATA->m_stipple = stipple; | |
95 | ||
96 | if (M_BRUSHDATA->m_stipple.GetMask()) | |
97 | M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; | |
98 | else | |
99 | M_BRUSHDATA->m_style = wxSTIPPLE; | |
100 | ||
101 | RealizeResource(); | |
102 | } | |
103 | ||
104 | wxBrush::wxBrush(ThemeBrush macThemeBrush ) | |
105 | { | |
106 | m_refData = new wxBrushRefData; | |
107 | ||
108 | M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme; | |
109 | M_BRUSHDATA->m_macThemeBrush = macThemeBrush; | |
110 | ||
111 | RealizeResource(); | |
112 | } | |
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(); | |
131 | M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour; | |
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 | ||
141 | M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour; | |
142 | M_BRUSHDATA->m_colour.Set(r, g, b); | |
143 | ||
144 | RealizeResource(); | |
145 | } | |
146 | ||
147 | void wxBrush::SetStyle(int Style) | |
148 | { | |
149 | Unshare(); | |
150 | ||
151 | M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour; | |
152 | M_BRUSHDATA->m_style = Style; | |
153 | ||
154 | RealizeResource(); | |
155 | } | |
156 | ||
157 | void wxBrush::SetStipple(const wxBitmap& Stipple) | |
158 | { | |
159 | Unshare(); | |
160 | ||
161 | M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour; | |
162 | M_BRUSHDATA->m_stipple = Stipple; | |
163 | ||
164 | RealizeResource(); | |
165 | } | |
166 | ||
167 | void wxBrush::SetMacTheme(ThemeBrush macThemeBrush) | |
168 | { | |
169 | Unshare(); | |
170 | ||
171 | M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme; | |
172 | M_BRUSHDATA->m_macThemeBrush = macThemeBrush; | |
173 | ||
174 | RealizeResource(); | |
175 | } | |
176 | ||
177 | void wxBrush::SetMacThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent) | |
178 | { | |
179 | Unshare(); | |
180 | ||
181 | M_BRUSHDATA->m_macBrushKind = kwxMacBrushThemeBackground; | |
182 | M_BRUSHDATA->m_macThemeBackground = macThemeBackground; | |
183 | M_BRUSHDATA->m_macThemeBackgroundExtent = *(Rect*)extent ; | |
184 | RealizeResource(); | |
185 | } | |
186 | ||
187 | bool wxBrush::RealizeResource() | |
188 | { | |
189 | return TRUE; | |
190 | } | |
191 | ||
192 | unsigned long wxBrush::GetMacThemeBackground( WXRECTPTR extent) const | |
193 | { | |
194 | if ( M_BRUSHDATA && M_BRUSHDATA->m_macBrushKind == kwxMacBrushThemeBackground ) | |
195 | { | |
196 | if ( extent ) | |
197 | *(Rect*)extent = M_BRUSHDATA->m_macThemeBackgroundExtent ; | |
198 | return M_BRUSHDATA->m_macThemeBackground ; | |
199 | } | |
200 | else | |
201 | { | |
202 | return 0 ; | |
203 | } | |
204 | } | |
205 | ||
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 | }; |