gimp.c 18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "config.h"

Hans Breuer's avatar
Hans Breuer committed
21 22
#include <string.h> /* strlen */

23
#include <glib-object.h>
24

25 26
#include "libgimpbase/gimpbase.h"

27
#include "core-types.h"
28
#include "pdb/pdb-types.h"
29 30

#include "pdb/procedural_db.h"
31
#include "pdb/internal_procs.h"
32

Michael Natterer's avatar
Michael Natterer committed
33 34
#include "xcf/xcf.h"

35 36 37 38 39
#include "gimp.h"
#include "gimpbrush.h"
#include "gimpbrushgenerated.h"
#include "gimpbrushpipe.h"
#include "gimpbuffer.h"
Michael Natterer's avatar
Michael Natterer committed
40 41
#include "gimpcontext.h"
#include "gimpcoreconfig.h"
42
#include "gimpdatafactory.h"
43
#include "gimpdocuments.h"
44 45
#include "gimpgradient.h"
#include "gimpimage.h"
46
#include "gimpimage-new.h"
Michael Natterer's avatar
Michael Natterer committed
47
#include "gimpimagefile.h"
48
#include "gimplist.h"
Michael Natterer's avatar
Michael Natterer committed
49
#include "gimpmodules.h"
50 51
#include "gimppalette.h"
#include "gimppattern.h"
52
#include "gimpparasite.h"
53
#include "gimptoolinfo.h"
54
#include "gimpunit.h"
55 56 57 58

#include "libgimp/gimpintl.h"


59 60
static void   gimp_class_init (GimpClass *klass);
static void   gimp_init       (Gimp      *gimp);
61

62 63
static void   gimp_dispose    (GObject   *object);
static void   gimp_finalize   (GObject   *object);
64 65 66 67 68


static GimpObjectClass *parent_class = NULL;


69
GType 
70 71
gimp_get_type (void)
{
72
  static GType object_type = 0;
73 74 75

  if (! object_type)
    {
76
      static const GTypeInfo object_info =
77 78
      {
        sizeof (GimpClass),
79 80 81 82 83 84 85 86
	(GBaseInitFunc) NULL,
	(GBaseFinalizeFunc) NULL,
	(GClassInitFunc) gimp_class_init,
	NULL,		/* class_finalize */
	NULL,		/* class_data     */
	sizeof (Gimp),
	0,              /* n_preallocs    */
	(GInstanceInitFunc) gimp_init,
87 88
      };

89 90 91
      object_type = g_type_register_static (GIMP_TYPE_OBJECT,
					    "Gimp", 
					    &object_info, 0);
92 93 94 95 96 97 98 99
    }

  return object_type;
}

static void
gimp_class_init (GimpClass *klass)
{
100
  GObjectClass *object_class;
101

102
  object_class = G_OBJECT_CLASS (klass);
103

104
  parent_class = g_type_class_peek_parent (klass);
105

106 107
  object_class->dispose  = gimp_dispose;
  object_class->finalize = gimp_finalize;
108 109 110 111 112
}

