Lazarus

Programming => LCL => Topic started by: staratel20 on January 16, 2020, 11:59:22 pm

Title: Behaviour of TPopupMenu.OnClick
Post by: staratel20 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
Title: Re: Behaviour of TPopupMenu.OnClick
Post by: jamie on January 17, 2020, 12:17:02 am
Maybe you need the "AutoPopUp := False " ?
Title: Re: Behaviour of TPopupMenu.OnClick
Post by: lucamar 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?
Title: Re: Behaviour of TPopupMenu.OnClick
Post by: staratel20 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)
Title: Re: Behaviour of TPopupMenu.OnClick
Post by: jamie 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.
Title: Re: Behaviour of TPopupMenu.OnClick
Post by: staratel20 on January 18, 2020, 11:50:47 pm
Yes jamie, this time you're right. And it sad for me to hear it...
Title: Re: Behaviour of TPopupMenu.OnClick
Post by: staratel20 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
Title: Re: Behaviour of TPopupMenu.OnClick
Post by: rfwoolf 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.
Title: Re: Behaviour of TPopupMenu.OnClick
Post by: rfwoolf 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
Title: Re: Behaviour of TPopupMenu.OnClick
Post by: jamie 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.
TinyPortal © 2005-2018