/****************************************************************************** * gtk_ItemFactoryDeleteEntry( itemFactory, entry ) --> NIL *****************************************************************************/ int clip_GTK_ITEMFACTORYDELETEENTRY(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); ClipArrVar *cventry = (ClipArrVar *)_clip_vptr(_clip_par(cm, 2)); GtkItemFactoryEntry entry ; ClipVar *cfunc ; C_var *data ; CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, ARRAY_t); entry.path = (cventry->items[0].t.type==UNDEF_t)?NULL:cventry->items[0].s.str.buf; entry.accelerator = (cventry->items[1].t.type==UNDEF_t)?NULL:cventry->items[1].s.str.buf; cfunc = &cventry->items[2]; data = NEW(C_var); data->cm = cm; data->co = citem; _clip_mclone(cm, &data->cfunc, cfunc); entry.callback = (cfunc==NULL)?0:(GtkItemFactoryCallback1)_item_factory_callback1; entry.callback_action = (cventry->items[3].t.type==UNDEF_t)?0:(guint)cventry->items[3].n.d; entry.item_type = (cventry->items[4].t.type==UNDEF_t)?NULL:cventry->items[4].s.str.buf; gtk_item_factory_delete_entry(GTK_ITEM_FACTORY(citem->object), &entry); return 0; err: return 1; }
static void cb_menu_destroy (GtkWidget *widget, GtkItemFactory *factory) { g_return_if_fail (factory); g_return_if_fail (GTK_IS_ITEM_FACTORY (factory)); g_object_unref (G_OBJECT (factory)); }
/****************************************************************************** * gtk_ItemFactoryDeleteItem( itemFactory, spath ) --> NIL ******************************************************************************/ int clip_GTK_ITEMFACTORYDELETEITEM(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); const gchar *path = _clip_parc(cm, 2); CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, CHARACTER_t); gtk_item_factory_delete_item(GTK_ITEM_FACTORY(citem->object), path ); return 0; err: return 1; }
void gtk_utils_set_menu_items_sensitive (GtkItemFactory *item_factory, gboolean are_sensitive, ...) { va_list arguments; const gchar *path; g_return_if_fail (GTK_IS_ITEM_FACTORY (item_factory)); va_start (arguments, are_sensitive); while ((path = va_arg (arguments, const gchar *)) != NULL) { gtk_widget_set_sensitive (gtk_item_factory_get_widget (item_factory, path), are_sensitive); } va_end (arguments); }
/****************************************************************************** * gtk_ItemFactoryCreateItems( itemFactory, array_entry ) --> NIL ******************************************************************************/ int clip_GTK_ITEMFACTORYCREATEITEMS(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); ClipArrVar *cventry = (ClipArrVar *)_clip_vptr(_clip_par(cm, 2)); gint i, n ; CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, ARRAY_t); n = cventry->count; for (i=0; i<n; i++) { ClipArrVar *it = (ClipArrVar *)_clip_vptr(cventry->items[i].a.items); ClipVar *cfunc ; C_var *c ; GtkItemFactoryEntry entry; entry.path = (it->items[0].t.type==UNDEF_t)?NULL:it->items[0].s.str.buf; entry.accelerator = (it->items[1].t.type==UNDEF_t)?NULL:it->items[1].s.str.buf; cfunc = (it->items[2].t.type==UNDEF_t)?NULL:&it->items[2]; c = NEW(C_var); c->cm = cm; c->co = citem; _clip_mclone(cm, &c->cfunc, cfunc); entry.callback = (cfunc==NULL)?0:(GtkItemFactoryCallback1)_item_factory_callback1; entry.callback_action = 1; entry.item_type = (it->items[4].t.type==UNDEF_t)?0:it->items[4].s.str.buf; //citem->destroy = __itemfactory_destroy_data; //citem->data = c; gtk_item_factory_create_item(GTK_ITEM_FACTORY(citem->object), &entry, c, 1); } return 0; err: return 1; }
/****************************************************************************** * gtk_ItemFactoryGetWidget( itemFactory, spath ) --> widget ******************************************************************************/ int clip_GTK_ITEMFACTORYGETWIDGET(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); const gchar *path = _clip_parc(cm, 2); GtkWidget *wid ; C_widget *cwid ; CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, CHARACTER_t); wid = gtk_item_factory_get_widget(GTK_ITEM_FACTORY(citem->object), path); if (!wid) goto err; cwid = _register_widget(cm, wid, NULL); _clip_mclone(cm,RETPTR(cm),&cwid->obj); return 0; err: return 1; }
/****************************************************************************** * gtk_ItemFactoryConstruct( itemFactory, container_type, spath, accel_group ) --> NIL * container_type is one of :GTK_TYPE_MENU_BAR, GTK_TYPE_MENU or GTK_TYPE_OPTION_MENU ******************************************************************************/ int clip_GTK_ITEMFACTORYCONSTRUCT(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); GtkType type = INT_OPTION(cm, 2, GTK_TYPE_MENU_BAR); const gchar *path = _clip_parc(cm, 3); C_object *caccel = _fetch_cobject(cm, _clip_spar(cm, 4)); CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, NUMERIC_t); CHECKARG(3, CHARACTER_t); CHECKOPT(4, MAP_t); CHECKCOBJOPT(caccel, GTK_IS_ACCEL_GROUP(caccel->object)); gtk_item_factory_construct(GTK_ITEM_FACTORY(citem->object), type, path, GTK_ACCEL_GROUP(caccel->object)); return 0; err: return 1; }
/****************************************************************************** * gtk_ItemFactoryGetItemByAction( itemFactory, naction ) --> widget ******************************************************************************/ int clip_GTK_ITEMFACTORYGETITEMBYACTION(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); gint action = _clip_parni(cm, 2); GtkWidget *wid ; C_widget *cwid ; CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, NUMERIC_t); wid = gtk_item_factory_get_item_by_action( GTK_ITEM_FACTORY(citem->object), action); if (!wid) goto err; cwid = _register_widget(cm, wid, NULL); _clip_mclone(cm,RETPTR(cm),&cwid->obj); return 0; err: return 1; }
/****************************************************************************** * gtk_ItemFactoryPopup( itemFactory, nx, ny, nmouse_button, ntime ) --> NIL * itemFactory of type GLIP_GTK_TYPE_MENU ******************************************************************************/ int clip_GTK_ITEMFACTORYPOPUP(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); gint x = _clip_parni(cm, 2); gint y = _clip_parni(cm, 3); gint mouse_button = _clip_parni(cm, 4); guint32 time = _clip_parni(cm, 5); CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, NUMERIC_t); CHECKARG(3, NUMERIC_t); CHECKARG(4, NUMERIC_t); CHECKARG(5, NUMERIC_t); gtk_item_factory_popup(GTK_ITEM_FACTORY(citem->object), x, y, mouse_button, time ); return 0; err: return 1; }
/** * gwy_graph_func_build_menu: * @item_factory: A #GtkItemFactory to add items to. * @prefix: Where to add the menu items to the factory. * @item_callback: A #GtkItemFactoryCallback1 called when an item from the * menu is selected. * * Creates #GtkItemFactory for a graph menu with all registered graph * functions. * * Returns: The menu item factory as a #GtkObject. **/ GtkObject* gwy_graph_func_build_menu(GtkObject *item_factory, const gchar *prefix, GCallback item_callback) { GtkItemFactoryEntry branch = { NULL, NULL, NULL, 0, "<Branch>", NULL }; GtkItemFactoryEntry tearoff = { NULL, NULL, NULL, 0, "<Tearoff>", NULL }; GtkItemFactoryEntry item = { NULL, NULL, item_callback, 0, "<Item>", NULL }; GtkItemFactory *factory; GString *current, *prev; const gchar *mpath; GSList *l, *entries = NULL; gint i, dp_len; g_return_val_if_fail(GTK_IS_ITEM_FACTORY(item_factory), NULL); factory = GTK_ITEM_FACTORY(item_factory); if (!graph_funcs) { g_warning("No graph function present to build menu of"); entries = NULL; } else g_hash_table_foreach(graph_funcs, gwy_hash_table_to_slist_cb, &entries); entries = g_slist_sort(entries, (GCompareFunc)graph_menu_entry_compare); dp_len = strlen(prefix); /* the root branch */ current = g_string_new(prefix); /* the root tearoff */ prev = g_string_new(prefix); g_string_append(prev, "/---"); tearoff.path = prev->str; gtk_item_factory_create_item(factory, &tearoff, NULL, 1); /* create missing branches * XXX: Gtk+ essentially can do this itself * but this way we can e. g. put a tearoff at the top of each branch... */ for (l = entries; l; l = g_slist_next(l)) { GraphFuncInfo *func_info = (GraphFuncInfo*)l->data; mpath = func_info->menu_path_translated; if (!mpath || !*mpath) continue; if (mpath[0] != '/') { g_warning("Menu path `%s' doesn't start with a slash", mpath); continue; } g_string_truncate(current, dp_len); g_string_append(current, mpath); /* find where the paths differ */ i = gwy_strdiffpos(current->str + dp_len, prev->str + dp_len); if (!current->str[i] && !prev->str[i]) g_warning("Duplicate menu entry `%s'", mpath); else { /* find where the next / is */ do { i++; } while (current->str[i] && current->str[i] != '/'); } while (current->str[i]) { /* create a branch with a tearoff */ current->str[i] = '\0'; branch.path = current->str; gtk_item_factory_create_item(factory, &branch, NULL, 1); g_string_assign(prev, current->str); g_string_append(prev, "/---"); tearoff.path = prev->str; gtk_item_factory_create_item(factory, &tearoff, NULL, 1); current->str[i] = '/'; /* find where the next / is */ do { i++; } while (current->str[i] && current->str[i] != '/'); } /* XXX: passing directly func_info->name may be a little dangerous, * OTOH who would eventually free a newly allocated string? */ item.path = current->str; gtk_item_factory_create_item(factory, &item, (gpointer)func_info->info.name, 1); GWY_SWAP(GString*, current, prev); } g_string_free(prev, TRUE); g_string_free(current, TRUE); g_slist_free(entries); return item_factory; }