X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a62f32af0050ab4907ab2771a40875a0eb27a452..b64c92ee20b022a88d3fe5371b0e17fb7818894f:/src/mac/carbon/renderer.cpp?ds=inline diff --git a/src/mac/carbon/renderer.cpp b/src/mac/carbon/renderer.cpp index ad3be942d7..c9c3904f5c 100644 --- a/src/mac/carbon/renderer.cpp +++ b/src/mac/carbon/renderer.cpp @@ -26,6 +26,7 @@ #endif #include "wx/renderer.h" +#include "wx/graphics.h" #include "wx/mac/uma.h" @@ -36,8 +37,12 @@ public: virtual void DrawHeaderButton( wxWindow *win, wxDC& dc, const wxRect& rect, - int flags = 0 ); + int flags = 0, + wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, + wxHeaderButtonParams* params = NULL ); + virtual int GetHeaderButtonHeight(wxWindow *win); + // draw the expanded/collapsed icon for a tree control item virtual void DrawTreeItemButton( wxWindow *win, wxDC& dc, @@ -125,16 +130,14 @@ wxRendererNative& wxRendererNative::GetDefault() void wxRendererMac::DrawHeaderButton( wxWindow *win, wxDC& dc, const wxRect& rect, - int flags ) + int flags, + wxHeaderSortIconType sortArrow, + wxHeaderButtonParams* params ) { - int major, minor; - - wxGetOsVersion( &major, &minor ); - - const wxCoord x = dc.XLOG2DEV(rect.x - 1); - const wxCoord y = dc.YLOG2DEV(rect.y - 1); - const wxCoord w = dc.XLOG2DEVREL(rect.width); - const wxCoord h = dc.YLOG2DEVREL(rect.height); + const wxCoord x = dc.LogicalToDeviceX(rect.x /*- 1*/); + const wxCoord y = dc.LogicalToDeviceY(rect.y /*- 1*/); + const wxCoord w = dc.LogicalToDeviceXRel(rect.width); + const wxCoord h = dc.LogicalToDeviceYRel(rect.height); dc.SetBrush( *wxTRANSPARENT_BRUSH ); @@ -158,7 +161,7 @@ void wxRendererMac::DrawHeaderButton( wxWindow *win, CGContextRef cgContext; #if wxMAC_USE_CORE_GRAPHICS - cgContext = ((wxMacCGContext*)(dc.GetGraphicContext()))->GetNativeContext(); + cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext(); #else Rect bounds; @@ -179,11 +182,28 @@ void wxRendererMac::DrawHeaderButton( wxWindow *win, memset( &drawInfo, 0, sizeof(drawInfo) ); drawInfo.version = 0; - drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive; drawInfo.kind = kThemeListHeaderButton; - drawInfo.value = 0; + drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive; + drawInfo.value = (flags & wxCONTROL_SELECTED) ? kThemeButtonOn : kThemeButtonOff; drawInfo.adornment = kThemeAdornmentNone; + + // The down arrow is drawn automatically, change it to an up arrow if needed. + if ( sortArrow == wxHDR_SORT_ICON_UP ) + drawInfo.adornment = kThemeAdornmentHeaderButtonSortUp; + HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect ); + + // If we don't want any arrows we need to draw over the one already there + if ( (flags & wxCONTROL_SELECTED) && (sortArrow == wxHDR_SORT_ICON_NONE) ) + { + // clip to the header rectangle + CGContextSaveGState( cgContext ); + CGContextClipToRect( cgContext, headerRect ); + // but draw bigger than that so the arrow will get clipped off + headerRect.size.width += 25; + HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect ); + CGContextRestoreGState( cgContext ); + } } #if wxMAC_USE_CORE_GRAPHICS @@ -191,8 +211,35 @@ void wxRendererMac::DrawHeaderButton( wxWindow *win, QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext ); #endif } + + // Reserve room for the arrows before writing the label, and turn off the + // flags we've already handled + wxRect newRect(rect); + if ( (flags & wxCONTROL_SELECTED) && (sortArrow != wxHDR_SORT_ICON_NONE) ) + { + newRect.width -= 12; + sortArrow = wxHDR_SORT_ICON_NONE; + } + flags &= ~wxCONTROL_SELECTED; + + DrawHeaderButtonContents(win, dc, newRect, flags, sortArrow, params); +} + + +int wxRendererMac::GetHeaderButtonHeight(wxWindow* WXUNUSED(win)) +{ + SInt32 standardHeight; + OSStatus errStatus; + + errStatus = GetThemeMetric( kThemeMetricListHeaderHeight, &standardHeight ); + if (errStatus == noErr) + { + return standardHeight; + } + return -1; } + void wxRendererMac::DrawTreeItemButton( wxWindow *win, wxDC& dc, const wxRect& rect, @@ -283,7 +330,7 @@ void wxRendererMac::DrawSplitterSash( wxWindow *win, CGContextRef cgContext; #if wxMAC_USE_CORE_GRAPHICS - cgContext = ((wxMacCGContext*)(dc.GetGraphicContext()))->GetNativeContext(); + cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext(); #else Rect bounds; GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds );