]> git.saurik.com Git - wxWidgets.git/blobdiff - src/motif/scrolbar.cpp
deprecate wxDC::SetClippingRegion(wxRegion) overload and replace it with SetDeviceCli...
[wxWidgets.git] / src / motif / scrolbar.cpp
index 99e5316bebb7a604df58cf712292726f5f253628..587be3ca89c15c7acafdeed8b6a333ee20f1e0f6 100644 (file)
@@ -1,25 +1,35 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        scrolbar.cpp
+// Name:        src/motif/scrolbar.cpp
 // Purpose:     wxScrollBar
 // Author:      Julian Smart
 // Modified by:
 // Created:     17/09/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
 // Purpose:     wxScrollBar
 // Author:      Julian Smart
 // Modified by:
 // Created:     17/09/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
-// Licence:    wxWindows licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-#pragma implementation "scrolbar.h"
-#endif
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
 
 #include "wx/scrolbar.h"
 
 
 #include "wx/scrolbar.h"
 
-#if !USE_SHARED_LIBRARY
-IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
-
+#ifdef __VMS__
+#pragma message disable nosimpint
+#endif
+#include <Xm/Xm.h>
+#include <Xm/ScrollBar.h>
+#ifdef __VMS__
+#pragma message enable nosimpint
 #endif
 
 #endif
 
+#include "wx/motif/private.h"
+
+static void wxScrollBarCallback(Widget widget, XtPointer clientData,
+                        XmScaleCallbackStruct *cbs);
+
+IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
+
 // Scrollbar
 bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
            const wxPoint& pos,
 // Scrollbar
 bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
            const wxPoint& pos,
@@ -27,52 +37,151 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
            const wxValidator& validator,
            const wxString& name)
 {
            const wxValidator& validator,
            const wxString& name)
 {
-    if (!parent)
-        return FALSE;
-    parent->AddChild(this);
-    SetName(name);
-       SetValidator(validator);
-    
-    m_windowStyle = style;
-
-    if ( id == -1 )
-           m_windowId = (int)NewControlId();
-    else
-           m_windowId = id;
-
-    // TODO create scrollbar
-    return TRUE;
+    if( !CreateControl( parent, id, pos, size, style, validator, name ) )
+        return false;
+    PreCreation();
+
+    wxSize newSize =
+        ( style & wxHORIZONTAL ) ? wxSize( 140, 16 ) : wxSize( 16, 140 );
+    if( size.x != -1 ) newSize.x = size.x;
+    if( size.y != -1 ) newSize.y = size.y;
+
+    Widget parentWidget = (Widget) parent->GetClientWidget();
+
+    m_mainWidget =
+        DoCreateScrollBar( (WXWidget)parentWidget,
+                           (wxOrientation)(style & (wxHORIZONTAL|wxVERTICAL)),
+                           (void (*)())wxScrollBarCallback );
+
+    PostCreation();
+    AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
+                  pos.x, pos.y, newSize.x, newSize.y);
+
+    return true;
 }
 
 wxScrollBar::~wxScrollBar()
 {
 }
 
 }
 
 wxScrollBar::~wxScrollBar()
 {
 }
 
-void wxScrollBar::SetPosition(int viewStart)
+void wxScrollBar::SetThumbPosition(int pos)
 {
 {
-    // TODO
+    XtVaSetValues ((Widget) m_mainWidget,
+                   XmNvalue, pos,
+                   NULL);
 }
 
 }
 
-int wxScrollBar::GetPosition() const
+int wxScrollBar::GetThumbPosition() const
 {
 {
-    // TODO
-    return 0;
+    int pos;
+    XtVaGetValues((Widget) m_mainWidget,
+                  XmNvalue, &pos, NULL);
+    return pos;
 }
 
 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
 }
 
 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
-    bool refresh)
+    bool WXUNUSED(refresh))
 {
     m_viewSize = pageSize;
     m_pageSize = thumbSize;
     m_objectSize = range;
 
 {
     m_viewSize = pageSize;
     m_pageSize = thumbSize;
     m_objectSize = range;
 
-    // TODO
-}
+    if (range == 0)
+      range = 1;
+    if (thumbSize == 0)
+      thumbSize = 1;
 
 
+    XtVaSetValues((Widget) m_mainWidget,
+         XmNvalue, position,
+         XmNminimum, 0,
+         XmNmaximum, range,
+         XmNsliderSize, thumbSize,
+         XmNpageIncrement, pageSize,
+         NULL);
+}
 
 void wxScrollBar::Command(wxCommandEvent& event)
 {
 
 void wxScrollBar::Command(wxCommandEvent& event)
 {
-    SetPosition(event.m_commandInt);
+    SetThumbPosition(event.GetInt());
     ProcessCommand(event);
 }
 
     ProcessCommand(event);
 }
 
+void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize))
+{
+    // TODO
+    // Do anything for a scrollbar? A font will never be seen.
+}
+
+void wxScrollBar::ChangeBackgroundColour()
+{
+    wxWindow::ChangeBackgroundColour();
+
+    XtVaSetValues ((Widget) GetMainWidget(),
+        XmNtroughColor, m_backgroundColour.AllocColour(XtDisplay((Widget) GetMainWidget())),
+        NULL);
+}
+
+static void wxScrollBarCallback(Widget widget, XtPointer clientData,
+                                XmScaleCallbackStruct *cbs)
+{
+    wxScrollBar *scrollBar = (wxScrollBar*)wxGetWindowFromTable(widget);
+    wxCHECK_RET( scrollBar, _T("invalid widget in scrollbar callback") );
+
+    wxOrientation orientation = (wxOrientation)wxPtrToUInt(clientData);
+    wxEventType eventType = wxEVT_NULL;
+
+    switch (cbs->reason)
+    {
+        case XmCR_INCREMENT:
+        {
+            eventType = wxEVT_SCROLL_LINEDOWN;
+            break;
+        }
+        case XmCR_DECREMENT:
+        {
+            eventType = wxEVT_SCROLL_LINEUP;
+            break;
+        }
+        case XmCR_DRAG:
+        {
+            eventType = wxEVT_SCROLL_THUMBTRACK;
+            break;
+        }
+        case XmCR_VALUE_CHANGED:
+        {
+            eventType = wxEVT_SCROLL_THUMBRELEASE;
+            break;
+        }
+        case XmCR_PAGE_INCREMENT:
+        {
+            eventType = wxEVT_SCROLL_PAGEDOWN;
+            break;
+        }
+        case XmCR_PAGE_DECREMENT:
+        {
+            eventType = wxEVT_SCROLL_PAGEUP;
+            break;
+        }
+        case XmCR_TO_TOP:
+        {
+            eventType = wxEVT_SCROLL_TOP;
+            break;
+        }
+        case XmCR_TO_BOTTOM:
+        {
+            eventType = wxEVT_SCROLL_BOTTOM;
+            break;
+        }
+        default:
+        {
+            // Should never get here
+            wxFAIL_MSG("Unknown scroll event.");
+            break;
+        }
+    }
+
+    wxScrollEvent event(eventType, scrollBar->GetId(),
+                        cbs->value, orientation);
+    event.SetEventObject(scrollBar);
+    scrollBar->HandleWindowEvent(event);
+}