[gtk] stack: Don't emit bad ::selection-changed signals



commit 8c0b70691bedbfa5de3951cde2d60d4749cb59ee
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Feb 13 09:01:07 2019 -0500

    stack: Don't emit bad ::selection-changed signals
    
    We have to be careful to not pass bad numbers to
    this signal, which was happening in cases where
    we have on old or new selected item.

 gtk/gtkstack.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
index ba80e9faf3..7a23d471f3 100644
--- a/gtk/gtkstack.c
+++ b/gtk/gtkstack.c
@@ -1114,8 +1114,8 @@ set_visible_child (GtkStack               *stack,
   GtkWidget *toplevel;
   GtkWidget *focus;
   gboolean contains_focus = FALSE;
-  guint old_pos = 0;
-  guint new_pos = 0;
+  guint old_pos = GTK_INVALID_LIST_POSITION;
+  guint new_pos = GTK_INVALID_LIST_POSITION;
 
   /* if we are being destroyed, do not bother with transitions
    * and notifications
@@ -1247,9 +1247,18 @@ set_visible_child (GtkStack               *stack,
                             stack_props[PROP_VISIBLE_CHILD_NAME]);
 
   if (priv->pages)
-    gtk_selection_model_selection_changed (priv->pages,
-                                           MIN (old_pos, new_pos), 
-                                           MAX (old_pos, new_pos) - MIN (old_pos, new_pos) + 1);
+    {
+      if (old_pos == GTK_INVALID_LIST_POSITION && new_pos == GTK_INVALID_LIST_POSITION)
+        ; /* nothing to do */
+      else if (old_pos == GTK_INVALID_LIST_POSITION)
+        gtk_selection_model_selection_changed (priv->pages, new_pos, 1);
+      else if (new_pos == GTK_INVALID_LIST_POSITION)
+        gtk_selection_model_selection_changed (priv->pages, old_pos, 1);
+      else
+        gtk_selection_model_selection_changed (priv->pages,
+                                               MIN (old_pos, new_pos),
+                                               MAX (old_pos, new_pos) - MIN (old_pos, new_pos) + 1);
+    }
 
   gtk_stack_start_transition (stack, transition_type, transition_duration);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]