Recent

Author Topic: Behaviour of TPopupMenu.OnClick  (Read 5757 times)

staratel20

  • Full Member
  • ***
  • Posts: 206
Behaviour of TPopupMenu.OnClick
« on: January 16, 2020, 11:59:22 pm »
When I create the dispatcher of PopupMenu TMenuItem.OnClick which is have submenu from right , it actually appears on event OnMouseEnter (or more correct to say - SubMenu.OnShow), which is obviously, not the same. That will be good to bring TPopupMenu.OnMouseDown , TPopupMenu.OnMouseUp , OnMouseEnter, OnMouseLeave. The behaviour of TPopupMenu.OnClick could be the same for good compatibility with Delphi projects.

Gonna explain the main thing - What for?
For example I need to check and uncheck TMenuItem by Clicking on it, but the right submenu of this item - it is some options, that affects if only TMenuItem checked

Thank you for attention
« Last Edit: January 17, 2020, 12:02:09 am by staratel20 »
Windows 7 SP1 x64, FPC 3.0.0, Lazarus from trunk: http://svn.freepascal.org/svn/lazarus/trunk

CountIdentity, ModeClassName - good property naming
IdentityCount,  ClassNameMode  - bad property naming

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Behaviour of TPopupMenu.OnClick
« Reply #1 on: January 17, 2020, 12:17:02 am »
Maybe you need the "AutoPopUp := False " ?
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Behaviour of TPopupMenu.OnClick
« Reply #2 on: January 17, 2020, 12:39:30 pm »
I on't exactly understand what's your problem but just in case, you can (un-)check items automatically by setting their AutoCheck property to True.

To set the Checked state from code you should do it either in the menu OnPopUp event, for items in the starting popup, or in the submenu's "parent" item OnClick

Just to make sure: your problem is that the sub-menu is shown before the "parent" OnClick event is fired?
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

staratel20

  • Full Member
  • ***
  • Posts: 206
Re: Behaviour of TPopupMenu.OnClick
« Reply #3 on: January 18, 2020, 10:50:38 pm »
jamie: no, I want AutoPopup, but I don't want component use auto-popup event like clicking event. For me it almost the same like to use OnMouseEnter like OnMouseClick with only delay difference

lucamar: I need to analyze your answer a little longer, please give me some time to reply.

This time thanks. Any other ideas - also good)
« Last Edit: January 18, 2020, 11:49:21 pm by staratel20 »
Windows 7 SP1 x64, FPC 3.0.0, Lazarus from trunk: http://svn.freepascal.org/svn/lazarus/trunk

CountIdentity, ModeClassName - good property naming
IdentityCount,  ClassNameMode  - bad property naming

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Behaviour of TPopupMenu.OnClick
« Reply #4 on: January 18, 2020, 11:47:49 pm »
I appears you are looking for additional event triggers to be added to the menus ?

 I just looked at the online Delphi help and I don't see anything there that Lazarus does not have..

 You could hook into the Window of the PopupMenu and handle the events but then it won't be cross platform.
The only true wisdom is knowing you know nothing

staratel20

  • Full Member
  • ***
  • Posts: 206
Re: Behaviour of TPopupMenu.OnClick
« Reply #5 on: January 18, 2020, 11:50:47 pm »
Yes jamie, this time you're right. And it sad for me to hear it...
Windows 7 SP1 x64, FPC 3.0.0, Lazarus from trunk: http://svn.freepascal.org/svn/lazarus/trunk

CountIdentity, ModeClassName - good property naming
IdentityCount,  ClassNameMode  - bad property naming

staratel20

  • Full Member
  • ***
  • Posts: 206
Re: Behaviour of TPopupMenu.OnClick
« Reply #6 on: January 21, 2020, 12:53:05 pm »
Also I still think that this is very, very wrong. Because the name of event not corresponds to what really happen
Windows 7 SP1 x64, FPC 3.0.0, Lazarus from trunk: http://svn.freepascal.org/svn/lazarus/trunk

CountIdentity, ModeClassName - good property naming
IdentityCount,  ClassNameMode  - bad property naming

rfwoolf

  • Newbie
  • Posts: 4
Re: Behaviour of TPopupMenu.OnClick
« Reply #7 on: June 13, 2020, 04:11:27 am »
+1
I'm having this same problem, but staratel20 did not explain it very well.

Summary:
If you have a TPopupMenu with a TMenuItem (parent) with a sub (child) TMenuItem, when you simply hover on the parent TMenuItem:
Expected behaviour:
The Submenu Item should open.
Actual behaviour:
The Submenu Item opens, AND it triggers the onClick event of the parent TMenuItem (if one exists) (if AutoCheck is false) or toggles the 'checked' status of the parent TMenuItem (if AutoCheck is true)

Steps to reproduce (if AutoCheck is set to true):
1. Create a TPopupMenu
2. Inside it: Create a Menu Item (parent)
    Set Checked := true;
    Set AutoCheck := true; (or see below if you set AutoCheck to false)
3. Inside that menu item: Create a **sub** Menu item (child) to the right.
4. Run the program, and **hover** over the parent menu.
Problem: It toggles the 'checked' status of the parent MenuItem.

Alternative (if AutoCheck set to false):
1. Create a TPopupMenu
2. Inside it: Create a Menu Item (parent)
    Set Checked := true;
    Set AutoCheck := false;
