Use gtk_menu_attach_to_widget()

master
Yevgen Muntyan 2007-01-07 23:10:35 -06:00
parent d95671b8f2
commit 89db53d70e
6 changed files with 17 additions and 58 deletions

View File

@ -1,7 +1,7 @@
/* /*
* moolinklabel.c * moolinklabel.c
* *
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu> * Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -200,8 +200,7 @@ moo_link_label_button_press (GtkWidget *widget,
return FALSE; return FALSE;
menu = gtk_menu_new (); menu = gtk_menu_new ();
MOO_OBJECT_REF_SINK (menu); gtk_menu_attach_to_widget (GTK_MENU (menu), widget, NULL);
g_object_set_data_full (G_OBJECT (widget), "moo-menu", menu, g_object_unref);
item = gtk_image_menu_item_new_with_label ("Copy Link"); item = gtk_image_menu_item_new_with_label ("Copy Link");
image = gtk_image_new_from_stock (GTK_STOCK_COPY, GTK_ICON_SIZE_MENU); image = gtk_image_new_from_stock (GTK_STOCK_COPY, GTK_ICON_SIZE_MENU);

View File

@ -1065,20 +1065,6 @@ doc_move (MooFileSelector *filesel,
} }
static gboolean
really_destroy_menu (GtkWidget *menu)
{
g_object_unref (menu);
return FALSE;
}
static void
destroy_menu (GtkWidget *menu)
{
g_idle_add ((GSourceFunc) really_destroy_menu, menu);
}
typedef enum { typedef enum {
DROP_DOC_ASK = 1, DROP_DOC_ASK = 1,
DROP_DOC_SAVE_AS, DROP_DOC_SAVE_AS,
@ -1213,8 +1199,7 @@ create_drop_doc_menu (MooFileSelector *filesel,
GSList *items = NULL; GSList *items = NULL;
menu = gtk_menu_new (); menu = gtk_menu_new ();
MOO_OBJECT_REF_SINK (menu); gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (filesel), NULL);
g_signal_connect (menu, "deactivate", G_CALLBACK (destroy_menu), NULL);
g_signal_connect (menu, "key-press-event", G_CALLBACK (menu_key_event), NULL); g_signal_connect (menu, "key-press-event", G_CALLBACK (menu_key_event), NULL);
g_signal_connect (menu, "key-release-event", G_CALLBACK (menu_key_event), NULL); g_signal_connect (menu, "key-release-event", G_CALLBACK (menu_key_event), NULL);

View File

@ -1,7 +1,7 @@
/* /*
* moofileview.c * moofileview.c
* *
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu> * Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -3157,19 +3157,6 @@ file_view_properties_dialog (MooFileView *fileview)
/* Popup menu /* Popup menu
*/ */
static gboolean
really_destroy_menu (GtkWidget *menu)
{
g_object_unref (menu);
return FALSE;
}
static void
destroy_menu (GtkWidget *menu)
{
g_idle_add ((GSourceFunc) really_destroy_menu, menu);
}
/* TODO */ /* TODO */
static void static void
menu_position_func (G_GNUC_UNUSED GtkMenu *menu, menu_position_func (G_GNUC_UNUSED GtkMenu *menu,
@ -3218,8 +3205,7 @@ do_popup (MooFileView *fileview,
MOO_UI_MENU, "MooFileView/Menu", MOO_UI_MENU, "MooFileView/Menu",
fileview->priv->actions, fileview->priv->actions,
NULL); NULL);
gtk_object_sink (g_object_ref (menu)); gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (fileview), NULL);
g_signal_connect (menu, "deactivate", G_CALLBACK (destroy_menu), NULL);
_moo_file_view_tools_check (fileview); _moo_file_view_tools_check (fileview);
g_signal_emit (fileview, signals[POPULATE_POPUP], 0, files, menu); g_signal_emit (fileview, signals[POPULATE_POPUP], 0, files, menu);
@ -5681,8 +5667,7 @@ moo_file_view_drop_uris (MooFileView *fileview,
char *dir_copy = g_strdup (destdir); char *dir_copy = g_strdup (destdir);
menu = gtk_menu_new (); menu = gtk_menu_new ();
gtk_object_sink (g_object_ref (menu)); gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (fileview), NULL);
g_signal_connect (menu, "deactivate", G_CALLBACK (destroy_menu), NULL);
g_object_set_data_full (G_OBJECT (menu), "moo-file-view-drop-files", g_object_set_data_full (G_OBJECT (menu), "moo-file-view-drop-files",
filenames, (GDestroyNotify) free_string_list); filenames, (GDestroyNotify) free_string_list);
g_object_set_data_full (G_OBJECT (menu), "moo-file-view-drop-dir", g_object_set_data_full (G_OBJECT (menu), "moo-file-view-drop-dir",

View File

@ -1,7 +1,7 @@
/* /*
* mooterm-private.h * mooterm-private.h
* *
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu> * Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -161,8 +161,6 @@ struct _MooTermPrivate {
gulong track_release_id; gulong track_release_id;
gulong track_scroll_id; gulong track_scroll_id;
GtkWidget *menu;
GtkIMContext *im; GtkIMContext *im;
gboolean im_preedit_active; gboolean im_preedit_active;
GdkModifierType modifiers; GdkModifierType modifiers;

View File

@ -579,10 +579,6 @@ moo_term_unrealize (GtkWidget *widget)
g_source_remove (term->priv->update_timer); g_source_remove (term->priv->update_timer);
term->priv->update_timer = 0; term->priv->update_timer = 0;
if (term->priv->menu)
g_object_unref (term->priv->menu);
term->priv->menu = NULL;
for (i = 0; i < POINTERS_NUM; ++i) for (i = 0; i < POINTERS_NUM; ++i)
{ {
if (term->priv->pointer[i]) if (term->priv->pointer[i])
@ -1844,37 +1840,35 @@ void
_moo_term_do_popup_menu (MooTerm *term, _moo_term_do_popup_menu (MooTerm *term,
GdkEventButton *event) GdkEventButton *event)
{ {
GtkWidget *menu;
GtkWidget *item; GtkWidget *item;
g_return_if_fail (MOO_IS_TERM (term)); g_return_if_fail (MOO_IS_TERM (term));
if (term->priv->menu) menu = gtk_menu_new ();
g_object_unref (term->priv->menu); gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (term), NULL);
term->priv->menu = gtk_menu_new ();
MOO_OBJECT_REF_SINK (term->priv->menu);
item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL); item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
gtk_widget_set_sensitive (item, moo_term_get_selection_bounds (term, NULL, NULL)); gtk_widget_set_sensitive (item, moo_term_get_selection_bounds (term, NULL, NULL));
gtk_widget_show (item); gtk_widget_show (item);
g_signal_connect_swapped (item, "activate", g_signal_connect_swapped (item, "activate",
G_CALLBACK (menu_copy), term); G_CALLBACK (menu_copy), term);
gtk_menu_shell_append (GTK_MENU_SHELL (term->priv->menu), item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
item = gtk_image_menu_item_new_from_stock (GTK_STOCK_PASTE, NULL); item = gtk_image_menu_item_new_from_stock (GTK_STOCK_PASTE, NULL);
gtk_widget_show (item); gtk_widget_show (item);
g_signal_connect_swapped (item, "activate", g_signal_connect_swapped (item, "activate",
G_CALLBACK (menu_paste), term); G_CALLBACK (menu_paste), term);
gtk_menu_shell_append (GTK_MENU_SHELL (term->priv->menu), item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_emit (term, signals[POPULATE_POPUP], 0, term->priv->menu); g_signal_emit (term, signals[POPULATE_POPUP], 0, menu);
if (event) if (event)
gtk_menu_popup (GTK_MENU (term->priv->menu), gtk_menu_popup (GTK_MENU (menu),
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
event->button, event->time); event->button, event->time);
else else
gtk_menu_popup (GTK_MENU (term->priv->menu), NULL, NULL, gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
(GtkMenuPositionFunc) menu_position_func, (GtkMenuPositionFunc) menu_position_func,
term, 0, gtk_get_current_event_time ()); term, 0, gtk_get_current_event_time ());
} }

View File

@ -3120,13 +3120,13 @@ static gboolean moo_notebook_do_popup (MooNotebook *nb,
menu = nb->priv->popup_func (nb, page->child, nb->priv->popup_user_data); menu = nb->priv->popup_func (nb, page->child, nb->priv->popup_user_data);
g_return_val_if_fail (GTK_IS_MENU (menu), FALSE); g_return_val_if_fail (GTK_IS_MENU (menu), FALSE);
MOO_OBJECT_REF_SINK (menu); gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (nb), NULL);
g_signal_emit (nb, signals[POPULATE_POPUP], 0, page->child, menu, &dont); g_signal_emit (nb, signals[POPULATE_POPUP], 0, page->child, menu, &dont);
if (dont) if (dont)
{ {
g_object_unref (menu); gtk_menu_detach (GTK_MENU (menu));
return FALSE; return FALSE;
} }
@ -3138,8 +3138,6 @@ static gboolean moo_notebook_do_popup (MooNotebook *nb,
popup_position_func, &data, popup_position_func, &data,
event ? event->button : 0, event ? event->button : 0,
event ? event->time : gtk_get_current_event_time ()); event ? event->time : gtk_get_current_event_time ());
g_object_unref (menu);
return TRUE; return TRUE;
} }