[gtkmm] Add Gtk::Constraint*



commit d7cb2bb41b8bfc8201b37344222d9990e649651f
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Fri Jul 12 15:29:15 2019 +0200

    Add Gtk::Constraint*
    
    Add Gtk::Constraint, Gtk::ConstraintGuide, Gtk::ConstraintLayout,
    Gtk::ConstraintTarget

 .gitignore                   |   8 +++
 gtk/gtkmm.h                  |   1 +
 gtk/src/constraint.ccg       |  20 ++++++++
 gtk/src/constraint.hg        | 115 +++++++++++++++++++++++++++++++++++++++++++
 gtk/src/constraintguide.ccg  |  17 +++++++
 gtk/src/constraintguide.hg   |  72 +++++++++++++++++++++++++++
 gtk/src/constraintlayout.ccg |  62 +++++++++++++++++++++++
 gtk/src/constraintlayout.hg  | 110 +++++++++++++++++++++++++++++++++++++++++
 gtk/src/constrainttarget.ccg |  17 +++++++
 gtk/src/constrainttarget.hg  |  47 ++++++++++++++++++
 gtk/src/filelist.am          |   4 ++
 gtk/src/widget.ccg           |  13 +++++
 gtk/src/widget.hg            |  16 +++++-
 tools/m4/convert_gtk.m4      |   9 ++++
 14 files changed, 510 insertions(+), 1 deletion(-)
---
diff --git a/.gitignore b/.gitignore
index 205d3094..4d0551a8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -222,6 +222,14 @@ gtk/gtkmm/combobox.cc
 gtk/gtkmm/combobox.h
 gtk/gtkmm/comboboxtext.cc
 gtk/gtkmm/comboboxtext.h
+gtk/gtkmm/constraint.cc
+gtk/gtkmm/constraint.h
+gtk/gtkmm/constraintguide.cc
+gtk/gtkmm/constraintguide.h
+gtk/gtkmm/constraintlayout.cc
+gtk/gtkmm/constraintlayout.h
+gtk/gtkmm/constrainttarget.cc
+gtk/gtkmm/constrainttarget.h
 gtk/gtkmm/container.cc
 gtk/gtkmm/container.h
 gtk/gtkmm/csslocation.cc
diff --git a/gtk/gtkmm.h b/gtk/gtkmm.h
index 3df17fa6..ae4d700f 100644
--- a/gtk/gtkmm.h
+++ b/gtk/gtkmm.h
@@ -132,6 +132,7 @@ extern const int gtkmm_micro_version;
 #include <gtkmm/colorchooserdialog.h>
 #include <gtkmm/combobox.h>
 #include <gtkmm/comboboxtext.h>
+#include <gtkmm/constraintlayout.h>
 #include <gtkmm/container.h>
 #include <gtkmm/cssprovider.h>
 #include <gtkmm/csssection.h>
