Expected bug in multi-line string nodes (TControl.ClientRect vs scroll bars)

8 views
Skip to first unread message

Arioch The

unread,
Jan 10, 2019, 9:59:20 AM1/10/19
to Virtual Treeview
My VTV fork is significantly behind, but for what I see this part of VTV did not changed.

The core issue here is if TControl.ClientWidth should account for vertical scroll bar or ignore it.

Personally I think it should - in Windows GDI terms "client area" of a window, is where an application paints data for user to read, and servicing decorations, like shadows, scrollbars and what not, should be excluded.

AFAIR stock VCL TMemo and TStringGrid do account, though I did not test right off.

Whatever the choice VTV would make though, it should be uniform. Either VTV should expect .ClientRect to include or to exclude the scrollbars.

Now we come to function TCustomVirtualStringTree.ComputeNodeHeight

In the ending lines it has the following command:

    PaintInfo.CellRect.Right := ClientWidth;

Then it goes

  Winapi.Windows.DrawTextW(Canvas.Handle, PWideChar(S), Length(S), PaintInfo.CellRect, DrawFormat);

And here is the caveat.

Take a usual VirtualStringTree and feel it with items like

1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 A
1 2 3 4 5 6 7 8 9 A B

and so forth so that

1) windows can "word-wrap" it at any place
2) there should be many enough items to make VST having vertical scroll bar
3) in every item tokens are different, making easy to spot wrong position of wrapping

Now, the following application code might be seen as very weird, but it is legacy code from years and years ago.
Rehashing all of many them without knowing what all those hack-arounds were for exactly, and thus unable to predict how removing them all may side-effect the app - is no option for me now.

Anyway, it is only to make the bug visually easy to see.

Make VirtualStringTree.OnMeasureItem use ComputeNodeHeight to calculate the height

Make VirtualStringTree.BeforeCellPaint do:
    Exclude(Node.Height, vstHeightMeasured);
    Sender.MeasueItem.Height( TargetCanvas, Node);

Maybe even this events hijacking would be not needed, dunno.
Maybe today VTV makes exactly the same internally.

However, with code like this the unexpected happen - the long lines are wrapped BEHIND the scrollbars, making rightmost parts of the text invisible.
Reply all
Reply to author
Forward
0 new messages