]> git.saurik.com Git - wxWidgets.git/blobdiff - src/univ/slider.cpp
Make status bar grip move to the left in RTL.
[wxWidgets.git] / src / univ / slider.cpp
index d96bd7c500e0851dadb67b45a1fe2b10beeda523..4df2aae29a84810976ef866ca7ce4adba8d2d65a 100644 (file)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
-// Name:        univ/slider.cpp
+// Name:        src/univ/slider.cpp
 // Purpose:     implementation of the universal version of wxSlider
 // Author:      Vadim Zeitlin
 // Modified by:
 // Purpose:     implementation of the universal version of wxSlider
 // Author:      Vadim Zeitlin
 // Modified by:
 // headers
 // ----------------------------------------------------------------------------
 
 // headers
 // ----------------------------------------------------------------------------
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-    #pragma implementation "univslider.h"
-#endif
-
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
     #pragma hdrstop
 #endif
 
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
     #pragma hdrstop
 #endif
 
-#ifndef WX_PRECOMP
-    #include "wx/dc.h"
-#endif
+#if wxUSE_SLIDER
 
 #include "wx/slider.h"
 
 
 #include "wx/slider.h"
 
-#if wxUSE_SLIDER
+#ifndef WX_PRECOMP
+    #include "wx/dc.h"
+#endif
 
 #include "wx/univ/renderer.h"
 #include "wx/univ/inphand.h"
 #include "wx/univ/theme.h"
 
 
 #include "wx/univ/renderer.h"
 #include "wx/univ/inphand.h"
 #include "wx/univ/theme.h"
 
+// ----------------------------------------------------------------------------
+// wxStdSliderInputHandler: default slider input handling
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxStdSliderInputHandler : public wxStdInputHandler
+{
+public:
+    // default ctor
+    wxStdSliderInputHandler(wxInputHandler *inphand)
+        : wxStdInputHandler(inphand)
+    {
+    }
+
+    // base class methods
+    virtual bool HandleKey(wxInputConsumer *consumer,
+                           const wxKeyEvent& event,
+                           bool pressed);
+    virtual bool HandleMouse(wxInputConsumer *consumer,
+                             const wxMouseEvent& event);
+    virtual bool HandleMouseMove(wxInputConsumer *consumer,
+                                 const wxMouseEvent& event);
+
+    virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event);
+};
+
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
@@ -184,7 +205,8 @@ bool wxSlider::ChangeValueBy(int inc)
 bool wxSlider::ChangeValueTo(int value)
 {
     // check if the value is going to change at all
 bool wxSlider::ChangeValueTo(int value)
 {
     // check if the value is going to change at all
-    if (value == m_value) return false;
+    if (value == m_value)
+        return false;
 
     // this method is protected and we should only call it with normalized
     // value!
 
     // this method is protected and we should only call it with normalized
     // value!
@@ -194,11 +216,15 @@ bool wxSlider::ChangeValueTo(int value)
 
     Refresh();
 
 
     Refresh();
 
-    // generate the event
+    // generate the events: both a specific scroll event and a command event
+    wxScrollEvent eventScroll(wxEVT_SCROLL_CHANGED, GetId());
+    eventScroll.SetPosition(m_value);
+    eventScroll.SetEventObject( this );
+    (void)GetEventHandler()->ProcessEvent(eventScroll);
+
     wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId());
     event.SetInt(m_value);
     event.SetEventObject(this);
     wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId());
     event.SetInt(m_value);
     event.SetEventObject(this);
-
     (void)GetEventHandler()->ProcessEvent(event);
 
     return true;
     (void)GetEventHandler()->ProcessEvent(event);
 
     return true;
