1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpdockcolumns.c
* Copyright (C) 2009 Martin Nordholts <martinn@src.gnome.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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "widgets-types.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpmarshal.h"
#include "gimpdialogfactory.h"
#include "gimpdock.h"
#include "gimpdockable.h"
#include "gimpdockbook.h"
#include "gimpdockcolumns.h"
#include "gimpmenudock.h"
#include "gimppanedbox.h"
#include "gimptoolbox.h"
#include "gimpuimanager.h"
#include "gimp-log.h"
enum
{
PROP_0,
PROP_CONTEXT,
PROP_DIALOG_FACTORY,
PROP_UI_MANAGER
};
enum
{
DOCK_ADDED,
DOCK_REMOVED,
LAST_SIGNAL
};
struct _GimpDockColumnsPrivate
{
GimpContext *context;
GimpDialogFactory *dialog_factory;
GimpUIManager *ui_manager;
GList *docks;
GtkWidget *paned_hbox;
};
static void gimp_dock_columns_dispose (GObject *object);
static void gimp_dock_columns_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_dock_columns_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static gboolean gimp_dock_columns_dropped_cb (GtkWidget *source,
gint insert_index,
gpointer data);
static void gimp_dock_columns_real_dock_added (GimpDockColumns *dock_columns,
GimpDock *dock);
static void gimp_dock_columns_real_dock_removed (GimpDockColumns *dock_columns,
GimpDock *dock);
static void gimp_dock_columns_dock_book_removed (GimpDockColumns *dock_columns,
GimpDockbook *dockbook,
GimpDock *dock);
G_DEFINE_TYPE_WITH_PRIVATE (GimpDockColumns, gimp_dock_columns, GTK_TYPE_BOX)
#define parent_class gimp_dock_columns_parent_class
static guint dock_columns_signals[LAST_SIGNAL] = { 0 };
static void
gimp_dock_columns_class_init (GimpDockColumnsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = gimp_dock_columns_dispose;
object_class->set_property = gimp_dock_columns_set_property;
object_class->get_property = gimp_dock_columns_get_property;
klass->dock_added = gimp_dock_columns_real_dock_added;
klass->dock_removed = gimp_dock_columns_real_dock_removed;
g_object_class_install_property (object_class, PROP_CONTEXT,
g_param_spec_object ("context",
NULL, NULL,
GIMP_TYPE_CONTEXT,
GIMP_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_DIALOG_FACTORY,
g_param_spec_object ("dialog-factory",
NULL, NULL,
GIMP_TYPE_DIALOG_FACTORY,
GIMP_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_UI_MANAGER,
g_param_spec_object ("ui-manager",
NULL, NULL,
GIMP_TYPE_UI_MANAGER,
GIMP_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
dock_columns_signals[DOCK_ADDED] =
g_signal_new ("dock-added",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpDockColumnsClass, dock_added),
NULL, NULL,
gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GIMP_TYPE_DOCK);
dock_columns_signals[DOCK_REMOVED] =
g_signal_new ("dock-removed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpDockColumnsClass, dock_removed),
NULL, NULL,
gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GIMP_TYPE_DOCK);
}
static void
gimp_dock_columns_init (GimpDockColumns *dock_columns)
{
gtk_orientable_set_orientation (GTK_ORIENTABLE (dock_columns),
GTK_ORIENTATION_HORIZONTAL);
dock_columns->p = gimp_dock_columns_get_instance_private (dock_columns);
dock_columns->p->paned_hbox = gimp_paned_box_new (FALSE, 0,
GTK_ORIENTATION_HORIZONTAL);
gimp_paned_box_set_dropped_cb (GIMP_PANED_BOX (dock_columns->p->paned_hbox),
gimp_dock_columns_dropped_cb,
dock_columns);
gtk_box_pack_start (GTK_BOX (dock_columns), dock_columns->p->paned_hbox,
TRUE, TRUE, 0);
gtk_widget_show (dock_columns->p->paned_hbox);
}
static void
gimp_dock_columns_dispose (GObject *object)
{
GimpDockColumns *dock_columns = GIMP_DOCK_COLUMNS (object);
while (dock_columns->p->docks)
{
GimpDock *dock = dock_columns->p->docks->data;
g_object_ref (dock);
gimp_dock_columns_remove_dock (dock_columns, dock);
gtk_widget_destroy (GTK_WIDGET (dock));
g_object_unref (dock);
}
if (dock_columns->p->context)
{
g_object_remove_weak_pointer (G_OBJECT (dock_columns->p->context),
(gpointer) &dock_columns->p->context);
dock_columns->p->context = NULL;
}
if (dock_columns->p->dialog_factory)
{
g_object_remove_weak_pointer (G_OBJECT (dock_columns->p->dialog_factory),
(gpointer) &dock_columns->p->dialog_factory);
dock_columns->p->dialog_factory = NULL;
}
if (dock_columns->p->ui_manager)
{
g_object_remove_weak_pointer (G_OBJECT (dock_columns->p->ui_manager),
(gpointer)&dock_columns->p->ui_manager);
dock_columns->p->ui_manager = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gimp_dock_columns_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpDockColumns *dock_columns = GIMP_DOCK_COLUMNS (object);
switch (property_id)
{
case PROP_CONTEXT:
if (dock_columns->p->context)
g_object_remove_weak_pointer (G_OBJECT (dock_columns->p->context),
(gpointer) &dock_columns->p->context);
dock_columns->p->context = g_value_get_object (value);
if (dock_columns->p->context)
g_object_add_weak_pointer (G_OBJECT (dock_columns->p->context),
(gpointer) &dock_columns->p->context);
break;
case PROP_DIALOG_FACTORY:
if (dock_columns->p->dialog_factory)
g_object_remove_weak_pointer (G_OBJECT (dock_columns->p->dialog_factory),
(gpointer) &dock_columns->p->dialog_factory);
dock_columns->p->dialog_factory = g_value_get_object (value);
if (dock_columns->p->dialog_factory)
g_object_add_weak_pointer (G_OBJECT (dock_columns->p->dialog_factory),
(gpointer) &dock_columns->p->dialog_factory);
break;
case PROP_UI_MANAGER:
if (dock_columns->p->ui_manager)
g_object_remove_weak_pointer (G_OBJECT (dock_columns->p->ui_manager),
(gpointer) &dock_columns->p->ui_manager);
dock_columns->p->ui_manager = g_value_get_object (value);
if (dock_columns->p->ui_manager)
g_object_add_weak_pointer (G_OBJECT (dock_columns->p->ui_manager),
(gpointer) &dock_columns->p->ui_manager);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_dock_columns_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpDockColumns *dock_columns = GIMP_DOCK_COLUMNS (object);
switch (property_id)
{
case PROP_CONTEXT:
g_value_set_object (value, dock_columns->p->context);
break;
case PROP_DIALOG_FACTORY:
g_value_set_object (value, dock_columns->p->dialog_factory);
break;
case PROP_UI_MANAGER:
g_value_set_object (value, dock_columns->p->ui_manager);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gboolean
gimp_dock_columns_dropped_cb (GtkWidget *source,
gint insert_index,
gpointer data)
{
GimpDockColumns *dock_columns = GIMP_DOCK_COLUMNS (data);
GimpDockable *dockable = gimp_dockbook_drag_source_to_dockable (source);
GtkWidget *dockbook = NULL;
if (! dockable)
return FALSE;
/* Create a new dock (including a new dockbook) */
gimp_dock_columns_prepare_dockbook (dock_columns,
insert_index,
&dockbook);
/* Move the dockable to the new dockbook */
g_object_ref (dockbook);
g_object_ref (dockable);
gimp_dockbook_remove (gimp_dockable_get_dockbook (dockable), dockable);
gimp_dockbook_add (GIMP_DOCKBOOK (dockbook), dockable, -1);
g_object_unref (dockable);
g_object_unref (dockbook);
return TRUE;
}
static void
gimp_dock_columns_real_dock_added (GimpDockColumns *dock_columns,
GimpDock *dock)
{
}
static void
gimp_dock_columns_real_dock_removed (GimpDockColumns *dock_columns,
GimpDock *dock)
{
}
static void
gimp_dock_columns_dock_book_removed (GimpDockColumns *dock_columns,
GimpDockbook *dockbook,
GimpDock *dock)
{
g_return_if_fail (GIMP_IS_DOCK (dock));
if (gimp_dock_get_dockbooks (dock) == NULL &&
! GIMP_IS_TOOLBOX (dock) &&
gtk_widget_get_parent (GTK_WIDGET (dock)) != NULL)
gimp_dock_columns_remove_dock (dock_columns, dock);
}
/**
* gimp_dock_columns_new:
* @context:
*
* Returns: A new #GimpDockColumns.
**/
GtkWidget *
gimp_dock_columns_new (GimpContext *context,
GimpDialogFactory *dialog_factory,
GimpUIManager *ui_manager)
{
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (dialog_factory), NULL);
g_return_val_if_fail (GIMP_IS_UI_MANAGER (ui_manager), NULL);
return g_object_new (GIMP_TYPE_DOCK_COLUMNS,
"context", context,
"dialog-factory", dialog_factory,
"ui-manager", ui_manager,
NULL);
}
/**
* gimp_dock_columns_add_dock:
* @dock_columns:
* @dock:
*
* Add a dock, added to a horizontal GimpPanedBox.
**/
void
gimp_dock_columns_add_dock (GimpDockColumns *dock_columns,
GimpDock *dock,
gint index)
{
g_return_if_fail (GIMP_IS_DOCK_COLUMNS (dock_columns));
g_return_if_fail (GIMP_IS_DOCK (dock));
GIMP_LOG (DND, "Adding GimpDock %p to GimpDockColumns %p", dock, dock_columns);
dock_columns->p->docks = g_list_insert (dock_columns->p->docks, dock, index);
gimp_dock_update_with_context (dock, dock_columns->p->context);
gimp_paned_box_add_widget (GIMP_PANED_BOX (dock_columns->p->paned_hbox),
GTK_WIDGET (dock),
index);
g_signal_connect_object (dock, "book-removed",
G_CALLBACK (gimp_dock_columns_dock_book_removed),
dock_columns,
G_CONNECT_SWAPPED);
g_signal_emit (dock_columns, dock_columns_signals[DOCK_ADDED], 0, dock);
}
/**
* gimp_dock_columns_prepare_dockbook:
* @dock_columns:
* @dock_index:
* @dockbook_p:
*
* Create a new dock and add it to the dock columns with the given
* dock_index insert index, then create and add a dockbook and put it
* in the dock.
**/
void
gimp_dock_columns_prepare_dockbook (GimpDockColumns *dock_columns,
gint dock_index,
GtkWidget **dockbook_p)
{
GimpMenuFactory *menu_factory;
GtkWidget *dock;
GtkWidget *dockbook;
dock = gimp_menu_dock_new ();
gimp_dock_columns_add_dock (dock_columns, GIMP_DOCK (dock), dock_index);
menu_factory = gimp_dialog_factory_get_menu_factory (dock_columns->p->dialog_factory);
dockbook = gimp_dockbook_new (menu_factory);
gimp_dock_add_book (GIMP_DOCK (dock), GIMP_DOCKBOOK (dockbook), -1);
gtk_widget_show (GTK_WIDGET (dock));
if (dockbook_p)
*dockbook_p = dockbook;
}
void
gimp_dock_columns_remove_dock (GimpDockColumns *dock_columns,
GimpDock *dock)
{
g_return_if_fail (GIMP_IS_DOCK_COLUMNS (dock_columns));
g_return_if_fail (GIMP_IS_DOCK (dock));
GIMP_LOG (DND, "Removing GimpDock %p from GimpDockColumns %p", dock, dock_columns);
dock_columns->p->docks = g_list_remove (dock_columns->p->docks, dock);
gimp_dock_update_with_context (dock, NULL);
g_signal_handlers_disconnect_by_func (dock,
gimp_dock_columns_dock_book_removed,
dock_columns);
g_object_ref (dock);
gimp_paned_box_remove_widget (GIMP_PANED_BOX (dock_columns->p->paned_hbox),
GTK_WIDGET (dock));
g_signal_emit (dock_columns, dock_columns_signals[DOCK_REMOVED], 0, dock);
g_object_unref (dock);
}
GList *
gimp_dock_columns_get_docks (GimpDockColumns *dock_columns)
{
g_return_val_if_fail (GIMP_IS_DOCK_COLUMNS (dock_columns), NULL);
return dock_columns->p->docks;
}
GimpContext *
gimp_dock_columns_get_context (GimpDockColumns *dock_columns)
{
g_return_val_if_fail (GIMP_IS_DOCK_COLUMNS (dock_columns), NULL);
return dock_columns->p->context;
}
void
gimp_dock_columns_set_context (GimpDockColumns *dock_columns,
GimpContext *context)
{
g_return_if_fail (GIMP_IS_DOCK_COLUMNS (dock_columns));
dock_columns->p->context = context;
}
GimpDialogFactory *
gimp_dock_columns_get_dialog_factory (GimpDockColumns *dock_columns)
{
g_return_val_if_fail (GIMP_IS_DOCK_COLUMNS (dock_columns), NULL);
return dock_columns->p->dialog_factory;
}
GimpUIManager *
gimp_dock_columns_get_ui_manager (GimpDockColumns *dock_columns)
{
g_return_val_if_fail (GIMP_IS_DOCK_COLUMNS (dock_columns), NULL);
return dock_columns->p->ui_manager;
}
|