Przeglądaj źródła

Speed box in Progress window responds to mouse wheel

Source commit: 72f6f29b46659dbced4b1d7eaffd03cf312b2ccb
Martin Prikryl 6 lat temu
rodzic
commit
56eaa66b7c

+ 3 - 0
source/core/CopyParam.cpp

@@ -989,6 +989,9 @@ bool __fastcall TCopyParamType::operator==(const TCopyParamType & rhp) const
 }
 }
 #undef C
 #undef C
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
+const unsigned long MinSpeed = 8 * 1024;
+const unsigned long MaxSpeed = 8 * 1024 * 1024;
+//---------------------------------------------------------------------------
 static bool __fastcall TryGetSpeedLimit(const UnicodeString & Text, unsigned long & Speed)
 static bool __fastcall TryGetSpeedLimit(const UnicodeString & Text, unsigned long & Speed)
 {
 {
   bool Result;
   bool Result;

+ 2 - 0
source/core/CopyParam.h

@@ -152,5 +152,7 @@ unsigned long __fastcall GetSpeedLimit(const UnicodeString & Text);
 UnicodeString __fastcall SetSpeedLimit(unsigned long Limit);
 UnicodeString __fastcall SetSpeedLimit(unsigned long Limit);
 void __fastcall CopySpeedLimits(TStrings * Source, TStrings * Dest);
 void __fastcall CopySpeedLimits(TStrings * Source, TStrings * Dest);
 TOperationSide ReverseOperationSide(TOperationSide Side);
 TOperationSide ReverseOperationSide(TOperationSide Side);
+extern const unsigned long MinSpeed;
+extern const unsigned long MaxSpeed;
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 #endif
 #endif

+ 76 - 0
source/forms/Progress.cpp

@@ -14,6 +14,7 @@
 #include <DateUtils.hpp>
 #include <DateUtils.hpp>
 #include <Consts.hpp>
 #include <Consts.hpp>
 #include <HistoryComboBox.hpp>
 #include <HistoryComboBox.hpp>
+#include <windowsx.h>
 
 
 #include "Progress.h"
 #include "Progress.h"
 //---------------------------------------------------------------------
 //---------------------------------------------------------------------
@@ -91,6 +92,7 @@ __fastcall TProgressForm::TProgressForm(
   FPendingSkip = false;
   FPendingSkip = false;
   FSynchronizeProgress = SynchronizeProgress;
   FSynchronizeProgress = SynchronizeProgress;
   FAllowSkip = AllowSkip;
   FAllowSkip = AllowSkip;
+  FWheelDelta = 0;
   UseSystemSettings(this);
   UseSystemSettings(this);
 
 
   FOnceDoneItems.Add(odoIdle, IdleOnceDoneItem);
   FOnceDoneItems.Add(odoIdle, IdleOnceDoneItem);
@@ -700,6 +702,7 @@ UnicodeString __fastcall TProgressForm::ItemSpeed(const UnicodeString & Text,
   UnicodeString Result = SetSpeedLimit(FCPSLimit);
   UnicodeString Result = SetSpeedLimit(FCPSLimit);
   SaveToHistory(Item->Strings, Result);
   SaveToHistory(Item->Strings, Result);
   CustomWinConfiguration->History[L"SpeedLimit"] = Item->Strings;
   CustomWinConfiguration->History[L"SpeedLimit"] = Item->Strings;
+  FWheelDelta = 0;
 
 
   return Result;
   return Result;
 }
 }
@@ -753,3 +756,76 @@ void __fastcall TProgressForm::SkipItemClick(TObject * /*Sender*/)
   SetCancelLower(csCancelFile);
   SetCancelLower(csCancelFile);
 }
 }
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
+void __fastcall TProgressForm::MouseWheelHandler(TMessage & Message)
+{
+  int X = GET_X_LPARAM(Message.LParam);
+  int Y = GET_Y_LPARAM(Message.LParam);
+  TPoint P = Toolbar->ScreenToClient(TPoint(X, Y));
+  if (Toolbar->ClientRect.Contains(P))
+  {
+    TTBItemViewer * Viewer = Toolbar->View->Find(SpeedComboBoxItem);
+    if (Viewer->BoundsRect.Contains(P))
+    {
+      int Delta = GET_WHEEL_DELTA_WPARAM(Message.WParam);
+      FWheelDelta += Delta;
+      unsigned long CurrentSpeed = GetSpeedLimit(SpeedComboBoxItem->Text);
+      unsigned long Speed = CurrentSpeed;
+      unsigned int CPS = FData.CPS();
+      int Step = 4 * WHEEL_DELTA;
+      if (FWheelDelta > 0)
+      {
+        while (FWheelDelta > Step)
+        {
+          if (Speed > 0)
+          {
+            Speed *= 2;
+            if (Speed > std::max(MaxSpeed, static_cast<unsigned long>(CPS) * 2))
+            {
+              Speed = 0;
+            }
+          }
+          FWheelDelta -= Step;
+        }
+      }
+      else if (FWheelDelta < 0)
+      {
+        while (FWheelDelta < -Step)
+        {
+          if (Speed == 0)
+          {
+            Speed = 8;
+            while (Speed * 2 < CPS)
+            {
+              Speed *= 2;
+            }
+          }
+          else
+          {
+            if (Speed > MinSpeed)
+            {
+              Speed /= 2;
+            }
+          }
+          FWheelDelta += Step;
+        }
+      }
+
+      if (Speed != CurrentSpeed)
+      {
+        TTBEditItemViewer * EditViewer = dynamic_cast<TTBEditItemViewer *>(Viewer);
+        if (EditViewer->EditControl != NULL)
+        {
+          EditViewer->View->CancelMode();
+        }
+
+        FCPSLimit = Speed;
+        SpeedComboBoxItem->Text = SetSpeedLimit(Speed);
+      }
+
+      Message.Result = 1;
+    }
+  }
+
+  TForm::MouseWheelHandler(Message);
+}
+//---------------------------------------------------------------------------

