mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-06 17:38:15 +02:00
gtk, gtk2: handle situations when popup menu has been inserted into main menu submenu (remaining part of issue #0014144)
git-svn-id: trunk@20862 -
This commit is contained in:
parent
3a6fe8e7aa
commit
405bc268f5
@ -116,28 +116,34 @@ begin
|
|||||||
if ParentMenuWidget=nil then
|
if ParentMenuWidget=nil then
|
||||||
RaiseGDBException('TGtkWidgetSet.AttachMenu ParentMenuWidget=nil');
|
RaiseGDBException('TGtkWidgetSet.AttachMenu ParentMenuWidget=nil');
|
||||||
|
|
||||||
if GtkWidgetIsA(ParentMenuWidget,GTK_TYPE_MENU_BAR) then begin
|
if GTK_IS_MENU_BAR(ParentMenuWidget) then
|
||||||
|
begin
|
||||||
// mainmenu (= a menu bar)
|
// mainmenu (= a menu bar)
|
||||||
ContainerMenu:=ParentMenuWidget;
|
ContainerMenu := ParentMenuWidget;
|
||||||
gtk_menu_bar_insert(ParentMenuWidget,MenuItem, AMenuItem.MenuVisibleIndex);
|
gtk_menu_bar_insert(ParentMenuWidget, MenuItem, AMenuItem.MenuVisibleIndex);
|
||||||
end
|
end
|
||||||
else begin
|
else
|
||||||
// menu item
|
begin
|
||||||
|
// if it is a menu
|
||||||
|
if GTK_IS_MENU(ParentMenuWidget) then
|
||||||
|
ContainerMenu := ParentMenuWidget
|
||||||
|
else // menu item
|
||||||
|
ContainerMenu := PGtkWidget(gtk_object_get_data(PGtkObject(ParentMenuWidget),
|
||||||
|
'ContainerMenu')); // find the menu container
|
||||||
|
|
||||||
// find the menu container
|
if ContainerMenu = nil then
|
||||||
ContainerMenu := PGtkWidget(gtk_object_get_data(
|
begin
|
||||||
PGtkObject(ParentMenuWidget),
|
if (GetParentMenu is TPopupMenu) and (Parent.Parent=nil) then
|
||||||
'ContainerMenu'));
|
begin
|
||||||
if ContainerMenu = nil then begin
|
ContainerMenu := PGtkWidget(GetParentMenu.Handle);
|
||||||
if (GetParentMenu is TPopupMenu) and (Parent.Parent=nil) then begin
|
|
||||||
ContainerMenu:=PGtkWidget(GetParentMenu.Handle);
|
|
||||||
gtk_object_set_data(PGtkObject(ContainerMenu), 'ContainerMenu',
|
gtk_object_set_data(PGtkObject(ContainerMenu), 'ContainerMenu',
|
||||||
ContainerMenu);
|
ContainerMenu);
|
||||||
end else begin
|
end else
|
||||||
|
begin
|
||||||
ContainerMenu := gtk_menu_new;
|
ContainerMenu := gtk_menu_new;
|
||||||
gtk_object_set_data(PGtkObject(ParentMenuWidget), 'ContainerMenu',
|
gtk_object_set_data(PGtkObject(ParentMenuWidget), 'ContainerMenu',
|
||||||
ContainerMenu);
|
ContainerMenu);
|
||||||
gtk_menu_item_set_submenu(PGTKMenuItem(ParentMenuWidget),ContainerMenu);
|
gtk_menu_item_set_submenu(PGTKMenuItem(ParentMenuWidget), ContainerMenu);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
gtk_menu_insert(ContainerMenu, MenuItem, AMenuItem.MenuVisibleIndex);
|
gtk_menu_insert(ContainerMenu, MenuItem, AMenuItem.MenuVisibleIndex);
|
||||||
@ -410,6 +416,7 @@ class procedure TGtkWSPopupMenu.Popup(const APopupMenu: TPopupMenu;
|
|||||||
var
|
var
|
||||||
APoint: TPoint;
|
APoint: TPoint;
|
||||||
AProc: Pointer;
|
AProc: Pointer;
|
||||||
|
MenuWidget: PGtkWidget;
|
||||||
begin
|
begin
|
||||||
ReleaseMouseCapture;
|
ReleaseMouseCapture;
|
||||||
APoint.X := X;
|
APoint.X := X;
|
||||||
@ -419,18 +426,19 @@ begin
|
|||||||
AProc := nil
|
AProc := nil
|
||||||
else
|
else
|
||||||
AProc := @GtkWS_Popup;
|
AProc := @GtkWS_Popup;
|
||||||
gtk_menu_popup(PGtkMenu(APopupMenu.Handle),
|
|
||||||
nil,
|
MenuWidget := PGtkWidget(APopupMenu.Handle);
|
||||||
nil,
|
// MenuWidget can be either GtkMenu or GtkMenuItem submenu
|
||||||
TGtkMenuPositionFunc(AProc),
|
if GTK_IS_MENU_ITEM(MenuWidget) then
|
||||||
@APoint,
|
MenuWidget := gtk_menu_item_get_submenu(PGtkMenuItem(MenuWidget));
|
||||||
0,
|
gtk_menu_popup(PGtkMenu(MenuWidget), nil, nil, TGtkMenuPositionFunc(AProc),
|
||||||
{$ifdef gtk1}
|
@APoint, 0,
|
||||||
gdk_event_get_time(gtk_get_current_event)
|
{$ifdef gtk1}
|
||||||
{$else}
|
gdk_event_get_time(gtk_get_current_event)
|
||||||
gtk_get_current_event_time()
|
{$else}
|
||||||
{$endif}
|
gtk_get_current_event_time()
|
||||||
);
|
{$endif}
|
||||||
|
);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -175,28 +175,34 @@ begin
|
|||||||
if ParentMenuWidget=nil then
|
if ParentMenuWidget=nil then
|
||||||
RaiseGDBException('TGtkWidgetSet.AttachMenu ParentMenuWidget=nil');
|
RaiseGDBException('TGtkWidgetSet.AttachMenu ParentMenuWidget=nil');
|
||||||
|
|
||||||
if GtkWidgetIsA(ParentMenuWidget,GTK_TYPE_MENU_BAR) then begin
|
if GTK_IS_MENU_BAR(ParentMenuWidget) then
|
||||||
|
begin
|
||||||
// mainmenu (= a menu bar)
|
// mainmenu (= a menu bar)
|
||||||
ContainerMenu:=ParentMenuWidget;
|
ContainerMenu := ParentMenuWidget;
|
||||||
gtk_menu_bar_insert(ParentMenuWidget,MenuItem, AMenuItem.MenuVisibleIndex);
|
gtk_menu_bar_insert(ParentMenuWidget, MenuItem, AMenuItem.MenuVisibleIndex);
|
||||||
end
|
end
|
||||||
else begin
|
else
|
||||||
// menu item
|
begin
|
||||||
|
// if it is a menu
|
||||||
|
if GTK_IS_MENU(ParentMenuWidget) then
|
||||||
|
ContainerMenu := ParentMenuWidget
|
||||||
|
else // menu item
|
||||||
|
ContainerMenu := PGtkWidget(gtk_object_get_data(PGtkObject(ParentMenuWidget),
|
||||||
|
'ContainerMenu')); // find the menu container
|
||||||
|
|
||||||
// find the menu container
|
if ContainerMenu = nil then
|
||||||
ContainerMenu := PGtkWidget(gtk_object_get_data(
|
begin
|
||||||
PGtkObject(ParentMenuWidget),
|
if (GetParentMenu is TPopupMenu) and (Parent.Parent=nil) then
|
||||||
'ContainerMenu'));
|
begin
|
||||||
if ContainerMenu = nil then begin
|
ContainerMenu := PGtkWidget(GetParentMenu.Handle);
|
||||||
if (GetParentMenu is TPopupMenu) and (Parent.Parent=nil) then begin
|
|
||||||
ContainerMenu:=PGtkWidget(GetParentMenu.Handle);
|
|
||||||
gtk_object_set_data(PGtkObject(ContainerMenu), 'ContainerMenu',
|
gtk_object_set_data(PGtkObject(ContainerMenu), 'ContainerMenu',
|
||||||
ContainerMenu);
|
ContainerMenu);
|
||||||
end else begin
|
end else
|
||||||
|
begin
|
||||||
ContainerMenu := gtk_menu_new;
|
ContainerMenu := gtk_menu_new;
|
||||||
gtk_object_set_data(PGtkObject(ParentMenuWidget), 'ContainerMenu',
|
gtk_object_set_data(PGtkObject(ParentMenuWidget), 'ContainerMenu',
|
||||||
ContainerMenu);
|
ContainerMenu);
|
||||||
gtk_menu_item_set_submenu(PGTKMenuItem(ParentMenuWidget),ContainerMenu);
|
gtk_menu_item_set_submenu(PGTKMenuItem(ParentMenuWidget), ContainerMenu);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
gtk_menu_insert(ContainerMenu, MenuItem, AMenuItem.MenuVisibleIndex);
|
gtk_menu_insert(ContainerMenu, MenuItem, AMenuItem.MenuVisibleIndex);
|
||||||
@ -205,7 +211,7 @@ begin
|
|||||||
SetContainerMenuToggleSize;
|
SetContainerMenuToggleSize;
|
||||||
|
|
||||||
if GtkWidgetIsA(MenuItem, GTK_TYPE_RADIO_MENU_ITEM) then
|
if GtkWidgetIsA(MenuItem, GTK_TYPE_RADIO_MENU_ITEM) then
|
||||||
TGtkWidgetSet(WidgetSet).RegroupMenuItem(HMENU(PtrUInt(MenuItem)),GroupIndex);
|
TGtkWidgetSet(WidgetSet).RegroupMenuItem(HMENU(PtrUInt(MenuItem)), GroupIndex);
|
||||||
end;
|
end;
|
||||||
//DebugLn('TGtkWidgetSet.AttachMenu END ',AMenuItem.Name,':',AMenuItem.ClassName);
|
//DebugLn('TGtkWidgetSet.AttachMenu END ',AMenuItem.Name,':',AMenuItem.ClassName);
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user