eventcontrollerscroll: Port to new API model

This commit is contained in:
Benjamin Otte 2018-03-10 18:29:57 +01:00 committed by Carlos Garnacho
parent 1e6eb1f8b9
commit 74dbb057ed
14 changed files with 59 additions and 106 deletions

View File

@ -249,11 +249,10 @@ struct _GtkCalendarPrivate
gint detail_width_chars;
gint detail_overflow[6];
GtkEventController *scroll_controller;
GtkEventController *key_controller;
};
static void gtk_calendar_finalize (GObject *calendar);
static void gtk_calendar_finalize (GObject *object);
static void gtk_calendar_destroy (GtkWidget *widget);
static void gtk_calendar_set_property (GObject *object,
guint prop_id,
@ -641,6 +640,7 @@ static void
gtk_calendar_init (GtkCalendar *calendar)
{
GtkWidget *widget = GTK_WIDGET (calendar);
GtkEventController *controller;
GtkGesture *gesture;
time_t secs;
struct tm *tm;
@ -681,13 +681,13 @@ gtk_calendar_init (GtkCalendar *calendar)
g_signal_connect (gesture, "drag-update", G_CALLBACK (gtk_calendar_drag_update), calendar);
gtk_widget_add_controller (GTK_WIDGET (calendar), GTK_EVENT_CONTROLLER (gesture));
priv->scroll_controller =
gtk_event_controller_scroll_new (GTK_WIDGET (calendar),
GTK_EVENT_CONTROLLER_SCROLL_VERTICAL |
controller =
gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL |
GTK_EVENT_CONTROLLER_SCROLL_DISCRETE);
g_signal_connect (priv->scroll_controller, "scroll",
g_signal_connect (controller, "scroll",
G_CALLBACK (gtk_calendar_scroll_controller_scroll),
calendar);
gtk_widget_add_controller (GTK_WIDGET (calendar), controller);
priv->key_controller =
gtk_event_controller_key_new (GTK_WIDGET (calendar));
@ -1333,7 +1333,6 @@ gtk_calendar_finalize (GObject *object)
{
GtkCalendarPrivate *priv = GTK_CALENDAR (object)->priv;
g_object_unref (priv->scroll_controller);
g_object_unref (priv->key_controller);
G_OBJECT_CLASS (gtk_calendar_parent_class)->finalize (object);

View File

@ -157,8 +157,6 @@ struct _GtkComboBoxPrivate
GtkTreeViewRowSeparatorFunc row_separator_func;
gpointer row_separator_data;
GDestroyNotify row_separator_destroy;
GtkEventController *scroll_controller;
};
/* There are 2 modes to this widget, which can be characterized as follows:
@ -895,6 +893,7 @@ gtk_combo_box_init (GtkComboBox *combo_box)
GtkComboBoxPrivate *priv;
GtkStyleContext *context;
GtkTreeMenu *menu;
GtkEventController *controller;
combo_box->priv = gtk_combo_box_get_instance_private (combo_box);
priv = combo_box->priv;
@ -938,13 +937,12 @@ gtk_combo_box_init (GtkComboBox *combo_box)
GTK_WIDGET (combo_box),
NULL);
priv->scroll_controller =
gtk_event_controller_scroll_new (GTK_WIDGET (combo_box),
GTK_EVENT_CONTROLLER_SCROLL_VERTICAL |
GTK_EVENT_CONTROLLER_SCROLL_DISCRETE);
g_signal_connect (priv->scroll_controller, "scroll",
controller = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL |
GTK_EVENT_CONTROLLER_SCROLL_DISCRETE);
g_signal_connect (controller, "scroll",
G_CALLBACK (gtk_combo_box_scroll_controller_scroll),
combo_box);
gtk_widget_add_controller (GTK_WIDGET (combo_box), controller);
}
static void
@ -2720,8 +2718,6 @@ gtk_combo_box_dispose (GObject* object)
GtkComboBox *combo_box = GTK_COMBO_BOX (object);
GtkComboBoxPrivate *priv = combo_box->priv;
g_clear_object (&priv->scroll_controller);
if (priv->popup_widget)
{
/* Stop menu destruction triggering toggle on a now-invalid button */

View File

@ -450,22 +450,16 @@ gtk_event_controller_scroll_init (GtkEventControllerScroll *scroll)
/**
* gtk_event_controller_scroll_new:
* @widget: a #GtkWidget
* @flags: behavior flags
*
* Creates a new event controller that will handle scroll events
* for the given @widget.
* Creates a new event controller that will handle scroll events.
*
* Returns: a new #GtkEventControllerScroll
**/
GtkEventController *
gtk_event_controller_scroll_new (GtkWidget *widget,
GtkEventControllerScrollFlags flags)
gtk_event_controller_scroll_new (GtkEventControllerScrollFlags flags)
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
return g_object_new (GTK_TYPE_EVENT_CONTROLLER_SCROLL,
"widget", widget,
"flags", flags,
NULL);
}

View File

@ -64,8 +64,7 @@ GDK_AVAILABLE_IN_ALL
GType gtk_event_controller_scroll_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkEventController *gtk_event_controller_scroll_new (GtkWidget *widget,
GtkEventControllerScrollFlags flags);
GtkEventController *gtk_event_controller_scroll_new (GtkEventControllerScrollFlags flags);
GDK_AVAILABLE_IN_ALL
void gtk_event_controller_scroll_set_flags (GtkEventControllerScroll *scroll,
GtkEventControllerScrollFlags flags);

View File

@ -629,16 +629,6 @@ gtk_font_chooser_widget_map (GtkWidget *widget)
GTK_WIDGET_CLASS (gtk_font_chooser_widget_parent_class)->map (widget);
}
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,
@ -767,6 +757,7 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
gtk_widget_class_bind_template_callback (widget_class, size_change_cb);
gtk_widget_class_bind_template_callback (widget_class, output_cb);
gtk_widget_class_bind_template_callback (widget_class, selection_changed);
gtk_widget_class_bind_template_callback (widget_class, resize_by_scroll_cb);
gtk_widget_class_set_css_name (widget_class, I_("fontchooser"));
}
@ -889,9 +880,6 @@ gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser)
fontchooser,
NULL);
setup_scroll_resize (priv->preview, fontchooser);
setup_scroll_resize (priv->size_slider, fontchooser);
priv->tweak_action = G_ACTION (g_simple_action_new_stateful ("tweak", NULL, g_variant_new_boolean (FALSE)));
g_signal_connect (priv->tweak_action, "change-state", G_CALLBACK (change_tweak), fontchooser);

