[gimp/wip/Jehan/classy-GIMP: 11/50] libgimp: update non-generated API using GimpItem/GimpDrawable/GimpLayer.



commit 3f1491e5720eaf94a73a7a0baf454743e8792802
Author: Jehan <jehan girinstud io>
Date:   Tue Aug 13 16:16:08 2019 +0200

    libgimp: update non-generated API using GimpItem/GimpDrawable/GimpLayer.
    
    I did the same trick with GIMP_DEPRECATED_REPLACE_NEW_API macro, apart
    for some minor widget API to preview drawable, which I will fix right
    away in our plug-ins.

 libgimp/gimpaspectpreview.c     | 111 ++++++-------
 libgimp/gimpaspectpreview.h     |   2 +-
 libgimp/gimpdrawable.c          | 337 +++++++++++++++++++++++++++++++++++-----
 libgimp/gimpdrawable.h          |  64 +++++++-
 libgimp/gimpdrawablepreview.c   | 148 +++++++++---------
 libgimp/gimpdrawablepreview.h   |   8 +-
 libgimp/gimpexport.c            | 200 +++++++++++++++---------
 libgimp/gimpexport.h            |   2 +-
 libgimp/gimpimagemetadata.c     |  15 +-
 libgimp/gimpitemcombobox.c      |  14 +-
 libgimp/gimplayer.c             | 100 ++++++++----
 libgimp/gimplayer.h             |  46 +++---
 libgimp/gimpparamspecs.c        |  14 +-
 libgimp/gimpselection.c         |  63 +++++++-
 libgimp/gimpselection.h         |  22 ++-
 libgimp/gimptilebackendplugin.c |  14 +-
 libgimp/gimptilebackendplugin.h |   4 +-
 libgimp/gimpzoompreview.c       | 162 +++++++++----------
 libgimp/gimpzoompreview.h       |   9 +-
 19 files changed, 908 insertions(+), 427 deletions(-)
---
diff --git a/libgimp/gimpaspectpreview.c b/libgimp/gimpaspectpreview.c
index c2441bacff..40ea37fa1b 100644
--- a/libgimp/gimpaspectpreview.c
+++ b/libgimp/gimpaspectpreview.c
@@ -46,12 +46,12 @@
 enum
 {
   PROP_0,
-  PROP_DRAWABLE_ID
+  PROP_DRAWABLE
 };
 
 struct _GimpAspectPreviewPrivate
 {
-  gint32 drawable_ID;
+  GimpDrawable *drawable;
 };
 
 typedef struct
@@ -89,9 +89,8 @@ static void  gimp_aspect_preview_untransform   (GimpPreview     *preview,
                                                 gint            *dest_x,
                                                 gint            *dest_y);
 
