]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/renderer.cpp
PCH support.
[wxWidgets.git] / src / mac / carbon / renderer.cpp
index ad3be942d7f8d719aec43ee2fa075c08bb227392..c9c3904f5c60c0213397bc58018868e177b92c9f 100644 (file)
@@ -26,6 +26,7 @@
 #endif
 
 #include "wx/renderer.h"
 #endif
 
 #include "wx/renderer.h"
+#include "wx/graphics.h"
 #include "wx/mac/uma.h"
 
 
 #include "wx/mac/uma.h"
 
 
@@ -36,8 +37,12 @@ public:
     virtual void DrawHeaderButton( wxWindow *win,
         wxDC& dc,
         const wxRect& rect,
     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,
     // 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,
 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 );
 
 
     dc.SetBrush( *wxTRANSPARENT_BRUSH );
 
@@ -158,7 +161,7 @@ void wxRendererMac::DrawHeaderButton( wxWindow *win,
         CGContextRef cgContext;
 
 #if wxMAC_USE_CORE_GRAPHICS
         CGContextRef cgContext;
 
 #if wxMAC_USE_CORE_GRAPHICS
-        cgContext = ((wxMacCGContext*)(dc.GetGraphicContext()))->GetNativeContext();
+        cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext();
 #else
         Rect bounds;
 
 #else
         Rect bounds;
 
@@ -179,11 +182,28 @@ void wxRendererMac::DrawHeaderButton( wxWindow *win,
 
             memset( &drawInfo, 0, sizeof(drawInfo) );
             drawInfo.version = 0;
 
             memset( &drawInfo, 0, sizeof(drawInfo) );
             drawInfo.version = 0;
-            drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive;
             drawInfo.kind = kThemeListHeaderButton;
             drawInfo.kind = kThemeListHeaderButton;
-            drawInfo.value = 0;
+            drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive;
+            drawInfo.value = (flags & wxCONTROL_SELECTED) ? kThemeButtonOn : kThemeButtonOff;
             drawInfo.adornment = kThemeAdornmentNone;
             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 );
             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
         }
 
 #if wxMAC_USE_CORE_GRAPHICS
@@ -191,8 +211,35 @@ void wxRendererMac::DrawHeaderButton( wxWindow *win,
         QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
 #endif
     }
         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,
 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
         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 );
 #else
         Rect bounds;
         GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds );