gtk2: make TPopupMenu.Popup synchronous

git-svn-id: trunk@29831 -
This commit is contained in:
paul 2011-03-14 02:54:06 +00:00
parent eaa88d5d11
commit 2d658d768b

View File

@ -82,6 +82,9 @@ implementation
{$I gtk2defines.inc}
var
MenuWidget: PGtkWidget = nil;
function Gtk2MenuItemButtonPress(widget: PGtkWidget; event: PGdkEventButton;
user_data: gpointer): gboolean; cdecl;
var
@ -613,6 +616,8 @@ end;
procedure gtkWSPopupMenuDeactivate(widget: PGtkWidget; data: gPointer); cdecl;
begin
if widget = MenuWidget then
MenuWidget := nil;
if data <> nil then
g_idle_add(@gtkWSPopupDelayedClose, Pointer(PWidgetInfo(data)^.LCLObject));
end;
@ -645,7 +650,6 @@ class procedure TGtk2WSPopupMenu.Popup(const APopupMenu: TPopupMenu; const X,
var
APoint: TPoint;
AProc: Pointer;
MenuWidget: PGtkWidget;
WidgetInfo: PWidgetInfo;
begin
ReleaseMouseCapture;
@ -659,9 +663,22 @@ begin
WidgetInfo^.DataOwner := False;
// MenuWidget can be either GtkMenu or GtkMenuItem submenu
if GTK_IS_MENU_ITEM(MenuWidget) then
MenuWidget := gtk_menu_item_get_submenu(PGtkMenuItem(MenuWidget));
MenuWidget := gtk_menu_item_get_submenu(PGtkMenuItem(MenuWidget));
gtk_menu_popup(PGtkMenu(MenuWidget), nil, nil, TGtkMenuPositionFunc(AProc),
WidgetInfo, 0, gtk_get_current_event_time());
repeat
try
WidgetSet.AppProcessMessages; // process all events
except
if Application.CaptureExceptions then
Application.HandleException(APopupMenu)
else
raise;
end;
if Application.Terminated or not Assigned(MenuWidget) then
break;
Application.Idle(true);
until False;
end;
end.