[gtkmm] Add Gdk::ContentProvider



commit 6422c7665c5d9ffcc097f4d48d19fd23b2301d44
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Sun Dec 17 16:52:09 2017 +0100

    Add Gdk::ContentProvider
    
    and add more methods to Gdk::Clipboard.

 .gitignore                  |    2 +
 gdk/src/clipboard.ccg       |   34 ++++++++++++++++++++
 gdk/src/clipboard.hg        |   52 ++++++++++++++++++++++++++++--
 gdk/src/contentprovider.ccg |   16 +++++++++
 gdk/src/contentprovider.hg  |   73 +++++++++++++++++++++++++++++++++++++++++++
 gdk/src/filelist.am         |    1 +
 tools/m4/convert_gdk.m4     |    5 +++
 7 files changed, 179 insertions(+), 4 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 3266ff8..f839abe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -57,6 +57,8 @@ gdk/gdkmm/contentformats.cc
 gdk/gdkmm/contentformats.h
 gdk/gdkmm/contentformatsbuilder.cc
 gdk/gdkmm/contentformatsbuilder.h
+gdk/gdkmm/contentprovider.cc
+gdk/gdkmm/contentprovider.h
 gdk/gdkmm/cursor.cc
 gdk/gdkmm/cursor.h
 gdk/gdkmm/device.cc
diff --git a/gdk/src/clipboard.ccg b/gdk/src/clipboard.ccg
index 0586bd2..513c69a 100644
--- a/gdk/src/clipboard.ccg
+++ b/gdk/src/clipboard.ccg
@@ -13,4 +13,38 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
+ 
+#include <giomm/cancellable.h>
 
+namespace
+{
+
+// This function is identical to Gio::SignalProxy_async_callback() in
+// glibmm/gio/giomm/slot_async.cc. That function is not available
+// outside glibmm/gio, because slot_async.h is not installed.
+void SignalProxy_async_callback(GObject*, GAsyncResult* res, void* data)
+{
+  Gio::SlotAsyncReady* the_slot = static_cast<Gio::SlotAsyncReady*>(data);
+
+  try
+  {
+    auto result = Glib::wrap(res, true /* take copy */);
+    (*the_slot)(result);
+  }
+  catch (...)
+  {
+    Glib::exception_handlers_invoke();
+  }
+
+  delete the_slot;
+}
+
+} // anonymous namespace
+
+namespace Gdk
+{
+bool Clipboard::unset_content()
+{
+  return gdk_clipboard_set_content(gobj(), nullptr);
+}
+} // namespace Gdk
diff --git a/gdk/src/clipboard.hg b/gdk/src/clipboard.hg
index 0c7fc1b..3953372 100644
--- a/gdk/src/clipboard.hg
+++ b/gdk/src/clipboard.hg
@@ -16,16 +16,39 @@
 
 #include <glibmm/object.h>
 #include <gdkmm/contentformats.h>
+#include <gdkmm/contentprovider.h>
 #include <gdkmm/display.h>
 #include <gdkmm/texture.h>
 
 _DEFS(gdkmm,gdk)
 _PINCLUDE(glibmm/private/object_p.h)
 
