gimpcontext.c 114 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
4
 * gimpcontext.c
5
 * Copyright (C) 1999-2010 Michael Natterer
6
 *
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 3 of the License, or
10 11 12 13 14 15 16 17
 * (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
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
Sven Neumann's avatar
Sven Neumann committed
20 21 22

#include "config.h"

23
#include <cairo.h>
24
#include <gegl.h>
25

26
#include "libgimpbase/gimpbase.h"
27
#include "libgimpcolor/gimpcolor.h"
28
#include "libgimpconfig/gimpconfig.h"
29

30 31
#include "core-types.h"

32 33
#include "config/gimpcoreconfig.h"

34
#include "gimp.h"
35
#include "gimp-utils.h"
36
#include "gimpbrush.h"
37
#include "gimpbuffer.h"
38
#include "gimpcontainer.h"
39
#include "gimpcontext.h"
40
#include "gimpdatafactory.h"
Michael Natterer's avatar
Michael Natterer committed
41
#include "gimpdynamics.h"
42
#include "gimpimagefile.h"
43
#include "gimpgradient.h"
44
#include "gimpimage.h"
45
#include "gimpmarshal.h"
46
#include "gimppaintinfo.h"
47
#include "gimppalette.h"
48
#include "gimppattern.h"
49
#include "gimptemplate.h"
50
#include "gimptoolinfo.h"
51
#include "gimptoolpreset.h"
52

53 54
#include "text/gimpfont.h"

55
#include "gimp-intl.h"
56

57

58
typedef void (* GimpContextCopyPropFunc) (GimpContext *src,
59
                                          GimpContext *dest);
60 61


62 63 64
#define context_find_defined(context,prop) \
  while (!(((context)->defined_props) & (1 << (prop))) && (context)->parent) \
    (context) = (context)->parent
65

66 67

/*  local function prototypes  */
68

69
static void    gimp_context_config_iface_init (GimpConfigInterface   *iface);
70

71
static void       gimp_context_constructed    (GObject               *object);
72 73 74 75 76 77 78 79 80 81
static void       gimp_context_dispose        (GObject               *object);
static void       gimp_context_finalize       (GObject               *object);
static void       gimp_context_set_property   (GObject               *object,
                                               guint                  property_id,
                                               const GValue          *value,
                                               GParamSpec            *pspec);
static void       gimp_context_get_property   (GObject               *object,
                                               guint                  property_id,
                                               GValue                *value,
                                               GParamSpec            *pspec);
82 83
static gint64     gimp_context_get_memsize    (GimpObject            *object,
                                               gint64                *gui_size);
84

85
static gboolean   gimp_context_serialize            (GimpConfig       *config,
86 87
                                                     GimpConfigWriter *writer,
                                                     gpointer          data);
88
static gboolean   gimp_context_serialize_property   (GimpConfig       *config,
89 90 91 92
                                                     guint             property_id,
                                                     const GValue     *value,
                                                     GParamSpec       *pspec,
                                                     GimpConfigWriter *writer);
93
static gboolean   gimp_context_deserialize_property (GimpConfig       *config,
94 95 96 97 98
                                                     guint             property_id,
                                                     GValue           *value,
                                                     GParamSpec       *pspec,
                                                     GScanner         *scanner,
                                                     GTokenType       *expected);
99

100
/*  image  */
101
static void gimp_context_image_removed       (GimpContainer    *container,
102 103
                                              GimpImage        *image,
                                              GimpContext      *context);
104
static void gimp_context_real_set_image      (GimpContext      *context,
105
                                              GimpImage        *image);
106 107

/*  display  */
108
static void gimp_context_display_removed     (GimpContainer    *container,
109 110
                                              gpointer          display,
                                              GimpContext      *context);
111
static void gimp_context_real_set_display    (GimpContext      *context,
112
                                              gpointer          display);
113 114

/*  tool  */
115
static void gimp_context_tool_dirty          (GimpToolInfo     *tool_info,
116
                                              GimpContext      *context);
117
static void gimp_context_tool_removed        (GimpContainer    *container,
118 119
                                              GimpToolInfo     *tool_info,
                                              GimpContext      *context);
120
static void gimp_context_tool_list_thaw      (GimpContainer    *container,
121
                                              GimpContext      *context);
122
static void gimp_context_real_set_tool       (GimpContext      *context,
123
                                              GimpToolInfo     *tool_info);
124

125 126 127 128 129 130 131 132 133 134 135
/*  paint info  */
static void gimp_context_paint_info_dirty    (GimpPaintInfo    *paint_info,
                                              GimpContext      *context);
static void gimp_context_paint_info_removed  (GimpContainer    *container,
                                              GimpPaintInfo    *paint_info,
                                              GimpContext      *context);
static void gimp_context_paint_info_list_thaw(GimpContainer    *container,
                                              GimpContext      *context);
static void gimp_context_real_set_paint_info (GimpContext      *context,
                                              GimpPaintInfo    *paint_info);

136 137
/*  foreground  */
static void gimp_context_real_set_foreground (GimpContext      *context,
138
                                              const GimpRGB    *color);
139 140 141

/*  background  */
static void gimp_context_real_set_background (GimpContext      *context,
142
                                              const GimpRGB    *color);
143 144 145

/*  opacity  */
static void gimp_context_real_set_opacity    (GimpContext      *context,
146
                                              gdouble           opacity);
147 148 149

/*  paint mode  */
static void gimp_context_real_set_paint_mode (GimpContext      *context,
150
                                              GimpLayerModeEffects paint_mode);
151 152

/*  brush  */
153
static void gimp_context_brush_dirty         (GimpBrush        *brush,
154
                                              GimpContext      *context);
155
static void gimp_context_brush_removed       (GimpContainer    *brush_list,
156 157
                                              GimpBrush        *brush,
                                              GimpContext      *context);
158
static void gimp_context_brush_list_thaw     (GimpContainer    *container,
159
                                              GimpContext      *context);
160
static void gimp_context_real_set_brush      (GimpContext      *context,
161
                                              GimpBrush        *brush);
162

163 164
/*  dynamics  */

Michael Natterer's avatar
Michael Natterer committed
165 166
static void gimp_context_dynamics_dirty      (GimpDynamics     *dynamics,
                                              GimpContext      *context);
167
static void gimp_context_dynamics_removed    (GimpContainer    *container,
168
                                              GimpDynamics     *dynamics,
169 170 171 172
                                              GimpContext      *context);
static void gimp_context_dynamics_list_thaw  (GimpContainer    *container,
                                              GimpContext      *context);
static void gimp_context_real_set_dynamics   (GimpContext      *context,
173
                                              GimpDynamics     *dynamics);
174

175
/*  pattern  */
176
static void gimp_context_pattern_dirty       (GimpPattern      *pattern,
177
                                              GimpContext      *context);
178
static void gimp_context_pattern_removed     (GimpContainer    *container,
179 180
                                              GimpPattern      *pattern,
                                              GimpContext      *context);
181
static void gimp_context_pattern_list_thaw   (GimpContainer    *container,
182
                                              GimpContext      *context);
183
static void gimp_context_real_set_pattern    (GimpContext      *context,
184
                                              GimpPattern      *pattern);
185 186

/*  gradient  */
187
static void gimp_context_gradient_dirty      (GimpGradient     *gradient,
188
                                              GimpContext      *context);
189
static void gimp_context_gradient_removed    (GimpContainer    *container,
190 191
                                              GimpGradient     *gradient,
                                              GimpContext      *context);
192
static void gimp_context_gradient_list_thaw  (GimpContainer    *container,
193
                                              GimpContext      *context);
194
static void gimp_context_real_set_gradient   (GimpContext      *context,
195
                                              GimpGradient     *gradient);
196

197 198
/*  palette  */
static void gimp_context_palette_dirty       (GimpPalette      *palette,
199
                                              GimpContext      *context);
200
static void gimp_context_palette_removed     (GimpContainer    *container,
201 202
                                              GimpPalette      *palatte,
                                              GimpContext      *context);
203
static void gimp_context_palette_list_thaw   (GimpContainer    *container,
204
                                              GimpContext      *context);
205
static void gimp_context_real_set_palette    (GimpContext      *context,
206
                                              GimpPalette      *palatte);
207

208
/*  tool preset  */
209 210 211 212 213 214 215 216 217
static void gimp_context_tool_preset_dirty     (GimpToolPreset   *tool_preset,
                                                GimpContext      *context);
static void gimp_context_tool_preset_removed   (GimpContainer    *container,
                                                GimpToolPreset   *tool_preset,
                                                GimpContext      *context);
static void gimp_context_tool_preset_list_thaw (GimpContainer    *container,
                                                GimpContext      *context);
static void gimp_context_real_set_tool_preset  (GimpContext      *context,
                                                GimpToolPreset   *tool_preset);
218

219 220
/*  font  */
static void gimp_context_font_dirty          (GimpFont         *font,
221
                                              GimpContext      *context);
222
static void gimp_context_font_removed        (GimpContainer    *container,
223 224
                                              GimpFont         *font,
                                              GimpContext      *context);
225
static void gimp_context_font_list_thaw      (GimpContainer    *container,
226
                                              GimpContext      *context);
227
static void gimp_context_real_set_font       (GimpContext      *context,
228
                                              GimpFont         *font);
229

230 231
/*  buffer  */
static void gimp_context_buffer_dirty        (GimpBuffer       *buffer,
232
                                              GimpContext      *context);
233
static void gimp_context_buffer_removed      (GimpContainer    *container,
234 235
                                              GimpBuffer       *buffer,
                                              GimpContext      *context);
236
static void gimp_context_buffer_list_thaw    (GimpContainer    *container,
237
                                              GimpContext      *context);
238
static void gimp_context_real_set_buffer     (GimpContext      *context,
239
                                              GimpBuffer       *buffer);
240

241 242
/*  imagefile  */
static void gimp_context_imagefile_dirty     (GimpImagefile    *imagefile,
243
                                              GimpContext      *context);
244
static void gimp_context_imagefile_removed   (GimpContainer    *container,
245 246
                                              GimpImagefile    *imagefile,
                                              GimpContext      *context);
247
static void gimp_context_imagefile_list_thaw (GimpContainer    *container,
248
                                              GimpContext      *context);
249
static void gimp_context_real_set_imagefile  (GimpContext      *context,
250
                                              GimpImagefile    *imagefile);
251

252 253
/*  template  */
static void gimp_context_template_dirty      (GimpTemplate     *template,
254
                                              GimpContext      *context);
255
static void gimp_context_template_removed    (GimpContainer    *container,
256 257
                                              GimpTemplate     *template,
                                              GimpContext      *context);
258
static void gimp_context_template_list_thaw  (GimpContainer    *container,
259
                                              GimpContext      *context);
260
static void gimp_context_real_set_template   (GimpContext      *context,
261
                                              GimpTemplate     *template);
262

263

264 265 266 267 268 269 270
/*  utilities  */
static gpointer gimp_context_find_object     (GimpContext      *context,
                                              GimpContainer    *container,
                                              const gchar      *object_name,
                                              gpointer          standard_object);


271
/*  properties & signals  */
272

273 274
enum
{
275 276 277
  GIMP_CONTEXT_PROP_0,
  GIMP_CONTEXT_PROP_GIMP

Sven Neumann's avatar
Sven Neumann committed
278
  /*  remaining values are in core-enums.h  (GimpContextPropType)  */
279 280
};

281 282
enum
{
283 284
  DUMMY_0,
  DUMMY_1,
285 286 287
  IMAGE_CHANGED,
  DISPLAY_CHANGED,
  TOOL_CHANGED,
288
  PAINT_INFO_CHANGED,
289 290 291 292 293
  FOREGROUND_CHANGED,
  BACKGROUND_CHANGED,
  OPACITY_CHANGED,
  PAINT_MODE_CHANGED,
  BRUSH_CHANGED,
Alexia Death's avatar
Alexia Death committed
294
  DYNAMICS_CHANGED,
295 296
  PATTERN_CHANGED,
  GRADIENT_CHANGED,
297
  PALETTE_CHANGED,
298
  TOOL_PRESET_CHANGED,
299
  FONT_CHANGED,
300
  BUFFER_CHANGED,
301
  IMAGEFILE_CHANGED,
302
  TEMPLATE_CHANGED,
303 304 305
  LAST_SIGNAL
};

306
static const gchar * const gimp_context_prop_names[] =
307
{
308 309
  NULL, /* PROP_0 */
  "gimp",
310 311 312
  "image",
  "display",
  "tool",
313
  "paint-info",
314 315 316
  "foreground",
  "background",
  "opacity",
317
  "paint-mode",
318
  "brush",
Alexia Death's avatar
Alexia Death committed
319
  "dynamics",
320 321 322
  "pattern",
  "gradient",
  "palette",
323
  "tool-preset",
324
  "font",
325
  "buffer",
326
  "imagefile",
Alexia Death's avatar
Alexia Death committed
327
  "template"
328 329
};

330
static GType gimp_context_prop_types[] =
331
{
332 333
  G_TYPE_NONE, /* PROP_0    */
  G_TYPE_NONE, /* PROP_GIMP */
334
  0,
335
  G_TYPE_NONE,
336
  0,
337
  0,
338 339 340 341
  G_TYPE_NONE,
  G_TYPE_NONE,
  G_TYPE_NONE,
  G_TYPE_NONE,
342 343
  0,
  0,
344
  0,
345
  0,
346
  0,
347
  0,
348
  0,
349
  0,
350
  0,
351
  0
352 353
};

354

355
G_DEFINE_TYPE_WITH_CODE (GimpContext, gimp_context, GIMP_TYPE_VIEWABLE,
356
                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG,
357
                                                gimp_context_config_iface_init))
