1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/renderer.cpp
3 // Purpose: implementation of wxRendererNative for Mac
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // for compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
20 #include "wx/string.h"
22 #include "wx/bitmap.h"
23 #include "wx/settings.h"
24 #include "wx/dcclient.h"
25 #include "wx/toplevel.h"
28 #include "wx/renderer.h"
29 #include "wx/graphics.h"
30 #include "wx/mac/uma.h"
33 class WXDLLEXPORT wxRendererMac
: public wxDelegateRendererNative
36 // draw the header control button (used by wxListCtrl)
37 virtual void DrawHeaderButton( wxWindow
*win
,
41 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
42 wxHeaderButtonParams
* params
= NULL
);
44 virtual int GetHeaderButtonHeight(wxWindow
*win
);
46 // draw the expanded/collapsed icon for a tree control item
47 virtual void DrawTreeItemButton( wxWindow
*win
,
52 // draw a (vertical) sash
53 virtual void DrawSplitterSash( wxWindow
*win
,
62 wxBitmap m_bmpTreeExpanded
;
63 wxBitmap m_bmpTreeCollapsed
;
66 // ============================================================================
68 // ============================================================================
71 wxRendererNative
& wxRendererNative::GetDefault()
73 static wxRendererMac s_rendererMac
;
78 void wxRendererMac::DrawHeaderButton( wxWindow
*win
,
82 wxHeaderSortIconType sortArrow
,
83 wxHeaderButtonParams
* params
)
85 const wxCoord x
= dc
.LogicalToDeviceX(rect
.x
/*- 1*/);
86 const wxCoord y
= dc
.LogicalToDeviceY(rect
.y
/*- 1*/);
87 const wxCoord w
= dc
.LogicalToDeviceXRel(rect
.width
);
88 const wxCoord h
= dc
.LogicalToDeviceYRel(rect
.height
);
90 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
92 HIRect headerRect
= CGRectMake( x
, y
, w
, h
);
93 if ( !dc
.IsKindOf( CLASSINFO( wxPaintDC
) ) )
97 (short) headerRect
.origin
.y
, (short) headerRect
.origin
.x
,
98 (short) (headerRect
.origin
.y
+ headerRect
.size
.height
),
99 (short) (headerRect
.origin
.x
+ headerRect
.size
.width
)
102 RgnHandle updateRgn
= NewRgn();
103 RectRgn( updateRgn
, &r
);
104 HIViewSetNeedsDisplayInRegion( (HIViewRef
) win
->GetHandle(), updateRgn
, true );
105 DisposeRgn( updateRgn
);
109 CGContextRef cgContext
;
111 #if wxMAC_USE_CORE_GRAPHICS
112 cgContext
= (CGContextRef
) dc
.GetGraphicsContext()->GetNativeContext();
116 GetPortBounds( (CGrafPtr
) dc
.m_macPort
, &bounds
);
117 QDBeginCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
119 CGContextTranslateCTM( cgContext
, 0, bounds
.bottom
- bounds
.top
);
120 CGContextScaleCTM( cgContext
, 1, -1 );
122 HIShapeReplacePathInCGContext( HIShapeCreateWithQDRgn( (RgnHandle
) dc
.m_macCurrentClipRgn
), cgContext
);
123 CGContextClip( cgContext
);
124 HIViewConvertRect( &headerRect
, (HIViewRef
) win
->GetHandle(), (HIViewRef
) win
->MacGetTopLevelWindow()->GetHandle() );
128 HIThemeButtonDrawInfo drawInfo
;
131 memset( &drawInfo
, 0, sizeof(drawInfo
) );
132 drawInfo
.version
= 0;
133 drawInfo
.kind
= kThemeListHeaderButton
;
134 drawInfo
.state
= (flags
& wxCONTROL_DISABLED
) ? kThemeStateInactive
: kThemeStateActive
;
135 drawInfo
.value
= (flags
& wxCONTROL_SELECTED
) ? kThemeButtonOn
: kThemeButtonOff
;
136 drawInfo
.adornment
= kThemeAdornmentNone
;
138 // The down arrow is drawn automatically, change it to an up arrow if needed.
139 if ( sortArrow
== wxHDR_SORT_ICON_UP
)
140 drawInfo
.adornment
= kThemeAdornmentHeaderButtonSortUp
;
142 HIThemeDrawButton( &headerRect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
, &labelRect
);
144 // If we don't want any arrows we need to draw over the one already there
145 if ( (flags
& wxCONTROL_SELECTED
) && (sortArrow
== wxHDR_SORT_ICON_NONE
) )
147 // clip to the header rectangle
148 CGContextSaveGState( cgContext
);
149 CGContextClipToRect( cgContext
, headerRect
);
150 // but draw bigger than that so the arrow will get clipped off
151 headerRect
.size
.width
+= 25;
152 HIThemeDrawButton( &headerRect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
, &labelRect
);
153 CGContextRestoreGState( cgContext
);
157 #if wxMAC_USE_CORE_GRAPHICS
159 QDEndCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
163 // Reserve room for the arrows before writing the label, and turn off the
164 // flags we've already handled
165 wxRect
newRect(rect
);
166 if ( (flags
& wxCONTROL_SELECTED
) && (sortArrow
!= wxHDR_SORT_ICON_NONE
) )
169 sortArrow
= wxHDR_SORT_ICON_NONE
;
171 flags
&= ~wxCONTROL_SELECTED
;
173 DrawHeaderButtonContents(win
, dc
, newRect
, flags
, sortArrow
, params
);
177 int wxRendererMac::GetHeaderButtonHeight(wxWindow
* WXUNUSED(win
))
179 SInt32 standardHeight
;
182 errStatus
= GetThemeMetric( kThemeMetricListHeaderHeight
, &standardHeight
);
183 if (errStatus
== noErr
)
185 return standardHeight
;
190 void wxRendererMac::DrawTreeItemButton( wxWindow
*win
,
195 const wxCoord x
= dc
.LogicalToDeviceX(rect
.x
/*- 1*/);
196 const wxCoord y
= dc
.LogicalToDeviceY(rect
.y
/*- 1*/);
197 const wxCoord w
= dc
.LogicalToDeviceXRel(rect
.width
);
198 const wxCoord h
= dc
.LogicalToDeviceYRel(rect
.height
);
200 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
202 HIRect headerRect
= CGRectMake( x
, y
, w
, h
);
203 if ( !dc
.IsKindOf( CLASSINFO( wxPaintDC
) ) )
207 (short) headerRect
.origin
.y
, (short) headerRect
.origin
.x
,
208 (short) (headerRect
.origin
.y
+ headerRect
.size
.height
),
209 (short) (headerRect
.origin
.x
+ headerRect
.size
.width
)
212 RgnHandle updateRgn
= NewRgn();
213 RectRgn( updateRgn
, &r
);
214 HIViewSetNeedsDisplayInRegion( (HIViewRef
) win
->GetHandle(), updateRgn
, true );
215 DisposeRgn( updateRgn
);
219 CGContextRef cgContext
;
221 #if wxMAC_USE_CORE_GRAPHICS
222 cgContext
= (CGContextRef
) dc
.GetGraphicsContext()->GetNativeContext();
226 GetPortBounds( (CGrafPtr
) dc
.m_macPort
, &bounds
);
227 QDBeginCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
229 CGContextTranslateCTM( cgContext
, 0, bounds
.bottom
- bounds
.top
);
230 CGContextScaleCTM( cgContext
, 1, -1 );
232 HIShapeReplacePathInCGContext( HIShapeCreateWithQDRgn( (RgnHandle
) dc
.m_macCurrentClipRgn
), cgContext
);
233 CGContextClip( cgContext
);
234 HIViewConvertRect( &headerRect
, (HIViewRef
) win
->GetHandle(), (HIViewRef
) win
->MacGetTopLevelWindow()->GetHandle() );
238 HIThemeButtonDrawInfo drawInfo
;
241 memset( &drawInfo
, 0, sizeof(drawInfo
) );
242 drawInfo
.version
= 0;
243 drawInfo
.kind
= kThemeDisclosureButton
;
244 drawInfo
.state
= (flags
& wxCONTROL_DISABLED
) ? kThemeStateInactive
: kThemeStateActive
;
245 // Apple mailing list posts say to use the arrow adornment constants, but those don't work.
246 // We need to set the value using the 'old' DrawThemeButton constants instead.
247 drawInfo
.value
= (flags
& wxCONTROL_EXPANDED
) ? kThemeDisclosureDown
: kThemeDisclosureRight
;
248 drawInfo
.adornment
= kThemeAdornmentNone
;
250 HIThemeDrawButton( &headerRect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
, &labelRect
);
254 #if wxMAC_USE_CORE_GRAPHICS
256 QDEndCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
261 void wxRendererMac::DrawSplitterSash( wxWindow
*win
,
265 wxOrientation orient
,
266 int WXUNUSED(flags
) )
268 bool hasMetal
= win
->MacGetTopLevelWindow()->MacGetMetalAppearance();
270 GetThemeMetric( kThemeMetricSmallPaneSplitterHeight
, &height
);
272 if (orient
== wxVERTICAL
)
273 splitterRect
= CGRectMake( position
, 0, height
, size
.y
);
275 splitterRect
= CGRectMake( 0, position
, size
.x
, height
);
277 #if !wxMAC_USE_CORE_GRAPHICS
280 (HIViewRef
) win
->GetHandle(),
281 (HIViewRef
) win
->MacGetTopLevelWindow()->GetHandle() );
284 // under compositing we should only draw when called by the OS, otherwise just issue a redraw command
285 // strange redraw errors occur if we don't do this
287 if ( !dc
.IsKindOf( CLASSINFO( wxPaintDC
) ) )
291 (short) splitterRect
.origin
.y
,
292 (short) splitterRect
.origin
.x
,
293 (short) (splitterRect
.origin
.y
+ splitterRect
.size
.height
),
294 (short) (splitterRect
.origin
.x
+ splitterRect
.size
.width
)
297 RgnHandle updateRgn
= NewRgn();
298 RectRgn( updateRgn
, &r
);
299 HIViewSetNeedsDisplayInRegion( (HIViewRef
) win
->GetHandle(), updateRgn
, true );
300 DisposeRgn( updateRgn
);
304 CGContextRef cgContext
;
306 #if wxMAC_USE_CORE_GRAPHICS
307 cgContext
= (CGContextRef
) dc
.GetGraphicsContext()->GetNativeContext();
310 GetPortBounds( (CGrafPtr
) dc
.m_macPort
, &bounds
);
311 QDBeginCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
312 CGContextTranslateCTM( cgContext
, 0, bounds
.bottom
- bounds
.top
);
313 CGContextScaleCTM( cgContext
, 1, -1 );
316 HIThemeSplitterDrawInfo drawInfo
;
317 drawInfo
.version
= 0;
318 drawInfo
.state
= kThemeStateActive
;
319 drawInfo
.adornment
= hasMetal
? kHIThemeSplitterAdornmentMetal
: kHIThemeSplitterAdornmentNone
;
320 HIThemeDrawPaneSplitter( &splitterRect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
);
322 #if wxMAC_USE_CORE_GRAPHICS
324 QDEndCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);