1
0
Эх сурвалжийг харах

Issue 128 – Optionally disable smooth scrolling in an internal editor

https://winscp.net/tracker/128

Source commit: 6237d918671451352c1f8ded00f9b7c99ddfb33a
Martin Prikryl 1 жил өмнө
parent
commit
33ba913b08

+ 33 - 0
source/forms/Editor.cpp

@@ -172,6 +172,7 @@ protected:
   void __fastcall SetTabSize(unsigned int TabSize);
   void __fastcall WMPaste();
   void __fastcall EMStreamIn(TMessage & Message);
+  void WMMouseWheel(TMessage & Message);
   bool __stdcall StreamLoad(TRichEditStreamInfo * StreamInfo,
     unsigned char * Buff, long Read, long & WasRead);
   DYNAMIC void __fastcall KeyDown(Word & Key, TShiftState Shift);
@@ -410,6 +411,34 @@ void __fastcall TEditorRichEdit::EMStreamIn(TMessage & Message)
   TNewRichEdit::Dispatch(&Message);
 }
 //---------------------------------------------------------------------------
+void TEditorRichEdit::WMMouseWheel(TMessage & Message)
+{
+  unsigned int ScrollLines = 0;
+  if (WinConfiguration->Editor.DisableSmoothScroll &&
+      SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &ScrollLines, 0) &&
+      (ScrollLines != 0))
+  {
+    int Delta = GET_WHEEL_DELTA_WPARAM(Message.WParam);
+    bool Up = (Delta > 0);
+    if (ScrollLines == WHEEL_PAGESCROLL)
+    {
+      SendMessage(Handle, WM_VSCROLL, Up ? SB_PAGEUP : SB_PAGEDOWN, 0);
+    }
+    else
+    {
+      int LinesToScroll = (abs(Delta) / WHEEL_DELTA) * ScrollLines;
+      for (int Index = 0; Index < LinesToScroll; Index++)
+      {
+        SendMessage(Handle, WM_VSCROLL, Up ? SB_LINEUP : SB_LINEDOWN, 0);
+      }
+    }
+  }
+  else
+  {
+    TNewRichEdit::Dispatch(&Message);
+  }
+}
+//---------------------------------------------------------------------------
 void __fastcall TEditorRichEdit::Dispatch(void * Message)
 {
   TMessage * M = static_cast<TMessage *>(Message);
@@ -423,6 +452,10 @@ void __fastcall TEditorRichEdit::Dispatch(void * Message)
       EMStreamIn(*M);
       break;
 
+    case WM_MOUSEWHEEL:
+      WMMouseWheel(*M);
+      break;
+
     default:
       TNewRichEdit::Dispatch(Message);
       break;

+ 2 - 0
source/forms/Preferences.cpp

@@ -396,6 +396,7 @@ void __fastcall TPreferencesDialog::LoadConfiguration()
     TWinConfiguration::RestoreFont(WinConfiguration->Editor.Font, FEditorFont.get());
     FEditorFont->Color = WinConfiguration->Editor.FontColor;
     FEditorBackgroundColor = WinConfiguration->Editor.BackgroundColor;
+    EditorDisableSmoothScrollCheck->Checked = WinConfiguration->Editor.DisableSmoothScroll;
     (*FEditorList) = *WinConfiguration->EditorList;
     UpdateEditorListView();
     BOOLPROP(EditorCheckNotModified);
@@ -797,6 +798,7 @@ void __fastcall TPreferencesDialog::SaveConfiguration()
     TWinConfiguration::StoreFont(FEditorFont.get(), WinConfiguration->Editor.Font);
     WinConfiguration->Editor.FontColor = FEditorFont->Color;
     WinConfiguration->Editor.BackgroundColor = FEditorBackgroundColor;
+    WinConfiguration->Editor.DisableSmoothScroll = EditorDisableSmoothScrollCheck->Checked;
     WinConfiguration->EditorList = FEditorList;
     BOOLPROP(EditorCheckNotModified);
 

+ 22 - 0
source/forms/Preferences.dfm

@@ -3377,6 +3377,28 @@ object PreferencesDialog: TPreferencesDialog
             OnClick = EditorBackgroundColorButtonClick
           end
         end
+        object InternalEditorBehaviourGroup: TGroupBox
+          Left = 13
+          Top = 284
+          Width = 389
+          Height = 49
+          Anchors = [akLeft, akTop, akRight]
+          Caption = 'Behaviour'
+          TabOrder = 2
+          DesignSize = (
+            389
+            49)
+          object EditorDisableSmoothScrollCheck: TCheckBox
+            Left = 16
+            Top = 20
+            Width = 353
+            Height = 17
+            Anchors = [akLeft, akTop, akRight]
+            Caption = 'Disable s&mooth scrolling'
+            TabOrder = 0
+            OnClick = ControlChange
+          end
+        end
       end
       object FileColorsSheet: TTabSheet
         Tag = 25

+ 2 - 0
source/forms/Preferences.h

@@ -355,6 +355,8 @@ __published:
   TCheckBox *SshHostCAsFromPuTTYCheck;
   TButton *ConfigureSshHostCAsButton;
   TCheckBox *SessionTabCaptionTruncationCheck;
+  TGroupBox *InternalEditorBehaviourGroup;
+  TCheckBox *EditorDisableSmoothScrollCheck;
   void __fastcall FormShow(TObject *Sender);
   void __fastcall ControlChange(TObject *Sender);
   void __fastcall EditorFontButtonClick(TObject *Sender);

+ 2 - 0
source/windows/WinConfiguration.cpp

@@ -662,6 +662,7 @@ void __fastcall TWinConfiguration::Default()
   FEditor.WarnOnEncodingFallback = true;
   FEditor.WarnOrLargeFileSize = true;
   FEditor.AutoFont = true;
+  FEditor.DisableSmoothScroll = false;
 
   FQueueView.Height = 140;
   FQueueView.HeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
@@ -1148,6 +1149,7 @@ THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool & SessionList)
     KEY(Bool,     Editor.WarnOnEncodingFallback); \
     KEY(Bool,     Editor.WarnOrLargeFileSize); \
     KEY(Bool,     Editor.AutoFont); \
+    KEY(Bool,     Editor.DisableSmoothScroll); \
   ); \
   BLOCK(L"Interface\\QueueView", CANCREATE, \
     KEY(Integer,  QueueView.Height); \

+ 2 - 1
source/windows/WinConfiguration.h

@@ -133,11 +133,12 @@ struct TEditorConfiguration {
   bool WarnOnEncodingFallback;
   bool WarnOrLargeFileSize;
   bool AutoFont;
+  bool DisableSmoothScroll;
   bool __fastcall operator !=(TEditorConfiguration & rhc)
     { return C(Font) C(FontColor) C(BackgroundColor) C(WordWrap) C(FindText) C(ReplaceText)
       C(FindMatchCase) C(FindWholeWord) C(FindDown) C(TabSize)
       C(MaxEditors) C(EarlyClose) C(SDIShellEditor) C(WindowParams)
-      C(Encoding) C(WarnOnEncodingFallback) C(WarnOrLargeFileSize) C(AutoFont) 0; };
+      C(Encoding) C(WarnOnEncodingFallback) C(WarnOrLargeFileSize) C(AutoFont) C(DisableSmoothScroll) 0; };
 };
 //---------------------------------------------------------------------------
 enum TQueueViewShow { qvShow, qvHideWhenEmpty, qvHide };