From d0ad5a8abb732ae9b80d036116b6c2c1e5bef985 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 6 May 2009 17:18:12 +0100 Subject: [PATCH] [text] Expose position_to_coords() The clutter_text_position_to_coords() is useful for ClutterText subclasses. See bug: http://bugzilla.openedhand.com/show_bug.cgi?id=1521 Based on a patch by: Raymond Liu --- clutter/clutter-text.c | 16 ++++++++++++---- clutter/clutter-text.h | 5 +++++ doc/reference/clutter/clutter-sections.txt | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index b0b1a194b..0f56462f5 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -469,7 +469,7 @@ clutter_text_coords_to_position (ClutterText *text, return index_ + trailing; } -/* +/** * clutter_text_position_to_coords: * @self: a #ClutterText * @position: position in characters @@ -480,19 +480,28 @@ clutter_text_coords_to_position (ClutterText *text, * Retrieves the coordinates of the given @position. * * Return value: %TRUE if the conversion was successful + * + * Since: 1.0 */ -static gboolean +gboolean clutter_text_position_to_coords (ClutterText *self, gint position, gfloat *x, gfloat *y, gfloat *line_height) { - ClutterTextPrivate *priv = self->priv; + ClutterTextPrivate *priv; PangoRectangle rect; gint password_char_bytes = 1; gint index_; + g_return_val_if_fail (CLUTTER_IS_TEXT (self), FALSE); + + priv = self->priv; + + if (position < -1 || position > priv->n_chars) + return FALSE; + if (priv->password_char != 0) password_char_bytes = g_unichar_to_utf8 (priv->password_char, NULL); @@ -527,7 +536,6 @@ clutter_text_position_to_coords (ClutterText *self, if (line_height) *line_height = CLUTTER_UNITS_FROM_PANGO_UNIT (rect.height); - /* FIXME: should return false if coords were outside text */ return TRUE; } diff --git a/clutter/clutter-text.h b/clutter/clutter-text.h index 01b058cf7..f34ff967a 100644 --- a/clutter/clutter-text.h +++ b/clutter/clutter-text.h @@ -198,6 +198,11 @@ void clutter_text_set_single_line_mode (ClutterText *sel gboolean clutter_text_get_single_line_mode (ClutterText *self); gboolean clutter_text_activate (ClutterText *self); +gboolean clutter_text_position_to_coords (ClutterText *self, + gint position, + gfloat *x, + gfloat *y, + gfloat *line_height); G_END_DECLS diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt index e8c8a46ad..af7e7feea 100644 --- a/doc/reference/clutter/clutter-sections.txt +++ b/doc/reference/clutter/clutter-sections.txt @@ -1599,6 +1599,7 @@ clutter_text_get_cursor_size clutter_text_activate +clutter_text_position_to_coords CLUTTER_IS_TEXT