[gtkmm: 1/2] Add Gtk::TreeListModel and Gtk::TreeListRow
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm: 1/2] Add Gtk::TreeListModel and Gtk::TreeListRow
- Date: Sun, 9 Aug 2020 14:12:45 +0000 (UTC)
commit 90ad359ec32ee2a9da6a13760f502fd981d3e269
Author: Andreas Persson <andreasp56 outlook com>
Date: Fri Aug 7 09:08:35 2020 +0200
Add Gtk::TreeListModel and Gtk::TreeListRow
.gitignore | 4 ++
gtk/gtkmm.h | 1 +
gtk/gtkmm/meson.build | 2 +
gtk/src/filelist.am | 2 +
gtk/src/gtk_extra_objects.defs | 12 ++++
gtk/src/gtk_signals.defs | 81 +++++++++++++++++++++++++
gtk/src/treelistmodel.ccg | 56 ++++++++++++++++++
gtk/src/treelistmodel.hg | 98 +++++++++++++++++++++++++++++++
gtk/src/treelistrow.ccg | 17 ++++++
gtk/src/treelistrow.hg | 75 +++++++++++++++++++++++
tools/extra_defs_gen/generate_defs_gtk.cc | 2 +
tools/m4/convert_gtk.m4 | 1 +
12 files changed, 351 insertions(+)
---
diff --git a/.gitignore b/.gitignore
index 264f7462..af5b23f4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -563,6 +563,10 @@ gtk/gtkmm/treedragsource.cc
gtk/gtkmm/treedragsource.h
gtk/gtkmm/treeiter.cc
gtk/gtkmm/treeiter.h
+gtk/gtkmm/treelistmodel.cc
+gtk/gtkmm/treelistmodel.h
+gtk/gtkmm/treelistrow.cc
+gtk/gtkmm/treelistrow.h
gtk/gtkmm/treemodel.cc
gtk/gtkmm/treemodel.h
gtk/gtkmm/treemodelfilter.cc
diff --git a/gtk/gtkmm.h b/gtk/gtkmm.h
index 050a24bf..c0bac01e 100644
--- a/gtk/gtkmm.h
+++ b/gtk/gtkmm.h
@@ -272,6 +272,7 @@ extern const int gtkmm_micro_version;
#include <gtkmm/textview.h>
#include <gtkmm/togglebutton.h>
#include <gtkmm/tooltip.h>
+#include <gtkmm/treelistmodel.h>
#include <gtkmm/treemodel.h>
#include <gtkmm/treemodelfilter.h>
#include <gtkmm/treemodelsort.h>
diff --git a/gtk/gtkmm/meson.build b/gtk/gtkmm/meson.build
index 76643cda..45eaf5e3 100644
--- a/gtk/gtkmm/meson.build
+++ b/gtk/gtkmm/meson.build
@@ -233,6 +233,8 @@ gtkmm_any_hg_ccg_basenames = [
'treedragdest',
'treedragsource',
'treeiter',
+ 'treelistmodel',
+ 'treelistrow',
'treemodel',
'treemodelfilter',
'treemodelsort',
diff --git a/gtk/src/filelist.am b/gtk/src/filelist.am
index 6d091921..4555b9f7 100644
--- a/gtk/src/filelist.am
+++ b/gtk/src/filelist.am
@@ -218,6 +218,8 @@ gtkmm_files_any_hg = \
treedragdest.hg \
treedragsource.hg \
treeiter.hg \
+ treelistmodel.hg \
+ treelistrow.hg \
treemodel.hg \
treemodelfilter.hg \
treemodelsort.hg \
diff --git a/gtk/src/gtk_extra_objects.defs b/gtk/src/gtk_extra_objects.defs
index 455b44ca..63f11612 100644
--- a/gtk/src/gtk_extra_objects.defs
+++ b/gtk/src/gtk_extra_objects.defs
@@ -580,6 +580,18 @@
(gtype-id "GTK_TYPE_TOOLTIP")
)
+(define-object TreeListModel
+ (in-module "Gtk")
+ (c-name "GtkTreeListModel")
+ (gtype-id "GTK_TYPE_TREE_LIST_MODEL")
+)
+
+(define-object TreeListRow
+ (in-module "Gtk")
+ (c-name "GtkTreeListRow")
+ (gtype-id "GTK_TYPE_TREE_LIST_ROW")
+)
+
(define-object TreeRowReference
(in-module "Gtk")
(c-name "GtkTreeRowReference")
diff --git a/gtk/src/gtk_signals.defs b/gtk/src/gtk_signals.defs
index d016d3a1..45c102b0 100644
--- a/gtk/src/gtk_signals.defs
+++ b/gtk/src/gtk_signals.defs
@@ -11840,6 +11840,87 @@
)
)
+;; From GtkTreeListModel
+
+(define-property autoexpand
+ (of-object "GtkTreeListModel")
+ (prop-type "GParamBoolean")
+ (docs "If all rows should be expanded by default")
+ (readable #t)
+ (writable #t)
+ (construct-only #f)
+ (default-value "FALSE")
+)
+
+(define-property model
+ (of-object "GtkTreeListModel")
+ (prop-type "GParamObject")
+ (docs "The root model displayed")
+ (readable #t)
+ (writable #f)
+ (construct-only #f)
+)
+
+(define-property passthrough
+ (of-object "GtkTreeListModel")
+ (prop-type "GParamBoolean")
+ (docs "If child model values are passed through")
+ (readable #t)
+ (writable #t)
+ (construct-only #t)
+ (default-value "FALSE")
+)
+
+;; From GtkTreeListRow
+
+(define-property children
+ (of-object "GtkTreeListRow")
+ (prop-type "GParamObject")
+ (docs "Model holding the row’s children")
+ (readable #t)
+ (writable #f)
+ (construct-only #f)
+)
+
+(define-property depth
+ (of-object "GtkTreeListRow")
+ (prop-type "GParamUInt")
+ (docs "Depth in the tree")
+ (readable #t)
+ (writable #f)
+ (construct-only #f)
+ (default-value "0")
+)
+
+(define-property expandable
+ (of-object "GtkTreeListRow")
+ (prop-type "GParamBoolean")
+ (docs "If this row can ever be expanded")
+ (readable #t)
+ (writable #f)
+ (construct-only #f)
+ (default-value "FALSE")
+)
+
+(define-property expanded
+ (of-object "GtkTreeListRow")
+ (prop-type "GParamBoolean")
+ (docs "If this row is currently expanded")
+ (readable #t)
+ (writable #t)
+ (construct-only #f)
+ (default-value "FALSE")
+)
+
+(define-property item
+ (of-object "GtkTreeListRow")
+ (prop-type "GParamObject")
+ (docs "The item held in this row")
+ (readable #t)
+ (writable #f)
+ (construct-only #f)
+)
+
;; From GtkTreeSelection
(define-signal changed
diff --git a/gtk/src/treelistmodel.ccg b/gtk/src/treelistmodel.ccg
new file mode 100644
index 00000000..af8bffb0
--- /dev/null
+++ b/gtk/src/treelistmodel.ccg
@@ -0,0 +1,56 @@
+/* Copyright (C) 2020 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
+{
+
+GListModel* TreeListModel_CreateModelFunc(gpointer item, gpointer user_data)
+{
+ auto slot = static_cast<Gtk::TreeListModel::SlotCreateModel*>(user_data);
+ auto result = (*slot)(Glib::wrap(G_OBJECT(item), true));
+ if (result)
+ return G_LIST_MODEL(result->gobj_copy());
+ else
+ return nullptr;
+}
+
+void TreeListModel_destroy_callback(gpointer data)
+{
+ delete static_cast<Gtk::TreeListModel::SlotCreateModel*>(data);
+}
+
+} // anonymous namespace
+
+namespace Gtk
+{
+
+// The only way to set create_func is to use gtk_tree_list_model_new.
+TreeListModel::TreeListModel(const Glib::RefPtr<Gio::ListModel>& root,
+ const SlotCreateModel& slot_create,
+ bool passthrough, bool autoexpand)
+:
+ Glib::ObjectBase(nullptr),
+ Glib::Object(G_OBJECT(gtk_tree_list_model_new(
+ G_LIST_MODEL(root->gobj_copy()), passthrough, autoexpand,
+ &TreeListModel_CreateModelFunc,
+ new SlotCreateModel(slot_create),
+ &TreeListModel_destroy_callback)))
+{
+}
+
+}
diff --git a/gtk/src/treelistmodel.hg b/gtk/src/treelistmodel.hg
new file mode 100644
index 00000000..0f7f7b27
--- /dev/null
+++ b/gtk/src/treelistmodel.hg
@@ -0,0 +1,98 @@
+/* Copyright (C) 2020 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/>.
+ */
+
+_CONFIGINCLUDE(gtkmmconfig.h)
+
+#include <glibmm/object.h>
+#include <giomm/listmodel.h>
+#include <gtkmm/treelistrow.h>
+
+_DEFS(gtkmm,gtk)
+_PINCLUDE(glibmm/private/object_p.h)
+
+namespace Gtk
+{
+
+/** A list model that can create child models on demand.
+ *
+ * %Gtk::TreeListModel is a Gio::ListModel implementation that can expand rows
+ * by creating new child list models on demand.
+ *
+ * @see Gio::ListModel
+ *
+ * @newin{3,98}
+ */
+class GTKMM_API TreeListModel : public Glib::Object, public Gio::ListModel
+{
+ _CLASS_GOBJECT(TreeListModel, GtkTreeListModel, GTK_TREE_LIST_MODEL, Glib::Object, GObject, , , GTKMM_API)
+ _IMPLEMENTS_INTERFACE(Gio::ListModel)
+ _STRUCT_NOT_HIDDEN
+
+public:
+
+ /** For instance:
+ * Glib::RefPtr<Gio::ListModel> create_func(const Glib::RefPtr<Glib::ObjectBase>& item);
+ *
+ * Prototype of the function called to create new child models when
+ * Gtk::TreeListRow::set_expanded() is called.
+ *
+ * This function can return <tt>nullptr</tt> to indicate that @a item is
+ * guaranteed to be a leaf node and will never have children.
+ * If it does not have children but may get children later, it should return
+ * an empty model that is filled once children arrive.
+ *
+ * @param item The item that is being expanded.
+ *
+ * @return The model tracking the children of @a item or <tt>nullptr</tt> if
+ * @a item can never have children.
+ */
+ using SlotCreateModel = sigc::slot<Glib::RefPtr<Gio::ListModel>(const Glib::RefPtr<Glib::ObjectBase>&)>;
+
+protected:
+
+ TreeListModel(const Glib::RefPtr<Gio::ListModel>& root, const SlotCreateModel& slot_create, bool
passthrough = false, bool autoexpand = false);
+
+public:
+
+ /** Creates a new empty %Gtk::TreeListModel displaying @a root with
+ * all rows collapsed.
+ *
+ * @param root The Gio::ListModel to use as root.
+ * @param slot_create Slot to call to create the Gio::ListModel for
+ * the children of an item.
+ * @param passthrough <tt>true</tt> to pass through items from the models.
+ * @param autoexpand <tt>true</tt> to set the autoexpand property and
+ * expand the @a root model.
+ */
+ _WRAP_CREATE(const Glib::RefPtr<Gio::ListModel>& root, const SlotCreateModel& slot_create, bool
passthrough = false, bool autoexpand = false)
+
+ _WRAP_METHOD(Glib::RefPtr<Gio::ListModel> get_model(), gtk_tree_list_model_get_model, refreturn)
+ _WRAP_METHOD(Glib::RefPtr<const Gio::ListModel> get_model() const, gtk_tree_list_model_get_model,
refreturn, constversion)
+ _WRAP_METHOD(bool get_passthrough() const, gtk_tree_list_model_get_passthrough)
+ _WRAP_METHOD(void set_autoexpand(bool autoexpand = true), gtk_tree_list_model_set_autoexpand)
+ _WRAP_METHOD(bool get_autoexpand() const, gtk_tree_list_model_get_autoexpand)
+
+ _WRAP_METHOD(Glib::RefPtr<TreeListRow> get_child_row(guint position), gtk_tree_list_model_get_child_row)
+ _WRAP_METHOD(Glib::RefPtr<const TreeListRow> get_child_row(guint position) const,
gtk_tree_list_model_get_child_row, constversion)
+ _WRAP_METHOD(Glib::RefPtr<TreeListRow> get_row(guint position), gtk_tree_list_model_get_row)
+ _WRAP_METHOD(Glib::RefPtr<const TreeListRow> get_row(guint position) const, gtk_tree_list_model_get_row,
constversion)
+
+ _WRAP_PROPERTY("autoexpand", bool)
+ _WRAP_PROPERTY("model", Glib::RefPtr<Gio::ListModel>)
+ _WRAP_PROPERTY("passthrough", bool)
+};
+
+} // namespace Gtk
diff --git a/gtk/src/treelistrow.ccg b/gtk/src/treelistrow.ccg
new file mode 100644
index 00000000..57b87fdc
--- /dev/null
+++ b/gtk/src/treelistrow.ccg
@@ -0,0 +1,17 @@
+/* Copyright (C) 2020 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/treelistrow.hg b/gtk/src/treelistrow.hg
new file mode 100644
index 00000000..741b3578
--- /dev/null
+++ b/gtk/src/treelistrow.hg
@@ -0,0 +1,75 @@
+/* Copyright (C) 2020 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/>.
+ */
+
+_CONFIGINCLUDE(gtkmmconfig.h)
+
+#include <glibmm/object.h>
+#include <giomm/listmodel.h>
+#include <gtk/gtk.h>
+
+_DEFS(gtkmm,gtk)
+_PINCLUDE(glibmm/private/object_p.h)
+
+namespace Gtk
+{
+
+/** A row in a Gtk::TreeListModel.
+ *
+ * %Gtk::TreeListRow is the object used by Gtk::TreeListModel to
+ * represent items. It allows navigating the model as a tree and
+ * modify the state of rows.
+ *
+ * %Gtk::TreeListRow instances are created by a Gtk::TreeListModel only
+ * when the Gtk::TreeListModel::property_passthrough() property is not set.
+ *
+ * There are various support objects that can make use of %Gtk::TreeListRow
+ * objects, such as the Gtk::TreeExpander widget that allows displaying
+ * an icon to expand or collapse a row or Gtk::TreeListRowSorter that makes
+ * it possible to sort trees properly.
+ *
+ * @see Gtk::TreeListModel
+ *
+ * @newin{3,98}
+ */
+class GTKMM_API TreeListRow : public Glib::Object
+{
+ _CLASS_GOBJECT(TreeListRow, GtkTreeListRow, GTK_TREE_LIST_ROW, Glib::Object, GObject, , , GTKMM_API)
+ _STRUCT_NOT_HIDDEN
+
+public:
+#m4 _CONVERSION(`gpointer',`Glib::RefPtr<Glib::ObjectBase>',`Glib::wrap(G_OBJECT($3))')
+ _WRAP_METHOD(Glib::RefPtr<Glib::ObjectBase> get_item(), gtk_tree_list_row_get_item)
+ _WRAP_METHOD(Glib::RefPtr<const Glib::ObjectBase> get_item() const, gtk_tree_list_row_get_item,
constversion)
+ _WRAP_METHOD(void set_expanded(bool expanded = true), gtk_tree_list_row_set_expanded)
+ _WRAP_METHOD(bool get_expanded() const, gtk_tree_list_row_get_expanded)
+ _WRAP_METHOD(bool is_expandable() const, gtk_tree_list_row_is_expandable)
+ _WRAP_METHOD(guint get_position() const, gtk_tree_list_row_get_position)
+ _WRAP_METHOD(guint get_depth() const, gtk_tree_list_row_get_depth)
+ _WRAP_METHOD(Glib::RefPtr<Gio::ListModel> get_children(), gtk_tree_list_row_get_children, refreturn)
+ _WRAP_METHOD(Glib::RefPtr<const Gio::ListModel> get_children() const, gtk_tree_list_row_get_children,
refreturn, constversion)
+ _WRAP_METHOD(Glib::RefPtr<TreeListRow> get_parent(), gtk_tree_list_row_get_parent)
+ _WRAP_METHOD(Glib::RefPtr<const TreeListRow> get_parent() const, gtk_tree_list_row_get_parent,
constversion)
+ _WRAP_METHOD(Glib::RefPtr<TreeListRow> get_child_row(guint position), gtk_tree_list_row_get_child_row)
+ _WRAP_METHOD(Glib::RefPtr<const TreeListRow> get_child_row(guint position) const,
gtk_tree_list_row_get_child_row, constversion)
+
+ _WRAP_PROPERTY("children", Glib::RefPtr<Gio::ListModel>)
+ _WRAP_PROPERTY("depth", guint)
+ _WRAP_PROPERTY("expandable", bool)
+ _WRAP_PROPERTY("expanded", bool)
+ _WRAP_PROPERTY("item", Glib::RefPtr<Glib::ObjectBase>)
+};
+
+}
diff --git a/tools/extra_defs_gen/generate_defs_gtk.cc b/tools/extra_defs_gen/generate_defs_gtk.cc
index 8109cd92..f311a609 100644
--- a/tools/extra_defs_gen/generate_defs_gtk.cc
+++ b/tools/extra_defs_gen/generate_defs_gtk.cc
@@ -230,6 +230,8 @@ int main(int /* argc */, char** /* argv */)
<< get_defs( GTK_TYPE_TOGGLE_BUTTON )
<< get_defs( GTK_TYPE_TOOLTIP )
<< get_defs( GTK_TYPE_TREE_MODEL )
+ << get_defs( GTK_TYPE_TREE_LIST_MODEL )
+ << get_defs( GTK_TYPE_TREE_LIST_ROW )
<< get_defs( GTK_TYPE_TREE_SELECTION )
<< get_defs( GTK_TYPE_TREE_SORTABLE )
<< get_defs( GTK_TYPE_TREE_MODEL_FILTER )
diff --git a/tools/m4/convert_gtk.m4 b/tools/m4/convert_gtk.m4
index a9105931..c3c1a5f5 100644
--- a/tools/m4/convert_gtk.m4
+++ b/tools/m4/convert_gtk.m4
@@ -592,3 +592,4 @@ _CONVERSION(`GtkListItemFactory*',`Glib::RefPtr<ListItemFactory>',`Glib::wrap($3
_CONVERSION(`GtkStringObject*',`Glib::RefPtr<StringObject>',`Glib::wrap($3)')
_CONVERSION(`const Glib::RefPtr<Sorter>&', `GtkSorter*', __CONVERT_REFPTR_TO_P)
_CONVERSION(`GtkSorter*',`Glib::RefPtr<Sorter>',`Glib::wrap($3)')
+_CONVERSION(`GtkTreeListRow*',`Glib::RefPtr<TreeListRow>',`Glib::wrap($3)')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]