From ad96f4be55f36720840dfbaf2eba51df1481ac78 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Thu, 1 Jun 2017 11:30:59 +0200 Subject: [PATCH] fixing header button to properly use native themed arrows --- src/osx/carbon/renderer.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/osx/carbon/renderer.cpp b/src/osx/carbon/renderer.cpp index 8cc34dbcef..17cec77e49 100644 --- a/src/osx/carbon/renderer.cpp +++ b/src/osx/carbon/renderer.cpp @@ -198,34 +198,35 @@ int wxRendererMac::DrawHeaderButton( wxWindow *win, memset( &drawInfo, 0, sizeof(drawInfo) ); drawInfo.version = 0; drawInfo.kind = kThemeListHeaderButton; - drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive; - drawInfo.value = (flags & wxCONTROL_PRESSED) ? kThemeButtonOn : kThemeButtonOff; drawInfo.adornment = kThemeAdornmentNone; + drawInfo.value = kThemeButtonOff; + if ( flags & wxCONTROL_DISABLED ) + drawInfo.state = kThemeStateInactive; + else if ( flags & wxCONTROL_PRESSED ) + drawInfo.state = kThemeStatePressed; + else + drawInfo.state = kThemeStateActive; - // The down arrow is drawn automatically, change it to an up arrow if needed. + // The down arrow is drawn automatically (if value is kThemeButtonOn) + // 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_PRESSED) && (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 ); + drawInfo.adornment = kThemeAdornmentHeaderButtonSortUp; + drawInfo.value = kThemeButtonOn; } + else if (sortArrow == wxHDR_SORT_ICON_DOWN ) + { + drawInfo.value = kThemeButtonOn; + } + + HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect ); } } // Reserve room for the arrows before writing the label, and turn off the // flags we've already handled wxRect newRect(rect); - if ( (flags & wxCONTROL_PRESSED) && (sortArrow != wxHDR_SORT_ICON_NONE) ) + if ( sortArrow != wxHDR_SORT_ICON_NONE ) { newRect.width -= 12; sortArrow = wxHDR_SORT_ICON_NONE;