[gtkmm] Wrap GtkBorder as boxed type.



commit d63e25b7c28e7f2ed6cc4c541b85f4987768d470
Author: Krzesimir Nowak <qdlacz gmail com>
Date:   Tue Dec 22 17:53:36 2009 +0100

    Wrap GtkBorder as boxed type.
    
    * gtk/src/border.[hg|ccg]: Wrapped GtkBorder.
    * gtk/src/filelist.am: Added border.hg and border.ccg.
    * gtk/src/entry.hg: Removed a TODO and typedef and included
    border.h.
    * gtk/src/range.[hg|ccg]: Made get_range_border vfunc use
    Gtk::Border& instead of GtkBorder* - this needed wrapping it
    partially by hand by writing custom C callback.
    * tools/m4/convert_gtk.m4: Added conversion macros for Gtk::Border.
    * gtk/gtkmm.h: Added border.h include.
    * MSVC_Net{2005,2008}/gtkmm/gtkmm.vcproj: Added border.h
    and border.cc to build.

 .gitignore                      |    2 +
 ChangeLog                       |   12 ++++++++++
 MSVC_Net2005/gtkmm/gtkmm.vcproj |    4 +++
 MSVC_Net2008/gtkmm/gtkmm.vcproj |    4 +++
 gtk/src/border.ccg              |   20 ++++++++++++++++
 gtk/src/border.hg               |   45 +++++++++++++++++++++++++++++++++++++
 gtk/src/filelist.am             |    1 +
 gtk/src/range.ccg               |   47 +++++++++++++++++++++++++++++++++++---
 gtk/src/range.hg                |   20 ++++++++++++++--
 tools/m4/convert_gtk.m4         |    6 +++-
 10 files changed, 152 insertions(+), 9 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index d5bf66d..b911446 100644
--- a/.gitignore
+++ b/.gitignore
@@ -171,6 +171,8 @@ gtk/gtkmm/bin.cc
 gtk/gtkmm/bin.h
 gtk/gtkmm/box.cc
 gtk/gtkmm/box.h
+gtk/gtkmm/border.cc
+gtk/gtkmm/border.h
 gtk/gtkmm/builder.cc
 gtk/gtkmm/builder.h
 gtk/gtkmm/button.cc
diff --git a/ChangeLog b/ChangeLog
index 8ca8ac5..a9da231 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2009-12-11  Krzesimir Nowak  <qdlacz gmail com>
+
+	* gtk/src/border.[hg|ccg]: Wrapped GtkBorder.
+	* gtk/src/entry.hg: Removed a TODO and typedef and included border.h.
+	* gtk/src/range.[hg|ccg]: Made get_range_border vfunc use Gtk::Border&
+	instead of GtkBorder* - this needed wrapping it partially by hand by
+	writing custom C callback.
+	* tools/m4/convert_gtk.m4: Added conversion macros for Gtk::Border.
+	* gtk/gtkmm.h: Added border.h include.
+	* MSVC_Net{2005,2008}/gtkmm/gtkmm.vcproj: Added border.h and border.cc
+	to build.
+
 2009-05-05  Murray Cumming  <murrayc murrayc com>
 
 	* gdk/gdkmm/general.[h|cc]:
diff --git a/MSVC_Net2005/gtkmm/gtkmm.vcproj b/MSVC_Net2005/gtkmm/gtkmm.vcproj
index 947f091..a06c8aa 100755
--- a/MSVC_Net2005/gtkmm/gtkmm.vcproj
+++ b/MSVC_Net2005/gtkmm/gtkmm.vcproj
@@ -240,6 +240,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\gtk\gtkmm\border.cc"
+				>
+			</File>
+			<File
 				RelativePath="..\..\gtk\gtkmm\box.cc"
 				>
 			</File>
diff --git a/MSVC_Net2008/gtkmm/gtkmm.vcproj b/MSVC_Net2008/gtkmm/gtkmm.vcproj
index 1a55c2e..7339db0 100644
--- a/MSVC_Net2008/gtkmm/gtkmm.vcproj
+++ b/MSVC_Net2008/gtkmm/gtkmm.vcproj
@@ -239,6 +239,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\gtk\gtkmm\border.cc"
+				>
+			</File>
+			<File
 				RelativePath="..\..\gtk\gtkmm\box.cc"
 				>
 			</File>
diff --git a/gtk/src/border.ccg b/gtk/src/border.ccg
new file mode 100644
index 0000000..14c3865
--- /dev/null
+++ b/gtk/src/border.ccg
@@ -0,0 +1,20 @@
+/* border.cc
+ *
+ * Copyright 2009 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, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gtk/gtk.h>
diff --git a/gtk/src/border.hg b/gtk/src/border.hg
new file mode 100644
index 0000000..844a2ab
--- /dev/null
+++ b/gtk/src/border.hg
@@ -0,0 +1,45 @@
+/* border.h
+ *
+ * Copyright 2009 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, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+_DEFS(gtkmm,gtk)
+
+namespace Gtk
+{
+
+class Border
+{
+  _CLASS_BOXEDTYPE(Border, GtkBorder, gtk_border_new, gtk_border_copy, gtk_border_free)
+public:
+
+  _MEMBER_GET(left, left, int, gint)
+  _MEMBER_SET(left, left, int, gint)
+
+  _MEMBER_GET(right, right, int, gint)
+  _MEMBER_SET(right, right, int, gint)
+
+  _MEMBER_GET(top, top, int, gint)
+  _MEMBER_SET(top, top, int, gint)
+
+  _MEMBER_GET(bottom, bottom, int, gint)
+  _MEMBER_SET(bottom, bottom, int, gint)
+};
+
+} /* namespace Gtk */
+
+
diff --git a/gtk/src/filelist.am b/gtk/src/filelist.am
index 0710cee..7ec3962 100644
--- a/gtk/src/filelist.am
+++ b/gtk/src/filelist.am
@@ -25,6 +25,7 @@ gtkmm_files_any_hg =		\
 	aspectframe.hg		\
 	assistant.hg		\
 	bin.hg			\
