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

« back to all changes in this revision

Viewing changes to app/config/gimpconfig-params.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
2
 
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
 
 *
4
 
 * ParamSpecs for config objects
5
 
 * Copyright (C) 2001-2003  Sven Neumann <sven@gimp.org>
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 2 of the License, or
10
 
 * (at your option) any later version.
11
 
 *
12
 
 * This program is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 * GNU General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program; if not, write to the Free Software
19
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
 
 */
21
 
 
22
 
#include "config.h"
23
 
 
24
 
#include <glib-object.h>
25
 
 
26
 
#include "libgimpbase/gimpbase.h"
27
 
#include "libgimpcolor/gimpcolor.h"
28
 
#include "libgimpmath/gimpmath.h"
29
 
 
30
 
#include "config-types.h"
31
 
 
32
 
#include "gimpconfig-params.h"
33
 
#include "gimpconfig-types.h"
34
 
 
35
 
 
36
 
/*
37
 
 * GIMP_TYPE_PARAM_RGB
38
 
 */
39
 
 
40
 
#define GIMP_PARAM_SPEC_RGB(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_RGB, GimpParamSpecRGB))
41
 
 
42
 
static void       gimp_param_rgb_class_init  (GParamSpecClass *class);
43
 
static void       gimp_param_rgb_init        (GParamSpec      *pspec);
44
 
static void       gimp_param_rgb_set_default (GParamSpec      *pspec,
45
 
                                              GValue          *value);
46
 
static gboolean   gimp_param_rgb_validate    (GParamSpec      *pspec,
47
 
                                              GValue          *value);
48
 
static gint       gimp_param_rgb_values_cmp  (GParamSpec      *pspec,
49
 
                                              const GValue    *value1,
50
 
                                              const GValue    *value2);
51
 
 
52
 
typedef struct _GimpParamSpecRGB GimpParamSpecRGB;
53
 
 
54
 
struct _GimpParamSpecRGB
55
 
{
56
 
  GParamSpecBoxed  parent_instance;
57
 
 
58
 
  GimpRGB          default_value;
59
 
};
60
 
 
61
 
GType
62
 
gimp_param_rgb_get_type (void)
63
 
{
64
 
  static GType spec_type = 0;
65
 
 
66
 
  if (!spec_type)
67
 
    {
68
 
      static const GTypeInfo type_info =
69
 
      {
70
 
        sizeof (GParamSpecClass),
71
 
        NULL, NULL,
72
 
        (GClassInitFunc) gimp_param_rgb_class_init,
73
 
        NULL, NULL,
74
 
        sizeof (GimpParamSpecRGB),
75
 
        0,
76
 
        (GInstanceInitFunc) gimp_param_rgb_init
77
 
      };
78
 
 
79
 
      spec_type = g_type_register_static (G_TYPE_PARAM_BOXED,
80
 
                                          "GimpParamRGB",
81
 
                                          &type_info, 0);
82
 
    }
83
 
 
84
 
  return spec_type;
85
 
}
86
 
 
87
 
static void
88
 
gimp_param_rgb_class_init (GParamSpecClass *class)
89
 
{
90
 
  class->value_type        = GIMP_TYPE_RGB;
91
 
  class->value_set_default = gimp_param_rgb_set_default;
92
 
  class->value_validate    = gimp_param_rgb_validate;
93
 
  class->values_cmp        = gimp_param_rgb_values_cmp;
94
 
}
95
 
 
96
 
static void
97
 
gimp_param_rgb_init (GParamSpec *pspec)
98
 
{
99
 
  GimpParamSpecRGB *cspec = GIMP_PARAM_SPEC_RGB (pspec);
100
 
 
101
 
  gimp_rgba_set (&cspec->default_value, 0.0, 0.0, 0.0, 0.0);
102
 
}
103
 
 
104
 
static void
105
 
gimp_param_rgb_set_default (GParamSpec *pspec,
106
 
                            GValue     *value)
107
 
{
108
 
  GimpParamSpecRGB *cspec = GIMP_PARAM_SPEC_RGB (pspec);
109
 
 
110
 
  g_value_set_static_boxed (value, &cspec->default_value);
111
 
}
112
 
 
113
 
static gboolean
114
 
