]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/carbon/renderer.cpp
set m_isBeingDeleted to true (only) in SendDestroyEvent(); call it as early as possib...
[wxWidgets.git] / src / osx / carbon / renderer.cpp
index abcc1d6aa2b655e960921e2b1af05663199ec120..3f8c1a95e67962269b75d82e02c029742718bca6 100644 (file)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// Name:        src/mac/carbon/renderer.cpp
+// Name:        src/osx/carbon/renderer.cpp
 // Purpose:     implementation of wxRendererNative for Mac
 // Author:      Vadim Zeitlin
 // Modified by:
 
 #include "wx/renderer.h"
 #include "wx/graphics.h"
-#include "wx/mac/uma.h"
+#include "wx/dcgraph.h"
+#include "wx/osx/private.h"
+
+#if wxOSX_USE_COCOA
+// bring in the theme headers
+#include <Carbon/Carbon.h>
+#endif
+
+// check if we're currently in a paint event
+inline bool wxInPaintEvent(wxWindow* win, wxDC& dc)
+{
+    return ( win->MacGetCGContextRef() != NULL );
+}
+
 
 
 class WXDLLEXPORT wxRendererMac : public wxDelegateRendererNative
@@ -62,6 +75,8 @@ public:
                               const wxRect& rect,
                               int flags = 0);
 
+    virtual wxSize GetCheckBoxSize(wxWindow* win);
+
     virtual void DrawComboBoxDropButton(wxWindow *win,
                                         wxDC& dc,
                                         const wxRect& rect,
@@ -79,6 +94,14 @@ public:
 
     virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0);
 
+    virtual void DrawChoice(wxWindow* win, wxDC& dc, const wxRect& rect, int flags=0);
+
+    virtual void DrawComboBox(wxWindow* win, wxDC& dc, const wxRect& rect, int flags=0);
+
+    virtual void DrawTextCtrl(wxWindow* win, wxDC& dc, const wxRect& rect, int flags=0);
+
+    virtual void DrawRadioButton(wxWindow* win, wxDC& dc, const wxRect& rect, int flags=0);
+
 private:
     void DrawMacThemeButton(wxWindow *win,
                             wxDC& dc,
@@ -119,7 +142,7 @@ int wxRendererMac::DrawHeaderButton( wxWindow *win,
     dc.SetBrush( *wxTRANSPARENT_BRUSH );
 
     HIRect headerRect = CGRectMake( x, y, w, h );
-    if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) )
+    if ( !wxInPaintEvent(win, dc) )
     {
         win->Refresh( &rect );
     }
@@ -202,7 +225,7 @@ void wxRendererMac::DrawTreeItemButton( wxWindow *win,
     dc.SetBrush( *wxTRANSPARENT_BRUSH );
 
     HIRect headerRect = CGRectMake( x, y, w, h );
-    if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) )
+    if ( !wxInPaintEvent(win, dc) )
     {
         win->Refresh( &rect );
     }
@@ -236,7 +259,7 @@ void wxRendererMac::DrawSplitterSash( wxWindow *win,
     wxOrientation orient,
     int WXUNUSED(flags) )
 {
-    bool hasMetal = win->MacGetTopLevelWindow()->MacGetMetalAppearance();
+    bool hasMetal = win->MacGetTopLevelWindow()->GetExtraStyle() & wxFRAME_EX_METAL;
     SInt32 height;
     GetThemeMetric( kThemeMetricSmallPaneSplitterHeight, &height );
     HIRect splitterRect;
@@ -248,7 +271,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 ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) )
+    if ( !wxInPaintEvent(win, dc) )
     {
         wxRect rect( (int) splitterRect.origin.x, (int) splitterRect.origin.y, (int) splitterRect.size.width,
                      (int) splitterRect.size.height );
@@ -305,7 +328,7 @@ wxRendererMac::DrawMacThemeButton(wxWindow *win,
     dc.SetBrush( *wxTRANSPARENT_BRUSH );
 
     HIRect headerRect = CGRectMake( x, y, w, h );
-    if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) )
+    if ( !wxInPaintEvent(win, dc) )
     {
         win->Refresh( &rect );
     }
@@ -326,7 +349,9 @@ wxRendererMac::DrawMacThemeButton(wxWindow *win,
         if (flags & wxCONTROL_UNDETERMINED)
             drawInfo.value = kThemeButtonMixed;
         drawInfo.adornment = adornment;
-
+        if (flags & wxCONTROL_FOCUSED)
+            drawInfo.adornment |= kThemeAdornmentFocus;
+        
         HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect );
     }
 }
