2007-05-31 18:33:42 +00:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
2008-06-24 10:22:53 +00:00
|
|
|
* Neil Jagdish Patel <njp@o-hand.com>
|
2007-05-31 18:33:42 +00:00
|
|
|
*
|
|
|
|
* 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
|
2007-06-01 11:34:40 +00:00
|
|
|
* @short_description: A single line text entry actor
|
2007-05-31 18:33:42 +00:00
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* #ClutterEntry is a #ClutterTexture that allows single line text entry.
|
|
|
|
*
|
|
|
|
* #ClutterEntry is available since Clutter 0.4.
|
2007-05-31 18:33:42 +00:00
|
|
|
*/
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-05-31 18:33:42 +00:00
|
|
|
#include "config.h"
|
2007-10-12 08:17:00 +00:00
|
|
|
#endif
|
2007-05-31 18:33:42 +00:00
|
|
|
|
2008-06-23 10:32:43 +00:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
#include "clutter-entry.h"
|
2007-06-01 11:34:40 +00:00
|
|
|
|
|
|
|
#include "clutter-debug.h"
|
2007-05-31 18:33:42 +00:00
|
|
|
#include "clutter-enum-types.h"
|
2007-06-01 11:34:40 +00:00
|
|
|
#include "clutter-keysyms.h"
|
|
|
|
#include "clutter-main.h"
|
2007-06-01 15:18:05 +00:00
|
|
|
#include "clutter-marshal.h"
|
2007-05-31 18:33:42 +00:00
|
|
|
#include "clutter-private.h"
|
|
|
|
#include "clutter-rectangle.h"
|
2007-06-01 11:34:40 +00:00
|
|
|
#include "clutter-units.h"
|
2008-10-30 17:11:29 +00:00
|
|
|
|
|
|
|
#include "cogl-pango.h"
|
2007-05-31 18:33:42 +00:00
|
|
|
|
|
|
|
#define DEFAULT_FONT_NAME "Sans 10"
|
2007-06-01 15:18:05 +00:00
|
|
|
#define ENTRY_CURSOR_WIDTH 1
|
2007-06-01 16:50:35 +00:00
|
|
|
#define ENTRY_PADDING 5
|
2007-05-31 18:33:42 +00:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (ClutterEntry, clutter_entry, CLUTTER_TYPE_ACTOR);
|
|
|
|
|
|
|
|
/* Probably move into main */
|
|
|
|
static PangoContext *_context = NULL;
|
|
|
|
|
2008-11-17 14:21:49 +00:00
|
|
|
static const ClutterColor default_text_color = { 0, 0, 0, 255 };
|
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2007-07-04 09:33:04 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
PROP_FONT_NAME,
|
|
|
|
PROP_TEXT,
|
|
|
|
PROP_COLOR,
|
|
|
|
PROP_ALIGNMENT, /* FIXME */
|
|
|
|
PROP_POSITION,
|
2007-06-01 15:58:17 +00:00
|
|
|
PROP_CURSOR,
|
2007-06-01 17:18:21 +00:00
|
|
|
PROP_TEXT_VISIBLE,
|
2007-07-04 09:33:04 +00:00
|
|
|
PROP_MAX_LENGTH,
|
2007-10-26 15:56:17 +00:00
|
|
|
PROP_ENTRY_PADDING,
|
|
|
|
PROP_X_ALIGN
|
2007-05-31 18:33:42 +00:00
|
|
|
};
|
|
|
|
|
2007-06-01 11:50:18 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
TEXT_CHANGED,
|
2007-06-01 15:18:05 +00:00
|
|
|
CURSOR_EVENT,
|
2007-06-07 21:23:07 +00:00
|
|
|
ACTIVATE,
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 11:50:18 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint entry_signals[LAST_SIGNAL] = { 0, };
|
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
#define CLUTTER_ENTRY_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_ENTRY, ClutterEntryPrivate))
|
|
|
|
|
|
|
|
struct _ClutterEntryPrivate
|
|
|
|
{
|
|
|
|
PangoContext *context;
|
|
|
|
PangoFontDescription *desc;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
ClutterColor fgcol;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
gchar *text;
|
|
|
|
gchar *font_name;
|
2007-06-01 15:58:17 +00:00
|
|
|
gboolean text_visible;
|
|
|
|
gunichar priv_char;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
gint extents_width;
|
|
|
|
gint extents_height;
|
|
|
|
|
2007-10-26 15:56:17 +00:00
|
|
|
gint width;
|
2008-06-09 10:13:20 +00:00
|
|
|
gint n_chars; /* number of chars */
|
|
|
|
gint n_bytes; /* number of bytes */
|
2007-10-26 15:56:17 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
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;
|
2007-06-01 16:50:35 +00:00
|
|
|
gint text_x;
|
2007-06-01 17:18:21 +00:00
|
|
|
gint max_length;
|
2007-07-04 09:33:04 +00:00
|
|
|
gint entry_padding;
|
2007-10-26 15:56:17 +00:00
|
|
|
gdouble x_align;
|
2007-05-31 18:33:42 +00:00
|
|
|
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
PangoAttrList *effective_attrs;
|
|
|
|
PangoLayout *layout;
|
|
|
|
gint width_chars;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:18:05 +00:00
|
|
|
ClutterGeometry cursor_pos;
|
2007-05-31 18:33:42 +00:00
|
|
|
gboolean show_cursor;
|
|
|
|
};
|
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
static void
|
|
|
|
clutter_entry_set_entry_padding (ClutterEntry *entry,
|
|
|
|
guint padding)
|
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv = entry->priv;
|
|
|
|
|
|
|
|
if (priv->entry_padding != padding)
|
|
|
|
{
|
|
|
|
priv->entry_padding = padding;
|
|
|
|
|
2008-01-31 14:24:04 +00:00
|
|
|
if (CLUTTER_ACTOR_IS_VISIBLE (entry))
|
2007-07-04 09:33:04 +00:00
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (entry));
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (entry), "entry-padding");
|
|
|
|
}
|
|
|
|
}
|
2007-05-31 18:33:42 +00:00
|
|
|
|
|
|
|
static void
|
2007-10-12 08:17:00 +00:00
|
|
|
clutter_entry_set_property (GObject *object,
|
2007-05-31 18:33:42 +00:00
|
|
|
guint prop_id,
|
2007-10-12 08:17:00 +00:00
|
|
|
const GValue *value,
|
2007-05-31 18:33:42 +00:00
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ClutterEntry *entry;
|
|
|
|
ClutterEntryPrivate *priv;
|
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
entry = CLUTTER_ENTRY (object);
|
2007-05-31 18:33:42 +00:00
|
|
|
priv = entry->priv;
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
switch (prop_id)
|
2007-05-31 18:33:42 +00:00
|
|
|
{
|
|
|
|
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:
|
2008-11-17 14:21:49 +00:00
|
|
|
clutter_entry_set_color (entry, clutter_value_get_color (value));
|
2007-05-31 18:33:42 +00:00
|
|
|
break;
|
|
|
|
case PROP_ALIGNMENT:
|
|
|
|
clutter_entry_set_alignment (entry, g_value_get_enum (value));
|
|
|
|
break;
|
|
|
|
case PROP_POSITION:
|
2008-01-31 14:24:04 +00:00
|
|
|
clutter_entry_set_cursor_position (entry, g_value_get_int (value));
|
2007-05-31 18:33:42 +00:00
|
|
|
break;
|
|
|
|
case PROP_CURSOR:
|
|
|
|
clutter_entry_set_visible_cursor (entry, g_value_get_boolean (value));
|
|
|
|
break;
|
2007-06-01 15:58:17 +00:00
|
|
|
case PROP_TEXT_VISIBLE:
|
|
|
|
clutter_entry_set_visibility (entry, g_value_get_boolean (value));
|
|
|
|
break;
|
2007-06-01 17:18:21 +00:00
|
|
|
case PROP_MAX_LENGTH:
|
|
|
|
clutter_entry_set_max_length (entry, g_value_get_int (value));
|
|
|
|
break;
|
2007-07-04 09:33:04 +00:00
|
|
|
case PROP_ENTRY_PADDING:
|
|
|
|
clutter_entry_set_entry_padding (entry, g_value_get_uint (value));
|
|
|
|
break;
|
2007-10-26 15:56:17 +00:00
|
|
|
case PROP_X_ALIGN:
|
|
|
|
entry->priv->x_align = g_value_get_double (value);
|
2008-08-18 15:33:38 +00:00
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (object));
|
2007-10-26 15:56:17 +00:00
|
|
|
break;
|
2007-05-31 18:33:42 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-10-12 08:17:00 +00:00
|
|
|
clutter_entry_get_property (GObject *object,
|
2007-05-31 18:33:42 +00:00
|
|
|
guint prop_id,
|
2007-10-12 08:17:00 +00:00
|
|
|
GValue *value,
|
2007-05-31 18:33:42 +00:00
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ClutterEntry *entry;
|
|
|
|
ClutterEntryPrivate *priv;
|
|
|
|
|
|
|
|
entry = CLUTTER_ENTRY(object);
|
|
|
|
priv = entry->priv;
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
switch (prop_id)
|
2007-05-31 18:33:42 +00:00
|
|
|
{
|
|
|
|
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:
|
2008-11-17 14:21:49 +00:00
|
|
|
clutter_value_set_color (value, &priv->fgcol);
|
2007-05-31 18:33:42 +00:00
|
|
|
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;
|
2007-06-01 15:58:17 +00:00
|
|
|
case PROP_TEXT_VISIBLE:
|
|
|
|
g_value_set_boolean (value, priv->text_visible);
|
|
|
|
break;
|
2007-06-01 17:18:21 +00:00
|
|
|
case PROP_MAX_LENGTH:
|
|
|
|
g_value_set_int (value, priv->max_length);
|
|
|
|
break;
|
2007-07-04 09:33:04 +00:00
|
|
|
case PROP_ENTRY_PADDING:
|
|
|
|
g_value_set_uint (value, priv->entry_padding);
|
|
|
|
break;
|
2007-10-26 15:56:17 +00:00
|
|
|
case PROP_X_ALIGN:
|
|
|
|
g_value_set_double (value, priv->x_align);
|
|
|
|
break;
|
2007-05-31 18:33:42 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2007-10-12 08:17:00 +00:00
|
|
|
}
|
2007-05-31 18:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
pango_layout_set_alignment (priv->layout, priv->alignment);
|
|
|
|
pango_layout_set_ellipsize (priv->layout, priv->ellipsize);
|
2007-10-12 08:17:00 +00:00
|
|
|
pango_layout_set_single_paragraph_mode (priv->layout,
|
2007-05-31 18:33:42 +00:00
|
|
|
priv->single_line_mode);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
pango_layout_set_font_description (priv->layout, priv->desc);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:58:17 +00:00
|
|
|
if (priv->text_visible)
|
2008-06-09 10:13:20 +00:00
|
|
|
pango_layout_set_text (priv->layout, priv->text, priv->n_bytes);
|
2007-05-31 18:33:42 +00:00
|
|
|
else
|
2007-06-01 15:58:17 +00:00
|
|
|
{
|
2008-06-09 10:13:20 +00:00
|
|
|
GString *str = g_string_sized_new (priv->n_bytes);
|
|
|
|
gunichar invisible_char;
|
2008-06-24 10:40:58 +00:00
|
|
|
gchar buf[7];
|
|
|
|
gint char_len, i;
|
2007-10-26 15:56:17 +00:00
|
|
|
|
2008-06-09 10:13:20 +00:00
|
|
|
if (priv->priv_char != 0)
|
|
|
|
invisible_char = priv->priv_char;
|
|
|
|
else
|
|
|
|
invisible_char = '*';
|
|
|
|
|
2008-06-24 10:40:58 +00:00
|
|
|
/* 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);
|
|
|
|
|
2008-06-09 10:13:20 +00:00
|
|
|
for (i = 0; i < priv->n_chars; i++)
|
2008-06-24 10:40:58 +00:00
|
|
|
g_string_append_len (str, buf, char_len);
|
2008-06-09 10:13:20 +00:00
|
|
|
|
|
|
|
pango_layout_set_text (priv->layout, str->str, str->len);
|
2008-06-24 10:40:58 +00:00
|
|
|
|
2008-06-09 10:13:20 +00:00
|
|
|
g_string_free (str, TRUE);
|
2007-06-01 15:58:17 +00:00
|
|
|
}
|
2007-10-26 15:56:17 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
if (priv->wrap)
|
|
|
|
pango_layout_set_wrap (priv->layout, priv->wrap_mode);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
if (priv->wrap && width > 0)
|
2007-07-04 09:33:04 +00:00
|
|
|
pango_layout_set_width (priv->layout, width * PANGO_SCALE);
|
2007-05-31 18:33:42 +00:00
|
|
|
else
|
|
|
|
pango_layout_set_width (priv->layout, -1);
|
2008-05-28 Emmanuele Bassi <ebassi@openedhand.com>
Bug #919 - Replacement pango renderer (Neil Roberts)
* clutter/clutter-backend.h:
* clutter/clutter-backend.c:
(clutter_backend_set_font_options),
(clutter_backend_get_font_options): Add the ability to set
the cairo_font_options_t* for the backend at construction
time, so that backend implementations can have their own
options.
* clutter/clutter-color.c: Include pango/pango-attributes.h
for the pango_color_parse() function.
* clutter/clutter-label.c:
(clutter_label_ensure_layout),
(clutter_label_init), (clutter_label_set_text),
(clutter_label_set_font_name), (clutter_label_set_ellipsize),
(clutter_label_set_use_markup): Ensure that the cache is
always primed when the Label changes; this makes sure that
the cache is rebuilt outside the paint run, which should
make the painting perform better especially on embedded
devices.
* clutter/clutter-entry.c:
(clutter_entry_ensure_layout),
(clutter_entry_init), (clutter_entry_set_text),
(clutter_entry_set_font_name): Ditto as above.
* clutter/clutter-private.h:
* clutter/clutter-main.[ch]: Create the font-map inside the
main context; add two new functions:
clutter_clear_glyph_cache()
clutter_set_use_mipmapped_text()
that control the glyphs cache.
* clutter/pango/Makefile.am:
* clutter/pango/pangoclutter-fontmap.c:
* clutter/pango/pangoclutter-private.h:
* clutter/pango/pangoclutter-render.c:
* clutter/pango/pangoclutter.h: Rewrite the Pango renderer
using a PangoCairo context and saving the glyphs inside a
more efficient cache.
* configure.ac: Depend on pangocairo instead of pangoft2.
2008-05-28 14:03:28 +00:00
|
|
|
|
|
|
|
/* Prime the cache for the layout */
|
2008-10-30 17:11:29 +00:00
|
|
|
cogl_pango_ensure_glyph_cache_for_layout (priv->layout);
|
2007-05-31 18:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_entry_clear_layout (ClutterEntry *entry)
|
|
|
|
{
|
|
|
|
if (entry->priv->layout)
|
|
|
|
{
|
|
|
|
g_object_unref (entry->priv->layout);
|
|
|
|
entry->priv->layout = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-26 11:31:50 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
static void
|
|
|
|
clutter_entry_ensure_cursor_position (ClutterEntry *entry)
|
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv;
|
2007-08-07 14:07:39 +00:00
|
|
|
gint index_;
|
2007-07-26 11:31:50 +00:00
|
|
|
PangoRectangle rect;
|
2008-06-24 10:22:53 +00:00
|
|
|
gint priv_char_bytes;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
priv = entry->priv;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2008-06-24 10:22:53 +00:00
|
|
|
/* 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;
|
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
if (priv->position == -1)
|
2008-06-24 10:22:53 +00:00
|
|
|
{
|
|
|
|
if (priv->text_visible)
|
|
|
|
index_ = strlen (priv->text);
|
|
|
|
else
|
|
|
|
index_ = priv->n_chars * priv_char_bytes;
|
|
|
|
}
|
2007-05-31 18:33:42 +00:00
|
|
|
else
|
2008-06-24 10:22:53 +00:00
|
|
|
{
|
|
|
|
if (priv->text_visible)
|
|
|
|
index_ = offset_to_bytes (priv->text, priv->position);
|
|
|
|
else
|
|
|
|
index_ = priv->position * priv_char_bytes;
|
|
|
|
}
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-08-07 14:07:39 +00:00
|
|
|
pango_layout_get_cursor_pos (priv->layout, index_, &rect, NULL);
|
2007-07-04 09:33:04 +00:00
|
|
|
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;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
g_signal_emit (entry, entry_signals[CURSOR_EVENT], 0, &priv->cursor_pos);
|
2007-06-01 15:18:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_entry_clear_cursor_position (ClutterEntry *entry)
|
|
|
|
{
|
|
|
|
entry->priv->cursor_pos.width = 0;
|
|
|
|
}
|
2007-05-31 18:33:42 +00:00
|
|
|
|
2007-06-01 15:18:05 +00:00
|
|
|
void
|
|
|
|
clutter_entry_paint_cursor (ClutterEntry *entry)
|
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv;
|
|
|
|
|
|
|
|
priv = entry->priv;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:18:05 +00:00
|
|
|
if (priv->show_cursor)
|
|
|
|
{
|
2008-11-12 13:57:58 +00:00
|
|
|
cogl_set_source_color4ub (priv->fgcol.red,
|
|
|
|
priv->fgcol.green,
|
|
|
|
priv->fgcol.blue,
|
|
|
|
priv->fgcol.alpha);
|
|
|
|
|
2008-06-23 10:32:43 +00:00
|
|
|
cogl_rectangle (priv->cursor_pos.x,
|
|
|
|
priv->cursor_pos.y,
|
|
|
|
priv->cursor_pos.width,
|
|
|
|
priv->cursor_pos.height);
|
2007-10-12 08:17:00 +00:00
|
|
|
}
|
2007-05-31 18:33:42 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
static void
|
2007-05-31 18:33:42 +00:00
|
|
|
clutter_entry_paint (ClutterActor *self)
|
|
|
|
{
|
|
|
|
ClutterEntry *entry;
|
|
|
|
ClutterEntryPrivate *priv;
|
2007-06-01 16:50:35 +00:00
|
|
|
PangoRectangle logical;
|
2007-10-26 15:56:17 +00:00
|
|
|
gint width, actor_width;
|
2007-06-01 16:50:35 +00:00
|
|
|
gint text_width;
|
|
|
|
gint cursor_x;
|
2008-11-12 13:57:58 +00:00
|
|
|
CoglColor color = { 0, };
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
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;
|
|
|
|
}
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-10-26 15:56:17 +00:00
|
|
|
if (priv->width < 0)
|
|
|
|
width = clutter_actor_get_width (self);
|
|
|
|
else
|
|
|
|
width = priv->width;
|
|
|
|
|
2008-10-30 16:37:55 +00:00
|
|
|
cogl_clip_set (0, 0,
|
|
|
|
COGL_FIXED_FROM_INT (width),
|
|
|
|
COGL_FIXED_FROM_INT (clutter_actor_get_height (self)));
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-10-26 15:56:17 +00:00
|
|
|
actor_width = width - (2 * priv->entry_padding);
|
2007-06-01 16:50:35 +00:00
|
|
|
clutter_entry_ensure_layout (entry, actor_width);
|
2007-06-01 15:18:05 +00:00
|
|
|
clutter_entry_ensure_cursor_position (entry);
|
2007-05-31 18:33:42 +00:00
|
|
|
|
2007-06-01 16:50:35 +00:00
|
|
|
pango_layout_get_extents (priv->layout, NULL, &logical);
|
|
|
|
text_width = logical.width / PANGO_SCALE;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 16:50:35 +00:00
|
|
|
if (actor_width < text_width)
|
2007-05-31 18:33:42 +00:00
|
|
|
{
|
2007-06-01 16:50:35 +00:00
|
|
|
/* We need to do some scrolling */
|
|
|
|
cursor_x = priv->cursor_pos.x;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 16:50:35 +00:00
|
|
|
/* If the cursor is at the begining or the end of the text, the placement
|
2007-07-04 09:33:04 +00:00
|
|
|
* is easy, however, if the cursor is in the middle somewhere, we need to
|
2007-10-12 08:17:00 +00:00
|
|
|
* make sure the text doesn't move until the cursor is either in the
|
2007-07-04 09:33:04 +00:00
|
|
|
* far left or far right
|
|
|
|
*/
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 16:50:35 +00:00
|
|
|
if (priv->position == 0)
|
|
|
|
priv->text_x = 0;
|
|
|
|
else if (priv->position == -1)
|
|
|
|
{
|
|
|
|
priv->text_x = actor_width - text_width;
|
2007-07-04 09:33:04 +00:00
|
|
|
priv->cursor_pos.x += priv->text_x + priv->entry_padding;
|
2007-06-01 16:50:35 +00:00
|
|
|
}
|
2007-10-12 08:17:00 +00:00
|
|
|
else
|
2007-06-01 16:50:35 +00:00
|
|
|
{
|
2007-10-19 10:15:57 +00:00
|
|
|
if (priv->text_x <= 0)
|
2007-06-01 16:50:35 +00:00
|
|
|
{
|
|
|
|
gint diff = -1 * priv->text_x;
|
2007-07-04 09:33:04 +00:00
|
|
|
|
2007-06-01 16:50:35 +00:00
|
|
|
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);
|
|
|
|
}
|
2007-07-04 09:33:04 +00:00
|
|
|
|
|
|
|
priv->cursor_pos.x += priv->text_x + priv->entry_padding;
|
2007-06-01 16:50:35 +00:00
|
|
|
}
|
2007-10-12 08:17:00 +00:00
|
|
|
|
|
|
|
}
|
2007-06-01 16:50:35 +00:00
|
|
|
else
|
|
|
|
{
|
2007-10-26 15:56:17 +00:00
|
|
|
priv->text_x = (actor_width - text_width) * priv->x_align;
|
2008-08-18 15:33:38 +00:00
|
|
|
priv->cursor_pos.x += priv->text_x + priv->entry_padding;
|
2007-05-31 18:33:42 +00:00
|
|
|
}
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2008-10-30 17:11:29 +00:00
|
|
|
cogl_color_set_from_4ub (&color,
|
|
|
|
priv->fgcol.red,
|
|
|
|
priv->fgcol.green,
|
|
|
|
priv->fgcol.blue,
|
|
|
|
clutter_actor_get_paint_opacity (self));
|
2008-02-20 10:59:47 +00:00
|
|
|
|
2008-10-30 17:11:29 +00:00
|
|
|
cogl_pango_render_layout (priv->layout,
|
|
|
|
priv->text_x + priv->entry_padding, 0,
|
|
|
|
&color, 0);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
if (CLUTTER_ENTRY_GET_CLASS (entry)->paint_cursor)
|
2007-06-01 16:50:35 +00:00
|
|
|
CLUTTER_ENTRY_GET_CLASS (entry)->paint_cursor (entry);
|
2008-06-23 20:55:24 +00:00
|
|
|
|
|
|
|
cogl_clip_unset ();
|
2007-05-31 18:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com>
Bug #815 - Split up request, allocation, and paint box
* clutter/clutter-actor.[ch]: Rework the size allocation,
request and paint area. Now ::request_coords() is called
::allocate(), and ::query_coords() has been split into
::get_preferred_width() and ::get_preferred_height(). See
the documentation and the layout test on how to implement
a container and layout manager with the new API. (#915,
based on a patch by Havoc Pennington, Lucas Rocha and Johan
Bilien)
* clutter/clutter-clone-texture.c: Port CloneTexture to
the new size negotiation API; it just means forwarding
the requests to the parent texture.
* clutter/clutter-deprecated.h: Add deprecated and replaced
API.
* clutter/clutter-entry.c: Port Entry to the new size
negotiation API.
* clutter/clutter-group.c: Port Group to the new size
negotiation API; the semantics of the Group actor do not
change.
* clutter/clutter-label.c: Port Label to the new size
negotiation API, and vastly simplify the code.
* clutter/clutter-main.[ch]: Add API for executing a
relayout when needed.
* clutter/clutter-private.h: Add new Stage private API.
* clutter/clutter-rectangle.c: Update the get_abs_opacity()
call to get_paint_opacity().
* clutter/clutter-stage.c:
(clutter_stage_get_preferred_width),
(clutter_stage_get_preferred_height),
(clutter_stage_allocate),
(clutter_stage_class_init): Port Stage to the new size
negotiation API.
* clutter/clutter-texture.c: Port Texture to the new size
negotiation API.
* clutter/clutter-types.h: Add ClutterRequestMode enumeration.
* clutter/x11/clutter-stage-x11.c: Port the X11 stage
implementation to the new size negotiation API.
* tests/Makefile.am: Add the layout manager test case.
* tests/test-opacity.c: Update.
* tests/test-project.c: Update.
* tests/test-layout.c: Test case for a layout manager implemented
using the new size negotiation API; the layout manager handles
both transformed and untransformed children.
2008-06-10 17:07:52 +00:00
|
|
|
clutter_entry_allocate (ClutterActor *self,
|
|
|
|
const ClutterActorBox *box,
|
|
|
|
gboolean absolute_origin_changed)
|
2007-05-31 18:33:42 +00:00
|
|
|
{
|
2007-10-26 15:56:17 +00:00
|
|
|
ClutterEntry *entry = CLUTTER_ENTRY (self);
|
|
|
|
ClutterEntryPrivate *priv = entry->priv;
|
|
|
|
gint width;
|
|
|
|
|
2007-12-10 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/clutter-actor.c:
(clutter_actor_set_property),
(clutter_actor_get_property),
(clutter_actor_class_init): Add the rotation-* properties,
controlling the rotation angle and center on each axis. (#614)
(parse_rotation_array), (parse_rotation),
(clutter_actor_parse_custom_node),
(clutter_actor_set_custom_property),
(clutter_scriptable_iface_init): Add a new "rotation" custom
property for expressing the rotation along each axis in a
compact way:
"rotation" : [
{ "x-axis" : [ <angle>, [ <y>, <z> ] ] },
{ "y-axis" : [ <angle>, [ <x>, <z> ] ] },
{ "z-axis" : [ <angle>, [ <x>, <y> ] ] }
]
(clutter_geometry_get_type),(clutter_vertex_get_type),
(clutter_actor_box_get_type): Use the I_() macro instead of
directly calling g_intern_static_string().
* clutter/clutter-entry.c (clutter_entry_request_coords):
* clutter/clutter-label.c (clutter_label_ensure_layout),
(clutter_label_request_coords): Use CLUTTER_UNITS_FROM_DEVICE()
instead of CLUTTER_UNITS_FROM_INT(), as "device" means "pixels".
* clutter/clutter-private.h: Add the I_() macro for intern
static strings.
* tests/test-script.json: Test the newly added "rotation"
custom property.
2007-12-10 11:01:10 +00:00
|
|
|
width = CLUTTER_UNITS_TO_DEVICE (box->x2 - box->x1);
|
2007-10-26 15:56:17 +00:00
|
|
|
|
|
|
|
if (priv->width != width)
|
|
|
|
{
|
|
|
|
clutter_entry_clear_layout (entry);
|
|
|
|
clutter_entry_ensure_layout (entry, width);
|
|
|
|
|
|
|
|
priv->width = width;
|
|
|
|
}
|
2007-11-23 17:12:27 +00:00
|
|
|
|
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com>
Bug #815 - Split up request, allocation, and paint box
* clutter/clutter-actor.[ch]: Rework the size allocation,
request and paint area. Now ::request_coords() is called
::allocate(), and ::query_coords() has been split into
::get_preferred_width() and ::get_preferred_height(). See
the documentation and the layout test on how to implement
a container and layout manager with the new API. (#915,
based on a patch by Havoc Pennington, Lucas Rocha and Johan
Bilien)
* clutter/clutter-clone-texture.c: Port CloneTexture to
the new size negotiation API; it just means forwarding
the requests to the parent texture.
* clutter/clutter-deprecated.h: Add deprecated and replaced
API.
* clutter/clutter-entry.c: Port Entry to the new size
negotiation API.
* clutter/clutter-group.c: Port Group to the new size
negotiation API; the semantics of the Group actor do not
change.
* clutter/clutter-label.c: Port Label to the new size
negotiation API, and vastly simplify the code.
* clutter/clutter-main.[ch]: Add API for executing a
relayout when needed.
* clutter/clutter-private.h: Add new Stage private API.
* clutter/clutter-rectangle.c: Update the get_abs_opacity()
call to get_paint_opacity().
* clutter/clutter-stage.c:
(clutter_stage_get_preferred_width),
(clutter_stage_get_preferred_height),
(clutter_stage_allocate),
(clutter_stage_class_init): Port Stage to the new size
negotiation API.
* clutter/clutter-texture.c: Port Texture to the new size
negotiation API.
* clutter/clutter-types.h: Add ClutterRequestMode enumeration.
* clutter/x11/clutter-stage-x11.c: Port the X11 stage
implementation to the new size negotiation API.
* tests/Makefile.am: Add the layout manager test case.
* tests/test-opacity.c: Update.
* tests/test-project.c: Update.
* tests/test-layout.c: Test case for a layout manager implemented
using the new size negotiation API; the layout manager handles
both transformed and untransformed children.
2008-06-10 17:07:52 +00:00
|
|
|
CLUTTER_ACTOR_CLASS (clutter_entry_parent_class)->allocate (self, box, absolute_origin_changed);
|
2007-05-31 18:33:42 +00:00
|
|
|
}
|
|
|
|
|
2008-03-06 12:39:24 +00:00
|
|
|
static inline void
|
|
|
|
clutter_entry_handle_key_event_internal (ClutterEntry *entry,
|
|
|
|
ClutterKeyEvent *event)
|
|
|
|
{
|
2008-06-09 10:13:20 +00:00
|
|
|
gunichar key_unichar;
|
2008-03-06 12:39:24 +00:00
|
|
|
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:
|
2008-06-09 10:13:20 +00:00
|
|
|
key_unichar = clutter_key_event_unicode (event);
|
|
|
|
if (g_unichar_validate (key_unichar))
|
|
|
|
clutter_entry_insert_unichar (entry, key_unichar);
|
2008-03-06 12:39:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_entry_key_press (ClutterActor *actor,
|
|
|
|
ClutterKeyEvent *event)
|
|
|
|
{
|
|
|
|
clutter_entry_handle_key_event_internal (CLUTTER_ENTRY (actor), event);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
static void
|
2007-05-31 18:33:42 +00:00
|
|
|
clutter_entry_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
ClutterEntry *self = CLUTTER_ENTRY(object);
|
2007-10-12 08:17:00 +00:00
|
|
|
ClutterEntryPrivate *priv;
|
2007-05-31 18:33:42 +00:00
|
|
|
|
|
|
|
priv = self->priv;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
static void
|
2007-05-31 18:33:42 +00:00
|
|
|
clutter_entry_finalize (GObject *object)
|
|
|
|
{
|
2007-07-04 09:33:04 +00:00
|
|
|
ClutterEntryPrivate *priv = CLUTTER_ENTRY (object)->priv;
|
|
|
|
|
|
|
|
if (priv->desc)
|
2007-10-12 08:17:00 +00:00
|
|
|
pango_font_description_free (priv->desc);
|
2007-07-04 09:33:04 +00:00
|
|
|
|
|
|
|
g_free (priv->text);
|
|
|
|
g_free (priv->font_name);
|
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
G_OBJECT_CLASS (clutter_entry_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_entry_class_init (ClutterEntryClass *klass)
|
|
|
|
{
|
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com>
Bug #815 - Split up request, allocation, and paint box
* clutter/clutter-actor.[ch]: Rework the size allocation,
request and paint area. Now ::request_coords() is called
::allocate(), and ::query_coords() has been split into
::get_preferred_width() and ::get_preferred_height(). See
the documentation and the layout test on how to implement
a container and layout manager with the new API. (#915,
based on a patch by Havoc Pennington, Lucas Rocha and Johan
Bilien)
* clutter/clutter-clone-texture.c: Port CloneTexture to
the new size negotiation API; it just means forwarding
the requests to the parent texture.
* clutter/clutter-deprecated.h: Add deprecated and replaced
API.
* clutter/clutter-entry.c: Port Entry to the new size
negotiation API.
* clutter/clutter-group.c: Port Group to the new size
negotiation API; the semantics of the Group actor do not
change.
* clutter/clutter-label.c: Port Label to the new size
negotiation API, and vastly simplify the code.
* clutter/clutter-main.[ch]: Add API for executing a
relayout when needed.
* clutter/clutter-private.h: Add new Stage private API.
* clutter/clutter-rectangle.c: Update the get_abs_opacity()
call to get_paint_opacity().
* clutter/clutter-stage.c:
(clutter_stage_get_preferred_width),
(clutter_stage_get_preferred_height),
(clutter_stage_allocate),
(clutter_stage_class_init): Port Stage to the new size
negotiation API.
* clutter/clutter-texture.c: Port Texture to the new size
negotiation API.
* clutter/clutter-types.h: Add ClutterRequestMode enumeration.
* clutter/x11/clutter-stage-x11.c: Port the X11 stage
implementation to the new size negotiation API.
* tests/Makefile.am: Add the layout manager test case.
* tests/test-opacity.c: Update.
* tests/test-project.c: Update.
* tests/test-layout.c: Test case for a layout manager implemented
using the new size negotiation API; the layout manager handles
both transformed and untransformed children.
2008-06-10 17:07:52 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2007-05-31 18:33:42 +00:00
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
2008-11-17 14:21:49 +00:00
|
|
|
GParamSpec *pspec;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
klass->paint_cursor = clutter_entry_paint_cursor;
|
2007-05-31 18:33:42 +00:00
|
|
|
|
|
|
|
actor_class->paint = clutter_entry_paint;
|
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com>
Bug #815 - Split up request, allocation, and paint box
* clutter/clutter-actor.[ch]: Rework the size allocation,
request and paint area. Now ::request_coords() is called
::allocate(), and ::query_coords() has been split into
::get_preferred_width() and ::get_preferred_height(). See
the documentation and the layout test on how to implement
a container and layout manager with the new API. (#915,
based on a patch by Havoc Pennington, Lucas Rocha and Johan
Bilien)
* clutter/clutter-clone-texture.c: Port CloneTexture to
the new size negotiation API; it just means forwarding
the requests to the parent texture.
* clutter/clutter-deprecated.h: Add deprecated and replaced
API.
* clutter/clutter-entry.c: Port Entry to the new size
negotiation API.
* clutter/clutter-group.c: Port Group to the new size
negotiation API; the semantics of the Group actor do not
change.
* clutter/clutter-label.c: Port Label to the new size
negotiation API, and vastly simplify the code.
* clutter/clutter-main.[ch]: Add API for executing a
relayout when needed.
* clutter/clutter-private.h: Add new Stage private API.
* clutter/clutter-rectangle.c: Update the get_abs_opacity()
call to get_paint_opacity().
* clutter/clutter-stage.c:
(clutter_stage_get_preferred_width),
(clutter_stage_get_preferred_height),
(clutter_stage_allocate),
(clutter_stage_class_init): Port Stage to the new size
negotiation API.
* clutter/clutter-texture.c: Port Texture to the new size
negotiation API.
* clutter/clutter-types.h: Add ClutterRequestMode enumeration.
* clutter/x11/clutter-stage-x11.c: Port the X11 stage
implementation to the new size negotiation API.
* tests/Makefile.am: Add the layout manager test case.
* tests/test-opacity.c: Update.
* tests/test-project.c: Update.
* tests/test-layout.c: Test case for a layout manager implemented
using the new size negotiation API; the layout manager handles
both transformed and untransformed children.
2008-06-10 17:07:52 +00:00
|
|
|
actor_class->allocate = clutter_entry_allocate;
|
2008-03-06 12:39:24 +00:00
|
|
|
actor_class->key_press_event = clutter_entry_key_press;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
gobject_class->finalize = clutter_entry_finalize;
|
|
|
|
gobject_class->dispose = clutter_entry_dispose;
|
2007-05-31 18:33:42 +00:00
|
|
|
gobject_class->set_property = clutter_entry_set_property;
|
|
|
|
gobject_class->get_property = clutter_entry_get_property;
|
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2007-05-31 18:33:42 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class, PROP_FONT_NAME,
|
|
|
|
g_param_spec_string ("font-name",
|
|
|
|
"Font Name",
|
|
|
|
"Pango font description",
|
|
|
|
NULL,
|
2007-10-26 15:56:17 +00:00
|
|
|
CLUTTER_PARAM_READWRITE));
|
2007-07-04 09:33:04 +00:00
|
|
|
/**
|
|
|
|
* ClutterEntry:text:
|
|
|
|
*
|
|
|
|
* The text inside the entry.
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-05-31 18:33:42 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class, PROP_TEXT,
|
|
|
|
g_param_spec_string ("text",
|
|
|
|
"Text",
|
|
|
|
"Text to render",
|
|
|
|
NULL,
|
2007-10-26 15:56:17 +00:00
|
|
|
CLUTTER_PARAM_READWRITE));
|
2007-07-04 09:33:04 +00:00
|
|
|
/**
|
|
|
|
* ClutterEntry:color:
|
|
|
|
*
|
|
|
|
* The color of the text inside the entry.
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2008-11-17 14:21:49 +00:00
|
|
|
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);
|
2007-07-04 09:33:04 +00:00
|
|
|
/**
|
|
|
|
* ClutterEntry:alignment:
|
|
|
|
*
|
|
|
|
* The preferred alignment for the string.
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-10-12 08:17:00 +00:00
|
|
|
g_object_class_install_property
|
2007-05-31 18:33:42 +00:00
|
|
|
(gobject_class, PROP_ALIGNMENT,
|
2007-07-04 09:33:04 +00:00
|
|
|
g_param_spec_enum ("alignment",
|
|
|
|
"Alignment",
|
|
|
|
"The preferred alignment for the string,",
|
|
|
|
PANGO_TYPE_ALIGNMENT,
|
|
|
|
PANGO_ALIGN_LEFT,
|
|
|
|
CLUTTER_PARAM_READWRITE));
|
2007-06-01 15:18:05 +00:00
|
|
|
/**
|
2007-07-04 09:33:04 +00:00
|
|
|
* ClutterEntry:position:
|
2007-06-01 15:18:05 +00:00
|
|
|
*
|
|
|
|
* The current input cursor position. -1 is taken to be the end of the text
|
2007-07-04 09:33:04 +00:00
|
|
|
*
|
|
|
|
* Since: 0.4
|
2007-10-12 08:17:00 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property
|
2007-05-31 18:33:42 +00:00
|
|
|
(gobject_class, PROP_POSITION,
|
2007-07-04 09:33:04 +00:00
|
|
|
g_param_spec_int ("position",
|
|
|
|
"Position",
|
|
|
|
"The cursor position",
|
|
|
|
-1, G_MAXINT,
|
|
|
|
-1,
|
|
|
|
CLUTTER_PARAM_READWRITE));
|
2007-06-01 15:18:05 +00:00
|
|
|
|
|
|
|
/**
|
2007-07-04 09:33:04 +00:00
|
|
|
* ClutterEntry:cursor-visible:
|
|
|
|
*
|
|
|
|
* Whether the input cursor is visible or not.
|
2007-06-01 15:18:05 +00:00
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Since: 0.4
|
2007-10-12 08:17:00 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property
|
2007-05-31 18:33:42 +00:00
|
|
|
(gobject_class, PROP_CURSOR,
|
|
|
|
g_param_spec_boolean ( "cursor-visible",
|
|
|
|
"Cursor Visible",
|
2007-06-01 15:18:05 +00:00
|
|
|
"Whether the input cursor is visible",
|
2007-05-31 18:33:42 +00:00
|
|
|
TRUE,
|
|
|
|
CLUTTER_PARAM_READWRITE));
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:58:17 +00:00
|
|
|
/**
|
2007-07-04 09:33:04 +00:00
|
|
|
* ClutterEntry:text-visible:
|
|
|
|
*
|
2008-02-15 16:40:26 +00:00
|
|
|
* Whether the text is visible in plain form, or replaced by the
|
2007-07-04 09:33:04 +00:00
|
|
|
* character set by clutter_entry_set_invisible_char().
|
2007-06-01 15:58:17 +00:00
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Since: 0.4
|
2007-10-12 08:17:00 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property
|
2007-06-01 15:58:17 +00:00
|
|
|
(gobject_class, PROP_TEXT_VISIBLE,
|
|
|
|
g_param_spec_boolean ("text-visible",
|
|
|
|
"Text Visible",
|
2008-02-15 16:40:26 +00:00
|
|
|
"Whether the text is visible in plain form",
|
2007-06-01 15:58:17 +00:00
|
|
|
TRUE,
|
|
|
|
CLUTTER_PARAM_READWRITE));
|
2007-06-01 17:18:21 +00:00
|
|
|
|
|
|
|
/**
|
2007-07-04 09:33:04 +00:00
|
|
|
* ClutterEntry:max-length:
|
2007-06-01 17:18:21 +00:00
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* The maximum length of the entry text.
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
2007-10-12 08:17:00 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property
|
2007-06-01 17:18:21 +00:00
|
|
|
(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));
|
2007-07-04 09:33:04 +00:00
|
|
|
/**
|
|
|
|
* 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));
|
2007-10-26 15:56:17 +00:00
|
|
|
/**
|
|
|
|
* 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));
|
2007-06-01 11:50:18 +00:00
|
|
|
/**
|
|
|
|
* ClutterEntry::text-changed:
|
|
|
|
* @entry: the actor which received the event
|
|
|
|
*
|
2008-02-15 16:40:26 +00:00
|
|
|
* The ::text-changed signal is emitted after @entry's text changes
|
2007-06-01 11:50:18 +00:00
|
|
|
*/
|
|
|
|
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);
|
2007-05-31 18:33:42 +00:00
|
|
|
|
2007-06-01 15:18:05 +00:00
|
|
|
/**
|
|
|
|
* ClutterEntry::cursor-event:
|
|
|
|
* @entry: the actor which received the event
|
|
|
|
* @geometry: a #ClutterGeometry
|
|
|
|
*
|
2008-02-15 16:40:26 +00:00
|
|
|
* The ::cursor-event signal is emitted each time the input cursor's geometry
|
2007-06-01 15:18:05 +00:00
|
|
|
* changes, this could be a positional or size change. If you would like to
|
2008-02-15 16:40:26 +00:00
|
|
|
* implement your own input cursor, set the cursor-visible property to %FALSE,
|
2007-06-01 15:18:05 +00:00
|
|
|
* and connect to this signal to position and size your own cursor.
|
2007-07-04 09:33:04 +00:00
|
|
|
*
|
|
|
|
* Since: 0.4
|
2007-06-01 15:18:05 +00:00
|
|
|
*/
|
|
|
|
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);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-07 21:23:07 +00:00
|
|
|
/**
|
|
|
|
* ClutterEntry::activate:
|
|
|
|
* @entry: the actor which received the event
|
|
|
|
*
|
2008-02-15 16:40:26 +00:00
|
|
|
* The ::activate signal is emitted each time the entry is 'activated'
|
2008-03-06 12:39:24 +00:00
|
|
|
* by the user, normally by pressing the 'Enter' key.
|
2007-07-04 09:33:04 +00:00
|
|
|
*
|
|
|
|
* Since: 0.4
|
2007-06-07 21:23:07 +00:00
|
|
|
*/
|
|
|
|
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);
|
2007-06-01 15:18:05 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
g_type_class_add_private (gobject_class, sizeof (ClutterEntryPrivate));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_entry_init (ClutterEntry *self)
|
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv;
|
2007-07-31 08:28:17 +00:00
|
|
|
gdouble resolution;
|
|
|
|
gint font_size;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
self->priv = priv = CLUTTER_ENTRY_GET_PRIVATE (self);
|
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
if (G_UNLIKELY (_context == NULL))
|
2008-06-13 09:10:39 +00:00
|
|
|
_context = _clutter_context_create_pango_context (CLUTTER_CONTEXT ());
|
2008-05-28 Emmanuele Bassi <ebassi@openedhand.com>
Bug #919 - Replacement pango renderer (Neil Roberts)
* clutter/clutter-backend.h:
* clutter/clutter-backend.c:
(clutter_backend_set_font_options),
(clutter_backend_get_font_options): Add the ability to set
the cairo_font_options_t* for the backend at construction
time, so that backend implementations can have their own
options.
* clutter/clutter-color.c: Include pango/pango-attributes.h
for the pango_color_parse() function.
* clutter/clutter-label.c:
(clutter_label_ensure_layout),
(clutter_label_init), (clutter_label_set_text),
(clutter_label_set_font_name), (clutter_label_set_ellipsize),
(clutter_label_set_use_markup): Ensure that the cache is
always primed when the Label changes; this makes sure that
the cache is rebuilt outside the paint run, which should
make the painting perform better especially on embedded
devices.
* clutter/clutter-entry.c:
(clutter_entry_ensure_layout),
(clutter_entry_init), (clutter_entry_set_text),
(clutter_entry_set_font_name): Ditto as above.
* clutter/clutter-private.h:
* clutter/clutter-main.[ch]: Create the font-map inside the
main context; add two new functions:
clutter_clear_glyph_cache()
clutter_set_use_mipmapped_text()
that control the glyphs cache.
* clutter/pango/Makefile.am:
* clutter/pango/pangoclutter-fontmap.c:
* clutter/pango/pangoclutter-private.h:
* clutter/pango/pangoclutter-render.c:
* clutter/pango/pangoclutter.h: Rewrite the Pango renderer
using a PangoCairo context and saving the glyphs inside a
more efficient cache.
* configure.ac: Depend on pangocairo instead of pangoft2.
2008-05-28 14:03:28 +00:00
|
|
|
|
2008-06-13 09:10:39 +00:00
|
|
|
resolution = pango_cairo_context_get_resolution (_context);
|
2007-05-31 18:33:42 +00:00
|
|
|
|
|
|
|
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;
|
2007-06-01 15:58:17 +00:00
|
|
|
priv->priv_char = '*';
|
2007-06-01 16:50:35 +00:00
|
|
|
priv->text_visible = TRUE;
|
|
|
|
priv->text_x = 0;
|
2007-06-01 17:18:21 +00:00
|
|
|
priv->max_length = 0;
|
2007-07-04 09:33:04 +00:00
|
|
|
priv->entry_padding = ENTRY_PADDING;
|
2007-10-26 15:56:17 +00:00
|
|
|
priv->x_align = 0.0;
|
2007-05-31 18:33:42 +00:00
|
|
|
|
2008-11-17 14:21:49 +00:00
|
|
|
priv->fgcol = default_text_color;
|
2007-05-31 18:33:42 +00:00
|
|
|
|
|
|
|
priv->font_name = g_strdup (DEFAULT_FONT_NAME);
|
|
|
|
priv->desc = pango_font_description_from_string (priv->font_name);
|
2007-07-31 08:28:17 +00:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
priv->show_cursor = TRUE;
|
2007-05-31 18:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Return value: the newly created #ClutterEntry
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
2007-05-31 18:33:42 +00:00
|
|
|
*/
|
2007-07-04 09:33:04 +00:00
|
|
|
ClutterActor *
|
2007-05-31 18:33:42 +00:00
|
|
|
clutter_entry_new_with_text (const gchar *font_name,
|
|
|
|
const gchar *text)
|
|
|
|
{
|
2007-07-26 11:31:50 +00:00
|
|
|
ClutterActor *entry = clutter_entry_new ();
|
|
|
|
|
|
|
|
g_object_set (entry,
|
|
|
|
"font-name", font_name,
|
|
|
|
"text", text,
|
|
|
|
NULL);
|
|
|
|
return entry;
|
2007-05-31 18:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2008-02-15 17:11:50 +00:00
|
|
|
* Creates a new #ClutterEntry displaying @text with @color
|
2007-05-31 18:33:42 +00:00
|
|
|
* using @font_name.
|
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Return value: the newly created #ClutterEntry
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
2007-05-31 18:33:42 +00:00
|
|
|
*/
|
2007-07-04 09:33:04 +00:00
|
|
|
ClutterActor *
|
|
|
|
clutter_entry_new_full (const gchar *font_name,
|
|
|
|
const gchar *text,
|
|
|
|
const ClutterColor *color)
|
2007-05-31 18:33:42 +00:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2007-10-12 08:17:00 +00:00
|
|
|
ClutterActor *entry = g_object_new (CLUTTER_TYPE_ENTRY,
|
2007-07-26 11:31:50 +00:00
|
|
|
NULL);
|
|
|
|
clutter_actor_set_size (entry, 50, 50);
|
|
|
|
|
|
|
|
return entry;
|
2007-05-31 18:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_entry_get_text:
|
|
|
|
* @entry: a #ClutterEntry
|
|
|
|
*
|
2008-02-15 16:40:26 +00:00
|
|
|
* Retrieves the text displayed by @entry.
|
2007-05-31 18:33:42 +00:00
|
|
|
*
|
|
|
|
* Return value: the text of the entry. The returned string is
|
2007-07-04 09:33:04 +00:00
|
|
|
* owned by #ClutterEntry and should not be modified or freed.
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
2007-05-31 18:33:42 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Sets @text as the text to be displayed by @entry. The
|
|
|
|
* ClutterEntry::text-changed signal is emitted.
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
2007-05-31 18:33:42 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_entry_set_text (ClutterEntry *entry,
|
|
|
|
const gchar *text)
|
|
|
|
{
|
2007-06-01 17:18:21 +00:00
|
|
|
ClutterEntryPrivate *priv;
|
2007-05-31 18:33:42 +00:00
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_ENTRY (entry));
|
2007-10-26 15:56:17 +00:00
|
|
|
g_return_if_fail (text != NULL);
|
2007-05-31 18:33:42 +00:00
|
|
|
|
|
|
|
priv = entry->priv;
|
|
|
|
|
|
|
|
g_object_ref (entry);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
if (priv->max_length > 0)
|
2007-06-01 17:18:21 +00:00
|
|
|
{
|
|
|
|
gint len = g_utf8_strlen (text, -1);
|
2007-07-04 09:33:04 +00:00
|
|
|
|
2007-06-01 17:18:21 +00:00
|
|
|
if (len < priv->max_length)
|
2007-10-12 08:17:00 +00:00
|
|
|
{
|
2007-06-01 17:18:21 +00:00
|
|
|
g_free (priv->text);
|
2008-06-09 10:13:20 +00:00
|
|
|
|
2007-06-01 17:18:21 +00:00
|
|
|
priv->text = g_strdup (text);
|
2008-06-09 10:13:20 +00:00
|
|
|
priv->n_bytes = strlen (text);
|
|
|
|
priv->n_chars = len;
|
2007-06-01 17:18:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-11 15:07:36 +00:00
|
|
|
gchar * n = g_malloc0 (priv->max_length + 1);
|
2007-07-04 09:33:04 +00:00
|
|
|
|
2007-10-11 15:07:36 +00:00
|
|
|
g_utf8_strncpy (n, text, priv->max_length);
|
2007-07-04 09:33:04 +00:00
|
|
|
g_free (priv->text);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-10-11 15:07:36 +00:00
|
|
|
priv->text = n;
|
2008-06-09 10:13:20 +00:00
|
|
|
priv->n_bytes = strlen (n);
|
|
|
|
priv->n_chars = priv->max_length;
|
2007-06-01 17:18:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_free (priv->text);
|
2007-10-26 15:56:17 +00:00
|
|
|
|
2007-06-01 17:18:21 +00:00
|
|
|
priv->text = g_strdup (text);
|
2008-06-09 10:13:20 +00:00
|
|
|
priv->n_bytes = strlen (text);
|
2007-10-26 15:56:17 +00:00
|
|
|
priv->n_chars = g_utf8_strlen (priv->text, -1);
|
2007-06-01 17:18:21 +00:00
|
|
|
}
|
2007-05-31 18:33:42 +00:00
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
clutter_entry_clear_layout (entry);
|
|
|
|
clutter_entry_clear_cursor_position (entry);
|
2008-05-28 Emmanuele Bassi <ebassi@openedhand.com>
Bug #919 - Replacement pango renderer (Neil Roberts)
* clutter/clutter-backend.h:
* clutter/clutter-backend.c:
(clutter_backend_set_font_options),
(clutter_backend_get_font_options): Add the ability to set
the cairo_font_options_t* for the backend at construction
time, so that backend implementations can have their own
options.
* clutter/clutter-color.c: Include pango/pango-attributes.h
for the pango_color_parse() function.
* clutter/clutter-label.c:
(clutter_label_ensure_layout),
(clutter_label_init), (clutter_label_set_text),
(clutter_label_set_font_name), (clutter_label_set_ellipsize),
(clutter_label_set_use_markup): Ensure that the cache is
always primed when the Label changes; this makes sure that
the cache is rebuilt outside the paint run, which should
make the painting perform better especially on embedded
devices.
* clutter/clutter-entry.c:
(clutter_entry_ensure_layout),
(clutter_entry_init), (clutter_entry_set_text),
(clutter_entry_set_font_name): Ditto as above.
* clutter/clutter-private.h:
* clutter/clutter-main.[ch]: Create the font-map inside the
main context; add two new functions:
clutter_clear_glyph_cache()
clutter_set_use_mipmapped_text()
that control the glyphs cache.
* clutter/pango/Makefile.am:
* clutter/pango/pangoclutter-fontmap.c:
* clutter/pango/pangoclutter-private.h:
* clutter/pango/pangoclutter-render.c:
* clutter/pango/pangoclutter.h: Rewrite the Pango renderer
using a PangoCairo context and saving the glyphs inside a
more efficient cache.
* configure.ac: Depend on pangocairo instead of pangoft2.
2008-05-28 14:03:28 +00:00
|
|
|
/* Recreate the layout so the glyph cache will be primed */
|
|
|
|
clutter_entry_ensure_layout (entry, -1);
|
2007-05-31 18:33:42 +00:00
|
|
|
|
2008-01-31 14:24:04 +00:00
|
|
|
if (CLUTTER_ACTOR_IS_VISIBLE (entry))
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (entry));
|
2007-05-31 18:33:42 +00:00
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
g_signal_emit (G_OBJECT (entry), entry_signals[TEXT_CHANGED], 0);
|
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
g_object_notify (G_OBJECT (entry), "text");
|
2007-05-31 18:33:42 +00:00
|
|
|
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.
|
2007-07-04 09:33:04 +00:00
|
|
|
*
|
|
|
|
* Since: 0.4
|
2007-05-31 18:33:42 +00:00
|
|
|
*/
|
|
|
|
G_CONST_RETURN gchar *
|
|
|
|
clutter_entry_get_font_name (ClutterEntry *entry)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_ENTRY (entry), NULL);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
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.
|
2007-07-04 09:33:04 +00:00
|
|
|
*
|
|
|
|
* Since: 0.4
|
2007-05-31 18:33:42 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_entry_set_font_name (ClutterEntry *entry,
|
|
|
|
const gchar *font_name)
|
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv;
|
|
|
|
PangoFontDescription *desc;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_ENTRY (entry));
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
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);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
if (priv->desc)
|
|
|
|
pango_font_description_free (priv->desc);
|
|
|
|
|
|
|
|
priv->desc = desc;
|
|
|
|
|
|
|
|
if (entry->priv->text && entry->priv->text[0] != '\0')
|
|
|
|
{
|
2007-10-12 08:17:00 +00:00
|
|
|
clutter_entry_clear_layout (entry);
|
2008-05-28 Emmanuele Bassi <ebassi@openedhand.com>
Bug #919 - Replacement pango renderer (Neil Roberts)
* clutter/clutter-backend.h:
* clutter/clutter-backend.c:
(clutter_backend_set_font_options),
(clutter_backend_get_font_options): Add the ability to set
the cairo_font_options_t* for the backend at construction
time, so that backend implementations can have their own
options.
* clutter/clutter-color.c: Include pango/pango-attributes.h
for the pango_color_parse() function.
* clutter/clutter-label.c:
(clutter_label_ensure_layout),
(clutter_label_init), (clutter_label_set_text),
(clutter_label_set_font_name), (clutter_label_set_ellipsize),
(clutter_label_set_use_markup): Ensure that the cache is
always primed when the Label changes; this makes sure that
the cache is rebuilt outside the paint run, which should
make the painting perform better especially on embedded
devices.
* clutter/clutter-entry.c:
(clutter_entry_ensure_layout),
(clutter_entry_init), (clutter_entry_set_text),
(clutter_entry_set_font_name): Ditto as above.
* clutter/clutter-private.h:
* clutter/clutter-main.[ch]: Create the font-map inside the
main context; add two new functions:
clutter_clear_glyph_cache()
clutter_set_use_mipmapped_text()
that control the glyphs cache.
* clutter/pango/Makefile.am:
* clutter/pango/pangoclutter-fontmap.c:
* clutter/pango/pangoclutter-private.h:
* clutter/pango/pangoclutter-render.c:
* clutter/pango/pangoclutter.h: Rewrite the Pango renderer
using a PangoCairo context and saving the glyphs inside a
more efficient cache.
* configure.ac: Depend on pangocairo instead of pangoft2.
2008-05-28 14:03:28 +00:00
|
|
|
/* Recreate the layout so the glyph cache will be primed */
|
|
|
|
clutter_entry_ensure_layout (entry, -1);
|
2007-05-31 18:33:42 +00:00
|
|
|
|
2008-01-31 14:24:04 +00:00
|
|
|
if (CLUTTER_ACTOR_IS_VISIBLE (entry))
|
2007-07-04 09:33:04 +00:00
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (entry));
|
2007-05-31 18:33:42 +00:00
|
|
|
}
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
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.
|
2007-07-04 09:33:04 +00:00
|
|
|
*
|
|
|
|
* Since: 0.4
|
2007-05-31 18:33:42 +00:00
|
|
|
*/
|
|
|
|
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);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
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.
|
2007-07-04 09:33:04 +00:00
|
|
|
*
|
|
|
|
* Since: 0.4
|
2007-05-31 18:33:42 +00:00
|
|
|
*/
|
|
|
|
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
|
2007-10-12 08:17:00 +00:00
|
|
|
*
|
2007-05-31 18:33:42 +00:00
|
|
|
* 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.
|
2007-10-12 08:17:00 +00:00
|
|
|
*
|
2007-05-31 18:33:42 +00:00
|
|
|
* Return value: the #PangoLayout for this entry
|
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Since: 0.4
|
2007-05-31 18:33:42 +00:00
|
|
|
**/
|
2007-07-04 09:33:04 +00:00
|
|
|
PangoLayout *
|
2007-05-31 18:33:42 +00:00
|
|
|
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.
|
2007-07-04 09:33:04 +00:00
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-05-31 18:33:42 +00:00
|
|
|
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;
|
2007-10-26 15:56:17 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
clutter_entry_clear_layout (entry);
|
|
|
|
|
2008-01-31 14:24:04 +00:00
|
|
|
if (CLUTTER_ACTOR_IS_VISIBLE (entry))
|
2007-05-31 18:33:42 +00:00
|
|
|
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
|
|
|
|
*
|
2008-02-15 16:40:26 +00:00
|
|
|
* Return value: The entry's #PangoAlignment
|
2007-05-31 18:33:42 +00:00
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Since 0.4
|
|
|
|
*/
|
2007-05-31 18:33:42 +00:00
|
|
|
PangoAlignment
|
|
|
|
clutter_entry_get_alignment (ClutterEntry *entry)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_ENTRY (entry), FALSE);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
return entry->priv->alignment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-01-31 14:24:04 +00:00
|
|
|
* clutter_entry_set_cursor_position:
|
2007-05-31 18:33:42 +00:00
|
|
|
* @entry: a #ClutterEntry
|
2007-07-04 09:33:04 +00:00
|
|
|
* @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
|
2007-10-12 08:17:00 +00:00
|
|
|
* that the position should be set after the last character in the entry.
|
2007-05-31 18:33:42 +00:00
|
|
|
* Note that this position is in characters, not in bytes.
|
2007-07-04 09:33:04 +00:00
|
|
|
*
|
2008-01-31 14:24:04 +00:00
|
|
|
* Since: 0.6
|
2007-07-04 09:33:04 +00:00
|
|
|
*/
|
2007-05-31 18:33:42 +00:00
|
|
|
void
|
2008-01-31 14:24:04 +00:00
|
|
|
clutter_entry_set_cursor_position (ClutterEntry *entry,
|
|
|
|
gint position)
|
2007-05-31 18:33:42 +00:00
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv;
|
|
|
|
gint len;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_ENTRY (entry));
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
priv = entry->priv;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
if (priv->text == NULL)
|
|
|
|
return;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
len = g_utf8_strlen (priv->text, -1);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
if (position < 0 || position >= len)
|
|
|
|
priv->position = -1;
|
|
|
|
else
|
|
|
|
priv->position = position;
|
|
|
|
|
2007-06-01 15:18:05 +00:00
|
|
|
clutter_entry_clear_cursor_position (entry);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2008-01-31 14:24:04 +00:00
|
|
|
if (CLUTTER_ACTOR_IS_VISIBLE (entry))
|
2007-07-04 09:33:04 +00:00
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (entry));
|
2007-05-31 18:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-01-31 14:24:04 +00:00
|
|
|
* clutter_entry_get_cursor_position:
|
2007-05-31 18:33:42 +00:00
|
|
|
* @entry: a #ClutterEntry
|
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Gets the position, in characters, of the cursor in @entry.
|
2007-05-31 18:33:42 +00:00
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Return value: the position of the cursor.
|
2007-05-31 18:33:42 +00:00
|
|
|
*
|
2008-01-31 14:24:04 +00:00
|
|
|
* Since: 0.6
|
2007-07-04 09:33:04 +00:00
|
|
|
*/
|
2007-05-31 18:33:42 +00:00
|
|
|
gint
|
2008-01-31 14:24:04 +00:00
|
|
|
clutter_entry_get_cursor_position (ClutterEntry *entry)
|
2007-05-31 18:33:42 +00:00
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_ENTRY (entry), 0);
|
|
|
|
|
|
|
|
priv = entry->priv;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
return priv->position;
|
|
|
|
}
|
|
|
|
|
2007-06-01 11:34:40 +00:00
|
|
|
/**
|
|
|
|
* clutter_entry_handle_key_event:
|
|
|
|
* @entry: a #ClutterEntry
|
|
|
|
* @kev: a #ClutterKeyEvent
|
|
|
|
*
|
2007-10-12 08:17:00 +00:00
|
|
|
* This function will handle a #ClutterKeyEvent, like those returned in a
|
2007-06-01 11:34:40 +00:00
|
|
|
* 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
|
2007-07-04 09:33:04 +00:00
|
|
|
* input cursor. You should use this function inside a handler for the
|
|
|
|
* ClutterStage::key-press-event or ClutterStage::key-release-event.
|
2007-06-01 11:34:40 +00:00
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Since: 0.4
|
2008-03-06 12:39:24 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 0.8: The key events will automatically be handled when
|
|
|
|
* giving the key focus to an entry using clutter_stage_set_key_focus().
|
2007-07-04 09:33:04 +00:00
|
|
|
*/
|
2007-06-01 11:34:40 +00:00
|
|
|
void
|
2007-07-04 09:33:04 +00:00
|
|
|
clutter_entry_handle_key_event (ClutterEntry *entry,
|
|
|
|
ClutterKeyEvent *kev)
|
2007-06-01 11:34:40 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (CLUTTER_IS_ENTRY (entry));
|
|
|
|
|
2008-03-06 12:39:24 +00:00
|
|
|
clutter_entry_handle_key_event_internal (entry, kev);
|
2007-06-01 11:34:40 +00:00
|
|
|
}
|
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
/**
|
2007-07-04 09:33:04 +00:00
|
|
|
* clutter_entry_insert_unichar:
|
2007-05-31 18:33:42 +00:00
|
|
|
* @entry: a #ClutterEntry
|
2007-06-01 15:58:17 +00:00
|
|
|
* @wc: a Unicode character
|
2007-05-31 18:33:42 +00:00
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Insert a character to the right of the current position of the cursor,
|
|
|
|
* and updates the position of the cursor.
|
2007-10-12 08:17:00 +00:00
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-05-31 18:33:42 +00:00
|
|
|
void
|
2007-07-04 09:33:04 +00:00
|
|
|
clutter_entry_insert_unichar (ClutterEntry *entry,
|
|
|
|
gunichar wc)
|
2007-05-31 18:33:42 +00:00
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv;
|
|
|
|
GString *new = NULL;
|
2007-07-26 11:31:50 +00:00
|
|
|
glong pos;
|
2007-05-31 18:33:42 +00:00
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_ENTRY (entry));
|
|
|
|
g_return_if_fail (g_unichar_validate (wc));
|
|
|
|
|
2007-06-29 17:18:13 +00:00
|
|
|
if (wc == 0)
|
|
|
|
return;
|
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
priv = entry->priv;
|
|
|
|
|
|
|
|
g_object_ref (entry);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
new = g_string_new (priv->text);
|
2007-07-26 11:31:50 +00:00
|
|
|
pos = offset_to_bytes (priv->text, priv->position);
|
|
|
|
new = g_string_insert_unichar (new, pos, wc);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
clutter_entry_set_text (entry, new->str);
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
if (priv->position >= 0)
|
2008-01-31 14:24:04 +00:00
|
|
|
clutter_entry_set_cursor_position (entry, priv->position + 1);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
g_string_free (new, TRUE);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
g_object_notify (G_OBJECT (entry), "text");
|
2007-05-31 18:33:42 +00:00
|
|
|
g_object_unref (entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-07-04 09:33:04 +00:00
|
|
|
* clutter_entry_delete_chars:
|
2007-05-31 18:33:42 +00:00
|
|
|
* @entry: a #ClutterEntry
|
|
|
|
* @len: the number of characters to remove.
|
|
|
|
*
|
|
|
|
* Characters are removed from before the current postion of the cursor.
|
2007-10-12 08:17:00 +00:00
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-05-31 18:33:42 +00:00
|
|
|
void
|
2007-07-04 09:33:04 +00:00
|
|
|
clutter_entry_delete_chars (ClutterEntry *entry,
|
|
|
|
guint num)
|
2007-05-31 18:33:42 +00:00
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv;
|
|
|
|
GString *new = NULL;
|
|
|
|
gint len;
|
2007-07-26 11:31:50 +00:00
|
|
|
gint pos;
|
|
|
|
gint num_pos;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_ENTRY (entry));
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
priv = entry->priv;
|
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
if (!priv->text)
|
|
|
|
return;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
g_object_ref (entry);
|
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
len = g_utf8_strlen (priv->text, -1);
|
|
|
|
new = g_string_new (priv->text);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
if (priv->position == -1)
|
2007-07-26 11:31:50 +00:00
|
|
|
{
|
|
|
|
num_pos = offset_to_bytes (priv->text, len - num);
|
|
|
|
new = g_string_erase (new, num_pos, -1);
|
|
|
|
}
|
2007-05-31 18:33:42 +00:00
|
|
|
else
|
2007-07-26 11:31:50 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2007-05-31 18:33:42 +00:00
|
|
|
clutter_entry_set_text (entry, new->str);
|
|
|
|
|
|
|
|
if (priv->position > 0)
|
2008-01-31 14:24:04 +00:00
|
|
|
clutter_entry_set_cursor_position (entry, priv->position - num);
|
2007-05-31 18:33:42 +00:00
|
|
|
|
|
|
|
g_string_free (new, TRUE);
|
2007-07-04 09:33:04 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (entry), "text");
|
2007-05-31 18:33:42 +00:00
|
|
|
g_object_unref (entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_entry_insert_text:
|
|
|
|
* @entry: a #ClutterEntry
|
|
|
|
* @text: the text to insert
|
2007-07-04 09:33:04 +00:00
|
|
|
* @position: the position at which to insert the text.
|
|
|
|
*
|
2007-05-31 18:33:42 +00:00
|
|
|
* Insert text at a specifc position.
|
2007-07-04 09:33:04 +00:00
|
|
|
*
|
|
|
|
* A value of 0 indicates that the text will be inserted before the first
|
2008-02-15 16:40:26 +00:00
|
|
|
* 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.
|
2007-10-12 08:17:00 +00:00
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-05-31 18:33:42 +00:00
|
|
|
void
|
2007-10-12 08:17:00 +00:00
|
|
|
clutter_entry_insert_text (ClutterEntry *entry,
|
2007-05-31 18:33:42 +00:00
|
|
|
const gchar *text,
|
|
|
|
gssize position)
|
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv;
|
|
|
|
GString *new = NULL;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_ENTRY (entry));
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
priv = entry->priv;
|
|
|
|
|
|
|
|
new = g_string_new (priv->text);
|
|
|
|
new = g_string_insert (new, position, text);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
clutter_entry_set_text (entry, new->str);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
g_string_free (new, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-07-04 09:33:04 +00:00
|
|
|
* clutter_entry_delete_text:
|
2007-05-31 18:33:42 +00:00
|
|
|
* @entry: a #ClutterEntry
|
2007-10-12 08:17:00 +00:00
|
|
|
* @start_pos: the starting position.
|
|
|
|
* @end_pos: the end position.
|
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* 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
|
|
|
|
*/
|
2007-05-31 18:33:42 +00:00
|
|
|
void
|
|
|
|
clutter_entry_delete_text (ClutterEntry *entry,
|
|
|
|
gssize start_pos,
|
|
|
|
gssize end_pos)
|
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv;
|
|
|
|
GString *new = NULL;
|
2007-10-01 13:44:33 +00:00
|
|
|
gint start_bytes;
|
|
|
|
gint end_bytes;
|
2007-05-31 18:33:42 +00:00
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_ENTRY (entry));
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
priv = entry->priv;
|
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
if (!priv->text)
|
|
|
|
return;
|
2007-10-01 13:44:33 +00:00
|
|
|
|
|
|
|
start_bytes = offset_to_bytes (priv->text, start_pos);
|
|
|
|
end_bytes = offset_to_bytes (priv->text, end_pos);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
new = g_string_new (priv->text);
|
2007-10-01 13:44:33 +00:00
|
|
|
new = g_string_erase (new, start_bytes, end_bytes - start_bytes);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
clutter_entry_set_text (entry, new->str);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
g_string_free (new, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-07-04 09:33:04 +00:00
|
|
|
* clutter_entry_set_visible_cursor:
|
2007-05-31 18:33:42 +00:00
|
|
|
* @entry: a #ClutterEntry
|
|
|
|
* @visible: whether the input cursor should be visible
|
2007-10-12 08:17:00 +00:00
|
|
|
*
|
2007-05-31 18:33:42 +00:00
|
|
|
* Sets the visibility of the input cursor.
|
2007-07-04 09:33:04 +00:00
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-05-31 18:33:42 +00:00
|
|
|
void
|
2007-07-04 09:33:04 +00:00
|
|
|
clutter_entry_set_visible_cursor (ClutterEntry *entry,
|
|
|
|
gboolean visible)
|
2007-05-31 18:33:42 +00:00
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_ENTRY (entry));
|
2007-07-04 09:33:04 +00:00
|
|
|
|
2007-05-31 18:33:42 +00:00
|
|
|
priv = entry->priv;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
if (priv->show_cursor != visible)
|
|
|
|
{
|
|
|
|
priv->show_cursor = visible;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (entry), "cursor-visible");
|
|
|
|
|
2008-01-31 14:24:04 +00:00
|
|
|
if (CLUTTER_ACTOR_IS_VISIBLE (entry))
|
2007-07-04 09:33:04 +00:00
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (entry));
|
|
|
|
}
|
2007-05-31 18:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-07-04 09:33:04 +00:00
|
|
|
* clutter_entry_get_visible_cursor:
|
2007-05-31 18:33:42 +00:00
|
|
|
* @entry: a #ClutterEntry
|
|
|
|
*
|
2008-02-15 16:40:26 +00:00
|
|
|
* Returns the input cursor's visibility
|
2007-05-31 18:33:42 +00:00
|
|
|
*
|
|
|
|
* Return value: whether the input cursor is visible
|
2007-10-12 08:17:00 +00:00
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-05-31 18:33:42 +00:00
|
|
|
gboolean
|
|
|
|
clutter_entry_get_visible_cursor (ClutterEntry *entry)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_ENTRY (entry), FALSE);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
return entry->priv->show_cursor;
|
2007-05-31 18:33:42 +00:00
|
|
|
}
|
|
|
|
|
2007-06-01 15:58:17 +00:00
|
|
|
/**
|
2007-07-04 09:33:04 +00:00
|
|
|
* clutter_entry_set_visibility:
|
2007-06-01 15:58:17 +00:00
|
|
|
* @entry: a #ClutterEntry
|
2008-02-15 16:40:26 +00:00
|
|
|
* @visible: %TRUE if the contents of the entry are displayed as plaintext.
|
2007-06-01 15:58:17 +00:00
|
|
|
*
|
2007-10-12 08:17:00 +00:00
|
|
|
* Sets whether the contents of the entry are visible or not. When visibility
|
2008-02-15 16:40:26 +00:00
|
|
|
* is set to %FALSE, characters are displayed as the invisible char, and will
|
2007-06-01 15:58:17 +00:00
|
|
|
* also appear that way when the text in the entry widget is copied elsewhere.
|
2007-10-12 08:17:00 +00:00
|
|
|
*
|
|
|
|
* The default invisible char is the asterisk '*', but it can be changed with
|
2008-02-15 16:40:26 +00:00
|
|
|
* clutter_entry_set_invisible_char().
|
2007-10-12 08:17:00 +00:00
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-06-01 15:58:17 +00:00
|
|
|
void
|
|
|
|
clutter_entry_set_visibility (ClutterEntry *entry, gboolean visible)
|
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:58:17 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_ENTRY (entry));
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:58:17 +00:00
|
|
|
priv = entry->priv;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:58:17 +00:00
|
|
|
priv->text_visible = visible;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:58:17 +00:00
|
|
|
clutter_entry_clear_layout (entry);
|
|
|
|
clutter_entry_clear_cursor_position (entry);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2008-01-31 14:24:04 +00:00
|
|
|
if (CLUTTER_ACTOR_IS_VISIBLE (entry))
|
2007-10-12 08:17:00 +00:00
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (entry));
|
2007-06-01 15:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-07-04 09:33:04 +00:00
|
|
|
* clutter_entry_get_visibility:
|
2007-06-01 15:58:17 +00:00
|
|
|
* @entry: a #ClutterEntry
|
|
|
|
*
|
2008-02-15 16:40:26 +00:00
|
|
|
* Returns the entry text visibility.
|
2007-06-01 15:58:17 +00:00
|
|
|
*
|
2008-02-15 16:40:26 +00:00
|
|
|
* Return value: %TRUE if the contents of the entry are displayed as plaintext.
|
2007-10-12 08:17:00 +00:00
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-06-01 15:58:17 +00:00
|
|
|
gboolean
|
|
|
|
clutter_entry_get_visibility (ClutterEntry *entry)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CLUTTER_IS_ENTRY (entry), TRUE);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
return entry->priv->text_visible;
|
2007-06-01 15:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-07-04 09:33:04 +00:00
|
|
|
* clutter_entry_set_invisible_char:
|
2007-06-01 15:58:17 +00:00
|
|
|
* @entry: a #ClutterEntry
|
2007-10-12 08:17:00 +00:00
|
|
|
* @wc: a Unicode character
|
2007-06-01 15:58:17 +00:00
|
|
|
*
|
2007-10-12 08:17:00 +00:00
|
|
|
* Sets the character to use in place of the actual text when
|
2008-02-15 16:40:26 +00:00
|
|
|
* 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
|
2007-06-01 15:58:17 +00:00
|
|
|
* 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
|
2007-10-12 08:17:00 +00:00
|
|
|
* no feedback at all; there will be no text on the screen as they type.
|
2007-07-04 09:33:04 +00:00
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-06-01 15:58:17 +00:00
|
|
|
void
|
|
|
|
clutter_entry_set_invisible_char (ClutterEntry *entry, gunichar wc)
|
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:58:17 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_ENTRY (entry));
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:58:17 +00:00
|
|
|
priv = entry->priv;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:58:17 +00:00
|
|
|
priv->priv_char = wc;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:58:17 +00:00
|
|
|
if (!priv->text_visible)
|
|
|
|
return;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:58:17 +00:00
|
|
|
clutter_entry_clear_layout (entry);
|
|
|
|
clutter_entry_clear_cursor_position (entry);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2008-01-31 14:24:04 +00:00
|
|
|
if (CLUTTER_ACTOR_IS_VISIBLE (entry))
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (entry));
|
2007-06-01 15:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-07-04 09:33:04 +00:00
|
|
|
* clutter_entry_get_invisible_char:
|
2007-06-01 15:58:17 +00:00
|
|
|
* @entry: a #ClutterEntry
|
|
|
|
*
|
|
|
|
* Returns the character to use in place of the actual text when text-visibility
|
2008-02-15 16:40:26 +00:00
|
|
|
* is set to %FALSE
|
2007-06-01 15:58:17 +00:00
|
|
|
*
|
2007-10-12 08:17:00 +00:00
|
|
|
* Return value: a Unicode character
|
|
|
|
*
|
2007-06-01 15:58:17 +00:00
|
|
|
**/
|
|
|
|
gunichar
|
|
|
|
clutter_entry_get_invisible_char (ClutterEntry *entry)
|
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:58:17 +00:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_ENTRY (entry), TRUE);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:58:17 +00:00
|
|
|
priv = entry->priv;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 15:58:17 +00:00
|
|
|
return priv->priv_char;
|
|
|
|
}
|
|
|
|
|
2007-06-01 17:18:21 +00:00
|
|
|
/**
|
2007-07-04 09:33:04 +00:00
|
|
|
* clutter_entry_set_max_length:
|
2007-06-01 17:18:21 +00:00
|
|
|
* @entry: a #ClutterEntry
|
2008-06-05 10:05:01 +00:00
|
|
|
* @max: the maximum number of characters allowed in the entry; 0
|
|
|
|
* to disable or -1 to set the length of the current string
|
2007-06-01 17:18:21 +00:00
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* 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
|
2007-10-12 08:17:00 +00:00
|
|
|
* truncated to fit.
|
|
|
|
*
|
2007-07-04 09:33:04 +00:00
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-06-01 17:18:21 +00:00
|
|
|
void
|
2007-07-04 09:33:04 +00:00
|
|
|
clutter_entry_set_max_length (ClutterEntry *entry,
|
|
|
|
gint max)
|
2007-06-01 17:18:21 +00:00
|
|
|
{
|
|
|
|
ClutterEntryPrivate *priv;
|
|
|
|
gchar *new = NULL;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 17:18:21 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_ENTRY (entry));
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-01 17:18:21 +00:00
|
|
|
priv = entry->priv;
|
2007-07-04 09:33:04 +00:00
|
|
|
|
|
|
|
if (priv->max_length != max)
|
|
|
|
{
|
|
|
|
g_object_ref (entry);
|
|
|
|
|
|
|
|
if (max < 0)
|
|
|
|
max = g_utf8_strlen (priv->text, -1);
|
|
|
|
|
|
|
|
priv->max_length = max;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
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);
|
|
|
|
}
|
2007-06-01 17:18:21 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
2007-06-01 17:18:21 +00:00
|
|
|
|
2007-07-04 09:33:04 +00:00
|
|
|
return entry->priv->max_length;
|
|
|
|
}
|