[gtk+] fontchooser: Fix smooth scrolling in the scale and the preview entry



commit 1859fe8dcfd5a647884df646968a797dadeaa790
Author: Alberto Ruiz <aruiz gnome org>
Date:   Sun Jul 21 20:46:30 2013 +0200

    fontchooser: Fix smooth scrolling in the scale and the preview entry

 gtk/gtkfontchooserwidget.c  |   18 ++++++++++++++----
 gtk/gtkfontchooserwidget.ui |    4 ++--
 2 files changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index a5d66d2..f8efb77 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -412,9 +412,9 @@ cursor_changed_cb (GtkTreeView *treeview,
 }
 
 static gboolean
-zoom_preview_cb (GtkWidget      *scrolled_window,
-                 GdkEventScroll *event,
-                 gpointer        user_data)
+resize_by_scroll_cb (GtkWidget      *scrolled_window,
+                     GdkEventScroll *event,
+                     gpointer        user_data)
 {
   GtkFontChooserWidget *fc = user_data;
   GtkFontChooserWidgetPrivate *priv = fc->priv;
@@ -428,6 +428,15 @@ zoom_preview_cb (GtkWidget      *scrolled_window,
     gtk_adjustment_set_value (adj,
                               gtk_adjustment_get_value (adj) -
                               gtk_adjustment_get_step_increment (adj));
+  else if (event->direction == GDK_SCROLL_SMOOTH && event->delta_x != 0.0)
+    gtk_adjustment_set_value (adj,
+                              gtk_adjustment_get_value (adj) +
+                              gtk_adjustment_get_step_increment (adj) * event->delta_x);
+  else if (event->direction == GDK_SCROLL_SMOOTH && event->delta_y != 0.0)
+    gtk_adjustment_set_value (adj,
+                              gtk_adjustment_get_value (adj) -
+                              gtk_adjustment_get_step_increment (adj) * event->delta_y);
+
   return TRUE;
 }
 
@@ -490,7 +499,7 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
   gtk_widget_class_bind_callback (widget_class, cursor_changed_cb);
   gtk_widget_class_bind_callback (widget_class, row_activated_cb);
   gtk_widget_class_bind_callback (widget_class, gtk_font_chooser_widget_set_cell_size);
-  gtk_widget_class_bind_callback (widget_class, zoom_preview_cb);
+  gtk_widget_class_bind_callback (widget_class, resize_by_scroll_cb);
   gtk_widget_class_bind_callback (widget_class, row_deleted_cb);
   gtk_widget_class_bind_callback (widget_class, row_inserted_cb);
   gtk_widget_class_bind_callback (widget_class, row_deleted_cb);
@@ -515,6 +524,7 @@ gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser)
   /* Set default preview text */
   gtk_entry_set_text (GTK_ENTRY (priv->preview),
                       pango_language_get_sample_string (NULL));
+  gtk_widget_add_events (priv->preview, GDK_SCROLL_MASK);
 
   /* Set the upper values of the spin/scale with G_MAXINT / PANGO_SCALE */
   gtk_spin_button_set_range (GTK_SPIN_BUTTON (priv->size_spin),
diff --git a/gtk/gtkfontchooserwidget.ui b/gtk/gtkfontchooserwidget.ui
index dd61bc9..cfd7e63 100644
--- a/gtk/gtkfontchooserwidget.ui
+++ b/gtk/gtkfontchooserwidget.ui
@@ -140,7 +140,7 @@
             <property name="can_focus">True</property>
             <property name="invisible_char">•</property>
             <property name="text">Sample string goes here</property>
-            <signal name="scroll-event" handler="zoom_preview_cb" swapped="no"/>
+            <signal name="scroll-event" handler="resize_by_scroll_cb" swapped="no"/>
           </object>
           <packing>
             <property name="left_attach">0</property>
@@ -156,7 +156,7 @@
             <property name="hexpand">True</property>
             <property name="adjustment">slider_adjustment</property>
             <property name="digits">0</property>
-            <signal name="scroll-event" handler="zoom_preview_cb" swapped="no"/>
+            <signal name="scroll-event" handler="resize_by_scroll_cb" swapped="no"/>
           </object>
           <packing>
             <property name="left_attach">0</property>


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