diff --git a/gtk/src/constraint.ccg b/gtk/src/constraint.ccg
new file mode 100644
index 00000000..c64524b4
--- /dev/null
+++ b/gtk/src/constraint.ccg
@@ -0,0 +1,20 @@
+/* Copyright (C) 2019 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 <gtk/gtk.h>
+
+using Attribute = Gtk::Constraint::Attribute;
+using Relation = Gtk::Constraint::Relation;
diff --git a/gtk/src/constraint.hg b/gtk/src/constraint.hg
new file mode 100644
index 00000000..a61c7c42
--- /dev/null
+++ b/gtk/src/constraint.hg
@@ -0,0 +1,115 @@
+/* Copyright (C) 2019 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 <glibmm/object.h>
+#include <gtkmm/constrainttarget.h>
+#include <gtk/gtk.h>
+
+_DEFS(gtkmm,gtk)
+_PINCLUDE(glibmm/private/object_p.h)
+
+namespace Gtk
+{
+
+/** The description of a constraint.
+ *
+ * %Gtk::Constraint describes a constraint between an attribute on a widget
+ * and another attribute on another widget, expressed as a linear equation like:
+ *
+ *   target.attr1 = source.attr2 × multiplier + constant
+ *
+ * Each %Constraint is part of a system that will be solved by a
+ * Gtk::ConstraintLayout in order to allocate and position each child widget.
+ *
+ * A %Constraint is immutable once it's created.
+ *
+ * @newin{3,96}
+ */
+class Constraint : public Glib::Object
+{
+  _CLASS_GOBJECT(Constraint, GtkConstraint, GTK_CONSTRAINT, Glib::Object, GObject)
+  _STRUCT_NOT_HIDDEN
+
+public:
+  _WRAP_ENUM(Attribute, GtkConstraintAttribute)
+  _WRAP_ENUM(Relation, GtkConstraintRelation)
+  _WRAP_ENUM(Strength, GtkConstraintStrength, CONV_TO_INT)
+
+protected:
+  _WRAP_CTOR(Constraint(const Glib::RefPtr<ConstraintTarget>& target,
+             Attribute target_attribute, Relation relation,
+             const Glib::RefPtr<ConstraintTarget>& source, Attribute  source_attribute,
+             double multiplier, double constant, int strength), gtk_constraint_new)
+  _WRAP_CTOR(Constraint(const Glib::RefPtr<ConstraintTarget>& target,
+             Attribute target_attribute, Relation relation,
+             double constant, int strength), gtk_constraint_new_constant)
+
+public:
+  /** Creates a new %Gtk::Constraint representing a relation between a layout
+   * attribute on a source and a layout attribute on a target.
+   *
+   * @param target A Gtk::ConstraintTarget or an empty Glib::RefPtr.
+   * @param target_attribute The attribute of @a target to be set.
+   * @param relation The relation equivalence between @a target_attribute and @a source_attribute.
+   * @param source A Gtk::ConstraintTarget or an empty Glib::RefPtr.
+   * @param source_attribute The attribute of @a source to be read.
+   * @param multiplier A multiplication factor to be applied to @a source_attribute.
+   * @param constant A constant to be added to @a source_attribute.
+   * @param strength The strength of the constraint.
+   * @return The newly created %Gtk::Constraint.
+   */
+  _WRAP_CREATE(const Glib::RefPtr<ConstraintTarget>& target, Attribute target_attribute,
+               Relation relation, const Glib::RefPtr<ConstraintTarget>& source,
+               Attribute source_attribute, double multiplier, double constant, int strength)
+
+  /** Creates a new %Gtk::Constraint representing a relation between a layout
+   * attribute on a target and a constant value.
+   *
+   * @param target A Gtk::ConstraintTarget or an empty Glib::RefPtr.
+   * @param target_attribute The attribute of @a target to be set.
+   * @param relation The relation equivalence between @a target_attribute and @a constant.
+   * @param constant A constant to be set on @a target_attribute.
+   * @param strength The strength of the constraint.
+   * @return The newly created %Gtk::Constraint.
+   */
+  _WRAP_CREATE(const Glib::RefPtr<ConstraintTarget>& target, Attribute target_attribute,
+               Relation relation, double constant, int strength)
+
+  _WRAP_METHOD(Glib::RefPtr<ConstraintTarget> get_target(), gtk_constraint_get_target, refreturn)
+  _WRAP_METHOD(Glib::RefPtr<const ConstraintTarget> get_target() const, gtk_constraint_get_target, 
refreturn, constversion)
+  _WRAP_METHOD(Attribute get_target_attribute() const, gtk_constraint_get_target_attribute)
+  _WRAP_METHOD(Glib::RefPtr<ConstraintTarget> get_source(), gtk_constraint_get_source, refreturn)
+  _WRAP_METHOD(Glib::RefPtr<const ConstraintTarget> get_source() const, gtk_constraint_get_source, 
refreturn, constversion)
+  _WRAP_METHOD(Attribute get_source_attribute() const, gtk_constraint_get_source_attribute)
+  _WRAP_METHOD(Relation get_relation() const, gtk_constraint_get_relation)
+  _WRAP_METHOD(double get_multiplier() const, gtk_constraint_get_multiplier)
+  _WRAP_METHOD(double get_constant() const, gtk_constraint_get_constant)
+  _WRAP_METHOD(int get_strength() const, gtk_constraint_get_strength)
+  _WRAP_METHOD(bool is_required() const, gtk_constraint_is_required)
+  _WRAP_METHOD(bool is_attached() const, gtk_constraint_is_attached)
+  _WRAP_METHOD(bool is_constant() const, gtk_constraint_is_constant)
+
+  _WRAP_PROPERTY("target", Glib::RefPtr<ConstraintTarget>)
+  _WRAP_PROPERTY("target-attribute", Attribute)
+  _WRAP_PROPERTY("relation", Relation)
+  _WRAP_PROPERTY("source", Glib::RefPtr<ConstraintTarget>)
+  _WRAP_PROPERTY("source-attribute", Attribute)
+  _WRAP_PROPERTY("multiplier", double)
+  _WRAP_PROPERTY("constant", double)
+  _WRAP_PROPERTY("strength", int)
+};
+
+} // namespace Gtk
diff --git a/gtk/src/constraintguide.ccg b/gtk/src/constraintguide.ccg
new file mode 100644
index 00000000..3663c616
--- /dev/null
+++ b/gtk/src/constraintguide.ccg
@@ -0,0 +1,17 @@
+/* Copyright (C) 2019 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 <gtk/gtk.h>
diff --git a/gtk/src/constraintguide.hg b/gtk/src/constraintguide.hg
new file mode 100644
index 00000000..f84dd04f
--- /dev/null
+++ b/gtk/src/constraintguide.hg
@@ -0,0 +1,72 @@
+/* Copyright (C) 2019 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 <glibmm/object.h>
+#include <gtkmm/constrainttarget.h>
+#include <gtkmm/constraint.h>
+#include <gtk/gtk.h>
+
+_DEFS(gtkmm,gtk)
+_PINCLUDE(glibmm/private/object_p.h)
+
+namespace Gtk
+{
+
+ /** An invisible constraint target.
+ *
+ * A %ConstraintGuide is an invisible layout element that can be
+ * used by widgets inside a Gtk::ConstraintLayout as a source or a target
+ * of a Gtk::Constraint. Guides can be used like guidelines or as
+ * flexible space.
+ *
+ * Unlike a Gtk::Widget, a %Gtk::ConstraintGuide will not be drawn.
+ *
+ * @newin{3,96}
+ */
+class ConstraintGuide : public Glib::Object, public ConstraintTarget
+{
+  _CLASS_GOBJECT(ConstraintGuide, GtkConstraintGuide, GTK_CONSTRAINT_GUIDE, Glib::Object, GObject)
+  _IMPLEMENTS_INTERFACE(ConstraintTarget)
+  _STRUCT_NOT_HIDDEN
+
+protected:
+  _CTOR_DEFAULT()
+
+public:
+  _WRAP_CREATE()
+
+  _WRAP_METHOD(void set_min_size(int width, int height), gtk_constraint_guide_set_min_size)
+  _WRAP_METHOD(void get_min_size(int& width, int& height) const, gtk_constraint_guide_get_min_size)
+  _WRAP_METHOD(void set_nat_size(int width, int height), gtk_constraint_guide_set_nat_size)
+  _WRAP_METHOD(void get_nat_size(int& width, int& height) const, gtk_constraint_guide_get_nat_size)
+  _WRAP_METHOD(void set_max_size(int width, int height), gtk_constraint_guide_set_max_size)
+  _WRAP_METHOD(void get_max_size(int& width, int& height) const, gtk_constraint_guide_get_max_size)
+  _WRAP_METHOD(void set_strength(Constraint::Strength strength), gtk_constraint_guide_set_strength)
+  _WRAP_METHOD(Constraint::Strength get_strength() const, gtk_constraint_guide_get_strength)
+  _WRAP_METHOD(void set_name(const Glib::ustring& name), gtk_constraint_guide_set_name)
+  _WRAP_METHOD(Glib::ustring get_name() const, gtk_constraint_guide_get_name)
+
+  _WRAP_PROPERTY("min-width", int)
+  _WRAP_PROPERTY("min-height", int)
+  _WRAP_PROPERTY("nat-width", int)
+  _WRAP_PROPERTY("nat-height", int)
+  _WRAP_PROPERTY("max-width", int)
+  _WRAP_PROPERTY("max-height", int)
+  _WRAP_PROPERTY("strength", Constraint::Strength)
+  _WRAP_PROPERTY("name", Glib::ustring)
+};
+
+} // namespace Gtk
diff --git a/gtk/src/constraintlayout.ccg b/gtk/src/constraintlayout.ccg
new file mode 100644
index 00000000..7ba6e017
--- /dev/null
+++ b/gtk/src/constraintlayout.ccg
@@ -0,0 +1,62 @@
+/* Copyright (C) 2019 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 <gtk/gtk.h>
+
+namespace Gtk
+{
+
+void ConstraintLayout::add_constraint(const Glib::RefPtr<Constraint>& constraint)
+{
+  // gtk_constraint_layout_add_constraint() does not take a ref.
+  if (constraint)
+    constraint->reference();
+  gtk_constraint_layout_add_constraint(gobj(), Glib::unwrap(constraint));
+}
+
+void ConstraintLayout::add_guide(const Glib::RefPtr<ConstraintGuide>& guide)
+{
+  // gtk_constraint_layout_add_guide() does not take a ref.
+  if (guide)
+    guide->reference();
+  gtk_constraint_layout_add_guide(gobj(), Glib::unwrap(guide));
+}
+
+std::vector<Glib::RefPtr<Constraint>> ConstraintLayout::add_constraints_from_description(
+  const std::vector<Glib::ustring>& lines, int hspacing, int vspacing, const VFLmap& views)
+{
+  GHashTable* hash_table_views = g_hash_table_new(g_str_hash, g_str_equal);
+  for (const auto& it : views)
+    g_hash_table_insert(hash_table_views, const_cast<char*>(it.first.c_str()), it.second->gobj());
+
+  GError* gerror = nullptr;
+  GList* constraints = gtk_constraint_layout_add_constraints_from_descriptionv(
+    gobj(), Glib::ArrayHandler<Glib::ustring>::vector_to_array(lines).data(),
+    lines.size(), hspacing, vspacing, hash_table_views, &gerror);
+
+  g_hash_table_unref(hash_table_views);
+
+  if (gerror)
+  {
+    g_list_free(constraints);
+    ::Glib::Error::throw_exception(gerror);
+  }
+
+  return Glib::ListHandler<Glib::RefPtr<Constraint>>::list_to_vector(
+    constraints, Glib::OWNERSHIP_SHALLOW);
+}
+
+} // namespace Gtk
diff --git a/gtk/src/constraintlayout.hg b/gtk/src/constraintlayout.hg
new file mode 100644
index 00000000..b5fda18e
--- /dev/null
+++ b/gtk/src/constraintlayout.hg
@@ -0,0 +1,110 @@
+/* Copyright (C) 2019 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 <gtkmm/layoutmanager.h>
+#include <gtkmm/buildable.h>
+#include <gtkmm/constraint.h>
+#include <gtkmm/constraintguide.h>
+#include <giomm/listmodel.h>
+#include <vector>
+#include <map>
+
+_DEFS(gtkmm,gtk)
+_PINCLUDE(gtkmm/private/layoutmanager_p.h)
+
+namespace Gtk
+{
+_WRAP_GERROR(ConstraintVflParserError, GtkConstraintVflParserError, GTK_CONSTRAINT_VFL_PARSER_ERROR)
+
+/** A layout manager using constraints.
+ *
+ * %ConstraintLayout is a layout manager that uses relations between
+ * widget attributes, expressed via Gtk::Constraint instances, to measure
+ * and allocate widgets.
+ *
+ * See the description of GtkConstraintLayout in GTK for a detailed description
+ * of how constraints work.
+ *
+ * @newin{3,96}
+ */
+class ConstraintLayout : public LayoutManager, public Buildable
+{
+  _CLASS_GOBJECT(ConstraintLayout, GtkConstraintLayout, GTK_CONSTRAINT_LAYOUT, LayoutManager, 
GtkLayoutManager)
+  _IMPLEMENTS_INTERFACE(Buildable)
+  _STRUCT_NOT_HIDDEN
+
+protected:
+  _CTOR_DEFAULT()
+
+public:
+  _WRAP_CREATE()
+
+  _WRAP_METHOD_DOCS_ONLY(gtk_constraint_layout_add_constraint)
+  void add_constraint(const Glib::RefPtr<Constraint>& constraint);
+  _WRAP_METHOD(void remove_constraint(const Glib::RefPtr<Constraint>& constraint),
+    gtk_constraint_layout_remove_constraint)
+  _WRAP_METHOD(void remove_all_constraints(), gtk_constraint_layout_remove_all_constraints)
+
+  _WRAP_METHOD_DOCS_ONLY(gtk_constraint_layout_add_guide)
+  void add_guide(const Glib::RefPtr<ConstraintGuide>& guide);
+  _WRAP_METHOD(void remove_guide(const Glib::RefPtr<ConstraintGuide>& guide),
+    gtk_constraint_layout_remove_guide)
+
+  /** A map type, used by add_constraints_from_description().
+   */
+  using VFLmap = std::map<Glib::ustring, Glib::RefPtr<ConstraintTarget>>;
+
+  /** Creates a list of constraints from a formal description using a compact
+   * description syntax called VFL, or "Visual Format Language".
+   *
+   * The Visual Format Language is based on Apple's AutoLayout
+   * <a 
href="https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage.html";>VFL</a>.
+   * See also the description of gtk_constraint_layout_add_constraints_from_descriptionv()
+   * in GTK.
+   *
+   * The @a views dictionary is used to match Gtk::ConstraintTargets to the symbolic
+   * view name inside the VFL.
+   *
+   * **Note**: The VFL grammar used by GTK is slightly different than the one
+   * defined by Apple, as it can use symbolic values for the constraint's
+   * strength instead of numeric values; additionally, GTK allows adding
+   * simple arithmetic operations inside predicates.
+   *
+   * @param lines A vector of Visual Format Language lines defining a set of constraints.
+   * @param hspacing Default horizontal spacing value, or -1 for the fallback value.
+   * @param vspacing Default vertical spacing value, or -1 for the fallback value.
+   * @param views A dictionary of [ name, target ] pairs; the `name` keys map
+   *   to the view names in the VFL lines, while the `target` values map to
+   *   children of the widget using a Gtk::ConstraintLayout, or guides.
+   * @return The vector of Gtk::Constraints that were added to the layout.
+   * @throws Gtk::ConstraintVflParserError
+   */
+  std::vector<Glib::RefPtr<Constraint>> add_constraints_from_description(
+    const std::vector<Glib::ustring>& lines, int hspacing, int vspacing, const VFLmap& views);
+  _IGNORE(gtk_constraint_layout_add_constraints_from_descriptionv,
+          gtk_constraint_layout_add_constraints_from_description)
+
+  _WRAP_METHOD(Glib::RefPtr<Gio::ListModel> observe_constraints(),
+    gtk_constraint_layout_observe_constraints)
+  _WRAP_METHOD(Glib::RefPtr<const Gio::ListModel> observe_constraints() const,
+    gtk_constraint_layout_observe_constraints, constversion)
+  _WRAP_METHOD(Glib::RefPtr<Gio::ListModel> observe_guides(),
+    gtk_constraint_layout_observe_guides)
+  _WRAP_METHOD(Glib::RefPtr<const Gio::ListModel> observe_guides() const,
+    gtk_constraint_layout_observe_guides, constversion)
+};
+
+} // namespace Gtk
diff --git a/gtk/src/constrainttarget.ccg b/gtk/src/constrainttarget.ccg
new file mode 100644
index 00000000..3663c616
--- /dev/null
+++ b/gtk/src/constrainttarget.ccg
@@ -0,0 +1,17 @@
+/* Copyright (C) 2019 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 <gtk/gtk.h>
diff --git a/gtk/src/constrainttarget.hg b/gtk/src/constrainttarget.hg
new file mode 100644
index 00000000..9f771534
--- /dev/null
+++ b/gtk/src/constrainttarget.hg
@@ -0,0 +1,47 @@
+/* Copyright (C) 2019 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 <glibmm/interface.h>
+
+_DEFS(gtkmm,gtk)
+_PINCLUDE(glibmm/private/interface_p.h)
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+extern "C"
+{
+typedef struct _GtkConstraintTargetInterface GtkConstraintTargetInterface;
+}
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+
+namespace Gtk
+{
+/** Helper interface for Gtk::Constraint.
+ *
+ * The %ConstraintTarget interface is implemented by objects that
+ * can be used as source or target in Gtk::Constraints. Besides
+ * Gtk::Widget, it is also implemented by Gtk::ConstraintGuide.
+ *
+ * @newin{3,96}
+ */
+class ConstraintTarget : public Glib::Interface
+{
+  _CLASS_INTERFACE(ConstraintTarget, GtkConstraintTarget, GTK_CONSTRAINT_TARGET, 
GtkConstraintTargetInterface)
+
+public:
+  // Nothing!
+};
+
+} // namespace Gtk
diff --git a/gtk/src/filelist.am b/gtk/src/filelist.am
index c81cd140..56013cca 100644
--- a/gtk/src/filelist.am
+++ b/gtk/src/filelist.am
@@ -58,6 +58,10 @@ gtkmm_files_any_hg =         \
        colorchooserdialog.hg   \
        combobox.hg             \
        comboboxtext.hg         \
