1 | /* GTK - The GIMP Toolkit |
---|
2 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
---|
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 | /* |
---|
21 | * gtkinputdialog.c |
---|
22 | * |
---|
23 | * Copyright 1997 Owen Taylor <owt1@cornell.edu> |
---|
24 | * |
---|
25 | */ |
---|
26 | |
---|
27 | /* |
---|
28 | * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS |
---|
29 | * file for a list of people on the GTK+ Team. See the ChangeLog |
---|
30 | * files for a list of changes. These files are distributed with |
---|
31 | * GTK+ at ftp://ftp.gtk.org/pub/gtk/. |
---|
32 | */ |
---|
33 | |
---|
34 | |
---|
35 | #include <stdio.h> |
---|
36 | #include <stdlib.h> |
---|
37 | #include <ctype.h> |
---|
38 | #include "gdk/gdkkeysyms.h" |
---|
39 | #include "gtkbutton.h" |
---|
40 | #include "gtkentry.h" |
---|
41 | #include "gtkhbox.h" |
---|
42 | #include "gtkhseparator.h" |
---|
43 | #include "gtkinputdialog.h" |
---|
44 | #include "gtklabel.h" |
---|
45 | #include "gtklistitem.h" |
---|
46 | #include "gtkmain.h" |
---|
47 | #include "gtkmenu.h" |
---|
48 | #include "gtkmenuitem.h" |
---|
49 | #include "gtknotebook.h" |
---|
50 | #include "gtkoptionmenu.h" |
---|
51 | #include "gtkscrolledwindow.h" |
---|
52 | #include "gtksignal.h" |
---|
53 | #include "gtktable.h" |
---|
54 | #include "gtkvbox.h" |
---|
55 | |
---|
56 | #include "gtkintl.h" |
---|
57 | |
---|
58 | typedef struct { |
---|
59 | gint index; |
---|
60 | GtkWidget *entry; |
---|
61 | GtkInputDialog *inputd; |
---|
62 | } GtkInputKeyInfo; |
---|
63 | |
---|
64 | enum |
---|
65 | { |
---|
66 | ENABLE_DEVICE, |
---|
67 | DISABLE_DEVICE, |
---|
68 | LAST_SIGNAL |
---|
69 | }; |
---|
70 | |
---|
71 | |
---|
72 | #define AXIS_LIST_WIDTH 160 |
---|
73 | #define AXIS_LIST_HEIGHT 175 |
---|
74 | |
---|
75 | #define KEYS_LIST_WIDTH 200 |
---|
76 | #define KEYS_LIST_HEIGHT 175 |
---|
77 | |
---|
78 | /* Forward declarations */ |
---|
79 | |
---|
80 | static void gtk_input_dialog_class_init (GtkInputDialogClass *klass); |
---|
81 | static void gtk_input_dialog_init (GtkInputDialog *inputd); |
---|
82 | static GdkDeviceInfo *gtk_input_dialog_get_device_info(guint32 deviceid); |
---|
83 | static void gtk_input_dialog_set_device(GtkWidget *widget, gpointer data); |
---|
84 | static void gtk_input_dialog_finalize (GtkObject *object); |
---|
85 | static void gtk_input_dialog_set_mapping_mode(GtkWidget *w, |
---|
86 | gpointer data); |
---|
87 | static void gtk_input_dialog_set_axis(GtkWidget *widget, gpointer data); |
---|
88 | static void gtk_input_dialog_fill_axes (GtkInputDialog *inputd, |
---|
89 | GdkDeviceInfo *info); |
---|
90 | static void gtk_input_dialog_set_key (GtkInputKeyInfo *key, |
---|
91 | guint keyval, |
---|
92 | GdkModifierType modifiers); |
---|
93 | static gint gtk_input_dialog_key_press (GtkWidget *widget, |
---|
94 | GdkEventKey *event, |
---|
95 | GtkInputKeyInfo *key); |
---|
96 | static void gtk_input_dialog_clear_key (GtkWidget *widget, |
---|
97 | GtkInputKeyInfo *key); |
---|
98 | static void gtk_input_dialog_destroy_key (GtkWidget *widget, |
---|
99 | GtkInputKeyInfo *key); |
---|
100 | static void gtk_input_dialog_fill_keys (GtkInputDialog *inputd, |
---|
101 | GdkDeviceInfo *info); |
---|
102 | |
---|
103 | static GtkObjectClass *parent_class = NULL; |
---|
104 | static guint input_dialog_signals[LAST_SIGNAL] = { 0 }; |
---|
105 | |
---|
106 | static GdkDeviceInfo * |
---|
107 | gtk_input_dialog_get_device_info(guint32 deviceid) |
---|
108 | { |
---|
109 | GList *tmp_list = gdk_input_list_devices(); |
---|
110 | while (tmp_list) |
---|
111 | { |
---|
112 | if (((GdkDeviceInfo *)tmp_list->data)->deviceid == deviceid) |
---|
113 | return (GdkDeviceInfo *)tmp_list->data; |
---|
114 | tmp_list = tmp_list->next; |
---|
115 | } |
---|
116 | |
---|
117 | return NULL; |
---|
118 | } |
---|
119 | |
---|
120 | GtkType |
---|
121 | gtk_input_dialog_get_type (void) |
---|
122 | { |
---|
123 | static GtkType input_dialog_type = 0; |
---|
124 | |
---|
125 | if (!input_dialog_type) |
---|
126 | { |
---|
127 | static const GtkTypeInfo input_dialog_info = |
---|
128 | { |
---|
129 | "GtkInputDialog", |
---|
130 | sizeof (GtkInputDialog), |
---|
131 | sizeof (GtkInputDialogClass), |
---|
132 | (GtkClassInitFunc) gtk_input_dialog_class_init, |
---|
133 | (GtkObjectInitFunc) gtk_input_dialog_init, |
---|
134 | /* reserved_1 */ NULL, |
---|
135 | /* reserved_2 */ NULL, |
---|
136 | (GtkClassInitFunc) NULL, |
---|
137 | }; |
---|
138 | |
---|
139 | input_dialog_type = gtk_type_unique (GTK_TYPE_DIALOG, |
---|
140 | &input_dialog_info); |
---|
141 | } |
---|
142 | |
---|
143 | return input_dialog_type; |
---|
144 | } |
---|
145 | |
---|
146 | static void |
---|
147 | gtk_input_dialog_class_init (GtkInputDialogClass *klass) |
---|
148 | { |
---|
149 | GtkObjectClass *object_class; |
---|
150 | |
---|
151 | object_class = (GtkObjectClass*) klass; |
---|
152 | |
---|
153 | parent_class = gtk_type_class (GTK_TYPE_DIALOG); |
---|
154 | |
---|
155 | input_dialog_signals[ENABLE_DEVICE] = |
---|
156 | gtk_signal_new ("enable_device", |
---|
157 | GTK_RUN_LAST, |
---|
158 | object_class->type, |
---|
159 | GTK_SIGNAL_OFFSET (GtkInputDialogClass, enable_device), |
---|
160 | gtk_marshal_NONE__INT, |
---|
161 | GTK_TYPE_NONE, 1, GTK_TYPE_INT); |
---|
162 | |
---|
163 | input_dialog_signals[DISABLE_DEVICE] = |
---|
164 | gtk_signal_new ("disable_device", |
---|
165 | GTK_RUN_LAST, |
---|
166 | object_class->type, |
---|
167 | GTK_SIGNAL_OFFSET (GtkInputDialogClass, disable_device), |
---|
168 | gtk_marshal_NONE__INT, |
---|
169 | GTK_TYPE_NONE, 1, GTK_TYPE_INT); |
---|
170 | |
---|
171 | gtk_object_class_add_signals (object_class, input_dialog_signals, |
---|
172 | LAST_SIGNAL); |
---|
173 | |
---|
174 | |
---|
175 | object_class->finalize = gtk_input_dialog_finalize; |
---|
176 | klass->enable_device = NULL; |
---|
177 | klass->disable_device = NULL; |
---|
178 | } |
---|
179 | |
---|
180 | static void |
---|
181 | gtk_input_dialog_init (GtkInputDialog *inputd) |
---|
182 | { |
---|
183 | GtkWidget *vbox; |
---|
184 | GtkWidget *util_box; |
---|
185 | GtkWidget *label; |
---|
186 | GtkWidget *device_menu; |
---|
187 | GtkWidget *mapping_menu; |
---|
188 | GtkWidget *menuitem; |
---|
189 | GtkWidget *optionmenu; |
---|
190 | GtkWidget *separator; |
---|
191 | GtkWidget *notebook; |
---|
192 | |
---|
193 | GList *tmp_list; |
---|
194 | GList *device_info; |
---|
195 | |
---|
196 | device_info = gdk_input_list_devices(); |
---|
197 | |
---|
198 | /* shell and main vbox */ |
---|
199 | |
---|
200 | gtk_window_set_title (GTK_WINDOW (inputd), _("Input")); |
---|
201 | |
---|
202 | vbox = gtk_vbox_new (FALSE, 4); |
---|
203 | gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); |
---|
204 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (inputd)->vbox), vbox, TRUE, TRUE, 0); |
---|
205 | |
---|
206 | if (g_list_length(device_info) <= 1) /* only core device */ |
---|
207 | { |
---|
208 | label = gtk_label_new (_("No input devices")); |
---|
209 | gtk_container_add (GTK_CONTAINER (vbox), label); |
---|
210 | |
---|
211 | gtk_widget_show (label); |
---|
212 | } |
---|
213 | else |
---|
214 | { |
---|
215 | /* menu for selecting device */ |
---|
216 | |
---|
217 | device_menu = gtk_menu_new (); |
---|
218 | |
---|
219 | for (tmp_list = device_info; tmp_list; tmp_list = tmp_list->next) { |
---|
220 | GdkDeviceInfo *info = (GdkDeviceInfo *)(tmp_list->data); |
---|
221 | if (info->deviceid != GDK_CORE_POINTER) |
---|
222 | { |
---|
223 | menuitem = gtk_menu_item_new_with_label(info->name); |
---|
224 | |
---|
225 | gtk_menu_append(GTK_MENU(device_menu),menuitem); |
---|
226 | gtk_widget_show(menuitem); |
---|
227 | gtk_object_set_user_data (GTK_OBJECT (menuitem), inputd); |
---|
228 | gtk_signal_connect (GTK_OBJECT (menuitem), "activate", |
---|
229 | (GtkSignalFunc) gtk_input_dialog_set_device, |
---|
230 | GUINT_TO_POINTER(info->deviceid)); |
---|
231 | } |
---|
232 | } |
---|
233 | |
---|
234 | util_box = gtk_hbox_new (FALSE, 2); |
---|
235 | gtk_box_pack_start (GTK_BOX (vbox), util_box, FALSE, FALSE, 0); |
---|
236 | |
---|
237 | label = gtk_label_new(_("Device:")); |
---|
238 | gtk_box_pack_start (GTK_BOX (util_box), label, FALSE, FALSE, 2); |
---|
239 | |
---|
240 | optionmenu = gtk_option_menu_new (); |
---|
241 | gtk_box_pack_start (GTK_BOX (util_box), optionmenu, TRUE, TRUE, 2); |
---|
242 | gtk_widget_show (optionmenu); |
---|
243 | gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), device_menu); |
---|
244 | |
---|
245 | gtk_widget_show (label); |
---|
246 | |
---|
247 | /* Device options */ |
---|
248 | |
---|
249 | /* mapping mode option menu */ |
---|
250 | |
---|
251 | mapping_menu = gtk_menu_new (); |
---|
252 | |
---|
253 | menuitem = gtk_menu_item_new_with_label(_("Disabled")); |
---|
254 | gtk_menu_append(GTK_MENU(mapping_menu),menuitem); |
---|
255 | gtk_object_set_user_data (GTK_OBJECT (menuitem), inputd); |
---|
256 | gtk_widget_show(menuitem); |
---|
257 | gtk_signal_connect (GTK_OBJECT (menuitem), "activate", |
---|
258 | (GtkSignalFunc) gtk_input_dialog_set_mapping_mode, |
---|
259 | GINT_TO_POINTER (GDK_MODE_DISABLED)); |
---|
260 | |
---|
261 | menuitem = gtk_menu_item_new_with_label(_("Screen")); |
---|
262 | gtk_menu_append(GTK_MENU(mapping_menu),menuitem); |
---|
263 | gtk_object_set_user_data (GTK_OBJECT (menuitem), inputd); |
---|
264 | gtk_widget_show(menuitem); |
---|
265 | gtk_signal_connect (GTK_OBJECT (menuitem), "activate", |
---|
266 | (GtkSignalFunc) gtk_input_dialog_set_mapping_mode, |
---|
267 | GINT_TO_POINTER (GDK_MODE_SCREEN)); |
---|
268 | |
---|
269 | menuitem = gtk_menu_item_new_with_label(_("Window")); |
---|
270 | gtk_menu_append(GTK_MENU(mapping_menu),menuitem); |
---|
271 | gtk_object_set_user_data (GTK_OBJECT (menuitem), inputd); |
---|
272 | gtk_widget_show(menuitem); |
---|
273 | gtk_signal_connect (GTK_OBJECT (menuitem), "activate", |
---|
274 | (GtkSignalFunc) gtk_input_dialog_set_mapping_mode, |
---|
275 | GINT_TO_POINTER (GDK_MODE_WINDOW)); |
---|
276 | |
---|
277 | label = gtk_label_new(_("Mode: ")); |
---|
278 | gtk_box_pack_start (GTK_BOX (util_box), label, FALSE, FALSE, 2); |
---|
279 | |
---|
280 | inputd->mode_optionmenu = gtk_option_menu_new (); |
---|
281 | gtk_box_pack_start (GTK_BOX (util_box), inputd->mode_optionmenu, FALSE, FALSE, 2); |
---|
282 | gtk_widget_show (inputd->mode_optionmenu); |
---|
283 | gtk_option_menu_set_menu (GTK_OPTION_MENU (inputd->mode_optionmenu), mapping_menu); |
---|
284 | |
---|
285 | gtk_widget_show(label); |
---|
286 | |
---|
287 | gtk_widget_show (util_box); |
---|
288 | |
---|
289 | util_box = gtk_hbox_new (FALSE, 2); |
---|
290 | gtk_box_pack_start (GTK_BOX(vbox), util_box, FALSE, FALSE, 0); |
---|
291 | |
---|
292 | gtk_widget_show (label); |
---|
293 | gtk_widget_show (util_box); |
---|
294 | |
---|
295 | separator = gtk_hseparator_new(); |
---|
296 | gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, TRUE, 0); |
---|
297 | gtk_widget_show (separator); |
---|
298 | |
---|
299 | /* Notebook */ |
---|
300 | |
---|
301 | notebook = gtk_notebook_new (); |
---|
302 | gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0); |
---|
303 | gtk_widget_show (notebook); |
---|
304 | |
---|
305 | /* The axis listbox */ |
---|
306 | |
---|
307 | label = gtk_label_new (_("Axes")); |
---|
308 | |
---|
309 | inputd->axis_listbox = gtk_scrolled_window_new (NULL, NULL); |
---|
310 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(inputd->axis_listbox), |
---|
311 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
---|
312 | |
---|
313 | gtk_widget_set_usize (inputd->axis_listbox, AXIS_LIST_WIDTH, AXIS_LIST_HEIGHT); |
---|
314 | gtk_notebook_append_page (GTK_NOTEBOOK(notebook), |
---|
315 | inputd->axis_listbox, label); |
---|
316 | |
---|
317 | gtk_widget_show (inputd->axis_listbox); |
---|
318 | |
---|
319 | inputd->axis_list = 0; |
---|
320 | |
---|
321 | /* Keys listbox */ |
---|
322 | |
---|
323 | label = gtk_label_new (_("Keys")); |
---|
324 | |
---|
325 | inputd->keys_listbox = gtk_scrolled_window_new (NULL, NULL); |
---|
326 | gtk_widget_set_usize (inputd->keys_listbox, KEYS_LIST_WIDTH, KEYS_LIST_HEIGHT); |
---|
327 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(inputd->keys_listbox), |
---|
328 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
---|
329 | gtk_notebook_append_page (GTK_NOTEBOOK(notebook), |
---|
330 | inputd->keys_listbox, label); |
---|
331 | |
---|
332 | gtk_widget_show (inputd->keys_listbox); |
---|
333 | |
---|
334 | inputd->keys_list = 0; |
---|
335 | |
---|
336 | /* ...set_device expects to get input dialog from widget user data */ |
---|
337 | gtk_object_set_user_data (GTK_OBJECT (inputd), inputd); |
---|
338 | gtk_input_dialog_set_device(GTK_WIDGET(inputd), |
---|
339 | GUINT_TO_POINTER (((GdkDeviceInfo *)device_info->data)->deviceid)); |
---|
340 | |
---|
341 | } |
---|
342 | |
---|
343 | /* We create the save button in any case, so that clients can |
---|
344 | connect to it, without paying attention to whether it exits */ |
---|
345 | inputd->save_button = gtk_button_new_with_label (_("Save")); |
---|
346 | GTK_WIDGET_SET_FLAGS (inputd->save_button, GTK_CAN_DEFAULT); |
---|
347 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG(inputd)->action_area), |
---|
348 | inputd->save_button, TRUE, TRUE, 0); |
---|
349 | gtk_widget_show (inputd->save_button); |
---|
350 | |
---|
351 | if (g_list_length(device_info) <= 1) /* only core device */ |
---|
352 | gtk_widget_set_sensitive(inputd->save_button, FALSE); |
---|
353 | |
---|
354 | inputd->close_button = gtk_button_new_with_label (_("Close")); |
---|
355 | GTK_WIDGET_SET_FLAGS (inputd->close_button, GTK_CAN_DEFAULT); |
---|
356 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG(inputd)->action_area), |
---|
357 | inputd->close_button, TRUE, TRUE, 0); |
---|
358 | |
---|
359 | gtk_widget_show (inputd->close_button); |
---|
360 | gtk_widget_grab_default (inputd->close_button); |
---|
361 | |
---|
362 | gtk_widget_show (vbox); |
---|
363 | } |
---|
364 | |
---|
365 | |
---|
366 | GtkWidget* |
---|
367 | gtk_input_dialog_new (void) |
---|
368 | { |
---|
369 | GtkInputDialog *inputd; |
---|
370 | |
---|
371 | inputd = gtk_type_new (GTK_TYPE_INPUT_DIALOG); |
---|
372 | |
---|
373 | return GTK_WIDGET (inputd); |
---|
374 | } |
---|
375 | |
---|
376 | static void |
---|
377 | gtk_input_dialog_set_device(GtkWidget *widget, gpointer data) |
---|
378 | { |
---|
379 | guint32 deviceid = GPOINTER_TO_UINT(data); |
---|
380 | GdkDeviceInfo *info; |
---|
381 | |
---|
382 | GtkInputDialog *inputd = GTK_INPUT_DIALOG( |
---|
383 | gtk_object_get_user_data(GTK_OBJECT(widget))); |
---|
384 | |
---|
385 | inputd->current_device = deviceid; |
---|
386 | info = gtk_input_dialog_get_device_info (deviceid); |
---|
387 | |
---|
388 | gtk_input_dialog_fill_axes(inputd, info); |
---|
389 | gtk_input_dialog_fill_keys(inputd, info); |
---|
390 | |
---|
391 | gtk_option_menu_set_history(GTK_OPTION_MENU(inputd->mode_optionmenu), |
---|
392 | info->mode); |
---|
393 | } |
---|
394 | |
---|
395 | static void |
---|
396 | gtk_input_dialog_finalize (GtkObject *object) |
---|
397 | { |
---|
398 | /* GtkInputDialog *inputd = GTK_INPUT_DIALOG (object); */ |
---|
399 | |
---|
400 | /* Clean up ? */ |
---|
401 | |
---|
402 | (* GTK_OBJECT_CLASS (parent_class)->finalize) (object); |
---|
403 | } |
---|
404 | |
---|
405 | static void |
---|
406 | gtk_input_dialog_set_mapping_mode(GtkWidget *w, |
---|
407 | gpointer data) |
---|
408 | { |
---|
409 | GtkInputDialog *inputd = GTK_INPUT_DIALOG( |
---|
410 | gtk_object_get_user_data(GTK_OBJECT(w))); |
---|
411 | GdkDeviceInfo *info = gtk_input_dialog_get_device_info (inputd->current_device); |
---|
412 | GdkInputMode old_mode = info->mode; |
---|
413 | GdkInputMode mode = GPOINTER_TO_INT (data); |
---|
414 | |
---|
415 | if (mode != old_mode) |
---|
416 | { |
---|
417 | if (gdk_input_set_mode(inputd->current_device, mode)) |
---|
418 | { |
---|
419 | if (mode == GDK_MODE_DISABLED) |
---|
420 | gtk_signal_emit (GTK_OBJECT (inputd), |
---|
421 | input_dialog_signals[DISABLE_DEVICE], |
---|
422 | info->deviceid); |
---|
423 | else |
---|
424 | gtk_signal_emit (GTK_OBJECT (inputd), |
---|
425 | input_dialog_signals[ENABLE_DEVICE], |
---|
426 | info->deviceid); |
---|
427 | } |
---|
428 | else |
---|
429 | gtk_option_menu_set_history (GTK_OPTION_MENU (inputd->mode_optionmenu), |
---|
430 | old_mode); |
---|
431 | |
---|
432 | /* FIXME: error dialog ? */ |
---|
433 | } |
---|
434 | } |
---|
435 | |
---|
436 | static void |
---|
437 | gtk_input_dialog_set_axis(GtkWidget *widget, gpointer data) |
---|
438 | { |
---|
439 | GdkAxisUse use = GPOINTER_TO_INT(data) & 0xFFFF; |
---|
440 | GdkAxisUse old_use; |
---|
441 | GdkAxisUse *new_axes; |
---|
442 | GtkInputDialog *inputd = GTK_INPUT_DIALOG (gtk_object_get_user_data (GTK_OBJECT (widget))); |
---|
443 | GdkDeviceInfo *info = gtk_input_dialog_get_device_info (inputd->current_device); |
---|
444 | |
---|
445 | gint axis = (GPOINTER_TO_INT(data) >> 16) - 1; |
---|
446 | gint old_axis; |
---|
447 | int i; |
---|
448 | |
---|
449 | new_axes = g_new (GdkAxisUse, info->num_axes); |
---|
450 | old_axis = -1; |
---|
451 | for (i=0;i<info->num_axes;i++) |
---|
452 | { |
---|
453 | new_axes[i] = info->axes[i]; |
---|
454 | if (info->axes[i] == use) |
---|
455 | old_axis = i; |
---|
456 | } |
---|
457 | |
---|
458 | if (axis != -1) |
---|
459 | old_use = info->axes[axis]; |
---|
460 | else |
---|
461 | old_use = GDK_AXIS_IGNORE; |
---|
462 | |
---|
463 | if (axis == old_axis) |
---|
464 | return; |
---|
465 | |
---|
466 | /* we must always have an x and a y axis */ |
---|
467 | if ((axis == -1 && (use == GDK_AXIS_X || use == GDK_AXIS_Y)) || |
---|
468 | (old_axis == -1 && (old_use == GDK_AXIS_X || old_use == GDK_AXIS_Y))) |
---|
469 | { |
---|
470 | gtk_option_menu_set_history ( |
---|
471 | GTK_OPTION_MENU (inputd->axis_items[use]), |
---|
472 | old_axis + 1); |
---|
473 | } |
---|
474 | else |
---|
475 | { |
---|
476 | if (axis != -1) |
---|
477 | new_axes[axis] = use; |
---|
478 | |
---|
479 | if (old_axis != -1) |
---|
480 | new_axes[old_axis] = old_use; |
---|
481 | |
---|
482 | if (old_use != GDK_AXIS_IGNORE) |
---|
483 | { |
---|
484 | gtk_option_menu_set_history ( |
---|
485 | GTK_OPTION_MENU (inputd->axis_items[old_use]), |
---|
486 | old_axis + 1); |
---|
487 | } |
---|
488 | gdk_input_set_axes (info->deviceid, new_axes); |
---|
489 | } |
---|
490 | |
---|
491 | g_free (new_axes); |
---|
492 | } |
---|
493 | |
---|
494 | static void |
---|
495 | gtk_input_dialog_fill_axes(GtkInputDialog *inputd, GdkDeviceInfo *info) |
---|
496 | { |
---|
497 | static const char *axis_use_strings[GDK_AXIS_LAST] = |
---|
498 | { |
---|
499 | "", |
---|
500 | N_("X"), |
---|
501 | N_("Y"), |
---|
502 | N_("Pressure"), |
---|
503 | N_("X Tilt"), |
---|
504 | N_("Y Tilt") |
---|
505 | }; |
---|
506 | |
---|
507 | int i,j; |
---|
508 | GtkWidget *menu; |
---|
509 | GtkWidget *option_menu; |
---|
510 | GtkWidget *label; |
---|
511 | |
---|
512 | /* remove all the old items */ |
---|
513 | if (inputd->axis_list) |
---|
514 | { |
---|
515 | gtk_widget_hide (inputd->axis_list); /* suppress resizes (or get warnings) */ |
---|
516 | gtk_widget_destroy (inputd->axis_list); |
---|
517 | } |
---|
518 | inputd->axis_list = gtk_table_new (GDK_AXIS_LAST, 2, 0); |
---|
519 | gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (inputd->axis_listbox), |
---|
520 | inputd->axis_list); |
---|
521 | gtk_widget_show (inputd->axis_list); |
---|
522 | |
---|
523 | gtk_widget_realize (inputd->axis_list); |
---|
524 | gdk_window_set_background (inputd->axis_list->window, |
---|
525 | &inputd->axis_list->style->base[GTK_STATE_NORMAL]); |
---|
526 | |
---|
527 | for (i=GDK_AXIS_X;i<GDK_AXIS_LAST;i++) |
---|
528 | { |
---|
529 | /* create the label */ |
---|
530 | |
---|
531 | label = gtk_label_new (_(axis_use_strings[i])); |
---|
532 | gtk_table_attach (GTK_TABLE (inputd->axis_list), label, 0, 1, i, i+1, |
---|
533 | 0, 0, 2, 2); |
---|
534 | |
---|
535 | /* and the use option menu */ |
---|
536 | menu = gtk_menu_new(); |
---|
537 | |
---|
538 | for (j = -1; j < info->num_axes; j++) |
---|
539 | { |
---|
540 | char buffer[16]; |
---|
541 | GtkWidget *menu_item; |
---|
542 | |
---|
543 | if (j == -1) |
---|
544 | menu_item = gtk_menu_item_new_with_label (_("none")); |
---|
545 | else |
---|
546 | { |
---|
547 | sprintf (buffer,"%d",j+1); |
---|
548 | menu_item = gtk_menu_item_new_with_label (buffer); |
---|
549 | } |
---|
550 | gtk_object_set_user_data (GTK_OBJECT (menu_item), inputd); |
---|
551 | gtk_signal_connect (GTK_OBJECT (menu_item), "activate", |
---|
552 | (GtkSignalFunc) gtk_input_dialog_set_axis, |
---|
553 | GINT_TO_POINTER (0x10000 * (j + 1) + i)); |
---|
554 | gtk_widget_show (menu_item); |
---|
555 | gtk_menu_append (GTK_MENU (menu), menu_item); |
---|
556 | } |
---|
557 | |
---|
558 | inputd->axis_items[i] = option_menu = gtk_option_menu_new (); |
---|
559 | gtk_table_attach (GTK_TABLE (inputd->axis_list), option_menu, |
---|
560 | 1, 2, i, i+1, 0, 0, 2, 2); |
---|
561 | |
---|
562 | gtk_widget_show (option_menu); |
---|
563 | gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu); |
---|
564 | for (j = 0; j < info->num_axes; j++) |
---|
565 | if (info->axes[j] == (GdkAxisUse) i) |
---|
566 | { |
---|
567 | gtk_option_menu_set_history (GTK_OPTION_MENU (option_menu), j+1); |
---|
568 | break; |
---|
569 | } |
---|
570 | |
---|
571 | gtk_widget_show (label); |
---|
572 | } |
---|
573 | } |
---|
574 | |
---|
575 | static void |
---|
576 | gtk_input_dialog_clear_key (GtkWidget *widget, GtkInputKeyInfo *key) |
---|
577 | { |
---|
578 | gtk_entry_set_text (GTK_ENTRY(key->entry), _("(disabled)")); |
---|
579 | gdk_input_set_key (key->inputd->current_device, key->index, 0, 0); |
---|
580 | } |
---|
581 | |
---|
582 | static void |
---|
583 | gtk_input_dialog_set_key (GtkInputKeyInfo *key, |
---|
584 | guint keyval, GdkModifierType modifiers) |
---|
585 | { |
---|
586 | GString *str; |
---|
587 | gchar chars[2]; |
---|
588 | |
---|
589 | if (keyval) |
---|
590 | { |
---|
591 | str = g_string_new(""); |
---|
592 | |
---|
593 | if (modifiers & GDK_SHIFT_MASK) |
---|
594 | g_string_append (str, "Shft+"); |
---|
595 | if (modifiers & GDK_CONTROL_MASK) |
---|
596 | g_string_append (str, "Ctl+"); |
---|
597 | if (modifiers & GDK_MOD1_MASK) |
---|
598 | g_string_append (str, "Alt+"); |
---|
599 | |
---|
600 | if ((keyval >= 0x20) && (keyval <= 0xFF)) |
---|
601 | { |
---|
602 | chars[0] = keyval; |
---|
603 | chars[1] = 0; |
---|
604 | g_string_append (str, chars); |
---|
605 | } |
---|
606 | else |
---|
607 | g_string_append (str, _("(unknown)")); |
---|
608 | gtk_entry_set_text (GTK_ENTRY(key->entry), str->str); |
---|
609 | |
---|
610 | g_string_free (str, TRUE); |
---|
611 | } |
---|
612 | else |
---|
613 | { |
---|
614 | gtk_entry_set_text (GTK_ENTRY(key->entry), _("(disabled)")); |
---|
615 | } |
---|
616 | } |
---|
617 | |
---|
618 | static gint |
---|
619 | gtk_input_dialog_key_press (GtkWidget *widget, |
---|
620 | GdkEventKey *event, |
---|
621 | GtkInputKeyInfo *key) |
---|
622 | { |
---|
623 | gtk_input_dialog_set_key (key, event->keyval, event->state & 0xFF); |
---|
624 | gdk_input_set_key (key->inputd->current_device, key->index, |
---|
625 | event->keyval, event->state & 0xFF); |
---|
626 | |
---|
627 | gtk_signal_emit_stop_by_name (GTK_OBJECT(widget), "key_press_event"); |
---|
628 | |
---|
629 | return TRUE; |
---|
630 | } |
---|
631 | |
---|
632 | static void |
---|
633 | gtk_input_dialog_destroy_key (GtkWidget *widget, GtkInputKeyInfo *key) |
---|
634 | { |
---|
635 | g_free (key); |
---|
636 | } |
---|
637 | |
---|
638 | static void |
---|
639 | gtk_input_dialog_fill_keys(GtkInputDialog *inputd, GdkDeviceInfo *info) |
---|
640 | { |
---|
641 | int i; |
---|
642 | GtkWidget *label; |
---|
643 | GtkWidget *button; |
---|
644 | |
---|
645 | char buffer[32]; |
---|
646 | |
---|
647 | /* remove all the old items */ |
---|
648 | if (inputd->keys_list) |
---|
649 | { |
---|
650 | gtk_widget_hide (inputd->keys_list); /* suppress resizes (or get warnings) */ |
---|
651 | gtk_widget_destroy (inputd->keys_list); |
---|
652 | } |
---|
653 | |
---|
654 | inputd->keys_list = gtk_table_new (info->num_keys, 3, FALSE); |
---|
655 | gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (inputd->keys_listbox), |
---|
656 | inputd->keys_list); |
---|
657 | gtk_widget_show (inputd->keys_list); |
---|
658 | |
---|
659 | gtk_widget_realize (inputd->keys_list); |
---|
660 | gdk_window_set_background (inputd->keys_list->window, |
---|
661 | &inputd->keys_list->style->base[GTK_STATE_NORMAL]); |
---|
662 | |
---|
663 | for (i=0;i<info->num_keys;i++) |
---|
664 | { |
---|
665 | GtkInputKeyInfo *key = g_new (GtkInputKeyInfo, 1); |
---|
666 | key->index = i; |
---|
667 | key->inputd = inputd; |
---|
668 | |
---|
669 | /* create the label */ |
---|
670 | |
---|
671 | sprintf(buffer, "%d", i+1); |
---|
672 | label = gtk_label_new(buffer); |
---|
673 | gtk_table_attach (GTK_TABLE (inputd->keys_list), label, 0, 1, i, i+1, |
---|
674 | 0, 0, 2, 2); |
---|
675 | gtk_widget_show (label); |
---|
676 | |
---|
677 | /* the entry */ |
---|
678 | |
---|
679 | key->entry = gtk_entry_new (); |
---|
680 | gtk_table_attach (GTK_TABLE (inputd->keys_list), key->entry, 1, 2, i, i+1, |
---|
681 | GTK_EXPAND | GTK_FILL , 0, 2, 2); |
---|
682 | gtk_widget_show (key->entry); |
---|
683 | |
---|
684 | gtk_signal_connect (GTK_OBJECT(key->entry), "key_press_event", |
---|
685 | GTK_SIGNAL_FUNC (gtk_input_dialog_key_press), key); |
---|
686 | gtk_signal_connect (GTK_OBJECT(key->entry), "destroy", |
---|
687 | GTK_SIGNAL_FUNC (gtk_input_dialog_destroy_key), |
---|
688 | key); |
---|
689 | |
---|
690 | /* and clear button */ |
---|
691 | |
---|
692 | button = gtk_button_new_with_label (_("clear")); |
---|
693 | gtk_table_attach (GTK_TABLE (inputd->keys_list), button, 2, 3, i, i+1, |
---|
694 | 0, 0, 2, 2); |
---|
695 | gtk_widget_show (button); |
---|
696 | |
---|
697 | gtk_signal_connect (GTK_OBJECT(button), "clicked", |
---|
698 | GTK_SIGNAL_FUNC (gtk_input_dialog_clear_key), key); |
---|
699 | |
---|
700 | gtk_input_dialog_set_key (key, info->keys[i].keyval, |
---|
701 | info->keys[i].modifiers); |
---|
702 | } |
---|
703 | } |
---|