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/mac/uma.h"
32 class WXDLLEXPORT wxRendererMac
: public wxDelegateRendererNative
35 // draw the header control button (used by wxListCtrl)
36 virtual void DrawHeaderButton( wxWindow
*win
,
40 wxHeaderButtonParams
* params
= NULL
);
42 virtual int GetHeaderButtonHeight(wxWindow
*win
);
44 // draw the expanded/collapsed icon for a tree control item
45 virtual void DrawTreeItemButton( wxWindow
*win
,
50 // draw a (vertical) sash
51 virtual void DrawSplitterSash( wxWindow
*win
,
60 wxBitmap m_bmpTreeExpanded
;
61 wxBitmap m_bmpTreeCollapsed
;
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
69 static const char *aqua_arrow_right_xpm
[] =
71 // columns rows colors chars-per-pixel
93 static const char *aqua_arrow_down_xpm
[] =
95 // columns rows colors chars-per-pixel
116 // ============================================================================
118 // ============================================================================
121 wxRendererNative
& wxRendererNative::GetDefault()
123 static wxRendererMac s_rendererMac
;
125 return s_rendererMac
;
128 void wxRendererMac::DrawHeaderButton( wxWindow
*win
,
132 wxHeaderButtonParams
* params
)
134 const wxCoord x
= dc
.XLOG2DEV(rect
.x
/*- 1*/);
135 const wxCoord y
= dc
.YLOG2DEV(rect
.y
/*- 1*/);
136 const wxCoord w
= dc
.XLOG2DEVREL(rect
.width
);
137 const wxCoord h
= dc
.YLOG2DEVREL(rect
.height
);
139 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
141 HIRect headerRect
= CGRectMake( x
, y
, w
, h
);
142 if ( !dc
.IsKindOf( CLASSINFO( wxPaintDC
) ) )
146 (short) headerRect
.origin
.y
, (short) headerRect
.origin
.x
,
147 (short) (headerRect
.origin
.y
+ headerRect
.size
.height
),
148 (short) (headerRect
.origin
.x
+ headerRect
.size
.width
)
151 RgnHandle updateRgn
= NewRgn();
152 RectRgn( updateRgn
, &r
);
153 HIViewSetNeedsDisplayInRegion( (HIViewRef
) win
->GetHandle(), updateRgn
, true );
154 DisposeRgn( updateRgn
);
158 CGContextRef cgContext
;
160 #if wxMAC_USE_CORE_GRAPHICS
161 cgContext
= ((wxMacCGContext
*)(dc
.GetGraphicContext()))->GetNativeContext();
165 GetPortBounds( (CGrafPtr
) dc
.m_macPort
, &bounds
);
166 QDBeginCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
168 CGContextTranslateCTM( cgContext
, 0, bounds
.bottom
- bounds
.top
);
169 CGContextScaleCTM( cgContext
, 1, -1 );
171 HIShapeReplacePathInCGContext( HIShapeCreateWithQDRgn( (RgnHandle
) dc
.m_macCurrentClipRgn
), cgContext
);
172 CGContextClip( cgContext
);
173 HIViewConvertRect( &headerRect
, (HIViewRef
) win
->GetHandle(), (HIViewRef
) win
->MacGetTopLevelWindow()->GetHandle() );
177 HIThemeButtonDrawInfo drawInfo
;
180 memset( &drawInfo
, 0, sizeof(drawInfo
) );
181 drawInfo
.version
= 0;
182 drawInfo
.kind
= kThemeListHeaderButton
;
183 drawInfo
.state
= (flags
& wxCONTROL_DISABLED
) ? kThemeStateInactive
: kThemeStateActive
;
184 drawInfo
.value
= (flags
& wxCONTROL_SELECTED
) ? kThemeButtonOn
: kThemeButtonOff
;
185 drawInfo
.adornment
= kThemeAdornmentNone
;
187 // The down arrow is drawn automatically, change it to an up arrow if needed.
188 if ( flags
& wxCONTROL_UPICON
)
189 drawInfo
.adornment
= kThemeAdornmentHeaderButtonSortUp
;
191 HIThemeDrawButton( &headerRect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
, &labelRect
);
193 // If we don't want any arrows we need to draw over the one already there
194 if ( (flags
& wxCONTROL_SELECTED
) && !(flags
& (wxCONTROL_UPICON
|wxCONTROL_DOWNICON
)) )
196 // clip to the header rectangle
197 CGContextSaveGState( cgContext
);
198 CGContextClipToRect( cgContext
, headerRect
);
199 // but draw bigger than that so the arrow will get clipped off
200 headerRect
.size
.width
+= 25;
201 HIThemeDrawButton( &headerRect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
, &labelRect
);
202 CGContextRestoreGState( cgContext
);
206 #if wxMAC_USE_CORE_GRAPHICS
208 QDEndCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
212 // Reserve room for the arrows before writing the label, and turn off the
213 // flags we've already handled
214 wxRect
newRect(rect
);
215 if ( (flags
& wxCONTROL_SELECTED
) && (flags
& (wxCONTROL_UPICON
|wxCONTROL_DOWNICON
)) )
219 flags
&= ~(wxCONTROL_SELECTED
| wxCONTROL_UPICON
| wxCONTROL_DOWNICON
);
221 DrawHeaderButtonContents(win
, dc
, newRect
, flags
, params
);
225 int wxRendererMac::GetHeaderButtonHeight(wxWindow
* WXUNUSED(win
))
227 SInt32 standardHeight
;
230 errStatus
= GetThemeMetric( kThemeMetricListHeaderHeight
, &standardHeight
);
231 if (errStatus
== noErr
)
233 return standardHeight
;
239 void wxRendererMac::DrawTreeItemButton( wxWindow
*win
,
244 // init the buttons on demand
245 if ( !m_bmpTreeExpanded
.Ok() )
247 m_bmpTreeExpanded
= wxBitmap(aqua_arrow_down_xpm
);
248 m_bmpTreeCollapsed
= wxBitmap(aqua_arrow_right_xpm
);
253 // VZ: this is the old code from treectlg.cpp which apparently doesn't work
254 // but I kept it here just in case it is needed -- if not, please
257 #if 0 // def __WXMAC__
258 wxMacPortSetter
helper(&dc
);
259 wxMacWindowClipper
clipper(this);
260 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() );
263 int loc_y
= y_mid
- 6;
264 MacWindowToRootWindow( &loc_x
, &loc_y
);
265 Rect bounds
= { loc_y
, loc_x
, loc_y
+ 18, loc_x
+ 12 };
266 ThemeButtonDrawInfo info
=
269 item
->IsExpanded() ? kThemeDisclosureDown
: kThemeDisclosureRight
,
273 DrawThemeButton( &bounds
, kThemeDisclosureButton
, &info
, NULL
, NULL
, NULL
, NULL
);
276 flags
& wxCONTROL_EXPANDED
278 : m_bmpTreeCollapsed
,
279 rect
.x
, rect
.y
, true /* use mask */);
283 void wxRendererMac::DrawSplitterSash( wxWindow
*win
,
287 wxOrientation orient
,
288 int WXUNUSED(flags
) )
290 bool hasMetal
= win
->MacGetTopLevelWindow()->MacGetMetalAppearance();
292 GetThemeMetric( kThemeMetricSmallPaneSplitterHeight
, &height
);
294 if (orient
== wxVERTICAL
)
295 splitterRect
= CGRectMake( position
, 0, height
, size
.y
);
297 splitterRect
= CGRectMake( 0, position
, size
.x
, height
);
299 #if !wxMAC_USE_CORE_GRAPHICS
302 (HIViewRef
) win
->GetHandle(),
303 (HIViewRef
) win
->MacGetTopLevelWindow()->GetHandle() );
306 // under compositing we should only draw when called by the OS, otherwise just issue a redraw command
307 // strange redraw errors occur if we don't do this
309 if ( !dc
.IsKindOf( CLASSINFO( wxPaintDC
) ) )
313 (short) splitterRect
.origin
.y
,
314 (short) splitterRect
.origin
.x
,
315 (short) (splitterRect
.origin
.y
+ splitterRect
.size
.height
),
316 (short) (splitterRect
.origin
.x
+ splitterRect
.size
.width
)
319 RgnHandle updateRgn
= NewRgn();
320 RectRgn( updateRgn
, &r
);
321 HIViewSetNeedsDisplayInRegion( (HIViewRef
) win
->GetHandle(), updateRgn
, true );
322 DisposeRgn( updateRgn
);
326 CGContextRef cgContext
;
328 #if wxMAC_USE_CORE_GRAPHICS
329 cgContext
= ((wxMacCGContext
*)(dc
.GetGraphicContext()))->GetNativeContext();
332 GetPortBounds( (CGrafPtr
) dc
.m_macPort
, &bounds
);
333 QDBeginCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
334 CGContextTranslateCTM( cgContext
, 0, bounds
.bottom
- bounds
.top
);
335 CGContextScaleCTM( cgContext
, 1, -1 );
338 HIThemeSplitterDrawInfo drawInfo
;
339 drawInfo
.version
= 0;
340 drawInfo
.state
= kThemeStateActive
;
341 drawInfo
.adornment
= hasMetal
? kHIThemeSplitterAdornmentMetal
: kHIThemeSplitterAdornmentNone
;
342 HIThemeDrawPaneSplitter( &splitterRect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
);
344 #if wxMAC_USE_CORE_GRAPHICS
346 QDEndCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);