[gtk+/touch-selection-improvements: 6/9] textview: Pass a boolean telling whether a selection drag should extend



commit 2db1b036a2e37d0d13f08e1ae20dbfcbc360c5bd
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Nov 20 13:57:46 2014 +0100

    textview: Pass a boolean telling whether a selection drag should extend
    
    Instead of passing a GdkEvent and let the function figure out whether the
    selection should be extended, let that to the caller and just pass a
    boolean here.

 gtk/gtktextview.c |   28 +++++++++++++++-------------
 1 files changed, 15 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index bfedfb7..5b1e353 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -457,7 +457,7 @@ static void     gtk_text_view_check_keymap_direction (GtkTextView        *text_v
 static void     gtk_text_view_start_selection_drag   (GtkTextView          *text_view,
                                                       const GtkTextIter    *iter,
                                                       SelectionGranularity  granularity,
-                                                      const GdkEvent       *event);
+                                                      gboolean              extends);
 static gboolean gtk_text_view_end_selection_drag     (GtkTextView        *text_view);
 static void     gtk_text_view_start_selection_dnd    (GtkTextView        *text_view,
                                                       const GtkTextIter  *iter,
@@ -5128,6 +5128,15 @@ gtk_text_view_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
   else if (button == GDK_BUTTON_PRIMARY)
     {
       GtkTextHandleMode handle_mode = GTK_TEXT_HANDLE_MODE_NONE;
+      gboolean extends = FALSE;
+      GdkModifierType state;
+
+      gdk_event_get_state (event, &state);
+
+      if (state &
+          gtk_widget_get_modifier_mask (GTK_WIDGET (text_view),
+                                        GDK_MODIFIER_INTENT_EXTEND_SELECTION))
+        extends = TRUE;
 
       switch (n_press)
         {
@@ -5144,10 +5153,7 @@ gtk_text_view_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
 
             if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
                                                       &start, &end) &&
-                gtk_text_iter_in_range (&iter, &start, &end) &&
-                !(event->button.state &
-                  gtk_widget_get_modifier_mask (GTK_WIDGET (text_view),
-                                                GDK_MODIFIER_INTENT_EXTEND_SELECTION)))
+                gtk_text_iter_in_range (&iter, &start, &end) && !extends)
               {
                 /* Claim the sequence on the drag gesture, but attach no selection data */
                 gtk_gesture_set_state (priv->drag_gesture,
@@ -5156,7 +5162,7 @@ gtk_text_view_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
               }
 
             gtk_text_view_start_selection_drag (text_view, &iter,
-                                                SELECT_CHARACTERS, event);
+                                                SELECT_CHARACTERS, extends);
             break;
           }
         case 2:
@@ -5168,7 +5174,7 @@ gtk_text_view_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
                                  &iter, NULL, NULL);
           gtk_text_view_start_selection_drag (text_view, &iter,
                                               n_press == 2 ? SELECT_WORDS : SELECT_LINES,
-                                              event);
+                                              extends);
           break;
         default:
           break;
@@ -7174,14 +7180,13 @@ static void
 gtk_text_view_start_selection_drag (GtkTextView          *text_view,
                                     const GtkTextIter    *iter,
                                     SelectionGranularity  granularity,
-                                    const GdkEvent       *event)
+                                    gboolean              extend)
 {
   GtkTextViewPrivate *priv;
   GtkTextIter cursor, ins, bound;
   GtkTextIter orig_start, orig_end;
   GtkTextBuffer *buffer;
   SelectionData *data;
-  GdkModifierType state;
 
   priv = text_view->priv;
   data = g_slice_new0 (SelectionData);
@@ -7195,11 +7200,8 @@ gtk_text_view_start_selection_drag (GtkTextView          *text_view,
   extend_selection (text_view, data->granularity, &ins, &bound);
   orig_start = ins;
   orig_end = bound;
-  gdk_event_get_state (event, &state);
 
-  if (state &
-      gtk_widget_get_modifier_mask (GTK_WIDGET (text_view),
-                                    GDK_MODIFIER_INTENT_EXTEND_SELECTION))
+  if (extend)
     {
       /* Extend selection */
       GtkTextIter old_ins, old_bound;


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