Recent

Author Topic: Unresponsive hints of TVirtualDrawTree + error in demo  (Read 1678 times)

trexet

  • New Member
  • *
  • Posts: 37
Unresponsive hints of TVirtualDrawTree + error in demo
« on: June 26, 2024, 04:22:34 pm »
Hi.

Using Lazarus 3.4 and laz.virtualtreeview_package 5.5.3.1, found several problems with hints of TVirtualDrawTree.

First, the vst_advanced demo, DrawTreeDemo module, does not show hints at all, while the hints are supposed to be shown for Thumbnails column. Checking into the TBaseVirtualTree.CMHintShow, I found that the Hint property of VDT must be set as well.

Second, after fixing that, I do get hints now, but they are unresponsive:
1) Hints do not hide until I move the mouse out of the whole VDT or scroll (expected behavior is hiding the hint when moving mouse to another node/column)
2) Moving mouse from one hint-able cell straight to other hint-able cell keeps the old hint
3) Scrolling VDT so that mouse points to the hint-able cell does not show the hint

Third, I supposed that the demo hints are unresponsive because they are pretty labor-intensive, requiring scaling and rendering the bitmap. Thus I've implemented the hints in my program which do only the DrawText(), however, nothing changed at all.

So, I supposed that issue 1 can be partially fixed by setting the TBaseVirtualTree.HintData.HintInfo^.HideTimeout := 2000 during OnDrawHint. However, HintData is protected, so I put it right into TBaseVirtualTree.CMHintShow. Indeed that's a dirty trick, but at least hints became less annoying.

Another problem is that TVirtualDrawTree does not allow using system text hints and OnGetHint as the TVirtualStringTree does - that would be much easier for text hints.

wp

  • Hero Member
  • *****
  • Posts: 12266
Re: Unresponsive hints of TVirtualDrawTree + error in demo
« Reply #1 on: June 26, 2024, 06:14:20 pm »
Would you mind to write a bug report and add a patch?

Thaddy

  • Hero Member
  • *****
  • Posts: 15487
  • Censorship about opinions does not belong here.
Re: Unresponsive hints of TVirtualDrawTree + error in demo
« Reply #2 on: June 26, 2024, 06:20:23 pm »
Would you mind to write a bug report and add a patch?
and add a patch?

Never happens and in this case I don't believe the code is at fault, but the use:
This is code that has matured for over 20 years, so highly unlikely it does not work.
Mis- expectations about the virtual controls is very common, though.
« Last Edit: June 26, 2024, 06:30:00 pm by Thaddy »
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

trexet

  • New Member
  • *
  • Posts: 37
Re: Unresponsive hints of TVirtualDrawTree + error in demo
« Reply #3 on: June 26, 2024, 08:05:01 pm »
highly unlikely it does not work.
Mis- expectations about the virtual controls is very common, though.

You can check the vst_advanced demo and it's DrawTreeDemo module to make sure that
1) the demo is incorrect
2) either fixing the problem in demo reveals problems with VDT hints, or the demo demonstrates an incorrect use of VDT

This is code that has matured for over 20 years

On the other side, this is code that was developed for Windows XP. Anything may have changed, and judging by the demos, VDT does not get as much attention or use as VST, so some bugs may have been unnoticed.

Would you mind to write a bug report and add a patch?
Sure I'll make a bug report and maybe even a patch for Hint field in the demo, however, I have no idea how to fix the hint behavior for VDT I fixed it - see post below.
I have no hope for it getting fixed, because
1) It's not a part of the LCL, and VDT is not widely used
2) The package doesn't seem to be maintained and synced to the original one (v5 is more than 10 years old, the latest is v8)
I've made a bug report into what I thought to be the package repo, but missed a bit  :D
« Last Edit: June 27, 2024, 02:45:47 am by trexet »

trexet

  • New Member
  • *
  • Posts: 37
Re: Unresponsive hints of TVirtualDrawTree + error in demo
« Reply #4 on: June 27, 2024, 12:43:07 am »
Checking the demo further, I discovered that even the system-drawn hints and tooltips (GridDemo, WindowsXPStyleDemo) suffer from the described issue. Supposedly, that's how the Windows handles the mouse staying inside the same Control, but I may be wrong and just need to investigate mouse handling within VirtualTree further.

-----

However, I've made some progress on reducing the boilerplate code of drawing a simple text hint for the VDT. Currently, it makes no use of OnGetHindKind and vhkText, using vhkOwnerDraw by default. Thus, I added the TVTHintKind to TVTHintData, so it's preserved over CMHintShow() calls.

Next, I added OnGetHint to VDT, being called if TVTHintData.Kind = vhkText. And finally, inside TVirtualTreeHintWindow.CalcHintRect() I replaced
Code: Pascal  [Select][+][-]
  1.       // The draw tree gets its hint size by the application (but only if not a header hint is about to show).
  2.       // This size has already been determined in CMHintShow.
  3.       if (Tree is TCustomVirtualDrawTree) and Assigned(Node) then
