1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
5
* Copyright (C) 2005 Michael Natterer <mitch@gimp.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
#include "libgimpwidgets/gimpwidgets.h"
30
#define GIMP_ENABLE_CONTROLLER_UNDER_CONSTRUCTION
31
#include "libgimpwidgets/gimpcontroller.h"
33
#include "widgets-types.h"
35
#include "core/gimp.h"
36
#include "core/gimpcontainer.h"
38
#include "gimpcontainertreeview.h"
39
#include "gimpcontainerview.h"
40
#include "gimpcontrollereditor.h"
41
#include "gimpcontrollerlist.h"
42
#include "gimpcontrollerinfo.h"
43
#include "gimpcontrollerkeyboard.h"
44
#include "gimpcontrollerwheel.h"
45
#include "gimpcontrollers.h"
46
#include "gimpdialogfactory.h"
47
#include "gimphelp-ids.h"
48
#include "gimpmessagebox.h"
49
#include "gimpmessagedialog.h"
50
#include "gimppropwidgets.h"
51
#include "gimpuimanager.h"
52
#include "gimpwidgets-utils.h"
54
#include "gimp-intl.h"
72
static GObject * gimp_controller_list_constructor (GType type,
74
GObjectConstructParam *params);
75
static void gimp_controller_list_set_property (GObject *object,
79
static void gimp_controller_list_get_property (GObject *object,
84
static void gimp_controller_list_finalize (GObject *object);
86
static void gimp_controller_list_src_sel_changed (GtkTreeSelection *sel,
87
GimpControllerList *list);
88
static void gimp_controller_list_row_activated (GtkTreeView *tv,
90
GtkTreeViewColumn *column,
91
GimpControllerList *list);
93
static void gimp_controller_list_select_item (GimpContainerView *view,
94
GimpViewable *viewable,
96
GimpControllerList *list);
97
static void gimp_controller_list_activate_item (GimpContainerView *view,
98
GimpViewable *viewable,
100
GimpControllerList *list);
102
static void gimp_controller_list_add_clicked (GtkWidget *button,
103
GimpControllerList *list);
104
static void gimp_controller_list_remove_clicked (GtkWidget *button,
105
GimpControllerList *list);
107
static void gimp_controller_list_edit_clicked (GtkWidget *button,
108
GimpControllerList *list);
109
static void gimp_controller_list_edit_destroy (GtkWidget *widget,
110
GimpControllerInfo *info);
111
static void gimp_controller_list_up_clicked (GtkWidget *button,
112
GimpControllerList *list);
113
static void gimp_controller_list_down_clicked (GtkWidget *button,
114
GimpControllerList *list);
117
G_DEFINE_TYPE (GimpControllerList, gimp_controller_list, GTK_TYPE_VBOX)
119
#define parent_class gimp_controller_list_parent_class
123
gimp_controller_list_class_init (GimpControllerListClass *klass)
125
GObjectClass *object_class = G_OBJECT_CLASS (klass);
127
object_class->constructor = gimp_controller_list_constructor;
128
object_class->set_property = gimp_controller_list_set_property;
129
object_class->get_property = gimp_controller_list_get_property;
130
object_class->finalize = gimp_controller_list_finalize;
132
g_object_class_install_property (object_class, PROP_GIMP,
133
g_param_spec_object ("gimp",
136
GIMP_PARAM_READWRITE |
137
G_PARAM_CONSTRUCT_ONLY));
141
gimp_controller_list_init (GimpControllerList *list)
146
GtkTreeViewColumn *column;
147
GtkCellRenderer *cell;
150
GtkIconSize icon_size;
153
GType *controller_types;
154
guint n_controller_types;
159
list->hbox = hbox = gtk_hbox_new (FALSE, 6);
160
gtk_box_pack_start (GTK_BOX (list), hbox, TRUE, TRUE, 0);
161
gtk_widget_show (hbox);
163
sw = gtk_scrolled_window_new (NULL, NULL);
164
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
166
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
167
GTK_POLICY_AUTOMATIC,
168
GTK_POLICY_AUTOMATIC);
169
gtk_box_pack_start (GTK_BOX (hbox), sw, TRUE, TRUE, 0);
170
gtk_widget_show (sw);
172
list->src = gtk_list_store_new (NUM_COLUMNS,
176
tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list->src));
177
g_object_unref (list->src);
179
gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW (tv), FALSE);
181
column = gtk_tree_view_column_new ();
182
gtk_tree_view_column_set_title (column, _("Available Controllers"));
183
gtk_tree_view_append_column (GTK_TREE_VIEW (tv), column);
185
cell = gtk_cell_renderer_pixbuf_new ();
186
gtk_tree_view_column_pack_start (column, cell, FALSE);
187
gtk_tree_view_column_set_attributes (column, cell,
188
"stock-id", COLUMN_ICON,
191
g_object_get (cell, "stock-size", &icon_size, NULL);
193
cell = gtk_cell_renderer_text_new ();
194
gtk_tree_view_column_pack_start (column, cell, TRUE);
195
gtk_tree_view_column_set_attributes (column, cell,
199
gtk_container_add (GTK_CONTAINER (sw), tv);
200
gtk_widget_show (tv);
202
g_signal_connect_object (tv, "row-activated",
203
G_CALLBACK (gimp_controller_list_row_activated),
206
list->src_sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
207
gtk_tree_selection_set_mode (list->src_sel, GTK_SELECTION_BROWSE);
209
g_signal_connect_object (list->src_sel, "changed",
210
G_CALLBACK (gimp_controller_list_src_sel_changed),
213
controller_types = g_type_children (GIMP_TYPE_CONTROLLER,
214
&n_controller_types);
216
for (i = 0; i < n_controller_types; i++)
218
GimpControllerClass *controller_class;
221
controller_class = g_type_class_ref (controller_types[i]);
223
gtk_list_store_append (list->src, &iter);
224
gtk_list_store_set (list->src, &iter,
225
COLUMN_ICON, controller_class->stock_id,
226
COLUMN_NAME, controller_class->name,
227
COLUMN_TYPE, controller_types[i],
230
g_type_class_unref (controller_class);
233
vbox = gtk_vbox_new (TRUE, 0);
234
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
235
gtk_widget_show (vbox);
237
list->add_button = gtk_button_new ();
238
gtk_box_pack_start (GTK_BOX (vbox), list->add_button, TRUE, FALSE, 0);
239
gtk_widget_set_sensitive (list->add_button, FALSE);
240
gtk_widget_show (list->add_button);
242
image = gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD, GTK_ICON_SIZE_BUTTON);
243
gtk_container_add (GTK_CONTAINER (list->add_button), image);
244
gtk_widget_show (image);
246
g_signal_connect (list->add_button, "clicked",
247
G_CALLBACK (gimp_controller_list_add_clicked),
250
g_object_add_weak_pointer (G_OBJECT (list->add_button),
251
(gpointer) &list->add_button);
253
list->remove_button = gtk_button_new ();
254
gtk_box_pack_start (GTK_BOX (vbox), list->remove_button, TRUE, FALSE, 0);
255
gtk_widget_set_sensitive (list->remove_button, FALSE);
256
gtk_widget_show (list->remove_button);
258
image = gtk_image_new_from_stock (GTK_STOCK_GO_BACK, GTK_ICON_SIZE_BUTTON);
259
gtk_container_add (GTK_CONTAINER (list->remove_button), image);
260
gtk_widget_show (image);
262
g_signal_connect (list->remove_button, "clicked",
263
G_CALLBACK (gimp_controller_list_remove_clicked),
266
g_object_add_weak_pointer (G_OBJECT (list->remove_button),
267
(gpointer) &list->remove_button);
269
gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (GTK_WIDGET (list)),
270
icon_size, &icon_width, &icon_height);
272
list->dest = gimp_container_tree_view_new (NULL, NULL, icon_height, 0);
273
gtk_tree_view_column_set_title (GIMP_CONTAINER_TREE_VIEW (list->dest)->main_column,
274
_("Active Controllers"));
275
gtk_tree_view_set_headers_visible (GIMP_CONTAINER_TREE_VIEW (list->dest)->view,
277
gtk_box_pack_start (GTK_BOX (list->hbox), list->dest, TRUE, TRUE, 0);
278
gtk_widget_show (list->dest);
280
g_signal_connect_object (list->dest, "select-item",
281
G_CALLBACK (gimp_controller_list_select_item),
283
g_signal_connect_object (list->dest, "activate-item",
284
G_CALLBACK (gimp_controller_list_activate_item),
288
gimp_editor_add_button (GIMP_EDITOR (list->dest),
290
_("Configure the selected controller"),
292
G_CALLBACK (gimp_controller_list_edit_clicked),
296
gimp_editor_add_button (GIMP_EDITOR (list->dest),
298
_("Move the selected controller up"),
300
G_CALLBACK (gimp_controller_list_up_clicked),
304
gimp_editor_add_button (GIMP_EDITOR (list->dest),
306
_("Move the selected controller down"),
308
G_CALLBACK (gimp_controller_list_down_clicked),
312
gtk_widget_set_sensitive (list->edit_button, FALSE);
313
gtk_widget_set_sensitive (list->up_button, FALSE);
314
gtk_widget_set_sensitive (list->down_button, FALSE);
318
gimp_controller_list_constructor (GType type,
320
GObjectConstructParam *params)
323
GimpControllerList *list;
325
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
327
list = GIMP_CONTROLLER_LIST (object);
329
g_assert (GIMP_IS_GIMP (list->gimp));
331
gimp_container_view_set_container (GIMP_CONTAINER_VIEW (list->dest),
332
gimp_controllers_get_list (list->gimp));
334
gimp_container_view_set_context (GIMP_CONTAINER_VIEW (list->dest),
335
gimp_get_user_context (list->gimp));
341
gimp_controller_list_set_property (GObject *object,
346
GimpControllerList *list = GIMP_CONTROLLER_LIST (object);
351
list->gimp = GIMP (g_value_dup_object (value));
354
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
360
gimp_controller_list_get_property (GObject *object,
365
GimpControllerList *list = GIMP_CONTROLLER_LIST (object);
370
g_value_set_object (value, list->gimp);
373
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
379
gimp_controller_list_finalize (GObject *object)
381
GimpControllerList *list = GIMP_CONTROLLER_LIST (object);
385
g_object_unref (list->gimp);
389
G_OBJECT_CLASS (parent_class)->finalize (object);
393
/* public functions */
396
gimp_controller_list_new (Gimp *gimp)
398
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
400
return g_object_new (GIMP_TYPE_CONTROLLER_LIST,
406
/* private functions */
409
gimp_controller_list_src_sel_changed (GtkTreeSelection *sel,
410
GimpControllerList *list)
416
if (gtk_tree_selection_get_selected (sel, &model, &iter))
420
gtk_tree_model_get (model, &iter,
422
COLUMN_TYPE, &list->src_gtype,
425
if (list->add_button)
428
g_strdup_printf (_("Add '%s' to the list of active controllers"),
430
gtk_widget_set_sensitive (list->add_button, TRUE);
437
if (list->add_button)
438
gtk_widget_set_sensitive (list->add_button, FALSE);
441
if (list->add_button)
443
gimp_help_set_help_data (list->add_button, tip, NULL);
449
gimp_controller_list_row_activated (GtkTreeView *tv,
451
GtkTreeViewColumn *column,
452
GimpControllerList *list)
454
if (GTK_WIDGET_IS_SENSITIVE (list->add_button))
455
gtk_button_clicked (GTK_BUTTON (list->add_button));
459
gimp_controller_list_select_item (GimpContainerView *view,
460
GimpViewable *viewable,
461
gpointer insert_data,
462
GimpControllerList *list)
466
list->dest_info = GIMP_CONTROLLER_INFO (viewable);
468
selected = GIMP_IS_CONTROLLER_INFO (list->dest_info);
470
if (list->remove_button)
472
GimpObject *object = GIMP_OBJECT (list->dest_info);
475
gtk_widget_set_sensitive (list->remove_button, selected);
479
g_strdup_printf (_("Remove '%s' from the list of active controllers"),
480
gimp_object_get_name (object));
482
gimp_help_set_help_data (list->remove_button, tip, NULL);
486
gtk_widget_set_sensitive (list->edit_button, selected);
487
gtk_widget_set_sensitive (list->up_button, selected);
488
gtk_widget_set_sensitive (list->down_button, selected);
492
gimp_controller_list_activate_item (GimpContainerView *view,
493
GimpViewable *viewable,
494
gpointer insert_data,
495
GimpControllerList *list)
497
if (GTK_WIDGET_IS_SENSITIVE (list->edit_button))
498
gtk_button_clicked (GTK_BUTTON (list->edit_button));
502
gimp_controller_list_add_clicked (GtkWidget *button,
503
GimpControllerList *list)
505
GimpControllerInfo *info;
506
GimpContainer *container;
508
if (list->src_gtype == GIMP_TYPE_CONTROLLER_KEYBOARD &&
509
gimp_controllers_get_keyboard (list->gimp) != NULL)
511
gimp_message (list->gimp, G_OBJECT (button), GIMP_MESSAGE_WARNING,
512
_("There can only be one active keyboard "
514
"You already have a keyboard controller in "
515
"your list of active controllers."));
518
else if (list->src_gtype == GIMP_TYPE_CONTROLLER_WHEEL &&
519
gimp_controllers_get_wheel (list->gimp) != NULL)
521
gimp_message (list->gimp, G_OBJECT (button), GIMP_MESSAGE_WARNING,
522
_("There can only be one active wheel "
524
"You already have a wheel controller in "
525
"your list of active controllers."));
529
info = gimp_controller_info_new (list->src_gtype);
530
container = gimp_controllers_get_list (list->gimp);
531
gimp_container_add (container, GIMP_OBJECT (info));
532
g_object_unref (info);
534
gimp_container_view_select_item (GIMP_CONTAINER_VIEW (list->dest),
535
GIMP_VIEWABLE (info));
536
gimp_controller_list_edit_clicked (NULL, list);
540
gimp_controller_list_remove_clicked (GtkWidget *button,
541
GimpControllerList *list)
547
#define RESPONSE_DISABLE 1
549
dialog = gimp_message_dialog_new (_("Remove Controller?"),
551
GTK_WIDGET (list), GTK_DIALOG_MODAL,
554
_("Disable Controller"), RESPONSE_DISABLE,
555
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
556
_("Remove Controller"), GTK_RESPONSE_OK,
560
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
567
g_strdup_printf (_("Remove Controller '%s'?"),
568
gimp_object_get_name (GIMP_OBJECT (list->dest_info)));
571
g_strdup_printf (_("Removing this controller from the list of "
572
"active controllers will permanently delete "
573
"all event mappings you have configured.\n\n"
574
"Selecting \"Disable Controller\" will disable "
575
"the controller without removing it."));
577
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
579
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
585
switch (gimp_dialog_run (GIMP_DIALOG (dialog)))
587
case RESPONSE_DISABLE:
588
gimp_controller_info_set_enabled (list->dest_info, FALSE);
591
case GTK_RESPONSE_OK:
593
GtkWidget *editor_dialog;
594
GimpContainer *container;
596
editor_dialog = g_object_get_data (G_OBJECT (list->dest_info),
597
"gimp-controller-editor-dialog");
600
gtk_dialog_response (GTK_DIALOG (editor_dialog),
601
GTK_RESPONSE_DELETE_EVENT);
603
container = gimp_controllers_get_list (list->gimp);
604
gimp_container_remove (container, GIMP_OBJECT (list->dest_info));
612
gtk_widget_destroy (dialog);
616
gimp_controller_list_edit_clicked (GtkWidget *button,
617
GimpControllerList *list)
622
dialog = g_object_get_data (G_OBJECT (list->dest_info),
623
"gimp-controller-editor-dialog");
627
gtk_window_present (GTK_WINDOW (dialog));
631
dialog = gimp_dialog_new (_("Configure Input Controller"),
632
"gimp-controller-editor-dialog",
633
gtk_widget_get_toplevel (GTK_WIDGET (list)),
634
GTK_DIALOG_DESTROY_WITH_PARENT,
635
gimp_standard_help_func,
636
GIMP_HELP_PREFS_INPUT_CONTROLLERS,
638
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
642
gimp_dialog_factory_add_foreign (gimp_dialog_factory_from_name ("toplevel"),
643
"gimp-controller-editor-dialog",
646
g_signal_connect (dialog, "response",
647
G_CALLBACK (gtk_widget_destroy),
650
editor = gimp_controller_editor_new (list->dest_info,
651
gimp_get_user_context (list->gimp));
652
gtk_container_set_border_width (GTK_CONTAINER (editor), 12);
653
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), editor);
654
gtk_widget_show (editor);
656
g_object_set_data (G_OBJECT (list->dest_info), "gimp-controller-editor-dialog",
659
g_signal_connect_object (dialog, "destroy",
660
G_CALLBACK (gimp_controller_list_edit_destroy),
661
G_OBJECT (list->dest_info), 0);
663
g_signal_connect_object (list, "destroy",
664
G_CALLBACK (gtk_widget_destroy),
667
g_signal_connect_object (list, "unmap",
668
G_CALLBACK (gtk_widget_destroy),
672
gtk_widget_show (dialog);
676
gimp_controller_list_edit_destroy (GtkWidget *widget,
677
GimpControllerInfo *info)
679
g_object_set_data (G_OBJECT (info), "gimp-controller-editor-dialog", NULL);
683
gimp_controller_list_up_clicked (GtkWidget *button,
684
GimpControllerList *list)
686
GimpContainer *container;
689
container = gimp_controllers_get_list (list->gimp);
691
index = gimp_container_get_child_index (container,
692
GIMP_OBJECT (list->dest_info));
695
gimp_container_reorder (container, GIMP_OBJECT (list->dest_info),
700
gimp_controller_list_down_clicked (GtkWidget *button,
701
GimpControllerList *list)
703
GimpContainer *container;
706
container = gimp_controllers_get_list (list->gimp);
708
index = gimp_container_get_child_index (container,
709
GIMP_OBJECT (list->dest_info));
711
if (index < gimp_container_num_children (container) - 1)
712
gimp_container_reorder (container, GIMP_OBJECT (list->dest_info),