[gimp] Move "disp_count" and "instance_count" to GimpImagePrivate



commit 0b2c804e9d9ea702d428a8e3ace8cb7a487ddf62
Author: Michael Natterer <mitch gimp org>
Date:   Wed Feb 3 21:20:29 2010 +0100

    Move "disp_count" and "instance_count" to GimpImagePrivate
    
    and add the neccessary API to access and modify them.

 app/actions/images-actions.c         |   14 +++++++---
 app/actions/images-commands.c        |    2 +-
 app/core/gimpimage-private.h         |    3 ++
 app/core/gimpimage.c                 |   47 ++++++++++++++++++++++++++++++++-
 app/core/gimpimage.h                 |   13 +++++++--
 app/display/gimpdisplay-foreach.c    |    6 ++--
 app/display/gimpdisplay.c            |    7 +++--
 app/display/gimpdisplayshell-close.c |   10 +++---
 app/pdb/display-cmds.c               |    8 +++---
 app/pdb/image-cmds.c                 |    2 +-
 tools/pdbgen/pdb/display.pdb         |    8 +++---
 tools/pdbgen/pdb/image.pdb           |    2 +-
 12 files changed, 91 insertions(+), 31 deletions(-)
---
diff --git a/app/actions/images-actions.c b/app/actions/images-actions.c
index e66d490..87d939c 100644
--- a/app/actions/images-actions.c
+++ b/app/actions/images-actions.c
@@ -75,18 +75,24 @@ void
 images_actions_update (GimpActionGroup *group,
                        gpointer         data)
 {
-  GimpContext *context = action_data_get_context (data);
-  GimpImage   *image   = NULL;
+  GimpContext *context    = action_data_get_context (data);
+  GimpImage   *image      = NULL;
+  gint         disp_count = 0;
 
   if (context)
-    image = gimp_context_get_image (context);
+    {
+      image = gimp_context_get_image (context);
+
+      if (image)
+        disp_count = gimp_image_get_display_count (image);
+    }
 
 #define SET_SENSITIVE(action,condition) \
         gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
 
   SET_SENSITIVE ("images-raise-views", image);
   SET_SENSITIVE ("images-new-view",    image);
-  SET_SENSITIVE ("images-delete",      image && image->disp_count == 0);
+  SET_SENSITIVE ("images-delete",      image && disp_count == 0);
 
 #undef SET_SENSITIVE
 }
diff --git a/app/actions/images-commands.c b/app/actions/images-commands.c
index ee52b49..d314a19 100644
--- a/app/actions/images-commands.c
+++ b/app/actions/images-commands.c
@@ -104,7 +104,7 @@ images_delete_image_cmd_callback (GtkAction *action,
 
   if (image && gimp_container_have (container, GIMP_OBJECT (image)))
     {
-      if (image->disp_count == 0)
+      if (gimp_image_get_display_count (image) == 0)
         g_object_unref (image);
     }
 }
diff --git a/app/core/gimpimage-private.h b/app/core/gimpimage-private.h
index cf79832..67dc115 100644
--- a/app/core/gimpimage-private.h
+++ b/app/core/gimpimage-private.h
@@ -44,6 +44,9 @@ struct _GimpImagePrivate
   gint               export_dirty;          /*  'dirty' but for export       */
 
   gint               undo_freeze_count;     /*  counts the _freeze's         */
+
+  gint               instance_count;        /*  number of instances          */
+  gint               disp_count;            /*  number of displays           */
 };
 
 #define GIMP_IMAGE_GET_PRIVATE(image) \
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 22189c7..c9004c7 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -607,8 +607,8 @@ gimp_image_init (GimpImage *image)
 
   private->export_dirty        = 1;
 
-  image->instance_count        = 0;
-  image->disp_count            = 0;
+  private->instance_count      = 0;
+  private->disp_count          = 0;
 
   image->tattoo_state          = 0;
 
@@ -2228,6 +2228,49 @@ gimp_image_flush (GimpImage *image)
 }
 
 
