~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/tools/gimp-tools.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis and others
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
21
21
#include <gtk/gtk.h>
22
22
 
23
23
#include "libgimpbase/gimpbase.h"
 
24
#include "libgimpconfig/gimpconfig.h"
 
25
#include "libgimpwidgets/gimpwidgets.h"
24
26
 
25
27
#include "tools-types.h"
26
28
 
27
 
#include "config/gimpconfig.h"
28
 
#include "config/gimpconfig-utils.h"
29
 
 
30
29
#include "core/gimp.h"
31
 
#include "core/gimplist.h"
 
30
#include "core/gimp-contexts.h"
32
31
#include "core/gimptoolinfo.h"
33
32
#include "core/gimptooloptions.h"
 
33
#include "core/gimptoolpresets.h"
34
34
 
35
35
#include "gimp-tools.h"
36
36
#include "gimptooloptions-gui.h"
37
37
#include "tool_manager.h"
38
38
 
39
39
#include "gimpairbrushtool.h"
 
40
#include "gimpaligntool.h"
40
41
#include "gimpblendtool.h"
41
42
#include "gimpbrightnesscontrasttool.h"
42
43
#include "gimpbucketfilltool.h"
53
54
#include "gimperasertool.h"
54
55
#include "gimpfliptool.h"
55
56
#include "gimpfreeselecttool.h"
 
57
#include "gimpforegroundselecttool.h"
56
58
#include "gimpfuzzyselecttool.h"
 
59
#include "gimphealtool.h"
57
60
#include "gimphuesaturationtool.h"
58
61
#include "gimpinktool.h"
59
62
#include "gimpiscissorstool.h"
63
66
#include "gimpmovetool.h"
64
67
#include "gimppaintbrushtool.h"
65
68
#include "gimppenciltool.h"
 
69
#include "gimpperspectiveclonetool.h"
66
70
#include "gimpperspectivetool.h"
67
71
#include "gimpposterizetool.h"
68
 
#include "gimprectselecttool.h"
69
72
#include "gimpthresholdtool.h"
 
73
#include "gimprectangleselecttool.h"
70
74
#include "gimprotatetool.h"
71
75
#include "gimpscaletool.h"
72
76
#include "gimpsheartool.h"
94
98
                                   gpointer                data);
95
99
 
96
100
 
 
101
/*  private variables  */
 
102
 
 
103
static gboolean   tool_options_deleted = FALSE;
 
104
 
 
105
 
97
106
/*  public functions  */
98
107
 
99
108
void
118
127
    gimp_dodge_burn_tool_register,
119
128
    gimp_smudge_tool_register,
120
129
    gimp_convolve_tool_register,
 
130
    gimp_perspective_clone_tool_register,
 
131
    gimp_heal_tool_register,
121
132
    gimp_clone_tool_register,
122
133
    gimp_ink_tool_register,
123
134
    gimp_airbrush_tool_register,
136
147
    gimp_scale_tool_register,
137
148
    gimp_rotate_tool_register,
138
149
    gimp_crop_tool_register,
 
150
    gimp_align_tool_register,
139
151
    gimp_move_tool_register,
140
152
 
141
153
    /*  non-modifying tools  */
150
162
 
151
163
    /*  selection tools */
152
164
 
 
165
    gimp_foreground_select_tool_register,
153
166
    gimp_iscissors_tool_register,
154
167
    gimp_by_color_select_tool_register,
155
168
    gimp_fuzzy_select_tool_register,
220
233
 
221
234
  filename = gimp_personal_rc_file ("toolrc");
222
235
 
 
236
  if (gimp->be_verbose)
 
237
    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
 
238
 
223
239
  if (gimp_config_deserialize_file (GIMP_CONFIG (gimp_list), filename,
224
240
                                    NULL, NULL))
225
241
    {
 
242
      gint n = gimp_container_num_children (gimp->tool_info_list);
226
243
      gint i;
227
244
 
228
245
      gimp_list_reverse (GIMP_LIST (gimp_list));
245
262
                            "visible", GIMP_TOOL_INFO (list->data)->visible,
246
263
                            NULL);