@@ -743,52 +769,91 @@ bool wxSlider::PerformAction(const wxControlAction& action,
                              long numArg,
                              const wxString& strArg)
 {
                              long numArg,
                              const wxString& strArg)
 {
-     if ( action == wxACTION_SLIDER_START )
+    wxEventType scrollEvent = wxEVT_NULL;
+    int value;
+    bool valueChanged = true;
+
+    if ( action == wxACTION_SLIDER_START )
     {
     {
-        ChangeValueTo(m_min);
+        scrollEvent = wxEVT_SCROLL_TOP;
+        value = m_min;
     }
     else if ( action == wxACTION_SLIDER_END )
     {
     }
     else if ( action == wxACTION_SLIDER_END )
     {
-        ChangeValueTo(m_max);
+        scrollEvent = wxEVT_SCROLL_BOTTOM;
+        value = m_max;
     }
     else if ( action == wxACTION_SLIDER_PAGE_CHANGE )
     {
     }
     else if ( action == wxACTION_SLIDER_PAGE_CHANGE )
     {
-        ChangeValueBy(numArg * GetPageSize());
+        value = NormalizeValue(m_value + numArg * GetPageSize());
     }
     else if ( action == wxACTION_SLIDER_LINE_UP )
     {
     }
     else if ( action == wxACTION_SLIDER_LINE_UP )
     {
-        ChangeValueBy(+GetLineSize());
+        scrollEvent = wxEVT_SCROLL_LINEUP;
+        value = NormalizeValue(m_value + +GetLineSize());
     }
     else if ( action == wxACTION_SLIDER_LINE_DOWN )
     {
     }
     else if ( action == wxACTION_SLIDER_LINE_DOWN )
     {
-        ChangeValueBy(-GetLineSize());
+        scrollEvent = wxEVT_SCROLL_LINEDOWN;
+        value = NormalizeValue(m_value + -GetLineSize());
     }
     else if ( action == wxACTION_SLIDER_PAGE_UP )
     {
     }
     else if ( action == wxACTION_SLIDER_PAGE_UP )
     {
-        ChangeValueBy(+GetPageSize());
+        scrollEvent = wxEVT_SCROLL_PAGEUP;
+        value = NormalizeValue(m_value + +GetPageSize());
     }
     else if ( action == wxACTION_SLIDER_PAGE_DOWN )
     {
     }
     else if ( action == wxACTION_SLIDER_PAGE_DOWN )
     {
-        ChangeValueBy(-GetPageSize());
+        scrollEvent = wxEVT_SCROLL_PAGEDOWN;
+        value = NormalizeValue(m_value + -GetPageSize());
     }
     }
-    else if ( action == wxACTION_SLIDER_THUMB_DRAG )
+    else if ( action == wxACTION_SLIDER_THUMB_DRAG ||
+                action == wxACTION_SLIDER_THUMB_MOVE )
     {
     {
-        // no special processing for it
-        return true;
+        scrollEvent = wxEVT_SCROLL_THUMBTRACK;
+
+        // we shouldn't generate a command event about this change but we still
+        // should update our value and the slider appearance
+        valueChanged = false;
+        m_value =
+        value = (int)numArg;
+        Refresh();
     }
     }
-    else if ( action == wxACTION_SLIDER_THUMB_MOVE ||
-              action == wxACTION_SLIDER_THUMB_RELEASE )
+    else if ( action == wxACTION_SLIDER_THUMB_RELEASE )
     {
     {
-        ChangeValueTo((int)numArg);
+        scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
+        value = (int)numArg;
     }
     else
     {
         return wxControl::PerformAction(action, numArg, strArg);
     }
 
     }
     else
     {
         return wxControl::PerformAction(action, numArg, strArg);
     }
 
+    // update wxSlider current value and generate wxCommandEvent, except while
+    // dragging the thumb
+    if ( valueChanged )
+        ChangeValueTo(value);
+
+    // also generate more precise wxScrollEvent if applicable
+    if ( scrollEvent != wxEVT_NULL )
+    {
+        wxScrollEvent event(scrollEvent, GetId());
+        event.SetPosition(value);
+        event.SetEventObject( this );
+        GetEventHandler()->ProcessEvent(event);
+    }
+
     return true;
 }
 
     return true;
 }
 
+/* static */
+wxInputHandler *wxSlider::GetStdInputHandler(wxInputHandler *handlerDef)
+{
+    static wxStdSliderInputHandler s_handler(handlerDef);
+
+    return &s_handler;
+}
+
 // ----------------------------------------------------------------------------
 // wxSlider implementation of wxControlWithThumb interface
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // wxSlider implementation of wxControlWithThumb interface
 // ----------------------------------------------------------------------------
@@ -800,7 +865,7 @@ wxScrollThumb::Shaft wxSlider::HitTest(const wxPoint& pt) const
     CalcThumbRect(&rectShaft, &rectThumb, NULL);
 
     // check for possible shaft or thumb hit
     CalcThumbRect(&rectShaft, &rectThumb, NULL);
 
     // check for possible shaft or thumb hit
-    if (!rectShaft.Inside(pt) && !rectThumb.Inside(pt))
+    if (!rectShaft.Contains(pt) && !rectThumb.Contains(pt))
     {
         return wxScrollThumb::Shaft_None;
     }
     {
         return wxScrollThumb::Shaft_None;
     }
@@ -823,13 +888,13 @@ wxScrollThumb::Shaft wxSlider::HitTest(const wxPoint& pt) const
         x3 = rectThumb.GetRight();
         x4 = rectShaft.GetRight();
     }
         x3 = rectThumb.GetRight();
         x4 = rectShaft.GetRight();
     }