358 359

#define parent_class gimp_context_parent_class
360

361
static guint gimp_context_signals[LAST_SIGNAL] = { 0 };
362

363

364 365 366
static void
gimp_context_class_init (GimpContextClass *klass)
{
367 368
  GObjectClass    *object_class      = G_OBJECT_CLASS (klass);
  GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
369 370 371 372 373
  GimpRGB          black;
  GimpRGB          white;

  gimp_rgba_set (&black, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
  gimp_rgba_set (&white, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE);
374

375
  gimp_context_signals[IMAGE_CHANGED] =
376
    g_signal_new ("image-changed",
377 378 379 380 381 382 383
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, image_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
                  GIMP_TYPE_IMAGE);
384 385

  gimp_context_signals[DISPLAY_CHANGED] =
386
    g_signal_new ("display-changed",
387 388 389 390 391 392 393
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, display_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
                  GIMP_TYPE_OBJECT);
394 395

  gimp_context_signals[TOOL_CHANGED] =
396
    g_signal_new ("tool-changed",
397 398 399 400 401 402 403
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, tool_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
                  GIMP_TYPE_TOOL_INFO);
404

405 406 407 408 409 410 411 412 413 414
  gimp_context_signals[PAINT_INFO_CHANGED] =
    g_signal_new ("paint-info-changed",
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, paint_info_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
                  GIMP_TYPE_PAINT_INFO);

415
  gimp_context_signals[FOREGROUND_CHANGED] =
416
    g_signal_new ("foreground-changed",
417 418 419 420 421 422
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, foreground_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__BOXED,
                  G_TYPE_NONE, 1,
423
                  GIMP_TYPE_RGB | G_SIGNAL_TYPE_STATIC_SCOPE);
424 425

  gimp_context_signals[BACKGROUND_CHANGED] =
426
    g_signal_new ("background-changed",
427 428 429 430 431 432
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, background_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__BOXED,
                  G_TYPE_NONE, 1,
433
                  GIMP_TYPE_RGB | G_SIGNAL_TYPE_STATIC_SCOPE);
434

435
  gimp_context_signals[OPACITY_CHANGED] =
436
    g_signal_new ("opacity-changed",
437 438 439 440 441 442 443
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, opacity_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__DOUBLE,
                  G_TYPE_NONE, 1,
                  G_TYPE_DOUBLE);
444 445

  gimp_context_signals[PAINT_MODE_CHANGED] =
446
    g_signal_new ("paint-mode-changed",
447 448 449 450 451 452 453
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, paint_mode_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__ENUM,
                  G_TYPE_NONE, 1,
                  GIMP_TYPE_LAYER_MODE_EFFECTS);
454

455
  gimp_context_signals[BRUSH_CHANGED] =
456
    g_signal_new ("brush-changed",
457 458 459 460 461 462 463
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, brush_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
                  GIMP_TYPE_BRUSH);
464

465 466 467 468 469 470 471 472
  gimp_context_signals[DYNAMICS_CHANGED] =
    g_signal_new ("dynamics-changed",
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, dynamics_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
473
                  GIMP_TYPE_DYNAMICS);
474

475
  gimp_context_signals[PATTERN_CHANGED] =
476
    g_signal_new ("pattern-changed",
477 478 479 480 481 482 483
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, pattern_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
                  GIMP_TYPE_PATTERN);
484 485

  gimp_context_signals[GRADIENT_CHANGED] =
486
    g_signal_new ("gradient-changed",
487 488 489 490 491 492 493
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, gradient_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
                  GIMP_TYPE_GRADIENT);
494

495
  gimp_context_signals[PALETTE_CHANGED] =
496
    g_signal_new ("palette-changed",
497 498 499 500 501 502 503
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, palette_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
                  GIMP_TYPE_PALETTE);
504

505 506 507 508 509 510 511 512 513 514
  gimp_context_signals[TOOL_PRESET_CHANGED] =
    g_signal_new ("tool-preset-changed",
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, tool_preset_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
                  GIMP_TYPE_TOOL_PRESET);

515
  gimp_context_signals[FONT_CHANGED] =
516
    g_signal_new ("font-changed",
517 518 519 520 521 522 523
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, font_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
                  GIMP_TYPE_FONT);
524

525
  gimp_context_signals[BUFFER_CHANGED] =
526
    g_signal_new ("buffer-changed",
527 528 529 530 531 532 533
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, buffer_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
                  GIMP_TYPE_BUFFER);
534

535
  gimp_context_signals[IMAGEFILE_CHANGED] =
536
    g_signal_new ("imagefile-changed",
537 538 539 540 541 542 543
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, imagefile_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
                  GIMP_TYPE_IMAGEFILE);
544

545
  gimp_context_signals[TEMPLATE_CHANGED] =
546
    g_signal_new ("template-changed",
547 548 549 550 551 552 553
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GimpContextClass, template_changed),
                  NULL, NULL,
                  gimp_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
                  GIMP_TYPE_TEMPLATE);
554

555
  object_class->constructed      = gimp_context_constructed;
556 557 558 559 560 561 562 563 564 565
  object_class->set_property     = gimp_context_set_property;
  object_class->get_property     = gimp_context_get_property;
  object_class->dispose          = gimp_context_dispose;
  object_class->finalize         = gimp_context_finalize;

  gimp_object_class->get_memsize = gimp_context_get_memsize;

  klass->image_changed           = NULL;
  klass->display_changed         = NULL;
  klass->tool_changed            = NULL;
566
  klass->paint_info_changed      = NULL;
567 568 569 570 571
  klass->foreground_changed      = NULL;
  klass->background_changed      = NULL;
  klass->opacity_changed         = NULL;
  klass->paint_mode_changed      = NULL;
  klass->brush_changed           = NULL;
572
  klass->dynamics_changed        = NULL;
573 574 575
  klass->pattern_changed         = NULL;
  klass->gradient_changed        = NULL;
  klass->palette_changed         = NULL;
576
  klass->tool_preset_changed     = NULL;
577
  klass->font_changed            = NULL;
578 579
  klass->buffer_changed          = NULL;
  klass->imagefile_changed       = NULL;
580
  klass->template_changed        = NULL;
581

582 583 584 585 586 587 588 589 590 591 592 593 594
  gimp_context_prop_types[GIMP_CONTEXT_PROP_IMAGE]       = GIMP_TYPE_IMAGE;
  gimp_context_prop_types[GIMP_CONTEXT_PROP_TOOL]        = GIMP_TYPE_TOOL_INFO;
  gimp_context_prop_types[GIMP_CONTEXT_PROP_PAINT_INFO]  = GIMP_TYPE_PAINT_INFO;
  gimp_context_prop_types[GIMP_CONTEXT_PROP_BRUSH]       = GIMP_TYPE_BRUSH;
  gimp_context_prop_types[GIMP_CONTEXT_PROP_DYNAMICS]    = GIMP_TYPE_DYNAMICS;
  gimp_context_prop_types[GIMP_CONTEXT_PROP_PATTERN]     = GIMP_TYPE_PATTERN;
  gimp_context_prop_types[GIMP_CONTEXT_PROP_GRADIENT]    = GIMP_TYPE_GRADIENT;
  gimp_context_prop_types[GIMP_CONTEXT_PROP_PALETTE]     = GIMP_TYPE_PALETTE;
  gimp_context_prop_types[GIMP_CONTEXT_PROP_TOOL_PRESET] = GIMP_TYPE_TOOL_PRESET;
  gimp_context_prop_types[GIMP_CONTEXT_PROP_FONT]        = GIMP_TYPE_FONT;
  gimp_context_prop_types[GIMP_CONTEXT_PROP_BUFFER]      = GIMP_TYPE_BUFFER;
  gimp_context_prop_types[GIMP_CONTEXT_PROP_IMAGEFILE]   = GIMP_TYPE_IMAGEFILE;
  gimp_context_prop_types[GIMP_CONTEXT_PROP_TEMPLATE]    = GIMP_TYPE_TEMPLATE;
595

596
  g_object_class_install_property (object_class, GIMP_CONTEXT_PROP_GIMP,
597 598 599
                                   g_param_spec_object ("gimp",
                                                        NULL, NULL,
                                                        GIMP_TYPE_GIMP,
600
                                                        GIMP_PARAM_READWRITE |
601 602
                                                        G_PARAM_CONSTRUCT_ONLY));

603 604 605 606
  g_object_class_install_property (object_class, GIMP_CONTEXT_PROP_IMAGE,
                                   g_param_spec_object (gimp_context_prop_names[GIMP_CONTEXT_PROP_IMAGE],
                                                        NULL, NULL,
                                                        GIMP_TYPE_IMAGE,
607
                                                        GIMP_PARAM_READWRITE));
608

609 610
  g_object_class_install_property (object_class, GIMP_CONTEXT_PROP_DISPLAY,
                                   g_param_spec_object (gimp_context_prop_names[GIMP_CONTEXT_PROP_DISPLAY],
611 612
                                                        NULL, NULL,
                                                        GIMP_TYPE_OBJECT,
613
                                                        GIMP_PARAM_READWRITE));
614

615 616
  GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_TOOL,
                                   gimp_context_prop_names[GIMP_CONTEXT_PROP_TOOL], NULL,
617
                                   GIMP_TYPE_TOOL_INFO,
618
                                   GIMP_PARAM_STATIC_STRINGS);
