[Lazarus] TTreeView.OnItemClicked

Mattias Gaertner nc-gaertnma at netcologne.de
Sun Apr 24 11:28:12 CEST 2011


On Sun, 24 Apr 2011 10:59:07 +0300
"Juha (gmail)" <juha.manninen62 at gmail.com> wrote:

> 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.

I think your 99% is highly exaggerated.
There is only one place in the whole IDE and here it is not clear if
with or without background (I would prefer with).


> 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;

There was a small mistake. The 'and' must be a '='.

 
> 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.

I still think they are hardly used.
If OnNodeClicked would support clicking via keyboard then it has a gain.


Mattias




More information about the Lazarus mailing list