]>
Commit | Line | Data |
---|---|---|
9c7f49f5 | 1 | /////////////////////////////////////////////////////////////////////////////// |
7af14d71 | 2 | // Name: src/mac/carbon/renderer.cpp |
38c4cb6a | 3 | // Purpose: implementation of wxRendererNative for Mac |
9c7f49f5 VZ |
4 | // Author: Vadim Zeitlin |
5 | // Modified by: | |
6 | // Created: 20.07.2003 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org> | |
65571936 | 9 | // License: wxWindows licence |
9c7f49f5 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
9c7f49f5 VZ |
12 | // for compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #ifndef WX_PRECOMP | |
20 | #include "wx/string.h" | |
4c948343 VZ |
21 | #include "wx/dc.h" |
22 | #include "wx/bitmap.h" | |
23 | #include "wx/settings.h" | |
ed4b0fdc | 24 | #include "wx/dcclient.h" |
1832043f | 25 | #include "wx/toplevel.h" |
7af14d71 | 26 | #endif |
9c7f49f5 VZ |
27 | |
28 | #include "wx/renderer.h" | |
8acd14d1 | 29 | #include "wx/graphics.h" |
547aafd2 | 30 | #include "wx/mac/uma.h" |
9c7f49f5 | 31 | |
9c7f49f5 | 32 | |
5cb80ad2 | 33 | class WXDLLEXPORT wxRendererMac : public wxDelegateRendererNative |
9c7f49f5 VZ |
34 | { |
35 | public: | |
36 | // draw the header control button (used by wxListCtrl) | |
7af14d71 DS |
37 | virtual void DrawHeaderButton( wxWindow *win, |
38 | wxDC& dc, | |
39 | const wxRect& rect, | |
4b94ddc4 | 40 | int flags = 0, |
80752b57 | 41 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, |
4b94ddc4 | 42 | wxHeaderButtonParams* params = NULL ); |
9c7f49f5 | 43 | |
4b94ddc4 RD |
44 | virtual int GetHeaderButtonHeight(wxWindow *win); |
45 | ||
9c7f49f5 | 46 | // draw the expanded/collapsed icon for a tree control item |
7af14d71 DS |
47 | virtual void DrawTreeItemButton( wxWindow *win, |
48 | wxDC& dc, | |
49 | const wxRect& rect, | |
50 | int flags = 0 ); | |
9c7f49f5 | 51 | |
b3208e11 | 52 | // draw a (vertical) sash |
7af14d71 DS |
53 | virtual void DrawSplitterSash( wxWindow *win, |
54 | wxDC& dc, | |
55 | const wxSize& size, | |
56 | wxCoord position, | |
57 | wxOrientation orient, | |
58 | int flags = 0 ); | |
b3208e11 | 59 | |
9c7f49f5 VZ |
60 | private: |
61 | // the tree buttons | |
7af14d71 DS |
62 | wxBitmap m_bmpTreeExpanded; |
63 | wxBitmap m_bmpTreeCollapsed; | |
9c7f49f5 VZ |
64 | }; |
65 | ||
9c7f49f5 VZ |
66 | // ============================================================================ |
67 | // implementation | |
68 | // ============================================================================ | |
69 | ||
7af14d71 | 70 | // static |
f0244295 | 71 | wxRendererNative& wxRendererNative::GetDefault() |
9c7f49f5 VZ |
72 | { |
73 | static wxRendererMac s_rendererMac; | |
74 | ||
75 | return s_rendererMac; | |
76 | } | |
77 | ||
7af14d71 DS |
78 | void wxRendererMac::DrawHeaderButton( wxWindow *win, |
79 | wxDC& dc, | |
80 | const wxRect& rect, | |
4b94ddc4 | 81 | int flags, |
80752b57 | 82 | wxHeaderSortIconType sortArrow, |
4b94ddc4 | 83 | wxHeaderButtonParams* params ) |
9c7f49f5 | 84 | { |
2185a8a3 | 85 | #if !wxMAC_USE_CORE_GRAPHICS |
1c5decd0 SC |
86 | const wxCoord x = dc.LogicalToDeviceX(rect.x); |
87 | const wxCoord y = dc.LogicalToDeviceY(rect.y); | |
977d15a6 SC |
88 | const wxCoord w = dc.LogicalToDeviceXRel(rect.width); |
89 | const wxCoord h = dc.LogicalToDeviceYRel(rect.height); | |
1c5decd0 SC |
90 | #else |
91 | // now the wxGCDC is using native transformations | |
92 | const wxCoord x = rect.x; | |
93 | const wxCoord y = rect.y; | |
94 | const wxCoord w = rect.width; | |
95 | const wxCoord h = rect.height; | |
96 | #endif | |
7af14d71 | 97 | |
11d1adbf | 98 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); |
9c7f49f5 | 99 | |
a62f32af SC |
100 | HIRect headerRect = CGRectMake( x, y, w, h ); |
101 | if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) ) | |
2480cf88 | 102 | { |
a62f32af | 103 | Rect r = |
2480cf88 | 104 | { |
a62f32af SC |
105 | (short) headerRect.origin.y, (short) headerRect.origin.x, |
106 | (short) (headerRect.origin.y + headerRect.size.height), | |
107 | (short) (headerRect.origin.x + headerRect.size.width) | |
108 | }; | |
109 | ||
110 | RgnHandle updateRgn = NewRgn(); | |
111 | RectRgn( updateRgn, &r ); | |
112 | HIViewSetNeedsDisplayInRegion( (HIViewRef) win->GetHandle(), updateRgn, true ); | |
113 | DisposeRgn( updateRgn ); | |
114 | } | |
115 | else | |
116 | { | |
117 | CGContextRef cgContext; | |
7af14d71 | 118 | |
2480cf88 | 119 | #if wxMAC_USE_CORE_GRAPHICS |
be01a403 | 120 | cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext(); |
2480cf88 | 121 | #else |
a62f32af | 122 | Rect bounds; |
7af14d71 | 123 | |
a62f32af SC |
124 | GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds ); |
125 | QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); | |
7af14d71 | 126 | |
a62f32af SC |
127 | CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top ); |
128 | CGContextScaleCTM( cgContext, 1, -1 ); | |
7af14d71 | 129 | |
a62f32af SC |
130 | HIShapeReplacePathInCGContext( HIShapeCreateWithQDRgn( (RgnHandle) dc.m_macCurrentClipRgn ), cgContext ); |
131 | CGContextClip( cgContext ); | |
132 | HIViewConvertRect( &headerRect, (HIViewRef) win->GetHandle(), (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() ); | |
2480cf88 | 133 | #endif |
7af14d71 | 134 | |
a62f32af SC |
135 | { |
136 | HIThemeButtonDrawInfo drawInfo; | |
137 | HIRect labelRect; | |
7af14d71 | 138 | |
a62f32af SC |
139 | memset( &drawInfo, 0, sizeof(drawInfo) ); |
140 | drawInfo.version = 0; | |
a62f32af | 141 | drawInfo.kind = kThemeListHeaderButton; |
4b94ddc4 RD |
142 | drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive; |
143 | drawInfo.value = (flags & wxCONTROL_SELECTED) ? kThemeButtonOn : kThemeButtonOff; | |
a62f32af | 144 | drawInfo.adornment = kThemeAdornmentNone; |
4b94ddc4 RD |
145 | |
146 | // The down arrow is drawn automatically, change it to an up arrow if needed. | |
80752b57 | 147 | if ( sortArrow == wxHDR_SORT_ICON_UP ) |
4b94ddc4 RD |
148 | drawInfo.adornment = kThemeAdornmentHeaderButtonSortUp; |
149 | ||
a62f32af | 150 | HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect ); |
4b94ddc4 RD |
151 | |
152 | // If we don't want any arrows we need to draw over the one already there | |
80752b57 | 153 | if ( (flags & wxCONTROL_SELECTED) && (sortArrow == wxHDR_SORT_ICON_NONE) ) |
4b94ddc4 RD |
154 | { |
155 | // clip to the header rectangle | |
156 | CGContextSaveGState( cgContext ); | |
157 | CGContextClipToRect( cgContext, headerRect ); | |
158 | // but draw bigger than that so the arrow will get clipped off | |
159 | headerRect.size.width += 25; | |
160 | HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect ); | |
161 | CGContextRestoreGState( cgContext ); | |
162 | } | |
a62f32af | 163 | } |
7af14d71 | 164 | |
2480cf88 SC |
165 | #if wxMAC_USE_CORE_GRAPHICS |
166 | #else | |
a62f32af | 167 | QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); |
2480cf88 | 168 | #endif |
11d1adbf | 169 | } |
4b94ddc4 RD |
170 | |
171 | // Reserve room for the arrows before writing the label, and turn off the | |
172 | // flags we've already handled | |
173 | wxRect newRect(rect); | |
80752b57 | 174 | if ( (flags & wxCONTROL_SELECTED) && (sortArrow != wxHDR_SORT_ICON_NONE) ) |
4b94ddc4 RD |
175 | { |
176 | newRect.width -= 12; | |
80752b57 | 177 | sortArrow = wxHDR_SORT_ICON_NONE; |
4b94ddc4 | 178 | } |
80752b57 | 179 | flags &= ~wxCONTROL_SELECTED; |
4b94ddc4 | 180 | |
80752b57 | 181 | DrawHeaderButtonContents(win, dc, newRect, flags, sortArrow, params); |
4b94ddc4 RD |
182 | } |
183 | ||
184 | ||
185 | int wxRendererMac::GetHeaderButtonHeight(wxWindow* WXUNUSED(win)) | |
186 | { | |
187 | SInt32 standardHeight; | |
188 | OSStatus errStatus; | |
189 | ||
190 | errStatus = GetThemeMetric( kThemeMetricListHeaderHeight, &standardHeight ); | |
191 | if (errStatus == noErr) | |
192 | { | |
193 | return standardHeight; | |
194 | } | |
195 | return -1; | |
9c7f49f5 VZ |
196 | } |
197 | ||
7af14d71 DS |
198 | void wxRendererMac::DrawTreeItemButton( wxWindow *win, |
199 | wxDC& dc, | |
200 | const wxRect& rect, | |
201 | int flags ) | |
9c7f49f5 | 202 | { |
1c5decd0 SC |
203 | #if !wxMAC_USE_CORE_GRAPHICS |
204 | const wxCoord x = dc.LogicalToDeviceX(rect.x); | |
205 | const wxCoord y = dc.LogicalToDeviceY(rect.y); | |
46b59ead KO |
206 | const wxCoord w = dc.LogicalToDeviceXRel(rect.width); |
207 | const wxCoord h = dc.LogicalToDeviceYRel(rect.height); | |
f3d0a750 | 208 | #else |
1c5decd0 | 209 | // now the wxGCDC is using native transformations |
f3d0a750 RD |
210 | const wxCoord x = rect.x; |
211 | const wxCoord y = rect.y; | |
212 | const wxCoord w = rect.width; | |
213 | const wxCoord h = rect.height; | |
214 | #endif | |
1c5decd0 | 215 | |
46b59ead KO |
216 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); |
217 | ||
218 | HIRect headerRect = CGRectMake( x, y, w, h ); | |
219 | if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) ) | |
220 | { | |
221 | Rect r = | |
9c7f49f5 | 222 | { |
46b59ead KO |
223 | (short) headerRect.origin.y, (short) headerRect.origin.x, |
224 | (short) (headerRect.origin.y + headerRect.size.height), | |
225 | (short) (headerRect.origin.x + headerRect.size.width) | |
226 | }; | |
227 | ||
228 | RgnHandle updateRgn = NewRgn(); | |
229 | RectRgn( updateRgn, &r ); | |
230 | HIViewSetNeedsDisplayInRegion( (HIViewRef) win->GetHandle(), updateRgn, true ); | |
231 | DisposeRgn( updateRgn ); | |
9c7f49f5 | 232 | } |
46b59ead KO |
233 | else |
234 | { | |
235 | CGContextRef cgContext; | |
9c7f49f5 | 236 | |
46b59ead KO |
237 | #if wxMAC_USE_CORE_GRAPHICS |
238 | cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext(); | |
239 | #else | |
240 | Rect bounds; | |
9c7f49f5 | 241 | |
46b59ead KO |
242 | GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds ); |
243 | QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); | |
7af14d71 | 244 | |
46b59ead KO |
245 | CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top ); |
246 | CGContextScaleCTM( cgContext, 1, -1 ); | |
247 | ||
248 | HIShapeReplacePathInCGContext( HIShapeCreateWithQDRgn( (RgnHandle) dc.m_macCurrentClipRgn ), cgContext ); | |
249 | CGContextClip( cgContext ); | |
250 | HIViewConvertRect( &headerRect, (HIViewRef) win->GetHandle(), (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() ); | |
251 | #endif | |
7af14d71 | 252 | |
7af14d71 | 253 | { |
46b59ead KO |
254 | HIThemeButtonDrawInfo drawInfo; |
255 | HIRect labelRect; | |
256 | ||
257 | memset( &drawInfo, 0, sizeof(drawInfo) ); | |
258 | drawInfo.version = 0; | |
259 | drawInfo.kind = kThemeDisclosureButton; | |
260 | drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive; | |
261 | // Apple mailing list posts say to use the arrow adornment constants, but those don't work. | |
262 | // We need to set the value using the 'old' DrawThemeButton constants instead. | |
263 | drawInfo.value = (flags & wxCONTROL_EXPANDED) ? kThemeDisclosureDown : kThemeDisclosureRight; | |
264 | drawInfo.adornment = kThemeAdornmentNone; | |
265 | ||
266 | HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect ); | |
267 | ||
268 | } | |
269 | ||
270 | #if wxMAC_USE_CORE_GRAPHICS | |
271 | #else | |
272 | QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); | |
7af14d71 | 273 | #endif |
46b59ead | 274 | } |
9c7f49f5 VZ |
275 | } |
276 | ||
7af14d71 DS |
277 | void wxRendererMac::DrawSplitterSash( wxWindow *win, |
278 | wxDC& dc, | |
279 | const wxSize& size, | |
280 | wxCoord position, | |
281 | wxOrientation orient, | |
282 | int WXUNUSED(flags) ) | |
b3208e11 | 283 | { |
a62f32af SC |
284 | bool hasMetal = win->MacGetTopLevelWindow()->MacGetMetalAppearance(); |
285 | SInt32 height; | |
286 | GetThemeMetric( kThemeMetricSmallPaneSplitterHeight, &height ); | |
287 | HIRect splitterRect; | |
288 | if (orient == wxVERTICAL) | |
289 | splitterRect = CGRectMake( position, 0, height, size.y ); | |
290 | else | |
291 | splitterRect = CGRectMake( 0, position, size.x, height ); | |
7af14d71 | 292 | |
2480cf88 | 293 | #if !wxMAC_USE_CORE_GRAPHICS |
a62f32af SC |
294 | HIViewConvertRect( |
295 | &splitterRect, | |
296 | (HIViewRef) win->GetHandle(), | |
297 | (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() ); | |
2480cf88 | 298 | #endif |
547aafd2 | 299 | |
a62f32af SC |
300 | // under compositing we should only draw when called by the OS, otherwise just issue a redraw command |
301 | // strange redraw errors occur if we don't do this | |
547aafd2 | 302 | |
a62f32af SC |
303 | if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) ) |
304 | { | |
305 | Rect r = | |
547aafd2 | 306 | { |
a62f32af SC |
307 | (short) splitterRect.origin.y, |
308 | (short) splitterRect.origin.x, | |
309 | (short) (splitterRect.origin.y + splitterRect.size.height), | |
310 | (short) (splitterRect.origin.x + splitterRect.size.width) | |
311 | }; | |
312 | ||
313 | RgnHandle updateRgn = NewRgn(); | |
314 | RectRgn( updateRgn, &r ); | |
315 | HIViewSetNeedsDisplayInRegion( (HIViewRef) win->GetHandle(), updateRgn, true ); | |
316 | DisposeRgn( updateRgn ); | |
317 | } | |
318 | else | |
319 | { | |
320 | CGContextRef cgContext; | |
7af14d71 | 321 | |
20b69855 | 322 | #if wxMAC_USE_CORE_GRAPHICS |
be01a403 | 323 | cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext(); |
20b69855 | 324 | #else |
a62f32af SC |
325 | Rect bounds; |
326 | GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds ); | |
327 | QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); | |
328 | CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top ); | |
329 | CGContextScaleCTM( cgContext, 1, -1 ); | |
2480cf88 | 330 | #endif |
547aafd2 | 331 | |
a62f32af SC |
332 | HIThemeSplitterDrawInfo drawInfo; |
333 | drawInfo.version = 0; | |
334 | drawInfo.state = kThemeStateActive; | |
335 | drawInfo.adornment = hasMetal ? kHIThemeSplitterAdornmentMetal : kHIThemeSplitterAdornmentNone; | |
336 | HIThemeDrawPaneSplitter( &splitterRect, &drawInfo, cgContext, kHIThemeOrientationNormal ); | |
2480cf88 SC |
337 | |
338 | #if wxMAC_USE_CORE_GRAPHICS | |
339 | #else | |
a62f32af | 340 | QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); |
20b69855 | 341 | #endif |
547aafd2 | 342 | } |
b3208e11 | 343 | } |