aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorMiguel de Icaza <miguel@src.gnome.org>2000-04-26 23:03:27 +0800
committerMiguel de Icaza <miguel@src.gnome.org>2000-04-26 23:03:27 +0800
commit85eafe5cb2cf0d6c5aeff0cd97840be7e3911b46 (patch)
treeb160609d1d06969050c167b561dec9a1431c1453 /widgets
parent19de6b40b6a2a399c317728d304c0b005c7ceb0b (diff)
downloadgsoc2013-evolution-85eafe5cb2cf0d6c5aeff0cd97840be7e3911b46.tar
gsoc2013-evolution-85eafe5cb2cf0d6c5aeff0cd97840be7e3911b46.tar.gz
gsoc2013-evolution-85eafe5cb2cf0d6c5aeff0cd97840be7e3911b46.tar.bz2
gsoc2013-evolution-85eafe5cb2cf0d6c5aeff0cd97840be7e3911b46.tar.lz
gsoc2013-evolution-85eafe5cb2cf0d6c5aeff0cd97840be7e3911b46.tar.xz
gsoc2013-evolution-85eafe5cb2cf0d6c5aeff0cd97840be7e3911b46.tar.zst
gsoc2013-evolution-85eafe5cb2cf0d6c5aeff0cd97840be7e3911b46.zip
add e-popup-menu.[ch]
svn path=/trunk/; revision=2635
Diffstat (limited to 'widgets')
-rw-r--r--widgets/misc/e-popup-menu.c99
-rw-r--r--widgets/misc/e-popup-menu.h16
2 files changed, 115 insertions, 0 deletions
diff --git a/widgets/misc/e-popup-menu.c b/widgets/misc/e-popup-menu.c
new file mode 100644
index 0000000000..192d234371
--- /dev/null
+++ b/widgets/misc/e-popup-menu.c
@@ -0,0 +1,99 @@
+/*
+ * e-popup-menu.c: popup menu display
+ *
+ * Author:
+ * Miguel de Icaza (miguel@kernel.org)
+ * Jody Goldberg (jgoldberg@home.com)
+ *
+ * (C) 2000 Helix Code, Inc.
+ */
+#include <config.h>
+#include <gnome.h>
+#include "e-popup-menu.h"
+#include "e-gui-utils.h"
+
+/*
+ * Creates an item with an optional icon
+ */
+static GtkWidget *
+make_item (GtkMenu *menu, const char *name, const char *pixname)
+{
+ GtkWidget *label, *item;
+ guint label_accel;
+
+ if (*name == '\0')
+ return gtk_menu_item_new ();
+
+ /*
+ * Ugh. This needs to go into Gtk+
+ */
+ label = gtk_accel_label_new ("");
+ label_accel = gtk_label_parse_uline (GTK_LABEL (label), name);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_widget_show (label);
+
+ item = gtk_pixmap_menu_item_new ();
+ gtk_container_add (GTK_CONTAINER (item), label);
+
+ if (label_accel != GDK_VoidSymbol){
+ gtk_widget_add_accelerator (
+ item,
+ "activate_item",
+ gtk_menu_ensure_uline_accel_group (GTK_MENU (menu)),
+ label_accel, 0,
+ GTK_ACCEL_LOCKED);
+ }
+
+ if (pixname){
+ GtkWidget *pixmap = gnome_stock_pixmap_widget (item, pixname);
+
+ gtk_widget_show (pixmap);
+ gtk_pixmap_menu_item_set_pixmap (
+ GTK_PIXMAP_MENU_ITEM (item), pixmap);
+ }
+
+ return item;
+}
+
+GtkMenu *
+e_popup_menu_create (EPopupMenu *menu_list, int disable_mask, void *closure)
+{
+ GtkMenu *menu = GTK_MENU (gtk_menu_new ());
+ int i;
+
+ for (i = 0; menu_list [i].name; i++){
+ GtkWidget *item;
+
+ item = make_item (menu, menu_list [i].name,
+ menu_list [i].pixname);
+
+ if (menu_list [i].fn)
+ gtk_signal_connect (
+ GTK_OBJECT (item), "activate",
+ GTK_SIGNAL_FUNC (menu_list [i].fn),
+ closure);
+
+ if (menu_list [i].disable_mask & disable_mask)
+ gtk_widget_set_sensitive (item, FALSE);
+
+ gtk_widget_show (item);
+ gtk_menu_append (menu, item);
+ }
+
+ return menu;
+
+}
+
+void
+e_popup_menu_run (EPopupMenu *menu_list, GdkEventButton *event, int disable_mask, void *closure)
+{
+ GtkMenu *menu;
+
+ g_return_if_fail (menu_list != NULL);
+ g_return_if_fail (event != NULL);
+
+ menu = e_popup_menu_create (menu_list, disable_mask, closure);
+
+ e_popup_menu (menu, event);
+}
+
diff --git a/widgets/misc/e-popup-menu.h b/widgets/misc/e-popup-menu.h
new file mode 100644
index 0000000000..400e6987b7
--- /dev/null
+++ b/widgets/misc/e-popup-menu.h
@@ -0,0 +1,16 @@
+#ifndef E_POPUP_MENU_H
+#define E_POPUP_MENU_H
+
+#include <gtk/gtkwidget.h>
+
+typedef struct {
+ char const * const name;
+ char const * const pixname;
+ void (*fn)(GtkWidget *widget, void *closure);
+ int disable_mask;
+} EPopupMenu;
+
+void e_popup_menu_run (EPopupMenu *menu_list, GdkEventButton *event,
+ int disable_mask, void *closure);
+
+#endif /* E_POPUP_MENU_H */