2005-09-22 16:33:50 +00:00
|
|
|
/* gtkcellrendereraccel.h
|
2005-09-10 01:51:07 +00:00
|
|
|
* Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2005-09-10 01:51:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
accel_edited_callback (GtkCellRendererText *cell,
|
|
|
|
const char *path_string,
|
|
|
|
guint keyval,
|
|
|
|
GdkModifierType mask,
|
|
|
|
guint hardware_keycode,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model = (GtkTreeModel *)data;
|
|
|
|
GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
|
|
|
|
g_print ("%u %d %u\n", keyval, mask, hardware_keycode);
|
|
|
|
|
|
|
|
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
|
|
|
0, (gint)mask,
|
|
|
|
1, keyval,
|
2011-10-26 11:47:07 +00:00
|
|
|
2, hardware_keycode,
|
2005-09-10 01:51:07 +00:00
|
|
|
-1);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
2014-09-06 20:28:15 +00:00
|
|
|
static void
|
|
|
|
accel_cleared_callback (GtkCellRendererText *cell,
|
|
|
|
const char *path_string,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model = (GtkTreeModel *)data;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
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, 0, 0, 1, 0, 2, 0, -1);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
2005-09-10 01:51:07 +00:00
|
|
|
static GtkWidget *
|
|
|
|
key_test (void)
|
|
|
|
{
|
|
|
|
GtkWidget *window, *sw, *tv;
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
GtkCellRenderer *rend;
|
|
|
|
gint i;
|
2014-09-06 20:30:59 +00:00
|
|
|
GtkWidget *box, *entry;
|
2005-09-10 01:51:07 +00:00
|
|
|
|
|
|
|
/* create window */
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2014-09-06 20:30:59 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
|
2005-09-10 01:51:07 +00:00
|
|
|
|
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (sw, TRUE);
|
2014-09-06 20:30:59 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
|
|
|
|
gtk_widget_show (box);
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), box);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (box), sw);
|
2005-09-10 01:51:07 +00:00
|
|
|
|
2011-10-26 11:47:07 +00:00
|
|
|
store = gtk_list_store_new (3, G_TYPE_INT, G_TYPE_UINT, G_TYPE_UINT);
|
2005-09-10 01:51:07 +00:00
|
|
|
tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
|
|
|
|
gtk_container_add (GTK_CONTAINER (sw), tv);
|
|
|
|
column = gtk_tree_view_column_new ();
|
2005-09-22 16:33:50 +00:00
|
|
|
rend = gtk_cell_renderer_accel_new ();
|
2016-10-02 15:37:22 +00:00
|
|
|
g_object_set (G_OBJECT (rend),
|
|
|
|
"accel-mode", GTK_CELL_RENDERER_ACCEL_MODE_GTK,
|
|
|
|
"editable", TRUE,
|
2005-09-10 01:51:07 +00:00
|
|
|
NULL);
|
|
|
|
g_signal_connect (G_OBJECT (rend),
|
|
|
|
"accel-edited",
|
|
|
|
G_CALLBACK (accel_edited_callback),
|
|
|
|
store);
|
2014-09-06 20:28:15 +00:00
|
|
|
g_signal_connect (G_OBJECT (rend),
|
|
|
|
"accel-cleared",
|
|
|
|
G_CALLBACK (accel_cleared_callback),
|
|
|
|
store);
|
2005-09-10 01:51:07 +00:00
|
|
|
|
|
|
|
gtk_tree_view_column_pack_start (column, rend,
|
|
|
|
TRUE);
|
|
|
|
gtk_tree_view_column_set_attributes (column, rend,
|
|
|
|
"accel-mods", 0,
|
|
|
|
"accel-key", 1,
|
2011-10-26 11:47:07 +00:00
|
|
|
"keycode", 2,
|
2005-09-10 01:51:07 +00:00
|
|
|
NULL);
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tv), column);
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
}
|
|
|
|
|
2014-09-06 20:30:59 +00:00
|
|
|
entry = gtk_entry_new ();
|
|
|
|
gtk_widget_show (entry);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), entry);
|
|
|
|
|
2005-09-10 01:51:07 +00:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
main (gint argc, gchar **argv)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2005-09-10 01:51:07 +00:00
|
|
|
|
|
|
|
dialog = key_test ();
|
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (dialog);
|
2005-09-10 01:51:07 +00:00
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|