summaryrefslogtreecommitdiff
path: root/gtk/gtktextlayout.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2016-02-10 00:01:54 -0500
committerMatthias Clasen <mclasen@redhat.com>2016-02-10 00:01:54 -0500
commita3a5cf1087278e3e727a74c75f2532bcb14ddca6 (patch)
treef57bf8d9eec815c01d851962087ba7b2d6faa7a7 /gtk/gtktextlayout.c
parent019dab7c38a0891f494749e9e8fb27c30e8a5f25 (diff)
downloadgtk+-a3a5cf1087278e3e727a74c75f2532bcb14ddca6.tar.gz
text view: Improve tag pointer tracking
A problem that has been observed in polari is that links in tags are clickable all the way into the margin. This problem is caused by gtk_text_view_get_iter_at_position ignoring the return value of pango_layout_xy_to_index. Instead, pass it back as a boolean return value. This is technically an API break, but we've allowed ourselves to change return types from void to gboolean before.
Diffstat (limited to 'gtk/gtktextlayout.c')
-rw-r--r--gtk/gtktextlayout.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/gtk/gtktextlayout.c b/gtk/gtktextlayout.c
index 185c1a0de7..6adcdc5ae7 100644
--- a/gtk/gtktextlayout.c
+++ b/gtk/gtktextlayout.c
@@ -362,7 +362,7 @@ gtk_text_layout_default_style_changed (GtkTextLayout *layout)
}
void
-gtk_text_layout_set_default_style (GtkTextLayout *layout,
+gtk_text_layout_set_default_style (GtkTextLayout *layout,
GtkTextAttributes *values)
{
g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
@@ -2736,32 +2736,37 @@ gtk_text_layout_get_line_at_y (GtkTextLayout *layout,
gtk_text_layout_get_iter_at_line (layout, target_iter, line, 0);
}
-void
+gboolean
gtk_text_layout_get_iter_at_pixel (GtkTextLayout *layout,
GtkTextIter *target_iter,
- gint x,
- gint y)
+ gint x,
+ gint y)
{
gint trailing;
+ gboolean inside;
+
+ inside = gtk_text_layout_get_iter_at_position (layout, target_iter, &trailing, x, y);
- gtk_text_layout_get_iter_at_position (layout, target_iter, &trailing, x, y);
+ gtk_text_iter_forward_chars (target_iter, trailing);
- gtk_text_iter_forward_chars (target_iter, trailing);
+ return inside;
}
-void gtk_text_layout_get_iter_at_position (GtkTextLayout *layout,
- GtkTextIter *target_iter,
- gint *trailing,
- gint x,
- gint y)
+gboolean
+gtk_text_layout_get_iter_at_position (GtkTextLayout *layout,
+ GtkTextIter *target_iter,
+ gint *trailing,
+ gint x,
+ gint y)
{
GtkTextLine *line;
gint byte_index;
gint line_top;
GtkTextLineDisplay *display;
+ gboolean inside;
- g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
- g_return_if_fail (target_iter != NULL);
+ g_return_val_if_fail (GTK_IS_TEXT_LAYOUT (layout), FALSE);
+ g_return_val_if_fail (target_iter != NULL, FALSE);
get_line_at_y (layout, y, &line, &line_top);
@@ -2778,6 +2783,8 @@ void gtk_text_layout_get_iter_at_position (GtkTextLayout *layout,
byte_index = _gtk_text_line_byte_count (line);
if (trailing)
*trailing = 0;
+
+ inside = FALSE;
}
else
{
@@ -2785,13 +2792,15 @@ void gtk_text_layout_get_iter_at_position (GtkTextLayout *layout,
* 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);
+ inside = 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, 0);
gtk_text_layout_free_line_display (layout, display);
+
+ return inside;
}