gimp_param_rgb_validate (GParamSpec *pspec,
115
 
                         GValue     *value)
116
 
{
117
 
  GimpRGB *rgb;
118
 
 
119
 
  rgb = value->data[0].v_pointer;
120
 
 
121
 
  if (rgb)
122
 
    {
123
 
      GimpRGB oval;
124
 
 
125
 
      oval = *rgb;
126
 
 
127
 
      gimp_rgb_clamp (rgb);
128
 
 
129
 
      return (oval.r != rgb->r ||
130
 
              oval.g != rgb->g ||
131
 
              oval.b != rgb->b ||
132
 
              oval.a != rgb->a);
133
 
    }
134
 
 
135
 
  return FALSE;
136
 
}
137
 
 
138
 
static gint
139
 
gimp_param_rgb_values_cmp (GParamSpec   *pspec,
140
 
                           const GValue *value1,
141
 
                           const GValue *value2)
142
 
{
143
 
  GimpRGB *rgb1;
144
 
  GimpRGB *rgb2;
145
 
 
146
 
  rgb1 = value1->data[0].v_pointer;
147
 
  rgb2 = value2->data[0].v_pointer;
148
 
 
149
 
  /*  try to return at least *something*, it's useless anyway...  */
150
 
 
151
 
  if (! rgb1)
152
 
    return rgb2 != NULL ? -1 : 0;
153
 
  else if (! rgb2)
154
 
    return rgb1 != NULL;
155
 
  else
156
 
    {
157
 
      guint32 int1, int2;
158
 
 
159
 
      gimp_rgba_get_uchar (rgb1,
160
 
                           ((guchar *) &int1) + 0,
161
 
                           ((guchar *) &int1) + 1,
162
 
                           ((guchar *) &int1) + 2,
163
 
                           ((guchar *) &int1) + 3);
164
 
      gimp_rgba_get_uchar (rgb2,
165
 
                           ((guchar *) &int2) + 0,
166
 
                           ((guchar *) &int2) + 1,
167
 
                           ((guchar *) &int2) + 2,
168
 
                           ((guchar *) &int2) + 3);
169
 
 
170
 
      return int1 - int2;
171
 
    }
172
 
}
173
 
 
174
 
GParamSpec *
175
 
gimp_param_spec_rgb (const gchar   *name,
176
 
                     const gchar   *nick,
177
 
                     const gchar   *blurb,
178
 
                     const GimpRGB *default_value,
179
 
                     GParamFlags    flags)
180
 
{
181
 
  GimpParamSpecRGB *cspec;
182
 
 
183
 
  g_return_val_if_fail (default_value != NULL, NULL);
184
 
 
185
 
  cspec = g_param_spec_internal (GIMP_TYPE_PARAM_RGB,
186
 
                                 name, nick, blurb, flags);
187
 
 
188
 
  cspec->default_value = *default_value;
189
 
 
190
 
  return G_PARAM_SPEC (cspec);
191
 
}
192
 
 
193
 
 
194
 
/*
195
 
 * GIMP_TYPE_PARAM_MATRIX2
196
 
 */
197
 
 
198
 
#define GIMP_PARAM_SPEC_MATRIX2(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_MATRIX2, GimpParamSpecMatrix2))
199
 
 
200
 
static void   gimp_param_matrix2_class_init  (GParamSpecClass *class);
201
 
static void   gimp_param_matrix2_init        (GParamSpec      *pspec);
202
 
static void   gimp_param_matrix2_set_default (GParamSpec      *pspec,
203
 
                                              GValue          *value);
204
 
static gint   gimp_param_matrix2_values_cmp  (GParamSpec      *pspec,
205
 
                                              const GValue    *value1,
206
 
                                              const GValue    *value2);
207
 
 
208
 
typedef struct _GimpParamSpecMatrix2 GimpParamSpecMatrix2;
209
 
 
210
 
struct _GimpParamSpecMatrix2
211
 
{
212
 
  GParamSpecBoxed      parent_instance;
213
 
 
214
 
  GimpMatrix2          default_value;
215
 
};
216
 
 
217
 
GType
218
 
gimp_param_matrix2_get_type (void)
219
 