+       constraint.hg           \
+       constraintguide.hg \
+       constraintlayout.hg \
+       constrainttarget.hg \
        container.hg            \
        csslocation.hg          \
        cssprovider.hg          \
diff --git a/gtk/src/widget.ccg b/gtk/src/widget.ccg
index fb4d822d..f20d12eb 100644
--- a/gtk/src/widget.ccg
+++ b/gtk/src/widget.ccg
@@ -307,6 +307,19 @@ void Gtk::Widget::compute_expand_vfunc(bool& hexpand_p, bool& vexpand_p)
 Widget::~Widget() noexcept
 {}
 
+Glib::RefPtr<ConstraintTarget> Widget::make_refptr_constrainttarget()
+{
+  auto refcnt_constrainttarget =
+    Glib::make_refptr_for_instance(static_cast<ConstraintTarget*>(this));
+  refcnt_constrainttarget->reference();
+  return refcnt_constrainttarget;
+}
+
+Glib::RefPtr<const ConstraintTarget> Widget::make_refptr_constrainttarget() const
+{
+  return const_cast<Widget*>(this)->make_refptr_constrainttarget();
+}
+
 void Widget::reparent(Container& new_parent)
 {
   auto old_parent = get_parent();
diff --git a/gtk/src/widget.hg b/gtk/src/widget.hg
index 18f62e40..e8a5f667 100644
--- a/gtk/src/widget.hg
+++ b/gtk/src/widget.hg
@@ -29,6 +29,7 @@ _CONFIGINCLUDE(gtkmmconfig.h)
 
 #include <gtkmm/object.h>
 #include <gtkmm/buildable.h>
+#include <gtkmm/constrainttarget.h>
 #include <gdkmm/events.h>
 #include <gdkmm/types.h>
 #include <gdkmm/drag.h>
@@ -102,21 +103,34 @@ typedef Gdk::Rectangle Allocation;
  */
 class Widget
 : public Object,
-  public Buildable
+  public Buildable,
+  public ConstraintTarget
 #ifdef GTKMM_ATKMM_ENABLED
   ,public Atk::Implementor
 #endif //GTKMM_ATKMM_ENABLED
 {
   _CLASS_GTKOBJECT(Widget,GtkWidget,GTK_WIDGET,Object,GObject)
   _IMPLEMENTS_INTERFACE(Buildable)
+  _IMPLEMENTS_INTERFACE(ConstraintTarget)
   _IMPLEMENTS_INTERFACE(Atk::Implementor, ifdef GTKMM_ATKMM_ENABLED)
+
   _IGNORE(gtk_widget_destroy, gtk_widget_destroyed, gtk_widget_list_accel_closures)
   _IGNORE(gtk_widget_paintable_new)
+
 public:
   friend class Main;
   _CUSTOM_DTOR
   _DOCUMENT_DTOR(Destroys the widget. The widget will be automatically removed from the parent container.)
 
+  /** Converts this widget to a reference counted Gtk::ConstraintTarget.
+   * Useful in calls to Gtk::Constraint::create().
+   */
+  Glib::RefPtr<ConstraintTarget> make_refptr_constrainttarget();
+
+  /** Converts this widget to a reference counted Gtk::ConstraintTarget.
+   */
+  Glib::RefPtr<const ConstraintTarget> make_refptr_constrainttarget() const;
+
   _WRAP_METHOD(void show(), gtk_widget_show)
   _WRAP_METHOD(void hide(), gtk_widget_hide)
 
diff --git a/tools/m4/convert_gtk.m4 b/tools/m4/convert_gtk.m4
index dfbeb9d1..79df5b57 100644
--- a/tools/m4/convert_gtk.m4
+++ b/tools/m4/convert_gtk.m4
@@ -38,6 +38,9 @@ _CONV_ENUM(Gtk,ButtonsType)
 _CONV_INCLASS_ENUM(Gtk,Calendar,DisplayOptions)
 _CONV_ENUM(Gtk,CellRendererMode)
 _CONV_ENUM(Gtk,CellRendererState)
+_CONV_INCLASS_ENUM(Gtk,Constraint,Attribute)
+_CONV_INCLASS_ENUM(Gtk,Constraint,Relation)
+_CONV_INCLASS_ENUM(Gtk,Constraint,Strength)
 _CONV_ENUM(Gtk,CornerType)
 _CONV_ENUM(Gtk,CssParserError)
 _CONV_ENUM(Gtk,CssParserWarning)
@@ -600,3 +603,9 @@ _CONVERSION(`GPermission*',`Glib::RefPtr<Gio::Permission>',`Glib::wrap($3)')
 
 _CONVERSION(`const Glib::RefPtr<Pango::FontMap>&',`PangoFontMap*',__CONVERT_REFPTR_TO_P)
 _CONVERSION(`const Glib::RefPtr<const Pango::FontMap>&',`PangoFontMap*',__CONVERT_CONST_REFPTR_TO_P)
+
+# Constraint, ConstraintGuide, ConstraintTarget
+_CONVERSION(`const Glib::RefPtr<Constraint>&',`GtkConstraint*',__CONVERT_REFPTR_TO_P)
+_CONVERSION(`const Glib::RefPtr<ConstraintGuide>&',`GtkConstraintGuide*',__CONVERT_REFPTR_TO_P)
+_CONVERSION(`GtkConstraintTarget*',`Glib::RefPtr<ConstraintTarget>',`Glib::wrap($3)')
+_CONVERSION(`const Glib::RefPtr<ConstraintTarget>&',`gpointer',__CONVERT_REFPTR_TO_P)


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