]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/slider95.cpp
implement wxListBox::EnsureVisible() in wxGTK; add a test for it to the widgets sample
[wxWidgets.git] / src / msw / slider95.cpp
index 5db488c88c865275609ea9c10e00f9087b99af2a..1ebdb425dce97d8f5f4873a7fe1f9d5f8abe0bc2 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        msw/slider.cpp
+// Name:        src/msw/slider.cpp
 // Purpose:     wxSlider, using the Win95 (and later) trackbar control
 // Author:      Julian Smart
 // Modified by:
 // declarations
 // ============================================================================
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "slider95.h"
-#endif
-
 // ----------------------------------------------------------------------------
 // headers
 // ----------------------------------------------------------------------------
 
 #if wxUSE_SLIDER
 
+#include "wx/slider.h"
+
 #ifndef WX_PRECOMP
+    #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
     #include "wx/brush.h"
 #endif
 
-#include "wx/slider.h"
 #include "wx/msw/subwin.h"
 
-#if !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
-    #include <commctrl.h>
-#endif
-
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
@@ -107,10 +101,10 @@ wxBEGIN_FLAGS( wxSliderStyle )
 
 wxEND_FLAGS( wxSliderStyle )
 
-IMPLEMENT_DYNAMIC_CLASS_XTI(wxSlider, wxControl,"wx/scrolbar.h")
+IMPLEMENT_DYNAMIC_CLASS_XTI(wxSlider, wxControl,"wx/slider.h")
 
 wxBEGIN_PROPERTIES_TABLE(wxSlider)
-    wxEVENT_RANGE_PROPERTY( Scroll , wxEVT_SCROLL_TOP , wxEVT_SCROLL_ENDSCROLL , wxScrollEvent )
+    wxEVENT_RANGE_PROPERTY( Scroll , wxEVT_SCROLL_TOP , wxEVT_SCROLL_CHANGED , wxScrollEvent )
     wxEVENT_PROPERTY( Updated , wxEVT_COMMAND_SLIDER_UPDATED , wxCommandEvent )
 
     wxPROPERTY( Value , int , SetValue, GetValue , 0, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
@@ -147,6 +141,8 @@ void wxSlider::Init()
     m_rangeMax = 0;
     m_rangeMin = 0;
     m_tickFreq = 0;
+
+    m_isDragging = false;
 }
 
 bool
@@ -186,7 +182,7 @@ wxSlider::Create(wxWindow *parent,
             }
     };
 
