[gtk/wip/chergert/textview-widgets] textview: rename translate coordinate functions
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/textview-widgets] textview: rename translate coordinate functions
- Date: Wed, 18 Sep 2019 20:38:08 +0000 (UTC)
commit 437cfabf521374a5a26fd3516129c4177f17aa2c
Author: Christian Hergert <chergert redhat com>
Date: Wed Sep 18 13:37:54 2019 -0700
textview: rename translate coordinate functions
This changes the translate coord functions to remove the TextWindowType
eventually.
demos/gtk-demo/hypertext.c | 3 +-
demos/node-editor/node-editor-window.c | 3 +-
gtk/a11y/gtktextviewaccessible.c | 6 +-
gtk/gtkaboutdialog.c | 8 +-
gtk/gtktextutil.c | 22 +++-
gtk/gtktextview.c | 224 ++++++++-------------------------
gtk/gtktextview.h | 28 ++---
gtk/inspector/css-editor.c | 3 +-
tests/testtooltips.c | 3 +-
9 files changed, 91 insertions(+), 209 deletions(-)
---
diff --git a/demos/gtk-demo/hypertext.c b/demos/gtk-demo/hypertext.c
index b053ed581f..fbea7a4c4c 100644
--- a/demos/gtk-demo/hypertext.c
+++ b/demos/gtk-demo/hypertext.c
@@ -149,8 +149,7 @@ released_cb (GtkGestureClick *gesture,
if (gtk_gesture_single_get_button (GTK_GESTURE_SINGLE (gesture)) > 1)
return;
- gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
- GTK_TEXT_WINDOW_WIDGET,
+ gtk_text_view_widget_to_buffer_coords (GTK_TEXT_VIEW (text_view),
x, y, &tx, &ty);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
diff --git a/demos/node-editor/node-editor-window.c b/demos/node-editor/node-editor-window.c
index 9e880354f3..fdb18166bb 100644
--- a/demos/node-editor/node-editor-window.c
+++ b/demos/node-editor/node-editor-window.c
@@ -288,8 +288,7 @@ text_view_query_tooltip_cb (GtkWidget *widget,
{
gint bx, by, trailing;
- gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (self->text_view), GTK_TEXT_WINDOW_TEXT,
- x, y, &bx, &by);
+ gtk_text_view_widget_to_buffer_coords (GTK_TEXT_VIEW (self->text_view), x, y, &bx, &by);
gtk_text_view_get_iter_at_position (GTK_TEXT_VIEW (self->text_view), &iter, &trailing, bx, by);
}
diff --git a/gtk/a11y/gtktextviewaccessible.c b/gtk/a11y/gtktextviewaccessible.c
index 67dce5bd0f..c13026add7 100644
--- a/gtk/a11y/gtktextviewaccessible.c
+++ b/gtk/a11y/gtktextviewaccessible.c
@@ -462,8 +462,7 @@ gtk_text_view_accessible_get_offset_at_point (AtkText *text,
view = GTK_TEXT_VIEW (widget);
- gtk_text_view_window_to_buffer_coords (view, GTK_TEXT_WINDOW_WIDGET,
- x, y, &buff_x, &buff_y);
+ gtk_text_view_widget_to_buffer_coords (view, x, y, &buff_x, &buff_y);
gtk_text_view_get_visible_rect (view, &rect);
/* Clamp point to visible rectangle */
@@ -513,8 +512,7 @@ gtk_text_view_accessible_get_character_extents (AtkText *text,
*height = rectangle.height;
*width = rectangle.width;
- gtk_text_view_buffer_to_surface_coords (view, GTK_TEXT_WINDOW_WIDGET,
- rectangle.x, rectangle.y, x, y);
+ gtk_text_view_buffer_to_widget_coords (view, rectangle.x, rectangle.y, x, y);
if (coords != ATK_XY_WINDOW)
{
*x = 0;
diff --git a/gtk/gtkaboutdialog.c b/gtk/gtkaboutdialog.c
index 4b38d343f4..4bc9ad024f 100644
--- a/gtk/gtkaboutdialog.c
+++ b/gtk/gtkaboutdialog.c
@@ -1960,9 +1960,7 @@ text_view_released (GtkGestureClick *gesture,
if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
return;
- gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
- GTK_TEXT_WINDOW_WIDGET,
- x, y, &tx, &ty);
+ gtk_text_view_widget_to_buffer_coords (GTK_TEXT_VIEW (text_view), x, y, &tx, &ty);
gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, tx, ty);
@@ -2019,9 +2017,7 @@ text_view_motion (GtkEventControllerMotion *motion,
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (motion));
- gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (widget),
- GTK_TEXT_WINDOW_WIDGET,
- x, y, &tx, &ty);
+ gtk_text_view_widget_to_buffer_coords (GTK_TEXT_VIEW (widget), x, y, &tx, &ty);
set_cursor_if_appropriate (about, GTK_TEXT_VIEW (widget), tx, ty);
}
diff --git a/gtk/gtktextutil.c b/gtk/gtktextutil.c
index 200f87285c..97ea569d5c 100644
--- a/gtk/gtktextutil.c
+++ b/gtk/gtktextutil.c
@@ -158,6 +158,24 @@ set_attributes_from_style (GtkStyleContext *context,
gtk_style_context_get (context, "font", &values->font, NULL);
}
+static gint
+get_gutter_width (GtkTextView *text_view,
+ GtkTextWindowType window_type)
+{
+ GtkWidget *gutter;
+ GtkAllocation alloc;
+
+ gutter = gtk_text_view_get_gutter (text_view, window_type);
+
+ if (gutter != NULL)
+ {
+ gtk_widget_get_allocation (gutter, &alloc);
+ return alloc.width;
+ }
+
+ return 0;
+}
+
GdkPaintable *
gtk_text_util_create_rich_drag_icon (GtkWidget *widget,
GtkTextBuffer *buffer,
@@ -208,8 +226,8 @@ gtk_text_util_create_rich_drag_icon (GtkWidget *widget,
if (GTK_IS_TEXT_VIEW (widget))
{
layout_width = layout_width
- - gtk_text_view_get_border_window_size (GTK_TEXT_VIEW (widget), GTK_TEXT_WINDOW_LEFT)
- - gtk_text_view_get_border_window_size (GTK_TEXT_VIEW (widget), GTK_TEXT_WINDOW_RIGHT);
+ - get_gutter_width (GTK_TEXT_VIEW (widget), GTK_TEXT_WINDOW_LEFT)
+ - get_gutter_width (GTK_TEXT_VIEW (widget), GTK_TEXT_WINDOW_RIGHT);
}
style->direction = gtk_widget_get_direction (widget);
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index d8f71c4983..fb33317885 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -2015,7 +2015,7 @@ gtk_text_view_get_buffer (GtkTextView *text_view)
* cursor’s offset within the preedit sequence.
*
* The rectangle position is in buffer coordinates; use
- * gtk_text_view_buffer_to_surface_coords() to convert these
+ * gtk_text_view_buffer_to_widget_coords() to convert these
* coordinates to coordinates for one of the windows in the text view.
**/
void
@@ -2053,7 +2053,7 @@ gtk_text_view_get_cursor_locations (GtkTextView *text_view,
* 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().
+ * gtk_text_view_widget_to_buffer_coords().
*
* Returns: %TRUE if the position is over text
*/
@@ -2087,7 +2087,7 @@ gtk_text_view_get_iter_at_location (GtkTextView *text_view,
* 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().
+ * gtk_text_view_widget_to_buffer_coords().
*
* Note that this is different from gtk_text_view_get_iter_at_location(),
* which returns cursor locations, i.e. positions between
@@ -2118,7 +2118,7 @@ gtk_text_view_get_iter_at_position (GtkTextView *text_view,
*
* Gets a rectangle which roughly contains the character at @iter.
* The rectangle position is in buffer coordinates; use
- * gtk_text_view_buffer_to_surface_coords() to convert these
+ * gtk_text_view_buffer_to_widget_coords() to convert these
* coordinates to coordinates for one of the windows in the text view.
**/
void
@@ -2143,7 +2143,7 @@ gtk_text_view_get_iter_location (GtkTextView *text_view,
*
* Gets the y coordinate of the top of the line containing @iter,
* and the height of the line. The coordinate is a buffer coordinate;
- * convert to window coordinates with gtk_text_view_buffer_to_surface_coords().
+ * convert to window coordinates with gtk_text_view_buffer_to_widget_coords().
**/
void
gtk_text_view_get_line_yrange (GtkTextView *text_view,
@@ -2171,7 +2171,7 @@ gtk_text_view_get_line_yrange (GtkTextView *text_view,
*
* Gets the #GtkTextIter at the start of the line containing
* the coordinate @y. @y is in buffer coordinates, convert from
- * window coordinates with gtk_text_view_window_to_buffer_coords().
+ * window coordinates with gtk_text_view_widget_to_buffer_coords().
* If non-%NULL, @line_top will be filled with the coordinate of the top
* edge of the line.
**/
@@ -2793,7 +2793,7 @@ gtk_text_view_move_mark_onscreen (GtkTextView *text_view,
*
* Fills @visible_rect with the currently-visible
* region of the buffer, in buffer coordinates. Convert to window coordinates
- * with gtk_text_view_buffer_to_surface_coords().
+ * with gtk_text_view_buffer_to_widget_coords().
**/
void
gtk_text_view_get_visible_rect (GtkTextView *text_view,
@@ -4781,8 +4781,9 @@ gtk_text_view_show_magnifier (GtkTextView *text_view,
gtk_text_view_get_iter_location (text_view, iter,
(GdkRectangle *) &rect);
rect.x = x + priv->xoffset;
- gtk_text_view_buffer_to_surface_coords (text_view, GTK_TEXT_WINDOW_TEXT,
- rect.x, rect.y, &rect.x, &rect.y);
+ gtk_text_view_buffer_to_widget_coords (text_view,
+ rect.x, rect.y,
+ &rect.x, &rect.y);
_text_window_to_widget_coords (text_view, &rect.x, &rect.y);
req.height = rect.height * N_LINES *
_gtk_magnifier_get_magnification (GTK_MAGNIFIER (priv->magnifier));
@@ -7170,8 +7171,7 @@ gtk_text_view_drag_gesture_update (GtkGestureDrag *gesture,
GtkTextIter iter;
gint buffer_x, buffer_y;
- gtk_text_view_window_to_buffer_coords (text_view,
- GTK_TEXT_WINDOW_TEXT,
+ gtk_text_view_widget_to_buffer_coords (text_view,
start_x, start_y,
&buffer_x,
&buffer_y);
@@ -7855,10 +7855,7 @@ gtk_text_view_drag_motion (GtkWidget *widget,
y > (target_rect.y + target_rect.height))
return FALSE; /* outside the text window, allow parent widgets to handle event */
- gtk_text_view_window_to_buffer_coords (text_view,
- GTK_TEXT_WINDOW_WIDGET,
- x, y,
- &bx, &by);
+ gtk_text_view_widget_to_buffer_coords (text_view, x, y, &bx, &by);
gtk_text_layout_get_iter_at_pixel (priv->layout,
&newplace,
@@ -8837,12 +8834,11 @@ gtk_text_view_do_popup (GtkTextView *text_view,
if (is_visible)
{
- gtk_text_view_buffer_to_surface_coords (text_view,
- GTK_TEXT_WINDOW_WIDGET,
- iter_location.x,
- iter_location.y,
- &iter_location.x,
- &iter_location.y);
+ gtk_text_view_buffer_to_widget_coords (text_view,
+ iter_location.x,
+ iter_location.y,
+ &iter_location.x,
+ &iter_location.y);
gtk_popover_set_pointing_to (GTK_POPOVER (priv->popup_menu), &iter_location);
}
@@ -9259,185 +9255,70 @@ gtk_text_view_get_css_node (GtkTextView *text_view,
}
/**
- * gtk_text_view_buffer_to_surface_coords:
+ * gtk_text_view_buffer_to_widget_coords:
* @text_view: a #GtkTextView
- * @win: a #GtkTextWindowType except #GTK_TEXT_WINDOW_PRIVATE
* @buffer_x: buffer x coordinate
* @buffer_y: buffer y coordinate
- * @window_x: (out) (allow-none): window x coordinate return location or %NULL
- * @window_y: (out) (allow-none): window y coordinate return location or %NULL
+ * @widget_x: (out) (allow-none): window x coordinate return location or %NULL
+ * @widget_y: (out) (allow-none): window y coordinate return location or %NULL
*
* Converts coordinate (@buffer_x, @buffer_y) to coordinates for the window
- * @win, and stores the result in (@window_x, @window_y).
+ * @win, and stores the result in (@widget_x, @widget_y).
*
* Note that you can’t convert coordinates for a nonexisting window.
**/
void
-gtk_text_view_buffer_to_surface_coords (GtkTextView *text_view,
- GtkTextWindowType win,
- gint buffer_x,
- gint buffer_y,
- gint *window_x,
- gint *window_y)
+gtk_text_view_buffer_to_widget_coords (GtkTextView *text_view,
+ gint buffer_x,
+ gint buffer_y,
+ gint *widget_x,
+ gint *widget_y)
{
- GtkTextViewPrivate *priv = text_view->priv;
-
g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
- buffer_x -= priv->xoffset;
- buffer_y -= priv->yoffset;
-
- switch (win)
- {
- case GTK_TEXT_WINDOW_WIDGET:
- buffer_x += priv->border_window_size.left;
- buffer_y += priv->border_window_size.top;
- break;
-
- case GTK_TEXT_WINDOW_TEXT:
- break;
-
- case GTK_TEXT_WINDOW_LEFT:
- buffer_x += priv->border_window_size.left;
- break;
-
- case GTK_TEXT_WINDOW_RIGHT:
- buffer_x -= text_window_get_width (priv->text_window);
- break;
-
- case GTK_TEXT_WINDOW_TOP:
- buffer_y += priv->border_window_size.top;
- break;
-
- case GTK_TEXT_WINDOW_BOTTOM:
- buffer_y -= text_window_get_height (priv->text_window);
- break;
+ buffer_x -= text_view->priv->xoffset;
+ buffer_x += text_view->priv->border_window_size.left;
- case GTK_TEXT_WINDOW_PRIVATE:
- g_warning ("%s: can't get coords for private windows", G_STRFUNC);
- break;
+ buffer_y -= text_view->priv->yoffset;
+ buffer_y += text_view->priv->border_window_size.top;
- default:
- g_warning ("%s: Unknown GtkTextWindowType", G_STRFUNC);
- break;
- }
+ if (widget_x != NULL)
+ *widget_x = buffer_x;
- if (window_x)
- *window_x = buffer_x;
- if (window_y)
- *window_y = buffer_y;
+ if (widget_y != NULL)
+ *widget_y = buffer_y;
}
/**
- * gtk_text_view_window_to_buffer_coords:
+ * gtk_text_view_widget_to_buffer_coords:
* @text_view: a #GtkTextView
- * @win: a #GtkTextWindowType except #GTK_TEXT_WINDOW_PRIVATE
- * @window_x: window x coordinate
- * @window_y: window y coordinate
+ * @widget_x: widget x coordinate
+ * @widget_y: widget y coordinate
* @buffer_x: (out) (allow-none): buffer x coordinate return location or %NULL
* @buffer_y: (out) (allow-none): buffer y coordinate return location or %NULL
*
- * Converts coordinates on the window identified by @win to buffer
- * coordinates, storing the result in (@buffer_x,@buffer_y).
+ * Converts coordinates @widget_x and @widget_y in the widgets coordinate
+ * space to buffer coordinates, storing the result in (@buffer_x,@buffer_y).
*
- * Note that you can’t convert coordinates for a nonexisting window.
+ * Since: 4.0
**/
void
-gtk_text_view_window_to_buffer_coords (GtkTextView *text_view,
- GtkTextWindowType win,
- gint window_x,
- gint window_y,
- gint *buffer_x,
- gint *buffer_y)
+gtk_text_view_widget_to_buffer_coords (GtkTextView *text_view,
+ gint widget_x,
+ gint widget_y,
+ gint *buffer_x,
+ gint *buffer_y)
{
- GtkTextViewPrivate *priv = text_view->priv;
-
g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
- switch (win)
- {
- case GTK_TEXT_WINDOW_WIDGET:
- window_x -= priv->border_window_size.left;
- window_y -= priv->border_window_size.top;
- break;
-
- case GTK_TEXT_WINDOW_TEXT:
- break;
-
- case GTK_TEXT_WINDOW_LEFT:
- window_x -= priv->border_window_size.left;
- break;
-
- case GTK_TEXT_WINDOW_RIGHT:
- window_x += text_window_get_width (priv->text_window);
- break;
-
- case GTK_TEXT_WINDOW_TOP:
- window_y -= priv->border_window_size.top;
- break;
-
- case GTK_TEXT_WINDOW_BOTTOM:
- window_y += text_window_get_height (priv->text_window);
- break;
-
- case GTK_TEXT_WINDOW_PRIVATE:
- g_warning ("%s: can't get coords for private windows", G_STRFUNC);
- break;
-
- default:
- g_warning ("%s: Unknown GtkTextWindowType", G_STRFUNC);
- break;
- }
-
- if (buffer_x)
- *buffer_x = window_x + priv->xoffset;
- if (buffer_y)
- *buffer_y = window_y + priv->yoffset;
-}
-
-/**
- * gtk_text_view_get_border_window_size:
- * @text_view: a #GtkTextView
- * @type: window to return size from
- *
- * Gets the width of the specified border window.
- *
- * @type must be one of %GTK_TEXT_WINDOW_LEFT, %GTK_TEXT_WINDOW_RIGHT,
- * %GTK_TEXT_WINDOW_TOP, or %GTK_TEXT_WINDOW_BOTTOM.
- *
- * Returns: width of window
- **/
-gint
-gtk_text_view_get_border_window_size (GtkTextView *text_view,
- GtkTextWindowType type)
-{
- GtkTextViewPrivate *priv = text_view->priv;
-
- g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0);
-
- switch (type)
- {
- case GTK_TEXT_WINDOW_LEFT:
- return priv->border_window_size.left;
-
- case GTK_TEXT_WINDOW_RIGHT:
- return priv->border_window_size.right;
-
- case GTK_TEXT_WINDOW_TOP:
- return priv->border_window_size.top;
+ widget_x -= text_view->priv->border_window_size.left;
+ widget_y -= text_view->priv->border_window_size.top;
- case GTK_TEXT_WINDOW_BOTTOM:
- return priv->border_window_size.bottom;
-
- case GTK_TEXT_WINDOW_PRIVATE:
- case GTK_TEXT_WINDOW_WIDGET:
- case GTK_TEXT_WINDOW_TEXT:
- default:
- g_warning ("Can only get size of left/right/top/bottom border windows with
gtk_text_view_get_border_window_size()");
- break;
- }
+ if (buffer_x != NULL)
+ *buffer_x = widget_x + text_view->priv->xoffset;
- return 0;
+ if (buffer_y != NULL)
+ *buffer_y = widget_y + text_view->priv->yoffset;
}
static void
@@ -10042,8 +9923,7 @@ gtk_text_view_insert_emoji (GtkTextView *text_view)
gtk_text_buffer_get_insert (buffer));
gtk_text_view_get_iter_location (text_view, &iter, (GdkRectangle *) &rect);
- gtk_text_view_buffer_to_surface_coords (text_view, GTK_TEXT_WINDOW_TEXT,
- rect.x, rect.y, &rect.x, &rect.y);
+ gtk_text_view_buffer_to_widget_coords (text_view, rect.x, rect.y, &rect.x, &rect.y);
_text_window_to_widget_coords (text_view, &rect.x, &rect.y);
gtk_popover_set_pointing_to (GTK_POPOVER (chooser), &rect);
diff --git a/gtk/gtktextview.h b/gtk/gtktextview.h
index 3877943a6e..ac5b970576 100644
--- a/gtk/gtktextview.h
+++ b/gtk/gtktextview.h
@@ -266,23 +266,17 @@ void gtk_text_view_get_line_at_y (GtkTextView *text_view
gint *line_top);
GDK_AVAILABLE_IN_ALL
-void gtk_text_view_buffer_to_surface_coords (GtkTextView *text_view,
- GtkTextWindowType win,
- gint buffer_x,
- gint buffer_y,
- gint *window_x,
- gint *window_y);
-GDK_AVAILABLE_IN_ALL
-void gtk_text_view_window_to_buffer_coords (GtkTextView *text_view,
- GtkTextWindowType win,
- gint window_x,
- gint window_y,
- gint *buffer_x,
- gint *buffer_y);
-
-GDK_AVAILABLE_IN_ALL
-gint gtk_text_view_get_border_window_size (GtkTextView *text_view,
- GtkTextWindowType type);
+void gtk_text_view_buffer_to_widget_coords (GtkTextView *text_view,
+ gint buffer_x,
+ gint buffer_y,
+ gint *widget_x,
+ gint *widget_y);
+GDK_AVAILABLE_IN_ALL
+void gtk_text_view_widget_to_buffer_coords (GtkTextView *text_view,
+ gint widget_x,
+ gint widget_y,
+ gint *buffer_x,
+ gint *buffer_y);
GDK_AVAILABLE_IN_ALL
gboolean gtk_text_view_forward_display_line (GtkTextView *text_view,
diff --git a/gtk/inspector/css-editor.c b/gtk/inspector/css-editor.c
index 16b156a4e5..ad23980d98 100644
--- a/gtk/inspector/css-editor.c
+++ b/gtk/inspector/css-editor.c
@@ -84,8 +84,7 @@ query_tooltip_cb (GtkWidget *widget,
{
gint bx, by, trailing;
- gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (ce->priv->view), GTK_TEXT_WINDOW_TEXT,
- x, y, &bx, &by);
+ gtk_text_view_widget_to_buffer_coords (GTK_TEXT_VIEW (ce->priv->view), x, y, &bx, &by);
gtk_text_view_get_iter_at_position (GTK_TEXT_VIEW (ce->priv->view), &iter, &trailing, bx, by);
}
diff --git a/tests/testtooltips.c b/tests/testtooltips.c
index 04eda125e1..d2055229ec 100644
--- a/tests/testtooltips.c
+++ b/tests/testtooltips.c
@@ -104,8 +104,7 @@ query_tooltip_text_view_cb (GtkWidget *widget,
{
gint bx, by, trailing;
- gtk_text_view_window_to_buffer_coords (text_view, GTK_TEXT_WINDOW_TEXT,
- x, y, &bx, &by);
+ gtk_text_view_widget_to_buffer_coords (text_view, x, y, &bx, &by);
gtk_text_view_get_iter_at_position (text_view, &iter, &trailing, bx, by);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]