diff options
author | Lionel Landwerlin <llandwerlin@gmail.com> | 2013-07-09 16:46:35 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2013-11-20 23:19:53 +0000 |
commit | fe991ac7c0e257e19d34aa3b9800323aa828970a (patch) | |
tree | 4e2c93d8d6890bfa2d629dc8300d546c59742146 | |
parent | 2fec31a5aa89c4e1d877f6252d43309f806f39f6 (diff) | |
download | clutter-fe991ac7c0e257e19d34aa3b9800323aa828970a.tar.gz |
clutter-text: prevent text buffer creation if not needed
When allocating or asking for preferred width/height on a ClutterText,
it can notify a change on buffer/text/max-length if no text has been
set.
https://bugzilla.gnome.org/show_bug.cgi?id=703882
(cherry picked from commit eed94960562693e489354afb2a78a355301515fa)
Signed-off-by: Emmanuele Bassi <ebassi@gnome.org>
-rw-r--r-- | clutter/clutter-text.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index 0cfb63f69..b5d1198d7 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -341,6 +341,18 @@ clutter_text_clear_selection (ClutterText *self) } } +static gboolean +clutter_text_is_empty (ClutterText *self) +{ + if (self->priv->buffer == NULL) + return TRUE; + + if (clutter_text_buffer_get_length (self->priv->buffer) == 0) + return TRUE; + + return FALSE; +} + static gchar * clutter_text_get_display_text (ClutterText *self) { @@ -348,6 +360,13 @@ clutter_text_get_display_text (ClutterText *self) ClutterTextBuffer *buffer; const gchar *text; + /* short-circuit the case where the buffer is unset or it's empty, + * to avoid creating a pointless TextBuffer and emitting + * notifications with it + */ + if (clutter_text_is_empty (self)) + return g_strdup (""); + buffer = get_buffer (self); text = clutter_text_buffer_get_text (buffer); |