-    wxASSERT_MSG( !(style & wxSL_VERTICAL) | !(style & wxSL_HORIZONTAL),
+    wxASSERT_MSG( !(style & wxSL_VERTICAL) || !(style & wxSL_HORIZONTAL),
                     _T("incompatible slider direction and orientation") );
 
 
@@ -212,17 +208,21 @@ wxSlider::Create(wxWindow *parent,
         HWND hwndParent = GetHwndOf(parent);
         for ( size_t n = 0; n < SliderLabel_Last; n++ )
         {
-            (*m_labels)[n] = ::CreateWindow
-                               (
-                                    wxT("STATIC"),
-                                    NULL,
-                                    WS_CHILD | WS_VISIBLE | SS_CENTER,
-                                    0, 0, 0, 0,
-                                    hwndParent,
-                                    (HMENU)NewControlId(),
-                                    wxGetInstance(),
-                                    NULL
-                               );
+            wxWindowIDRef lblid = NewControlId();
+
+            HWND wnd = ::CreateWindow
+                         (
+                            wxT("STATIC"),
+                            NULL,
+                            WS_CHILD | WS_VISIBLE | SS_CENTER,
+                            0, 0, 0, 0,
+                            hwndParent,
+                            (HMENU)lblid.GetValue(),
+                            wxGetInstance(),
+                            NULL
+                         );
+
+            m_labels->Set(n, wnd, lblid);
         }
 
         m_labels->SetFont(GetFont());
@@ -326,14 +326,29 @@ bool wxSlider::MSWOnScroll(int WXUNUSED(orientation),
 
         case SB_THUMBTRACK:
             scrollEvent = wxEVT_SCROLL_THUMBTRACK;
+            m_isDragging = true;
             break;
 
         case SB_THUMBPOSITION:
-            scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
+            if ( m_isDragging )
+            {
+                scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
+                m_isDragging = false;
+            }
+            else
+            {
+                // this seems to only happen when the mouse wheel is used: in
+                // this case, as it might be unexpected to get THUMBRELEASE
+                // without preceding THUMBTRACKs, we don't generate it at all
+                // but generate CHANGED event because the control itself does
+                // not send us SB_ENDSCROLL for whatever reason when mouse
+                // wheel is used
+                scrollEvent = wxEVT_SCROLL_CHANGED;
+            }
             break;
 
         case SB_ENDSCROLL:
-            scrollEvent = wxEVT_SCROLL_ENDSCROLL;
+            scrollEvent = wxEVT_SCROLL_CHANGED;
             break;
 
         default:
@@ -353,13 +368,13 @@ bool wxSlider::MSWOnScroll(int WXUNUSED(orientation),
     wxScrollEvent event(scrollEvent, m_windowId);
     event.SetPosition(newPos);
     event.SetEventObject( this );
-    GetEventHandler()->ProcessEvent(event);
+    HandleWindowEvent(event);
 
     wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() );
     cevent.SetInt( newPos );
     cevent.SetEventObject( this );
 
-    return GetEventHandler()->ProcessEvent( cevent );
+    return HandleWindowEvent( cevent );
 }
 
 void wxSlider::Command (wxCommandEvent & event)
@@ -453,22 +468,20 @@ void wxSlider::DoMoveWindow(int x, int y, int width, int height)
 
         // position all labels: min at the top, value in the middle and max at
         // the bottom
-        ::MoveWindow((*m_labels)[SliderLabel_Min],
-                     xLabel, y, wLabel, hLabel, TRUE);
+        DoMoveSibling((HWND)(*m_labels)[SliderLabel_Min],
+                     xLabel, y, wLabel, hLabel);
 
-        ::MoveWindow((*m_labels)[SliderLabel_Value],
-                     xLabel, y + (height - hLabel)/2, wLabel, hLabel, TRUE);
+        DoMoveSibling((HWND)(*m_labels)[SliderLabel_Value],
+                     xLabel, y + (height - hLabel)/2, wLabel, hLabel);
 
-        ::MoveWindow((*m_labels)[SliderLabel_Max],
-                     xLabel, y + height - hLabel, wLabel, hLabel, TRUE);
+        DoMoveSibling((HWND)(*m_labels)[SliderLabel_Max],
+                      xLabel, y + height - hLabel, wLabel, hLabel);
 
         // position the slider itself along the left/right edge
-        ::MoveWindow(GetHwnd(),
-                     HasFlag(wxSL_LEFT) ? x : x + wLabel + HGAP,
-                     y + hLabel/2,
-                     width - wLabel - HGAP,
-                     height - hLabel,
-                     TRUE);
+        wxSliderBase::DoMoveWindow(HasFlag(wxSL_LEFT) ? x : x + wLabel + HGAP,
+                                   y + hLabel/2,
+                                   width - wLabel - HGAP,
+                                   height - hLabel);
     }
     else // horizontal
     {
@@ -479,22 +492,20 @@ void wxSlider::DoMoveWindow(int x, int y, int width, int height)
 
         // position all labels: min on the left, value in the middle and max to
         // the right
-        ::MoveWindow((*m_labels)[SliderLabel_Min],
-                     x, yLabel, wLabel, hLabel, TRUE);
+        DoMoveSibling((HWND)(*m_labels)[SliderLabel_Min],
+                      x, yLabel, wLabel, hLabel);
 
-        ::MoveWindow((*m_labels)[SliderLabel_Value],
-                     x + (width - wLabel)/2, yLabel, wLabel, hLabel, TRUE);
+        DoMoveSibling((HWND)(*m_labels)[SliderLabel_Value],
+                      x + (width - wLabel)/2, yLabel, wLabel, hLabel);
 
-        ::MoveWindow((*m_labels)[SliderLabel_Max],
-                     x + width - wLabel, yLabel, wLabel, hLabel, TRUE);
+        DoMoveSibling((HWND)(*m_labels)[SliderLabel_Max],
+                      x + width - wLabel, yLabel, wLabel, hLabel);
 
         // position the slider itself along the top/bottom edge
-        ::MoveWindow(GetHwnd(),
-                     x,
-                     HasFlag(wxSL_TOP) ? y : y + hLabel,
-                     width,
-                     height - hLabel,
-                     TRUE);
+        wxSliderBase::DoMoveWindow(x,
+                                   HasFlag(wxSL_TOP) ? y : y + hLabel,
+                                   width,
+                                   height - hLabel);
     }
 }
 
@@ -566,7 +577,7 @@ void wxSlider::SetValue(int value)
 
     if ( m_labels )
     {
-        ::SetWindowText((*m_labels)[SliderLabel_Value], Format(value));
+        ::SetWindowText((*m_labels)[SliderLabel_Value], Format(value).wx_str());
     }
 }
 
@@ -580,8 +591,10 @@ void wxSlider::SetRange(int minValue, int maxValue)
 
     if ( m_labels )
     {
-        ::SetWindowText((*m_labels)[SliderLabel_Min], Format(ValueInvertOrNot(m_rangeMin)));
-        ::SetWindowText((*m_labels)[SliderLabel_Max], Format(ValueInvertOrNot(m_rangeMax)));
+        ::SetWindowText((*m_labels)[SliderLabel_Min],
+                        Format(ValueInvertOrNot(m_rangeMin)).wx_str());
+        ::SetWindowText((*m_labels)[SliderLabel_Max],
+                        Format(ValueInvertOrNot(m_rangeMax)).wx_str());
     }
 }
 
@@ -625,7 +638,7 @@ int wxSlider::GetLineSize() const
 
 int wxSlider::GetSelEnd() const
 {
-    return (int)::SendMessage(GetHwnd(), TBM_SETSELEND, 0, 0);
+    return (int)::SendMessage(GetHwnd(), TBM_GETSELEND, 0, 0);
 }
 
 int wxSlider::GetSelStart() const