Commit 4aebf932 authored by Kristian Rietveld's avatar Kristian Rietveld Committed by Kristian Rietveld

fix a load of open line ends (cell_edited): modified patch from German Poo

Sat Jan 19 20:49:41 2002  Kristian Rietveld  <kris@gtk.org>

        * demos/gtk-demo/editable_cells.c: fix a load of open line ends
        (cell_edited): modified patch from German Poo Caaman~o
        to fix up old_text declaration and free the memory
        (do_editable_cells): unref the model after creating the treeview

        * demos/gtk-demo/list_store.c: fix a load of open line ends,
        (add_columns): set the sort column id, so we can sort

        * demos/gtk-demo/tree_store.c: fix a load of open line ends,
        (do_tree_store): unref the model after creating the treeview
parent 31283d57
Sat Jan 19 20:49:41 2002 Kristian Rietveld <kris@gtk.org>
* demos/gtk-demo/editable_cells.c: fix a load of open line ends
(cell_edited): modified patch from German Poo Caaman~o
to fix up old_text declaration and free the memory
(do_editable_cells): unref the model after creating the treeview
* demos/gtk-demo/list_store.c: fix a load of open line ends,
(add_columns): set the sort column id, so we can sort
* demos/gtk-demo/tree_store.c: fix a load of open line ends,
(do_tree_store): unref the model after creating the treeview
2002-01-19 Havoc Pennington <hp@pobox.com>
* gtk/gtkwindow.c: link to new X11 section in a lot of places when
......
Sat Jan 19 20:49:41 2002 Kristian Rietveld <kris@gtk.org>
* demos/gtk-demo/editable_cells.c: fix a load of open line ends
(cell_edited): modified patch from German Poo Caaman~o
to fix up old_text declaration and free the memory
(do_editable_cells): unref the model after creating the treeview
* demos/gtk-demo/list_store.c: fix a load of open line ends,
(add_columns): set the sort column id, so we can sort
* demos/gtk-demo/tree_store.c: fix a load of open line ends,
(do_tree_store): unref the model after creating the treeview
2002-01-19 Havoc Pennington <hp@pobox.com>
* gtk/gtkwindow.c: link to new X11 section in a lot of places when
......
Sat Jan 19 20:49:41 2002 Kristian Rietveld <kris@gtk.org>
* demos/gtk-demo/editable_cells.c: fix a load of open line ends
(cell_edited): modified patch from German Poo Caaman~o
to fix up old_text declaration and free the memory
(do_editable_cells): unref the model after creating the treeview
* demos/gtk-demo/list_store.c: fix a load of open line ends,
(add_columns): set the sort column id, so we can sort
* demos/gtk-demo/tree_store.c: fix a load of open line ends,
(do_tree_store): unref the model after creating the treeview
2002-01-19 Havoc Pennington <hp@pobox.com>
* gtk/gtkwindow.c: link to new X11 section in a lot of places when
......
Sat Jan 19 20:49:41 2002 Kristian Rietveld <kris@gtk.org>
* demos/gtk-demo/editable_cells.c: fix a load of open line ends
(cell_edited): modified patch from German Poo Caaman~o
to fix up old_text declaration and free the memory
(do_editable_cells): unref the model after creating the treeview
* demos/gtk-demo/list_store.c: fix a load of open line ends,
(add_columns): set the sort column id, so we can sort
* demos/gtk-demo/tree_store.c: fix a load of open line ends,
(do_tree_store): unref the model after creating the treeview
2002-01-19 Havoc Pennington <hp@pobox.com>
* gtk/gtkwindow.c: link to new X11 section in a lot of places when
......
Sat Jan 19 20:49:41 2002 Kristian Rietveld <kris@gtk.org>
* demos/gtk-demo/editable_cells.c: fix a load of open line ends
(cell_edited): modified patch from German Poo Caaman~o
to fix up old_text declaration and free the memory
(do_editable_cells): unref the model after creating the treeview
* demos/gtk-demo/list_store.c: fix a load of open line ends,
(add_columns): set the sort column id, so we can sort
* demos/gtk-demo/tree_store.c: fix a load of open line ends,
(do_tree_store): unref the model after creating the treeview
2002-01-19 Havoc Pennington <hp@pobox.com>
* gtk/gtkwindow.c: link to new X11 section in a lot of places when
......
Sat Jan 19 20:49:41 2002 Kristian Rietveld <kris@gtk.org>
* demos/gtk-demo/editable_cells.c: fix a load of open line ends
(cell_edited): modified patch from German Poo Caaman~o
to fix up old_text declaration and free the memory
(do_editable_cells): unref the model after creating the treeview
* demos/gtk-demo/list_store.c: fix a load of open line ends,
(add_columns): set the sort column id, so we can sort
* demos/gtk-demo/tree_store.c: fix a load of open line ends,
(do_tree_store): unref the model after creating the treeview
2002-01-19 Havoc Pennington <hp@pobox.com>
* gtk/gtkwindow.c: link to new X11 section in a lot of places when
......
Sat Jan 19 20:49:41 2002 Kristian Rietveld <kris@gtk.org>
* demos/gtk-demo/editable_cells.c: fix a load of open line ends
(cell_edited): modified patch from German Poo Caaman~o
to fix up old_text declaration and free the memory
(do_editable_cells): unref the model after creating the treeview
* demos/gtk-demo/list_store.c: fix a load of open line ends,
(add_columns): set the sort column id, so we can sort
* demos/gtk-demo/tree_store.c: fix a load of open line ends,
(do_tree_store): unref the model after creating the treeview
2002-01-19 Havoc Pennington <hp@pobox.com>
* gtk/gtkwindow.c: link to new X11 section in a lot of places when
......
/* Tree View/Editable Cells
*
*
* This demo demonstrates the use of editable cells in a GtkTreeView. If
* you're new to the GtkTreeView widgets and associates, look into
* the GtkListStore example first.
......@@ -72,7 +72,7 @@ create_model (void)
/* create array */
articles = g_array_sized_new (FALSE, FALSE, sizeof (Item), 1);
add_items ();
/* create list store */
......@@ -131,11 +131,11 @@ remove_item (GtkWidget *widget, gpointer data)
{
gint i;
GtkTreePath *path;
path = gtk_tree_model_get_path (model, &iter);
i = gtk_tree_path_get_indices (path)[0];
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
g_array_remove_index (articles, i);
gtk_tree_path_free (path);
......@@ -151,39 +151,41 @@ cell_edited (GtkCellRendererText *cell,
GtkTreeModel *model = (GtkTreeModel *)data;
GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
GtkTreeIter iter;
gchar old_text[256]; /* ugly? */
gint *column;
column = g_object_get_data (G_OBJECT (cell), "column");
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, column, old_text, -1);
switch ((gint) column)
{
case COLUMN_NUMBER:
{
gint i;
i = gtk_tree_path_get_indices (path)[0];
g_array_index (articles, Item, i).number = atoi (new_text);
gtk_list_store_set (GTK_LIST_STORE (model), &iter, column,
atoi (new_text), -1);
g_array_index (articles, Item, i).number, -1);
}
break;
case COLUMN_PRODUCT:
{
gint i;
gchar *old_text;
gtk_tree_model_get (model, &iter, column, &old_text, -1);
g_free (old_text);
i = gtk_tree_path_get_indices (path)[0];
g_free (g_array_index (articles, Item, i).product);
g_array_index (articles, Item, i).product = g_strdup (new_text);
gtk_list_store_set (GTK_LIST_STORE (model), &iter, column,
new_text, -1);
g_array_index (articles, Item, i).product, -1);
}
break;
}
......@@ -214,7 +216,7 @@ add_columns (GtkTreeView *treeview)
g_signal_connect (G_OBJECT (renderer), "edited",
G_CALLBACK (cell_edited), model);
g_object_set_data (G_OBJECT (renderer), "column", (gint *)COLUMN_PRODUCT);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
-1, "Product", renderer,
"text", COLUMN_PRODUCT,
......@@ -233,7 +235,7 @@ do_editable_cells (void)
GtkWidget *treeview;
GtkWidget *button;
GtkTreeModel *model;
/* create window, etc */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Shopping list");
......@@ -261,14 +263,15 @@ do_editable_cells (void)
/* create tree view */
treeview = gtk_tree_view_new_with_model (model);
g_object_unref (G_OBJECT (model));
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
GTK_SELECTION_SINGLE);
add_columns (GTK_TREE_VIEW (treeview));
gtk_container_add (GTK_CONTAINER (sw), treeview);
/* some buttons */
hbox = gtk_hbox_new (TRUE, 4);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
......@@ -285,7 +288,7 @@ do_editable_cells (void)
gtk_window_set_default_size (GTK_WINDOW (window), 320, 200);
}
if (!GTK_WIDGET_VISIBLE (window))
gtk_widget_show_all (window);
else
......
/* Tree View/List Store
*
* The GtkListStore is used to store data in list form, to be used
* The GtkListStore is used to store data in list form, to be used
* later on by a GtkTreeView to display it. This demo builds a
* simple GtkListStore and displays it. See the Stock Browser
* demo for a more advanced example.
......@@ -92,10 +92,10 @@ fixed_toggled (GtkCellRendererToggle *cell,
/* do something with the value */
fixed ^= 1;
/* set new value */
gtk_list_store_set (GTK_LIST_STORE (model), &iter, COLUMN_FIXED, fixed, -1);
/* clean up */
gtk_tree_path_free (path);
}
......@@ -130,8 +130,9 @@ add_columns (GtkTreeView *treeview)
"text",
COLUMN_NUMBER,
NULL);
gtk_tree_view_column_set_sort_column_id (column, COLUMN_NUMBER);
gtk_tree_view_append_column (treeview, column);
/* column for severities */
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Severity",
......@@ -139,8 +140,9 @@ add_columns (GtkTreeView *treeview)
"text",
COLUMN_SEVERITY,
NULL);
gtk_tree_view_column_set_sort_column_id (column, COLUMN_SEVERITY);
gtk_tree_view_append_column (treeview, column);
/* column for description */
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Description",
......@@ -148,6 +150,7 @@ add_columns (GtkTreeView *treeview)
"text",
COLUMN_DESCRIPTION,
NULL);
gtk_tree_view_column_set_sort_column_id (column, COLUMN_DESCRIPTION);
gtk_tree_view_append_column (treeview, column);
}
......@@ -183,7 +186,7 @@ do_list_store (void)
GTK_POLICY_NEVER,
GTK_POLICY_AUTOMATIC);
gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
/* create tree model */
model = create_model ();
......@@ -194,9 +197,9 @@ do_list_store (void)
COLUMN_DESCRIPTION);
g_object_unref (G_OBJECT (model));
gtk_container_add (GTK_CONTAINER (sw), treeview);
/* add columns to the tree view */
add_columns (GTK_TREE_VIEW (treeview));
......
......@@ -2,7 +2,7 @@
*
* The GtkTreeStore is used to store data in tree form, to be
* used later on by a GtkTreeView to display it. This demo builds
* a simple GtkTreeStore and displays it. If you're new to the
* a simple GtkTreeStore and displays it. If you're new to the
* GtkTreeView widgets and associates, look into the GtkListStore
* example first.
*
......@@ -46,7 +46,7 @@ static TreeItem january[] =
{
{"New Years Day", TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, NULL },
{"Presidential Inauguration", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
{"Martin Luther King Jr. day", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
{"Martin Luther King Jr. day", FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, NULL },
{ NULL }
};
......@@ -116,7 +116,7 @@ static TreeItem september[] =
static TreeItem october[] =
{
{ "National Children's Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
{ "National Children's Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
{ "Bosses' Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
{ "Sweetest Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
{ "Mother-in-Law's Day", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL },
......@@ -200,7 +200,7 @@ create_model (void)
while (holiday->label)
{
GtkTreeIter child_iter;
gtk_tree_store_append (model, &child_iter, &iter);
gtk_tree_store_set (model, &child_iter,
HOLIDAY_NAME_COLUMN, holiday->label,
......@@ -212,7 +212,7 @@ create_model (void)
VISIBLE_COLUMN, TRUE,
WORLD_COLUMN, holiday->world_holiday,
-1);
holiday++;
}
......@@ -235,7 +235,7 @@ item_toggled (GtkCellRendererToggle *cell,
gint *column;
column = g_object_get_data (G_OBJECT (cell), "column");
/* get toggled iter */
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, column, &toggle_item, -1);
......@@ -287,13 +287,13 @@ add_columns (GtkTreeView *treeview)
VISIBLE_COLUMN,
"activatable",
WORLD_COLUMN, NULL);
column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
/* havoc column */
renderer = gtk_cell_renderer_toggle_new ();
g_object_set (G_OBJECT (renderer), "xalign", 0.0, NULL);
......@@ -309,18 +309,18 @@ add_columns (GtkTreeView *treeview)
"visible",
VISIBLE_COLUMN,
NULL);
column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
/* tim column */
renderer = gtk_cell_renderer_toggle_new ();
g_object_set (G_OBJECT (renderer), "xalign", 0.0, NULL);
g_object_set_data (G_OBJECT (renderer), "column", (gint *)TIM_COLUMN);
g_signal_connect (G_OBJECT (renderer), "toggled", G_CALLBACK (item_toggled),
model);
col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
......@@ -332,18 +332,18 @@ add_columns (GtkTreeView *treeview)
VISIBLE_COLUMN,
"activatable",
WORLD_COLUMN, NULL);
column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
/* owen column */
renderer = gtk_cell_renderer_toggle_new ();
g_object_set (G_OBJECT (renderer), "xalign", 0.0, NULL);
g_object_set_data (G_OBJECT (renderer), "column", (gint *)OWEN_COLUMN);
g_signal_connect (G_OBJECT (renderer), "toggled", G_CALLBACK (item_toggled),
model);
col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
......@@ -354,13 +354,13 @@ add_columns (GtkTreeView *treeview)
"visible",
VISIBLE_COLUMN,
NULL);
column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
/* dave column */
renderer = gtk_cell_renderer_toggle_new ();
g_object_set (G_OBJECT (renderer), "xalign", 0.0, NULL);
......@@ -376,7 +376,7 @@ add_columns (GtkTreeView *treeview)
"visible",
VISIBLE_COLUMN,
NULL);
column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1);
gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
GTK_TREE_VIEW_COLUMN_FIXED);
......@@ -397,17 +397,17 @@ do_tree_store (void)
/* create window, etc */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Card planning sheet");
g_signal_connect (G_OBJECT (window), "destroy",
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
vbox = gtk_vbox_new (FALSE, 8);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_box_pack_start (GTK_BOX (vbox),
gtk_label_new ("Jonathan's Holiday Card Planning Sheet"),
FALSE, FALSE, 0);
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
GTK_SHADOW_ETCHED_IN);
......@@ -418,17 +418,19 @@ do_tree_store (void)
/* create model */
model = create_model ();
/* create tree view */
treeview = gtk_tree_view_new_with_model (model);
g_object_unref (G_OBJECT (model));
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
GTK_SELECTION_MULTIPLE);
add_columns (GTK_TREE_VIEW (treeview));
gtk_container_add (GTK_CONTAINER (sw), treeview);
/* expand all rows after the treeview widget has been realized */
g_signal_connect (G_OBJECT (treeview), "realize",
G_CALLBACK (gtk_tree_view_expand_all), NULL);
gtk_window_set_default_size (GTK_WINDOW (window), 650, 400);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment