]> git.saurik.com Git - wxWidgets.git/blobdiff - src/motif/scrolbar.cpp
[wxGTK] wxFileDialog: Use native overwrite confirmation if possible
[wxWidgets.git] / src / motif / scrolbar.cpp
index f6f2df3d3635727e026d02a508b8ab0bf9be2d73..bb3f97a8d24262bd4506ade89412a5af3da16c89 100644 (file)
@@ -9,25 +9,32 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
 #pragma implementation "scrolbar.h"
 #endif
 
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#include "wx/defs.h"
 #include "wx/scrolbar.h"
 
-#include <X11/IntrinsicP.h>
+#ifdef __VMS__
+#pragma message disable nosimpint
+#define XtDisplay XTDISPLAY
+#endif
 #include <Xm/Xm.h>
-#include <Xm/RowColumn.h>
 #include <Xm/ScrollBar.h>
+#ifdef __VMS__
+#pragma message enable nosimpint
+#endif
 
-#include <wx/motif/private.h>
+#include "wx/motif/private.h"
 
 static void wxScrollBarCallback(Widget widget, XtPointer clientData,
                         XmScaleCallbackStruct *cbs);
 
-#if !USE_SHARED_LIBRARY
 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
-#endif
 
 // Scrollbar
 bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
@@ -36,66 +43,26 @@ 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;
-    }
+    if( !CreateControl( parent, id, pos, size, style, validator, name ) )
+        return false;
+
+    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();
-    int direction = (style & wxHORIZONTAL) ? XmHORIZONTAL: XmVERTICAL;
-
-    Widget scrollBarWidget = XtVaCreateManagedWidget("scrollBarWidget",
-                  xmScrollBarWidgetClass,  parentWidget,
-                  XmNorientation,      direction,
-                  NULL);
-
-    m_mainWidget = (Widget) scrollBarWidget;
-
-    // This will duplicate other events
-    //    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);
-
-    SetCanAddEventHandler(TRUE);
-    AttachWidget (parent, m_mainWidget, (WXWidget) NULL, x, y, width, height);
+
+    m_mainWidget =
+        DoCreateScrollBar( (WXWidget)parentWidget,
+                           (wxOrientation)(style & (wxHORIZONTAL|wxVERTICAL)),
+                           (void (*)())wxScrollBarCallback );
+
+    AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
+                  pos.x, pos.y, newSize.x, newSize.y);
     ChangeBackgroundColour();
 
-    return TRUE;
+    return true;
 }
 
 wxScrollBar::~wxScrollBar()
@@ -104,29 +71,21 @@ 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,
-    bool refresh)
+    bool WXUNUSED(refresh))
 {
     m_viewSize = pageSize;
     m_pageSize = thumbSize;
@@ -148,11 +107,11 @@ 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);
 }
 
-void wxScrollBar::ChangeFont(bool keepOriginalSize)
+void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize))
 {
     // TODO
     // Do anything for a scrollbar? A font will never be seen.
@@ -167,17 +126,13 @@ void wxScrollBar::ChangeBackgroundColour()
         NULL);
 }
 
-void wxScrollBar::ChangeForegroundColour()
-{
-    wxWindow::ChangeForegroundColour();
-}
-
 static void wxScrollBarCallback(Widget widget, XtPointer clientData,
-                        XmScaleCallbackStruct *cbs)
+                                XmScaleCallbackStruct *cbs)
 {
-    wxScrollBar *scrollBar = (wxScrollBar *)clientData;
-
+    wxScrollBar *scrollBar = (wxScrollBar*)wxGetWindowFromTable(widget);
+    wxOrientation orientation = (wxOrientation)(int)clientData;
     wxEventType eventType = wxEVT_NULL;
+
     switch (cbs->reason)
     {
         case XmCR_INCREMENT:
@@ -197,9 +152,7 @@ static void wxScrollBarCallback(Widget widget, XtPointer clientData,
         }
         case XmCR_VALUE_CHANGED:
         {
-            // TODO: Should this be intercepted too, or will it cause
-            // duplicate events?
-            eventType = wxEVT_SCROLL_THUMBTRACK;
+            eventType = wxEVT_SCROLL_THUMBRELEASE;
             break;
         }
         case XmCR_PAGE_INCREMENT:
@@ -230,13 +183,8 @@ static void wxScrollBarCallback(Widget 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);
-*/
 }
-