static void
gimp_init (Gimp *gimp)
{
113 114
  gimp_core_config_init (gimp);

115 116 117
  gimp->be_verbose              = FALSE;
  gimp->no_data                 = FALSE;
  gimp->no_interface            = FALSE;
118
  gimp->message_handler         = GIMP_CONSOLE;
119
  gimp->stack_trace_mode        = GIMP_STACK_TRACE_NEVER;
Michael Natterer's avatar
Michael Natterer committed
120

121
  gimp->main_loops              = NULL;
122

123 124 125 126 127
  gimp->gui_main_loop_func      = NULL;
  gimp->gui_main_loop_quit_func = NULL;
  gimp->gui_create_display_func = NULL;
  gimp->gui_set_busy_func       = NULL;
  gimp->gui_unset_busy_func     = NULL;
128
  gimp->gui_message_func        = NULL;
129 130 131

  gimp->busy                    = 0;
  gimp->busy_idle_id            = 0;
132

133 134 135
  gimp_units_init (gimp);

  gimp_parasites_init (gimp);
136

Michael Natterer's avatar
Michael Natterer committed
137 138
  gimp_modules_init (gimp);

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
  gimp->images              = gimp_list_new (GIMP_TYPE_IMAGE,
					     GIMP_CONTAINER_POLICY_WEAK);
  gimp->next_image_ID       = 1;
  gimp->next_guide_ID       = 1;
  gimp->image_table         = g_hash_table_new (g_direct_hash, NULL);

  gimp->next_drawable_ID    = 1;
  gimp->drawable_table      = g_hash_table_new (g_direct_hash, NULL);

  gimp->global_buffer       = NULL;
  gimp->named_buffers       = gimp_list_new (GIMP_TYPE_BUFFER,
					     GIMP_CONTAINER_POLICY_STRONG);
  gimp->brush_factory       = NULL;
  gimp->pattern_factory     = NULL;
  gimp->gradient_factory    = NULL;
  gimp->palette_factory     = NULL;
155 156 157

  procedural_db_init (gimp);

Michael Natterer's avatar
Michael Natterer committed
158 159 160
  gimp->load_procs          = NULL;
  gimp->save_procs          = NULL;

Michael Natterer's avatar
Michael Natterer committed
161 162
  xcf_init (gimp);

163 164
  gimp->tool_info_list      = gimp_list_new (GIMP_TYPE_TOOL_INFO,
					     GIMP_CONTAINER_POLICY_STRONG);
165
  gimp->standard_tool_info  = NULL;
166

167
  gimp_documents_init (gimp);
Michael Natterer's avatar
Michael Natterer committed
168

169 170 171
  gimp->image_base_type_names   = NULL;
  gimp->fill_type_names         = NULL;
  gimp->have_current_cut_buffer = FALSE;
Michael Natterer's avatar
Michael Natterer committed
172

173 174 175 176 177
  gimp->context_list            = NULL;
  gimp->standard_context        = NULL;
  gimp->default_context         = NULL;
  gimp->user_context            = NULL;
  gimp->current_context         = NULL;
178 179 180
}

static void
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
gimp_dispose (GObject *object)
{
  Gimp *gimp;

  gimp = GIMP (object);

  if (gimp->brush_factory)
    gimp_data_factory_data_free (gimp->brush_factory);

  if (gimp->pattern_factory)
    gimp_data_factory_data_free (gimp->pattern_factory);

  if (gimp->gradient_factory)
    gimp_data_factory_data_free (gimp->gradient_factory);

  if (gimp->palette_factory)
    gimp_data_factory_data_free (gimp->palette_factory);

  G_OBJECT_CLASS (parent_class)->dispose (object);
}

static void
gimp_finalize (GObject *object)
204 205 206 207 208
{
  Gimp *gimp;

  gimp = GIMP (object);

209 210
  if (gimp->current_context)
    gimp_set_current_context (gimp, NULL);
Michael Natterer's avatar
Michael Natterer committed
211

212 213 214 215 216
  if (gimp->user_context)
    gimp_set_user_context (gimp, NULL);

  if (gimp->default_context)
    gimp_set_default_context (gimp, NULL);
Michael Natterer's avatar
Michael Natterer committed
217 218 219

  if (gimp->standard_context)
    {
220
      g_object_unref (G_OBJECT (gimp->standard_context));
Michael Natterer's avatar
Michael Natterer committed
221 222 223
      gimp->standard_context = NULL;
    }

224 225
  if (gimp->image_base_type_names)
    gimp_image_new_exit (gimp);
226

227 228
  if (gimp->documents)
    gimp_documents_exit (gimp);
Michael Natterer's avatar
Michael Natterer committed
229

230 231
  gimp_tool_info_set_standard (gimp, NULL);

232 233
  if (gimp->tool_info_list)
    {
234
      g_object_unref (G_OBJECT (gimp->tool_info_list));
235 236 237
      gimp->tool_info_list = NULL;
    }

Michael Natterer's avatar
Michael Natterer committed
238 239
  xcf_exit (gimp);

Michael Natterer's avatar
Michael Natterer committed
240 241 242 243 244 245 246 247 248 249 250 251 252
  procedural_db_free (gimp);

  if (gimp->load_procs)
    {
      g_slist_free (gimp->load_procs);
      gimp->load_procs = NULL;
    }

  if (gimp->save_procs)
    {
      g_slist_free (gimp->save_procs);
      gimp->save_procs = NULL;
    }
253 254 255

  if (gimp->brush_factory)
    {
256
      g_object_unref (G_OBJECT (gimp->brush_factory));
257 258 259 260 261
      gimp->brush_factory = NULL;
    }

  if (gimp->pattern_factory)
    {
262
      g_object_unref (G_OBJECT (gimp->pattern_factory));
263 264 265 266 267
      gimp->pattern_factory = NULL;
    }

  if (gimp->gradient_factory)
    {
268
      g_object_unref (G_OBJECT (gimp->gradient_factory));
269 270 271 272 273
      gimp->gradient_factory = NULL;
    }

  if (gimp->palette_factory)
    {
274
      g_object_unref (G_OBJECT (gimp->palette_factory));
275 276 277 278 279
      gimp->palette_factory = NULL;
    }

  if (gimp->named_buffers)
    {
280
      g_object_unref (G_OBJECT (gimp->named_buffers));
281 282 283 284 285
      gimp->named_buffers = NULL;
    }

  if (gimp->global_buffer)
    {
286
      g_object_unref (G_OBJECT (gimp->global_buffer));
287 288 289
      gimp->global_buffer = NULL;
    }

290 291 292 293 294 295 296 297 298 299 300 301
  if (gimp->drawable_table)
    {
      g_hash_table_destroy (gimp->drawable_table);
      gimp->drawable_table = NULL;
    }

  if (gimp->image_table)
    {
      g_hash_table_destroy (gimp->image_table);
      gimp->image_table = NULL;
    }

302 303
  if (gimp->images)
    {
304
      g_object_unref (G_OBJECT (gimp->images));
305 306 307
      gimp->images = NULL;
    }

Michael Natterer's avatar
Michael Natterer committed
308 309 310
  if (gimp->modules)
    gimp_modules_exit (gimp);

311 312
  if (gimp->parasites)
    gimp_parasites_exit (gimp);
313

314 315
  if (gimp->user_units)
    gimp_units_exit (gimp);
316

317
  G_OBJECT_CLASS (parent_class)->finalize (object);
318 319 320
}

