[gtk/wip/otte/listview: 97/100] Add GtkColumnView skeleton
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 97/100] Add GtkColumnView skeleton
- Date: Tue, 29 Oct 2019 04:04:52 +0000 (UTC)
commit 9cbc309661efcc7f1312bd07d73ff86bb436d61e
Author: Benjamin Otte <otte redhat com>
Date: Mon Oct 28 01:18:14 2019 +0100
Add GtkColumnView skeleton
It's just a copy/paste of the listview code with all the internals
gutted. The code doesn't do anything.
docs/reference/gtk/gtk4-sections.txt | 43 +++++
gtk/gtk.h | 2 +
gtk/gtkcolumnview.c | 358 +++++++++++++++++++++++++++++++++++
gtk/gtkcolumnview.h | 69 +++++++
gtk/gtkcolumnviewcolumn.c | 338 +++++++++++++++++++++++++++++++++
gtk/gtkcolumnviewcolumn.h | 70 +++++++
gtk/meson.build | 4 +
7 files changed, 884 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 4344e85f30..47e0f7e8dc 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -536,6 +536,49 @@ GTK_TYPE_LIST_VIEW
gtk_list_view_get_type
</SECTION>
+<SECTION>
+<FILE>gtkcolumnview</FILE>
+<TITLE>GtkColumnView</TITLE>
+GtkColumnView
+gtk_column_view_new
+gtk_column_view_get_columns
+gtk_column_view_get_model
+gtk_column_view_set_model
+gtk_column_view_get_show_separators
+gtk_column_view_set_show_separators
+<SUBSECTION Standard>
+GTK_COLUMN_VIEW
+GTK_COLUMN_VIEW_CLASS
+GTK_COLUMN_VIEW_GET_CLASS
+GTK_IS_COLUMN_VIEW
+GTK_IS_COLUMN_VIEW_CLASS
+GTK_TYPE_COLUMN_VIEW
+<SUBSECTION Private>
+gtk_column_view_get_type
+</SECTION>
+
+<SECTION>
+<FILE>gtkcolumnviewcolumn</FILE>
+<TITLE>GtkColumnViewColumn</TITLE>
+GtkColumnViewColumn
+gtk_column_view_column_new
+gtk_column_view_column_new_with_factory
+gtk_column_view_column_get_column_view
+gtk_column_view_column_set_factory
+gtk_column_view_column_get_factory
+gtk_column_view_column_set_title
+gtk_column_view_column_get_title
+<SUBSECTION Standard>
+GTK_COLUMN_VIEW_COLUMN
+GTK_COLUMN_VIEW_COLUMN_CLASS
+GTK_COLUMN_VIEW_COLUMN_GET_CLASS
+GTK_IS_COLUMN_VIEW_COLUMN
+GTK_IS_COLUMN_VIEW_COLUMN_CLASS
+GTK_TYPE_COLUMN_VIEW_COLUMN
+<SUBSECTION Private>
+gtk_column_view_column_get_type
+</SECTION>
+
<SECTION>
<FILE>gtkgridview</FILE>
<TITLE>GtkGridView</TITLE>
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 1ac3f3a767..9842ccbddd 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -82,6 +82,8 @@
#include <gtk/gtkcolorchooserdialog.h>
#include <gtk/gtkcolorchooserwidget.h>
#include <gtk/gtkcolorutils.h>
+#include <gtk/gtkcolumnview.h>
+#include <gtk/gtkcolumnviewcolumn.h>
#include <gtk/gtkcombobox.h>
#include <gtk/gtkcomboboxtext.h>
#include <gtk/gtkconstraintlayout.h>
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
new file mode 100644
index 0000000000..63124085b5
--- /dev/null
+++ b/gtk/gtkcolumnview.c
@@ -0,0 +1,358 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *
+ * 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/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#include "config.h"
+
+#include "gtkcolumnview.h"
+
+#include "gtkboxlayout.h"
+#include "gtkcolumnviewcolumn.h"
+#include "gtkintl.h"
+#include "gtklistview.h"
+#include "gtkmain.h"
+#include "gtkprivate.h"
+#include "gtkwidgetprivate.h"
+
+/**
+ * SECTION:gtkcolumnview
+ * @title: GtkColumnView
+ * @short_description: A widget for displaying lists in multiple columns
+ * @see_also: #GtkColumnViewColumn, #GtkTreeView
+ *
+ * GtkColumnView is a widget to present a view into a large dynamic list of items
+ * using multiple columns.
+ */
+
+struct _GtkColumnView
+{
+ GtkWidget parent_instance;
+
+ GListStore *columns;
+
+ GtkListView *listview;
+};
+
+struct _GtkColumnViewClass
+{
+ GtkWidgetClass parent_class;
+};
+
+enum
+{
+ PROP_0,
+ PROP_COLUMNS,
+ PROP_MODEL,
+ PROP_SHOW_SEPARATORS,
+
+ N_PROPS
+};
+
+enum {
+ ACTIVATE,
+ LAST_SIGNAL
+};
+
+G_DEFINE_TYPE (GtkColumnView, gtk_column_view, GTK_TYPE_WIDGET)
+
+static GParamSpec *properties[N_PROPS] = { NULL, };
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static void
+gtk_column_view_activate_cb (GtkListView *listview,
+ guint pos,
+ GtkColumnView *self)
+{
+ g_signal_emit (self, signals[ACTIVATE], 0, pos);
+}
+
+static void
+gtk_column_view_dispose (GObject *object)
+{
+ GtkColumnView *self = GTK_COLUMN_VIEW (object);
+
+ g_list_store_remove_all (self->columns);
+
+ g_clear_pointer ((GtkWidget **) &self->listview, gtk_widget_unparent);
+
+ G_OBJECT_CLASS (gtk_column_view_parent_class)->dispose (object);
+}
+
+static void
+gtk_column_view_finalize (GObject *object)
+{
+ GtkColumnView *self = GTK_COLUMN_VIEW (object);
+
+ g_object_unref (self->columns);
+
+ G_OBJECT_CLASS (gtk_column_view_parent_class)->finalize (object);
+}
+
+static void
+gtk_column_view_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkColumnView *self = GTK_COLUMN_VIEW (object);
+
+ switch (property_id)
+ {
+ case PROP_COLUMNS:
+ g_value_set_object (value, self->columns);
+ break;
+
+ case PROP_MODEL:
+ g_value_set_object (value, gtk_list_view_get_model (self->listview));
+ break;
+
+ case PROP_SHOW_SEPARATORS:
+ g_value_set_boolean (value, gtk_list_view_get_show_separators (self->listview));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_column_view_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkColumnView *self = GTK_COLUMN_VIEW (object);
+
+ switch (property_id)
+ {
+ case PROP_MODEL:
+ gtk_column_view_set_model (self, g_value_get_object (value));
+ break;
+
+ case PROP_SHOW_SEPARATORS:
+ gtk_column_view_set_show_separators (self, g_value_get_boolean (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_column_view_class_init (GtkColumnViewClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->dispose = gtk_column_view_dispose;
+ gobject_class->finalize = gtk_column_view_finalize;
+ gobject_class->get_property = gtk_column_view_get_property;
+ gobject_class->set_property = gtk_column_view_set_property;
+
+ /**
+ * GtkColumnView:columns:
+ *
+ * The list of columns
+ */
+ properties[PROP_COLUMNS] =
+ g_param_spec_object ("columns",
+ P_("Columns"),
+ P_("List of columns"),
+ G_TYPE_LIST_MODEL,
+ G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * GtkColumnView:model:
+ *
+ * Model for the items displayed
+ */
+ properties[PROP_MODEL] =
+ g_param_spec_object ("model",
+ P_("Model"),
+ P_("Model for the items displayed"),
+ G_TYPE_LIST_MODEL,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * GtkColumnView:show-separators:
+ *
+ * Show separators between rows
+ */
+ properties[PROP_SHOW_SEPARATORS] =
+ g_param_spec_boolean ("show-separators",
+ P_("Show separators"),
+ P_("Show separators between rows"),
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
+ g_object_class_install_properties (gobject_class, N_PROPS, properties);
+
+ /**
+ * GtkColumnView::activate:
+ * @self: The #GtkColumnView
+ * @position: position of item to activate
+ *
+ * The ::activate signal is emitted when a row has been activated by the user,
+ * usually via activating the GtkListBase|list.activate-item action.
+ *
+ * This allows for a convenient way to handle activation in a columnview.
+ * See gtk_list_item_set_activatable() for details on how to use this signal.
+ */
+ signals[ACTIVATE] =
+ g_signal_new (I_("activate"),
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE, 1,
+ G_TYPE_UINT);
+ g_signal_set_va_marshaller (signals[ACTIVATE],
+ G_TYPE_FROM_CLASS (gobject_class),
+ g_cclosure_marshal_VOID__UINTv);
+
+ gtk_widget_class_set_css_name (widget_class, I_("columnview"));
+ gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
+}
+
+static void
+gtk_column_view_init (GtkColumnView *self)
+{
+ self->columns = g_list_store_new (GTK_TYPE_COLUMN_VIEW_COLUMN);
+
+ self->listview = GTK_LIST_VIEW (gtk_list_view_new ());
+ g_signal_connect (self->listview, "activate", G_CALLBACK (gtk_column_view_activate_cb), self);
+ gtk_widget_set_parent (GTK_WIDGET (self->listview), GTK_WIDGET (self));
+}
+
+/**
+ * gtk_column_view_new:
+ *
+ * Creates a new empty #GtkColumnView.
+ *
+ * You most likely want to call gtk_column_view_set_factory() to
+ * set up a way to map its items to widgets and gtk_column_view_set_model()
+ * to set a model to provide items next.
+ *
+ * Returns: a new #GtkColumnView
+ **/
+GtkWidget *
+gtk_column_view_new (void)
+{
+ return g_object_new (GTK_TYPE_COLUMN_VIEW, NULL);
+}
+
+/**
+ * gtk_column_view_get_model:
+ * @self: a #GtkColumnView
+ *
+ * Gets the model that's currently used to read the items displayed.
+ *
+ * Returns: (nullable) (transfer none): The model in use
+ **/
+GListModel *
+gtk_column_view_get_model (GtkColumnView *self)
+{
+ g_return_val_if_fail (GTK_IS_COLUMN_VIEW (self), NULL);
+
+ return gtk_list_view_get_model (self->listview);
+}
+
+/**
+ * gtk_column_view_set_model:
+ * @self: a #GtkColumnView
+ * @model: (allow-none) (transfer none): the model to use or %NULL for none
+ *
+ * Sets the #GListModel to use.
+ *
+ * If the @model is a #GtkSelectionModel, it is used for managing the selection.
+ * Otherwise, @self creates a #GtkSingleSelection for the selection.
+ **/
+void
+gtk_column_view_set_model (GtkColumnView *self,
+ GListModel *model)
+{
+ g_return_if_fail (GTK_IS_COLUMN_VIEW (self));
+ g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
+
+ if (gtk_list_view_get_model (self->listview) == model)
+ return;
+
+ gtk_list_view_set_model (self->listview, model);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
+}
+
+/**
+ * gtk_column_view_get_columns:
+ * @self: a #GtkColumnView
+ *
+ * Gets the list of columns in this column view. This list is constant over
+ * the lifetime of @self and can be used to monitor changes to the columns
+ * of @self by connecting to the GListModel:items-changed signal.
+ *
+ * Returns: (transfer none): The list managing the columns
+ **/
+GListModel *
+gtk_column_view_get_columns (GtkColumnView *self)
+{
+ g_return_val_if_fail (GTK_IS_COLUMN_VIEW (self), NULL);
+
+ return G_LIST_MODEL (self->columns);
+}
+
+/**
+ * gtk_column_view_set_show_separators:
+ * @self: a #GtkColumnView
+ * @show_separators: %TRUE to show separators
+ *
+ * Sets whether the list should show separators
+ * between rows.
+ */
+void
+gtk_column_view_set_show_separators (GtkColumnView *self,
+ gboolean show_separators)
+{
+ g_return_if_fail (GTK_IS_COLUMN_VIEW (self));
+
+ if (gtk_list_view_get_show_separators (self->listview) == show_separators)
+ return;
+
+ gtk_list_view_set_show_separators (self->listview, show_separators);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_SEPARATORS]);
+}
+
+/**
+ * gtk_column_view_get_show_separators:
+ * @self: a #GtkColumnView
+ *
+ * Returns whether the list box should show separators
+ * between rows.
+ *
+ * Returns: %TRUE if the list box shows separators
+ */
+gboolean
+gtk_column_view_get_show_separators (GtkColumnView *self)
+{
+ g_return_val_if_fail (GTK_IS_COLUMN_VIEW (self), FALSE);
+
+ return gtk_list_view_get_show_separators (self->listview);
+}
diff --git a/gtk/gtkcolumnview.h b/gtk/gtkcolumnview.h
new file mode 100644
index 0000000000..20327dd063
--- /dev/null
+++ b/gtk/gtkcolumnview.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *
+ * 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/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#ifndef __GTK_COLUMN_VIEW_H__
+#define __GTK_COLUMN_VIEW_H__
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gtk/gtktypes.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_COLUMN_VIEW (gtk_column_view_get_type ())
+#define GTK_COLUMN_VIEW(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_COLUMN_VIEW, GtkColumnView))
+#define GTK_COLUMN_VIEW_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_COLUMN_VIEW,
GtkColumnViewClass))
+#define GTK_IS_COLUMN_VIEW(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_COLUMN_VIEW))
+#define GTK_IS_COLUMN_VIEW_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_COLUMN_VIEW))
+#define GTK_COLUMN_VIEW_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_COLUMN_VIEW,
GtkColumnViewClass))
+
+/**
+ * GtkColumnView:
+ *
+ * GtkColumnView is the simple list implementation for GTK's list widgets.
+ */
+typedef struct _GtkColumnView GtkColumnView;
+typedef struct _GtkColumnViewClass GtkColumnViewClass;
+/* forward declaration */
+typedef struct _GtkColumnViewColumn GtkColumnViewColumn;
+
+GDK_AVAILABLE_IN_ALL
+GType gtk_column_view_get_type (void) G_GNUC_CONST;
+
+GDK_AVAILABLE_IN_ALL
+GtkWidget * gtk_column_view_new (void);
+
+GDK_AVAILABLE_IN_ALL
+GListModel * gtk_column_view_get_columns (GtkColumnView *self);
+GDK_AVAILABLE_IN_ALL
+GListModel * gtk_column_view_get_model (GtkColumnView *self);
+GDK_AVAILABLE_IN_ALL
+void gtk_column_view_set_model (GtkColumnView *self,
+ GListModel *model);
+GDK_AVAILABLE_IN_ALL
+gboolean gtk_column_view_get_show_separators (GtkColumnView *self);
+GDK_AVAILABLE_IN_ALL
+void gtk_column_view_set_show_separators (GtkColumnView *self,
+ gboolean show_Separators);
+
+G_END_DECLS
+
+#endif /* __GTK_COLUMN_VIEW_H__ */
diff --git a/gtk/gtkcolumnviewcolumn.c b/gtk/gtkcolumnviewcolumn.c
new file mode 100644
index 0000000000..c44beecd6b
--- /dev/null
+++ b/gtk/gtkcolumnviewcolumn.c
@@ -0,0 +1,338 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *
+ * 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/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#include "config.h"
+
+#include "gtkcolumnviewcolumn.h"
+
+#include "gtkintl.h"
+#include "gtklistbaseprivate.h"
+#include "gtklistitemmanagerprivate.h"
+#include "gtkmain.h"
+#include "gtkprivate.h"
+#include "gtkrbtreeprivate.h"
+#include "gtkstylecontext.h"
+#include "gtkwidgetprivate.h"
+
+/**
+ * SECTION:gtkcolumnviewcolumn
+ * @title: GtkColumnViewColumn
+ * @short_description: The column added to GtkColumnView
+ * @see_also: #GtkColumnView
+ *
+ * GtkColumnViewColumn represents the columns being added to #GtkColumnView.
+ */
+
+struct _GtkColumnViewColumn
+{
+ GObject parent_instance;
+
+ GtkListItemFactory *factory;
+ char *title;
+
+ /* data for the view */
+ GtkColumnView *view;
+};
+
+struct _GtkColumnViewColumnClass
+{
+ GObjectClass parent_class;
+};
+
+enum
+{
+ PROP_0,
+ PROP_COLUMN_VIEW,
+ PROP_FACTORY,
+ PROP_TITLE,
+
+ N_PROPS
+};
+
+G_DEFINE_TYPE (GtkColumnViewColumn, gtk_column_view_column, G_TYPE_OBJECT)
+
+static GParamSpec *properties[N_PROPS] = { NULL, };
+
+static void
+gtk_column_view_column_dispose (GObject *object)
+{
+ GtkColumnViewColumn *self = GTK_COLUMN_VIEW_COLUMN (object);
+
+ g_assert (self->view == NULL); /* would hold a ref otherwise */
+ g_clear_object (&self->factory);
+ g_clear_pointer (&self->title, g_free);
+
+ G_OBJECT_CLASS (gtk_column_view_column_parent_class)->dispose (object);
+}
+
+static void
+gtk_column_view_column_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkColumnViewColumn *self = GTK_COLUMN_VIEW_COLUMN (object);
+
+ switch (property_id)
+ {
+ case PROP_COLUMN_VIEW:
+ g_value_set_object (value, self->view);
+ break;
+
+ case PROP_FACTORY:
+ g_value_set_object (value, self->factory);
+ break;
+
+ case PROP_TITLE:
+ g_value_set_string (value, self->title);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_column_view_column_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkColumnViewColumn *self = GTK_COLUMN_VIEW_COLUMN (object);
+
+ switch (property_id)
+ {
+ case PROP_FACTORY:
+ gtk_column_view_column_set_factory (self, g_value_get_object (value));
+ break;
+
+ case PROP_TITLE:
+ gtk_column_view_column_set_title (self, g_value_get_string (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_column_view_column_class_init (GtkColumnViewColumnClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->dispose = gtk_column_view_column_dispose;
+ gobject_class->get_property = gtk_column_view_column_get_property;
+ gobject_class->set_property = gtk_column_view_column_set_property;
+
+ /**
+ * GtkColumnViewColumn:column-view:
+ *
+ * #GtkColumnView this column is a part of
+ */
+ properties[PROP_COLUMN_VIEW] =
+ g_param_spec_object ("column-view",
+ P_("Column view"),
+ P_("Column view this column is a part of"),
+ G_TYPE_LIST_MODEL,
+ G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * GtkColumnViewColumn:factory:
+ *
+ * Factory for populating list items
+ */
+ properties[PROP_FACTORY] =
+ g_param_spec_object ("factory",
+ P_("Factory"),
+ P_("Factory for populating list items"),
+ GTK_TYPE_LIST_ITEM_FACTORY,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * GtkColumnViewColumn:title:
+ *
+ * Title displayed in the header
+ */
+ properties[PROP_TITLE] =
+ g_param_spec_string ("title",
+ P_("Title"),
+ P_("Title displayed in the header"),
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
+ g_object_class_install_properties (gobject_class, N_PROPS, properties);
+}
+
+static void
+gtk_column_view_column_init (GtkColumnViewColumn *self)
+{
+}
+
+/**
+ * gtk_column_view_column_new:
+ * @title: (nullable): Title to use for this column
+ *
+ * Creates a new #GtkColumnViewColumn.
+ *
+ * You most likely want to call gtk_column_add_column() next.
+ *
+ * Returns: a new #GtkColumnViewColumn
+ **/
+GtkColumnViewColumn *
+gtk_column_view_column_new (const char *title)
+{
+ return g_object_new (GTK_TYPE_COLUMN_VIEW_COLUMN,
+ "title", title,
+ NULL);
+}
+
+/**
+ * gtk_column_view_column_new_with_factory:
+ * @title: (nullable): Title to use for this column
+ * @factory: (transfer full): The factory to populate items with
+ *
+ * Creates a new #GtkColumnViewColumn that uses the given @factory for
+ * mapping items to widgets.
+ *
+ * You most likely want to call gtk_column_add_column() next.
+ *
+ * The function takes ownership of the
+ * argument, so you can write code like
+ * ```
+ * column = gtk_column_view_column_new_with_factory (_("Name"),
+ * gtk_builder_list_item_factory_new_from_resource ("/name.ui"));
+ * ```
+ *
+ * Returns: a new #GtkColumnViewColumn using the given @factory
+ **/
+GtkColumnViewColumn *
+gtk_column_view_column_new_with_factory (const char *title,
+ GtkListItemFactory *factory)
+{
+ GtkColumnViewColumn *result;
+
+ g_return_val_if_fail (GTK_IS_LIST_ITEM_FACTORY (factory), NULL);
+
+ result = g_object_new (GTK_TYPE_COLUMN_VIEW_COLUMN,
+ "factory", factory,
+ "title", title,
+ NULL);
+
+ g_object_unref (factory);
+
+ return result;
+}
+
+/**
+ * gtk_column_view_column_get_column_view:
+ * @self: a #GtkColumnViewColumn
+ *
+ * Gets the column view that's currently displaying this column.
+ *
+ * If @self has not been added to a column view yet, %NULL is returned.
+ *
+ * Returns: (nullable) (transfer none): The column view displaying @self.
+ **/
+GtkColumnView *
+gtk_column_view_column_get_column_view (GtkColumnViewColumn *self)
+{
+ g_return_val_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self), NULL);
+
+ return self->view;
+}
+
+/**
+ * gtk_column_view_column_get_factory:
+ * @self: a #GtkColumnViewColumn
+ *
+ * Gets the factory that's currently used to populate list items for
+ * this column.
+ *
+ * Returns: (nullable) (transfer none): The factory in use
+ **/
+GtkListItemFactory *
+gtk_column_view_column_get_factory (GtkColumnViewColumn *self)
+{
+ g_return_val_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self), NULL);
+
+ return self->factory;
+}
+
+/**
+ * gtk_column_view_column_set_factory:
+ * @self: a #GtkColumnViewColumn
+ * @factory: (allow-none) (transfer none): the factory to use or %NULL for none
+ *
+ * Sets the #GtkListItemFactory to use for populating list items for this
+ * column.
+ **/
+void
+gtk_column_view_column_set_factory (GtkColumnViewColumn *self,
+ GtkListItemFactory *factory)
+{
+ g_return_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self));
+ g_return_if_fail (factory == NULL || GTK_LIST_ITEM_FACTORY (factory));
+
+ if (!g_set_object (&self->factory, factory))
+ return;
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FACTORY]);
+}
+
+/**
+ * gtk_column_view_column_set_title:
+ * @self: a #GtkColumnViewColumn
+ * @title: (nullable): Title to use for this column
+ *
+ * Sets the title of this column. The title is displayed in the header of a
+ * #GtkColumnView for this column and is therefor user-facing text that should
+ * be translated.
+ */
+void
+gtk_column_view_column_set_title (GtkColumnViewColumn *self,
+ const char *title)
+{
+ g_return_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self));
+
+ if (g_strcmp0 (self->title, title) == 0)
+ return;
+
+ g_free (self->title);
+ self->title = g_strdup (title);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TITLE]);
+}
+
+/**
+ * gtk_column_view_column_get_title:
+ * @self: a #GtkColumnViewColumn
+ *
+ * Returns the title set with gtk_column_view_column_set_title().
+ *
+ * Returns: (nullable) The column's title
+ */
+const char *
+gtk_column_view_column_get_title (GtkColumnViewColumn *self)
+{
+ g_return_val_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self), FALSE);
+
+ return self->title;
+}
diff --git a/gtk/gtkcolumnviewcolumn.h b/gtk/gtkcolumnviewcolumn.h
new file mode 100644
index 0000000000..612cdb1854
--- /dev/null
+++ b/gtk/gtkcolumnviewcolumn.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *
+ * 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/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#ifndef __GTK_COLUMN_VIEW_COLUMN_H__
+#define __GTK_COLUMN_VIEW_COLUMN_H__
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gtk/gtkcolumnview.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_COLUMN_VIEW_COLUMN (gtk_column_view_column_get_type ())
+#define GTK_COLUMN_VIEW_COLUMN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_COLUMN_VIEW_COLUMN,
GtkColumnViewColumn))
+#define GTK_COLUMN_VIEW_COLUMN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_COLUMN_VIEW_COLUMN,
GtkColumnViewColumnClass))
+#define GTK_IS_COLUMN_VIEW_COLUMN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_COLUMN_VIEW_COLUMN))
+#define GTK_IS_COLUMN_VIEW_COLUMN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_COLUMN_VIEW_COLUMN))
+#define GTK_COLUMN_VIEW_COLUMN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_COLUMN_VIEW_COLUMN,
GtkColumnViewColumnClass))
+
+/**
+ * GtkColumnViewColumn:
+ *
+ * GtkColumnViewColumns are added to #GtkColumnViews.
+ */
+typedef struct _GtkColumnViewColumnClass GtkColumnViewColumnClass;
+
+GDK_AVAILABLE_IN_ALL
+GType gtk_column_view_column_get_type (void) G_GNUC_CONST;
+
+GDK_AVAILABLE_IN_ALL
+GtkColumnViewColumn * gtk_column_view_column_new (const char *title);
+GDK_AVAILABLE_IN_ALL
+GtkColumnViewColumn * gtk_column_view_column_new_with_factory (const char *title,
+ GtkListItemFactory *factory);
+
+GDK_AVAILABLE_IN_ALL
+GtkColumnView * gtk_column_view_column_get_column_view (GtkColumnViewColumn *self);
+GDK_AVAILABLE_IN_ALL
+void gtk_column_view_column_set_factory (GtkColumnViewColumn *self,
+ GtkListItemFactory *factory);
+GDK_AVAILABLE_IN_ALL
+GtkListItemFactory * gtk_column_view_column_get_factory (GtkColumnViewColumn *self);
+
+GDK_AVAILABLE_IN_ALL
+void gtk_column_view_column_set_title (GtkColumnViewColumn *self,
+ const char *title);
+GDK_AVAILABLE_IN_ALL
+const char * gtk_column_view_column_get_title (GtkColumnViewColumn *self);
+
+G_END_DECLS
+
+#endif /* __GTK_COLUMN_VIEW_COLUMN_H__ */
diff --git a/gtk/meson.build b/gtk/meson.build
index 937f0fbe7d..4c90a253c1 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -204,6 +204,8 @@ gtk_public_sources = files([
'gtkcolorchooserdialog.c',
'gtkcolorchooserwidget.c',
'gtkcolorutils.c',
+ 'gtkcolumnview.c',
+ 'gtkcolumnviewcolumn.c',
'gtkcombobox.c',
'gtkcomboboxtext.c',
'gtkcomposetable.c',
@@ -481,6 +483,8 @@ gtk_public_headers = files([
'gtkcolorchooserdialog.h',
'gtkcolorchooserwidget.h',
'gtkcolorutils.h',
+ 'gtkcolumnview.h',
+ 'gtkcolumnviewcolumn.h',
'gtkcombobox.h',
'gtkcomboboxtext.h',
'gtkconstraintguide.h',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]