2010-02-12 22:46:07 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpdeviceinfoeditor.c
|
|
|
|
* Copyright (C) 2010 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "gimpdeviceinfo.h"
|
|
|
|
#include "gimpdeviceinfoeditor.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_INFO
|
|
|
|
};
|
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
AXIS_COLUMN_INDEX,
|
|
|
|
AXIS_COLUMN_NAME,
|
|
|
|
AXIS_COLUMN_INPUT_NAME,
|
|
|
|
AXIS_N_COLUMNS
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
INPUT_COLUMN_INDEX,
|
|
|
|
INPUT_COLUMN_NAME,
|
|
|
|
INPUT_N_COLUMNS
|
|
|
|
};
|
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
enum
|
2010-02-12 22:46:07 +08:00
|
|
|
{
|
2010-02-13 04:35:39 +08:00
|
|
|
KEY_COLUMN_INDEX,
|
|
|
|
KEY_COLUMN_NAME,
|
|
|
|
KEY_COLUMN_KEY,
|
|
|
|
KEY_COLUMN_MASK,
|
|
|
|
KEY_N_COLUMNS
|
2010-02-12 22:46:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _GimpDeviceInfoEditorPrivate GimpDeviceInfoEditorPrivate;
|
|
|
|
|
|
|
|
struct _GimpDeviceInfoEditorPrivate
|
|
|
|
{
|
|
|
|
GimpDeviceInfo *info;
|
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
GtkListStore *input_store;
|
2010-02-16 01:24:19 +08:00
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
GtkListStore *axis_store;
|
|
|
|
GtkTreeIter axis_iters[GDK_AXIS_LAST - GDK_AXIS_X];
|
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
GtkListStore *key_store;
|
2010-02-12 22:46:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define GIMP_DEVICE_INFO_EDITOR_GET_PRIVATE(editor) \
|
|
|
|
G_TYPE_INSTANCE_GET_PRIVATE (editor, \
|
|
|
|
GIMP_TYPE_DEVICE_INFO_EDITOR, \
|
|
|
|
GimpDeviceInfoEditorPrivate)
|
|
|
|
|
|
|
|
|
|
|
|
static GObject * gimp_device_info_editor_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params);
|
|
|
|
static void gimp_device_info_editor_finalize (GObject *object);
|
|
|
|
static void gimp_device_info_editor_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_device_info_editor_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
void gimp_device_info_editor_set_axes (GimpDeviceInfoEditor *editor);
|
|
|
|
|
|
|
|
void gimp_device_info_editor_axis_changed (GtkCellRendererCombo *combo,
|
|
|
|
const gchar *path_string,
|
|
|
|
GtkTreeIter *new_iter,
|
2010-02-12 22:46:07 +08:00
|
|
|
GimpDeviceInfoEditor *editor);
|
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
static void gimp_device_info_editor_key_edited (GtkCellRendererAccel *accel,
|
|
|
|
const char *path_string,
|
|
|
|
guint accel_key,
|
|
|
|
GdkModifierType accel_mask,
|
|
|
|
guint hardware_keycode,
|
|
|
|
GimpDeviceInfoEditor *editor);
|
|
|
|
static void gimp_device_info_editor_key_cleared (GtkCellRendererAccel *accel,
|
|
|
|
const char *path_string,
|
|
|
|
GimpDeviceInfoEditor *editor);
|
2010-02-12 22:46:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GimpDeviceInfoEditor, gimp_device_info_editor, GTK_TYPE_VBOX)
|
|
|
|
|
|
|
|
#define parent_class gimp_device_info_editor_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_device_info_editor_class_init (GimpDeviceInfoEditorClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->constructor = gimp_device_info_editor_constructor;
|
|
|
|
object_class->finalize = gimp_device_info_editor_finalize;
|
|
|
|
object_class->set_property = gimp_device_info_editor_set_property;
|
|
|
|
object_class->get_property = gimp_device_info_editor_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_INFO,
|
|
|
|
g_param_spec_object ("info",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_DEVICE_INFO,
|
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
|
|
|
g_type_class_add_private (object_class, sizeof (GimpDeviceInfoEditorPrivate));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_device_info_editor_init (GimpDeviceInfoEditor *editor)
|
|
|
|
{
|
2010-02-13 04:35:39 +08:00
|
|
|
GimpDeviceInfoEditorPrivate *private;
|
2010-02-15 20:12:26 +08:00
|
|
|
GtkWidget *frame;
|
2010-02-15 23:48:21 +08:00
|
|
|
GtkWidget *frame2;
|
|
|
|
GtkWidget *view;
|
2010-02-13 04:35:39 +08:00
|
|
|
GtkWidget *scrolled_win;
|
2010-02-15 20:12:26 +08:00
|
|
|
GtkWidget *key_view;
|
2010-02-13 04:35:39 +08:00
|
|
|
GtkCellRenderer *cell;
|
2010-02-15 23:48:21 +08:00
|
|
|
gint i;
|
2010-02-13 04:35:39 +08:00
|
|
|
|
|
|
|
private = GIMP_DEVICE_INFO_EDITOR_GET_PRIVATE (editor);
|
|
|
|
|
2010-02-12 22:46:07 +08:00
|
|
|
gtk_box_set_spacing (GTK_BOX (editor), 6);
|
2010-02-13 04:35:39 +08:00
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
/* the axes */
|
|
|
|
|
|
|
|
frame = gimp_frame_new (_("Axes"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (editor), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
frame2 = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame2), GTK_SHADOW_IN);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), frame2);
|
|
|
|
gtk_widget_show (frame2);
|
|
|
|
|
|
|
|
private->axis_store = gtk_list_store_new (AXIS_N_COLUMNS,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_STRING);
|
|
|
|
|
|
|
|
for (i = GDK_AXIS_X; i < GDK_AXIS_LAST; i++)
|
|
|
|
{
|
|
|
|
static const gchar *const axis_use_strings[] =
|
|
|
|
{
|
|
|
|
N_("X"),
|
|
|
|
N_("Y"),
|
|
|
|
N_("Pressure"),
|
|
|
|
N_("X tilt"),
|
|
|
|
N_("Y tilt"),
|
|
|
|
N_("Wheel")
|
|
|
|
};
|
|
|
|
|
|
|
|
const gchar *string = gettext (axis_use_strings[i - 1]);
|
|
|
|
|
|
|
|
gtk_list_store_insert_with_values (private->axis_store,
|
|
|
|
&private->axis_iters[i - 1], -1,
|
|
|
|
AXIS_COLUMN_INDEX, i,
|
|
|
|
AXIS_COLUMN_NAME, string,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (private->axis_store));
|
|
|
|
g_object_unref (private->axis_store);
|
|
|
|
|
|
|
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
|
|
|
|
|
|
|
|
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
|
|
|
|
-1, NULL,
|
|
|
|
gtk_cell_renderer_text_new (),
|
|
|
|
"text", AXIS_COLUMN_NAME,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
private->input_store = gtk_list_store_new (INPUT_N_COLUMNS,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_STRING);
|
|
|
|
|
|
|
|
cell = gtk_cell_renderer_combo_new ();
|
|
|
|
g_object_set (cell,
|
|
|
|
"mode", GTK_CELL_RENDERER_MODE_EDITABLE,
|
|
|
|
"editable", TRUE,
|
|
|
|
"model", private->input_store,
|
|
|
|
"text-column", INPUT_COLUMN_NAME,
|
|
|
|
"has-entry", FALSE,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_object_unref (private->input_store);
|
|
|
|
|
|
|
|
g_signal_connect (cell, "changed",
|
|
|
|
G_CALLBACK (gimp_device_info_editor_axis_changed),
|
|
|
|
editor);
|
|
|
|
|
|
|
|
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
|
|
|
|
-1, NULL,
|
|
|
|
cell,
|
|
|
|
"text", AXIS_COLUMN_INPUT_NAME,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame2), view);
|
|
|
|
gtk_widget_show (view);
|
|
|
|
|
|
|
|
/* the keys */
|
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
private->key_store = gtk_list_store_new (KEY_N_COLUMNS,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_UINT,
|
|
|
|
GDK_TYPE_MODIFIER_TYPE);
|
|
|
|
key_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (private->key_store));
|
|
|
|
g_object_unref (private->key_store);
|
|
|
|
|
2010-02-15 20:12:26 +08:00
|
|
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (key_view), FALSE);
|
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (key_view),
|
2010-02-15 20:12:26 +08:00
|
|
|
-1, NULL,
|
2010-02-13 04:35:39 +08:00
|
|
|
gtk_cell_renderer_text_new (),
|
|
|
|
"text", KEY_COLUMN_NAME,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
cell = gtk_cell_renderer_accel_new ();
|
2010-02-13 04:57:58 +08:00
|
|
|
g_object_set (cell,
|
|
|
|
"mode", GTK_CELL_RENDERER_MODE_EDITABLE,
|
|
|
|
"editable", TRUE,
|
|
|
|
NULL);
|
2010-02-13 04:35:39 +08:00
|
|
|
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (key_view),
|
2010-02-15 20:12:26 +08:00
|
|
|
-1, NULL,
|
2010-02-13 04:35:39 +08:00
|
|
|
cell,
|
|
|
|
"accel-key", KEY_COLUMN_KEY,
|
|
|
|
"accel-mods", KEY_COLUMN_MASK,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_signal_connect (cell, "accel-edited",
|
|
|
|
G_CALLBACK (gimp_device_info_editor_key_edited),
|
|
|
|
editor);
|
|
|
|
g_signal_connect (cell, "accel-cleared",
|
|
|
|
G_CALLBACK (gimp_device_info_editor_key_cleared),
|
|
|
|
editor);
|
|
|
|
|
2010-02-15 20:12:26 +08:00
|
|
|
frame = gimp_frame_new (_("Keys"));
|
|
|
|
gtk_box_pack_end (GTK_BOX (editor), frame, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
|
|
|
|
GTK_SHADOW_IN);
|
2010-02-15 19:59:29 +08:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
2010-02-15 20:12:26 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), scrolled_win);
|
2010-02-13 04:35:39 +08:00
|
|
|
gtk_widget_show (scrolled_win);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled_win), key_view);
|
|
|
|
gtk_widget_show (key_view);
|
2010-02-12 22:46:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
gimp_device_info_editor_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
|
|
|
{
|
|
|
|
GObject *object;
|
|
|
|
GimpDeviceInfoEditor *editor;
|
|
|
|
GimpDeviceInfoEditorPrivate *private;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *combo;
|
2010-02-15 23:48:21 +08:00
|
|
|
gint n_axes;
|
2010-02-12 22:46:07 +08:00
|
|
|
gint n_keys;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
|
|
|
|
|
|
|
|
editor = GIMP_DEVICE_INFO_EDITOR (object);
|
|
|
|
private = GIMP_DEVICE_INFO_EDITOR_GET_PRIVATE (object);
|
|
|
|
|
|
|
|
g_assert (GIMP_IS_DEVICE_INFO (private->info));
|
|
|
|
|
|
|
|
/* the mode menu */
|
|
|
|
|
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
|
|
|
gtk_box_pack_start (GTK_BOX (editor), hbox, FALSE, FALSE, 0);
|
2010-02-15 23:48:21 +08:00
|
|
|
gtk_box_reorder_child (GTK_BOX (editor), hbox, 0);
|
2010-02-12 22:46:07 +08:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic (_("_Mode:"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
combo = gimp_prop_enum_combo_box_new (G_OBJECT (private->info), "mode",
|
|
|
|
0, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (combo);
|
|
|
|
|
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
|
|
|
|
|
|
|
|
/* the axes */
|
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
n_axes = gimp_device_info_get_n_axes (private->info);
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
for (i = -1; i < n_axes; i++)
|
2010-02-12 22:46:07 +08:00
|
|
|
{
|
2010-02-15 23:48:21 +08:00
|
|
|
gchar name[16];
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
if (i == -1)
|
|
|
|
g_snprintf (name, sizeof (name), _("none"));
|
|
|
|
else
|
|
|
|
g_snprintf (name, sizeof (name), "%d", i + 1);
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
gtk_list_store_insert_with_values (private->input_store, NULL, -1,
|
|
|
|
INPUT_COLUMN_INDEX, i,
|
|
|
|
INPUT_COLUMN_NAME, name,
|
|
|
|
-1);
|
2010-02-12 22:46:07 +08:00
|
|
|
}
|
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
gimp_device_info_editor_set_axes (editor);
|
|
|
|
|
2010-02-12 22:46:07 +08:00
|
|
|
/* the keys */
|
|
|
|
|
|
|
|
n_keys = gimp_device_info_get_n_keys (private->info);
|
|
|
|
|
|
|
|
for (i = 0; i < n_keys; i++)
|
|
|
|
{
|
2010-02-13 04:35:39 +08:00
|
|
|
gchar string[32];
|
|
|
|
guint keyval;
|
|
|
|
GdkModifierType modifiers;
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
g_snprintf (string, sizeof (string), "%d", i + 1);
|
2010-02-12 22:46:07 +08:00
|
|
|
|
|
|
|
gimp_device_info_get_key (private->info, i, &keyval, &modifiers);
|
|
|
|
|
2010-02-13 04:55:20 +08:00
|
|
|
gtk_list_store_insert_with_values (private->key_store, NULL, -1,
|
2010-02-13 04:35:39 +08:00
|
|
|
KEY_COLUMN_INDEX, i,
|
|
|
|
KEY_COLUMN_NAME, string,
|
|
|
|
KEY_COLUMN_KEY, keyval,
|
|
|
|
KEY_COLUMN_MASK, modifiers,
|
|
|
|
-1);
|
2010-02-12 22:46:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_device_info_editor_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpDeviceInfoEditorPrivate *private;
|
|
|
|
|
|
|
|
private = GIMP_DEVICE_INFO_EDITOR_GET_PRIVATE (object);
|
|
|
|
|
|
|
|
if (private->info)
|
|
|
|
{
|
|
|
|
g_object_unref (private->info);
|
|
|
|
private->info = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_device_info_editor_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpDeviceInfoEditorPrivate *private;
|
|
|
|
|
|
|
|
private = GIMP_DEVICE_INFO_EDITOR_GET_PRIVATE (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_INFO:
|
|
|
|
private->info = g_value_dup_object (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_device_info_editor_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpDeviceInfoEditorPrivate *private;
|
|
|
|
|
|
|
|
private = GIMP_DEVICE_INFO_EDITOR_GET_PRIVATE (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_INFO:
|
|
|
|
g_value_set_object (value, private->info);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-02-15 23:48:21 +08:00
|
|
|
gimp_device_info_editor_set_axes (GimpDeviceInfoEditor *editor)
|
2010-02-12 22:46:07 +08:00
|
|
|
{
|
|
|
|
GimpDeviceInfoEditorPrivate *private;
|
2010-02-15 23:48:21 +08:00
|
|
|
gint n_axes;
|
|
|
|
gint i;
|
2010-02-12 22:46:07 +08:00
|
|
|
|
|
|
|
private = GIMP_DEVICE_INFO_EDITOR_GET_PRIVATE (editor);
|
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
n_axes = gimp_device_info_get_n_axes (private->info);
|
|
|
|
|
|
|
|
for (i = GDK_AXIS_X; i < GDK_AXIS_LAST; i++)
|
2010-02-12 22:46:07 +08:00
|
|
|
{
|
2010-02-15 23:48:21 +08:00
|
|
|
gchar input_name[23];
|
|
|
|
gint j;
|
|
|
|
|
|
|
|
for (j = 0; j < n_axes; j++)
|
2010-02-12 22:46:07 +08:00
|
|
|
{
|
2010-02-15 23:48:21 +08:00
|
|
|
if (gimp_device_info_get_axis_use (private->info, j) == i)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j == n_axes)
|
|
|
|
j = -1;
|
|
|
|
|
|
|
|
if (j == -1)
|
|
|
|
g_snprintf (input_name, sizeof (input_name), _("none"));
|
|
|
|
else
|
|
|
|
g_snprintf (input_name, sizeof (input_name), "%d", j + 1);
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
gtk_list_store_set (private->axis_store,
|
|
|
|
&private->axis_iters[i - 1],
|
|
|
|
AXIS_COLUMN_INPUT_NAME, input_name,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
}
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
void
|
|
|
|
gimp_device_info_editor_axis_changed (GtkCellRendererCombo *combo,
|
|
|
|
const gchar *path_string,
|
|
|
|
GtkTreeIter *new_iter,
|
|
|
|
GimpDeviceInfoEditor *editor)
|
|
|
|
{
|
|
|
|
GimpDeviceInfoEditorPrivate *private;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter new_use_iter;
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
private = GIMP_DEVICE_INFO_EDITOR_GET_PRIVATE (editor);
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
path = gtk_tree_path_new_from_string (path_string);
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-15 23:48:21 +08:00
|
|
|
if (gtk_tree_model_get_iter (GTK_TREE_MODEL (private->axis_store),
|
|
|
|
&new_use_iter, path))
|
|
|
|
{
|
|
|
|
GdkAxisUse new_use = GDK_AXIS_IGNORE;
|
|
|
|
GdkAxisUse old_use = GDK_AXIS_IGNORE;
|
|
|
|
gint new_axis = -1;
|
|
|
|
gint old_axis = -1;
|
|
|
|
gint n_axes;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (private->axis_store), &new_use_iter,
|
|
|
|
AXIS_COLUMN_INDEX, &new_use,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (private->input_store), new_iter,
|
|
|
|
INPUT_COLUMN_INDEX, &new_axis,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
n_axes = gimp_device_info_get_n_axes (private->info);
|
|
|
|
|
|
|
|
for (i = 0; i < n_axes; i++)
|
|
|
|
if (gimp_device_info_get_axis_use (private->info, i) == new_use)
|
|
|
|
{
|
|
|
|
old_axis = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_axis == old_axis)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (new_axis != -1)
|
|
|
|
old_use = gimp_device_info_get_axis_use (private->info, new_axis);
|
|
|
|
|
|
|
|
/* we must always have an x and a y axis */
|
|
|
|
if ((new_axis == -1 && (new_use == GDK_AXIS_X ||
|
|
|
|
new_use == GDK_AXIS_Y)) ||
|
|
|
|
(old_axis == -1 && (old_use == GDK_AXIS_X ||
|
|
|
|
old_use == GDK_AXIS_Y)))
|
|
|
|
{
|
|
|
|
/* do nothing */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-12 22:46:07 +08:00
|
|
|
if (new_axis != -1)
|
2010-02-15 23:48:21 +08:00
|
|
|
gimp_device_info_set_axis_use (private->info, new_axis, new_use);
|
|
|
|
|
|
|
|
if (old_axis != -1)
|
|
|
|
gimp_device_info_set_axis_use (private->info, old_axis, old_use);
|
|
|
|
|
|
|
|
gimp_device_info_editor_set_axes (editor);
|
2010-02-12 22:46:07 +08:00
|
|
|
}
|
|
|
|
}
|
2010-02-15 23:48:21 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
gtk_tree_path_free (path);
|
2010-02-12 22:46:07 +08:00
|
|
|
}
|
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
static void
|
|
|
|
gimp_device_info_editor_key_edited (GtkCellRendererAccel *accel,
|
|
|
|
const char *path_string,
|
|
|
|
guint accel_key,
|
|
|
|
GdkModifierType accel_mask,
|
|
|
|
guint hardware_keycode,
|
|
|
|
GimpDeviceInfoEditor *editor)
|
2010-02-12 22:46:07 +08:00
|
|
|
{
|
|
|
|
GimpDeviceInfoEditorPrivate *private;
|
2010-02-13 04:35:39 +08:00
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
private = GIMP_DEVICE_INFO_EDITOR_GET_PRIVATE (editor);
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
path = gtk_tree_path_new_from_string (path_string);
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
if (gtk_tree_model_get_iter (GTK_TREE_MODEL (private->key_store), &iter, path))
|
|
|
|
{
|
|
|
|
gint index;
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (private->key_store), &iter,
|
|
|
|
KEY_COLUMN_INDEX, &index,
|
|
|
|
-1);
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
gtk_list_store_set (private->key_store, &iter,
|
|
|
|
KEY_COLUMN_KEY, accel_key,
|
|
|
|
KEY_COLUMN_MASK, accel_mask,
|
|
|
|
-1);
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-13 04:39:38 +08:00
|
|
|
gimp_device_info_set_key (private->info, index, accel_key, accel_mask);
|
2010-02-13 04:35:39 +08:00
|
|
|
}
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
gtk_tree_path_free (path);
|
2010-02-12 22:46:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-02-13 04:35:39 +08:00
|
|
|
gimp_device_info_editor_key_cleared (GtkCellRendererAccel *accel,
|
|
|
|
const char *path_string,
|
|
|
|
GimpDeviceInfoEditor *editor)
|
2010-02-12 22:46:07 +08:00
|
|
|
{
|
2010-02-13 04:35:39 +08:00
|
|
|
GimpDeviceInfoEditorPrivate *private;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
private = GIMP_DEVICE_INFO_EDITOR_GET_PRIVATE (editor);
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
path = gtk_tree_path_new_from_string (path_string);
|
|
|
|
|
|
|
|
if (gtk_tree_model_get_iter (GTK_TREE_MODEL (private->key_store), &iter, path))
|
2010-02-12 22:46:07 +08:00
|
|
|
{
|
2010-02-13 04:35:39 +08:00
|
|
|
gint index;
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (private->key_store), &iter,
|
|
|
|
KEY_COLUMN_INDEX, &index,
|
|
|
|
-1);
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
gtk_list_store_set (private->key_store, &iter,
|
|
|
|
KEY_COLUMN_KEY, 0,
|
|
|
|
KEY_COLUMN_MASK, 0,
|
|
|
|
-1);
|
2010-02-12 22:46:07 +08:00
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
gimp_device_info_set_key (private->info, index, 0, 0);
|
2010-02-12 22:46:07 +08:00
|
|
|
}
|
|
|
|
|
2010-02-13 04:35:39 +08:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
2010-02-12 22:46:07 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gimp_device_info_editor_new (GimpDeviceInfo *info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DEVICE_INFO (info), NULL);
|
|
|
|
|
|
|
|
return g_object_new (GIMP_TYPE_DEVICE_INFO_EDITOR,
|
|
|
|
"info", info,
|
|
|
|
NULL);
|
|
|
|
}
|