]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/carbon/renderer.cpp
Add wxCALL_FOR_EACH() macro.
[wxWidgets.git] / src / osx / carbon / renderer.cpp
index fd3b471abf6a84cff35a0416890fcb45e885539b..2dad815345256e3ce35436ed10b315bf69892631 100644 (file)
@@ -6,12 +6,14 @@
 // Created:     20.07.2003
 // RCS-ID:      $Id$
 // Copyright:   (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
-// License:     wxWindows licence
+// Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
 // for compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
+#if wxOSX_USE_COCOA_OR_CARBON
+
 #ifdef __BORLANDC__
     #pragma hdrstop
 #endif
     #include "wx/bitmap.h"
     #include "wx/settings.h"
     #include "wx/dcclient.h"
+    #include "wx/dcmemory.h"
     #include "wx/toplevel.h"
 #endif
 
 #include "wx/renderer.h"
 #include "wx/graphics.h"
 #include "wx/dcgraph.h"
+#include "wx/splitter.h"
 #include "wx/osx/private.h"
 
 #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
     #include "wx/mstream.h"
 #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
 
-// check if we're currently in a paint event
-inline bool wxInPaintEvent(wxWindow* win, wxDC& dc)
+
+// check if we're having a CGContext we can draw into
+inline bool wxHasCGContext(wxWindow* WXUNUSED(win), wxDC& dc)
 {
-    wxUnusedVar(dc);
-    return ( win->MacGetCGContextRef() != NULL );
+    wxGCDCImpl* gcdc = wxDynamicCast( dc.GetImpl() , wxGCDCImpl);
+    
+    if ( gcdc )
+    {
+        if ( gcdc->GetGraphicsContext()->GetNativeContext() )
+            return true;
+    }
+    return false;
 }
 
 
@@ -57,6 +68,8 @@ public:
 
     virtual int GetHeaderButtonHeight(wxWindow *win);
 
+    virtual int GetHeaderButtonMargin(wxWindow *win);
+
     // draw the expanded/collapsed icon for a tree control item
     virtual void DrawTreeItemButton( wxWindow *win,
         wxDC& dc,
@@ -111,6 +124,8 @@ public:
                                     int flags = 0);
 #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
 