Gimp *
321 322 323 324
gimp_new (gboolean           be_verbose,
          gboolean           no_data,
          gboolean           no_interface,
          GimpStackTraceMode stack_trace_mode)
325 326 327
{
  Gimp *gimp;

Michael Natterer's avatar
Michael Natterer committed
328
  gimp = g_object_new (GIMP_TYPE_GIMP, NULL);
329

330 331 332
  gimp->be_verbose       = be_verbose   ? TRUE : FALSE;
  gimp->no_data          = no_data      ? TRUE : FALSE;
  gimp->no_interface     = no_interface ? TRUE : FALSE;
333
  gimp->stack_trace_mode = stack_trace_mode;
Michael Natterer's avatar
Michael Natterer committed
334

335 336 337 338
  return gimp;
}

void
339 340
gimp_initialize (Gimp               *gimp,
                 GimpInitStatusFunc  status_callback)
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
{
  GimpContext *context;

  static const GimpDataFactoryLoaderEntry brush_loader_entries[] =
  {
    { gimp_brush_load,           GIMP_BRUSH_FILE_EXTENSION           },
    { gimp_brush_load,           GIMP_BRUSH_PIXMAP_FILE_EXTENSION    },
    { gimp_brush_generated_load, GIMP_BRUSH_GENERATED_FILE_EXTENSION },
    { gimp_brush_pipe_load,      GIMP_BRUSH_PIPE_FILE_EXTENSION      }
  };

  static const GimpDataFactoryLoaderEntry pattern_loader_entries[] =
  {
    { gimp_pattern_load, GIMP_PATTERN_FILE_EXTENSION }
  };

  static const GimpDataFactoryLoaderEntry gradient_loader_entries[] =
  {
    { gimp_gradient_load, GIMP_GRADIENT_FILE_EXTENSION },
    { gimp_gradient_load, NULL /* legacy loader */     }
  };

  static const GimpDataFactoryLoaderEntry palette_loader_entries[] =
  {
    { gimp_palette_load, GIMP_PALETTE_FILE_EXTENSION },
    { gimp_palette_load, NULL /* legacy loader */    }
  };

  g_return_if_fail (GIMP_IS_GIMP (gimp));
370
  g_return_if_fail (status_callback != NULL);
371 372 373

  gimp->brush_factory =
    gimp_data_factory_new (GIMP_TYPE_BRUSH,
374
			   (const gchar **) &gimp->config->brush_path,
375
			   brush_loader_entries,
376
			   G_N_ELEMENTS (brush_loader_entries),
377 378 379 380 381
			   gimp_brush_new,
			   gimp_brush_get_standard);

  gimp->pattern_factory =
    gimp_data_factory_new (GIMP_TYPE_PATTERN,
382
			   (const gchar **) &gimp->config->pattern_path,
383
			   pattern_loader_entries,
384
			   G_N_ELEMENTS (pattern_loader_entries),
385 386 387 388 389
			   gimp_pattern_new,
			   gimp_pattern_get_standard);

  gimp->gradient_factory =
    gimp_data_factory_new (GIMP_TYPE_GRADIENT,
390
			   (const gchar **) &gimp->config->gradient_path,
391
			   gradient_loader_entries,
392
			   G_N_ELEMENTS (gradient_loader_entries),
393 394 395 396 397
			   gimp_gradient_new,
			   gimp_gradient_get_standard);

  gimp->palette_factory =
    gimp_data_factory_new (GIMP_TYPE_PALETTE,
398
			   (const gchar **) &gimp->config->palette_path,
399
			   palette_loader_entries,
400
			   G_N_ELEMENTS (palette_loader_entries),
401 402 403 404 405
			   gimp_palette_new,
			   gimp_palette_get_standard);

  gimp_image_new_init (gimp);

406
  gimp->standard_context = gimp_context_new (gimp, "Standard", NULL);
407

408 409 410 411
  /*  the default context contains the user's saved preferences
   *
   *  TODO: load from disk
   */
412
  context = gimp_context_new (gimp, "Default", NULL);
413
  gimp_set_default_context (gimp, context);
414
  g_object_unref (G_OBJECT (context));
415

416 417
  /*  the initial user_context is a straight copy of the default context
   */
418
  context = gimp_context_new (gimp, "User", context);
419
  gimp_set_user_context (gimp, context);
420
  g_object_unref (G_OBJECT (context));
421 422

  gimp_set_current_context (gimp, context);
423 424 425 426

  /*  register all internal procedures  */
  (* status_callback) (_("Procedural Database"), NULL, -1);
  internal_procs_init (gimp, status_callback);
427 428 429
}