+namespace Gio
+{
+class Cancellable;
+}
+
 namespace Gdk
 {
-/** The %Clipboard object represents a clipboard of data shared between different processes
- * or between different widgets in the same process.
+/** Share data between applications for Copy-and-Paste.
+ *
+ * The %Gdk::Clipboard object represents a clipboard of data shared
+ * between different applications or between different parts of
+ * the same application.
+ *
+ * To get a %Clipboard object, use Gdk::Display::get_clipboard() or
+ * Gdk::Display::get_primary_clipboard(). You can find out about the data that
+ * is currently available in a clipboard using get_formats().
+ *
+ * To make text or image data available in a clipboard, use set_text() or
+ * set_texture(). For other data, you can use set_content(),
+ * which takes a Gdk::ContentProvider object.
+ *
+ * To read textual or image data from a clipboard, use read_text_async() or
+ * read_texture_async(). For other data, use read_async(),
+ * which provides a Gio::InputStream object.
+ *
+ * @see Gdk::ContentProvider, Gdk::ContentFormats
  *
  * @newin{3,94}
  */
@@ -39,14 +62,35 @@ public:
   _WRAP_METHOD(Glib::RefPtr<ContentFormats> get_formats(), gdk_clipboard_get_formats, refreturn)
   _WRAP_METHOD(Glib::RefPtr<const ContentFormats> get_formats() const, gdk_clipboard_get_formats, refreturn, 
constversion)
   _WRAP_METHOD(bool is_local() const, gdk_clipboard_is_local)
-  //TODO: Add many more methods
+  _WRAP_METHOD(Glib::RefPtr<ContentProvider> get_content(), gdk_clipboard_get_content, refreturn)
+  _WRAP_METHOD(Glib::RefPtr<const ContentProvider> get_content() const, gdk_clipboard_get_content, 
refreturn, constversion)
+
+  _WRAP_METHOD(void read_texture_async(const Gio::SlotAsyncReady& slot{callback}, const 
Glib::RefPtr<Gio::Cancellable>& cancellable{.?}),
+    gdk_clipboard_read_texture_async, slot_name slot, slot_callback SignalProxy_async_callback)
+  _WRAP_METHOD(Glib::RefPtr<Texture> read_texture_finish(const Glib::RefPtr<Gio::AsyncResult>& result),
+    gdk_clipboard_read_texture_finish, errthrow)
+
+  _WRAP_METHOD(void read_text_async(const Gio::SlotAsyncReady& slot{callback}, const 
Glib::RefPtr<Gio::Cancellable>& cancellable{.?}),
+    gdk_clipboard_read_text_async, slot_name slot, slot_callback SignalProxy_async_callback)
+  _WRAP_METHOD(Glib::ustring read_text_finish(const Glib::RefPtr<Gio::AsyncResult>& result),
+    gdk_clipboard_read_text_finish, errthrow)
+
+  _WRAP_METHOD(bool set_content(const Glib::RefPtr<const ContentProvider>& provider), 
gdk_clipboard_set_content)
+  /** Clears the clipboard.
+   *
+   * In the rare case of a failure, this function will return <tt>false</tt>.
+   * The clipboard will then continue reporting its old contents.
+   *
+   * @return <tt>true</tt> if unsetting the clipboard succeeded.
+   */
+  bool unset_content();
   _WRAP_METHOD(void set_text(const Glib::ustring& text), gdk_clipboard_set_text)
   _WRAP_METHOD(void set_texture(const Glib::RefPtr<const Texture>& texture), gdk_clipboard_set_texture)
 
   _WRAP_PROPERTY("display", Glib::RefPtr<Display>)
   _WRAP_PROPERTY("formats", Glib::RefPtr<ContentFormats>)
   _WRAP_PROPERTY("local", bool)
-  //TODO: _WRAP_PROPERTY("content", Glib::RefPtr<ContentProvider>)
+  _WRAP_PROPERTY("content", Glib::RefPtr<ContentProvider>)
 
   // There are no public signals or vfuncs.
 };
