]> git.saurik.com Git - wxWidgets.git/blobdiff - src/cocoa/scrolbar.mm
Added ability to switch off more components of the size page UI
[wxWidgets.git] / src / cocoa / scrolbar.mm
index 9a21343de604a0d89e95c313aa91af979d05152f..4ce46ec46277de9deaf7ef9cfbd6cf7679ef959c 100644 (file)
@@ -1,40 +1,87 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        cocoa/scrolbar.mm
+// Name:        src/cocoa/scrolbar.mm
 // Purpose:     wxScrollBar
 // Author:      David Elliott
 // Purpose:     wxScrollBar
 // Author:      David Elliott
-// Modified by:
+// Modified by: Mark Oxenham
 // Created:     2004/04/25
 // RCS-ID:      $Id$
 // Copyright:   (c) 2004 David Elliott
 // Created:     2004/04/25
 // RCS-ID:      $Id$
 // Copyright:   (c) 2004 David Elliott
-// Licence:    wxWindows licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #include "wx/wxprec.h"
 /////////////////////////////////////////////////////////////////////////////
 
 #include "wx/wxprec.h"
+
 #if wxUSE_SCROLLBAR
 
 #if wxUSE_SCROLLBAR
 
+#include "wx/scrolbar.h"
+
 #ifndef WX_PRECOMP
     #include "wx/app.h"
 #ifndef WX_PRECOMP
     #include "wx/app.h"
-    #include "wx/scrolbar.h"
 #endif //WX_PRECOMP
 
 #import <AppKit/NSScroller.h>
 
 #endif //WX_PRECOMP
 
 #import <AppKit/NSScroller.h>
 
-IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
 BEGIN_EVENT_TABLE(wxScrollBar, wxScrollBarBase)
 END_EVENT_TABLE()
 WX_IMPLEMENT_COCOA_OWNER(wxScrollBar,NSScroller,NSControl,NSView)
 
 BEGIN_EVENT_TABLE(wxScrollBar, wxScrollBarBase)
 END_EVENT_TABLE()
 WX_IMPLEMENT_COCOA_OWNER(wxScrollBar,NSScroller,NSControl,NSView)
 
+inline NSControlSize AdjustDimension(
+                int             &pos,
+                wxSize          &size,
+                int             (wxSize::*GetDimension)() const,
+                void            (wxSize::*SetDimension)(int))
+{
+    NSControlSize controlSize = NSRegularControlSize;
+    const int dimension = (size.*GetDimension)();
+
+    if ((size.GetHeight() == -1) || (size.GetWidth() == -1) || (dimension >= 15)) 
+    {
+        (size.*SetDimension)(15);
+    }
+    else
+    {
+        (size.*SetDimension)(11);
+        controlSize = NSSmallControlSize;
+    }
+
+    pos += (dimension - (size.*GetDimension)() + 1) / 2;
+
+    return (controlSize);
+}
+
 bool wxScrollBar::Create(wxWindow *parent, wxWindowID winid,
             const wxPoint& pos, const wxSize& size, long style,
             const wxValidator& validator, const wxString& name)
 {
 bool wxScrollBar::Create(wxWindow *parent, wxWindowID winid,
             const wxPoint& pos, const wxSize& size, long style,
             const wxValidator& validator, const wxString& name)
 {
-    if(!CreateControl(parent,winid,pos,size,style,validator,name))
+    NSControlSize controlSize = NSRegularControlSize;
+    wxSize adjustedSize(size);
+    wxPoint adjustedPos(pos);
+
+    if ((style & wxSB_HORIZONTAL) && ((size.GetHeight() != wxDefaultCoord) || (size.GetHeight() == -1)))
+    {
+        controlSize = AdjustDimension(adjustedPos.y, adjustedSize, &wxSize::GetHeight, &wxSize::SetHeight);
+    }
+    else if ((style & wxSB_VERTICAL) && (size.GetWidth() != wxDefaultCoord || (size.GetWidth() == -1)))
+    {
+        controlSize = AdjustDimension(adjustedPos.x, adjustedSize, &wxSize::GetWidth, &wxSize::SetWidth);
+    }
+
+    if(!CreateControl(parent,winid,adjustedPos,adjustedSize,style,validator,name))
         return false;
         return false;
-    SetNSScroller([[NSScroller alloc] initWithFrame: MakeDefaultNSRect(size)]);
+    SetNSScroller([[NSScroller alloc] initWithFrame: MakeDefaultNSRect(adjustedSize)]);
     [m_cocoaNSView release];
     if(m_parent)
         m_parent->CocoaAddChild(this);
     [m_cocoaNSView release];
     if(m_parent)
         m_parent->CocoaAddChild(this);
-    SetInitialFrameRect(pos,size);
+    SetInitialFrameRect(adjustedPos,adjustedSize);
+
+    BOOL nsEnabled = [GetNSScroller() isEnabled];
+
+    if (IsEnabled() != (nsEnabled != NO))
+    {
+        [GetNSScroller() setEnabled: !nsEnabled];
+    }
+
+    [GetNSScroller() setControlSize: controlSize];
 
     return true;
 }
 
     return true;
 }
@@ -128,7 +175,7 @@ void wxScrollBar::Cocoa_wxNSScrollerAction()
     wxScrollEvent event(command, GetId(), GetThumbPosition(),
         HasFlag(wxSB_VERTICAL)?wxVERTICAL:wxHORIZONTAL);
     event.SetEventObject(this);
     wxScrollEvent event(command, GetId(), GetThumbPosition(),
         HasFlag(wxSB_VERTICAL)?wxVERTICAL:wxHORIZONTAL);
     event.SetEventObject(this);
-    GetEventHandler()->ProcessEvent(event);
+    HandleWindowEvent(event);
 }
 
 #endif // wxUSE_SCROLLBAR
 }
 
 #endif // wxUSE_SCROLLBAR