summaryrefslogtreecommitdiff
path: root/demos/gtk-demo/combobox.c
diff options
context:
space:
mode:
Diffstat (limited to 'demos/gtk-demo/combobox.c')
-rw-r--r--demos/gtk-demo/combobox.c190
1 files changed, 95 insertions, 95 deletions
diff --git a/demos/gtk-demo/combobox.c b/demos/gtk-demo/combobox.c
index e9bf96ba22..354fcab0d8 100644
--- a/demos/gtk-demo/combobox.c
+++ b/demos/gtk-demo/combobox.c
@@ -1,15 +1,15 @@
-/* Combo boxes
+/* Combo boxes
*
* The ComboBox widget allows to select one option out of a list.
* The ComboBoxEntry additionally allows the user to enter a value
- * that is not in the list of options.
+ * that is not in the list of options.
*
* How the options are displayed is controlled by cell renderers.
*/
#include <gtk/gtk.h>
-enum
+enum
{
PIXBUF_COL,
TEXT_COL
@@ -20,16 +20,16 @@ strip_underscore (const gchar *text)
{
gchar *p, *q;
gchar *result;
-
+
result = g_strdup (text);
p = q = result;
- while (*p)
+ while (*p)
{
if (*p != '_')
- {
- *q = *p;
- q++;
- }
+ {
+ *q = *p;
+ q++;
+ }
p++;
}
*q = '\0';
@@ -46,7 +46,7 @@ create_stock_icon_store (void)
GTK_STOCK_NEW,
GTK_STOCK_CLEAR,
NULL,
- GTK_STOCK_OPEN
+ GTK_STOCK_OPEN
};
GtkStockItem item;
@@ -58,50 +58,50 @@ create_stock_icon_store (void)
gint i;
cellview = gtk_cell_view_new ();
-
+
store = gtk_list_store_new (2, GDK_TYPE_PIXBUF, G_TYPE_STRING);
for (i = 0; i < G_N_ELEMENTS (stock_id); i++)
{
if (stock_id[i])
- {
- pixbuf = gtk_widget_render_icon_pixbuf (cellview, stock_id[i],
- GTK_ICON_SIZE_BUTTON);
- gtk_stock_lookup (stock_id[i], &item);
- label = strip_underscore (item.label);
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- PIXBUF_COL, pixbuf,
- TEXT_COL, label,
- -1);
- g_object_unref (pixbuf);
- g_free (label);
- }
+ {
+ pixbuf = gtk_widget_render_icon_pixbuf (cellview, stock_id[i],
+ GTK_ICON_SIZE_BUTTON);
+ gtk_stock_lookup (stock_id[i], &item);
+ label = strip_underscore (item.label);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ PIXBUF_COL, pixbuf,
+ TEXT_COL, label,
+ -1);
+ g_object_unref (pixbuf);
+ g_free (label);
+ }
else
- {
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- PIXBUF_COL, NULL,
- TEXT_COL, "separator",
- -1);
- }
+ {
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ PIXBUF_COL, NULL,
+ TEXT_COL, "separator",
+ -1);
+ }
}
gtk_widget_destroy (cellview);
-
+
return GTK_TREE_MODEL (store);
}
/* A GtkCellLayoutDataFunc that demonstrates how one can control
- * sensitivity of rows. This particular function does nothing
+ * sensitivity of rows. This particular function does nothing
* useful and just makes the second row insensitive.
*/
static void
set_sensitive (GtkCellLayout *cell_layout,
- GtkCellRenderer *cell,
- GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- gpointer data)
+ GtkCellRenderer *cell,
+ GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ gpointer data)
{
GtkTreePath *path;
gint *indices;
@@ -116,13 +116,13 @@ set_sensitive (GtkCellLayout *cell_layout,
}
/* A GtkTreeViewRowSeparatorFunc that demonstrates how rows can be
- * rendered as separators. This particular function does nothing
+ * rendered as separators. This particular function does nothing
* useful and just turns the fourth row into a separator.
*/
static gboolean
is_separator (GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
+ GtkTreeIter *iter,
+ gpointer data)
{
GtkTreePath *path;
gboolean result;
@@ -141,11 +141,11 @@ create_capital_store (void)
gchar *group;
gchar *capital;
} capitals[] = {
- { "A - B", NULL },
+ { "A - B", NULL },
{ NULL, "Albany" },
{ NULL, "Annapolis" },
{ NULL, "Atlanta" },
- { NULL, "Augusta" },
+ { NULL, "Augusta" },
{ NULL, "Austin" },
{ NULL, "Baton Rouge" },
{ NULL, "Bismarck" },
@@ -199,36 +199,36 @@ create_capital_store (void)
{ NULL, "Trenton" },
{ NULL, NULL }
};
-
+
GtkTreeIter iter, iter2;
GtkTreeStore *store;
gint i;
store = gtk_tree_store_new (1, G_TYPE_STRING);
-
+
for (i = 0; capitals[i].group || capitals[i].capital; i++)
{
if (capitals[i].group)
- {
- gtk_tree_store_append (store, &iter, NULL);
- gtk_tree_store_set (store, &iter, 0, capitals[i].group, -1);
- }
+ {
+ gtk_tree_store_append (store, &iter, NULL);
+ gtk_tree_store_set (store, &iter, 0, capitals[i].group, -1);
+ }
else if (capitals[i].capital)
- {
- gtk_tree_store_append (store, &iter2, &iter);
- gtk_tree_store_set (store, &iter2, 0, capitals[i].capital, -1);
- }
+ {
+ gtk_tree_store_append (store, &iter2, &iter);
+ gtk_tree_store_set (store, &iter2, 0, capitals[i].capital, -1);
+ }
}
-
+
return GTK_TREE_MODEL (store);
}
static void
is_capital_sensitive (GtkCellLayout *cell_layout,
- GtkCellRenderer *cell,
- GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- gpointer data)
+ GtkCellRenderer *cell,
+ GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ gpointer data)
{
gboolean sensitive;
@@ -274,8 +274,8 @@ struct _MaskEntryClass
static void mask_entry_editable_init (GtkEditableInterface *iface);
G_DEFINE_TYPE_WITH_CODE (MaskEntry, mask_entry, GTK_TYPE_ENTRY,
- G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
- mask_entry_editable_init));
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
+ mask_entry_editable_init));
static void
@@ -286,10 +286,10 @@ mask_entry_set_background (MaskEntry *entry)
if (entry->mask)
{
if (!g_regex_match_simple (entry->mask, gtk_entry_get_text (GTK_ENTRY (entry)), 0, 0))
- {
- gtk_widget_override_color (GTK_WIDGET (entry), 0, &error_color);
- return;
- }
+ {
+ gtk_widget_override_color (GTK_WIDGET (entry), 0, &error_color);
+ return;
+ }
}
gtk_widget_override_color (GTK_WIDGET (entry), 0, NULL);
@@ -338,58 +338,58 @@ do_combobox (GtkWidget *do_widget)
gtk_window_set_screen (GTK_WINDOW (window),
gtk_widget_get_screen (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Combo boxes");
-
+
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&window);
-
+
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
gtk_container_add (GTK_CONTAINER (window), vbox);
/* A combobox demonstrating cell renderers, separators and
- * insensitive rows
+ * insensitive rows
*/
frame = gtk_frame_new ("Some stock icons");
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
-
+
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_set_border_width (GTK_CONTAINER (box), 5);
gtk_container_add (GTK_CONTAINER (frame), box);
-
+
model = create_stock_icon_store ();
combo = gtk_combo_box_new_with_model (model);
g_object_unref (model);
gtk_container_add (GTK_CONTAINER (box), combo);
-
+
renderer = gtk_cell_renderer_pixbuf_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer,
- "pixbuf", PIXBUF_COL,
- NULL);
+ "pixbuf", PIXBUF_COL,
+ NULL);
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo),
- renderer,
- set_sensitive,
- NULL, NULL);
-
+ renderer,
+ set_sensitive,
+ NULL, NULL);
+
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer,
- "text", TEXT_COL,
- NULL);
+ "text", TEXT_COL,
+ NULL);
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo),
- renderer,
- set_sensitive,
- NULL, NULL);
+ renderer,
+ set_sensitive,
+ NULL, NULL);
+
+ gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
+ is_separator, NULL, NULL);
- gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
- is_separator, NULL, NULL);
-
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
-
+
/* A combobox demonstrating trees.
*/
frame = gtk_frame_new ("Where are we ?");
@@ -398,7 +398,7 @@ do_combobox (GtkWidget *do_widget)
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_set_border_width (GTK_CONTAINER (box), 5);
gtk_container_add (GTK_CONTAINER (frame), box);
-
+
model = create_capital_store ();
combo = gtk_combo_box_new_with_model (model);
g_object_unref (model);
@@ -407,12 +407,12 @@ do_combobox (GtkWidget *do_widget)
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer,
- "text", 0,
- NULL);
+ "text", 0,
+ NULL);
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo),
- renderer,
- is_capital_sensitive,
- NULL, NULL);
+ renderer,
+ is_capital_sensitive,
+ NULL, NULL);
path = gtk_tree_path_new_from_indices (0, 8, -1);
gtk_tree_model_get_iter (model, &iter, path);
@@ -423,18 +423,18 @@ do_combobox (GtkWidget *do_widget)
*/
frame = gtk_frame_new ("Editable");
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
-
+
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_set_border_width (GTK_CONTAINER (box), 5);
gtk_container_add (GTK_CONTAINER (frame), box);
-
+
combo = gtk_combo_box_text_new_with_entry ();
fill_combo_entry (combo);
gtk_container_add (GTK_CONTAINER (box), combo);
-
+
entry = g_object_new (TYPE_MASK_ENTRY, NULL);
MASK_ENTRY (entry)->mask = "^([0-9]*|One|Two|2\302\275|Three)$";
-
+
gtk_container_remove (GTK_CONTAINER (combo), gtk_bin_get_child (GTK_BIN (combo)));
gtk_container_add (GTK_CONTAINER (combo), entry);
@@ -464,7 +464,7 @@ do_combobox (GtkWidget *do_widget)
gtk_widget_show_all (window);
}
else
- {
+ {
gtk_widget_destroy (window);
window = NULL;
}