[gtkmm] Gtk::Scrollable, ToolShell: Add some vfuncs



commit 54a0f5a3a9528e7469feabebed1cf7fed45a8a92
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Wed Dec 28 19:17:01 2016 +0100

    Gtk::Scrollable, ToolShell: Add some vfuncs
    
    * gtk/src/gtk_vfuncs.defs: Add some vfuncs.
    * gtk/src/scrollable.[ccg|hg]: Add get_border_vfunc().
    * gtk/src/toolshell.hg: Add 4 vfuncs. Make most vfuncs const.

 gtk/src/gtk_vfuncs.defs |   73 +++++++++++++++++++++++++++++++++-------------
 gtk/src/scrollable.ccg  |   49 +++++++++++++++++++++++++++++++
 gtk/src/scrollable.hg   |    3 +-
 gtk/src/toolshell.hg    |   12 +++++--
 4 files changed, 110 insertions(+), 27 deletions(-)
---
diff --git a/gtk/src/gtk_vfuncs.defs b/gtk/src/gtk_vfuncs.defs
index 9f6861d..3c6e396 100644
--- a/gtk/src/gtk_vfuncs.defs
+++ b/gtk/src/gtk_vfuncs.defs
@@ -408,6 +408,58 @@
   (return-type "none")
 )
 
+; GtkScrollable
+
+(define-vfunc get_border
+  (of-object "GtkScrollable")
+  (return-type "gboolean")
+  (parameters
+    '("GtkBorder*" "border")
+  )
+)
+
+; GtkToolShell
+
+(define-vfunc get_icon_size
+  (of-object "GtkToolShell")
+  (return-type "GtkIconSize")
+)
+
+(define-vfunc get_orientation
+  (of-object "GtkToolShell")
+  (return-type "GtkOrientation")
+)
+
+(define-vfunc get_style
+  (of-object "GtkToolShell")
+  (return-type "GtkToolbarStyle")
+)
+
+(define-vfunc rebuild_menu
+  (of-object "GtkToolShell")
+  (return-type "none")
+)
+
+(define-vfunc get_text_orientation
+  (of-object "GtkToolShell")
+  (return-type "GtkOrientation")
+)
+
+(define-vfunc get_text_alignment
+  (of-object "GtkToolShell")
+  (return-type "gfloat")
+)
+
+(define-vfunc get_ellipsize_mode
+  (of-object "GtkToolShell")
+  (return-type "PangoEllipsizeMode")
+)
+
+(define-vfunc get_text_size_group
+  (of-object "GtkToolShell")
+  (return-type "GtkSizeGroup*")
+)
+
 ; GtkTreeModel
 
 (define-vfunc get_flags
@@ -773,24 +825,3 @@
   )
 )
 
-; GtkToolShell
-
-(define-vfunc get_icon_size
-  (of-object "GtkToolShell")
-  (return-type "GtkIconSize")
-)
-
-(define-vfunc get_orientation
-  (of-object "GtkToolShell")
-  (return-type "GtkOrientation")
-)
-
-(define-vfunc get_style
-  (of-object "GtkToolShell")
-  (return-type "GtkToolbarStyle")
-)
-
-(define-vfunc rebuild_menu
-  (of-object "GtkToolShell")
-  (return-type "none")
-)
diff --git a/gtk/src/scrollable.ccg b/gtk/src/scrollable.ccg
index 832ab48..0486421 100644
--- a/gtk/src/scrollable.ccg
+++ b/gtk/src/scrollable.ccg
@@ -20,6 +20,55 @@
 namespace Gtk
 {
 
+// This vfunc callback is custom implemented because we want the output
+// argument of the C++ vfunc to be Gtk::Border& (not GtkBorder* or GtkBorder&),
+// and when a GtkBorder is wrapped in a Gtk::Border, the Gtk::Border takes
+// ownership of the GtkBorder or a copy of it. The wrapped copy must be assigned
+// to the original GtkBorder after the call to the C++ vfunc.
+gboolean Scrollable_Class::get_border_vfunc_callback(GtkScrollable* self, GtkBorder* border)
+{
+  const auto 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_())
+  {
+    const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
+    if(obj) // This can be NULL during destruction.
+    {
+      try // Trap C++ exceptions which would normally be lost because this is a C callback.
+      {
+        // Call the virtual member method, which derived classes might override.
+        Border border_copy(border, true);
+        auto result = obj->get_border_vfunc(border_copy);
+        if (border)
+          *border = *border_copy.gobj();
+        return result;
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+    }
+  }
+
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C 
interface).
+g_type_interface_peek(G_OBJECT_GET_CLASS(self), CppObjectType::get_type()) // Get the interface.
+)  );
+
+  // Call the original underlying C function:
+  if(base && base->get_border)
+    return (*base->get_border)(self, border);
+
+  using RType = gboolean;
+  return RType();
+}
+
 void Scrollable::unset_hadjustment()
 {
   gtk_scrollable_set_hadjustment(gobj(), nullptr);
diff --git a/gtk/src/scrollable.hg b/gtk/src/scrollable.hg
index cca1dc7..45c164b 100644
--- a/gtk/src/scrollable.hg
+++ b/gtk/src/scrollable.hg
@@ -75,8 +75,7 @@ public:
   _WRAP_PROPERTY("hscroll-policy", ScrollablePolicy)
   _WRAP_PROPERTY("vscroll-policy", ScrollablePolicy)
 
-  //TODO: Add when we can break ABI:
-  //_WRAP_VFUNC(bool get_border(Border& border) const, get_border)
+  _WRAP_VFUNC(bool get_border(Border& border) const, get_border, custom_vfunc_callback)
 };
 
 } // namespace Gtk
diff --git a/gtk/src/toolshell.hg b/gtk/src/toolshell.hg
index e36086c..50c209e 100644
--- a/gtk/src/toolshell.hg
+++ b/gtk/src/toolshell.hg
@@ -55,11 +55,15 @@ public:
 
 protected:
 
-  _WRAP_VFUNC(IconSize get_icon_size(), get_icon_size)
-  _WRAP_VFUNC(Orientation get_orientation(), get_orientation)
-  _WRAP_VFUNC(ToolbarStyle get_style(), get_style)
+  _WRAP_VFUNC(IconSize get_icon_size() const, get_icon_size)
+  _WRAP_VFUNC(Orientation get_orientation() const, get_orientation)
+  _WRAP_VFUNC(ToolbarStyle get_style() const, get_style)
   _WRAP_VFUNC(void rebuild_menu(), rebuild_menu)
-  //TODO: Add the other vfuncs when we can break ABI.
+  _WRAP_VFUNC(Orientation get_text_orientation() const, get_text_orientation)
+  _WRAP_VFUNC(float get_text_alignment() const, get_text_alignment)
+  _WRAP_VFUNC(Pango::EllipsizeMode get_ellipsize_mode() const, get_ellipsize_mode)
+#m4 _CONVERSION(`Glib::RefPtr<SizeGroup>', `GtkSizeGroup*', __CONVERT_REFPTR_TO_P)
+  _WRAP_VFUNC(Glib::RefPtr<SizeGroup> get_text_size_group(), get_text_size_group, refreturn)
 };
 
 } // namespace Gtk


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