View Issue Details

IDProjectCategoryView StatusLast Update
0025415LazarusLCLpublic2019-04-26 07:31
ReporterAnton KavalenkaAssigned ToMichl 
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionopen 
Product Version1.3 (SVN)Product Build 
Target VersionFixed in Version 
Summary0025415: LCL: TPopupMenu inserted in TmainMenu disappear after being shown by another control
DescriptionTPopupMenu, inserted in TMainMenu (as collection of items) works until the popup menu shown by calling PopupMethod or show as context menu of control.
Steps To ReproduceClick "View" - Point to "Layout" -> submenu "Classes" will be shown.
Right-click the form - submenu "Classes" will be shown again.
Clich "View" - "Layout" submenu is hidden.
Additional Informationbehaviour is identical under i386-win32 and x86_64-gtk2
TagsNo tags attached.
Fixed in Revision
LazTarget
WidgetsetGTK 2, Win32/Win64
Attached Files
  • laztest85.zip (129,126 bytes)
  • p1.PNG (7,783 bytes)
    p1.PNG (7,783 bytes)
  • p2.PNG (5,852 bytes)
    p2.PNG (5,852 bytes)
  • p3.PNG (5,973 bytes)
    p3.PNG (5,973 bytes)
  • popupmenu.inc.patch (540 bytes)
    Index: lcl/include/popupmenu.inc
    ===================================================================
    --- lcl/include/popupmenu.inc	(revision 53363)
    +++ lcl/include/popupmenu.inc	(working copy)
    @@ -75,8 +75,9 @@
       if Items.Count = 0 then exit;
       ActivePopupMenu := Self;
       Items.InitiateActions;
    -  DestroyHandle;
    -  CreateHandle;
    +// removed due to mantis #0025415
    +//  DestroyHandle;
    +//  CreateHandle;
       if Assigned(OnMenuPopupHandler) then OnMenuPopupHandler(Self);
       TWSPopupMenuClass(WidgetSetClass).Popup(Self, X, Y);
     end;
    
    popupmenu.inc.patch (540 bytes)
  • SimpleTest.zip (2,063 bytes)
  • layout-mac.png (74,884 bytes)
    layout-mac.png (74,884 bytes)

Relationships

related to 0015614 closedPaul Ishenin TPopupMenu.Close() need rework 
related to 0030867 closedJuha Manninen Strange behaviour of a popupmenu for ComboBox, Memo and Panel 

Activities

Anton Kavalenka

2013-12-10 14:57

reporter  

laztest85.zip (129,126 bytes)

Anton Kavalenka

2013-12-10 14:57

reporter  

p1.PNG (7,783 bytes)
p1.PNG (7,783 bytes)

Anton Kavalenka

2013-12-10 14:57

reporter  

p2.PNG (5,852 bytes)
p2.PNG (5,852 bytes)

Anton Kavalenka

2013-12-10 14:57

reporter  

p3.PNG (5,973 bytes)
p3.PNG (5,973 bytes)

Juha Manninen

2013-12-10 20:40

developer   ~0071858

Example project is missing.

Anton Kavalenka

2013-12-10 22:37

reporter   ~0071863

laztes85.zip - 1st file

Reiner

2013-12-12 04:47

reporter   ~0071871

There are two issues here:
Firstly, a TMenuItem has a Parent TMenuItem - that is it can only have ONE parent. You are populating a list of a TPopupMenu (so when you call pmViewClasses.Items.Add(mi) the parent of your items becomes the popup menu). You are then miView.Add(pmViewClasses.Items) to add your popup menu to the view menu. You cannot do this as the menu items can't have different parents.

If you look at the LCL code where it eventually goes to (TMenuItem.Insert) you will notice it tries to catch already assigned menu items being re-assigned
  if Item.Parent <> nil then RaiseGDBException('Menu inserted twice');

The problem is you are adding pmViewClasses.Items to your View menu, which is actually the top level menu item of the popup and that has no parent. This is why your code doesn't generate an exception when you try and copy your menu items (it should) and where the Lazarus bug is.

The proper way to do this is to create a separate TMenuItem for each one in your popup and add these other ones to a sub-menu of your View menu (you could even use .Assign).

Looking at the Lazarus source I'm not sure how you would fix this so that it raises an exception because TPopupMenu.Items is a TMenuItem with Parent=nil.

Anton Kavalenka

2013-12-12 08:35

reporter   ~0071872

Thank you for analysis.

But it works both in Delphi 7 and XE2.

The idea in code:
You show menu entirely (with popup inserted) or part of menu (popup only).
Nothing inserted twice. Just show tree or branch of tree.

It works in Delphi, IMO, because Delphi allocates real HMenu handles immediately before showing menu, and does not cache them.

Anton Kavalenka

2013-12-16 14:23

reporter   ~0071923

Last edited: 2013-12-16 15:02

View 2 revisions

Adding the following code into OnClose handler of TpopupMenu
solves the problem.