3. Inside that menu item: Create a **sub** Menu item (child) to the right.
4. Create an **OnClick** event handler for the parent Menu Item:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.MenuItem1Click(Sender: TObject);
  2. begin
  3.   showmessage('Clicked!');
  4. end;
5. Run the program, and **hover** over the parent menu.
Problem: It triggers the OnClick event.

I'm running Lazarus 2.0.6 on Windows 10.

rfwoolf

  • Newbie
  • Posts: 4
Re: Behaviour of TPopupMenu.OnClick
« Reply #8 on: June 13, 2020, 04:19:28 am »
Sadly, this bug was created in this fix:
https://bugs.freepascal.org/view.php?id=35219
They fixed 1 thing but broke another.
I have created a new bug report: 0037210
« Last Edit: June 13, 2020, 04:32:53 am by rfwoolf »

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Behaviour of TPopupMenu.OnClick
« Reply #9 on: June 13, 2020, 06:57:31 pm »
Personally I think they should revert the first one cause what did was not a big.
But now you have two problems one doing something that's not suppose to happen in the place and now this bug

Doesn't anyone check these things before blindly applying a patch?
A child popup has events u can use and why does someone think they ARE suppose trigger the parents too?

.... I bet the one that created the patch is grinning.
The only true wisdom is knowing you know nothing

El Salvador

  • Full Member
  • ***
  • Posts: 133
Re: Behaviour of TPopupMenu.OnClick
« Reply #10 on: January 02, 2021, 06:26:14 pm »
In my application, I need the event onclick for parent TMenuItem (with submenu) to create a dynamic trayicon menu (so I will populate the menu per level). Any ideas to include the patch in my application, without modify directly Lazarus source?

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Behaviour of TPopupMenu.OnClick
« Reply #11 on: January 02, 2021, 07:27:13 pm »
I guess I don't understand the problem here ?

first off, I don't see an issue with false triggering of menus in the trunk or in my old copies .


But if you want to trigger an assigned OnClick handle of the parent of some child menu item then just assign the child menu item onclick and from there onclick handler you can call the parent handler directly...
line this
In the OnClick Method of your SubMenu
Code: Pascal  [Select][+][-]
  1.  TmenuItem(Sender).Parent.OnClick(sender);
  2.  
The only true wisdom is knowing you know nothing

El Salvador

  • Full Member
  • ***
  • Posts: 133
Re: Behaviour of TPopupMenu.OnClick
« Reply #12 on: January 03, 2021, 11:20:59 am »
Quote
first off, I don't see an issue with false triggering of menus in the trunk or in my old copies .
In rev. 64308, this doesn't work. When you open a TMenuItem with a child, onClick will be not called (patch reverted). In Laz 2.0.10, instead, onClick works.

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Behaviour of TPopupMenu.OnClick
« Reply #13 on: January 03, 2021, 04:22:08 pm »
what Onclick are you referring to ?

The Onclick of the child or the parent ? Please be clear about this because you are confusing the matter !

The rerun this , a child's onclcik should be fired only when you click on the child and the parent of that child should not be fired! period!

Why  you may ask, well. this is simple
 If I were to dynamically create child menus then I don't want the parent onclick handler to fire, why? because the parent  should only fire when there are no children in the list! ..

 This gives the option of notifying the user that there are no child menus and thus they could add them or what ever..

 So if I read your thoughts correctly you believe the parent menu should also be fired regardless and if that is the case then you are wrong!

 And if you believe as I do and you are saying that 2.0.10 does fire always then of course its an error in 2.0.10.
if you want to fix that you can with your local copy until the trunk gets released.


« Last Edit: January 03, 2021, 04:24:20 pm by jamie »
The only true wisdom is knowing you know nothing

El Salvador

  • Full Member
  • ***
  • Posts: 133
Re: Behaviour of TPopupMenu.OnClick
« Reply #14 on: January 03, 2021, 07:14:00 pm »
Quote
The rerun this , a child's onclcik should be fired only when you click on the child and the parent of that child should not be fired! period!
Wait, maybe I explained myself wrong. I'm sorry.  :-[

I known this is a false issue (or wrong patch or wrong behaviour), but in my software built in Delphi (from 7 to 10.3), this behaviour is perfectly normal. I want to replicate it in Lazarus. I kindly ask for help to replicate this behaviour in my software's source. I don't want fix a false issue in Lazarus. There is no way? Ok, no problem, friends like before.  :D

Quote
If I were to dynamically create child menus then I don't want the parent onclick handler to fire, why? because the parent  should only fire when there are no children in the list! ..
Why? I'm working on a popupmenu who resemble a folder structure (any folder chosen by user). So I can't populate the whole structure (it can be too slow, based of folder structure), if user want see first or second level of it (ex., compared to 4 or 5 levels of subfolders).

Quote
So if I read your thoughts correctly you believe the parent menu should also be fired regardless and if that is the case then you are wrong!
See above.

Quote
And if you believe as I do and you are saying that 2.0.10 does fire always then of course its an error in 2.0.10
As already mentioned, this behaviour is present in 2.0.10 and only for me, it's ok. But this patch is reverted in Lazarus trunk, as it should be. So I need to find a solution for the future Lazarus 2.2.

Quote
if you want to fix that you can with your local copy until the trunk gets released.
I don't want a fix in Lazarus sources, but in my application sources. Make personal patch can lead to human errors. If there is a way, better make it in software sources.

 

TinyPortal © 2005-2018