static void load_stock_items (GtkToolPalette *palette) { GtkWidget *group_af = gtk_tool_item_group_new ("Stock Icons (A-F)"); GtkWidget *group_gn = gtk_tool_item_group_new ("Stock Icons (G-N)"); GtkWidget *group_or = gtk_tool_item_group_new ("Stock Icons (O-R)"); GtkWidget *group_sz = gtk_tool_item_group_new ("Stock Icons (S-Z)"); GtkWidget *group = NULL; GtkToolItem *item; GSList *stock_ids; GSList *iter; stock_ids = gtk_stock_list_ids (); stock_ids = g_slist_sort (stock_ids, (GCompareFunc) strcmp); gtk_container_add (GTK_CONTAINER (palette), group_af); gtk_container_add (GTK_CONTAINER (palette), group_gn); gtk_container_add (GTK_CONTAINER (palette), group_or); gtk_container_add (GTK_CONTAINER (palette), group_sz); for (iter = stock_ids; iter; iter = g_slist_next (iter)) { GtkStockItem stock_item; gchar *id = iter->data; switch (id[4]) { case 'a': group = group_af; break; case 'g': group = group_gn; break; case 'o': group = group_or; break; case 's': group = group_sz; break; } item = gtk_tool_button_new_from_stock (id); gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (item), id); gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE); gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1); if (!gtk_stock_lookup (id, &stock_item) || !stock_item.label) gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), id); g_free (id); } g_slist_free (stock_ids); }
static VALUE stock_m_list_ids(VALUE klass) { GSList *ids = gtk_stock_list_ids(); GSList *l; VALUE ary = rb_ary_new(); for (l = ids; l != NULL; l = g_slist_next(l)) { rb_ary_push(ary, CSTR2SYM(l->data)); g_free(l->data); } g_slist_free(ids); return ary; }
static void create_treeview (GtkWidget *vbox) { GtkWidget *scrolledwindow; GtkListStore *store; GtkWidget *tree_view; GSList *stock_ids; GSList *list; scrolledwindow = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_SHADOW_IN); gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0); store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)); g_object_unref (store); gtk_container_add (GTK_CONTAINER (scrolledwindow), tree_view); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view), -1, "Icon", gtk_cell_renderer_pixbuf_new (), "stock-id", 0, NULL); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view), -1, "Label", gtk_cell_renderer_text_new (), "text", 1, NULL); stock_ids = gtk_stock_list_ids (); for (list = stock_ids; list; list = g_slist_next (list)) { const gchar *stock_id = list->data; GtkStockItem item; if (gtk_stock_lookup (stock_id, &item)) { gtk_list_store_insert_with_values (store, NULL, -1, 0, item.stock_id, 1, item.label, -1); } } g_slist_foreach (stock_ids, (GFunc) g_free, NULL); g_slist_free (stock_ids); }
static void populate_flowbox_stock (GtkFlowBox *flowbox) { GtkWidget *widget; static GSList *stock_ids = NULL; GSList *l; gint i; if (!stock_ids) stock_ids = gtk_stock_list_ids (); for (i = 0, l = stock_ids; i < 30 && l != NULL; i++, l = l->next) { gchar *stock_id = l->data; gchar *text = g_strdup_printf ("Item %02d", i); widget = gtk_button_new_from_stock (stock_id); gtk_widget_show (widget); g_object_set_data_full (G_OBJECT (widget), "id", (gpointer)g_strdup (text), g_free); gtk_container_add (GTK_CONTAINER (flowbox), widget); } }
gint main (gint argc, gchar **argv) { GnomeProgram *program; GtkWidget *window, *scrolled_window, *icon_list, *vbox, *button; GSList *ids, *list; gint i; program = gnome_program_init ("testiconlist", "0.0", LIBGNOMEUI_MODULE, argc, argv, NULL); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 400, 300); vbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (window), vbox); scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN); icon_list = gnome_icon_list_new (80, NULL, GNOME_ICON_LIST_IS_EDITABLE); gtk_container_add (GTK_CONTAINER (scrolled_window), icon_list); g_signal_connect (icon_list, "select_icon", G_CALLBACK (select_icon), NULL); g_signal_connect (icon_list, "unselect_icon", G_CALLBACK (unselect_icon), NULL); gnome_icon_list_set_selection_mode (GNOME_ICON_LIST (icon_list), GTK_SELECTION_EXTENDED); ids = gtk_stock_list_ids (); gnome_icon_list_append_pixbuf (GNOME_ICON_LIST (icon_list), gtk_widget_render_icon (icon_list, GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON, NULL), "slirpe", "What happens if we have a long long line here?"); gnome_icon_list_append_pixbuf (GNOME_ICON_LIST (icon_list), gtk_widget_render_icon (icon_list, GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON, NULL), "slirpe", "What happens if we have a longlonglongword here?"); for (list = ids, i = 0; list; list = list->next, i++) { gchar *name = list->data; if (i > 2) break; gnome_icon_list_append_pixbuf (GNOME_ICON_LIST (icon_list), gtk_widget_render_icon (icon_list, name, GTK_ICON_SIZE_BUTTON, NULL), name, "Sliff! السلام عليكم"); g_free (name); } button = gtk_button_new_from_stock (GTK_STOCK_QUIT); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); gtk_widget_show_all (window); gtk_main (); g_object_unref (program); return 0; }
static GArray * list_stock_items (gboolean include_images) { GtkStockItem item; GSList *l = NULL, *stock_list = NULL, *p = NULL; gchar *stock_id = NULL, *prefix = NULL; gint stock_enum = 1, i = 0; GEnumValue value; GArray *values = NULL; GladeStockItem *gsi; GSList *gsi_list = NULL; GSList *gsi_list_list = NULL; stock_list = g_slist_reverse (gtk_stock_list_ids ()); values = g_array_sized_new (TRUE, TRUE, sizeof (GEnumValue), g_slist_length (stock_list) + 1); /* Add first "no stock" element which is sorted alone ! */ gsi = new_from_values ("None", "glade-none", 0); gsi_list = g_slist_insert_sorted (gsi_list, gsi, (GCompareFunc) compare_two_gsi); gsi_list_list = g_slist_append (gsi_list_list, gsi_list); gsi_list = NULL; /* We want gtk+ stock items to appear first */ if ((stock_prefixs && strcmp (stock_prefixs->data, "gtk-")) || stock_prefixs == NULL) stock_prefixs = g_slist_prepend (stock_prefixs, g_strdup ("gtk-")); for (p = stock_prefixs; p; p = g_slist_next (p)) { prefix = p->data; for (l = stock_list; l; l = g_slist_next (l)) { stock_id = l->data; if (g_str_has_prefix (stock_id, prefix) == FALSE || gtk_stock_lookup (stock_id, &item) == FALSE ) continue; gsi = new_from_values (item.label, stock_id, stock_enum++ ); gsi_list = g_slist_insert_sorted (gsi_list, gsi, (GCompareFunc) compare_two_gsi); } gsi_list_list = g_slist_append (gsi_list_list, gsi_list); gsi_list = NULL; /* Images are appended after the gtk+ group of items */ if (include_images && !strcmp (prefix, "gtk-")) { for (i = 0; i < G_N_ELEMENTS (builtin_stock_images); i++) { gsi = new_from_values (builtin_stock_images[i], builtin_stock_images[i], stock_enum++); gsi_list = g_slist_insert_sorted (gsi_list, gsi, (GCompareFunc) compare_two_gsi); } gsi_list_list = g_slist_append (gsi_list_list, gsi_list); gsi_list = NULL; } } for (p = gsi_list_list; p; p = g_slist_next (p)) { for (l = (GSList *) p->data; l; l = g_slist_next (l)) { gsi = (GladeStockItem *) l->data; value.value = gsi->value; value.value_name = g_strdup (gsi->value_name); value.value_nick = g_strdup (gsi->value_nick); values = g_array_append_val (values, value); g_free (gsi->value_nick); g_free (gsi->value_name); g_free (gsi->clean_name); g_free (gsi); } g_slist_free ((GSList *) p->data); } g_slist_free (gsi_list_list); /* Add the trailing end marker */ value.value = 0; value.value_name = NULL; value.value_nick = NULL; values = g_array_append_val (values, value); stock_prefixs_done = TRUE; g_slist_free (stock_list); return values; }
/** \brief Retrieve different information. \author Peter G. Baum **/ int gnoclInfoCmd ( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] ) { static const char *cmd[] = { "version", "gtkVersion", "hasGnomeSupport", "allStockItems", "breakpoint", NULL }; enum optIdx { VersionIdx, GtkVersionIdx, HasGnomeIdx, AllStockItems, BreakpointIdx }; int idx; if ( objc != 2 ) { Tcl_WrongNumArgs ( interp, 1, objv, "option" ); return TCL_ERROR; } if ( Tcl_GetIndexFromObj ( interp, objv[1], cmd, "option", TCL_EXACT, &idx ) != TCL_OK ) return TCL_ERROR; switch ( idx ) { case VersionIdx: Tcl_SetObjResult ( interp, Tcl_NewStringObj ( VERSION, -1 ) ); break; case GtkVersionIdx: { char buffer[128]; sprintf ( buffer, "%d.%d.%d", gtk_major_version, gtk_minor_version, gtk_micro_version ); Tcl_SetObjResult ( interp, Tcl_NewStringObj ( buffer, -1 ) ); } break; case HasGnomeIdx: Tcl_SetObjResult ( interp, Tcl_NewBooleanObj ( #ifdef GNOCL_USE_GNOME 1 #else 0 #endif ) ); break; case AllStockItems: { Tcl_Obj *res = Tcl_NewListObj ( 0, NULL ); GSList *ids = gtk_stock_list_ids(); GSList *p; for ( p = ids; p != NULL; p = p->next ) { char *txt = p->data; int skip = 0; /* FIXME: gtk-missing-image, gtk-dnd-multiple and gtk-dnd fail lookup, why? { GtkStockItem sp; printf( "%s lookup: %d\n", txt, gtk_stock_lookup( txt, &sp ) ); } **/ /* see createStockName and gnoclGetStockName */ if ( strncmp ( txt, "gtk", 3 ) == 0 ) skip = 3; #ifdef GNOCL_USE_GNOME else if ( strncmp ( txt, "gnome-stock", 11 ) == 0 ) skip = 11; #endif if ( skip > 0 ) { GString *name = g_string_new ( NULL ); char *tp = txt + skip; for ( ; *tp; ++tp ) { if ( *tp == '-' ) { ++tp; g_string_append_c ( name, toupper ( *tp ) ); } else g_string_append_c ( name, *tp ); } Tcl_ListObjAppendElement ( interp, res, Tcl_NewStringObj ( name->str, -1 ) ); /* printf( "%s -> %s\n", (char *)p->data, name->str ); */ g_string_free ( name, 1 ); } else Tcl_ListObjAppendElement ( interp, res, Tcl_NewStringObj ( txt, -1 ) ); g_free ( p->data ); } g_slist_free ( ids ); Tcl_SetObjResult ( interp, res ); } break; case BreakpointIdx: /* this is only for debugging */ G_BREAKPOINT(); break; } return TCL_OK; }
static GtkTreeModel* create_model (void) { GtkListStore *store; GSList *ids; GSList *tmp_list; store = gtk_list_store_new (2, STOCK_ITEM_INFO_TYPE, G_TYPE_STRING); ids = gtk_stock_list_ids (); ids = g_slist_sort (ids, (GCompareFunc) strcmp); tmp_list = ids; while (tmp_list != NULL) { StockItemInfo info; GtkStockItem item; GtkTreeIter iter; GtkIconSet *icon_set; info.id = tmp_list->data; if (gtk_stock_lookup (info.id, &item)) { info.item = item; } else { info.item.label = NULL; info.item.stock_id = NULL; info.item.modifier = 0; info.item.keyval = 0; info.item.translation_domain = NULL; } /* only show icons for stock IDs that have default icons */ icon_set = gtk_icon_factory_lookup_default (info.id); if (icon_set) { GtkIconSize *sizes = NULL; gint n_sizes = 0; gint i; GtkIconSize size; /* See what sizes this stock icon really exists at */ gtk_icon_set_get_sizes (icon_set, &sizes, &n_sizes); /* Use menu size if it exists, otherwise first size found */ size = sizes[0]; i = 0; while (i < n_sizes) { if (sizes[i] == GTK_ICON_SIZE_MENU) { size = GTK_ICON_SIZE_MENU; break; } ++i; } g_free (sizes); info.small_icon = gtk_widget_render_icon (window, info.id, size, NULL); if (size != GTK_ICON_SIZE_MENU) { /* Make the result the proper size for our thumbnail */ gint w, h; GdkPixbuf *scaled; gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h); scaled = gdk_pixbuf_scale_simple (info.small_icon, w, h, GDK_INTERP_BILINEAR); g_object_unref (info.small_icon); info.small_icon = scaled; } } else info.small_icon = NULL; if (info.item.keyval != 0) { info.accel_str = gtk_accelerator_name (info.item.keyval, info.item.modifier); } else { info.accel_str = g_strdup (""); } info.macro = id_to_macro (info.id); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, 0, &info, 1, info.id, -1); g_free (info.macro); g_free (info.accel_str); if (info.small_icon) g_object_unref (info.small_icon); tmp_list = g_slist_next (tmp_list); } g_slist_foreach (ids, (GFunc)g_free, NULL); g_slist_free (ids); return GTK_TREE_MODEL (store); }