Merge branch 'wip/otte/for-master' into 'master'

Wip/otte/for master

See merge request GNOME/gtk!2064
This commit is contained in:
Benjamin Otte 2020-06-08 18:43:31 +00:00
commit bd2f2a6f65
7 changed files with 50 additions and 34 deletions

View File

@ -1389,10 +1389,9 @@ gtk_list_base_stop_rubberband (GtkListBase *self)
}
else
{
if (!priv->rubberband->extend)
gtk_selection_model_unselect_all (model);
gtk_selection_model_select_callback (model, range_cb, priv->rubberband->active);
gtk_selection_model_select_callback (model,
!priv->rubberband->extend,
range_cb, priv->rubberband->active);
}
g_clear_pointer (&priv->rubberband, rubberband_data_free);

View File

@ -395,7 +395,6 @@ gtk_list_item_manager_add_items (GtkListItemManager *self,
if (item == NULL || item->widget)
item = gtk_rb_tree_insert_before (self->items, item);
item->n_items += n_items;
gtk_rb_tree_node_mark_dirty (item);
@ -570,12 +569,6 @@ gtk_list_item_manager_ensure_items (GtkListItemManager *self,
gtk_list_item_manager_release_list_item (self, NULL, widget);
}
static void
gtk_list_item_manager_model_selection_changed_cb (GListModel *model,
guint position,
guint n_items,
GtkListItemManager *self);
static void
gtk_list_item_manager_model_items_changed_cb (GListModel *model,
guint position,
@ -742,8 +735,6 @@ gtk_list_item_manager_model_items_changed_cb (GListModel *model,
g_hash_table_unref (change);
gtk_list_item_manager_model_selection_changed_cb (model, position, added, self);
gtk_widget_queue_resize (self->widget);
}
@ -988,7 +979,7 @@ gtk_list_item_manager_try_reacquire_list_item (GtkListItemManager *self,
gtk_list_item_widget_update (list_item,
position,
gtk_list_item_widget_get_item (list_item),
gtk_list_item_widget_get_selected (list_item));
gtk_selection_model_is_selected (self->model, position));
gtk_widget_insert_after (result, self->widget, prev_sibling);
/* XXX: Should we let the listview do this? */
gtk_widget_queue_resize (result);

View File

@ -175,6 +175,7 @@ gtk_multi_selection_unselect_all (GtkSelectionModel *model)
static gboolean
gtk_multi_selection_add_or_remove (GtkSelectionModel *model,
gboolean unselect_rest,
gboolean add,
GtkSelectionCallback callback,
gpointer data)
@ -190,6 +191,13 @@ gtk_multi_selection_add_or_remove (GtkSelectionModel *model,
min = G_MAXUINT;
max = 0;
if (unselect_rest)
{
min = gtk_set_get_min (self->selected);
max = gtk_set_get_max (self->selected);
gtk_set_remove_all (self->selected);
}
for (pos = 0; pos < n; pos = start + n_items)
{
callback (pos, &start, &n_items, &in, data);
@ -223,10 +231,11 @@ gtk_multi_selection_add_or_remove (GtkSelectionModel *model,
static gboolean
gtk_multi_selection_select_callback (GtkSelectionModel *model,
gboolean unselect_rest,
GtkSelectionCallback callback,
gpointer data)
{
return gtk_multi_selection_add_or_remove (model, TRUE, callback, data);
return gtk_multi_selection_add_or_remove (model, unselect_rest, TRUE, callback, data);
}
static gboolean
@ -234,7 +243,7 @@ gtk_multi_selection_unselect_callback (GtkSelectionModel *model,
GtkSelectionCallback callback,
gpointer data)
{
return gtk_multi_selection_add_or_remove (model, FALSE, callback, data);
return gtk_multi_selection_add_or_remove (model, FALSE, FALSE, callback, data);
}
static void

View File

@ -210,16 +210,24 @@ gtk_property_selection_unselect_all (GtkSelectionModel *model)
static gboolean
gtk_property_selection_add_or_remove (GtkSelectionModel *model,
gboolean unselect_rest,
gboolean add,
GtkSelectionCallback callback,
gpointer data)
{
GtkPropertySelection *self = GTK_PROPERTY_SELECTION (model);
guint pos, start, n;
guint pos, start, n, n_items;
gboolean in;
guint min, max;
guint i;
n_items = g_list_model_get_n_items (G_LIST_MODEL (self));
if (unselect_rest)
{
for (i = 0; i < n_items; i++)
set_selected (self, i, FALSE);
}
min = G_MAXUINT;
max = 0;
@ -241,7 +249,10 @@ gtk_property_selection_add_or_remove (GtkSelectionModel *model,
}
while (n > 0);
if (min <= max)
/* FIXME: do better here */
if (unselect_rest)
gtk_selection_model_selection_changed (model, 0, n_items);
else if (min <= max)
gtk_selection_model_selection_changed (model, min, max - min + 1);
return TRUE;
@ -249,10 +260,11 @@ gtk_property_selection_add_or_remove (GtkSelectionModel *model,
static gboolean
gtk_property_selection_select_callback (GtkSelectionModel *model,
gboolean unselect_rest,
GtkSelectionCallback callback,
gpointer data)
{
return gtk_property_selection_add_or_remove (model, TRUE, callback, data);
return gtk_property_selection_add_or_remove (model, unselect_rest, TRUE, callback, data);
}
static gboolean
@ -260,7 +272,7 @@ gtk_property_selection_unselect_callback (GtkSelectionModel *model,
GtkSelectionCallback callback,
gpointer data)
{
return gtk_property_selection_add_or_remove (model, FALSE, callback, data);
return gtk_property_selection_add_or_remove (model, FALSE, FALSE, callback, data);
}
static void

View File

@ -85,7 +85,7 @@ gtk_selection_model_default_is_selected (GtkSelectionModel *model,
static gboolean
gtk_selection_model_default_select_item (GtkSelectionModel *model,
guint position,
gboolean exclusive)
gboolean unselect_rest)
{
return FALSE;
}
@ -100,7 +100,7 @@ static gboolean
gtk_selection_model_default_select_range (GtkSelectionModel *model,
guint position,
guint n_items,
gboolean exclusive)
gboolean unselect_rest)
{
return FALSE;
}
@ -115,6 +115,7 @@ gtk_selection_model_default_unselect_range (GtkSelectionModel *model,
static gboolean
gtk_selection_model_default_select_callback (GtkSelectionModel *model,
gboolean unselect_rest,
GtkSelectionCallback callback,
gpointer data)
{
@ -228,21 +229,21 @@ gtk_selection_model_is_selected (GtkSelectionModel *model,
* gtk_selection_model_select_item:
* @model: a #GtkSelectionModel
* @position: the position of the item to select
* @exclusive: whether previously selected items should be unselected
* @unselect_rest: whether previously selected items should be unselected
*
* Requests to select an item in the model.
*/
gboolean
gtk_selection_model_select_item (GtkSelectionModel *model,
guint position,
gboolean exclusive)
gboolean unselect_rest)
{
GtkSelectionModelInterface *iface;
g_return_val_if_fail (GTK_IS_SELECTION_MODEL (model), 0);
iface = GTK_SELECTION_MODEL_GET_IFACE (model);
return iface->select_item (model, position, exclusive);
return iface->select_item (model, position, unselect_rest);
}
/**
@ -269,7 +270,7 @@ gtk_selection_model_unselect_item (GtkSelectionModel *model,
* @model: a #GtkSelectionModel
* @position: the first item to select
* @n_items: the number of items to select
* @exclusive: whether previously selected items should be unselected
* @unselect_rest: whether previously selected items should be unselected
*
* Requests to select a range of items in the model.
*/
@ -277,14 +278,14 @@ gboolean
gtk_selection_model_select_range (GtkSelectionModel *model,
guint position,
guint n_items,
gboolean exclusive)
gboolean unselect_rest)
{
GtkSelectionModelInterface *iface;
g_return_val_if_fail (GTK_IS_SELECTION_MODEL (model), 0);
iface = GTK_SELECTION_MODEL_GET_IFACE (model);
return iface->select_range (model, position, n_items, exclusive);
return iface->select_range (model, position, n_items, unselect_rest);
}
/**
@ -345,6 +346,7 @@ gtk_selection_model_unselect_all (GtkSelectionModel *model)
/**
* gtk_selection_model_select_callback:
* @model: a #GtkSelectionModel
* @unselect_rest: whether previously selected items should be unselected
* @callback: (scope call): a #GtkSelectionCallback to determine items to select
* @data: data to pass to @callback
*
@ -353,12 +355,13 @@ gtk_selection_model_unselect_all (GtkSelectionModel *model)
*/
gboolean
gtk_selection_model_select_callback (GtkSelectionModel *model,
gboolean unselect_rest,
GtkSelectionCallback callback,
gpointer data)
{
g_return_val_if_fail (GTK_IS_SELECTION_MODEL (model), FALSE);
return GTK_SELECTION_MODEL_GET_IFACE (model)->select_callback (model, callback, data);
return GTK_SELECTION_MODEL_GET_IFACE (model)->select_callback (model, unselect_rest, callback, data);
}
/**

View File

@ -97,19 +97,20 @@ struct _GtkSelectionModelInterface
gboolean (* select_item) (GtkSelectionModel *model,
guint position,
gboolean exclusive);
gboolean unselect_rest);
gboolean (* unselect_item) (GtkSelectionModel *model,
guint position);
gboolean (* select_range) (GtkSelectionModel *model,
guint position,
guint n_items,
gboolean exclusive);
gboolean unselect_rest);
gboolean (* unselect_range) (GtkSelectionModel *model,
guint position,
guint n_items);
gboolean (* select_all) (GtkSelectionModel *model);
gboolean (* unselect_all) (GtkSelectionModel *model);
gboolean (* select_callback) (GtkSelectionModel *model,
gboolean unselect_rest,
GtkSelectionCallback callback,
gpointer data);
gboolean (* unselect_callback) (GtkSelectionModel *model,
@ -129,7 +130,7 @@ gboolean gtk_selection_model_is_selected (GtkSelectionMod
GDK_AVAILABLE_IN_ALL
gboolean gtk_selection_model_select_item (GtkSelectionModel *model,
guint position,
gboolean exclusive);
gboolean unselect_rest);
GDK_AVAILABLE_IN_ALL
gboolean gtk_selection_model_unselect_item (GtkSelectionModel *model,
guint position);
@ -137,7 +138,7 @@ GDK_AVAILABLE_IN_ALL
gboolean gtk_selection_model_select_range (GtkSelectionModel *model,
guint position,
guint n_items,
gboolean exclusive);
gboolean unselect_rest);
GDK_AVAILABLE_IN_ALL
gboolean gtk_selection_model_unselect_range (GtkSelectionModel *model,
guint position,
@ -149,6 +150,7 @@ gboolean gtk_selection_model_unselect_all (GtkSelectionMod
GDK_AVAILABLE_IN_ALL
gboolean gtk_selection_model_select_callback (GtkSelectionModel *model,
gboolean unselect_rest,
GtkSelectionCallback callback,
gpointer data);
GDK_AVAILABLE_IN_ALL

View File

@ -496,7 +496,7 @@ test_callback (void)
assert_selection (selection, "");
assert_selection_changes (selection, "");
ret = gtk_selection_model_select_callback (selection, select_some, data);
ret = gtk_selection_model_select_callback (selection, FALSE, select_some, data);
g_assert_true (ret);
assert_selection (selection, "3 4 5 7 8 9");
assert_selection_changes (selection, "2:7");