diff options
-rw-r--r-- | widgets/menus/gal-view-instance.c | 139 | ||||
-rw-r--r-- | widgets/menus/gal-view-instance.h | 4 | ||||
-rw-r--r-- | widgets/misc/e-popup-menu.c | 100 | ||||
-rw-r--r-- | widgets/misc/e-popup-menu.h | 30 | ||||
-rw-r--r-- | widgets/table/e-table-memory-store.c | 8 | ||||
-rw-r--r-- | widgets/table/e-table-memory-store.h | 4 |
6 files changed, 254 insertions, 31 deletions
diff --git a/widgets/menus/gal-view-instance.c b/widgets/menus/gal-view-instance.c index 26e1f5546d..1cc0389f47 100644 --- a/widgets/menus/gal-view-instance.c +++ b/widgets/menus/gal-view-instance.c @@ -36,8 +36,10 @@ #include <gal/widgets/e-unicode.h> #include "gal-view-instance.h" #include "gal-view-instance-save-as-dialog.h" +#include "gal-define-views-dialog.h" #include <sys/stat.h> #include <unistd.h> +#include <gtk/gtkcheckmenuitem.h> #define GVI_CLASS(e) ((GalViewInstanceClass *)((GtkObject *)e)->klass) @@ -45,6 +47,10 @@ static GtkObjectClass *gal_view_instance_parent_class; +static const EPopupMenu separator = E_POPUP_SEPARATOR; +static const EPopupMenu terminator = E_POPUP_TERMINATOR; + + #define d(x) x enum { @@ -479,3 +485,136 @@ gal_view_instance_exists (GalViewInstance *instance) return FALSE; } + +typedef struct { + GalViewInstance *instance; + char *id; +} ListenerClosure; + +static void +view_item_cb (GtkWidget *widget, + gpointer user_data) +{ + ListenerClosure *closure = user_data; + + if (GTK_CHECK_MENU_ITEM (widget)->active) { + gal_view_instance_set_current_view_id (closure->instance, closure->id); + } +} + +static void +add_popup_radio_item (EPopupMenu *menu_item, + gchar *title, + void (*fn) (GtkWidget *widget, gpointer closure), + gpointer closure, + gboolean value) +{ + const EPopupMenu menu_item_struct = + E_POPUP_RADIO_ITEM_CC (title, + fn, + closure, + 0, + value); + + e_popup_menu_copy_1 (menu_item, &menu_item_struct); +} + +static void +add_popup_menu_item (EPopupMenu *menu_item, + gchar *title, + void (*fn) (GtkWidget *widget, gpointer closure), + gpointer closure) +{ + const EPopupMenu menu_item_struct = + E_POPUP_ITEM_CC (title, + fn, + closure, + 0); + + e_popup_menu_copy_1 (menu_item, &menu_item_struct); +} + +static void +define_views_dialog_clicked(GtkWidget *dialog, int button, GalViewInstance *instance) +{ + if (button == 0) { + gal_view_collection_save(instance->collection); + } + gnome_dialog_close(GNOME_DIALOG(dialog)); +} + +static void +define_views_cb(GtkWidget *widget, + GalViewInstance *instance) +{ + GtkWidget *dialog = gal_define_views_dialog_new(instance->collection); + gtk_signal_connect(GTK_OBJECT(dialog), "clicked", + GTK_SIGNAL_FUNC(define_views_dialog_clicked), instance); + gtk_widget_show(dialog); +} + +static void +save_current_view_cb(GtkWidget *widget, + GalViewInstance *instance) +{ + gal_view_instance_save_as (instance); +} + +EPopupMenu * +gal_view_instance_get_popup_menu (GalViewInstance *instance) +{ + EPopupMenu *ret_val; + int length; + int i; + gboolean found = FALSE; + char *id; + + length = gal_view_collection_get_count(instance->collection); + id = gal_view_instance_get_current_view_id (instance); + + ret_val = g_new (EPopupMenu, length + 6); + + for (i = 0; i < length; i++) { + gboolean value = FALSE; + GalViewCollectionItem *item = gal_view_collection_get_view_item(instance->collection, i); + ListenerClosure *closure; + + closure = g_new (ListenerClosure, 1); + closure->instance = instance; + closure->id = item->id; + gtk_object_ref (GTK_OBJECT(closure->instance)); + + if (!found && id && !strcmp (id, item->id)) { + found = TRUE; + value = TRUE; + } + + add_popup_radio_item (ret_val + i, item->title, GTK_SIGNAL_FUNC (view_item_cb), closure, value); + } + + if (!found) { + e_popup_menu_copy_1 (ret_val + i++, &separator); + + add_popup_radio_item (ret_val + i++, N_("Custom View"), NULL, NULL, TRUE); + add_popup_menu_item (ret_val + i++, N_("Save Custom View"), GTK_SIGNAL_FUNC (save_current_view_cb), instance); + } + + e_popup_menu_copy_1 (ret_val + i++, &separator); + add_popup_menu_item (ret_val + i++, N_("Define Views"), GTK_SIGNAL_FUNC (define_views_cb), instance); + e_popup_menu_copy_1 (ret_val + i++, &terminator); + + return ret_val; +} + +void +gal_view_instance_free_popup_menu (GalViewInstance *instance, EPopupMenu *menu) +{ + int i; + /* This depends on the first non-custom closure to be a separator or a terminator. */ + for (i = 0; menu[i].name && *(menu[i].name); i++) { + gtk_object_unref (GTK_OBJECT ( ((ListenerClosure *)(menu[i].closure))->instance)); + g_free (menu[i].closure); + } + + e_popup_menu_free (menu); +} diff --git a/widgets/menus/gal-view-instance.h b/widgets/menus/gal-view-instance.h index 9d0febf0f0..5e5ea6817e 100644 --- a/widgets/menus/gal-view-instance.h +++ b/widgets/menus/gal-view-instance.h @@ -26,6 +26,7 @@ #include <gtk/gtkobject.h> #include <gal/menus/gal-view-collection.h> +#include <gal/widgets/e-popup-menu.h> #include <libgnome/gnome-defs.h> BEGIN_GNOME_DECLS @@ -108,6 +109,9 @@ const char *gal_view_instance_get_default_view (GalViewInstance *inst void gal_view_instance_set_default_view (GalViewInstance *instance, const char *id); +EPopupMenu *gal_view_instance_get_popup_menu (GalViewInstance *instance); +void gal_view_instance_free_popup_menu (GalViewInstance *instance, + EPopupMenu *menu); END_GNOME_DECLS diff --git a/widgets/misc/e-popup-menu.c b/widgets/misc/e-popup-menu.c index 780ed55c76..86a07a74c8 100644 --- a/widgets/misc/e-popup-menu.c +++ b/widgets/misc/e-popup-menu.c @@ -106,21 +106,21 @@ e_popup_menu_create (EPopupMenu *menu_list, guint32 disable_mask, guint32 hide_m gboolean last_item_separator = TRUE; int last_non_separator = -1; int 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 (); @@ -132,14 +132,14 @@ e_popup_menu_create (EPopupMenu *menu_list, guint32 disable_mask, guint32 hide_m 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_group (GTK_RADIO_MENU_ITEM (item)); - + make_item (menu, GTK_MENU_ITEM (item), L_(menu_list[i].name), menu_list[i].pixmap_widget); } else { item = gtk_menu_item_new (); } - + gtk_menu_append (menu, item); - + if (!menu_list[i].submenu) { if (menu_list[i].fn) gtk_signal_connect (GTK_OBJECT (item), "activate", @@ -148,22 +148,22 @@ e_popup_menu_create (EPopupMenu *menu_list, guint32 disable_mask, guint32 hide_m } 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; } @@ -180,3 +180,75 @@ e_popup_menu_run (EPopupMenu *menu_list, GdkEvent *event, guint32 disable_mask, e_popup_menu (menu, event); } +void +e_popup_menu_copy_1 (EPopupMenu *destination, + const EPopupMenu *source) +{ + destination->name = g_strdup (source->name); + destination->pixname = g_strdup (source->pixname); + destination->fn = source->fn; + destination->submenu = e_popup_menu_copy (source->submenu); + destination->disable_mask = source->disable_mask; + + destination->pixmap_widget = source->pixmap_widget; + if (destination->pixmap_widget) + gtk_object_ref (GTK_OBJECT (destination->pixmap_widget)); + destination->closure = source->closure; + + destination->is_toggle = source->is_toggle; + destination->is_radio = source->is_radio; + destination->is_active = source->is_active; + + destination->use_custom_closure = source->use_custom_closure; +} + +void +e_popup_menu_free_1 (EPopupMenu *menu_item) +{ + g_free (menu_item->name); + g_free (menu_item->pixname); + e_popup_menu_free (menu_item->submenu); + + if (menu_item->pixmap_widget) + gtk_object_unref (GTK_OBJECT (menu_item->pixmap_widget)); +} + +EPopupMenu * +e_popup_menu_copy (const EPopupMenu *menu_list) +{ + int i; + EPopupMenu *ret_val; + + if (menu_list == NULL) + return NULL; + + for (i = 0; menu_list[i].name; i++) { + /* Intentionally empty */ + } + + ret_val = g_new (EPopupMenu, i + 1); + + for (i = 0; menu_list[i].name; i++) { + e_popup_menu_copy_1 (ret_val + i, menu_list + i); + } + + /* Copy the terminator */ + e_popup_menu_copy_1 (ret_val + i, menu_list + i); + + return ret_val; +} + +void +e_popup_menu_free (EPopupMenu *menu_list) +{ + int i; + + if (menu_list == NULL) + return; + + for (i = 0; menu_list[i].name; i++) { + e_popup_menu_free_1 (menu_list + i); + } + g_free (menu_list); +} + diff --git a/widgets/misc/e-popup-menu.h b/widgets/misc/e-popup-menu.h index 095c1a42d7..50fb7c23e5 100644 --- a/widgets/misc/e-popup-menu.h +++ b/widgets/misc/e-popup-menu.h @@ -74,7 +74,7 @@ typedef struct _EPopupMenu EPopupMenu; struct _EPopupMenu { char *name; - const gchar *pixmap; + gchar *pixname; void (*fn) (GtkWidget *widget, void *closure); EPopupMenu *submenu; guint32 disable_mask; @@ -91,16 +91,24 @@ struct _EPopupMenu { }; -GtkMenu *e_popup_menu_create (EPopupMenu *menu_list, - guint32 disable_mask, - guint32 hide_mask, - void *default_closure); - -void e_popup_menu_run (EPopupMenu *menu_list, - GdkEvent *event, - guint32 disable_mask, - guint32 hide_mask, - void *default_closure); +GtkMenu *e_popup_menu_create (EPopupMenu *menu_list, + guint32 disable_mask, + guint32 hide_mask, + void *default_closure); +void e_popup_menu_run (EPopupMenu *menu_list, + GdkEvent *event, + guint32 disable_mask, + guint32 hide_mask, + void *default_closure); + +/* Doesn't copy or free the memory. Just the contents. */ +void e_popup_menu_copy_1 (EPopupMenu *destination, + const EPopupMenu *menu_item); +void e_popup_menu_free_1 (EPopupMenu *menu_item); + +/* Copies or frees the entire structure. */ +EPopupMenu *e_popup_menu_copy (const EPopupMenu *menu_item); +void e_popup_menu_free (EPopupMenu *menu_item); END_GNOME_DECLS diff --git a/widgets/table/e-table-memory-store.c b/widgets/table/e-table-memory-store.c index f3f29e54ee..1bac335237 100644 --- a/widgets/table/e-table-memory-store.c +++ b/widgets/table/e-table-memory-store.c @@ -207,7 +207,7 @@ etms_append_row (ETableModel *etm, ETableModel *source, int row) row_count = e_table_model_row_count (E_TABLE_MODEL (etms)); - e_table_memory_store_insert (etms, row_count, new_data, NULL); + e_table_memory_store_insert_array (etms, row_count, new_data, NULL); } static void @@ -327,7 +327,7 @@ e_table_memory_store_adopt_value_at (ETableMemoryStore *etms, int col, int row, /* The size of these arrays is the number of columns. */ void -e_table_memory_store_insert (ETableMemoryStore *etms, int row, void **store, gpointer data) +e_table_memory_store_insert_array (ETableMemoryStore *etms, int row, void **store, gpointer data) { int row_count; int i; @@ -348,7 +348,7 @@ e_table_memory_store_insert (ETableMemoryStore *etms, int row, void **store, gpo } void -e_table_memory_store_insert_list (ETableMemoryStore *etms, int row, gpointer data, ...) +e_table_memory_store_insert (ETableMemoryStore *etms, int row, gpointer data, ...) { void **store; va_list args; @@ -362,7 +362,7 @@ e_table_memory_store_insert_list (ETableMemoryStore *etms, int row, gpointer dat } va_end (args); - e_table_memory_store_insert (etms, row, store, data); + e_table_memory_store_insert_array (etms, row, store, data); g_free (store); } diff --git a/widgets/table/e-table-memory-store.h b/widgets/table/e-table-memory-store.h index 60bd037758..2c088815de 100644 --- a/widgets/table/e-table-memory-store.h +++ b/widgets/table/e-table-memory-store.h @@ -97,11 +97,11 @@ void e_table_memory_store_adopt_value_at (ETableMemoryStore void *value); /* The size of these arrays is the number of columns. */ -void e_table_memory_store_insert (ETableMemoryStore *etms, +void e_table_memory_store_insert_array (ETableMemoryStore *etms, int row, void **store, gpointer data); -void e_table_memory_store_insert_list (ETableMemoryStore *etms, +void e_table_memory_store_insert (ETableMemoryStore *etms, int row, gpointer data, ...); |