7

When I use toUseExplorerTheme in TVirtualStringTree.PaintOptions it draws the selection like this:

Illustration of selection with toUseExplorerTheme

Notice that the selection extends from the left side of the control to the position of the rightmost extent of any node caption; the selections are all the same width.

I want it to look as in this image (someone else's project, using Virtual TreeView), where the selection covers only the text of the node caption:

enter image description here

Unless there is a regression in Virtual TreeView (I'm using 5.2.2) then this must be possible, but I cannot find the right combination of options.

Here's my set-up code:

fTree := TVirtualStringTree.Create(Self);
fTree.Parent            := Self;
fTree.Align             := alClient;

fTree.OnGetText         := TreeGetText;
fTree.OnInitNode        := TreeInitNode;
fTree.OnInitChildren    := TreeInitChildren;
fTree.OnChange          := TreeSelectionChange;
fTree.RootNodeCount     := 1;
fTree.DrawSelectionMode := smBlendedRectangle;

fTree.TreeOptions.PaintOptions     := fTree.TreeOptions.PaintOptions
                                      + [toUseExplorerTheme];
fTree.TreeOptions.SelectionOptions := fTree.TreeOptions.SelectionOptions
                                      + [toMultiSelect];
Ian Goldby
  • 5,609
  • 1
  • 45
  • 81
  • Ragged edges on multi-select? Yikes.... Tastes differ I guess, but it is going to look, well... untidy? +1 For a well put question though. – Marjan Venema Dec 17 '13 at 18:04
  • @Marjan, variety is the spice of life :-) – TLama Dec 18 '13 at 08:22
  • @MarjanVenema An alternative is Explorer-style selections that span the entire width, but then it's harder/impossible to click outside the selection to deselect all. Anyway, I like the ragged right edge. – Ian Goldby Dec 18 '13 at 09:40
  • No worries. Though you might get flamed at [ux.se] for that :-) – Marjan Venema Dec 18 '13 at 11:37

1 Answers1

6

Sorry, that was my fault. The statement I've suggested in this issue should have rather be:

procedure DrawBackground(State: Integer);
begin
  // if the full row selection is disabled or toGridExtensions is in the MiscOptions, draw the selection
  // into the InnerRect, otherwise into the RowRect
  if not (toFullRowSelect in FOptions.FSelectionOptions) or (toGridExtensions in FOptions.FMiscOptions) then
    DrawThemeBackground(Theme, PaintInfo.Canvas.Handle, TVP_TREEITEM, State, InnerRect, nil)
  else
    DrawThemeBackground(Theme, PaintInfo.Canvas.Handle, TVP_TREEITEM, State, RowRect, nil);
end;

The same applies also to the next nested procedure DrawThemedFocusRect. The fix is now commited to the revision r587, so please update your Virtual Treeview. Thanks to @joachim for cooperation!

Community
  • 1
  • 1
TLama
  • 75,147
  • 17
  • 214
  • 392
  • @Joachim, wow, that was quick. However, could you do the similar also to the `DrawThemedFocusRect` nested procedure, please ? I was going to submit an issue today since I was busy yesterday. Thank you and sorry for this issue! – TLama Dec 18 '13 at 08:19
  • Thanks. I found this in my first hour of using Virtual TreeView and couldn't seriously believe I had found a bug no one else had noticed! Turns out I was wrong this time ;-) Not sure my question deserves quite so many up-votes though… Virtual TreeView must be a nightmare to test with so many configurable options. – Ian Goldby Dec 18 '13 at 09:27
  • @TLama: Done also for DrawThemedFocusRect() in r587. Would you mind reviewing the code change? – Joachim Marder Dec 18 '13 at 12:17