{
220
 
  static GType spec_type = 0;
221
 
 
222
 
  if (!spec_type)
223
 
    {
224
 
      static const GTypeInfo type_info =
225
 
      {
226
 
        sizeof (GParamSpecClass),
227
 
        NULL, NULL,
228
 
        (GClassInitFunc) gimp_param_matrix2_class_init,
229
 
        NULL, NULL,
230
 
        sizeof (GimpParamSpecMatrix2),
231
 
        0,
232
 
        (GInstanceInitFunc) gimp_param_matrix2_init
233
 
      };
234
 
 
235
 
      spec_type = g_type_register_static (G_TYPE_PARAM_BOXED,
236
 
                                          "GimpParamMatrix2",
237
 
                                          &type_info, 0);
238
 
    }
239
 
 
240
 
  return spec_type;
241
 
}
242
 
 
243
 
static void
244
 
gimp_param_matrix2_class_init (GParamSpecClass *class)
245
 
{
246
 
  class->value_type        = GIMP_TYPE_MATRIX2;
247
 
  class->value_set_default = gimp_param_matrix2_set_default;
248
 
  class->values_cmp        = gimp_param_matrix2_values_cmp;
249
 
}
250
 
 
251
 
static void
252
 
gimp_param_matrix2_init (GParamSpec *pspec)
253
 
{
254
 
  GimpParamSpecMatrix2 *cspec = GIMP_PARAM_SPEC_MATRIX2 (pspec);
255
 
 
256
 
  gimp_matrix2_identity (&cspec->default_value);
257
 
}
258
 
 
259
 
static void
260
 
gimp_param_matrix2_set_default (GParamSpec *pspec,
261
 
                                GValue     *value)
262
 
{
263
 
  GimpParamSpecMatrix2 *cspec = GIMP_PARAM_SPEC_MATRIX2 (pspec);
264
 
 
265
 
  g_value_set_static_boxed (value, &cspec->default_value);
266
 
}
267
 
 
268
 
static gint
269
 
gimp_param_matrix2_values_cmp (GParamSpec   *pspec,
270
 
                               const GValue *value1,
271
 
                               const GValue *value2)
272
 
{
273
 
  GimpMatrix2 *matrix1;
274
 
  GimpMatrix2 *matrix2;
275
 
  gint         i, j;
276
 
 
277
 
  matrix1 = value1->data[0].v_pointer;
278
 
  matrix2 = value2->data[0].v_pointer;
279
 
 
280
 
  /*  try to return at least *something*, it's useless anyway...  */
281
 
 
282
 
  if (! matrix1)
283
 
    return matrix2 != NULL ? -1 : 0;
284
 
  else if (! matrix2)
285
 
    return matrix1 != NULL;
286
 
 
287
 
  for (i = 0; i < 2; i++)
288
 
    for (j = 0; j < 2; j++)
289
 
      if (matrix1->coeff[i][j] != matrix2->coeff[i][j])
290
 
        return 1;
291
 
 
292
 
  return 0;
293
 
}
294
 
 
295
 
GParamSpec *
296
 
gimp_param_spec_matrix2 (const gchar       *name,
297
 
                         const gchar       *nick,
298
 
                         const gchar       *blurb,
299
 
                         const GimpMatrix2 *default_value,
300
 
                         GParamFlags        flags)
301
 
{
302
 
  GimpParamSpecMatrix2 *cspec;
303
 
 
304
 
  g_return_val_if_fail (default_value != NULL, NULL);
305
 
 
306
 
  cspec = g_param_spec_internal (GIMP_TYPE_PARAM_MATRIX2,
307
 
                                 name, nick, blurb, flags);
308
 
 
309
 
  cspec->default_value = *default_value;
310
 
 
311
 
  return G_PARAM_SPEC (cspec);
312
 
}
313
 
 
314
 
 
315
 
/*
316
 
 * GIMP_TYPE_PARAM_MEMSIZE
317
 
 */
318
 
 
319
 
static void  gimp_param_memsize_class_init (GParamSpecClass *class);
320
 
 
321
 
GType
322
 
gimp_param_memsize_get_type (void)
323
 