+/*  display / instance counters  */
+
+gint
+gimp_image_get_display_count (const GimpImage *image)
+{
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), 0);
+
+  return GIMP_IMAGE_GET_PRIVATE (image)->disp_count;
+}
+
+void
+gimp_image_inc_display_count (GimpImage *image)
+{
+  g_return_if_fail (GIMP_IS_IMAGE (image));
+
+  GIMP_IMAGE_GET_PRIVATE (image)->disp_count++;
+}
+
+void
+gimp_image_dec_display_count (GimpImage *image)
+{
+  g_return_if_fail (GIMP_IS_IMAGE (image));
+
+  GIMP_IMAGE_GET_PRIVATE (image)->disp_count--;
+}
+
+gint
+gimp_image_get_instance_count (const GimpImage *image)
+{
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), 0);
+
+  return GIMP_IMAGE_GET_PRIVATE (image)->instance_count;
+}
+
+void
+gimp_image_inc_instance_count (GimpImage *image)
+{
+  g_return_if_fail (GIMP_IS_IMAGE (image));
+
+  GIMP_IMAGE_GET_PRIVATE (image)->instance_count++;
+}
+
+
 /*  color transforms / utilities  */
 
 void
diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h
index 301fbfc..d5520b1 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -105,9 +105,6 @@ struct _GimpImage
 
   Gimp              *gimp;                  /*  the GIMP the image belongs to*/
 
-  gint               instance_count;        /*  number of instances          */
-  gint               disp_count;            /*  number of displays           */
-
   GimpTattoo         tattoo_state;          /*  the last used tattoo         */
 
   GimpProjection    *projection;            /*  projection layers & channels */
@@ -344,6 +341,16 @@ gint            gimp_image_get_dirty_time        (const GimpImage    *image);
 void            gimp_image_flush                 (GimpImage          *image);
 
 
+/*  display / instance counters  */
+
+gint            gimp_image_get_display_count     (const GimpImage    *image);
+void            gimp_image_inc_display_count     (GimpImage          *image);
+void            gimp_image_dec_display_count     (GimpImage          *image);
+
+gint            gimp_image_get_instance_count    (const GimpImage    *image);
+void            gimp_image_inc_instance_count    (GimpImage          *image);
+
+
 /*  color transforms / utilities  */
 
 void            gimp_image_get_foreground        (const GimpImage    *image,
diff --git a/app/display/gimpdisplay-foreach.c b/app/display/gimpdisplay-foreach.c
index a0fbc0f..831da9b 100644
--- a/app/display/gimpdisplay-foreach.c
+++ b/app/display/gimpdisplay-foreach.c
@@ -60,8 +60,8 @@ gimp_displays_image_dirty_callback (GimpImage     *image,
                                     GimpDirtyMask  dirty_mask,
                                     GimpContainer *container)
 {
-  if (gimp_image_is_dirty (image) &&
-      image->disp_count > 0 &&
+  if (gimp_image_is_dirty (image)              &&
+      gimp_image_get_display_count (image) > 0 &&
       ! gimp_container_have (container, GIMP_OBJECT (image)))
     gimp_container_add (container, GIMP_OBJECT (image));
 }
@@ -133,7 +133,7 @@ gimp_displays_get_dirty_images (Gimp *gimp)
           GimpImage *image = list->data;
 
           if (gimp_image_is_dirty (image) &&
-              image->disp_count > 0)
+              gimp_image_get_display_count (image) > 0)
             gimp_container_add (container, GIMP_OBJECT (image));
         }
 