View File

@ -1086,6 +1086,7 @@ gtk_menu_init (GtkMenu *menu)
{
GtkMenuPrivate *priv;
GtkGesture *gesture;
GtkEventController *controller;
priv = gtk_menu_get_instance_private (menu);
@ -1138,11 +1139,10 @@ gtk_menu_init (GtkMenu *menu)
g_signal_connect (gesture, "released", G_CALLBACK (gtk_menu_released_cb), menu);
gtk_widget_add_controller (GTK_WIDGET (menu), GTK_EVENT_CONTROLLER (gesture));
priv->scroll_controller =
gtk_event_controller_scroll_new (GTK_WIDGET (menu),
GTK_EVENT_CONTROLLER_SCROLL_VERTICAL);
g_signal_connect (priv->scroll_controller, "scroll",
controller = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL);
g_signal_connect (controller, "scroll",
G_CALLBACK (gtk_menu_scroll_controller_scroll), menu);
gtk_widget_add_controller (GTK_WIDGET (menu), controller);
priv->motion_controller =
gtk_event_controller_motion_new (GTK_WIDGET (menu));
@ -1225,7 +1225,6 @@ gtk_menu_finalize (GObject *object)
gtk_widget_unparent (priv->top_arrow_widget);
gtk_widget_unparent (priv->bottom_arrow_widget);
g_clear_object (&priv->scroll_controller);
g_clear_object (&priv->motion_controller);
g_clear_object (&priv->key_controller);

View File

@ -75,7 +75,6 @@ struct _GtkMenuPrivate
GtkWidget *top_arrow_widget;
GtkWidget *bottom_arrow_widget;
GtkEventController *scroll_controller;
GtkEventController *motion_controller;
GtkEventController *key_controller;

View File

@ -75,8 +75,6 @@ struct _GtkPathBarPrivate
GIcon *home_icon;
GIcon *desktop_icon;
GtkEventController *scroll_controller;
GList *button_list;
GList *first_scrolled_button;
GList *fake_root;
@ -217,6 +215,7 @@ static void
gtk_path_bar_init (GtkPathBar *path_bar)
{
GtkStyleContext *context;
GtkEventController *controller;
path_bar->priv = gtk_path_bar_get_instance_private (path_bar);
@ -245,13 +244,12 @@ gtk_path_bar_init (GtkPathBar *path_bar)
path_bar->priv->get_info_cancellable = NULL;
path_bar->priv->cancellables = NULL;
path_bar->priv->scroll_controller =
gtk_event_controller_scroll_new (GTK_WIDGET (path_bar),
GTK_EVENT_CONTROLLER_SCROLL_VERTICAL |
GTK_EVENT_CONTROLLER_SCROLL_DISCRETE);
g_signal_connect (path_bar->priv->scroll_controller, "scroll",
controller = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL |
GTK_EVENT_CONTROLLER_SCROLL_DISCRETE);
g_signal_connect (controller, "scroll",
G_CALLBACK (gtk_path_bar_scroll_controller_scroll),
path_bar);
gtk_widget_add_controller (GTK_WIDGET (path_bar), controller);
}
static void
@ -326,8 +324,6 @@ gtk_path_bar_finalize (GObject *object)
g_clear_object (&path_bar->priv->file_system);
g_clear_object (&path_bar->priv->scroll_controller);
G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
}