void
430 431 432
gimp_restore (Gimp               *gimp,
              GimpInitStatusFunc  status_callback,
	      gboolean            no_data)
433 434
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));
435
  g_return_if_fail (status_callback != NULL);
436 437

  /*  initialize  the global parasite table  */
438
  (* status_callback) (_("Looking for data files"), _("Parasites"), 0.00);
439
  gimp_parasiterc_load (gimp);
440 441

  /*  initialize the list of gimp brushes    */
442
  (* status_callback) (NULL, _("Brushes"), 0.18);
443 444 445
  gimp_data_factory_data_init (gimp->brush_factory, no_data); 

  /*  initialize the list of gimp patterns   */
446
  (* status_callback) (NULL, _("Patterns"), 0.36);
447 448 449
  gimp_data_factory_data_init (gimp->pattern_factory, no_data); 

  /*  initialize the list of gimp palettes   */
450
  (* status_callback) (NULL, _("Palettes"), 0.54);
451 452 453
  gimp_data_factory_data_init (gimp->palette_factory, no_data); 

  /*  initialize the list of gimp gradients  */
454
  (* status_callback) (NULL, _("Gradients"), 0.72);
455 456
  gimp_data_factory_data_init (gimp->gradient_factory, no_data); 

457
  /*  initialize the document history  */
458
  (* status_callback) (NULL, _("Documents"), 0.90);
459 460
  gimp_documents_load (gimp);

461
  (* status_callback) (NULL, NULL, 1.00);
Michael Natterer's avatar
Michael Natterer committed
462 463

  gimp_modules_load (gimp);
464
}
465 466 467 468

void
gimp_shutdown (Gimp *gimp)
{
469 470
  g_return_if_fail (GIMP_IS_GIMP (gimp));

Michael Natterer's avatar
Michael Natterer committed
471
  gimp_modules_unload (gimp);
472 473 474 475
  gimp_data_factory_data_save (gimp->brush_factory);
  gimp_data_factory_data_save (gimp->pattern_factory);
  gimp_data_factory_data_save (gimp->gradient_factory);
  gimp_data_factory_data_save (gimp->palette_factory);
476
  gimp_documents_save (gimp);
477
  gimp_parasiterc_save (gimp);
478 479 480
  gimp_unitrc_save (gimp);
}

