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