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
,
41 // draw the expanded/collapsed icon for a tree control item
42 virtual void DrawTreeItemButton( wxWindow
*win
,
47 // draw a (vertical) sash
48 virtual void DrawSplitterSash( wxWindow
*win
,
57 wxBitmap m_bmpTreeExpanded
;
58 wxBitmap m_bmpTreeCollapsed
;
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
66 static const char *aqua_arrow_right_xpm
[] =
68 // columns rows colors chars-per-pixel
90 static const char *aqua_arrow_down_xpm
[] =
92 // columns rows colors chars-per-pixel
113 // ============================================================================
115 // ============================================================================
118 wxRendererNative
& wxRendererNative::GetDefault()
120 static wxRendererMac s_rendererMac
;
122 return s_rendererMac
;
125 void wxRendererMac::DrawHeaderButton( wxWindow
*win
,
132 wxGetOsVersion( &major
, &minor
);
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
.state
= (flags
& wxCONTROL_DISABLED
) ? kThemeStateInactive
: kThemeStateActive
;
183 drawInfo
.kind
= kThemeListHeaderButton
;
185 drawInfo
.adornment
= kThemeAdornmentNone
;
186 HIThemeDrawButton( &headerRect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
, &labelRect
);
189 #if wxMAC_USE_CORE_GRAPHICS
191 QDEndCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
196 void wxRendererMac::DrawTreeItemButton( wxWindow
*win
,
201 // init the buttons on demand
202 if ( !m_bmpTreeExpanded
.Ok() )
204 m_bmpTreeExpanded
= wxBitmap(aqua_arrow_down_xpm
);
205 m_bmpTreeCollapsed
= wxBitmap(aqua_arrow_right_xpm
);
210 // VZ: this is the old code from treectlg.cpp which apparently doesn't work
211 // but I kept it here just in case it is needed -- if not, please
214 #if 0 // def __WXMAC__
215 wxMacPortSetter
helper(&dc
);
216 wxMacWindowClipper
clipper(this);
217 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() );
220 int loc_y
= y_mid
- 6;
221 MacWindowToRootWindow( &loc_x
, &loc_y
);
222 Rect bounds
= { loc_y
, loc_x
, loc_y
+ 18, loc_x
+ 12 };
223 ThemeButtonDrawInfo info
=
226 item
->IsExpanded() ? kThemeDisclosureDown
: kThemeDisclosureRight
,
230 DrawThemeButton( &bounds
, kThemeDisclosureButton
, &info
, NULL
, NULL
, NULL
, NULL
);
233 flags
& wxCONTROL_EXPANDED
235 : m_bmpTreeCollapsed
,
236 rect
.x
, rect
.y
, true /* use mask */);
240 void wxRendererMac::DrawSplitterSash( wxWindow
*win
,
244 wxOrientation orient
,
245 int WXUNUSED(flags
) )
247 bool hasMetal
= win
->MacGetTopLevelWindow()->MacGetMetalAppearance();
249 GetThemeMetric( kThemeMetricSmallPaneSplitterHeight
, &height
);
251 if (orient
== wxVERTICAL
)
252 splitterRect
= CGRectMake( position
, 0, height
, size
.y
);
254 splitterRect
= CGRectMake( 0, position
, size
.x
, height
);
256 #if !wxMAC_USE_CORE_GRAPHICS
259 (HIViewRef
) win
->GetHandle(),
260 (HIViewRef
) win
->MacGetTopLevelWindow()->GetHandle() );
263 // under compositing we should only draw when called by the OS, otherwise just issue a redraw command
264 // strange redraw errors occur if we don't do this
266 if ( !dc
.IsKindOf( CLASSINFO( wxPaintDC
) ) )
270 (short) splitterRect
.origin
.y
,
271 (short) splitterRect
.origin
.x
,
272 (short) (splitterRect
.origin
.y
+ splitterRect
.size
.height
),
273 (short) (splitterRect
.origin
.x
+ splitterRect
.size
.width
)
276 RgnHandle updateRgn
= NewRgn();
277 RectRgn( updateRgn
, &r
);
278 HIViewSetNeedsDisplayInRegion( (HIViewRef
) win
->GetHandle(), updateRgn
, true );
279 DisposeRgn( updateRgn
);
283 CGContextRef cgContext
;
285 #if wxMAC_USE_CORE_GRAPHICS
286 cgContext
= ((wxMacCGContext
*)(dc
.GetGraphicContext()))->GetNativeContext();
289 GetPortBounds( (CGrafPtr
) dc
.m_macPort
, &bounds
);
290 QDBeginCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);
291 CGContextTranslateCTM( cgContext
, 0, bounds
.bottom
- bounds
.top
);
292 CGContextScaleCTM( cgContext
, 1, -1 );
295 HIThemeSplitterDrawInfo drawInfo
;
296 drawInfo
.version
= 0;
297 drawInfo
.state
= kThemeStateActive
;
298 drawInfo
.adornment
= hasMetal
? kHIThemeSplitterAdornmentMetal
: kHIThemeSplitterAdornmentNone
;
299 HIThemeDrawPaneSplitter( &splitterRect
, &drawInfo
, cgContext
, kHIThemeOrientationNormal
);
301 #if wxMAC_USE_CORE_GRAPHICS
303 QDEndCGContext( (CGrafPtr
) dc
.m_macPort
, &cgContext
);