481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
void
gimp_main_loop (Gimp *gimp)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));

  if (gimp->gui_main_loop_func)
    {
      gimp->gui_main_loop_func (gimp);
    }
  else
    {
      GMainLoop *loop;

      loop = g_main_loop_new (NULL, TRUE);

      gimp->main_loops = g_list_prepend (gimp->main_loops, loop);

      g_main_loop_run (loop);

      gimp->main_loops = g_list_remove (gimp->main_loops, loop);

      g_main_loop_unref (loop);
    }
}

void
gimp_main_loop_quit (Gimp *gimp)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));

  if (gimp->gui_main_loop_func)
    {
      gimp->gui_main_loop_quit_func (gimp);
    }
  else
    {
      GMainLoop *loop;

      loop = (GMainLoop *) gimp->main_loops->data;

      g_main_loop_quit (loop);
    }
}

525 526 527 528 529 530
void
gimp_set_busy (Gimp *gimp)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));

  /* FIXME: gimp_busy HACK */
Michael Natterer's avatar
Michael Natterer committed
531
  gimp->busy++;
532

Michael Natterer's avatar
Michael Natterer committed
533 534 535 536 537
  if (gimp->busy == 1)
    {
      if (gimp->gui_set_busy_func)
        gimp->gui_set_busy_func (gimp);
    }
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
}

static gboolean
gimp_idle_unset_busy (gpointer data)
{
  Gimp *gimp;

  gimp = (Gimp *) data;

  gimp_unset_busy (gimp);

  gimp->busy_idle_id = 0;

  return FALSE;
}

void
gimp_set_busy_until_idle (Gimp *gimp)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));

  if (! gimp->busy_idle_id)
    {
      gimp_set_busy (gimp);

      gimp->busy_idle_id = g_idle_add_full (G_PRIORITY_HIGH,
					    gimp_idle_unset_busy, gimp,
					    NULL);
    }
}

void
gimp_unset_busy (Gimp *gimp)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));
Michael Natterer's avatar
Michael Natterer committed
573
  g_return_if_fail (gimp->busy > 0);
574 575

  /* FIXME: gimp_busy HACK */
Michael Natterer's avatar
Michael Natterer committed
576 577 578 579 580 581 582
  gimp->busy--;

  if (gimp->busy == 0)
    {
      if (gimp->gui_unset_busy_func)
        gimp->gui_unset_busy_func (gimp);
    }
583
}
584

585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
void
gimp_message (Gimp        *gimp,
              const gchar *message)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));

  switch (gimp->message_handler)
    {
    case GIMP_MESSAGE_BOX:
    case GIMP_ERROR_CONSOLE:
      if (gimp->gui_message_func)
        {
          gimp->gui_message_func (gimp, message);
          return;
        }
      break;

    default:
      break;
    }

  g_printerr ("%s: %s\n", GIMP_OBJECT (gimp)->name, message);
}

609 610 611 612
GimpImage *
gimp_create_image (Gimp              *gimp,
		   gint               width,
		   gint               height,
613 614
		   GimpImageBaseType  type,
		   gboolean           attach_comment)
615 616 617 618 619
{
  GimpImage *gimage;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);

Michael Natterer's avatar
Michael Natterer committed
620
  gimage = gimp_image_new (gimp, width, height, type);
621

622 623
  gimp_container_add (gimp->images, GIMP_OBJECT (gimage));

624
  if (attach_comment && gimp->config->default_comment)
625 626 627 628 629
    {
      GimpParasite *parasite;

      parasite = gimp_parasite_new ("gimp-comment",
				    GIMP_PARASITE_PERSISTENT,
630 631
				    strlen (gimp->config->default_comment) + 1,
				    gimp->config->default_comment);
632 633 634 635
      gimp_image_parasite_attach (gimage, parasite);
      gimp_parasite_free (parasite);
    }

636 637 638
  return gimage;
}

639
GimpObject *
640
gimp_create_display (Gimp      *gimp,
641 642
		     GimpImage *gimage,
                     guint      scale)
643
{
644 645
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
646

647
  if (gimp->gui_create_display_func)
648
    {
649
      return gimp->gui_create_display_func (gimage, scale);
650
    }
651 652

  return NULL;
653
}
Michael Natterer's avatar
Michael Natterer committed
654

