[gtkmm: 1/3] Add Gtk::ListView
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm: 1/3] Add Gtk::ListView
- Date: Mon, 20 Jul 2020 09:13:46 +0000 (UTC)
commit 5ed6c0b1e5f63c720af6a376a046e32c05dc96bb
Author: Andreas Persson <andreasp56 outlook com>
Date: Sat Jul 18 14:08:24 2020 +0200
Add Gtk::ListView
Add bindings for ListView and its base class ListBase.
.gitignore | 4 +
gtk/gtkmm.h | 1 +
gtk/gtkmm/meson.build | 2 +
gtk/src/filelist.am | 1 +
gtk/src/gtk_signals.defs | 59 +++++++++++++++
gtk/src/listbase.ccg | 17 +++++
gtk/src/listbase.hg | 34 +++++++++
gtk/src/listview.ccg | 17 +++++
gtk/src/listview.hg | 121 ++++++++++++++++++++++++++++++
tools/extra_defs_gen/generate_defs_gtk.cc | 1 +
10 files changed, 257 insertions(+)
---
diff --git a/.gitignore b/.gitignore
index 7b8f436f1..a9266d8da 100644
--- a/.gitignore
+++ b/.gitignore
@@ -367,6 +367,8 @@ gtk/gtkmm/levelbar.cc
gtk/gtkmm/levelbar.h
gtk/gtkmm/linkbutton.cc
gtk/gtkmm/linkbutton.h
+gtk/gtkmm/listbase.cc
+gtk/gtkmm/listbase.h
gtk/gtkmm/listbox.cc
gtk/gtkmm/listbox.h
gtk/gtkmm/listboxrow.cc
@@ -377,6 +379,8 @@ gtk/gtkmm/listitemfactory.cc
gtk/gtkmm/listitemfactory.h
gtk/gtkmm/liststore.cc
gtk/gtkmm/liststore.h
+gtk/gtkmm/listview.cc
+gtk/gtkmm/listview.h
gtk/gtkmm/lockbutton.cc
gtk/gtkmm/lockbutton.h
gtk/gtkmm/mediacontrols.cc
diff --git a/gtk/gtkmm.h b/gtk/gtkmm.h
index b888ac876..52804e9e0 100644
--- a/gtk/gtkmm.h
+++ b/gtk/gtkmm.h
@@ -192,6 +192,7 @@ extern const int gtkmm_micro_version;
#include <gtkmm/listbox.h>
#include <gtkmm/listboxrow.h>
#include <gtkmm/liststore.h>
+#include <gtkmm/listview.h>
#include <gtkmm/listviewtext.h>
#include <gtkmm/linkbutton.h>
#include <gtkmm/mediacontrols.h>
diff --git a/gtk/gtkmm/meson.build b/gtk/gtkmm/meson.build
index c32b1a7e6..4c3dce000 100644
--- a/gtk/gtkmm/meson.build
+++ b/gtk/gtkmm/meson.build
@@ -141,11 +141,13 @@ gtkmm_any_hg_ccg_basenames = [
'layoutmanager',
'levelbar',
'linkbutton',
+ 'listbase',
'listbox',
'listboxrow',
'listitem',
'listitemfactory',
'liststore',
+ 'listview',
'lockbutton',
'mediacontrols',
'mediafile',
diff --git a/gtk/src/filelist.am b/gtk/src/filelist.am
index e92e284b3..39cc1c2d3 100644
--- a/gtk/src/filelist.am
+++ b/gtk/src/filelist.am
@@ -131,6 +131,7 @@ gtkmm_files_any_hg = \
listitem.hg \
listitemfactory.hg \
liststore.hg \
+ listview.hg \
lockbutton.hg \
mediacontrols.hg \
mediafile.hg \
diff --git a/gtk/src/gtk_signals.defs b/gtk/src/gtk_signals.defs
index 203f3e110..6a0bc43c3 100644
--- a/gtk/src/gtk_signals.defs
+++ b/gtk/src/gtk_signals.defs
@@ -6152,6 +6152,65 @@
(default-value "FALSE")
)
+;; From GtkListView
+
+(define-signal activate
+ (of-object "GtkListView")
+ (return-type "void")
+ (flags "Run Last")
+ (parameters
+ '("guint" "p0")
+ )
+)
+
+(define-property factory
+ (of-object "GtkListView")
+ (prop-type "GParamObject")
+ (docs "Factory for populating list items")
+ (readable #t)
+ (writable #t)
+ (construct-only #f)
+)
+
+(define-property model
+ (of-object "GtkListView")
+ (prop-type "GParamObject")
+ (docs "Model for the items displayed")
+ (readable #t)
+ (writable #t)
+ (construct-only #f)
+)
+
+(define-property show-separators
+ (of-object "GtkListView")
+ (prop-type "GParamBoolean")
+ (docs "Show separators between rows")
+ (readable #t)
+ (writable #t)
+ (construct-only #f)
+ (default-value "FALSE")
+)
+
+(define-property single-click-activate
+ (of-object "GtkListView")
+ (prop-type "GParamBoolean")
+ (docs "Activate rows on single click")
+ (readable #t)
+ (writable #t)
+ (construct-only #f)
+ (default-value "FALSE")
+)
+
+(define-property enable-rubberband
+ (of-object "GtkListView")
+ (prop-type "GParamBoolean")
+ (docs "Allow selecting items by dragging with the mouse")
+ (readable #t)
+ (writable #t)
+ (construct-only #f)
+ (default-value "FALSE")
+)
+
;; From GtkLockButton
(define-property permission
diff --git a/gtk/src/listbase.ccg b/gtk/src/listbase.ccg
new file mode 100644
index 000000000..57b87fdcf
--- /dev/null
+++ b/gtk/src/listbase.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/listbase.hg b/gtk/src/listbase.hg
new file mode 100644
index 000000000..6ee767755
--- /dev/null
+++ b/gtk/src/listbase.hg
@@ -0,0 +1,34 @@
+/* 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 <gtkmm/widget.h>
+#include <gtkmm/orientable.h>
+#include <gtkmm/scrollable.h>
+
+_DEFS(gtkmm,gtk)
+_PINCLUDE(gtkmm/private/widget_p.h)
+
+namespace Gtk
+{
+
+class GTKMM_API ListBase : public Widget, public Orientable, public Scrollable
+{
+ _CLASS_GTKOBJECT(ListBase, GtkListBase, GTK_LIST_BASE, Gtk::Widget, GtkWidget, , , GTKMM_API)
+ _IMPLEMENTS_INTERFACE(Orientable)
+ _IMPLEMENTS_INTERFACE(Scrollable)
+};
+
+} // namespace Gtk
diff --git a/gtk/src/listview.ccg b/gtk/src/listview.ccg
new file mode 100644
index 000000000..57b87fdcf
--- /dev/null
+++ b/gtk/src/listview.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/listview.hg b/gtk/src/listview.hg
new file mode 100644
index 000000000..8e265b8e2
--- /dev/null
+++ b/gtk/src/listview.hg
@@ -0,0 +1,121 @@
+/* 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 <gtkmm/listbase.h>
+#include <giomm/listmodel.h>
+#include <gtkmm/listitemfactory.h>
+
+_DEFS(gtkmm,gtk)
+_PINCLUDE(gtkmm/private/listbase_p.h)
+
+namespace Gtk
+{
+
+/** A widget for displaying lists.
+ *
+ * %Gtk::ListView is a widget to present a view into a large dynamic list of items.
+ *
+ * %Gtk::ListView uses its factory to generate one row widget for each visible item
+ * and shows them in a linear display, either vertically or horizontally. The
+ * property_show_separators() property offers a simple way to display separators
+ * between the rows.
+ *
+ * %Gtk::ListView allows the user to select items according to the selection
+ * characteristics of the model. If the provided model is not a Gtk::SelectionModel,
+ * %Gtk::ListView will wrap it in a Gtk::SingleSelection. For models that allow
+ * multiple selected items, it is possible to turn on _rubberband selection_,
+ * using set_enable_rubberband().
+ *
+ * If you need multiple columns with headers, see Gtk::ColumnView.
+ *
+ * An example of using %Gtk::ListView:
+ * ~~~
+ * void setup_listitem_cb(const Glib::RefPtr<Gtk::ListItem>& list_item)
+ * {
+ * auto image = new Gtk::Image;
+ * image->set_icon_size(Gtk::IconSize::LARGE);
+ * list_item->set_child(*image);
+ * }
+ *
+ * void bind_listitem_cb(const Glib::RefPtr<Gtk::ListItem>& list_item)
+ * {
+ * auto item = list_item->get_item();
+ * if (auto app_info = std::dynamic_pointer_cast<Gio::AppInfo>(item))
+ * if (auto image = dynamic_cast<Gtk::Image*>(list_item->get_child()))
+ * image->set(app_info->get_icon());
+ * }
+ *
+ * void activate_cb(Gtk::ListView* list, guint position)
+ * {
+ * auto item = list->get_model()->get_object(position);
+ * if (auto app_info = std::dynamic_pointer_cast<Gio::AppInfo>(item))
+ * app_info->launch(std::vector<Glib::RefPtr<Gio::File>>());
+ * }
+ *
+ * ...
+ *
+ * auto factory = Gtk::SignalListItemFactory::create();
+ * factory->signal_setup().connect(sigc::ptr_fun(setup_listitem_cb));
+ * factory->signal_bind().connect(sigc::ptr_fun(bind_listitem_cb));
+ *
+ * auto list = new Gtk::ListView(factory);
+ *
+ * list->signal_activate().connect(
+ * sigc::bind<0>(sigc::ptr_fun(activate_cb), list));
+ *
+ * auto model = create_application_list();
+ * list->set_model(model);
+ *
+ * scrolled_window.set_child(*list);
+ * ~~~
+ * @see Gio::ListModel, Gtk::ColumnView, Gtk::GridView
+ *
+ * @ingroup Widgets
+ *
+ * @newin{3,98}
+ */
+class GTKMM_API ListView : public ListBase
+{
+ _CLASS_GTKOBJECT(ListView, GtkListView, GTK_LIST_VIEW, ListBase, GtkListBase, , , GTKMM_API)
+
+public:
+ _CTOR_DEFAULT
+ _WRAP_CTOR(ListView(const Glib::RefPtr<ListItemFactory>& factory), gtk_list_view_new_with_factory)
+
+ _WRAP_METHOD(Glib::RefPtr<Gio::ListModel> get_model(), gtk_list_view_get_model, refreturn)
+ _WRAP_METHOD(Glib::RefPtr<const Gio::ListModel> get_model() const, gtk_list_view_get_model, refreturn,
constversion)
+ _WRAP_METHOD(void set_model(const Glib::RefPtr<Gio::ListModel>& model), gtk_list_view_set_model)
+ _WRAP_METHOD(void set_factory(const Glib::RefPtr<ListItemFactory>& factory), gtk_list_view_set_factory)
+ _WRAP_METHOD(Glib::RefPtr<ListItemFactory> get_factory(), gtk_list_view_get_factory, refreturn)
+ _WRAP_METHOD(Glib::RefPtr<const ListItemFactory> get_factory() const, gtk_list_view_get_factory,
refreturn, constversion)
+ _WRAP_METHOD(void set_show_separators(bool show_separators = true), gtk_list_view_set_show_separators)
+ _WRAP_METHOD(bool get_show_separators() const, gtk_list_view_get_show_separators)
+ _WRAP_METHOD(void set_single_click_activate(bool single_click_activate = true),
gtk_list_view_set_single_click_activate)
+ _WRAP_METHOD(bool get_single_click_activate() const, gtk_list_view_get_single_click_activate)
+ _WRAP_METHOD(void set_enable_rubberband(bool enable_rubberband = true),
gtk_list_view_set_enable_rubberband)
+ _WRAP_METHOD(bool get_enable_rubberband() const, gtk_list_view_get_enable_rubberband)
+
+ _WRAP_PROPERTY("factory", Glib::RefPtr<ListItemFactory>)
+ _WRAP_PROPERTY("model", Glib::RefPtr<Gio::ListModel>)
+ _WRAP_PROPERTY("show-separators", bool)
+ _WRAP_PROPERTY("single-click-activate", bool)
+ _WRAP_PROPERTY("enable-rubberband", bool)
+
+ // no_default_handler because GtkListViewClass is private.
+ _WRAP_SIGNAL(void activate(guint pos), "activate", no_default_handler)
+};
+
+} // namespace Gtk
diff --git a/tools/extra_defs_gen/generate_defs_gtk.cc b/tools/extra_defs_gen/generate_defs_gtk.cc
index 9034001c7..3c7f18b3a 100644
--- a/tools/extra_defs_gen/generate_defs_gtk.cc
+++ b/tools/extra_defs_gen/generate_defs_gtk.cc
@@ -147,6 +147,7 @@ int main(int /* argc */, char** /* argv */)
<< get_defs( GTK_TYPE_LIST_BOX )
<< get_defs( GTK_TYPE_LIST_BOX_ROW )
<< get_defs( GTK_TYPE_LIST_ITEM )
+ << get_defs( GTK_TYPE_LIST_VIEW )
<< get_defs( GTK_TYPE_LOCK_BUTTON )
<< get_defs( GTK_TYPE_MEDIA_CONTROLS )
<< get_defs( GTK_TYPE_MEDIA_FILE )
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]