-static void  gimp_aspect_preview_set_drawable_id
-                                               (GimpAspectPreview *preview,
-                                                gint32             drawable_ID);
+static void  gimp_aspect_preview_set_drawable  (GimpAspectPreview *preview,
+                                                GimpDrawable      *drawable);
 
 
 G_DEFINE_TYPE_WITH_PRIVATE (GimpAspectPreview, gimp_aspect_preview,
@@ -128,13 +127,13 @@ gimp_aspect_preview_class_init (GimpAspectPreviewClass *klass)
    *
    * Since: 2.10
    */
-  g_object_class_install_property (object_class, PROP_DRAWABLE_ID,
-                                   g_param_spec_int ("drawable-id",
-                                                     "Drawable ID",
-                                                     "The drawable this preview is attached to",
-                                                     -1, G_MAXINT, -1,
-                                                     GIMP_PARAM_READWRITE |
-                                                     G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property (object_class, PROP_DRAWABLE,
+                                   g_param_spec_object ("drawable",
+                                                        "Drawable",
+                                                        "The drawable this preview is attached to",
+                                                        GIMP_TYPE_DRAWABLE,
+                                                        GIMP_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT_ONLY));
 }
 
 static void
@@ -172,9 +171,11 @@ gimp_aspect_preview_constructed (GObject *object)
 static void
 gimp_aspect_preview_dispose (GObject *object)
 {
-  const gchar *data_name = g_object_get_data (G_OBJECT (object),
-                                              "gimp-aspect-preview-data-name");
+  GimpAspectPreviewPrivate *priv = GET_PRIVATE (object);
+  const gchar              *data_name;
 
+  data_name = g_object_get_data (G_OBJECT (object),
+                                 "gimp-aspect-preview-data-name");
   if (data_name)
     {
       GimpPreview     *preview = GIMP_PREVIEW (object);
@@ -185,6 +186,8 @@ gimp_aspect_preview_dispose (GObject *object)
       gimp_set_data (data_name, &settings, sizeof (PreviewSettings));
     }
 
+  g_clear_object (&priv->drawable);
+
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
@@ -199,8 +202,8 @@ gimp_aspect_preview_get_property (GObject    *object,
 
   switch (property_id)
     {
-    case PROP_DRAWABLE_ID:
-      g_value_set_int (value, priv->drawable_ID);
+    case PROP_DRAWABLE:
+      g_value_set_object (value, priv->drawable);
       break;
 
     default:
@@ -211,17 +214,16 @@ gimp_aspect_preview_get_property (GObject    *object,
 
 static void
 gimp_aspect_preview_set_property (GObject      *object,
-                                    guint         property_id,
-                                    const GValue *value,
-                                    GParamSpec   *pspec)
+                                  guint         property_id,
+                                  const GValue *value,
+                                  GParamSpec   *pspec)
 {
   GimpAspectPreview *preview = GIMP_ASPECT_PREVIEW (object);
 
   switch (property_id)
     {
-    case PROP_DRAWABLE_ID:
-      gimp_aspect_preview_set_drawable_id (preview,
-                                           g_value_get_int (value));
+    case PROP_DRAWABLE:
+      gimp_aspect_preview_set_drawable (preview, g_value_dup_object (value));
       break;
 
     default:
@@ -247,8 +249,8 @@ gimp_aspect_preview_style_updated (GtkWidget *widget)
       gint                      preview_height;
       gint                      size;
 
-      width  = gimp_drawable_width  (priv->drawable_ID);
-      height = gimp_drawable_height (priv->drawable_ID);
+      width  = gimp_drawable_width  (priv->drawable);
+      height = gimp_drawable_height (priv->drawable);
 
       gtk_widget_style_get (widget,
                             "size", &size,
@@ -297,39 +299,42 @@ gimp_aspect_preview_draw_buffer (GimpPreview  *preview,
 
   gimp_preview_get_size (preview, &width, &height);
 
-  image = gimp_item_get_image (priv->drawable_ID);
+  image = gimp_item_get_image (GIMP_ITEM (priv->drawable));
 
   if (gimp_selection_is_empty (image))
     {
       gimp_preview_area_draw (GIMP_PREVIEW_AREA (area),
                               0, 0,
                               width, height,
-                              gimp_drawable_type (priv->drawable_ID),
+                              gimp_drawable_type (priv->drawable),
                               buffer,
                               rowstride);
     }
   else
     {
-      guchar *sel;
-      guchar *src;
-      gint    selection_ID;
-      gint    w, h;
-      gint    bpp;
+      guchar       *sel;
+      guchar       *src;
+      GimpDrawable *selection;
+      gint          selection_ID;
+      gint          w, h;
+      gint          bpp;
 
       selection_ID = gimp_image_get_selection (image);
+      selection = GIMP_DRAWABLE (gimp_item_new_by_id (selection_ID));
 
       w = width;
       h = height;
 
-      src = gimp_drawable_get_thumbnail_data (priv->drawable_ID,
+      src = gimp_drawable_get_thumbnail_data (priv->drawable,
                                               &w, &h, &bpp);
-      sel = gimp_drawable_get_thumbnail_data (selection_ID,
+      sel = gimp_drawable_get_thumbnail_data (selection,
                                               &w, &h, &bpp);
+      g_object_unref (selection);
 
       gimp_preview_area_mask (GIMP_PREVIEW_AREA (area),
                               0, 0, width, height,
-                              gimp_drawable_type (priv->drawable_ID),
-                              src, width * gimp_drawable_bpp (priv->drawable_ID),
+                              gimp_drawable_type (priv->drawable),
+                              src, width * gimp_drawable_bpp (priv->drawable),
                               buffer, rowstride,
                               sel, width);
 
@@ -352,8 +357,8 @@ gimp_aspect_preview_transform (GimpPreview *preview,
 
   gimp_preview_get_size (preview, &width, &height);
 
-  *dest_x = (gdouble) src_x * width  / gimp_drawable_width  (priv->drawable_ID);
-  *dest_y = (gdouble) src_y * height / gimp_drawable_height (priv->drawable_ID);
+  *dest_x = (gdouble) src_x * width  / gimp_drawable_width  (priv->drawable);
+  *dest_y = (gdouble) src_y * height / gimp_drawable_height (priv->drawable);
 }
 
 static void
@@ -369,13 +374,13 @@ gimp_aspect_preview_untransform (GimpPreview *preview,
 
   gimp_preview_get_size (preview, &width, &height);
 
-  *dest_x = (gdouble) src_x * gimp_drawable_width  (priv->drawable_ID) / width;
-  *dest_y = (gdouble) src_y * gimp_drawable_height (priv->drawable_ID) / height;
+  *dest_x = (gdouble) src_x * gimp_drawable_width  (priv->drawable) / width;
+  *dest_y = (gdouble) src_y * gimp_drawable_height (priv->drawable) / height;
 }
 
 static void
-gimp_aspect_preview_set_drawable_id (GimpAspectPreview *preview,
-                                     gint32             drawable_ID)
+gimp_aspect_preview_set_drawable (GimpAspectPreview *preview,
+                                  GimpDrawable      *drawable)
 {
   GimpAspectPreviewPrivate *priv = GET_PRIVATE (preview);
   gint                      d_width;
@@ -383,12 +388,12 @@ gimp_aspect_preview_set_drawable_id (GimpAspectPreview *preview,
   gint                      width;
   gint                      height;
 
-  g_return_if_fail (priv->drawable_ID < 1);
+  g_return_if_fail (priv->drawable == NULL);
 
-  priv->drawable_ID = drawable_ID;
+  priv->drawable = drawable;
 
-  d_width  = gimp_drawable_width  (priv->drawable_ID);
-  d_height = gimp_drawable_height (priv->drawable_ID);
+  d_width  = gimp_drawable_width  (priv->drawable);
+  d_height = gimp_drawable_height (priv->drawable);
 
   if (d_width > d_height)
     {
@@ -411,23 +416,23 @@ gimp_aspect_preview_set_drawable_id (GimpAspectPreview *preview,
 }
 
 /**
- * gimp_aspect_preview_new_from_drawable_id:
- * @drawable_ID: a drawable ID
+ * gimp_aspect_preview_new_from_drawable:
+ * @drawable: (transfer none): a drawable
  *
- * Creates a new #GimpAspectPreview widget for @drawable_ID. See also
- * gimp_drawable_preview_new_from_drawable_id().
+ * Creates a new #GimpAspectPreview widget for @drawable_. See also
+ * gimp_drawable_preview_new_from_drawable().
  *
  * Since: 2.10
  *
  * Returns: a new #GimpAspectPreview.
  **/
 GtkWidget *
-gimp_aspect_preview_new_from_drawable_id (gint32 drawable_ID)
+gimp_aspect_preview_new_from_drawable (GimpDrawable *drawable)
 {
-  g_return_val_if_fail (gimp_item_is_valid (drawable_ID), NULL);
-  g_return_val_if_fail (gimp_item_is_drawable (drawable_ID), NULL);
+  g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
+  g_return_val_if_fail (gimp_item_is_valid (GIMP_ITEM (drawable)), NULL);
 
   return g_object_new (GIMP_TYPE_ASPECT_PREVIEW,
-                       "drawable-id", drawable_ID,
+                       "drawable", drawable,
                        NULL);
 }
diff --git a/libgimp/gimpaspectpreview.h b/libgimp/gimpaspectpreview.h
index 3e7cc4ead0..e7d126aaaf 100644
--- a/libgimp/gimpaspectpreview.h
+++ b/libgimp/gimpaspectpreview.h
@@ -67,7 +67,7 @@ struct _GimpAspectPreviewClass
 
 GType       gimp_aspect_preview_get_type             (void) G_GNUC_CONST;
 
-GtkWidget * gimp_aspect_preview_new_from_drawable_id (gint32 drawable_ID);
+GtkWidget * gimp_aspect_preview_new_from_drawable (GimpDrawable *drawable);
 
 
 G_END_DECLS
diff --git a/libgimp/gimpdrawable.c b/libgimp/gimpdrawable.c
index c0a9eff740..da86c2b9b0 100644
--- a/libgimp/gimpdrawable.c
+++ b/libgimp/gimpdrawable.c
@@ -45,17 +45,17 @@ gimp_drawable_init (GimpDrawable *drawable)
 
 
 guchar *
-gimp_drawable_get_thumbnail_data (gint32  drawable_ID,
-                                  gint   *width,
-                                  gint   *height,
-                                  gint   *bpp)
+gimp_drawable_get_thumbnail_data (GimpDrawable *drawable,
+                                  gint         *width,
+                                  gint         *height,
+                                  gint         *bpp)
 {
   gint    ret_width;
   gint    ret_height;
   guchar *image_data;
   gint    data_size;
 
-  _gimp_drawable_thumbnail (drawable_ID,
+  _gimp_drawable_thumbnail (drawable,
                             *width,
                             *height,
                             &ret_width,
@@ -72,13 +72,13 @@ gimp_drawable_get_thumbnail_data (gint32  drawable_ID,
 
 /**
  * gimp_drawable_get_thumbnail:
- * @drawable_ID: the drawable ID
- * @width:       the requested thumbnail width  (<= 1024 pixels)
- * @height:      the requested thumbnail height (<= 1024 pixels)
- * @alpha:       how to handle an alpha channel
+ * @drawable: the drawable ID
+ * @width:    the requested thumbnail width  (<= 1024 pixels)
+ * @height:   the requested thumbnail height (<= 1024 pixels)
+ * @alpha:    how to handle an alpha channel
  *
  * Retrieves a thumbnail pixbuf for the drawable identified by
- * @drawable_ID. The thumbnail will be not larger than the requested
+ * @drawable. The thumbnail will be not larger than the requested
  * size.
  *
  * Returns: (transfer full): a new #GdkPixbuf
@@ -86,7 +86,7 @@ gimp_drawable_get_thumbnail_data (gint32  drawable_ID,
  * Since: 2.2
  **/
 GdkPixbuf *
-gimp_drawable_get_thumbnail (gint32                  drawable_ID,
+gimp_drawable_get_thumbnail (GimpDrawable           *drawable,
                              gint                    width,
                              gint                    height,
                              GimpPixbufTransparency  alpha)
@@ -99,7 +99,7 @@ gimp_drawable_get_thumbnail (gint32                  drawable_ID,
   g_return_val_if_fail (width  > 0 && width  <= 1024, NULL);
   g_return_val_if_fail (height > 0 && height <= 1024, NULL);
 
-  data = gimp_drawable_get_thumbnail_data (drawable_ID,
+  data = gimp_drawable_get_thumbnail_data (drawable,
                                            &thumb_width,
                                            &thumb_height,
                                            &thumb_bpp);
@@ -113,21 +113,21 @@ gimp_drawable_get_thumbnail (gint32                  drawable_ID,
 }
 
 guchar *
-gimp_drawable_get_sub_thumbnail_data (gint32  drawable_ID,
-                                      gint    src_x,
-                                      gint    src_y,
-                                      gint    src_width,
-                                      gint    src_height,
-                                      gint   *dest_width,
-                                      gint   *dest_height,
-                                      gint   *bpp)
+gimp_drawable_get_sub_thumbnail_data (GimpDrawable *drawable,
+                                      gint          src_x,
+                                      gint          src_y,
+                                      gint          src_width,
+                                      gint          src_height,
+                                      gint         *dest_width,
+                                      gint         *dest_height,
+                                      gint         *bpp)
 {
   gint    ret_width;
   gint    ret_height;
   guchar *image_data;
   gint    data_size;
 
-  _gimp_drawable_sub_thumbnail (drawable_ID,
+  _gimp_drawable_sub_thumbnail (drawable,
                                 src_x, src_y,
                                 src_width, src_height,
                                 *dest_width,
@@ -146,7 +146,7 @@ gimp_drawable_get_sub_thumbnail_data (gint32  drawable_ID,
 
 /**
  * gimp_drawable_get_sub_thumbnail:
- * @drawable_ID: the drawable ID
+ * @drawable:    the drawable ID
  * @src_x:       the x coordinate of the area
  * @src_y:       the y coordinate of the area
  * @src_width:   the width of the area
@@ -156,7 +156,7 @@ gimp_drawable_get_sub_thumbnail_data (gint32  drawable_ID,
  * @alpha:       how to handle an alpha channel
  *
  * Retrieves a thumbnail pixbuf for the drawable identified by
- * @drawable_ID. The thumbnail will be not larger than the requested
+ * @drawable. The thumbnail will be not larger than the requested
  * size.
  *
  * Returns: (transfer full): a new #GdkPixbuf
@@ -164,7 +164,7 @@ gimp_drawable_get_sub_thumbnail_data (gint32  drawable_ID,
  * Since: 2.2
  **/
 GdkPixbuf *
-gimp_drawable_get_sub_thumbnail (gint32                  drawable_ID,
+gimp_drawable_get_sub_thumbnail (GimpDrawable           *drawable,
                                  gint                    src_x,
                                  gint                    src_y,
                                  gint                    src_width,
@@ -185,7 +185,7 @@ gimp_drawable_get_sub_thumbnail (gint32                  drawable_ID,
   g_return_val_if_fail (dest_width  > 0 && dest_width  <= 1024, NULL);
   g_return_val_if_fail (dest_height > 0 && dest_height <= 1024, NULL);
 
-  data = gimp_drawable_get_sub_thumbnail_data (drawable_ID,
+  data = gimp_drawable_get_sub_thumbnail_data (drawable,
                                                src_x, src_y,
                                                src_width, src_height,
                                                &thumb_width,
@@ -202,7 +202,7 @@ gimp_drawable_get_sub_thumbnail (gint32                  drawable_ID,
 
 /**
  * gimp_drawable_get_buffer:
- * @drawable_ID: the ID of the #GimpDrawable to get the buffer for.
+ * @drawable: the ID of the #GimpDrawable to get the buffer for.
  *
  * Returns a #GeglBuffer of a specified drawable. The buffer can be used
  * like any other GEGL buffer. Its data will we synced back with the core
@@ -216,14 +216,14 @@ gimp_drawable_get_sub_thumbnail (gint32                  drawable_ID,
  * Since: 2.10
  */
 GeglBuffer *
-gimp_drawable_get_buffer (gint32 drawable_ID)
+gimp_drawable_get_buffer (GimpDrawable *drawable)
 {
-  if (gimp_item_is_valid (drawable_ID))
+  if (gimp_item_is_valid (GIMP_ITEM (drawable)))
     {
       GeglTileBackend *backend;
       GeglBuffer      *buffer;
 
-      backend = _gimp_tile_backend_plugin_new (drawable_ID, FALSE);
+      backend = _gimp_tile_backend_plugin_new (drawable, FALSE);
       buffer = gegl_buffer_new_for_backend (NULL, backend);
       g_object_unref (backend);
 
@@ -235,7 +235,7 @@ gimp_drawable_get_buffer (gint32 drawable_ID)
 
 /**
  * gimp_drawable_get_shadow_buffer:
- * @drawable_ID: the ID of the #GimpDrawable to get the buffer for.
+ * @drawable: the ID of the #GimpDrawable to get the buffer for.
  *
  * Returns a #GeglBuffer of a specified drawable's shadow tiles. The
  * buffer can be used like any other GEGL buffer. Its data will we
@@ -249,14 +249,14 @@ gimp_drawable_get_buffer (gint32 drawable_ID)
  * Since: 2.10
  */
 GeglBuffer *
-gimp_drawable_get_shadow_buffer (gint32 drawable_ID)
+gimp_drawable_get_shadow_buffer (GimpDrawable *drawable)
 {
-  if (gimp_item_is_valid (drawable_ID))
+  if (gimp_item_is_valid (GIMP_ITEM (drawable)))
     {
       GeglTileBackend *backend;
       GeglBuffer      *buffer;
 
-      backend = _gimp_tile_backend_plugin_new (drawable_ID, TRUE);
+      backend = _gimp_tile_backend_plugin_new (drawable, TRUE);
       buffer = gegl_buffer_new_for_backend (NULL, backend);
       g_object_unref (backend);
 
@@ -268,7 +268,7 @@ gimp_drawable_get_shadow_buffer (gint32 drawable_ID)
 
 /**
  * gimp_drawable_get_format:
- * @drawable_ID: the ID of the #GimpDrawable to get the format for.
+ * @drawable: the ID of the #GimpDrawable to get the format for.
  *
  * Returns the #Babl format of the drawable.
  *
@@ -277,10 +277,10 @@ gimp_drawable_get_shadow_buffer (gint32 drawable_ID)
  * Since: 2.10
  */
 const Babl *
-gimp_drawable_get_format (gint32 drawable_ID)
+gimp_drawable_get_format (GimpDrawable *drawable)
 {
   const Babl *format     = NULL;
-  gchar      *format_str = _gimp_drawable_get_format (drawable_ID);
+  gchar      *format_str = _gimp_drawable_get_format (drawable);
 
   /* _gimp_drawable_get_format() only returns the encoding, so we
    * create the actual space from the image's profile
@@ -289,9 +289,9 @@ gimp_drawable_get_format (gint32 drawable_ID)
   if (format_str)
     {
       const Babl *space = NULL;
-      GimpImage  *image = gimp_item_get_image (drawable_ID);
+      GimpImage  *image = gimp_item_get_image (GIMP_ITEM (drawable));
 
-      if (gimp_item_is_layer (drawable_ID))
+      if (gimp_item_is_layer (GIMP_ITEM (drawable)))
         {
           GimpColorProfile *profile = gimp_image_get_color_profile (image);
 
@@ -316,7 +316,7 @@ gimp_drawable_get_format (gint32 drawable_ID)
             }
         }
 
-      if (gimp_drawable_is_indexed (drawable_ID))
+      if (gimp_drawable_is_indexed (drawable))
         {
           const Babl *palette;
           const Babl *palette_alpha;
@@ -326,7 +326,7 @@ gimp_drawable_get_format (gint32 drawable_ID)
           babl_new_palette_with_space (format_str, space,
                                        &palette, &palette_alpha);
 
-          if (gimp_drawable_has_alpha (drawable_ID))
+          if (gimp_drawable_has_alpha (drawable))
             format = palette_alpha;
           else
             format = palette;
@@ -355,7 +355,7 @@ gimp_drawable_get_format (gint32 drawable_ID)
 }
 /**
  * gimp_drawable_get_thumbnail_format:
- * @drawable_ID: the ID of the #GimpDrawable to get the thumbnail format for.
+ * @drawable: the ID of the #GimpDrawable to get the thumbnail format for.
  *
  * Returns the #Babl thumbnail format of the drawable.
  *
@@ -364,13 +364,264 @@ gimp_drawable_get_format (gint32 drawable_ID)
  * Since: 2.10.14
  */
 const Babl *
-gimp_drawable_get_thumbnail_format (gint32 drawable_ID)
+gimp_drawable_get_thumbnail_format (GimpDrawable *drawable)
 {
   const Babl *format     = NULL;
-  gchar      *format_str = _gimp_drawable_get_thumbnail_format (drawable_ID);
+  gchar      *format_str = _gimp_drawable_get_thumbnail_format (drawable);
 
   if (format_str)
     format = babl_format (format_str);
 
   return format;
 }
+
+
+/* Deprecated API. */
+
+
+/**
+ * gimp_drawable_get_thumbnail_data_deprecated: (skip)
+ * @drawable_ID: the drawable ID
+ * @width:       the requested thumbnail width  (<= 1024 pixels)
+ * @height:      the requested thumbnail height (<= 1024 pixels)
+ * @bpp:
+ *
+ * Retrieves thumbnail data for the drawable identified by @drawable_ID.
+ * The thumbnail will be not larger than the requested size.
+ *
+ * Returns: (transfer full):
+ **/
+guchar *
+gimp_drawable_get_thumbnail_data_deprecated (gint32  drawable_ID,
+                                             gint   *width,
+                                             gint   *height,
+                                             gint   *bpp)
+{
+  GimpDrawable *drawable;
+  guchar       *data = NULL;
+
+  drawable = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
+
+  g_return_val_if_fail (drawable, NULL);
+
+  data = gimp_drawable_get_thumbnail_data (drawable, width, height, bpp);
+  g_object_unref (drawable);
+
+  return data;
+}
+
+/**
+ * gimp_drawable_get_thumbnail_deprecated: (skip)
+ * @drawable_ID: the drawable ID
+ * @width:       the requested thumbnail width  (<= 1024 pixels)
+ * @height:      the requested thumbnail height (<= 1024 pixels)
+ * @alpha:       how to handle an alpha channel
+ *
+ * Retrieves a thumbnail pixbuf for the drawable identified by
+ * @drawable_ID. The thumbnail will be not larger than the requested
+ * size.
+ *
+ * Returns: (transfer full): a new #GdkPixbuf
+ *
+ * Since: 2.2
+ **/
+GdkPixbuf *
+gimp_drawable_get_thumbnail_deprecated (gint32                  drawable_ID,
+                                        gint                    width,
+                                        gint                    height,
+                                        GimpPixbufTransparency  alpha)
+{
+  GimpDrawable *drawable;
+  GdkPixbuf    *thumbnail = NULL;
+
+  drawable = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
+
+  g_return_val_if_fail (drawable, NULL);
+
+  thumbnail = gimp_drawable_get_thumbnail (drawable, width, height, alpha);
+  g_object_unref (drawable);
+
+  return thumbnail;
+}
+
+guchar *
+gimp_drawable_get_sub_thumbnail_data_deprecated (gint32  drawable_ID,
+                                                 gint    src_x,
+                                                 gint    src_y,
+                                                 gint    src_width,
+                                                 gint    src_height,
+                                                 gint   *dest_width,
+                                                 gint   *dest_height,
+                                                 gint   *bpp)
+{
+  GimpDrawable *drawable;
+  guchar       *data = NULL;
+
+  drawable = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
+
+  g_return_val_if_fail (drawable, NULL);
+
+  data = gimp_drawable_get_sub_thumbnail_data (drawable, src_x, src_y,
+                                               src_width, src_height,
+                                               dest_width, dest_height, bpp);
+  g_object_unref (drawable);
+
+  return data;
+}
+
+/**
+ * gimp_drawable_get_sub_thumbnail_deprecated: (skip)
+ * @drawable_ID: the drawable ID
+ * @src_x:       the x coordinate of the area
+ * @src_y:       the y coordinate of the area
+ * @src_width:   the width of the area
+ * @src_height:  the height of the area
+ * @dest_width:  the requested thumbnail width  (<= 1024 pixels)
+ * @dest_height: the requested thumbnail height (<= 1024 pixels)
+ * @alpha:       how to handle an alpha channel
+ *
+ * Retrieves a thumbnail pixbuf for the drawable identified by
+ * @drawable_ID. The thumbnail will be not larger than the requested
+ * size.
+ *
+ * Returns: (transfer full): a new #GdkPixbuf
+ *
+ * Since: 2.2
+ **/
+GdkPixbuf *
+gimp_drawable_get_sub_thumbnail_deprecated (gint32                  drawable_ID,
+                                            gint                    src_x,
+                                            gint                    src_y,
+                                            gint                    src_width,
+                                            gint                    src_height,
+                                            gint                    dest_width,
+                                            gint                    dest_height,
+                                            GimpPixbufTransparency  alpha)
+{
+  GimpDrawable *drawable;
+  GdkPixbuf    *thumbnail = NULL;
+
+  drawable = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
+
+  g_return_val_if_fail (drawable, NULL);
+
+  thumbnail = gimp_drawable_get_sub_thumbnail (drawable, src_x, src_y,
+                                               src_width, src_height,
+                                               dest_width, dest_height, alpha);
+  g_object_unref (drawable);
+
+  return thumbnail;
+}
+
+/**
+ * gimp_drawable_get_buffer_deprecated: (skip)
+ * @drawable_ID: the ID of the #GimpDrawable to get the buffer for.
+ *
+ * Returns a #GeglBuffer of a specified drawable. The buffer can be used
+ * like any other GEGL buffer. Its data will we synced back with the core
+ * drawable when the buffer gets destroyed, or when gegl_buffer_flush()
+ * is called.
+ *
+ * Returns: (transfer full): The #GeglBuffer.
+ *
+ * See Also: gimp_drawable_get_shadow_buffer()
+ *
+ * Since: 2.10
+ */
+GeglBuffer *
+gimp_drawable_get_buffer_deprecated (gint32 drawable_ID)
+{
+  GimpDrawable *drawable;
+  GeglBuffer   *buffer = NULL;
+
+  drawable = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
+
+  g_return_val_if_fail (drawable, NULL);
+
+  buffer = gimp_drawable_get_buffer (drawable);
+  g_object_unref (drawable);
+
+  return buffer;
+}
+
+/**
+ * gimp_drawable_get_shadow_buffer_deprecated: (skip)
+ * @drawable_ID: the ID of the #GimpDrawable to get the buffer for.
+ *
+ * Returns a #GeglBuffer of a specified drawable's shadow tiles. The
+ * buffer can be used like any other GEGL buffer. Its data will we
+ * synced back with the core drawable's shadow tiles when the buffer
+ * gets destroyed, or when gegl_buffer_flush() is called.
+ *
+ * Returns: (transfer full): The #GeglBuffer.
+ *
+ * See Also: gimp_drawable_get_shadow_buffer()
+ *
+ * Since: 2.10
+ */
+GeglBuffer *
+gimp_drawable_get_shadow_buffer_deprecated (gint32 drawable_ID)
+{
+  GimpDrawable *drawable;
+  GeglBuffer   *buffer = NULL;
+
+  drawable = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
+
+  g_return_val_if_fail (drawable, NULL);
+
+  buffer = gimp_drawable_get_shadow_buffer (drawable);
+  g_object_unref (drawable);
+
+  return buffer;
+}
+
+/**
+ * gimp_drawable_get_format_deprecated: (skip)
+ * @drawable_ID: the ID of the #GimpDrawable to get the format for.
+ *
+ * Returns the #Babl format of the drawable.
+ *
+ * Returns: The #Babl format.
+ *
+ * Since: 2.10
+ */
+const Babl *
+gimp_drawable_get_format_deprecated (gint32 drawable_ID)
+{
+  GimpDrawable *drawable;
+  const Babl   *format = NULL;
+
+  drawable = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
+
+  g_return_val_if_fail (drawable, NULL);
+
+  format = gimp_drawable_get_format (drawable);
+  g_object_unref (drawable);
+
+  return format;
+}
+/**
+ * gimp_drawable_get_thumbnail_format_deprecated: (skip)
+ * @drawable_ID: the ID of the #GimpDrawable to get the thumbnail format for.
+ *
+ * Returns the #Babl thumbnail format of the drawable.
+ *
+ * Returns: The #Babl thumbnail format.
+ *
+ * Since: 2.10.14
+ */
+const Babl *
+gimp_drawable_get_thumbnail_format_deprecated (gint32 drawable_ID)
+{
+  GimpDrawable *drawable;
+  const Babl   *format = NULL;
+
+  drawable = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
+
+  g_return_val_if_fail (drawable, NULL);
+
+  format = gimp_drawable_get_thumbnail_format (drawable);
+  g_object_unref (drawable);
+
+  return format;
+}
diff --git a/libgimp/gimpdrawable.h b/libgimp/gimpdrawable.h
index 95c4abc57a..fdb2d1069e 100644
--- a/libgimp/gimpdrawable.h
+++ b/libgimp/gimpdrawable.h
@@ -64,22 +64,24 @@ struct _GimpDrawableClass
 
 GType        gimp_drawable_get_type               (void) G_GNUC_CONST;
 
-GeglBuffer * gimp_drawable_get_buffer             (gint32         drawable_ID);
-GeglBuffer * gimp_drawable_get_shadow_buffer      (gint32         drawable_ID);
+#ifndef GIMP_DEPRECATED_REPLACE_NEW_API
 
-const Babl * gimp_drawable_get_format             (gint32         drawable_ID);
-const Babl * gimp_drawable_get_thumbnail_format   (gint32         drawable_ID);
+GeglBuffer * gimp_drawable_get_buffer             (GimpDrawable  *drawable);
+GeglBuffer * gimp_drawable_get_shadow_buffer      (GimpDrawable  *drawable);
 
-guchar     * gimp_drawable_get_thumbnail_data     (gint32         drawable_ID,
+const Babl * gimp_drawable_get_format             (GimpDrawable  *drawable);
+const Babl * gimp_drawable_get_thumbnail_format   (GimpDrawable  *drawable);
+
+guchar     * gimp_drawable_get_thumbnail_data     (GimpDrawable  *drawable,
                                                    gint          *width,
                                                    gint          *height,
                                                    gint          *bpp);
-GdkPixbuf  * gimp_drawable_get_thumbnail          (gint32         drawable_ID,
+GdkPixbuf  * gimp_drawable_get_thumbnail          (GimpDrawable  *drawable,
                                                    gint           width,
                                                    gint           height,
                                                    GimpPixbufTransparency alpha);
 
-guchar     * gimp_drawable_get_sub_thumbnail_data (gint32         drawable_ID,
+guchar     * gimp_drawable_get_sub_thumbnail_data (GimpDrawable  *drawable,
                                                    gint           src_x,
                                                    gint           src_y,
                                                    gint           src_width,
@@ -87,7 +89,7 @@ guchar     * gimp_drawable_get_sub_thumbnail_data (gint32         drawable_ID,
                                                    gint          *dest_width,
                                                    gint          *dest_height,
                                                    gint          *bpp);
-GdkPixbuf  * gimp_drawable_get_sub_thumbnail      (gint32         drawable_ID,
+GdkPixbuf  * gimp_drawable_get_sub_thumbnail      (GimpDrawable  *drawable,
                                                    gint           src_x,
                                                    gint           src_y,
                                                    gint           src_width,
@@ -96,6 +98,52 @@ GdkPixbuf  * gimp_drawable_get_sub_thumbnail      (gint32         drawable_ID,
                                                    gint           dest_height,
                                                    GimpPixbufTransparency alpha);
 
+#else /* GIMP_DEPRECATED_REPLACE_NEW_API */
+
+#define gimp_drawable_get_buffer             gimp_drawable_get_buffer_deprecated
+#define gimp_drawable_get_shadow_buffer      gimp_drawable_get_shadow_buffer_deprecated
+#define gimp_drawable_get_format             gimp_drawable_get_format_deprecated
+#define gimp_drawable_get_thumbnail_format   gimp_drawable_get_thumbnail_format_deprecated
+#define gimp_drawable_get_thumbnail_data     gimp_drawable_get_thumbnail_data_deprecated
+#define gimp_drawable_get_thumbnail          gimp_drawable_get_thumbnail_deprecated
+#define gimp_drawable_get_sub_thumbnail_data gimp_drawable_get_sub_thumbnail_data_deprecated
+#define gimp_drawable_get_sub_thumbnail      gimp_drawable_get_sub_thumbnail_deprecated
+
+#endif /* GIMP_DEPRECATED_REPLACE_NEW_API */
+
+
+GeglBuffer * gimp_drawable_get_buffer_deprecated             (gint32         drawable_ID);
+GeglBuffer * gimp_drawable_get_shadow_buffer_deprecated      (gint32         drawable_ID);
+
+const Babl * gimp_drawable_get_format_deprecated             (gint32         drawable_ID);
+const Babl * gimp_drawable_get_thumbnail_format_deprecated   (gint32         drawable_ID);
+
+guchar     * gimp_drawable_get_thumbnail_data_deprecated     (gint32         drawable_ID,
+                                                              gint          *width,
+                                                              gint          *height,
+                                                              gint          *bpp);
+GdkPixbuf  * gimp_drawable_get_thumbnail_deprecated          (gint32         drawable_ID,
+                                                              gint           width,
+                                                              gint           height,
+                                                              GimpPixbufTransparency alpha);
+
+guchar     * gimp_drawable_get_sub_thumbnail_data_deprecated (gint32         drawable_ID,
+                                                              gint           src_x,
+                                                              gint           src_y,
+                                                              gint           src_width,
+                                                              gint           src_height,
+                                                              gint          *dest_width,
+                                                              gint          *dest_height,
+                                                              gint          *bpp);
+GdkPixbuf  * gimp_drawable_get_sub_thumbnail_deprecated      (gint32         drawable_ID,
+                                                              gint           src_x,
+                                                              gint           src_y,
+                                                              gint           src_width,
+                                                              gint           src_height,
+                                                              gint           dest_width,
+                                                              gint           dest_height,
+                                                              GimpPixbufTransparency alpha);
+
 
 G_END_DECLS
 
diff --git a/libgimp/gimpdrawablepreview.c b/libgimp/gimpdrawablepreview.c
index 973e6890a3..c62a6a361e 100644
--- a/libgimp/gimpdrawablepreview.c
+++ b/libgimp/gimpdrawablepreview.c
@@ -46,7 +46,7 @@
 enum
 {
   PROP_0,
-  PROP_DRAWABLE_ID
+  PROP_DRAWABLE
 };
 
 typedef struct
@@ -59,7 +59,7 @@ typedef struct
 
 struct _GimpDrawablePreviewPrivate
 {
-  gint32 drawable_ID;
+  GimpDrawable *drawable;
 };
 
 #define GET_PRIVATE(obj) (((GimpDrawablePreview *) (obj))->priv)
@@ -87,9 +87,8 @@ static void  gimp_drawable_preview_draw_buffer   (GimpPreview     *preview,
                                                   const guchar    *buffer,
                                                   gint             rowstride);
 
-static void  gimp_drawable_preview_set_drawable_id
-                                                (GimpDrawablePreview *preview,
-                                                 gint32               drawable_ID);
+static void  gimp_drawable_preview_set_drawable  (GimpDrawablePreview *preview,
+                                                  GimpDrawable        *drawable);
 
 
 G_DEFINE_TYPE_WITH_PRIVATE (GimpDrawablePreview, gimp_drawable_preview,
@@ -125,13 +124,13 @@ gimp_drawable_preview_class_init (GimpDrawablePreviewClass *klass)
    *
    * Since: 2.10
    */
-  g_object_class_install_property (object_class, PROP_DRAWABLE_ID,
-                                   g_param_spec_int ("drawable-id",
-                                                     "Drawable ID",
-                                                     "The drawable this preview is attached to",
-                                                     -1, G_MAXINT, -1,
-                                                     GIMP_PARAM_READWRITE |
-                                                     G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property (object_class, PROP_DRAWABLE,
+                                   g_param_spec_object ("drawable",
+                                                        "Drawable",
+                                                        "The drawable this preview is attached to",
+                                                        GIMP_TYPE_DRAWABLE,
+                                                        GIMP_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT_ONLY));
 
 }
 
@@ -172,9 +171,11 @@ gimp_drawable_preview_constructed (GObject *object)
 static void
 gimp_drawable_preview_dispose (GObject *object)
 {
-  const gchar *data_name = g_object_get_data (G_OBJECT (object),
-                                              "gimp-drawable-preview-data-name");
+  GimpDrawablePreviewPrivate *priv = GET_PRIVATE (object);
+  const gchar                *data_name;
 
+  data_name = g_object_get_data (G_OBJECT (object),
+                                 "gimp-drawable-preview-data-name");
   if (data_name)
     {
       GimpPreview     *preview = GIMP_PREVIEW (object);
@@ -186,6 +187,8 @@ gimp_drawable_preview_dispose (GObject *object)
       gimp_set_data (data_name, &settings, sizeof (PreviewSettings));
     }
 
+  g_clear_object (&priv->drawable);
+
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
@@ -199,9 +202,9 @@ gimp_drawable_preview_get_property (GObject    *object,
 
   switch (property_id)
     {
-    case PROP_DRAWABLE_ID:
-      g_value_set_int (value,
-                       gimp_drawable_preview_get_drawable_id (preview));
+    case PROP_DRAWABLE:
+      g_value_set_object (value,
+                          gimp_drawable_preview_get_drawable (preview));
       break;
 
     default:
@@ -220,9 +223,9 @@ gimp_drawable_preview_set_property (GObject      *object,
 
   switch (property_id)
     {
-    case PROP_DRAWABLE_ID:
-      gimp_drawable_preview_set_drawable_id (preview,
-                                             g_value_get_int (value));
+    case PROP_DRAWABLE:
+      gimp_drawable_preview_set_drawable (preview,
+                                          g_value_dup_object (value));
       break;
 
     default:
@@ -269,7 +272,7 @@ gimp_drawable_preview_draw_original (GimpPreview *preview)
   gint                        bpp;
   GimpImageType               type;
 
-  if (priv->drawable_ID < 1)
+  if (priv->drawable == NULL)
     return;
 
   gimp_preview_get_size (preview, &width, &height);
@@ -281,7 +284,7 @@ gimp_drawable_preview_draw_original (GimpPreview *preview)
 
   gimp_preview_set_offsets (preview, xoff, yoff);
 
-  buffer = gimp_drawable_get_sub_thumbnail_data (priv->drawable_ID,
+  buffer = gimp_drawable_get_sub_thumbnail_data (priv->drawable,
                                                  xoff + xmin,
                                                  yoff + ymin,
                                                  width, height,
@@ -311,14 +314,14 @@ gimp_drawable_preview_draw_thumb (GimpPreview     *preview,
 {
   GimpDrawablePreviewPrivate *priv = GET_PRIVATE (preview);
 
-  if (priv->drawable_ID > 0)
-    _gimp_drawable_preview_area_draw_thumb (area, priv->drawable_ID,
+  if (priv->drawable)
+    _gimp_drawable_preview_area_draw_thumb (area, priv->drawable,
                                             width, height);
 }
 
 void
 _gimp_drawable_preview_area_draw_thumb (GimpPreviewArea *area,
-                                        gint32           drawable_ID,
+                                        GimpDrawable    *drawable,
                                         gint             width,
                                         gint             height)
 {
@@ -329,18 +332,18 @@ _gimp_drawable_preview_area_draw_thumb (GimpPreviewArea *area,
   gint    nav_width, nav_height;
 
   g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
-  g_return_if_fail (gimp_item_is_valid (drawable_ID));
-  g_return_if_fail (gimp_item_is_drawable (drawable_ID));
+  g_return_if_fail (gimp_item_is_valid (GIMP_ITEM (drawable)));
+  g_return_if_fail (gimp_item_is_drawable (GIMP_ITEM (drawable)));
 
-  if (_gimp_drawable_preview_get_bounds (drawable_ID, &x1, &y1, &x2, &y2))
+  if (_gimp_drawable_preview_get_bounds (drawable, &x1, &y1, &x2, &y2))
     {
       width  = x2 - x1;
       height = y2 - y1;
     }
   else
     {
-      width  = gimp_drawable_width  (drawable_ID);
-      height = gimp_drawable_height (drawable_ID);
+      width  = gimp_drawable_width  (drawable);
+      height = gimp_drawable_height (drawable);
     }
 
   if (width > height)
@@ -354,16 +357,16 @@ _gimp_drawable_preview_area_draw_thumb (GimpPreviewArea *area,
       nav_width  = (width * nav_height) / height;
     }
 
-  if (_gimp_drawable_preview_get_bounds (drawable_ID, &x1, &y1, &x2, &y2))
+  if (_gimp_drawable_preview_get_bounds (drawable, &x1, &y1, &x2, &y2))
     {
-      buffer = gimp_drawable_get_sub_thumbnail_data (drawable_ID,
+      buffer = gimp_drawable_get_sub_thumbnail_data (drawable,
                                                      x1, y1, x2 - x1, y2 - y1,
                                                      &nav_width, &nav_height,
                                                      &bpp);
     }
   else
     {
-      buffer = gimp_drawable_get_thumbnail_data (drawable_ID,
+      buffer = gimp_drawable_get_thumbnail_data (drawable,
                                                  &nav_width, &nav_height,
                                                  &bpp);
     }
@@ -413,7 +416,7 @@ gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
   gimp_preview_get_bounds (gimp_preview, &xmin, &ymin, NULL, NULL);
   gimp_preview_get_offsets (gimp_preview, &xoff, &yoff);
 
-  image = gimp_item_get_image (priv->drawable_ID);
+  image = gimp_item_get_image (GIMP_ITEM (priv->drawable));
 
   if (gimp_selection_is_empty (image))
     {
@@ -422,7 +425,7 @@ gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
                               y - yoff - ymin,
                               width,
                               height,
-                              gimp_drawable_type (priv->drawable_ID),
+                              gimp_drawable_type (priv->drawable),
                               buf, rowstride);
     }
   else
@@ -433,9 +436,9 @@ gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
       gint draw_x, draw_y;
       gint draw_width, draw_height;
 
-      gimp_drawable_offsets (priv->drawable_ID, &offset_x, &offset_y);
+      gimp_drawable_offsets (priv->drawable, &offset_x, &offset_y);
 
-      if (gimp_drawable_mask_intersect (priv->drawable_ID,
+      if (gimp_drawable_mask_intersect (priv->drawable,
                                         &mask_x, &mask_y,
                                         &mask_width, &mask_height) &&
           gimp_rectangle_intersect (mask_x, mask_y,
@@ -445,6 +448,7 @@ gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
                                     &draw_width, &draw_height))
         {
           GimpImageType  type;
+          GimpDrawable  *selection;
           gint32         selection_ID;
           guchar        *src;
           guchar        *sel;
@@ -458,19 +462,21 @@ gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
           s_h = draw_height;
 
           selection_ID = gimp_image_get_selection (image);
+          selection = GIMP_DRAWABLE (gimp_item_new_by_id (selection_ID));
 
-          src = gimp_drawable_get_sub_thumbnail_data (priv->drawable_ID,
+          src = gimp_drawable_get_sub_thumbnail_data (priv->drawable,
                                                       draw_x, draw_y,
                                                       draw_width, draw_height,
                                                       &d_w, &d_h,
                                                       &d_bpp);
 
-          sel = gimp_drawable_get_sub_thumbnail_data (selection_ID,
+          sel = gimp_drawable_get_sub_thumbnail_data (selection,
                                                       draw_x + offset_x,
                                                       draw_y + offset_y,
                                                       draw_width, draw_height,
                                                       &s_w, &s_h,
                                                       &s_bpp);
+          g_object_unref (selection);
 
           switch (d_bpp)
             {
@@ -523,24 +529,24 @@ gimp_drawable_preview_draw_buffer (GimpPreview  *preview,
 }
 
 static void
-gimp_drawable_preview_set_drawable_id (GimpDrawablePreview *drawable_preview,
-                                       gint32               drawable_ID)
+gimp_drawable_preview_set_drawable (GimpDrawablePreview *drawable_preview,
+                                    GimpDrawable        *drawable)
 {
   GimpPreview                *preview = GIMP_PREVIEW (drawable_preview);
   GimpDrawablePreviewPrivate *priv    = GET_PRIVATE (preview);
   gint                        x1, y1, x2, y2;
 
-  g_return_if_fail (priv->drawable_ID < 1);
+  g_return_if_fail (priv->drawable == NULL);
 
-  priv->drawable_ID = drawable_ID;
+  priv->drawable = drawable;
 
-  _gimp_drawable_preview_get_bounds (drawable_ID, &x1, &y1, &x2, &y2);
+  _gimp_drawable_preview_get_bounds (drawable, &x1, &y1, &x2, &y2);
 
   gimp_preview_set_bounds (preview, x1, y1, x2, y2);
 
-  if (gimp_drawable_is_indexed (drawable_ID))
+  if (gimp_drawable_is_indexed (drawable))
     {
-      GimpImage *image = gimp_item_get_image (drawable_ID);
+      GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
       GtkWidget *area  = gimp_preview_get_area (preview);
       guchar    *cmap;
       gint       num_colors;
@@ -558,11 +564,11 @@ gimp_drawable_preview_set_drawable_id (GimpDrawablePreview *drawable_preview,
 #define MIN3(a, b, c)  (MIN (MIN ((a), (b)), (c)))
 
 gboolean
-_gimp_drawable_preview_get_bounds (gint32  drawable_ID,
-                                   gint   *xmin,
-                                   gint   *ymin,
-                                   gint   *xmax,
-                                   gint   *ymax)
+_gimp_drawable_preview_get_bounds (GimpDrawable *drawable,
+                                   gint         *xmin,
+                                   gint         *ymin,
+                                   gint         *xmax,
+                                   gint         *ymax)
 {
   gint     width;
   gint     height;
@@ -572,15 +578,15 @@ _gimp_drawable_preview_get_bounds (gint32  drawable_ID,
   gint     x2, y2;
   gboolean retval;
 
-  g_return_val_if_fail (gimp_item_is_valid (drawable_ID), FALSE);
-  g_return_val_if_fail (gimp_item_is_drawable (drawable_ID), FALSE);
+  g_return_val_if_fail (gimp_item_is_valid (GIMP_ITEM (drawable)), FALSE);
+  g_return_val_if_fail (gimp_item_is_drawable (GIMP_ITEM (drawable)), FALSE);
 
-  width  = gimp_drawable_width (drawable_ID);
-  height = gimp_drawable_height (drawable_ID);
+  width  = gimp_drawable_width (drawable);
+  height = gimp_drawable_height (drawable);
 
-  retval = gimp_drawable_mask_bounds (drawable_ID, &x1, &y1, &x2, &y2);
+  retval = gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
 
-  gimp_drawable_offsets (drawable_ID, &offset_x, &offset_y);
+  gimp_drawable_offsets (drawable, &offset_x, &offset_y);
 
   *xmin = MAX3 (x1 - SELECTION_BORDER, 0, - offset_x);
   *ymin = MAX3 (y1 - SELECTION_BORDER, 0, - offset_y);
@@ -592,39 +598,39 @@ _gimp_drawable_preview_get_bounds (gint32  drawable_ID,
 
 
 /**
- * gimp_drawable_preview_new_from_drawable_id:
- * @drawable_ID: a drawable ID
+ * gimp_drawable_preview_new_from_drawable:
+ * @drawable: (transfer none): a drawable
  *
- * Creates a new #GimpDrawablePreview widget for @drawable_ID.
+ * Creates a new #GimpDrawablePreview widget for @drawable.
  *
  * Returns: A pointer to the new #GimpDrawablePreview widget.
  *
  * Since: 2.10
  **/
 GtkWidget *
-gimp_drawable_preview_new_from_drawable_id (gint32 drawable_ID)
+gimp_drawable_preview_new_from_drawable (GimpDrawable *drawable)
 {
-  g_return_val_if_fail (gimp_item_is_valid (drawable_ID), NULL);
-  g_return_val_if_fail (gimp_item_is_drawable (drawable_ID), NULL);
+  g_return_val_if_fail (gimp_item_is_valid (GIMP_ITEM (drawable)), NULL);
+  g_return_val_if_fail (gimp_item_is_drawable (GIMP_ITEM (drawable)), NULL);
 
   return g_object_new (GIMP_TYPE_DRAWABLE_PREVIEW,
-                       "drawable-id", drawable_ID,
+                       "drawable", drawable,
                        NULL);
 }
 
 /**
- * gimp_drawable_preview_get_drawable_id:
+ * gimp_drawable_preview_get_drawable:
  * @preview:   a #GimpDrawablePreview widget
  *
- * Returns: the drawable_ID that has been passed to
- *               gimp_drawable_preview_new_from_drawable_id().
+ * Returns: (transfer none): the drawable that has been passed to
+ *          gimp_drawable_preview_new_from_drawable().
  *
  * Since: 2.10
  **/
-gint32
-gimp_drawable_preview_get_drawable_id (GimpDrawablePreview *preview)
+GimpDrawable *
+gimp_drawable_preview_get_drawable (GimpDrawablePreview *preview)
 {
-  g_return_val_if_fail (GIMP_IS_DRAWABLE_PREVIEW (preview), -1);
+  g_return_val_if_fail (GIMP_IS_DRAWABLE_PREVIEW (preview), NULL);
 
-  return GET_PRIVATE (preview)->drawable_ID;
+  return GET_PRIVATE (preview)->drawable;
 }
diff --git a/libgimp/gimpdrawablepreview.h b/libgimp/gimpdrawablepreview.h
index 17d19610af..48aa389650 100644
--- a/libgimp/gimpdrawablepreview.h
+++ b/libgimp/gimpdrawablepreview.h
@@ -67,15 +67,15 @@ struct _GimpDrawablePreviewClass
 
 GType          gimp_drawable_preview_get_type             (void) G_GNUC_CONST;
 
-GtkWidget    * gimp_drawable_preview_new_from_drawable_id (gint32               drawable_ID);
-gint32         gimp_drawable_preview_get_drawable_id      (GimpDrawablePreview *preview);
+GtkWidget    * gimp_drawable_preview_new_from_drawable (GimpDrawable        *drawable);
+GimpDrawable * gimp_drawable_preview_get_drawable      (GimpDrawablePreview *preview);
 
 /*  for internal use only  */
 G_GNUC_INTERNAL void      _gimp_drawable_preview_area_draw_thumb (GimpPreviewArea *area,
-                                                                  gint32           drawable_ID,
+                                                                  GimpDrawable    *drawable,
                                                                   gint             width,
                                                                   gint             height);
-G_GNUC_INTERNAL gboolean  _gimp_drawable_preview_get_bounds      (gint32           drawable_ID,
+G_GNUC_INTERNAL gboolean  _gimp_drawable_preview_get_bounds      (GimpDrawable    *drawable,
                                                                   gint            *xmin,
                                                                   gint            *ymin,
                                                                   gint            *xmax,
diff --git a/libgimp/gimpexport.c b/libgimp/gimpexport.c
index 0c4725db9d..290a09af49 100644
--- a/libgimp/gimpexport.c
+++ b/libgimp/gimpexport.c
@@ -51,8 +51,8 @@
  **/
 
 
-typedef void (* ExportFunc) (GimpImage *image,
-                             gint32    *drawable_ID);
+typedef void (* ExportFunc) (GimpImage     *image,
+                             GimpDrawable **drawable);
 
 
 /* the export action structure */
@@ -69,25 +69,29 @@ typedef struct
 /* the functions that do the actual export */
 
 static void
-export_merge (GimpImage *image,
-              gint32    *drawable_ID)
+export_merge (GimpImage     *image,
+              GimpDrawable **drawable)
 {
   gint32  nlayers;
   gint32  nvisible = 0;
   gint32  i;
   gint32 *layers;
-  gint32  merged;
-  gint32  transp;
 
   layers = gimp_image_get_layers (image, &nlayers);
   for (i = 0; i < nlayers; i++)
     {
-      if (gimp_item_get_visible (layers[i]))
+      GimpLayer *layer = GIMP_LAYER (gimp_item_new_by_id (layers[i]));
+
+      if (gimp_item_get_visible (GIMP_ITEM (layer)))
         nvisible++;
+
+      g_object_unref (layer);
     }
 
   if (nvisible <= 1)
     {
+      GimpLayer *transp;
+
       /* if there is only one (or zero) visible layer, add a new
        * transparent layer that has the same size as the canvas.  The
        * merge that follows will ensure that the offset, opacity and
@@ -96,33 +100,42 @@ export_merge (GimpImage *image,
       transp = gimp_layer_new (image, "-",
                                gimp_image_width (image),
                                gimp_image_height (image),
-                               gimp_drawable_type (*drawable_ID) | 1,
+                               gimp_drawable_type (*drawable) | 1,
                                100.0, GIMP_LAYER_MODE_NORMAL);
-      gimp_image_insert_layer (image, transp, -1, 1);
+      gimp_image_insert_layer (image, transp, NULL, 1);
       gimp_selection_none (image);
-      gimp_drawable_edit_clear (transp);
+      gimp_drawable_edit_clear (GIMP_DRAWABLE (transp));
       nvisible++;
+
+      g_object_unref (transp);
     }
 
   if (nvisible > 1)
     {
+      GimpLayer *merged;
+
       g_free (layers);
       merged = gimp_image_merge_visible_layers (image, GIMP_CLIP_TO_IMAGE);
 
-      if (merged != -1)
-        *drawable_ID = merged;
+      if (merged != NULL)
+        {
+          g_clear_object (drawable);
+          *drawable = GIMP_DRAWABLE (merged);
+        }
       else
-        return;  /* shouldn't happen */
+        {
+          return;  /* shouldn't happen */
+        }
 
       layers = gimp_image_get_layers (image, &nlayers);
 
       /*  make sure that the merged drawable matches the image size  */
-      if (gimp_drawable_width  (merged) != gimp_image_width  (image) ||
-          gimp_drawable_height (merged) != gimp_image_height (image))
+      if (gimp_drawable_width  (GIMP_DRAWABLE (merged)) != gimp_image_width  (image) ||
+          gimp_drawable_height (GIMP_DRAWABLE (merged)) != gimp_image_height (image))
         {
           gint off_x, off_y;
 
-          gimp_drawable_offsets (merged, &off_x, &off_y);
+          gimp_drawable_offsets (GIMP_DRAWABLE (merged), &off_x, &off_y);
           gimp_layer_resize (merged,
                              gimp_image_width (image),
                              gimp_image_height (image),
@@ -133,27 +146,33 @@ export_merge (GimpImage *image,
   /* remove any remaining (invisible) layers */
   for (i = 0; i < nlayers; i++)
     {
-      if (layers[i] != *drawable_ID)
-        gimp_image_remove_layer (image, layers[i]);
+      if (layers[i] != gimp_item_get_id (GIMP_ITEM (*drawable)))
+        {
+          GimpLayer *layer = GIMP_LAYER (gimp_item_new_by_id (layers[i]));
+
+          gimp_image_remove_layer (image, layer);
+
+          g_object_unref (layer);
+        }
     }
   g_free (layers);
 }
 
 static void
-export_flatten (GimpImage *image,
-                gint32    *drawable_ID)
+export_flatten (GimpImage     *image,
+                GimpDrawable **drawable)
 {
-  gint32 flattened;
+  GimpLayer *flattened;
 
   flattened = gimp_image_flatten (image);
 
-  if (flattened != -1)
-    *drawable_ID = flattened;
+  if (flattened != NULL)
+    *drawable = GIMP_DRAWABLE (flattened);
 }
 
 static void
-export_remove_alpha (GimpImage *image,
-                     gint32    *drawable_ID)
+export_remove_alpha (GimpImage     *image,
+                     GimpDrawable **drawable)
 {
   gint32  n_layers;
   gint32 *layers;
@@ -163,16 +182,21 @@ export_remove_alpha (GimpImage *image,
 
   for (i = 0; i < n_layers; i++)
     {
-      if (gimp_drawable_has_alpha (layers[i]))
-        gimp_layer_flatten (layers[i]);
+      GimpLayer *layer;
+
+      layer = GIMP_LAYER (gimp_item_new_by_id (layers[i]));
+      if (gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))
+        gimp_layer_flatten (layer);
+
+      g_object_unref (layer);
     }
 
   g_free (layers);
 }
 
 static void
-export_apply_masks (GimpImage *image,
-                    gint      *drawable_ID)
+export_apply_masks (GimpImage     *image,
+                    GimpDrawable **drawable)
 {
   gint32  n_layers;
   gint32 *layers;
@@ -182,36 +206,41 @@ export_apply_masks (GimpImage *image,
 
   for (i = 0; i < n_layers; i++)
     {
-      if (gimp_layer_get_mask (layers[i]) != -1)
-        gimp_layer_remove_mask (layers[i], GIMP_MASK_APPLY);
+      GimpLayer *layer;
+
+      layer = GIMP_LAYER (gimp_item_new_by_id (layers[i]));
+      if (gimp_layer_get_mask (layer) != -1)
+        gimp_layer_remove_mask (layer, GIMP_MASK_APPLY);
+
+      g_object_unref (layer);
     }
 
   g_free (layers);
 }
 
 static void
-export_convert_rgb (GimpImage *image,
-                    gint32    *drawable_ID)
+export_convert_rgb (GimpImage     *image,
+                    GimpDrawable **drawable)
 {
   gimp_image_convert_rgb (image);
 }
 
 static void
-export_convert_grayscale (GimpImage *image,
-                          gint32    *drawable_ID)
+export_convert_grayscale (GimpImage     *image,
+                          GimpDrawable **drawable)
 {
   gimp_image_convert_grayscale (image);
 }
 
 static void
-export_convert_indexed (GimpImage *image,
-                        gint32    *drawable_ID)
+export_convert_indexed (GimpImage     *image,
+                        GimpDrawable **drawable)
 {
   gint32 nlayers;
 
   /* check alpha */
   g_free (gimp_image_get_layers (image, &nlayers));
-  if (nlayers > 1 || gimp_drawable_has_alpha (*drawable_ID))
+  if (nlayers > 1 || gimp_drawable_has_alpha (*drawable))
     gimp_image_convert_indexed (image,
                                 GIMP_CONVERT_DITHER_NONE,
                                 GIMP_CONVERT_PALETTE_GENERATE,
@@ -224,8 +253,8 @@ export_convert_indexed (GimpImage *image,
 }
 
 static void
-export_convert_bitmap (GimpImage *image,
-                       gint32    *drawable_ID)
+export_convert_bitmap (GimpImage     *image,
+                       GimpDrawable **drawable)
 {
   if (gimp_image_base_type (image) == GIMP_INDEXED)
     gimp_image_convert_rgb (image);
@@ -237,8 +266,8 @@ export_convert_bitmap (GimpImage *image,
 }
 
 static void
-export_add_alpha (GimpImage *image,
-                  gint32    *drawable_ID)
+export_add_alpha (GimpImage     *image,
+                  GimpDrawable **drawable)
 {
   gint32  nlayers;
   gint32  i;
@@ -247,15 +276,20 @@ export_add_alpha (GimpImage *image,
   layers = gimp_image_get_layers (image, &nlayers);
   for (i = 0; i < nlayers; i++)
     {
-      if (!gimp_drawable_has_alpha (layers[i]))
-        gimp_layer_add_alpha (layers[i]);
+      GimpLayer *layer;
+
+      layer = GIMP_LAYER (gimp_item_new_by_id (layers[i]));
+      if (!gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))
+        gimp_layer_add_alpha (GIMP_LAYER (layer));
+
+      g_object_unref (layer);
     }
   g_free (layers);
 }
 
 static void
-export_void (GimpImage *image,
-             gint32    *drawable_ID)
+export_void (GimpImage     *image,
+             GimpDrawable **drawable)
 {
   /* do nothing */
 }
@@ -432,9 +466,9 @@ export_action_get_func (const ExportAction *action)
 static void
 export_action_perform (const ExportAction *action,
                        GimpImage          *image,
-                       gint32             *drawable_ID)
+                       GimpDrawable      **drawable)
 {
-  export_action_get_func (action) (image, drawable_ID);
+  export_action_get_func (action) (image, drawable);
 }
 
 
@@ -695,7 +729,7 @@ export_dialog (GSList      *actions,
 /**
  * gimp_export_image:
  * @image:        Pointer to the image.
- * @drawable_ID:  Pointer to the drawable_ID.
+ * @drawable:     Pointer to the drawable.
  * @format_name:  The (short) name of the image_format (e.g. JPEG or GIF).
  * @capabilities: What can the image_format do?
  *
@@ -725,7 +759,7 @@ export_dialog (GSList      *actions,
  **/
 GimpExportReturn
 gimp_export_image (GimpImage             **image,
-                   gint32                 *drawable_ID,
+                   GimpDrawable          **drawable,
                    const gchar            *format_name,
                    GimpExportCapabilities  capabilities)
 {
@@ -740,7 +774,8 @@ gimp_export_image (GimpImage             **image,
   gboolean           background_has_alpha = TRUE;
   GimpExportReturn   retval               = GIMP_EXPORT_CANCEL;
 
-  g_return_val_if_fail (gimp_image_is_valid (*image) && *drawable_ID > -1, FALSE);
+  g_return_val_if_fail (gimp_image_is_valid (*image) &&
+                        gimp_item_is_valid (GIMP_ITEM (*drawable)), FALSE);
 
   /* do some sanity checks */
   if (capabilities & GIMP_EXPORT_NEEDS_ALPHA)
@@ -757,16 +792,16 @@ gimp_export_image (GimpImage             **image,
 
   /* ask for confirmation if the user is not saving a layer (see bug #51114) */
   if (interactive &&
-      ! gimp_item_is_layer (*drawable_ID) &&
+      ! gimp_item_is_layer (GIMP_ITEM (*drawable)) &&
       ! (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS))
     {
-      if (gimp_item_is_layer_mask (*drawable_ID))
+      if (gimp_item_is_layer_mask (GIMP_ITEM (*drawable)))
         {
           retval = confirm_save_dialog
             (_("You are about to save a layer mask as %s.\n"
                "This will not save the visible layers."), format_name);
         }
-      else if (gimp_item_is_channel (*drawable_ID))
+      else if (gimp_item_is_channel (GIMP_ITEM (*drawable)))
         {
           retval = confirm_save_dialog
             (_("You are about to save a channel (saved selection) as %s.\n"
@@ -789,7 +824,9 @@ gimp_export_image (GimpImage             **image,
 
   for (i = 0; i < n_layers; i++)
     {
-      if (gimp_drawable_has_alpha (layers[i]))
+      GimpLayer *layer = GIMP_LAYER (gimp_item_new_by_id (layers[i]));
+
+      if (gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))
         {
           if (! (capabilities & GIMP_EXPORT_CAN_HANDLE_ALPHA))
             {
@@ -811,7 +848,7 @@ gimp_export_image (GimpImage             **image,
           /*  If this is the last layer, it's visible and has no alpha
            *  channel, then the image has a "flat" background
            */
-          if (i == n_layers - 1 && gimp_item_get_visible (layers[i]))
+          if (i == n_layers - 1 && gimp_item_get_visible (GIMP_ITEM (layer)))
             background_has_alpha = FALSE;
 
           if (capabilities & GIMP_EXPORT_NEEDS_ALPHA)
@@ -820,40 +857,47 @@ gimp_export_image (GimpImage             **image,
               break;
             }
         }
+      g_object_unref (layer);
     }
 
   if (! added_flatten)
     {
       for (i = 0; i < n_layers; i++)
         {
-          if (gimp_layer_get_mask (layers[i]) != -1)
+          GimpLayer *layer = GIMP_LAYER (gimp_item_new_by_id (layers[i]));
+
+          if (gimp_layer_get_mask (layer) != -1)
             has_layer_masks = TRUE;
+
+          g_object_unref (layer);
         }
     }
 
   if (! added_flatten)
     {
-      gint32  n_children;
-      gint32 *children;
+      GimpLayer *layer = GIMP_LAYER (gimp_item_new_by_id (layers[0]));
+      gint32    *children;
+      gint32     n_children;
 
-      children = gimp_item_get_children (layers[0], &n_children);
+      children = gimp_item_get_children (GIMP_ITEM (layer), &n_children);
+      g_object_unref (layer);
 
       /* check if layer size != canvas size, opacity != 100%, or offsets != 0 */
       if (n_layers == 1                     &&
           ! children                        &&
-          gimp_item_is_layer (*drawable_ID) &&
+          gimp_item_is_layer (GIMP_ITEM (*drawable)) &&
           ! (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS))
         {
           gint offset_x;
           gint offset_y;
 
-          gimp_drawable_offsets (*drawable_ID, &offset_x, &offset_y);
+          gimp_drawable_offsets (*drawable, &offset_x, &offset_y);
 
-          if ((gimp_layer_get_opacity (*drawable_ID) < 100.0) ||
+          if ((gimp_layer_get_opacity (GIMP_LAYER (*drawable)) < 100.0) ||
               (gimp_image_width (*image) !=
-               gimp_drawable_width (*drawable_ID))            ||
+               gimp_drawable_width (*drawable))            ||
               (gimp_image_height (*image) !=
-               gimp_drawable_height (*drawable_ID))           ||
+               gimp_drawable_height (*drawable))           ||
               offset_x || offset_y)
             {
               if (capabilities & GIMP_EXPORT_CAN_HANDLE_ALPHA)
@@ -1003,13 +1047,13 @@ gimp_export_image (GimpImage             **image,
       GSList *list;
 
       *image = gimp_image_duplicate (*image);
-      *drawable_ID = gimp_image_get_active_layer (*image);
+      *drawable = GIMP_DRAWABLE (gimp_image_get_active_layer (*image));
 
       gimp_image_undo_disable (*image);
 
       for (list = actions; list; list = list->next)
         {
-          export_action_perform (list->data, *image, drawable_ID);
+          export_action_perform (list->data, *image, drawable);
         }
     }
 
@@ -1127,18 +1171,30 @@ gimp_export_image_deprecated (gint32                 *image_ID,
                               const gchar            *format_name,
                               GimpExportCapabilities  capabilities)
 {
-  GimpImage        *image     = gimp_image_new_by_id (*image_ID);
-  GimpImage        *new_image = image;
+  GimpImage        *image;
+  GimpImage        *new_image;
+  GimpDrawable     *drawable;
+  GimpDrawable     *new_drawable;
   GimpExportReturn  retval;
 
-  retval = gimp_export_image (&new_image, drawable_ID,
+  image        = gimp_image_new_by_id (*image_ID);
+  new_image    = image;
+  drawable     = GIMP_DRAWABLE (gimp_item_new_by_id (*drawable_ID));
+  new_drawable = drawable;
+
+  retval = gimp_export_image (&new_image, &new_drawable,
                               format_name, capabilities);
 
-  *image_ID = gimp_image_get_id (new_image);
+  *image_ID    = gimp_image_get_id (new_image);
+  *drawable_ID = gimp_item_get_id (GIMP_ITEM (new_drawable));
   if (retval == GIMP_EXPORT_EXPORT)
-    g_object_unref (new_image);
+    {
+      g_object_unref (new_image);
+      g_object_unref (new_drawable);
+    }
 
   g_object_unref (image);
+  g_object_unref (drawable);
 
   return retval;
 }
diff --git a/libgimp/gimpexport.h b/libgimp/gimpexport.h
index 325ca9f3ca..f0ec72f698 100644
--- a/libgimp/gimpexport.h
+++ b/libgimp/gimpexport.h
@@ -84,7 +84,7 @@ GtkWidget        * gimp_export_dialog_get_content_area (GtkWidget              *
 #ifndef GIMP_DEPRECATED_REPLACE_NEW_API
 
 GimpExportReturn   gimp_export_image                   (GimpImage             **image,
-                                                        gint32                 *drawable_ID,
+                                                        GimpDrawable          **drawable,
                                                         const gchar            *format_name,
                                                         GimpExportCapabilities  capabilities);
 
diff --git a/libgimp/gimpimagemetadata.c b/libgimp/gimpimagemetadata.c
index d4eebb31cb..c4758f66d3 100644
--- a/libgimp/gimpimagemetadata.c
+++ b/libgimp/gimpimagemetadata.c
@@ -702,21 +702,22 @@ gimp_image_metadata_load_thumbnail (GFile   *file,
 
   if (pixbuf)
     {
-      gint32 layer_ID;
+      GimpLayer *layer;
 
       image = gimp_image_new (gdk_pixbuf_get_width  (pixbuf),
                                  gdk_pixbuf_get_height (pixbuf),
                                  GIMP_RGB);
       gimp_image_undo_disable (image);
 
-      layer_ID = gimp_layer_new_from_pixbuf (image, _("Background"),
-                                             pixbuf,
-                                             100.0,
-                                             gimp_image_get_default_new_layer_mode (image),
-                                             0.0, 0.0);
+      layer = gimp_layer_new_from_pixbuf (image, _("Background"),
+                                          pixbuf,
+                                          100.0,
+                                          gimp_image_get_default_new_layer_mode (image),
+                                          0.0, 0.0);
       g_object_unref (pixbuf);
 
-      gimp_image_insert_layer (image, layer_ID, -1, 0);
+      gimp_image_insert_layer (image, layer, NULL, 0);
+      g_object_unref (layer);
 
       gimp_image_metadata_rotate (image,
                                   gexiv2_metadata_get_orientation (GEXIV2_METADATA (metadata)));
diff --git a/libgimp/gimpitemcombobox.c b/libgimp/gimpitemcombobox.c
index 91650c92de..758afba3ce 100644
--- a/libgimp/gimpitemcombobox.c
+++ b/libgimp/gimpitemcombobox.c
@@ -467,12 +467,14 @@ gimp_item_combo_box_model_add (GimpIntComboBox *combo_box,
 
   for (i = 0; i < num_items; i++)
     {
+      GimpItem *item = gimp_item_new_by_id (items[i]);
+
       if ((! private->constraint && ! private->constraint_d)                                ||
           (private->constraint && (* private->constraint) (image, items[i], private->data)) ||
           (private->constraint_d && (* private->constraint_d) (gimp_image_get_id (image), items[i], 
private->data)))
         {
           gchar     *image_name = gimp_image_get_name (image);
-          gchar     *item_name  = gimp_item_get_name (items[i]);
+          gchar     *item_name  = gimp_item_get_name (item);
           gchar     *label;
           GdkPixbuf *thumb;
 
@@ -487,7 +489,7 @@ gimp_item_combo_box_model_add (GimpIntComboBox *combo_box,
           if (GIMP_IS_VECTORS_COMBO_BOX (combo_box))
             thumb = NULL;
           else
-            thumb = gimp_drawable_get_thumbnail (items[i],
+            thumb = gimp_drawable_get_thumbnail (GIMP_DRAWABLE (item),
                                                  THUMBNAIL_SIZE, THUMBNAIL_SIZE,
                                                  GIMP_PIXBUF_SMALL_CHECKS);
 
@@ -504,18 +506,20 @@ gimp_item_combo_box_model_add (GimpIntComboBox *combo_box,
           g_free (label);
         }
 
-      if (gimp_item_is_group (items[i]))
+      if (gimp_item_is_group (item))
         {
           gint32 *children;
           gint    n_children;
 
-          children = gimp_item_get_children (items[i], &n_children);
+          children = gimp_item_get_children (item, &n_children);
           gimp_item_combo_box_model_add (combo_box, store,
                                          image,
                                          n_children, children,
                                          tree_level + 1);
           g_free (children);
         }
+
+      g_object_unref (item);
     }
 
   g_free (indent);
@@ -583,7 +587,7 @@ gimp_item_combo_box_changed (GimpIntComboBox *combo_box)
 
   if (gimp_int_combo_box_get_active (combo_box, &item_ID))
     {
-      if (item_ID > 0 && ! gimp_item_is_valid (item_ID))
+      if (item_ID > 0 && ! _gimp_item_is_valid (item_ID))
         {
           GtkTreeModel *model;
           GList        *remove = NULL;
diff --git a/libgimp/gimplayer.c b/libgimp/gimplayer.c
index d019cb76a2..f9f6a49dc4 100644
--- a/libgimp/gimplayer.c
+++ b/libgimp/gimplayer.c
@@ -65,7 +65,7 @@ gimp_layer_init (GimpLayer *layer)
  *
  * Returns: The newly created layer.
  */
-gint32
+GimpLayer *
 gimp_layer_new (GimpImage     *image,
                 const gchar   *name,
                 gint           width,
@@ -85,7 +85,7 @@ gimp_layer_new (GimpImage     *image,
 
 /**
  * gimp_layer_copy:
- * @layer_ID: The layer to copy.
+ * @layer: The layer to copy.
  *
  * Copy a layer.
  *
@@ -93,12 +93,12 @@ gimp_layer_new (GimpImage     *image,
  * newly copied layer is for use within the original layer's image. It
  * should not be subsequently added to any other image.
  *
- * Returns: The newly copied layer.
+ * Returns: (transfer full): The newly copied layer.
  */
-gint32
-gimp_layer_copy (gint32  layer_ID)
+GimpLayer *
+gimp_layer_copy (GimpLayer *layer)
 {
-  return _gimp_layer_copy (layer_ID, FALSE);
+  return _gimp_layer_copy (layer, FALSE);
 }
 
 /**
@@ -125,7 +125,7 @@ gimp_layer_copy (gint32  layer_ID)
  *
  * Since: 2.4
  */
-gint32
+GimpLayer *
 gimp_layer_new_from_pixbuf (GimpImage     *image,
                             const gchar   *name,
                             GdkPixbuf     *pixbuf,
@@ -135,24 +135,24 @@ gimp_layer_new_from_pixbuf (GimpImage     *image,
                             gdouble        progress_end)
 {
   GeglBuffer *dest_buffer;
-  gint32      layer;
+  GimpLayer  *layer;
   gint        width;
   gint        height;
   gint        bpp;
   gdouble     range = progress_end - progress_start;
 
-  g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), -1);
+  g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
 
   if (gimp_image_base_type (image) != GIMP_RGB)
     {
       g_warning ("gimp_layer_new_from_pixbuf() needs an RGB image");
-      return -1;
+      return NULL;
     }
 
   if (gdk_pixbuf_get_colorspace (pixbuf) != GDK_COLORSPACE_RGB)
     {
       g_warning ("gimp_layer_new_from_pixbuf() assumes that GdkPixbuf is RGB");
-      return -1;
+      return NULL;
     }
 
   width  = gdk_pixbuf_get_width (pixbuf);
@@ -163,10 +163,10 @@ gimp_layer_new_from_pixbuf (GimpImage     *image,
                           bpp == 3 ? GIMP_RGB_IMAGE : GIMP_RGBA_IMAGE,
                           opacity, mode);
 
-  if (layer == -1)
-    return -1;
+  if (! layer)
+    return NULL;
 
-  dest_buffer = gimp_drawable_get_buffer (layer);
+  dest_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
 
   gegl_buffer_set (dest_buffer, GEGL_RECTANGLE (0, 0, width, height), 0,
                    gimp_pixbuf_get_format (pixbuf),
@@ -203,7 +203,7 @@ gimp_layer_new_from_pixbuf (GimpImage     *image,
  *
  * Since: 2.8
  */
-gint32
+GimpLayer *
 gimp_layer_new_from_surface (GimpImage            *image,
                              const gchar          *name,
                              cairo_surface_t      *surface,
@@ -212,20 +212,20 @@ gimp_layer_new_from_surface (GimpImage            *image,
 {
   GeglBuffer    *src_buffer;
   GeglBuffer    *dest_buffer;
-  gint32         layer;
+  GimpLayer     *layer;
   gint           width;
   gint           height;
   cairo_format_t format;
   gdouble        range = progress_end - progress_start;
 
-  g_return_val_if_fail (surface != NULL, -1);
+  g_return_val_if_fail (surface != NULL, NULL);
   g_return_val_if_fail (cairo_surface_get_type (surface) ==
-                        CAIRO_SURFACE_TYPE_IMAGE, -1);
+                        CAIRO_SURFACE_TYPE_IMAGE, NULL);
 
   if (gimp_image_base_type (image) != GIMP_RGB)
     {
       g_warning ("gimp_layer_new_from_surface() needs an RGB image");
-      return -1;
+      return NULL;
     }
 
   width  = cairo_image_surface_get_width (surface);
@@ -236,7 +236,7 @@ gimp_layer_new_from_surface (GimpImage            *image,
       format != CAIRO_FORMAT_RGB24)
     {
       g_warning ("gimp_layer_new_from_surface() assumes that surface is RGB");
-      return -1;
+      return NULL;
     }
 
   layer = gimp_layer_new (image, name, width, height,
@@ -245,11 +245,11 @@ gimp_layer_new_from_surface (GimpImage            *image,
                           100.0,
                           gimp_image_get_default_new_layer_mode (image));
 
-  if (layer == -1)
-    return -1;
+  if (layer == NULL)
+    return NULL;
 
   src_buffer = gimp_cairo_surface_create_buffer (surface);
-  dest_buffer = gimp_drawable_get_buffer (layer);
+  dest_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
 
   gegl_buffer_copy (src_buffer, NULL, GEGL_ABYSS_NONE,
                     dest_buffer, NULL);
@@ -298,12 +298,15 @@ gimp_layer_new_deprecated (gint32         image_id,
                            GimpLayerMode  mode)
 {
   GimpImage *image = gimp_image_new_by_id (image_id);
+  GimpLayer *layer;
   gint32     layer_id;
 
-  layer_id = gimp_layer_new (image, name, width, height,
-                             type, opacity, mode);
+  layer = gimp_layer_new (image, name, width, height,
+                          type, opacity, mode);
+  layer_id = gimp_item_get_id (GIMP_ITEM (layer));
 
   g_object_unref (image);
+  g_object_unref (layer);
 
   return layer_id;
 }
@@ -342,12 +345,15 @@ gimp_layer_new_from_pixbuf_deprecated (gint32         image_id,
                                        gdouble        progress_end)
 {
   GimpImage *image = gimp_image_new_by_id (image_id);
+  GimpLayer *layer;
   gint32     layer_id;
 
-  layer_id = gimp_layer_new_from_pixbuf (image, name, pixbuf, opacity, mode,
-                                          progress_start, progress_end);
+  layer = gimp_layer_new_from_pixbuf (image, name, pixbuf, opacity, mode,
+                                      progress_start, progress_end);
+  layer_id = gimp_item_get_id (GIMP_ITEM (layer));
 
   g_object_unref (image);
+  g_object_unref (layer);
 
   return layer_id;
 }
@@ -382,12 +388,48 @@ gimp_layer_new_from_surface_deprecated (gint32                image_id,
                                         gdouble               progress_end)
 {
   GimpImage *image = gimp_image_new_by_id (image_id);
+  GimpLayer *layer;
   gint32     layer_id;
 
-  layer_id = gimp_layer_new_from_surface (image, name, surface,
-                                          progress_start, progress_end);
+  layer = gimp_layer_new_from_surface (image, name, surface,
+                                       progress_start, progress_end);
+  layer_id = gimp_item_get_id (GIMP_ITEM (layer));
 
   g_object_unref (image);
+  g_object_unref (layer);
 
   return layer_id;
 }
+
+/**
+ * gimp_layer_copy_deprecated: (skip)
+ * @layer_ID: The layer to copy.
+ *
+ * Copy a layer.
+ *
+ * This procedure copies the specified layer and returns the copy. The
+ * newly copied layer is for use within the original layer's image. It
+ * should not be subsequently added to any other image.
+ *
+ * Returns: The newly copied layer.
+ */
+gint32
+gimp_layer_copy_deprecated (gint32 layer_ID)
+{
+  GimpLayer *layer;
+  GimpLayer *copy;
+  gint32     copy_id;
+
+  layer = GIMP_LAYER (gimp_item_new_by_id (layer_ID));
+  g_return_val_if_fail (layer, -1);
+
+  copy = gimp_layer_copy (layer);
+  g_return_val_if_fail (copy, -1);
+
+  copy_id = gimp_item_get_id (GIMP_ITEM (copy));
+
+  g_object_unref (copy);
+  g_object_unref (layer);
+
+  return copy_id;
+}
diff --git a/libgimp/gimplayer.h b/libgimp/gimplayer.h
index fc4dfd530d..aa36e85422 100644
--- a/libgimp/gimplayer.h
+++ b/libgimp/gimplayer.h
@@ -63,37 +63,38 @@ struct _GimpLayerClass
 
 GType    gimp_layer_get_type           (void) G_GNUC_CONST;
 
-gint32   gimp_layer_copy               (gint32           layer_ID);
-
 
 #ifndef GIMP_DEPRECATED_REPLACE_NEW_API
 
-gint32   gimp_layer_new                (GimpImage       *image,
-                                        const gchar     *name,
-                                        gint             width,
-                                        gint             height,
-                                        GimpImageType    type,
-                                        gdouble          opacity,
-                                        GimpLayerMode    mode);
-
-gint32   gimp_layer_new_from_pixbuf    (GimpImage       *image,
-                                        const gchar     *name,
-                                        GdkPixbuf       *pixbuf,
-                                        gdouble          opacity,
-                                        GimpLayerMode    mode,
-                                        gdouble          progress_start,
-                                        gdouble          progress_end);
-gint32   gimp_layer_new_from_surface   (GimpImage       *image,
-                                        const gchar     *name,
-                                        cairo_surface_t *surface,
-                                        gdouble          progress_start,
-                                        gdouble          progress_end);
+GimpLayer * gimp_layer_new                (GimpImage       *image,
+                                           const gchar     *name,
+                                           gint             width,
+                                           gint             height,
+                                           GimpImageType    type,
+                                           gdouble          opacity,
+                                           GimpLayerMode    mode);
+
+GimpLayer * gimp_layer_new_from_pixbuf    (GimpImage       *image,
+                                           const gchar     *name,
+                                           GdkPixbuf       *pixbuf,
+                                           gdouble          opacity,
+                                           GimpLayerMode    mode,
+                                           gdouble          progress_start,
+                                           gdouble          progress_end);
+GimpLayer * gimp_layer_new_from_surface   (GimpImage       *image,
+                                           const gchar     *name,
+                                           cairo_surface_t *surface,
+                                           gdouble          progress_start,
+                                           gdouble          progress_end);
+
+GimpLayer * gimp_layer_copy               (GimpLayer       *layer);
 
 #else /* GIMP_DEPRECATED_REPLACE_NEW_API */
 
 #define gimp_layer_new              gimp_layer_new_deprecated
 #define gimp_layer_new_from_pixbuf  gimp_layer_new_from_pixbuf_deprecated
 #define gimp_layer_new_from_surface gimp_layer_new_from_surface_deprecated
+#define gimp_layer_copy             gimp_layer_copy_deprecated
 
 #endif /* GIMP_DEPRECATED_REPLACE_NEW_API */
 
@@ -119,6 +120,7 @@ gint32   gimp_layer_new_from_surface_deprecated (gint32           image_id,
                                                  gdouble          progress_start,
                                                  gdouble          progress_end);
 
+gint32   gimp_layer_copy_deprecated             (gint32           layer_ID);
 
 G_END_DECLS
 
diff --git a/libgimp/gimpparamspecs.c b/libgimp/gimpparamspecs.c
index f5e3062511..19ebfc2c1f 100644
--- a/libgimp/gimpparamspecs.c
+++ b/libgimp/gimpparamspecs.c
@@ -297,7 +297,7 @@ gimp_param_item_id_validate (GParamSpec *pspec,
   if (ispec->none_ok && (item_id == 0 || item_id == -1))
     return FALSE;
 
-  if (! gimp_item_is_valid (item_id))
+  if (! _gimp_item_is_valid (item_id))
     {
       value->data[0].v_int = -1;
       return TRUE;
@@ -452,7 +452,7 @@ gimp_param_drawable_id_validate (GParamSpec *pspec,
   if (ispec->none_ok && (item_id == 0 || item_id == -1))
     return FALSE;
 
-  if (! gimp_item_is_drawable (item_id))
+  if (! _gimp_item_is_drawable (item_id))
     {
       value->data[0].v_int = -1;
       return TRUE;
@@ -589,7 +589,7 @@ gimp_param_layer_id_validate (GParamSpec *pspec,
   if (ispec->none_ok && (item_id == 0 || item_id == -1))
     return FALSE;
 
-  if (! gimp_item_is_layer (item_id))
+  if (! _gimp_item_is_layer (item_id))
     {
       value->data[0].v_int = -1;
       return TRUE;
@@ -726,7 +726,7 @@ gimp_param_channel_id_validate (GParamSpec *pspec,
   if (ispec->none_ok && (item_id == 0 || item_id == -1))
     return FALSE;
 
-  if (! gimp_item_is_channel (item_id))
+  if (! _gimp_item_is_channel (item_id))
     {
       value->data[0].v_int = -1;
       return TRUE;
@@ -863,7 +863,7 @@ gimp_param_layer_mask_id_validate (GParamSpec *pspec,
   if (ispec->none_ok && (item_id == 0 || item_id == -1))
     return FALSE;
 
-  if (! gimp_item_is_layer_mask (item_id))
+  if (! _gimp_item_is_layer_mask (item_id))
     {
       value->data[0].v_int = -1;
       return TRUE;
@@ -1000,7 +1000,7 @@ gimp_param_selection_id_validate (GParamSpec *pspec,
   if (ispec->none_ok && (item_id == 0 || item_id == -1))
     return FALSE;
 
-  if (! gimp_item_is_selection (item_id))
+  if (! _gimp_item_is_selection (item_id))
     {
       value->data[0].v_int = -1;
       return TRUE;
@@ -1137,7 +1137,7 @@ gimp_param_vectors_id_validate (GParamSpec *pspec,
   if (ispec->none_ok && (item_id == 0 || item_id == -1))
     return FALSE;
 
-  if (! gimp_item_is_vectors (item_id))
+  if (! _gimp_item_is_vectors (item_id))
     {
       value->data[0].v_int = -1;
       return TRUE;
diff --git a/libgimp/gimpselection.c b/libgimp/gimpselection.c
index 00c94e3c2f..58bc224366 100644
--- a/libgimp/gimpselection.c
+++ b/libgimp/gimpselection.c
@@ -24,6 +24,39 @@
 
 /**
  * gimp_selection_float:
+ * @image: ignored
+ * @drawable: The drawable from which to float selection.
+ * @offx: x offset for translation.
+ * @offy: y offset for translation.
+ *
+ * Float the selection from the specified drawable with initial offsets
+ * as specified.
+ *
+ * This procedure determines the region of the specified drawable that
+ * lies beneath the current selection. The region is then cut from the
+ * drawable and the resulting data is made into a new layer which is
+ * instantiated as a floating selection. The offsets allow initial
+ * positioning of the new floating selection.
+ *
+ * Returns: (transfer full): The floated layer.
+ */
+GimpLayer *
+gimp_selection_float (GimpImage    *image,
+                      GimpDrawable *drawable,
+                      gint          offx,
+                      gint          offy)
+{
+  return _gimp_selection_float (drawable,
+                                offx,
+                                offy);
+}
+
+
+/* Deprecated API. */
+
+
+/**
+ * gimp_selection_float_deprecated: (skip)
  * @image_ID: ignored
  * @drawable_ID: The drawable from which to float selection.
  * @offx: x offset for translation.
@@ -41,12 +74,28 @@
  * Returns: The floated layer.
  */
 gint32
-gimp_selection_float (gint32 image_ID,
-                      gint32 drawable_ID,
-                      gint   offx,
-                      gint   offy)
+gimp_selection_float_deprecated (gint32 image_ID,
+                                 gint32 drawable_ID,
+                                 gint   offx,
+                                 gint   offy)
 {
-  return _gimp_selection_float (drawable_ID,
-                                offx,
-                                offy);
+  GimpImage    *image;
+  GimpDrawable *drawable;
+  GimpLayer    *selection;
+  gint32        selection_id = -1;
+
+  image    = gimp_image_new_by_id (image_ID);
+  drawable = GIMP_DRAWABLE (gimp_item_new_by_id (drawable_ID));
+
+  selection = gimp_selection_float (image, drawable,
+                                    offx,
+                                    offy);
+  if (selection)
+    selection_id = gimp_item_get_id (GIMP_ITEM (selection));
+
+  g_object_unref (image);
+  g_object_unref (drawable);
+  g_object_unref (selection);
+
+  return selection_id;
 }
diff --git a/libgimp/gimpselection.h b/libgimp/gimpselection.h
index 8058c343ac..5073b43228 100644
--- a/libgimp/gimpselection.h
+++ b/libgimp/gimpselection.h
@@ -30,10 +30,24 @@ G_BEGIN_DECLS
 /* For information look into the C source or the html documentation */
 
 
-gint32   gimp_selection_float (gint32 image_ID,
-                               gint32 drawable_ID,
-                               gint   offx,
-                               gint   offy);
+#ifndef GIMP_DEPRECATED_REPLACE_NEW_API
+
+GimpLayer * gimp_selection_float (GimpImage    *image,
+                                  GimpDrawable *drawable,
+                                  gint          offx,
+                                  gint          offy);
+
+#else /* GIMP_DEPRECATED_REPLACE_NEW_API */
+
+#define gimp_selection_float gimp_selection_float_deprecated
+
+#endif /* GIMP_DEPRECATED_REPLACE_NEW_API */
+
+
+gint32   gimp_selection_float_deprecated (gint32 image_ID,
+                                          gint32 drawable_ID,
+                                          gint   offx,
+                                          gint   offy);
 
 
 G_END_DECLS
diff --git a/libgimp/gimptilebackendplugin.c b/libgimp/gimptilebackendplugin.c
index 8d52431115..955a0de7a6 100644
--- a/libgimp/gimptilebackendplugin.c
+++ b/libgimp/gimptilebackendplugin.c
@@ -175,14 +175,14 @@ gimp_tile_backend_plugin_command (GeglTileSource  *tile_store,
 /*  public functions  */
 
 GeglTileBackend *
-_gimp_tile_backend_plugin_new (gint32 drawable_id,
-                               gint   shadow)
+_gimp_tile_backend_plugin_new (GimpDrawable *drawable,
+                               gint          shadow)
 {
   GeglTileBackend       *backend;
   GimpTileBackendPlugin *backend_plugin;
-  const Babl            *format = gimp_drawable_get_format (drawable_id);
-  gint                   width  = gimp_drawable_width  (drawable_id);
-  gint                   height = gimp_drawable_height (drawable_id);
+  const Babl            *format = gimp_drawable_get_format (drawable);
+  gint                   width  = gimp_drawable_width  (drawable);
+  gint                   height = gimp_drawable_height (drawable);
 
   backend = g_object_new (GIMP_TYPE_TILE_BACKEND_PLUGIN,
                           "tile-width",  TILE_WIDTH,
@@ -192,11 +192,11 @@ _gimp_tile_backend_plugin_new (gint32 drawable_id,
 
   backend_plugin = GIMP_TILE_BACKEND_PLUGIN (backend);
 
-  backend_plugin->priv->drawable_id = drawable_id;
+  backend_plugin->priv->drawable_id = gimp_item_get_id (GIMP_ITEM (drawable));
   backend_plugin->priv->shadow      = shadow;
   backend_plugin->priv->width       = width;
   backend_plugin->priv->height      = height;
-  backend_plugin->priv->bpp         = gimp_drawable_bpp (drawable_id);
+  backend_plugin->priv->bpp         = gimp_drawable_bpp (drawable);
   backend_plugin->priv->ntile_rows  = (height + TILE_HEIGHT - 1) / TILE_HEIGHT;
   backend_plugin->priv->ntile_cols  = (width  + TILE_WIDTH  - 1) / TILE_WIDTH;
 
diff --git a/libgimp/gimptilebackendplugin.h b/libgimp/gimptilebackendplugin.h
index cfb77c53a8..3afefc39fd 100644
--- a/libgimp/gimptilebackendplugin.h
+++ b/libgimp/gimptilebackendplugin.h
@@ -52,8 +52,8 @@ struct _GimpTileBackendPluginClass
 
 GType             _gimp_tile_backend_plugin_get_type (void) G_GNUC_CONST;
 
-GeglTileBackend * _gimp_tile_backend_plugin_new      (gint32 drawable_id,
-                                                      gint   shadow);
+GeglTileBackend * _gimp_tile_backend_plugin_new      (GimpDrawable *drawable,
+                                                      gint          shadow);
 
 G_END_DECLS
 
diff --git a/libgimp/gimpzoompreview.c b/libgimp/gimpzoompreview.c
index 8dcae1f7a8..490a558b1e 100644
--- a/libgimp/gimpzoompreview.c
+++ b/libgimp/gimpzoompreview.c
@@ -46,7 +46,7 @@
 enum
 {
   PROP_0,
-  PROP_DRAWABLE_ID,
+  PROP_DRAWABLE,
   PROP_MODEL
 };
 
@@ -58,7 +58,7 @@ typedef struct
 
 struct _GimpZoomPreviewPrivate
 {
-  gint32         drawable_ID;
+  GimpDrawable  *drawable;
   GimpZoomModel *model;
   GdkRectangle   extents;
 };
@@ -108,8 +108,8 @@ static void     gimp_zoom_preview_untransform     (GimpPreview     *preview,
                                                    gint            *dest_x,
                                                    gint            *dest_y);
 
-static void     gimp_zoom_preview_set_drawable_id (GimpZoomPreview *preview,
-                                                   gint32           drawable_ID);
+static void     gimp_zoom_preview_set_drawable    (GimpZoomPreview *preview,
+                                                   GimpDrawable    *drawable);
 static void     gimp_zoom_preview_set_model       (GimpZoomPreview *preview,
                                                    GimpZoomModel   *model);
 
@@ -157,13 +157,13 @@ gimp_zoom_preview_class_init (GimpZoomPreviewClass *klass)
    *
    * Since: 2.10
    */
-  g_object_class_install_property (object_class, PROP_DRAWABLE_ID,
-                                   g_param_spec_int ("drawable-id",
-                                                     "Drawable ID",
-                                                     "The drawable this preview is attached to",
-                                                     -1, G_MAXINT, -1,
-                                                     GIMP_PARAM_READWRITE |
-                                                     G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property (object_class, PROP_DRAWABLE,
+                                   g_param_spec_object ("drawable",
+                                                        "Drawable",
+                                                        "The drawable this preview is attached to",
+                                                        GIMP_TYPE_DRAWABLE,
+                                                        GIMP_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT_ONLY));
 
   /**
    * GimpZoomPreview:model:
@@ -244,6 +244,7 @@ gimp_zoom_preview_finalize (GObject *object)
   GimpZoomPreviewPrivate *priv = GET_PRIVATE (object);
 
   g_clear_object (&priv->model);
+  g_clear_object (&priv->drawable);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -277,8 +278,8 @@ gimp_zoom_preview_get_property (GObject    *object,
 
   switch (property_id)
     {
-    case PROP_DRAWABLE_ID:
-      g_value_set_int (value, gimp_zoom_preview_get_drawable_id (preview));
+    case PROP_DRAWABLE:
+      g_value_set_object (value, gimp_zoom_preview_get_drawable (preview));
       break;
 
     case PROP_MODEL:
@@ -301,8 +302,8 @@ gimp_zoom_preview_set_property (GObject      *object,
 
   switch (property_id)
     {
-    case PROP_DRAWABLE_ID:
-      gimp_zoom_preview_set_drawable_id (preview, g_value_get_int (value));
+    case PROP_DRAWABLE:
+      gimp_zoom_preview_set_drawable (preview, g_value_dup_object (value));
       break;
 
     case PROP_MODEL:
@@ -397,7 +398,7 @@ gimp_zoom_preview_style_updated (GtkWidget *widget)
 
       gtk_widget_style_get (widget, "size", &size, NULL);
 
-      if (_gimp_drawable_preview_get_bounds (priv->drawable_ID,
+      if (_gimp_drawable_preview_get_bounds (priv->drawable,
                                              &x1, &y1, &x2, &y2))
         {
           width  = x2 - x1;
@@ -405,8 +406,8 @@ gimp_zoom_preview_style_updated (GtkWidget *widget)
         }
       else
         {
-          width  = gimp_drawable_width  (priv->drawable_ID);
-          height = gimp_drawable_height (priv->drawable_ID);
+          width  = gimp_drawable_width  (priv->drawable);
+          height = gimp_drawable_height (priv->drawable);
         }
 
       if (width > height)
@@ -473,7 +474,7 @@ gimp_zoom_preview_draw (GimpPreview *preview)
   if (! priv->model)
     return;
 
-  if (priv->drawable_ID < 1)
+  if (priv->drawable == NULL)
     return;
 
   data = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview),
@@ -485,7 +486,7 @@ gimp_zoom_preview_draw (GimpPreview *preview)
 
       gimp_preview_area_draw (GIMP_PREVIEW_AREA (area),
                               0, 0, width, height,
-                              gimp_drawable_type (priv->drawable_ID),
+                              gimp_drawable_type (priv->drawable),
                               data, width * bpp);
       g_free (data);
     }
@@ -503,32 +504,34 @@ gimp_zoom_preview_draw_buffer (GimpPreview  *preview,
   gint                    height;
 
   gimp_preview_get_size (preview, &width, &height);
-  image = gimp_item_get_image (priv->drawable_ID);
+  image = gimp_item_get_image (GIMP_ITEM (priv->drawable));
 
   if (gimp_selection_is_empty (image))
     {
       gimp_preview_area_draw (GIMP_PREVIEW_AREA (area),
                               0, 0,
                               width, height,
-                              gimp_drawable_type (priv->drawable_ID),
+                              gimp_drawable_type (priv->drawable),
                               buffer,
                               rowstride);
     }
   else
     {
-      guchar  *sel;
-      guchar  *src;
-      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;
+      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));
 
       w = width;
       h = height;
@@ -537,20 +540,21 @@ gimp_zoom_preview_draw_buffer (GimpPreview  *preview,
                                          &src_x, &src_y,
                                          &src_width, &src_height);
 
-      src = gimp_drawable_get_sub_thumbnail_data (priv->drawable_ID,
+      src = gimp_drawable_get_sub_thumbnail_data (priv->drawable,
                                                   src_x, src_y,
                                                   src_width, src_height,
                                                   &w, &h, &bpp);
-      gimp_drawable_offsets (priv->drawable_ID, &offsx, &offsy);
-      sel = gimp_drawable_get_sub_thumbnail_data (selection_ID,
+      gimp_drawable_offsets (priv->drawable, &offsx, &offsy);
+      sel = gimp_drawable_get_sub_thumbnail_data (selection,
                                                   src_x + offsx, src_y + offsy,
                                                   src_width, src_height,
                                                   &width, &height, &bpp);
+      g_object_unref (selection);
 
       gimp_preview_area_mask (GIMP_PREVIEW_AREA (area),
                               0, 0, width, height,
-                              gimp_drawable_type (priv->drawable_ID),
-                              src, width * gimp_drawable_bpp (priv->drawable_ID),
+                              gimp_drawable_type (priv->drawable),
+                              src, width * gimp_drawable_bpp (priv->drawable),
                               buffer, rowstride,
                               sel, width);
 
@@ -569,8 +573,8 @@ gimp_zoom_preview_draw_thumb (GimpPreview     *preview,
 {
   GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW (preview)->priv;
 
-  if (priv->drawable_ID > 0)
-    _gimp_drawable_preview_area_draw_thumb (area, priv->drawable_ID,
+  if (priv->drawable != NULL)
+    _gimp_drawable_preview_area_draw_thumb (area, priv->drawable,
                                             width, height);
 }
 
@@ -654,27 +658,27 @@ gimp_zoom_preview_untransform (GimpPreview *preview,
 }
 
 static void
-gimp_zoom_preview_set_drawable_id (GimpZoomPreview *preview,
-                                   gint32           drawable_ID)
+gimp_zoom_preview_set_drawable (GimpZoomPreview *preview,
+                                GimpDrawable    *drawable)
 {
   GimpZoomPreviewPrivate *priv = preview->priv;
   gint                    x, y;
   gint                    width, height;
   gint                    max_width, max_height;
 
-  g_return_if_fail (preview->priv->drawable_ID < 1);
+  g_return_if_fail (preview->priv->drawable == NULL);
 
-  priv->drawable_ID = drawable_ID;
+  priv->drawable = drawable;
 
-  if (gimp_drawable_mask_intersect (drawable_ID, &x, &y, &width, &height))
+  if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
     {
       priv->extents.x = x;
       priv->extents.y = y;
     }
   else
     {
-      width  = gimp_drawable_width  (drawable_ID);
-      height = gimp_drawable_height (drawable_ID);
+      width  = gimp_drawable_width  (drawable);
+      height = gimp_drawable_height (drawable);
 
       priv->extents.x = 0;
       priv->extents.y = 0;
@@ -760,35 +764,35 @@ gimp_zoom_preview_get_source_area (GimpPreview *preview,
 
 
 /**
- * gimp_zoom_preview_new_from_drawable_id:
- * @drawable_ID: a drawable ID
+ * gimp_zoom_preview_new_from_drawable:
+ * @drawable: (transfer none): a drawable
  *
- * Creates a new #GimpZoomPreview widget for @drawable_ID.
+ * Creates a new #GimpZoomPreview widget for @drawable.
  *
- * Since: 2.10
+ * Since: 3.0
  *
  * Returns: a new #GimpZoomPreview.
  **/
 GtkWidget *
-gimp_zoom_preview_new_from_drawable_id (gint32 drawable_ID)
+gimp_zoom_preview_new_from_drawable (GimpDrawable *drawable)
 {
-  g_return_val_if_fail (gimp_item_is_valid (drawable_ID), NULL);
-  g_return_val_if_fail (gimp_item_is_drawable (drawable_ID), NULL);
+  g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
+  g_return_val_if_fail (gimp_item_is_valid (GIMP_ITEM (drawable)), NULL);
 
   return g_object_new (GIMP_TYPE_ZOOM_PREVIEW,
-                       "drawable-id", drawable_ID,
+                       "drawable", drawable,
                        NULL);
 }
 
 /**
  * gimp_zoom_preview_new_with_model_from_drawable_id:
- * @drawable_ID: a drawable ID
- * @model:       a #GimpZoomModel
+ * @drawable: (transfer none): a drawable
+ * @model:    (transfer full): a #GimpZoomModel
  *
- * Creates a new #GimpZoomPreview widget for @drawable_ID using the
+ * Creates a new #GimpZoomPreview widget for @drawableusing the
  * given @model.
  *
- * This variant of gimp_zoom_preview_new_from_drawable_id() allows you
+ * This variant of gimp_zoom_preview_new_from_drawable() allows you
  * to create a preview using an existing zoom model. This may be
  * useful if for example you want to have two zoom previews that keep
  * their zoom factor in sync.
@@ -798,37 +802,37 @@ gimp_zoom_preview_new_from_drawable_id (gint32 drawable_ID)
  * Returns: a new #GimpZoomPreview.
  **/
 GtkWidget *
-gimp_zoom_preview_new_with_model_from_drawable_id (gint32         drawable_ID,
-                                                   GimpZoomModel *model)
+gimp_zoom_preview_new_with_model_from_drawable (GimpDrawable  *drawable,
+                                                GimpZoomModel *model)
 
 {
-  g_return_val_if_fail (gimp_item_is_valid (drawable_ID), NULL);
-  g_return_val_if_fail (gimp_item_is_drawable (drawable_ID), NULL);
+  g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
+  g_return_val_if_fail (gimp_item_is_valid (GIMP_ITEM (drawable)), NULL);
   g_return_val_if_fail (GIMP_IS_ZOOM_MODEL (model), NULL);
 
   return g_object_new (GIMP_TYPE_ZOOM_PREVIEW,
-                       "drawable-id", drawable_ID,
-                       "model",       model,
+                       "drawable", drawable,
+                       "model",    model,
                        NULL);
 }
 
 /**
- * gimp_zoom_preview_get_drawable_id:
+ * gimp_zoom_preview_get_drawable:
  * @preview: a #GimpZoomPreview widget
  *
- * Returns the drawable_ID the #GimpZoomPreview is attached to.
+ * Returns the drawable the #GimpZoomPreview is attached to.
  *
- * Returns: the drawable_ID that was passed to
- * gimp_zoom_preview_new_from_drawable_id().
+ * Returns: (transfer none): the drawable that was passed to
+ *          gimp_zoom_preview_new_from_drawable().
  *
- * Since: 2.10
+ * Since: 3.0
  **/
-gint32
-gimp_zoom_preview_get_drawable_id (GimpZoomPreview *preview)
+GimpDrawable *
+gimp_zoom_preview_get_drawable (GimpZoomPreview *preview)
 {
-  g_return_val_if_fail (GIMP_IS_ZOOM_PREVIEW (preview), -1);
+  g_return_val_if_fail (GIMP_IS_ZOOM_PREVIEW (preview), NULL);
 
-  return GET_PRIVATE (preview)->drawable_ID;
+  return GET_PRIVATE (preview)->drawable;
 }
 
 /**
@@ -838,7 +842,7 @@ gimp_zoom_preview_get_drawable_id (GimpZoomPreview *preview)
  * Returns the #GimpZoomModel the preview is using.
  *
  * Returns: (transfer none): a pointer to the #GimpZoomModel owned
- *               by the @preview
+ *          by the @preview
  *
  * Since: 2.4
  **/
@@ -897,14 +901,14 @@ gimp_zoom_preview_get_source (GimpZoomPreview *preview,
                               gint            *height,
                               gint            *bpp)
 {
-  gint32 drawable_ID;
+  GimpDrawable *drawable;
 
   g_return_val_if_fail (GIMP_IS_ZOOM_PREVIEW (preview), NULL);
   g_return_val_if_fail (width != NULL && height != NULL && bpp != NULL, NULL);
 
-  drawable_ID = gimp_zoom_preview_get_drawable_id (preview);
+  drawable = gimp_zoom_preview_get_drawable (preview);
 
-  if (drawable_ID > 0)
+  if (drawable)
     {
       GimpPreview *gimp_preview = GIMP_PREVIEW (preview);
       gint         src_x;
@@ -918,7 +922,7 @@ gimp_zoom_preview_get_source (GimpZoomPreview *preview,
                                          &src_x, &src_y,
                                          &src_width, &src_height);
 
-      return gimp_drawable_get_sub_thumbnail_data (drawable_ID,
+      return gimp_drawable_get_sub_thumbnail_data (drawable,
                                                    src_x, src_y,
                                                    src_width, src_height,
                                                    width, height, bpp);
diff --git a/libgimp/gimpzoompreview.h b/libgimp/gimpzoompreview.h
index eca61d25a2..da358ab21e 100644
--- a/libgimp/gimpzoompreview.h
+++ b/libgimp/gimpzoompreview.h
@@ -68,10 +68,9 @@ struct _GimpZoomPreviewClass
 
 GType           gimp_zoom_preview_get_type       (void) G_GNUC_CONST;
 
-GtkWidget     * gimp_zoom_preview_new_from_drawable_id
-                                                 (gint32           drawable_ID);
-GtkWidget     * gimp_zoom_preview_new_with_model_from_drawable_id
-                                                 (gint32           drawable_ID,
+GtkWidget     * gimp_zoom_preview_new_from_drawable (GimpDrawable *drawable);
+GtkWidget     * gimp_zoom_preview_new_with_model_from_drawable
+                                                 (GimpDrawable    *drawable,
                                                   GimpZoomModel   *model);
 
 guchar        * gimp_zoom_preview_get_source     (GimpZoomPreview *preview,
@@ -79,7 +78,7 @@ guchar        * gimp_zoom_preview_get_source     (GimpZoomPreview *preview,
                                                   gint            *height,
                                                   gint            *bpp);
 
-gint32          gimp_zoom_preview_get_drawable_id(GimpZoomPreview *preview);
+GimpDrawable  * gimp_zoom_preview_get_drawable   (GimpZoomPreview *preview);
 GimpZoomModel * gimp_zoom_preview_get_model      (GimpZoomPreview *preview);
 gdouble         gimp_zoom_preview_get_factor     (GimpZoomPreview *preview);
 


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