summaryrefslogtreecommitdiff
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
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.
-rw-r--r--gtk/gtktextlayout.c39
-rw-r--r--gtk/gtktextlayout.h20
-rw-r--r--gtk/gtktextview.c48
-rw-r--r--gtk/gtktextview.h4
4 files changed, 61 insertions, 50 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;
}
diff --git a/gtk/gtktextlayout.h b/gtk/gtktextlayout.h
index 2565b648cb..ba5318cf21 100644
--- a/gtk/gtktextlayout.h
+++ b/gtk/gtktextlayout.h
@@ -345,16 +345,16 @@ void gtk_text_layout_get_line_at_y (GtkTextLayout *layout,
gint y,
gint *line_top);
GDK_AVAILABLE_IN_ALL
-void gtk_text_layout_get_iter_at_pixel (GtkTextLayout *layout,
- GtkTextIter *iter,
- gint x,
- gint y);
-GDK_AVAILABLE_IN_ALL
-void gtk_text_layout_get_iter_at_position (GtkTextLayout *layout,
- GtkTextIter *iter,
- gint *trailing,
- gint x,
- gint y);
+gboolean gtk_text_layout_get_iter_at_pixel (GtkTextLayout *layout,
+ GtkTextIter *iter,
+ gint x,
+ gint y);
+GDK_AVAILABLE_IN_ALL
+gboolean gtk_text_layout_get_iter_at_position (GtkTextLayout *layout,
+ GtkTextIter *iter,
+ gint *trailing,
+ gint x,
+ gint y);
GDK_AVAILABLE_IN_ALL
void gtk_text_layout_invalidate (GtkTextLayout *layout,
const GtkTextIter *start,
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index c2d651b0cf..87039284fe 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -2091,20 +2091,21 @@ gtk_text_view_get_cursor_locations (GtkTextView *text_view,
* currently-displayed portion. If you have coordinates from an
* event, you have to convert those to buffer coordinates with
* gtk_text_view_window_to_buffer_coords().
- **/
-void
+ *
+ * Returns: %TRUE if the position is over text
+ */
+gboolean
gtk_text_view_get_iter_at_location (GtkTextView *text_view,
GtkTextIter *iter,
gint x,
gint y)
{
- g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
- g_return_if_fail (iter != NULL);
+ g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
+ g_return_val_if_fail (iter != NULL, FALSE);
gtk_text_view_ensure_layout (text_view);
-
- gtk_text_layout_get_iter_at_pixel (text_view->priv->layout,
- iter, x, y);
+
+ return gtk_text_layout_get_iter_at_pixel (text_view->priv->layout, iter, x, y);
}
/**
@@ -2113,38 +2114,39 @@ gtk_text_view_get_iter_at_location (GtkTextView *text_view,
* @iter: (out): a #GtkTextIter
* @trailing: (out) (allow-none): if non-%NULL, location to store an integer indicating where
* in the grapheme the user clicked. It will either be
- * zero, or the number of characters in the grapheme.
+ * zero, or the number of characters in the grapheme.
* 0 represents the trailing edge of the grapheme.
* @x: x position, in buffer coordinates
* @y: y position, in buffer coordinates
*
- * Retrieves the iterator pointing to the character at buffer
- * coordinates @x and @y. Buffer coordinates are coordinates for
- * the entire buffer, not just the currently-displayed portion.
- * If you have coordinates from an event, you have to convert
- * those to buffer coordinates with
+ * Retrieves the iterator pointing to the character at buffer
+ * coordinates @x and @y. Buffer coordinates are coordinates for
+ * the entire buffer, not just the currently-displayed portion.
+ * If you have coordinates from an event, you have to convert
+ * those to buffer coordinates with
* gtk_text_view_window_to_buffer_coords().
*
* Note that this is different from gtk_text_view_get_iter_at_location(),
* which returns cursor locations, i.e. positions between
* characters.
*
+ * Returns: %TRUE if the position is over text
+ *
* Since: 2.6
**/
-void
+gboolean
gtk_text_view_get_iter_at_position (GtkTextView *text_view,
- GtkTextIter *iter,
- gint *trailing,
- gint x,
- gint y)
+ GtkTextIter *iter,
+ gint *trailing,
+ gint x,
+ gint y)
{
- g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
- g_return_if_fail (iter != NULL);
+ g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
+ g_return_val_if_fail (iter != NULL, FALSE);
gtk_text_view_ensure_layout (text_view);
-
- gtk_text_layout_get_iter_at_position (text_view->priv->layout,
- iter, trailing, x, y);
+
+ return gtk_text_layout_get_iter_at_position (text_view->priv->layout, iter, trailing, x, y);
}
/**
diff --git a/gtk/gtktextview.h b/gtk/gtktextview.h
index 432e7b786c..0cf15c6f19 100644
--- a/gtk/gtktextview.h
+++ b/gtk/gtktextview.h
@@ -259,12 +259,12 @@ void gtk_text_view_get_iter_location (GtkTextView *text_view,
const GtkTextIter *iter,
GdkRectangle *location);
GDK_AVAILABLE_IN_ALL
-void gtk_text_view_get_iter_at_location (GtkTextView *text_view,
+gboolean gtk_text_view_get_iter_at_location (GtkTextView *text_view,
GtkTextIter *iter,
gint x,
gint y);
GDK_AVAILABLE_IN_ALL
-void gtk_text_view_get_iter_at_position (GtkTextView *text_view,
+gboolean gtk_text_view_get_iter_at_position (GtkTextView *text_view,
GtkTextIter *iter,
gint *trailing,
gint x,