[gtkmm] Add a specialization for Glib::Value<::Cairo::RefPtr<T>>



commit 18017d633069ac04795d4736e71ed08713977290
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Fri Oct 13 15:54:46 2017 +0200

    Add a specialization for Glib::Value<::Cairo::RefPtr<T>>
    
    * gdk/gdkmm/value_cairo.[h|cc]: New files. Add a specialization for
    Glib::Value<::Cairo::RefPtr<T>>. This specialization can't be put in glibmm,
    because glibmm does not depend on cairomm. It can't be put in cairomm,
    because cairomm does not depend on glibmm. So it's added here. It's needed
    for wrapping properties with a Cairo::RefPtr<T> value.
    * gdk/gdkmm/filelist.am: Add value_cairo.[h|cc].
    * gtk/src/cellrendererpixbuf.hg: Include value_cairo.h. It's needed for
    property_surface(). Bug 788513

 gdk/gdkmm/filelist.am         |    4 +-
 gdk/gdkmm/value_cairo.cc      |   33 ++++++++++++++++
 gdk/gdkmm/value_cairo.h       |   82 +++++++++++++++++++++++++++++++++++++++++
 gtk/src/cellrendererpixbuf.hg |    1 +
 4 files changed, 118 insertions(+), 2 deletions(-)
---
diff --git a/gdk/gdkmm/filelist.am b/gdk/gdkmm/filelist.am
index 504439b..b51bdd6 100644
--- a/gdk/gdkmm/filelist.am
+++ b/gdk/gdkmm/filelist.am
@@ -4,6 +4,6 @@ gdkmm_files_built_cc = $(gdkmm_files_used_hg:.hg=.cc) wrap_init.cc
 gdkmm_files_built_h  = $(gdkmm_files_used_hg:.hg=.h)
 gdkmm_files_built_ph = $(patsubst %.hg,private/%_p.h,$(gdkmm_files_used_hg))
 
-gdkmm_files_extra_cc = general.cc
-gdkmm_files_extra_h  = general.h wrap_init.h
+gdkmm_files_extra_cc = general.cc value_cairo.cc
+gdkmm_files_extra_h  = general.h value_cairo.h wrap_init.h
 gdkmm_files_extra_ph =
diff --git a/gdk/gdkmm/value_cairo.cc b/gdk/gdkmm/value_cairo.cc
new file mode 100644
index 0000000..6ed557a
--- /dev/null
+++ b/gdk/gdkmm/value_cairo.cc
@@ -0,0 +1,33 @@
+/* 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/>.
+ */
+
+#include <gdkmm/value_cairo.h>
+#include <cairo-gobject.h>
+
+namespace Gdk
+{
+namespace Cairo
+{
+
+template <>
+GType get_base_type<::Cairo::Region>() { return CAIRO_GOBJECT_TYPE_REGION; }
+
+template <>
+GType get_base_type<::Cairo::Surface>() { return CAIRO_GOBJECT_TYPE_SURFACE; }
+
+} //namespace Cairo
+
+} //namespace Gdk
diff --git a/gdk/gdkmm/value_cairo.h b/gdk/gdkmm/value_cairo.h
new file mode 100644
index 0000000..c71d39a
--- /dev/null
+++ b/gdk/gdkmm/value_cairo.h
@@ -0,0 +1,82 @@
+/* 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/>.
+ */
+
+#ifndef _GDKMM_VALUE_CAIRO_H
+#define _GDKMM_VALUE_CAIRO_H
+
+#include <glibmm/value.h>
+#include <cairomm/refptr.h>
+#include <type_traits>
+
+namespace Cairo
+{
+class Region;
+class Surface;
+}
+
+namespace Gdk
+{
+namespace Cairo
+{
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+template <typename T>
+GType get_base_type()
+{
+  static_assert(!std::is_same<T,T>::value, "No specialization available for type T.");
+  return 0;
+}
+
+template <>
+GType get_base_type<::Cairo::Region>();
+
+template <>
+GType get_base_type<::Cairo::Surface>();
+#endif // DOXYGEN_SHOULD_SKIP_THIS
+
+} //namespace Cairo
+
+} //namespace Gdk
+
+namespace Glib
+{
+/** Partial specialization of Glib::Value<> for Cairo::RefPtr<> to a Cairomm object.
+ */
+template <typename T, typename Enable>
+class Value<::Cairo::RefPtr<T>, Enable> : public ValueBase_Boxed
+{
+public:
+  using CppType = ::Cairo::RefPtr<T>;
+  using CType = typename T::cobject;
+
+  static GType value_type()
+  {
+    return Gdk::Cairo::get_base_type<std::remove_const_t<T>>();
+  }
+
+  void set(const CppType& data) { set_boxed(data->cobj()); }
+
+  CppType get() const
+  {
+    CType* CObj = static_cast<CType*>(get_boxed());
+    T* CppObj = new T(CObj, false); // false == take reference
+    return ::Cairo::make_refptr_for_instance<T>(CppObj);
+  }
+};
+
+} //namespace Glib
+
+#endif //_GDKMM_VALUE_CAIRO_H
diff --git a/gtk/src/cellrendererpixbuf.hg b/gtk/src/cellrendererpixbuf.hg
index a65c5b2..a834bb2 100644
--- a/gtk/src/cellrendererpixbuf.hg
+++ b/gtk/src/cellrendererpixbuf.hg
@@ -17,6 +17,7 @@
  */
 
 #include <gtkmm/cellrenderer.h>
+#include <gdkmm/value_cairo.h>
 #include <giomm/icon.h>
 _DEFS(gtkmm,gtk)
 _PINCLUDE(gtkmm/private/cellrenderer_p.h)


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