[gtkmm] Gtk::Widget: Add measure() and measure_vfunc()



commit e05f6e152337afb9a298b6057def46e4f2a98c9c
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Wed Nov 9 15:20:35 2016 +0100

    Gtk::Widget: Add measure() and measure_vfunc()
    
    * gtk/src/widget.[ccg|hg]: measure_vfunc() replaces the removed
    get_preferred_*_vfunc().
    * gtk/src/filechooserwidget.hg: Remove the TODO comment about implementing
    the FileChooserEmbed interface. GtkFileChooserWidget implements
    GtkFileChooserEmbed, but it's a private interface, available only in gtk+
    itself.

 gtk/src/filechooserwidget.hg |    2 -
 gtk/src/gtk_vfuncs.defs      |   12 ++++++++++
 gtk/src/widget.ccg           |   49 ++++++++++++++++++++++++++++++++++++++++++
 gtk/src/widget.hg            |    6 +++++
 4 files changed, 67 insertions(+), 2 deletions(-)
---
diff --git a/gtk/src/filechooserwidget.hg b/gtk/src/filechooserwidget.hg
index 17c956b..fa90a79 100644
--- a/gtk/src/filechooserwidget.hg
+++ b/gtk/src/filechooserwidget.hg
@@ -26,8 +26,6 @@ _PINCLUDE(gtkmm/private/box_p.h)
 namespace Gtk
 {
 
-//TODO: Derive from the FileChooserEmbed interface when it has been wrapped in gtkmm.
-
 /** File chooser widget that can be embedded in other widgets.
  *
  * FileChooserWidget is a widget suitable for selecting files. It is the main
diff --git a/gtk/src/gtk_vfuncs.defs b/gtk/src/gtk_vfuncs.defs
index 3fac474..9f6861d 100644
--- a/gtk/src/gtk_vfuncs.defs
+++ b/gtk/src/gtk_vfuncs.defs
@@ -653,6 +653,18 @@
   (return-type "GtkSizeRequestMode")
 )
 
+(define-vfunc measure
+  (of-object "GtkWidget")
+  (return-type "void")
+  (parameters
+    '("GtkOrientation" "orientation")
+    '("int" "for_size")
+    '("int*" "minimum")
+    '("int*" "natural")
+    '("int*" "minimum_baseline")
+    '("int*" "natural_baseline")
+  )
+)
 
 ; GtkRecentChooser
 
diff --git a/gtk/src/widget.ccg b/gtk/src/widget.ccg
index 854e165..b96e44a 100644
--- a/gtk/src/widget.ccg
+++ b/gtk/src/widget.ccg
@@ -225,6 +225,55 @@ void Widget_Class::drag_data_get_callback(GtkWidget* self, GdkDragContext* p0, G
   }
 }
 
+// This vfunc callback is custom implemented because we want the output
+// arguments of the C++ vfunc to be int& (not int*), and the vfunc_callback
+// function may be called from gtk+ with NULL pointers.
+void Widget_Class::measure_vfunc_callback(GtkWidget* self, GtkOrientation orientation, int for_size,
+  int* minimum, int* natural, int* minimum_baseline, int* natural_baseline)
+{
+  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.
+        int no_minimum = 0;
+        int no_natural = 0;
+        int no_minimum_baseline = 0;
+        int no_natural_baseline = 0;
+        obj->measure_vfunc((Orientation)orientation, for_size,
+          (minimum ? *minimum : no_minimum),
+          (natural ? *natural : no_natural),
+          (minimum_baseline ? *minimum_baseline : no_minimum_baseline),
+          (natural_baseline ? *natural_baseline : no_natural_baseline));
+        return;
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+    }
+  }
+
+  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->measure)
+    (*base->measure)(self, orientation, for_size, minimum, natural, minimum_baseline, natural_baseline);
+}
+
 Widget::~Widget() noexcept
 {}
 
diff --git a/gtk/src/widget.hg b/gtk/src/widget.hg
index 3e973f8..3aa1f3c 100644
--- a/gtk/src/widget.hg
+++ b/gtk/src/widget.hg
@@ -136,6 +136,8 @@ public:
   _WRAP_METHOD(void get_preferred_height_for_width(int width, int& minimum_height, int& natural_height, int& 
minimum_baseline, int& natural_baseline) const, gtk_widget_get_preferred_height_and_baseline_for_width)
   _WRAP_METHOD(void get_preferred_height(int& minimum_height, int& natural_height) const, 
gtk_widget_get_preferred_height)
   _WRAP_METHOD(void get_preferred_width_for_height(int height, int& minimum_width, int& natural_width) 
const, gtk_widget_get_preferred_width_for_height)
+  _WRAP_METHOD(void measure(Orientation orientation, int for_size, int& minimum, int& natural,
+    int& minimum_baseline, int& natural_baseline) const, gtk_widget_measure)
   _WRAP_METHOD(void get_preferred_size(Requisition& minimum_size, Requisition& natural_size) const, 
gtk_widget_get_preferred_size)
 
 
@@ -653,6 +655,8 @@ _CONVERSION(`GdkScreen*',`const Glib::RefPtr<Gdk::Screen>&',`Glib::wrap($3, true
 
   _WRAP_SIGNAL(bool popup_menu(), "popup_menu") //Note that popup-menu is a keybinding signal, but is really 
meant to be wrapped.
 
+  _IGNORE_SIGNAL("move-focus")dnl // Action signal
+
   //Keybinding signals:
   _IGNORE_SIGNAL("keynav_failed")
 
@@ -710,6 +714,8 @@ protected:
   _WRAP_VFUNC(Glib::RefPtr<Atk::Object> get_accessible(), "get_accessible", refreturn, ifdef 
GTKMM_ATKMM_ENABLED)
 
   _WRAP_VFUNC(SizeRequestMode get_request_mode() const, get_request_mode)
+  _WRAP_VFUNC(void measure(Orientation orientation, int for_size, int& minimum, int& natural,
+    int& minimum_baseline, int& natural_baseline) const, measure, custom_vfunc_callback)
   //TODO: Wrap all the new vfuncs when we can break ABI.
 
 protected:


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