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