with
Code: Pascal  [Select][+][-]
  1.       // The draw tree gets its hint size by the application (but only if not a header or vhkText hint is about to show).
  2.       // This size has already been determined in CMHintShow.
  3.       if (Tree is TCustomVirtualDrawTree) and Assigned(Node) and (FHintData.Kind = vhkOwnerDraw) then
resulting in hint rect size being calculated automatically if TVTHintData.Kind = vhkText. Thus, OnGetHintSize is not required for the text hints in the VDT.

Next steps should be getting rid of OnDrawHint if vhkText is set, and trying to fix unresponsiveness if the cursor stays inside VT.

UPD: Removing OnDrawHint turned out to be pretty easy after previous changes - just added TVTHintData.Kind check to TVirtualTreeHintWindow.Paint():
Code: Pascal  [Select][+][-]
  1. if (Tree is TCustomVirtualDrawTree) and Assigned(Node) and (Kind = vhkOwnerDraw) then
Thus, the cute system text hint is shown.

UPD2: Managed to fix unresponsiveness! (regardless of TVTHintData.Kind)
VT tracks which node/column is hovered (hot) in the TBaseVirtualTree.HandleHotTrack() (regardless to toHotTrack). It has a check if the hot node/column has changed, which can be extended for our purposes:
Code: Pascal  [Select][+][-]
  1.   if (HitInfo.HitNode <> FCurrentHotNode) or (HitInfo.HitColumn <> FCurrentHotColumn) then
  2.   begin
  3.     {...}
  4.     // If we left the old hot node, then we should hide it's hint
  5.     if ShowHint then
  6.       Application.HideHint;
  7.   end;
Works like a charm for moving mouse over columns, however, to work as expected for rows (nodes), toFullRowSelect must be set. The reason for such requirement is an object to discover, and that's enough for today.

-----

If anyone would share the correct repository I should make a PR/send a patch to, I'd be grateful.
« Last Edit: June 27, 2024, 02:44:59 am by trexet »

El Salvador

  • Full Member
  • ***
  • Posts: 138
Re: Unresponsive hints of TVirtualDrawTree + error in demo
« Reply #5 on: June 27, 2024, 09:20:59 am »
Quote
I have no hope for it getting fixed, because
1) It's not a part of the LCL, and VDT is not widely used
2) The package doesn't seem to be maintained and synced to the original one (v5 is more than 10 years old, the latest is v8)
There is also a (very experimental) attempt to port version 8 to Lazarus: https://github.com/salvadorbs/VirtualTreeView-Lazarus

wp

  • Hero Member
  • *****
  • Posts: 12266
Re: Unresponsive hints of TVirtualDrawTree + error in demo
« Reply #6 on: June 27, 2024, 12:22:58 pm »
You posted your bug report to the forum of the original Lazarus port, but mentioned the version which comes with Lazarus - and this confused blikblum, the original author... Edit your report and remove the "Laz" prefix so that it becomes clear that you are referring to blikblum version.

The version which is distributed along with Lazarus (TLazVirtualDrawTree, TLazVirtualStringTree) is a fork of blikblum's v5 since it is needed by OPM; the renaming was done to still allow users to install another VTV version.

trexet

  • New Member
  • *
  • Posts: 37
Re: Unresponsive hints of TVirtualDrawTree + error in demo
« Reply #7 on: June 27, 2024, 12:50:33 pm »
Going further:

Without toFullRowSelect, FCurrentHotNode is nullified most of the times, so Application.HideHint is being constantly triggered. Solved by using separate FCurrentHintNode to track which node triggered a hint.

Issues 1 and 2 fixed, now for 3. When scrolling, mouse stays in same position. Mouse must leave FLastHintRect to reshow a hint, so we should reset it on scroll in the TBaseVirtualTree.CMMouseWheel():
Code: Pascal  [Select][+][-]
  1.     // Mouse stays in same position, so reset area which the mouse must leave to reshow a hint
  2.     if ShowHint and (ScrollAmount <> 0) then
  3.       FLastHintRect := Rect(0, 0, 0, 0);
Works fine, although, the mouse still need to be moved a bit to trigger the CMHintShow.

Testing the demos - all OK
So, everything I've been complaining about is fixed + added system-drawn text hints to VDT

You posted your bug report to the forum of the original Lazarus port, but mentioned the version which comes with Lazarus - and this confused blikblum, the original author... Edit your report and remove the "Laz" prefix so that it becomes clear that you are referring to blikblum version.
Now I'm confused too. Should I send a patch to both blikblum's version on Github and Lazarus repo on Gitlab?

