diff options
author | Jonathan Blandford <jrb@redhat.com> | 2001-09-25 16:44:39 +0000 |
---|---|---|
committer | Jonathan Blandford <jrb@src.gnome.org> | 2001-09-25 16:44:39 +0000 |
commit | 92841cb95add212c35b2ef58129f043c33676c52 (patch) | |
tree | a58a60c4bc75ea3f716bfd59d3c193cf417fc5f4 /tests | |
parent | 8a2d408daed1b616ab760cdfeec050cb6e54c1de (diff) | |
download | gdk-pixbuf-92841cb95add212c35b2ef58129f043c33676c52.tar.gz |
Make a GtkCellEditable (get_widget_window_size): Change to let it honor
Tue Sep 25 12:34:42 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkentry.c: Make a GtkCellEditable
(get_widget_window_size): Change to let it honor size_allocate
when a CellEditable.
* gtk/gtktreeview.c: M-x clean-line-ends. Lots of focus and
editable changes.
(gtk_tree_view_set_cursor): Now you can set the cursor
horizontally, as well as start editing.
* gtk/gtkstyle.c (gtk_default_draw_check): changing toggle drawing
code to look more like the other check buttons.
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_get_size):
Change the way we calculate cell size.
* gtk/gtkmarshal.list (VOID:STRING,STRING): new marshaller.
* demos/gtk-demo/sizegroup.c: Add mnemonics.
* gtk/gtkcellrenderer.c (gtk_cell_renderer_get_size): Fix docs.
Fix logic.
* gtk/gtkcellrenderertext.c: Change to be editable.
* gtk/gtkcellrenderertoggle.c: Change to be activatable.
* test/testtreesort.c: Fix misspelling
* test/testreecolumns.c: Add mnemonics.
* test/testreeedit.c: New test program.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 6 | ||||
-rw-r--r-- | tests/testtreecolumns.c | 8 | ||||
-rw-r--r-- | tests/testtreeedit.c | 140 | ||||
-rw-r--r-- | tests/testtreefocus.c | 4 | ||||
-rw-r--r-- | tests/testtreesort.c | 2 |
5 files changed, 153 insertions, 7 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index ddb04fb83..44512c061 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -35,6 +35,7 @@ noinst_PROGRAMS = \ $(testsocket_programs) \ testtext \ testtextbuffer \ + testtreeedit \ testtreeview \ testtreefocus \ testtreecolumns \ @@ -52,6 +53,7 @@ testsocket_DEPENDENCIES = $(DEPS) testsocket_child_DEPENDENCIES = $(DEPS) testtext_DEPENDENCIES = $(TEST_DEPS) testtextbuffer_DEPENDENCIES = $(TEST_DEPS) +testtreeedit_DEPENDENCIS = $(DEPS) testtreeview_DEPENDENCIES = $(DEPS) testtreefocus_DEPENDENCIES = $(DEPS) testtreecolumns_DEPENDENCIES = $(DEPS) @@ -68,6 +70,7 @@ testselection_LDADD = $(LDADDS) testsocket_LDADD = $(LDADDS) testsocket_child_LDADD = $(LDADDS) testtextbuffer_LDADD = $(LDADDS) +testtreeedit_LDADD = $(LDADDS) testtreeview_LDADD = $(LDADDS) testtreefocus_LDADD = $(LDADDS) testtreecolumns_LDADD = $(LDADDS) @@ -79,6 +82,9 @@ testgtk_SOURCES = \ prop-editor.c \ testgtk.c +testtreeedit_SOURCES = \ + testtreeedit.c + testtreeview_SOURCES = \ prop-editor.c \ testtreeview.c diff --git a/tests/testtreecolumns.c b/tests/testtreecolumns.c index f0468ca6a..c57eb0755 100644 --- a/tests/testtreecolumns.c +++ b/tests/testtreecolumns.c @@ -620,14 +620,14 @@ main (int argc, char *argv[]) gtk_button_box_set_child_size (GTK_BUTTON_BOX (bbox), 0, 0); gtk_box_pack_start (GTK_BOX (vbox2), bbox, TRUE, TRUE, 0); - button = gtk_button_new_with_label ("<<"); + button = gtk_button_new_with_mnemonic ("<< (_Q)"); gtk_widget_set_sensitive (button, FALSE); gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (add_left_clicked), top_right_tree_view); g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (top_right_tree_view))), "changed", GTK_SIGNAL_FUNC (selection_changed), button); gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0); - button = gtk_button_new_with_label (">>"); + button = gtk_button_new_with_mnemonic (">> (_W)"); gtk_widget_set_sensitive (button, FALSE); gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (add_right_clicked), top_right_tree_view); g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (left_tree_view))), @@ -639,14 +639,14 @@ main (int argc, char *argv[]) gtk_button_box_set_child_size (GTK_BUTTON_BOX (bbox), 0, 0); gtk_box_pack_start (GTK_BOX (vbox2), bbox, TRUE, TRUE, 0); - button = gtk_button_new_with_label ("<<"); + button = gtk_button_new_with_mnemonic ("<< (_E)"); gtk_widget_set_sensitive (button, FALSE); gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (add_left_clicked), bottom_right_tree_view); g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (bottom_right_tree_view))), "changed", GTK_SIGNAL_FUNC (selection_changed), button); gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0); - button = gtk_button_new_with_label (">>"); + button = gtk_button_new_with_mnemonic (">> (_R)"); gtk_widget_set_sensitive (button, FALSE); gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (add_right_clicked), bottom_right_tree_view); g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (left_tree_view))), diff --git a/tests/testtreeedit.c b/tests/testtreeedit.c new file mode 100644 index 000000000..c9f595062 --- /dev/null +++ b/tests/testtreeedit.c @@ -0,0 +1,140 @@ +#include <gtk/gtk.h> + +typedef struct { + const gchar *string; + gboolean is_editable; +} ListEntry; + +enum { + STRING_COLUMN, + IS_EDITABLE_COLUMN, + NUM_COLUMNS +}; + +static ListEntry model_strings[] = +{ + {"A simple string", TRUE }, + {"Another string!", TRUE }, + {"Guess what, a third string. This one can't be edited", FALSE }, + {"And then a fourth string. Neither can this", FALSE }, + {"Multiline\nFun!", TRUE }, + { NULL } +}; + +static GtkTreeModel * +create_model (void) +{ + GtkListStore *model; + GtkTreeIter iter; + gint i; + + model = gtk_list_store_new (NUM_COLUMNS, + G_TYPE_STRING, + G_TYPE_BOOLEAN); + + for (i = 0; model_strings[i].string != NULL; i++) + { + gtk_list_store_append (model, &iter); + + gtk_list_store_set (model, &iter, + STRING_COLUMN, model_strings[i].string, + IS_EDITABLE_COLUMN, model_strings[i].is_editable, + -1); + } + + return GTK_TREE_MODEL (model); +} + +static void +toggled (GtkCellRendererToggle *cell, + gchar *path_string, + gpointer data) +{ + GtkTreeModel *model = GTK_TREE_MODEL (data); + GtkTreeIter iter; + GtkTreePath *path = gtk_tree_path_new_from_string (path_string); + gboolean value; + + gtk_tree_model_get_iter (model, &iter, path); + gtk_tree_model_get (model, &iter, IS_EDITABLE_COLUMN, &value, -1); + + value = !value; + gtk_list_store_set (GTK_LIST_STORE (model), &iter, IS_EDITABLE_COLUMN, value, -1); + + gtk_tree_path_free (path); +} + +static void +edited (GtkCellRendererText *cell, + gchar *path_string, + gchar *new_text, + gpointer data) +{ + GtkTreeModel *model = GTK_TREE_MODEL (data); + GtkTreeIter iter; + GtkTreePath *path = gtk_tree_path_new_from_string (path_string); + + gtk_tree_model_get_iter (model, &iter, path); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, STRING_COLUMN, new_text, -1); + + gtk_tree_path_free (path); +} + +gint +main (gint argc, gchar **argv) +{ + GtkWidget *window; + GtkWidget *scrolled_window; + GtkWidget *tree_view; + GtkTreeModel *tree_model; + GtkCellRenderer *renderer; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window), "GtkTreeView editing sample"); + gtk_signal_connect (GTK_OBJECT (window), "destroy", gtk_main_quit, NULL); + + scrolled_window = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_container_add (GTK_CONTAINER (window), scrolled_window); + + tree_model = create_model (); + tree_view = gtk_tree_view_new_with_model (tree_model); + gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE); + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE); + + renderer = gtk_cell_renderer_text_new (); + gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view), + -1, "String", + renderer, + "text", STRING_COLUMN, + "editable", IS_EDITABLE_COLUMN, + NULL); + + g_signal_connect (G_OBJECT (renderer), "edited", + G_CALLBACK (edited), tree_model); + renderer = gtk_cell_renderer_toggle_new (); + g_signal_connect (G_OBJECT (renderer), "toggled", + G_CALLBACK (toggled), tree_model); + + g_object_set (G_OBJECT (renderer), + "xalign", 0.0, + "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, + NULL); + gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view), + -1, "Editable", + renderer, + "active", IS_EDITABLE_COLUMN, + NULL); + gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view); + + gtk_window_set_default_size (GTK_WINDOW (window), + 650, 400); + + gtk_widget_show_all (window); + gtk_main (); + + return 0; +} diff --git a/tests/testtreefocus.c b/tests/testtreefocus.c index 08a3207c4..ca5afd318 100644 --- a/tests/testtreefocus.c +++ b/tests/testtreefocus.c @@ -348,7 +348,7 @@ main (int argc, char *argv[]) renderer, "active", ALEX_COLUMN, "visible", VISIBLE_COLUMN, - "can_activate", WORLD_COLUMN, + "activatable", WORLD_COLUMN, NULL); column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1); gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED); @@ -381,7 +381,7 @@ main (int argc, char *argv[]) renderer, "active", TIM_COLUMN, "visible", VISIBLE_COLUMN, - "can_activate", WORLD_COLUMN, + "activatable", WORLD_COLUMN, NULL); column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1); gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED); diff --git a/tests/testtreesort.c b/tests/testtreesort.c index b9f285efa..0dba6d29c 100644 --- a/tests/testtreesort.c +++ b/tests/testtreesort.c @@ -12,7 +12,7 @@ struct _ListSort static ListSort data[] = { - { "Apples", "Transmorgrify long word to demonstrate weirdness", "Exculpatory", "Gesundheit"}, + { "Apples", "Transmogrify long word to demonstrate weirdness", "Exculpatory", "Gesundheit"}, { "Oranges", "Wicker", "Adamantine", "Convivial" }, { "Bovine Spongiform Encephilopathy", "Sleazebucket", "Mountaineer", "Pander" }, { "Foot and Mouth", "Lampshade", "Skim Milk\nFull Milk", "Viewless" }, |