]> git.saurik.com Git - wxWidgets.git/blobdiff - src/motif/scrolbar.cpp
merged libpng 1.2.34 into the trunk (see #10043)
[wxWidgets.git] / src / motif / scrolbar.cpp
index e0a15b4a4ccdbfdd788b6d2e74a4923c14f29987..587be3ca89c15c7acafdeed8b6a333ee20f1e0f6 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        scrolbar.cpp
+// Name:        src/motif/scrolbar.cpp
 // Purpose:     wxScrollBar
 // Author:      Julian Smart
 // Modified by:
@@ -9,20 +9,15 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-#pragma implementation "scrolbar.h"
-#endif
-
-#include "wx/defs.h"
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
 
 #include "wx/scrolbar.h"
 
 #ifdef __VMS__
 #pragma message disable nosimpint
 #endif
-#include <X11/IntrinsicP.h>
 #include <Xm/Xm.h>
-#include <Xm/RowColumn.h>
 #include <Xm/ScrollBar.h>
 #ifdef __VMS__
 #pragma message enable nosimpint
@@ -42,65 +37,27 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
            const wxValidator& validator,
            const wxString& name)
 {
-    if (!parent)
-        return FALSE;
-    parent->AddChild(this);
-    SetName(name);
-    m_backgroundColour = parent->GetBackgroundColour();
-    m_foregroundColour = parent->GetForegroundColour();
-    SetValidator(validator);
-
-    m_windowStyle = style;
-
-    if ( id == -1 )
-        m_windowId = (int)NewControlId();
-    else
-        m_windowId = id;
-
-    int x = pos.x;
-    int y = pos.y;
-    int width = size.x;
-    int height = size.y;
-
-    if (width == -1)
-    {
-      if (style & wxHORIZONTAL)
-        width = 140;
-      else
-        width = 12;
-    }
-    if (height == -1)
-    {
-      if (style & wxVERTICAL)
-        height = 140;
-      else
-        height = 12;
-    }
-
-    Widget parentWidget = (Widget) parent->GetClientWidget();
-    int direction = (style & wxHORIZONTAL) ? XmHORIZONTAL: XmVERTICAL;
+    if( !CreateControl( parent, id, pos, size, style, validator, name ) )
+        return false;
+    PreCreation();
 
-    Widget scrollBarWidget = XtVaCreateManagedWidget("scrollBarWidget",
-                  xmScrollBarWidgetClass,  parentWidget,
-                  XmNorientation,      direction,
-                  NULL);
+    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;
 
-    m_mainWidget = (Widget) scrollBarWidget;
+    Widget parentWidget = (Widget) parent->GetClientWidget();
 
-    XtAddCallback(scrollBarWidget, XmNvalueChangedCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
-    XtAddCallback(scrollBarWidget, XmNdragCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
-    XtAddCallback(scrollBarWidget, XmNdecrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
-    XtAddCallback(scrollBarWidget, XmNincrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
-    XtAddCallback(scrollBarWidget, XmNpageDecrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
-    XtAddCallback(scrollBarWidget, XmNpageIncrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
-    XtAddCallback(scrollBarWidget, XmNtoTopCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
-    XtAddCallback(scrollBarWidget, XmNtoBottomCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
+    m_mainWidget =
+        DoCreateScrollBar( (WXWidget)parentWidget,
+                           (wxOrientation)(style & (wxHORIZONTAL|wxVERTICAL)),
+                           (void (*)())wxScrollBarCallback );
 
-    SetCanAddEventHandler(TRUE);
-    AttachWidget (parent, m_mainWidget, (WXWidget) NULL, x, y, width, height);
-    ChangeBackgroundColour();
+    PostCreation();
+    AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
+                  pos.x, pos.y, newSize.x, newSize.y);
 
-    return TRUE;
+    return true;
 }
 
 wxScrollBar::~wxScrollBar()
@@ -109,25 +66,17 @@ wxScrollBar::~wxScrollBar()
 
 void wxScrollBar::SetThumbPosition(int pos)
 {
-       if (m_mainWidget)
-       {
-               XtVaSetValues ((Widget) m_mainWidget,
-                               XmNvalue, pos,
-                               NULL);
-       }
+    XtVaSetValues ((Widget) m_mainWidget,
+                   XmNvalue, pos,
+                   NULL);
 }
 
 int wxScrollBar::GetThumbPosition() const
 {
-       if (m_mainWidget)
-       {
-        int pos;
-        XtVaGetValues((Widget) m_mainWidget,
-            XmNvalue, &pos, NULL);
-        return pos;
-    }
-    else
-        return 0;
+    int pos;
+    XtVaGetValues((Widget) m_mainWidget,
+                  XmNvalue, &pos, NULL);
+    return pos;
 }
 
 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
@@ -153,7 +102,7 @@ void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageS
 
 void wxScrollBar::Command(wxCommandEvent& event)
 {
-    SetThumbPosition(event.m_commandInt);
+    SetThumbPosition(event.GetInt());
     ProcessCommand(event);
 }
 
@@ -172,15 +121,13 @@ void wxScrollBar::ChangeBackgroundColour()
         NULL);
 }
 
-void wxScrollBar::ChangeForegroundColour()
+static void wxScrollBarCallback(Widget widget, XtPointer clientData,
+                                XmScaleCallbackStruct *cbs)
 {
-    wxWindow::ChangeForegroundColour();
-}
+    wxScrollBar *scrollBar = (wxScrollBar*)wxGetWindowFromTable(widget);
+    wxCHECK_RET( scrollBar, _T("invalid widget in scrollbar callback") );
 
-static void wxScrollBarCallback(Widget WXUNUSED(widget), XtPointer clientData,
-                        XmScaleCallbackStruct *cbs)
-{
-    wxScrollBar *scrollBar = (wxScrollBar *)clientData;
+    wxOrientation orientation = (wxOrientation)wxPtrToUInt(clientData);
     wxEventType eventType = wxEVT_NULL;
 
     switch (cbs->reason)
@@ -233,13 +180,8 @@ static void wxScrollBarCallback(Widget WXUNUSED(widget), XtPointer clientData,
         }
     }
 
-    wxScrollEvent event(eventType, scrollBar->GetId());
+    wxScrollEvent event(eventType, scrollBar->GetId(),
+                        cbs->value, orientation);
     event.SetEventObject(scrollBar);
-    event.SetPosition(cbs->value);
-    scrollBar->GetEventHandler()->ProcessEvent(event);
-/*
-    if (!scrollBar->inSetValue)
-      scrollBar->ProcessCommand(event);
-*/
+    scrollBar->HandleWindowEvent(event);
 }
-