247
264
 
248
 
              gimp_container_reorder (gimp->tool_info_list, object, i);
 
265
              gimp_container_reorder (gimp->tool_info_list,
 
266
                                      object, MIN (i, n - 1));
249
267
            }
250
268
        }
251
269
    }
257
275
       list;
258
276
       list = g_list_next (list))
259
277
    {
260
 
      GimpToolInfo           *tool_info;
 
278
      GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data);
 
279
 
 
280
      /*  get default values from prefs (see bug #120832)  */
 
281
      gimp_tool_options_reset (tool_info->tool_options);
 
282
    }
 
283
 
 
284
  gimp_contexts_load (gimp);
 
285
 
 
286
  for (list = GIMP_LIST (gimp->tool_info_list)->list;
 
287
       list;
 
288
       list = g_list_next (list))
 
289
    {
 
290
      GimpToolInfo           *tool_info = GIMP_TOOL_INFO (list->data);
261
291
      GimpToolOptionsGUIFunc  options_gui_func;
262
292
      GtkWidget              *options_gui;
263
293
 
264
 
      tool_info = GIMP_TOOL_INFO (list->data);
265
 
 
266
 
      /*  get default values from prefs (see bug #120832)  */
267
 
      gimp_tool_options_reset (tool_info->tool_options);
268
 
 
269
 
      gimp_tool_options_deserialize (tool_info->tool_options, NULL, NULL);
 
294
      gimp_context_copy_properties (gimp_get_user_context (gimp),
 
295
                                    GIMP_CONTEXT (tool_info->tool_options),
 
296
                                    GIMP_CONTEXT_ALL_PROPS_MASK);
 
297
 
 
298
      gimp_tool_options_deserialize (tool_info->tool_options, NULL);
270
299
 
271
300
      options_gui_func = g_object_get_data (G_OBJECT (tool_info),
272
301
                                            "gimp-tool-options-gui-func");
281
310
 
282
311
          options_gui = gimp_tool_options_gui (tool_info->tool_options);
283
312
 
284
 
          label = gtk_label_new (_("This tool has no options."));
 
313
          label = gtk_label_new (_("This tool has\nno options."));
 
314
          gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
 
315
          gimp_label_set_attributes (GTK_LABEL (label),
 
316
                                     PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
 
317
                                     -1);
285
318
          gtk_box_pack_start (GTK_BOX (options_gui), label, FALSE, FALSE, 6);
286
319
          gtk_widget_show (label);
287
320
        }
289
322
      g_object_set_data (G_OBJECT (tool_info->tool_options),
290
323
                         "gimp-tool-options-gui", options_gui);
291
324
 
292
 
      if (tool_info->options_presets)
293
 
        {
294
 
          gchar *filename;
295
 
          GList *list;
296
 
 
297
 
          filename = gimp_tool_options_build_filename (tool_info->tool_options,
298
 
                                                       "presets");
299
 
          gimp_config_deserialize_file (GIMP_CONFIG (tool_info->options_presets),
300
 
                                        filename,
301
 
                                        gimp, NULL);
302
 
          g_free (filename);
303
 
 
304
 
          gimp_list_reverse (GIMP_LIST (tool_info->options_presets));
305
 
 
306
 
          for (list = GIMP_LIST (tool_info->options_presets)->list;
307
 
               list;
308
 
               list = g_list_next (list))
309
 
            {
310
 
              g_object_set (list->data, "tool-info", tool_info, NULL);
311
 
            }
312
 
        }
 
325
      if (tool_info->presets)
 
326
        gimp_tool_presets_load (tool_info->presets, NULL);
313
327
    }
314
328
}
315
329
 
316
330
void
317
 
gimp_tools_save (Gimp *gimp)
 
331
gimp_tools_save (Gimp     *gimp,
 
332
                 gboolean  save_tool_options,
 
333
                 gboolean  always_save)
