From a49cc445b8921cc71304c0bd92a85efac8a148ef Mon Sep 17 00:00:00 2001 From: William Skaggs Date: Tue, 6 Jun 2006 22:48:57 +0000 Subject: [PATCH] Bill Skaggs * app/core/gimpguide.c * app/core/gimpguide.h: new files, implementing GuideGimp as a GimpObject * app/core/Makefile.am: add new files as sources * app/core/gimpimage-guides.h * app/core/gimpimage-guides.c: use the new object instead of defining GimpGuide here as a struct. * app/core/gimpimage-crop.c * app/core/gimpimage-duplicate.c * app/core/gimpimage-flip.c * app/core/gimpimage-resize.c * app/core/gimpimage-rotate.c * app/core/gimpimage-scale.c * app/core/gimpimage-snap.c * app/core/gimpimage-undo-push.c * app/core/gimpimage.c * app/display/gimpdisplayshell-draw.c * app/display/gimpdisplayshell.c * app/pdb/guides_cmds.c * app/tools/gimpmovetool.c * app/xcf/xcf-save.c * tools/pdbgen/pdb/guides.pdb: include "core/gimpguide.h", and use g_object_ref/unref instead of gimp_image_guide_ref/unref. --- ChangeLog | 28 +++++ app/core/Makefile.am | 2 + app/core/gimpguide.c | 167 ++++++++++++++++++++++++++++ app/core/gimpguide.h | 62 +++++++++++ app/core/gimpimage-crop.c | 1 + app/core/gimpimage-duplicate.c | 1 + app/core/gimpimage-flip.c | 1 + app/core/gimpimage-guides.c | 42 ++----- app/core/gimpimage-guides.h | 12 -- app/core/gimpimage-resize.c | 1 + app/core/gimpimage-rotate.c | 1 + app/core/gimpimage-scale.c | 1 + app/core/gimpimage-snap.c | 1 + app/core/gimpimage-undo-push.c | 7 +- app/core/gimpimage.c | 3 +- app/display/gimpdisplayshell-draw.c | 1 + app/display/gimpdisplayshell.c | 1 + app/pdb/guides_cmds.c | 1 + app/tools/gimpmovetool.c | 1 + app/xcf/xcf-save.c | 1 + tools/pdbgen/pdb/guides.pdb | 2 +- 21 files changed, 288 insertions(+), 49 deletions(-) create mode 100644 app/core/gimpguide.c create mode 100644 app/core/gimpguide.h diff --git a/ChangeLog b/ChangeLog index d514536000..5c04e340a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2006-06-07 Bill Skaggs + + * app/core/gimpguide.c + * app/core/gimpguide.h: new files, implementing GuideGimp as a GimpObject + + * app/core/Makefile.am: add new files as sources + + * app/core/gimpimage-guides.h + * app/core/gimpimage-guides.c: use the new object instead of defining + GimpGuide here as a struct. + + * app/core/gimpimage-crop.c + * app/core/gimpimage-duplicate.c + * app/core/gimpimage-flip.c + * app/core/gimpimage-resize.c + * app/core/gimpimage-rotate.c + * app/core/gimpimage-scale.c + * app/core/gimpimage-snap.c + * app/core/gimpimage-undo-push.c + * app/core/gimpimage.c + * app/display/gimpdisplayshell-draw.c + * app/display/gimpdisplayshell.c + * app/pdb/guides_cmds.c + * app/tools/gimpmovetool.c + * app/xcf/xcf-save.c + * tools/pdbgen/pdb/guides.pdb: include "core/gimpguide.h", and use + g_object_ref/unref instead of gimp_image_guide_ref/unref. + 2006-06-07 Sven Neumann * app/tools/gimprectangletool.c (gimp_rectangle_tool_initialize): diff --git a/app/core/Makefile.am b/app/core/Makefile.am index 49c0087701..d005d365e6 100644 --- a/app/core/Makefile.am +++ b/app/core/Makefile.am @@ -120,6 +120,8 @@ libappcore_a_sources = \ gimpgradient-save.h \ gimpgrid.c \ gimpgrid.h \ + gimpguide.c \ + gimpguide.h \ gimpimage.c \ gimpimage.h \ gimpimage-colorhash.c \ diff --git a/app/core/gimpguide.c b/app/core/gimpguide.c new file mode 100644 index 0000000000..f6e37492fb --- /dev/null +++ b/app/core/gimpguide.c @@ -0,0 +1,167 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * GimpGuide + * Copyright (C) 2003 Henrik Brix Andersen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include /* strcmp */ + +#include + +#include "libgimpbase/gimpbase.h" +#include "libgimpbase/gimplimits.h" +#include "libgimpconfig/gimpconfig.h" + +#include "core-types.h" + +#include "gimpguide.h" + +#include "gimp-intl.h" + + +enum +{ + PROP_0, + PROP_POSITION, + PROP_ORIENTATION, + PROP_ID +}; + + +static void gimp_guide_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); +static void gimp_guide_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); + + +G_DEFINE_TYPE (GimpGuide, gimp_guide, GIMP_TYPE_OBJECT) + + +static void +gimp_guide_class_init (GimpGuideClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = gimp_guide_get_property; + object_class->set_property = gimp_guide_set_property; + + GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_POSITION, + "position", + N_("Offset of the guide."), + -1, + GIMP_MAX_IMAGE_SIZE, -1, + GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_ORIENTATION, + "orientation", + N_("Orientation of the guide."), + GIMP_TYPE_ORIENTATION_TYPE, + GIMP_ORIENTATION_VERTICAL, + GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_ID, + "guide-id", + N_("Identifying number for the guide."), + 0, + G_MAXINT, 0, + GIMP_PARAM_STATIC_STRINGS); +} + +static void +gimp_guide_init (GimpGuide *guide) +{ +} + +static void +gimp_guide_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + GimpGuide *guide = GIMP_GUIDE (object); + + switch (property_id) + { + case PROP_POSITION: + g_value_set_int (value, guide->position); + break; + case PROP_ORIENTATION: + g_value_set_enum (value, guide->orientation); + break; + case PROP_ID: + g_value_set_int (value, guide->guide_ID); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gimp_guide_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + GimpGuide *guide = GIMP_GUIDE (object); + + switch (property_id) + { + case PROP_POSITION: + guide->position = g_value_get_int (value); + break; + case PROP_ORIENTATION: + guide->orientation = g_value_get_enum (value); + break; + case PROP_ID: + guide->guide_ID = g_value_get_int (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +gint +gimp_guide_get_position (GimpGuide *guide) +{ + g_return_val_if_fail (GIMP_IS_GUIDE (guide), 0); + + return guide->position; +} + +void +gimp_guide_set_position (GimpGuide *guide, + gint position) +{ + g_return_if_fail (GIMP_IS_GUIDE (guide)); + + guide->position = position; +} + +GimpOrientationType +gimp_guide_get_orientation (GimpGuide *guide) +{ + g_return_val_if_fail (GIMP_IS_GUIDE (guide), 0); + + return guide->orientation; +} diff --git a/app/core/gimpguide.h b/app/core/gimpguide.h new file mode 100644 index 0000000000..7e21aac31a --- /dev/null +++ b/app/core/gimpguide.h @@ -0,0 +1,62 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * GimpGuide + * Copyright (C) 2003 Henrik Brix Andersen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __GIMP_GUIDE_H__ +#define __GIMP_GUIDE_H__ + + +#include "gimpobject.h" + + +#define GIMP_TYPE_GUIDE (gimp_guide_get_type ()) +#define GIMP_GUIDE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_GUIDE, GimpGuide)) +#define GIMP_GUIDE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_GUIDE, GimpGuideClass)) +#define GIMP_IS_GUIDE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_GUIDE)) +#define GIMP_IS_GUIDE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_GUIDE)) +#define GIMP_GUIDE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_GUIDE, GimpGuideClass)) + + +typedef struct _GimpGuideClass GimpGuideClass; + +struct _GimpGuide +{ + GimpObject parent_instance; + + gint position; + GimpOrientationType orientation; + guint32 guide_ID; +}; + + +struct _GimpGuideClass +{ + GimpObjectClass parent_class; +}; + + +GType gimp_guide_get_type (void) G_GNUC_CONST; + +gint gimp_guide_get_position (GimpGuide *guide); +void gimp_guide_set_position (GimpGuide *guide, + gint position); +GimpOrientationType gimp_guide_get_orientation (GimpGuide *guide); + +#endif /* __GIMP_GUIDE_H__ */ diff --git a/app/core/gimpimage-crop.c b/app/core/gimpimage-crop.c index c2d7c4d94d..fc2261c0a0 100644 --- a/app/core/gimpimage-crop.c +++ b/app/core/gimpimage-crop.c @@ -28,6 +28,7 @@ #include "gimp.h" #include "gimpcontext.h" +#include "gimpguide.h" #include "gimpimage.h" #include "gimpimage-crop.h" #include "gimpimage-guides.h" diff --git a/app/core/gimpimage-duplicate.c b/app/core/gimpimage-duplicate.c index ed41e59713..8bbd1362ec 100644 --- a/app/core/gimpimage-duplicate.c +++ b/app/core/gimpimage-duplicate.c @@ -28,6 +28,7 @@ #include "gimp.h" #include "gimpchannel.h" +#include "gimpguide.h" #include "gimpimage.h" #include "gimpimage-colormap.h" #include "gimpimage-duplicate.h" diff --git a/app/core/gimpimage-flip.c b/app/core/gimpimage-flip.c index a188d869a9..b4bf44971b 100644 --- a/app/core/gimpimage-flip.c +++ b/app/core/gimpimage-flip.c @@ -24,6 +24,7 @@ #include "gimp.h" #include "gimpcontext.h" +#include "gimpguide.h" #include "gimpimage.h" #include "gimpimage-flip.h" #include "gimpimage-guides.h" diff --git a/app/core/gimpimage-guides.c b/app/core/gimpimage-guides.c index c3a5542bb2..6dbd9d3a0c 100644 --- a/app/core/gimpimage-guides.c +++ b/app/core/gimpimage-guides.c @@ -24,6 +24,7 @@ #include "gimp.h" #include "gimpimage.h" +#include "gimpguide.h" #include "gimpimage-guides.h" #include "gimpimage-undo-push.h" @@ -42,9 +43,8 @@ gimp_image_add_hguide (GimpImage *image, g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (position >= 0 && position <= image->height, NULL); - guide = g_new0 (GimpGuide, 1); + guide = g_object_new (GIMP_TYPE_GUIDE, NULL); - guide->ref_count = 1; guide->position = -1; guide->orientation = GIMP_ORIENTATION_HORIZONTAL; guide->guide_ID = image->gimp->next_guide_ID++; @@ -54,7 +54,7 @@ gimp_image_add_hguide (GimpImage *image, guide); gimp_image_add_guide (image, guide, position); - gimp_image_guide_unref (guide); + g_object_unref (G_OBJECT (guide)); return guide; } @@ -69,9 +69,8 @@ gimp_image_add_vguide (GimpImage *image, g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (position >= 0 && position <= image->width, NULL); - guide = g_new0 (GimpGuide, 1); + guide = g_object_new (GIMP_TYPE_GUIDE, NULL); - guide->ref_count = 1; guide->position = -1; guide->orientation = GIMP_ORIENTATION_VERTICAL; guide->guide_ID = image->gimp->next_guide_ID++; @@ -81,39 +80,18 @@ gimp_image_add_vguide (GimpImage *image, guide); gimp_image_add_guide (image, guide, position); - gimp_image_guide_unref (guide); + g_object_unref (G_OBJECT (guide)); return guide; } -GimpGuide * -gimp_image_guide_ref (GimpGuide *guide) -{ - g_return_val_if_fail (guide != NULL, NULL); - - guide->ref_count++; - - return guide; -} - -void -gimp_image_guide_unref (GimpGuide *guide) -{ - g_return_if_fail (guide != NULL); - - guide->ref_count--; - - if (guide->ref_count < 1) - g_free (guide); -} - void gimp_image_add_guide (GimpImage *image, GimpGuide *guide, gint position) { g_return_if_fail (GIMP_IS_IMAGE (image)); - g_return_if_fail (guide != NULL); + g_return_if_fail (GIMP_IS_GUIDE (guide)); g_return_if_fail (position >= 0); if (guide->orientation == GIMP_ORIENTATION_HORIZONTAL) @@ -124,7 +102,7 @@ gimp_image_add_guide (GimpImage *image, image->guides = g_list_prepend (image->guides, guide); guide->position = position; - gimp_image_guide_ref (guide); + g_object_ref (G_OBJECT (guide)); gimp_image_update_guide (image, guide); } @@ -135,7 +113,7 @@ gimp_image_remove_guide (GimpImage *image, gboolean push_undo) { g_return_if_fail (GIMP_IS_IMAGE (image)); - g_return_if_fail (guide != NULL); + g_return_if_fail (GIMP_IS_GUIDE (guide)); gimp_image_update_guide (image, guide); @@ -145,7 +123,7 @@ gimp_image_remove_guide (GimpImage *image, image->guides = g_list_remove (image->guides, guide); guide->position = -1; - gimp_image_guide_unref (guide); + g_object_unref (G_OBJECT (guide)); } void @@ -155,7 +133,7 @@ gimp_image_move_guide (GimpImage *image, gboolean push_undo) { g_return_if_fail (GIMP_IS_IMAGE (image)); - g_return_if_fail (guide != NULL); + g_return_if_fail (GIMP_IS_GUIDE (guide)); g_return_if_fail (position >= 0); if (guide->orientation == GIMP_ORIENTATION_HORIZONTAL) diff --git a/app/core/gimpimage-guides.h b/app/core/gimpimage-guides.h index 3f9ded6202..b1637dedce 100644 --- a/app/core/gimpimage-guides.h +++ b/app/core/gimpimage-guides.h @@ -20,15 +20,6 @@ #define __GIMP_IMAGE_GUIDES_H__ -struct _GimpGuide -{ - gint ref_count; - gint position; - GimpOrientationType orientation; - guint32 guide_ID; -}; - - GimpGuide * gimp_image_add_hguide (GimpImage *image, gint position, gboolean push_undo); @@ -36,9 +27,6 @@ GimpGuide * gimp_image_add_vguide (GimpImage *image, gint position, gboolean push_undo); -GimpGuide * gimp_image_guide_ref (GimpGuide *guide); -void gimp_image_guide_unref (GimpGuide *guide); - void gimp_image_add_guide (GimpImage *image, GimpGuide *guide, gint position); diff --git a/app/core/gimpimage-resize.c b/app/core/gimpimage-resize.c index 0c068c151c..0c6fbf478c 100644 --- a/app/core/gimpimage-resize.c +++ b/app/core/gimpimage-resize.c @@ -24,6 +24,7 @@ #include "gimp.h" #include "gimpcontext.h" +#include "gimpguide.h" #include "gimpimage.h" #include "gimpimage-guides.h" #include "gimpimage-item-list.h" diff --git a/app/core/gimpimage-rotate.c b/app/core/gimpimage-rotate.c index eaf61733a5..e8ab166ca3 100644 --- a/app/core/gimpimage-rotate.c +++ b/app/core/gimpimage-rotate.c @@ -24,6 +24,7 @@ #include "gimp.h" #include "gimpcontext.h" +#include "gimpguide.h" #include "gimpimage.h" #include "gimpimage-rotate.h" #include "gimpimage-guides.h" diff --git a/app/core/gimpimage-scale.c b/app/core/gimpimage-scale.c index 8a6573c492..7f116265f5 100644 --- a/app/core/gimpimage-scale.c +++ b/app/core/gimpimage-scale.c @@ -25,6 +25,7 @@ #include "base/tile-manager.h" #include "gimp.h" +#include "gimpguide.h" #include "gimpimage.h" #include "gimpimage-guides.h" #include "gimpimage-sample-points.h" diff --git a/app/core/gimpimage-snap.c b/app/core/gimpimage-snap.c index 3acd34f895..686137476a 100644 --- a/app/core/gimpimage-snap.c +++ b/app/core/gimpimage-snap.c @@ -23,6 +23,7 @@ #include "core-types.h" #include "gimp.h" +#include "gimpguide.h" #include "gimpimage.h" #include "gimpimage-grid.h" #include "gimpimage-guides.h" diff --git a/app/core/gimpimage-undo-push.c b/app/core/gimpimage-undo-push.c index 4e8ed5785f..b2d3787365 100644 --- a/app/core/gimpimage-undo-push.c +++ b/app/core/gimpimage-undo-push.c @@ -35,6 +35,7 @@ #include "gimp-parasites.h" #include "gimp.h" #include "gimpgrid.h" +#include "gimpguide.h" #include "gimpimage-colormap.h" #include "gimpimage-grid.h" #include "gimpimage-guides.h" @@ -347,7 +348,7 @@ gimp_image_undo_push_image_guide (GimpImage *image, { GuideUndo *gu = new->data; - gu->guide = gimp_image_guide_ref (guide); + gu->guide = g_object_ref (guide); gu->position = guide->position; gu->orientation = guide->orientation; @@ -379,7 +380,7 @@ undo_pop_image_guide (GimpUndo *undo, { undo->image->guides = g_list_prepend (undo->image->guides, gu->guide); gu->guide->position = gu->position; - gimp_image_guide_ref (gu->guide); + g_object_ref (gu->guide); gimp_image_update_guide (undo->image, gu->guide); } else if (gu->position == -1) @@ -407,7 +408,7 @@ undo_free_image_guide (GimpUndo *undo, { GuideUndo *gu = undo->data; - gimp_image_guide_unref (gu->guide); + g_object_unref (gu->guide); g_free (gu); } diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index d56b20f382..87adceb5ab 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -40,6 +40,7 @@ #include "gimp-utils.h" #include "gimpcontext.h" #include "gimpgrid.h" +#include "gimpguide.h" #include "gimpimage.h" #include "gimpimage-colorhash.h" #include "gimpimage-colormap.h" @@ -868,7 +869,7 @@ gimp_image_finalize (GObject *object) if (image->guides) { - g_list_foreach (image->guides, (GFunc) gimp_image_guide_unref, NULL); + g_list_foreach (image->guides, (GFunc) g_object_unref, NULL); g_list_free (image->guides); image->guides = NULL; } diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c index 70c2e4f36f..0c40a02413 100644 --- a/app/display/gimpdisplayshell-draw.c +++ b/app/display/gimpdisplayshell-draw.c @@ -25,6 +25,7 @@ #include "core/gimp-utils.h" #include "core/gimpcontext.h" #include "core/gimpgrid.h" +#include "core/gimpguide.h" #include "core/gimpimage.h" #include "core/gimpimage-guides.h" #include "core/gimpimage-sample-points.h" diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index f35a661943..e533c03190 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -36,6 +36,7 @@ #include "core/gimp.h" #include "core/gimpchannel.h" #include "core/gimpcontext.h" +#include "core/gimpguide.h" #include "core/gimpimage.h" #include "core/gimpimage-guides.h" #include "core/gimpimage-sample-points.h" diff --git a/app/pdb/guides_cmds.c b/app/pdb/guides_cmds.c index 7f169a50a6..795aacf323 100644 --- a/app/pdb/guides_cmds.c +++ b/app/pdb/guides_cmds.c @@ -28,6 +28,7 @@ #include "gimpprocedure.h" #include "core/gimpparamspecs.h" +#include "core/gimpguide.h" #include "core/gimpimage-guides.h" #include "core/gimpimage-undo-push.h" #include "core/gimpimage.h" diff --git a/app/tools/gimpmovetool.c b/app/tools/gimpmovetool.c index f0c1b85751..bc4460e131 100644 --- a/app/tools/gimpmovetool.c +++ b/app/tools/gimpmovetool.c @@ -28,6 +28,7 @@ #include "config/gimpguiconfig.h" #include "core/gimp.h" +#include "core/gimpguide.h" #include "core/gimpimage.h" #include "core/gimpimage-guides.h" #include "core/gimplayer.h" diff --git a/app/xcf/xcf-save.c b/app/xcf/xcf-save.c index b813548d87..d6a49dad5d 100644 --- a/app/xcf/xcf-save.c +++ b/app/xcf/xcf-save.c @@ -35,6 +35,7 @@ #include "core/gimpchannel.h" #include "core/gimpdrawable.h" #include "core/gimpgrid.h" +#include "core/gimpguide.h" #include "core/gimpimage.h" #include "core/gimpimage-grid.h" #include "core/gimpimage-guides.h" diff --git a/tools/pdbgen/pdb/guides.pdb b/tools/pdbgen/pdb/guides.pdb index 331368a566..7ba8f2c0c0 100644 --- a/tools/pdbgen/pdb/guides.pdb +++ b/tools/pdbgen/pdb/guides.pdb @@ -239,7 +239,7 @@ CODE } -@headers = qw("core/gimpimage-guides.h" "core/gimpimage-undo-push.h"); +@headers = qw("core/gimpguide.h" "core/gimpimage-guides.h" "core/gimpimage-undo-push.h"); @procs = qw(image_add_hguide image_add_vguide image_delete_guide image_find_next_guide image_get_guide_orientation