[gimp] app: add utility functions to get a generic paste GimpObject



commit 35588d79c8340993b5f7c33740a36ba431283d46
Author: Michael Natterer <mitch gimp org>
Date:   Wed Sep 21 00:11:15 2016 +0200

    app: add utility functions to get a generic paste GimpObject
    
    to Gimp and GimpClipboard. The object is either an image or a buffer
    or NULL.

 app/core/gimp.c             |   11 +++++++++++
 app/core/gimp.h             |    2 ++
 app/widgets/gimpclipboard.c |   30 +++++++++++++++++++++++++++++-
 app/widgets/gimpclipboard.h |    2 ++
 4 files changed, 44 insertions(+), 1 deletions(-)
---
diff --git a/app/core/gimp.c b/app/core/gimp.c
index d431d51..4e2af54 100644
--- a/app/core/gimp.c
+++ b/app/core/gimp.c
@@ -975,6 +975,17 @@ gimp_get_tool_info_iter (Gimp *gimp)
   return GIMP_LIST (gimp->tool_info_list)->queue->head;
 }
 
+GimpObject *
+gimp_get_clipboard_object (Gimp *gimp)
+{
+  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
+
+  if (gimp->clipboard_image)
+    return GIMP_OBJECT (gimp->clipboard_image);
+
+  return GIMP_OBJECT (gimp->clipboard_buffer);
+}
+
 void
 gimp_set_clipboard_image (Gimp      *gimp,
                           GimpImage *image)
diff --git a/app/core/gimp.h b/app/core/gimp.h
index 0012c6a..289be8e 100644
--- a/app/core/gimp.h
+++ b/app/core/gimp.h
@@ -185,6 +185,8 @@ GList        * gimp_get_image_windows      (Gimp                *gimp);
 GList        * gimp_get_paint_info_iter    (Gimp                *gimp);
 GList        * gimp_get_tool_info_iter     (Gimp                *gimp);
 
+GimpObject   * gimp_get_clipboard_object   (Gimp                *gimp);
+
 void           gimp_set_clipboard_image    (Gimp                *gimp,
                                             GimpImage           *image);
 GimpImage    * gimp_get_clipboard_image    (Gimp                *gimp);
diff --git a/app/widgets/gimpclipboard.c b/app/widgets/gimpclipboard.c
index 40aa6d7..1383e78 100644
--- a/app/widgets/gimpclipboard.c
+++ b/app/widgets/gimpclipboard.c
@@ -358,10 +358,38 @@ gimp_clipboard_has_curve (Gimp *gimp)
 }
 
 /**
+ * gimp_clipboard_get_object:
+ * @gimp: pointer to #Gimp
+ *
+ * Retrieves either an image or a buffer from the global image cut
+ * buffer of @gimp.
+ *
+ * The returned #GimpObject needs to be unref'ed when it's no longer
+ * needed.
+ *
+ * Return value: a reference to a #GimpObject or %NULL if there's no
+ *               image or buffer in the clipboard
+ **/
+GimpObject *
+gimp_clipboard_get_object (Gimp *gimp)
+{
+  GimpObject *object;
+
+  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
+
+  object = GIMP_OBJECT (gimp_clipboard_get_image (gimp));
+
+  if (! object)
+    object = GIMP_OBJECT (gimp_clipboard_get_buffer (gimp));
+
+  return object;
+}
+
+/**
  * gimp_clipboard_get_image:
  * @gimp: pointer to #Gimp
  *
- * Retrieves either an image from the global image cut buffer of @gimp.
+ * Retrieves an image from the global image cut buffer of @gimp.
  *
  * The returned #GimpImage needs to be unref'ed when it's no longer
  * needed.
diff --git a/app/widgets/gimpclipboard.h b/app/widgets/gimpclipboard.h
index 638ab14..dc2a1f1 100644
--- a/app/widgets/gimpclipboard.h
+++ b/app/widgets/gimpclipboard.h
@@ -27,6 +27,8 @@ gboolean     gimp_clipboard_has_buffer (Gimp        *gimp);
 gboolean     gimp_clipboard_has_svg    (Gimp        *gimp);
 gboolean     gimp_clipboard_has_curve  (Gimp        *gimp);
 
+GimpObject * gimp_clipboard_get_object (Gimp        *gimp);
+
 GimpImage  * gimp_clipboard_get_image  (Gimp        *gimp);
 GimpBuffer * gimp_clipboard_get_buffer (Gimp        *gimp);
 gchar      * gimp_clipboard_get_svg    (Gimp        *gimp,


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