{
324
 
  static GType spec_type = 0;
325
 
 
326
 
  if (!spec_type)
327
 
    {
328
 
      static const GTypeInfo type_info =
329
 
      {
330
 
        sizeof (GParamSpecClass),
331
 
        NULL, NULL,
332
 
        (GClassInitFunc) gimp_param_memsize_class_init,
333
 
        NULL, NULL,
334
 
        sizeof (GParamSpecUInt64),
335
 
        0, NULL, NULL
336
 
      };
337
 
 
338
 
      spec_type = g_type_register_static (G_TYPE_PARAM_UINT64,
339
 
                                          "GimpParamMemsize",
340
 
                                          &type_info, 0);
341
 
    }
342
 
 
343
 
  return spec_type;
344
 
}
345
 
 
346
 
static void
347
 
gimp_param_memsize_class_init (GParamSpecClass *class)
348
 
{
349
 
  class->value_type = GIMP_TYPE_MEMSIZE;
350
 
}
351
 
 
352
 
GParamSpec *
353
 
gimp_param_spec_memsize (const gchar *name,
354
 
                         const gchar *nick,
355
 
                         const gchar *blurb,
356
 
                         guint64      minimum,
357
 
                         guint64      maximum,
358
 
                         guint64      default_value,
359
 
                         GParamFlags  flags)
360
 
{
361
 
  GParamSpecUInt64 *pspec;
362
 
 
363
 
  pspec = g_param_spec_internal (GIMP_TYPE_PARAM_MEMSIZE,
364
 
                                 name, nick, blurb, flags);
365
 
 
366
 
  pspec->minimum       = minimum;
367
 
  pspec->maximum       = maximum;
368
 
  pspec->default_value = default_value;
369
 
 
370
 
  return G_PARAM_SPEC (pspec);
371
 
}
372
 
 
373
 
 
374
 
/*
375
 
 * GIMP_TYPE_PARAM_PATH
376
 
 */
377
 
 
378
 
#define GIMP_PARAM_SPEC_PATH(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_PATH, GimpParamSpecPath))
379
 
 
380
 
typedef struct _GimpParamSpecPath GimpParamSpecPath;
381
 
 
382
 
struct _GimpParamSpecPath
383
 
{
384
 
  GParamSpecString   parent_instance;
385
 
 
386
 
  GimpParamPathType  type;
387
 
};
388
 
 
389
 
static void  gimp_param_path_class_init (GParamSpecClass *class);
390
 
 
391
 
GType
392
 
gimp_param_path_get_type (void)
393
 
{
394
 
  static GType spec_type = 0;
395
 
 
396
 
  if (!spec_type)
397
 
    {
398
 
      static const GTypeInfo type_info =
399
 
      {
400
 
        sizeof (GParamSpecClass),
401
 
        NULL, NULL,
402
 
        (GClassInitFunc) gimp_param_path_class_init,
403
 
        NULL, NULL,
404
 
        sizeof (GimpParamSpecPath),
405
 
        0, NULL, NULL
406
 
      };
407
 
 
408
 
      spec_type = g_type_register_static (G_TYPE_PARAM_STRING,
409
 
                                          "GimpParamPath",
410
 
                                          &type_info, 0);
411
 
    }
412
 
 
413
 
  return spec_type;
414
 
}
415
 
 
416
 
static void
417
 
gimp_param_path_class_init (GParamSpecClass *class)
418
 
{
419
 
  class->value_type = GIMP_TYPE_PATH;
420
 
}
421
 
 
422
 
GParamSpec *
423
 
gimp_param_spec_path (const gchar        *name,
424
 
                      const gchar        *nick,
425
 
                      const gchar        *blurb,
426
 
                      GimpParamPathType   type,
427
 
                      gchar              *default_value,
428
 
                      GParamFlags         flags)
429
 
{
430
 
  GParamSpecString *pspec;
431
 
 
432
 
  pspec = g_param_spec_internal (GIMP_TYPE_PARAM_PATH,
433
 
                                 name, nick, blurb, flags);
434
 
 
435
 
 
436
 
  pspec->default_value = default_value;
437
 
 
438
 
  GIMP_PARAM_SPEC_PATH (pspec)->type = type;
439
 
 
440
 
  return G_PARAM_SPEC (pspec);
441
 
}
442
 
 
443
 
GimpParamPathType
444
 
gimp_param_spec_path_type (GParamSpec *pspec)
445
 