619

620 621 622
  GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_PAINT_INFO,
                                   gimp_context_prop_names[GIMP_CONTEXT_PROP_PAINT_INFO], NULL,
                                   GIMP_TYPE_PAINT_INFO,
623
                                   GIMP_PARAM_STATIC_STRINGS);
624

625 626
  GIMP_CONFIG_INSTALL_PROP_RGB (object_class, GIMP_CONTEXT_PROP_FOREGROUND,
                                gimp_context_prop_names[GIMP_CONTEXT_PROP_FOREGROUND],
627 628
                                NULL,
                                FALSE, &black,
629
                                GIMP_PARAM_STATIC_STRINGS);
630 631 632

  GIMP_CONFIG_INSTALL_PROP_RGB (object_class, GIMP_CONTEXT_PROP_BACKGROUND,
                                gimp_context_prop_names[GIMP_CONTEXT_PROP_BACKGROUND],
633 634
                                NULL,
                                FALSE, &white,
635
                                GIMP_PARAM_STATIC_STRINGS);
636

637
  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, GIMP_CONTEXT_PROP_OPACITY,
638
                                   gimp_context_prop_names[GIMP_CONTEXT_PROP_OPACITY],
639
                                   _("Opacity"),
640 641
                                   GIMP_OPACITY_TRANSPARENT,
                                   GIMP_OPACITY_OPAQUE,
