Hello wp,
you got the idea, exactly! And the good news is: it does work fine (tested with shelltree demo too).
With the only specification: the idea behind is not to move the check for "HasChildren" into the painting cycle,
but to move it there, where the SHGetFileInfoW is already doing it's job (here: for getImageIndex);. With the
pleasant accompanying effect, that it's only for the node that come into the view (maybe 30 instad of 18000 at once).
And what we surely don't want is that SHGetFileInfoW (we know it's time intensive) should be called again twice, elsewhere.That won't speedup, but slow down the overall process noticeably and kill the desired effect.
About the abuse the OnGetImageIndex: fully agree! I don't like it either!
(unfortunately the expensive SHGetFileInfoW is already herein ... and i want to reuse it's results).
So my preferred option would be, just as you proposed, a new event - that might be, purely optional, used or not.
A purely generic optional slot, transparent and nothing changing for existing apps.
Whatever it is named .... so i thought about, in the alternative proposal, something like that:
if FSelectedNode <> Node then begin
if Assigned(FOnCustomGetSettings) then // but that requires a variable def. outside of treeview.inc (commctrls)
FOnCustomGetSettings(Self, Node);
...
...
HasExpandSign := ShowButtons and Node.HasChildren and ((tvoShowRoot in Options) or (Node.Parent <> nil));
The only reason i didn't use that, had been that i tried to avoid to touch another file (commctrls.pp) for to place the definitions here.
Whatever this custom event is, it should meet the twofold requirements;
- can fetch the imageindex here as efficient as before (= only when needed). Instead of using OnGetImageIndex of course
- can reuse SHGetFileInfoW for to fetch other attributes and allow to set (and later paint) HasChildren here.
SHGetFileInfoW shouldn't be forced to be called elsewhere again (the need for multiple calls should be avoided)
So probably within PaintNode might stay the best place though.