Recent

Author Topic: Curious, is there a reason TtoolButton does not have a double click?  (Read 672 times)

jamie

  • Hero Member
  • *****
  • Posts: 7319
I just implemented a double click effect using a single click and tick timer, I was just curious why double click event never got put in?

Jamie
The only true wisdom is knowing you know nothing

Zvoni

  • Hero Member
  • *****
  • Posts: 3140
Re: Curious, is there a reason TtoolButton does not have a double click?
« Reply #1 on: September 08, 2025, 09:50:29 am »
I just implemented a double click effect using a single click and tick timer, I was just curious why double click event never got put in?

Jamie
How do you figure that?
https://lazarus-ccr.sourceforge.io/docs/lcl/comctrls/ttoolbutton.html

under Events there is an OnDblClick (inherited from TControl)

Or do you mean it's missing because it wasn't "Published" (not available in OI)?

Write your own "Procedure OnDblClick(Sender:TObject);" inside your TForm-Section,
put your DoubleClick-Code into the Procedure
in the OnCreate of the Form assign it to "OnDblClick"-Event,
Done
« Last Edit: September 08, 2025, 09:56:36 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Thaddy

  • Hero Member
  • *****
  • Posts: 18364
  • Here stood a man who saw the Elbe and jumped it.
Re: Curious, is there a reason TtoolButton does not have a double click?
« Reply #2 on: September 08, 2025, 09:53:02 am »
For toolbutton it is protected.....
Code: Pascal  [Select][+][-]
  1. TToolbuttonExt = class (TToolbutton);
  2. published
  3.   property OnDblClick;// that's all
  4. end;
You can now use it from code. It you register it, you can also use it from the object inspector.
Untested but this should be all there is to it.

You can also write a type helper for it.

The reason it is not in is maybe that it is the expected behavior for a toolbutton?
« Last Edit: September 08, 2025, 10:02:37 am by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

Zvoni

  • Hero Member
  • *****
  • Posts: 3140
Re: Curious, is there a reason TtoolButton does not have a double click?
« Reply #3 on: September 08, 2025, 10:01:37 am »
For toolbutton it is protected.....
Code: Pascal  [Select][+][-]
  1. TToolbuttonExt = class (TToolbutton);
  2. published
  3.   property OnDblClick;// that's all
  4. end;
You can now use it from code. It you register it, you can also use it from the object inspector.
Untested but this should be all there is to it.

You can also write a type helper for it.
Yep.
Missed that it's protected in TControl
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Thaddy

  • Hero Member
  • *****
  • Posts: 18364
  • Here stood a man who saw the Elbe and jumped it.
Re: Curious, is there a reason TtoolButton does not have a double click?
« Reply #4 on: September 08, 2025, 10:07:04 am »
Jamie probably also missed that ....  :D Did you? @Jamie?
[edit]
It seems that this does not work on all widgetsets, e.g. it fails on windows. Maybe that is due to the underlying Windows control.
« Last Edit: September 08, 2025, 11:04:23 am by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

jamie

  • Hero Member
  • *****
  • Posts: 7319
Re: Curious, is there a reason TtoolButton does not have a double click?
« Reply #5 on: September 08, 2025, 02:06:59 pm »
I don't miss much, and I didn't miss this one either.

I am aware of it being there, it's not published is what I meant to say.

I believe the Control Flag is set to not allow a double click.

It's no big deal but I use double clicks on a toolbar button, so I'll stick with what I got atm, it works.

Jamie
The only true wisdom is knowing you know nothing

Zvoni

  • Hero Member
  • *****
  • Posts: 3140
Re: Curious, is there a reason TtoolButton does not have a double click?
« Reply #6 on: September 08, 2025, 02:19:33 pm »
I don't miss much, and I didn't miss this one either.

I am aware of it being there, it's not published is what I meant to say.

I believe the Control Flag is set to not allow a double click.

It's no big deal but I use double clicks on a toolbar button, so I'll stick with what I got atm, it works.

Jamie

Looks like it
in toolbutton.inc
Code: Pascal  [Select][+][-]
  1. constructor TToolButton.Create(TheOwner: TComponent);
  2. begin
  3.   inherited Create(TheOwner);
  4.   FImageIndex := -1;
  5.   FStyle := tbsButton;
  6.   FShowCaption := true;
  7.   ControlStyle := [csCaptureMouse, csSetCaption, csDesignNoSmoothResize];  //<-- !!!!
  8.   with GetControlClassDefaultSize do
  9.     SetInitialBounds(0, 0, CX, CY);
  10.   AccessibleRole := larToolBarButton;
  11. end;                                  

In control.inc
Code: Pascal  [Select][+][-]
  1. constructor TControl.Create(TheOwner: TComponent);
  2. var
  3.   Side: TAnchorKind;
  4. begin
  5.   DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.Create'){$ENDIF};
  6.   try
  7.     //if AnsiCompareText(ClassName,'TSpeedButton')=0 then
  8.     //  DebugLn('TControl.Create START ',Name,':',ClassName);
  9.     inherited Create(TheOwner);
  10.  
  11.     // no csOpaque: delphi compatible, win32 themes notebook depend on it
  12.     // csOpaque means entire client area will be drawn
  13.     // (most controls are semi-transparent)
  14.     FAccessibleObject := CreateAccessibleObject();
  15.     FControlStyle := FControlStyle
  16.                    +[csCaptureMouse, csClickEvents, csSetCaption, csDoubleClicks];        //<--!!!
  17. .....

Control-Style is a Public Property, so it's accessible.
add the csDoubleClicks on creation?
« Last Edit: September 08, 2025, 02:22:49 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

jamie

  • Hero Member
  • *****
  • Posts: 7319
Re: Curious, is there a reason TtoolButton does not have a double click?
« Reply #7 on: September 08, 2025, 06:18:55 pm »
I'll stick with what I am doing now, it's just a couple of lines of code inside the OnClick.

Jamie
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018