Michael Natterer's avatar
Michael Natterer committed
655
#if 0
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
void
gimp_open_file (Gimp        *gimp,
		const gchar *filename,
		gboolean     with_display)
{
  GimpImage *gimage;
  gint       status;

  g_return_if_fail (GIMP_IS_GIMP (gimp));
  g_return_if_fail (filename != NULL);

  gimage = file_open_image (gimp,
			    filename,
			    filename,
			    _("Open"),
			    NULL,
			    RUN_INTERACTIVE,
			    &status);

  if (gimage)
    {
      gchar *absolute;

Michael Natterer's avatar
Michael Natterer committed
679
      /* enable & clear all undo steps */
680 681
      gimp_image_undo_enable (gimage);

Michael Natterer's avatar
Michael Natterer committed
682
      /* set the image to clean  */
683 684 685
      gimp_image_clean_all (gimage);

      if (with_display)
686
	gimp_create_display (gimage->gimp, gimage, 0x0101);
687 688 689 690 691 692 693 694 695

      absolute = file_open_absolute_filename (filename);

      document_index_add (absolute);
      menus_last_opened_add (absolute);

      g_free (absolute);
    }
}
Michael Natterer's avatar
Michael Natterer committed
696
#endif
697

Michael Natterer's avatar
Michael Natterer committed
698 699 700
GimpContext *
gimp_get_standard_context (Gimp *gimp)
{
701 702
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);

Michael Natterer's avatar
Michael Natterer committed
703 704 705 706 707 708 709
  return gimp->standard_context;
}

void
gimp_set_default_context (Gimp        *gimp,
			  GimpContext *context)
{
710 711 712 713 714
  g_return_if_fail (GIMP_IS_GIMP (gimp));
  g_return_if_fail (! context || GIMP_IS_CONTEXT (context));

  if (gimp->default_context)
    {
715
      g_object_unref (G_OBJECT (gimp->default_context));
716 717
    }

Michael Natterer's avatar
Michael Natterer committed
718
  gimp->default_context = context;
719 720 721

  if (gimp->default_context)
    {
722
      g_object_ref (G_OBJECT (gimp->default_context));
723
    }
Michael Natterer's avatar
Michael Natterer committed
724 725 726 727 728
}

GimpContext *
gimp_get_default_context (Gimp *gimp)
{
729 730
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);

Michael Natterer's avatar
Michael Natterer committed
731 732 733 734 735 736 737
  return gimp->default_context;
}

void
gimp_set_user_context (Gimp        *gimp,
		       GimpContext *context)
{
738 739 740 741 742
  g_return_if_fail (GIMP_IS_GIMP (gimp));
  g_return_if_fail (! context || GIMP_IS_CONTEXT (context));

  if (gimp->user_context)
    {
743
      g_object_unref (G_OBJECT (gimp->user_context));
744 745
    }

Michael Natterer's avatar
Michael Natterer committed
746
  gimp->user_context = context;
747 748 749

  if (gimp->user_context)
    {
750
      g_object_ref (G_OBJECT (gimp->user_context));
751
    }
Michael Natterer's avatar
Michael Natterer committed
752 753 754 755 756
}

GimpContext *
gimp_get_user_context (Gimp *gimp)
{
757 758
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);

Michael Natterer's avatar
Michael Natterer committed
759 760 761 762 763 764 765
  return gimp->user_context;
}

void
gimp_set_current_context (Gimp        *gimp,
			  GimpContext *context)
{
766 767 768 769 770
  g_return_if_fail (GIMP_IS_GIMP (gimp));
  g_return_if_fail (! context || GIMP_IS_CONTEXT (context));

  if (gimp->current_context)
    {
771
      g_object_unref (G_OBJECT (gimp->current_context));
772 773
    }

Michael Natterer's avatar
Michael Natterer committed
774
  gimp->current_context = context;
775 776 777

  if (gimp->current_context)
    {
778
      g_object_ref (G_OBJECT (gimp->current_context));
779
    }
Michael Natterer's avatar
Michael Natterer committed
780 781 782 783 784
}

GimpContext *
gimp_get_current_context (Gimp *gimp)
{
785 786
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);

Michael Natterer's avatar
Michael Natterer committed
787 788
  return gimp->current_context;
}