diff options
author | Matthias Clasen <mclasen@redhat.com> | 2016-06-19 23:54:07 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2016-06-19 23:54:07 -0400 |
commit | e01f35ef5f6d4520cc8e10ce284348ca542f2b89 (patch) | |
tree | 5d16925129c29f6853a22cc910093d52822f1ce2 /demos | |
parent | 8a2812217b9fbf92bfe2ad287f188fed9fe3e1e8 (diff) | |
download | gtk+-e01f35ef5f6d4520cc8e10ce284348ca542f2b89.tar.gz |
gtk3-demo: Make the filter model example more interesting
Allow editing values in the first treeview, to see the derived
models update in real time.
Diffstat (limited to 'demos')
-rw-r--r-- | demos/gtk-demo/filtermodel.c | 30 | ||||
-rw-r--r-- | demos/gtk-demo/filtermodel.ui | 16 |
2 files changed, 43 insertions, 3 deletions
diff --git a/demos/gtk-demo/filtermodel.c b/demos/gtk-demo/filtermodel.c index bca6674fa6..bb8ed45920 100644 --- a/demos/gtk-demo/filtermodel.c +++ b/demos/gtk-demo/filtermodel.c @@ -6,6 +6,7 @@ */ #include <gtk/gtk.h> +#include <stdlib.h> enum { WIDTH_COLUMN, @@ -83,6 +84,28 @@ visible_func (GtkTreeModel *model, return width < 10; } +static void +cell_edited (GtkCellRendererSpin *cell, + const char *path_string, + const char *new_text, + GtkListStore *store) +{ + int val; + GtkTreePath *path; + GtkTreeIter iter; + int column; + + path = gtk_tree_path_new_from_string (path_string); + gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path); + gtk_tree_path_free (path); + + column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column")); + + val = atoi (new_text); + + gtk_list_store_set (store, &iter, column, val, -1); +} + GtkWidget * do_filtermodel (GtkWidget *do_widget) { @@ -106,15 +129,21 @@ do_filtermodel (GtkWidget *do_widget) g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window); + store = (GtkListStore*)gtk_builder_get_object (builder, "liststore1"); + column = (GtkTreeViewColumn*)gtk_builder_get_object (builder, "treeviewcolumn1"); cell = (GtkCellRenderer*)gtk_builder_get_object (builder, "cellrenderertext1"); gtk_tree_view_column_set_cell_data_func (column, cell, format_number, GINT_TO_POINTER (WIDTH_COLUMN), NULL); + g_object_set_data (G_OBJECT (cell), "column", GINT_TO_POINTER (WIDTH_COLUMN)); + g_signal_connect (cell, "edited", G_CALLBACK (cell_edited), store); column = (GtkTreeViewColumn*)gtk_builder_get_object (builder, "treeviewcolumn2"); cell = (GtkCellRenderer*)gtk_builder_get_object (builder, "cellrenderertext2"); gtk_tree_view_column_set_cell_data_func (column, cell, format_number, GINT_TO_POINTER (HEIGHT_COLUMN), NULL); + g_object_set_data (G_OBJECT (cell), "column", GINT_TO_POINTER (HEIGHT_COLUMN)); + g_signal_connect (cell, "edited", G_CALLBACK (cell_edited), store); column = (GtkTreeViewColumn*)gtk_builder_get_object (builder, "treeviewcolumn3"); cell = (GtkCellRenderer*)gtk_builder_get_object (builder, "cellrenderertext3"); @@ -135,7 +164,6 @@ do_filtermodel (GtkWidget *do_widget) cell = (GtkCellRenderer*)gtk_builder_get_object (builder, "cellrendererpixbuf1"); gtk_tree_view_column_add_attribute (column, cell, "visible", SQUARE_COLUMN); - store = (GtkListStore*)gtk_builder_get_object (builder, "liststore1"); tree = (GtkWidget*)gtk_builder_get_object (builder, "treeview2"); types[WIDTH_COLUMN] = G_TYPE_INT; diff --git a/demos/gtk-demo/filtermodel.ui b/demos/gtk-demo/filtermodel.ui index 2b6c571004..3b39095bd6 100644 --- a/demos/gtk-demo/filtermodel.ui +++ b/demos/gtk-demo/filtermodel.ui @@ -24,6 +24,12 @@ </row> </data> </object> + <object class="GtkAdjustment" id="adj"> + <property name="lower">5</property> + <property name="upper">50</property> + <property name="step-increment">1</property> + <property name="page-increment">5</property> + </object> <object class="GtkWindow" id="window1"> <property name="title" translatable="yes">Filter Model</property> <child> @@ -63,7 +69,10 @@ <object class="GtkTreeViewColumn" id="treeviewcolumn1"> <property name="title" translatable="yes">Width</property> <child> - <object class="GtkCellRendererText" id="cellrenderertext1"/> + <object class="GtkCellRendererSpin" id="cellrenderertext1"> + <property name="editable">1</property> + <property name="adjustment">adj</property> + </object> </child> </object> </child> @@ -71,7 +80,10 @@ <object class="GtkTreeViewColumn" id="treeviewcolumn2"> <property name="title" translatable="yes">Height</property> <child> - <object class="GtkCellRendererText" id="cellrenderertext2"/> + <object class="GtkCellRendererSpin" id="cellrenderertext2"> + <property name="editable">1</property> + <property name="adjustment">adj</property> + </object> </child> </object> </child> |