TSRVScrollbar with TRichViewEdit

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

TSRVScrollbar with TRichViewEdit

Post by Jim Knopf »

Hi Sergey,

For optical reasons I want to control my TRichViewEdits with TSRVScrollbar instead of the built-in scrollbar. How can you get the height of the whole text?

Or is it possible to get the necessary data for the scrollbar (Max, PageSize) directly from the scrollbar of TRichViewEdit?

Best regards
Martin
standay
Posts: 261
Joined: Fri Jun 18, 2021 3:07 pm

Re: TSRVScrollbar with TRichViewEdit

Post by standay »

Martin,

Here's what I use for a regular rve and a 3rd party scrollbar (VertScrollBar in the code). It won't be directly applicable but it might help you get started.

Code: Select all

  if ActiveRVE.VScrollMax = 0 then
    VertScrollBar.PageSize := 0;
  if ActiveRVE.VScrollMax>0 then begin
    PageSize := (ActiveRVE.ClientHeight div ActiveRVE.VSmallStep);
    If (ActiveRVE.DocumentHeight > 0) then
      VertScrollBar.Max := ActiveRVE.VScrollMax + PageSize;
    VertScrollBar.PageSize := PageSize ;
    end
  else begin
    VertScrollBar.PageSize := 0;
    VertScrollBar.Max := 0;
  end;

  VertScrollBar.Position := ActiveRVE.VScrollPos;
  VertScrollBar.Visible := (VertScrollBar.Max>0);
This is all in a procedure I named ScrollAdjust. I call ScrollAdjust from various spots when needed. Here's the code I use in my 3rd party scrollbar:

Code: Select all

procedure TForm1.VertScrollBarChange(Sender: TObject);
begin
  ActiveRVE.VScrollPos := VertScrollBar.Position;
end;
Stan
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Re: TSRVScrollbar with TRichViewEdit

Post by Jim Knopf »

Hi Stan,

thanks for your quick support - works great. I think the secret is ActiveRVE.VScrollMax, which I didn't find in the help (and unfortunately didn't search in the source code).

Kind regards
Martin
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Re: TSRVScrollbar with TRichViewEdit

Post by Jim Knopf »

Hi Stan,

unfortunately this solution does not quite work. It doesn't work properly when the TRichViewEdit gets smaller. The problem is with ActiveRVE.VSmallStep, because that is usually only 10 pixels. But a text line is much higher, you would have to calculate from the text style. Unfortunately this only works correctly if all the text in the TRichViewEdit has the same font. On the other hand - and this is the case with me - it is a lot of calculating.

Therefore a direct access to the internal scrollbar of the TRichViewEdit would be the only clean and efficient solution in my opinion.

That works if the font stays the same:

Code: Select all

procedure ScrollAdjust(R: TRichViewEdit; B: TSRVScrollbar);
var PageSize: Integer;
    Th: Integer;
begin
  if not Assigned(R.Style) then
    Exit; // <<<<<<<<<<<<<<<<<<<<<< EXIT

  if R.VScrollMax = 0 then
    B.PageSize := 0;
  if R.VScrollMax > 0 then
  begin
    Th := Trunc(R.Style.TextStyles[R.GetItemStyle(0)].SizeDouble / 2. *
                R.Style.ParaStyles[R.GetItemStyle(0)].LineSpacing / 100);
    PageSize := R.ClientHeight div Th; // R.VSmallStep;
    If (R.DocumentHeight > 0) then
      B.Max := R.VScrollMax + PageSize;
    B.PageSize := PageSize;
  end
  else
  begin
    B.PageSize := 0;
    B.Max := 0;
  end;
B.Position := R.VScrollPos;
B.Visible := B.Max > 0;
end;

Kind regards
Martin
Last edited by Jim Knopf on Wed Aug 30, 2023 12:27 pm, edited 1 time in total.
standay
Posts: 261
Joined: Fri Jun 18, 2021 3:07 pm

Re: TSRVScrollbar with TRichViewEdit

Post by standay »

It works in my app with multiple fonts and sizes, but I'm not using a TRVScrollBar and my rve is not in a scale richview. So, my rve is not being "scaled" when I resize my app. A scale rv may require calling things in a slightly different way. I'm not using scale rv's now. My guess is when the rve inside the scale rv is being "squished," the measurements are off. There's probably a way to call it, i.e.:

