mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-25 05:01:09 +00:00
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.
This commit is contained in:
parent
019dab7c38
commit
a3a5cf1087
@ -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;
|
||||
|
||||
gtk_text_layout_get_iter_at_position (layout, target_iter, &trailing, x, y);
|
||||
inside = 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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
gboolean 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_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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user