[gtk+/font-chooser: 27/84] GtkFontChooser: Improvements on the spin/slider interaction



commit 10c9f56582edee34e5ca70b6c1a2b86c20c638cd
Author: Alberto Ruiz <aruiz gnome org>
Date:   Sat Apr 16 17:21:07 2011 +0100

    GtkFontChooser: Improvements on the spin/slider interaction

 gtk/gtkfontchooser.c |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkfontchooser.c b/gtk/gtkfontchooser.c
index 6349de2..f2d704a 100644
--- a/gtk/gtkfontchooser.c
+++ b/gtk/gtkfontchooser.c
@@ -98,6 +98,8 @@ struct _GtkFontSelectionPrivate
   gint             size;
   PangoFontFace   *face;
   PangoFontFamily *family;
+  
+  gboolean         ignore_slider;
 };
 
 
@@ -312,6 +314,13 @@ slider_change_cb (GtkAdjustment *adjustment, gpointer data)
 {
   GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)data;
 
+  /* If we set the silder value manually, we ignore this callback */
+  if (priv->ignore_slider)
+    {
+      priv->ignore_slider = FALSE;
+      return;
+    }
+
   gtk_adjustment_set_value (gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON(priv->size_spin)),
                             gtk_adjustment_get_value (adjustment));
 }
@@ -325,10 +334,16 @@ spin_change_cb (GtkAdjustment *adjustment, gpointer data)
   
   GtkAdjustment *slider_adj = gtk_range_get_adjustment (GTK_RANGE (priv->size_slider));
 
-  if (size >= gtk_adjustment_get_lower (slider_adj) ||
-      size <= gtk_adjustment_get_upper (slider_adj))
+  /* We ignore the slider value change callback for both of this set_value call */
+  if (size < gtk_adjustment_get_lower (slider_adj))
+    {
+      priv->ignore_slider = TRUE;
+      gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_lower (slider_adj));
+    }
+  else if (size > gtk_adjustment_get_upper (slider_adj))
     {
-      gtk_adjustment_set_value (slider_adj, size);
+      priv->ignore_slider = TRUE;
+      gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_upper (slider_adj));
     }
 
   priv->size = ((gint)gtk_adjustment_get_value (adjustment)) * PANGO_SCALE;
@@ -436,6 +451,7 @@ gtk_font_selection_init (GtkFontSelection *fontsel)
                     "value-changed", G_CALLBACK (slider_change_cb), (gpointer)priv);
   g_signal_connect (G_OBJECT (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin))),
                     "value-changed", G_CALLBACK (spin_change_cb), (gpointer)priv);
+  priv->ignore_slider = FALSE;
                     
   gtk_widget_pop_composite_child();
 }



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