2019-10-30 17:03:23 +00:00
|
|
|
/*
|
|
|
|
* 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 "gtkcolumnlistitemfactoryprivate.h"
|
|
|
|
|
|
|
|
#include "gtkboxlayout.h"
|
|
|
|
#include "gtkcolumnviewcolumnprivate.h"
|
2019-11-07 22:40:47 +00:00
|
|
|
#include "gtkcolumnviewlayoutprivate.h"
|
2019-10-30 17:03:23 +00:00
|
|
|
#include "gtklistitemfactoryprivate.h"
|
|
|
|
#include "gtklistitemprivate.h"
|
|
|
|
|
|
|
|
struct _GtkColumnListItemFactory
|
|
|
|
{
|
|
|
|
GtkListItemFactory parent_instance;
|
|
|
|
|
|
|
|
GtkColumnView *view; /* no reference, the view references us */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkColumnListItemFactoryClass
|
|
|
|
{
|
|
|
|
GtkListItemFactoryClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkColumnListItemFactory, gtk_column_list_item_factory, GTK_TYPE_LIST_ITEM_FACTORY)
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_column_list_item_factory_setup (GtkListItemFactory *factory,
|
2022-06-28 14:34:24 +00:00
|
|
|
GObject *item,
|
|
|
|
gboolean bind,
|
|
|
|
GFunc func,
|
|
|
|
gpointer data)
|
2019-10-30 17:03:23 +00:00
|
|
|
{
|
|
|
|
GtkColumnListItemFactory *self = GTK_COLUMN_LIST_ITEM_FACTORY (factory);
|
2022-06-28 14:34:24 +00:00
|
|
|
GtkListItemWidget *widget = data;
|
2019-10-30 17:03:23 +00:00
|
|
|
GListModel *columns;
|
|
|
|
guint i;
|
|
|
|
|
2019-11-02 05:15:38 +00:00
|
|
|
/* FIXME: evil */
|
|
|
|
gtk_widget_set_layout_manager (GTK_WIDGET (widget),
|
2019-11-07 22:40:47 +00:00
|
|
|
gtk_column_view_layout_new (self->view));
|
2019-10-30 17:03:23 +00:00
|
|
|
|
2022-06-28 14:34:24 +00:00
|
|
|
GTK_LIST_ITEM_FACTORY_CLASS (gtk_column_list_item_factory_parent_class)->setup (factory, item, bind, func, data);
|
2019-10-30 17:03:23 +00:00
|
|
|
|
|
|
|
columns = gtk_column_view_get_columns (self->view);
|
|
|
|
|
|
|
|
for (i = 0; i < g_list_model_get_n_items (columns); i++)
|
|
|
|
{
|
|
|
|
GtkColumnViewColumn *column = g_list_model_get_item (columns, i);
|
|
|
|
|
2022-12-29 18:56:01 +00:00
|
|
|
if (gtk_column_view_column_get_visible (column))
|
|
|
|
gtk_column_list_item_factory_add_column (self,
|
|
|
|
widget,
|
|
|
|
column,
|
|
|
|
FALSE);
|
2020-07-16 12:46:44 +00:00
|
|
|
|
|
|
|
g_object_unref (column);
|
2019-10-30 17:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_column_list_item_factory_teardown (GtkListItemFactory *factory,
|
2022-06-28 14:34:24 +00:00
|
|
|
GObject *item,
|
|
|
|
gboolean unbind,
|
|
|
|
GFunc func,
|
|
|
|
gpointer data)
|
2019-10-30 17:03:23 +00:00
|
|
|
{
|
2022-06-28 14:34:24 +00:00
|
|
|
GtkListItemWidget *widget = data;
|
2019-10-30 17:03:23 +00:00
|
|
|
GtkWidget *child;
|
|
|
|
|
2022-06-28 14:34:24 +00:00
|
|
|
GTK_LIST_ITEM_FACTORY_CLASS (gtk_column_list_item_factory_parent_class)->teardown (factory, item, unbind, func, data);
|
2019-10-30 17:03:23 +00:00
|
|
|
|
2019-11-02 05:15:38 +00:00
|
|
|
while ((child = gtk_widget_get_first_child (GTK_WIDGET (widget))))
|
2019-10-30 17:03:23 +00:00
|
|
|
{
|
2019-11-02 05:15:38 +00:00
|
|
|
gtk_list_item_widget_remove_child (GTK_LIST_ITEM_WIDGET (widget), child);
|
2019-10-30 17:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_column_list_item_factory_update (GtkListItemFactory *factory,
|
2022-06-28 14:34:24 +00:00
|
|
|
GObject *item,
|
|
|
|
gboolean unbind,
|
|
|
|
gboolean bind,
|
|
|
|
GFunc func,
|
|
|
|
gpointer data)
|
2019-10-30 17:03:23 +00:00
|
|
|
{
|
2022-06-28 14:34:24 +00:00
|
|
|
GtkListItem *list_item = GTK_LIST_ITEM (item);
|
2019-10-30 17:03:23 +00:00
|
|
|
GtkWidget *child;
|
|
|
|
|
2022-06-28 14:34:24 +00:00
|
|
|
GTK_LIST_ITEM_FACTORY_CLASS (gtk_column_list_item_factory_parent_class)->update (factory, item, unbind, bind, func, data);
|
2019-10-30 17:03:23 +00:00
|
|
|
|
2022-06-28 14:34:24 +00:00
|
|
|
for (child = gtk_widget_get_first_child (GTK_WIDGET (list_item->owner));
|
2019-10-30 17:03:23 +00:00
|
|
|
child;
|
|
|
|
child = gtk_widget_get_next_sibling (child))
|
|
|
|
{
|
2022-06-28 14:34:24 +00:00
|
|
|
gtk_list_item_widget_update (GTK_LIST_ITEM_WIDGET (child),
|
|
|
|
gtk_list_item_get_position (list_item),
|
|
|
|
gtk_list_item_get_item (list_item),
|
|
|
|
gtk_list_item_get_selected (list_item));
|
2019-10-30 17:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_column_list_item_factory_class_init (GtkColumnListItemFactoryClass *klass)
|
|
|
|
{
|
|
|
|
GtkListItemFactoryClass *factory_class = GTK_LIST_ITEM_FACTORY_CLASS (klass);
|
|
|
|
|
|
|
|
factory_class->setup = gtk_column_list_item_factory_setup;
|
|
|
|
factory_class->teardown = gtk_column_list_item_factory_teardown;
|
|
|
|
factory_class->update = gtk_column_list_item_factory_update;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_column_list_item_factory_init (GtkColumnListItemFactory *self)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkColumnListItemFactory *
|
|
|
|
gtk_column_list_item_factory_new (GtkColumnView *view)
|
|
|
|
{
|
|
|
|
GtkColumnListItemFactory *result;
|
|
|
|
|
|
|
|
result = g_object_new (GTK_TYPE_COLUMN_LIST_ITEM_FACTORY, NULL);
|
|
|
|
|
|
|
|
result->view = view;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_column_list_item_factory_add_column (GtkColumnListItemFactory *factory,
|
|
|
|
GtkListItemWidget *list_item,
|
|
|
|
GtkColumnViewColumn *column,
|
|
|
|
gboolean check_bind)
|
|
|
|
{
|
|
|
|
GtkWidget *cell;
|
|
|
|
|
2019-11-02 05:15:38 +00:00
|
|
|
cell = gtk_column_view_cell_new (column);
|
2019-10-30 17:03:23 +00:00
|
|
|
gtk_list_item_widget_add_child (GTK_LIST_ITEM_WIDGET (list_item), GTK_WIDGET (cell));
|
|
|
|
gtk_list_item_widget_update (GTK_LIST_ITEM_WIDGET (cell),
|
|
|
|
gtk_list_item_widget_get_position (list_item),
|
|
|
|
gtk_list_item_widget_get_item (list_item),
|
|
|
|
gtk_list_item_widget_get_selected (list_item));
|
|
|
|
}
|