{
446
 
  g_return_val_if_fail (GIMP_IS_PARAM_SPEC_PATH (pspec), 0);
447
 
 
448
 
  return GIMP_PARAM_SPEC_PATH (pspec)->type;
449
 
}
450
 
 
451
 
 
452
 
/*
453
 
 * GIMP_TYPE_PARAM_UNIT
454
 
 */
455
 
 
456
 
#define GIMP_PARAM_SPEC_UNIT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_UNIT, GimpParamSpecUnit))
457
 
 
458
 
typedef struct _GimpParamSpecUnit GimpParamSpecUnit;
459
 
 
460
 
struct _GimpParamSpecUnit
461
 
{
462
 
  GParamSpecInt parent_instance;
463
 
 
464
 
  gboolean      allow_percent;
465
 
};
466
 
 
467
 
static void      gimp_param_unit_class_init     (GParamSpecClass *class);
468
 
static gboolean  gimp_param_unit_value_validate (GParamSpec      *pspec,
469
 
                                                 GValue          *value);
470
 
 
471
 
GType
472
 
gimp_param_unit_get_type (void)
473
 
{
474
 
  static GType spec_type = 0;
475
 
 
476
 
  if (!spec_type)
477
 
    {
478
 
      static const GTypeInfo type_info =
479
 
      {
480
 
        sizeof (GParamSpecClass),
481
 
        NULL, NULL,
482
 
        (GClassInitFunc) gimp_param_unit_class_init,
483
 
        NULL, NULL,
484
 
        sizeof (GimpParamSpecUnit),
485
 
        0, NULL, NULL
486
 
      };
487
 
 
488
 
      spec_type = g_type_register_static (G_TYPE_PARAM_INT,
489
 
                                          "GimpParamUnit",
490
 
                                          &type_info, 0);
491
 
    }
492
 
 
493
 
  return spec_type;
494
 
}
495
 
 
496
 
static void
497
 
gimp_param_unit_class_init (GParamSpecClass *class)
498
 
{
499
 
  class->value_type     = GIMP_TYPE_UNIT;
500
 
  class->value_validate = gimp_param_unit_value_validate;
501
 
}
502
 
 
503
 
static gboolean
504
 
gimp_param_unit_value_validate (GParamSpec *pspec,
505
 
                                GValue     *value)
506
 
{
507
 
  GParamSpecInt     *ispec = G_PARAM_SPEC_INT (pspec);
508
 
  GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec);
509
 
  gint               oval  = value->data[0].v_int;
510
 
 
511
 
  if (uspec->allow_percent && value->data[0].v_int == GIMP_UNIT_PERCENT)
512
 
    {
513
 
      value->data[0].v_int = value->data[0].v_int;
514
 
    }
515
 
  else
516
 
    {
517
 
      value->data[0].v_int = CLAMP (value->data[0].v_int,
518
 
                                    ispec->minimum,
519
 
                                    gimp_unit_get_number_of_units () - 1);
520
 
    }
521
 
 
522
 
  return value->data[0].v_int != oval;
523
 
}
524
 
 
525
 
GParamSpec *
526
 
gimp_param_spec_unit (const gchar *name,
527
 
                      const gchar *nick,
528
 
                      const gchar *blurb,
529
 
                      gboolean     allow_pixels,
530
 
                      gboolean     allow_percent,
531
 
                      GimpUnit     default_value,
532
 
                      GParamFlags  flags)
533
 
{
534
 
  GimpParamSpecUnit *pspec;
535
 
  GParamSpecInt     *ispec;
536
 
 
537
 
  pspec = g_param_spec_internal (GIMP_TYPE_PARAM_UNIT,
538
 
                                 name, nick, blurb, flags);
539
 
 
540
 
  ispec = G_PARAM_SPEC_INT (pspec);
541
 
 
542
 
  ispec->default_value = default_value;
543
 
  ispec->minimum       = allow_pixels ? GIMP_UNIT_PIXEL : GIMP_UNIT_INCH;
544
 
  ispec->maximum       = GIMP_UNIT_PERCENT - 1;
545
 
 
546
 
  pspec->allow_percent = allow_percent;
547
 
 
548
 
  return G_PARAM_SPEC (pspec);
549
 
}