[gimp/wip/Jehan/classy-GIMP: 18/50] libgimp: fix the non-generated API with the new class types.



commit 6c807168d0acbaf488ad940f11fff2b2b3ffcddb
Author: Jehan <jehan girinstud io>
Date:   Tue Aug 13 22:54:37 2019 +0200

    libgimp: fix the non-generated API with the new class types.

 libgimp/gimp.c                |  6 ++--
 libgimp/gimp.h                |  2 +-
 libgimp/gimpaspectpreview.c   | 16 ++++-----
 libgimp/gimpchannel.c         | 13 +++++---
 libgimp/gimpchannel.h         | 12 +++----
 libgimp/gimpdrawablepreview.c | 18 +++++------
 libgimp/gimpexport.c          | 14 +++++---
 libgimp/gimpparamspecs.c      |  2 +-
 libgimp/gimpprogress.c        |  8 ++++-
 libgimp/gimpui.c              | 75 +++++++++++++++++++++++++++++++++++++------
 libgimp/gimpui.h              | 23 +++++++++++--
 libgimp/gimpzoompreview.c     | 30 ++++++++---------
 12 files changed, 151 insertions(+), 68 deletions(-)
---
diff --git a/libgimp/gimp.c b/libgimp/gimp.c
index 600542bef9..bf54b5a175 100644
--- a/libgimp/gimp.c
+++ b/libgimp/gimp.c
@@ -836,12 +836,12 @@ gimp_check_type (void)
  *
  * This is a constant value given at plug-in configuration time.
  *
- * Returns: the default display ID
+ * Returns: (transfer full): the default display ID
  **/
-gint32
+GimpDisplay *
 gimp_default_display (void)
 {
-  return _gdisp_ID;
+  return gimp_display_new_by_id (_gdisp_ID);
 }
 
 /**
diff --git a/libgimp/gimp.h b/libgimp/gimp.h
index 5a3631a5ba..43d37e623d 100644
--- a/libgimp/gimp.h
+++ b/libgimp/gimp.h
@@ -175,7 +175,7 @@ gboolean            gimp_export_xmp           (void) G_GNUC_CONST;
 gboolean            gimp_export_iptc          (void) G_GNUC_CONST;
 GimpCheckSize       gimp_check_size           (void) G_GNUC_CONST;
 GimpCheckType       gimp_check_type           (void) G_GNUC_CONST;
-gint32              gimp_default_display      (void) G_GNUC_CONST;
+GimpDisplay       * gimp_default_display      (void) G_GNUC_CONST;
 const gchar       * gimp_wm_class             (void) G_GNUC_CONST;
 const gchar       * gimp_display_name         (void) G_GNUC_CONST;
 gint                gimp_monitor_number       (void) G_GNUC_CONST;
diff --git a/libgimp/gimpaspectpreview.c b/libgimp/gimpaspectpreview.c
index 40ea37fa1b..273dd343c0 100644
--- a/libgimp/gimpaspectpreview.c
+++ b/libgimp/gimpaspectpreview.c
@@ -312,22 +312,20 @@ gimp_aspect_preview_draw_buffer (GimpPreview  *preview,
     }
   else
     {
-      guchar       *sel;
-      guchar       *src;
-      GimpDrawable *selection;
-      gint          selection_ID;
-      gint          w, h;
-      gint          bpp;
+      guchar        *sel;
+      guchar        *src;
+      GimpSelection *selection;
+      gint           w, h;
+      gint           bpp;
 
-      selection_ID = gimp_image_get_selection (image);
-      selection = GIMP_DRAWABLE (gimp_item_new_by_id (selection_ID));
+      selection = gimp_image_get_selection (image);
 
       w = width;
       h = height;
 
       src = gimp_drawable_get_thumbnail_data (priv->drawable,
                                               &w, &h, &bpp);
-      sel = gimp_drawable_get_thumbnail_data (selection,
+      sel = gimp_drawable_get_thumbnail_data (GIMP_DRAWABLE (selection),
                                               &w, &h, &bpp);
       g_object_unref (selection);
 
diff --git a/libgimp/gimpchannel.c b/libgimp/gimpchannel.c
index b81b204244..b379e3576d 100644
--- a/libgimp/gimpchannel.c
+++ b/libgimp/gimpchannel.c
@@ -62,7 +62,7 @@ gimp_channel_init (GimpChannel *channel)
  *
  * Returns: The newly created channel.
  */
