Commit 7610e299 authored by Michael Natterer's avatar Michael Natterer 😴

Use GimpValueArray and GimpParamSpecValueArray

instead of the deprecated stuff from GLib.
parent ffe74bbb
......@@ -22,6 +22,7 @@
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "actions-types.h"
......@@ -65,33 +66,33 @@
static void plug_in_procedure_execute (GimpPlugInProcedure *procedure,
Gimp *gimp,
GimpDisplay *display,
GValueArray *args,
GimpValueArray *args,
gint n_args);
static gint plug_in_collect_data_args (GtkAction *action,
GimpObject *object,
GParamSpec **pspecs,
GValueArray *args,
gint n_args);
static gint plug_in_collect_image_args (GtkAction *action,
GimpImage *image,
GParamSpec **pspecs,
GValueArray *args,
gint n_args);
static gint plug_in_collect_item_args (GtkAction *action,
GimpImage *image,
GimpItem *item,
GParamSpec **pspecs,
GValueArray *args,
gint n_args);
static gint plug_in_collect_display_args (GtkAction *action,
GimpDisplay *display,
GParamSpec **pspecs,
GValueArray *args,
gint n_args);
static void plug_in_reset_all_response (GtkWidget *dialog,
gint response_id,
Gimp *gimp);
static gint plug_in_collect_data_args (GtkAction *action,
GimpObject *object,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args);
static gint plug_in_collect_image_args (GtkAction *action,
GimpImage *image,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args);
static gint plug_in_collect_item_args (GtkAction *action,
GimpImage *image,
GimpItem *item,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args);
static gint plug_in_collect_display_args (GtkAction *action,
GimpDisplay *display,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args);
static void plug_in_reset_all_response (GtkWidget *dialog,
gint response_id,
Gimp *gimp);
/* public functions */
......@@ -101,17 +102,18 @@ plug_in_run_cmd_callback (GtkAction *action,
GimpPlugInProcedure *proc,
gpointer data)
{
GimpProcedure *procedure = GIMP_PROCEDURE (proc);
Gimp *gimp;
GValueArray *args;
gint n_args = 0;
GimpDisplay *display = NULL;
GimpProcedure *procedure = GIMP_PROCEDURE (proc);
Gimp *gimp;
GimpValueArray *args;
gint n_args = 0;
GimpDisplay *display = NULL;
return_if_no_gimp (gimp, data);
args = gimp_procedure_get_arguments (procedure);
/* initialize the first argument */
g_value_set_int (&args->values[n_args], GIMP_RUN_INTERACTIVE);
g_value_set_int (gimp_value_array_index (args, n_args),
GIMP_RUN_INTERACTIVE);
n_args++;
switch (procedure->proc_type)
......@@ -188,7 +190,7 @@ plug_in_run_cmd_callback (GtkAction *action,
if (n_args >= 1)
plug_in_procedure_execute (proc, gimp, display, args, n_args);
g_value_array_free (args);
gimp_value_array_unref (args);
}
void
......@@ -209,12 +211,12 @@ plug_in_repeat_cmd_callback (GtkAction *action,
if (procedure)
{
GValueArray *args;
gint n_args;
GimpValueArray *args;
gint n_args;
args = gimp_procedure_get_arguments (GIMP_PROCEDURE (procedure));
g_value_set_int (&args->values[0], run_mode);
g_value_set_int (gimp_value_array_index (args, 0), run_mode);
n_args = plug_in_collect_display_args (action, display,
GIMP_PROCEDURE (procedure)->args,
......@@ -222,7 +224,7 @@ plug_in_repeat_cmd_callback (GtkAction *action,
plug_in_procedure_execute (procedure, gimp, display, args, n_args);
g_value_array_free (args);
gimp_value_array_unref (args);
}
}
......@@ -231,16 +233,16 @@ plug_in_history_cmd_callback (GtkAction *action,
GimpPlugInProcedure *procedure,
gpointer data)
{
Gimp *gimp;
GimpDisplay *display;
GValueArray *args;
gint n_args;
Gimp *gimp;
GimpDisplay *display;
GimpValueArray *args;
gint n_args;
return_if_no_gimp (gimp, data);
return_if_no_display (display, data);
args = gimp_procedure_get_arguments (GIMP_PROCEDURE (procedure));
g_value_set_int (&args->values[0], GIMP_RUN_INTERACTIVE);
g_value_set_int (gimp_value_array_index (args, 0), GIMP_RUN_INTERACTIVE);
n_args = plug_in_collect_display_args (action, display,
GIMP_PROCEDURE (procedure)->args,
......@@ -248,7 +250,7 @@ plug_in_history_cmd_callback (GtkAction *action,
plug_in_procedure_execute (procedure, gimp, display, args, n_args);
g_value_array_free (args);
gimp_value_array_unref (args);
}
void
......@@ -291,7 +293,7 @@ static void
plug_in_procedure_execute (GimpPlugInProcedure *procedure,
Gimp *gimp,
GimpDisplay *display,
GValueArray *args,
GimpValueArray *args,
gint n_args)
{
GError *error = NULL;
......@@ -323,18 +325,18 @@ plug_in_procedure_execute (GimpPlugInProcedure *procedure,
}
static gint
plug_in_collect_data_args (GtkAction *action,
GimpObject *object,
GParamSpec **pspecs,
GValueArray *args,
gint n_args)
plug_in_collect_data_args (GtkAction *action,
GimpObject *object,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args)
{
if (args->n_values > n_args &&
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_STRING (pspecs[n_args]))
{
if (object)
{
g_value_set_string (&args->values[n_args],
g_value_set_string (gimp_value_array_index (args, n_args),
gimp_object_get_name (object));
n_args++;
}
......@@ -349,18 +351,18 @@ plug_in_collect_data_args (GtkAction *action,
}
static gint
plug_in_collect_image_args (GtkAction *action,
GimpImage *image,
GParamSpec **pspecs,
GValueArray *args,
gint n_args)
plug_in_collect_image_args (GtkAction *action,
GimpImage *image,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args)
{
if (args->n_values > n_args &&
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_IMAGE_ID (pspecs[n_args]))
{
if (image)
{
gimp_value_set_image (&args->values[n_args], image);
gimp_value_set_image (gimp_value_array_index (args, n_args), image);
n_args++;
}
else
......@@ -374,29 +376,30 @@ plug_in_collect_image_args (GtkAction *action,
}
static gint
plug_in_collect_item_args (GtkAction *action,
GimpImage *image,
GimpItem *item,
GParamSpec **pspecs,
GValueArray *args,
gint n_args)
plug_in_collect_item_args (GtkAction *action,
GimpImage *image,
GimpItem *item,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args)
{
if (args->n_values > n_args &&
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_IMAGE_ID (pspecs[n_args]))
{
if (image)
{
gimp_value_set_image (&args->values[n_args], image);
gimp_value_set_image (gimp_value_array_index (args, n_args), image);
n_args++;
if (args->n_values > n_args &&
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_ITEM_ID (pspecs[n_args]))
{
if (item &&
g_type_is_a (G_TYPE_FROM_INSTANCE (item),
GIMP_PARAM_SPEC_ITEM_ID (pspecs[n_args])->item_type))
{
gimp_value_set_item (&args->values[n_args], item);
gimp_value_set_item (gimp_value_array_index (args, n_args),
item);
n_args++;
}
else
......@@ -412,18 +415,19 @@ plug_in_collect_item_args (GtkAction *action,
}
static gint
plug_in_collect_display_args (GtkAction *action,
GimpDisplay *display,
GParamSpec **pspecs,
GValueArray *args,
gint n_args)
plug_in_collect_display_args (GtkAction *action,
GimpDisplay *display,
GParamSpec **pspecs,
GimpValueArray *args,
gint n_args)
{
if (args->n_values > n_args &&
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_DISPLAY_ID (pspecs[n_args]))
{
if (display)
{
gimp_value_set_display (&args->values[n_args], GIMP_OBJECT (display));
gimp_value_set_display (gimp_value_array_index (args, n_args),
GIMP_OBJECT (display));
n_args++;
}
else
......@@ -433,24 +437,26 @@ plug_in_collect_display_args (GtkAction *action,
}
}
if (args->n_values > n_args &&
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_IMAGE_ID (pspecs[n_args]))
{
GimpImage *image = display ? gimp_display_get_image (display) : NULL;
if (image)
{
gimp_value_set_image (&args->values[n_args], image);
gimp_value_set_image (gimp_value_array_index (args, n_args),
image);
n_args++;
if (args->n_values > n_args &&
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_DRAWABLE_ID (pspecs[n_args]))
{
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
if (drawable)
{
gimp_value_set_drawable (&args->values[n_args], drawable);
gimp_value_set_drawable (gimp_value_array_index (args, n_args),
drawable);
n_args++;
}
else
......
......@@ -22,6 +22,7 @@
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "actions-types.h"
......@@ -317,12 +318,12 @@ vectors_selection_to_vectors_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpImage *image;
GtkWidget *widget;
GimpProcedure *procedure;
GValueArray *args;
GimpDisplay *display;
GError *error = NULL;
GimpImage *image;
GtkWidget *widget;
GimpProcedure *procedure;
GimpValueArray *args;
GimpDisplay *display;
GError *error = NULL;
return_if_no_image (image, data);
return_if_no_widget (widget, data);
......@@ -346,15 +347,17 @@ vectors_selection_to_vectors_cmd_callback (GtkAction *action,
args = gimp_procedure_get_arguments (procedure);
gimp_value_array_truncate (args, 2);
g_value_set_int (&args->values[0], GIMP_RUN_INTERACTIVE);
gimp_value_set_image (&args->values[1], image);
g_value_set_int (gimp_value_array_index (args, 0),
GIMP_RUN_INTERACTIVE);
gimp_value_set_image (gimp_value_array_index (args, 1),
image);
gimp_procedure_execute_async (procedure, image->gimp,
action_data_get_context (data),
GIMP_PROGRESS (display), args,
GIMP_OBJECT (display), &error);
g_value_array_free (args);
gimp_value_array_unref (args);
if (error)
{
......
......@@ -22,6 +22,8 @@
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
#include "core/core-types.h"
#include "base/tile-swap.h"
......@@ -144,18 +146,20 @@ batch_run_cmd (Gimp *gimp,
GimpRunMode run_mode,
const gchar *cmd)
{
GValueArray *args;
GValueArray *return_vals;
GError *error = NULL;
gint i = 0;
GimpValueArray *args;
GimpValueArray *return_vals;
GError *error = NULL;
gint i = 0;
args = gimp_procedure_get_arguments (procedure);
if (procedure->num_args > i && GIMP_IS_PARAM_SPEC_INT32 (procedure->args[i]))
g_value_set_int (&args->values[i++], run_mode);
if (procedure->num_args > i &&
GIMP_IS_PARAM_SPEC_INT32 (procedure->args[i]))
g_value_set_int (gimp_value_array_index (args, i++), run_mode);
if (procedure->num_args > i && GIMP_IS_PARAM_SPEC_STRING (procedure->args[i]))
g_value_set_static_string (&args->values[i++], cmd);
if (procedure->num_args > i &&
GIMP_IS_PARAM_SPEC_STRING (procedure->args[i]))
g_value_set_static_string (gimp_value_array_index (args, i++), cmd);
return_vals =
gimp_pdb_execute_procedure_by_name_args (gimp->pdb,
......@@ -163,7 +167,7 @@ batch_run_cmd (Gimp *gimp,
NULL, &error,
proc_name, args);
switch (g_value_get_enum (&return_vals->values[0]))
switch (g_value_get_enum (gimp_value_array_index (return_vals, 0)))
{
case GIMP_PDB_EXECUTION_ERROR:
if (error)
......@@ -194,8 +198,8 @@ batch_run_cmd (Gimp *gimp,
break;
}
g_value_array_free (return_vals);
g_value_array_free (args);
gimp_value_array_unref (return_vals);
gimp_value_array_unref (args);
if (error)
g_error_free (error);
......
......@@ -588,19 +588,6 @@ gimp_parameters_free (GParameter *params,
}
}
void
gimp_value_array_truncate (GValueArray *args,
gint n_values)
{
gint i;
g_return_if_fail (args != NULL);
g_return_if_fail (n_values > 0 && n_values <= args->n_values);
for (i = args->n_values; i > n_values; i--)
g_value_array_remove (args, i - 1);
}
/* markup unescape code stolen and adapted from gmarkup.c
*/
static gchar *
......
......@@ -76,9 +76,6 @@ GParameter * gimp_parameters_append_valist (GType object_type
void gimp_parameters_free (GParameter *params,
gint n_params);
void gimp_value_array_truncate (GValueArray *args,
gint n_values);
gchar * gimp_markup_extract_text (const gchar *markup);
const gchar* gimp_enum_get_value_name (GType enum_type,
......
......@@ -22,6 +22,7 @@
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpmath/gimpmath.h"
#include "libgimpconfig/gimpconfig.h"
......@@ -30,6 +31,7 @@
#include "gimpcurve.h"
#include "gimpcurve-load.h"
#include "gimpcurve-save.h"
#include "gimpparamspecs.h"
#include "gimp-intl.h"
......@@ -159,11 +161,11 @@ gimp_curve_class_init (GimpCurveClass *klass)
array_spec = g_param_spec_double ("point", NULL, NULL,
-1.0, 1.0, 0.0, GIMP_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_POINTS,
g_param_spec_value_array ("points",
NULL, NULL,
array_spec,
GIMP_PARAM_STATIC_STRINGS |
GIMP_CONFIG_PARAM_FLAGS));
gimp_param_spec_value_array ("points",
NULL, NULL,
array_spec,
GIMP_PARAM_STATIC_STRINGS |
GIMP_CONFIG_PARAM_FLAGS));
GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_N_SAMPLES,
"n-samples",
......@@ -173,11 +175,11 @@ gimp_curve_class_init (GimpCurveClass *klass)
array_spec = g_param_spec_double ("sample", NULL, NULL,
0.0, 1.0, 0.0, GIMP_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_SAMPLES,
g_param_spec_value_array ("samples",
NULL, NULL,
array_spec,
GIMP_PARAM_STATIC_STRINGS |
GIMP_CONFIG_PARAM_FLAGS));
gimp_param_spec_value_array ("samples",
NULL, NULL,
array_spec,
GIMP_PARAM_STATIC_STRINGS |
GIMP_CONFIG_PARAM_FLAGS));
}
static void
......@@ -240,16 +242,19 @@ gimp_curve_set_property (GObject *object,
case PROP_POINTS:
{
GValueArray *array = g_value_get_boxed (value);
gint i;
GimpValueArray *array = g_value_get_boxed (value);
gint length;
gint i;
if (! array)
break;
for (i = 0; i < curve->n_points && i * 2 < array->n_values; i++)
length = gimp_value_array_length (array);
for (i = 0; i < curve->n_points && i * 2 < length; i++)
{
GValue *x = g_value_array_get_nth (array, i * 2);
GValue *y = g_value_array_get_nth (array, i * 2 + 1);
GValue *x = gimp_value_array_index (array, i * 2);
GValue *y = gimp_value_array_index (array, i * 2 + 1);
curve->points[i].x = g_value_get_double (x);
curve->points[i].y = g_value_get_double (y);
......@@ -263,15 +268,18 @@ gimp_curve_set_property (GObject *object,
case PROP_SAMPLES:
{
GValueArray *array = g_value_get_boxed (value);
gint i;
GimpValueArray *array = g_value_get_boxed (value);
gint length;
gint i;
if (! array)
break;
for (i = 0; i < curve->n_samples && i < array->n_values; i++)
length = gimp_value_array_length (array);
for (i = 0; i < curve->n_samples && i < length; i++)
{
GValue *v = g_value_array_get_nth (array, i);
GValue *v = gimp_value_array_index (array, i);
curve->samples[i] = g_value_get_double (v);
}
......@@ -304,19 +312,19 @@ gimp_curve_get_property (GObject *object,
case PROP_POINTS:
{
GValueArray *array = g_value_array_new (curve->n_points * 2);
GValue v = { 0, };
gint i;
GimpValueArray *array = gimp_value_array_new (curve->n_points * 2);
GValue v = { 0, };
gint i;
g_value_init (&v, G_TYPE_DOUBLE);
for (i = 0; i < curve->n_points; i++)
{
g_value_set_double (&v, curve->points[i].x);
g_value_array_append (array, &v);
gimp_value_array_append (array, &v);
g_value_set_double (&v, curve->points[i].y);
g_value_array_append (array, &v);
gimp_value_array_append (array, &v);
}
g_value_unset (&v);
......@@ -331,16 +339,16 @@ gimp_curve_get_property (GObject *object,
case PROP_SAMPLES:
{
GValueArray *array = g_value_array_new (curve->n_samples);
GValue v = { 0, };
gint i;
GimpValueArray *array = gimp_value_array_new (curve->n_samples);
GValue v = { 0, };
gint i;
g_value_init (&v, G_TYPE_DOUBLE);
for (i = 0; i < curve->n_samples; i++)
{
g_value_set_double (&v, curve->samples[i]);
g_value_array_append (array, &v);
gimp_value_array_append (array, &v);
}
g_value_unset (&v);
......
......@@ -23,6 +23,8 @@
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
#include "core-types.h"
#include "gimpdashpattern.h"
......@@ -214,23 +216,25 @@ gimp_dash_pattern_fill_segments (GArray *pattern,
}
GArray *
gimp_dash_pattern_from_value_array (GValueArray *value_array)
gimp_dash_pattern_from_value_array (GimpValueArray *value_array)
{
if (value_array == NULL || value_array->n_values == 0)
if (value_array == NULL || gimp_value_array_length (value_array) == 0)
{
return NULL;
}
else
{
GArray *pattern;
gint length;
gint i;
pattern = g_array_sized_new (FALSE, FALSE,
sizeof (gdouble), value_array->n_values);
length = gimp_value_array_length (value_array);
pattern = g_array_sized_new (FALSE, FALSE, sizeof (gdouble), length);
for (i = 0; i < value_array->n_values; i++)
for (i = 0; i < length; i++)
{
GValue *item = g_value_array_get_nth (value_array, i);
GValue *item = gimp_value_array_index (value_array, i);
gdouble val;
g_return_val_if_fail (G_VALUE_HOLDS_DOUBLE (item), NULL);
......@@ -244,7 +248,7 @@ gimp_dash_pattern_from_value_array (GValueArray *value_array)
}
}
GValueArray *
GimpValueArray *
gimp_dash_pattern_to_value_array (GArray *pattern)
{
if (pattern == NULL || pattern->len == 0)
......@@ -253,16 +257,16 @@ gimp_dash_pattern_to_value_array (GArray *pattern)
}
else
{
GValueArray *value_array = g_value_array_new (pattern->len);
GValue item = { 0, };
gint i;
GimpValueArray *value_array = gimp_value_array_new (pattern->len);
GValue item = { 0, };
gint i;
g_value_init (&item, G_TYPE_DOUBLE);
for (i = 0; i < pattern->len; i++)
{
g_value_set_double (&item, g_array_index (pattern, gdouble, i));
g_value_array_append (value_array, &item);
gimp_value_array_append (value_array, &item);
}
g_value_unset (&item);
......
......@@ -27,22 +27,22 @@
#define GIMP_VALUE_HOLDS_DASH_PATTERN(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_DASH_PATTERN))
GType gimp_dash_pattern_get_type (void) G_GNUC_CONST;
GType gimp_dash_pattern_get_type (void) G_GNUC_CONST;
GArray * gimp_dash_pattern_new_from_preset (GimpDashPreset preset);
GArray * gimp_dash_pattern_new_from_segments (const gboolean *segments,
gint n_segments,
gdouble dash_length);
GArray * gimp_dash_pattern_new_from_preset (GimpDashPreset preset);
GArray * gimp_dash_pattern_new_from_segments (const gboolean *segments,
gint n_segments,
gdouble dash_length);
void gimp_dash_pattern_fill_segments (GArray *pattern,
gboolean *segments,
gint n_segments);
void gimp_dash_pattern_fill_segments (GArray *pattern,
gboolean *segments,
gint n_segments);
GArray * gimp_dash_pattern_from_value_array (GValueArray *value_array);
GValueArray * gimp_dash_pattern_to_value_array (GArray *pattern);
GArray * gimp_dash_pattern_from_value_array (GimpValueArray *value_array);
GimpValueArray * gimp_dash_pattern_to_value_array (GArray *pattern);
GArray * gimp_dash_pattern_copy (GArray *pattern);
void gimp_dash_pattern_free (GArray *pattern);
GArray * gimp_dash_pattern_copy (GArray *pattern);
void gimp_dash_pattern_free (GArray *pattern);
#endif /* __GIMP_DASH_PATTERN_H__ */