wp

  • Hero Member
  • *****
  • Posts: 12266
Re: Unresponsive hints of TVirtualDrawTree + error in demo
« Reply #8 on: June 27, 2024, 03:20:49 pm »
Now I'm confused too. Should I send a patch to both blikblum's version on Github and Lazarus repo on Gitlab?
Send the patch to the blikblum repo, the Laz team later can adjust its LazVTV fork once your patch has been accepted by blikblum.

trexet

  • New Member
  • *
  • Posts: 37
Re: Unresponsive hints of TVirtualDrawTree + error in demo
« Reply #9 on: June 27, 2024, 04:23:16 pm »
OK, PR created: https://github.com/blikblum/VirtualTreeView-Lazarus/pull/33

What about fixing the empty Hint field in the DrawTreeDemo of vst_advanced demo? Should I make a PR in the Lazarus gitlab repo?
« Last Edit: June 27, 2024, 04:25:05 pm by trexet »

trexet

  • New Member
  • *
  • Posts: 37
Re: Unresponsive hints of TVirtualDrawTree + error in demo
« Reply #10 on: July 04, 2024, 11:47:49 am »
PR for VT got merged!

What about fixing the empty Hint field in the DrawTreeDemo of vst_advanced demo? Should I make a PR in the Lazarus gitlab repo?

wp

  • Hero Member
  • *****
  • Posts: 12266
Re: Unresponsive hints of TVirtualDrawTree + error in demo
« Reply #11 on: July 04, 2024, 01:11:52 pm »
Cannot compile blikblum's V5 now: In CMHintShow, there is now "DoGetHintKind(HitInfo.HitNode, HitInfo.HitColumn, FHintData.HintKind)" but FHintData only has a field "Kind" after your change. After replacing the HintKind by Kind here and two lines further down it does compile and install, though. How then can I test whether the patch works? Do you have a demo project which showed the original issue? You were referring to the "Advanced" demo, but are there any changes that I must make to this project?

trexet

  • New Member
  • *
  • Posts: 37
Re: Unresponsive hints of TVirtualDrawTree + error in demo
« Reply #12 on: July 04, 2024, 03:48:09 pm »
Cannot compile blikblum's V5 now: In CMHintShow, there is now "DoGetHintKind(HitInfo.HitNode, HitInfo.HitColumn, FHintData.HintKind)" but FHintData only has a field "Kind" after your change. After replacing the HintKind by Kind here and two lines further down it does compile and install, though. How then can I test whether the patch works? Do you have a demo project which showed the original issue? You were referring to the "Advanced" demo, but are there any changes that I must make to this project?

Thanks, pushed a fix. I've could mistyped it when moved the changes from my local package instance to the V5 repo.

As for test, you can test hints responsiveness with the existing Demo (WindowsXP or DrawTree would are convenient as they show hints by default).
To test system-drawn text hints of VDT, you can modify the DrawTree demo by adding these handlers:

Code: Pascal  [Select][+][-]
  1. procedure TDrawTreeForm.VDT1GetHint(Sender: TBaseVirtualTree;
  2.     Node: PVirtualNode; Column: TColumnIndex;
  3.     var LineBreakStyle: TVTTooltipLineBreakStyle; var HintText: String);
  4. var
  5.   Data: PShellObjectData;
  6. begin
  7.   Data := Sender.GetNodeData(Node);
  8.   if Column = 0 then HintText := Data.Display;
  9. end;
  10.  
  11. procedure TDrawTreeForm.VDT1GetHintKind(Sender: TBaseVirtualTree;
  12.   Node: PVirtualNode; Column: TColumnIndex; var Kind: TVTHintKind);
  13. begin
  14.   if Column = 0 then Kind := vhkText else Kind := vhkOwnerDraw;
  15.   // with #34 quickfix that can be without else:
  16.   // if Column = 0 then Kind := vhkText;
  17. end;

Note that the Hint property of VDT must not be empty for the vhkOwnerDraw hints ever to show as I mentioned earlier.
« Last Edit: July 04, 2024, 03:53:13 pm by trexet »

wp

  • Hero Member
  • *****
  • Posts: 12266
Re: Unresponsive hints of TVirtualDrawTree + error in demo
« Reply #13 on: July 04, 2024, 04:21:35 pm »
Thanks, got it working finally...

Committed changes to Lazarus port of VTV (incl. non-empty Hint property in the DrawTreeDemo).

Note that the Hint property of VDT must not be empty for the vhkOwnerDraw hints ever to show as I mentioned earlier.
Why is this necessary? Looks like something still is missing.

There is also an issue with the hints of the filename column of the DrawTreeForm because the hints are drawn too far away from the nodes (see attachment).
« Last Edit: July 04, 2024, 04:50:48 pm by wp »

 

TinyPortal © 2005-2018