642
                                   GIMP_OPACITY_OPAQUE,
643
                                   GIMP_PARAM_STATIC_STRINGS);
644

645
  GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, GIMP_CONTEXT_PROP_PAINT_MODE,
646
                                 gimp_context_prop_names[GIMP_CONTEXT_PROP_PAINT_MODE],
647
                                 _("Paint Mode"),
648
                                 GIMP_TYPE_LAYER_MODE_EFFECTS,
649
                                 GIMP_NORMAL_MODE,
650
                                 GIMP_PARAM_STATIC_STRINGS);
651

652 653
  GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_BRUSH,
                                   gimp_context_prop_names[GIMP_CONTEXT_PROP_BRUSH],
654
                                   NULL,
655
                                   GIMP_TYPE_BRUSH,
656
                                   GIMP_PARAM_STATIC_STRINGS);
657

658 659 660
  GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_DYNAMICS,
                                   gimp_context_prop_names[GIMP_CONTEXT_PROP_DYNAMICS],
                                   NULL,
661
                                   GIMP_TYPE_DYNAMICS,
662
                                   GIMP_PARAM_STATIC_STRINGS);
663

664 665
  GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_PATTERN,
                                   gimp_context_prop_names[GIMP_CONTEXT_PROP_PATTERN],
666
                                   NULL,
