//________________________________________________________________________________ void ComboBoxData::updateCellViewColor( void ) const { // change background color if( _cell._widget ) { const GdkRGBA color = { 0, 0, 0, 0 }; gtk_cell_view_set_background_rgba( GTK_CELL_VIEW( _cell._widget ), &color ); } }
static void gtk_cell_view_set_property (GObject *object, guint param_id, const GValue *value, GParamSpec *pspec) { GtkCellView *view = GTK_CELL_VIEW (object); GtkCellViewPrivate *priv = view->priv; GtkCellArea *area; GtkCellAreaContext *context; switch (param_id) { case PROP_ORIENTATION: priv->orientation = g_value_get_enum (value); if (priv->context) gtk_cell_area_context_reset (priv->context); _gtk_orientable_set_style_classes (GTK_ORIENTABLE (object)); break; case PROP_BACKGROUND: { GdkColor color; if (!g_value_get_string (value)) gtk_cell_view_set_background_color (view, NULL); else if (gdk_color_parse (g_value_get_string (value), &color)) gtk_cell_view_set_background_color (view, &color); else g_warning ("Don't know color `%s'", g_value_get_string (value)); g_object_notify (object, "background-gdk"); } break; case PROP_BACKGROUND_GDK: gtk_cell_view_set_background_color (view, g_value_get_boxed (value)); break; case PROP_BACKGROUND_RGBA: gtk_cell_view_set_background_rgba (view, g_value_get_boxed (value)); break; case PROP_BACKGROUND_SET: view->priv->background_set = g_value_get_boolean (value); break; case PROP_MODEL: gtk_cell_view_set_model (view, g_value_get_object (value)); break; case PROP_CELL_AREA: /* Construct-only, can only be assigned once */ area = g_value_get_object (value); if (area) { if (priv->area != NULL) { g_warning ("cell-area has already been set, ignoring construct property"); g_object_ref_sink (area); g_object_unref (area); } else priv->area = g_object_ref_sink (area); } break; case PROP_CELL_AREA_CONTEXT: /* Construct-only, can only be assigned once */ context = g_value_get_object (value); if (context) { if (priv->context != NULL) { g_warning ("cell-area-context has already been set, ignoring construct property"); g_object_ref_sink (context); g_object_unref (context); } else priv->context = g_object_ref (context); } break; case PROP_DRAW_SENSITIVE: gtk_cell_view_set_draw_sensitive (view, g_value_get_boolean (value)); break; case PROP_FIT_MODEL: gtk_cell_view_set_fit_model (view, g_value_get_boolean (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; } }
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; }