[gtk+/touch-text-selection] Fix calculation of selection_bound location



commit 291ff93a6bf19500395f2afa8688bc6af53d831b
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Sep 2 17:15:18 2012 -0400

    Fix calculation of selection_bound location
    
    _gtk_entry_get_selection_bound_location was not converting
    priv->selection_bound to an index before feeding it to pango.
    This was showing up as wrong handle positions when dragging
    selections in password entries.

 gtk/gtkentry.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index e642cd1..ed92815 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -3913,9 +3913,13 @@ _gtk_entry_get_selection_bound_location (GtkEntry *entry)
   PangoLayout *layout;
   PangoRectangle pos;
   gint x;
+  const gchar *text;
+  gint index;
 
   layout = gtk_entry_ensure_layout (entry, FALSE);
-  pango_layout_index_to_pos (layout, priv->selection_bound, &pos);
+  text = pango_layout_get_text (layout);
+  index = g_utf8_offset_to_pointer (text, priv->selection_bound) - text;
+  pango_layout_index_to_pos (layout, index, &pos);
 
   if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
     x = (pos.x + pos.width) / PANGO_SCALE;



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