667
                                   GIMP_TYPE_PATTERN,
668
                                   GIMP_PARAM_STATIC_STRINGS);
669

670 671
  GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_GRADIENT,
                                   gimp_context_prop_names[GIMP_CONTEXT_PROP_GRADIENT],
672
                                   NULL,
673
                                   GIMP_TYPE_GRADIENT,
674
                                   GIMP_PARAM_STATIC_STRINGS);
675

676 677
  GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_PALETTE,
                                   gimp_context_prop_names[GIMP_CONTEXT_PROP_PALETTE],
678
                                   NULL,
679
                                   GIMP_TYPE_PALETTE,
680
                                   GIMP_PARAM_STATIC_STRINGS);
681

682 683 684 685 686 687
  GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_TOOL_PRESET,
                                   gimp_context_prop_names[GIMP_CONTEXT_PROP_TOOL_PRESET],
                                   NULL,
                                   GIMP_TYPE_TOOL_PRESET,
                                   GIMP_PARAM_STATIC_STRINGS);

688 689 690 691
  GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_FONT,
                                   gimp_context_prop_names[GIMP_CONTEXT_PROP_FONT],
                                   NULL,
                                   GIMP_TYPE_FONT,
692
                                   GIMP_PARAM_STATIC_STRINGS);
693

