]> git.saurik.com Git - wxWidgets.git/commitdiff
Add support for horizontal mouse wheel scrolling in wxSTC.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 29 Jun 2013 12:52:58 +0000 (12:52 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 29 Jun 2013 12:52:58 +0000 (12:52 +0000)
Handle horizontal mouse wheel scrolling events in a similar (but simpler, as
they always scroll and never change the font size) way to the vertical ones in
wxStyledTextCtrl.

Closes #15266.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74312 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
src/stc/ScintillaWX.cpp
src/stc/ScintillaWX.h
src/stc/stc.cpp
src/stc/stc.cpp.in

index 5050dd61540d1a76f05a49d538bdb2a4bebe89d9..e149ab970e5d59380363a83cd48e1ed36effa612 100644 (file)
@@ -671,6 +671,7 @@ All (GUI):
 - Fix wxStyledTextCtrl::SetInsertionPointEnd() (troelsk).
 - Add wxFileDialog::GetCurrentlySelectedFilename() (Carl Godkin).
 - Add wxMouseEvent::GetColumnsPerAction() (toiffel).
+- Add support for horizontal mouse wheel scrolling in wxSTC (toiffel).
 - Improve wrapping of cell contents in wxGrid (nmset).
 
 wxGTK:
index 90779336696f95d3832491d179269ae123865c7e..84c0d35baaf22bb65da06ce50f67b55d45a4425a 100644 (file)
@@ -244,7 +244,8 @@ ScintillaWX::ScintillaWX(wxStyledTextCtrl* win) {
     focusEvent = false;
     wMain = win;
     stc   = win;
-    wheelRotation = 0;
+    wheelVRotation = 0;
+    wheelHRotation = 0;
     Initialise();
 #ifdef __WXMSW__
     sysCaretBitmap = 0;
@@ -830,13 +831,28 @@ void ScintillaWX::DoVScroll(int type, int pos) {
     ScrollTo(topLineNew);
 }
 
-void ScintillaWX::DoMouseWheel(int rotation, int delta,
-                               int linesPerAction, int ctrlDown,
-                               bool isPageScroll ) {
+void ScintillaWX::DoMouseWheel(wxMouseWheelAxis axis, int rotation, int delta,
+                               int linesPerAction, int columnsPerAction,
+                               bool ctrlDown, bool isPageScroll) {
     int topLineNew = topLine;
     int lines;
-
-    if (ctrlDown) {  // Zoom the fonts if Ctrl key down
+    int xPos = xOffset;
+    int pixels;
+
+    if (axis == wxMOUSE_WHEEL_HORIZONTAL) {
+        wheelHRotation += rotation * (columnsPerAction * vs.spaceWidth);
+        pixels = wheelHRotation / delta;
+        wheelHRotation -= pixels * delta;
+        if (pixels != 0) {
+            xPos += pixels;
+            PRectangle rcText = GetTextRectangle();
+            if (xPos > scrollWidth - rcText.Width()) {
+                xPos = scrollWidth - rcText.Width();
+            }
+            HorizontalScrollTo(xPos);
+        }
+    }
+    else if (ctrlDown) {  // Zoom the fonts if Ctrl key down
         if (rotation > 0) {
             KeyCommand(SCI_ZOOMIN);
         }
@@ -847,9 +863,9 @@ void ScintillaWX::DoMouseWheel(int rotation, int delta,
     else { // otherwise just scroll the window
         if ( !delta )
             delta = 120;
-        wheelRotation += rotation;
-        lines = wheelRotation / delta;
-        wheelRotation -= lines * delta;
+        wheelVRotation += rotation;
+        lines = wheelVRotation / delta;
+        wheelVRotation -= lines * delta;
         if (lines != 0) {
             if (isPageScroll)
                 lines = lines * LinesOnScreen();  // lines is either +1 or -1
index a7ac8023e084f9e464ac0ab4cf7790936caa4f6c..0f06c0a6d2200bff1ece80fa14d4ed9e93447fc4 100644 (file)
@@ -152,7 +152,9 @@ public:
     void DoLeftButtonUp(Point pt, unsigned int curTime, bool ctrl);
     void DoLeftButtonMove(Point pt);
     void DoMiddleButtonUp(Point pt);
-    void DoMouseWheel(int rotation, int delta, int linesPerAction, int ctrlDown, bool isPageScroll);
+    void DoMouseWheel(wxMouseWheelAxis axis, int rotation, int delta,
+                      int linesPerAction, int columnsPerAction,
+                      bool ctrlDown, bool isPageScroll);
     void DoAddChar(int key);
     int  DoKeyDown(const wxKeyEvent& event, bool* consumed);
     void DoTick() { Tick(); }
@@ -191,7 +193,8 @@ private:
     wxDragResult        dragResult;
 #endif
 
-    int                 wheelRotation;
+    int                 wheelVRotation;
+    int                 wheelHRotation;
 
     // For use in creating a system caret
     bool HasCaretSizeChanged();
index d4190e23fbb7f7c4a1f7642a893a0128c06581c6..64c3c3fd4542c4ed16ae29eb0958c7f763ef2e34 100644 (file)
@@ -4695,9 +4695,11 @@ void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent& evt) {
 
 void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt)
 {
-    m_swx->DoMouseWheel(evt.GetWheelRotation(),
+    m_swx->DoMouseWheel(evt.GetWheelAxis(),
+                        evt.GetWheelRotation(),
                         evt.GetWheelDelta(),
                         evt.GetLinesPerAction(),
+                        evt.GetColumnsPerAction(),
                         evt.ControlDown(),
                         evt.IsPageScroll());
 }
index 9a6562eed3ddab6adfe50d4954d14e72cf411274..f407276bbf17e0ba9fa9a85d5927e7ae689da3ff 100644 (file)
@@ -833,9 +833,11 @@ void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent& evt) {
 
 void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt)
 {
-    m_swx->DoMouseWheel(evt.GetWheelRotation(),
+    m_swx->DoMouseWheel(evt.GetWheelAxis(),
+                        evt.GetWheelRotation(),
                         evt.GetWheelDelta(),
                         evt.GetLinesPerAction(),
+                        evt.GetColumnsPerAction(),
                         evt.ControlDown(),
                         evt.IsPageScroll());
 }