]> Pileus Git - ~andy/gtk/blob - tests/testaccel.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / testaccel.c
1 /* gtkcellrendereraccel.h
2  * Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <gtk/gtk.h>
19 #include <gdk/gdkkeysyms.h>
20
21 static void
22 accel_edited_callback (GtkCellRendererText *cell,
23                        const char          *path_string,
24                        guint                keyval,
25                        GdkModifierType      mask,
26                        guint                hardware_keycode,
27                        gpointer             data)
28 {
29   GtkTreeModel *model = (GtkTreeModel *)data;
30   GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
31   GtkTreeIter iter;
32
33   gtk_tree_model_get_iter (model, &iter, path);
34
35   g_print ("%u %d %u\n", keyval, mask, hardware_keycode);
36   
37   gtk_list_store_set (GTK_LIST_STORE (model), &iter,
38                       0, (gint)mask,
39                       1, keyval,
40                       2, hardware_keycode,
41                       -1);
42   gtk_tree_path_free (path);
43 }
44
45 static GtkWidget *
46 key_test (void)
47 {
48         GtkWidget *window, *sw, *tv;
49         GtkListStore *store;
50         GtkTreeViewColumn *column;
51         GtkCellRenderer *rend;
52         gint i;
53
54         /* create window */
55         window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
56
57
58         sw = gtk_scrolled_window_new (NULL, NULL);
59         gtk_container_add (GTK_CONTAINER (window), sw);
60
61         store = gtk_list_store_new (3, G_TYPE_INT, G_TYPE_UINT, G_TYPE_UINT);
62         tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
63         gtk_container_add (GTK_CONTAINER (sw), tv);
64         column = gtk_tree_view_column_new ();
65         rend = gtk_cell_renderer_accel_new ();
66         g_object_set (G_OBJECT (rend), 
67                       "accel-mode", GTK_CELL_RENDERER_ACCEL_MODE_GTK, 
68                       "editable", TRUE, 
69                       NULL);
70         g_signal_connect (G_OBJECT (rend),
71                           "accel-edited",
72                           G_CALLBACK (accel_edited_callback),
73                           store);
74
75         gtk_tree_view_column_pack_start (column, rend,
76                                          TRUE);
77         gtk_tree_view_column_set_attributes (column, rend,
78                                              "accel-mods", 0,
79                                              "accel-key", 1,
80                                              "keycode", 2,
81                                              NULL);
82         gtk_tree_view_append_column (GTK_TREE_VIEW (tv), column);
83
84         for (i = 0; i < 10; i++) {
85                 GtkTreeIter iter;
86
87                 gtk_list_store_append (store, &iter);
88         }
89
90         /* done */
91
92         return window;
93 }
94
95 gint
96 main (gint argc, gchar **argv)
97 {
98   GtkWidget *dialog;
99   
100   gtk_init (&argc, &argv);
101
102   dialog = key_test ();
103
104   gtk_widget_show_all (dialog);
105
106   gtk_main ();
107
108   return 0;
109 }