Recent

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

staratel20

  • Full Member
  • ***
  • Posts: 203
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: 3520
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: 3019
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 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

staratel20

  • Full Member
  • ***
  • Posts: 203
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: 3520
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: 203
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: 203
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: 3520
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

 

TinyPortal © 2005-2018