694
  g_object_class_install_property (object_class, GIMP_CONTEXT_PROP_BUFFER,
695 696 697
                                   g_param_spec_object (gimp_context_prop_names[GIMP_CONTEXT_PROP_BUFFER],
                                                        NULL, NULL,
                                                        GIMP_TYPE_BUFFER,
698
                                                        GIMP_PARAM_READWRITE));
699

700
  g_object_class_install_property (object_class, GIMP_CONTEXT_PROP_IMAGEFILE,
701 702 703
                                   g_param_spec_object (gimp_context_prop_names[GIMP_CONTEXT_PROP_IMAGEFILE],
                                                        NULL, NULL,
                                                        GIMP_TYPE_IMAGEFILE,
704
                                                        GIMP_PARAM_READWRITE));
705 706

  g_object_class_install_property (object_class, GIMP_CONTEXT_PROP_TEMPLATE,
707 708 709
                                   g_param_spec_object (gimp_context_prop_names[GIMP_CONTEXT_PROP_TEMPLATE],
                                                        NULL, NULL,
                                                        GIMP_TYPE_TEMPLATE,
710
                                                        GIMP_PARAM_READWRITE));
711 712 713 714 715
}

static void
gimp_context_init (GimpContext *context)
{
716
  context->gimp            = NULL;
717

718
  context->parent          = NULL;
719

720 721
  context->defined_props   = GIMP_CONTEXT_ALL_PROPS_MASK;
  context->serialize_props = GIMP_CONTEXT_ALL_PROPS_MASK;
722

723 724
  context->image           = NULL;
  context->display         = NULL;
725

726 727
  context->tool_info       = NULL;
  context->tool_name       = NULL;
728

729 730 731
  context->paint_info      = NULL;
  context->paint_name      = NULL;

732 733
  context->brush           = NULL;
  context->brush_name      = NULL;
734

735 736 737
  context->dynamics        = NULL;
  context->dynamics_name   = NULL;

738 739
  context->pattern         = NULL;
  context->pattern_name    = NULL;
740

741 742
  context->gradient        = NULL;
  context->gradient_name   = NULL;
743

744 745
  context->palette         = NULL;
  context->palette_name    = NULL;
746

747 748 749
  context->tool_preset      = NULL;
  context->tool_preset_name = NULL;

750 751
  context->font            = NULL;
  context->font_name       = NULL;
752

753 754
  context->buffer          = NULL;
  context->buffer_name     = NULL;
755

756 757
  context->imagefile       = NULL;
  context->imagefile_name  = NULL;
758

759 760
  context->template        = NULL;
  context->template_name   = NULL;
761 762
}

763
static void
764
gimp_context_config_iface_init (GimpConfigInterface *iface)
765
{
766 767 768
  iface->serialize            = gimp_context_serialize;
  iface->serialize_property   = gimp_context_serialize_property;
  iface->deserialize_property = gimp_context_deserialize_property;
769 770
}

