]> git.sesse.net Git - vlc/commitdiff
- wxwidgets: for win32, patch movie wxSlider underlying control behaviour so that...
authorDamien Fouilleul <damienf@videolan.org>
Fri, 4 May 2007 17:57:30 +0000 (17:57 +0000)
committerDamien Fouilleul <damienf@videolan.org>
Fri, 4 May 2007 17:57:30 +0000 (17:57 +0000)
modules/gui/wxwidgets/input_manager.cpp

index efa475989feaef6f8519c57960c748ca697af4b0..049d8cee643b529957a65b9872a43c9c87e2e2c1 100644 (file)
@@ -58,6 +58,57 @@ END_EVENT_TABLE()
 #define STATUS_PLAYING 1
 #define STATUS_PAUSE 2
 
+#if WIN32
+
+#include <commctrl.h>
+
+/*
+** On win32, clicking on the slider channel causes the thumb to jump up or down a page size
+** like a scrollbar.  This is not particularily useful for a movie track, where we'd rather
+** see the thumb to jump where the mouse is.
+** Therefore, we replace the slider (TRACKBAR control) window proc with our, which intercept
+** the mouse down event, and move the thumb accordingly
+*/
+static LRESULT CALLBACK MovieSliderWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+    switch( uMsg )
+    {
+        case WM_LBUTTONDOWN:
+        {
+            POINT click = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
+            RECT tRect = {0, 0, 0, 0};
+            SendMessage(hWnd, TBM_GETTHUMBRECT, 0, (LPARAM)&tRect);
+
+            /* check whether click is not in thumb */
+            if( ! PtInRect(&tRect, click) )
+            {
+                LONG min = SendMessage(hWnd, TBM_GETRANGEMIN, 0, 0);
+                LONG max = SendMessage(hWnd, TBM_GETRANGEMAX, 0, 0);
+                LONG thumb = SendMessage(hWnd, TBM_GETTHUMBLENGTH, 0, 0);;
+                LONG newpos;
+
+                SendMessage(hWnd, TBM_GETCHANNELRECT, 0, (LPARAM)&tRect);
+
+                /* following is only valid for horizontal trackbar */
+                newpos = ((click.x-tRect.left-(thumb/2))*(max-min)+((tRect.right-tRect.left-thumb)/2))/(tRect.right-tRect.left-thumb);
+
+                /* set new postion */
+                SendMessage(hWnd, TBM_SETPOS, TRUE, newpos);
+                /* notify parent of change */
+                SendMessage(GetParent(hWnd), WM_HSCROLL, TB_ENDTRACK, (LPARAM)hWnd);
+
+                return 0;
+            }
+        }
+
+        default:
+            return CallWindowProc((WNDPROC)GetWindowLongPtr(hWnd, GWLP_USERDATA),
+                        hWnd, uMsg, wParam, lParam);
+    }
+}
+
+#endif
+
 /*****************************************************************************
  * Constructor.
  *****************************************************************************/
@@ -76,6 +127,20 @@ InputManager::InputManager( intf_thread_t *_p_intf, Interface *_p_main_intf,
     /* Create slider */
     slider = new wxSlider( this, SliderScroll_Event, 0, 0, SLIDER_MAX_POS );
 
+#if WIN32
+    /* modify behaviour of WIN32 underlying control
+      in order to implement proper movie slider */
+    {
+        HWND sliderHwnd = (HWND)slider->GetHWND();
+        /* put original WNDPROC into USERDATA, this may be incompatible with future version of
+           wxwidgets. */
+        SetWindowLongPtr(sliderHwnd, GWLP_USERDATA,
+            (LONG_PTR)GetWindowLongPtr(sliderHwnd, GWLP_WNDPROC));
+        /* put our own WNDPROC */
+        SetWindowLongPtr(sliderHwnd, GWLP_WNDPROC, (LONG_PTR)MovieSliderWindowProc);
+    }
+#endif
+
     /* Create disc buttons */
     disc_frame = new wxPanel( this );