318
334
{
319
 
  GList *list;
320
335
  gchar *filename;
321
336
 
322
337
  g_return_if_fail (GIMP_IS_GIMP (gimp));
323
338
 
324
 
  for (list = GIMP_LIST (gimp->tool_info_list)->list;
325
 
       list;
326
 
       list = g_list_next (list))
 
339
  if (save_tool_options && (! tool_options_deleted || always_save))
327
340
    {
328
 
      GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data);
329
 
 
330
 
      gimp_tool_options_serialize (tool_info->tool_options, NULL, NULL);
331
 
 
332
 
      if (tool_info->options_presets)
 
341
      GList *list;
 
342
 
 
343
      gimp_contexts_save (gimp);
 
344
 
 
345
      gimp_tool_options_create_folder ();
 
346
 
 
347
      for (list = GIMP_LIST (gimp->tool_info_list)->list;
 
348
           list;
 
349
           list = g_list_next (list))
333
350
        {
334
 
          gchar *filename;
335
 
          gchar *header;
336
 
          gchar *footer;
337
 
 
338
 
          filename = gimp_tool_options_build_filename (tool_info->tool_options,
339
 
                                                       "presets");
340
 
 
341
 
          header = g_strdup_printf ("GIMP %s options presets",
342
 
                                    GIMP_OBJECT (tool_info)->name);
343
 
          footer = g_strdup_printf ("end of %s options presets",
344
 
                                    GIMP_OBJECT (tool_info)->name);
345
 
 
346
 
          gimp_config_serialize_to_file (GIMP_CONFIG (tool_info->options_presets),
347
 
                                         filename, header, footer,
348
 
                                         NULL, NULL);
349
 
 
350
 
          g_free (filename);
351
 
          g_free (header);
352
 
          g_free (footer);
 
351
          GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data);
 
352
 
 
353
          gimp_tool_options_serialize (tool_info->tool_options, NULL);
353
354
        }
354
355
    }
355
356
 
356
357
  filename = gimp_personal_rc_file ("toolrc");
 
358
 
 
359
  if (gimp->be_verbose)
 
360
    g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
 
361
 
357
362
  gimp_config_serialize_to_file (GIMP_CONFIG (gimp->tool_info_list),
358
363
                                 filename,
359
364
                                 "GIMP toolrc",
362
367
  g_free (filename);
363
368
}
364
369
 
 
370
gboolean
 
371
gimp_tools_clear (Gimp    *gimp,
 
372
                  GError **error)
 
373
{
 
374
  GList    *list;
 
375
  gboolean  success = TRUE;
 
376
 
 
377
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
 
378
 
 
379
  for (list = GIMP_LIST (gimp->tool_info_list)->list;
 
380
       list && success;
 
381
       list = g_list_next (list))
 
382
    {
 
383
      GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data);
 
384
 
 
385
      success = gimp_tool_options_delete (tool_info->tool_options, NULL);
 
386
    }
 
387
 
 
388
  if (success)
 
389
    success = gimp_contexts_clear (gimp, error);
 
390
 
 
391
  if (success)
 
392
    tool_options_deleted = TRUE;
 
393
 
 
394
  return success;
 
395
}
 
396
 
