From 37d6243357b65ce2a2fa7a35b848ebefb88a3912 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sun, 6 May 2001 01:20:41 +0000 Subject: [PATCH] Added MouseWheel support to wxSTC git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10013 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/include/wx/stc/stc.h | 1 + contrib/src/stc/ScintillaWX.cpp | 17 +++++++++++++++++ contrib/src/stc/ScintillaWX.h | 2 ++ contrib/src/stc/gen_iface.py | 6 +++--- contrib/src/stc/stc.cpp | 9 +++++++++ contrib/src/stc/stc.cpp.in | 9 +++++++++ contrib/src/stc/stc.h.in | 1 + include/wx/stc/stc.h | 1 + src/stc/ScintillaWX.cpp | 17 +++++++++++++++++ src/stc/ScintillaWX.h | 2 ++ src/stc/gen_iface.py | 6 +++--- src/stc/stc.cpp | 9 +++++++++ src/stc/stc.cpp.in | 9 +++++++++ src/stc/stc.h.in | 1 + 14 files changed, 84 insertions(+), 6 deletions(-) diff --git a/contrib/include/wx/stc/stc.h b/contrib/include/wx/stc/stc.h index e2ec7c4b95..f9b26bdb8a 100644 --- a/contrib/include/wx/stc/stc.h +++ b/contrib/include/wx/stc/stc.h @@ -1256,6 +1256,7 @@ private: void OnMouseMove(wxMouseEvent& evt); void OnMouseLeftUp(wxMouseEvent& evt); void OnMouseRightUp(wxMouseEvent& evt); + void OnMouseWheel(wxMouseEvent& evt); void OnChar(wxKeyEvent& evt); void OnKeyDown(wxKeyEvent& evt); void OnLoseFocus(wxFocusEvent& evt); diff --git a/contrib/src/stc/ScintillaWX.cpp b/contrib/src/stc/ScintillaWX.cpp index e652082bb9..30a896b903 100644 --- a/contrib/src/stc/ScintillaWX.cpp +++ b/contrib/src/stc/ScintillaWX.cpp @@ -95,6 +95,7 @@ ScintillaWX::ScintillaWX(wxStyledTextCtrl* win) { wMain = win; wDraw = win; stc = win; + wheelRotation = 0; Initialise(); } @@ -363,6 +364,22 @@ void ScintillaWX::DoVScroll(int type, int pos) { ScrollTo(topLineNew); } + +void ScintillaWX::DoMouseWheel(int rotation, int delta, int linesPerAction) { + int topLineNew = topLine; + int lines; + + wheelRotation += rotation; + lines = wheelRotation / delta; + wheelRotation -= lines * delta; + if (lines != 0) { + lines *= linesPerAction; + topLineNew -= lines; + ScrollTo(topLineNew); + } +} + + void ScintillaWX::DoSize(int width, int height) { PRectangle rcClient(0,0,width,height); SetScrollBarsTo(rcClient); diff --git a/contrib/src/stc/ScintillaWX.h b/contrib/src/stc/ScintillaWX.h index b773eac3a9..fdd4f98dbd 100644 --- a/contrib/src/stc/ScintillaWX.h +++ b/contrib/src/stc/ScintillaWX.h @@ -119,6 +119,7 @@ public: void DoButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt); void DoButtonUp(Point pt, unsigned int curTime, bool ctrl); void DoButtonMove(Point pt); + void DoMouseWheel(int rotation, int delta, int linesPerAction); void DoAddChar(char ch); int DoKeyDown(int key, bool shift, bool ctrl, bool alt); void DoTick() { Tick(); } @@ -146,6 +147,7 @@ private: wxSTCDropTarget* dropTarget; wxDragResult dragResult; + int wheelRotation; }; //---------------------------------------------------------------------- diff --git a/contrib/src/stc/gen_iface.py b/contrib/src/stc/gen_iface.py index 8348993acc..6798593426 100644 --- a/contrib/src/stc/gen_iface.py +++ b/contrib/src/stc/gen_iface.py @@ -19,14 +19,14 @@ from fileinput import FileInput IFACE = './scintilla/include/Scintilla.iface' H_TEMPLATE = './stc.h.in' CPP_TEMPLATE = './stc.cpp.in' -H_DEST = '../../include/wx/stc/stc.h' # './stc_test.h' # -CPP_DEST = './stc.cpp' #'./stc_test.cpp' +H_DEST = '../../include/wx/stc/stc.h' +CPP_DEST = './stc.cpp' # Value prefixes to convert valPrefixes = [('SCI_', ''), ('SC_', ''), - ('SCN_', None), # just toss these... + ('SCN_', None), # just toss these out... ('SCEN_', None), ('SCE_', ''), ('SCLEX_', 'LEX_'), diff --git a/contrib/src/stc/stc.cpp b/contrib/src/stc/stc.cpp index 9b46ce0510..8a96ed76df 100644 --- a/contrib/src/stc/stc.cpp +++ b/contrib/src/stc/stc.cpp @@ -91,6 +91,7 @@ BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) EVT_MOTION (wxStyledTextCtrl::OnMouseMove) EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp) EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp) + EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel) EVT_CHAR (wxStyledTextCtrl::OnChar) EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown) EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus) @@ -1556,6 +1557,14 @@ void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) { m_swx->DoContextMenu(Point(pt.x, pt.y)); } + +void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) { + m_swx->DoMouseWheel(evt.GetWheelRotation(), + evt.GetWheelDelta(), + evt.GetLinesPerAction()); +} + + void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { long key = evt.KeyCode(); if ((key > WXK_ESCAPE) && diff --git a/contrib/src/stc/stc.cpp.in b/contrib/src/stc/stc.cpp.in index 13a2f1f49a..b2a778bb31 100644 --- a/contrib/src/stc/stc.cpp.in +++ b/contrib/src/stc/stc.cpp.in @@ -91,6 +91,7 @@ BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) EVT_MOTION (wxStyledTextCtrl::OnMouseMove) EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp) EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp) + EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel) EVT_CHAR (wxStyledTextCtrl::OnChar) EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown) EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus) @@ -350,6 +351,14 @@ void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) { m_swx->DoContextMenu(Point(pt.x, pt.y)); } + +void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) { + m_swx->DoMouseWheel(evt.GetWheelRotation(), + evt.GetWheelDelta(), + evt.GetLinesPerAction()); +} + + void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { long key = evt.KeyCode(); if ((key > WXK_ESCAPE) && diff --git a/contrib/src/stc/stc.h.in b/contrib/src/stc/stc.h.in index 36c25c2bf2..bab374459a 100644 --- a/contrib/src/stc/stc.h.in +++ b/contrib/src/stc/stc.h.in @@ -154,6 +154,7 @@ private: void OnMouseMove(wxMouseEvent& evt); void OnMouseLeftUp(wxMouseEvent& evt); void OnMouseRightUp(wxMouseEvent& evt); + void OnMouseWheel(wxMouseEvent& evt); void OnChar(wxKeyEvent& evt); void OnKeyDown(wxKeyEvent& evt); void OnLoseFocus(wxFocusEvent& evt); diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index e2ec7c4b95..f9b26bdb8a 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -1256,6 +1256,7 @@ private: void OnMouseMove(wxMouseEvent& evt); void OnMouseLeftUp(wxMouseEvent& evt); void OnMouseRightUp(wxMouseEvent& evt); + void OnMouseWheel(wxMouseEvent& evt); void OnChar(wxKeyEvent& evt); void OnKeyDown(wxKeyEvent& evt); void OnLoseFocus(wxFocusEvent& evt); diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index e652082bb9..30a896b903 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -95,6 +95,7 @@ ScintillaWX::ScintillaWX(wxStyledTextCtrl* win) { wMain = win; wDraw = win; stc = win; + wheelRotation = 0; Initialise(); } @@ -363,6 +364,22 @@ void ScintillaWX::DoVScroll(int type, int pos) { ScrollTo(topLineNew); } + +void ScintillaWX::DoMouseWheel(int rotation, int delta, int linesPerAction) { + int topLineNew = topLine; + int lines; + + wheelRotation += rotation; + lines = wheelRotation / delta; + wheelRotation -= lines * delta; + if (lines != 0) { + lines *= linesPerAction; + topLineNew -= lines; + ScrollTo(topLineNew); + } +} + + void ScintillaWX::DoSize(int width, int height) { PRectangle rcClient(0,0,width,height); SetScrollBarsTo(rcClient); diff --git a/src/stc/ScintillaWX.h b/src/stc/ScintillaWX.h index b773eac3a9..fdd4f98dbd 100644 --- a/src/stc/ScintillaWX.h +++ b/src/stc/ScintillaWX.h @@ -119,6 +119,7 @@ public: void DoButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt); void DoButtonUp(Point pt, unsigned int curTime, bool ctrl); void DoButtonMove(Point pt); + void DoMouseWheel(int rotation, int delta, int linesPerAction); void DoAddChar(char ch); int DoKeyDown(int key, bool shift, bool ctrl, bool alt); void DoTick() { Tick(); } @@ -146,6 +147,7 @@ private: wxSTCDropTarget* dropTarget; wxDragResult dragResult; + int wheelRotation; }; //---------------------------------------------------------------------- diff --git a/src/stc/gen_iface.py b/src/stc/gen_iface.py index 8348993acc..6798593426 100644 --- a/src/stc/gen_iface.py +++ b/src/stc/gen_iface.py @@ -19,14 +19,14 @@ from fileinput import FileInput IFACE = './scintilla/include/Scintilla.iface' H_TEMPLATE = './stc.h.in' CPP_TEMPLATE = './stc.cpp.in' -H_DEST = '../../include/wx/stc/stc.h' # './stc_test.h' # -CPP_DEST = './stc.cpp' #'./stc_test.cpp' +H_DEST = '../../include/wx/stc/stc.h' +CPP_DEST = './stc.cpp' # Value prefixes to convert valPrefixes = [('SCI_', ''), ('SC_', ''), - ('SCN_', None), # just toss these... + ('SCN_', None), # just toss these out... ('SCEN_', None), ('SCE_', ''), ('SCLEX_', 'LEX_'), diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 9b46ce0510..8a96ed76df 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -91,6 +91,7 @@ BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) EVT_MOTION (wxStyledTextCtrl::OnMouseMove) EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp) EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp) + EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel) EVT_CHAR (wxStyledTextCtrl::OnChar) EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown) EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus) @@ -1556,6 +1557,14 @@ void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) { m_swx->DoContextMenu(Point(pt.x, pt.y)); } + +void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) { + m_swx->DoMouseWheel(evt.GetWheelRotation(), + evt.GetWheelDelta(), + evt.GetLinesPerAction()); +} + + void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { long key = evt.KeyCode(); if ((key > WXK_ESCAPE) && diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index 13a2f1f49a..b2a778bb31 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -91,6 +91,7 @@ BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) EVT_MOTION (wxStyledTextCtrl::OnMouseMove) EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp) EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp) + EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel) EVT_CHAR (wxStyledTextCtrl::OnChar) EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown) EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus) @@ -350,6 +351,14 @@ void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) { m_swx->DoContextMenu(Point(pt.x, pt.y)); } + +void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) { + m_swx->DoMouseWheel(evt.GetWheelRotation(), + evt.GetWheelDelta(), + evt.GetLinesPerAction()); +} + + void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { long key = evt.KeyCode(); if ((key > WXK_ESCAPE) && diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in index 36c25c2bf2..bab374459a 100644 --- a/src/stc/stc.h.in +++ b/src/stc/stc.h.in @@ -154,6 +154,7 @@ private: void OnMouseMove(wxMouseEvent& evt); void OnMouseLeftUp(wxMouseEvent& evt); void OnMouseRightUp(wxMouseEvent& evt); + void OnMouseWheel(wxMouseEvent& evt); void OnChar(wxKeyEvent& evt); void OnKeyDown(wxKeyEvent& evt); void OnLoseFocus(wxFocusEvent& evt); -- 2.45.2