-gint32
+GimpChannel *
 gimp_channel_new (GimpImage     *image,
                   const gchar   *name,
                   guint          width,
@@ -111,13 +111,16 @@ gimp_channel_new_deprecated (gint32         image_id,
                              gdouble        opacity,
                              const GimpRGB *color)
 {
-  GimpImage *image = gimp_image_new_by_id (image_id);
-  gint32     channel_id;
+  GimpImage   *image = gimp_image_new_by_id (image_id);
+  GimpChannel *channel;
+  gint32       channel_id;
 
-  channel_id = gimp_channel_new (image, name, width, height,
-                                 opacity, color);
+  channel = gimp_channel_new (image, name, width, height,
+                              opacity, color);
+  channel_id = gimp_item_get_id (GIMP_ITEM (channel));
 
   g_object_unref (image);
+  g_object_unref (channel);
 
   return channel_id;
 }
diff --git a/libgimp/gimpchannel.h b/libgimp/gimpchannel.h
index 73b7b6c775..d77bca7938 100644
--- a/libgimp/gimpchannel.h
+++ b/libgimp/gimpchannel.h
@@ -67,12 +67,12 @@ GType    gimp_channel_get_type           (void) G_GNUC_CONST;
 
 #ifndef GIMP_DEPRECATED_REPLACE_NEW_API
 
-gint32  gimp_channel_new (GimpImage     *image,
-                          const gchar   *name,
-                          guint          width,
-                          guint          height,
-                          gdouble        opacity,
-                          const GimpRGB *color);
+GimpChannel *  gimp_channel_new (GimpImage     *image,
+                                 const gchar   *name,
+                                 guint          width,
+                                 guint          height,
+                                 gdouble        opacity,
+                                 const GimpRGB *color);
 
 #else /* GIMP_DEPRECATED_REPLACE_NEW_API */
 
diff --git a/libgimp/gimpdrawablepreview.c b/libgimp/gimpdrawablepreview.c
index c62a6a361e..dde86cc3a7 100644
--- a/libgimp/gimpdrawablepreview.c
+++ b/libgimp/gimpdrawablepreview.c
@@ -447,13 +447,12 @@ gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
                                     &draw_x, &draw_y,
                                     &draw_width, &draw_height))
         {
-          GimpImageType  type;
-          GimpDrawable  *selection;
-          gint32         selection_ID;
-          guchar        *src;
-          guchar        *sel;
-          gint           d_w, d_h, d_bpp;
-          gint           s_w, s_h, s_bpp;
+          GimpImageType   type;
+          GimpSelection  *selection;
+          guchar         *src;
+          guchar         *sel;
+          gint            d_w, d_h, d_bpp;
+          gint            s_w, s_h, s_bpp;
 
           d_w = draw_width;
           d_h = draw_height;
@@ -461,8 +460,7 @@ gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
           s_w = draw_width;
           s_h = draw_height;
 
-          selection_ID = gimp_image_get_selection (image);
-          selection = GIMP_DRAWABLE (gimp_item_new_by_id (selection_ID));
+          selection = gimp_image_get_selection (image);
 
           src = gimp_drawable_get_sub_thumbnail_data (priv->drawable,
                                                       draw_x, draw_y,
@@ -470,7 +468,7 @@ gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
                                                       &d_w, &d_h,
                                                       &d_bpp);
 
-          sel = gimp_drawable_get_sub_thumbnail_data (selection,
+          sel = gimp_drawable_get_sub_thumbnail_data (GIMP_DRAWABLE (selection),
                                                       draw_x + offset_x,
                                                       draw_y + offset_y,
                                                       draw_width, draw_height,
diff --git a/libgimp/gimpexport.c b/libgimp/gimpexport.c
index 290a09af49..c9de679e76 100644
--- a/libgimp/gimpexport.c
+++ b/libgimp/gimpexport.c
@@ -206,13 +206,16 @@ export_apply_masks (GimpImage     *image,
 
   for (i = 0; i < n_layers; i++)
     {
-      GimpLayer *layer;
+      GimpLayer     *layer;
+      GimpLayerMask *mask;
 
       layer = GIMP_LAYER (gimp_item_new_by_id (layers[i]));
-      if (gimp_layer_get_mask (layer) != -1)
+      mask = gimp_layer_get_mask (layer);
+      if (mask)
         gimp_layer_remove_mask (layer, GIMP_MASK_APPLY);
 
       g_object_unref (layer);
+      g_clear_object (&mask);
     }
 
   g_free (layers);
@@ -864,12 +867,15 @@ gimp_export_image (GimpImage             **image,
     {
       for (i = 0; i < n_layers; i++)
         {
-          GimpLayer *layer = GIMP_LAYER (gimp_item_new_by_id (layers[i]));
+          GimpLayer     *layer = GIMP_LAYER (gimp_item_new_by_id (layers[i]));
+          GimpLayerMask *mask;
 
-          if (gimp_layer_get_mask (layer) != -1)
+          mask = gimp_layer_get_mask (layer);
+          if (mask)
             has_layer_masks = TRUE;
 
           g_object_unref (layer);
+          g_clear_object (&mask);
         }
     }
 
diff --git a/libgimp/gimpparamspecs.c b/libgimp/gimpparamspecs.c
index 19ebfc2c1f..7252e11ea8 100644
--- a/libgimp/gimpparamspecs.c
+++ b/libgimp/gimpparamspecs.c
@@ -1291,7 +1291,7 @@ gimp_param_display_id_validate (GParamSpec *pspec,
   if (ispec->none_ok && (display_id == 0 || display_id == -1))
     return FALSE;
 
-  if (! gimp_display_is_valid (display_id))
+  if (! _gimp_display_is_valid (display_id))
     {
       value->data[0].v_int = -1;
       return TRUE;
diff --git a/libgimp/gimpprogress.c b/libgimp/gimpprogress.c
index c9a3a6ded2..9ffdd570fd 100644
--- a/libgimp/gimpprogress.c
+++ b/libgimp/gimpprogress.c
@@ -181,9 +181,15 @@ gimp_progress_uninstall (const gchar *progress_callback)
 gboolean
 gimp_progress_init (const gchar  *message)
 {
+  GimpDisplay *display = gimp_default_display ();
+  gboolean     success;
+
   gimp_progress_current = 0.0;
 
-  return _gimp_progress_init (message, gimp_default_display ());
+  success = _gimp_progress_init (message, display);
+  g_clear_object (&display);
+
+  return success;
 }
 
 /**
diff --git a/libgimp/gimpui.c b/libgimp/gimpui.c
index 64fcd475c1..b362a48e26 100644
--- a/libgimp/gimpui.c
+++ b/libgimp/gimpui.c
@@ -195,7 +195,7 @@ gimp_ui_get_foreign_window (guint32 window)
 
 /**
  * gimp_ui_get_display_window:
- * @gdisp_ID: a GimpDisplay ID.
+ * @display: a #GimpDisplay.
  *
  * Returns the #GdkWindow of a display window. The purpose is to allow
  * to make plug-in dialogs transient to the image display as explained
@@ -211,13 +211,13 @@ gimp_ui_get_foreign_window (guint32 window)
  * Since: 2.4
  */
 GdkWindow *
-gimp_ui_get_display_window (guint32 gdisp_ID)
+gimp_ui_get_display_window (GimpDisplay *display)
 {
   guint32 window;
 
   g_return_val_if_fail (gimp_ui_initialized, NULL);
 
-  window = gimp_display_get_window_handle (gdisp_ID);
+  window = gimp_display_get_window_handle (display);
   if (window)
     return gimp_ui_get_foreign_window (window);
 
@@ -267,12 +267,12 @@ gimp_window_transient_show (GtkWidget *window)
 
 /**
  * gimp_window_set_transient_for_display:
- * @window:   the #GtkWindow that should become transient
- * @gdisp_ID: display ID of the image window that should become the parent
+ * @window:  the #GtkWindow that should become transient
+ * @display: display of the image window that should become the parent
  *
  * Indicates to the window manager that @window is a transient dialog
  * associated with the GIMP image window that is identified by it's
- * display ID.  See gdk_window_set_transient_for () for more information.
+ * display ID. See gdk_window_set_transient_for () for more information.
  *
  * Most of the time you will want to use the convenience function
  * gimp_window_set_transient().
@@ -280,14 +280,14 @@ gimp_window_transient_show (GtkWidget *window)
  * Since: 2.4
  */
 void
-gimp_window_set_transient_for_display (GtkWindow *window,
-                                       guint32    gdisp_ID)
+gimp_window_set_transient_for_display (GtkWindow   *window,
+                                       GimpDisplay *display)
 {
   g_return_if_fail (gimp_ui_initialized);
   g_return_if_fail (GTK_IS_WINDOW (window));
 
   if (! gimp_window_set_transient_for (window,
-                                       gimp_ui_get_display_window (gdisp_ID)))
+                                       gimp_ui_get_display_window (display)))
     {
       /*  if setting the window transient failed, at least set
        *  WIN_POS_CENTER, which will center the window on the screen
@@ -448,3 +448,60 @@ gimp_osx_focus_window (void)
   [NSApp activateIgnoringOtherApps:YES];
 }
 #endif
+
+
+/* Deprecated API. */
+
+
+/**
+ * gimp_ui_get_display_window_deprecated: (skip)
+ * @gdisp_ID: a GimpDisplay ID.
+ *
+ * Returns the #GdkWindow of a display window. The purpose is to allow
+ * to make plug-in dialogs transient to the image display as explained
+ * with gdk_window_set_transient_for().
+ *
+ * You shouldn't have to call this function directly. Use
+ * gimp_window_set_transient_for_display() instead.
+ *
+ * Returns: (nullable) (transfer full): A reference to a #GdkWindow or %NULL.
+ *               You should unref the window using g_object_unref() as
+ *               soon as you don't need it any longer.
+ *
+ * Since: 2.4
+ */
+GdkWindow *
+gimp_ui_get_display_window_deprecated (guint32 gdisp_ID)
+{
+  GimpDisplay *display = gimp_display_new_by_id (gdisp_ID);
+  GdkWindow   *window;
+
+  window = gimp_ui_get_display_window (display);
+  g_object_unref (display);
+
+  return window;
+}
+
+/**
+ * gimp_window_set_transient_for_display_deprecated: (skip)
+ * @window:   the #GtkWindow that should become transient
+ * @gdisp_ID: display ID of the image window that should become the parent
+ *
+ * Indicates to the window manager that @window is a transient dialog
+ * associated with the GIMP image window that is identified by it's
+ * display ID.  See gdk_window_set_transient_for () for more information.
+ *
+ * Most of the time you will want to use the convenience function
+ * gimp_window_set_transient().
+ *
+ * Since: 2.4
+ */
+void
+gimp_window_set_transient_for_display_deprecated (GtkWindow *window,
+                                                  guint32    gdisp_ID)
+{
+  GimpDisplay *display = gimp_display_new_by_id (gdisp_ID);
+
+  gimp_window_set_transient_for_display (window, display);
+  g_object_unref (display);
+}
diff --git a/libgimp/gimpui.h b/libgimp/gimpui.h
index 0aef97e45e..c3302bf569 100644
--- a/libgimp/gimpui.h
+++ b/libgimp/gimpui.h
@@ -54,13 +54,30 @@ G_BEGIN_DECLS
 void        gimp_ui_init                          (const gchar *prog_name,
                                                    gboolean     preview);
 
-GdkWindow * gimp_ui_get_display_window            (guint32      gdisp_ID);
 GdkWindow * gimp_ui_get_progress_window           (void);
 
-void        gimp_window_set_transient_for_display (GtkWindow   *window,
-                                                   guint32      gdisp_ID);
 void        gimp_window_set_transient             (GtkWindow   *window);
 
+
+#ifndef GIMP_DEPRECATED_REPLACE_NEW_API
+
+GdkWindow * gimp_ui_get_display_window            (GimpDisplay *display);
+void        gimp_window_set_transient_for_display (GtkWindow   *window,
+                                                   GimpDisplay *display);
+
+#else /* GIMP_DEPRECATED_REPLACE_NEW_API */
+
+#define gimp_ui_get_display_window            gimp_ui_get_display_window_deprecated
+#define gimp_window_set_transient_for_display gimp_window_set_transient_for_display_deprecated
+
+#endif /* GIMP_DEPRECATED_REPLACE_NEW_API */
+
+
+GdkWindow * gimp_ui_get_display_window_deprecated            (guint32      gdisp_ID);
+void        gimp_window_set_transient_for_display_deprecated (GtkWindow   *window,
+                                                              guint32      gdisp_ID);
+
+
 G_END_DECLS
 
 #endif /* __GIMP_UI_H__ */
diff --git a/libgimp/gimpzoompreview.c b/libgimp/gimpzoompreview.c
index 490a558b1e..038d502988 100644
--- a/libgimp/gimpzoompreview.c
+++ b/libgimp/gimpzoompreview.c
@@ -517,21 +517,19 @@ gimp_zoom_preview_draw_buffer (GimpPreview  *preview,
     }
   else
     {
-      guchar       *sel;
-      guchar       *src;
-      GimpDrawable *selection;
-      gint          selection_ID;
-      gint          w, h;
-      gint          bpp;
-      gint          src_x;
-      gint          src_y;
-      gint          src_width;
-      gint          src_height;
-      gint          offsx = 0;
-      gint          offsy = 0;
-
-      selection_ID = gimp_image_get_selection (image);
-      selection = GIMP_DRAWABLE (gimp_item_new_by_id (selection_ID));
+      guchar        *sel;
+      guchar        *src;
+      GimpSelection *selection;
+      gint           w, h;
+      gint           bpp;
+      gint           src_x;
+      gint           src_y;
+      gint           src_width;
+      gint           src_height;
+      gint           offsx = 0;
+      gint           offsy = 0;
+
+      selection = gimp_image_get_selection (image);
 
       w = width;
       h = height;
@@ -545,7 +543,7 @@ gimp_zoom_preview_draw_buffer (GimpPreview  *preview,
                                                   src_width, src_height,
                                                   &w, &h, &bpp);
       gimp_drawable_offsets (priv->drawable, &offsx, &offsy);
-      sel = gimp_drawable_get_sub_thumbnail_data (selection,
+      sel = gimp_drawable_get_sub_thumbnail_data (GIMP_DRAWABLE (selection),
                                                   src_x + offsx, src_y + offsy,
                                                   src_width, src_height,
                                                   &width, &height, &bpp);


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