]>
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) | |
c97c9952 | 37 | virtual int DrawHeaderButton( wxWindow *win, |
7af14d71 DS |
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 | 44 | virtual int GetHeaderButtonHeight(wxWindow *win); |
a61c9122 | 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 ); | |
cf511e87 RD |
59 | |
60 | virtual void DrawComboBoxDropButton(wxWindow *win, | |
61 | wxDC& dc, | |
62 | const wxRect& rect, | |
63 | int flags = 0); | |
a61c9122 | 64 | |
cf511e87 RD |
65 | virtual void DrawPushButton(wxWindow *win, |
66 | wxDC& dc, | |
67 | const wxRect& rect, | |
68 | int flags = 0); | |
a61c9122 | 69 | |
a4609ab8 KO |
70 | virtual void DrawItemSelectionRect(wxWindow *win, |
71 | wxDC& dc, | |
72 | const wxRect& rect, | |
73 | int flags = 0); | |
b3208e11 | 74 | |
688a201a JS |
75 | virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0); |
76 | ||
9c7f49f5 | 77 | private: |
cf511e87 RD |
78 | void DrawMacThemeButton(wxWindow *win, |
79 | wxDC& dc, | |
80 | const wxRect& rect, | |
81 | int flags, | |
82 | int kind, | |
83 | int adornment); | |
a61c9122 | 84 | |
9c7f49f5 | 85 | // the tree buttons |
7af14d71 DS |
86 | wxBitmap m_bmpTreeExpanded; |
87 | wxBitmap m_bmpTreeCollapsed; | |
9c7f49f5 VZ |
88 | }; |
89 | ||
9c7f49f5 VZ |
90 | // ============================================================================ |
91 | // implementation | |
92 | // ============================================================================ | |
93 | ||
7af14d71 | 94 | // static |
f0244295 | 95 | wxRendererNative& wxRendererNative::GetDefault() |
9c7f49f5 VZ |
96 | { |
97 | static wxRendererMac s_rendererMac; | |
98 | ||
99 | return s_rendererMac; | |
100 | } | |
101 | ||
c97c9952 | 102 | int wxRendererMac::DrawHeaderButton( wxWindow *win, |
7af14d71 DS |
103 | wxDC& dc, |
104 | const wxRect& rect, | |
4b94ddc4 | 105 | int flags, |
80752b57 | 106 | wxHeaderSortIconType sortArrow, |
4b94ddc4 | 107 | wxHeaderButtonParams* params ) |
9c7f49f5 | 108 | { |
2185a8a3 | 109 | #if !wxMAC_USE_CORE_GRAPHICS |
1c5decd0 SC |
110 | const wxCoord x = dc.LogicalToDeviceX(rect.x); |
111 | const wxCoord y = dc.LogicalToDeviceY(rect.y); | |
977d15a6 SC |
112 | const wxCoord w = dc.LogicalToDeviceXRel(rect.width); |
113 | const wxCoord h = dc.LogicalToDeviceYRel(rect.height); | |
1c5decd0 SC |
114 | #else |
115 | // now the wxGCDC is using native transformations | |
116 | const wxCoord x = rect.x; | |
117 | const wxCoord y = rect.y; | |
118 | const wxCoord w = rect.width; | |
119 | const wxCoord h = rect.height; | |
120 | #endif | |
7af14d71 | 121 | |
11d1adbf | 122 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); |
9c7f49f5 | 123 | |
a62f32af SC |
124 | HIRect headerRect = CGRectMake( x, y, w, h ); |
125 | if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) ) | |
2480cf88 | 126 | { |
a62f32af | 127 | Rect r = |
2480cf88 | 128 | { |
a62f32af SC |
129 | (short) headerRect.origin.y, (short) headerRect.origin.x, |
130 | (short) (headerRect.origin.y + headerRect.size.height), | |
131 | (short) (headerRect.origin.x + headerRect.size.width) | |
132 | }; | |
133 | ||
134 | RgnHandle updateRgn = NewRgn(); | |
135 | RectRgn( updateRgn, &r ); | |
136 | HIViewSetNeedsDisplayInRegion( (HIViewRef) win->GetHandle(), updateRgn, true ); | |
137 | DisposeRgn( updateRgn ); | |
138 | } | |
139 | else | |
140 | { | |
141 | CGContextRef cgContext; | |
7af14d71 | 142 | |
2480cf88 | 143 | #if wxMAC_USE_CORE_GRAPHICS |
be01a403 | 144 | cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext(); |
2480cf88 | 145 | #else |
a62f32af | 146 | Rect bounds; |
7af14d71 | 147 | |
a62f32af SC |
148 | GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds ); |
149 | QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); | |
7af14d71 | 150 | |
a62f32af SC |
151 | CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top ); |
152 | CGContextScaleCTM( cgContext, 1, -1 ); | |
7af14d71 | 153 | |
a62f32af SC |
154 | HIShapeReplacePathInCGContext( HIShapeCreateWithQDRgn( (RgnHandle) dc.m_macCurrentClipRgn ), cgContext ); |
155 | CGContextClip( cgContext ); | |
156 | HIViewConvertRect( &headerRect, (HIViewRef) win->GetHandle(), (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() ); | |
2480cf88 | 157 | #endif |
7af14d71 | 158 | |
a62f32af SC |
159 | { |
160 | HIThemeButtonDrawInfo drawInfo; | |
161 | HIRect labelRect; | |
7af14d71 | 162 | |
a62f32af SC |
163 | memset( &drawInfo, 0, sizeof(drawInfo) ); |
164 | drawInfo.version = 0; | |
a62f32af | 165 | drawInfo.kind = kThemeListHeaderButton; |
4b94ddc4 RD |
166 | drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive; |
167 | drawInfo.value = (flags & wxCONTROL_SELECTED) ? kThemeButtonOn : kThemeButtonOff; | |
a62f32af | 168 | drawInfo.adornment = kThemeAdornmentNone; |
4b94ddc4 RD |
169 | |
170 | // The down arrow is drawn automatically, change it to an up arrow if needed. | |
80752b57 | 171 | if ( sortArrow == wxHDR_SORT_ICON_UP ) |
4b94ddc4 | 172 | drawInfo.adornment = kThemeAdornmentHeaderButtonSortUp; |
a61c9122 | 173 | |
a62f32af | 174 | HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect ); |
4b94ddc4 RD |
175 | |
176 | // If we don't want any arrows we need to draw over the one already there | |
80752b57 | 177 | if ( (flags & wxCONTROL_SELECTED) && (sortArrow == wxHDR_SORT_ICON_NONE) ) |
4b94ddc4 RD |
178 | { |
179 | // clip to the header rectangle | |
180 | CGContextSaveGState( cgContext ); | |
181 | CGContextClipToRect( cgContext, headerRect ); | |
182 | // but draw bigger than that so the arrow will get clipped off | |
183 | headerRect.size.width += 25; | |
184 | HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect ); | |
185 | CGContextRestoreGState( cgContext ); | |
a61c9122 | 186 | } |
a62f32af | 187 | } |
7af14d71 | 188 | |
2480cf88 SC |
189 | #if wxMAC_USE_CORE_GRAPHICS |
190 | #else | |
a62f32af | 191 | QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); |
2480cf88 | 192 | #endif |
11d1adbf | 193 | } |
4b94ddc4 RD |
194 | |
195 | // Reserve room for the arrows before writing the label, and turn off the | |
196 | // flags we've already handled | |
197 | wxRect newRect(rect); | |
80752b57 | 198 | if ( (flags & wxCONTROL_SELECTED) && (sortArrow != wxHDR_SORT_ICON_NONE) ) |
4b94ddc4 RD |
199 | { |
200 | newRect.width -= 12; | |
80752b57 | 201 | sortArrow = wxHDR_SORT_ICON_NONE; |
4b94ddc4 | 202 | } |
80752b57 | 203 | flags &= ~wxCONTROL_SELECTED; |
4b94ddc4 | 204 | |
c97c9952 | 205 | return DrawHeaderButtonContents(win, dc, newRect, flags, sortArrow, params); |
4b94ddc4 RD |
206 | } |
207 | ||
208 | ||
209 | int wxRendererMac::GetHeaderButtonHeight(wxWindow* WXUNUSED(win)) | |
210 | { | |
688a201a JS |
211 | SInt32 standardHeight; |
212 | OSStatus errStatus; | |
4b94ddc4 RD |
213 | |
214 | errStatus = GetThemeMetric( kThemeMetricListHeaderHeight, &standardHeight ); | |
215 | if (errStatus == noErr) | |
216 | { | |
217 | return standardHeight; | |
218 | } | |
219 | return -1; | |
9c7f49f5 VZ |
220 | } |
221 | ||
7af14d71 DS |
222 | void wxRendererMac::DrawTreeItemButton( wxWindow *win, |
223 | wxDC& dc, | |
224 | const wxRect& rect, | |
225 | int flags ) | |
9c7f49f5 | 226 | { |
1c5decd0 SC |
227 | #if !wxMAC_USE_CORE_GRAPHICS |
228 | const wxCoord x = dc.LogicalToDeviceX(rect.x); | |
229 | const wxCoord y = dc.LogicalToDeviceY(rect.y); | |
46b59ead KO |
230 | const wxCoord w = dc.LogicalToDeviceXRel(rect.width); |
231 | const wxCoord h = dc.LogicalToDeviceYRel(rect.height); | |
f3d0a750 | 232 | #else |
1c5decd0 | 233 | // now the wxGCDC is using native transformations |
f3d0a750 RD |
234 | const wxCoord x = rect.x; |
235 | const wxCoord y = rect.y; | |
236 | const wxCoord w = rect.width; | |
237 | const wxCoord h = rect.height; | |
a61c9122 | 238 | #endif |
1c5decd0 | 239 | |
46b59ead KO |
240 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); |
241 | ||
242 | HIRect headerRect = CGRectMake( x, y, w, h ); | |
243 | if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) ) | |
244 | { | |
245 | Rect r = | |
9c7f49f5 | 246 | { |
46b59ead KO |
247 | (short) headerRect.origin.y, (short) headerRect.origin.x, |
248 | (short) (headerRect.origin.y + headerRect.size.height), | |
249 | (short) (headerRect.origin.x + headerRect.size.width) | |
250 | }; | |
251 | ||
252 | RgnHandle updateRgn = NewRgn(); | |
253 | RectRgn( updateRgn, &r ); | |
254 | HIViewSetNeedsDisplayInRegion( (HIViewRef) win->GetHandle(), updateRgn, true ); | |
255 | DisposeRgn( updateRgn ); | |
9c7f49f5 | 256 | } |
46b59ead KO |
257 | else |
258 | { | |
259 | CGContextRef cgContext; | |
9c7f49f5 | 260 | |
46b59ead KO |
261 | #if wxMAC_USE_CORE_GRAPHICS |
262 | cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext(); | |
263 | #else | |
264 | Rect bounds; | |
9c7f49f5 | 265 | |
46b59ead KO |
266 | GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds ); |
267 | QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); | |
7af14d71 | 268 | |
46b59ead KO |
269 | CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top ); |
270 | CGContextScaleCTM( cgContext, 1, -1 ); | |
271 | ||
272 | HIShapeReplacePathInCGContext( HIShapeCreateWithQDRgn( (RgnHandle) dc.m_macCurrentClipRgn ), cgContext ); | |
273 | CGContextClip( cgContext ); | |
274 | HIViewConvertRect( &headerRect, (HIViewRef) win->GetHandle(), (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() ); | |
275 | #endif | |
7af14d71 | 276 | |
7af14d71 | 277 | { |
46b59ead KO |
278 | HIThemeButtonDrawInfo drawInfo; |
279 | HIRect labelRect; | |
280 | ||
281 | memset( &drawInfo, 0, sizeof(drawInfo) ); | |
282 | drawInfo.version = 0; | |
283 | drawInfo.kind = kThemeDisclosureButton; | |
284 | drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive; | |
285 | // Apple mailing list posts say to use the arrow adornment constants, but those don't work. | |
286 | // We need to set the value using the 'old' DrawThemeButton constants instead. | |
287 | drawInfo.value = (flags & wxCONTROL_EXPANDED) ? kThemeDisclosureDown : kThemeDisclosureRight; | |
a61c9122 | 288 | drawInfo.adornment = kThemeAdornmentNone; |
46b59ead KO |
289 | |
290 | HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect ); | |
a61c9122 | 291 | |
46b59ead KO |
292 | } |
293 | ||
294 | #if wxMAC_USE_CORE_GRAPHICS | |
295 | #else | |
296 | QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); | |
7af14d71 | 297 | #endif |
46b59ead | 298 | } |
9c7f49f5 VZ |
299 | } |
300 | ||
7af14d71 DS |
301 | void wxRendererMac::DrawSplitterSash( wxWindow *win, |
302 | wxDC& dc, | |
303 | const wxSize& size, | |
304 | wxCoord position, | |
305 | wxOrientation orient, | |
306 | int WXUNUSED(flags) ) | |
b3208e11 | 307 | { |
a62f32af SC |
308 | bool hasMetal = win->MacGetTopLevelWindow()->MacGetMetalAppearance(); |
309 | SInt32 height; | |
310 | GetThemeMetric( kThemeMetricSmallPaneSplitterHeight, &height ); | |
311 | HIRect splitterRect; | |
312 | if (orient == wxVERTICAL) | |
313 | splitterRect = CGRectMake( position, 0, height, size.y ); | |
314 | else | |
315 | splitterRect = CGRectMake( 0, position, size.x, height ); | |
7af14d71 | 316 | |
2480cf88 | 317 | #if !wxMAC_USE_CORE_GRAPHICS |
a62f32af SC |
318 | HIViewConvertRect( |
319 | &splitterRect, | |
320 | (HIViewRef) win->GetHandle(), | |
321 | (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() ); | |
2480cf88 | 322 | #endif |
547aafd2 | 323 | |
a62f32af SC |
324 | // under compositing we should only draw when called by the OS, otherwise just issue a redraw command |
325 | // strange redraw errors occur if we don't do this | |
547aafd2 | 326 | |
a62f32af SC |
327 | if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) ) |
328 | { | |
329 | Rect r = | |
547aafd2 | 330 | { |
a62f32af SC |
331 | (short) splitterRect.origin.y, |
332 | (short) splitterRect.origin.x, | |
333 | (short) (splitterRect.origin.y + splitterRect.size.height), | |
334 | (short) (splitterRect.origin.x + splitterRect.size.width) | |
335 | }; | |
336 | ||
337 | RgnHandle updateRgn = NewRgn(); | |
338 | RectRgn( updateRgn, &r ); | |
339 | HIViewSetNeedsDisplayInRegion( (HIViewRef) win->GetHandle(), updateRgn, true ); | |
340 | DisposeRgn( updateRgn ); | |
341 | } | |
342 | else | |
343 | { | |
344 | CGContextRef cgContext; | |
7af14d71 | 345 | |
20b69855 | 346 | #if wxMAC_USE_CORE_GRAPHICS |
be01a403 | 347 | cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext(); |
20b69855 | 348 | #else |
a62f32af SC |
349 | Rect bounds; |
350 | GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds ); | |
351 | QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); | |
352 | CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top ); | |
353 | CGContextScaleCTM( cgContext, 1, -1 ); | |
2480cf88 | 354 | #endif |
547aafd2 | 355 | |
a62f32af SC |
356 | HIThemeSplitterDrawInfo drawInfo; |
357 | drawInfo.version = 0; | |
358 | drawInfo.state = kThemeStateActive; | |
359 | drawInfo.adornment = hasMetal ? kHIThemeSplitterAdornmentMetal : kHIThemeSplitterAdornmentNone; | |
360 | HIThemeDrawPaneSplitter( &splitterRect, &drawInfo, cgContext, kHIThemeOrientationNormal ); | |
2480cf88 SC |
361 | |
362 | #if wxMAC_USE_CORE_GRAPHICS | |
363 | #else | |
a62f32af | 364 | QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); |
20b69855 | 365 | #endif |
547aafd2 | 366 | } |
b3208e11 | 367 | } |
a4609ab8 KO |
368 | |
369 | void | |
370 | wxRendererMac::DrawItemSelectionRect(wxWindow *win, | |
371 | wxDC& dc, | |
372 | const wxRect& rect, | |
373 | int flags ) | |
374 | { | |
055de350 VZ |
375 | if ( !(flags & wxCONTROL_SELECTED) ) |
376 | return; | |
ce0cf2b8 RR |
377 | |
378 | if (flags & wxCONTROL_FOCUSED) | |
379 | { | |
380 | if (!IsControlActive( (ControlRef)win->GetHandle() )) | |
381 | flags = wxCONTROL_SELECTED; | |
382 | } | |
055de350 | 383 | |
a61c9122 | 384 | RGBColor selColor; |
055de350 VZ |
385 | GetThemeBrushAsColor(flags & wxCONTROL_FOCUSED |
386 | ? kThemeBrushAlternatePrimaryHighlightColor | |
387 | : kThemeBrushSecondaryHighlightColor, | |
388 | 32, true, &selColor); | |
a61c9122 | 389 | |
055de350 | 390 | wxBrush selBrush(selColor); |
a4609ab8 KO |
391 | |
392 | dc.SetPen( *wxTRANSPARENT_PEN ); | |
393 | dc.SetBrush( selBrush ); | |
394 | dc.DrawRectangle( rect ); | |
395 | } | |
cf511e87 RD |
396 | |
397 | ||
398 | void | |
399 | wxRendererMac::DrawMacThemeButton(wxWindow *win, | |
400 | wxDC& dc, | |
401 | const wxRect& rect, | |
402 | int flags, | |
403 | int kind, | |
404 | int adornment) | |
405 | { | |
406 | #if !wxMAC_USE_CORE_GRAPHICS | |
407 | const wxCoord x = dc.LogicalToDeviceX(rect.x); | |
408 | const wxCoord y = dc.LogicalToDeviceY(rect.y); | |
409 | const wxCoord w = dc.LogicalToDeviceXRel(rect.width); | |
410 | const wxCoord h = dc.LogicalToDeviceYRel(rect.height); | |
411 | #else | |
412 | // now the wxGCDC is using native transformations | |
413 | const wxCoord x = rect.x; | |
414 | const wxCoord y = rect.y; | |
415 | const wxCoord w = rect.width; | |
416 | const wxCoord h = rect.height; | |
417 | #endif | |
418 | ||
419 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
420 | ||
421 | HIRect headerRect = CGRectMake( x, y, w, h ); | |
422 | if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) ) | |
423 | { | |
424 | Rect r = | |
425 | { | |
426 | (short) headerRect.origin.y, (short) headerRect.origin.x, | |
427 | (short) (headerRect.origin.y + headerRect.size.height), | |
428 | (short) (headerRect.origin.x + headerRect.size.width) | |
429 | }; | |
430 | ||
431 | RgnHandle updateRgn = NewRgn(); | |
432 | RectRgn( updateRgn, &r ); | |
433 | HIViewSetNeedsDisplayInRegion( (HIViewRef) win->GetHandle(), updateRgn, true ); | |
434 | DisposeRgn( updateRgn ); | |
435 | } | |
436 | else | |
437 | { | |
438 | CGContextRef cgContext; | |
439 | ||
440 | #if wxMAC_USE_CORE_GRAPHICS | |
441 | cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext(); | |
442 | #else | |
443 | Rect bounds; | |
444 | ||
445 | GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds ); | |
446 | QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); | |
447 | ||
448 | CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top ); | |
449 | CGContextScaleCTM( cgContext, 1, -1 ); | |
450 | ||
451 | HIShapeReplacePathInCGContext( HIShapeCreateWithQDRgn( (RgnHandle) dc.m_macCurrentClipRgn ), cgContext ); | |
452 | CGContextClip( cgContext ); | |
453 | HIViewConvertRect( &headerRect, (HIViewRef) win->GetHandle(), (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() ); | |
454 | #endif | |
455 | ||
456 | { | |
457 | HIThemeButtonDrawInfo drawInfo; | |
458 | HIRect labelRect; | |
459 | ||
460 | memset( &drawInfo, 0, sizeof(drawInfo) ); | |
461 | drawInfo.version = 0; | |
462 | drawInfo.kind = kind; | |
463 | drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive; | |
464 | drawInfo.value = (flags & wxCONTROL_SELECTED) ? kThemeButtonOn : kThemeButtonOff; | |
465 | drawInfo.adornment = adornment; | |
466 | ||
467 | HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect ); | |
468 | } | |
469 | ||
470 | #if wxMAC_USE_CORE_GRAPHICS | |
471 | #else | |
472 | QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); | |
473 | #endif | |
474 | } | |
475 | } | |
476 | ||
477 | ||
478 | void | |
479 | wxRendererMac::DrawComboBoxDropButton(wxWindow *win, | |
480 | wxDC& dc, | |
481 | const wxRect& rect, | |
482 | int flags) | |
483 | { | |
f8e1a81f | 484 | int kind; |
a61c9122 | 485 | if (win->GetWindowVariant() == wxWINDOW_VARIANT_SMALL || (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_SMALL)) |
f8e1a81f | 486 | kind = kThemeArrowButtonSmall; |
a61c9122 | 487 | else if (win->GetWindowVariant() == wxWINDOW_VARIANT_MINI || (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_MINI)) |
f8e1a81f JS |
488 | kind = kThemeArrowButtonMini; |
489 | else | |
490 | kind = kThemeArrowButton; | |
a61c9122 | 491 | |
cf511e87 | 492 | DrawMacThemeButton(win, dc, rect, flags, |
f8e1a81f | 493 | kind, kThemeAdornmentArrowDownArrow); |
cf511e87 | 494 | } |
a61c9122 | 495 | |
cf511e87 RD |
496 | void |
497 | wxRendererMac::DrawPushButton(wxWindow *win, | |
498 | wxDC& dc, | |
499 | const wxRect& rect, | |
500 | int flags) | |
501 | { | |
f8e1a81f | 502 | int kind; |
a61c9122 JS |
503 | if (win->GetWindowVariant() == wxWINDOW_VARIANT_SMALL || (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_SMALL)) |
504 | kind = kThemeBevelButtonSmall; | |
505 | // There is no kThemeBevelButtonMini, but in this case, use Small | |
506 | else if (win->GetWindowVariant() == wxWINDOW_VARIANT_MINI || (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_MINI)) | |
f8e1a81f JS |
507 | kind = kThemeBevelButtonSmall; |
508 | else | |
509 | kind = kThemeBevelButton; | |
510 | ||
cf511e87 | 511 | DrawMacThemeButton(win, dc, rect, flags, |
f8e1a81f | 512 | kind, kThemeAdornmentNone); |
cf511e87 | 513 | } |
a61c9122 | 514 | |
688a201a JS |
515 | void |
516 | wxRendererMac::DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) | |
517 | { | |
518 | if (!win) | |
519 | { | |
520 | wxDelegateRendererNative::DrawFocusRect(win, dc, rect, flags); | |
521 | return; | |
522 | } | |
523 | ||
524 | #if wxMAC_USE_CORE_GRAPHICS | |
525 | { | |
526 | CGRect cgrect = CGRectMake( rect.x , rect.y , rect.width, rect.height ) ; | |
527 | ||
528 | HIThemeFrameDrawInfo info ; | |
529 | memset( &info, 0 , sizeof(info) ) ; | |
530 | ||
531 | info.version = 0 ; | |
532 | info.kind = 0 ; | |
533 | info.state = kThemeStateActive; | |
534 | info.isFocused = true ; | |
535 | ||
536 | CGContextRef cgContext = (CGContextRef) win->MacGetCGContextRef() ; | |
537 | wxASSERT( cgContext ) ; | |
538 | ||
539 | HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ; | |
540 | } | |
541 | #else | |
542 | // FIXME: not yet working for !wxMAC_USE_CORE_GRAPHICS | |
543 | { | |
544 | Rect r; | |
545 | r.left = rect.x; r.top = rect.y; r.right = rect.GetRight(); r.bottom = rect.GetBottom(); | |
546 | wxTopLevelWindowMac* top = win->MacGetTopLevelWindow(); | |
547 | if ( top ) | |
548 | { | |
549 | wxPoint pt(0, 0) ; | |
550 | wxMacControl::Convert( &pt , win->GetPeer() , top->GetPeer() ) ; | |
551 | OffsetRect( &r , pt.x , pt.y ) ; | |
552 | } | |
553 | ||
554 | DrawThemeFocusRect( &r , true ) ; | |
555 | } | |
556 | #endif | |
557 | } | |
558 |