-    if ((x1 <= x) & (x < x2))
+    if ((x1 <= x) && (x < x2))
     {
         // or to the left
         return wxScrollThumb::Shaft_Above;
     }
 
     {
         // or to the left
         return wxScrollThumb::Shaft_Above;
     }
 
-    if ((x3 < x) & (x <= x4)) {
+    if ((x3 < x) && (x <= x4)) {
         // or to the right
         return wxScrollThumb::Shaft_Below;
     }
         // or to the right
         return wxScrollThumb::Shaft_Below;
     }
@@ -945,14 +1010,14 @@ bool wxSlider::OnPageScroll(int pageInc)
 }
 
 // ----------------------------------------------------------------------------
 }
 
 // ----------------------------------------------------------------------------
-// wxStdSliderButtonInputHandler
+// wxStdSliderInputHandler
 // ----------------------------------------------------------------------------
 
 // ----------------------------------------------------------------------------
 
-bool wxStdSliderButtonInputHandler::HandleKey(wxInputConsumer *consumer,
+bool wxStdSliderInputHandler::HandleKey(wxInputConsumer *consumer,
                                               const wxKeyEvent& event,
                                               bool pressed)
 {
                                               const wxKeyEvent& event,
                                               bool pressed)
 {
-   if ( pressed )
+    if ( pressed )
     {
         int keycode = event.GetKeyCode();
 
     {
         int keycode = event.GetKeyCode();
 
@@ -977,12 +1042,10 @@ bool wxStdSliderButtonInputHandler::HandleKey(wxInputConsumer *consumer,
                 action = wxACTION_SLIDER_LINE_DOWN;
                 break;
 
                 action = wxACTION_SLIDER_LINE_DOWN;
                 break;
 
-            case WXK_PRIOR:
             case WXK_PAGEUP:
                 action = wxACTION_SLIDER_PAGE_UP;
                 break;
 
             case WXK_PAGEUP:
                 action = wxACTION_SLIDER_PAGE_UP;
                 break;
 
-            case WXK_NEXT:
             case WXK_PAGEDOWN:
                 action = wxACTION_SLIDER_PAGE_DOWN;
                 break;
             case WXK_PAGEDOWN:
                 action = wxACTION_SLIDER_PAGE_DOWN;
                 break;
@@ -999,7 +1062,7 @@ bool wxStdSliderButtonInputHandler::HandleKey(wxInputConsumer *consumer,
     return wxStdInputHandler::HandleKey(consumer, event, pressed);
 }
 
     return wxStdInputHandler::HandleKey(consumer, event, pressed);
 }
 
-bool wxStdSliderButtonInputHandler::HandleMouse(wxInputConsumer *consumer,
+bool wxStdSliderInputHandler::HandleMouse(wxInputConsumer *consumer,
                                                 const wxMouseEvent& event)
 {
     wxSlider *slider = wxStaticCast(consumer->GetInputWindow(), wxSlider);
                                                 const wxMouseEvent& event)
 {
     wxSlider *slider = wxStaticCast(consumer->GetInputWindow(), wxSlider);
@@ -1013,7 +1076,7 @@ bool wxStdSliderButtonInputHandler::HandleMouse(wxInputConsumer *consumer,
     return wxStdInputHandler::HandleMouse(consumer, event);
 }
 
     return wxStdInputHandler::HandleMouse(consumer, event);
 }
 
-bool wxStdSliderButtonInputHandler::HandleMouseMove(wxInputConsumer *consumer,
+bool wxStdSliderInputHandler::HandleMouseMove(wxInputConsumer *consumer,
                                                     const wxMouseEvent& event)
 {
     wxSlider *slider = wxStaticCast(consumer->GetInputWindow(), wxSlider);
                                                     const wxMouseEvent& event)
 {
     wxSlider *slider = wxStaticCast(consumer->GetInputWindow(), wxSlider);
@@ -1028,10 +1091,10 @@ bool wxStdSliderButtonInputHandler::HandleMouseMove(wxInputConsumer *consumer,
 }
 
 bool
 }
 
 bool
-wxStdSliderButtonInputHandler::HandleFocus(wxInputConsumer * WXUNUSED(consumer),
+wxStdSliderInputHandler::HandleFocus(wxInputConsumer * WXUNUSED(consumer),
                                            const wxFocusEvent& WXUNUSED(event))
 {
                                            const wxFocusEvent& WXUNUSED(event))
 {
-    // slider's appearance changes when it gets/loses focus
+    // slider appearance changes when it gets/loses focus
     return true;
 }
 
     return true;
 }