1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 #include "config.h"
19 
20 #include <gdk-pixbuf/gdk-pixbuf.h>
21 #include <gegl.h>
22 
23 #include "libgimpbase/gimpbase.h"
24 
25 #include "core-types.h"
26 
27 #include "gimp.h"
28 #include "gimpimage.h"
29 #include "gimplayer.h"
30 #include "gimplayermask.h"
31 #include "gimpparamspecs.h"
32 #include "gimpselection.h"
33 
34 #include "vectors/gimpvectors.h"
35 
36 
37 /*
38  * GIMP_TYPE_INT32
39  */
40 
41 GType
gimp_int32_get_type(void)42 gimp_int32_get_type (void)
43 {
44   static GType type = 0;
45 
46   if (! type)
47     {
48       const GTypeInfo info = { 0, };
49 
50       type = g_type_register_static (G_TYPE_INT, "GimpInt32", &info, 0);
51     }
52 
53   return type;
54 }
55 
56 
57 /*
58  * GIMP_TYPE_PARAM_INT32
59  */
60 
61 static void   gimp_param_int32_class_init (GParamSpecClass *klass);
62 static void   gimp_param_int32_init       (GParamSpec      *pspec);
63 
64 GType
gimp_param_int32_get_type(void)65 gimp_param_int32_get_type (void)
66 {
67   static GType type = 0;
68 
69   if (! type)
70     {
71       const GTypeInfo info =
72       {
73         sizeof (GParamSpecClass),
74         NULL, NULL,
75         (GClassInitFunc) gimp_param_int32_class_init,
76         NULL, NULL,
77         sizeof (GimpParamSpecInt32),
78         0,
79         (GInstanceInitFunc) gimp_param_int32_init
80       };
81 
82       type = g_type_register_static (G_TYPE_PARAM_INT,
83                                      "GimpParamInt32", &info, 0);
84     }
85 
86   return type;
87 }
88 
89 static void
gimp_param_int32_class_init(GParamSpecClass * klass)90 gimp_param_int32_class_init (GParamSpecClass *klass)
91 {
92   klass->value_type = GIMP_TYPE_INT32;
93 }
94 
95 static void
gimp_param_int32_init(GParamSpec * pspec)96 gimp_param_int32_init (GParamSpec *pspec)
97 {
98 }
99 
100 GParamSpec *
gimp_param_spec_int32(const gchar * name,const gchar * nick,const gchar * blurb,gint minimum,gint maximum,gint default_value,GParamFlags flags)101 gimp_param_spec_int32 (const gchar *name,
102                        const gchar *nick,
103                        const gchar *blurb,
104                        gint         minimum,
105                        gint         maximum,
106                        gint         default_value,
107                        GParamFlags  flags)
108 {
109   GParamSpecInt *ispec;
110 
111   g_return_val_if_fail (minimum >= G_MININT32, NULL);
112   g_return_val_if_fail (maximum <= G_MAXINT32, NULL);
113   g_return_val_if_fail (default_value >= minimum &&
114                         default_value <= maximum, NULL);
115 
116   ispec = g_param_spec_internal (GIMP_TYPE_PARAM_INT32,
117                                  name, nick, blurb, flags);
118 
119   ispec->minimum       = minimum;
120   ispec->maximum       = maximum;
121   ispec->default_value = default_value;
122 
123   return G_PARAM_SPEC (ispec);
124 }
125 
126 
127 /*
128  * GIMP_TYPE_INT16
129  */
130 
131 GType
gimp_int16_get_type(void)132 gimp_int16_get_type (void)
133 {
134   static GType type = 0;
135 
136   if (! type)
137     {
138       const GTypeInfo info = { 0, };
139 
140       type = g_type_register_static (G_TYPE_INT, "GimpInt16", &info, 0);
141     }
142 
143   return type;
144 }
145 
146 
147 /*
148  * GIMP_TYPE_PARAM_INT16
149  */
150 
151 static void   gimp_param_int16_class_init (GParamSpecClass *klass);
152 static void   gimp_param_int16_init       (GParamSpec      *pspec);
153 
154 GType
gimp_param_int16_get_type(void)155 gimp_param_int16_get_type (void)
156 {
157   static GType type = 0;
158 
159   if (! type)
160     {
161       const GTypeInfo info =
162       {
163         sizeof (GParamSpecClass),
164         NULL, NULL,
165         (GClassInitFunc) gimp_param_int16_class_init,
166         NULL, NULL,
167         sizeof (GimpParamSpecInt16),
168         0,
169         (GInstanceInitFunc) gimp_param_int16_init
170       };
171 
172       type = g_type_register_static (G_TYPE_PARAM_INT,
173                                      "GimpParamInt16", &info, 0);
174     }
175 
176   return type;
177 }
178 
179 static void
gimp_param_int16_class_init(GParamSpecClass * klass)180 gimp_param_int16_class_init (GParamSpecClass *klass)
181 {
182   klass->value_type = GIMP_TYPE_INT16;
183 }
184 
185 static void
gimp_param_int16_init(GParamSpec * pspec)186 gimp_param_int16_init (GParamSpec *pspec)
187 {
188 }
189 
190 GParamSpec *
gimp_param_spec_int16(const gchar * name,const gchar * nick,const gchar * blurb,gint minimum,gint maximum,gint default_value,GParamFlags flags)191 gimp_param_spec_int16 (const gchar *name,
192                        const gchar *nick,
193                        const gchar *blurb,
194                        gint         minimum,
195                        gint         maximum,
196                        gint         default_value,
197                        GParamFlags  flags)
198 {
199   GParamSpecInt *ispec;
200 
201   g_return_val_if_fail (minimum >= G_MININT16, NULL);
202   g_return_val_if_fail (maximum <= G_MAXINT16, NULL);
203   g_return_val_if_fail (default_value >= minimum &&
204                         default_value <= maximum, NULL);
205 
206   ispec = g_param_spec_internal (GIMP_TYPE_PARAM_INT16,
207                                  name, nick, blurb, flags);
208 
209   ispec->minimum       = minimum;
210   ispec->maximum       = maximum;
211   ispec->default_value = default_value;
212 
213   return G_PARAM_SPEC (ispec);
214 }
215 
216 
217 /*
218  * GIMP_TYPE_INT8
219  */
220 
221 GType
gimp_int8_get_type(void)222 gimp_int8_get_type (void)
223 {
224   static GType type = 0;
225 
226   if (! type)
227     {
228       const GTypeInfo info = { 0, };
229 
230       type = g_type_register_static (G_TYPE_UINT, "GimpInt8", &info, 0);
231     }
232 
233   return type;
234 }
235 
236 
237 /*
238  * GIMP_TYPE_PARAM_INT8
239  */
240 
241 static void   gimp_param_int8_class_init (GParamSpecClass *klass);
242 static void   gimp_param_int8_init       (GParamSpec      *pspec);
243 
244 GType
gimp_param_int8_get_type(void)245 gimp_param_int8_get_type (void)
246 {
247   static GType type = 0;
248 
249   if (! type)
250     {
251       const GTypeInfo info =
252       {
253         sizeof (GParamSpecClass),
254         NULL, NULL,
255         (GClassInitFunc) gimp_param_int8_class_init,
256         NULL, NULL,
257         sizeof (GimpParamSpecInt8),
258         0,
259         (GInstanceInitFunc) gimp_param_int8_init
260       };
261 
262       type = g_type_register_static (G_TYPE_PARAM_UINT,
263                                      "GimpParamInt8", &info, 0);
264     }
265 
266   return type;
267 }
268 
269 static void
gimp_param_int8_class_init(GParamSpecClass * klass)270 gimp_param_int8_class_init (GParamSpecClass *klass)
271 {
272   klass->value_type = GIMP_TYPE_INT8;
273 }
274 
275 static void
gimp_param_int8_init(GParamSpec * pspec)276 gimp_param_int8_init (GParamSpec *pspec)
277 {
278 }
279 
280 GParamSpec *
gimp_param_spec_int8(const gchar * name,const gchar * nick,const gchar * blurb,guint minimum,guint maximum,guint default_value,GParamFlags flags)281 gimp_param_spec_int8 (const gchar *name,
282                       const gchar *nick,
283                       const gchar *blurb,
284                       guint        minimum,
285                       guint        maximum,
286                       guint        default_value,
287                       GParamFlags  flags)
288 {
289   GParamSpecInt *ispec;
290 
291   g_return_val_if_fail (maximum <= G_MAXUINT8, NULL);
292   g_return_val_if_fail (default_value >= minimum &&
293                         default_value <= maximum, NULL);
294 
295   ispec = g_param_spec_internal (GIMP_TYPE_PARAM_INT8,
296                                  name, nick, blurb, flags);
297 
298   ispec->minimum       = minimum;
299   ispec->maximum       = maximum;
300   ispec->default_value = default_value;
301 
302   return G_PARAM_SPEC (ispec);
303 }
304 
305 
306 /*
307  * GIMP_TYPE_PARAM_STRING
308  */
309 
310 static void       gimp_param_string_class_init (GParamSpecClass *klass);
311 static void       gimp_param_string_init       (GParamSpec      *pspec);
312 static gboolean   gimp_param_string_validate   (GParamSpec      *pspec,
313                                                 GValue          *value);
314 
315 static GParamSpecClass * gimp_param_string_parent_class = NULL;
316 
317 GType
gimp_param_string_get_type(void)318 gimp_param_string_get_type (void)
319 {
320   static GType type = 0;
321 
322   if (! type)
323     {
324       const GTypeInfo info =
325       {
326         sizeof (GParamSpecClass),
327         NULL, NULL,
328         (GClassInitFunc) gimp_param_string_class_init,
329         NULL, NULL,
330         sizeof (GimpParamSpecString),
331         0,
332         (GInstanceInitFunc) gimp_param_string_init
333       };
334 
335       type = g_type_register_static (G_TYPE_PARAM_STRING,
336                                      "GimpParamString", &info, 0);
337     }
338 
339   return type;
340 }
341 
342 static void
gimp_param_string_class_init(GParamSpecClass * klass)343 gimp_param_string_class_init (GParamSpecClass *klass)
344 {
345   gimp_param_string_parent_class = g_type_class_peek_parent (klass);
346 
347   klass->value_type     = G_TYPE_STRING;
348   klass->value_validate = gimp_param_string_validate;
349 }
350 
351 static void
gimp_param_string_init(GParamSpec * pspec)352 gimp_param_string_init (GParamSpec *pspec)
353 {
354   GimpParamSpecString *sspec = GIMP_PARAM_SPEC_STRING (pspec);
355 
356   G_PARAM_SPEC_STRING (pspec)->ensure_non_null = TRUE;
357 
358   sspec->allow_non_utf8 = FALSE;
359   sspec->non_empty      = FALSE;
360 }
361 
362 static gboolean
gimp_param_string_validate(GParamSpec * pspec,GValue * value)363 gimp_param_string_validate (GParamSpec *pspec,
364                             GValue     *value)
365 {
366   GimpParamSpecString *sspec  = GIMP_PARAM_SPEC_STRING (pspec);
367   gchar               *string = value->data[0].v_pointer;
368 
369   if (gimp_param_string_parent_class->value_validate (pspec, value))
370     return TRUE;
371 
372   if (string)
373     {
374       gchar *s;
375 
376       if (sspec->non_empty && ! string[0])
377         {
378           if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
379             g_free (string);
380           else
381             value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
382 
383           value->data[0].v_pointer = g_strdup ("none");
384           return TRUE;
385         }
386 
387       if (! sspec->allow_non_utf8 &&
388           ! g_utf8_validate (string, -1, (const gchar **) &s))
389         {
390           if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
391             {
392               value->data[0].v_pointer = g_strdup (string);
393               value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
394               string = value->data[0].v_pointer;
395             }
396 
397           for (s = string; *s; s++)
398             if (*s < ' ')
399               *s = '?';
400 
401           return TRUE;
402         }
403     }
404   else if (sspec->non_empty)
405     {
406       value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
407       value->data[0].v_pointer = g_strdup ("none");
408       return TRUE;
409     }
410 
411   return FALSE;
412 }
413 
414 GParamSpec *
gimp_param_spec_string(const gchar * name,const gchar * nick,const gchar * blurb,gboolean allow_non_utf8,gboolean null_ok,gboolean non_empty,const gchar * default_value,GParamFlags flags)415 gimp_param_spec_string (const gchar *name,
416                         const gchar *nick,
417                         const gchar *blurb,
418                         gboolean     allow_non_utf8,
419                         gboolean     null_ok,
420                         gboolean     non_empty,
421                         const gchar *default_value,
422                         GParamFlags  flags)
423 {
424   GimpParamSpecString *sspec;
425 
426   g_return_val_if_fail (! (null_ok && non_empty), NULL);
427 
428   sspec = g_param_spec_internal (GIMP_TYPE_PARAM_STRING,
429                                  name, nick, blurb, flags);
430 
431   if (sspec)
432     {
433       g_free (G_PARAM_SPEC_STRING (sspec)->default_value);
434       G_PARAM_SPEC_STRING (sspec)->default_value = g_strdup (default_value);
435 
436       G_PARAM_SPEC_STRING (sspec)->ensure_non_null = null_ok ? FALSE : TRUE;
437 
438       sspec->allow_non_utf8 = allow_non_utf8 ? TRUE : FALSE;
439       sspec->non_empty      = non_empty      ? TRUE : FALSE;
440     }
441 
442   return G_PARAM_SPEC (sspec);
443 }
444 
445 
446 /*
447  * GIMP_TYPE_PARAM_ENUM
448  */
449 
450 static void       gimp_param_enum_class_init (GParamSpecClass *klass);
451 static void       gimp_param_enum_init       (GParamSpec      *pspec);
452 static void       gimp_param_enum_finalize   (GParamSpec      *pspec);
453 static gboolean   gimp_param_enum_validate   (GParamSpec      *pspec,
454                                               GValue          *value);
455 
456 GType
gimp_param_enum_get_type(void)457 gimp_param_enum_get_type (void)
458 {
459   static GType type = 0;
460 
461   if (! type)
462     {
463       const GTypeInfo info =
464       {
465         sizeof (GParamSpecClass),
466         NULL, NULL,
467         (GClassInitFunc) gimp_param_enum_class_init,
468         NULL, NULL,
469         sizeof (GimpParamSpecEnum),
470         0,
471         (GInstanceInitFunc) gimp_param_enum_init
472       };
473 
474       type = g_type_register_static (G_TYPE_PARAM_ENUM,
475                                      "GimpParamEnum", &info, 0);
476     }
477 
478   return type;
479 }
480 
481 static void
gimp_param_enum_class_init(GParamSpecClass * klass)482 gimp_param_enum_class_init (GParamSpecClass *klass)
483 {
484   klass->value_type     = G_TYPE_ENUM;
485   klass->finalize       = gimp_param_enum_finalize;
486   klass->value_validate = gimp_param_enum_validate;
487 }
488 
489 static void
gimp_param_enum_init(GParamSpec * pspec)490 gimp_param_enum_init (GParamSpec *pspec)
491 {
492   GimpParamSpecEnum *espec = GIMP_PARAM_SPEC_ENUM (pspec);
493 
494   espec->excluded_values = NULL;
495 }
496 
497 static void
gimp_param_enum_finalize(GParamSpec * pspec)498 gimp_param_enum_finalize (GParamSpec *pspec)
499 {
500   GimpParamSpecEnum *espec = GIMP_PARAM_SPEC_ENUM (pspec);
501   GParamSpecClass   *parent_class;
502 
503   parent_class = g_type_class_peek (g_type_parent (GIMP_TYPE_PARAM_ENUM));
504 
505   g_slist_free (espec->excluded_values);
506 
507   parent_class->finalize (pspec);
508 }
509 
510 static gboolean
gimp_param_enum_validate(GParamSpec * pspec,GValue * value)511 gimp_param_enum_validate (GParamSpec *pspec,
512                           GValue     *value)
513 {
514   GimpParamSpecEnum *espec  = GIMP_PARAM_SPEC_ENUM (pspec);
515   GParamSpecClass   *parent_class;
516   GSList            *list;
517 
518   parent_class = g_type_class_peek (g_type_parent (GIMP_TYPE_PARAM_ENUM));
519 
520   if (parent_class->value_validate (pspec, value))
521     return TRUE;
522 
523   for (list = espec->excluded_values; list; list = g_slist_next (list))
524     {
525       if (GPOINTER_TO_INT (list->data) == value->data[0].v_long)
526         {
527           value->data[0].v_long = G_PARAM_SPEC_ENUM (pspec)->default_value;
528           return TRUE;
529         }
530     }
531 
532   return FALSE;
533 }
534 
535 GParamSpec *
gimp_param_spec_enum(const gchar * name,const gchar * nick,const gchar * blurb,GType enum_type,gint default_value,GParamFlags flags)536 gimp_param_spec_enum (const gchar *name,
537                       const gchar *nick,
538                       const gchar *blurb,
539                       GType        enum_type,
540                       gint         default_value,
541                       GParamFlags  flags)
542 {
543   GimpParamSpecEnum *espec;
544   GEnumClass        *enum_class;
545 
546   g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
547 
548   enum_class = g_type_class_ref (enum_type);
549 
550   g_return_val_if_fail (g_enum_get_value (enum_class, default_value) != NULL,
551                         NULL);
552 
553   espec = g_param_spec_internal (GIMP_TYPE_PARAM_ENUM,
554                                  name, nick, blurb, flags);
555 
556   G_PARAM_SPEC_ENUM (espec)->enum_class    = enum_class;
557   G_PARAM_SPEC_ENUM (espec)->default_value = default_value;
558   G_PARAM_SPEC (espec)->value_type         = enum_type;
559 
560   return G_PARAM_SPEC (espec);
561 }
562 
563 void
gimp_param_spec_enum_exclude_value(GimpParamSpecEnum * espec,gint value)564 gimp_param_spec_enum_exclude_value (GimpParamSpecEnum *espec,
565                                     gint               value)
566 {
567   g_return_if_fail (GIMP_IS_PARAM_SPEC_ENUM (espec));
568   g_return_if_fail (g_enum_get_value (G_PARAM_SPEC_ENUM (espec)->enum_class,
569                                       value) != NULL);
570 
571   espec->excluded_values = g_slist_prepend (espec->excluded_values,
572                                             GINT_TO_POINTER (value));
573 }
574 
575 
576 /*
577  * GIMP_TYPE_IMAGE_ID
578  */
579 
580 GType
gimp_image_id_get_type(void)581 gimp_image_id_get_type (void)
582 {
583   static GType type = 0;
584 
585   if (! type)
586     {
587       const GTypeInfo info = { 0, };
588 
589       type = g_type_register_static (G_TYPE_INT, "GimpImageID", &info, 0);
590     }
591 
592   return type;
593 }
594 
595 
596 /*
597  * GIMP_TYPE_PARAM_IMAGE_ID
598  */
599 
600 static void       gimp_param_image_id_class_init  (GParamSpecClass *klass);
601 static void       gimp_param_image_id_init        (GParamSpec      *pspec);
602 static void       gimp_param_image_id_set_default (GParamSpec      *pspec,
603                                                    GValue          *value);
604 static gboolean   gimp_param_image_id_validate    (GParamSpec      *pspec,
605                                                    GValue          *value);
606 static gint       gimp_param_image_id_values_cmp  (GParamSpec      *pspec,
607                                                    const GValue    *value1,
608                                                    const GValue    *value2);
609 
610 GType
gimp_param_image_id_get_type(void)611 gimp_param_image_id_get_type (void)
612 {
613   static GType type = 0;
614 
615   if (! type)
616     {
617       const GTypeInfo info =
618       {
619         sizeof (GParamSpecClass),
620         NULL, NULL,
621         (GClassInitFunc) gimp_param_image_id_class_init,
622         NULL, NULL,
623         sizeof (GimpParamSpecImageID),
624         0,
625         (GInstanceInitFunc) gimp_param_image_id_init
626       };
627 
628       type = g_type_register_static (G_TYPE_PARAM_INT,
629                                      "GimpParamImageID", &info, 0);
630     }
631 
632   return type;
633 }
634 
635 static void
gimp_param_image_id_class_init(GParamSpecClass * klass)636 gimp_param_image_id_class_init (GParamSpecClass *klass)
637 {
638   klass->value_type        = GIMP_TYPE_IMAGE_ID;
639   klass->value_set_default = gimp_param_image_id_set_default;
640   klass->value_validate    = gimp_param_image_id_validate;
641   klass->values_cmp        = gimp_param_image_id_values_cmp;
642 }
643 
644 static void
gimp_param_image_id_init(GParamSpec * pspec)645 gimp_param_image_id_init (GParamSpec *pspec)
646 {
647   GimpParamSpecImageID *ispec = GIMP_PARAM_SPEC_IMAGE_ID (pspec);
648 
649   ispec->gimp    = NULL;
650   ispec->none_ok = FALSE;
651 }
652 
653 static void
gimp_param_image_id_set_default(GParamSpec * pspec,GValue * value)654 gimp_param_image_id_set_default (GParamSpec *pspec,
655                                  GValue     *value)
656 {
657   value->data[0].v_int = -1;
658 }
659 
660 static gboolean
gimp_param_image_id_validate(GParamSpec * pspec,GValue * value)661 gimp_param_image_id_validate (GParamSpec *pspec,
662                               GValue     *value)
663 {
664   GimpParamSpecImageID *ispec    = GIMP_PARAM_SPEC_IMAGE_ID (pspec);
665   gint                  image_id = value->data[0].v_int;
666   GimpImage            *image;
667 
668   if (ispec->none_ok && (image_id == 0 || image_id == -1))
669     return FALSE;
670 
671   image = gimp_image_get_by_ID (ispec->gimp, image_id);
672 
673   if (! GIMP_IS_IMAGE (image))
674     {
675       value->data[0].v_int = -1;
676       return TRUE;
677     }
678 
679   return FALSE;
680 }
681 
682 static gint
gimp_param_image_id_values_cmp(GParamSpec * pspec,const GValue * value1,const GValue * value2)683 gimp_param_image_id_values_cmp (GParamSpec   *pspec,
684                                 const GValue *value1,
685                                 const GValue *value2)
686 {
687   gint image_id1 = value1->data[0].v_int;
688   gint image_id2 = value2->data[0].v_int;
689 
690   /*  try to return at least *something*, it's useless anyway...  */
691 
692   if (image_id1 < image_id2)
693     return -1;
694   else if (image_id1 > image_id2)
695     return 1;
696   else
697     return 0;
698 }
699 
700 GParamSpec *
gimp_param_spec_image_id(const gchar * name,const gchar * nick,const gchar * blurb,Gimp * gimp,gboolean none_ok,GParamFlags flags)701 gimp_param_spec_image_id (const gchar *name,
702                           const gchar *nick,
703                           const gchar *blurb,
704                           Gimp        *gimp,
705                           gboolean     none_ok,
706                           GParamFlags  flags)
707 {
708   GimpParamSpecImageID *ispec;
709 
710   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
711 
712   ispec = g_param_spec_internal (GIMP_TYPE_PARAM_IMAGE_ID,
713                                  name, nick, blurb, flags);
714 
715   ispec->gimp    = gimp;
716   ispec->none_ok = none_ok ? TRUE : FALSE;
717 
718   return G_PARAM_SPEC (ispec);
719 }
720 
721 GimpImage *
gimp_value_get_image(const GValue * value,Gimp * gimp)722 gimp_value_get_image (const GValue *value,
723                       Gimp         *gimp)
724 {
725   g_return_val_if_fail (GIMP_VALUE_HOLDS_IMAGE_ID (value), NULL);
726   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
727 
728   return gimp_image_get_by_ID (gimp, value->data[0].v_int);
729 }
730 
731 void
gimp_value_set_image(GValue * value,GimpImage * image)732 gimp_value_set_image (GValue    *value,
733                       GimpImage *image)
734 {
735   g_return_if_fail (GIMP_VALUE_HOLDS_IMAGE_ID (value));
736   g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));
737 
738   value->data[0].v_int = image ? gimp_image_get_ID (image) : -1;
739 }
740 
741 
742 /*
743  * GIMP_TYPE_ITEM_ID
744  */
745 
746 GType
gimp_item_id_get_type(void)747 gimp_item_id_get_type (void)
748 {
749   static GType type = 0;
750 
751   if (! type)
752     {
753       const GTypeInfo info = { 0, };
754 
755       type = g_type_register_static (G_TYPE_INT, "GimpItemID", &info, 0);
756     }
757 
758   return type;
759 }
760 
761 
762 /*
763  * GIMP_TYPE_PARAM_ITEM_ID
764  */
765 
766 static void       gimp_param_item_id_class_init  (GParamSpecClass *klass);
767 static void       gimp_param_item_id_init        (GParamSpec      *pspec);
768 static void       gimp_param_item_id_set_default (GParamSpec      *pspec,
769                                                   GValue          *value);
770 static gboolean   gimp_param_item_id_validate    (GParamSpec      *pspec,
771                                                   GValue          *value);
772 static gint       gimp_param_item_id_values_cmp  (GParamSpec      *pspec,
773                                                   const GValue    *value1,
774                                                   const GValue    *value2);
775 
776 GType
gimp_param_item_id_get_type(void)777 gimp_param_item_id_get_type (void)
778 {
779   static GType type = 0;
780 
781   if (! type)
782     {
783       const GTypeInfo info =
784       {
785         sizeof (GParamSpecClass),
786         NULL, NULL,
787         (GClassInitFunc) gimp_param_item_id_class_init,
788         NULL, NULL,
789         sizeof (GimpParamSpecItemID),
790         0,
791         (GInstanceInitFunc) gimp_param_item_id_init
792       };
793 
794       type = g_type_register_static (G_TYPE_PARAM_INT,
795                                      "GimpParamItemID", &info, 0);
796     }
797 
798   return type;
799 }
800 
801 static void
gimp_param_item_id_class_init(GParamSpecClass * klass)802 gimp_param_item_id_class_init (GParamSpecClass *klass)
803 {
804   klass->value_type        = GIMP_TYPE_ITEM_ID;
805   klass->value_set_default = gimp_param_item_id_set_default;
806   klass->value_validate    = gimp_param_item_id_validate;
807   klass->values_cmp        = gimp_param_item_id_values_cmp;
808 }
809 
810 static void
gimp_param_item_id_init(GParamSpec * pspec)811 gimp_param_item_id_init (GParamSpec *pspec)
812 {
813   GimpParamSpecItemID *ispec = GIMP_PARAM_SPEC_ITEM_ID (pspec);
814 
815   ispec->gimp      = NULL;
816   ispec->item_type = GIMP_TYPE_ITEM;
817   ispec->none_ok   = FALSE;
818 }
819 
820 static void
gimp_param_item_id_set_default(GParamSpec * pspec,GValue * value)821 gimp_param_item_id_set_default (GParamSpec *pspec,
822                                 GValue     *value)
823 {
824   value->data[0].v_int = -1;
825 }
826 
827 static gboolean
gimp_param_item_id_validate(GParamSpec * pspec,GValue * value)828 gimp_param_item_id_validate (GParamSpec *pspec,
829                              GValue     *value)
830 {
831   GimpParamSpecItemID *ispec   = GIMP_PARAM_SPEC_ITEM_ID (pspec);
832   gint                 item_id = value->data[0].v_int;
833   GimpItem            *item;
834 
835   if (ispec->none_ok && (item_id == 0 || item_id == -1))
836     return FALSE;
837 
838   item = gimp_item_get_by_ID (ispec->gimp, item_id);
839 
840   if (! item || ! g_type_is_a (G_TYPE_FROM_INSTANCE (item), ispec->item_type))
841     {
842       value->data[0].v_int = -1;
843       return TRUE;
844     }
845   else if (gimp_item_is_removed (item))
846     {
847       value->data[0].v_int = -1;
848       return TRUE;
849     }
850 
851   return FALSE;
852 }
853 
854 static gint
gimp_param_item_id_values_cmp(GParamSpec * pspec,const GValue * value1,const GValue * value2)855 gimp_param_item_id_values_cmp (GParamSpec   *pspec,
856                                const GValue *value1,
857                                const GValue *value2)
858 {
859   gint item_id1 = value1->data[0].v_int;
860   gint item_id2 = value2->data[0].v_int;
861 
862   /*  try to return at least *something*, it's useless anyway...  */
863 
864   if (item_id1 < item_id2)
865     return -1;
866   else if (item_id1 > item_id2)
867     return 1;
868   else
869     return 0;
870 }
871 
872 GParamSpec *
gimp_param_spec_item_id(const gchar * name,const gchar * nick,const gchar * blurb,Gimp * gimp,gboolean none_ok,GParamFlags flags)873 gimp_param_spec_item_id (const gchar *name,
874                          const gchar *nick,
875                          const gchar *blurb,
876                          Gimp        *gimp,
877                          gboolean     none_ok,
878                          GParamFlags  flags)
879 {
880   GimpParamSpecItemID *ispec;
881 
882   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
883 
884   ispec = g_param_spec_internal (GIMP_TYPE_PARAM_ITEM_ID,
885                                  name, nick, blurb, flags);
886 
887   ispec->gimp    = gimp;
888   ispec->none_ok = none_ok;
889 
890   return G_PARAM_SPEC (ispec);
891 }
892 
893 GimpItem *
gimp_value_get_item(const GValue * value,Gimp * gimp)894 gimp_value_get_item (const GValue *value,
895                      Gimp         *gimp)
896 {
897   GimpItem *item;
898 
899   g_return_val_if_fail (GIMP_VALUE_HOLDS_ITEM_ID (value), NULL);
900   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
901 
902   item = gimp_item_get_by_ID (gimp, value->data[0].v_int);
903 
904   if (item && ! GIMP_IS_ITEM (item))
905     return NULL;
906 
907   return item;
908 }
909 
910 void
gimp_value_set_item(GValue * value,GimpItem * item)911 gimp_value_set_item (GValue   *value,
912                      GimpItem *item)
913 {
914   g_return_if_fail (item == NULL || GIMP_IS_ITEM (item));
915 
916   /* FIXME remove hack as soon as bug #375864 is fixed */
917 
918   if (GIMP_VALUE_HOLDS_ITEM_ID (value))
919     {
920       value->data[0].v_int = item ? gimp_item_get_ID (item) : -1;
921     }
922   else if (GIMP_VALUE_HOLDS_DRAWABLE_ID (value) &&
923            (item == NULL || GIMP_IS_DRAWABLE (item)))
924     {
925       gimp_value_set_drawable (value, GIMP_DRAWABLE (item));
926     }
927   else if (GIMP_VALUE_HOLDS_LAYER_ID (value) &&
928            (item == NULL || GIMP_IS_LAYER (item)))
929     {
930       gimp_value_set_layer (value, GIMP_LAYER (item));
931     }
932   else if (GIMP_VALUE_HOLDS_CHANNEL_ID (value) &&
933            (item == NULL || GIMP_IS_CHANNEL (item)))
934     {
935       gimp_value_set_channel (value, GIMP_CHANNEL (item));
936     }
937   else if (GIMP_VALUE_HOLDS_LAYER_MASK_ID (value) &&
938            (item == NULL || GIMP_IS_LAYER_MASK (item)))
939     {
940       gimp_value_set_layer_mask (value, GIMP_LAYER_MASK (item));
941     }
942   else if (GIMP_VALUE_HOLDS_SELECTION_ID (value) &&
943            (item == NULL || GIMP_IS_SELECTION (item)))
944     {
945       gimp_value_set_selection (value, GIMP_SELECTION (item));
946     }
947   else if (GIMP_VALUE_HOLDS_VECTORS_ID (value) &&
948            (item == NULL || GIMP_IS_VECTORS (item)))
949     {
950       gimp_value_set_vectors (value, GIMP_VECTORS (item));
951     }
952   else
953     {
954       g_return_if_reached ();
955     }
956 }
957 
958 
959 /*
960  * GIMP_TYPE_DRAWABLE_ID
961  */
962 
963 GType
gimp_drawable_id_get_type(void)964 gimp_drawable_id_get_type (void)
965 {
966   static GType type = 0;
967 
968   if (! type)
969     {
970       const GTypeInfo info = { 0, };
971 
972       type = g_type_register_static (G_TYPE_INT, "GimpDrawableID", &info, 0);
973     }
974 
975   return type;
976 }
977 
978 
979 /*
980  * GIMP_TYPE_PARAM_DRAWABLE_ID
981  */
982 
983 static void   gimp_param_drawable_id_class_init (GParamSpecClass *klass);
984 static void   gimp_param_drawable_id_init       (GParamSpec      *pspec);
985 
986 GType
gimp_param_drawable_id_get_type(void)987 gimp_param_drawable_id_get_type (void)
988 {
989   static GType type = 0;
990 
991   if (! type)
992     {
993       const GTypeInfo info =
994       {
995         sizeof (GParamSpecClass),
996         NULL, NULL,
997         (GClassInitFunc) gimp_param_drawable_id_class_init,
998         NULL, NULL,
999         sizeof (GimpParamSpecDrawableID),
1000         0,
1001         (GInstanceInitFunc) gimp_param_drawable_id_init
1002       };
1003 
1004       type = g_type_register_static (GIMP_TYPE_PARAM_ITEM_ID,
1005                                      "GimpParamDrawableID", &info, 0);
1006     }
1007 
1008   return type;
1009 }
1010 
1011 static void
gimp_param_drawable_id_class_init(GParamSpecClass * klass)1012 gimp_param_drawable_id_class_init (GParamSpecClass *klass)
1013 {
1014   klass->value_type = GIMP_TYPE_DRAWABLE_ID;
1015 }
1016 
1017 static void
gimp_param_drawable_id_init(GParamSpec * pspec)1018 gimp_param_drawable_id_init (GParamSpec *pspec)
1019 {
1020   GimpParamSpecItemID *ispec = GIMP_PARAM_SPEC_ITEM_ID (pspec);
1021 
1022   ispec->item_type = GIMP_TYPE_DRAWABLE;
1023 }
1024 
1025 GParamSpec *
gimp_param_spec_drawable_id(const gchar * name,const gchar * nick,const gchar * blurb,Gimp * gimp,gboolean none_ok,GParamFlags flags)1026 gimp_param_spec_drawable_id (const gchar *name,
1027                              const gchar *nick,
1028                              const gchar *blurb,
1029                              Gimp        *gimp,
1030                              gboolean     none_ok,
1031                              GParamFlags  flags)
1032 {
1033   GimpParamSpecItemID *ispec;
1034 
1035   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1036 
1037   ispec = g_param_spec_internal (GIMP_TYPE_PARAM_DRAWABLE_ID,
1038                                  name, nick, blurb, flags);
1039 
1040   ispec->gimp    = gimp;
1041   ispec->none_ok = none_ok ? TRUE : FALSE;
1042 
1043   return G_PARAM_SPEC (ispec);
1044 }
1045 
1046 GimpDrawable *
gimp_value_get_drawable(const GValue * value,Gimp * gimp)1047 gimp_value_get_drawable (const GValue *value,
1048                          Gimp         *gimp)
1049 {
1050   GimpItem *item;
1051 
1052   g_return_val_if_fail (GIMP_VALUE_HOLDS_DRAWABLE_ID (value), NULL);
1053   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1054 
1055   item = gimp_item_get_by_ID (gimp, value->data[0].v_int);
1056 
1057   if (item && ! GIMP_IS_DRAWABLE (item))
1058     return NULL;
1059 
1060   return GIMP_DRAWABLE (item);
1061 }
1062 
1063 void
gimp_value_set_drawable(GValue * value,GimpDrawable * drawable)1064 gimp_value_set_drawable (GValue       *value,
1065                          GimpDrawable *drawable)
1066 {
1067   g_return_if_fail (GIMP_VALUE_HOLDS_DRAWABLE_ID (value));
1068   g_return_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable));
1069 
1070   value->data[0].v_int = drawable ? gimp_item_get_ID (GIMP_ITEM (drawable)) : -1;
1071 }
1072 
1073 
1074 /*
1075  * GIMP_TYPE_LAYER_ID
1076  */
1077 
1078 GType
gimp_layer_id_get_type(void)1079 gimp_layer_id_get_type (void)
1080 {
1081   static GType type = 0;
1082 
1083   if (! type)
1084     {
1085       const GTypeInfo info = { 0, };
1086 
1087       type = g_type_register_static (G_TYPE_INT, "GimpLayerID", &info, 0);
1088     }
1089 
1090   return type;
1091 }
1092 
1093 
1094 /*
1095  * GIMP_TYPE_PARAM_LAYER_ID
1096  */
1097 
1098 static void   gimp_param_layer_id_class_init (GParamSpecClass *klass);
1099 static void   gimp_param_layer_id_init       (GParamSpec      *pspec);
1100 
1101 GType
gimp_param_layer_id_get_type(void)1102 gimp_param_layer_id_get_type (void)
1103 {
1104   static GType type = 0;
1105 
1106   if (! type)
1107     {
1108       const GTypeInfo info =
1109       {
1110         sizeof (GParamSpecClass),
1111         NULL, NULL,
1112         (GClassInitFunc) gimp_param_layer_id_class_init,
1113         NULL, NULL,
1114         sizeof (GimpParamSpecLayerID),
1115         0,
1116         (GInstanceInitFunc) gimp_param_layer_id_init
1117       };
1118 
1119       type = g_type_register_static (GIMP_TYPE_PARAM_DRAWABLE_ID,
1120                                      "GimpParamLayerID", &info, 0);
1121     }
1122 
1123   return type;
1124 }
1125 
1126 static void
gimp_param_layer_id_class_init(GParamSpecClass * klass)1127 gimp_param_layer_id_class_init (GParamSpecClass *klass)
1128 {
1129   klass->value_type = GIMP_TYPE_LAYER_ID;
1130 }
1131 
1132 static void
gimp_param_layer_id_init(GParamSpec * pspec)1133 gimp_param_layer_id_init (GParamSpec *pspec)
1134 {
1135   GimpParamSpecItemID *ispec = GIMP_PARAM_SPEC_ITEM_ID (pspec);
1136 
1137   ispec->item_type = GIMP_TYPE_LAYER;
1138 }
1139 
1140 GParamSpec *
gimp_param_spec_layer_id(const gchar * name,const gchar * nick,const gchar * blurb,Gimp * gimp,gboolean none_ok,GParamFlags flags)1141 gimp_param_spec_layer_id (const gchar *name,
1142                           const gchar *nick,
1143                           const gchar *blurb,
1144                           Gimp        *gimp,
1145                           gboolean     none_ok,
1146                           GParamFlags  flags)
1147 {
1148   GimpParamSpecItemID *ispec;
1149 
1150   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1151 
1152   ispec = g_param_spec_internal (GIMP_TYPE_PARAM_LAYER_ID,
1153                                  name, nick, blurb, flags);
1154 
1155   ispec->gimp    = gimp;
1156   ispec->none_ok = none_ok ? TRUE : FALSE;
1157 
1158   return G_PARAM_SPEC (ispec);
1159 }
1160 
1161 GimpLayer *
gimp_value_get_layer(const GValue * value,Gimp * gimp)1162 gimp_value_get_layer (const GValue *value,
1163                       Gimp         *gimp)
1164 {
1165   GimpItem *item;
1166 
1167   g_return_val_if_fail (GIMP_VALUE_HOLDS_LAYER_ID (value), NULL);
1168   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1169 
1170   item = gimp_item_get_by_ID (gimp, value->data[0].v_int);
1171 
1172   if (item && ! GIMP_IS_LAYER (item))
1173     return NULL;
1174 
1175   return GIMP_LAYER (item);
1176 }
1177 
1178 void
gimp_value_set_layer(GValue * value,GimpLayer * layer)1179 gimp_value_set_layer (GValue    *value,
1180                       GimpLayer *layer)
1181 {
1182   g_return_if_fail (GIMP_VALUE_HOLDS_LAYER_ID (value));
1183   g_return_if_fail (layer == NULL || GIMP_IS_LAYER (layer));
1184 
1185   value->data[0].v_int = layer ? gimp_item_get_ID (GIMP_ITEM (layer)) : -1;
1186 }
1187 
1188 
1189 /*
1190  * GIMP_TYPE_CHANNEL_ID
1191  */
1192 
1193 GType
gimp_channel_id_get_type(void)1194 gimp_channel_id_get_type (void)
1195 {
1196   static GType type = 0;
1197 
1198   if (! type)
1199     {
1200       const GTypeInfo info = { 0, };
1201 
1202       type = g_type_register_static (G_TYPE_INT, "GimpChannelID", &info, 0);
1203     }
1204 
1205   return type;
1206 }
1207 
1208 
1209 /*
1210  * GIMP_TYPE_PARAM_CHANNEL_ID
1211  */
1212 
1213 static void   gimp_param_channel_id_class_init (GParamSpecClass *klass);
1214 static void   gimp_param_channel_id_init       (GParamSpec      *pspec);
1215 
1216 GType
gimp_param_channel_id_get_type(void)1217 gimp_param_channel_id_get_type (void)
1218 {
1219   static GType type = 0;
1220 
1221   if (! type)
1222     {
1223       const GTypeInfo info =
1224       {
1225         sizeof (GParamSpecClass),
1226         NULL, NULL,
1227         (GClassInitFunc) gimp_param_channel_id_class_init,
1228         NULL, NULL,
1229         sizeof (GimpParamSpecChannelID),
1230         0,
1231         (GInstanceInitFunc) gimp_param_channel_id_init
1232       };
1233 
1234       type = g_type_register_static (GIMP_TYPE_PARAM_DRAWABLE_ID,
1235                                      "GimpParamChannelID", &info, 0);
1236     }
1237 
1238   return type;
1239 }
1240 
1241 static void
gimp_param_channel_id_class_init(GParamSpecClass * klass)1242 gimp_param_channel_id_class_init (GParamSpecClass *klass)
1243 {
1244   klass->value_type = GIMP_TYPE_CHANNEL_ID;
1245 }
1246 
1247 static void
gimp_param_channel_id_init(GParamSpec * pspec)1248 gimp_param_channel_id_init (GParamSpec *pspec)
1249 {
1250   GimpParamSpecItemID *ispec = GIMP_PARAM_SPEC_ITEM_ID (pspec);
1251 
1252   ispec->item_type = GIMP_TYPE_CHANNEL;
1253 }
1254 
1255 GParamSpec *
gimp_param_spec_channel_id(const gchar * name,const gchar * nick,const gchar * blurb,Gimp * gimp,gboolean none_ok,GParamFlags flags)1256 gimp_param_spec_channel_id (const gchar *name,
1257                             const gchar *nick,
1258                             const gchar *blurb,
1259                             Gimp        *gimp,
1260                             gboolean     none_ok,
1261                             GParamFlags  flags)
1262 {
1263   GimpParamSpecItemID *ispec;
1264 
1265   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1266 
1267   ispec = g_param_spec_internal (GIMP_TYPE_PARAM_CHANNEL_ID,
1268                                  name, nick, blurb, flags);
1269 
1270   ispec->gimp    = gimp;
1271   ispec->none_ok = none_ok ? TRUE : FALSE;
1272 
1273   return G_PARAM_SPEC (ispec);
1274 }
1275 
1276 GimpChannel *
gimp_value_get_channel(const GValue * value,Gimp * gimp)1277 gimp_value_get_channel (const GValue *value,
1278                         Gimp         *gimp)
1279 {
1280   GimpItem *item;
1281 
1282   g_return_val_if_fail (GIMP_VALUE_HOLDS_CHANNEL_ID (value), NULL);
1283   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1284 
1285   item = gimp_item_get_by_ID (gimp, value->data[0].v_int);
1286 
1287   if (item && ! GIMP_IS_CHANNEL (item))
1288     return NULL;
1289 
1290   return GIMP_CHANNEL (item);
1291 }
1292 
1293 void
gimp_value_set_channel(GValue * value,GimpChannel * channel)1294 gimp_value_set_channel (GValue      *value,
1295                         GimpChannel *channel)
1296 {
1297   g_return_if_fail (GIMP_VALUE_HOLDS_CHANNEL_ID (value));
1298   g_return_if_fail (channel == NULL || GIMP_IS_CHANNEL (channel));
1299 
1300   value->data[0].v_int = channel ? gimp_item_get_ID (GIMP_ITEM (channel)) : -1;
1301 }
1302 
1303 
1304 /*
1305  * GIMP_TYPE_LAYER_MASK_ID
1306  */
1307 
1308 GType
gimp_layer_mask_id_get_type(void)1309 gimp_layer_mask_id_get_type (void)
1310 {
1311   static GType type = 0;
1312 
1313   if (! type)
1314     {
1315       const GTypeInfo info = { 0, };
1316 
1317       type = g_type_register_static (G_TYPE_INT, "GimpLayerMaskID", &info, 0);
1318     }
1319 
1320   return type;
1321 }
1322 
1323 
1324 /*
1325  * GIMP_TYPE_PARAM_LAYER_MASK_ID
1326  */
1327 
1328 static void   gimp_param_layer_mask_id_class_init (GParamSpecClass *klass);
1329 static void   gimp_param_layer_mask_id_init       (GParamSpec      *pspec);
1330 
1331 GType
gimp_param_layer_mask_id_get_type(void)1332 gimp_param_layer_mask_id_get_type (void)
1333 {
1334   static GType type = 0;
1335 
1336   if (! type)
1337     {
1338       const GTypeInfo info =
1339       {
1340         sizeof (GParamSpecClass),
1341         NULL, NULL,
1342         (GClassInitFunc) gimp_param_layer_mask_id_class_init,
1343         NULL, NULL,
1344         sizeof (GimpParamSpecLayerMaskID),
1345         0,
1346         (GInstanceInitFunc) gimp_param_layer_mask_id_init
1347       };
1348 
1349       type = g_type_register_static (GIMP_TYPE_PARAM_CHANNEL_ID,
1350                                      "GimpParamLayerMaskID", &info, 0);
1351     }
1352 
1353   return type;
1354 }
1355 
1356 static void
gimp_param_layer_mask_id_class_init(GParamSpecClass * klass)1357 gimp_param_layer_mask_id_class_init (GParamSpecClass *klass)
1358 {
1359   klass->value_type = GIMP_TYPE_LAYER_MASK_ID;
1360 }
1361 
1362 static void
gimp_param_layer_mask_id_init(GParamSpec * pspec)1363 gimp_param_layer_mask_id_init (GParamSpec *pspec)
1364 {
1365   GimpParamSpecItemID *ispec = GIMP_PARAM_SPEC_ITEM_ID (pspec);
1366 
1367   ispec->item_type = GIMP_TYPE_LAYER_MASK;
1368 }
1369 
1370 GParamSpec *
gimp_param_spec_layer_mask_id(const gchar * name,const gchar * nick,const gchar * blurb,Gimp * gimp,gboolean none_ok,GParamFlags flags)1371 gimp_param_spec_layer_mask_id (const gchar *name,
1372                                const gchar *nick,
1373                                const gchar *blurb,
1374                                Gimp        *gimp,
1375                                gboolean     none_ok,
1376                                GParamFlags  flags)
1377 {
1378   GimpParamSpecItemID *ispec;
1379 
1380   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1381 
1382   ispec = g_param_spec_internal (GIMP_TYPE_PARAM_LAYER_MASK_ID,
1383                                  name, nick, blurb, flags);
1384 
1385   ispec->gimp    = gimp;
1386   ispec->none_ok = none_ok ? TRUE : FALSE;
1387 
1388   return G_PARAM_SPEC (ispec);
1389 }
1390 
1391 GimpLayerMask *
gimp_value_get_layer_mask(const GValue * value,Gimp * gimp)1392 gimp_value_get_layer_mask (const GValue *value,
1393                            Gimp         *gimp)
1394 {
1395   GimpItem *item;
1396 
1397   g_return_val_if_fail (GIMP_VALUE_HOLDS_LAYER_MASK_ID (value), NULL);
1398   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1399 
1400   item = gimp_item_get_by_ID (gimp, value->data[0].v_int);
1401 
1402   if (item && ! GIMP_IS_LAYER_MASK (item))
1403     return NULL;
1404 
1405   return GIMP_LAYER_MASK (item);
1406 }
1407 
1408 void
gimp_value_set_layer_mask(GValue * value,GimpLayerMask * layer_mask)1409 gimp_value_set_layer_mask (GValue        *value,
1410                            GimpLayerMask *layer_mask)
1411 {
1412   g_return_if_fail (GIMP_VALUE_HOLDS_LAYER_MASK_ID (value));
1413   g_return_if_fail (layer_mask == NULL || GIMP_IS_LAYER_MASK (layer_mask));
1414 
1415   value->data[0].v_int = layer_mask ? gimp_item_get_ID (GIMP_ITEM (layer_mask)) : -1;
1416 }
1417 
1418 
1419 /*
1420  * GIMP_TYPE_SELECTION_ID
1421  */
1422 
1423 GType
gimp_selection_id_get_type(void)1424 gimp_selection_id_get_type (void)
1425 {
1426   static GType type = 0;
1427 
1428   if (! type)
1429     {
1430       const GTypeInfo info = { 0, };
1431 
1432       type = g_type_register_static (G_TYPE_INT, "GimpSelectionID", &info, 0);
1433     }
1434 
1435   return type;
1436 }
1437 
1438 
1439 /*
1440  * GIMP_TYPE_PARAM_SELECTION_ID
1441  */
1442 
1443 static void   gimp_param_selection_id_class_init (GParamSpecClass *klass);
1444 static void   gimp_param_selection_id_init       (GParamSpec      *pspec);
1445 
1446 GType
gimp_param_selection_id_get_type(void)1447 gimp_param_selection_id_get_type (void)
1448 {
1449   static GType type = 0;
1450 
1451   if (! type)
1452     {
1453       const GTypeInfo info =
1454       {
1455         sizeof (GParamSpecClass),
1456         NULL, NULL,
1457         (GClassInitFunc) gimp_param_selection_id_class_init,
1458         NULL, NULL,
1459         sizeof (GimpParamSpecSelectionID),
1460         0,
1461         (GInstanceInitFunc) gimp_param_selection_id_init
1462       };
1463 
1464       type = g_type_register_static (GIMP_TYPE_PARAM_CHANNEL_ID,
1465                                      "GimpParamSelectionID", &info, 0);
1466     }
1467 
1468   return type;
1469 }
1470 
1471 static void
gimp_param_selection_id_class_init(GParamSpecClass * klass)1472 gimp_param_selection_id_class_init (GParamSpecClass *klass)
1473 {
1474   klass->value_type = GIMP_TYPE_SELECTION_ID;
1475 }
1476 
1477 static void
gimp_param_selection_id_init(GParamSpec * pspec)1478 gimp_param_selection_id_init (GParamSpec *pspec)
1479 {
1480   GimpParamSpecItemID *ispec = GIMP_PARAM_SPEC_ITEM_ID (pspec);
1481 
1482   ispec->item_type = GIMP_TYPE_SELECTION;
1483 }
1484 
1485 GParamSpec *
gimp_param_spec_selection_id(const gchar * name,const gchar * nick,const gchar * blurb,Gimp * gimp,gboolean none_ok,GParamFlags flags)1486 gimp_param_spec_selection_id (const gchar *name,
1487                               const gchar *nick,
1488                               const gchar *blurb,
1489                               Gimp        *gimp,
1490                               gboolean     none_ok,
1491                               GParamFlags  flags)
1492 {
1493   GimpParamSpecItemID *ispec;
1494 
1495   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1496 
1497   ispec = g_param_spec_internal (GIMP_TYPE_PARAM_SELECTION_ID,
1498                                  name, nick, blurb, flags);
1499 
1500   ispec->gimp    = gimp;
1501   ispec->none_ok = none_ok ? TRUE : FALSE;
1502 
1503   return G_PARAM_SPEC (ispec);
1504 }
1505 
1506 GimpSelection *
gimp_value_get_selection(const GValue * value,Gimp * gimp)1507 gimp_value_get_selection (const GValue *value,
1508                           Gimp         *gimp)
1509 {
1510   GimpItem *item;
1511 
1512   g_return_val_if_fail (GIMP_VALUE_HOLDS_SELECTION_ID (value), NULL);
1513   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1514 
1515   item = gimp_item_get_by_ID (gimp, value->data[0].v_int);
1516 
1517   if (item && ! GIMP_IS_SELECTION (item))
1518     return NULL;
1519 
1520   return GIMP_SELECTION (item);
1521 }
1522 
1523 void
gimp_value_set_selection(GValue * value,GimpSelection * selection)1524 gimp_value_set_selection (GValue        *value,
1525                           GimpSelection *selection)
1526 {
1527   g_return_if_fail (GIMP_VALUE_HOLDS_SELECTION_ID (value));
1528   g_return_if_fail (selection == NULL || GIMP_IS_SELECTION (selection));
1529 
1530   value->data[0].v_int = selection ? gimp_item_get_ID (GIMP_ITEM (selection)) : -1;
1531 }
1532 
1533 
1534 /*
1535  * GIMP_TYPE_VECTORS_ID
1536  */
1537 
1538 GType
gimp_vectors_id_get_type(void)1539 gimp_vectors_id_get_type (void)
1540 {
1541   static GType type = 0;
1542 
1543   if (! type)
1544     {
1545       const GTypeInfo info = { 0, };
1546 
1547       type = g_type_register_static (G_TYPE_INT, "GimpVectorsID", &info, 0);
1548     }
1549 
1550   return type;
1551 }
1552 
1553 
1554 /*
1555  * GIMP_TYPE_PARAM_VECTORS_ID
1556  */
1557 
1558 static void   gimp_param_vectors_id_class_init (GParamSpecClass *klass);
1559 static void   gimp_param_vectors_id_init       (GParamSpec      *pspec);
1560 
1561 GType
gimp_param_vectors_id_get_type(void)1562 gimp_param_vectors_id_get_type (void)
1563 {
1564   static GType type = 0;
1565 
1566   if (! type)
1567     {
1568       const GTypeInfo info =
1569       {
1570         sizeof (GParamSpecClass),
1571         NULL, NULL,
1572         (GClassInitFunc) gimp_param_vectors_id_class_init,
1573         NULL, NULL,
1574         sizeof (GimpParamSpecVectorsID),
1575         0,
1576         (GInstanceInitFunc) gimp_param_vectors_id_init
1577       };
1578 
1579       type = g_type_register_static (GIMP_TYPE_PARAM_ITEM_ID,
1580                                      "GimpParamVectorsID", &info, 0);
1581     }
1582 
1583   return type;
1584 }
1585 
1586 static void
gimp_param_vectors_id_class_init(GParamSpecClass * klass)1587 gimp_param_vectors_id_class_init (GParamSpecClass *klass)
1588 {
1589   klass->value_type = GIMP_TYPE_VECTORS_ID;
1590 }
1591 
1592 static void
gimp_param_vectors_id_init(GParamSpec * pspec)1593 gimp_param_vectors_id_init (GParamSpec *pspec)
1594 {
1595   GimpParamSpecItemID *ispec = GIMP_PARAM_SPEC_ITEM_ID (pspec);
1596 
1597   ispec->item_type = GIMP_TYPE_VECTORS;
1598 }
1599 
1600 GParamSpec *
gimp_param_spec_vectors_id(const gchar * name,const gchar * nick,const gchar * blurb,Gimp * gimp,gboolean none_ok,GParamFlags flags)1601 gimp_param_spec_vectors_id (const gchar *name,
1602                             const gchar *nick,
1603                             const gchar *blurb,
1604                             Gimp        *gimp,
1605                             gboolean     none_ok,
1606                             GParamFlags  flags)
1607 {
1608   GimpParamSpecItemID *ispec;
1609 
1610   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1611 
1612   ispec = g_param_spec_internal (GIMP_TYPE_PARAM_VECTORS_ID,
1613                                  name, nick, blurb, flags);
1614 
1615   ispec->gimp    = gimp;
1616   ispec->none_ok = none_ok ? TRUE : FALSE;
1617 
1618   return G_PARAM_SPEC (ispec);
1619 }
1620 
1621 GimpVectors *
gimp_value_get_vectors(const GValue * value,Gimp * gimp)1622 gimp_value_get_vectors (const GValue *value,
1623                         Gimp         *gimp)
1624 {
1625   GimpItem *item;
1626 
1627   g_return_val_if_fail (GIMP_VALUE_HOLDS_VECTORS_ID (value), NULL);
1628   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1629 
1630   item = gimp_item_get_by_ID (gimp, value->data[0].v_int);
1631 
1632   if (item && ! GIMP_IS_VECTORS (item))
1633     return NULL;
1634 
1635   return GIMP_VECTORS (item);
1636 }
1637 
1638 void
gimp_value_set_vectors(GValue * value,GimpVectors * vectors)1639 gimp_value_set_vectors (GValue      *value,
1640                         GimpVectors *vectors)
1641 {
1642   g_return_if_fail (GIMP_VALUE_HOLDS_VECTORS_ID (value));
1643   g_return_if_fail (vectors == NULL || GIMP_IS_VECTORS (vectors));
1644 
1645   value->data[0].v_int = vectors ? gimp_item_get_ID (GIMP_ITEM (vectors)) : -1;
1646 }
1647 
1648 
1649 /*
1650  * GIMP_TYPE_DISPLAY_ID
1651  */
1652 
1653 GType
gimp_display_id_get_type(void)1654 gimp_display_id_get_type (void)
1655 {
1656   static GType type = 0;
1657 
1658   if (! type)
1659     {
1660       const GTypeInfo info = { 0, };
1661 
1662       type = g_type_register_static (G_TYPE_INT, "GimpDisplayID", &info, 0);
1663     }
1664 
1665   return type;
1666 }
1667 
1668 
1669 /*
1670  * GIMP_TYPE_PARAM_DISPLAY_ID
1671  */
1672 
1673 static void       gimp_param_display_id_class_init  (GParamSpecClass *klass);
1674 static void       gimp_param_display_id_init        (GParamSpec      *pspec);
1675 static void       gimp_param_display_id_set_default (GParamSpec      *pspec,
1676                                                      GValue          *value);
1677 static gboolean   gimp_param_display_id_validate    (GParamSpec      *pspec,
1678                                                      GValue          *value);
1679 static gint       gimp_param_display_id_values_cmp  (GParamSpec      *pspec,
1680                                                      const GValue    *value1,
1681                                                      const GValue    *value2);
1682 
1683 GType
gimp_param_display_id_get_type(void)1684 gimp_param_display_id_get_type (void)
1685 {
1686   static GType type = 0;
1687 
1688   if (! type)
1689     {
1690       const GTypeInfo info =
1691       {
1692         sizeof (GParamSpecClass),
1693         NULL, NULL,
1694         (GClassInitFunc) gimp_param_display_id_class_init,
1695         NULL, NULL,
1696         sizeof (GimpParamSpecDisplayID),
1697         0,
1698         (GInstanceInitFunc) gimp_param_display_id_init
1699       };
1700 
1701       type = g_type_register_static (G_TYPE_PARAM_INT,
1702                                      "GimpParamDisplayID", &info, 0);
1703     }
1704 
1705   return type;
1706 }
1707 
1708 static void
gimp_param_display_id_class_init(GParamSpecClass * klass)1709 gimp_param_display_id_class_init (GParamSpecClass *klass)
1710 {
1711   klass->value_type        = GIMP_TYPE_DISPLAY_ID;
1712   klass->value_set_default = gimp_param_display_id_set_default;
1713   klass->value_validate    = gimp_param_display_id_validate;
1714   klass->values_cmp        = gimp_param_display_id_values_cmp;
1715 }
1716 
1717 static void
gimp_param_display_id_init(GParamSpec * pspec)1718 gimp_param_display_id_init (GParamSpec *pspec)
1719 {
1720   GimpParamSpecDisplayID *ispec = GIMP_PARAM_SPEC_DISPLAY_ID (pspec);
1721 
1722   ispec->gimp    = NULL;
1723   ispec->none_ok = FALSE;
1724 }
1725 
1726 static void
gimp_param_display_id_set_default(GParamSpec * pspec,GValue * value)1727 gimp_param_display_id_set_default (GParamSpec *pspec,
1728                                    GValue     *value)
1729 {
1730   value->data[0].v_int = -1;
1731 }
1732 
1733 static gboolean
gimp_param_display_id_validate(GParamSpec * pspec,GValue * value)1734 gimp_param_display_id_validate (GParamSpec *pspec,
1735                                 GValue     *value)
1736 {
1737   GimpParamSpecDisplayID *ispec      = GIMP_PARAM_SPEC_DISPLAY_ID (pspec);
1738   gint                    display_id = value->data[0].v_int;
1739   GimpObject             *display;
1740 
1741   if (ispec->none_ok && (display_id == 0 || display_id == -1))
1742     return FALSE;
1743 
1744   display = gimp_get_display_by_ID (ispec->gimp, display_id);
1745 
1746   if (! GIMP_IS_OBJECT (display))
1747     {
1748       value->data[0].v_int = -1;
1749       return TRUE;
1750     }
1751 
1752   return FALSE;
1753 }
1754 
1755 static gint
gimp_param_display_id_values_cmp(GParamSpec * pspec,const GValue * value1,const GValue * value2)1756 gimp_param_display_id_values_cmp (GParamSpec   *pspec,
1757                                   const GValue *value1,
1758                                   const GValue *value2)
1759 {
1760   gint display_id1 = value1->data[0].v_int;
1761   gint display_id2 = value2->data[0].v_int;
1762 
1763   /*  try to return at least *something*, it's useless anyway...  */
1764 
1765   if (display_id1 < display_id2)
1766     return -1;
1767   else if (display_id1 > display_id2)
1768     return 1;
1769   else
1770     return 0;
1771 }
1772 
1773 GParamSpec *
gimp_param_spec_display_id(const gchar * name,const gchar * nick,const gchar * blurb,Gimp * gimp,gboolean none_ok,GParamFlags flags)1774 gimp_param_spec_display_id (const gchar *name,
1775                             const gchar *nick,
1776                             const gchar *blurb,
1777                             Gimp        *gimp,
1778                             gboolean     none_ok,
1779                             GParamFlags  flags)
1780 {
1781   GimpParamSpecDisplayID *ispec;
1782 
1783   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1784 
1785   ispec = g_param_spec_internal (GIMP_TYPE_PARAM_DISPLAY_ID,
1786                                  name, nick, blurb, flags);
1787 
1788   ispec->gimp    = gimp;
1789   ispec->none_ok = none_ok ? TRUE : FALSE;
1790 
1791   return G_PARAM_SPEC (ispec);
1792 }
1793 
1794 GimpObject *
gimp_value_get_display(const GValue * value,Gimp * gimp)1795 gimp_value_get_display (const GValue *value,
1796                         Gimp         *gimp)
1797 {
1798   g_return_val_if_fail (GIMP_VALUE_HOLDS_DISPLAY_ID (value), NULL);
1799   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
1800 
1801   return gimp_get_display_by_ID (gimp, value->data[0].v_int);
1802 }
1803 
1804 void
gimp_value_set_display(GValue * value,GimpObject * display)1805 gimp_value_set_display (GValue     *value,
1806                         GimpObject *display)
1807 {
1808   gint id = -1;
1809 
1810   g_return_if_fail (GIMP_VALUE_HOLDS_DISPLAY_ID (value));
1811   g_return_if_fail (display == NULL || GIMP_IS_OBJECT (display));
1812 
1813   if (display)
1814     g_object_get (display, "id", &id, NULL);
1815 
1816   value->data[0].v_int = id;
1817 }
1818 
1819 
1820 /*
1821  * GIMP_TYPE_ARRAY
1822  */
1823 
1824 GimpArray *
gimp_array_new(const guint8 * data,gsize length,gboolean static_data)1825 gimp_array_new (const guint8 *data,
1826                 gsize         length,
1827                 gboolean      static_data)
1828 {
1829   GimpArray *array;
1830 
1831   g_return_val_if_fail ((data == NULL && length == 0) ||
1832                         (data != NULL && length  > 0), NULL);
1833 
1834   array = g_slice_new0 (GimpArray);
1835 
1836   array->data        = static_data ? (guint8 *) data : g_memdup (data, length);
1837   array->length      = length;
1838   array->static_data = static_data;
1839 
1840   return array;
1841 }
1842 
1843 GimpArray *
gimp_array_copy(const GimpArray * array)1844 gimp_array_copy (const GimpArray *array)
1845 {
1846   if (array)
1847     return gimp_array_new (array->data, array->length, FALSE);
1848 
1849   return NULL;
1850 }
1851 
1852 void
gimp_array_free(GimpArray * array)1853 gimp_array_free (GimpArray *array)
1854 {
1855   if (array)
1856     {
1857       if (! array->static_data)
1858         g_free (array->data);
1859 
1860       g_slice_free (GimpArray, array);
1861     }
1862 }
1863 
1864 GType
gimp_array_get_type(void)1865 gimp_array_get_type (void)
1866 {
1867   static GType type = 0;
1868 
1869   if (! type)
1870     type = g_boxed_type_register_static ("GimpArray",
1871                                          (GBoxedCopyFunc) gimp_array_copy,
1872                                          (GBoxedFreeFunc) gimp_array_free);
1873 
1874   return type;
1875 }
1876 
1877 
1878 /*
1879  * GIMP_TYPE_PARAM_ARRAY
1880  */
1881 
1882 static void       gimp_param_array_class_init  (GParamSpecClass *klass);
1883 static void       gimp_param_array_init        (GParamSpec      *pspec);
1884 static gboolean   gimp_param_array_validate    (GParamSpec      *pspec,
1885                                                 GValue          *value);
1886 static gint       gimp_param_array_values_cmp  (GParamSpec      *pspec,
1887                                                 const GValue    *value1,
1888                                                 const GValue    *value2);
1889 
1890 GType
gimp_param_array_get_type(void)1891 gimp_param_array_get_type (void)
1892 {
1893   static GType type = 0;
1894 
1895   if (! type)
1896     {
1897       const GTypeInfo info =
1898       {
1899         sizeof (GParamSpecClass),
1900         NULL, NULL,
1901         (GClassInitFunc) gimp_param_array_class_init,
1902         NULL, NULL,
1903         sizeof (GimpParamSpecArray),
1904         0,
1905         (GInstanceInitFunc) gimp_param_array_init
1906       };
1907 
1908       type = g_type_register_static (G_TYPE_PARAM_BOXED,
1909                                      "GimpParamArray", &info, 0);
1910     }
1911 
1912   return type;
1913 }
1914 
1915 static void
gimp_param_array_class_init(GParamSpecClass * klass)1916 gimp_param_array_class_init (GParamSpecClass *klass)
1917 {
1918   klass->value_type     = GIMP_TYPE_ARRAY;
1919   klass->value_validate = gimp_param_array_validate;
1920   klass->values_cmp     = gimp_param_array_values_cmp;
1921 }
1922 
1923 static void
gimp_param_array_init(GParamSpec * pspec)1924 gimp_param_array_init (GParamSpec *pspec)
1925 {
1926 }
1927 
1928 static gboolean
gimp_param_array_validate(GParamSpec * pspec,GValue * value)1929 gimp_param_array_validate (GParamSpec *pspec,
1930                            GValue     *value)
1931 {
1932   GimpArray *array = value->data[0].v_pointer;
1933 
1934   if (array)
1935     {
1936       if ((array->data == NULL && array->length != 0) ||
1937           (array->data != NULL && array->length == 0))
1938         {
1939           g_value_set_boxed (value, NULL);
1940           return TRUE;
1941         }
1942     }
1943 
1944   return FALSE;
1945 }
1946 
1947 static gint
gimp_param_array_values_cmp(GParamSpec * pspec,const GValue * value1,const GValue * value2)1948 gimp_param_array_values_cmp (GParamSpec   *pspec,
1949                              const GValue *value1,
1950                              const GValue *value2)
1951 {
1952   GimpArray *array1 = value1->data[0].v_pointer;
1953   GimpArray *array2 = value2->data[0].v_pointer;
1954 
1955   /*  try to return at least *something*, it's useless anyway...  */
1956 
1957   if (! array1)
1958     return array2 != NULL ? -1 : 0;
1959   else if (! array2)
1960     return array1 != NULL ? 1 : 0;
1961   else if (array1->length < array2->length)
1962     return -1;
1963   else if (array1->length > array2->length)
1964     return 1;
1965 
1966   return 0;
1967 }
1968 
1969 GParamSpec *
gimp_param_spec_array(const gchar * name,const gchar * nick,const gchar * blurb,GParamFlags flags)1970 gimp_param_spec_array (const gchar *name,
1971                        const gchar *nick,
1972                        const gchar *blurb,
1973                        GParamFlags  flags)
1974 {
1975   GimpParamSpecArray *array_spec;
1976 
1977   array_spec = g_param_spec_internal (GIMP_TYPE_PARAM_ARRAY,
1978                                       name, nick, blurb, flags);
1979 
1980   return G_PARAM_SPEC (array_spec);
1981 }
1982 
1983 static const guint8 *
gimp_value_get_array(const GValue * value)1984 gimp_value_get_array (const GValue *value)
1985 {
1986   GimpArray *array = value->data[0].v_pointer;
1987 
1988   if (array)
1989     return array->data;
1990 
1991   return NULL;
1992 }
1993 
1994 static guint8 *
gimp_value_dup_array(const GValue * value)1995 gimp_value_dup_array (const GValue *value)
1996 {
1997   GimpArray *array = value->data[0].v_pointer;
1998 
1999   if (array)
2000     return g_memdup (array->data, array->length);
2001 
2002   return NULL;
2003 }
2004 
2005 static void
gimp_value_set_array(GValue * value,const guint8 * data,gsize length)2006 gimp_value_set_array (GValue       *value,
2007                       const guint8 *data,
2008                       gsize         length)
2009 {
2010   GimpArray *array = gimp_array_new (data, length, FALSE);
2011 
2012   g_value_take_boxed (value, array);
2013 }
2014 
2015 static void
gimp_value_set_static_array(GValue * value,const guint8 * data,gsize length)2016 gimp_value_set_static_array (GValue       *value,
2017                              const guint8 *data,
2018                              gsize         length)
2019 {
2020   GimpArray *array = gimp_array_new (data, length, TRUE);
2021 
2022   g_value_take_boxed (value, array);
2023 }
2024 
2025 static void
gimp_value_take_array(GValue * value,guint8 * data,gsize length)2026 gimp_value_take_array (GValue *value,
2027                        guint8 *data,
2028                        gsize   length)
2029 {
2030   GimpArray *array = gimp_array_new (data, length, TRUE);
2031 
2032   array->static_data = FALSE;
2033 
2034   g_value_take_boxed (value, array);
2035 }
2036 
2037 
2038 /*
2039  * GIMP_TYPE_INT8_ARRAY
2040  */
2041 
2042 GType
gimp_int8_array_get_type(void)2043 gimp_int8_array_get_type (void)
2044 {
2045   static GType type = 0;
2046 
2047   if (! type)
2048     type = g_boxed_type_register_static ("GimpInt8Array",
2049                                          (GBoxedCopyFunc) gimp_array_copy,
2050                                          (GBoxedFreeFunc) gimp_array_free);
2051 
2052   return type;
2053 }
2054 
2055 
2056 /*
2057  * GIMP_TYPE_PARAM_INT8_ARRAY
2058  */
2059 
2060 static void   gimp_param_int8_array_class_init (GParamSpecClass *klass);
2061 static void   gimp_param_int8_array_init       (GParamSpec      *pspec);
2062 
2063 GType
gimp_param_int8_array_get_type(void)2064 gimp_param_int8_array_get_type (void)
2065 {
2066   static GType type = 0;
2067 
2068   if (! type)
2069     {
2070       const GTypeInfo info =
2071       {
2072         sizeof (GParamSpecClass),
2073         NULL, NULL,
2074         (GClassInitFunc) gimp_param_int8_array_class_init,
2075         NULL, NULL,
2076         sizeof (GimpParamSpecArray),
2077         0,
2078         (GInstanceInitFunc) gimp_param_int8_array_init
2079       };
2080 
2081       type = g_type_register_static (GIMP_TYPE_PARAM_ARRAY,
2082                                      "GimpParamInt8Array", &info, 0);
2083     }
2084 
2085   return type;
2086 }
2087 
2088 static void
gimp_param_int8_array_class_init(GParamSpecClass * klass)2089 gimp_param_int8_array_class_init (GParamSpecClass *klass)
2090 {
2091   klass->value_type = GIMP_TYPE_INT8_ARRAY;
2092 }
2093 
2094 static void
gimp_param_int8_array_init(GParamSpec * pspec)2095 gimp_param_int8_array_init (GParamSpec *pspec)
2096 {
2097 }
2098 
2099 GParamSpec *
gimp_param_spec_int8_array(const gchar * name,const gchar * nick,const gchar * blurb,GParamFlags flags)2100 gimp_param_spec_int8_array (const gchar *name,
2101                             const gchar *nick,
2102                             const gchar *blurb,
2103                             GParamFlags  flags)
2104 {
2105   GimpParamSpecArray *array_spec;
2106 
2107   array_spec = g_param_spec_internal (GIMP_TYPE_PARAM_INT8_ARRAY,
2108                                       name, nick, blurb, flags);
2109 
2110   return G_PARAM_SPEC (array_spec);
2111 }
2112 
2113 const guint8 *
gimp_value_get_int8array(const GValue * value)2114 gimp_value_get_int8array (const GValue *value)
2115 {
2116   g_return_val_if_fail (GIMP_VALUE_HOLDS_INT8_ARRAY (value), NULL);
2117 
2118   return gimp_value_get_array (value);
2119 }
2120 
2121 guint8 *
gimp_value_dup_int8array(const GValue * value)2122 gimp_value_dup_int8array (const GValue *value)
2123 {
2124   g_return_val_if_fail (GIMP_VALUE_HOLDS_INT8_ARRAY (value), NULL);
2125 
2126   return gimp_value_dup_array (value);
2127 }
2128 
2129 void
gimp_value_set_int8array(GValue * value,const guint8 * data,gsize length)2130 gimp_value_set_int8array (GValue       *value,
2131                           const guint8 *data,
2132                           gsize         length)
2133 {
2134   g_return_if_fail (GIMP_VALUE_HOLDS_INT8_ARRAY (value));
2135 
2136   gimp_value_set_array (value, data, length);
2137 }
2138 
2139 void
gimp_value_set_static_int8array(GValue * value,const guint8 * data,gsize length)2140 gimp_value_set_static_int8array (GValue       *value,
2141                                  const guint8 *data,
2142                                  gsize         length)
2143 {
2144   g_return_if_fail (GIMP_VALUE_HOLDS_INT8_ARRAY (value));
2145 
2146   gimp_value_set_static_array (value, data, length);
2147 }
2148 
2149 void
gimp_value_take_int8array(GValue * value,guint8 * data,gsize length)2150 gimp_value_take_int8array (GValue *value,
2151                            guint8 *data,
2152                            gsize   length)
2153 {
2154   g_return_if_fail (GIMP_VALUE_HOLDS_INT8_ARRAY (value));
2155 
2156   gimp_value_take_array (value, data, length);
2157 }
2158 
2159 
2160 /*
2161  * GIMP_TYPE_INT16_ARRAY
2162  */
2163 
2164 GType
gimp_int16_array_get_type(void)2165 gimp_int16_array_get_type (void)
2166 {
2167   static GType type = 0;
2168 
2169   if (! type)
2170     type = g_boxed_type_register_static ("GimpInt16Array",
2171                                          (GBoxedCopyFunc) gimp_array_copy,
2172                                          (GBoxedFreeFunc) gimp_array_free);
2173 
2174   return type;
2175 }
2176 
2177 
2178 /*
2179  * GIMP_TYPE_PARAM_INT16_ARRAY
2180  */
2181 
2182 static void   gimp_param_int16_array_class_init (GParamSpecClass *klass);
2183 static void   gimp_param_int16_array_init       (GParamSpec      *pspec);
2184 
2185 GType
gimp_param_int16_array_get_type(void)2186 gimp_param_int16_array_get_type (void)
2187 {
2188   static GType type = 0;
2189 
2190   if (! type)
2191     {
2192       const GTypeInfo info =
2193       {
2194         sizeof (GParamSpecClass),
2195         NULL, NULL,
2196         (GClassInitFunc) gimp_param_int16_array_class_init,
2197         NULL, NULL,
2198         sizeof (GimpParamSpecArray),
2199         0,
2200         (GInstanceInitFunc) gimp_param_int16_array_init
2201       };
2202 
2203       type = g_type_register_static (GIMP_TYPE_PARAM_ARRAY,
2204                                      "GimpParamInt16Array", &info, 0);
2205     }
2206 
2207   return type;
2208 }
2209 
2210 static void
gimp_param_int16_array_class_init(GParamSpecClass * klass)2211 gimp_param_int16_array_class_init (GParamSpecClass *klass)
2212 {
2213   klass->value_type = GIMP_TYPE_INT16_ARRAY;
2214 }
2215 
2216 static void
gimp_param_int16_array_init(GParamSpec * pspec)2217 gimp_param_int16_array_init (GParamSpec *pspec)
2218 {
2219 }
2220 
2221 GParamSpec *
gimp_param_spec_int16_array(const gchar * name,const gchar * nick,const gchar * blurb,GParamFlags flags)2222 gimp_param_spec_int16_array (const gchar *name,
2223                              const gchar *nick,
2224                              const gchar *blurb,
2225                              GParamFlags  flags)
2226 {
2227   GimpParamSpecArray *array_spec;
2228 
2229   array_spec = g_param_spec_internal (GIMP_TYPE_PARAM_INT16_ARRAY,
2230                                       name, nick, blurb, flags);
2231 
2232   return G_PARAM_SPEC (array_spec);
2233 }
2234 
2235 const gint16 *
gimp_value_get_int16array(const GValue * value)2236 gimp_value_get_int16array (const GValue *value)
2237 {
2238   g_return_val_if_fail (GIMP_VALUE_HOLDS_INT16_ARRAY (value), NULL);
2239 
2240   return (const gint16 *) gimp_value_get_array (value);
2241 }
2242 
2243 gint16 *
gimp_value_dup_int16array(const GValue * value)2244 gimp_value_dup_int16array (const GValue *value)
2245 {
2246   g_return_val_if_fail (GIMP_VALUE_HOLDS_INT16_ARRAY (value), NULL);
2247 
2248   return (gint16 *) gimp_value_dup_array (value);
2249 }
2250 
2251 void
gimp_value_set_int16array(GValue * value,const gint16 * data,gsize length)2252 gimp_value_set_int16array (GValue       *value,
2253                            const gint16 *data,
2254                            gsize         length)
2255 {
2256   g_return_if_fail (GIMP_VALUE_HOLDS_INT16_ARRAY (value));
2257 
2258   gimp_value_set_array (value, (const guint8 *) data,
2259                         length * sizeof (gint16));
2260 }
2261 
2262 void
gimp_value_set_static_int16array(GValue * value,const gint16 * data,gsize length)2263 gimp_value_set_static_int16array (GValue       *value,
2264                                   const gint16 *data,
2265                                   gsize         length)
2266 {
2267   g_return_if_fail (GIMP_VALUE_HOLDS_INT16_ARRAY (value));
2268 
2269   gimp_value_set_static_array (value, (const guint8 *) data,
2270                                length * sizeof (gint16));
2271 }
2272 
2273 void
gimp_value_take_int16array(GValue * value,gint16 * data,gsize length)2274 gimp_value_take_int16array (GValue *value,
2275                             gint16 *data,
2276                             gsize   length)
2277 {
2278   g_return_if_fail (GIMP_VALUE_HOLDS_INT16_ARRAY (value));
2279 
2280   gimp_value_take_array (value, (guint8 *) data,
2281                          length * sizeof (gint16));
2282 }
2283 
2284 
2285 /*
2286  * GIMP_TYPE_INT32_ARRAY
2287  */
2288 
2289 GType
gimp_int32_array_get_type(void)2290 gimp_int32_array_get_type (void)
2291 {
2292   static GType type = 0;
2293 
2294   if (! type)
2295     type = g_boxed_type_register_static ("GimpInt32Array",
2296                                          (GBoxedCopyFunc) gimp_array_copy,
2297                                          (GBoxedFreeFunc) gimp_array_free);
2298 
2299   return type;
2300 }
2301 
2302 
2303 /*
2304  * GIMP_TYPE_PARAM_INT32_ARRAY
2305  */
2306 
2307 static void   gimp_param_int32_array_class_init (GParamSpecClass *klass);
2308 static void   gimp_param_int32_array_init       (GParamSpec      *pspec);
2309 
2310 GType
gimp_param_int32_array_get_type(void)2311 gimp_param_int32_array_get_type (void)
2312 {
2313   static GType type = 0;
2314 
2315   if (! type)
2316     {
2317       const GTypeInfo info =
2318       {
2319         sizeof (GParamSpecClass),
2320         NULL, NULL,
2321         (GClassInitFunc) gimp_param_int32_array_class_init,
2322         NULL, NULL,
2323         sizeof (GimpParamSpecArray),
2324         0,
2325         (GInstanceInitFunc) gimp_param_int32_array_init
2326       };
2327 
2328       type = g_type_register_static (GIMP_TYPE_PARAM_ARRAY,
2329                                      "GimpParamInt32Array", &info, 0);
2330     }
2331 
2332   return type;
2333 }
2334 
2335 static void
gimp_param_int32_array_class_init(GParamSpecClass * klass)2336 gimp_param_int32_array_class_init (GParamSpecClass *klass)
2337 {
2338   klass->value_type = GIMP_TYPE_INT32_ARRAY;
2339 }
2340 
2341 static void
gimp_param_int32_array_init(GParamSpec * pspec)2342 gimp_param_int32_array_init (GParamSpec *pspec)
2343 {
2344 }
2345 
2346 GParamSpec *
gimp_param_spec_int32_array(const gchar * name,const gchar * nick,const gchar * blurb,GParamFlags flags)2347 gimp_param_spec_int32_array (const gchar *name,
2348                              const gchar *nick,
2349                              const gchar *blurb,
2350                              GParamFlags  flags)
2351 {
2352   GimpParamSpecArray *array_spec;
2353 
2354   array_spec = g_param_spec_internal (GIMP_TYPE_PARAM_INT32_ARRAY,
2355                                       name, nick, blurb, flags);
2356 
2357   return G_PARAM_SPEC (array_spec);
2358 }
2359 
2360 const gint32 *
gimp_value_get_int32array(const GValue * value)2361 gimp_value_get_int32array (const GValue *value)
2362 {
2363   g_return_val_if_fail (GIMP_VALUE_HOLDS_INT32_ARRAY (value), NULL);
2364 
2365   return (const gint32 *) gimp_value_get_array (value);
2366 }
2367 
2368 gint32 *
gimp_value_dup_int32array(const GValue * value)2369 gimp_value_dup_int32array (const GValue *value)
2370 {
2371   g_return_val_if_fail (GIMP_VALUE_HOLDS_INT32_ARRAY (value), NULL);
2372 
2373   return (gint32 *) gimp_value_dup_array (value);
2374 }
2375 
2376 void
gimp_value_set_int32array(GValue * value,const gint32 * data,gsize length)2377 gimp_value_set_int32array (GValue       *value,
2378                            const gint32 *data,
2379                            gsize         length)
2380 {
2381   g_return_if_fail (GIMP_VALUE_HOLDS_INT32_ARRAY (value));
2382 
2383   gimp_value_set_array (value, (const guint8 *) data,
2384                         length * sizeof (gint32));
2385 }
2386 
2387 void
gimp_value_set_static_int32array(GValue * value,const gint32 * data,gsize length)2388 gimp_value_set_static_int32array (GValue       *value,
2389                                   const gint32 *data,
2390                                   gsize         length)
2391 {
2392   g_return_if_fail (GIMP_VALUE_HOLDS_INT32_ARRAY (value));
2393 
2394   gimp_value_set_static_array (value, (const guint8 *) data,
2395                                length * sizeof (gint32));
2396 }
2397 
2398 void
gimp_value_take_int32array(GValue * value,gint32 * data,gsize length)2399 gimp_value_take_int32array (GValue *value,
2400                             gint32 *data,
2401                             gsize   length)
2402 {
2403   g_return_if_fail (GIMP_VALUE_HOLDS_INT32_ARRAY (value));
2404 
2405   gimp_value_take_array (value, (guint8 *) data,
2406                          length * sizeof (gint32));
2407 }
2408 
2409 
2410 /*
2411  * GIMP_TYPE_FLOAT_ARRAY
2412  */
2413 
2414 GType
gimp_float_array_get_type(void)2415 gimp_float_array_get_type (void)
2416 {
2417   static GType type = 0;
2418 
2419   if (! type)
2420     type = g_boxed_type_register_static ("GimpFloatArray",
2421                                          (GBoxedCopyFunc) gimp_array_copy,
2422                                          (GBoxedFreeFunc) gimp_array_free);
2423 
2424   return type;
2425 }
2426 
2427 
2428 /*
2429  * GIMP_TYPE_PARAM_FLOAT_ARRAY
2430  */
2431 
2432 static void   gimp_param_float_array_class_init (GParamSpecClass *klass);
2433 static void   gimp_param_float_array_init       (GParamSpec      *pspec);
2434 
2435 GType
gimp_param_float_array_get_type(void)2436 gimp_param_float_array_get_type (void)
2437 {
2438   static GType type = 0;
2439 
2440   if (! type)
2441     {
2442       const GTypeInfo info =
2443       {
2444         sizeof (GParamSpecClass),
2445         NULL, NULL,
2446         (GClassInitFunc) gimp_param_float_array_class_init,
2447         NULL, NULL,
2448         sizeof (GimpParamSpecArray),
2449         0,
2450         (GInstanceInitFunc) gimp_param_float_array_init
2451       };
2452 
2453       type = g_type_register_static (GIMP_TYPE_PARAM_ARRAY,
2454                                      "GimpParamFloatArray", &info, 0);
2455     }
2456 
2457   return type;
2458 }
2459 
2460 static void
gimp_param_float_array_class_init(GParamSpecClass * klass)2461 gimp_param_float_array_class_init (GParamSpecClass *klass)
2462 {
2463   klass->value_type = GIMP_TYPE_FLOAT_ARRAY;
2464 }
2465 
2466 static void
gimp_param_float_array_init(GParamSpec * pspec)2467 gimp_param_float_array_init (GParamSpec *pspec)
2468 {
2469 }
2470 
2471 GParamSpec *
gimp_param_spec_float_array(const gchar * name,const gchar * nick,const gchar * blurb,GParamFlags flags)2472 gimp_param_spec_float_array (const gchar *name,
2473                              const gchar *nick,
2474                              const gchar *blurb,
2475                              GParamFlags  flags)
2476 {
2477   GimpParamSpecArray *array_spec;
2478 
2479   array_spec = g_param_spec_internal (GIMP_TYPE_PARAM_FLOAT_ARRAY,
2480                                       name, nick, blurb, flags);
2481 
2482   return G_PARAM_SPEC (array_spec);
2483 }
2484 
2485 const gdouble *
gimp_value_get_floatarray(const GValue * value)2486 gimp_value_get_floatarray (const GValue *value)
2487 {
2488   g_return_val_if_fail (GIMP_VALUE_HOLDS_FLOAT_ARRAY (value), NULL);
2489 
2490   return (const gdouble *) gimp_value_get_array (value);
2491 }
2492 
2493 gdouble *
gimp_value_dup_floatarray(const GValue * value)2494 gimp_value_dup_floatarray (const GValue *value)
2495 {
2496   g_return_val_if_fail (GIMP_VALUE_HOLDS_FLOAT_ARRAY (value), NULL);
2497 
2498   return (gdouble *) gimp_value_dup_array (value);
2499 }
2500 
2501 void
gimp_value_set_floatarray(GValue * value,const gdouble * data,gsize length)2502 gimp_value_set_floatarray (GValue        *value,
2503                            const gdouble *data,
2504                            gsize         length)
2505 {
2506   g_return_if_fail (GIMP_VALUE_HOLDS_FLOAT_ARRAY (value));
2507 
2508   gimp_value_set_array (value, (const guint8 *) data,
2509                         length * sizeof (gdouble));
2510 }
2511 
2512 void
gimp_value_set_static_floatarray(GValue * value,const gdouble * data,gsize length)2513 gimp_value_set_static_floatarray (GValue        *value,
2514                                   const gdouble *data,
2515                                   gsize         length)
2516 {
2517   g_return_if_fail (GIMP_VALUE_HOLDS_FLOAT_ARRAY (value));
2518 
2519   gimp_value_set_static_array (value, (const guint8 *) data,
2520                                length * sizeof (gdouble));
2521 }
2522 
2523 void
gimp_value_take_floatarray(GValue * value,gdouble * data,gsize length)2524 gimp_value_take_floatarray (GValue  *value,
2525                             gdouble *data,
2526                             gsize    length)
2527 {
2528   g_return_if_fail (GIMP_VALUE_HOLDS_FLOAT_ARRAY (value));
2529 
2530   gimp_value_take_array (value, (guint8 *) data,
2531                          length * sizeof (gdouble));
2532 }
2533 
2534 
2535 /*
2536  * GIMP_TYPE_STRING_ARRAY
2537  */
2538 
2539 GimpArray *
gimp_string_array_new(const gchar ** data,gsize length,gboolean static_data)2540 gimp_string_array_new (const gchar **data,
2541                        gsize         length,
2542                        gboolean      static_data)
2543 {
2544   GimpArray *array;
2545 
2546   g_return_val_if_fail ((data == NULL && length == 0) ||
2547                         (data != NULL && length  > 0), NULL);
2548 
2549   array = g_slice_new0 (GimpArray);
2550 
2551   if (! static_data)
2552     {
2553       gchar **tmp = g_new (gchar *, length);
2554       gint    i;
2555 
2556       for (i = 0; i < length; i++)
2557         tmp[i] = g_strdup (data[i]);
2558 
2559       array->data = (guint8 *) tmp;
2560     }
2561   else
2562     {
2563       array->data = (guint8 *) data;
2564     }
2565 
2566   array->length      = length;
2567   array->static_data = static_data;
2568 
2569   return array;
2570 }
2571 
2572 GimpArray *
gimp_string_array_copy(const GimpArray * array)2573 gimp_string_array_copy (const GimpArray *array)
2574 {
2575   if (array)
2576     return gimp_string_array_new ((const gchar **) array->data,
2577                                   array->length, FALSE);
2578 
2579   return NULL;
2580 }
2581 
2582 void
gimp_string_array_free(GimpArray * array)2583 gimp_string_array_free (GimpArray *array)
2584 {
2585   if (array)
2586     {
2587       if (! array->static_data)
2588         {
2589           gchar **tmp = (gchar **) array->data;
2590           gint    i;
2591 
2592           for (i = 0; i < array->length; i++)
2593             g_free (tmp[i]);
2594 
2595           g_free (array->data);
2596         }
2597 
2598       g_slice_free (GimpArray, array);
2599     }
2600 }
2601 
2602 GType
gimp_string_array_get_type(void)2603 gimp_string_array_get_type (void)
2604 {
2605   static GType type = 0;
2606 
2607   if (! type)
2608     type = g_boxed_type_register_static ("GimpStringArray",
2609                                          (GBoxedCopyFunc) gimp_string_array_copy,
2610                                          (GBoxedFreeFunc) gimp_string_array_free);
2611 
2612   return type;
2613 }
2614 
2615 
2616 /*
2617  * GIMP_TYPE_PARAM_STRING_ARRAY
2618  */
2619 
2620 static void       gimp_param_string_array_class_init  (GParamSpecClass *klass);
2621 static void       gimp_param_string_array_init        (GParamSpec      *pspec);
2622 static gboolean   gimp_param_string_array_validate    (GParamSpec      *pspec,
2623                                                        GValue          *value);
2624 static gint       gimp_param_string_array_values_cmp  (GParamSpec      *pspec,
2625                                                        const GValue    *value1,
2626                                                        const GValue    *value2);
2627 
2628 GType
gimp_param_string_array_get_type(void)2629 gimp_param_string_array_get_type (void)
2630 {
2631   static GType type = 0;
2632 
2633   if (! type)
2634     {
2635       const GTypeInfo info =
2636       {
2637         sizeof (GParamSpecClass),
2638         NULL, NULL,
2639         (GClassInitFunc) gimp_param_string_array_class_init,
2640         NULL, NULL,
2641         sizeof (GimpParamSpecArray),
2642         0,
2643         (GInstanceInitFunc) gimp_param_string_array_init
2644       };
2645 
2646       type = g_type_register_static (G_TYPE_PARAM_BOXED,
2647                                      "GimpParamStringArray", &info, 0);
2648     }
2649 
2650   return type;
2651 }
2652 
2653 static void
gimp_param_string_array_class_init(GParamSpecClass * klass)2654 gimp_param_string_array_class_init (GParamSpecClass *klass)
2655 {
2656   klass->value_type     = GIMP_TYPE_STRING_ARRAY;
2657   klass->value_validate = gimp_param_string_array_validate;
2658   klass->values_cmp     = gimp_param_string_array_values_cmp;
2659 }
2660 
2661 static void
gimp_param_string_array_init(GParamSpec * pspec)2662 gimp_param_string_array_init (GParamSpec *pspec)
2663 {
2664 }
2665 
2666 static gboolean
gimp_param_string_array_validate(GParamSpec * pspec,GValue * value)2667 gimp_param_string_array_validate (GParamSpec *pspec,
2668                                   GValue     *value)
2669 {
2670   GimpArray *array = value->data[0].v_pointer;
2671 
2672   if (array)
2673     {
2674       if ((array->data == NULL && array->length != 0) ||
2675           (array->data != NULL && array->length == 0))
2676         {
2677           g_value_set_boxed (value, NULL);
2678           return TRUE;
2679         }
2680     }
2681 
2682   return FALSE;
2683 }
2684 
2685 static gint
gimp_param_string_array_values_cmp(GParamSpec * pspec,const GValue * value1,const GValue * value2)2686 gimp_param_string_array_values_cmp (GParamSpec   *pspec,
2687                                     const GValue *value1,
2688                                     const GValue *value2)
2689 {
2690   GimpArray *array1 = value1->data[0].v_pointer;
2691   GimpArray *array2 = value2->data[0].v_pointer;
2692 
2693   /*  try to return at least *something*, it's useless anyway...  */
2694 
2695   if (! array1)
2696     return array2 != NULL ? -1 : 0;
2697   else if (! array2)
2698     return array1 != NULL ? 1 : 0;
2699   else if (array1->length < array2->length)
2700     return -1;
2701   else if (array1->length > array2->length)
2702     return 1;
2703 
2704   return 0;
2705 }
2706 
2707 GParamSpec *
gimp_param_spec_string_array(const gchar * name,const gchar * nick,const gchar * blurb,GParamFlags flags)2708 gimp_param_spec_string_array (const gchar *name,
2709                               const gchar *nick,
2710                               const gchar *blurb,
2711                               GParamFlags  flags)
2712 {
2713   GimpParamSpecStringArray *array_spec;
2714 
2715   array_spec = g_param_spec_internal (GIMP_TYPE_PARAM_STRING_ARRAY,
2716                                       name, nick, blurb, flags);
2717 
2718   return G_PARAM_SPEC (array_spec);
2719 }
2720 
2721 const gchar **
gimp_value_get_stringarray(const GValue * value)2722 gimp_value_get_stringarray (const GValue *value)
2723 {
2724   GimpArray *array;
2725 
2726   g_return_val_if_fail (GIMP_VALUE_HOLDS_STRING_ARRAY (value), NULL);
2727 
2728   array = value->data[0].v_pointer;
2729 
2730   if (array)
2731     return (const gchar **) array->data;
2732 
2733   return NULL;
2734 }
2735 
2736 gchar **
gimp_value_dup_stringarray(const GValue * value)2737 gimp_value_dup_stringarray (const GValue *value)
2738 {
2739   GimpArray *array;
2740 
2741   g_return_val_if_fail (GIMP_VALUE_HOLDS_STRING_ARRAY (value), NULL);
2742 
2743   array = value->data[0].v_pointer;
2744 
2745   if (array)
2746     {
2747       gchar **ret = g_memdup (array->data, array->length * sizeof (gchar *));
2748       gint    i;
2749 
2750       for (i = 0; i < array->length; i++)
2751         ret[i] = g_strdup (ret[i]);
2752 
2753       return ret;
2754     }
2755 
2756   return NULL;
2757 }
2758 
2759 void
gimp_value_set_stringarray(GValue * value,const gchar ** data,gsize length)2760 gimp_value_set_stringarray (GValue       *value,
2761                             const gchar **data,
2762                             gsize         length)
2763 {
2764   GimpArray *array;
2765 
2766   g_return_if_fail (GIMP_VALUE_HOLDS_STRING_ARRAY (value));
2767 
2768   array = gimp_string_array_new (data, length, FALSE);
2769 
2770   g_value_take_boxed (value, array);
2771 }
2772 
2773 void
gimp_value_set_static_stringarray(GValue * value,const gchar ** data,gsize length)2774 gimp_value_set_static_stringarray (GValue       *value,
2775                                    const gchar **data,
2776                                    gsize         length)
2777 {
2778   GimpArray *array;
2779 
2780   g_return_if_fail (GIMP_VALUE_HOLDS_STRING_ARRAY (value));
2781 
2782   array = gimp_string_array_new (data, length, TRUE);
2783 
2784   g_value_take_boxed (value, array);
2785 }
2786 
2787 void
gimp_value_take_stringarray(GValue * value,gchar ** data,gsize length)2788 gimp_value_take_stringarray (GValue  *value,
2789                              gchar  **data,
2790                              gsize    length)
2791 {
2792   GimpArray *array;
2793 
2794   g_return_if_fail (GIMP_VALUE_HOLDS_STRING_ARRAY (value));
2795 
2796   array = gimp_string_array_new ((const gchar **) data, length, TRUE);
2797   array->static_data = FALSE;
2798 
2799   g_value_take_boxed (value, array);
2800 }
2801 
2802 
2803 /*
2804  * GIMP_TYPE_COLOR_ARRAY
2805  */
2806 
2807 GType
gimp_color_array_get_type(void)2808 gimp_color_array_get_type (void)
2809 {
2810   static GType type = 0;
2811 
2812   if (! type)
2813     type = g_boxed_type_register_static ("GimpColorArray",
2814                                          (GBoxedCopyFunc) gimp_array_copy,
2815                                          (GBoxedFreeFunc) gimp_array_free);
2816 
2817   return type;
2818 }
2819 
2820 
2821 /*
2822  * GIMP_TYPE_PARAM_COLOR_ARRAY
2823  */
2824 
2825 static void  gimp_param_color_array_class_init (GParamSpecClass *klass);
2826 static void  gimp_param_color_array_init       (GParamSpec      *pspec);
2827 
2828 GType
gimp_param_color_array_get_type(void)2829 gimp_param_color_array_get_type (void)
2830 {
2831   static GType type = 0;
2832 
2833   if (! type)
2834     {
2835       const GTypeInfo info =
2836       {
2837         sizeof (GParamSpecClass),
2838         NULL, NULL,
2839         (GClassInitFunc) gimp_param_color_array_class_init,
2840         NULL, NULL,
2841         sizeof (GimpParamSpecArray),
2842         0,
2843         (GInstanceInitFunc) gimp_param_color_array_init
2844       };
2845 
2846       type = g_type_register_static (G_TYPE_PARAM_BOXED,
2847                                      "GimpParamColorArray", &info, 0);
2848     }
2849 
2850   return type;
2851 }
2852 
2853 static void
gimp_param_color_array_class_init(GParamSpecClass * klass)2854 gimp_param_color_array_class_init (GParamSpecClass *klass)
2855 {
2856   klass->value_type = GIMP_TYPE_COLOR_ARRAY;
2857 }
2858 
2859 static void
gimp_param_color_array_init(GParamSpec * pspec)2860 gimp_param_color_array_init (GParamSpec *pspec)
2861 {
2862 }
2863 
2864 GParamSpec *
gimp_param_spec_color_array(const gchar * name,const gchar * nick,const gchar * blurb,GParamFlags flags)2865 gimp_param_spec_color_array (const gchar *name,
2866                              const gchar *nick,
2867                              const gchar *blurb,
2868                              GParamFlags  flags)
2869 {
2870   GimpParamSpecColorArray *array_spec;
2871 
2872   array_spec = g_param_spec_internal (GIMP_TYPE_PARAM_COLOR_ARRAY,
2873                                       name, nick, blurb, flags);
2874 
2875   return G_PARAM_SPEC (array_spec);
2876 }
2877 
2878 const GimpRGB *
gimp_value_get_colorarray(const GValue * value)2879 gimp_value_get_colorarray (const GValue *value)
2880 {
2881   g_return_val_if_fail (GIMP_VALUE_HOLDS_COLOR_ARRAY (value), NULL);
2882 
2883   return (const GimpRGB *) gimp_value_get_array (value);
2884 }
2885 
2886 GimpRGB *
gimp_value_dup_colorarray(const GValue * value)2887 gimp_value_dup_colorarray (const GValue *value)
2888 {
2889   g_return_val_if_fail (GIMP_VALUE_HOLDS_COLOR_ARRAY (value), NULL);
2890 
2891   return (GimpRGB *) gimp_value_dup_array (value);
2892 }
2893 
2894 void
gimp_value_set_colorarray(GValue * value,const GimpRGB * data,gsize length)2895 gimp_value_set_colorarray (GValue        *value,
2896                            const GimpRGB *data,
2897                            gsize         length)
2898 {
2899   g_return_if_fail (GIMP_VALUE_HOLDS_COLOR_ARRAY (value));
2900 
2901   gimp_value_set_array (value, (const guint8 *) data,
2902                         length * sizeof (GimpRGB));
2903 }
2904 
2905 void
gimp_value_set_static_colorarray(GValue * value,const GimpRGB * data,gsize length)2906 gimp_value_set_static_colorarray (GValue        *value,
2907                                   const GimpRGB *data,
2908                                   gsize          length)
2909 {
2910   g_return_if_fail (GIMP_VALUE_HOLDS_COLOR_ARRAY (value));
2911 
2912   gimp_value_set_static_array (value, (const guint8 *) data,
2913                                length * sizeof (GimpRGB));
2914 }
2915 
2916 void
gimp_value_take_colorarray(GValue * value,GimpRGB * data,gsize length)2917 gimp_value_take_colorarray (GValue  *value,
2918                             GimpRGB *data,
2919                             gsize    length)
2920 {
2921   g_return_if_fail (GIMP_VALUE_HOLDS_COLOR_ARRAY (value));
2922 
2923   gimp_value_take_array (value, (guint8 *) data,
2924                          length * sizeof (GimpRGB));
2925 }
2926