Recent

Author Topic: TCustomListview does not fire Click event?  (Read 1845 times)

d7_2_laz

  • Full Member
  • ***
  • Posts: 110
TCustomListview does not fire Click event?
« on: March 09, 2021, 11:31:54 pm »
I'm bringing an old app from Delphi 7 to Lazarus 2.0.10 / Windows x64 only
and just noticed that within a component based on TCustomListView the Click event (on a listitem) does not fire. Trying with OnClick;= .... the same.
I couldn't believe that and looked into customlistview.inc and saw that the processing of the NM_CLICK notification is commented out (line 377).
Whereas in the Delphi 7 ComCtrls.pas  NM_Click is evaluated and remembered as a flag (FClicked := True;) that later is used for to distingiush that from drag and drop processing (being betwenn wm_lbuttundown/up). A simple hack here could badly interfere with Drag&Drop operations. I'd like to avoid such experiments.

I stopped my research for to ask, it this restriction (if if really should exist) is already known .... and what we can do here to precess a listview click event message in a component.

jamie

  • Hero Member
  • *****
  • Posts: 4446
Re: TCustomListview does not fire Click event?
« Reply #1 on: March 09, 2021, 11:43:52 pm »
Yup, I remember that code ..

Maybe one day it will get fixed.
The only true wisdom is knowing you know nothing

d7_2_laz

  • Full Member
  • ***
  • Posts: 110
Re: TCustomListview does not fire Click event?
« Reply #2 on: March 09, 2021, 11:48:55 pm »
One day? That is is a joke?
I thought to process a click event within a custom listview item should be a very basic  request in 2021.

wp

  • Hero Member
  • *****
  • Posts: 8395
Re: TCustomListview does not fire Click event?
« Reply #3 on: March 09, 2021, 11:53:52 pm »
I don't understand what you are talking about. Please run the attached project and see that the OnClick event indeed is fired.

Please provide a (simple) compilable example and demonstrate the issue.

Do not expect that the LCL works internally in exactly the same way as their VCL counterparts because LCL must support a variety of widgetsets while VCL only supports Windows.
« Last Edit: March 10, 2021, 12:09:37 am by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

jamie

  • Hero Member
  • *****
  • Posts: 4446
Re: TCustomListview does not fire Click event?
« Reply #4 on: March 10, 2021, 12:06:33 am »
I suppose  the WM_Notify could be handled/overridden to capture that message.
The only true wisdom is knowing you know nothing

d7_2_laz

  • Full Member
  • ***
  • Posts: 110
Re: TCustomListview does not fire Click event?
« Reply #5 on: March 10, 2021, 12:14:26 am »
Hello wp, greetings!
i already did try a check against a regular listview and noticed that that one is processing the click indeed (picture).
I had thw issue with a customlistview based compo and simply was asking if it is supposed to work with that one too, I'd rather prefer it's my own error because it is so basic.

janie - you would say: yes i would need to reimplement parts of the old Delphi 7 ComCtrls.pas stuff again?  (TCustomListView.CNNotif), or, as another approach, using WM_Notify?
But would that help others when havnig the same prob?

jamie

  • Hero Member
  • *****
  • Posts: 4446
Re: TCustomListview does not fire Click event?
« Reply #6 on: March 10, 2021, 01:40:32 am »
The windows style of doing it is to handle the WM_Notify but I appears that maybe when the LCL was written for the cross platforms they didn't take this into account..

 I believe a thread was already hashed out over this once and a different approach is being used...

 I don't remember now but I believe it could be handling the Mouse down messages and just doing a  NodeAtPos(…..) etc...

in any case, maybe what you should be doing is overriding the DoClick procedure instead
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 8395
Re: TCustomListview does not fire Click event?
« Reply #7 on: March 10, 2021, 01:57:06 am »
It is still unclear what you want to achieve. An OnClick event that fires only when a listitem is clicked rather than clicking anywhere inside the listview? In this case override the Click method (there is no general DoClick) and check the result of the GetHitTestInfoAt function before calling inherited. (BTW, rather than destroying the inherited behaviour of the OnClick event I'd introduce a new event for this purpose such as "OnListItemClick").
« Last Edit: March 10, 2021, 02:02:08 am by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

d7_2_laz

  • Full Member
  • ***
  • Posts: 110
Re: TCustomListview does not fire Click event?
« Reply #8 on: March 10, 2021, 02:13:55 am »
Thank you jamie and wp (wp: click onto a listitem caption, not into the non-selection area).

After a lot of investigation i found out that in fact i was wrong (it was hard for me to believe that the click could not be fetched in the customlistview in difference to the regular listview):

In fact the click had been eaten up (differently to D7 however!) by a BeginDrag operation in the MouseDown event. Those lines were guilty:
Code: Pascal  [Select][+][-]
  1.         if DragDetect(Handle, ClienttoScreen(Point(X, Y))) then
  2.            BeginDrag(True);

If i deactivate those lines, the click callback  is back. So i might have a problem elsewhere, but the original topic is a false assumption (because it's due to interference with DragDop). So i need to apologize! I was not aware of that when doing the post.
Of course it might be the case that those special measures in Delphi 7 comctrls.pas i mentioned in my OP had been the reason why i did not encounter that in Delphi.

 

TinyPortal © 2005-2018