View File

@ -117,7 +117,6 @@ struct _GtkRangePrivate
GtkGesture *multipress_gesture;
GtkGesture *drag_gesture;
GtkEventController *scroll_controller;
GtkEventController *key_controller;
GtkScrollType autoscroll_mode;
@ -535,6 +534,7 @@ gtk_range_init (GtkRange *range)
{
GtkRangePrivate *priv = gtk_range_get_instance_private (range);
GtkGesture *gesture;
GtkEventController *controller;
gtk_widget_set_has_surface (GTK_WIDGET (range), FALSE);
@ -591,11 +591,10 @@ gtk_range_init (GtkRange *range)
gtk_widget_add_controller (GTK_WIDGET (range), GTK_EVENT_CONTROLLER (gesture));
gtk_gesture_group (priv->drag_gesture, gesture);
priv->scroll_controller =
gtk_event_controller_scroll_new (GTK_WIDGET (range),
GTK_EVENT_CONTROLLER_SCROLL_BOTH_AXES);
g_signal_connect (priv->scroll_controller, "scroll",
controller = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_BOTH_AXES);
g_signal_connect (controller, "scroll",
G_CALLBACK (gtk_range_scroll_controller_scroll), range);
gtk_widget_add_controller (GTK_WIDGET (range), controller);
priv->key_controller =
gtk_event_controller_key_new (GTK_WIDGET (range));
@ -1294,7 +1293,6 @@ gtk_range_finalize (GObject *object)
GtkRange *range = GTK_RANGE (object);
GtkRangePrivate *priv = gtk_range_get_instance_private (range);
g_clear_object (&priv->scroll_controller);
g_clear_object (&priv->key_controller);
gtk_widget_unparent (priv->slider_widget);

View File

@ -124,8 +124,6 @@ struct _GtkScaleButtonPrivate
gchar **icon_list;
GtkAdjustment *adjustment; /* needed because it must be settable in init() */
GtkEventController *scroll_controller;
};
static void gtk_scale_button_constructed (GObject *object);
@ -367,6 +365,7 @@ gtk_scale_button_init (GtkScaleButton *button)
{
GtkScaleButtonPrivate *priv;
GtkStyleContext *context;
GtkEventController *controller;
button->priv = priv = gtk_scale_button_get_instance_private (button);
@ -385,12 +384,11 @@ gtk_scale_button_init (GtkScaleButton *button)
context = gtk_widget_get_style_context (GTK_WIDGET (button));
gtk_style_context_add_class (context, "scale");
priv->scroll_controller =
gtk_event_controller_scroll_new (GTK_WIDGET (button),
GTK_EVENT_CONTROLLER_SCROLL_VERTICAL);
g_signal_connect (priv->scroll_controller, "scroll",
controller = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL);
g_signal_connect (controller, "scroll",
G_CALLBACK (gtk_scale_button_scroll_controller_scroll),
button);
gtk_widget_add_controller (GTK_WIDGET (button), controller);
g_signal_connect (gtk_button_get_gesture (GTK_BUTTON (priv->plus_button)),
"pressed", G_CALLBACK (button_pressed_cb), button);
@ -485,8 +483,6 @@ gtk_scale_button_finalize (GObject *object)
priv->adjustment = NULL;
}
g_object_unref (priv->scroll_controller);
if (priv->autoscroll_timeout)
g_source_remove (priv->autoscroll_timeout);