procedure TForm1.pmViewClassesClose(Sender: TObject);
begin
  pmViewClasses.Items.Recreatehandle;
end;

Btw current TmenuItem.CreateHandle and TmenuItem.DestroyHandle is very asymmetric.
CreateHandle checks if current menu item has the same parent and then allocates new handle, Destroyhandle releases all the handles unconditionally.

In any way handles are cached when menu closed, and destroyed on next .Popup() method call.

Michl

2016-11-13 22:22

developer   ~0095849

This bug is related to 0015614. I have no Qt or OS X to test the issue fixed there.

When I remove DestroyHandle and CreateHandle from the the added code (revision 23585), it works like in Delphi. Tested with 32 and 64bit Windows 7 and 32 and 64bit Linux Mint KDE GTK2.

I add the patch, to show you, what I've done (DON'T APPLY IT, UNTIL IT IS CLEAR, WHAT IT ALSO AFFECTS).
I add a more simple test.

@Zeljan Rikalo, maybe you can have a look at this issue on Qt and OS X?

Maybe the workaround from 0015614 could be done in the TWSPopupMenuClass(WidgetSetClass)?

Michl

2016-11-13 22:22

developer  

popupmenu.inc.patch (540 bytes)
Index: lcl/include/popupmenu.inc
===================================================================
--- lcl/include/popupmenu.inc	(revision 53363)
+++ lcl/include/popupmenu.inc	(working copy)
@@ -75,8 +75,9 @@
   if Items.Count = 0 then exit;
   ActivePopupMenu := Self;
   Items.InitiateActions;
-  DestroyHandle;
-  CreateHandle;
+// removed due to mantis #0025415
+//  DestroyHandle;
+//  CreateHandle;
   if Assigned(OnMenuPopupHandler) then OnMenuPopupHandler(Self);
   TWSPopupMenuClass(WidgetSetClass).Popup(Self, X, Y);
 end;
popupmenu.inc.patch (540 bytes)

Michl

2016-11-13 22:23

developer  

SimpleTest.zip (2,063 bytes)

Anton Kavalenka

2016-11-14 17:03

reporter   ~0095868

seems like the patch make it working properly under win32 and gtk2

Juha Manninen

2016-12-11 19:34

developer   ~0096706

Michl, you know the issue best. What code should be applied?

Michl

2016-12-11 21:26

developer   ~0096708

Till now, no code should be applied, because afaik a HandleNeeded should be implemented. I'll look at it.

Anton Kavalenka

2019-04-24 13:53

reporter   ~0115771

The attached example behaves even strangely under MacOS/X Cocoa. So it is LCL-wide problem,
See the screenshot

layout-mac.png (74,884 bytes)
layout-mac.png (74,884 bytes)

Anton Kavalenka

2019-04-26 07:25

reporter   ~0115818

Please, can somebody keen in Cocoa WS have a look?
W32 and GTK2 working fine
GTK3 and Cocoa is broken.

Anton Kavalenka

2019-04-26 07:31

reporter   ~0115819

In GTK3 hack with Items.RecreateHandle helps

Issue History

Date Modified Username Field Change
2013-12-10 14:57 Anton Kavalenka New Issue
2013-12-10 14:57 Anton Kavalenka File Added: laztest85.zip
2013-12-10 14:57 Anton Kavalenka File Added: p1.PNG
2013-12-10 14:57 Anton Kavalenka File Added: p2.PNG
2013-12-10 14:57 Anton Kavalenka File Added: p3.PNG
2013-12-10 20:40 Juha Manninen Note Added: 0071858
2013-12-10 22:37 Anton Kavalenka Note Added: 0071863
2013-12-12 04:47 Reiner Note Added: 0071871
2013-12-12 08:35 Anton Kavalenka Note Added: 0071872
2013-12-16 14:23 Anton Kavalenka Note Added: 0071923
2013-12-16 15:02 Anton Kavalenka Note Edited: 0071923 View Revisions
2016-11-09 15:18 Juha Manninen Relationship added related to 0030867
2016-11-13 22:22 Michl Note Added: 0095849
2016-11-13 22:22 Michl File Added: popupmenu.inc.patch
2016-11-13 22:23 Michl File Added: SimpleTest.zip
2016-11-13 23:48 Juha Manninen Relationship added related to 0015614
2016-11-14 17:03 Anton Kavalenka Note Added: 0095868
2016-12-11 19:30 Juha Manninen Assigned To => Michl
2016-12-11 19:30 Juha Manninen Status new => assigned
2016-12-11 19:34 Juha Manninen Note Added: 0096706
2016-12-11 21:26 Michl Note Added: 0096708
2019-04-24 13:53 Anton Kavalenka File Added: layout-mac.png
2019-04-24 13:53 Anton Kavalenka Note Added: 0115771
2019-04-26 07:25 Anton Kavalenka Note Added: 0115818
2019-04-26 07:31 Anton Kavalenka Note Added: 0115819