Patch for cursor positioning in gtktextlayout



There is a problem with mouse positioning in gtk+-1.3.9 . The
problems occurs under the following scenario:

  Scenario 1:

     1. Make the alignment center or right margin.
     2. Type a short line in the widget.
     3. Press the mouse to the left of the text. 
     Result: The cursor is placed at the end of the line.
     Expected result: The cursor is positioned at the beginning of the line.

  Scenario 2:

     1. Make the alignment right margin.
     2. Type a short line, shorter than half the widget width.
     3. Press the mouse in the text.
     Result: The cursor is not moved.
     Expected result: The cursor should move

The following patch seems to solve the problem:

--- gtk+-1.3.9.org/gtk/gtktextlayout.c	Mon Sep 24 20:10:40 2001
+++ gtk+-1.3.9/gtk/gtktextlayout.c	Sun Sep 30 18:53:47 2001
@@ -2118,11 +2118,15 @@
 
   /* Adjust pixels to be on-screen. This gives nice
      behavior if the user is dragging with a pointer grab.
+
+     This doesn't work and has been erased... 
   */
+  /*
   if (x < 0)
     x = 0;
   if (x > layout->width)
     x = layout->width;
+  */
 
   get_line_at_y (layout, y, &line, &line_top);
 
@@ -2134,14 +2138,20 @@
   /* We clamp y to the area of the actual layout so that the layouts
    * hit testing works OK on the space above and below the layout
    */
-  y = CLAMP (y, 0, display->height - display->top_margin - display->bottom_margin - 1);
-
-  if (!pango_layout_xy_to_index (display->layout, x * PANGO_SCALE, y * PANGO_SCALE,
-                                 &byte_index, &trailing))
+  /* If we are below the layout, position the cursor at the last character
+     of the line.
+   */
+  if (y > display->height - display->top_margin - display->bottom_margin)
     {
       byte_index = _gtk_text_line_byte_count (line);
       trailing = 0;
     }
+  else 
+    /* Ignore the "outside" return value from pango. Pango is doing the right
+       thing even if we are outside the layout in the x-direction. */
+    pango_layout_xy_to_index (display->layout, x * PANGO_SCALE, y * PANGO_SCALE,
+			      &byte_index, &trailing);
+
 
   line_display_index_to_iter (layout, display, target_iter, byte_index, trailing);
 
--
                                                        ___   ___
                                                      /  o  \   o \
Dov Grobgeld                                         ( o  o  ) o   |
The Weizmann Institute of Science, Israel             \  o  /o  o /
"Where the tree of wisdom carries oranges"              | |   | |
                                                       _| |_ _| |_





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