771 772
static void
gimp_context_constructed (GObject *object)
773
{
774 775
  Gimp          *gimp;
  GimpContainer *container;
776

777 778
  if (G_OBJECT_CLASS (parent_class)->constructed)
    G_OBJECT_CLASS (parent_class)->constructed (object);
779 780 781 782 783

  gimp = GIMP_CONTEXT (object)->gimp;

  g_assert (GIMP_IS_GIMP (gimp));

784 785
  gimp->context_list = g_list_prepend (gimp->context_list, object);

786
  g_signal_connect_object (gimp->images, "remove",
787 788
                           G_CALLBACK (gimp_context_image_removed),
                           object, 0);
789
  g_signal_connect_object (gimp->displays, "remove",
790 791
                           G_CALLBACK (gimp_context_display_removed),
                           object, 0);
792

793
  g_signal_connect_object (gimp->tool_info_list, "remove",
794 795
                           G_CALLBACK (gimp_context_tool_removed),
                           object, 0);
796
  g_signal_connect_object (gimp->tool_info_list, "thaw",
797 798
                           G_CALLBACK (gimp_context_tool_list_thaw),
                           object, 0);
799

800 801 802 803 804 805 806
  g_signal_connect_object (gimp->paint_info_list, "remove",
                           G_CALLBACK (gimp_context_paint_info_removed),
                           object, 0);
  g_signal_connect_object (gimp->paint_info_list, "thaw",
                           G_CALLBACK (gimp_context_paint_info_list_thaw),
                           object, 0);

807 808
  container = gimp_data_factory_get_container (gimp->brush_factory);
  g_signal_connect_object (container, "remove",
809 810
                           G_CALLBACK (gimp_context_brush_removed),
                           object, 0);
811
  g_signal_connect_object (container, "thaw",
812 813
                           G_CALLBACK (gimp_context_brush_list_thaw),
                           object, 0);
814

815 816
  container = gimp_data_factory_get_container (gimp->dynamics_factory);
  g_signal_connect_object (container, "remove",
817 818
                           G_CALLBACK (gimp_context_dynamics_removed),
                           object, 0);
819
  g_signal_connect_object (container, "thaw",
820 821 822
                           G_CALLBACK (gimp_context_dynamics_list_thaw),
                           object, 0);

823 824
  container = gimp_data_factory_get_container (gimp->pattern_factory);
  g_signal_connect_object (container, "remove",
825 826
                           G_CALLBACK (gimp_context_pattern_removed),
                           object, 0);
827
  g_signal_connect_object (container, "thaw",
828 829
                           G_CALLBACK (gimp_context_pattern_list_thaw),
                           object, 0);
830

831 832
  container = gimp_data_factory_get_container (gimp->gradient_factory);
  g_signal_connect_object (container, "remove",
833 834
                           G_CALLBACK (gimp_context_gradient_removed),
                           object, 0);
835
  g_signal_connect_object (container, "thaw",
836 837
                           G_CALLBACK (gimp_context_gradient_list_thaw),
                           object, 0);
838

839 840
  container = gimp_data_factory_get_container (gimp->palette_factory);
  g_signal_connect_object (container, "remove",
841 842
                           G_CALLBACK (gimp_context_palette_removed),
                           object, 0);
843
  g_signal_connect_object (container, "thaw",
844 845
                           G_CALLBACK (gimp_context_palette_list_thaw),
                           object, 0);
846

847 848
  container = gimp_data_factory_get_container (gimp->tool_preset_factory);
  g_signal_connect_object (container, "remove",
849 850
                           G_CALLBACK (gimp_context_tool_preset_removed),
                           object, 0);
851
  g_signal_connect_object (container, "thaw",
852 853 854
                           G_CALLBACK (gimp_context_tool_preset_list_thaw),
                           object, 0);

855
  g_signal_connect_object (gimp->fonts, "remove",
856 857
                           G_CALLBACK (gimp_context_font_removed),
                           object, 0);
858
  g_signal_connect_object (gimp->fonts, "thaw",
859 860
                           G_CALLBACK (gimp_context_font_list_thaw),
                           object, 0);
861

862
  g_signal_connect_object (gimp->named_buffers, "remove",
863 864
                           G_CALLBACK (gimp_context_buffer_removed),
                           object, 0);
865
  g_signal_connect_object (gimp->named_buffers, "thaw",
866 867
                           G_CALLBACK (gimp_context_buffer_list_thaw),
                           object, 0);
868

869
  g_signal_connect_object (gimp->documents, "remove",
870 871
                           G_CALLBACK (gimp_context_imagefile_removed),
                           object, 0);
872
  g_signal_connect_object (gimp->documents, "thaw",
873 874
                           G_CALLBACK (gimp_context_imagefile_list_thaw),
                           object, 0);
875

876
  g_signal_connect_object (gimp->templates, "remove",
877 878
                           G_CALLBACK (gimp_context_template_removed),
                           object, 0);
879
  g_signal_connect_object (gimp->templates, "thaw",
880 881
                           G_CALLBACK (gimp_context_template_list_thaw),
                           object, 0);
882 883
}

884 885 886
static void
gimp_context_dispose (GObject *object)
{
887
  GimpContext *context = GIMP_CONTEXT (object);
888 889 890 891 892 893 894 895

  if (context->gimp)
    {
      context->gimp->context_list = g_list_remove (context->gimp->context_list,
                                                   context);
      context->gimp = NULL;
    }

896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967
  if (context->tool_info)
    {
      g_object_unref (context->tool_info);
      context->tool_info = NULL;
    }

  if (context->paint_info)
    {
      g_object_unref (context->paint_info);
      context->paint_info = NULL;
    }

  if (context->brush)
    {
      g_object_unref (context->brush);
      context->brush = NULL;
    }

  if (context->dynamics)
    {
      g_object_unref (context->dynamics);
      context->dynamics = NULL;
    }

  if (context->pattern)
    {
      g_object_unref (context->pattern);
      context->pattern = NULL;
    }

  if (context->gradient)
    {
      g_object_unref (context->gradient);
      context->gradient = NULL;
    }

  if (context->palette)
    {
      g_object_unref (context->palette);
      context->palette = NULL;
    }

  if (context->tool_preset)
    {
      g_object_unref (context->tool_preset);
      context->tool_preset = NULL;
    }

  if (context->font)
    {
      g_object_unref (context->font);
      context->font = NULL;
    }

  if (context->buffer)
    {
      g_object_unref (context->buffer);
      context->buffer = NULL;
    }

  if (context->imagefile)
    {
      g_object_unref (context->imagefile);
      context->imagefile = NULL;
    }

  if (context->template)
    {
      g_object_unref (context->template);
      context->template = NULL;
    }

968 969 970
  G_OBJECT_CLASS (parent_class)->dispose (object);
}

