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.0https://wiki.freepascal.org/TTreeView/esIndeed, 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?
TMyDirTree.TreeViewAdvancedCustomDrawItem ...........
if cdsSelected in State then
Self.Options := Self.Options + [tvoThemedDraw]
else Self.Options := Self.Options - [tvoThemedDraw];
attrs := Integer(Node.Data);
if attrs > 0 then // here's a condition which font color to set
Canvas.Font.Color := AttributeToColor(attrs);
if Not (cdsSelected in State) then
exit; // Leave custom draw with having set the font color for non-selected nodes
// and now do the custom draw stuff for the selected node ....