[gtk/current-event-apis: 9/11] gtk: Port widgets away from gtk_get_current_ apis
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/current-event-apis: 9/11] gtk: Port widgets away from gtk_get_current_ apis
- Date: Sat, 11 Apr 2020 21:30:28 +0000 (UTC)
commit 4b346538e24a19b628f787941bfe514efac5971a
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Apr 11 14:52:43 2020 -0400
gtk: Port widgets away from gtk_get_current_ apis
This commit handles complicated cases where we selections.
We handle this by adding extend and modify parameters to
the ::move-cursor signals, and adjust the bindings
accordingly.
gtk/gtkflowbox.c | 81 +++++++-----------
gtk/gtkiconview.c | 45 +++++-----
gtk/gtkiconviewprivate.h | 4 +-
gtk/gtklistbox.c | 81 ++++++------------
gtk/gtkmarshalers.list | 2 +
gtk/gtktreeview.c | 215 +++++++++++++++--------------------------------
6 files changed, 149 insertions(+), 279 deletions(-)
---
diff --git a/gtk/gtkflowbox.c b/gtk/gtkflowbox.c
index 73214fb90f..81c142318b 100644
--- a/gtk/gtkflowbox.c
+++ b/gtk/gtkflowbox.c
@@ -129,28 +129,6 @@ static void gtk_flow_box_set_accept_unpaired_release (GtkFlowBox *box,
static void gtk_flow_box_check_model_compat (GtkFlowBox *box);
-static void
-get_current_selection_modifiers (GtkWidget *widget,
- gboolean *modify,
- gboolean *extend)
-{
- GdkModifierType state = 0;
- GdkModifierType mask;
-
- *modify = FALSE;
- *extend = FALSE;
-
- if (gtk_get_current_event_state (&state))
- {
- mask = GDK_CONTROL_MASK;
- if ((state & mask) == mask)
- *modify = TRUE;
- mask = GDK_SHIFT_MASK;
- if ((state & mask) == mask)
- *extend = TRUE;
- }
-}
-
static void
path_from_horizontal_line_rects (cairo_t *cr,
GdkRectangle *lines,
@@ -307,15 +285,8 @@ static void
gtk_flow_box_child_set_focus (GtkFlowBoxChild *child)
{
GtkFlowBox *box = gtk_flow_box_child_get_box (child);
- gboolean modify;
- gboolean extend;
-
- get_current_selection_modifiers (GTK_WIDGET (box), &modify, &extend);
- if (modify)
- gtk_flow_box_update_cursor (box, child);
- else
- gtk_flow_box_update_selection (box, child, FALSE, FALSE);
+ gtk_flow_box_update_selection (box, child, FALSE, FALSE);
}
/* GtkWidget implementation {{{2 */
@@ -613,7 +584,9 @@ struct _GtkFlowBoxClass
void (*toggle_cursor_child) (GtkFlowBox *box);
gboolean (*move_cursor) (GtkFlowBox *box,
GtkMovementStep step,
- gint count);
+ gint count,
+ gboolean extend,
+ gboolean modify);
void (*select_all) (GtkFlowBox *box);
void (*unselect_all) (GtkFlowBox *box);
};
@@ -2708,10 +2681,13 @@ gtk_flow_box_click_gesture_released (GtkGestureClick *gesture,
GdkEventSequence *sequence;
GdkInputSource source;
GdkEvent *event;
+ GdkModifierType state;
gboolean modify;
gboolean extend;
- get_current_selection_modifiers (GTK_WIDGET (box), &modify, &extend);
+ state = gtk_event_controller_get_current_event_state (GTK_EVENT_CONTROLLER (gesture));
+ modify = (state & GDK_CONTROL_MASK) != 0;
+ extend = (state & GDK_SHIFT_MASK) != 0;
/* With touch, we default to modifying the selection.
* You can still clear the selection and start over
@@ -2747,6 +2723,7 @@ gtk_flow_box_drag_gesture_begin (GtkGestureDrag *gesture,
GtkWidget *widget)
{
GtkFlowBoxPrivate *priv = BOX_PRIV (widget);
+ GdkModifierType state;
if (priv->selection_mode != GTK_SELECTION_MULTIPLE)
{
@@ -2757,7 +2734,10 @@ gtk_flow_box_drag_gesture_begin (GtkGestureDrag *gesture,
priv->rubberband_select = FALSE;
priv->rubberband_first = NULL;
priv->rubberband_last = NULL;
- get_current_selection_modifiers (widget, &priv->rubberband_modify, &priv->rubberband_extend);
+
+ state = gtk_event_controller_get_current_event_state (GTK_EVENT_CONTROLLER (gesture));
+ priv->rubberband_modify = (state & GDK_CONTROL_MASK) != 0;
+ priv->rubberband_extend = (state & GDK_SHIFT_MASK) != 0;
}
static void
@@ -2992,25 +2972,22 @@ gtk_flow_box_add_move_binding (GtkWidgetClass *widget_class,
GtkMovementStep step,
gint count)
{
- GdkModifierType extend_mod_mask = GDK_SHIFT_MASK;
- GdkModifierType modify_mod_mask = GDK_CONTROL_MASK;
-
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask,
"move-cursor",
- "(ii)", step, count);
+ "(iibb)", step, count, FALSE, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
- keyval, modmask | extend_mod_mask,
+ keyval, modmask | GDK_SHIFT_MASK,
"move-cursor",
- "(ii)", step, count);
+ "(iibb)", step, count, TRUE, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
- keyval, modmask | modify_mod_mask,
+ keyval, modmask | GDK_CONTROL_MASK,
"move-cursor",
- "(ii)", step, count);
+ "(iibb)", step, count, FALSE, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
- keyval, modmask | extend_mod_mask | modify_mod_mask,
+ keyval, modmask | GDK_SHIFT_MASK | GDK_CONTROL_MASK,
"move-cursor",
- "(ii)", step, count);
+ "(iibb)", step, count, TRUE, TRUE);
}
static void
@@ -3038,11 +3015,11 @@ gtk_flow_box_toggle_cursor_child (GtkFlowBox *box)
static gboolean
gtk_flow_box_move_cursor (GtkFlowBox *box,
GtkMovementStep step,
- gint count)
+ gint count,
+ gboolean extend,
+ gboolean modify)
{
GtkFlowBoxPrivate *priv = BOX_PRIV (box);
- gboolean modify;
- gboolean extend;
GtkFlowBoxChild *child;
GtkFlowBoxChild *prev;
GtkFlowBoxChild *next;
@@ -3227,8 +3204,6 @@ gtk_flow_box_move_cursor (GtkFlowBox *box,
}
}
- get_current_selection_modifiers (GTK_WIDGET (box), &modify, &extend);
-
gtk_flow_box_update_cursor (box, child);
if (!modify)
gtk_flow_box_update_selection (box, child, FALSE, extend);
@@ -3577,6 +3552,8 @@ gtk_flow_box_class_init (GtkFlowBoxClass *class)
* @box: the #GtkFlowBox on which the signal is emitted
* @step: the granularity fo the move, as a #GtkMovementStep
* @count: the number of @step units to move
+ * @extend: whether to extend the selection
+ * @modify: whether to modify the selection
*
* The ::move-cursor signal is a
* [keybinding signal][GtkBindingSignal]
@@ -3602,12 +3579,12 @@ gtk_flow_box_class_init (GtkFlowBoxClass *class)
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkFlowBoxClass, move_cursor),
NULL, NULL,
- _gtk_marshal_BOOLEAN__ENUM_INT,
- G_TYPE_BOOLEAN, 2,
- GTK_TYPE_MOVEMENT_STEP, G_TYPE_INT);
+ _gtk_marshal_BOOLEAN__ENUM_INT_BOOLEAN_BOOLEAN,
+ G_TYPE_BOOLEAN, 4,
+ GTK_TYPE_MOVEMENT_STEP, G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
g_signal_set_va_marshaller (signals[MOVE_CURSOR],
G_TYPE_FROM_CLASS (class),
- _gtk_marshal_BOOLEAN__ENUM_INTv);
+ _gtk_marshal_BOOLEAN__ENUM_INT_BOOLEAN_BOOLEANv);
/**
* GtkFlowBox::select-all:
* @box: the #GtkFlowBox on which the signal is emitted
diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c
index 163b97b8bf..b078d69531 100644
--- a/gtk/gtkiconview.c
+++ b/gtk/gtkiconview.c
@@ -241,7 +241,9 @@ static void gtk_icon_view_add_move_binding (GtkWid
gint count);
static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
GtkMovementStep step,
- gint count);
+ gint count,
+ gboolean extend,
+ gboolean modify);
static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
gint count);
static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
@@ -776,6 +778,8 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
* @iconview: the object which received the signal
* @step: the granularity of the move, as a #GtkMovementStep
* @count: the number of @step units to move
+ * @extend: whether to extend the selection
+ * @modify: whether to modify the selection
*
* The ::move-cursor signal is a
* [keybinding signal][GtkBindingSignal]
@@ -798,13 +802,15 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
NULL, NULL,
- _gtk_marshal_BOOLEAN__ENUM_INT,
- G_TYPE_BOOLEAN, 2,
+ _gtk_marshal_BOOLEAN__ENUM_INT_BOOLEAN_BOOLEAN,
+ G_TYPE_BOOLEAN, 4,
GTK_TYPE_MOVEMENT_STEP,
- G_TYPE_INT);
+ G_TYPE_INT,
+ G_TYPE_BOOLEAN,
+ G_TYPE_BOOLEAN);
g_signal_set_va_marshaller (icon_view_signals[MOVE_CURSOR],
G_TYPE_FROM_CLASS (klass),
- _gtk_marshal_BOOLEAN__ENUM_INTv);
+ _gtk_marshal_BOOLEAN__ENUM_INT_BOOLEAN_BOOLEANv);
/* Key bindings */
gtk_widget_class_add_binding_signal (widget_class,
@@ -1823,7 +1829,7 @@ gtk_icon_view_motion (GtkEventController *controller,
icon_view->priv->mouse_x = x;
icon_view->priv->mouse_y = y;
- device = gtk_get_current_event_device (); /* FIXME: controller device */
+ device = gtk_event_controller_get_current_event_device (controller);
gtk_icon_view_maybe_begin_drag (icon_view, x, y, device);
if (icon_view->priv->doing_rubberband)
@@ -3421,12 +3427,12 @@ gtk_icon_view_add_move_binding (GtkWidgetClass *widget_class,
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask,
I_("move-cursor"),
- "(ii)", step, count);
+ "(iibb)", step, count, FALSE, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
keyval, GDK_SHIFT_MASK,
"move-cursor",
- "(ii)", step, count);
+ "(iibb)", step, count, TRUE, FALSE);
if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
return;
@@ -3434,21 +3440,21 @@ gtk_icon_view_add_move_binding (GtkWidgetClass *widget_class,
gtk_widget_class_add_binding_signal (widget_class,
keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"move-cursor",
- "(ii)", step, count);
+ "(iibb)", step, count, TRUE, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
keyval, GDK_CONTROL_MASK,
"move-cursor",
- "(ii)", step, count);
+ "(iibb)", step, count, FALSE, TRUE);
}
static gboolean
gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
GtkMovementStep step,
- gint count)
+ gint count,
+ gboolean extend,
+ gboolean modify)
{
- GdkModifierType state;
-
g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
step == GTK_MOVEMENT_VISUAL_POSITIONS ||
@@ -3462,17 +3468,8 @@ gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
gtk_widget_grab_focus (GTK_WIDGET (icon_view));
- if (gtk_get_current_event_state (&state))
- {
- GdkModifierType extend_mod_mask = GDK_SHIFT_MASK;
- GdkModifierType modify_mod_mask = GDK_CONTROL_MASK;
-
- if ((state & modify_mod_mask) == modify_mod_mask)
- icon_view->priv->modify_selection_pressed = TRUE;
- if ((state & extend_mod_mask) == extend_mod_mask)
- icon_view->priv->extend_selection_pressed = TRUE;
- }
- /* else we assume not pressed */
+ icon_view->priv->extend_selection_pressed = extend;
+ icon_view->priv->modify_selection_pressed = modify;
switch (step)
{
diff --git a/gtk/gtkiconviewprivate.h b/gtk/gtkiconviewprivate.h
index 1cfd1aa3d8..8c58bccf96 100644
--- a/gtk/gtkiconviewprivate.h
+++ b/gtk/gtkiconviewprivate.h
@@ -63,7 +63,9 @@ struct _GtkIconViewClass
void (* toggle_cursor_item) (GtkIconView *icon_view);
gboolean (* move_cursor) (GtkIconView *icon_view,
GtkMovementStep step,
- gint count);
+ gint count,
+ gboolean extend,
+ gboolean modify);
gboolean (* activate_cursor_item) (GtkIconView *icon_view);
};
diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c
index 090ee4f2d4..2ca063710e 100644
--- a/gtk/gtklistbox.c
+++ b/gtk/gtklistbox.c
@@ -147,7 +147,9 @@ struct _GtkListBoxClass
void (*toggle_cursor_row) (GtkListBox *box);
void (*move_cursor) (GtkListBox *box,
GtkMovementStep step,
- gint count);
+ gint count,
+ gboolean extend,
+ gboolean modify);
void (*selected_rows_changed) (GtkListBox *box);
void (*select_all) (GtkListBox *box);
void (*unselect_all) (GtkListBox *box);
@@ -261,7 +263,9 @@ static void gtk_list_box_activate_cursor_row (GtkListBo
static void gtk_list_box_toggle_cursor_row (GtkListBox *box);
static void gtk_list_box_move_cursor (GtkListBox *box,
GtkMovementStep step,
- gint count);
+ gint count,
+ gboolean extend,
+ gboolean modify);
static void gtk_list_box_finalize (GObject *obj);
static void gtk_list_box_parent_cb (GObject *object,
GParamSpec *pspec,
@@ -594,12 +598,12 @@ gtk_list_box_class_init (GtkListBoxClass *klass)
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkListBoxClass, move_cursor),
NULL, NULL,
- _gtk_marshal_VOID__ENUM_INT,
- G_TYPE_NONE, 2,
- GTK_TYPE_MOVEMENT_STEP, G_TYPE_INT);
+ _gtk_marshal_VOID__ENUM_INT_BOOLEAN_BOOLEAN,
+ G_TYPE_NONE, 4,
+ GTK_TYPE_MOVEMENT_STEP, G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
g_signal_set_va_marshaller (signals[MOVE_CURSOR],
G_TYPE_FROM_CLASS (klass),
- _gtk_marshal_VOID__ENUM_INTv);
+ _gtk_marshal_VOID__ENUM_INT_BOOLEAN_BOOLEANv);
widget_class->activate_signal = signals[ACTIVATE_CURSOR_ROW];
@@ -1426,25 +1430,22 @@ gtk_list_box_add_move_binding (GtkWidgetClass *widget_class,
GtkMovementStep step,
gint count)
{
- GdkModifierType extend_mod_mask = GDK_SHIFT_MASK;
- GdkModifierType modify_mod_mask = GDK_CONTROL_MASK;
-
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask,
"move-cursor",
- "(ii)", step, count);
+ "(iibb)", step, count, FALSE, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
- keyval, modmask | extend_mod_mask,
+ keyval, modmask | GDK_SHIFT_MASK,
"move-cursor",
- "(ii)", step, count);
+ "(iibb)", step, count, TRUE, FALSE);
gtk_widget_class_add_binding_signal (widget_class,
- keyval, modmask | modify_mod_mask,
+ keyval, modmask | GDK_CONTROL_MASK,
"move-cursor",
- "(ii)", step, count);
+ "(iibb)", step, count, FALSE, TRUE);
gtk_widget_class_add_binding_signal (widget_class,
- keyval, modmask | extend_mod_mask | modify_mod_mask,
- "move-cursor",
- "(ii)", step, count);
+ keyval, modmask | GDK_SHIFT_MASK | GDK_CONTROL_MASK,
+ "move-cursor",
+ "(iibb)", step, count, TRUE, TRUE);
}
static void
@@ -1764,28 +1765,6 @@ gtk_list_box_click_gesture_pressed (GtkGestureClick *gesture,
}
}
-static void
-get_current_selection_modifiers (GtkWidget *widget,
- gboolean *modify,
- gboolean *extend)
-{
- GdkModifierType state = 0;
- GdkModifierType mask;
-
- *modify = FALSE;
- *extend = FALSE;
-
- if (gtk_get_current_event_state (&state))
- {
- mask = GDK_CONTROL_MASK;
- if ((state & mask) == mask)
- *modify = TRUE;
- mask = GDK_SHIFT_MASK;
- if ((state & mask) == mask)
- *extend = TRUE;
- }
-}
-
static void
gtk_list_box_click_unpaired_release (GtkGestureClick *gesture,
gdouble x,
@@ -1829,16 +1808,19 @@ gtk_list_box_click_gesture_released (GtkGestureClick *gesture,
GdkEventSequence *sequence;
GdkInputSource source;
GdkEvent *event;
- gboolean modify;
+ GdkModifierType state;
gboolean extend;
+ gboolean modify;
- get_current_selection_modifiers (GTK_WIDGET (box), &modify, &extend);
/* With touch, we default to modifying the selection.
* You can still clear the selection and start over
* by holding Ctrl.
*/
sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
+ state = gdk_event_get_modifier_state (event);
+ extend = (state & GDK_SHIFT_MASK) != 0;
+ modify = (state & GDK_CONTROL_MASK) != 0;
source = gdk_device_get_source (gdk_event_get_source_device (event));
if (source == GDK_SOURCE_TOUCHSCREEN)
@@ -2730,10 +2712,10 @@ gtk_list_box_toggle_cursor_row (GtkListBox *box)
static void
gtk_list_box_move_cursor (GtkListBox *box,
GtkMovementStep step,
- gint count)
+ gint count,
+ gboolean extend,
+ gboolean modify)
{
- gboolean modify;
- gboolean extend;
GtkListBoxRow *row;
gint page_size;
GSequenceIter *iter;
@@ -2851,8 +2833,6 @@ gtk_list_box_move_cursor (GtkListBox *box,
return;
}
- get_current_selection_modifiers (GTK_WIDGET (box), &modify, &extend);
-
gtk_list_box_update_cursor (box, row, TRUE);
if (!modify)
gtk_list_box_update_selection (box, row, FALSE, extend);
@@ -2876,18 +2856,11 @@ static void
gtk_list_box_row_set_focus (GtkListBoxRow *row)
{
GtkListBox *box = gtk_list_box_row_get_box (row);
- gboolean modify;
- gboolean extend;
if (!box)
return;
- get_current_selection_modifiers (GTK_WIDGET (row), &modify, &extend);
-
- if (modify)
- gtk_list_box_update_cursor (box, row, TRUE);
- else
- gtk_list_box_update_selection (box, row, FALSE, FALSE);
+ gtk_list_box_update_selection (box, row, FALSE, FALSE);
}
static gboolean
diff --git a/gtk/gtkmarshalers.list b/gtk/gtkmarshalers.list
index ee0d355f85..6e91f452b5 100644
--- a/gtk/gtkmarshalers.list
+++ b/gtk/gtkmarshalers.list
@@ -29,6 +29,7 @@ BOOLEAN:ENUM,BOOLEAN
BOOLEAN:ENUM,BOXED,BOXED,BOXED
BOOLEAN:ENUM,DOUBLE
BOOLEAN:ENUM,INT
+BOOLEAN:ENUM,INT,BOOLEAN,BOOLEAN
BOOLEAN:FLAGS
BOOLEAN:OBJECT
BOOLEAN:OBJECT,UINT,FLAGS
@@ -76,6 +77,7 @@ VOID:ENUM,FLOAT
VOID:ENUM,FLOAT,BOOLEAN
VOID:ENUM,INT
VOID:ENUM,INT,BOOLEAN
+VOID:ENUM,INT,BOOLEAN,BOOLEAN
VOID:ENUM,INT,INT
VOID:ENUM,OBJECT
VOID:ENUM,STRING
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 83daf4f487..30f97c408e 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -345,7 +345,9 @@ struct _GtkTreeViewClass
/* Key Binding signals */
gboolean (* move_cursor) (GtkTreeView *tree_view,
GtkMovementStep step,
- gint count);
+ gint count,
+ gboolean extend,
+ gboolean modify);
gboolean (* select_all) (GtkTreeView *tree_view);
gboolean (* unselect_all) (GtkTreeView *tree_view);
gboolean (* select_cursor_row) (GtkTreeView *tree_view,
@@ -715,7 +717,9 @@ static void gtk_tree_view_drag_data_received (GObject
/* tree_model signals */
static gboolean gtk_tree_view_real_move_cursor (GtkTreeView *tree_view,
GtkMovementStep step,
- gint count);
+ gint count,
+ gboolean extend,
+ gboolean modify);
static gboolean gtk_tree_view_real_select_all (GtkTreeView *tree_view);
static gboolean gtk_tree_view_real_unselect_all (GtkTreeView *tree_view);
static gboolean gtk_tree_view_real_select_cursor_row (GtkTreeView *tree_view,
@@ -850,8 +854,7 @@ static TreeViewDragInfo* get_info (GtkTreeView *tree_view);
/* interactive search */
static void gtk_tree_view_ensure_interactive_directory (GtkTreeView *tree_view);
static void gtk_tree_view_search_popover_hide (GtkWidget *search_popover,
- GtkTreeView *tree_view,
- GdkDevice *device);
+ GtkTreeView *tree_view);
static void gtk_tree_view_search_preedit_changed (GtkText *text,
const char *preedit,
GtkTreeView *tree_view);
@@ -900,7 +903,6 @@ static gboolean gtk_tree_view_start_editing (GtkTreeView *tree_
static void gtk_tree_view_stop_editing (GtkTreeView *tree_view,
gboolean cancel_editing);
static gboolean gtk_tree_view_real_start_interactive_search (GtkTreeView *tree_view,
- GdkDevice *device,
gboolean keybinding);
static gboolean gtk_tree_view_start_interactive_search (GtkTreeView *tree_view);
static GtkTreeViewColumn *gtk_tree_view_get_drop_column (GtkTreeView *tree_view,
@@ -1376,15 +1378,16 @@ gtk_tree_view_class_init (GtkTreeViewClass *class)
/**
* GtkTreeView::move-cursor:
* @tree_view: the object on which the signal is emitted.
- * @step: the granularity of the move, as a
- * #GtkMovementStep. %GTK_MOVEMENT_LOGICAL_POSITIONS,
- * %GTK_MOVEMENT_VISUAL_POSITIONS, %GTK_MOVEMENT_DISPLAY_LINES,
- * %GTK_MOVEMENT_PAGES and %GTK_MOVEMENT_BUFFER_ENDS are
- * supported. %GTK_MOVEMENT_LOGICAL_POSITIONS and
- * %GTK_MOVEMENT_VISUAL_POSITIONS are treated identically.
- * @direction: the direction to move: +1 to move forwards;
- * -1 to move backwards. The resulting movement is
- * undefined for all other values.
+ * @step: the granularity of the move, as a #GtkMovementStep.
+ * %GTK_MOVEMENT_LOGICAL_POSITIONS, %GTK_MOVEMENT_VISUAL_POSITIONS,
+ * %GTK_MOVEMENT_DISPLAY_LINES, %GTK_MOVEMENT_PAGES and
+ * %GTK_MOVEMENT_BUFFER_ENDS are supported.
+ * %GTK_MOVEMENT_LOGICAL_POSITIONS and %GTK_MOVEMENT_VISUAL_POSITIONS
+ * are treated identically.
+ * @direction: the direction to move: +1 to move forwards; -1 to move
+ * backwards. The resulting movement is undefined for all other values.
+ * @extend: whether to extend the selection
+ * @modify: whether to modify the selection
*
* The #GtkTreeView::move-cursor signal is a [keybinding
* signal][GtkBindingSignal] which gets emitted when the user
@@ -1404,13 +1407,15 @@ gtk_tree_view_class_init (GtkTreeViewClass *class)
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkTreeViewClass, move_cursor),
NULL, NULL,
- _gtk_marshal_BOOLEAN__ENUM_INT,
- G_TYPE_BOOLEAN, 2,
+ _gtk_marshal_BOOLEAN__ENUM_INT_BOOLEAN_BOOLEAN,
+ G_TYPE_BOOLEAN, 4,
GTK_TYPE_MOVEMENT_STEP,
- G_TYPE_INT);
+ G_TYPE_INT,
+ G_TYPE_BOOLEAN,
+ G_TYPE_BOOLEAN);
g_signal_set_va_marshaller (tree_view_signals[MOVE_CURSOR],
G_TYPE_FROM_CLASS (o_class),
- _gtk_marshal_BOOLEAN__ENUM_INTv);
+ _gtk_marshal_BOOLEAN__ENUM_INT_BOOLEAN_BOOLEANv);
tree_view_signals[SELECT_ALL] =
g_signal_new (I_("select-all"),
@@ -1537,46 +1542,15 @@ gtk_tree_view_class_init (GtkTreeViewClass *class)
gtk_tree_view_add_move_binding (widget_class, GDK_KEY_KP_Page_Down, 0, TRUE,
GTK_MOVEMENT_PAGES, 1);
+ gtk_tree_view_add_move_binding (widget_class, GDK_KEY_Right, 0, FALSE,
+ GTK_MOVEMENT_VISUAL_POSITIONS, 1);
+ gtk_tree_view_add_move_binding (widget_class, GDK_KEY_Left, 0, FALSE,
+ GTK_MOVEMENT_VISUAL_POSITIONS, -1);
- gtk_widget_class_add_binding_signal (widget_class,
- GDK_KEY_Right, 0,
- "move-cursor",
- "(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, 1);
-
- gtk_widget_class_add_binding_signal (widget_class,
- GDK_KEY_Left, 0,
- "move-cursor",
- "(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, -1);
-
- gtk_widget_class_add_binding_signal (widget_class,
- GDK_KEY_KP_Right, 0,
- "move-cursor",
- "(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, 1);
-
- gtk_widget_class_add_binding_signal (widget_class,
- GDK_KEY_KP_Left, 0,
- "move-cursor",
- "(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, -1);
-
- gtk_widget_class_add_binding_signal (widget_class,
- GDK_KEY_Right, GDK_CONTROL_MASK,
- "move-cursor",
- "(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, 1);
-
- gtk_widget_class_add_binding_signal (widget_class,
- GDK_KEY_Left, GDK_CONTROL_MASK,
- "move-cursor",
- "(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, -1);
-
- gtk_widget_class_add_binding_signal (widget_class,
- GDK_KEY_KP_Right, GDK_CONTROL_MASK,
- "move-cursor",
- "(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, 1);
-
- gtk_widget_class_add_binding_signal (widget_class,
- GDK_KEY_KP_Left, GDK_CONTROL_MASK,
- "move-cursor",
- "(ii)", GTK_MOVEMENT_VISUAL_POSITIONS, -1);
+ gtk_tree_view_add_move_binding (widget_class, GDK_KEY_KP_Right, 0, FALSE,
+ GTK_MOVEMENT_VISUAL_POSITIONS, 1);
+ gtk_tree_view_add_move_binding (widget_class, GDK_KEY_KP_Left, 0, FALSE,
+ GTK_MOVEMENT_VISUAL_POSITIONS, -1);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_space, GDK_CONTROL_MASK, "toggle-cursor-row",
NULL);
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
"toggle-cursor-row", NULL);
@@ -2778,33 +2752,23 @@ gtk_tree_view_get_expander_size (GtkTreeView *tree_view)
}
static void
-get_current_selection_modifiers (GtkWidget *widget,
- gboolean *modify,
- gboolean *extend)
+get_current_selection_modifiers (GtkEventController *controller,
+ gboolean *modify,
+ gboolean *extend)
{
- GdkModifierType state = 0;
- GdkModifierType mask;
-
- *modify = FALSE;
- *extend = FALSE;
+ GdkModifierType state;
- if (gtk_get_current_event_state (&state))
- {
- mask = GDK_CONTROL_MASK;
- if ((state & mask) == mask)
- *modify = TRUE;
- mask = GDK_SHIFT_MASK;
- if ((state & mask) == mask)
- *extend = TRUE;
- }
+ state = gtk_event_controller_get_current_event_state (controller);
+ *modify = (state & GDK_CONTROL_MASK) != 0;
+ *extend = (state & GDK_SHIFT_MASK) != 0;
}
static void
gtk_tree_view_click_gesture_pressed (GtkGestureClick *gesture,
- gint n_press,
- gdouble x,
- gdouble y,
- GtkTreeView *tree_view)
+ int n_press,
+ double x,
+ double y,
+ GtkTreeView *tree_view)
{
GtkWidget *widget = GTK_WIDGET (tree_view);
GdkRectangle background_area, cell_area;
@@ -3006,7 +2970,7 @@ gtk_tree_view_click_gesture_pressed (GtkGestureClick *gesture,
GtkCellRenderer *focus_cell;
gboolean modify, extend;
- get_current_selection_modifiers (widget, &modify, &extend);
+ get_current_selection_modifiers (GTK_EVENT_CONTROLLER (gesture), &modify, &extend);
tree_view->modify_selection_pressed = modify;
tree_view->extend_selection_pressed = extend;
@@ -3094,7 +3058,7 @@ gtk_tree_view_drag_gesture_begin (GtkGestureDrag *gesture,
tree_view->rubber_band_y += tree_view->dy;
tree_view->rubber_band_status = RUBBER_BAND_MAYBE_START;
- get_current_selection_modifiers (GTK_WIDGET (tree_view), &modify, &extend);
+ get_current_selection_modifiers (GTK_EVENT_CONTROLLER (gesture), &modify, &extend);
tree_view->rubber_band_modify = modify;
tree_view->rubber_band_extend = extend;
}
@@ -3316,7 +3280,7 @@ gtk_tree_view_click_gesture_released (GtkGestureClick *gesture,
tree_view->button_pressed_node != tree_view->prelight_node)
return;
- get_current_selection_modifiers (GTK_WIDGET (tree_view), &modify, &extend);
+ get_current_selection_modifiers (GTK_EVENT_CONTROLLER (gesture), &modify, &extend);
if (tree_view->arrow_prelit)
{
@@ -5466,12 +5430,7 @@ gtk_tree_view_forward_controller_key_pressed (GtkEventControllerKey *key,
gtk_event_controller_key_forward (key, tree_view->search_entry);
if (tree_view->imcontext_changed)
- {
- GdkDevice *device;
-
- device = gtk_get_current_event_device ();
- return gtk_tree_view_real_start_interactive_search (tree_view, device, FALSE);
- }
+ return gtk_tree_view_real_start_interactive_search (tree_view, FALSE);
}
}
@@ -5537,8 +5496,7 @@ gtk_tree_view_focus_controller_focus_out (GtkEventController *focus,
if (tree_view->search_popover &&
!gtk_event_controller_focus_contains_focus (GTK_EVENT_CONTROLLER_FOCUS (focus)))
- gtk_tree_view_search_popover_hide (tree_view->search_popover, tree_view,
- gtk_get_current_event_device ());
+ gtk_tree_view_search_popover_hide (tree_view->search_popover, tree_view);
}
/* Incremental Reflow
@@ -7937,10 +7895,10 @@ gtk_tree_view_css_changed (GtkWidget *widget,
static gboolean
gtk_tree_view_real_move_cursor (GtkTreeView *tree_view,
GtkMovementStep step,
- gint count)
+ gint count,
+ gboolean extend,
+ gboolean modify)
{
- GdkModifierType state;
-
g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), FALSE);
g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
step == GTK_MOVEMENT_VISUAL_POSITIONS ||
@@ -7957,20 +7915,8 @@ gtk_tree_view_real_move_cursor (GtkTreeView *tree_view,
tree_view->draw_keyfocus = TRUE;
gtk_widget_grab_focus (GTK_WIDGET (tree_view));
- if (gtk_get_current_event_state (&state))
- {
- GdkModifierType extend_mod_mask;
- GdkModifierType modify_mod_mask;
-
- extend_mod_mask = GDK_SHIFT_MASK;
- modify_mod_mask = GDK_CONTROL_MASK;
-
- if ((state & modify_mod_mask) == modify_mod_mask)
- tree_view->modify_selection_pressed = TRUE;
- if ((state & extend_mod_mask) == extend_mod_mask)
- tree_view->extend_selection_pressed = TRUE;
- }
- /* else we assume not pressed */
+ tree_view->modify_selection_pressed = modify;
+ tree_view->extend_selection_pressed = extend;
switch (step)
{
@@ -8902,30 +8848,30 @@ gtk_tree_view_add_move_binding (GtkWidgetClass *widget_class,
GtkMovementStep step,
gint count)
{
-
gtk_widget_class_add_binding_signal (widget_class,
keyval, modmask,
"move-cursor",
- "(ii)", step, count);
+ "(iibb)", step, count, FALSE, FALSE);
if (add_shifted_binding)
gtk_widget_class_add_binding_signal (widget_class,
keyval, GDK_SHIFT_MASK,
"move-cursor",
- "(ii)", step, count);
+ "(iibb)", step, count, TRUE, FALSE);
if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
return;
- gtk_widget_class_add_binding_signal (widget_class, keyval,
- GDK_CONTROL_MASK | GDK_SHIFT_MASK,
- "move-cursor",
- "(ii)", step, count);
-
gtk_widget_class_add_binding_signal (widget_class,
keyval, GDK_CONTROL_MASK,
"move-cursor",
- "(ii)", step, count);
+ "(iibb)", step, count, FALSE, TRUE);
+
+ if (add_shifted_binding)
+ gtk_widget_class_add_binding_signal (widget_class, keyval,
+ GDK_CONTROL_MASK | GDK_SHIFT_MASK,
+ "move-cursor",
+ "(iibb)", step, count, TRUE, TRUE);
}
static gint
@@ -9960,7 +9906,6 @@ static gboolean
gtk_tree_view_real_select_cursor_parent (GtkTreeView *tree_view)
{
GtkTreePath *cursor_path = NULL;
- GdkModifierType state;
if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
goto out;
@@ -9977,23 +9922,11 @@ gtk_tree_view_real_select_cursor_parent (GtkTreeView *tree_view)
gtk_tree_path_up (cursor_path);
- if (gtk_get_current_event_state (&state))
- {
- GdkModifierType modify_mod_mask;
-
- modify_mod_mask = GDK_CONTROL_MASK;
-
- if ((state & modify_mod_mask) == modify_mod_mask)
- tree_view->modify_selection_pressed = TRUE;
- }
-
gtk_tree_view_real_set_cursor (tree_view, cursor_path, CLEAR_AND_SELECT | CLAMP_NODE);
gtk_tree_path_free (cursor_path);
gtk_widget_grab_focus (GTK_WIDGET (tree_view));
- tree_view->modify_selection_pressed = FALSE;
-
return TRUE;
}
@@ -10006,7 +9939,7 @@ gtk_tree_view_real_select_cursor_parent (GtkTreeView *tree_view)
static gboolean
gtk_tree_view_search_entry_flush_timeout (GtkTreeView *tree_view)
{
- gtk_tree_view_search_popover_hide (tree_view->search_popover, tree_view, NULL);
+ gtk_tree_view_search_popover_hide (tree_view->search_popover, tree_view);
tree_view->typeselect_flush_timeout = 0;
return FALSE;
@@ -10067,7 +10000,6 @@ gtk_tree_view_ensure_interactive_directory (GtkTreeView *tree_view)
*/
static gboolean
gtk_tree_view_real_start_interactive_search (GtkTreeView *tree_view,
- GdkDevice *device,
gboolean keybinding)
{
/* We only start interactive search if we have focus or the columns
@@ -10148,9 +10080,7 @@ gtk_tree_view_real_start_interactive_search (GtkTreeView *tree_view,
static gboolean
gtk_tree_view_start_interactive_search (GtkTreeView *tree_view)
{
- return gtk_tree_view_real_start_interactive_search (tree_view,
- gtk_get_current_event_device (),
- TRUE);
+ return gtk_tree_view_real_start_interactive_search (tree_view, TRUE);
}
/* Callbacks */
@@ -13527,8 +13457,7 @@ gtk_tree_view_set_search_entry (GtkTreeView *tree_view,
static void
gtk_tree_view_search_popover_hide (GtkWidget *search_popover,
- GtkTreeView *tree_view,
- GdkDevice *device)
+ GtkTreeView *tree_view)
{
if (tree_view->disable_popdown)
return;
@@ -13587,9 +13516,7 @@ gtk_tree_view_search_activate (GtkEntry *entry,
{
GtkTreePath *path;
- gtk_tree_view_search_popover_hide (tree_view->search_popover,
- tree_view,
- gtk_get_current_event_device ());
+ gtk_tree_view_search_popover_hide (tree_view->search_popover, tree_view);
/* If we have a row selected and it's the cursor row, we activate
* the row XXX */
@@ -13612,14 +13539,7 @@ gtk_tree_view_search_pressed_cb (GtkGesture *gesture,
double y,
GtkTreeView *tree_view)
{
- GdkDevice *keyb_device;
- GdkEventSequence *sequence;
- GdkEvent *event;
-
- sequence = gtk_gesture_get_last_updated_sequence (gesture);
- event = gtk_gesture_get_last_event (gesture, sequence);
- keyb_device = gdk_device_get_associated_device (gdk_event_get_device (event));
- gtk_tree_view_search_popover_hide (tree_view->search_popover, tree_view, keyb_device);
+ gtk_tree_view_search_popover_hide (tree_view->search_popover, tree_view);
}
static gboolean
@@ -13670,8 +13590,7 @@ gtk_tree_view_search_key_pressed (GtkEventControllerKey *key,
if (!tree_view->search_custom_entry_set
&& gtk_tree_view_search_key_cancels_search (keyval))
{
- gtk_tree_view_search_popover_hide (tree_view->search_popover, tree_view,
- gtk_get_current_event_device ());
+ gtk_tree_view_search_popover_hide (tree_view->search_popover, tree_view);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]