971
static void
972
gimp_context_finalize (GObject *object)
973
{
974
  GimpContext *context = GIMP_CONTEXT (object);
975

976
  context->parent  = NULL;
977 978 979
  context->image   = NULL;
  context->display = NULL;

980 981 982 983 984 985
  if (context->tool_name)
    {
      g_free (context->tool_name);
      context->tool_name = NULL;
    }

986 987 988 989 990 991
  if (context->paint_name)
    {
      g_free (context->paint_name);
      context->paint_name = NULL;
    }

992 993 994 995 996 997
  if (context->brush_name)
    {
      g_free (context->brush_name);
      context->brush_name = NULL;
    }

998 999 1000 1001 1002 1003
  if (context->dynamics_name)
    {
      g_free (context->dynamics_name);
      context->dynamics_name = NULL;
    }

1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
  if (context->pattern_name)
    {
      g_free (context->pattern_name);
      context->pattern_name = NULL;
    }

  if (context->gradient_name)
    {
      g_free (context->gradient_name);
      context->gradient_name = NULL;
    }

1016 1017 1018 1019 1020 1021
  if (context->palette_name)
    {
      g_free (context->palette_name);
      context->palette_name = NULL;
    }

1022 1023 1024 1025 1026 1027
  if (context->tool_preset_name)
    {
      g_free (context->tool_preset_name);
      context->tool_preset_name = NULL;
    }

1028 1029 1030 1031 1032 1033
  if (context->font_name)
    {
      g_free (context->font_name);
      context->font_name = NULL;
    }

1034 1035 1036 1037 1038
  if (context->buffer_name)
    {
      g_free (context->buffer_name);
      context->buffer_name = NULL;
    }
1039

1040 1041 1042 1043 1044
  if (context->imagefile_name)
    {
      g_free (context->imagefile_name);
      context->imagefile_name = NULL;
    }
1045

1046 1047 1048 1049 1050
  if (context->template_name)
    {
      g_free (context->template_name);
      context->template_name = NULL;
    }
1051

1052
  G_OBJECT_CLASS (parent_class)->finalize (object);
1053 1054 1055
}

static void
1056
gimp_context_set_property (GObject      *object,
1057 1058 1059
                           guint         property_id,
                           const GValue *value,
                           GParamSpec   *pspec)
1060
{
1061
  GimpContext *context = GIMP_CONTEXT (object);
1062

1063
  switch (property_id)
1064
    {
1065
    case GIMP_CONTEXT_PROP_GIMP:
1066 1067
      context->gimp = g_value_get_object (value);
      break;
1068
    case GIMP_CONTEXT_PROP_IMAGE:
1069
      gimp_context_set_image (context, g_value_get_object (value));
1070
      break;
1071
    case GIMP_CONTEXT_PROP_DISPLAY:
1072
      gimp_context_set_display (context, g_value_get_object (value));
1073
      break;
1074
    case GIMP_CONTEXT_PROP_TOOL:
1075
      gimp_context_set_tool (context, g_value_get_object (value));
1076
      break;
1077 1078 1079
    case GIMP_CONTEXT_PROP_PAINT_INFO:
      gimp_context_set_paint_info (context, g_value_get_object (value));
      break;
1080
    case GIMP_CONTEXT_PROP_FOREGROUND:
1081
      gimp_context_set_foreground (context, g_value_get_boxed (value));
1082
      break;
1083
    case GIMP_CONTEXT_PROP_BACKGROUND:
1084
      gimp_context_set_background (context, g_value_get_boxed (value));
1085
      break;
1086
    case GIMP_CONTEXT_PROP_OPACITY:
1087
      gimp_context_set_opacity (context, g_value_get_double (value));
1088
      break;
1089
    case GIMP_CONTEXT_PROP_PAINT_MODE:
1090
      gimp_context_set_paint_mode (context, g_value_get_enum (value));
1091
      break;
1092
    case GIMP_CONTEXT_PROP_BRUSH:
1093
      gimp_context_set_brush (context, g_value_get_object (value));
1094
      break;
1095 1096 1097
    case GIMP_CONTEXT_PROP_DYNAMICS:
      gimp_context_set_dynamics (context, g_value_get_object (value));
      break;
1098
    case GIMP_CONTEXT_PROP_PATTERN:
1099
      gimp_context_set_pattern (context, g_value_get_object (value));
1100
      break;
1101
    case GIMP_CONTEXT_PROP_GRADIENT:
1102
      gimp_context_set_gradient (context, g_value_get_object (value));
1103
      break;
1104
    case GIMP_CONTEXT_PROP_PALETTE:
1105
      gimp_context_set_palette (context, g_value_get_object (value));
</