diff --git a/gdk/src/contentprovider.ccg b/gdk/src/contentprovider.ccg
new file mode 100644
index 0000000..0586bd2
--- /dev/null
+++ b/gdk/src/contentprovider.ccg
@@ -0,0 +1,16 @@
+/* Copyright (C) 2017 The gtkmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
diff --git a/gdk/src/contentprovider.hg b/gdk/src/contentprovider.hg
new file mode 100644
index 0000000..ea7024b
--- /dev/null
+++ b/gdk/src/contentprovider.hg
@@ -0,0 +1,73 @@
+/* Copyright (C) 2017 The gtkmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+_DEFS(gdkmm,gdk)
+_PINCLUDE(glibmm/private/object_p.h)
+
+#include <glibmm/refptr.h>
+#include <gdkmm/contentformats.h>
+
+_CC_INCLUDE(gdk/gdk.h)
+
+namespace Gdk
+{
+
+/** Provides content for data transfer between applications.
+ *
+ * A %Gdk::ContentProvider is used to provide content for the clipboard in
+ * a number of formats.
+ *
+ * To create a %ContentProvider, use one of the overloaded create() methods.
+ *
+ * GDK knows how to handle common text and image formats out-of-the-box. See
+ * Gdk::ContentSerializer and Gdk::ContentDeserializer if you want to add support
+ * for application-specific data formats.
+ *
+ * @See Gdk::ContentSerializer, Gdk::ContentDeserializer
+ *
+ * @newin{3,94}
+ */
+class ContentProvider : public Glib::Object
+{
+  _CLASS_GOBJECT(ContentProvider, GdkContentProvider, GDK_CONTENT_PROVIDER, Glib::Object, GObject)
+
+public:
+  // _WRAP_METHOD is used for the create() methods because the gdk_content_provider_new_for_*()
+  // functions do more than call g_object_new().
+  _WRAP_METHOD(static Glib::RefPtr<ContentProvider> create(const Glib::ustring& mime_type,
+    const Glib::RefPtr<const Glib::Bytes>& bytes), gdk_content_provider_new_for_bytes)
+  _WRAP_METHOD(static Glib::RefPtr<ContentProvider> create(const Glib::ValueBase& value),
+    gdk_content_provider_new_for_value)
+
+  // ref_formats() and ref_storable_formats() are const because they return
+  // newly created ContentFormats instances.
+  _WRAP_METHOD(Glib::RefPtr<ContentFormats> ref_formats() const, gdk_content_provider_ref_formats)
+  _WRAP_METHOD(Glib::RefPtr<ContentFormats> ref_storable_formats() const, 
gdk_content_provider_ref_storable_formats)
+
+  _WRAP_METHOD(void content_changed(), gdk_content_provider_content_changed)
+
+  _WRAP_PROPERTY("formats", Glib::RefPtr<ContentFormats>)
+  _WRAP_PROPERTY("storable-formats", Glib::RefPtr<ContentFormats>)
+
+  _WRAP_SIGNAL(void content_changed(), "content-changed")
+
+  // GdkContentProvider contains vfuncs, but it's no use wrapping them as long as
+  // there is no constructor that calls g_object_new() to create a gtkmm__GdkContentProvider
+  // instance. A GdkContentProvider instance never calls an overriding vfunc in
+  // Gdk::ContentProvider.
+};
+
+} // namespace Gdk
diff --git a/gdk/src/filelist.am b/gdk/src/filelist.am
index 4b406ea..9713c79 100644
--- a/gdk/src/filelist.am
+++ b/gdk/src/filelist.am
@@ -17,6 +17,7 @@ gdkmm_files_any_hg =          \
        clipboard.hg            \
        contentformats.hg               \
        contentformatsbuilder.hg                \
+       contentprovider.hg              \
        cursor.hg               \
        device.hg               \
        display.hg              \
diff --git a/tools/m4/convert_gdk.m4 b/tools/m4/convert_gdk.m4
index d73f7b2..55e8dd3 100644
--- a/tools/m4/convert_gdk.m4
+++ b/tools/m4/convert_gdk.m4
@@ -240,6 +240,11 @@ _CONVERSION(`GdkContentFormats*',`Glib::RefPtr<const ContentFormats>',`Glib::wra
 _CONVERSION(`GdkContentFormats*',`Glib::RefPtr<Gdk::ContentFormats>',`Glib::wrap($3)')
 _CONVERSION(`GdkContentFormats*',`Glib::RefPtr<const Gdk::ContentFormats>',`Glib::wrap($3)')
 
+# ContentProvider
+_CONVERSION(`const Glib::RefPtr<ContentProvider>&',`GdkContentProvider*',__CONVERT_REFPTR_TO_P)
+_CONVERSION(`const Glib::RefPtr<const ContentProvider>&',`GdkContentProvider*',__CONVERT_CONST_REFPTR_TO_P)
+_CONVERSION(`GdkContentProvider*',`Glib::RefPtr<ContentProvider>',`Glib::wrap($3)')
+
 # XPM data
 _CONVERSION(`const char*const*',`const char**',`const_cast<const char**>($3)',`$3')
 


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