View File

@ -259,9 +259,6 @@ struct _GtkScrolledWindowPrivate
GtkGesture *drag_gesture;
GtkGesture *pan_gesture;
/* Scroll event controller */
GtkEventController *scroll_controller;
GtkEventController *motion_controller;
gdouble drag_start_x;
@ -327,7 +324,6 @@ static void gtk_scrolled_window_get_property (GObject *objec
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gtk_scrolled_window_finalize (GObject *object);
static void gtk_scrolled_window_destroy (GtkWidget *widget);
static void gtk_scrolled_window_snapshot (GtkWidget *widget,
@ -521,7 +517,6 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
gobject_class->set_property = gtk_scrolled_window_set_property;
gobject_class->get_property = gtk_scrolled_window_get_property;
gobject_class->finalize = gtk_scrolled_window_finalize;
widget_class->destroy = gtk_scrolled_window_destroy;
widget_class->snapshot = gtk_scrolled_window_snapshot;
@ -1885,6 +1880,7 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
{
GtkWidget *widget = GTK_WIDGET (scrolled_window);
GtkScrolledWindowPrivate *priv;
GtkEventController *controller;
GtkCssNode *widget_node;
GQuark classes[4] = {
g_quark_from_static_string (GTK_STYLE_CLASS_LEFT),
@ -1981,18 +1977,17 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
gtk_scrolled_window_update_use_indicators (scrolled_window);
priv->scroll_controller =
gtk_event_controller_scroll_new (widget,
GTK_EVENT_CONTROLLER_SCROLL_BOTH_AXES |
GTK_EVENT_CONTROLLER_SCROLL_KINETIC);
g_signal_connect (priv->scroll_controller, "scroll-begin",
controller = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_BOTH_AXES |
GTK_EVENT_CONTROLLER_SCROLL_KINETIC);
g_signal_connect (controller, "scroll-begin",
G_CALLBACK (scroll_controller_scroll_begin), scrolled_window);
g_signal_connect (priv->scroll_controller, "scroll",
g_signal_connect (controller, "scroll",
G_CALLBACK (scroll_controller_scroll), scrolled_window);
g_signal_connect (priv->scroll_controller, "scroll-end",
g_signal_connect (controller, "scroll-end",
G_CALLBACK (scroll_controller_scroll_end), scrolled_window);
g_signal_connect (priv->scroll_controller, "decelerate",
g_signal_connect (controller, "decelerate",
G_CALLBACK (scroll_controller_decelerate), scrolled_window);
gtk_widget_add_controller (widget, controller);
priv->motion_controller = gtk_event_controller_motion_new (widget);
g_signal_connect (priv->motion_controller, "leave",
@ -2611,18 +2606,6 @@ gtk_scrolled_window_destroy (GtkWidget *widget)
GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->destroy (widget);
}
static void
gtk_scrolled_window_finalize (GObject *object)
{
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (object);
GtkScrolledWindowPrivate *priv = scrolled_window->priv;
g_clear_object (&priv->scroll_controller);
G_OBJECT_CLASS (gtk_scrolled_window_parent_class)->finalize (object);
}
static void
gtk_scrolled_window_set_property (GObject *object,
guint prop_id,

View File

@ -200,8 +200,6 @@ struct _GtkSpinButtonPrivate
GtkOrientation orientation;
GtkEventController *scroll_controller;
guint digits : 10;
guint need_timer : 1;
guint numeric : 1;
@ -828,6 +826,7 @@ static void
gtk_spin_button_init (GtkSpinButton *spin_button)
{
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button);
GtkEventController *controller;
GtkGesture *gesture;
gtk_widget_set_has_surface (GTK_WIDGET (spin_button), FALSE);
@ -900,12 +899,11 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
G_CALLBACK (swipe_gesture_update), spin_button);
gtk_widget_add_controller (GTK_WIDGET (spin_button), GTK_EVENT_CONTROLLER (gesture));
priv->scroll_controller =
gtk_event_controller_scroll_new (GTK_WIDGET (spin_button),
GTK_EVENT_CONTROLLER_SCROLL_VERTICAL |
GTK_EVENT_CONTROLLER_SCROLL_DISCRETE);
g_signal_connect (priv->scroll_controller, "scroll",
controller = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL |
GTK_EVENT_CONTROLLER_SCROLL_DISCRETE);
g_signal_connect (controller, "scroll",
G_CALLBACK (scroll_controller_scroll), spin_button);
gtk_widget_add_controller (GTK_WIDGET (spin_button), controller);
}
static void
@ -916,8 +914,6 @@ gtk_spin_button_finalize (GObject *object)
gtk_spin_button_unset_adjustment (spin_button);
g_object_unref (priv->scroll_controller);
gtk_widget_unparent (priv->box);
G_OBJECT_CLASS (gtk_spin_button_parent_class)->finalize (object);

View File

@ -10523,13 +10523,11 @@ gtk_tree_view_ensure_interactive_directory (GtkTreeView *tree_view)
G_CALLBACK (gtk_tree_view_search_pressed_cb), tree_view);
gtk_widget_add_controller (tree_view->priv->search_window, GTK_EVENT_CONTROLLER (gesture));
controller = gtk_event_controller_scroll_new (tree_view->priv->search_window,
GTK_EVENT_CONTROLLER_SCROLL_VERTICAL);
g_object_set_data_full (G_OBJECT (tree_view->priv->search_window), "scroll",
controller, g_object_unref);
controller = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL);
g_signal_connect (controller, "scroll",
G_CALLBACK (gtk_tree_view_search_scroll_event),
tree_view);
gtk_widget_add_controller (tree_view->priv->search_window, controller);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);

View File

@ -111,6 +111,12 @@
<object class="GtkEntry" id="preview">
<property name="can-focus">1</property>
<property name="placeholder-text" translatable="yes">Preview text</property>
<child>
<object class="GtkEventControllerScroll">
<property name="flags" translatable="yes">horizontal</property>
<signal name="scroll" handler="resize_by_scroll_cb"/>
</object>
</child>
</object>
<packing>
<property name="left-attach">0</property>
@ -136,6 +142,12 @@
<property name="adjustment">slider_adjustment</property>
<property name="draw-value">0</property>
<property name="round-digits">0</property>
<child>
<object class="GtkEventControllerScroll">
<property name="flags" translatable="yes">horizontal</property>
<signal name="scroll" handler="resize_by_scroll_cb"/>
</object>
</child>
</object>
<packing>
<property name="left-attach">1</property>