diff --git a/clutter/clutter-entry.c b/clutter/clutter-entry.c deleted file mode 100644 index 1ae661eda..000000000 --- a/clutter/clutter-entry.c +++ /dev/null @@ -1,1795 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Authored By Matthew Allum - * Neil Jagdish Patel - * - * Copyright (C) 2006 OpenedHand - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/** - * SECTION:clutter-entry - * @short_description: A single line text entry actor - * - * #ClutterEntry is a #ClutterTexture that allows single line text entry. - * - * #ClutterEntry is available since Clutter 0.4. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include "clutter-entry.h" - -#include "clutter-debug.h" -#include "clutter-enum-types.h" -#include "clutter-keysyms.h" -#include "clutter-main.h" -#include "clutter-marshal.h" -#include "clutter-private.h" -#include "clutter-rectangle.h" -#include "clutter-units.h" - -#include "cogl-pango.h" - -#define DEFAULT_FONT_NAME "Sans 10" -#define ENTRY_CURSOR_WIDTH 1 -#define ENTRY_PADDING 5 - -G_DEFINE_TYPE (ClutterEntry, clutter_entry, CLUTTER_TYPE_ACTOR); - -/* Probably move into main */ -static PangoContext *_context = NULL; - -static const ClutterColor default_text_color = { 0, 0, 0, 255 }; - -enum -{ - PROP_0, - - PROP_FONT_NAME, - PROP_TEXT, - PROP_COLOR, - PROP_ALIGNMENT, /* FIXME */ - PROP_POSITION, - PROP_CURSOR, - PROP_TEXT_VISIBLE, - PROP_MAX_LENGTH, - PROP_ENTRY_PADDING, - PROP_X_ALIGN -}; - -enum -{ - TEXT_CHANGED, - CURSOR_EVENT, - ACTIVATE, - - LAST_SIGNAL -}; - -static guint entry_signals[LAST_SIGNAL] = { 0, }; - -#define CLUTTER_ENTRY_GET_PRIVATE(obj) \ -(G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_ENTRY, ClutterEntryPrivate)) - -struct _ClutterEntryPrivate -{ - PangoContext *context; - PangoFontDescription *desc; - - ClutterColor fgcol; - - gchar *text; - gchar *font_name; - gboolean text_visible; - gunichar priv_char; - - gint extents_width; - gint extents_height; - - gint width; - gint n_chars; /* number of chars */ - gint n_bytes; /* number of bytes */ - - guint alignment : 2; - guint wrap : 1; - guint use_underline : 1; - guint use_markup : 1; - guint ellipsize : 3; - guint single_line_mode : 1; - guint wrap_mode : 3; - gint position; - gint text_x; - gint max_length; - gint entry_padding; - gdouble x_align; - - PangoAttrList *attrs; - PangoAttrList *effective_attrs; - PangoLayout *layout; - gint width_chars; - - ClutterGeometry cursor_pos; - gboolean show_cursor; -}; - -static void -clutter_entry_set_entry_padding (ClutterEntry *entry, - guint padding) -{ - ClutterEntryPrivate *priv = entry->priv; - - if (priv->entry_padding != padding) - { - priv->entry_padding = padding; - - if (CLUTTER_ACTOR_IS_VISIBLE (entry)) - clutter_actor_queue_redraw (CLUTTER_ACTOR (entry)); - - g_object_notify (G_OBJECT (entry), "entry-padding"); - } -} - -static void -clutter_entry_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - ClutterEntry *entry; - ClutterEntryPrivate *priv; - - entry = CLUTTER_ENTRY (object); - priv = entry->priv; - - switch (prop_id) - { - case PROP_FONT_NAME: - clutter_entry_set_font_name (entry, g_value_get_string (value)); - break; - case PROP_TEXT: - clutter_entry_set_text (entry, g_value_get_string (value)); - break; - case PROP_COLOR: - clutter_entry_set_color (entry, clutter_value_get_color (value)); - break; - case PROP_ALIGNMENT: - clutter_entry_set_alignment (entry, g_value_get_enum (value)); - break; - case PROP_POSITION: - clutter_entry_set_cursor_position (entry, g_value_get_int (value)); - break; - case PROP_CURSOR: - clutter_entry_set_visible_cursor (entry, g_value_get_boolean (value)); - break; - case PROP_TEXT_VISIBLE: - clutter_entry_set_visibility (entry, g_value_get_boolean (value)); - break; - case PROP_MAX_LENGTH: - clutter_entry_set_max_length (entry, g_value_get_int (value)); - break; - case PROP_ENTRY_PADDING: - clutter_entry_set_entry_padding (entry, g_value_get_uint (value)); - break; - case PROP_X_ALIGN: - entry->priv->x_align = g_value_get_double (value); - clutter_actor_queue_redraw (CLUTTER_ACTOR (object)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -clutter_entry_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - ClutterEntry *entry; - ClutterEntryPrivate *priv; - - entry = CLUTTER_ENTRY(object); - priv = entry->priv; - - switch (prop_id) - { - case PROP_FONT_NAME: - g_value_set_string (value, priv->font_name); - break; - case PROP_TEXT: - g_value_set_string (value, priv->text); - break; - case PROP_COLOR: - clutter_value_set_color (value, &priv->fgcol); - break; - case PROP_ALIGNMENT: - g_value_set_enum (value, priv->alignment); - break; - case PROP_POSITION: - g_value_set_int (value, priv->position); - break; - case PROP_CURSOR: - g_value_set_boolean (value, priv->show_cursor); - break; - case PROP_TEXT_VISIBLE: - g_value_set_boolean (value, priv->text_visible); - break; - case PROP_MAX_LENGTH: - g_value_set_int (value, priv->max_length); - break; - case PROP_ENTRY_PADDING: - g_value_set_uint (value, priv->entry_padding); - break; - case PROP_X_ALIGN: - g_value_set_double (value, priv->x_align); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -clutter_entry_ensure_layout (ClutterEntry *entry, gint width) -{ - ClutterEntryPrivate *priv; - - priv = entry->priv; - - if (!priv->layout) - { - priv->layout = pango_layout_new (_context); - - if (priv->effective_attrs) - pango_layout_set_attributes (priv->layout, priv->effective_attrs); - - pango_layout_set_alignment (priv->layout, priv->alignment); - pango_layout_set_ellipsize (priv->layout, priv->ellipsize); - pango_layout_set_single_paragraph_mode (priv->layout, - priv->single_line_mode); - - pango_layout_set_font_description (priv->layout, priv->desc); - - if (priv->text_visible) - pango_layout_set_text (priv->layout, priv->text, priv->n_bytes); - else - { - GString *str = g_string_sized_new (priv->n_bytes); - gunichar invisible_char; - gchar buf[7]; - gint char_len, i; - - if (priv->priv_char != 0) - invisible_char = priv->priv_char; - else - invisible_char = '*'; - - /* we need to convert the string built of invisible characters - * into UTF-8 for it to be fed to the Pango layout - */ - memset (buf, 0, sizeof (buf)); - char_len = g_unichar_to_utf8 (invisible_char, buf); - - for (i = 0; i < priv->n_chars; i++) - g_string_append_len (str, buf, char_len); - - pango_layout_set_text (priv->layout, str->str, str->len); - - g_string_free (str, TRUE); - } - - if (priv->wrap) - pango_layout_set_wrap (priv->layout, priv->wrap_mode); - - if (priv->wrap && width > 0) - pango_layout_set_width (priv->layout, width * PANGO_SCALE); - else - pango_layout_set_width (priv->layout, -1); - - /* Prime the cache for the layout */ - cogl_pango_ensure_glyph_cache_for_layout (priv->layout); - } -} - -static void -clutter_entry_clear_layout (ClutterEntry *entry) -{ - if (entry->priv->layout) - { - g_object_unref (entry->priv->layout); - entry->priv->layout = NULL; - } -} - -static gint -offset_to_bytes (const gchar *text, gint pos) -{ - gchar *c = NULL; - gint i, j, len; - - if (pos < 1) - return pos; - - c = g_utf8_next_char (text); - j = 1; - len = strlen (text); - - for (i = 0; i < len; i++) - { - if (&text[i] == c) - { - if (j == pos) - break; - else - { - c = g_utf8_next_char (c); - j++; - } - } - } - return i; -} - - -static void -clutter_entry_ensure_cursor_position (ClutterEntry *entry) -{ - ClutterEntryPrivate *priv; - gint index_; - PangoRectangle rect; - gint priv_char_bytes; - - priv = entry->priv; - - /* If characters are invisible, get the byte-length of the invisible - * character. If priv_char is 0, we use '*', which is ASCII (1 byte). - */ - if (!priv->text_visible && priv->priv_char) - priv_char_bytes = g_unichar_to_utf8 (priv->priv_char, NULL); - else - priv_char_bytes = 1; - - if (priv->position == -1) - { - if (priv->text_visible) - index_ = strlen (priv->text); - else - index_ = priv->n_chars * priv_char_bytes; - } - else - { - if (priv->text_visible) - index_ = offset_to_bytes (priv->text, priv->position); - else - index_ = priv->position * priv_char_bytes; - } - - pango_layout_get_cursor_pos (priv->layout, index_, &rect, NULL); - priv->cursor_pos.x = rect.x / PANGO_SCALE; - priv->cursor_pos.y = rect.y / PANGO_SCALE; - priv->cursor_pos.width = ENTRY_CURSOR_WIDTH; - priv->cursor_pos.height = rect.height / PANGO_SCALE; - - g_signal_emit (entry, entry_signals[CURSOR_EVENT], 0, &priv->cursor_pos); -} - -static void -clutter_entry_clear_cursor_position (ClutterEntry *entry) -{ - entry->priv->cursor_pos.width = 0; -} - -void -clutter_entry_paint_cursor (ClutterEntry *entry) -{ - ClutterEntryPrivate *priv; - - priv = entry->priv; - - if (priv->show_cursor) - { - cogl_set_source_color4ub (priv->fgcol.red, - priv->fgcol.green, - priv->fgcol.blue, - priv->fgcol.alpha); - - cogl_rectangle (priv->cursor_pos.x, - priv->cursor_pos.y, - priv->cursor_pos.width, - priv->cursor_pos.height); - } -} - -static void -clutter_entry_paint (ClutterActor *self) -{ - ClutterEntry *entry; - ClutterEntryPrivate *priv; - PangoRectangle logical; - gint width, actor_width; - gint text_width; - gint cursor_x; - CoglColor color = { 0, }; - - entry = CLUTTER_ENTRY(self); - priv = entry->priv; - - if (priv->desc == NULL || priv->text == NULL) - { - CLUTTER_NOTE (ACTOR, "layout: %p , desc: %p, text %p", - priv->layout, - priv->desc, - priv->text); - return; - } - - if (priv->width < 0) - width = clutter_actor_get_width (self); - else - width = priv->width; - - cogl_clip_set (0, 0, - COGL_FIXED_FROM_INT (width), - COGL_FIXED_FROM_INT (clutter_actor_get_height (self))); - - actor_width = width - (2 * priv->entry_padding); - clutter_entry_ensure_layout (entry, actor_width); - clutter_entry_ensure_cursor_position (entry); - - pango_layout_get_extents (priv->layout, NULL, &logical); - text_width = logical.width / PANGO_SCALE; - - if (actor_width < text_width) - { - /* We need to do some scrolling */ - cursor_x = priv->cursor_pos.x; - - /* If the cursor is at the begining or the end of the text, the placement - * is easy, however, if the cursor is in the middle somewhere, we need to - * make sure the text doesn't move until the cursor is either in the - * far left or far right - */ - - if (priv->position == 0) - priv->text_x = 0; - else if (priv->position == -1) - { - priv->text_x = actor_width - text_width; - priv->cursor_pos.x += priv->text_x + priv->entry_padding; - } - else - { - if (priv->text_x <= 0) - { - gint diff = -1 * priv->text_x; - - if (cursor_x < diff) - priv->text_x += diff - cursor_x; - else if (cursor_x > (diff + actor_width)) - priv->text_x -= cursor_x - (diff+actor_width); - } - - priv->cursor_pos.x += priv->text_x + priv->entry_padding; - } - - } - else - { - priv->text_x = (actor_width - text_width) * priv->x_align; - priv->cursor_pos.x += priv->text_x + priv->entry_padding; - } - - cogl_color_set_from_4ub (&color, - priv->fgcol.red, - priv->fgcol.green, - priv->fgcol.blue, - clutter_actor_get_paint_opacity (self)); - - cogl_pango_render_layout (priv->layout, - priv->text_x + priv->entry_padding, 0, - &color, 0); - - if (CLUTTER_ENTRY_GET_CLASS (entry)->paint_cursor) - CLUTTER_ENTRY_GET_CLASS (entry)->paint_cursor (entry); - - cogl_clip_unset (); -} - -static void -clutter_entry_allocate (ClutterActor *self, - const ClutterActorBox *box, - gboolean absolute_origin_changed) -{ - ClutterEntry *entry = CLUTTER_ENTRY (self); - ClutterEntryPrivate *priv = entry->priv; - gint width; - - width = CLUTTER_UNITS_TO_DEVICE (box->x2 - box->x1); - - if (priv->width != width) - { - clutter_entry_clear_layout (entry); - clutter_entry_ensure_layout (entry, width); - - priv->width = width; - } - - CLUTTER_ACTOR_CLASS (clutter_entry_parent_class)->allocate (self, box, absolute_origin_changed); -} - -static inline void -clutter_entry_handle_key_event_internal (ClutterEntry *entry, - ClutterKeyEvent *event) -{ - gunichar key_unichar; - ClutterEntryPrivate *priv = entry->priv; - gint pos = priv->position; - gint len = 0; - gint keyval = clutter_key_event_symbol (event); - - if (priv->text) - len = g_utf8_strlen (priv->text, -1); - - switch (keyval) - { - case CLUTTER_Return: - case CLUTTER_KP_Enter: - case CLUTTER_ISO_Enter: - g_signal_emit (entry, entry_signals[ACTIVATE], 0); - break; - - case CLUTTER_Escape: - case CLUTTER_Up: - case CLUTTER_KP_Up: - case CLUTTER_Down: - case CLUTTER_KP_Down: - case CLUTTER_Shift_L: - case CLUTTER_Shift_R: - break; - - case CLUTTER_BackSpace: - if (pos != 0 && len != 0) - clutter_entry_delete_chars (entry, 1); - break; - - case CLUTTER_Delete: - case CLUTTER_KP_Delete: - if (len && pos != -1) - clutter_entry_delete_text (entry, pos, pos+1);; - break; - - case CLUTTER_Left: - case CLUTTER_KP_Left: - if (pos != 0 && len != 0) - { - if (pos == -1) - clutter_entry_set_cursor_position (entry, len - 1); - else - clutter_entry_set_cursor_position (entry, pos - 1); - } - break; - - case CLUTTER_Right: - case CLUTTER_KP_Right: - if (pos != -1 && len != 0) - { - if (pos != len) - clutter_entry_set_cursor_position (entry, pos + 1); - } - break; - - case CLUTTER_End: - case CLUTTER_KP_End: - clutter_entry_set_cursor_position (entry, -1); - break; - - case CLUTTER_Begin: - case CLUTTER_Home: - case CLUTTER_KP_Home: - clutter_entry_set_cursor_position (entry, 0); - break; - - default: - key_unichar = clutter_key_event_unicode (event); - if (g_unichar_validate (key_unichar)) - clutter_entry_insert_unichar (entry, key_unichar); - break; - } -} - -static gboolean -clutter_entry_key_press (ClutterActor *actor, - ClutterKeyEvent *event) -{ - clutter_entry_handle_key_event_internal (CLUTTER_ENTRY (actor), event); - - return TRUE; -} - -static void -clutter_entry_dispose (GObject *object) -{ - ClutterEntry *self = CLUTTER_ENTRY(object); - ClutterEntryPrivate *priv; - - priv = self->priv; - - if (priv->layout) - { - g_object_unref (priv->layout); - priv->layout = NULL; - } - - if (priv->context) - { - g_object_unref (priv->context); - priv->context = NULL; - } - - G_OBJECT_CLASS (clutter_entry_parent_class)->dispose (object); -} - -static void -clutter_entry_finalize (GObject *object) -{ - ClutterEntryPrivate *priv = CLUTTER_ENTRY (object)->priv; - - if (priv->desc) - pango_font_description_free (priv->desc); - - g_free (priv->text); - g_free (priv->font_name); - - G_OBJECT_CLASS (clutter_entry_parent_class)->finalize (object); -} - -static void -clutter_entry_class_init (ClutterEntryClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); - GParamSpec *pspec; - - klass->paint_cursor = clutter_entry_paint_cursor; - - actor_class->paint = clutter_entry_paint; - actor_class->allocate = clutter_entry_allocate; - actor_class->key_press_event = clutter_entry_key_press; - - gobject_class->finalize = clutter_entry_finalize; - gobject_class->dispose = clutter_entry_dispose; - gobject_class->set_property = clutter_entry_set_property; - gobject_class->get_property = clutter_entry_get_property; - - /** - * ClutterEntry:font-name: - * - * The font to be used by the entry, expressed in a string that - * can be parsed by pango_font_description_from_string(). - * - * Since: 0.4 - */ - g_object_class_install_property - (gobject_class, PROP_FONT_NAME, - g_param_spec_string ("font-name", - "Font Name", - "Pango font description", - NULL, - CLUTTER_PARAM_READWRITE)); - /** - * ClutterEntry:text: - * - * The text inside the entry. - * - * Since: 0.4 - */ - g_object_class_install_property - (gobject_class, PROP_TEXT, - g_param_spec_string ("text", - "Text", - "Text to render", - NULL, - CLUTTER_PARAM_READWRITE)); - /** - * ClutterEntry:color: - * - * The color of the text inside the entry. - * - * Since: 0.4 - */ - pspec = clutter_param_spec_color ("color", - "Color", - "The color of the text", - &default_text_color, - CLUTTER_PARAM_READWRITE); - g_object_class_install_property (gobject_class, PROP_COLOR, pspec); - /** - * ClutterEntry:alignment: - * - * The preferred alignment for the string. - * - * Since: 0.4 - */ - g_object_class_install_property - (gobject_class, PROP_ALIGNMENT, - g_param_spec_enum ("alignment", - "Alignment", - "The preferred alignment for the string,", - PANGO_TYPE_ALIGNMENT, - PANGO_ALIGN_LEFT, - CLUTTER_PARAM_READWRITE)); - /** - * ClutterEntry:position: - * - * The current input cursor position. -1 is taken to be the end of the text - * - * Since: 0.4 - */ - g_object_class_install_property - (gobject_class, PROP_POSITION, - g_param_spec_int ("position", - "Position", - "The cursor position", - -1, G_MAXINT, - -1, - CLUTTER_PARAM_READWRITE)); - - /** - * ClutterEntry:cursor-visible: - * - * Whether the input cursor is visible or not. - * - * Since: 0.4 - */ - g_object_class_install_property - (gobject_class, PROP_CURSOR, - g_param_spec_boolean ( "cursor-visible", - "Cursor Visible", - "Whether the input cursor is visible", - TRUE, - CLUTTER_PARAM_READWRITE)); - - /** - * ClutterEntry:text-visible: - * - * Whether the text is visible in plain form, or replaced by the - * character set by clutter_entry_set_invisible_char(). - * - * Since: 0.4 - */ - g_object_class_install_property - (gobject_class, PROP_TEXT_VISIBLE, - g_param_spec_boolean ("text-visible", - "Text Visible", - "Whether the text is visible in plain form", - TRUE, - CLUTTER_PARAM_READWRITE)); - - /** - * ClutterEntry:max-length: - * - * The maximum length of the entry text. - * - * Since: 0.4 - */ - g_object_class_install_property - (gobject_class, PROP_MAX_LENGTH, - g_param_spec_int ("max-length", - "Max Length", - "The maximum length of the entry text", - 0, G_MAXINT, - 0, - CLUTTER_PARAM_READWRITE)); - /** - * ClutterEntry:entry-padding: - * - * The padding space between the text and the entry right and left borders. - * - * Since: 0.4 - */ - g_object_class_install_property - (gobject_class, PROP_ENTRY_PADDING, - g_param_spec_uint ("entry-padding", - "Entry Padding", - "The padding space between the text and the left and " - "right borders", - 0, G_MAXUINT, - ENTRY_PADDING, - CLUTTER_PARAM_READWRITE)); - /** - * ClutterEntry:x-align: - * - * Horizontal alignment to be used for the text (0.0 for left alignment, - * 1.0 for right alignment). - * - * Since: 0.6 - */ - g_object_class_install_property (gobject_class, - PROP_X_ALIGN, - g_param_spec_double ("x-align", - "Horizontal Alignment", - "The horizontal alignment to be used for the text", - 0.0, 1.0, 0.0, - CLUTTER_PARAM_READWRITE)); - /** - * ClutterEntry::text-changed: - * @entry: the actor which received the event - * - * The ::text-changed signal is emitted after @entry's text changes - */ - entry_signals[TEXT_CHANGED] = - g_signal_new ("text-changed", - G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ClutterEntryClass, text_changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - /** - * ClutterEntry::cursor-event: - * @entry: the actor which received the event - * @geometry: a #ClutterGeometry - * - * The ::cursor-event signal is emitted each time the input cursor's geometry - * changes, this could be a positional or size change. If you would like to - * implement your own input cursor, set the cursor-visible property to %FALSE, - * and connect to this signal to position and size your own cursor. - * - * Since: 0.4 - */ - entry_signals[CURSOR_EVENT] = - g_signal_new ("cursor-event", - G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ClutterEntryClass, cursor_event), - NULL, NULL, - clutter_marshal_VOID__BOXED, - G_TYPE_NONE, 1, - CLUTTER_TYPE_GEOMETRY | G_SIGNAL_TYPE_STATIC_SCOPE); - - /** - * ClutterEntry::activate: - * @entry: the actor which received the event - * - * The ::activate signal is emitted each time the entry is 'activated' - * by the user, normally by pressing the 'Enter' key. - * - * Since: 0.4 - */ - entry_signals[ACTIVATE] = - g_signal_new ("activate", - G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ClutterEntryClass, activate), - NULL, NULL, - clutter_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - g_type_class_add_private (gobject_class, sizeof (ClutterEntryPrivate)); -} - -static void -clutter_entry_init (ClutterEntry *self) -{ - ClutterEntryPrivate *priv; - gdouble resolution; - gint font_size; - - self->priv = priv = CLUTTER_ENTRY_GET_PRIVATE (self); - - if (G_UNLIKELY (_context == NULL)) - _context = _clutter_context_create_pango_context (CLUTTER_CONTEXT ()); - - resolution = pango_cairo_context_get_resolution (_context); - - priv->alignment = PANGO_ALIGN_LEFT; - priv->wrap = FALSE; - priv->wrap_mode = PANGO_WRAP_WORD; - priv->ellipsize = PANGO_ELLIPSIZE_NONE; - priv->use_underline = FALSE; - priv->use_markup = FALSE; - priv->layout = NULL; - priv->text = NULL; - priv->attrs = NULL; - priv->position = -1; - priv->priv_char = '*'; - priv->text_visible = TRUE; - priv->text_x = 0; - priv->max_length = 0; - priv->entry_padding = ENTRY_PADDING; - priv->x_align = 0.0; - - priv->fgcol = default_text_color; - - priv->font_name = g_strdup (DEFAULT_FONT_NAME); - priv->desc = pango_font_description_from_string (priv->font_name); - - /* we use the font size to set the default width and height, in case - * the user doesn't call clutter_actor_set_size(). - */ - font_size = PANGO_PIXELS (pango_font_description_get_size (priv->desc)) - * resolution - / 72.0; - clutter_actor_set_size (CLUTTER_ACTOR (self), font_size * 20, 50); - - priv->show_cursor = TRUE; -} - -/** - * clutter_entry_new_with_text: - * @font_name: the name (and size) of the font to be used - * @text: the text to be displayed - * - * Creates a new #ClutterEntry displaying @text using @font_name. - * - * Return value: the newly created #ClutterEntry - * - * Since: 0.4 - */ -ClutterActor * -clutter_entry_new_with_text (const gchar *font_name, - const gchar *text) -{ - ClutterActor *entry = clutter_entry_new (); - - g_object_set (entry, - "font-name", font_name, - "text", text, - NULL); - return entry; -} - -/** - * clutter_entry_new_full: - * @font_name: the name (and size) of the font to be used - * @text: the text to be displayed - * @color: #ClutterColor for text - * - * Creates a new #ClutterEntry displaying @text with @color - * using @font_name. - * - * Return value: the newly created #ClutterEntry - * - * Since: 0.4 - */ -ClutterActor * -clutter_entry_new_full (const gchar *font_name, - const gchar *text, - const ClutterColor *color) -{ - ClutterActor *entry; - - entry = clutter_entry_new_with_text (font_name, text); - clutter_entry_set_color (CLUTTER_ENTRY(entry), color); - - return entry; -} - -/** - * clutter_entry_new: - * - * Creates a new, empty #ClutterEntry. - * - * Returns: the newly created #ClutterEntry - */ -ClutterActor * -clutter_entry_new (void) -{ - ClutterActor *entry = g_object_new (CLUTTER_TYPE_ENTRY, - NULL); - clutter_actor_set_size (entry, 50, 50); - - return entry; -} - -/** - * clutter_entry_get_text: - * @entry: a #ClutterEntry - * - * Retrieves the text displayed by @entry. - * - * Return value: the text of the entry. The returned string is - * owned by #ClutterEntry and should not be modified or freed. - * - * Since: 0.4 - */ -G_CONST_RETURN gchar * -clutter_entry_get_text (ClutterEntry *entry) -{ - g_return_val_if_fail (CLUTTER_IS_ENTRY (entry), NULL); - - return entry->priv->text; -} - -/** - * clutter_entry_set_text: - * @entry: a #ClutterEntry - * @text: the text to be displayed - * - * Sets @text as the text to be displayed by @entry. The - * ClutterEntry::text-changed signal is emitted. - * - * Since: 0.4 - */ -void -clutter_entry_set_text (ClutterEntry *entry, - const gchar *text) -{ - ClutterEntryPrivate *priv; - - g_return_if_fail (CLUTTER_IS_ENTRY (entry)); - g_return_if_fail (text != NULL); - - priv = entry->priv; - - g_object_ref (entry); - - if (priv->max_length > 0) - { - gint len = g_utf8_strlen (text, -1); - - if (len < priv->max_length) - { - g_free (priv->text); - - priv->text = g_strdup (text); - priv->n_bytes = strlen (text); - priv->n_chars = len; - } - else - { - gchar * n = g_malloc0 (priv->max_length + 1); - - g_utf8_strncpy (n, text, priv->max_length); - g_free (priv->text); - - priv->text = n; - priv->n_bytes = strlen (n); - priv->n_chars = priv->max_length; - } - } - else - { - g_free (priv->text); - - priv->text = g_strdup (text); - priv->n_bytes = strlen (text); - priv->n_chars = g_utf8_strlen (priv->text, -1); - } - - clutter_entry_clear_layout (entry); - clutter_entry_clear_cursor_position (entry); - /* Recreate the layout so the glyph cache will be primed */ - clutter_entry_ensure_layout (entry, -1); - - if (CLUTTER_ACTOR_IS_VISIBLE (entry)) - clutter_actor_queue_redraw (CLUTTER_ACTOR (entry)); - - g_signal_emit (G_OBJECT (entry), entry_signals[TEXT_CHANGED], 0); - - g_object_notify (G_OBJECT (entry), "text"); - g_object_unref (entry); -} - -/** - * clutter_entry_get_font_name: - * @entry: a #ClutterEntry - * - * Retrieves the font used by @entry. - * - * Return value: a string containing the font name, in a format - * understandable by pango_font_description_from_string(). The - * string is owned by #ClutterEntry and should not be modified - * or freed. - * - * Since: 0.4 - */ -G_CONST_RETURN gchar * -clutter_entry_get_font_name (ClutterEntry *entry) -{ - g_return_val_if_fail (CLUTTER_IS_ENTRY (entry), NULL); - - return entry->priv->font_name; -} - -/** - * clutter_entry_set_font_name: - * @entry: a #ClutterEntry - * @font_name: a font name and size, or %NULL for the default font - * - * Sets @font_name as the font used by @entry. - * - * @font_name must be a string containing the font name and its - * size, similarly to what you would feed to the - * pango_font_description_from_string() function. - * - * Since: 0.4 - */ -void -clutter_entry_set_font_name (ClutterEntry *entry, - const gchar *font_name) -{ - ClutterEntryPrivate *priv; - PangoFontDescription *desc; - - g_return_if_fail (CLUTTER_IS_ENTRY (entry)); - - if (!font_name || font_name[0] == '\0') - font_name = DEFAULT_FONT_NAME; - - priv = entry->priv; - - if (strcmp (priv->font_name, font_name) == 0) - return; - - desc = pango_font_description_from_string (font_name); - if (!desc) - { - g_warning ("Attempting to create a PangoFontDescription for " - "font name `%s', but failed.", - font_name); - return; - } - - g_object_ref (entry); - - g_free (priv->font_name); - priv->font_name = g_strdup (font_name); - - if (priv->desc) - pango_font_description_free (priv->desc); - - priv->desc = desc; - - if (entry->priv->text && entry->priv->text[0] != '\0') - { - clutter_entry_clear_layout (entry); - /* Recreate the layout so the glyph cache will be primed */ - clutter_entry_ensure_layout (entry, -1); - - if (CLUTTER_ACTOR_IS_VISIBLE (entry)) - clutter_actor_queue_redraw (CLUTTER_ACTOR (entry)); - } - - g_object_notify (G_OBJECT (entry), "font-name"); - g_object_unref (entry); -} - - -/** - * clutter_entry_set_color: - * @entry: a #ClutterEntry - * @color: a #ClutterColor - * - * Sets the color of @entry. - * - * Since: 0.4 - */ -void -clutter_entry_set_color (ClutterEntry *entry, - const ClutterColor *color) -{ - ClutterActor *actor; - ClutterEntryPrivate *priv; - - g_return_if_fail (CLUTTER_IS_ENTRY (entry)); - g_return_if_fail (color != NULL); - - priv = entry->priv; - - g_object_ref (entry); - - priv->fgcol.red = color->red; - priv->fgcol.green = color->green; - priv->fgcol.blue = color->blue; - priv->fgcol.alpha = color->alpha; - - actor = CLUTTER_ACTOR (entry); - - clutter_actor_set_opacity (actor, priv->fgcol.alpha); - - if (CLUTTER_ACTOR_IS_VISIBLE (actor)) - clutter_actor_queue_redraw (actor); - - g_object_notify (G_OBJECT (entry), "color"); - g_object_unref (entry); -} - -/** - * clutter_entry_get_color: - * @entry: a #ClutterEntry - * @color: return location for a #ClutterColor - * - * Retrieves the color of @entry. - * - * Since: 0.4 - */ -void -clutter_entry_get_color (ClutterEntry *entry, - ClutterColor *color) -{ - ClutterEntryPrivate *priv; - - g_return_if_fail (CLUTTER_IS_ENTRY (entry)); - g_return_if_fail (color != NULL); - - priv = entry->priv; - - color->red = priv->fgcol.red; - color->green = priv->fgcol.green; - color->blue = priv->fgcol.blue; - color->alpha = priv->fgcol.alpha; -} - -/** - * clutter_entry_get_layout: - * @entry: a #ClutterEntry - * - * Gets the #PangoLayout used to display the entry. - * The layout is useful to e.g. convert text positions to - * pixel positions. - * The returned layout is owned by the entry so need not be - * freed by the caller. - * - * Return value: the #PangoLayout for this entry - * - * Since: 0.4 - **/ -PangoLayout * -clutter_entry_get_layout (ClutterEntry *entry) -{ - g_return_val_if_fail (CLUTTER_IS_ENTRY (entry), NULL); - - clutter_entry_ensure_layout (entry, -1); - - return entry->priv->layout; -} - -/** - * clutter_entry_set_alignment: - * @entry: a #ClutterEntry - * @alignment: A #PangoAlignment - * - * Sets text alignment of the entry. - * - * Since: 0.4 - */ -void -clutter_entry_set_alignment (ClutterEntry *entry, - PangoAlignment alignment) -{ - ClutterEntryPrivate *priv; - - g_return_if_fail (CLUTTER_IS_ENTRY (entry)); - - priv = entry->priv; - - if (priv->alignment != alignment) - { - g_object_ref (entry); - - priv->alignment = alignment; - - clutter_entry_clear_layout (entry); - - if (CLUTTER_ACTOR_IS_VISIBLE (entry)) - clutter_actor_queue_redraw (CLUTTER_ACTOR (entry)); - - g_object_notify (G_OBJECT (entry), "alignment"); - g_object_unref (entry); - } -} - -/** - * clutter_entry_get_alignment: - * @entry: a #ClutterEntry - * - * Returns the entry's text alignment - * - * Return value: The entry's #PangoAlignment - * - * Since: 0.4 - */ -PangoAlignment -clutter_entry_get_alignment (ClutterEntry *entry) -{ - g_return_val_if_fail (CLUTTER_IS_ENTRY (entry), FALSE); - - return entry->priv->alignment; -} - -/** - * clutter_entry_set_cursor_position: - * @entry: a #ClutterEntry - * @position: the position of the cursor. - * - * Sets the position of the cursor. The @position must be less than or - * equal to the number of characters in the entry. A value of -1 indicates - * that the position should be set after the last character in the entry. - * Note that this position is in characters, not in bytes. - * - * Since: 0.6 - */ -void -clutter_entry_set_cursor_position (ClutterEntry *entry, - gint position) -{ - ClutterEntryPrivate *priv; - gint len; - - g_return_if_fail (CLUTTER_IS_ENTRY (entry)); - - priv = entry->priv; - - if (priv->text == NULL) - return; - - len = g_utf8_strlen (priv->text, -1); - - if (position < 0 || position >= len) - priv->position = -1; - else - priv->position = position; - - clutter_entry_clear_cursor_position (entry); - - if (CLUTTER_ACTOR_IS_VISIBLE (entry)) - clutter_actor_queue_redraw (CLUTTER_ACTOR (entry)); -} - -/** - * clutter_entry_get_cursor_position: - * @entry: a #ClutterEntry - * - * Gets the position, in characters, of the cursor in @entry. - * - * Return value: the position of the cursor. - * - * Since: 0.6 - */ -gint -clutter_entry_get_cursor_position (ClutterEntry *entry) -{ - ClutterEntryPrivate *priv; - - g_return_val_if_fail (CLUTTER_IS_ENTRY (entry), 0); - - priv = entry->priv; - - return priv->position; -} - -/** - * clutter_entry_handle_key_event: - * @entry: a #ClutterEntry - * @kev: a #ClutterKeyEvent - * - * This function will handle a #ClutterKeyEvent, like those returned in a - * key-press/release-event, and will translate it for the @entry. This includes - * non-alphanumeric keys, such as the arrows keys, which will move the - * input cursor. You should use this function inside a handler for the - * ClutterStage::key-press-event or ClutterStage::key-release-event. - * - * Since: 0.4 - * - * Deprecated: 0.8: The key events will automatically be handled when - * giving the key focus to an entry using clutter_stage_set_key_focus(). - */ -void -clutter_entry_handle_key_event (ClutterEntry *entry, - ClutterKeyEvent *kev) -{ - g_return_if_fail (CLUTTER_IS_ENTRY (entry)); - - clutter_entry_handle_key_event_internal (entry, kev); -} - -/** - * clutter_entry_insert_unichar: - * @entry: a #ClutterEntry - * @wc: a Unicode character - * - * Insert a character to the right of the current position of the cursor, - * and updates the position of the cursor. - * - * Since: 0.4 - */ -void -clutter_entry_insert_unichar (ClutterEntry *entry, - gunichar wc) -{ - ClutterEntryPrivate *priv; - GString *new = NULL; - glong pos; - - g_return_if_fail (CLUTTER_IS_ENTRY (entry)); - g_return_if_fail (g_unichar_validate (wc)); - - if (wc == 0) - return; - - priv = entry->priv; - - g_object_ref (entry); - - new = g_string_new (priv->text); - pos = offset_to_bytes (priv->text, priv->position); - new = g_string_insert_unichar (new, pos, wc); - - clutter_entry_set_text (entry, new->str); - - if (priv->position >= 0) - clutter_entry_set_cursor_position (entry, priv->position + 1); - - g_string_free (new, TRUE); - - g_object_notify (G_OBJECT (entry), "text"); - g_object_unref (entry); -} - -/** - * clutter_entry_delete_chars: - * @entry: a #ClutterEntry - * @len: the number of characters to remove. - * - * Characters are removed from before the current postion of the cursor. - * - * Since: 0.4 - */ -void -clutter_entry_delete_chars (ClutterEntry *entry, - guint num) -{ - ClutterEntryPrivate *priv; - GString *new = NULL; - gint len; - gint pos; - gint num_pos; - - g_return_if_fail (CLUTTER_IS_ENTRY (entry)); - - priv = entry->priv; - - if (!priv->text) - return; - - g_object_ref (entry); - - len = g_utf8_strlen (priv->text, -1); - new = g_string_new (priv->text); - - if (priv->position == -1) - { - num_pos = offset_to_bytes (priv->text, len - num); - new = g_string_erase (new, num_pos, -1); - } - else - { - pos = offset_to_bytes (priv->text, priv->position - num); - num_pos = offset_to_bytes (priv->text, priv->position); - new = g_string_erase (new, pos, num_pos-pos); - } - clutter_entry_set_text (entry, new->str); - - if (priv->position > 0) - clutter_entry_set_cursor_position (entry, priv->position - num); - - g_string_free (new, TRUE); - - g_object_notify (G_OBJECT (entry), "text"); - g_object_unref (entry); -} - -/** - * clutter_entry_insert_text: - * @entry: a #ClutterEntry - * @text: the text to insert - * @position: the position at which to insert the text. - * - * Insert text at a specifc position. - * - * A value of 0 indicates that the text will be inserted before the first - * character in the entry's text, and a value of -1 indicates that the text - * will be inserted after the last character in the entry's text. - * - * Since: 0.4 - */ -void -clutter_entry_insert_text (ClutterEntry *entry, - const gchar *text, - gssize position) -{ - ClutterEntryPrivate *priv; - GString *new = NULL; - - g_return_if_fail (CLUTTER_IS_ENTRY (entry)); - - priv = entry->priv; - - new = g_string_new (priv->text); - new = g_string_insert (new, position, text); - - clutter_entry_set_text (entry, new->str); - - g_string_free (new, TRUE); -} - -/** - * clutter_entry_delete_text: - * @entry: a #ClutterEntry - * @start_pos: the starting position. - * @end_pos: the end position. - * - * Deletes a sequence of characters. The characters that are deleted are - * those characters at positions from @start_pos up to, but not including, - * @end_pos. If @end_pos is negative, then the characters deleted will be - * those characters from @start_pos to the end of the text. - * - * Since: 0.4 - */ -void -clutter_entry_delete_text (ClutterEntry *entry, - gssize start_pos, - gssize end_pos) -{ - ClutterEntryPrivate *priv; - GString *new = NULL; - gint start_bytes; - gint end_bytes; - - g_return_if_fail (CLUTTER_IS_ENTRY (entry)); - - priv = entry->priv; - - if (!priv->text) - return; - - start_bytes = offset_to_bytes (priv->text, start_pos); - end_bytes = offset_to_bytes (priv->text, end_pos); - - new = g_string_new (priv->text); - new = g_string_erase (new, start_bytes, end_bytes - start_bytes); - - clutter_entry_set_text (entry, new->str); - - g_string_free (new, TRUE); -} - -/** - * clutter_entry_set_visible_cursor: - * @entry: a #ClutterEntry - * @visible: whether the input cursor should be visible - * - * Sets the visibility of the input cursor. - * - * Since: 0.4 - */ -void -clutter_entry_set_visible_cursor (ClutterEntry *entry, - gboolean visible) -{ - ClutterEntryPrivate *priv; - - g_return_if_fail (CLUTTER_IS_ENTRY (entry)); - - priv = entry->priv; - - if (priv->show_cursor != visible) - { - priv->show_cursor = visible; - - g_object_notify (G_OBJECT (entry), "cursor-visible"); - - if (CLUTTER_ACTOR_IS_VISIBLE (entry)) - clutter_actor_queue_redraw (CLUTTER_ACTOR (entry)); - } -} - -/** - * clutter_entry_get_visible_cursor: - * @entry: a #ClutterEntry - * - * Returns the input cursor's visibility - * - * Return value: whether the input cursor is visible - * - * Since: 0.4 - */ -gboolean -clutter_entry_get_visible_cursor (ClutterEntry *entry) -{ - g_return_val_if_fail (CLUTTER_IS_ENTRY (entry), FALSE); - - return entry->priv->show_cursor; -} - -/** - * clutter_entry_set_visibility: - * @entry: a #ClutterEntry - * @visible: %TRUE if the contents of the entry are displayed as plaintext. - * - * Sets whether the contents of the entry are visible or not. When visibility - * is set to %FALSE, characters are displayed as the invisible char, and will - * also appear that way when the text in the entry widget is copied elsewhere. - * - * The default invisible char is the asterisk '*', but it can be changed with - * clutter_entry_set_invisible_char(). - * - * Since: 0.4 - */ -void -clutter_entry_set_visibility (ClutterEntry *entry, gboolean visible) -{ - ClutterEntryPrivate *priv; - - g_return_if_fail (CLUTTER_IS_ENTRY (entry)); - - priv = entry->priv; - - priv->text_visible = visible; - - clutter_entry_clear_layout (entry); - clutter_entry_clear_cursor_position (entry); - - if (CLUTTER_ACTOR_IS_VISIBLE (entry)) - clutter_actor_queue_redraw (CLUTTER_ACTOR (entry)); -} - -/** - * clutter_entry_get_visibility: - * @entry: a #ClutterEntry - * - * Returns the entry text visibility. - * - * Return value: %TRUE if the contents of the entry are displayed as plaintext. - * - * Since: 0.4 - */ -gboolean -clutter_entry_get_visibility (ClutterEntry *entry) -{ - g_return_val_if_fail (CLUTTER_IS_ENTRY (entry), TRUE); - - return entry->priv->text_visible; -} - -/** - * clutter_entry_set_invisible_char: - * @entry: a #ClutterEntry - * @wc: a Unicode character - * - * Sets the character to use in place of the actual text when - * clutter_entry_set_visibility() has been called to set text visibility - * to %FALSE. i.e. this is the character used in "password mode" to show the - * user how many characters have been typed. The default invisible char is an - * asterisk ('*'). If you set the invisible char to 0, then the user will get - * no feedback at all; there will be no text on the screen as they type. - * - * Since: 0.4 - */ -void -clutter_entry_set_invisible_char (ClutterEntry *entry, gunichar wc) -{ - ClutterEntryPrivate *priv; - - g_return_if_fail (CLUTTER_IS_ENTRY (entry)); - - priv = entry->priv; - - priv->priv_char = wc; - - if (!priv->text_visible) - return; - - clutter_entry_clear_layout (entry); - clutter_entry_clear_cursor_position (entry); - - if (CLUTTER_ACTOR_IS_VISIBLE (entry)) - clutter_actor_queue_redraw (CLUTTER_ACTOR (entry)); -} - -/** - * clutter_entry_get_invisible_char: - * @entry: a #ClutterEntry - * - * Returns the character to use in place of the actual text when text-visibility - * is set to %FALSE - * - * Return value: a Unicode character - * - **/ -gunichar -clutter_entry_get_invisible_char (ClutterEntry *entry) -{ - ClutterEntryPrivate *priv; - - g_return_val_if_fail (CLUTTER_IS_ENTRY (entry), TRUE); - - priv = entry->priv; - - return priv->priv_char; -} - -/** - * clutter_entry_set_max_length: - * @entry: a #ClutterEntry - * @max: the maximum number of characters allowed in the entry; 0 - * to disable or -1 to set the length of the current string - * - * Sets the maximum allowed length of the contents of the actor. If the - * current contents are longer than the given length, then they will be - * truncated to fit. - * - * Since: 0.4 - */ -void -clutter_entry_set_max_length (ClutterEntry *entry, - gint max) -{ - ClutterEntryPrivate *priv; - gchar *new = NULL; - - g_return_if_fail (CLUTTER_IS_ENTRY (entry)); - - priv = entry->priv; - - if (priv->max_length != max) - { - g_object_ref (entry); - - if (max < 0) - max = g_utf8_strlen (priv->text, -1); - - priv->max_length = max; - - new = g_strdup (priv->text); - clutter_entry_set_text (entry, new); - g_free (new); - - g_object_notify (G_OBJECT (entry), "max-length"); - g_object_unref (entry); - } -} - -/** - * clutter_entry_get_max_length: - * @entry: a #ClutterEntry - * - * Gets the maximum length of text that can be set into @entry. - * See clutter_entry_set_max_length(). - * - * Return value: the maximum number of characters. - * - * Since: 0.4 - */ -gint -clutter_entry_get_max_length (ClutterEntry *entry) -{ - g_return_val_if_fail (CLUTTER_IS_ENTRY (entry), -1); - - return entry->priv->max_length; -} diff --git a/clutter/clutter-entry.h b/clutter/clutter-entry.h deleted file mode 100644 index b43408522..000000000 --- a/clutter/clutter-entry.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Authored By Matthew Allum - * Neil Jagdish Patel . - */ - -#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) -#error "Only can be included directly." -#endif - -#ifndef __CLUTTER_ENTRY_H__ -#define __CLUTTER_ENTRY_H__ - -#include -#include -#include -#include - - -G_BEGIN_DECLS - -#define CLUTTER_TYPE_ENTRY (clutter_entry_get_type ()) - -#define CLUTTER_ENTRY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - CLUTTER_TYPE_ENTRY, ClutterEntry)) - -#define CLUTTER_ENTRY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - CLUTTER_TYPE_ENTRY, ClutterEntryClass)) - -#define CLUTTER_IS_ENTRY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - CLUTTER_TYPE_ENTRY)) - -#define CLUTTER_IS_ENTRY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - CLUTTER_TYPE_ENTRY)) - -#define CLUTTER_ENTRY_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - CLUTTER_TYPE_ENTRY, ClutterEntryClass)) - -typedef struct _ClutterEntry ClutterEntry; -typedef struct _ClutterEntryClass ClutterEntryClass; -typedef struct _ClutterEntryPrivate ClutterEntryPrivate; - -struct _ClutterEntry -{ - /*< private >*/ - ClutterActor parent_instance; - - ClutterEntryPrivate *priv; -}; - -/** - * ClutterEntryClass: - * @paint_cursor: virtual function for subclasses to use to draw a custom - * cursor instead of the default one - * @text_changed: signal class handler for ClutterEntry::text-changed - * @cursor_event: signal class handler for ClutterEntry::cursor-event - * @activate: signal class handler for ClutterEntry::activate - * - * Class fo entry actors. - * - * Since: 0.4 - */ -struct _ClutterEntryClass -{ - /*< private >*/ - ClutterActorClass parent_class; - - /*< public >*/ - /* vfuncs, not signals */ - void (* paint_cursor) (ClutterEntry *entry); - - /* signals */ - void (* text_changed) (ClutterEntry *entry); - void (* cursor_event) (ClutterEntry *entry, - ClutterGeometry *geometry); - void (* activate) (ClutterEntry *entry); - - /*< private >*/ - /* padding for future */ - void (*_clutter_entry_1) (void); - void (*_clutter_entry_2) (void); - void (*_clutter_entry_3) (void); - void (*_clutter_entry_4) (void); -}; - -GType clutter_entry_get_type (void) G_GNUC_CONST; - -ClutterActor * clutter_entry_new (void); -ClutterActor * clutter_entry_new_full (const gchar *font_name, - const gchar *text, - const ClutterColor *color); -ClutterActor * clutter_entry_new_with_text (const gchar *font_name, - const gchar *text); -void clutter_entry_set_text (ClutterEntry *entry, - const gchar *text); -G_CONST_RETURN gchar *clutter_entry_get_text (ClutterEntry *entry); -void clutter_entry_set_font_name (ClutterEntry *entry, - const gchar *font_name); -G_CONST_RETURN gchar *clutter_entry_get_font_name (ClutterEntry *entry); -void clutter_entry_set_color (ClutterEntry *entry, - const ClutterColor *color); -void clutter_entry_get_color (ClutterEntry *entry, - ClutterColor *color); -PangoLayout * clutter_entry_get_layout (ClutterEntry *entry); -void clutter_entry_set_alignment (ClutterEntry *entry, - PangoAlignment alignment); -PangoAlignment clutter_entry_get_alignment (ClutterEntry *entry); -void clutter_entry_set_cursor_position (ClutterEntry *entry, - gint position); -gint clutter_entry_get_cursor_position (ClutterEntry *entry); -void clutter_entry_insert_unichar (ClutterEntry *entry, - gunichar wc); -void clutter_entry_delete_chars (ClutterEntry *entry, - guint len); -void clutter_entry_insert_text (ClutterEntry *entry, - const gchar *text, - gssize position); -void clutter_entry_delete_text (ClutterEntry *entry, - gssize start_pos, - gssize end_pos); -void clutter_entry_set_visible_cursor (ClutterEntry *entry, - gboolean visible); -gboolean clutter_entry_get_visible_cursor (ClutterEntry *entry); - -void clutter_entry_set_visibility (ClutterEntry *entry, - gboolean visible); -gboolean clutter_entry_get_visibility (ClutterEntry *entry); -void clutter_entry_set_invisible_char (ClutterEntry *entry, - gunichar wc); -gunichar clutter_entry_get_invisible_char (ClutterEntry *entry); -void clutter_entry_set_max_length (ClutterEntry *entry, - gint max); -gint clutter_entry_get_max_length (ClutterEntry *entry); - -#ifndef CLUTTER_DISABLE_DEPRECATED -void clutter_entry_handle_key_event (ClutterEntry *entry, - ClutterKeyEvent *kev); -#endif - -G_END_DECLS - -#endif /* __CLUTTER_ENTRY_H__ */ diff --git a/clutter/clutter-label.c b/clutter/clutter-label.c deleted file mode 100644 index 74434e246..000000000 --- a/clutter/clutter-label.c +++ /dev/null @@ -1,1347 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Authored By Matthew Allum - * - * Copyright (C) 2006 OpenedHand - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/** - * SECTION:clutter-label - * @short_description: Actor for displaying text - * - * #ClutterLabel is a #ClutterActor that displays text using Pango. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "clutter-label.h" -#include "clutter-main.h" -#include "clutter-enum-types.h" -#include "clutter-private.h" -#include "clutter-debug.h" -#include "clutter-units.h" - -#include "cogl-pango.h" - -#define DEFAULT_FONT_NAME "Sans 10" - -G_DEFINE_TYPE (ClutterLabel, clutter_label, CLUTTER_TYPE_ACTOR) - -/* Probably move into main */ -static PangoContext *_context = NULL; - -static const ClutterColor default_text_color = { 0, 0, 0, 255 }; - -enum -{ - PROP_0, - PROP_FONT_NAME, - PROP_TEXT, - PROP_COLOR, - PROP_ATTRIBUTES, - PROP_USE_MARKUP, - PROP_ALIGNMENT, - PROP_WRAP, - PROP_WRAP_MODE, - PROP_JUSTIFY, - PROP_ELLIPSIZE, -}; - -#define CLUTTER_LABEL_GET_PRIVATE(obj) \ -(G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_LABEL, ClutterLabelPrivate)) - -typedef struct _ClutterLabelCachedLayout ClutterLabelCachedLayout; - -struct _ClutterLabelCachedLayout -{ - /* Cached layout. Pango internally caches the computed extents when - they are requested so there is no need to cache that as well */ - PangoLayout *layout; - /* The width that used to generate this layout */ - ClutterUnit width; - /* A number representing the age of this cache (so that when a new - layout is needed the last used cache is replaced) */ - guint age; -}; - -/* We need at least three cached layouts to run the allocation without - regenerating a new layout. First the layout will be generated at - full width to get the preferred width, then it will be generated at - the preferred width to get the preferred height and then it might - be regenerated at a different width to get the height for the - actual allocated width */ -#define CLUTTER_LABEL_N_CACHED_LAYOUTS 3 - -struct _ClutterLabelPrivate -{ - PangoFontDescription *font_desc; - - ClutterColor fgcol; - - gchar *text; - gchar *font_name; - - PangoAttrList *attrs; - PangoAttrList *effective_attrs; - - ClutterLabelCachedLayout cached_layouts[CLUTTER_LABEL_N_CACHED_LAYOUTS]; - guint cache_age; - - guint alignment : 2; - guint wrap : 1; - guint use_underline : 1; - guint use_markup : 1; - guint ellipsize : 3; - guint single_line_mode : 1; - guint wrap_mode : 3; - guint justify : 1; -}; - -/* - * clutter_label_create_layout_no_cache: - * @label: a #ClutterLabel - * @allocation_width: the width of the layout, or -1 - * - * Creates a new #PangoLayout for the given @allocation_width, using - * the layout properties of the @label. - * - * This function will not touch the glyphs cache. - * - * This function should be used by clutter_label_get_preferred_width() - * and clutter_label_get_preferred_height(). - */ -static PangoLayout * -clutter_label_create_layout_no_cache (ClutterLabel *label, - ClutterUnit allocation_width) -{ - ClutterLabelPrivate *priv = label->priv; - PangoLayout *layout; - - layout = pango_layout_new (_context); - - if (priv->effective_attrs) - pango_layout_set_attributes (layout, priv->effective_attrs); - - pango_layout_set_alignment (layout, priv->alignment); - pango_layout_set_single_paragraph_mode (layout, priv->single_line_mode); - - pango_layout_set_font_description (layout, priv->font_desc); - pango_layout_set_justify (layout, priv->justify); - - if (priv->text) - { - if (!priv->use_markup) - pango_layout_set_text (layout, priv->text, -1); - else - pango_layout_set_markup (layout, priv->text, -1); - } - - if (allocation_width > 0 && - (priv->ellipsize != PANGO_ELLIPSIZE_NONE || priv->wrap)) - { - int layout_width, layout_height; - - pango_layout_get_size (layout, &layout_width, &layout_height); - - /* No need to set ellipsize or wrap if we already have enough - * space, since we don't want to make the layout wider than it - * would be otherwise. - */ - - if (CLUTTER_UNITS_FROM_PANGO_UNIT (layout_width) > allocation_width) - { - if (priv->ellipsize != PANGO_ELLIPSIZE_NONE) - { - gint width; - - width = allocation_width > 0 - ? CLUTTER_UNITS_TO_PANGO_UNIT (allocation_width) - : -1; - - pango_layout_set_ellipsize (layout, priv->ellipsize); - pango_layout_set_width (layout, width); - } - else if (priv->wrap) - { - gint width; - - width = allocation_width > 0 - ? CLUTTER_UNITS_TO_PANGO_UNIT (allocation_width) - : -1; - - pango_layout_set_wrap (layout, priv->wrap_mode); - pango_layout_set_width (layout, width); - } - } - } - - return layout; -} - -static void -clutter_label_dirty_cache (ClutterLabel *label) -{ - ClutterLabelPrivate *priv = label->priv; - int i; - - /* Delete the cached layouts so they will be recreated the next time - they are needed */ - for (i = 0; i < CLUTTER_LABEL_N_CACHED_LAYOUTS; i++) - if (priv->cached_layouts[i].layout) - { - g_object_unref (priv->cached_layouts[i].layout); - priv->cached_layouts[i].layout = NULL; - } -} - -/* - * clutter_label_create_layout: - * @label: a #ClutterLabel - * @allocation_width: the allocation width - * - * Like clutter_label_create_layout_no_cache(), but will also ensure - * the glyphs cache. If a previously cached layout generated using the - * same width is available then that will be used instead of - * generating a new one. - */ -static PangoLayout * -clutter_label_create_layout (ClutterLabel *label, - ClutterUnit allocation_width) -{ - ClutterLabelPrivate *priv = label->priv; - int i; - ClutterLabelCachedLayout *oldest_cache = priv->cached_layouts; - gboolean found_free_cache = FALSE; - - /* Search for a cached layout with the same width and keep track of - the oldest one */ - for (i = 0; i < CLUTTER_LABEL_N_CACHED_LAYOUTS; i++) - { - if (priv->cached_layouts[i].layout == NULL) - { - /* Always prefer free cache spaces */ - found_free_cache = TRUE; - oldest_cache = priv->cached_layouts + i; - } - /* If this cached layout is using the same width then we can - just return that directly */ - else if (priv->cached_layouts[i].width == allocation_width) - { - CLUTTER_NOTE (ACTOR, "ClutterLabel: %p: cache hit for width %i", - label, CLUTTER_UNITS_TO_DEVICE (allocation_width)); - return priv->cached_layouts[i].layout; - } - else if (!found_free_cache && (priv->cached_layouts[i].age - < oldest_cache->age)) - oldest_cache = priv->cached_layouts + i; - } - - CLUTTER_NOTE (ACTOR, "ClutterLabel: %p: cache miss for width %i", - label, CLUTTER_UNITS_TO_DEVICE (allocation_width)); - - /* If we make it here then we didn't have a cached version so we - need to recreate the layout */ - if (oldest_cache->layout) - g_object_unref (oldest_cache->layout); - - oldest_cache->layout - = clutter_label_create_layout_no_cache (label, allocation_width); - - cogl_pango_ensure_glyph_cache_for_layout (oldest_cache->layout); - - /* Mark the 'time' this cache was created and advance the time */ - oldest_cache->age = priv->cache_age++; - - oldest_cache->width = allocation_width; - - return oldest_cache->layout; -} - -static void -clutter_label_paint (ClutterActor *self) -{ - ClutterLabel *label = CLUTTER_LABEL (self); - ClutterLabelPrivate *priv = label->priv; - PangoLayout *layout; - ClutterActorBox alloc = { 0, }; - CoglColor color = { 0, }; - - if (priv->font_desc == NULL || priv->text == NULL) - { - CLUTTER_NOTE (ACTOR, "desc: %p, text %p", - priv->font_desc ? priv->font_desc : 0x0, - priv->text ? priv->text : 0x0); - return; - } - - CLUTTER_NOTE (PAINT, "painting label (text:`%s')", priv->text); - - clutter_actor_get_allocation_box (self, &alloc); - layout = clutter_label_create_layout (label, alloc.x2 - alloc.x1); - - cogl_color_set_from_4ub (&color, - priv->fgcol.red, - priv->fgcol.green, - priv->fgcol.blue, - clutter_actor_get_paint_opacity (self)); - - cogl_pango_render_layout (layout, 0, 0, &color, 0); -} - -static void -clutter_label_get_preferred_width (ClutterActor *self, - ClutterUnit for_height, - ClutterUnit *min_width_p, - ClutterUnit *natural_width_p) -{ - ClutterLabel *label = CLUTTER_LABEL (self); - ClutterLabelPrivate *priv = label->priv; - PangoRectangle logical_rect = { 0, }; - PangoLayout *layout; - ClutterUnit layout_width; - - layout = clutter_label_create_layout (label, -1); - - pango_layout_get_extents (layout, NULL, &logical_rect); - - layout_width = logical_rect.width > 0 - ? CLUTTER_UNITS_FROM_PANGO_UNIT (logical_rect.width) - : 1; - - if (min_width_p) - { - if (priv->wrap || priv->ellipsize) - *min_width_p = 1; - else - *min_width_p = layout_width; - } - - if (natural_width_p) - *natural_width_p = layout_width; -} - -static void -clutter_label_get_preferred_height (ClutterActor *self, - ClutterUnit for_width, - ClutterUnit *min_height_p, - ClutterUnit *natural_height_p) -{ - ClutterLabel *label = CLUTTER_LABEL (self); - - if (for_width == 0) - { - if (min_height_p) - *min_height_p = 0; - - if (natural_height_p) - *natural_height_p = 0; - } - else - { - PangoLayout *layout; - PangoRectangle logical_rect = { 0, }; - ClutterUnit height; - - layout = clutter_label_create_layout (label, for_width); - - pango_layout_get_extents (layout, NULL, &logical_rect); - height = CLUTTER_UNITS_FROM_PANGO_UNIT (logical_rect.height); - - if (min_height_p) - *min_height_p = height; - - if (natural_height_p) - *natural_height_p = height; - } -} - -static void -clutter_label_allocate (ClutterActor *self, - const ClutterActorBox *box, - gboolean origin_changed) -{ - ClutterLabel *label = CLUTTER_LABEL (self); - ClutterActorClass *parent_class; - - /* Ensure that there is a cached label with the right width so that - we don't need to create the label during the paint run */ - clutter_label_create_layout (label, box->x2 - box->x1); - - parent_class = CLUTTER_ACTOR_CLASS (clutter_label_parent_class); - parent_class->allocate (self, box, origin_changed); -} - -static void -clutter_label_dispose (GObject *object) -{ - ClutterLabel *self = CLUTTER_LABEL(object); - ClutterLabelPrivate *priv; - - priv = self->priv; - - /* Get rid of the cached layouts */ - clutter_label_dirty_cache (self); - - G_OBJECT_CLASS (clutter_label_parent_class)->dispose (object); -} - -static void -clutter_label_finalize (GObject *object) -{ - ClutterLabel *self = CLUTTER_LABEL(object); - ClutterLabelPrivate *priv; - - priv = self->priv; - - if (priv->font_desc) - pango_font_description_free (priv->font_desc); - - g_free (priv->text); - g_free (priv->font_name); - - G_OBJECT_CLASS (clutter_label_parent_class)->finalize (object); -} - -static void -clutter_label_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - ClutterLabel *label; - ClutterLabelPrivate *priv; - - label = CLUTTER_LABEL(object); - priv = label->priv; - - switch (prop_id) - { - case PROP_FONT_NAME: - clutter_label_set_font_name (label, g_value_get_string (value)); - break; - case PROP_TEXT: - clutter_label_set_text (label, g_value_get_string (value)); - break; - case PROP_COLOR: - clutter_label_set_color (label, clutter_value_get_color (value)); - break; - case PROP_ATTRIBUTES: - clutter_label_set_attributes (label, g_value_get_boxed (value)); - break; - case PROP_ALIGNMENT: - clutter_label_set_alignment (label, g_value_get_enum (value)); - break; - case PROP_USE_MARKUP: - clutter_label_set_use_markup (label, g_value_get_boolean (value)); - break; - case PROP_WRAP: - clutter_label_set_line_wrap (label, g_value_get_boolean (value)); - break; - case PROP_JUSTIFY: - clutter_label_set_justify (label, g_value_get_boolean (value)); - break; - case PROP_WRAP_MODE: - clutter_label_set_line_wrap_mode (label, g_value_get_enum (value)); - break; - case PROP_ELLIPSIZE: - clutter_label_set_ellipsize (label, g_value_get_enum (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -clutter_label_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - ClutterLabel *label; - ClutterLabelPrivate *priv; - - label = CLUTTER_LABEL (object); - priv = label->priv; - - switch (prop_id) - { - case PROP_FONT_NAME: - g_value_set_string (value, priv->font_name); - break; - case PROP_TEXT: - g_value_set_string (value, priv->text); - break; - case PROP_COLOR: - clutter_value_set_color (value, &priv->fgcol); - break; - case PROP_ATTRIBUTES: - g_value_set_boxed (value, priv->attrs); - break; - case PROP_ALIGNMENT: - g_value_set_enum (value, priv->alignment); - break; - case PROP_USE_MARKUP: - g_value_set_boolean (value, priv->use_markup); - break; - case PROP_JUSTIFY: - g_value_set_boolean (value, priv->justify); - break; - case PROP_WRAP: - g_value_set_boolean (value, priv->wrap); - break; - case PROP_WRAP_MODE: - g_value_set_enum (value, priv->wrap_mode); - break; - case PROP_ELLIPSIZE: - g_value_set_enum (value, priv->ellipsize); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -clutter_label_class_init (ClutterLabelClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); - GParamSpec *pspec; - - actor_class->paint = clutter_label_paint; - actor_class->get_preferred_width = clutter_label_get_preferred_width; - actor_class->get_preferred_height = clutter_label_get_preferred_height; - actor_class->allocate = clutter_label_allocate; - - gobject_class->finalize = clutter_label_finalize; - gobject_class->dispose = clutter_label_dispose; - gobject_class->set_property = clutter_label_set_property; - gobject_class->get_property = clutter_label_get_property; - - /** - * ClutterLabel:font-name: - * - * The font to be used by the #ClutterLabel, as a string - * that can be parsed by pango_font_description_from_string(). - * - * Since: 0.2 - */ - pspec = g_param_spec_string ("font-name", - "Font Name", - "The font to be used by the label", - NULL, - CLUTTER_PARAM_READWRITE); - g_object_class_install_property (gobject_class, PROP_FONT_NAME, pspec); - - pspec = g_param_spec_string ("text", - "Text", - "The text to render", - NULL, - CLUTTER_PARAM_READWRITE); - g_object_class_install_property (gobject_class, PROP_TEXT, pspec); - - pspec = clutter_param_spec_color ("color", - "Font Color", - "Color of the font used by the label", - &default_text_color, - CLUTTER_PARAM_READWRITE); - g_object_class_install_property (gobject_class, PROP_COLOR, pspec); - - pspec = g_param_spec_boxed ("attributes", - "Attributes", - "A list of style attributes to apply to " - "the text of the label", - PANGO_TYPE_ATTR_LIST, - CLUTTER_PARAM_READWRITE); - g_object_class_install_property (gobject_class, PROP_ATTRIBUTES, pspec); - - /** - * ClutterLabel:use-markup: - * - * Whether the text of the label includes Pango markup. See - * pango_layout_set_markup() in the Pango documentation. - * - * Since: 0.2 - */ - pspec = g_param_spec_boolean ("use-markup", - "Use markup", - "Whether or not the text of the label " - "includes Pango markup", - FALSE, - CLUTTER_PARAM_READWRITE); - g_object_class_install_property (gobject_class, PROP_USE_MARKUP, pspec); - - /** - * ClutterLabel:wrap: - * - * Whether to wrap the lines of #ClutterLabel:text if the contents - * exceed the available allocation. The wrapping strategy is - * controlled by the #ClutterLabel:wrap-mode property. - * - * Since: 0.2 - */ - pspec = g_param_spec_boolean ("wrap", - "Line wrap", - "If set, wrap the lines if the text " - "becomes too wide", - FALSE, - CLUTTER_PARAM_READWRITE); - g_object_class_install_property (gobject_class, PROP_WRAP, pspec); - - /** - * ClutterLabel:wrap-mode: - * - * If #ClutterLabel:wrap is set to %TRUE, this property will - * control how the text is wrapped. - * - * Since: 0.2 - */ - pspec = g_param_spec_enum ("wrap-mode", - "Line wrap mode", - "Control how line-wrapping is done", - PANGO_TYPE_WRAP_MODE, - PANGO_WRAP_WORD, - CLUTTER_PARAM_READWRITE); - g_object_class_install_property (gobject_class, PROP_WRAP_MODE, pspec); - - pspec = g_param_spec_enum ("ellipsize", - "Ellipsize", - "The preferred place to ellipsize the string, " - "if the label does not have enough room to " - "display the entire string", - PANGO_TYPE_ELLIPSIZE_MODE, - PANGO_ELLIPSIZE_NONE, - CLUTTER_PARAM_READWRITE); - g_object_class_install_property (gobject_class, PROP_ELLIPSIZE, pspec); - - /** - * ClutterLabel:alignment: - * - * The preferred alignment for the text. This property controls - * the alignment of multi-line paragraphs. - * - * Since: 0.2 - */ - pspec = g_param_spec_enum ("alignment", - "Alignment", - "The preferred alignment for the string, " - "for multi-line text", - PANGO_TYPE_ALIGNMENT, - PANGO_ALIGN_LEFT, - CLUTTER_PARAM_READWRITE); - g_object_class_install_property (gobject_class, PROP_ALIGNMENT, pspec); - - /** - * ClutterLabel:justify: - * - * Whether the contents of the label should be justified on both - * margins. - * - * Since: 0.6 - */ - pspec = g_param_spec_boolean ("justify", - "Justify", - "Whether the contents of the label " - "should be justified", - FALSE, - CLUTTER_PARAM_READWRITE); - g_object_class_install_property (gobject_class, PROP_JUSTIFY, pspec); - - g_type_class_add_private (gobject_class, sizeof (ClutterLabelPrivate)); -} - -static void -clutter_label_init (ClutterLabel *self) -{ - ClutterLabelPrivate *priv; - int i; - - self->priv = priv = CLUTTER_LABEL_GET_PRIVATE (self); - - if (G_UNLIKELY (_context == NULL)) - _context = _clutter_context_create_pango_context (CLUTTER_CONTEXT ()); - - priv->alignment = PANGO_ALIGN_LEFT; - priv->wrap = FALSE; - priv->wrap_mode = PANGO_WRAP_WORD; - priv->ellipsize = PANGO_ELLIPSIZE_NONE; - priv->use_underline = FALSE; - priv->use_markup = FALSE; - priv->justify = FALSE; - - for (i = 0; i < CLUTTER_LABEL_N_CACHED_LAYOUTS; i++) - priv->cached_layouts[i].layout = NULL; - - priv->text = NULL; - priv->attrs = NULL; - - priv->fgcol = default_text_color; - - priv->font_name = g_strdup (DEFAULT_FONT_NAME); - priv->font_desc = pango_font_description_from_string (priv->font_name); -} - -/** - * clutter_label_new_with_text: - * @font_name: the name (and size) of the font to be used - * @text: the text to be displayed - * - * Creates a new #ClutterLabel displaying @text using @font_name. - * - * Return value: a #ClutterLabel - */ -ClutterActor* -clutter_label_new_with_text (const gchar *font_name, - const gchar *text) -{ - return g_object_new (CLUTTER_TYPE_LABEL, - "font-name", font_name, - "text", text, - NULL); -} - -/** - * clutter_label_new_full: - * @font_name: the name (and size) of the font to be used - * @text: the text to be displayed - * @color: #ClutterColor for text - * - * Creates a new #ClutterLabel displaying @text with @color - * using @font_name. - * - * Return value: a #ClutterLabel - */ -ClutterActor* -clutter_label_new_full (const gchar *font_name, - const gchar *text, - const ClutterColor *color) -{ - return g_object_new (CLUTTER_TYPE_LABEL, - "font-name", font_name, - "text", text, - "color", color, - NULL); -} - -/** - * clutter_label_new: - * - * Creates a new, empty #ClutterLabel. - * - * Returns: the newly created #ClutterLabel - */ -ClutterActor * -clutter_label_new (void) -{ - return g_object_new (CLUTTER_TYPE_LABEL, NULL); -} - -/** - * clutter_label_get_text: - * @label: a #ClutterLabel - * - * Retrieves the text displayed by @label - * - * Return value: the text of the label. The returned string is - * owned by #ClutterLabel and should not be modified or freed. - */ -G_CONST_RETURN gchar * -clutter_label_get_text (ClutterLabel *label) -{ - g_return_val_if_fail (CLUTTER_IS_LABEL (label), NULL); - - return label->priv->text; -} - -/** - * clutter_label_set_text: - * @label: a #ClutterLabel - * @text: the text to be displayed - * - * Sets @text as the text to be displayed by @label. - */ -void -clutter_label_set_text (ClutterLabel *label, - const gchar *text) -{ - ClutterLabelPrivate *priv; - - g_return_if_fail (CLUTTER_IS_LABEL (label)); - - priv = label->priv; - - g_free (priv->text); - - priv->text = g_strdup (text); - - clutter_label_dirty_cache (label); - - clutter_actor_queue_relayout (CLUTTER_ACTOR (label)); - - g_object_notify (G_OBJECT (label), "text"); -} - -/** - * clutter_label_get_font_name: - * @label: a #ClutterLabel - * - * Retrieves the font used by @label. - * - * Return value: a string containing the font name, in a format - * understandable by pango_font_description_from_string(). The - * string is owned by @label and should not be modified - * or freed. - */ -G_CONST_RETURN gchar * -clutter_label_get_font_name (ClutterLabel *label) -{ - g_return_val_if_fail (CLUTTER_IS_LABEL (label), NULL); - - return label->priv->font_name; -} - -/** - * clutter_label_set_font_name: - * @label: a #ClutterLabel - * @font_name: a font name and size, or %NULL for the default font - * - * Sets @font_name as the font used by @label. - * - * @font_name must be a string containing the font name and its - * size, similarly to what you would feed to the - * pango_font_description_from_string() function. - */ -void -clutter_label_set_font_name (ClutterLabel *label, - const gchar *font_name) -{ - ClutterLabelPrivate *priv; - PangoFontDescription *desc; - - g_return_if_fail (CLUTTER_IS_LABEL (label)); - - if (!font_name || font_name[0] == '\0') - font_name = DEFAULT_FONT_NAME; - - priv = label->priv; - - if (strcmp (priv->font_name, font_name) == 0) - return; - - desc = pango_font_description_from_string (font_name); - if (!desc) - { - g_warning ("Attempting to create a PangoFontDescription for " - "font name `%s', but failed.", - font_name); - return; - } - - g_free (priv->font_name); - priv->font_name = g_strdup (font_name); - - if (priv->font_desc) - pango_font_description_free (priv->font_desc); - - priv->font_desc = desc; - - clutter_label_dirty_cache (label); - - if (label->priv->text && label->priv->text[0] != '\0') - clutter_actor_queue_relayout (CLUTTER_ACTOR (label)); - - g_object_notify (G_OBJECT (label), "font-name"); -} - - -/** - * clutter_label_set_color: - * @label: a #ClutterLabel - * @color: a #ClutterColor - * - * Sets the color of @label. - */ -void -clutter_label_set_color (ClutterLabel *label, - const ClutterColor *color) -{ - ClutterActor *actor; - ClutterLabelPrivate *priv; - - g_return_if_fail (CLUTTER_IS_LABEL (label)); - g_return_if_fail (color != NULL); - - priv = label->priv; - - g_object_ref (label); - - priv->fgcol.red = color->red; - priv->fgcol.green = color->green; - priv->fgcol.blue = color->blue; - priv->fgcol.alpha = color->alpha; - - actor = CLUTTER_ACTOR (label); - - clutter_actor_set_opacity (actor, priv->fgcol.alpha); - - if (CLUTTER_ACTOR_IS_VISIBLE (actor)) - clutter_actor_queue_redraw (actor); - - g_object_notify (G_OBJECT (label), "color"); - g_object_unref (label); -} - -/** - * clutter_label_get_color: - * @label: a #ClutterLabel - * @color: return location for a #ClutterColor - * - * Retrieves the color of @label. - */ -void -clutter_label_get_color (ClutterLabel *label, - ClutterColor *color) -{ - ClutterLabelPrivate *priv; - - g_return_if_fail (CLUTTER_IS_LABEL (label)); - g_return_if_fail (color != NULL); - - priv = label->priv; - - color->red = priv->fgcol.red; - color->green = priv->fgcol.green; - color->blue = priv->fgcol.blue; - color->alpha = priv->fgcol.alpha; -} - -/** - * clutter_label_set_ellipsize: - * @label: a #ClutterLabel - * @mode: a #PangoEllipsizeMode - * - * Sets the mode used to ellipsize (add an ellipsis: "...") to the text - * if there is not enough space to render the entire string. - * - * Since: 0.2 - **/ -void -clutter_label_set_ellipsize (ClutterLabel *label, - PangoEllipsizeMode mode) -{ - ClutterLabelPrivate *priv; - - g_return_if_fail (CLUTTER_IS_LABEL (label)); - g_return_if_fail (mode >= PANGO_ELLIPSIZE_NONE && - mode <= PANGO_ELLIPSIZE_END); - - priv = label->priv; - - if ((PangoEllipsizeMode) priv->ellipsize != mode) - { - priv->ellipsize = mode; - - clutter_label_dirty_cache (label); - - clutter_actor_queue_relayout (CLUTTER_ACTOR (label)); - - g_object_notify (G_OBJECT (label), "ellipsize"); - } -} - -/** - * clutter_label_get_ellipsize: - * @label: a #ClutterLabel - * - * Returns the ellipsizing position of the label. - * See clutter_label_set_ellipsize(). - * - * Return value: #PangoEllipsizeMode - * - * Since: 0.2 - **/ -PangoEllipsizeMode -clutter_label_get_ellipsize (ClutterLabel *label) -{ - g_return_val_if_fail (CLUTTER_IS_LABEL (label), PANGO_ELLIPSIZE_NONE); - - return label->priv->ellipsize; -} - -/** - * clutter_label_set_line_wrap: - * @label: a #ClutterLabel - * @wrap: the setting - * - * Toggles line wrapping within the #ClutterLabel widget. %TRUE makes - * it break lines if text exceeds the widget's size. %FALSE lets the - * text get cut off by the edge of the widget if it exceeds the widget - * size. - * - * Since: 0.2 - */ -void -clutter_label_set_line_wrap (ClutterLabel *label, - gboolean wrap) -{ - ClutterLabelPrivate *priv; - - g_return_if_fail (CLUTTER_IS_LABEL (label)); - - priv = label->priv; - - wrap = wrap != FALSE; - - if (priv->wrap != wrap) - { - priv->wrap = wrap; - - clutter_label_dirty_cache (label); - - clutter_actor_queue_relayout (CLUTTER_ACTOR (label)); - - g_object_notify (G_OBJECT (label), "wrap"); - } -} - -/** - * clutter_label_get_line_wrap: - * @label: a #ClutterLabel - * - * Returns whether lines in the label are automatically wrapped. - * See clutter_label_set_line_wrap (). - * - * Return value: %TRUE if the lines of the label are automatically wrapped. - * - * Since: 0.2 - */ -gboolean -clutter_label_get_line_wrap (ClutterLabel *label) -{ - g_return_val_if_fail (CLUTTER_IS_LABEL (label), FALSE); - - return label->priv->wrap; -} - -/** - * clutter_label_set_line_wrap_mode: - * @label: a #ClutterLabel - * @wrap_mode: the line wrapping mode - * - * If line wrapping is on (see clutter_label_set_line_wrap()) this controls how - * the line wrapping is done. The default is %PANGO_WRAP_WORD which means - * wrap on word boundaries. - * - * Since: 0.2 - **/ -void -clutter_label_set_line_wrap_mode (ClutterLabel *label, - PangoWrapMode wrap_mode) -{ - ClutterLabelPrivate *priv; - - g_return_if_fail (CLUTTER_IS_LABEL (label)); - - priv = label->priv; - - if (priv->wrap_mode != wrap_mode) - { - priv->wrap_mode = wrap_mode; - - clutter_label_dirty_cache (label); - - clutter_actor_queue_relayout (CLUTTER_ACTOR (label)); - - g_object_notify (G_OBJECT (label), "wrap-mode"); - } -} - -/** - * clutter_label_get_line_wrap_mode: - * @label: a #ClutterLabel - * - * Returns line wrap mode used by the label. - * See clutter_label_set_line_wrap_mode (). - * - * Return value: %TRUE if the lines of the label are automatically wrapped. - * - * Since: 0.2 - */ -PangoWrapMode -clutter_label_get_line_wrap_mode (ClutterLabel *label) -{ - g_return_val_if_fail (CLUTTER_IS_LABEL (label), FALSE); - - return label->priv->wrap_mode; -} - -/** - * clutter_label_get_layout: - * @label: a #ClutterLabel - * - * Gets the #PangoLayout used to display the label. - * The layout is useful to e.g. convert text positions to - * pixel positions. - * The returned layout is owned by the label so need not be - * freed by the caller. - * - * Return value: the #PangoLayout for this label - * - * Since: 0.2 - **/ -PangoLayout * -clutter_label_get_layout (ClutterLabel *label) -{ - ClutterUnit width; - - g_return_val_if_fail (CLUTTER_IS_LABEL (label), NULL); - - width = clutter_actor_get_widthu (CLUTTER_ACTOR (label)); - - return clutter_label_create_layout (label, width); -} - -static inline void -clutter_label_set_attributes_internal (ClutterLabel *label, - PangoAttrList *attrs) -{ -} - -/** - * clutter_label_set_attributes: - * @label: a #ClutterLabel - * @attrs: a #PangoAttrList - * - * Sets a #PangoAttrList; the attributes in the list are applied to the - * label text. The attributes set with this function will be ignored - * if the "use_markup" property - * is %TRUE. - * - * Since: 0.2 - **/ -void -clutter_label_set_attributes (ClutterLabel *label, - PangoAttrList *attrs) -{ - ClutterLabelPrivate *priv; - - g_return_if_fail (CLUTTER_IS_LABEL (label)); - - priv = label->priv; - - if (attrs) - pango_attr_list_ref (attrs); - - if (priv->attrs) - pango_attr_list_unref (priv->attrs); - - if (!priv->use_markup) - { - if (attrs) - pango_attr_list_ref (attrs); - - if (priv->effective_attrs) - pango_attr_list_unref (priv->effective_attrs); - - priv->effective_attrs = attrs; - } - - priv->attrs = attrs; - - clutter_label_dirty_cache (label); - - g_object_notify (G_OBJECT (label), "attributes"); - - clutter_actor_queue_relayout (CLUTTER_ACTOR (label)); -} - -/** - * clutter_label_get_attributes: - * @label: a #ClutterLabel - * - * Gets the attribute list that was set on the label using - * clutter_label_set_attributes(), if any. - * - * Return value: the attribute list, or %NULL if none was set. - * - * Since: 0.2 - **/ -PangoAttrList * -clutter_label_get_attributes (ClutterLabel *label) -{ - g_return_val_if_fail (CLUTTER_IS_LABEL (label), NULL); - - return label->priv->attrs; -} - -/** - * clutter_label_set_use_markup: - * @label: a #ClutterLabel - * @setting: %TRUE if the label's text should be parsed for markup. - * - * Sets whether the text of the label contains markup in Pango's text markup - * language. - **/ -void -clutter_label_set_use_markup (ClutterLabel *label, - gboolean setting) -{ - ClutterLabelPrivate *priv; - - g_return_if_fail (CLUTTER_IS_LABEL (label)); - - priv = label->priv; - - if (priv->use_markup != setting) - { - priv->use_markup = setting; - - clutter_label_dirty_cache (label); - - clutter_actor_queue_relayout (CLUTTER_ACTOR (label)); - - g_object_notify (G_OBJECT (label), "use-markup"); - } -} - -/** - * clutter_label_get_use_markup: - * @label: a #ClutterLabel - * - * Returns whether the label's text is interpreted as marked up with - * the Pango text markup - * language. See clutter_label_set_use_markup (). - * - * Return value: %TRUE if the label's text will be parsed for markup. - **/ -gboolean -clutter_label_get_use_markup (ClutterLabel *label) -{ - g_return_val_if_fail (CLUTTER_IS_LABEL (label), FALSE); - - return label->priv->use_markup; -} - -/** - * clutter_label_set_alignment: - * @label: a #ClutterLabel - * @alignment: A #PangoAlignment - * - * Sets text alignment of the label. - * - * The alignment will only be used when the contents of the - * label are enough to wrap, and the #ClutterLabel:wrap - * property is set to %TRUE. - **/ -void -clutter_label_set_alignment (ClutterLabel *label, - PangoAlignment alignment) -{ - ClutterLabelPrivate *priv; - - g_return_if_fail (CLUTTER_IS_LABEL (label)); - - priv = label->priv; - - if (priv->alignment != alignment) - { - priv->alignment = alignment; - - clutter_label_dirty_cache (label); - - clutter_actor_queue_relayout (CLUTTER_ACTOR (label)); - - g_object_notify (G_OBJECT (label), "alignment"); - } -} - -/** - * clutter_label_get_alignment: - * @label: a #ClutterLabel - * - * Returns the label's text alignment - * - * Return value: The label's #PangoAlignment - * - * Since: 0.2 - **/ -PangoAlignment -clutter_label_get_alignment (ClutterLabel *label) -{ - g_return_val_if_fail (CLUTTER_IS_LABEL (label), FALSE); - - return label->priv->alignment; -} - -/** - * clutter_label_set_justify: - * @label: a #ClutterLabel - * @justify: whether the text should be justified - * - * Sets whether the text of the @label actor should be justified - * on both margins. This setting is ignored if Clutter is compiled - * against Pango < 1.18. - * - * Since: 0.6 - */ -void -clutter_label_set_justify (ClutterLabel *label, - gboolean justify) -{ - ClutterLabelPrivate *priv; - - g_return_if_fail (CLUTTER_IS_LABEL (label)); - - priv = label->priv; - - if (priv->justify != justify) - { - priv->justify = justify; - - clutter_label_dirty_cache (label); - - clutter_actor_queue_relayout (CLUTTER_ACTOR (label)); - - g_object_notify (G_OBJECT (label), "justify"); - } -} - -/** - * clutter_label_get_justify: - * @label: a #ClutterLabel - * - * Retrieves whether the label should justify the text on both margins. - * - * Return value: %TRUE if the text should be justified - * - * Since: 0.6 - */ -gboolean -clutter_label_get_justify (ClutterLabel *label) -{ - g_return_val_if_fail (CLUTTER_IS_LABEL (label), FALSE); - - return label->priv->justify; -} diff --git a/clutter/clutter-label.h b/clutter/clutter-label.h deleted file mode 100644 index d6021c2f3..000000000 --- a/clutter/clutter-label.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Authored By Matthew Allum - * - * Copyright (C) 2006 OpenedHand - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) -#error "Only can be included directly." -#endif - -#ifndef __CLUTTER_LABEL_H__ -#define __CLUTTER_LABEL_H__ - -#include -#include -#include - - -G_BEGIN_DECLS - -#define CLUTTER_TYPE_LABEL (clutter_label_get_type ()) - -#define CLUTTER_LABEL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - CLUTTER_TYPE_LABEL, ClutterLabel)) - -#define CLUTTER_LABEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - CLUTTER_TYPE_LABEL, ClutterLabelClass)) - -#define CLUTTER_IS_LABEL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - CLUTTER_TYPE_LABEL)) - -#define CLUTTER_IS_LABEL_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - CLUTTER_TYPE_LABEL)) - -#define CLUTTER_LABEL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - CLUTTER_TYPE_LABEL, ClutterLabelClass)) - -typedef struct _ClutterLabel ClutterLabel; -typedef struct _ClutterLabelClass ClutterLabelClass; -typedef struct _ClutterLabelPrivate ClutterLabelPrivate; - -struct _ClutterLabel -{ - ClutterActor parent; - - /*< private >*/ - ClutterLabelPrivate *priv; -}; - -struct _ClutterLabelClass -{ - /*< private >*/ - ClutterActorClass parent_class; - - void (*_clutter_label_1) (void); - void (*_clutter_label_2) (void); - void (*_clutter_label_3) (void); - void (*_clutter_label_4) (void); -}; - -GType clutter_label_get_type (void) G_GNUC_CONST; - -ClutterActor * clutter_label_new (void); - -ClutterActor* clutter_label_new_full (const gchar *font_name, - const gchar *text, - const ClutterColor *color); - -ClutterActor * clutter_label_new_with_text (const gchar *font_name, - const gchar *text); -void clutter_label_set_text (ClutterLabel *label, - const gchar *text); -G_CONST_RETURN gchar *clutter_label_get_text (ClutterLabel *label); -void clutter_label_set_font_name (ClutterLabel *label, - const gchar *font_name); -G_CONST_RETURN gchar *clutter_label_get_font_name (ClutterLabel *label); -void clutter_label_set_color (ClutterLabel *label, - const ClutterColor *color); -void clutter_label_get_color (ClutterLabel *label, - ClutterColor *color); -void clutter_label_set_ellipsize (ClutterLabel *label, - PangoEllipsizeMode mode); -PangoEllipsizeMode clutter_label_get_ellipsize (ClutterLabel *label); -void clutter_label_set_line_wrap (ClutterLabel *label, - gboolean wrap); -gboolean clutter_label_get_line_wrap (ClutterLabel *label); -void clutter_label_set_line_wrap_mode (ClutterLabel *label, - PangoWrapMode wrap_mode); -PangoWrapMode clutter_label_get_line_wrap_mode (ClutterLabel *label); -PangoLayout * clutter_label_get_layout (ClutterLabel *label); -void clutter_label_set_attributes (ClutterLabel *label, - PangoAttrList *attrs); -PangoAttrList * clutter_label_get_attributes (ClutterLabel *label); -void clutter_label_set_use_markup (ClutterLabel *label, - gboolean setting); -gboolean clutter_label_get_use_markup (ClutterLabel *label); -void clutter_label_set_alignment (ClutterLabel *label, - PangoAlignment alignment); -PangoAlignment clutter_label_get_alignment (ClutterLabel *label); -void clutter_label_set_justify (ClutterLabel *label, - gboolean justify); -gboolean clutter_label_get_justify (ClutterLabel *label); - -G_END_DECLS - -#endif /* __CLUTTER_LABEL_H__ */