[gtk/stack-fixes: 13/13] Fix problems with the no-selection state
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/stack-fixes: 13/13] Fix problems with the no-selection state
- Date: Sat, 9 Feb 2019 01:41:31 +0000 (UTC)
commit 4df08533a09fc0de58bdd2ea4dd4b92e3fb054a3
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Feb 8 19:01:11 2019 -0500
Fix problems with the no-selection state
It turns out that GtkSingleSelection will sometimes have
a selected value of 0, even when there is no child at that
position (because the model is empty). Therefore, comparing
the selected value to GTK_INVALID_LIST_POSITION is not
sufficient. Use n_items <= selected instead.
gtk/gtkstack.c | 8 ++++----
gtk/gtkstackswitcher.c | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
index f6e69f6fb0..cd2148a4a8 100644
--- a/gtk/gtkstack.c
+++ b/gtk/gtkstack.c
@@ -2249,15 +2249,15 @@ transform_from (GBinding *binding,
guint selected;
selected = g_value_get_uint (from_value);
- if (selected == GTK_INVALID_LIST_POSITION)
- g_value_set_object (to_value, NULL);
- else
+ if (selected < g_list_model_get_n_items (G_LIST_MODEL (priv->pages)))
{
GtkWidget *child;
child = g_list_model_get_item (G_LIST_MODEL (priv->pages), selected);
g_value_set_object (to_value, child);
+ return TRUE;
}
- return TRUE;
+ else
+ return FALSE;
}
/**
diff --git a/gtk/gtkstackswitcher.c b/gtk/gtkstackswitcher.c
index c626f65d6f..e25850bf59 100644
--- a/gtk/gtkstackswitcher.c
+++ b/gtk/gtkstackswitcher.c
@@ -362,7 +362,7 @@ populate_switcher (GtkStackSwitcher *self)
}
selected = gtk_single_selection_get_selected (GTK_SINGLE_SELECTION (priv->pages));
- if (selected != GTK_INVALID_LIST_POSITION)
+ if (selected < g_list_model_get_n_items (G_LIST_MODEL (priv->pages)))
{
widget = g_list_model_get_item (G_LIST_MODEL (priv->pages), selected);
button = g_hash_table_lookup (priv->buttons, widget);
@@ -418,7 +418,7 @@ selection_changed_cb (GtkSelectionModel *model,
GtkWidget *button;
selected = gtk_single_selection_get_selected (GTK_SINGLE_SELECTION (model));
- if (selected == GTK_INVALID_LIST_POSITION)
+ if (g_list_model_get_n_items (G_LIST_MODEL (model)) <= selected)
return;
child = g_list_model_get_item (G_LIST_MODEL (model), selected);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]