@@ -340,8 +365,41 @@ wxRendererMac::DrawCheckBox(wxWindow *win,
     if (flags & wxCONTROL_CHECKED)
         flags |= wxCONTROL_SELECTED;
 
+    int kind;
+    
+    if (win->GetWindowVariant() == wxWINDOW_VARIANT_SMALL ||
+        (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_SMALL))
+        kind = kThemeCheckBoxSmall;
+    else if (win->GetWindowVariant() == wxWINDOW_VARIANT_MINI ||
+             (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_MINI))
+        kind = kThemeCheckBoxMini;
+    else
+        kind = kThemeCheckBox;
+
+
     DrawMacThemeButton(win, dc, rect, flags,
-                       kThemeCheckBox, kThemeAdornmentNone);
+                       kind, kThemeAdornmentNone);
+}
+
+wxSize wxRendererMac::GetCheckBoxSize(wxWindow* WXUNUSED(win))
+{
+    wxSize size;
+    SInt32 width, height;
+    OSStatus errStatus;
+
+    errStatus = GetThemeMetric(kThemeMetricCheckBoxWidth, &width);
+    if (errStatus == noErr)
+    {
+        size.SetWidth(width);
+    }
+
+    errStatus = GetThemeMetric(kThemeMetricCheckBoxHeight, &height);
+    if (errStatus == noErr)
+    {
+        size.SetHeight(height);
+    }
+
+    return size;
 }
 
 void
@@ -393,6 +451,7 @@ wxRendererMac::DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int fl
     CGRect cgrect = CGRectMake( rect.x , rect.y , rect.width, rect.height ) ;
 
     HIThemeFrameDrawInfo info ;
+
     memset( &info, 0 , sizeof(info) ) ;
 
     info.version = 0 ;
@@ -406,3 +465,99 @@ wxRendererMac::DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int fl
     HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
 }
 
+void wxRendererMac::DrawChoice(wxWindow* win, wxDC& dc,
+                           const wxRect& rect, int flags)
+{
+    int kind;
+    
+    if (win->GetWindowVariant() == wxWINDOW_VARIANT_SMALL ||
+        (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_SMALL))
+        kind = kThemePopupButtonSmall;
+    else if (win->GetWindowVariant() == wxWINDOW_VARIANT_MINI ||
+             (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_MINI))
+        kind = kThemePopupButtonMini;
+    else
+        kind = kThemePopupButton;
+
+    DrawMacThemeButton(win, dc, rect, flags, kind, kThemeAdornmentNone);
+}
+
+
+void wxRendererMac::DrawComboBox(wxWindow* win, wxDC& dc,
+                             const wxRect& rect, int flags)
+{
+    int kind;
+    
+    if (win->GetWindowVariant() == wxWINDOW_VARIANT_SMALL ||
+        (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_SMALL))
+        kind = kThemeComboBoxSmall;
+    else if (win->GetWindowVariant() == wxWINDOW_VARIANT_MINI ||
+             (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_MINI))
+        kind = kThemeComboBoxMini;
+    else
+        kind = kThemeComboBox;
+
+    DrawMacThemeButton(win, dc, rect, flags, kind, kThemeAdornmentNone);
+}
+
+void wxRendererMac::DrawRadioButton(wxWindow* win, wxDC& dc,
+                                const wxRect& rect, int flags)
+{
+    int kind;
+    
+    if (win->GetWindowVariant() == wxWINDOW_VARIANT_SMALL ||
+        (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_SMALL))
+        kind = kThemeRadioButtonSmall;
+    else if (win->GetWindowVariant() == wxWINDOW_VARIANT_MINI ||
+             (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_MINI))
+        kind = kThemeRadioButtonMini;
+    else
+        kind = kThemeRadioButton;
+
+    if (flags & wxCONTROL_CHECKED)
+        flags |= wxCONTROL_SELECTED;
+
+    DrawMacThemeButton(win, dc, rect, flags,
+                          kind, kThemeAdornmentNone);
+}
+
+void wxRendererMac::DrawTextCtrl(wxWindow* win, wxDC& dc,
+                             const wxRect& rect, int flags)
+{
+    const wxCoord x = rect.x;
+    const wxCoord y = rect.y;
+    const wxCoord w = rect.width;
+    const wxCoord h = rect.height;
+
+    dc.SetBrush( *wxWHITE_BRUSH );
+    dc.SetPen( *wxTRANSPARENT_PEN );
+    dc.DrawRectangle(rect);
+    
+    dc.SetBrush( *wxTRANSPARENT_BRUSH );
+
+    HIRect hiRect = CGRectMake( x, y, w, h );
+    if ( !wxInPaintEvent(win, dc) )
+    {
+        win->Refresh( &rect );
+    }
+    else
+    {
+        CGContextRef cgContext;
+
+        cgContext = (CGContextRef) static_cast<wxGCDCImpl*>(dc.GetImpl())->GetGraphicsContext()->GetNativeContext();
+
+        {
+            HIThemeFrameDrawInfo drawInfo;
+
+            memset( &drawInfo, 0, sizeof(drawInfo) );
+            drawInfo.version = 0;
+            drawInfo.kind = kHIThemeFrameTextFieldSquare;
+            drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive;
+            if (flags & wxCONTROL_FOCUSED)
+                drawInfo.isFocused = true;
+
+            HIThemeDrawFrame( &hiRect, &drawInfo, cgContext, kHIThemeOrientationNormal);
+        }
+    }
+}
+