TRichViewEdit - with own VerticalScrollbar and extra buttons

General TRichView support forum. Please post your questions here
Post Reply
a.weber
Posts: 63
Joined: Wed Mar 02, 2022 7:02 am

TRichViewEdit - with own VerticalScrollbar and extra buttons

Post by a.weber »

Hello Sergey,

I want to replace a lot TMemo controls in our forms - with TRichViewEdit and a limited set of formating possibilties for our users. The available space on our forms is very limited, so we tried this. I did create a new subclass from TRichViewEdit in the constructor I disabled the original vertical scrollbar and created a new one of your TSRVScrollBar and two additional buttons on top and bottom of it. Now it looks like this at runtime:
vmsrv01.png
vmsrv01.png (20.04 KiB) Viewed 7892 times
The burger button, will show a editing toolbar on top of the control - but not inside the control - so it is nothing you have to worry about,
vmsrv02.png
vmsrv02.png (21.02 KiB) Viewed 7892 times
(the toolbar will be a shared objects for all of our memos and exists only as a single instance)

Looks nice - but doesn't work - I thought it would be enough the override AdjustClientRect() and remove the scrollbar from the "ClientArea" and so
from ClientWidth - but it seems that your painting and calculation isn't useing ClientWidth? or has a copy from it?
So if I type text in single line it will be painted behind the scrollbar.
Also if the richedit starts to scroll verticaly things go wrong - because it tries to scroll also my controls.
(the memo's in that case will use the Option.rvoClientTextWidth = TRUE, to avoid the horizontal scalebar)

Can you offer me some help / hints how to solve this - may I have to override some additional methods to get work?
I have allready found the sample that show's how to use external scrollbars and how to synchronize them with a TRichViewEdit,
that was useful - to keep my scrollbar in sync.

with best regards

André
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRichViewEdit - with own VerticalScrollbar and extra buttons

Post by Sergey Tkachenko »

You can simply hide the scrollbars:
VScrollVisible := False;
HScrollVisible := False;

Than place custom scrollbars near the editor.
See https://www.trichview.com/support/files/extscroll.zip
a.weber
Posts: 63
Joined: Wed Mar 02, 2022 7:02 am

Re: TRichViewEdit - with own VerticalScrollbar and extra buttons

Post by a.weber »

Hello Sergey,
You can simply hide the scrollbars:
VScrollVisible := False;
HScrollVisible := False;
That is what I did inside the constructor of my own class I made the VerticalScrollbar hidden and tried to replace them with my own one.
Than place custom scrollbars near the editor.
See https://www.trichview.com/support/files/extscroll.zip
That sample I know allready - this is ok for some or a single usecase but not for a lot.

I would prefer the "subclassing" way - instead of placing extra components around, that would make the life of our GUI designers much eaisier, because they don't need to write any addional code - just add / replace the control.

Do you see a chance that childcontrols of TRichView of a certain kind / class - would be excluded from scrolling / painting?

André
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRichViewEdit - with own VerticalScrollbar and extra buttons

Post by Sergey Tkachenko »

Children are scrolled in TRVScroller.ScrollChildren.
If it would solve the problem, I can add a virtual method CanBeScrolled(ChildControl: TControl): Boolean and use in this method.

But probably another solution would be simpler: a control that includes both TRIchView and scrollbars as children (this approach is used in DevExpress controls, including TcxTRichViewEdit)
a.weber
Posts: 63
Joined: Wed Mar 02, 2022 7:02 am

Re: TRichViewEdit - with own VerticalScrollbar and extra buttons

Post by a.weber »

Hello,

thanks for your response and pointing me to the right source ... I have modified RvScroll.pas in this way:

Code: Select all

{------------------------------------------------------}
function TRVScroller.DoAllowScrollChild(const ctrl: TControl): boolean;
begin
  // this is a virtual protected method - which I override in my own class, to decide what is scrolled
  // my be a good idea to also add dx,dy TRVCoord to this callback, to have all information needed to 
  // decide about scrolling or not?
  result := true;
end;

{------------------------------------------------------}
procedure TRVScroller.ScrollChildren(dx, dy: TRVCoord);
var
  i: Integer;
begin
  if RVIsZeroCoord(dx) and RVIsZeroCoord(dy) then
     exit;
  {$IFDEF FIREMONKEY}
  for i := 0 to ControlsCount - 1 do
  begin
    if DoAllowScrollChild(Controls[i]) then
       ...
  end;
  {$ELSE}
  DisableAlign;
  try
    for i := 0 to ControlCount - 1 do
    begin
      if DoAllowScrollChild(Controls[i]) then
      begin
         ....
      end;
    end
  finally
    {$IFnDEF FPC}
    ControlState := ControlState - [csAlignmentNeeded];
    {$ENDIF}
    EnableAlign;
  end;
  {$ENDIF}
end;
I also override TWinControl.GetClientRect - to return only the clientrect without scrollbar so there is no obvious flickering to see.
Only updating the scroll to the correct PageSize/Min/Max seems not the work in all cases - I have to check this.
(Currently I copied your code from the external scrollbar sample, may be I have missed something)

André
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Re: TRichViewEdit - with own VerticalScrollbar and extra buttons

Post by standay »

a.weber wrote: Wed Aug 17, 2022 5:18 am Only updating the scroll to the correct PageSize/Min/Max seems not the work in all cases - I have to check this.
(Currently I copied your code from the external scrollbar sample, may be I have missed something)

André
This seemed to work for me, but might need some tweaking on your part:

Code: Select all

  FVScrollPage := rve.ClientHeight div rve.VSmallStep;
  ScrollBar1.Max := rve.DocumentHeight div rve.VSmallStep;
  ScrollBar1.PageSize := FVScrollPage;
Stan
Post Reply