365
397
GList *
366
398
gimp_tools_get_default_order (Gimp *gimp)
367
399
{
392
424
  Gimp         *gimp = (Gimp *) data;
393
425
  GimpToolInfo *tool_info;
394
426
  const gchar  *paint_core_name;
 
427
  gboolean      visible;
395
428
 
396
429
  g_return_if_fail (GIMP_IS_GIMP (gimp));
397
430
  g_return_if_fail (g_type_is_a (tool_type, GIMP_TYPE_TOOL));
403
436
 
404
437
  if (tool_type == GIMP_TYPE_PENCIL_TOOL)
405
438
    {
406
 
      paint_core_name = "GimpPencil";
 
439
      paint_core_name = "gimp-pencil";
407
440
    }
408
441
  else if (tool_type == GIMP_TYPE_PAINTBRUSH_TOOL)
409
442
    {
410
 
      paint_core_name = "GimpPaintbrush";
 
443
      paint_core_name = "gimp-paintbrush";
411
444
    }
412
445
  else if (tool_type == GIMP_TYPE_ERASER_TOOL)
413
446
    {
414
 
      paint_core_name = "GimpEraser";
 
447
      paint_core_name = "gimp-eraser";
415
448
    }
416
449
  else if (tool_type == GIMP_TYPE_AIRBRUSH_TOOL)
417
450
    {
418
 
      paint_core_name = "GimpAirbrush";
 
451
      paint_core_name = "gimp-airbrush";
419
452
    }
420
453
  else if (tool_type == GIMP_TYPE_CLONE_TOOL)
421
454
    {
422
 
      paint_core_name = "GimpClone";
 
455
      paint_core_name = "gimp-clone";
 
456
    }
 
457
  else if (tool_type == GIMP_TYPE_HEAL_TOOL)
 
458
    {
 
459
      paint_core_name = "gimp-heal";
 
460
    }
 
461
  else if (tool_type == GIMP_TYPE_PERSPECTIVE_CLONE_TOOL)
 
462
    {
 
463
      paint_core_name = "gimp-perspective-clone";
423
464
    }
424
465
  else if (tool_type == GIMP_TYPE_CONVOLVE_TOOL)
425
466
    {
426
 
      paint_core_name = "GimpConvolve";
 
467
      paint_core_name = "gimp-convolve";
427
468
    }
428
469
  else if (tool_type == GIMP_TYPE_SMUDGE_TOOL)
429
470
    {
430
 
      paint_core_name = "GimpSmudge";
 
471
      paint_core_name = "gimp-smudge";
431
472
    }
432
473
  else if (tool_type == GIMP_TYPE_DODGE_BURN_TOOL)
433
474
    {
434
 
      paint_core_name = "GimpDodgeBurn";
 
475
      paint_core_name = "gimp-dodge-burn";
435
476
    }
436
477
  else if (tool_type == GIMP_TYPE_INK_TOOL)
437
478
    {
438
 
      paint_core_name = "GimpInk";
 
479
      paint_core_name = "gimp-ink";
439
480
    }
440
481
  else
441
482
    {
442
 
      paint_core_name = "GimpPaintbrush";
 
483
      paint_core_name = "gimp-paintbrush";
443
484
    }
444
485
 
445
486
  tool_info = gimp_tool_info_new (gimp,
446
 
                                  tool_type,
 
487
                                  tool_type,
447
488
                                  tool_options_type,
448
 
                                  context_props,
449
 
                                  identifier,
450
 
                                  blurb,
451
 
                                  help,
452
 
                                  menu_path,
453
 
                                  menu_accel,
454
 
                                  help_domain,
455
 
                                  help_data,
 
489
                                  context_props,
 
490
                                  identifier,
 
491
                                  blurb,
 
492
                                  help,
 
493
                                  menu_path,
 
494
                                  menu_accel,
 
495
                                  help_domain,
 
496
                                  help_data,
456
497
                                  paint_core_name,
457
 
                                  stock_id);
458
 
 
459
 
  if (tool_type == GIMP_TYPE_TEXT_TOOL)
460
 
    gimp_config_connect (G_OBJECT (tool_info->tool_options),
461
 
                         G_OBJECT (gimp_get_user_context (gimp)),
462
 
                         "font");
463
 
 
464
 
  if (g_type_is_a (tool_type, GIMP_TYPE_IMAGE_MAP_TOOL))
465
 
    g_object_set (tool_info, "visible", FALSE, NULL);
 
498
                                  stock_id);
 
499
 
 
500
  visible = (! g_type_is_a (tool_type, GIMP_TYPE_IMAGE_MAP_TOOL));
 
501
 
 
502
  g_object_set (tool_info, "visible", visible, NULL);
 
503
  g_object_set_data (G_OBJECT (tool_info), "gimp-tool-default-visible",
 
504
                     GINT_TO_POINTER (visible));
466
505
 
467
506
  g_object_set_data (G_OBJECT (tool_info), "gimp-tool-options-gui-func",
468
507
                     options_gui_func);