+ 2 - 0
source/forms/Progress.h

@@ -113,6 +113,7 @@ private:
   bool FAllowSkip;
   bool FAllowSkip;
   TSynchronizeProgress * FSynchronizeProgress;
   TSynchronizeProgress * FSynchronizeProgress;
   UnicodeString FProgressStr;
   UnicodeString FProgressStr;
+  int FWheelDelta;
 
 
   void __fastcall SetOnceDoneOperation(TOnceDoneOperation value);
   void __fastcall SetOnceDoneOperation(TOnceDoneOperation value);
   TTBCustomItem * __fastcall CurrentOnceDoneItem();
   TTBCustomItem * __fastcall CurrentOnceDoneItem();
@@ -133,6 +134,7 @@ protected:
   void __fastcall Minimize(TObject * Sender);
   void __fastcall Minimize(TObject * Sender);
   virtual void __fastcall Dispatch(void * Message);
   virtual void __fastcall Dispatch(void * Message);
   void __fastcall SetCancelLower(TCancelStatus ACancel);
   void __fastcall SetCancelLower(TCancelStatus ACancel);
+  DYNAMIC void __fastcall MouseWheelHandler(TMessage & Message);
 
 
   INTERFACE_HOOK;
   INTERFACE_HOOK;
 
 

+ 3 - 3
source/windows/CustomWinConfiguration.cpp

@@ -73,10 +73,10 @@ void __fastcall TCustomWinConfiguration::DefaultHistory()
   // If we need to solve this for another history, we should introduce
   // If we need to solve this for another history, we should introduce
   // a generic solution, like language-specific history ("SpeedLimitEN")
   // a generic solution, like language-specific history ("SpeedLimitEN")
   Strings->Add(LoadStr(SPEED_UNLIMITED));
   Strings->Add(LoadStr(SPEED_UNLIMITED));
-  unsigned long Speed = 8192;
-  while (Speed >= 8)
+  unsigned long Speed = MaxSpeed;
+  while (Speed >= MinSpeed)
   {
   {
-    Strings->Add(IntToStr(int(Speed)));
+    Strings->Add(SetSpeedLimit(Speed));
     Speed = Speed / 2;
     Speed = Speed / 2;
   }
   }
   FHistory->AddObject(L"SpeedLimit", Strings.release());
   FHistory->AddObject(L"SpeedLimit", Strings.release());