diff --git a/app/display/gimpdisplay.c b/app/display/gimpdisplay.c
index 9b2f62c..09fc6f0 100644
--- a/app/display/gimpdisplay.c
+++ b/app/display/gimpdisplay.c
@@ -622,7 +622,7 @@ gimp_display_set_image (GimpDisplay *display,
 
       gimp_display_disconnect (display);
 
-      display->image->disp_count--;
+      gimp_image_inc_display_count (display->image);
 
       /*  set display->image before unrefing because there may be code
        *  that listens for image removals and then iterates the
@@ -647,9 +647,10 @@ gimp_display_set_image (GimpDisplay *display,
 
       g_object_ref (image);
 
-      private->instance = image->instance_count++;
+      private->instance = gimp_image_get_instance_count (image);
+      gimp_image_inc_instance_count (image);
 
-      image->disp_count++;
+      gimp_image_dec_display_count (image);
 
       gimp_display_connect (display);
 
diff --git a/app/display/gimpdisplayshell-close.c b/app/display/gimpdisplayshell-close.c
index bc3ac50..8dc8fff 100644
--- a/app/display/gimpdisplayshell-close.c
+++ b/app/display/gimpdisplayshell-close.c
@@ -85,10 +85,10 @@ gimp_display_shell_close (GimpDisplayShell *shell,
    *  it before nuking it--this only applies if its the last view
    *  to an image canvas.  (a image with disp_count = 1)
    */
-  if (! kill_it                   &&
-      image                       &&
-      image->disp_count == 1      &&
-      gimp_image_is_dirty (image) &&
+  if (! kill_it                                 &&
+      image                                     &&
+      gimp_image_get_display_count (image) == 1 &&
+      gimp_image_is_dirty (image)               &&
       shell->display->config->confirm_on_close)
     {
       /*  If there's a save dialog active for this image, then raise it.
@@ -238,7 +238,7 @@ static gboolean
 gimp_display_shell_close_time_changed (GimpMessageBox *box)
 {
   GimpImage *image      = g_object_get_data (G_OBJECT (box), "gimp-image");
-  gint      *dirty_time = gimp_image_get_dirty_time (image);
+  gint       dirty_time = gimp_image_get_dirty_time (image);
 
   if (dirty_time)
     {
diff --git a/app/pdb/display-cmds.c b/app/pdb/display-cmds.c
index ed3a520..9c2c898 100644
--- a/app/pdb/display-cmds.c
+++ b/app/pdb/display-cmds.c
@@ -79,7 +79,7 @@ display_new_invoker (GimpProcedure      *procedure,
       if (display)
         {
           /* the first display takes ownership of the image */
-          if (image->disp_count == 1)
+          if (gimp_image_get_display_count (image) == 1)
             g_object_unref (image);
         }
       else
@@ -179,15 +179,15 @@ displays_reconnect_invoker (GimpProcedure      *procedure,
   if (success)
     {
       success = (old_image != new_image    &&
-                 old_image->disp_count > 0 &&
-                 new_image->disp_count == 0);
+                 gimp_image_get_display_count (old_image) > 0 &&
+                 gimp_image_get_display_count (new_image) == 0);
 
       if (success)
         {
           gimp_reconnect_displays (gimp, old_image, new_image);
 
           /* take ownership of the image */
-          if (new_image->disp_count > 0)
+          if (gimp_image_get_display_count (new_image) > 0)
             g_object_unref (new_image);
         }
     }
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index 0c581d8..1a8c577 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -210,7 +210,7 @@ image_delete_invoker (GimpProcedure      *procedure,
 
   if (success)
     {
-      if (image->disp_count == 0)
+      if (gimp_image_get_display_count (image) == 0)
         g_object_unref (image);
       else
         success = FALSE;
diff --git a/tools/pdbgen/pdb/display.pdb b/tools/pdbgen/pdb/display.pdb
index 90256c9..edebd63 100644
--- a/tools/pdbgen/pdb/display.pdb
+++ b/tools/pdbgen/pdb/display.pdb
@@ -78,7 +78,7 @@ HELP
   if (display)
     {
       /* the first display takes ownership of the image */
-      if (image->disp_count == 1)
+      if (gimp_image_get_display_count (image) == 1)
         g_object_unref (image);
     }
   else
@@ -192,15 +192,15 @@ HELP
 	code => <<'CODE'
 {
   success = (old_image != new_image    &&
-             old_image->disp_count > 0 &&
-             new_image->disp_count == 0);
+             gimp_image_get_display_count (old_image) > 0 &&
+             gimp_image_get_display_count (new_image) == 0);
 
   if (success)
     {
       gimp_reconnect_displays (gimp, old_image, new_image);
 
       /* take ownership of the image */
-      if (new_image->disp_count > 0)
+      if (gimp_image_get_display_count (new_image) > 0)
         g_object_unref (new_image);
     }
 }
diff --git a/tools/pdbgen/pdb/image.pdb b/tools/pdbgen/pdb/image.pdb
index f1127ec..d9045cf 100644
--- a/tools/pdbgen/pdb/image.pdb
+++ b/tools/pdbgen/pdb/image.pdb
@@ -177,7 +177,7 @@ HELP
     %invoke = (
 	code => <<'CODE'
 {
-  if (image->disp_count == 0)
+  if (gimp_image_get_display_count (image) == 0)
     g_object_unref (image);
   else
     success = FALSE;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]