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"
|
|
|
|
|
2020-10-15 04:09:06 +00:00
|
|
|
#include "gtklistviewprivate.h"
|
2018-09-16 18:52:06 +00:00
|
|
|
|
2020-06-26 00:56:38 +00:00
|
|
|
#include "gtkbitset.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"
|
2018-09-18 17:58:19 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2020-10-15 03:34:51 +00:00
|
|
|
#include "gtkmultiselection.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
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* GtkListView:
|
2018-09-16 18:52:06 +00:00
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* `GtkListView` presents a large dynamic list of items.
|
2020-06-04 14:05:17 +00:00
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* `GtkListView` uses its factory to generate one row widget for each visible
|
|
|
|
* item and shows them in a linear display, either vertically or horizontally.
|
2020-06-04 19:33:53 +00:00
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* The [property@Gtk.ListView:show-separators] property offers a simple way to
|
|
|
|
* display separators between the rows.
|
|
|
|
*
|
|
|
|
* `GtkListView` allows the user to select items according to the selection
|
2020-09-06 15:19:24 +00:00
|
|
|
* characteristics of the model. For models that allow multiple selected items,
|
|
|
|
* it is possible to turn on _rubberband selection_, using
|
2021-02-28 18:09:48 +00:00
|
|
|
* [property@Gtk.ListView:enable-rubberband].
|
2020-06-04 19:33:53 +00:00
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* If you need multiple columns with headers, see [class@Gtk.ColumnView].
|
2020-06-04 19:33:53 +00:00
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* To learn more about the list widget framework, see the
|
|
|
|
* [overview](section-list-widget.html).
|
2020-06-04 19:33:53 +00:00
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* An example of using `GtkListView`:
|
|
|
|
* ```c
|
2020-06-05 00:11:35 +00:00
|
|
|
* static void
|
|
|
|
* setup_listitem_cb (GtkListItemFactory *factory,
|
|
|
|
* GtkListItem *list_item)
|
|
|
|
* {
|
|
|
|
* GtkWidget *image;
|
|
|
|
*
|
|
|
|
* image = gtk_image_new ();
|
|
|
|
* gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
|
|
|
|
* gtk_list_item_set_child (list_item, image);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* static void
|
|
|
|
* bind_listitem_cb (GtkListItemFactory *factory,
|
|
|
|
* GtkListItem *list_item)
|
|
|
|
* {
|
|
|
|
* GtkWidget *image;
|
|
|
|
* GAppInfo *app_info;
|
|
|
|
*
|
|
|
|
* image = gtk_list_item_get_child (list_item);
|
|
|
|
* app_info = gtk_list_item_get_item (list_item);
|
|
|
|
* gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (app_info));
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* static void
|
|
|
|
* activate_cb (GtkListView *list,
|
|
|
|
* guint position,
|
|
|
|
* gpointer unused)
|
|
|
|
* {
|
|
|
|
* GAppInfo *app_info;
|
|
|
|
*
|
2020-09-06 15:19:24 +00:00
|
|
|
* app_info = g_list_model_get_item (G_LIST_MODEL (gtk_list_view_get_model (list)), position);
|
2020-06-05 00:11:35 +00:00
|
|
|
* g_app_info_launch (app_info, NULL, NULL, NULL);
|
|
|
|
* g_object_unref (app_info);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* ...
|
|
|
|
*
|
2020-07-26 22:27:23 +00:00
|
|
|
* model = create_application_list ();
|
|
|
|
*
|
2020-06-05 00:11:35 +00:00
|
|
|
* factory = gtk_signal_list_item_factory_new ();
|
|
|
|
* g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
|
|
|
|
* g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL);
|
|
|
|
*
|
2020-09-06 15:19:24 +00:00
|
|
|
* list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
|
2020-06-05 00:11:35 +00:00
|
|
|
*
|
|
|
|
* g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);
|
|
|
|
*
|
|
|
|
* gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
|
2021-02-28 18:09:48 +00:00
|
|
|
* ```
|
2020-06-05 00:11:35 +00:00
|
|
|
*
|
2020-06-04 14:05:17 +00:00
|
|
|
* # CSS nodes
|
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* ```
|
2020-08-05 20:41:53 +00:00
|
|
|
* listview[.separators][.rich-list][.navigation-sidebar][.data-table]
|
2021-05-17 13:05:05 +00:00
|
|
|
* ├── row[.activatable]
|
2020-06-04 14:05:17 +00:00
|
|
|
* │
|
2021-05-17 13:05:05 +00:00
|
|
|
* ├── row[.activatable]
|
2020-06-04 14:05:17 +00:00
|
|
|
* │
|
|
|
|
* ┊
|
|
|
|
* ╰── [rubberband]
|
2021-02-28 18:09:48 +00:00
|
|
|
* ```
|
2020-06-04 14:05:17 +00:00
|
|
|
*
|
2021-05-17 13:05:05 +00:00
|
|
|
* `GtkListView` uses a single CSS node named `listview`. It may carry the
|
|
|
|
* `.separators` style class, when [property@Gtk.ListView:show-separators]
|
|
|
|
* property is set. Each child widget uses a single CSS node named `row`.
|
2021-05-20 23:16:59 +00:00
|
|
|
* If the [property@Gtk.ListItem:activatable] property is set, the
|
2021-05-17 13:05:05 +00:00
|
|
|
* corresponding row will have the `.activatable` style class. For
|
|
|
|
* rubberband selection, a node with name `rubberband` is used.
|
2020-08-05 20:41:53 +00:00
|
|
|
*
|
|
|
|
* The main listview node may also carry style classes to select
|
|
|
|
* the style of [list presentation](ListContainers.html#list-styles):
|
|
|
|
* .rich-list, .navigation-sidebar or .data-table.
|
2020-10-21 02:53:30 +00:00
|
|
|
*
|
|
|
|
* # Accessibility
|
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* `GtkListView` uses the %GTK_ACCESSIBLE_ROLE_LIST role, and the list
|
|
|
|
* items use the %GTK_ACCESSIBLE_ROLE_LIST_ITEM role.
|
2018-09-16 18:52:06 +00:00
|
|
|
*/
|
|
|
|
|
2018-09-18 02:56:19 +00:00
|
|
|
typedef struct _ListRow ListRow;
|
|
|
|
typedef struct _ListRowAugment ListRowAugment;
|
|
|
|
|
|
|
|
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,
|
2019-12-23 19:47:19 +00:00
|
|
|
PROP_ENABLE_RUBBERBAND,
|
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;
|
|
|
|
}
|
|
|
|
|
2020-06-26 00:56:38 +00:00
|
|
|
static GtkBitset *
|
|
|
|
gtk_list_view_get_items_in_rect (GtkListBase *base,
|
|
|
|
const cairo_rectangle_int_t *rect)
|
|
|
|
{
|
|
|
|
GtkListView *self = GTK_LIST_VIEW (base);
|
|
|
|
guint first, last, n_items;
|
|
|
|
GtkBitset *result;
|
|
|
|
ListRow *row;
|
|
|
|
|
|
|
|
result = gtk_bitset_new_empty ();
|
|
|
|
|
|
|
|
n_items = gtk_list_base_get_n_items (base);
|
|
|
|
if (n_items == 0)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
row = gtk_list_view_get_row_at_y (self, rect->y, NULL);
|
|
|
|
if (row)
|
|
|
|
first = gtk_list_item_manager_get_item_position (self->item_manager, row);
|
|
|
|
else
|
|
|
|
first = rect->y < 0 ? 0 : n_items - 1;
|
|
|
|
row = gtk_list_view_get_row_at_y (self, rect->y + rect->height, NULL);
|
|
|
|
if (row)
|
|
|
|
last = gtk_list_item_manager_get_item_position (self->item_manager, row);
|
|
|
|
else
|
|
|
|
last = rect->y < 0 ? 0 : n_items - 1;
|
|
|
|
|
|
|
|
gtk_bitset_add_range_closed (result, first, last);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
2020-11-24 13:19:06 +00:00
|
|
|
GtkScrollablePolicy scroll_policy, opposite_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);
|
2020-11-24 13:19:06 +00:00
|
|
|
opposite_scroll_policy = gtk_list_base_get_scroll_policy (GTK_LIST_BASE (self), opposite_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)
|
2022-07-12 19:42:28 +00:00
|
|
|
{
|
|
|
|
gtk_list_base_update_adjustments (GTK_LIST_BASE (self), 0, 0, 0, 0, &x, &y);
|
|
|
|
return;
|
|
|
|
}
|
2018-09-25 23:37:38 +00:00
|
|
|
|
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;
|
2020-11-24 13:19:06 +00:00
|
|
|
if (opposite_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
|
|
|
{
|
2020-06-24 02:49:21 +00:00
|
|
|
gtk_list_base_size_allocate_child (GTK_LIST_BASE (self),
|
2019-10-22 01:21:39 +00:00
|
|
|
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
|
|
|
}
|
2020-06-26 00:55:53 +00:00
|
|
|
|
|
|
|
gtk_list_base_allocate_rubberband (GTK_LIST_BASE (self));
|
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;
|
|
|
|
|
2019-12-23 19:47:19 +00:00
|
|
|
case PROP_ENABLE_RUBBERBAND:
|
|
|
|
g_value_set_boolean (value, gtk_list_base_get_enable_rubberband (GTK_LIST_BASE (self)));
|
|
|
|
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;
|
|
|
|
|
2019-12-23 19:47:19 +00:00
|
|
|
case PROP_ENABLE_RUBBERBAND:
|
|
|
|
gtk_list_view_set_enable_rubberband (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";
|
2020-10-15 03:34:51 +00:00
|
|
|
list_base_class->list_item_role = GTK_ACCESSIBLE_ROLE_LIST_ITEM;
|
2019-10-23 00:34:28 +00:00
|
|
|
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;
|
2020-06-26 00:56:38 +00:00
|
|
|
list_base_class->get_items_in_rect = gtk_list_view_get_items_in_rect;
|
2019-10-25 05:39:57 +00:00
|
|
|
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
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* GtkListView:factory: (attributes org.gtk.Property.get=gtk_list_view_get_factory org.gtk.Property.set=gtk_list_view_set_factory)
|
2019-10-08 22:07:07 +00:00
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* Factory for populating list items.
|
2019-10-08 22:07:07 +00:00
|
|
|
*/
|
|
|
|
properties[PROP_FACTORY] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("factory", NULL, NULL,
|
2019-10-08 22:07:07 +00:00
|
|
|
GTK_TYPE_LIST_ITEM_FACTORY,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* GtkListView:model: (attributes org.gtk.Property.get=gtk_list_view_get_model org.gtk.Property.set=gtk_list_view_set_model)
|
2018-09-16 18:52:06 +00:00
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* Model for the items displayed.
|
2018-09-16 18:52:06 +00:00
|
|
|
*/
|
|
|
|
properties[PROP_MODEL] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("model", NULL, NULL,
|
2020-08-31 21:06:48 +00:00
|
|
|
GTK_TYPE_SELECTION_MODEL,
|
2018-09-16 18:52:06 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
2019-06-04 01:01:15 +00:00
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* GtkListView:show-separators: (attributes org.gtk.Property.get=gtk_list_view_get_show_separators org.gtk.Property.set=gtk_list_view_set_show_separators)
|
2019-06-04 01:01:15 +00:00
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* Show separators between rows.
|
2019-06-04 01:01:15 +00:00
|
|
|
*/
|
|
|
|
properties[PROP_SHOW_SEPARATORS] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boolean ("show-separators", NULL, NULL,
|
2019-06-04 01:01:15 +00:00
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2019-12-14 01:57:57 +00:00
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* GtkListView:single-click-activate: (attributes org.gtk.Property.get=gtk_list_view_get_single_click_activate org.gtk.Property.set=gtk_list_view_set_single_click_activate)
|
2019-12-14 01:57:57 +00:00
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* Activate rows on single click and select them on hover.
|
2019-12-14 01:57:57 +00:00
|
|
|
*/
|
|
|
|
properties[PROP_SINGLE_CLICK_ACTIVATE] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boolean ("single-click-activate", NULL, NULL,
|
2019-12-14 01:57:57 +00:00
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2019-12-23 19:47:19 +00:00
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* GtkListView:enable-rubberband: (attributes org.gtk.Property.get=gtk_list_view_get_enable_rubberband org.gtk.Property.set=gtk_list_view_set_enable_rubberband)
|
2019-12-23 19:47:19 +00:00
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* Allow rubberband selection.
|
2019-12-23 19:47:19 +00:00
|
|
|
*/
|
|
|
|
properties[PROP_ENABLE_RUBBERBAND] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boolean ("enable-rubberband", NULL, NULL,
|
2019-12-23 19:47:19 +00:00
|
|
|
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:
|
2021-02-28 18:09:48 +00:00
|
|
|
* @self: The `GtkListView`
|
2019-10-15 21:06:36 +00:00
|
|
|
* @position: position of item to activate
|
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* Emitted when a row has been activated by the user,
|
2019-10-15 21:06:36 +00:00
|
|
|
* usually via activating the GtkListView|list.activate-item action.
|
|
|
|
*
|
|
|
|
* This allows for a convenient way to handle activation in a listview.
|
2021-02-28 18:09:48 +00:00
|
|
|
* See [method@Gtk.ListItem.set_activatable] for details on how to use
|
|
|
|
* this signal.
|
2019-10-15 21:06:36 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* Activates the item given in @position by emitting the
|
|
|
|
* [signal@Gtk.ListView::activate] signal.
|
2019-10-15 21:06:36 +00:00
|
|
|
*/
|
|
|
|
gtk_widget_class_install_action (widget_class,
|
|
|
|
"list.activate-item",
|
|
|
|
"u",
|
|
|
|
gtk_list_view_activate_item);
|
|
|
|
|
2020-06-04 12:42:55 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("listview"));
|
2020-10-15 03:34:51 +00:00
|
|
|
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_LIST);
|
2018-09-16 18:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2020-06-26 04:37:57 +00:00
|
|
|
|
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (self), "view");
|
2018-09-16 18:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_list_view_new:
|
2021-05-21 00:45:06 +00:00
|
|
|
* @model: (nullable) (transfer full): the model to use
|
|
|
|
* @factory: (nullable) (transfer full): The factory to populate items with
|
2019-10-08 22:07:07 +00:00
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* Creates a new `GtkListView` that uses the given @factory for
|
2019-10-08 22:07:07 +00:00
|
|
|
* mapping items to widgets.
|
|
|
|
*
|
|
|
|
* The function takes ownership of the
|
2020-09-01 16:24:06 +00:00
|
|
|
* arguments, so you can write code like
|
2021-02-28 18:09:48 +00:00
|
|
|
* ```c
|
|
|
|
* list_view = gtk_list_view_new (create_model (),
|
|
|
|
* gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
|
2019-10-08 22:07:07 +00:00
|
|
|
* ```
|
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* Returns: a new `GtkListView` using the given @model and @factory
|
|
|
|
*/
|
2019-10-08 22:07:07 +00:00
|
|
|
GtkWidget *
|
2020-09-01 16:24:06 +00:00
|
|
|
gtk_list_view_new (GtkSelectionModel *model,
|
|
|
|
GtkListItemFactory *factory)
|
2019-10-08 22:07:07 +00:00
|
|
|
{
|
|
|
|
GtkWidget *result;
|
|
|
|
|
2020-08-31 21:06:48 +00:00
|
|
|
g_return_val_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model), NULL);
|
2020-07-26 22:27:23 +00:00
|
|
|
g_return_val_if_fail (factory == NULL || GTK_IS_LIST_ITEM_FACTORY (factory), NULL);
|
2019-10-08 22:07:07 +00:00
|
|
|
|
|
|
|
result = g_object_new (GTK_TYPE_LIST_VIEW,
|
2020-07-26 22:27:23 +00:00
|
|
|
"model", model,
|
2019-10-08 22:07:07 +00:00
|
|
|
"factory", factory,
|
|
|
|
NULL);
|
|
|
|
|
2020-07-26 22:27:23 +00:00
|
|
|
/* consume the references */
|
|
|
|
g_clear_object (&model);
|
|
|
|
g_clear_object (&factory);
|
2019-10-08 22:07:07 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* gtk_list_view_get_model: (attributes org.gtk.Method.get_property=model)
|
|
|
|
* @self: a `GtkListView`
|
2018-09-16 18:52:06 +00:00
|
|
|
*
|
|
|
|
* Gets the model that's currently used to read the items displayed.
|
|
|
|
*
|
|
|
|
* Returns: (nullable) (transfer none): The model in use
|
2021-02-28 18:09:48 +00:00
|
|
|
*/
|
2020-08-31 21:06:48 +00:00
|
|
|
GtkSelectionModel *
|
2018-09-16 18:52:06 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* gtk_list_view_set_model: (attributes org.gtk.Method.set_property=model)
|
|
|
|
* @self: a `GtkListView`
|
2021-05-21 00:45:06 +00:00
|
|
|
* @model: (nullable) (transfer none): the model to use
|
2018-10-03 16:53:06 +00:00
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* Sets the model to use.
|
|
|
|
*
|
|
|
|
* This must be a [iface@Gtk.SelectionModel] to use.
|
|
|
|
*/
|
2018-09-16 18:52:06 +00:00
|
|
|
void
|
2020-08-31 21:06:48 +00:00
|
|
|
gtk_list_view_set_model (GtkListView *self,
|
|
|
|
GtkSelectionModel *model)
|
2018-09-16 18:52:06 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_LIST_VIEW (self));
|
2020-08-31 21:06:48 +00:00
|
|
|
g_return_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model));
|
2018-09-16 18:52:06 +00:00
|
|
|
|
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;
|
|
|
|
|
2020-10-15 03:34:51 +00:00
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (self),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_MULTI_SELECTABLE, GTK_IS_MULTI_SELECTION (model),
|
|
|
|
-1);
|
|
|
|
|
2018-09-16 18:52:06 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
|
|
|
|
}
|
|
|
|
|
2019-10-08 22:07:07 +00:00
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* gtk_list_view_get_factory: (attributes org.gtk.Method.get_property=factory)
|
|
|
|
* @self: a `GtkListView`
|
2019-10-08 22:07:07 +00:00
|
|
|
*
|
|
|
|
* Gets the factory that's currently used to populate list items.
|
|
|
|
*
|
|
|
|
* Returns: (nullable) (transfer none): The factory in use
|
2021-02-28 18:09:48 +00:00
|
|
|
*/
|
2019-10-08 22:07:07 +00:00
|
|
|
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
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* gtk_list_view_set_factory: (attributes org.gtk.Method.set_property=factory)
|
|
|
|
* @self: a `GtkListView`
|
2021-05-21 00:45:06 +00:00
|
|
|
* @factory: (nullable) (transfer none): the factory to use
|
2019-10-08 22:07:07 +00:00
|
|
|
*
|
2021-02-28 18:09:48 +00:00
|
|
|
* 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));
|
2022-02-26 02:04:53 +00:00
|
|
|
g_return_if_fail (factory == NULL || GTK_IS_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
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* gtk_list_view_set_show_separators: (attributes org.gtk.Method.set_property=show-separators)
|
|
|
|
* @self: a `GtkListView`
|
2019-06-04 01:01:15 +00:00
|
|
|
* @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)
|
2020-06-03 21:36:52 +00:00
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (self), "separators");
|
2019-06-04 01:01:15 +00:00
|
|
|
else
|
2020-06-03 21:36:52 +00:00
|
|
|
gtk_widget_remove_css_class (GTK_WIDGET (self), "separators");
|
2019-06-04 01:01:15 +00:00
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_SEPARATORS]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* gtk_list_view_get_show_separators: (attributes org.gtk.Method.get_property=show-separators)
|
|
|
|
* @self: a `GtkListView`
|
2019-06-04 01:01:15 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* gtk_list_view_set_single_click_activate: (attributes org.gtk.Method.set_property=single-click-activate)
|
|
|
|
* @self: a `GtkListView`
|
2019-12-14 01:57:57 +00:00
|
|
|
* @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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* gtk_list_view_get_single_click_activate: (attributes org.gtk.Method.set_property=single-click-activate)
|
|
|
|
* @self: a `GtkListView`
|
2019-12-14 01:57:57 +00:00
|
|
|
*
|
|
|
|
* 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);
|
|
|
|
}
|
2019-12-23 19:47:19 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* gtk_list_view_set_enable_rubberband: (attributes org.gtk.Method.set_property=enable-rubberband)
|
|
|
|
* @self: a `GtkListView`
|
2019-12-23 19:47:19 +00:00
|
|
|
* @enable_rubberband: %TRUE to enable rubberband selection
|
|
|
|
*
|
|
|
|
* Sets whether selections can be changed by dragging with the mouse.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_list_view_set_enable_rubberband (GtkListView *self,
|
|
|
|
gboolean enable_rubberband)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_LIST_VIEW (self));
|
|
|
|
|
|
|
|
if (enable_rubberband == gtk_list_base_get_enable_rubberband (GTK_LIST_BASE (self)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_list_base_set_enable_rubberband (GTK_LIST_BASE (self), enable_rubberband);
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ENABLE_RUBBERBAND]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-28 18:09:48 +00:00
|
|
|
* gtk_list_view_get_enable_rubberband: (attributes org.gtk.Method.get_property=enable-rubberband)
|
|
|
|
* @self: a `GtkListView`
|
2019-12-23 19:47:19 +00:00
|
|
|
*
|
|
|
|
* Returns whether rows can be selected by dragging with the mouse.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if rubberband selection is enabled
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_list_view_get_enable_rubberband (GtkListView *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_VIEW (self), FALSE);
|
|
|
|
|
|
|
|
return gtk_list_base_get_enable_rubberband (GTK_LIST_BASE (self));
|
|
|
|
}
|