From 2209e174328790b140bb4a43c53fcdf7436d4a75 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 16 Dec 2008 12:25:45 +0000 Subject: [PATCH] Fix ClutterText::get_selection() The clutter_text_get_selection() function was not checking the passed argument, and was still accessing the contents of the Text actor using clutter_text_get_text(). This commit also adds the last few gtk-doc annotations missing from ClutterText. --- clutter/clutter-text.c | 59 +++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index f6c354ef6..d9c813790 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -2383,19 +2383,30 @@ clutter_text_get_cursor_color (ClutterText *self, *color = priv->cursor_color; } +/** + * clutter_text_get_selection: + * @self: a #ClutterText + * + * Retrieves the currently selected text. + * + * Return value: a newly allocated string containing the currently + * selected text, or %NULL. Use g_free() to free the returned + * string. + * + * Since: 1.0 + */ gchar * -clutter_text_get_selection (ClutterText *text) +clutter_text_get_selection (ClutterText *self) { ClutterTextPrivate *priv; - const gchar *utf8 = clutter_text_get_text (text); - gchar *str; - gint len; - gint start_index; - gint end_index; - gint start_offset; - gint end_offset; + gchar *str; + gint len; + gint start_index, end_index; + gint start_offset, end_offset; - priv = text->priv; + g_return_val_if_fail (CLUTTER_IS_TEXT (self), NULL); + + priv = self->priv; start_index = priv->position; end_index = priv->selection_bound; @@ -2410,15 +2421,28 @@ clutter_text_get_selection (ClutterText *text) end_index = temp; } - start_offset = offset_to_bytes (utf8, start_index); - end_offset = offset_to_bytes (utf8, end_index); + start_offset = offset_to_bytes (priv->text, start_index); + end_offset = offset_to_bytes (priv->text, end_index); len = end_offset - start_offset; str = g_malloc (len + 1); - g_utf8_strncpy (str, utf8 + start_offset, end_index-start_index); + g_utf8_strncpy (str, priv->text + start_offset, end_index - start_index); + return str; } +/** + * clutter_text_set_selection_bound: + * @self: a #ClutterText + * @selection_bound: the position of the end of the selection, in characters + * + * Sets the other end of the selection, starting from the current + * cursor position. + * + * If @selection_bound is -1, the selection unset. + * + * Since: 1.0 + */ void clutter_text_set_selection_bound (ClutterText *self, gint selection_bound) @@ -2440,6 +2464,17 @@ clutter_text_set_selection_bound (ClutterText *self, } } +/** + * clutter_text_get_selection_bound: + * @self: a #ClutterText + * + * Retrieves the other end of the selection of a #ClutterText actor, + * in characters from the current cursor position. + * + * Return value: the position of the other end of the selection + * + * Since: 1.0 + */ gint clutter_text_get_selection_bound (ClutterText *self) {