00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00025 #include <glib.h>
00026
00027 #include "frame-common.h"
00028 #include "func-list.h"
00029
00030
00031
00032 void func_list_add_new_func (GList **list, const char *name, void (*func)(GtkMenuItem *, gpointer))
00033 {
00034 func_list_t *f = g_malloc (sizeof (func_list_t));
00035
00036 f->type = FUNCTION;
00037 f->name = g_strdup (name);
00038 f->data.func = func;
00039
00040 *list = g_list_prepend (*list, f);
00041 }
00042
00043
00044
00045 void func_list_add_new_submenu (GList **list, const char *name, GList *children)
00046 {
00047 func_list_t *f = g_malloc (sizeof (func_list_t));
00048
00049 f->type = SUBMENU;
00050 f->name = g_strdup (name);
00051 f->data.children = children;
00052
00053 *list = g_list_prepend (*list, f);
00054 }
00055
00056
00057
00058 void func_list_add_new_separator (GList **list)
00059 {
00060 func_list_t *f = g_malloc (sizeof (func_list_t));
00061
00062 f->type = SEPARATOR;
00063 f->name = NULL;
00064
00065 *list = g_list_prepend (*list, f);
00066 }
00067
00068
00069
00070 void func_list_t_free (func_list_t *fn)
00071 {
00072 if (fn) {
00073 g_free (fn->name);
00074 if (fn->type == SUBMENU)
00075 g_list_free (fn->data.children);
00076 }
00077 g_free (fn);
00078 }
00079
00080
00081
00082 GtkWidget *func_list_t_setup_submenu (func_list_t *parent, frame_t *f)
00083 {
00084 g_return_val_if_fail (parent != NULL, NULL);
00085 g_return_val_if_fail (parent->type == SUBMENU, NULL);
00086
00087 GList *iter = parent->data.children;
00088 GtkWidget *menu = gtk_menu_new ();
00089 GtkWidget *childmenu = NULL;
00090
00091 if (iter) {
00092 do {
00093 func_list_t *fn = iter->data;
00094 GtkWidget *item = NULL;
00095
00096 switch (fn->type) {
00097 case FUNCTION:
00098 item = gtk_menu_item_new_with_label (fn->name);
00099
00100 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
00101
00102 g_signal_connect (item, "activate", G_CALLBACK (fn->data.func), (gpointer) f);
00103 gtk_widget_show (item);
00104 break;
00105 case SEPARATOR:
00106 item = gtk_separator_menu_item_new ();
00107 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
00108 gtk_widget_show (item);
00109 break;
00110 case SUBMENU:
00111 item = gtk_menu_item_new_with_label (fn->name);
00112 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
00113
00114 childmenu = func_list_t_setup_submenu (fn, f);
00115 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), childmenu);
00116
00117 gtk_widget_show (item);
00118 break;
00119 }
00120 func_list_t_free (fn);
00121 } while ((iter = g_list_next (iter)) != NULL);
00122
00123 g_list_free (parent->data.children);
00124 parent->data.children = NULL;
00125 }
00126
00127 return menu;
00128 }