mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-20 01:08:22 +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,24 +116,30 @@ 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
|
|
||||||
if (GetParentMenu is TPopupMenu) and (Parent.Parent=nil) then begin
|
|
||||||
ContainerMenu := PGtkWidget(GetParentMenu.Handle);
|
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);
|
||||||
@ -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,12 +426,13 @@ 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),
|
||||||
|
@APoint, 0,
|
||||||
{$ifdef gtk1}
|
{$ifdef gtk1}
|
||||||
gdk_event_get_time(gtk_get_current_event)
|
gdk_event_get_time(gtk_get_current_event)
|
||||||
{$else}
|
{$else}
|
||||||
|
@ -175,24 +175,30 @@ 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
|
|
||||||
if (GetParentMenu is TPopupMenu) and (Parent.Parent=nil) then begin
|
|
||||||
ContainerMenu := PGtkWidget(GetParentMenu.Handle);
|
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user