From d6a1733667e7aa0b9d7c5e03d606f13fddf42f84 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Wed, 1 Jun 2011 09:07:50 -0400 Subject: Move EPopupMenu to /widgets/table. ETableHeaderItem is the last user of EPopupMenu. Move it to /widgets/table to discourage further use and strip out unused features. The functionality it provides has long since been superseded by GtkUIManager and GtkAction. --- widgets/misc/Makefile.am | 2 - widgets/misc/e-popup-menu.c | 147 ------------------------------------ widgets/misc/e-popup-menu.h | 72 ------------------ widgets/table/Makefile.am | 2 + widgets/table/e-popup-menu.c | 109 ++++++++++++++++++++++++++ widgets/table/e-popup-menu.h | 55 ++++++++++++++ widgets/table/e-table-header-item.c | 2 +- 7 files changed, 167 insertions(+), 222 deletions(-) delete mode 100644 widgets/misc/e-popup-menu.c delete mode 100644 widgets/misc/e-popup-menu.h create mode 100644 widgets/table/e-popup-menu.c create mode 100644 widgets/table/e-popup-menu.h (limited to 'widgets') diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am index 4076249f19..05a5967b7f 100644 --- a/widgets/misc/Makefile.am +++ b/widgets/misc/Makefile.am @@ -46,7 +46,6 @@ widgetsinclude_HEADERS = \ e-paned.h \ e-picture-gallery.h \ e-popup-action.h \ - e-popup-menu.h \ e-port-entry.h \ e-preferences-window.h \ e-preview-pane.h \ @@ -126,7 +125,6 @@ libemiscwidgets_la_SOURCES = \ e-paned.c \ e-picture-gallery.c \ e-popup-action.c \ - e-popup-menu.c \ e-port-entry.c \ e-preferences-window.c \ e-preview-pane.c \ diff --git a/widgets/misc/e-popup-menu.c b/widgets/misc/e-popup-menu.c deleted file mode 100644 index d166ac01b4..0000000000 --- a/widgets/misc/e-popup-menu.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Miguel de Icaza - * Jody Goldberg (jgoldberg@home.com) - * Jeffrey Stedfast - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include -#include - -#include "e-popup-menu.h" - -/* - * Creates an item with an optional icon - */ -static void -make_item (GtkMenu *menu, GtkMenuItem *item, const gchar *name, GtkWidget *pixmap) -{ - GtkWidget *label; - - if (*name == '\0') - return; - - /* - * Ugh. This needs to go into Gtk+ - */ - label = gtk_label_new_with_mnemonic (name); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_widget_show (label); - - gtk_container_add (GTK_CONTAINER (item), label); - - if (pixmap && GTK_IS_IMAGE_MENU_ITEM (item)) { - gtk_widget_show (pixmap); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), pixmap); - } -} - -GtkMenu * -e_popup_menu_create (EPopupMenu *menu_list, - guint32 disable_mask, - guint32 hide_mask, - gpointer default_closure) -{ - return e_popup_menu_create_with_domain (menu_list, - disable_mask, - hide_mask, - default_closure, - NULL); -} - -GtkMenu * -e_popup_menu_create_with_domain (EPopupMenu *menu_list, - guint32 disable_mask, - guint32 hide_mask, - gpointer default_closure, - const gchar *domain) -{ - GtkMenu *menu = GTK_MENU (gtk_menu_new ()); - GSList *group = NULL; - gboolean last_item_separator = TRUE; - gint last_non_separator = -1; - gint i; - - for (i = 0; menu_list[i].name; i++) { - if (strcmp ("", menu_list[i].name) && !(menu_list [i].disable_mask & hide_mask)) { - last_non_separator = i; - } - } - - for (i = 0; i <= last_non_separator; i++) { - gboolean separator; - - separator = !strcmp ("", menu_list[i].name); - - if ((!(separator && last_item_separator)) && !(menu_list[i].disable_mask & hide_mask)) { - GtkWidget *item = NULL; - - if (!separator) { - if (menu_list[i].is_toggle) - item = gtk_check_menu_item_new (); - else if (menu_list[i].is_radio) - item = gtk_radio_menu_item_new (group); - else - item = menu_list[i].pixmap_widget ? gtk_image_menu_item_new () : gtk_menu_item_new (); - if (menu_list[i].is_toggle || menu_list[i].is_radio) - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), menu_list[i].is_active); - if (menu_list[i].is_radio) - group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item)); - - make_item (menu, GTK_MENU_ITEM (item), dgettext (domain, menu_list[i].name), menu_list[i].pixmap_widget); - } else { - item = gtk_menu_item_new (); - } - - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - if (!menu_list[i].submenu) { - if (menu_list[i].fn) - g_signal_connect (item, "activate", - G_CALLBACK (menu_list[i].fn), - menu_list[i].use_custom_closure ? menu_list[i].closure : default_closure); - } else { - /* submenu */ - GtkMenu *submenu; - - submenu = e_popup_menu_create (menu_list[i].submenu, disable_mask, hide_mask, - default_closure); - - gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), GTK_WIDGET (submenu)); - } - - if (menu_list[i].disable_mask & disable_mask) - gtk_widget_set_sensitive (item, FALSE); - - gtk_widget_show (item); - - last_item_separator = separator; - } - } - - return menu; -} diff --git a/widgets/misc/e-popup-menu.h b/widgets/misc/e-popup-menu.h deleted file mode 100644 index 24a8fa6022..0000000000 --- a/widgets/misc/e-popup-menu.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Miguel de Icaza - * Jody Goldberg (jgoldberg@home.com) - * Jeffrey Stedfast - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_POPUP_MENU_H -#define E_POPUP_MENU_H - -#include - -G_BEGIN_DECLS - -#define E_POPUP_SEPARATOR { (gchar *) "", NULL, (NULL), NULL, 0 } -#define E_POPUP_TERMINATOR { NULL, NULL, (NULL), NULL, 0 } - -#define E_POPUP_ITEM(name,fn,disable_mask) \ - { (gchar *) (name), NULL, (fn), NULL, \ - (disable_mask), NULL, NULL, 0, 0, 0, 0 } - -typedef struct _EPopupMenu EPopupMenu; - -struct _EPopupMenu { - gchar *name; - gchar *pixname; - GCallback fn; - - EPopupMenu *submenu; - guint32 disable_mask; - - /* Added post 0.19 */ - GtkWidget *pixmap_widget; - gpointer closure; - - guint is_toggle : 1; - guint is_radio : 1; - guint is_active : 1; - - guint use_custom_closure : 1; -}; - -GtkMenu * e_popup_menu_create (EPopupMenu *menu_list, - guint32 disable_mask, - guint32 hide_mask, - gpointer default_closure); -GtkMenu * e_popup_menu_create_with_domain (EPopupMenu *menu_list, - guint32 disable_mask, - guint32 hide_mask, - gpointer default_closure, - const gchar *domain); - -G_END_DECLS - -#endif /* E_POPUP_MENU_H */ diff --git a/widgets/table/Makefile.am b/widgets/table/Makefile.am index 2764c96c81..0ae1e2b7e9 100644 --- a/widgets/table/Makefile.am +++ b/widgets/table/Makefile.am @@ -29,6 +29,7 @@ libetable_la_SOURCES = \ e-cell-tree.c \ e-cell-vbox.c \ e-cell-hbox.c \ + e-popup-menu.c \ e-table-click-to-add.c \ e-table-col.c \ e-table-column-specification.c \ @@ -104,6 +105,7 @@ libetableinclude_HEADERS = \ e-cell-tree.h \ e-cell-vbox.h \ e-cell-hbox.h \ + e-popup-menu.h \ e-table-click-to-add.h \ e-table-col-dnd.h \ e-table-col.h \ diff --git a/widgets/table/e-popup-menu.c b/widgets/table/e-popup-menu.c new file mode 100644 index 0000000000..07589b1589 --- /dev/null +++ b/widgets/table/e-popup-menu.c @@ -0,0 +1,109 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + * + * Authors: + * Miguel de Icaza + * Jody Goldberg (jgoldberg@home.com) + * Jeffrey Stedfast + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include +#include + +#include "e-popup-menu.h" + +/* + * Creates an item with an optional icon + */ +static void +make_item (GtkMenu *menu, GtkMenuItem *item, const gchar *name) +{ + GtkWidget *label; + + if (*name == '\0') + return; + + /* + * Ugh. This needs to go into Gtk+ + */ + label = gtk_label_new_with_mnemonic (name); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_widget_show (label); + + gtk_container_add (GTK_CONTAINER (item), label); +} + +GtkMenu * +e_popup_menu_create_with_domain (EPopupMenu *menu_list, + guint32 disable_mask, + guint32 hide_mask, + gpointer default_closure, + const gchar *domain) +{ + GtkMenu *menu = GTK_MENU (gtk_menu_new ()); + gboolean last_item_separator = TRUE; + gint last_non_separator = -1; + gint i; + + for (i = 0; menu_list[i].name; i++) { + if (strcmp ("", menu_list[i].name) && !(menu_list [i].disable_mask & hide_mask)) { + last_non_separator = i; + } + } + + for (i = 0; i <= last_non_separator; i++) { + gboolean separator; + + separator = !strcmp ("", menu_list[i].name); + + if ((!(separator && last_item_separator)) && !(menu_list[i].disable_mask & hide_mask)) { + GtkWidget *item = NULL; + + if (!separator) { + item = gtk_menu_item_new (); + + make_item (menu, GTK_MENU_ITEM (item), dgettext (domain, menu_list[i].name)); + } else { + item = gtk_menu_item_new (); + } + + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + + if (menu_list[i].fn) + g_signal_connect (item, "activate", + G_CALLBACK (menu_list[i].fn), + default_closure); + + if (menu_list[i].disable_mask & disable_mask) + gtk_widget_set_sensitive (item, FALSE); + + gtk_widget_show (item); + + last_item_separator = separator; + } + } + + return menu; +} diff --git a/widgets/table/e-popup-menu.h b/widgets/table/e-popup-menu.h new file mode 100644 index 0000000000..9fd3616eb2 --- /dev/null +++ b/widgets/table/e-popup-menu.h @@ -0,0 +1,55 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + * + * Authors: + * Miguel de Icaza + * Jody Goldberg (jgoldberg@home.com) + * Jeffrey Stedfast + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef E_POPUP_MENU_H +#define E_POPUP_MENU_H + +#include + +G_BEGIN_DECLS + +#define E_POPUP_SEPARATOR { (gchar *) "", NULL, (NULL), 0 } +#define E_POPUP_TERMINATOR { NULL, NULL, (NULL), 0 } + +#define E_POPUP_ITEM(name,fn,disable_mask) \ + { (gchar *) (name), NULL, (fn), (disable_mask) } + +typedef struct _EPopupMenu EPopupMenu; + +struct _EPopupMenu { + gchar *name; + gchar *pixname; + GCallback fn; + guint32 disable_mask; +}; + +GtkMenu * e_popup_menu_create_with_domain (EPopupMenu *menu_list, + guint32 disable_mask, + guint32 hide_mask, + gpointer default_closure, + const gchar *domain); + +G_END_DECLS + +#endif /* E_POPUP_MENU_H */ diff --git a/widgets/table/e-table-header-item.c b/widgets/table/e-table-header-item.c index 9215e7b2fb..d8a7d0d7a0 100644 --- a/widgets/table/e-table-header-item.c +++ b/widgets/table/e-table-header-item.c @@ -36,8 +36,8 @@ #include "e-util/e-util.h" #include "e-util/e-xml-utils.h" #include "misc/e-canvas.h" -#include "misc/e-popup-menu.h" +#include "e-popup-menu.h" #include "e-table.h" #include "e-table-col-dnd.h" #include "e-table-config.h" -- cgit