Recent

Author Topic: TreeView, FontColor without tvoThemedDraw vs. TreeViewAdvancedCustomDrawItem  (Read 538 times)

d7_2_laz

  • Hero Member
  • *****
  • Posts: 511
Windows x64, Lazarus 2.2.2

That was really not on top of my prio list, but from time to time i noticed that for a treeview setting a font color (depending on certain conditions) did not work within my TreeViewAdvancedCustomDrawItem.
With Delphi 7 (using a Windows-API for Treeview) it did work, with Lazarus (native treeview) it does not.
I did find the advice which gave the clue - one needs to exclude tvoThemedDraw from the treeview's options. See:
https://forum.lazarus.freepascal.org/index.php?topic=19412.0
https://wiki.freepascal.org/TTreeView/es

Indeed, that helps.
But now other directives within TreeViewAdvancedCustomDrawItem stop to work. One example: for to paint a special background and border style for a selected node.

So my first question would be: does the exclusion of tvoThemedDraw stops to work the custom draw as previously  used? Why, and is it by design?

Now about my second question. I did find a workaround. For the case give above, a simple trick might help.
- For selected nodes, that should be painted in a special way, include tvoThemedDraw.
- For the other nodes: exclude tvoThemedDraw.  See code snippet below.

That does mean: within the TreeViewAdvancedCustomDrawItem, the treeview option "tvoThemedDraw" would be needed to be switched on or off, depending on a certain condition.
Surprisingly enough, seen functionally that does work. But seen conceptionally i feel very very uncomfortable with such a tactics (ouch !!! Really we need to do that?)
The question: is that really the foreseen way to go?
Does anybody encounter such situation or can give any additional info?

Code: Pascal  [Select][+][-]
  1. TMyDirTree.TreeViewAdvancedCustomDrawItem  ...........
  2.  
  3.   if cdsSelected in State then
  4.         Self.Options := Self.Options + [tvoThemedDraw]
  5.   else  Self.Options := Self.Options - [tvoThemedDraw];
  6.   attrs := Integer(Node.Data);
  7.   if attrs > 0 then    // here's a condition which font color to set
  8.      Canvas.Font.Color := AttributeToColor(attrs);
  9.   if Not (cdsSelected in State) then
  10.      exit;  // Leave custom draw with having set the font color for non-selected nodes
  11.   // and now do the custom draw stuff for the selected node ....  


Lazarus 3.2  FPC 3.2.2 Win10 64bit

wp

  • Hero Member
  • *****
  • Posts: 11857
https://wiki.freepascal.org/TTreeView/es
That this hint is available only in the Spanish wiki indicates a weakness of the wiki translation approach...

Comparing with Delphi XE 10.4 I see that changing the Font.Color is applied. Looking for an Options property - there is none. Therefore, I guess that Delphi is drawing the node without theme services.

I think basically the idea behind the LCL TreeView is correct: Normally paint the nodes with theme services, or change an option (tvoThemedDraw) if you want to paint them without themes (like Delphi), i.e. give control to the color properties. I wish other controls had this option, too.

If turning off tvoThemedDraw has side effects you should post an example so that the issue can be studied and debugged. Ideally in bugtracker, so that it is seen by all developers.


« Last Edit: July 02, 2022, 12:16:46 pm by wp »

d7_2_laz

  • Hero Member
  • *****
  • Posts: 511
Thanks once more wp for the possibility to exchange opinions here!

No, from a practical point of view i didn't see side effects yet, but at least i would have liked to ask if anybody can imagine a "don't do this" (to switch theme awareness on or off on an individual node level).
Do you see some "don't do this" here?

I would not like to push it as a lcl bug, but at least it's worthy to know that one might switch tvoThemedDraw on for to set a brush color,
whereas it's needed to switch it off for to define a font color. That's somehow counterintuitive.

I attached a small test project for interest.

PS: forgot to mention: within TreeViewAdvancedCustomDrawItem, i don't need (and don't want) to set DefaultDraw to false.
« Last Edit: July 02, 2022, 02:43:33 pm by d7_2_laz »
Lazarus 3.2  FPC 3.2.2 Win10 64bit

 

TinyPortal © 2005-2018