50
50
#define CELL_SIZE 20 /* The size of the view cells */
53
60
struct _GimpDeviceStatusEntry
62
GimpDeviceInfo *device_info;
61
GtkWidget *foreground;
62
GtkWidget *background;
68
GtkWidget *foreground;
69
GtkWidget *background;
69
static void gimp_device_status_class_init (GimpDeviceStatusClass *klass);
70
static void gimp_device_status_init (GimpDeviceStatus *editor);
76
static GObject *gimp_device_status_constructor (GType type,
78
GObjectConstructParam *params);
79
static void gimp_device_status_set_property (GObject *object,
72
84
static void gimp_device_status_destroy (GtkObject *object);
86
static void gimp_device_status_device_add (GimpContainer *devices,
87
GimpDeviceInfo *device_info,
88
GimpDeviceStatus *status);
89
static void gimp_device_status_device_remove (GimpContainer *devices,
90
GimpDeviceInfo *device_info,
91
GimpDeviceStatus *status);
74
93
static void gimp_device_status_update_entry (GimpDeviceInfo *device_info,
75
94
GimpDeviceStatusEntry *entry);
76
95
static void gimp_device_status_save_clicked (GtkWidget *button,
77
96
GimpDeviceStatus *status);
78
static void gimp_device_status_preview_clicked (GtkWidget *widget,
97
static void gimp_device_status_view_clicked (GtkWidget *widget,
79
98
GdkModifierType state,
80
99
const gchar *identifier);
83
static GimpEditorClass *parent_class = NULL;
87
gimp_device_status_get_type (void)
89
static GType view_type = 0;
93
static const GTypeInfo view_info =
95
sizeof (GimpDeviceStatusClass),
97
NULL, /* base_finalize */
98
(GClassInitFunc) gimp_device_status_class_init,
99
NULL, /* class_finalize */
100
NULL, /* class_data */
101
sizeof (GimpDeviceStatus),
103
(GInstanceInitFunc) gimp_device_status_init,
106
view_type = g_type_register_static (GIMP_TYPE_EDITOR,
102
G_DEFINE_TYPE (GimpDeviceStatus, gimp_device_status, GIMP_TYPE_EDITOR)
104
#define parent_class gimp_device_status_parent_class
115
108
gimp_device_status_class_init (GimpDeviceStatusClass *klass)
117
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
119
parent_class = g_type_class_peek_parent (klass);
121
object_class->destroy = gimp_device_status_destroy;
110
GObjectClass *object_class = G_OBJECT_CLASS (klass);
111
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
113
object_class->constructor = gimp_device_status_constructor;
114
object_class->set_property = gimp_device_status_set_property;
116
gtk_object_class->destroy = gimp_device_status_destroy;
118
g_object_class_install_property (object_class, PROP_GIMP,
119
g_param_spec_object ("gimp", NULL, NULL,
121
GIMP_PARAM_WRITABLE |
122
G_PARAM_CONSTRUCT_ONLY));
125
126
gimp_device_status_init (GimpDeviceStatus *status)
131
display = gtk_widget_get_display (GTK_WIDGET (status));
133
128
status->gimp = NULL;
134
129
status->current_device = NULL;
135
status->num_devices = g_list_length (gdk_display_list_devices (display));
136
status->entries = g_new0 (GimpDeviceStatusEntry,
137
status->num_devices);
139
status->table = gtk_table_new (status->num_devices * 3, 7, FALSE);
140
gtk_container_set_border_width (GTK_CONTAINER (status->table), 6);
141
gtk_table_set_col_spacings (GTK_TABLE (status->table), 6);
142
gtk_container_add (GTK_CONTAINER (status), status->table);
143
gtk_widget_show (status->table);
145
for (list = gdk_display_list_devices (display), i = 0;
147
list = list->next, i++)
149
GimpDeviceInfo *device_info;
150
GimpContext *context;
151
GimpDeviceStatusEntry *entry = &status->entries[i];
156
entry->device = GDK_DEVICE (list->data);
158
device_info = gimp_device_info_get_by_device (entry->device);
159
context = GIMP_CONTEXT (device_info);
161
closure = g_cclosure_new (G_CALLBACK (gimp_device_status_update_entry),
163
g_object_watch_closure (G_OBJECT (status), closure);
164
g_signal_connect_closure (device_info, "changed", closure, FALSE);
168
entry->separator = gtk_hbox_new (FALSE, 0);
169
gtk_table_attach (GTK_TABLE (status->table), entry->separator,
171
GTK_FILL, GTK_FILL, 0, 2);
175
/* the device name */
177
entry->label = gtk_label_new (NULL);
179
markup = g_strdup_printf ("<b>%s</b>", GIMP_OBJECT (device_info)->name);
180
gtk_label_set_markup (GTK_LABEL (entry->label), markup);
183
gtk_widget_set_size_request (entry->label, -1, CELL_SIZE);
184
gtk_misc_set_alignment (GTK_MISC (entry->label), 0.0, 0.5);
185
gtk_table_attach (GTK_TABLE (status->table), entry->label,
187
GTK_FILL, GTK_FILL, 0, 2);
189
entry->arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
190
gtk_widget_set_size_request (entry->arrow, CELL_SIZE, CELL_SIZE);
191
gtk_table_attach (GTK_TABLE (status->table), entry->arrow,
193
GTK_FILL, GTK_FILL, 0, 0);
199
entry->tool = gimp_prop_preview_new (G_OBJECT (context),
201
GIMP_VIEW (entry->tool)->clickable = TRUE;
202
gtk_table_attach (GTK_TABLE (status->table), entry->tool,
206
g_signal_connect (entry->tool, "clicked",
207
G_CALLBACK (gimp_device_status_preview_clicked),
208
"gimp-tool-list|gimp-tool-grid");
210
/* the foreground color */
212
entry->foreground = gimp_prop_color_area_new (G_OBJECT (context),
214
CELL_SIZE, CELL_SIZE,
215
GIMP_COLOR_AREA_FLAT);
216
gtk_widget_add_events (entry->foreground,
217
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
218
gtk_table_attach (GTK_TABLE (status->table), entry->foreground,
222
/* the background color */
224
entry->background = gimp_prop_color_area_new (G_OBJECT (context),
226
CELL_SIZE, CELL_SIZE,
227
GIMP_COLOR_AREA_FLAT);
228
gtk_widget_add_events (entry->background,
229
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
230
gtk_table_attach (GTK_TABLE (status->table), entry->background,
236
entry->brush = gimp_prop_preview_new (G_OBJECT (context),
238
GIMP_VIEW (entry->brush)->clickable = TRUE;
239
GIMP_VIEW (entry->brush)->show_popup = TRUE;
240
gtk_table_attach (GTK_TABLE (status->table), entry->brush,
244
g_signal_connect (entry->brush, "clicked",
245
G_CALLBACK (gimp_device_status_preview_clicked),
246
"gimp-brush-grid|gimp-brush-list");
250
entry->pattern = gimp_prop_preview_new (G_OBJECT (context),
251
"pattern", CELL_SIZE);
252
GIMP_VIEW (entry->pattern)->clickable = TRUE;
253
GIMP_VIEW (entry->pattern)->show_popup = TRUE;
254
gtk_table_attach (GTK_TABLE (status->table), entry->pattern,
258
g_signal_connect (entry->pattern, "clicked",
259
G_CALLBACK (gimp_device_status_preview_clicked),
260
"gimp-pattern-grid|gimp-pattern-list");
264
entry->gradient = gimp_prop_preview_new (G_OBJECT (context),
265
"gradient", 2 * CELL_SIZE);
266
GIMP_VIEW (entry->gradient)->clickable = TRUE;
267
GIMP_VIEW (entry->gradient)->show_popup = TRUE;
268
gtk_table_attach (GTK_TABLE (status->table), entry->gradient,
272
g_signal_connect (entry->gradient, "clicked",
273
G_CALLBACK (gimp_device_status_preview_clicked),
274
"gimp-gradient-list|gimp-gradient-grid");
276
gimp_device_status_update_entry (device_info, entry);
131
status->vbox = gtk_vbox_new (FALSE, 12);
132
gtk_container_set_border_width (GTK_CONTAINER (status->vbox), 6);
133
gtk_container_add (GTK_CONTAINER (status), status->vbox);
134
gtk_widget_show (status->vbox);
279
136
status->save_button =
280
137
gimp_editor_add_button (GIMP_EDITOR (status), GTK_STOCK_SAVE,
145
gimp_device_status_constructor (GType type,
147
GObjectConstructParam *params)
150
GimpDeviceStatus *status;
151
GimpContainer *devices;
154
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
156
status = GIMP_DEVICE_STATUS (object);
158
g_assert (GIMP_IS_GIMP (status->gimp));
160
devices = gimp_devices_get_list (status->gimp);
162
for (list = GIMP_LIST (devices)->list; list; list = list->next)
163
gimp_device_status_device_add (devices, list->data, status);
165
g_signal_connect_object (devices, "add",
166
G_CALLBACK (gimp_device_status_device_add),
168
g_signal_connect_object (devices, "remove",
169
G_CALLBACK (gimp_device_status_device_remove),
172
gimp_device_status_update (status);
178
gimp_device_status_set_property (GObject *object,
183
GimpDeviceStatus *status = GIMP_DEVICE_STATUS (object);
188
status->gimp = g_value_get_object (value);
191
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
288
197
gimp_device_status_destroy (GtkObject *object)
290
199
GimpDeviceStatus *status = GIMP_DEVICE_STATUS (object);
296
for (i = 0; i < status->num_devices; i++)
205
for (list = status->devices; list; list = list->next)
298
GimpDeviceStatusEntry *entry = &status->entries[i];
207
GimpDeviceStatusEntry *entry = list->data;
300
g_signal_handlers_disconnect_by_func (entry->device,
209
g_signal_handlers_disconnect_by_func (entry->device_info,
301
210
gimp_device_status_update_entry,
305
g_free (status->entries);
306
status->entries = NULL;
307
status->num_devices = 0;
215
g_list_free (status->devices);
216
status->devices = NULL;
310
219
GTK_OBJECT_CLASS (parent_class)->destroy (object);
223
gimp_device_status_device_add (GimpContainer *devices,
224
GimpDeviceInfo *device_info,
225
GimpDeviceStatus *status)
227
GimpContext *context = GIMP_CONTEXT (device_info);
228
GimpDeviceStatusEntry *entry;
233
/* only list present devices */
234
if (! device_info->device)
237
entry = g_new0 (GimpDeviceStatusEntry, 1);
239
status->devices = g_list_prepend (status->devices, entry);
241
entry->device_info = device_info;
243
closure = g_cclosure_new (G_CALLBACK (gimp_device_status_update_entry),
245
g_object_watch_closure (G_OBJECT (status), closure);
246
g_signal_connect_closure (device_info, "changed", closure, FALSE);
248
entry->table = gtk_table_new (2, 7, FALSE);
249
gtk_table_set_col_spacings (GTK_TABLE (entry->table), 6);
250
gtk_box_pack_start (GTK_BOX (status->vbox), entry->table,
252
gtk_widget_show (entry->table);
254
/* the device name */
256
if (device_info->display == gdk_display_get_default ())
257
name = g_strdup (gimp_object_get_name (GIMP_OBJECT (device_info)));
259
name = g_strdup_printf ("%s (%s)",
260
gimp_object_get_name (GIMP_OBJECT (device_info)),
261
gdk_display_get_name (device_info->display));
263
entry->label = gtk_label_new (name);
266
gimp_label_set_attributes (GTK_LABEL (entry->label),
267
PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
269
gtk_widget_set_size_request (entry->label, -1, CELL_SIZE);
270
gtk_misc_set_alignment (GTK_MISC (entry->label), 0.0, 0.5);
271
gtk_table_attach (GTK_TABLE (entry->table), entry->label,
272
1, 7, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
273
gtk_widget_show (entry->label);
277
entry->arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
278
gtk_widget_set_size_request (entry->arrow, CELL_SIZE, CELL_SIZE);
279
gtk_table_attach (GTK_TABLE (entry->table), entry->arrow,
280
0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
282
hbox = gtk_hbox_new (FALSE, 0);
283
gtk_widget_set_size_request (hbox, CELL_SIZE, CELL_SIZE);
284
gtk_table_attach (GTK_TABLE (entry->table), hbox,
285
0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
286
gtk_widget_show (hbox);
290
entry->tool = gimp_prop_view_new (G_OBJECT (context), "tool",
292
GIMP_VIEW (entry->tool)->clickable = TRUE;
293
gtk_table_attach (GTK_TABLE (entry->table), entry->tool,
294
1, 2, 1, 2, 0, 0, 0, 0);
295
gtk_widget_show (entry->tool);
297
g_signal_connect (entry->tool, "clicked",
298
G_CALLBACK (gimp_device_status_view_clicked),
299
"gimp-tool-list|gimp-tool-grid");
301
/* the foreground color */
303
entry->foreground = gimp_prop_color_area_new (G_OBJECT (context),
305
CELL_SIZE, CELL_SIZE,
306
GIMP_COLOR_AREA_FLAT);
307
gtk_widget_add_events (entry->foreground,
308
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
309
gtk_table_attach (GTK_TABLE (entry->table), entry->foreground,
310
2, 3, 1, 2, 0, 0, 0, 0);
311
gtk_widget_show (entry->foreground);
313
/* the background color */
315
entry->background = gimp_prop_color_area_new (G_OBJECT (context),
317
CELL_SIZE, CELL_SIZE,
318
GIMP_COLOR_AREA_FLAT);
319
gtk_widget_add_events (entry->background,
320
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
321
gtk_table_attach (GTK_TABLE (entry->table), entry->background,
322
3, 4, 1, 2, 0, 0, 0, 0);
323
gtk_widget_show (entry->background);
327
entry->brush = gimp_prop_view_new (G_OBJECT (context), "brush",
329
GIMP_VIEW (entry->brush)->clickable = TRUE;
330
GIMP_VIEW (entry->brush)->show_popup = TRUE;
331
gtk_table_attach (GTK_TABLE (entry->table), entry->brush,
332
4, 5, 1, 2, 0, 0, 0, 0);
333
gtk_widget_show (entry->brush);
335
g_signal_connect (entry->brush, "clicked",
336
G_CALLBACK (gimp_device_status_view_clicked),
337
"gimp-brush-grid|gimp-brush-list");
341
entry->pattern = gimp_prop_view_new (G_OBJECT (context), "pattern",
343
GIMP_VIEW (entry->pattern)->clickable = TRUE;
344
GIMP_VIEW (entry->pattern)->show_popup = TRUE;
345
gtk_table_attach (GTK_TABLE (entry->table), entry->pattern,
346
5, 6, 1, 2, 0, 0, 0, 0);
347
gtk_widget_show (entry->pattern);
349
g_signal_connect (entry->pattern, "clicked",
350
G_CALLBACK (gimp_device_status_view_clicked),
351
"gimp-pattern-grid|gimp-pattern-list");
355
entry->gradient = gimp_prop_view_new (G_OBJECT (context), "gradient",
356
context, 2 * CELL_SIZE);
357
GIMP_VIEW (entry->gradient)->clickable = TRUE;
358
GIMP_VIEW (entry->gradient)->show_popup = TRUE;
359
gtk_table_attach (GTK_TABLE (entry->table), entry->gradient,
360
6, 7, 1, 2, 0, 0, 0, 0);
361
gtk_widget_show (entry->gradient);
363
g_signal_connect (entry->gradient, "clicked",
364
G_CALLBACK (gimp_device_status_view_clicked),
365
"gimp-gradient-list|gimp-gradient-grid");
367
gimp_device_status_update_entry (device_info, entry);
371
gimp_device_status_device_remove (GimpContainer *devices,
372
GimpDeviceInfo *device_info,
373
GimpDeviceStatus *status)
377
for (list = status->devices; list; list = list->next)
379
GimpDeviceStatusEntry *entry = list->data;
381
if (entry->device_info == device_info)
383
status->devices = g_list_remove (status->devices, entry);
385
g_signal_handlers_disconnect_by_func (entry->device_info,
386
gimp_device_status_update_entry,
314
396
gimp_device_status_new (Gimp *gimp)
316
GimpDeviceStatus *status;
318
398
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
320
status = g_object_new (GIMP_TYPE_DEVICE_STATUS, NULL);
324
gimp_device_status_update (status);
326
return GTK_WIDGET (status);
400
return g_object_new (GIMP_TYPE_DEVICE_STATUS,
330
406
gimp_device_status_update (GimpDeviceStatus *status)
334
410
g_return_if_fail (GIMP_IS_DEVICE_STATUS (status));
336
412
status->current_device = gimp_devices_get_current (status->gimp);
338
for (i = 0; i < status->num_devices; i++)
414
for (list = status->devices; list; list = list->next)
340
GimpDeviceStatusEntry *entry = &status->entries[i];
416
GimpDeviceStatusEntry *entry = list->data;
342
if (entry->device == status->current_device)
418
if (entry->device_info->device &&
419
entry->device_info->device == status->current_device)
343
420
gtk_widget_show (entry->arrow);
345
422
gtk_widget_hide (entry->arrow);