+    virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
+
 private:
     void DrawMacThemeButton(wxWindow *win,
                             wxDC& dc,
@@ -151,7 +166,7 @@ int wxRendererMac::DrawHeaderButton( wxWindow *win,
     dc.SetBrush( *wxTRANSPARENT_BRUSH );
 
     HIRect headerRect = CGRectMake( x, y, w, h );
-    if ( !wxInPaintEvent(win, dc) )
+    if ( !wxHasCGContext(win, dc) )
     {
         win->Refresh( &rect );
     }
@@ -220,6 +235,12 @@ int wxRendererMac::GetHeaderButtonHeight(wxWindow* WXUNUSED(win))
     return -1;
 }
 
+int wxRendererMac::GetHeaderButtonMargin(wxWindow *WXUNUSED(win))
+{
+    wxFAIL_MSG( "GetHeaderButtonMargin() not implemented" );
+    return -1;
+}
+
 void wxRendererMac::DrawTreeItemButton( wxWindow *win,
     wxDC& dc,
     const wxRect& rect,
@@ -234,7 +255,7 @@ void wxRendererMac::DrawTreeItemButton( wxWindow *win,
     dc.SetBrush( *wxTRANSPARENT_BRUSH );
 
     HIRect headerRect = CGRectMake( x, y, w, h );
-    if ( !wxInPaintEvent(win, dc) )
+    if ( !wxHasCGContext(win, dc) )
     {
         win->Refresh( &rect );
     }
@@ -261,6 +282,37 @@ void wxRendererMac::DrawTreeItemButton( wxWindow *win,
     }
 }
 
+wxSplitterRenderParams
+wxRendererMac::GetSplitterParams(const wxWindow *win)
+{
+    // see below
+    SInt32 sashWidth,
+            border;
+#if wxOSX_USE_COCOA
+    if ( win->HasFlag(wxSP_3DSASH) )
+        GetThemeMetric( kThemeMetricPaneSplitterHeight, &sashWidth ); // Cocoa == Carbon == 7
+    else if ( win->HasFlag(wxSP_NOSASH) ) // actually Cocoa doesn't allow 0
+        sashWidth = 0;
+    else // no 3D effect - Cocoa [NSSplitView dividerThickNess] for NSSplitViewDividerStyleThin
+        sashWidth = 1;
+#else // Carbon
+    if ( win->HasFlag(wxSP_3DSASH) )
+        GetThemeMetric( kThemeMetricPaneSplitterHeight, &sashWidth );
+    else if ( win->HasFlag(wxSP_NOSASH) )
+        sashWidth = 0;
+    else // no 3D effect
+        GetThemeMetric( kThemeMetricSmallPaneSplitterHeight, &sashWidth );
+#endif // Cocoa/Carbon
+
+    if ( win->HasFlag(wxSP_3DBORDER) )
+        border = 2;
+    else // no 3D effect
+        border = 0;
+
+    return wxSplitterRenderParams(sashWidth, border, false);
+}
+
+
 void wxRendererMac::DrawSplitterSash( wxWindow *win,
     wxDC& dc,
     const wxSize& size,
@@ -270,7 +322,9 @@ void wxRendererMac::DrawSplitterSash( wxWindow *win,
 {
     bool hasMetal = win->MacGetTopLevelWindow()->GetExtraStyle() & wxFRAME_EX_METAL;
     SInt32 height;
-    GetThemeMetric( kThemeMetricSmallPaneSplitterHeight, &height );
+
+    height = wxRendererNative::Get().GetSplitterParams(win).widthSash;
+
     HIRect splitterRect;
     if (orient == wxVERTICAL)
         splitterRect = CGRectMake( position, 0, height, size.y );
@@ -280,7 +334,7 @@ void wxRendererMac::DrawSplitterSash( wxWindow *win,
     // under compositing we should only draw when called by the OS, otherwise just issue a redraw command
     // strange redraw errors occur if we don't do this
 
-    if ( !wxInPaintEvent(win, dc) )
+    if ( !wxHasCGContext(win, dc) )
     {
         wxRect rect( (int) splitterRect.origin.x, (int) splitterRect.origin.y, (int) splitterRect.size.width,
                      (int) splitterRect.size.height );
@@ -299,17 +353,20 @@ void wxRendererMac::DrawSplitterSash( wxWindow *win,
 
         if ( hasMetal )
             HIThemeDrawBackground(&splitterRect, &bgdrawInfo, cgContext, kHIThemeOrientationNormal);
-        else 
+        else
         {
             CGContextSetFillColorWithColor(cgContext,win->GetBackgroundColour().GetCGColor());
             CGContextFillRect(cgContext,splitterRect);
         }
-        
-        HIThemeSplitterDrawInfo drawInfo;
-        drawInfo.version = 0;
-        drawInfo.state = kThemeStateActive;
-        drawInfo.adornment = hasMetal ? kHIThemeSplitterAdornmentMetal : kHIThemeSplitterAdornmentNone;
-        HIThemeDrawPaneSplitter( &splitterRect, &drawInfo, cgContext, kHIThemeOrientationNormal );
+
+        if ( win->HasFlag(wxSP_3DSASH) )
+        {
+            HIThemeSplitterDrawInfo drawInfo;
+            drawInfo.version = 0;
+            drawInfo.state = kThemeStateActive;
+            drawInfo.adornment = hasMetal ? kHIThemeSplitterAdornmentMetal : kHIThemeSplitterAdornmentNone;
+            HIThemeDrawPaneSplitter( &splitterRect, &drawInfo, cgContext, kHIThemeOrientationNormal );
+        }
     }
 }
 
@@ -350,7 +407,7 @@ wxRendererMac::DrawMacThemeButton(wxWindow *win,
     dc.SetBrush( *wxTRANSPARENT_BRUSH );
 
     HIRect headerRect = CGRectMake( x, y, w, h );
-    if ( !wxInPaintEvent(win, dc) )
+    if ( !wxHasCGContext(win, dc) )
     {
         win->Refresh( &rect );
     }
@@ -558,7 +615,7 @@ void wxRendererMac::DrawTextCtrl(wxWindow* win, wxDC& dc,
     dc.SetBrush( *wxTRANSPARENT_BRUSH );
 
     HIRect hiRect = CGRectMake( x, y, w, h );
-    if ( !wxInPaintEvent(win, dc) )
+    if ( !wxHasCGContext(win, dc) )
     {
         win->Refresh( &rect );
     }
@@ -806,3 +863,5 @@ void wxRendererMac::DrawTitleBarBitmap(wxWindow *win,
 }
 
 #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
+
+#endif