Browse Source

Make TFPMemo view srollable even if no scrollbars are attached to it

Margers 7 months ago
parent
commit
24f498292a
2 changed files with 21 additions and 4 deletions
  1. 17 0
      packages/ide/fpviews.pas
  2. 4 4
      packages/ide/weditor.pas

+ 17 - 0
packages/ide/fpviews.pas

@@ -5012,6 +5012,7 @@ end;
 procedure TFPMemo.HandleEvent(var Event: TEvent);
 var DontClear: boolean;
     S: string;
+    LineCount,LinesScroll : Sw_Integer;
 begin
   case Event.What of
     evKeyDown :
@@ -5028,6 +5029,22 @@ begin
         end;
         if not DontClear then ClearEvent(Event);
       end;
+    evMouseDown:
+      if (Event.Buttons=mbScrollUp) then { mouse scroll up}
+        begin
+          LinesScroll:=1;
+          if Event.Double then LinesScroll:=LinesScroll+4;
+          LineCount:=Max(GetLineCount,1);
+          ScrollTo(Delta.X,Min(Max(0,LineCount-Size.Y),Delta.Y+LinesScroll));
+          ClearEvent(Event);
+        end else
+      if (Event.Buttons=mbScrollDown) then  { mouse scroll down }
+        begin
+          LinesScroll:=-1;
+          if Event.Double then LinesScroll:=LinesScroll-4;
+          ScrollTo(Delta.X, Max(0,Delta.Y+LinesScroll));
+          ClearEvent(Event);
+        end;
   end;
   inherited HandleEvent(Event);
 end;

+ 4 - 4
packages/ide/weditor.pas

@@ -3583,10 +3583,10 @@ end;
 
 procedure TCustomCodeEditor.ScrollTo(X, Y: sw_Integer);
 begin
-  inherited ScrollTo(X,Y);
-  if (HScrollBar=nil) or (VScrollBar=nil) then
-     begin Delta.X:=X; Delta.Y:=Y; end;
-  DrawView;
+   inherited ScrollTo(X,Y);
+   if (HScrollBar=nil) then Delta.X:=Max(X,0);
+   if (VScrollBar=nil) then Delta.Y:=Max(Min(Y,GetLineCount-1),0);
+   if (HScrollBar=nil) or (VScrollBar=nil) then DrawView;
 end;
 
 function TCustomCodeEditor.IsModal: boolean;