Code: Select all

VSmallStepPX := ActiveRVE.VSmallStep * ActiveRVE.GetRealDocumentPixelsPerInch div ActiveRVE.Style.UnitsPixelsPerInch;
Something like that. Maybe Sergey can look at it and tell you a way around it.

BTW, the main issue I've found with the built-in scrollbars is it is real tricky to show/hide the vertical bar based on content. When it is shown/hidden, the rve has to reformat. Minor issue is it may not match the app UI visually. The horizontal bar is much easier to deal with. You may find it much easier to leave the built-in vertical sb visible all the time.

Be interested to know if you get it working later.

Stan
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Re: TSRVScrollbar with TRichViewEdit

Post by Jim Knopf »

Hi Sergey,

in the meantime I experimented a lot and came to the conclusion that TSRVScrollbar sometimes sets the property PageSize wrong. This makes the scroller, for example, not half the height of the control (as it should be mathematically) but the same height and logically you can't scroll. I have verified this with countless attempts. I would like to use TRVScrollbar on Developer Express' TdxTreeList as well, so that the look is the same throughout.
I noticed that the properties are accessed with inherited, which I don't understand, for example with

Code: Select all

procedure TSRVScrollBar.SetPageSize(Value: Integer);
begin
  If (inherited PageSize <> Math.Max(Math.Min(Value, Max), Min)) then
  begin
    inherited PageSize := Math.Max(Math.Min(Value, Max), Min);         
    InvalidateIfNotStandard;
  end;
end;
Do you have any idea what I can do here to make it work reliably?

@Stan: I use TSRVScrollbar with normal TRVEdits, because TSRVEdit already has the scrollbar built in. So of course I don't need to do anything there.

Greetings
Martin
standay
Posts: 261
Joined: Fri Jun 18, 2021 3:07 pm

Re: TSRVScrollbar with TRichViewEdit

Post by standay »

Martin,

I use an ATScrollBar which seems to work well. It's on github here:

https://github.com/Alexey-T/ATFlatControls

It seems to play well with things I've used it on and you can set all the colors as desired.

Be interesting to see what Sergey says!

Stan
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Re: TSRVScrollbar with TRichViewEdit

Post by Jim Knopf »

Hi Stan,

thanks for the tip, i will try it.
I also found a component on torry.net (fatscrollbar) - I always have to make sure that components are still available for Delphi 5.

But I would much rather use Sergey's TRVScrollbar, then everything fits together. I am also very curious about his answer.

Martin
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Re: TSRVScrollbar with TRichViewEdit

Post by Jim Knopf »

What a coincidence!

It could be that I just found the problem, but need to test further.

With TSRVScrollbar you have to set the property PageSize to 0 in design mode! If you don't, then at least the value you entered is used (see code in post Sep 01, 2023 8:25 pm).

I had (from testing) PageSize generally on 20 and thereby it seems to have not worked with small RVEdits and Treelists.
standay
Posts: 261
Joined: Fri Jun 18, 2021 3:07 pm

Re: TSRVScrollbar with TRichViewEdit

Post by standay »

OK, I got curious and downloaded the scalerv trial so I could get hold of a TSRVScrollbar. I set up a simple app using that for a vertical bar. It works OK with the code I posted earlier with one change:

Code: Select all

VertScrollBar.PageSize := PageSize ;
to

Code: Select all

VertScrollBar.PageSize := PageSize + 1;
Mine works OK with any mix of fonts and font sizes.

It took a while to figure out it needs an SRVSkinManager, and that took a while to figure out as well. It's no problem to change colors of the SB elements, but it looks like you use images for the up and down arrows, as well as thumb "lines" (if you want them).

Since there are draw events for the up, down, and thumb, I tried those and that all works great. I might be able to replace the AT scrollbars with the TSRVScrollbar. I'll do more testing.

BTW, I set the TabStop to false as I've had issues with scrollbars where it was set to true. I have the pagesize set to 0 in design mode (it defaulted to that).

Here's a test with the up arrow button with an orange bgnd and a png image, the sb area a dark gray, the thumb silver, and the down arrow button as it looks normally.

sbtest.png
sbtest.png (74.26 KiB) Viewed 49344 times

Stan
Post Reply