[gtk+/wip/matthiasc/kill-event-signals: 29/62] fontchooser: Stop using ::scroll-event
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/kill-event-signals: 29/62] fontchooser: Stop using ::scroll-event
- Date: Tue, 2 Jan 2018 04:54:14 +0000 (UTC)
commit de8c73e3413dfca3f282cce7911fcd55a5df5eaa
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jan 1 00:49:38 2018 -0500
fontchooser: Stop using ::scroll-event
We have an event controller for this purpose now.
gtk/gtkfontchooserwidget.c | 52 +++++++++++++++++-----------------------
gtk/ui/gtkfontchooserwidget.ui | 2 -
2 files changed, 22 insertions(+), 32 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index 0335531..be06bec 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -51,6 +51,7 @@
#include "gtkwidget.h"
#include "gtksettings.h"
#include "gtkdialog.h"
+#include "gtkeventcontrollerscroll.h"
/**
* SECTION:gtkfontchooserwidget
@@ -491,40 +492,19 @@ cursor_changed_cb (GtkTreeView *treeview,
gtk_delayed_font_description_unref (desc);
}
-static gboolean
-resize_by_scroll_cb (GtkWidget *scrolled_window,
- GdkEventScroll *event,
- gpointer user_data)
+static void
+resize_by_scroll_cb (GtkEventControllerScroll *controller,
+ double dx,
+ double dy,
+ gpointer user_data)
{
GtkFontChooserWidget *fc = user_data;
GtkFontChooserWidgetPrivate *priv = fc->priv;
GtkAdjustment *adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin));
- GdkScrollDirection direction;
- gdouble delta_x, delta_y;
-
- if (!gdk_event_get_scroll_direction ((GdkEvent *) event, &direction))
- return GDK_EVENT_PROPAGATE;
-
- gdk_event_get_scroll_deltas ((GdkEvent *) event, &delta_x, &delta_y);
-
- if (direction == GDK_SCROLL_UP || direction == GDK_SCROLL_RIGHT)
- gtk_adjustment_set_value (adj,
- gtk_adjustment_get_value (adj) +
- gtk_adjustment_get_step_increment (adj));
- else if (direction == GDK_SCROLL_DOWN || direction == GDK_SCROLL_LEFT)
- gtk_adjustment_set_value (adj,
- gtk_adjustment_get_value (adj) -
- gtk_adjustment_get_step_increment (adj));
- else if (direction == GDK_SCROLL_SMOOTH && delta_x != 0.0)
- gtk_adjustment_set_value (adj,
- gtk_adjustment_get_value (adj) +
- gtk_adjustment_get_step_increment (adj) * delta_x);
- else if (direction == GDK_SCROLL_SMOOTH && delta_y != 0.0)
- gtk_adjustment_set_value (adj,
- gtk_adjustment_get_value (adj) -
- gtk_adjustment_get_step_increment (adj) * delta_y);
- return TRUE;
+ gtk_adjustment_set_value (adj,
+ gtk_adjustment_get_value (adj) +
+ gtk_adjustment_get_step_increment (adj) * dx);
}
static void
@@ -559,6 +539,16 @@ rows_changed_cb (GtkFontChooserWidget *fontchooser)
}
static void
+setup_scroll_resize (GtkWidget *widget,
+ GtkFontChooserWidget *fontchooser)
+{
+ GtkEventController *controller;
+
+ controller = gtk_event_controller_scroll_new (widget, GTK_EVENT_CONTROLLER_SCROLL_HORIZONTAL);
+ g_signal_connect (controller, "scroll", G_CALLBACK (resize_by_scroll_cb), fontchooser);
+}
+
+static void
gtk_font_chooser_widget_measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
@@ -657,7 +647,6 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
gtk_widget_class_bind_template_callback (widget_class, cursor_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, row_activated_cb);
gtk_widget_class_bind_template_callback (widget_class, gtk_font_chooser_widget_set_cell_size);
- gtk_widget_class_bind_template_callback (widget_class, resize_by_scroll_cb);
gtk_widget_class_bind_template_callback (widget_class, rows_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, size_change_cb);
gtk_widget_class_bind_template_callback (widget_class, output_cb);
@@ -703,6 +692,9 @@ gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser)
fontchooser,
NULL);
+ setup_scroll_resize (priv->preview, fontchooser);
+ setup_scroll_resize (priv->size_slider, fontchooser);
+
/* Load data and set initial style-dependent parameters */
gtk_font_chooser_widget_load_fonts (fontchooser, TRUE);
gtk_font_chooser_widget_set_cell_size (fontchooser);
diff --git a/gtk/ui/gtkfontchooserwidget.ui b/gtk/ui/gtkfontchooserwidget.ui
index b77c606..6b8847b 100644
--- a/gtk/ui/gtkfontchooserwidget.ui
+++ b/gtk/ui/gtkfontchooserwidget.ui
@@ -109,7 +109,6 @@
<object class="GtkEntry" id="preview">
<property name="can-focus">1</property>
<property name="placeholder-text" translatable="yes">Preview text</property>
- <signal name="scroll-event" handler="resize_by_scroll_cb" swapped="no"/>
</object>
<packing>
<property name="left-attach">0</property>
@@ -124,7 +123,6 @@
<property name="adjustment">slider_adjustment</property>
<property name="draw-value">0</property>
<property name="round-digits">0</property>
- <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]