2018-09-16 18:52:06 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2018 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 "gtklistview.h"
|
|
|
|
|
2019-06-10 02:58:45 +00:00
|
|
|
#include "gtkintl.h"
|
2019-10-22 06:01:16 +00:00
|
|
|
#include "gtklistbaseprivate.h"
|
2018-09-20 03:18:34 +00:00
|
|
|
#include "gtklistitemmanagerprivate.h"
|
2019-10-15 21:45:33 +00:00
|
|
|
#include "gtkmain.h"
|
2019-10-06 03:46:50 +00:00
|
|
|
#include "gtkprivate.h"
|
2019-06-10 01:43:52 +00:00
|
|
|
#include "gtkrbtreeprivate.h"
|
2019-06-04 01:01:15 +00:00
|
|
|
#include "gtkstylecontext.h"
|
2018-09-18 17:58:19 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2018-09-16 18:52:06 +00:00
|
|
|
|
2018-09-25 23:37:38 +00:00
|
|
|
/* Maximum number of list items created by the listview.
|
|
|
|
* For debugging, you can set this to G_MAXUINT to ensure
|
|
|
|
* there's always a list item for every row.
|
|
|
|
*/
|
|
|
|
#define GTK_LIST_VIEW_MAX_LIST_ITEMS 200
|
|
|
|
|
2019-02-27 07:45:28 +00:00
|
|
|
/* Extra items to keep above + below every tracker */
|
|
|
|
#define GTK_LIST_VIEW_EXTRA_ITEMS 2
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtklistview
|
|
|
|
* @title: GtkListView
|
|
|
|
* @short_description: A widget for displaying lists
|
|
|
|
* @see_also: #GListModel
|
|
|
|
*
|
|
|
|
* GtkListView is a widget to present a view into a large dynamic list of items.
|
|
|
|
*/
|
|
|
|
|
2018-09-18 02:56:19 +00:00
|
|
|
typedef struct _ListRow ListRow;
|
|
|
|
typedef struct _ListRowAugment ListRowAugment;
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
struct _GtkListView
|
|
|
|
{
|
2019-10-22 06:01:16 +00:00
|
|
|
GtkListBase parent_instance;
|
2018-09-16 18:52:06 +00:00
|
|
|
|
2018-09-20 03:18:34 +00:00
|
|
|
GtkListItemManager *item_manager;
|
2019-06-04 01:01:15 +00:00
|
|
|
gboolean show_separators;
|
2018-09-18 02:56:19 +00:00
|
|
|
|
2018-09-18 17:58:19 +00:00
|
|
|
int list_width;
|
2018-09-18 02:56:19 +00:00
|
|
|
};
|
|
|
|
|
2019-10-22 06:01:16 +00:00
|
|
|
struct _GtkListViewClass
|
|
|
|
{
|
|
|
|
GtkListBaseClass parent_class;
|
|
|
|
};
|
|
|
|
|
2018-09-18 02:56:19 +00:00
|
|
|
struct _ListRow
|
|
|
|
{
|
2019-02-06 19:48:08 +00:00
|
|
|
GtkListItemManagerItem parent;
|
2018-09-25 23:37:38 +00:00
|
|
|
guint height; /* per row */
|
2018-09-18 02:56:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _ListRowAugment
|
|
|
|
{
|
2019-02-06 19:48:08 +00:00
|
|
|
GtkListItemManagerItemAugment parent;
|
2018-09-25 23:37:38 +00:00
|
|
|
guint height; /* total */
|
2018-09-16 18:52:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2019-10-08 22:07:07 +00:00
|
|
|
PROP_FACTORY,
|
2018-09-16 18:52:06 +00:00
|
|
|
PROP_MODEL,
|
2019-06-04 01:01:15 +00:00
|
|
|
PROP_SHOW_SEPARATORS,
|
2019-12-14 01:57:57 +00:00
|
|
|
PROP_SINGLE_CLICK_ACTIVATE,
|
2018-09-16 18:52:06 +00:00
|
|
|
|
|
|
|
N_PROPS
|
|
|
|
};
|
|
|
|
|
2019-10-15 21:06:36 +00:00
|
|
|
enum {
|
|
|
|
ACTIVATE,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2019-10-24 00:07:37 +00:00
|
|
|
G_DEFINE_TYPE (GtkListView, gtk_list_view, GTK_TYPE_LIST_BASE)
|
2018-09-16 18:52:06 +00:00
|
|
|
|
|
|
|
static GParamSpec *properties[N_PROPS] = { NULL, };
|
2019-10-15 21:06:36 +00:00
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
2018-09-16 18:52:06 +00:00
|
|
|
|
2018-09-25 23:37:38 +00:00
|
|
|
static void G_GNUC_UNUSED
|
|
|
|
dump (GtkListView *self)
|
|
|
|
{
|
|
|
|
ListRow *row;
|
|
|
|
guint n_widgets, n_list_rows;
|
|
|
|
|
|
|
|
n_widgets = 0;
|
|
|
|
n_list_rows = 0;
|
2019-02-06 19:48:08 +00:00
|
|
|
//g_print ("ANCHOR: %u - %u\n", self->anchor_start, self->anchor_end);
|
|
|
|
for (row = gtk_list_item_manager_get_first (self->item_manager);
|
2018-09-25 23:37:38 +00:00
|
|
|
row;
|
|
|
|
row = gtk_rb_tree_node_get_next (row))
|
|
|
|
{
|
2019-02-06 19:48:08 +00:00
|
|
|
if (row->parent.widget)
|
2018-09-25 23:37:38 +00:00
|
|
|
n_widgets++;
|
|
|
|
n_list_rows++;
|
2019-02-06 19:48:08 +00:00
|
|
|
g_print (" %4u%s (%upx)\n", row->parent.n_items, row->parent.widget ? " (widget)" : "", row->height);
|
2018-09-25 23:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_print (" => %u widgets in %u list rows\n", n_widgets, n_list_rows);
|
|
|
|
}
|
|
|
|
|
2018-09-18 02:56:19 +00:00
|
|
|
static void
|
|
|
|
list_row_augment (GtkRbTree *tree,
|
|
|
|
gpointer node_augment,
|
|
|
|
gpointer node,
|
|
|
|
gpointer left,
|
|
|
|
gpointer right)
|
2018-09-16 18:52:06 +00:00
|
|
|
{
|
2018-09-18 02:56:19 +00:00
|
|
|
ListRow *row = node;
|
|
|
|
ListRowAugment *aug = node_augment;
|
|
|
|
|
2019-02-06 19:48:08 +00:00
|
|
|
gtk_list_item_manager_augment_node (tree, node_augment, node, left, right);
|
|
|
|
|
|
|
|
aug->height = row->height * row->parent.n_items;
|
2018-09-18 02:56:19 +00:00
|
|
|
|
|
|
|
if (left)
|
|
|
|
{
|
|
|
|
ListRowAugment *left_aug = gtk_rb_tree_get_augment (tree, left);
|
|
|
|
|
|
|
|
aug->height += left_aug->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (right)
|
|
|
|
{
|
|
|
|
ListRowAugment *right_aug = gtk_rb_tree_get_augment (tree, right);
|
|
|
|
|
|
|
|
aug->height += right_aug->height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-19 05:08:30 +00:00
|
|
|
static ListRow *
|
|
|
|
gtk_list_view_get_row_at_y (GtkListView *self,
|
|
|
|
int y,
|
|
|
|
int *offset)
|
|
|
|
{
|
|
|
|
ListRow *row, *tmp;
|
|
|
|
|
2019-02-06 19:48:08 +00:00
|
|
|
row = gtk_list_item_manager_get_root (self->item_manager);
|
2018-09-19 05:08:30 +00:00
|
|
|
|
|
|
|
while (row)
|
|
|
|
{
|
|
|
|
tmp = gtk_rb_tree_node_get_left (row);
|
|
|
|
if (tmp)
|
|
|
|
{
|
2019-02-06 19:48:08 +00:00
|
|
|
ListRowAugment *aug = gtk_list_item_manager_get_item_augment (self->item_manager, tmp);
|
2018-09-19 05:08:30 +00:00
|
|
|
if (y < aug->height)
|
|
|
|
{
|
|
|
|
row = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
y -= aug->height;
|
|
|
|
}
|
|
|
|
|
2019-02-06 19:48:08 +00:00
|
|
|
if (y < row->height * row->parent.n_items)
|
2018-09-19 05:08:30 +00:00
|
|
|
break;
|
2019-02-06 19:48:08 +00:00
|
|
|
y -= row->height * row->parent.n_items;
|
2018-09-19 05:08:30 +00:00
|
|
|
|
|
|
|
row = gtk_rb_tree_node_get_right (row);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset)
|
|
|
|
*offset = row ? y : 0;
|
|
|
|
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
list_row_get_y (GtkListView *self,
|
|
|
|
ListRow *row)
|
|
|
|
{
|
2018-09-25 23:37:38 +00:00
|
|
|
ListRow *parent, *left;
|
|
|
|
int y;
|
|
|
|
|
|
|
|
left = gtk_rb_tree_node_get_left (row);
|
|
|
|
if (left)
|
|
|
|
{
|
2019-02-06 19:48:08 +00:00
|
|
|
ListRowAugment *aug = gtk_list_item_manager_get_item_augment (self->item_manager, left);
|
2018-09-25 23:37:38 +00:00
|
|
|
y = aug->height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
y = 0;
|
2018-09-19 05:08:30 +00:00
|
|
|
|
|
|
|
for (parent = gtk_rb_tree_node_get_parent (row);
|
|
|
|
parent != NULL;
|
|
|
|
parent = gtk_rb_tree_node_get_parent (row))
|
|
|
|
{
|
2018-09-25 23:37:38 +00:00
|
|
|
left = gtk_rb_tree_node_get_left (parent);
|
2018-09-19 05:08:30 +00:00
|
|
|
|
|
|
|
if (left != row)
|
|
|
|
{
|
|
|
|
if (left)
|
|
|
|
{
|
2019-02-06 19:48:08 +00:00
|
|
|
ListRowAugment *aug = gtk_list_item_manager_get_item_augment (self->item_manager, left);
|
2018-09-19 05:08:30 +00:00
|
|
|
y += aug->height;
|
|
|
|
}
|
2019-02-06 19:48:08 +00:00
|
|
|
y += parent->height * parent->parent.n_items;
|
2018-09-19 05:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
row = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return y ;
|
|
|
|
}
|
|
|
|
|
2018-09-18 17:58:19 +00:00
|
|
|
static int
|
|
|
|
gtk_list_view_get_list_height (GtkListView *self)
|
|
|
|
{
|
|
|
|
ListRow *row;
|
|
|
|
ListRowAugment *aug;
|
2019-10-26 06:49:27 +00:00
|
|
|
|
2019-02-06 19:48:08 +00:00
|
|
|
row = gtk_list_item_manager_get_root (self->item_manager);
|
2018-09-18 17:58:19 +00:00
|
|
|
if (row == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2019-02-06 19:48:08 +00:00
|
|
|
aug = gtk_list_item_manager_get_item_augment (self->item_manager, row);
|
2018-09-18 17:58:19 +00:00
|
|
|
return aug->height;
|
|
|
|
}
|
|
|
|
|
2019-10-25 05:39:57 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_list_view_get_allocation_along (GtkListBase *base,
|
|
|
|
guint pos,
|
|
|
|
int *offset,
|
|
|
|
int *size)
|
|
|
|
{
|
|
|
|
GtkListView *self = GTK_LIST_VIEW (base);
|
|
|
|
ListRow *row;
|
|
|
|
guint skip;
|
|
|
|
int y;
|
|
|
|
|
|
|
|
row = gtk_list_item_manager_get_nth (self->item_manager, pos, &skip);
|
|
|
|
if (row == NULL)
|
|
|
|
{
|
|
|
|
if (offset)
|
|
|
|
*offset = 0;
|
|
|
|
if (size)
|
|
|
|
*size = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
y = list_row_get_y (self, row);
|
|
|
|
y += skip * row->height;
|
|
|
|
|
|
|
|
if (offset)
|
|
|
|
*offset = y;
|
|
|
|
if (size)
|
|
|
|
*size = row->height;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_list_view_get_allocation_across (GtkListBase *base,
|
|
|
|
guint pos,
|
|
|
|
int *offset,
|
|
|
|
int *size)
|
|
|
|
{
|
|
|
|
GtkListView *self = GTK_LIST_VIEW (base);
|
|
|
|
|
|
|
|
if (offset)
|
|
|
|
*offset = 0;
|
|
|
|
if (size)
|
|
|
|
*size = self->list_width;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-10-24 04:49:38 +00:00
|
|
|
static guint
|
|
|
|
gtk_list_view_move_focus_along (GtkListBase *base,
|
|
|
|
guint pos,
|
|
|
|
int steps)
|
|
|
|
{
|
|
|
|
if (steps < 0)
|
|
|
|
return pos - MIN (pos, -steps);
|
|
|
|
else
|
|
|
|
{
|
2019-10-26 06:49:27 +00:00
|
|
|
pos += MIN (gtk_list_base_get_n_items (base) - pos - 1, steps);
|
2019-10-24 04:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2019-10-25 05:39:57 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_list_view_get_position_from_allocation (GtkListBase *base,
|
|
|
|
int across,
|
|
|
|
int along,
|
|
|
|
guint *pos,
|
|
|
|
cairo_rectangle_int_t *area)
|
|
|
|
{
|
|
|
|
GtkListView *self = GTK_LIST_VIEW (base);
|
|
|
|
ListRow *row;
|
|
|
|
int remaining;
|
|
|
|
|
|
|
|
if (across >= self->list_width)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
row = gtk_list_view_get_row_at_y (self, along, &remaining);
|
|
|
|
if (row == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*pos = gtk_list_item_manager_get_item_position (self->item_manager, row);
|
|
|
|
g_assert (remaining < row->height * row->parent.n_items);
|
|
|
|
*pos += remaining / row->height;
|
|
|
|
|
|
|
|
if (area)
|
|
|
|
{
|
|
|
|
area->x = 0;
|
|
|
|
area->width = self->list_width;
|
|
|
|
area->y = along - remaining % row->height;
|
|
|
|
area->height = row->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-10-24 04:49:38 +00:00
|
|
|
static guint
|
|
|
|
gtk_list_view_move_focus_across (GtkListBase *base,
|
|
|
|
guint pos,
|
|
|
|
int steps)
|
|
|
|
{
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2018-09-25 23:37:38 +00:00
|
|
|
static int
|
|
|
|
compare_ints (gconstpointer first,
|
|
|
|
gconstpointer second)
|
|
|
|
{
|
|
|
|
return *(int *) first - *(int *) second;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
gtk_list_view_get_unknown_row_height (GtkListView *self,
|
|
|
|
GArray *heights)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (heights->len > 0, 0);
|
|
|
|
|
|
|
|
/* return the median and hope rows are generally uniform with few outliers */
|
|
|
|
g_array_sort (heights, compare_ints);
|
|
|
|
|
|
|
|
return g_array_index (heights, int, heights->len / 2);
|
|
|
|
}
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
static void
|
2018-09-25 23:37:38 +00:00
|
|
|
gtk_list_view_measure_across (GtkWidget *widget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
int for_size,
|
|
|
|
int *minimum,
|
|
|
|
int *natural)
|
2018-09-16 18:52:06 +00:00
|
|
|
{
|
|
|
|
GtkListView *self = GTK_LIST_VIEW (widget);
|
2018-09-18 02:56:19 +00:00
|
|
|
ListRow *row;
|
|
|
|
int min, nat, child_min, child_nat;
|
|
|
|
/* XXX: Figure out how to split a given height into per-row heights.
|
|
|
|
* Good luck! */
|
2018-09-25 23:37:38 +00:00
|
|
|
for_size = -1;
|
2018-09-16 18:52:06 +00:00
|
|
|
|
2018-09-18 02:56:19 +00:00
|
|
|
min = 0;
|
|
|
|
nat = 0;
|
|
|
|
|
2019-02-06 19:48:08 +00:00
|
|
|
for (row = gtk_list_item_manager_get_first (self->item_manager);
|
2018-09-18 02:56:19 +00:00
|
|
|
row != NULL;
|
|
|
|
row = gtk_rb_tree_node_get_next (row))
|
2018-09-16 18:52:06 +00:00
|
|
|
{
|
2018-09-25 23:37:38 +00:00
|
|
|
/* ignore unavailable rows */
|
2019-02-06 19:48:08 +00:00
|
|
|
if (row->parent.widget == NULL)
|
2018-09-25 23:37:38 +00:00
|
|
|
continue;
|
|
|
|
|
2019-02-06 19:48:08 +00:00
|
|
|
gtk_widget_measure (row->parent.widget,
|
2018-09-18 02:56:19 +00:00
|
|
|
orientation, for_size,
|
|
|
|
&child_min, &child_nat, NULL, NULL);
|
2018-09-25 23:37:38 +00:00
|
|
|
min = MAX (min, child_min);
|
|
|
|
nat = MAX (nat, child_nat);
|
|
|
|
}
|
|
|
|
|
|
|
|
*minimum = min;
|
|
|
|
*natural = nat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_list_view_measure_list (GtkWidget *widget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
int for_size,
|
|
|
|
int *minimum,
|
|
|
|
int *natural)
|
|
|
|
{
|
|
|
|
GtkListView *self = GTK_LIST_VIEW (widget);
|
|
|
|
ListRow *row;
|
|
|
|
int min, nat, child_min, child_nat;
|
|
|
|
GArray *min_heights, *nat_heights;
|
|
|
|
guint n_unknown;
|
|
|
|
|
|
|
|
min_heights = g_array_new (FALSE, FALSE, sizeof (int));
|
|
|
|
nat_heights = g_array_new (FALSE, FALSE, sizeof (int));
|
|
|
|
n_unknown = 0;
|
|
|
|
min = 0;
|
|
|
|
nat = 0;
|
|
|
|
|
2019-02-06 19:48:08 +00:00
|
|
|
for (row = gtk_list_item_manager_get_first (self->item_manager);
|
2018-09-25 23:37:38 +00:00
|
|
|
row != NULL;
|
|
|
|
row = gtk_rb_tree_node_get_next (row))
|
|
|
|
{
|
2019-02-06 19:48:08 +00:00
|
|
|
if (row->parent.widget)
|
2018-09-18 02:56:19 +00:00
|
|
|
{
|
2019-02-06 19:48:08 +00:00
|
|
|
gtk_widget_measure (row->parent.widget,
|
2018-09-25 23:37:38 +00:00
|
|
|
orientation, for_size,
|
|
|
|
&child_min, &child_nat, NULL, NULL);
|
|
|
|
g_array_append_val (min_heights, child_min);
|
|
|
|
g_array_append_val (nat_heights, child_nat);
|
|
|
|
min += child_min;
|
|
|
|
nat += child_nat;
|
2018-09-18 02:56:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-06 19:48:08 +00:00
|
|
|
n_unknown += row->parent.n_items;
|
2018-09-18 02:56:19 +00:00
|
|
|
}
|
2018-09-16 18:52:06 +00:00
|
|
|
}
|
|
|
|
|
2018-09-25 23:37:38 +00:00
|
|
|
if (n_unknown)
|
|
|
|
{
|
|
|
|
min += n_unknown * gtk_list_view_get_unknown_row_height (self, min_heights);
|
|
|
|
nat += n_unknown * gtk_list_view_get_unknown_row_height (self, nat_heights);
|
|
|
|
}
|
|
|
|
g_array_free (min_heights, TRUE);
|
|
|
|
g_array_free (nat_heights, TRUE);
|
|
|
|
|
2018-09-18 02:56:19 +00:00
|
|
|
*minimum = min;
|
|
|
|
*natural = nat;
|
2018-09-16 18:52:06 +00:00
|
|
|
}
|
|
|
|
|
2018-09-25 23:37:38 +00:00
|
|
|
static void
|
|
|
|
gtk_list_view_measure (GtkWidget *widget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
int for_size,
|
|
|
|
int *minimum,
|
|
|
|
int *natural,
|
|
|
|
int *minimum_baseline,
|
|
|
|
int *natural_baseline)
|
|
|
|
{
|
2019-10-06 03:46:50 +00:00
|
|
|
GtkListView *self = GTK_LIST_VIEW (widget);
|
|
|
|
|
2019-10-24 00:07:37 +00:00
|
|
|
if (orientation == gtk_list_base_get_orientation (GTK_LIST_BASE (self)))
|
2018-09-25 23:37:38 +00:00
|
|
|
gtk_list_view_measure_list (widget, orientation, for_size, minimum, natural);
|
2019-10-06 03:46:50 +00:00
|
|
|
else
|
|
|
|
gtk_list_view_measure_across (widget, orientation, for_size, minimum, natural);
|
2018-09-25 23:37:38 +00:00
|
|
|
}
|
|
|
|
|
2019-10-22 01:21:39 +00:00
|
|
|
static void
|
|
|
|
gtk_list_view_size_allocate_child (GtkListView *self,
|
|
|
|
GtkWidget *child,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
|
|
|
GtkAllocation child_allocation;
|
|
|
|
|
2019-10-24 00:07:37 +00:00
|
|
|
if (gtk_list_base_get_orientation (GTK_LIST_BASE (self)) == GTK_ORIENTATION_VERTICAL)
|
2019-10-22 01:21:39 +00:00
|
|
|
{
|
|
|
|
child_allocation.x = x;
|
|
|
|
child_allocation.y = y;
|
|
|
|
child_allocation.width = width;
|
|
|
|
child_allocation.height = height;
|
|
|
|
}
|
|
|
|
else if (_gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_LTR)
|
|
|
|
{
|
|
|
|
child_allocation.x = y;
|
|
|
|
child_allocation.y = x;
|
|
|
|
child_allocation.width = height;
|
|
|
|
child_allocation.height = width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int mirror_point = gtk_widget_get_width (GTK_WIDGET (self));
|
|
|
|
|
|
|
|
child_allocation.x = mirror_point - y - height;
|
|
|
|
child_allocation.y = x;
|
|
|
|
child_allocation.width = height;
|
|
|
|
child_allocation.height = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_size_allocate (child, &child_allocation, -1);
|
|
|
|
}
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
static void
|
|
|
|
gtk_list_view_size_allocate (GtkWidget *widget,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int baseline)
|
|
|
|
{
|
2018-09-18 02:56:19 +00:00
|
|
|
GtkListView *self = GTK_LIST_VIEW (widget);
|
|
|
|
ListRow *row;
|
2018-09-25 23:37:38 +00:00
|
|
|
GArray *heights;
|
2018-09-18 17:58:19 +00:00
|
|
|
int min, nat, row_height;
|
2019-10-22 01:21:39 +00:00
|
|
|
int x, y;
|
2019-10-24 00:07:37 +00:00
|
|
|
GtkOrientation orientation, opposite_orientation;
|
2019-10-22 21:46:34 +00:00
|
|
|
GtkScrollablePolicy scroll_policy;
|
2019-10-06 03:46:50 +00:00
|
|
|
|
2019-10-24 00:07:37 +00:00
|
|
|
orientation = gtk_list_base_get_orientation (GTK_LIST_BASE (self));
|
|
|
|
opposite_orientation = OPPOSITE_ORIENTATION (orientation);
|
|
|
|
scroll_policy = gtk_list_base_get_scroll_policy (GTK_LIST_BASE (self), orientation);
|
2018-09-18 17:58:19 +00:00
|
|
|
|
2018-09-25 23:37:38 +00:00
|
|
|
/* step 0: exit early if list is empty */
|
2019-02-06 19:48:08 +00:00
|
|
|
if (gtk_list_item_manager_get_root (self->item_manager) == NULL)
|
2018-09-25 23:37:38 +00:00
|
|
|
return;
|
|
|
|
|
2018-09-18 17:58:19 +00:00
|
|
|
/* step 1: determine width of the list */
|
2019-10-06 03:46:50 +00:00
|
|
|
gtk_widget_measure (widget, opposite_orientation,
|
2018-09-18 17:58:19 +00:00
|
|
|
-1,
|
|
|
|
&min, &nat, NULL, NULL);
|
2019-10-24 00:07:37 +00:00
|
|
|
self->list_width = orientation == GTK_ORIENTATION_VERTICAL ? width : height;
|
2019-10-22 21:46:34 +00:00
|
|
|
if (scroll_policy == GTK_SCROLL_MINIMUM)
|
2019-10-06 03:46:50 +00:00
|
|
|
self->list_width = MAX (min, self->list_width);
|
2018-09-18 17:58:19 +00:00
|
|
|
else
|
2019-10-06 03:46:50 +00:00
|
|
|
self->list_width = MAX (nat, self->list_width);
|
2018-09-18 17:58:19 +00:00
|
|
|
|
2018-09-25 23:37:38 +00:00
|
|
|
/* step 2: determine height of known list items */
|
|
|
|
heights = g_array_new (FALSE, FALSE, sizeof (int));
|
|
|
|
|
2019-02-06 19:48:08 +00:00
|
|
|
for (row = gtk_list_item_manager_get_first (self->item_manager);
|
2018-09-18 02:56:19 +00:00
|
|
|
row != NULL;
|
|
|
|
row = gtk_rb_tree_node_get_next (row))
|
|
|
|
{
|
2019-02-06 19:48:08 +00:00
|
|
|
if (row->parent.widget == NULL)
|
2018-09-25 23:37:38 +00:00
|
|
|
continue;
|
|
|
|
|
2019-10-24 00:07:37 +00:00
|
|
|
gtk_widget_measure (row->parent.widget, orientation,
|
2018-09-18 17:58:19 +00:00
|
|
|
self->list_width,
|
|
|
|
&min, &nat, NULL, NULL);
|
2019-10-22 21:46:34 +00:00
|
|
|
if (scroll_policy == GTK_SCROLL_MINIMUM)
|
2018-09-18 17:58:19 +00:00
|
|
|
row_height = min;
|
|
|
|
else
|
|
|
|
row_height = nat;
|
|
|
|
if (row->height != row_height)
|
2018-09-18 02:56:19 +00:00
|
|
|
{
|
2018-09-18 17:58:19 +00:00
|
|
|
row->height = row_height;
|
2018-09-18 02:56:19 +00:00
|
|
|
gtk_rb_tree_node_mark_dirty (row);
|
|
|
|
}
|
2018-09-25 23:37:38 +00:00
|
|
|
g_array_append_val (heights, row_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* step 3: determine height of unknown items */
|
|
|
|
row_height = gtk_list_view_get_unknown_row_height (self, heights);
|
|
|
|
g_array_free (heights, TRUE);
|
|
|
|
|
2019-02-06 19:48:08 +00:00
|
|
|
for (row = gtk_list_item_manager_get_first (self->item_manager);
|
2018-09-25 23:37:38 +00:00
|
|
|
row != NULL;
|
|
|
|
row = gtk_rb_tree_node_get_next (row))
|
|
|
|
{
|
2019-02-06 19:48:08 +00:00
|
|
|
if (row->parent.widget)
|
2018-09-25 23:37:38 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (row->height != row_height)
|
|
|
|
{
|
|
|
|
row->height = row_height;
|
|
|
|
gtk_rb_tree_node_mark_dirty (row);
|
|
|
|
}
|
2018-09-18 17:58:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* step 3: update the adjustments */
|
2019-10-26 06:49:27 +00:00
|
|
|
gtk_list_base_update_adjustments (GTK_LIST_BASE (self),
|
|
|
|
self->list_width,
|
|
|
|
gtk_list_view_get_list_height (self),
|
|
|
|
gtk_widget_get_size (widget, opposite_orientation),
|
|
|
|
gtk_widget_get_size (widget, orientation),
|
|
|
|
&x, &y);
|
|
|
|
x = -x;
|
|
|
|
y = -y;
|
2018-09-18 17:58:19 +00:00
|
|
|
|
|
|
|
/* step 4: actually allocate the widgets */
|
2019-10-06 03:46:50 +00:00
|
|
|
|
2019-10-22 01:21:39 +00:00
|
|
|
for (row = gtk_list_item_manager_get_first (self->item_manager);
|
|
|
|
row != NULL;
|
|
|
|
row = gtk_rb_tree_node_get_next (row))
|
2019-10-06 03:46:50 +00:00
|
|
|
{
|
2019-10-22 01:21:39 +00:00
|
|
|
if (row->parent.widget)
|
2019-10-06 03:46:50 +00:00
|
|
|
{
|
2019-10-22 01:21:39 +00:00
|
|
|
gtk_list_view_size_allocate_child (self,
|
|
|
|
row->parent.widget,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
self->list_width,
|
|
|
|
row->height);
|
2019-10-06 03:46:50 +00:00
|
|
|
}
|
2019-10-22 01:21:39 +00:00
|
|
|
|
|
|
|
y += row->height * row->parent.n_items;
|
2018-09-18 02:56:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
static void
|
|
|
|
gtk_list_view_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkListView *self = GTK_LIST_VIEW (object);
|
|
|
|
|
2019-10-23 00:34:28 +00:00
|
|
|
self->item_manager = NULL;
|
2018-09-17 05:29:50 +00:00
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
G_OBJECT_CLASS (gtk_list_view_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_list_view_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkListView *self = GTK_LIST_VIEW (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2019-10-08 22:07:07 +00:00
|
|
|
case PROP_FACTORY:
|
|
|
|
g_value_set_object (value, gtk_list_item_manager_get_factory (self->item_manager));
|
|
|
|
break;
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
case PROP_MODEL:
|
2019-10-26 06:49:27 +00:00
|
|
|
g_value_set_object (value, gtk_list_base_get_model (GTK_LIST_BASE (self)));
|
2018-09-16 18:52:06 +00:00
|
|
|
break;
|
|
|
|
|
2019-06-04 01:01:15 +00:00
|
|
|
case PROP_SHOW_SEPARATORS:
|
|
|
|
g_value_set_boolean (value, self->show_separators);
|
|
|
|
break;
|
|
|
|
|
2019-12-14 01:57:57 +00:00
|
|
|
case PROP_SINGLE_CLICK_ACTIVATE:
|
|
|
|
g_value_set_boolean (value, gtk_list_item_manager_get_single_click_activate (self->item_manager));
|
|
|
|
break;
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_list_view_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkListView *self = GTK_LIST_VIEW (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2019-10-08 22:07:07 +00:00
|
|
|
case PROP_FACTORY:
|
|
|
|
gtk_list_view_set_factory (self, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
case PROP_MODEL:
|
|
|
|
gtk_list_view_set_model (self, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
2019-06-04 01:01:15 +00:00
|
|
|
case PROP_SHOW_SEPARATORS:
|
|
|
|
gtk_list_view_set_show_separators (self, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2019-12-14 01:57:57 +00:00
|
|
|
case PROP_SINGLE_CLICK_ACTIVATE:
|
|
|
|
gtk_list_view_set_single_click_activate (self, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-15 21:06:36 +00:00
|
|
|
static void
|
|
|
|
gtk_list_view_activate_item (GtkWidget *widget,
|
|
|
|
const char *action_name,
|
|
|
|
GVariant *parameter)
|
|
|
|
{
|
|
|
|
GtkListView *self = GTK_LIST_VIEW (widget);
|
|
|
|
guint pos;
|
|
|
|
|
|
|
|
if (!g_variant_check_format_string (parameter, "u", FALSE))
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_variant_get (parameter, "u", &pos);
|
2019-10-26 06:49:27 +00:00
|
|
|
if (pos >= gtk_list_base_get_n_items (GTK_LIST_BASE (self)))
|
2019-10-15 21:06:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
g_signal_emit (widget, signals[ACTIVATE], 0, pos);
|
|
|
|
}
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
static void
|
|
|
|
gtk_list_view_class_init (GtkListViewClass *klass)
|
|
|
|
{
|
2019-10-22 21:46:34 +00:00
|
|
|
GtkListBaseClass *list_base_class = GTK_LIST_BASE_CLASS (klass);
|
2018-09-16 18:52:06 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2019-10-22 21:46:34 +00:00
|
|
|
|
2019-10-23 00:34:28 +00:00
|
|
|
list_base_class->list_item_name = "row";
|
|
|
|
list_base_class->list_item_size = sizeof (ListRow);
|
|
|
|
list_base_class->list_item_augment_size = sizeof (ListRowAugment);
|
|
|
|
list_base_class->list_item_augment_func = list_row_augment;
|
2019-10-25 05:39:57 +00:00
|
|
|
list_base_class->get_allocation_along = gtk_list_view_get_allocation_along;
|
|
|
|
list_base_class->get_allocation_across = gtk_list_view_get_allocation_across;
|
|
|
|
list_base_class->get_position_from_allocation = gtk_list_view_get_position_from_allocation;
|
2019-10-24 04:49:38 +00:00
|
|
|
list_base_class->move_focus_along = gtk_list_view_move_focus_along;
|
|
|
|
list_base_class->move_focus_across = gtk_list_view_move_focus_across;
|
2018-09-16 18:52:06 +00:00
|
|
|
|
|
|
|
widget_class->measure = gtk_list_view_measure;
|
|
|
|
widget_class->size_allocate = gtk_list_view_size_allocate;
|
|
|
|
|
|
|
|
gobject_class->dispose = gtk_list_view_dispose;
|
|
|
|
gobject_class->get_property = gtk_list_view_get_property;
|
|
|
|
gobject_class->set_property = gtk_list_view_set_property;
|
|
|
|
|
2019-10-08 22:07:07 +00:00
|
|
|
/**
|
|
|
|
* GtkListView: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);
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
/**
|
|
|
|
* GtkListView: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);
|
|
|
|
|
2019-06-04 01:01:15 +00:00
|
|
|
/**
|
|
|
|
* GtkListView: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);
|
|
|
|
|
2019-12-14 01:57:57 +00:00
|
|
|
/**
|
|
|
|
* GtkListView:single-click-activate:
|
|
|
|
*
|
|
|
|
* Activate rows on single click and select them on hover
|
|
|
|
*/
|
|
|
|
properties[PROP_SINGLE_CLICK_ACTIVATE] =
|
|
|
|
g_param_spec_boolean ("single-click-activate",
|
|
|
|
P_("Single click activate"),
|
|
|
|
P_("Activate rows on single click"),
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
g_object_class_install_properties (gobject_class, N_PROPS, properties);
|
|
|
|
|
2019-10-15 21:06:36 +00:00
|
|
|
/**
|
|
|
|
* GtkListView::activate:
|
|
|
|
* @self: The #GtkListView
|
|
|
|
* @position: position of item to activate
|
|
|
|
*
|
|
|
|
* The ::activate signal is emitted when a row has been activated by the user,
|
|
|
|
* usually via activating the GtkListView|list.activate-item action.
|
|
|
|
*
|
|
|
|
* This allows for a convenient way to handle activation in a listview.
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkListView|list.activate-item:
|
|
|
|
* @position: position of item to activate
|
|
|
|
*
|
|
|
|
* Activates the item given in @position by emitting the GtkListView::activate
|
|
|
|
* signal.
|
|
|
|
*/
|
|
|
|
gtk_widget_class_install_action (widget_class,
|
|
|
|
"list.activate-item",
|
|
|
|
"u",
|
|
|
|
gtk_list_view_activate_item);
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("list"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_list_view_init (GtkListView *self)
|
|
|
|
{
|
2019-10-23 00:34:28 +00:00
|
|
|
self->item_manager = gtk_list_base_get_manager (GTK_LIST_BASE (self));
|
2019-10-26 06:49:27 +00:00
|
|
|
|
|
|
|
gtk_list_base_set_anchor_max_widgets (GTK_LIST_BASE (self),
|
|
|
|
GTK_LIST_VIEW_MAX_LIST_ITEMS,
|
|
|
|
GTK_LIST_VIEW_EXTRA_ITEMS);
|
2018-09-16 18:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_list_view_new:
|
|
|
|
*
|
|
|
|
* Creates a new empty #GtkListView.
|
|
|
|
*
|
2019-10-08 22:07:07 +00:00
|
|
|
* You most likely want to call gtk_list_view_set_factory() to
|
|
|
|
* set up a way to map its items to widgets and gtk_list_view_set_model()
|
|
|
|
* to set a model to provide items next.
|
2018-09-16 18:52:06 +00:00
|
|
|
*
|
|
|
|
* Returns: a new #GtkListView
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_list_view_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_LIST_VIEW, NULL);
|
|
|
|
}
|
|
|
|
|
2019-10-08 22:07:07 +00:00
|
|
|
/**
|
|
|
|
* gtk_list_view_new_with_factory:
|
|
|
|
* @factory: (transfer full): The factory to populate items with
|
|
|
|
*
|
|
|
|
* Creates a new #GtkListView that uses the given @factory for
|
|
|
|
* mapping items to widgets.
|
|
|
|
*
|
|
|
|
* You most likely want to call gtk_list_view_set_model() to set
|
|
|
|
* a model next.
|
|
|
|
*
|
|
|
|
* The function takes ownership of the
|
|
|
|
* argument, so you can write code like
|
|
|
|
* ```
|
|
|
|
* list_view = gtk_list_view_new_with_factory (
|
|
|
|
* gtk_builder_list_item_factory_newfrom_resource ("/resource.ui"));
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Returns: a new #GtkListView using the given @factory
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_list_view_new_with_factory (GtkListItemFactory *factory)
|
|
|
|
{
|
|
|
|
GtkWidget *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_ITEM_FACTORY (factory), NULL);
|
|
|
|
|
|
|
|
result = g_object_new (GTK_TYPE_LIST_VIEW,
|
|
|
|
"factory", factory,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_object_unref (factory);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
/**
|
|
|
|
* gtk_list_view_get_model:
|
|
|
|
* @self: a #GtkListView
|
|
|
|
*
|
|
|
|
* Gets the model that's currently used to read the items displayed.
|
|
|
|
*
|
|
|
|
* Returns: (nullable) (transfer none): The model in use
|
|
|
|
**/
|
|
|
|
GListModel *
|
|
|
|
gtk_list_view_get_model (GtkListView *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_VIEW (self), NULL);
|
|
|
|
|
2019-10-26 06:49:27 +00:00
|
|
|
return gtk_list_base_get_model (GTK_LIST_BASE (self));
|
2018-09-16 18:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_list_view_set_model:
|
|
|
|
* @self: a #GtkListView
|
2018-10-03 16:53:06 +00:00
|
|
|
* @model: (allow-none) (transfer none): the model to use or %NULL for none
|
|
|
|
*
|
|
|
|
* Sets the #GListModel to use.
|
2018-09-16 18:52:06 +00:00
|
|
|
*
|
2018-10-03 16:53:06 +00:00
|
|
|
* If the @model is a #GtkSelectionModel, it is used for managing the selection.
|
|
|
|
* Otherwise, @self creates a #GtkSingleSelection for the selection.
|
2018-09-16 18:52:06 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_list_view_set_model (GtkListView *self,
|
|
|
|
GListModel *model)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_LIST_VIEW (self));
|
|
|
|
g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
|
|
|
|
|
2019-10-26 06:49:27 +00:00
|
|
|
if (!gtk_list_base_set_model (GTK_LIST_BASE (self), model))
|
2018-09-16 18:52:06 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
|
|
|
|
}
|
|
|
|
|
2019-10-08 22:07:07 +00:00
|
|
|
/**
|
|
|
|
* gtk_list_view_get_factory:
|
|
|
|
* @self: a #GtkListView
|
|
|
|
*
|
|
|
|
* Gets the factory that's currently used to populate list items.
|
|
|
|
*
|
|
|
|
* Returns: (nullable) (transfer none): The factory in use
|
|
|
|
**/
|
|
|
|
GtkListItemFactory *
|
|
|
|
gtk_list_view_get_factory (GtkListView *self)
|
2018-09-17 05:29:50 +00:00
|
|
|
{
|
2019-10-08 22:07:07 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_LIST_VIEW (self), NULL);
|
2018-09-17 05:29:50 +00:00
|
|
|
|
2019-10-08 22:07:07 +00:00
|
|
|
return gtk_list_item_manager_get_factory (self->item_manager);
|
2018-09-17 05:29:50 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 22:07:07 +00:00
|
|
|
/**
|
|
|
|
* gtk_list_view_set_factory:
|
|
|
|
* @self: a #GtkListView
|
|
|
|
* @factory: (allow-none) (transfer none): the factory to use or %NULL for none
|
|
|
|
*
|
|
|
|
* Sets the #GtkListItemFactory to use for populating list items.
|
|
|
|
**/
|
2019-06-10 02:58:45 +00:00
|
|
|
void
|
2019-10-08 22:07:07 +00:00
|
|
|
gtk_list_view_set_factory (GtkListView *self,
|
|
|
|
GtkListItemFactory *factory)
|
2019-06-10 02:58:45 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_LIST_VIEW (self));
|
2019-10-08 22:07:07 +00:00
|
|
|
g_return_if_fail (factory == NULL || GTK_LIST_ITEM_FACTORY (factory));
|
2019-06-10 02:58:45 +00:00
|
|
|
|
2019-10-08 22:07:07 +00:00
|
|
|
if (factory == gtk_list_item_manager_get_factory (self->item_manager))
|
|
|
|
return;
|
2019-06-10 02:58:45 +00:00
|
|
|
|
|
|
|
gtk_list_item_manager_set_factory (self->item_manager, factory);
|
2019-10-08 22:07:07 +00:00
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FACTORY]);
|
2019-06-10 02:58:45 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 01:01:15 +00:00
|
|
|
/**
|
|
|
|
* gtk_list_view_set_show_separators:
|
|
|
|
* @self: a #GtkListView
|
|
|
|
* @show_separators: %TRUE to show separators
|
|
|
|
*
|
|
|
|
* Sets whether the list box should show separators
|
|
|
|
* between rows.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_list_view_set_show_separators (GtkListView *self,
|
|
|
|
gboolean show_separators)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_LIST_VIEW (self));
|
|
|
|
|
|
|
|
if (self->show_separators == show_separators)
|
|
|
|
return;
|
|
|
|
|
|
|
|
self->show_separators = show_separators;
|
|
|
|
|
|
|
|
if (show_separators)
|
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)), "separators");
|
|
|
|
else
|
|
|
|
gtk_style_context_remove_class (gtk_widget_get_style_context (GTK_WIDGET (self)), "separators");
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_SEPARATORS]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_list_view_get_show_separators:
|
|
|
|
* @self: a #GtkListView
|
|
|
|
*
|
|
|
|
* Returns whether the list box should show separators
|
|
|
|
* between rows.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the list box shows separators
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_list_view_get_show_separators (GtkListView *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_VIEW (self), FALSE);
|
|
|
|
|
|
|
|
return self->show_separators;
|
|
|
|
}
|
2019-12-14 01:57:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_list_view_set_single_click_activate:
|
|
|
|
* @self: a #GtkListView
|
|
|
|
* @single_click_activate: %TRUE to activate items on single click
|
|
|
|
*
|
|
|
|
* Sets whether rows should be activated on single click and
|
|
|
|
* selected on hover.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_list_view_set_single_click_activate (GtkListView *self,
|
|
|
|
gboolean single_click_activate)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_LIST_VIEW (self));
|
|
|
|
|
|
|
|
if (single_click_activate == gtk_list_item_manager_get_single_click_activate (self->item_manager))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_list_item_manager_set_single_click_activate (self->item_manager, single_click_activate);
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SINGLE_CLICK_ACTIVATE]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_list_view_get_single_click_activate:
|
|
|
|
* @self: a #GtkListView
|
|
|
|
*
|
|
|
|
* Returns whether rows will be activated on single click and
|
|
|
|
* selected on hover.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if rows are activated on single click
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_list_view_get_single_click_activate (GtkListView *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_VIEW (self), FALSE);
|
|
|
|
|
|
|
|
return gtk_list_item_manager_get_single_click_activate (self->item_manager);
|
|
|
|
}
|