]> Pileus Git - ~andy/gtk/blob - tests/testaccel.c
tests: Store keycode in tree for testaccel
[~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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <gtk/gtk.h>
21 #include <gdk/gdkkeysyms.h>
22
23 static void
24 accel_edited_callback (GtkCellRendererText *cell,
25                        const char          *path_string,
26                        guint                keyval,
27                        GdkModifierType      mask,
28                        guint                hardware_keycode,
29                        gpointer             data)
30 {
31   GtkTreeModel *model = (GtkTreeModel *)data;
32   GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
33   GtkTreeIter iter;
34
35   gtk_tree_model_get_iter (model, &iter, path);
36
37   g_print ("%u %d %u\n", keyval, mask, hardware_keycode);
38   
39   gtk_list_store_set (GTK_LIST_STORE (model), &iter,
40                       0, (gint)mask,
41                       1, keyval,
42                       2, hardware_keycode,
43                       -1);
44   gtk_tree_path_free (path);
45 }
46
47 static GtkWidget *
48 key_test (void)
49 {
50         GtkWidget *window, *sw, *tv;
51         GtkListStore *store;
52         GtkTreeViewColumn *column;
53         GtkCellRenderer *rend;
54         gint i;
55
56         /* create window */
57         window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
58
59
60         sw = gtk_scrolled_window_new (NULL, NULL);
61         gtk_container_add (GTK_CONTAINER (window), sw);
62
63         store = gtk_list_store_new (3, G_TYPE_INT, G_TYPE_UINT, G_TYPE_UINT);
64         tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
65         gtk_container_add (GTK_CONTAINER (sw), tv);
66         column = gtk_tree_view_column_new ();
67         rend = gtk_cell_renderer_accel_new ();
68         g_object_set (G_OBJECT (rend), 
69                       "accel-mode", GTK_CELL_RENDERER_ACCEL_MODE_GTK, 
70                       "editable", TRUE, 
71                       NULL);
72         g_signal_connect (G_OBJECT (rend),
73                           "accel-edited",
74                           G_CALLBACK (accel_edited_callback),
75                           store);
76
77         gtk_tree_view_column_pack_start (column, rend,
78                                          TRUE);
79         gtk_tree_view_column_set_attributes (column, rend,
80                                              "accel-mods", 0,
81                                              "accel-key", 1,
82                                              "keycode", 2,
83                                              NULL);
84         gtk_tree_view_append_column (GTK_TREE_VIEW (tv), column);
85
86         for (i = 0; i < 10; i++) {
87                 GtkTreeIter iter;
88
89                 gtk_list_store_append (store, &iter);
90         }
91
92         /* done */
93
94         return window;
95 }
96
97 gint
98 main (gint argc, gchar **argv)
99 {
100   GtkWidget *dialog;
101   
102   gtk_init (&argc, &argv);
103
104   dialog = key_test ();
105
106   gtk_widget_show_all (dialog);
107
108   gtk_main ();
109
110   return 0;
111 }