[glibmm] Gio::File: Add TypeTraits to fix Gtk::FileChooser::get_files() in gtkmm.



commit bc774a7129c20ab62d002b9909bf46611fbaa84e
Author: Jonathon Jongsma <jonathon jongsma collabora co uk>
Date:   Fri Mar 26 10:49:33 2010 +0100

     Gio::File: Add TypeTraits to fix Gtk::FileChooser::get_files() in gtkmm.
    
      * gio/src/file.hg: add TypeTraits to allow concrete implementations
        of GFile to be wrapped properly.  For example, this fix allows
        Gtk::FileChooser::get_files() to work properly (Fixes #590940)

 ChangeLog       |    8 ++++++++
 gio/src/file.hg |   40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 49f7dd1..bc51a9a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-03-26  Jonathon Jongsma  <jonathon jongsma collabora co uk>
+
+    Gio::File: Add TypeTraits to fix Gtk::FileChooser::get_files() in gtkmm.
+
+	* gio/src/file.hg: add TypeTraits to allow concrete implementations
+    of GFile to be wrapped properly.  For example, this fix allows
+    Gtk::FileChooser::get_files() to work properly (Fixes #590940)
+
 2010-03-26  Murray Cumming  <murrayc murrayc com>
 
     Add regression test for Bug #613250.
diff --git a/gio/src/file.hg b/gio/src/file.hg
index 50275f0..4681b83 100644
--- a/gio/src/file.hg
+++ b/gio/src/file.hg
@@ -2637,3 +2637,43 @@ public:
 
 } // namespace Gio
 
+namespace Glib
+{
+
+//Pre-declare this so we can use it in TypeTrait:
+Glib::RefPtr<Gio::File> wrap(GFile* object, bool take_copy);
+
+namespace Container_Helpers
+{
+
+/** This specialization of TypeTraits exists 
+ * because the default use of Glib::wrap(GObject*), 
+ * instead of a specific Glib::wrap(GSomeInterface*),
+ * would not return a wrapper for an interface.
+ */ 
+template <>
+struct TypeTraits< Glib::RefPtr<Gio::File> >
+{
+  typedef Glib::RefPtr<Gio::File> CppType;
+  typedef GFile* CType;
+  typedef GFile* CTypeNonConst;
+
+  static CType   to_c_type      (const CppType& item)
+  { return Glib::unwrap (item); }
+
+  static CppType to_cpp_type    (const CType& item)
+  {
+    //Use a specific Glib::wrap() function, 
+    //because CType has the specific type (not just GObject):
+    return Glib::wrap(item, true /* take_copy */);
+  }
+
+  static void    release_c_type (CType item)
+  {
+    GLIBMM_DEBUG_UNREFERENCE(0, item);
+    g_object_unref(item);
+  }
+};
+
+} // Container_Helpers
+} // Glib



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