+	border.hg		\
 	box.hg			\
 	buildable.hg		\
 	builder.hg		\
diff --git a/gtk/src/range.ccg b/gtk/src/range.ccg
index 6c9598c..3801fbe 100644
--- a/gtk/src/range.ccg
+++ b/gtk/src/range.ccg
@@ -29,12 +29,51 @@ void Range::unset_adjustment()
   gtk_range_set_adjustment(gobj(), 0);
 }
 
-Gdk::Rectangle Range::get_range_rect() const
+#ifdef GLIBMM_VFUNCS_ENABLED
+void Range_Class::get_range_border_vfunc_callback(GtkRange* self, GtkBorder* border)
 {
-  Gdk::Rectangle result;
-  gtk_range_get_range_rect(const_cast<GtkRange*>(gobj()), result.gobj());
-  return result;
+  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
+      Glib::ObjectBase::_get_current_wrapper((GObject*)self));
+
+  // Non-gtkmmproc-generated custom classes implicitly call the default
+  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
+  // generated classes can use this optimisation, which avoids the unnecessary
+  // parameter conversions if there is no possibility of the virtual function
+  // being overridden:
+  if(obj_base && obj_base->is_derived_())
+  {
+    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
+    if(obj) // This can be NULL during destruction.
+    {
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try // Trap C++ exceptions which would normally be lost because this is a C callback.
+      {
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+        // Call the virtual member method, which derived classes might override.
+        Gtk::Border cxx_border(border, true);
+        obj->get_range_border_vfunc(cxx_border);
+        *border = *(cxx_border.gobj());
+        return;
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  }
+
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
+  );
+
+  // Call the original underlying C function:
+  if(base && base->get_range_border)
+    (*base->get_range_border)(self, border);
+
 }
+#endif //GLIBMM_VFUNCS_ENABLED
 
 } // namespace Gtk
 
diff --git a/gtk/src/range.hg b/gtk/src/range.hg
index cd8b6ac..6a03903 100644
--- a/gtk/src/range.hg
+++ b/gtk/src/range.hg
@@ -127,9 +127,23 @@ public:
   _WRAP_PROPERTY("fill-level", double)
   
 protected:
-#m4 _CONVERSION(`Gtk::Border*',`GtkBorder*',($3))
-#m4 _CONVERSION(`GtkBorder*',`Gtk::Border*',($3))
-  _WRAP_VFUNC(void get_range_border(Gtk::Border* border) const, get_range_border)
+  virtual void get_range_border_vfunc(Gtk::Border& border) const;
+#m4begin
+dnl /* get_range_border_vfunc is wrapped partially by hand (C callback is
+dnl  * custom), because this vfunc is a getter with a "return value" as
+dnl  * parameter. This complicates things a bit - we cannot use Glib::wrap in
+dnl  * obj->get_range_border_vfunc(Glib::wrap(c_border));
+dnl  * because compiler complains about passing `Gtk::Border', when expecting
+dnl  * `Gtk::Border&'. Using `Gtk::Border(c_border)' also does not work, because
+dnl  * it is making a copy of passed C border and, when went out of scope,
+dnl  * destroys it without copying contents to a C border. See:
+dnl  * https://bugzilla.gnome.org/show_bug.cgi?id=603926#c3
+dnl  */
+dnl // _VFUNC_H is not used - prototype is written above.
+  _VFUNC_PH(get_range_border, void, `GtkRange* self, GtkBorder* border')
+  _VFUNC_CC(get_range_border_vfunc, get_range_border, void, void, `Gtk::Border& border', `border.gobj()', 1)
+dnl // _VFUNC_PCC is not used - custom C callback is implemented in range.ccg.
+#m4end
 };
 
 } // namespace Gtk
diff --git a/tools/m4/convert_gtk.m4 b/tools/m4/convert_gtk.m4
index bc1da3b..fbd7223 100644
--- a/tools/m4/convert_gtk.m4
+++ b/tools/m4/convert_gtk.m4
@@ -521,8 +521,10 @@ _CONVERSION(`GtkEntry*',`const Entry*',__RP2P)
 _CONVERSION(`Entry&',`GtkEntry*',__FR2P)
 
 
-_CONVERSION(`const Border&',`const GtkBorder*',`&($3)')
-_CONVERSION(`const GtkBorder*',`Border',`*($3)')
+_CONVERSION(`Gtk::Border&',`GtkBorder*',__FR2P)
+_CONVERSION(`GtkBorder*',`Gtk::Border&',`Glib::wrap($3)')
+_CONVERSION(`const Border&',`const GtkBorder*',__FR2P)
+_CONVERSION(`const GtkBorder*',`Border',`Glib::wrap(const_cast<GtkBorder*>($3))')
 
 #RecentFilter
 _CONVERSION(`GtkRecentFilterFlags',`RecentFilterFlags',`($2)$3')



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