static void gtk_app_chooser_button_build_ui (GtkAppChooserButton *self) { GtkCellRenderer *cell; GtkCellArea *area; gtk_combo_box_set_model (GTK_COMBO_BOX (self), GTK_TREE_MODEL (self->priv->store)); area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (self)); gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self), row_separator_func, NULL, NULL); cell = gtk_cell_renderer_pixbuf_new (); gtk_cell_area_add_with_properties (area, cell, "align", FALSE, "expand", FALSE, "fixed-size", FALSE, NULL); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (self), cell, "gicon", COLUMN_ICON, NULL); cell = gtk_cell_renderer_text_new (); gtk_cell_area_add_with_properties (area, cell, "align", FALSE, "expand", TRUE, NULL); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (self), cell, "text", COLUMN_LABEL, NULL); gtk_app_chooser_button_populate (self); }
int main (int argc, char **argv) { GtkWidget *window, *cellview, *mainbox; GtkWidget *combobox, *comboboxtext, *comboboxgrid; GtkWidget *tmp, *boom; GtkCellRenderer *renderer; GtkTreeModel *model; GtkTreePath *path; GtkTreeIter iter; GdkRGBA color; GtkCellArea *area; gchar *text; gint i; gtk_init (&argc, &argv); if (g_getenv ("RTL")) gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL); if (g_getenv ("LISTMODE")) { GtkCssProvider *provider = gtk_css_provider_new (); gtk_css_provider_load_from_data (provider, "* { -GtkComboBox-appears-as-list: true; }", -1, NULL); gtk_style_context_add_provider_for_screen (gdk_screen_get_default (), GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_FALLBACK); } window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width (GTK_CONTAINER (window), 5); g_signal_connect (window, "destroy", gtk_main_quit, NULL); mainbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); gtk_container_add (GTK_CONTAINER (window), mainbox); /* GtkCellView */ tmp = gtk_frame_new ("GtkCellView"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); cellview = gtk_cell_view_new (); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cellview), renderer, FALSE); g_object_set (renderer, "icon-name", "dialog-warning", NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cellview), renderer, TRUE); g_object_set (renderer, "text", "la la la", NULL); gtk_container_add (GTK_CONTAINER (boom), cellview); /* GtkComboBox list */ tmp = gtk_frame_new ("GtkComboBox (list)"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_list_blaat (); combobox = gtk_combo_box_new_with_model (model); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "icon-name", 0, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 1, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combobox), is_separator, NULL, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); /* GtkComboBox dynamic list */ tmp = gtk_frame_new ("GtkComboBox (dynamic list)"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_empty_list_blaat (); combobox = gtk_combo_box_new_with_model (model); g_signal_connect (combobox, "notify::popup-shown", G_CALLBACK (populate_list_blaat), combobox); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "icon-name", 0, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 1, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combobox), is_separator, NULL, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); /* GtkComboBox custom entry */ tmp = gtk_frame_new ("GtkComboBox (custom)"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_list_blaat (); combobox = gtk_combo_box_new_with_model (model); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "icon-name", 0, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 1, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combobox), is_separator, NULL, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); tmp = gtk_cell_view_new (); gtk_widget_show (tmp); gtk_cell_view_set_model (GTK_CELL_VIEW (tmp), model); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (tmp), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (tmp), renderer, "text", 1, NULL); color.red = 1.0; color.blue = 1.0; color.green = 0; color.alpha = 1.0; gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (tmp), &color); displayed_row_changed (GTK_COMBO_BOX (combobox), GTK_CELL_VIEW (tmp)); g_signal_connect (combobox, "changed", G_CALLBACK (displayed_row_changed), tmp); gtk_container_add (GTK_CONTAINER (combobox), tmp); /* GtkComboBox tree */ tmp = gtk_frame_new ("GtkComboBox (tree)"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_tree_blaat (); combobox = gtk_combo_box_new_with_model (model); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "icon-name", 0, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 1, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, set_sensitive, NULL, NULL); gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combobox), is_separator, NULL, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); #if 0 g_timeout_add (1000, (GSourceFunc) animation_timer, model); #endif /* GtkComboBox (grid mode) */ tmp = gtk_frame_new ("GtkComboBox (grid mode)"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); comboboxgrid = create_combo_box_grid_demo (); gtk_box_pack_start (GTK_BOX (boom), comboboxgrid, FALSE, FALSE, 0); /* GtkComboBoxEntry */ tmp = gtk_frame_new ("GtkComboBox with entry"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); comboboxtext = gtk_combo_box_text_new_with_entry (); setup_combo_entry (GTK_COMBO_BOX_TEXT (comboboxtext)); gtk_container_add (GTK_CONTAINER (boom), comboboxtext); /* Phylogenetic tree */ tmp = gtk_frame_new ("What are you ?"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_phylogenetic_tree (); combobox = gtk_combo_box_new_with_model (model); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); /* Capitals */ tmp = gtk_frame_new ("Where are you ?"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_capital_tree (); combobox = gtk_combo_box_new_with_model (model); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox), renderer, capital_sensitive, NULL, NULL); path = gtk_tree_path_new_from_indices (0, 8, -1); gtk_tree_model_get_iter (model, &iter, path); gtk_tree_path_free (path); gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter); #if 1 gdk_threads_add_timeout (1000, (GSourceFunc) capital_animation, model); #endif /* Aligned Food */ tmp = gtk_frame_new ("Hungry ?"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_food_list (); combobox = gtk_combo_box_new_with_model (model); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (combobox)); renderer = gtk_cell_renderer_text_new (); gtk_cell_area_add_with_properties (area, renderer, "align", TRUE, "expand", TRUE, NULL); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_area_add_with_properties (area, renderer, "align", TRUE, "expand", TRUE, NULL); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 1, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); /* Ellipsizing growing combos */ tmp = gtk_frame_new ("Unconstrained Menu"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); boom = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_set_border_width (GTK_CONTAINER (boom), 5); gtk_container_add (GTK_CONTAINER (tmp), boom); model = create_list_long (); combobox = gtk_combo_box_new_with_model (model); g_object_unref (model); gtk_container_add (GTK_CONTAINER (boom), combobox); renderer = gtk_cell_renderer_text_new (); g_object_set (G_OBJECT (renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); gtk_combo_box_set_popup_fixed_width (GTK_COMBO_BOX (combobox), FALSE); tmp = gtk_frame_new ("Looong"); gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0); combobox = gtk_combo_box_text_new (); for (i = 0; i < 200; i++) { text = g_strdup_printf ("Item %d", i); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combobox), text); g_free (text); } gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 53); gtk_container_add (GTK_CONTAINER (tmp), combobox); gtk_widget_show_all (window); gtk_main (); return 0; }