From 26520b92c94da37347eb42a5a5d8d6cca36cf4f3 Mon Sep 17 00:00:00 2001 From: skalogryz Date: Fri, 7 Jul 2017 18:01:02 +0000 Subject: [PATCH] richmemo: prevent win32 scrolling on changing text attributes git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5974 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/richmemo/richmemo.pas | 9 --------- components/richmemo/win32/win32richmemo.pas | 18 ++++++++++++++++-- .../richmemo/win32/win32richmemoproc.pas | 13 +++++++++++++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/components/richmemo/richmemo.pas b/components/richmemo/richmemo.pas index f81097007..24c255530 100644 --- a/components/richmemo/richmemo.pas +++ b/components/richmemo/richmemo.pas @@ -864,7 +864,6 @@ var p : TFontParams; allowInternalChange: Boolean; fp : TFontParams; - h,v : integer; const AllFontStyles : TFontStyles = [fsBold, fsItalic, fsUnderline, fsStrikeOut]; begin @@ -872,8 +871,6 @@ begin if (ModifyMask = []) or (TextLength = 0) then Exit; - h:=Self.HorzScrollBar.Position; - v:=Self.VertScrollBar.Position; allowInternalChange:=(not (tmm_Styles in ModifyMask)) or (AddFontStyle+RemoveFontStyle=AllFontStyles); if allowInternalChange and (TWSCustomRichMemoClass(WidgetSetClass).isInternalChange(Self, ModifyMask)) then @@ -886,8 +883,6 @@ begin Exit; end; - //todo: this is temporary workaround - // the style changing should not be adjusting the scroll Lines.BeginUpdate; try // manually looping from text ranges and re-applying @@ -912,10 +907,6 @@ begin inc(i, l); end; finally - // todo: this is a workaround. - // getting position is necessary, so the cached values are refershed - if Self.HorzScrollBar.Position<>h then Self.HorzScrollBar.Position:=h; - if Self.VertScrollBar.Position<>v then Self.VertScrollBar.Position:=v; Lines.EndUpdate; end; end; diff --git a/components/richmemo/win32/win32richmemo.pas b/components/richmemo/win32/win32richmemo.pas index 914eaccaf..3f11f0768 100644 --- a/components/richmemo/win32/win32richmemo.pas +++ b/components/richmemo/win32/win32richmemo.pas @@ -630,9 +630,11 @@ var OrigLen : Integer; NeedLock : Boolean; eventmask : Integer; + pt : TPoint; begin if not Assigned(RichEditManager) or not Assigned(AWinControl) then Exit; + RichEditManager.GetScroll(AWinControl.Handle, pt); eventmask := RichEditManager.SetEventMask(AWinControl.Handle, 0); RichEditManager.GetSelection(AWinControl.Handle, OrigStart, OrigLen); @@ -646,6 +648,7 @@ begin end else RichEditManager.SetSelectedTextStyle(AWinControl.Handle, Params); + RichEditManager.SetScroll(AWinControl.Handle, pt); RichEditManager.SetEventMask(AWinControl.Handle, eventmask); end; @@ -654,12 +657,15 @@ class function TWin32WSCustomRichMemo.GetTextAttributes(const AWinControl: TWinC var Orig : TCHARRANGE; eventmask : LongWord; + pt : TPoint; begin if not Assigned(RichEditManager) or not Assigned(AWinControl) then begin Result := false; Exit; end; InitFontParams(Params); + + RichEditManager.GetScroll(AWinControl.Handle, pt); eventmask := RichEditManager.SetEventMask(AWinControl.Handle, 0); LockRedraw(TCustomRichMemo(AWinControl), AWinControl.Handle); @@ -670,6 +676,7 @@ begin Result := RichEditManager.GetSelectedTextStyle(AWinControl.Handle, Params ); RichEditManager.SetSelRange(AWinControl.Handle, Orig); + RichEditManager.SetScroll(AWinControl.Handle, pt); UnlockRedraw(TCustomRichMemo(AWinControl), AWinControl.Handle, false); RichEditManager.SetEventMask(AWinControl.Handle,eventmask); @@ -689,8 +696,10 @@ var OrigLen : Integer; eventmask : longword; NeedLock : Boolean; + pt : TPoint; begin eventmask := RichEditManager.SetEventMask(AWinControl.Handle, 0); + RichEditManager.GetScroll(AWinControl.Handle, pt); RichEditManager.GetSelection(AWinControl.Handle, OrigStart, OrigLen); NeedLock := (OrigStart <> TextStart) or (OrigLen <> TextLen); @@ -703,6 +712,7 @@ begin end else RichEditManager.SetSelectedTextStyle(AWinControl.Handle, Params, True, AModifyMask); + RichEditManager.SetScroll(AWinControl.Handle, pt); RichEditManager.SetEventMask(AWinControl.Handle, eventmask); end; @@ -743,12 +753,15 @@ class function TWin32WSCustomRichMemo.GetStyleRange( var Orig : TCharRange; eventmask : longword; + pt : TPoint; begin if not Assigned(RichEditManager) or not Assigned(AWinControl) then begin Result := false; Exit; end; + RichEditManager.GetScroll(AWinControl.Handle, pt); + eventmask := RichEditManager.SetEventMask(AWinControl.Handle, 0); LockRedraw(TCustomRichMemo(AWinControl), AWinControl.Handle); @@ -761,6 +774,7 @@ begin end; RichEditManager.SetSelRange(AWinControl.Handle, Orig); + RichEditManager.SetScroll(AWinControl.Handle, pt); UnlockRedraw(TCustomRichMemo(AWinControl), AWinControl.Handle, false); RichEditManager.SetEventMask(AWinControl.Handle, eventmask); @@ -1460,10 +1474,10 @@ var begin if not Assigned(AWinControl) or not (AWinControl.HandleAllocated) or ((DeltaX=0) and (DeltaY=0)) then Exit; - Windows.SendMessage(AWinControl.Handle, EM_GETSCROLLPOS, 0, LPARAM(@pt)); + RichEditManager.GetScroll(AWinControl.Handle, pt); dec(pt.x,DeltaX); dec(pt.y,Deltay); - Windows.SendMessage(AWinControl.Handle, EM_SETSCROLLPOS, 0, LPARAM(@pt)); + RichEditManager.SetScroll(AWinControl.Handle, pt); end; // The function doesn't use Windows 7 (Vista?) animations. And should. diff --git a/components/richmemo/win32/win32richmemoproc.pas b/components/richmemo/win32/win32richmemoproc.pas index e0639a802..516a6df64 100644 --- a/components/richmemo/win32/win32richmemoproc.pas +++ b/components/richmemo/win32/win32richmemoproc.pas @@ -193,6 +193,9 @@ type class function Find(RichEditWnd: THandle; const ANiddle: WideString; const ASearch: TIntSearchOpt; var TextLen: Integer): Integer; virtual; overload; class function Find(RichEditWnd: THandle; const ANiddle: WideString; const ASearch: TIntSearchOpt): Integer; overload; class procedure GetParaRange(RichEditWnd: Handle; TextStart: integer; var para: TParaRange); virtual; + + class procedure GetScroll(RichEditWnd: Handle; out pt: TPoint); virtual; + class procedure SetScroll(RichEditWnd: Handle; const pt: TPoint); virtual; end; TRichManagerClass = class of TRichEditManager; @@ -973,6 +976,16 @@ begin para.length:=toend; end; +class procedure TRichEditManager.GetScroll(RichEditWnd: Handle; out pt: TPoint); +begin + SendMessage(RichEditWnd, EM_GETSCROLLPOS, 0, LPARAM(@pt)); +end; + +class procedure TRichEditManager.SetScroll(RichEditWnd: Handle; const pt: TPoint); +begin + SendMessage(RichEditWnd, EM_SETSCROLLPOS, 0, LPARAM(@pt)); +end; + function WinInsertImageFromFile (const ARichMemo: TCustomRichMemo; APos: Integer; const FileNameUTF8: string; const AImgSize: TSize): Boolean;