create_color_pixbuf (const char *color)
{
GdkPixbuf *pixbuf;
- GdkColor col;
+ GdkRGBA rgba;
int x;
int num;
- int rowstride;
guchar *pixels, *p;
- if (!gdk_color_parse (color, &col))
+ if (!gdk_rgba_parse (&rgba, color))
return NULL;
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
FALSE, 8,
16, 16);
- rowstride = gdk_pixbuf_get_rowstride (pixbuf);
p = pixels = gdk_pixbuf_get_pixels (pixbuf);
num = gdk_pixbuf_get_width (pixbuf) *
gdk_pixbuf_get_height (pixbuf);
for (x = 0; x < num; x++) {
- p[0] = col.red / 65535 * 255;
- p[1] = col.green / 65535 * 255;
- p[2] = col.blue / 65535 * 255;
+ p[0] = rgba.red * 255;
+ p[1] = rgba.green * 255;
+ p[2] = rgba.blue * 255;
p += 3;
}
store = gtk_tree_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_BOOLEAN);
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_DIALOG_WARNING,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_DIALOG_WARNING,
+ GTK_ICON_SIZE_BUTTON);
gtk_tree_store_append (store, &iter, NULL);
gtk_tree_store_set (store, &iter,
0, pixbuf,
2, FALSE,
-1);
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_STOP,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_STOP,
+ GTK_ICON_SIZE_BUTTON);
gtk_tree_store_append (store, &iter2, &iter);
gtk_tree_store_set (store, &iter2,
0, pixbuf,
2, FALSE,
-1);
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_NEW,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_NEW,
+ GTK_ICON_SIZE_BUTTON);
gtk_tree_store_append (store, &iter2, &iter);
gtk_tree_store_set (store, &iter2,
0, pixbuf,
2, FALSE,
-1);
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_CLEAR,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_CLEAR,
+ GTK_ICON_SIZE_BUTTON);
gtk_tree_store_append (store, &iter, NULL);
gtk_tree_store_set (store, &iter,
0, pixbuf,
-1);
#endif
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_OPEN,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_OPEN,
+ GTK_ICON_SIZE_BUTTON);
gtk_tree_store_append (store, &iter, NULL);
gtk_tree_store_set (store, &iter,
0, pixbuf,
store = gtk_list_store_new (2, GDK_TYPE_PIXBUF, G_TYPE_STRING);
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_DIALOG_WARNING,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_DIALOG_WARNING,
+ GTK_ICON_SIZE_BUTTON);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
cellview = gtk_cell_view_new ();
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_STOP,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_STOP,
+ GTK_ICON_SIZE_BUTTON);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "gtk-stock-stop",
-1);
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_NEW,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_NEW,
+ GTK_ICON_SIZE_BUTTON);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "gtk-stock-new",
-1);
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_CLEAR,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_CLEAR,
+ GTK_ICON_SIZE_BUTTON);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "separator",
-1);
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_OPEN,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_OPEN,
+ GTK_ICON_SIZE_BUTTON);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
store = gtk_list_store_new (2, GDK_TYPE_PIXBUF, G_TYPE_STRING);
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_DIALOG_WARNING,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_DIALOG_WARNING,
+ GTK_ICON_SIZE_BUTTON);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "gtk-stock-dialog-warning",
-1);
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_STOP,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_STOP,
+ GTK_ICON_SIZE_BUTTON);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "gtk-stock-stop",
-1);
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_NEW,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_NEW,
+ GTK_ICON_SIZE_BUTTON);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "gtk-stock-new",
-1);
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_CLEAR,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_CLEAR,
+ GTK_ICON_SIZE_BUTTON);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
1, "separator",
-1);
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_OPEN,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_OPEN,
+ GTK_ICON_SIZE_BUTTON);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, pixbuf,
return GTK_TREE_MODEL (store);
}
+
+static GtkTreeModel *
+create_list_long (void)
+{
+ GtkTreeIter iter;
+ GtkListStore *store;
+
+ store = gtk_list_store_new (1, G_TYPE_STRING);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, "here is some long long text that grows out of the combo's allocation",
+ -1);
+
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, "with at least a few of these rows",
+ -1);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, "so that we can get some ellipsized text here",
+ -1);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, "and see the combo box menu being allocated without any constraints",
+ -1);
+
+ return GTK_TREE_MODEL (store);
+}
+
+static GtkTreeModel *
+create_food_list (void)
+{
+ GtkTreeIter iter;
+ GtkListStore *store;
+
+ store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, "Pepperoni",
+ 1, "Pizza",
+ -1);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, "Cheese",
+ 1, "Burger",
+ -1);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, "Pineapple",
+ 1, "Milkshake",
+ -1);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, "Orange",
+ 1, "Soda",
+ -1);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, "Club",
+ 1, "Sandwich",
+ -1);
+
+ return GTK_TREE_MODEL (store);
+}
+
+
/* blaat */
static GtkTreeModel *
create_phylogenetic_tree (void)
}
static void
-setup_combo_entry (GtkWidget *entry_box)
+setup_combo_entry (GtkComboBoxText *combo)
{
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"dum de dum");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"la la la");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"la la la dum de dum la la la la la la boom de da la la");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"bloop");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"bleep");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaas");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaas0");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaas1");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaas2");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaas3");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaas4");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaas5");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaas6");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaas7");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaas8");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaas9");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaasa");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaasb");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaasc");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaasd");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaase");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaasf");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaas10");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaas11");
- gtk_combo_box_append_text (GTK_COMBO_BOX (entry_box),
+ gtk_combo_box_text_append_text (combo,
"klaas12");
}
GtkTreeModel *model;
GtkTreePath *path;
GtkTreeIter iter;
- GdkColor color;
- GtkListStore *store;
+ GdkRGBA color;
+ GtkCellArea *area;
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_vbox_new (FALSE, 2);
+ 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_vbox_new (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 ();
- pixbuf = gtk_widget_render_icon (cellview, GTK_STOCK_DIALOG_WARNING,
- GTK_ICON_SIZE_BUTTON, NULL);
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, GTK_STOCK_DIALOG_WARNING,
+ GTK_ICON_SIZE_BUTTON);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cellview),
renderer,
tmp = gtk_frame_new ("GtkComboBox (list)");
gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0);
- boom = gtk_vbox_new (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);
tmp = gtk_frame_new ("GtkComboBox (dynamic list)");
gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0);
- boom = gtk_vbox_new (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);
tmp = gtk_frame_new ("GtkComboBox (custom)");
gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0);
- boom = gtk_vbox_new (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);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (tmp), renderer,
"text", 1,
NULL);
- color.red = 0xffff;
- color.blue = 0xffff;
+ color.red = 1.0;
+ color.blue = 1.0;
color.green = 0;
- gtk_cell_view_set_background_color (GTK_CELL_VIEW (tmp), &color);
+ 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);
tmp = gtk_frame_new ("GtkComboBox (tree)");
gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0);
- boom = gtk_vbox_new (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);
tmp = gtk_frame_new ("GtkComboBox (grid mode)");
gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0);
- boom = gtk_vbox_new (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);
tmp = gtk_frame_new ("GtkComboBox with entry");
gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0);
- boom = gtk_vbox_new (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);
- store = gtk_list_store_new (1, G_TYPE_STRING);
- comboboxtext = g_object_new (GTK_TYPE_COMBO_BOX,
- "has-entry", TRUE,
- "model", store,
- "entry-text-column", 0,
- NULL);
- g_object_unref (store);
-
- setup_combo_entry (comboboxtext);
+ comboboxtext = gtk_combo_box_text_new_with_entry ();
+ setup_combo_entry (GTK_COMBO_BOX_TEXT (comboboxtext));
gtk_container_add (GTK_CONTAINER (boom), comboboxtext);
tmp = gtk_frame_new ("What are you ?");
gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0);
- boom = gtk_vbox_new (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);
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_vbox_new (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);
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);
+
gtk_widget_show_all (window);
gtk_main ();