[Lazarus] TTreeView.OnItemClicked

Juha (gmail) juha.manninen62 at gmail.com
Sun Apr 24 09:59:07 CEST 2011


Mattias Gaertner kirjoitti sunnuntai, 24. huhtikuuta 2011 02:19:03:
> > Is it OK to implement a new event OnItemClick or OnNodeClick for
> > TTreeView? It would be triggered only a node is clicked, not the '+' or
> > background.
> 
> Often the background should be included in the trigger area.
> And sometimes - as for example in the find in files dialog - you need
> to distinguish between single and multi click.
> All this can be easily done with OnMouseDown/Up.

Ok, it is _relatively_ easy but still not very intuitive.
I guess 99% of code is only interested in clicked Nodes.
Looking at your fix to TSearchResultsView, most of TreeViewMouseUp code is only 
for checking if a Node is left-clicked:

 var
   TV: TCustomTreeView;
   Node: TTreeNode;
 begin
   if Button<>mbLeft then exit;
   TV:=Sender as TCustomTreeView;
   Node:=TV.GetNodeAt(X,Y);
   if Node=nil then exit;
   if x<Node.DisplayTextLeft then exit;

...and then dealing with single/double click:

   if ([ssDouble,ssTriple,ssQuad]*Shift=[])
     and EnvironmentOptions.MsgViewDblClickJumps then exit;

In this case both single and double clicks need to be handled but typically 
only one of them.

So, I still think it is a good idea to have events
OnNodeClicked and OnNodeDoubleClicked
with "Node: TTreeNode" parameter.

Juha




More information about the Lazarus mailing list