Merge the ClutterText actor
Merge branch 'text-actor' * text-actor: (108 commits) Re-align ClutterText header file [text] Fix cursor sizing Comments and whitespace fixes to ClutterText [docs] Add newly added :single-line-mode accessors Update the ignore file [tests] Add text field interactive test [text] Add single-line-mode to ClutterText [text] Fix the deletion actions [text] Use cached length when possible [tests] Add unit for the ClutterText:password-char property [docs] Update the Text section [text] Coalesce text visibility and password character Allow localizations to change the text direction Clean up the update_pango_context() function Pass the PangoContext, not the MainContext Revert the logic of the PangoContext check Remove the binding pool entry from the list Remove BindingPool::list_actions() Add ClutterActor::create_pango_context() Rename the PangoContext creation functions ...
This commit is contained in:
commit
c54bd99097
2
.gitignore
vendored
2
.gitignore
vendored
@ -111,6 +111,7 @@ stamp-h1
|
||||
/tests/interactive/test-easing
|
||||
/tests/interactive/test-interactive
|
||||
/tests/interactive/test-binding-pool
|
||||
/tests/interactive/test-text-field
|
||||
/tests/interactive/redhand.png
|
||||
/tests/interactive/test-script.json
|
||||
/tests/conform/test-conformance
|
||||
@ -158,6 +159,7 @@ stamp-h1
|
||||
/clutter/x11/stamp-clutter-x11-enum-types.h
|
||||
/po/Makefile.in.in
|
||||
/po/POTFILES
|
||||
/po/*.pot
|
||||
*.swn
|
||||
*.swo
|
||||
*.swp
|
||||
|
@ -64,7 +64,6 @@ source_h = \
|
||||
$(srcdir)/clutter-container.h \
|
||||
$(srcdir)/clutter-deprecated.h \
|
||||
$(srcdir)/clutter-effect.h \
|
||||
$(srcdir)/clutter-entry.h \
|
||||
$(srcdir)/clutter-event.h \
|
||||
$(srcdir)/clutter-feature.h \
|
||||
$(srcdir)/clutter-fixed.h \
|
||||
@ -72,7 +71,6 @@ source_h = \
|
||||
$(srcdir)/clutter-group.h \
|
||||
$(srcdir)/clutter-interval.h \
|
||||
$(srcdir)/clutter-keysyms.h \
|
||||
$(srcdir)/clutter-label.h \
|
||||
$(srcdir)/clutter-list-model.h \
|
||||
$(srcdir)/clutter-main.h \
|
||||
$(srcdir)/clutter-media.h \
|
||||
@ -87,6 +85,7 @@ source_h = \
|
||||
$(srcdir)/clutter-stage.h \
|
||||
$(srcdir)/clutter-stage-manager.h \
|
||||
$(srcdir)/clutter-texture.h \
|
||||
$(srcdir)/clutter-text.h \
|
||||
$(srcdir)/clutter-timeline.h \
|
||||
$(srcdir)/clutter-timeout-pool.h \
|
||||
$(srcdir)/clutter-types.h \
|
||||
@ -155,7 +154,6 @@ source_c = \
|
||||
clutter-color.c \
|
||||
clutter-container.c \
|
||||
clutter-effect.c \
|
||||
clutter-entry.c \
|
||||
clutter-enum-types.c \
|
||||
clutter-event.c \
|
||||
clutter-feature.c \
|
||||
@ -164,7 +162,6 @@ source_c = \
|
||||
clutter-group.c \
|
||||
clutter-id-pool.c \
|
||||
clutter-interval.c \
|
||||
clutter-label.c \
|
||||
clutter-list-model.c \
|
||||
clutter-main.c \
|
||||
clutter-marshal.c \
|
||||
@ -182,6 +179,7 @@ source_c = \
|
||||
clutter-stage-manager.c \
|
||||
clutter-stage-window.c \
|
||||
clutter-texture.c \
|
||||
clutter-text.c \
|
||||
clutter-timeline.c \
|
||||
clutter-timeout-pool.c \
|
||||
clutter-units.c \
|
||||
|
@ -221,7 +221,9 @@ struct _ClutterActorPrivate
|
||||
/* cached allocation is invalid (request has changed, probably) */
|
||||
guint needs_allocation : 1;
|
||||
|
||||
guint show_on_set_parent : 1;
|
||||
guint has_clip : 1;
|
||||
|
||||
ClutterUnit clip[4];
|
||||
|
||||
/* Rotation angles */
|
||||
@ -260,7 +262,7 @@ struct _ClutterActorPrivate
|
||||
|
||||
ShaderData *shader_data;
|
||||
|
||||
gboolean show_on_set_parent;
|
||||
PangoContext *pango_context;
|
||||
};
|
||||
|
||||
enum
|
||||
@ -1957,6 +1959,12 @@ clutter_actor_dispose (GObject *object)
|
||||
|
||||
destroy_shader_data (self);
|
||||
|
||||
if (priv->pango_context)
|
||||
{
|
||||
g_object_unref (priv->pango_context);
|
||||
priv->pango_context = NULL;
|
||||
}
|
||||
|
||||
g_signal_emit (self, actor_signals[DESTROY], 0);
|
||||
|
||||
G_OBJECT_CLASS (clutter_actor_parent_class)->dispose (object);
|
||||
@ -7591,3 +7599,99 @@ clutter_actor_allocate_preferred_size (ClutterActor *self,
|
||||
|
||||
clutter_actor_allocate (self, &actor_box, absolute_origin_changed);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_actor_grab_key_focus:
|
||||
* @self: a #ClutterActor
|
||||
*
|
||||
* Sets the key focus of the #ClutterStage including @self
|
||||
* to this #ClutterActor.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
void
|
||||
clutter_actor_grab_key_focus (ClutterActor *self)
|
||||
{
|
||||
ClutterActor *parent;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_ACTOR (self));
|
||||
|
||||
parent = clutter_actor_get_parent (self);
|
||||
if (!parent)
|
||||
return;
|
||||
|
||||
parent = clutter_actor_get_stage (self);
|
||||
if (parent && CLUTTER_IS_STAGE (parent))
|
||||
clutter_stage_set_key_focus (CLUTTER_STAGE (parent), self);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_actor_get_pango_context:
|
||||
* @self: a #ClutterActor
|
||||
*
|
||||
* Retrieves the #PangoContext for @self. The actor's #PangoContext
|
||||
* is already configured using the appropriate font map, resolution
|
||||
* and font options.
|
||||
*
|
||||
* Unlike clutter_actor_create_pango_context(), this context is owend
|
||||
* by the #ClutterActor and it will be updated each time the options
|
||||
* stored by the #ClutterBackend change.
|
||||
*
|
||||
* You can use the returned #PangoContext to create a #PangoLayout
|
||||
* and render text using cogl_pango_render_layout() to reuse the
|
||||
* glyphs cache also used by Clutter.
|
||||
*
|
||||
* Return value: the #PangoContext for a #ClutterActor. The returned
|
||||
* #PangoContext is owned by the actor and should not be unreferenced
|
||||
* by the application code
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
PangoContext *
|
||||
clutter_actor_get_pango_context (ClutterActor *self)
|
||||
{
|
||||
ClutterActorPrivate *priv;
|
||||
ClutterMainContext *ctx;
|
||||
|
||||
g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
|
||||
|
||||
priv = self->priv;
|
||||
|
||||
if (priv->pango_context)
|
||||
return priv->pango_context;
|
||||
|
||||
ctx = CLUTTER_CONTEXT ();
|
||||
priv->pango_context = _clutter_context_get_pango_context (ctx);
|
||||
g_object_ref (priv->pango_context);
|
||||
|
||||
return priv->pango_context;
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_actor_create_pango_context:
|
||||
* @self: a #ClutterActor
|
||||
*
|
||||
* Creates a #PangoContext for the given actor. The #PangoContext
|
||||
* is already configured using the appropriate font map, resolution
|
||||
* and font options.
|
||||
*
|
||||
* See also clutter_actor_get_pango_context().
|
||||
*
|
||||
* Return value: the newly created #PangoContext. Use g_object_ref()
|
||||
* on the returned value to deallocate its resources
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
PangoContext *
|
||||
clutter_actor_create_pango_context (ClutterActor *self)
|
||||
{
|
||||
ClutterMainContext *ctx;
|
||||
PangoContext *retval;
|
||||
|
||||
g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
|
||||
|
||||
ctx = CLUTTER_CONTEXT ();
|
||||
retval = _clutter_context_create_pango_context (ctx);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
@ -31,6 +31,8 @@
|
||||
/* clutter-actor.h */
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <pango/pango.h>
|
||||
|
||||
#include <clutter/clutter-color.h>
|
||||
#include <clutter/clutter-fixed.h>
|
||||
#include <clutter/clutter-types.h>
|
||||
@ -420,6 +422,8 @@ void clutter_actor_set_opacity (ClutterActor
|
||||
guint8 opacity);
|
||||
guint8 clutter_actor_get_opacity (ClutterActor *self);
|
||||
guint8 clutter_actor_get_paint_opacity (ClutterActor *self);
|
||||
gboolean clutter_actor_get_paint_visibility (ClutterActor *self);
|
||||
|
||||
|
||||
void clutter_actor_set_name (ClutterActor *self,
|
||||
const gchar *name);
|
||||
@ -559,7 +563,10 @@ void clutter_actor_apply_relative_transform_to_point (ClutterActor *self,
|
||||
const ClutterVertex *point,
|
||||
ClutterVertex *vertex);
|
||||
|
||||
gboolean clutter_actor_get_paint_visibility (ClutterActor *self);
|
||||
void clutter_actor_grab_key_focus (ClutterActor *self);
|
||||
|
||||
PangoContext *clutter_actor_get_pango_context (ClutterActor *self);
|
||||
PangoContext *clutter_actor_create_pango_context (ClutterActor *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -44,10 +44,13 @@
|
||||
#include "clutter-backend.h"
|
||||
#include "clutter-debug.h"
|
||||
#include "clutter-fixed.h"
|
||||
#include "clutter-marshal.h"
|
||||
#include "clutter-private.h"
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (ClutterBackend, clutter_backend, G_TYPE_OBJECT);
|
||||
|
||||
#define DEFAULT_FONT_NAME "Sans 10"
|
||||
|
||||
#define CLUTTER_BACKEND_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_BACKEND, ClutterBackendPrivate))
|
||||
|
||||
@ -60,11 +63,24 @@ struct _ClutterBackendPrivate
|
||||
ClutterFixed resolution;
|
||||
|
||||
cairo_font_options_t *font_options;
|
||||
|
||||
gchar *font_name;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
RESOLUTION_CHANGED,
|
||||
FONT_CHANGED,
|
||||
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint backend_signals[LAST_SIGNAL] = { 0, };
|
||||
|
||||
static void
|
||||
clutter_backend_dispose (GObject *gobject)
|
||||
{
|
||||
ClutterBackendPrivate *priv = CLUTTER_BACKEND (gobject)->priv;
|
||||
ClutterMainContext *clutter_context;
|
||||
|
||||
clutter_context = clutter_context_get_default ();
|
||||
@ -76,6 +92,8 @@ clutter_backend_dispose (GObject *gobject)
|
||||
clutter_context->events_queue = NULL;
|
||||
}
|
||||
|
||||
g_free (priv->font_name);
|
||||
|
||||
clutter_backend_set_font_options (CLUTTER_BACKEND (gobject), NULL);
|
||||
|
||||
G_OBJECT_CLASS (clutter_backend_parent_class)->dispose (gobject);
|
||||
@ -89,6 +107,24 @@ clutter_backend_class_init (ClutterBackendClass *klass)
|
||||
gobject_class->dispose = clutter_backend_dispose;
|
||||
|
||||
g_type_class_add_private (gobject_class, sizeof (ClutterBackendPrivate));
|
||||
|
||||
backend_signals[RESOLUTION_CHANGED] =
|
||||
g_signal_new (I_("resolution-changed"),
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (ClutterBackendClass, resolution_changed),
|
||||
NULL, NULL,
|
||||
clutter_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
|
||||
backend_signals[FONT_CHANGED] =
|
||||
g_signal_new (I_("font-changed"),
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (ClutterBackendClass, font_changed),
|
||||
NULL, NULL,
|
||||
clutter_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -388,8 +424,9 @@ clutter_backend_set_resolution (ClutterBackend *backend,
|
||||
priv->resolution = fixed_dpi;
|
||||
|
||||
if (CLUTTER_CONTEXT ()->font_map)
|
||||
cogl_pango_font_map_set_resolution (CLUTTER_CONTEXT ()->font_map,
|
||||
COGL_FIXED_TO_FLOAT (fixed_dpi));
|
||||
cogl_pango_font_map_set_resolution (CLUTTER_CONTEXT ()->font_map, dpi);
|
||||
|
||||
g_signal_emit (backend, backend_signals[RESOLUTION_CHANGED], 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -445,6 +482,8 @@ clutter_backend_set_font_options (ClutterBackend *backend,
|
||||
priv->font_options = cairo_font_options_copy (options);
|
||||
else
|
||||
priv->font_options = NULL;
|
||||
|
||||
g_signal_emit (backend, backend_signals[FONT_CHANGED], 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -482,3 +521,63 @@ clutter_backend_get_font_options (ClutterBackend *backend)
|
||||
return priv->font_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_backend_set_font_name:
|
||||
* @backend: a #ClutterBackend
|
||||
* @font_name: the name of the font
|
||||
*
|
||||
* Sets the default font to be used by Clutter. The @font_name string
|
||||
* must either be %NULL, which means that the font name from the
|
||||
* default #ClutterBackend will be used; or be something that can
|
||||
* be parsed by the pango_font_description_from_string() function.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
void
|
||||
clutter_backend_set_font_name (ClutterBackend *backend,
|
||||
const gchar *font_name)
|
||||
{
|
||||
ClutterBackendPrivate *priv;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_BACKEND (backend));
|
||||
|
||||
priv = backend->priv;
|
||||
|
||||
g_free (priv->font_name);
|
||||
|
||||
if (font_name == NULL || *font_name == '\0')
|
||||
priv->font_name = g_strdup (DEFAULT_FONT_NAME);
|
||||
else
|
||||
priv->font_name = g_strdup (font_name);
|
||||
|
||||
g_signal_emit (backend, backend_signals[FONT_CHANGED], 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_backend_get_font_name:
|
||||
* @backend: a #ClutterBackend
|
||||
*
|
||||
* Retrieves the default font name as set by
|
||||
* clutter_backend_set_font_name().
|
||||
*
|
||||
* Return value: the font name for the backend. The returned string is
|
||||
* owned by the #ClutterBackend and should never be modified or freed
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
G_CONST_RETURN gchar *
|
||||
clutter_backend_get_font_name (ClutterBackend *backend)
|
||||
{
|
||||
ClutterBackendPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), NULL);
|
||||
|
||||
priv = backend->priv;
|
||||
|
||||
if (G_LIKELY (priv->font_name))
|
||||
return priv->font_name;
|
||||
|
||||
priv->font_name = g_strdup (DEFAULT_FONT_NAME);
|
||||
|
||||
return priv->font_name;
|
||||
}
|
||||
|
@ -30,6 +30,8 @@
|
||||
|
||||
#include <cairo.h>
|
||||
#include <glib-object.h>
|
||||
#include <pango/pango.h>
|
||||
|
||||
#include <clutter/clutter-actor.h>
|
||||
#include <clutter/clutter-stage.h>
|
||||
#include <clutter/clutter-event.h>
|
||||
@ -77,6 +79,10 @@ struct _ClutterBackendClass
|
||||
ClutterStage *stage);
|
||||
void (* ensure_context) (ClutterBackend *backend,
|
||||
ClutterStage *stage);
|
||||
|
||||
/* signals */
|
||||
void (* resolution_changed) (ClutterBackend *backend);
|
||||
void (* font_changed) (ClutterBackend *backend);
|
||||
};
|
||||
|
||||
GType clutter_backend_get_type (void) G_GNUC_CONST;
|
||||
@ -95,6 +101,9 @@ guint clutter_backend_get_double_click_distance (ClutterBackend
|
||||
void clutter_backend_set_font_options (ClutterBackend *backend,
|
||||
cairo_font_options_t *options);
|
||||
cairo_font_options_t *clutter_backend_get_font_options (ClutterBackend *backend);
|
||||
void clutter_backend_set_font_name (ClutterBackend *backend,
|
||||
const gchar *font_name);
|
||||
G_CONST_RETURN gchar *clutter_backend_get_font_name (ClutterBackend *backend);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -476,10 +476,129 @@ clutter_binding_pool_install_closure (ClutterBindingPool *pool,
|
||||
g_hash_table_insert (pool->entries_hash, entry, entry);
|
||||
}
|
||||
|
||||
gchar **
|
||||
clutter_binding_pool_list_actions (ClutterBindingPool *pool)
|
||||
/**
|
||||
* clutter_binding_pool_override_action:
|
||||
* @pool: a #ClutterBindingPool
|
||||
* @key_val: key symbol
|
||||
* @modifiers: bitmask of modifiers
|
||||
* @callback: function to be called when the action is activated
|
||||
* @data: data to be passed to @callback
|
||||
* @notify: function to be called when the action is removed
|
||||
* from the pool
|
||||
*
|
||||
* Allows overriding the action for @key_val and @modifiers inside a
|
||||
* #ClutterBindingPool. See clutter_binding_pool_install_action().
|
||||
*
|
||||
* When an action has been activated using clutter_binding_pool_activate()
|
||||
* the passed @callback will be invoked (with @data).
|
||||
*
|
||||
* Actions can be blocked with clutter_binding_pool_block_action()
|
||||
* and then unblocked using clutter_binding_pool_unblock_action().
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
void
|
||||
clutter_binding_pool_override_action (ClutterBindingPool *pool,
|
||||
guint key_val,
|
||||
ClutterModifierType modifiers,
|
||||
GCallback callback,
|
||||
gpointer data,
|
||||
GDestroyNotify notify)
|
||||
{
|
||||
return NULL;
|
||||
ClutterBindingEntry *entry;
|
||||
GClosure *closure;
|
||||
|
||||
g_return_if_fail (pool != NULL);
|
||||
g_return_if_fail (key_val != 0);
|
||||
g_return_if_fail (callback != NULL);
|
||||
|
||||
entry = binding_pool_lookup_entry (pool, key_val, modifiers);
|
||||
if (G_UNLIKELY (entry == NULL))
|
||||
{
|
||||
g_warning ("There is no action for the given key symbol "
|
||||
"of %d (modifiers: %d) installed inside the "
|
||||
"binding pool.",
|
||||
key_val, modifiers);
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry->closure)
|
||||
{
|
||||
g_closure_unref (entry->closure);
|
||||
entry->closure = NULL;
|
||||
}
|
||||
|
||||
closure = g_cclosure_new (callback, data, (GClosureNotify) notify);
|
||||
entry->closure = g_closure_ref (closure);
|
||||
g_closure_sink (closure);
|
||||
|
||||
if (G_CLOSURE_NEEDS_MARSHAL (closure))
|
||||
{
|
||||
GClosureMarshal marshal;
|
||||
|
||||
marshal = clutter_marshal_BOOLEAN__STRING_UINT_ENUM;
|
||||
g_closure_set_marshal (closure, marshal);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_binding_pool_override_action:
|
||||
* @pool: a #ClutterBindingPool
|
||||
* @key_val: key symbol
|
||||
* @modifiers: bitmask of modifiers
|
||||
* @closure: a #GClosure
|
||||
*
|
||||
* A #GClosure variant of clutter_binding_pool_override_action().
|
||||
*
|
||||
* Allows overriding the action for @key_val and @modifiers inside a
|
||||
* #ClutterBindingPool. See clutter_binding_pool_install_closure().
|
||||
*
|
||||
* When an action has been activated using clutter_binding_pool_activate()
|
||||
* the passed @callback will be invoked (with @data).
|
||||
*
|
||||
* Actions can be blocked with clutter_binding_pool_block_action()
|
||||
* and then unblocked using clutter_binding_pool_unblock_action().
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
void
|
||||
clutter_binding_pool_override_closure (ClutterBindingPool *pool,
|
||||
guint key_val,
|
||||
ClutterModifierType modifiers,
|
||||
GClosure *closure)
|
||||
{
|
||||
ClutterBindingEntry *entry;
|
||||
|
||||
g_return_if_fail (pool != NULL);
|
||||
g_return_if_fail (key_val != 0);
|
||||
g_return_if_fail (closure != NULL);
|
||||
|
||||
entry = binding_pool_lookup_entry (pool, key_val, modifiers);
|
||||
if (G_UNLIKELY (entry == NULL))
|
||||
{
|
||||
g_warning ("There is no action for the given key symbol "
|
||||
"of %d (modifiers: %d) installed inside the "
|
||||
"binding pool.",
|
||||
key_val, modifiers);
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry->closure)
|
||||
{
|
||||
g_closure_unref (entry->closure);
|
||||
entry->closure = NULL;
|
||||
}
|
||||
|
||||
entry->closure = g_closure_ref (closure);
|
||||
g_closure_sink (closure);
|
||||
|
||||
if (G_CLOSURE_NEEDS_MARSHAL (closure))
|
||||
{
|
||||
GClosureMarshal marshal;
|
||||
|
||||
marshal = clutter_marshal_BOOLEAN__STRING_UINT_ENUM;
|
||||
g_closure_set_marshal (closure, marshal);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -531,6 +650,7 @@ clutter_binding_pool_remove_action (ClutterBindingPool *pool,
|
||||
ClutterModifierType modifiers)
|
||||
{
|
||||
ClutterBindingEntry remove_entry = { 0, };
|
||||
GSList *l;
|
||||
|
||||
g_return_if_fail (pool != NULL);
|
||||
g_return_if_fail (key_val != 0);
|
||||
@ -540,6 +660,18 @@ clutter_binding_pool_remove_action (ClutterBindingPool *pool,
|
||||
remove_entry.key_val = key_val;
|
||||
remove_entry.modifiers = modifiers;
|
||||
|
||||
for (l = pool->entries; l != NULL; l = l->data)
|
||||
{
|
||||
ClutterBindingEntry *e = l->data;
|
||||
|
||||
if (e->key_val == remove_entry.key_val &&
|
||||
e->modifiers == remove_entry.modifiers)
|
||||
{
|
||||
pool->entries = g_slist_remove_link (pool->entries, l);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_hash_table_remove (pool->entries_hash, &remove_entry);
|
||||
}
|
||||
|
||||
|
@ -72,8 +72,17 @@ void clutter_binding_pool_install_closure (ClutterBindingPool
|
||||
guint key_val,
|
||||
ClutterModifierType modifiers,
|
||||
GClosure *closure);
|
||||
void clutter_binding_pool_override_action (ClutterBindingPool *pool,
|
||||
guint key_val,
|
||||
ClutterModifierType modifiers,
|
||||
GCallback callback,
|
||||
gpointer data,
|
||||
GDestroyNotify notify);
|
||||
void clutter_binding_pool_override_closure (ClutterBindingPool *pool,
|
||||
guint key_val,
|
||||
ClutterModifierType modifiers,
|
||||
GClosure *closure);
|
||||
|
||||
gchar ** clutter_binding_pool_list_actions (ClutterBindingPool *pool);
|
||||
G_CONST_RETURN gchar *clutter_binding_pool_find_action (ClutterBindingPool *pool,
|
||||
guint key_val,
|
||||
ClutterModifierType modifiers);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,165 +0,0 @@
|
||||
/*
|
||||
* Clutter.
|
||||
*
|
||||
* An OpenGL based 'interactive canvas' library.
|
||||
*
|
||||
* Authored By Matthew Allum <mallum@openedhand.com>
|
||||
* Neil Jagdish Patel <njp@o-hand.com
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <clutter/clutter.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __CLUTTER_ENTRY_H__
|
||||
#define __CLUTTER_ENTRY_H__
|
||||
|
||||
#include <clutter/clutter-actor.h>
|
||||
#include <clutter/clutter-color.h>
|
||||
#include <clutter/clutter-event.h>
|
||||
#include <pango/pango.h>
|
||||
|
||||
|
||||
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__ */
|
File diff suppressed because it is too large
Load Diff
@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Clutter.
|
||||
*
|
||||
* An OpenGL based 'interactive canvas' library.
|
||||
*
|
||||
* Authored By Matthew Allum <mallum@openedhand.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <clutter/clutter.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __CLUTTER_LABEL_H__
|
||||
#define __CLUTTER_LABEL_H__
|
||||
|
||||
#include <clutter/clutter-actor.h>
|
||||
#include <clutter/clutter-color.h>
|
||||
#include <pango/pango.h>
|
||||
|
||||
|
||||
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__ */
|
@ -69,6 +69,8 @@ static guint clutter_default_fps = 60;
|
||||
static guint clutter_main_loop_level = 0;
|
||||
static GSList *main_loops = NULL;
|
||||
|
||||
static PangoDirection clutter_text_direction = PANGO_DIRECTION_LTR;
|
||||
|
||||
guint clutter_debug_flags = 0; /* global clutter debug flag */
|
||||
|
||||
#ifdef CLUTTER_ENABLE_DEBUG
|
||||
@ -401,23 +403,100 @@ _clutter_do_pick (ClutterStage *stage,
|
||||
return clutter_get_actor_by_gid (id);
|
||||
}
|
||||
|
||||
static PangoDirection
|
||||
clutter_get_text_direction (void)
|
||||
{
|
||||
PangoDirection dir = PANGO_DIRECTION_LTR;
|
||||
const gchar *direction;
|
||||
|
||||
direction = g_getenv ("CLUTTER_TEXT_DIRECTION");
|
||||
if (direction && *direction != '\0')
|
||||
{
|
||||
if (strcmp (direction, "rtl") == 0)
|
||||
dir = PANGO_DIRECTION_RTL;
|
||||
else if (strcmp (direction, "ltr") == 0)
|
||||
dir = PANGO_DIRECTION_LTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Translate to default:RTL if you want your widgets
|
||||
* to be RTL, otherwise translate to default:LTR.
|
||||
*
|
||||
* Do *not* translate it to "predefinito:LTR": if it
|
||||
* it isn't default:LTR or default:RTL it will not work
|
||||
*/
|
||||
char *e = _("default:LTR");
|
||||
|
||||
if (strcmp (e, "default:RTL") == 0)
|
||||
dir = PANGO_DIRECTION_RTL;
|
||||
else if (strcmp (e, "default:LTR") == 0)
|
||||
dir = PANGO_DIRECTION_LTR;
|
||||
else
|
||||
g_warning ("Whoever translated default:LTR did so wrongly.");
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
static void
|
||||
update_pango_context (ClutterBackend *backend,
|
||||
PangoContext *context)
|
||||
{
|
||||
PangoFontDescription *font_desc;
|
||||
cairo_font_options_t *font_options;
|
||||
const gchar *font_name;
|
||||
gdouble resolution;
|
||||
|
||||
/* update the text direction */
|
||||
pango_context_set_base_dir (context, clutter_text_direction);
|
||||
|
||||
/* get the configuration for the PangoContext from the backend */
|
||||
font_name = clutter_backend_get_font_name (backend);
|
||||
font_options = clutter_backend_get_font_options (backend);
|
||||
resolution = clutter_backend_get_resolution (backend);
|
||||
|
||||
font_desc = pango_font_description_from_string (font_name);
|
||||
|
||||
if (resolution < 0)
|
||||
resolution = 96.0; /* fall back */
|
||||
|
||||
pango_context_set_font_description (context, font_desc);
|
||||
pango_cairo_context_set_font_options (context, font_options);
|
||||
pango_cairo_context_set_resolution (context, resolution);
|
||||
|
||||
pango_font_description_free (font_desc);
|
||||
}
|
||||
|
||||
PangoContext *
|
||||
_clutter_context_get_pango_context (ClutterMainContext *self)
|
||||
{
|
||||
if (G_UNLIKELY (self->pango_context == NULL))
|
||||
{
|
||||
PangoContext *context;
|
||||
|
||||
context = cogl_pango_font_map_create_context (self->font_map);
|
||||
self->pango_context = context;
|
||||
|
||||
g_signal_connect (self->backend, "resolution-changed",
|
||||
G_CALLBACK (update_pango_context),
|
||||
self->pango_context);
|
||||
g_signal_connect (self->backend, "font-changed",
|
||||
G_CALLBACK (update_pango_context),
|
||||
self->pango_context);
|
||||
}
|
||||
|
||||
update_pango_context (self->backend, self->pango_context);
|
||||
|
||||
return self->pango_context;
|
||||
}
|
||||
|
||||
PangoContext *
|
||||
_clutter_context_create_pango_context (ClutterMainContext *self)
|
||||
{
|
||||
PangoContext *context;
|
||||
gdouble resolution;
|
||||
cairo_font_options_t *font_options;
|
||||
|
||||
resolution = clutter_backend_get_resolution (self->backend);
|
||||
if (resolution < 0)
|
||||
resolution = 96.0; /* fall back */
|
||||
|
||||
context = cogl_pango_font_map_create_context (self->font_map);
|
||||
|
||||
pango_cairo_context_set_resolution (context, resolution);
|
||||
|
||||
font_options = clutter_backend_get_font_options (self->backend);
|
||||
pango_cairo_context_set_font_options (context, font_options);
|
||||
update_pango_context (self->backend, context);
|
||||
|
||||
return context;
|
||||
}
|
||||
@ -1004,6 +1083,17 @@ clutter_get_timestamp (void)
|
||||
#endif
|
||||
}
|
||||
|
||||
static gboolean
|
||||
clutter_arg_direction_cb (const char *key,
|
||||
const char *value,
|
||||
gpointer user_data)
|
||||
{
|
||||
clutter_text_direction =
|
||||
(strcmp (value, "rtl") == 0) ? PANGO_DIRECTION_RTL
|
||||
: PANGO_DIRECTION_LTR;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef CLUTTER_ENABLE_DEBUG
|
||||
static gboolean
|
||||
@ -1077,6 +1167,8 @@ clutter_init_real (GError **error)
|
||||
cogl_pango_font_map_set_resolution (ctx->font_map, resolution);
|
||||
cogl_pango_font_map_set_use_mipmapping (ctx->font_map, TRUE);
|
||||
|
||||
clutter_text_direction = clutter_get_text_direction ();
|
||||
|
||||
/* Stage will give us a GL Context etc */
|
||||
stage = clutter_stage_get_default ();
|
||||
if (!stage)
|
||||
@ -1147,6 +1239,9 @@ static GOptionEntry clutter_args[] = {
|
||||
N_("Default frame rate"), "FPS" },
|
||||
{ "g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &clutter_fatal_warnings,
|
||||
N_("Make all warnings fatal"), NULL },
|
||||
{ "clutter-text-direction", 0, 0, G_OPTION_ARG_CALLBACK,
|
||||
clutter_arg_direction_cb,
|
||||
N_("Direction for the text"), "DIRECTION" },
|
||||
#ifdef CLUTTER_ENABLE_DEBUG
|
||||
{ "clutter-debug", 0, 0, G_OPTION_ARG_CALLBACK, clutter_arg_debug_cb,
|
||||
N_("Clutter debugging flags to set"), "FLAGS" },
|
||||
|
@ -38,6 +38,8 @@
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "pango/cogl-pango.h"
|
||||
|
||||
#include "clutter-backend.h"
|
||||
#include "clutter-event.h"
|
||||
#include "clutter-feature.h"
|
||||
@ -45,7 +47,6 @@
|
||||
#include "clutter-stage-manager.h"
|
||||
#include "clutter-stage-window.h"
|
||||
#include "clutter-stage.h"
|
||||
#include "pango/cogl-pango.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -125,6 +126,7 @@ struct _ClutterMainContext
|
||||
gint fb_r_mask, fb_g_mask, fb_b_mask;
|
||||
gint fb_r_mask_used, fb_g_mask_used, fb_b_mask_used;
|
||||
|
||||
PangoContext *pango_context; /* Global Pango context */
|
||||
CoglPangoFontMap *font_map; /* Global font map */
|
||||
|
||||
GSList *input_devices; /* For extra input devices, i.e
|
||||
@ -134,6 +136,7 @@ struct _ClutterMainContext
|
||||
#define CLUTTER_CONTEXT() (clutter_context_get_default ())
|
||||
ClutterMainContext *clutter_context_get_default (void);
|
||||
PangoContext *_clutter_context_create_pango_context (ClutterMainContext *self);
|
||||
PangoContext *_clutter_context_get_pango_context (ClutterMainContext *self);
|
||||
|
||||
#define CLUTTER_PRIVATE_FLAGS(a) (((ClutterActor *) (a))->private_flags)
|
||||
#define CLUTTER_SET_PRIVATE_FLAGS(a,f) (CLUTTER_PRIVATE_FLAGS (a) |= (f))
|
||||
|
3753
clutter/clutter-text.c
Normal file
3753
clutter/clutter-text.c
Normal file
File diff suppressed because it is too large
Load Diff
198
clutter/clutter-text.h
Normal file
198
clutter/clutter-text.h
Normal file
@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Clutter.
|
||||
*
|
||||
* An OpenGL based 'interactive canvas' library.
|
||||
*
|
||||
* Copyright (C) 2008 Intel Corporation.
|
||||
*
|
||||
* Authored By: Øyvind Kolås <pippin@o-hand.com>
|
||||
* Emmanuele Bassi <ebassi@linux.intel.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <clutter/clutter.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __CLUTTER_TEXT_H__
|
||||
#define __CLUTTER_TEXT_H__
|
||||
|
||||
#include <clutter/clutter-actor.h>
|
||||
#include <pango/pango.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define CLUTTER_TYPE_TEXT (clutter_text_get_type ())
|
||||
#define CLUTTER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_TEXT, ClutterText))
|
||||
#define CLUTTER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_TEXT, ClutterTextClass))
|
||||
#define CLUTTER_IS_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_TEXT))
|
||||
#define CLUTTER_IS_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_TEXT))
|
||||
#define CLUTTER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_TEXT, ClutterTextClass))
|
||||
|
||||
typedef struct _ClutterText ClutterText;
|
||||
typedef struct _ClutterTextPrivate ClutterTextPrivate;
|
||||
typedef struct _ClutterTextClass ClutterTextClass;
|
||||
|
||||
/**
|
||||
* ClutterText:
|
||||
*
|
||||
* The #ClutterText struct contains only private data.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
struct _ClutterText
|
||||
{
|
||||
/*< private >*/
|
||||
ClutterActor parent_instance;
|
||||
|
||||
ClutterTextPrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* ClutterTextClass:
|
||||
* @text_changed: class handler for the #ClutterText::text-changed signal
|
||||
* @activate: class handler for the #ClutterText::activate signal
|
||||
* @cursor_event: class handler for the #ClutterText::cursor_event signal
|
||||
*
|
||||
* The #ClutterTextClass struct contains only private data.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
struct _ClutterTextClass
|
||||
{
|
||||
/*< private >*/
|
||||
ClutterActorClass parent_class;
|
||||
|
||||
/*< public >*/
|
||||
/* signals, not vfuncs */
|
||||
void (* text_changed) (ClutterText *self);
|
||||
void (* activate) (ClutterText *self);
|
||||
void (* cursor_event) (ClutterText *self,
|
||||
const ClutterGeometry *geometry);
|
||||
|
||||
/*< private >*/
|
||||
/* padding for future expansion */
|
||||
void (* _clutter_reserved1) (void);
|
||||
void (* _clutter_reserved2) (void);
|
||||
void (* _clutter_reserved3) (void);
|
||||
void (* _clutter_reserved4) (void);
|
||||
void (* _clutter_reserved5) (void);
|
||||
void (* _clutter_reserved6) (void);
|
||||
void (* _clutter_reserved7) (void);
|
||||
void (* _clutter_reserved8) (void);
|
||||
};
|
||||
|
||||
GType clutter_text_get_type (void) G_GNUC_CONST;
|
||||
|
||||
ClutterActor * clutter_text_new (void);
|
||||
ClutterActor * clutter_text_new_full (const gchar *font_name,
|
||||
const gchar *text,
|
||||
const ClutterColor *color);
|
||||
ClutterActor * clutter_text_new_with_text (const gchar *font_name,
|
||||
const gchar *text);
|
||||
|
||||
G_CONST_RETURN gchar *clutter_text_get_text (ClutterText *self);
|
||||
void clutter_text_set_text (ClutterText *self,
|
||||
const gchar *text);
|
||||
PangoLayout * clutter_text_get_layout (ClutterText *self);
|
||||
void clutter_text_set_color (ClutterText *self,
|
||||
const ClutterColor *color);
|
||||
void clutter_text_get_color (ClutterText *self,
|
||||
ClutterColor *color);
|
||||
void clutter_text_set_font_name (ClutterText *self,
|
||||
const gchar *font_name);
|
||||
G_CONST_RETURN gchar *clutter_text_get_font_name (ClutterText *self);
|
||||
|
||||
void clutter_text_set_ellipsize (ClutterText *self,
|
||||
PangoEllipsizeMode mode);
|
||||
PangoEllipsizeMode clutter_text_get_ellipsize (ClutterText *self);
|
||||
void clutter_text_set_line_wrap (ClutterText *self,
|
||||
gboolean line_wrap);
|
||||
gboolean clutter_text_get_line_wrap (ClutterText *self);
|
||||
void clutter_text_set_line_wrap_mode (ClutterText *self,
|
||||
PangoWrapMode wrap_mode);
|
||||
PangoWrapMode clutter_text_get_line_wrap_mode (ClutterText *self);
|
||||
PangoLayout * clutter_text_get_layout (ClutterText *self);
|
||||
void clutter_text_set_attributes (ClutterText *self,
|
||||
PangoAttrList *attrs);
|
||||
PangoAttrList * clutter_text_get_attributes (ClutterText *self);
|
||||
void clutter_text_set_use_markup (ClutterText *self,
|
||||
gboolean setting);
|
||||
gboolean clutter_text_get_use_markup (ClutterText *self);
|
||||
void clutter_text_set_alignment (ClutterText *self,
|
||||
PangoAlignment alignment);
|
||||
PangoAlignment clutter_text_get_alignment (ClutterText *self);
|
||||
void clutter_text_set_justify (ClutterText *self,
|
||||
gboolean justify);
|
||||
gboolean clutter_text_get_justify (ClutterText *self);
|
||||
|
||||
void clutter_text_insert_unichar (ClutterText *self,
|
||||
gunichar wc);
|
||||
void clutter_text_delete_chars (ClutterText *self,
|
||||
guint n_chars);
|
||||
void clutter_text_insert_text (ClutterText *self,
|
||||
const gchar *text,
|
||||
gssize position);
|
||||
void clutter_text_delete_text (ClutterText *self,
|
||||
gssize start_pos,
|
||||
gssize end_pos);
|
||||
gchar * clutter_text_get_chars (ClutterText *self,
|
||||
gssize start_pos,
|
||||
gssize end_pos);
|
||||
void clutter_text_set_editable (ClutterText *self,
|
||||
gboolean editable);
|
||||
gboolean clutter_text_get_editable (ClutterText *self);
|
||||
void clutter_text_set_activatable (ClutterText *self,
|
||||
gboolean activatable);
|
||||
gboolean clutter_text_get_activatable (ClutterText *self);
|
||||
|
||||
gint clutter_text_get_cursor_position (ClutterText *self);
|
||||
void clutter_text_set_cursor_position (ClutterText *self,
|
||||
gint position);
|
||||
void clutter_text_set_cursor_visible (ClutterText *self,
|
||||
gboolean cursor_visible);
|
||||
gboolean clutter_text_get_cursor_visible (ClutterText *self);
|
||||
void clutter_text_set_cursor_color (ClutterText *self,
|
||||
const ClutterColor *color);
|
||||
void clutter_text_get_cursor_color (ClutterText *self,
|
||||
ClutterColor *color);
|
||||
void clutter_text_set_cursor_size (ClutterText *self,
|
||||
gint size);
|
||||
guint clutter_text_get_cursor_size (ClutterText *self);
|
||||
void clutter_text_set_selectable (ClutterText *self,
|
||||
gboolean selectable);
|
||||
gboolean clutter_text_get_selectable (ClutterText *self);
|
||||
void clutter_text_set_selection_bound (ClutterText *self,
|
||||
gint selection_bound);
|
||||
gint clutter_text_get_selection_bound (ClutterText *self);
|
||||
void clutter_text_set_selection (ClutterText *self,
|
||||
gssize start_pos,
|
||||
gssize end_pos);
|
||||
gchar * clutter_text_get_selection (ClutterText *self);
|
||||
void clutter_text_set_password_char (ClutterText *self,
|
||||
gunichar wc);
|
||||
gunichar clutter_text_get_password_char (ClutterText *self);
|
||||
void clutter_text_set_max_length (ClutterText *self,
|
||||
gint max);
|
||||
gint clutter_text_get_max_length (ClutterText *self);
|
||||
void clutter_text_set_single_line_mode (ClutterText *self,
|
||||
gboolean single_line);
|
||||
gboolean clutter_text_get_single_line_mode (ClutterText *self);
|
||||
|
||||
gboolean clutter_text_activate (ClutterText *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_TEXT_H__ */
|
@ -47,14 +47,12 @@
|
||||
#include "clutter-container.h"
|
||||
#include "clutter-deprecated.h"
|
||||
#include "clutter-effect.h"
|
||||
#include "clutter-entry.h"
|
||||
#include "clutter-event.h"
|
||||
#include "clutter-feature.h"
|
||||
#include "clutter-frame-source.h"
|
||||
#include "clutter-group.h"
|
||||
#include "clutter-interval.h"
|
||||
#include "clutter-keysyms.h"
|
||||
#include "clutter-label.h"
|
||||
#include "clutter-list-model.h"
|
||||
#include "clutter-main.h"
|
||||
#include "clutter-media.h"
|
||||
@ -69,6 +67,7 @@
|
||||
#include "clutter-stage.h"
|
||||
#include "clutter-stage-manager.h"
|
||||
#include "clutter-texture.h"
|
||||
#include "clutter-text.h"
|
||||
#include "clutter-timeline.h"
|
||||
#include "clutter-timeout-pool.h"
|
||||
#include "clutter-types.h"
|
||||
|
@ -55,6 +55,7 @@ CFILE_GLOB=$(top_srcdir)/clutter/*.c
|
||||
# e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h
|
||||
IGNORE_HFILES=\
|
||||
clutter.h \
|
||||
clutter-bezier.h \
|
||||
clutter-debug.h \
|
||||
clutter-deprecated.h \
|
||||
clutter-enum-types.h \
|
||||
|
@ -58,8 +58,7 @@
|
||||
<xi:include href="xml/clutter-texture.xml"/>
|
||||
<xi:include href="xml/clutter-clone-texture.xml"/>
|
||||
<xi:include href="xml/clutter-cairo-texture.xml"/>
|
||||
<xi:include href="xml/clutter-label.xml"/>
|
||||
<xi:include href="xml/clutter-entry.xml"/>
|
||||
<xi:include href="xml/clutter-text.xml"/>
|
||||
</chapter>
|
||||
|
||||
<chapter>
|
||||
|
@ -66,48 +66,6 @@ clutter_unit_get_type
|
||||
clutter_param_unit_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>clutter-label</FILE>
|
||||
<TITLE>ClutterLabel</TITLE>
|
||||
ClutterLabel
|
||||
ClutterLabelClass
|
||||
clutter_label_new
|
||||
clutter_label_new_with_text
|
||||
clutter_label_new_full
|
||||
clutter_label_set_text
|
||||
clutter_label_get_text
|
||||
clutter_label_set_font_name
|
||||
clutter_label_get_font_name
|
||||
clutter_label_set_color
|
||||
clutter_label_get_color
|
||||
clutter_label_set_ellipsize
|
||||
clutter_label_get_ellipsize
|
||||
clutter_label_set_line_wrap
|
||||
clutter_label_get_line_wrap
|
||||
clutter_label_set_line_wrap_mode
|
||||
clutter_label_get_line_wrap_mode
|
||||
clutter_label_get_layout
|
||||
clutter_label_set_attributes
|
||||
clutter_label_get_attributes
|
||||
clutter_label_set_use_markup
|
||||
clutter_label_get_use_markup
|
||||
clutter_label_set_alignment
|
||||
clutter_label_get_alignment
|
||||
clutter_label_get_justify
|
||||
clutter_label_set_justify
|
||||
|
||||
<SUBSECTION Standard>
|
||||
CLUTTER_LABEL
|
||||
CLUTTER_IS_LABEL
|
||||
CLUTTER_TYPE_LABEL
|
||||
CLUTTER_LABEL_CLASS
|
||||
CLUTTER_IS_LABEL_CLASS
|
||||
CLUTTER_LABEL_GET_CLASS
|
||||
<SUBSECTION Private>
|
||||
ClutterLabelPrivate
|
||||
clutter_label_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>clutter-behaviour</FILE>
|
||||
<TITLE>ClutterBehaviour</TITLE>
|
||||
@ -476,6 +434,10 @@ clutter_actor_get_scalex
|
||||
clutter_actor_set_rotationx
|
||||
clutter_actor_get_rotationx
|
||||
|
||||
<SUBSECTION>
|
||||
clutter_actor_grab_key_focus
|
||||
clutter_actor_get_pango_context
|
||||
|
||||
<SUBSECTION Standard>
|
||||
CLUTTER_TYPE_GEOMETRY
|
||||
CLUTTER_TYPE_ACTOR_BOX
|
||||
@ -698,6 +660,8 @@ ClutterPathCallback
|
||||
ClutterPathNodeType
|
||||
clutter_path_new
|
||||
clutter_path_new_with_description
|
||||
|
||||
<SUBSECTION>
|
||||
clutter_path_add_move_to
|
||||
clutter_path_add_rel_move_to
|
||||
clutter_path_add_line_to
|
||||
@ -708,6 +672,8 @@ clutter_path_add_close
|
||||
clutter_path_add_string
|
||||
clutter_path_add_node
|
||||
clutter_path_add_cairo_path
|
||||
|
||||
<SUBSECTION>
|
||||
clutter_path_get_n_nodes
|
||||
clutter_path_get_node
|
||||
clutter_path_get_nodes
|
||||
@ -869,14 +835,16 @@ clutter_behaviour_ellipse_get_type
|
||||
<FILE>clutter-backend</FILE>
|
||||
<TITLE>ClutterBackend</TITLE>
|
||||
clutter_get_default_backend
|
||||
clutter_backend_get_resolution
|
||||
clutter_backend_set_resolution
|
||||
clutter_backend_get_double_click_time
|
||||
clutter_backend_get_resolution
|
||||
clutter_backend_set_double_click_time
|
||||
clutter_backend_get_double_click_distance
|
||||
clutter_backend_get_double_click_time
|
||||
clutter_backend_set_double_click_distance
|
||||
clutter_backend_get_double_click_distance
|
||||
clutter_backend_set_font_options
|
||||
clutter_backend_get_font_options
|
||||
clutter_backend_set_font_name
|
||||
clutter_backend_get_font_name
|
||||
<SUBSECTION Standard>
|
||||
CLUTTER_BACKEND
|
||||
CLUTTER_IS_BACKEND
|
||||
@ -1219,50 +1187,6 @@ CLUTTER_COGL
|
||||
CLUTTER_NO_FPU
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>clutter-entry</FILE>
|
||||
<TITLE>ClutterEntry</TITLE>
|
||||
ClutterEntry
|
||||
ClutterEntryClass
|
||||
clutter_entry_new
|
||||
clutter_entry_new_with_text
|
||||
clutter_entry_new_full
|
||||
clutter_entry_set_text
|
||||
clutter_entry_get_text
|
||||
clutter_entry_set_font_name
|
||||
clutter_entry_get_font_name
|
||||
clutter_entry_set_color
|
||||
clutter_entry_get_color
|
||||
clutter_entry_get_layout
|
||||
clutter_entry_set_alignment
|
||||
clutter_entry_get_alignment
|
||||
clutter_entry_set_cursor_position
|
||||
clutter_entry_get_cursor_position
|
||||
clutter_entry_handle_key_event
|
||||
clutter_entry_insert_unichar
|
||||
clutter_entry_delete_chars
|
||||
clutter_entry_insert_text
|
||||
clutter_entry_delete_text
|
||||
clutter_entry_set_visible_cursor
|
||||
clutter_entry_get_visible_cursor
|
||||
clutter_entry_set_visibility
|
||||
clutter_entry_get_visibility
|
||||
clutter_entry_set_invisible_char
|
||||
clutter_entry_get_invisible_char
|
||||
clutter_entry_set_max_length
|
||||
clutter_entry_get_max_length
|
||||
<SUBSECTION Standard>
|
||||
CLUTTER_ENTRY
|
||||
CLUTTER_IS_ENTRY
|
||||
CLUTTER_TYPE_ENTRY
|
||||
CLUTTER_ENTRY_CLASS
|
||||
CLUTTER_IS_ENTRY_CLASS
|
||||
CLUTTER_ENTRY_GET_CLASS
|
||||
<SUBSECTION Private>
|
||||
ClutterEntryPrivate
|
||||
clutter_entry_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>clutter-effect</FILE>
|
||||
<TITLE>Clutter Effects</TITLE>
|
||||
@ -1533,11 +1457,27 @@ clutter_shader_release
|
||||
clutter_shader_is_compiled
|
||||
clutter_shader_set_is_enabled
|
||||
clutter_shader_get_is_enabled
|
||||
clutter_shader_set_uniform_1f
|
||||
|
||||
<SUBSECTION>
|
||||
clutter_shader_set_uniform
|
||||
clutter_shader_get_cogl_program
|
||||
clutter_shader_get_cogl_fragment_shader
|
||||
clutter_shader_get_cogl_vertex_shader
|
||||
clutter_shader_set_uniform_1f
|
||||
|
||||
<SUBSECTION>
|
||||
ClutterShaderFloat
|
||||
CLUTTER_VALUE_HOLDS_SHADER_FLOAT
|
||||
clutter_value_set_shader_float
|
||||
clutter_value_get_shader_float
|
||||
ClutterShaderInt
|
||||
CLUTTER_VALUE_HOLDS_SHADER_INT
|
||||
clutter_value_set_shader_int
|
||||
clutter_value_get_shader_int
|
||||
ClutterShaderMatrix
|
||||
CLUTTER_VALUE_HOLDS_SHADER_MATRIX
|
||||
clutter_value_set_shader_matrix
|
||||
clutter_value_get_shader_matrix
|
||||
|
||||
<SUBSECTION>
|
||||
CLUTTER_VALUE_HOLDS_SHADER_FLOAT
|
||||
@ -1572,6 +1512,9 @@ clutter_shader_float_get_type
|
||||
clutter_shader_int_get_type
|
||||
clutter_shader_matrix_get_type
|
||||
clutter_shader_error_quark
|
||||
clutter_shader_float_get_type
|
||||
clutter_shader_int_get_type
|
||||
clutter_shader_matrix_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
@ -1638,8 +1581,8 @@ clutter_interval_set_interval
|
||||
clutter_interval_get_interval
|
||||
|
||||
<SUBSECTION>
|
||||
clutter_interval_validate
|
||||
clutter_interval_compute_value
|
||||
clutter_interval_validate
|
||||
|
||||
<SUBSECTION Standard>
|
||||
CLUTTER_TYPE_INTERVAL
|
||||
@ -1668,7 +1611,8 @@ clutter_binding_pool_find
|
||||
<SUBSECTION>
|
||||
clutter_binding_pool_install_action
|
||||
clutter_binding_pool_install_closure
|
||||
clutter_binding_pool_list_actions
|
||||
clutter_binding_pool_override_action
|
||||
clutter_binding_pool_override_closure
|
||||
clutter_binding_pool_find_action
|
||||
clutter_binding_pool_remove_action
|
||||
clutter_binding_pool_block_action
|
||||
@ -1705,4 +1649,82 @@ CLUTTER_CAIRO_TEXTURE_GET_CLASS
|
||||
<SUBSECTION Private>
|
||||
ClutterCairoTexturePrivate
|
||||
clutter_cairo_texture_get_type
|
||||
|
||||
<SECTION>
|
||||
<TITLE>ClutterText</TITLE>
|
||||
<FILE>clutter-text</FILE>
|
||||
ClutterText
|
||||
ClutterTextClass
|
||||
clutter_text_new
|
||||
clutter_text_new_full
|
||||
clutter_text_new_with_text
|
||||
|
||||
<SUBSECTION>
|
||||
clutter_text_set_text
|
||||
clutter_text_get_text
|
||||
clutter_text_set_activatable
|
||||
clutter_text_get_activatable
|
||||
clutter_text_set_alignment
|
||||
clutter_text_get_alignment
|
||||
clutter_text_set_attributes
|
||||
clutter_text_get_attributes
|
||||
clutter_text_set_color
|
||||
clutter_text_get_color
|
||||
clutter_text_set_ellipsize
|
||||
clutter_text_get_ellipsize
|
||||
clutter_text_set_font_name
|
||||
clutter_text_get_font_name
|
||||
clutter_text_set_password_char
|
||||
clutter_text_get_password_char
|
||||
clutter_text_set_justify
|
||||
clutter_text_get_justify
|
||||
clutter_text_get_layout
|
||||
clutter_text_set_line_wrap
|
||||
clutter_text_get_line_wrap
|
||||
clutter_text_set_line_wrap_mode
|
||||
clutter_text_get_line_wrap_mode
|
||||
clutter_text_set_max_length
|
||||
clutter_text_get_max_length
|
||||
clutter_text_set_selectable
|
||||
clutter_text_get_selectable
|
||||
clutter_text_set_selection
|
||||
clutter_text_get_selection
|
||||
clutter_text_set_selection_bound
|
||||
clutter_text_get_selection_bound
|
||||
clutter_text_set_single_line_mode
|
||||
clutter_text_get_single_line_mode
|
||||
clutter_text_set_use_markup
|
||||
clutter_text_get_use_markup
|
||||
|
||||
<SUBSECTION>
|
||||
clutter_text_set_editable
|
||||
clutter_text_get_editable
|
||||
clutter_text_insert_text
|
||||
clutter_text_insert_unichar
|
||||
clutter_text_delete_chars
|
||||
clutter_text_delete_text
|
||||
clutter_text_get_chars
|
||||
clutter_text_set_cursor_color
|
||||
clutter_text_get_cursor_color
|
||||
clutter_text_set_cursor_position
|
||||
clutter_text_get_cursor_position
|
||||
clutter_text_set_cursor_visible
|
||||
clutter_text_get_cursor_visible
|
||||
clutter_text_set_cursor_size
|
||||
clutter_text_get_cursor_size
|
||||
|
||||
<SUBSECTION>
|
||||
clutter_text_activate
|
||||
|
||||
<SUBSECTION Standard>
|
||||
CLUTTER_IS_TEXT
|
||||
CLUTTER_IS_TEXT_CLASS
|
||||
CLUTTER_TEXT
|
||||
CLUTTER_TEXT_CLASS
|
||||
CLUTTER_TEXT_GET_CLASS
|
||||
CLUTTER_TYPE_TEXT
|
||||
|
||||
<SUBSECTION Private>
|
||||
ClutterTextPrivate
|
||||
clutter_text_get_type
|
||||
</SECTION>
|
||||
|
@ -6,7 +6,6 @@ clutter_stage_get_type
|
||||
clutter_rectangle_get_type
|
||||
clutter_texture_get_type
|
||||
clutter_clone_texture_get_type
|
||||
clutter_label_get_type
|
||||
clutter_timeline_get_type
|
||||
clutter_media_get_type
|
||||
clutter_behaviour_get_type
|
||||
@ -19,7 +18,6 @@ clutter_path_get_type
|
||||
clutter_behaviour_rotate_get_type
|
||||
clutter_behaviour_scale_get_type
|
||||
clutter_backend_get_type
|
||||
clutter_entry_get_type
|
||||
clutter_script_get_type
|
||||
clutter_scriptable_get_type
|
||||
clutter_model_get_type
|
||||
@ -29,3 +27,4 @@ clutter_score_get_type
|
||||
clutter_shader_get_type
|
||||
clutter_child_meta_get_type
|
||||
clutter_cairo_texture_get_type
|
||||
clutter_text_get_type
|
||||
|
@ -17,14 +17,14 @@ test_conformance_SOURCES = \
|
||||
test-mesh-mutability.c \
|
||||
test-path.c \
|
||||
test-pick.c \
|
||||
test-label-cache.c \
|
||||
test-clutter-entry.c \
|
||||
test-clutter-rectangle.c \
|
||||
test-clutter-fixed.c \
|
||||
test-actor-invariants.c \
|
||||
test-paint-opacity.c \
|
||||
test-backface-culling.c \
|
||||
test-binding-pool.c \
|
||||
test-clutter-text.c \
|
||||
test-text-cache.c \
|
||||
$(NULL)
|
||||
|
||||
# For convenience, this provides a way to easily run individual unit tests:
|
||||
|
@ -1,370 +0,0 @@
|
||||
#include <glib.h>
|
||||
#include <clutter/clutter.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "test-conform-common.h"
|
||||
|
||||
typedef struct {
|
||||
gunichar unichar;
|
||||
const char bytes[6];
|
||||
gint nbytes;
|
||||
} TestData;
|
||||
|
||||
const TestData
|
||||
test_data[] = {
|
||||
{ 0xe4, "\xc3\xa4", 2 }, /* LATIN SMALL LETTER A WITH DIAERESIS */
|
||||
{ 0x2665, "\xe2\x99\xa5", 3 } /* BLACK HEART SUIT */
|
||||
};
|
||||
|
||||
void
|
||||
test_entry_utf8_validation (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
gunichar unichar;
|
||||
char bytes[6];
|
||||
int nbytes;
|
||||
|
||||
g_assert (g_unichar_validate (t->unichar));
|
||||
|
||||
nbytes = g_unichar_to_utf8 (t->unichar, bytes);
|
||||
bytes[nbytes] = '\0';
|
||||
g_assert (nbytes == t->nbytes);
|
||||
g_assert (memcmp (t->bytes, bytes, nbytes) == 0);
|
||||
|
||||
unichar = g_utf8_get_char_validated (bytes, nbytes);
|
||||
g_assert (unichar == t->unichar);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
get_nbytes (ClutterEntry *entry)
|
||||
{
|
||||
const char *s = clutter_entry_get_text (entry);
|
||||
return strlen (s);
|
||||
}
|
||||
|
||||
static int
|
||||
get_nchars (ClutterEntry *entry)
|
||||
{
|
||||
const char *s = clutter_entry_get_text (entry);
|
||||
g_assert (g_utf8_validate (s, -1, NULL));
|
||||
return g_utf8_strlen (s, -1);
|
||||
}
|
||||
|
||||
#define DONT_MOVE_CURSOR (-2)
|
||||
|
||||
static void
|
||||
insert_unichar (ClutterEntry *entry, gunichar unichar, int position)
|
||||
{
|
||||
if (position > DONT_MOVE_CURSOR)
|
||||
{
|
||||
clutter_entry_set_cursor_position (entry, position);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, position);
|
||||
}
|
||||
|
||||
clutter_entry_insert_unichar (entry, unichar);
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_empty (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
|
||||
g_assert (clutter_entry_get_text (entry) == NULL);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_set_empty (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
|
||||
/* annoyingly slightly different from initially empty */
|
||||
clutter_entry_set_text (entry, "");
|
||||
g_assert_cmpint (get_nchars (entry), ==, 0);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 0);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_set_text (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
|
||||
clutter_entry_set_text (entry, "abcdef");
|
||||
g_assert_cmpint (get_nchars (entry), ==, 6);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 6);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
|
||||
clutter_entry_set_cursor_position (entry, 5);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 5);
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
/* FIXME: cursor position should be -1?
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
*/
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_append_some (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 1; j <= 4; j++)
|
||||
{
|
||||
insert_unichar (entry, t->unichar, DONT_MOVE_CURSOR);
|
||||
g_assert_cmpint (get_nchars (entry), ==, j);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, j * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
}
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_prepend_some (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
int j;
|
||||
|
||||
clutter_entry_insert_unichar (entry, t->unichar);
|
||||
g_assert_cmpint (get_nchars (entry), ==, 1);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 1 * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
|
||||
for (j = 2; j <= 4; j++)
|
||||
{
|
||||
insert_unichar (entry, t->unichar, 0);
|
||||
g_assert_cmpint (get_nchars (entry), ==, j);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, j * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 1);
|
||||
}
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_insert (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
|
||||
clutter_entry_insert_unichar (entry, t->unichar);
|
||||
clutter_entry_insert_unichar (entry, t->unichar);
|
||||
|
||||
insert_unichar (entry, t->unichar, 1);
|
||||
g_assert_cmpint (get_nchars (entry), ==, 3);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 3 * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 2);
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_delete_chars (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 4; j++)
|
||||
clutter_entry_insert_unichar (entry, t->unichar);
|
||||
|
||||
clutter_entry_set_cursor_position (entry, 2);
|
||||
clutter_entry_delete_chars (entry, 1);
|
||||
g_assert_cmpint (get_nchars (entry), ==, 3);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 3 * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 1);
|
||||
|
||||
clutter_entry_set_cursor_position (entry, 2);
|
||||
clutter_entry_delete_chars (entry, 1);
|
||||
g_assert_cmpint (get_nchars (entry), ==, 2);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 2 * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 1);
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_delete_text (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 4; j++)
|
||||
clutter_entry_insert_unichar (entry, t->unichar);
|
||||
|
||||
clutter_entry_set_cursor_position (entry, 3);
|
||||
clutter_entry_delete_text (entry, 2, 4);
|
||||
|
||||
g_assert_cmpint (get_nchars (entry), ==, 2);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 2 * t->nbytes);
|
||||
|
||||
/* FIXME: cursor position should be -1?
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
*/
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
static void
|
||||
init_event (ClutterKeyEvent *event)
|
||||
{
|
||||
event->type = CLUTTER_KEY_PRESS;
|
||||
event->time = 0; /* not needed */
|
||||
event->flags = CLUTTER_EVENT_FLAG_SYNTHETIC;
|
||||
event->stage = NULL; /* not needed */
|
||||
event->source = NULL; /* not needed */
|
||||
event->modifier_state = 0;
|
||||
event->hardware_keycode = 0; /* not needed */
|
||||
}
|
||||
|
||||
static void
|
||||
send_keyval (ClutterEntry *entry, int keyval)
|
||||
{
|
||||
ClutterKeyEvent event;
|
||||
|
||||
init_event (&event);
|
||||
event.keyval = keyval;
|
||||
event.unicode_value = 0; /* should be ignored for cursor keys etc. */
|
||||
|
||||
clutter_entry_handle_key_event (entry, &event);
|
||||
}
|
||||
|
||||
static inline void
|
||||
send_unichar (ClutterEntry *entry, gunichar unichar)
|
||||
{
|
||||
ClutterKeyEvent event;
|
||||
|
||||
init_event (&event);
|
||||
event.keyval = 0; /* should be ignored for printable characters */
|
||||
event.unicode_value = unichar;
|
||||
|
||||
clutter_entry_handle_key_event (entry, &event);
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_cursor (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 4; ++j)
|
||||
clutter_entry_insert_unichar (entry, t->unichar);
|
||||
|
||||
clutter_entry_set_cursor_position (entry, 2);
|
||||
|
||||
/* test cursor moves and is clamped */
|
||||
send_keyval (entry, CLUTTER_Left);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 1);
|
||||
|
||||
send_keyval (entry, CLUTTER_Left);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 0);
|
||||
|
||||
send_keyval (entry, CLUTTER_Left);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 0);
|
||||
|
||||
/* delete text containing the cursor */
|
||||
clutter_entry_set_cursor_position (entry, 3);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 3);
|
||||
|
||||
clutter_entry_delete_text (entry, 2, 4);
|
||||
send_keyval (entry, CLUTTER_Left);
|
||||
|
||||
/* FIXME: cursor position should be -1?
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
*/
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_event (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
|
||||
send_unichar (entry, t->unichar);
|
||||
|
||||
g_assert_cmpint (get_nchars (entry), ==, 1);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 1 * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
431
tests/conform/test-clutter-text.c
Normal file
431
tests/conform/test-clutter-text.c
Normal file
@ -0,0 +1,431 @@
|
||||
#include <glib.h>
|
||||
#include <clutter/clutter.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "test-conform-common.h"
|
||||
|
||||
typedef struct {
|
||||
gunichar unichar;
|
||||
const char bytes[6];
|
||||
gint nbytes;
|
||||
} TestData;
|
||||
|
||||
static const TestData
|
||||
test_text_data[] = {
|
||||
{ 0xe4, "\xc3\xa4", 2 }, /* LATIN SMALL LETTER A WITH DIAERESIS */
|
||||
{ 0x2665, "\xe2\x99\xa5", 3 } /* BLACK HEART SUIT */
|
||||
};
|
||||
|
||||
void
|
||||
test_text_utf8_validation (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
gunichar unichar;
|
||||
char bytes[6];
|
||||
int nbytes;
|
||||
|
||||
g_assert (g_unichar_validate (t->unichar));
|
||||
|
||||
nbytes = g_unichar_to_utf8 (t->unichar, bytes);
|
||||
bytes[nbytes] = '\0';
|
||||
g_assert (nbytes == t->nbytes);
|
||||
g_assert (memcmp (t->bytes, bytes, nbytes) == 0);
|
||||
|
||||
unichar = g_utf8_get_char_validated (bytes, nbytes);
|
||||
g_assert (unichar == t->unichar);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
get_nbytes (ClutterText *text)
|
||||
{
|
||||
const char *s = clutter_text_get_text (text);
|
||||
return strlen (s);
|
||||
}
|
||||
|
||||
static int
|
||||
get_nchars (ClutterText *text)
|
||||
{
|
||||
const char *s = clutter_text_get_text (text);
|
||||
g_assert (g_utf8_validate (s, -1, NULL));
|
||||
return g_utf8_strlen (s, -1);
|
||||
}
|
||||
|
||||
#define DONT_MOVE_CURSOR (-2)
|
||||
|
||||
static void
|
||||
insert_unichar (ClutterText *text, gunichar unichar, int position)
|
||||
{
|
||||
if (position > DONT_MOVE_CURSOR)
|
||||
{
|
||||
clutter_text_set_cursor_position (text, position);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, position);
|
||||
}
|
||||
|
||||
clutter_text_insert_unichar (text, unichar);
|
||||
}
|
||||
|
||||
void
|
||||
test_text_empty (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
|
||||
g_assert_cmpstr (clutter_text_get_text (text), ==, "");
|
||||
g_assert_cmpint (*clutter_text_get_text (text), ==, '\0');
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_set_empty (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
|
||||
/* annoyingly slightly different from initially empty */
|
||||
clutter_text_set_text (text, "");
|
||||
g_assert_cmpint (get_nchars (text), ==, 0);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 0);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_set_text (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
|
||||
clutter_text_set_text (text, "abcdef");
|
||||
g_assert_cmpint (get_nchars (text), ==, 6);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 6);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
|
||||
clutter_text_set_cursor_position (text, 5);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 5);
|
||||
|
||||
/* FIXME: cursor position should be -1?
|
||||
clutter_text_set_text (text, "");
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
*/
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_append_some (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 1; j <= 4; j++)
|
||||
{
|
||||
insert_unichar (text, t->unichar, DONT_MOVE_CURSOR);
|
||||
|
||||
g_assert_cmpint (get_nchars (text), ==, j);
|
||||
g_assert_cmpint (get_nbytes (text), ==, j * t->nbytes);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
}
|
||||
|
||||
clutter_text_set_text (text, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_prepend_some (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
int j;
|
||||
|
||||
clutter_text_insert_unichar (text, t->unichar);
|
||||
|
||||
g_assert_cmpint (get_nchars (text), ==, 1);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 1 * t->nbytes);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
|
||||
for (j = 2; j <= 4; j++)
|
||||
{
|
||||
insert_unichar (text, t->unichar, 0);
|
||||
|
||||
g_assert_cmpint (get_nchars (text), ==, j);
|
||||
g_assert_cmpint (get_nbytes (text), ==, j * t->nbytes);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1);
|
||||
}
|
||||
|
||||
clutter_text_set_text (text, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_insert (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
|
||||
clutter_text_insert_unichar (text, t->unichar);
|
||||
clutter_text_insert_unichar (text, t->unichar);
|
||||
|
||||
insert_unichar (text, t->unichar, 1);
|
||||
|
||||
g_assert_cmpint (get_nchars (text), ==, 3);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 3 * t->nbytes);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 2);
|
||||
|
||||
clutter_text_set_text (text, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_delete_chars (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 4; j++)
|
||||
clutter_text_insert_unichar (text, t->unichar);
|
||||
|
||||
clutter_text_set_cursor_position (text, 2);
|
||||
clutter_text_delete_chars (text, 1);
|
||||
g_assert_cmpint (get_nchars (text), ==, 3);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 3 * t->nbytes);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1);
|
||||
|
||||
clutter_text_set_cursor_position (text, 2);
|
||||
clutter_text_delete_chars (text, 1);
|
||||
g_assert_cmpint (get_nchars (text), ==, 2);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 2 * t->nbytes);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1);
|
||||
|
||||
clutter_text_set_text (text, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_get_chars (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
gchar *chars;
|
||||
|
||||
clutter_text_set_text (text, "00abcdef11");
|
||||
g_assert_cmpint (get_nchars (text), ==, 10);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 10);
|
||||
g_assert_cmpstr (clutter_text_get_text (text), ==, "00abcdef11");
|
||||
|
||||
chars = clutter_text_get_chars (text, 2, -1);
|
||||
g_assert_cmpstr (chars, ==, "abcdef11");
|
||||
g_free (chars);
|
||||
|
||||
chars = clutter_text_get_chars (text, 0, 8);
|
||||
g_assert_cmpstr (chars, ==, "00abcdef");
|
||||
g_free (chars);
|
||||
|
||||
chars = clutter_text_get_chars (text, 2, 8);
|
||||
g_assert_cmpstr (chars, ==, "abcdef");
|
||||
g_free (chars);
|
||||
|
||||
chars = clutter_text_get_chars (text, 8, 12);
|
||||
g_assert_cmpstr (chars, ==, "11");
|
||||
g_free (chars);
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_delete_text (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 4; j++)
|
||||
clutter_text_insert_unichar (text, t->unichar);
|
||||
|
||||
clutter_text_set_cursor_position (text, 3);
|
||||
clutter_text_delete_text (text, 2, 4);
|
||||
|
||||
g_assert_cmpint (get_nchars (text), ==, 2);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 2 * t->nbytes);
|
||||
|
||||
/* FIXME: cursor position should be -1?
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
*/
|
||||
|
||||
clutter_text_set_text (text, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_password_char (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
|
||||
g_assert_cmpint (clutter_text_get_password_char (text), ==, 0);
|
||||
|
||||
clutter_text_set_text (text, "hello");
|
||||
g_assert_cmpstr (clutter_text_get_text (text), ==, "hello");
|
||||
|
||||
clutter_text_set_password_char (text, '*');
|
||||
g_assert_cmpint (clutter_text_get_password_char (text), ==, '*');
|
||||
|
||||
g_assert_cmpstr (clutter_text_get_text (text), ==, "hello");
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
static void
|
||||
init_event (ClutterKeyEvent *event)
|
||||
{
|
||||
event->type = CLUTTER_KEY_PRESS;
|
||||
event->time = 0; /* not needed */
|
||||
event->flags = CLUTTER_EVENT_FLAG_SYNTHETIC;
|
||||
event->stage = NULL; /* not needed */
|
||||
event->source = NULL; /* not needed */
|
||||
event->modifier_state = 0;
|
||||
event->hardware_keycode = 0; /* not needed */
|
||||
}
|
||||
|
||||
static void
|
||||
send_keyval (ClutterText *text, int keyval)
|
||||
{
|
||||
ClutterKeyEvent event;
|
||||
|
||||
init_event (&event);
|
||||
event.keyval = keyval;
|
||||
event.unicode_value = 0; /* should be ignored for cursor keys etc. */
|
||||
|
||||
clutter_actor_event (CLUTTER_ACTOR (text), (ClutterEvent *) &event, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
send_unichar (ClutterText *text, gunichar unichar)
|
||||
{
|
||||
ClutterKeyEvent event;
|
||||
|
||||
init_event (&event);
|
||||
event.keyval = 0; /* should be ignored for printable characters */
|
||||
event.unicode_value = unichar;
|
||||
|
||||
clutter_actor_event (CLUTTER_ACTOR (text), (ClutterEvent *) &event, FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
test_text_cursor (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
int i;
|
||||
|
||||
/* only editable entries listen to events */
|
||||
clutter_text_set_editable (text, TRUE);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 4; ++j)
|
||||
clutter_text_insert_unichar (text, t->unichar);
|
||||
|
||||
clutter_text_set_cursor_position (text, 2);
|
||||
|
||||
/* test cursor moves and is clamped */
|
||||
send_keyval (text, CLUTTER_Left);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1);
|
||||
|
||||
send_keyval (text, CLUTTER_Left);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 0);
|
||||
|
||||
send_keyval (text, CLUTTER_Left);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 0);
|
||||
|
||||
/* delete text containing the cursor */
|
||||
clutter_text_set_cursor_position (text, 3);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 3);
|
||||
|
||||
clutter_text_delete_text (text, 2, 4);
|
||||
send_keyval (text, CLUTTER_Left);
|
||||
|
||||
/* FIXME: cursor position should be -1?
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
*/
|
||||
|
||||
clutter_text_set_text (text, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_event (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
int i;
|
||||
|
||||
/* only editable entries listen to events */
|
||||
clutter_text_set_editable (text, TRUE);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
|
||||
send_unichar (text, t->unichar);
|
||||
|
||||
g_assert_cmpint (get_nchars (text), ==, 1);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 1 * t->nbytes);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
|
||||
clutter_text_set_text (text, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
@ -68,22 +68,21 @@ main (int argc, char **argv)
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/picking", test_pick);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/label", test_label_cache);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_utf8_validation);
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_empty);
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_set_empty);
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_set_text);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_append_some);
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_prepend_some);
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_insert);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_delete_chars);
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_delete_text);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_cursor);
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_event);
|
||||
/* ClutterText */
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_utf8_validation);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_empty);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_set_empty);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_set_text);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_append_some);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_prepend_some);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_insert);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_delete_chars);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_delete_text);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_cursor);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_event);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_get_chars);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_cache);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_password_char);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/rectangle", test_rect_set_size);
|
||||
TEST_CONFORM_SIMPLE ("/rectangle", test_rect_set_color);
|
||||
|
@ -14,12 +14,12 @@ test_label_opacity (TestConformSimpleFixture *fixture,
|
||||
|
||||
stage = clutter_stage_get_default ();
|
||||
|
||||
label = clutter_label_new_with_text ("Sans 18px", "Label, 50% opacity");
|
||||
clutter_label_set_color (CLUTTER_LABEL (label), &label_color);
|
||||
label = clutter_text_new_with_text ("Sans 18px", "Label, 50% opacity");
|
||||
clutter_text_set_color (CLUTTER_TEXT (label), &label_color);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("label 50%%.get_color()/1\n");
|
||||
clutter_label_get_color (CLUTTER_LABEL (label), &color_check);
|
||||
clutter_text_get_color (CLUTTER_TEXT (label), &color_check);
|
||||
g_assert (color_check.alpha == label_color.alpha);
|
||||
|
||||
clutter_container_add (CLUTTER_CONTAINER (stage), label, NULL);
|
||||
@ -27,12 +27,16 @@ test_label_opacity (TestConformSimpleFixture *fixture,
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("label 50%%.get_color()/2\n");
|
||||
clutter_label_get_color (CLUTTER_LABEL (label), &color_check);
|
||||
clutter_text_get_color (CLUTTER_TEXT (label), &color_check);
|
||||
g_assert (color_check.alpha == label_color.alpha);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("label 50%%.get_paint_opacity() = %d\n",
|
||||
clutter_actor_get_paint_opacity (label));
|
||||
g_print ("label 50%%.get_paint_opacity()/1\n");
|
||||
g_assert (clutter_actor_get_paint_opacity (label) == 255);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("label 50%%.get_paint_opacity()/2\n");
|
||||
clutter_actor_set_opacity (label, 128);
|
||||
g_assert (clutter_actor_get_paint_opacity (label) == 128);
|
||||
|
||||
clutter_actor_destroy (label);
|
||||
@ -66,8 +70,7 @@ test_rectangle_opacity (TestConformSimpleFixture *fixture,
|
||||
g_assert (color_check.alpha == rect_color.alpha);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("rect 100%%.get_paint_opacity() = %d\n",
|
||||
clutter_actor_get_paint_opacity (rect));
|
||||
g_print ("rect 100%%.get_paint_opacity()\n");
|
||||
g_assert (clutter_actor_get_paint_opacity (rect) == 255);
|
||||
|
||||
clutter_actor_destroy (rect);
|
||||
@ -91,25 +94,24 @@ test_paint_opacity (TestConformSimpleFixture *fixture,
|
||||
clutter_actor_set_position (group1, 10, 30);
|
||||
clutter_actor_show (group1);
|
||||
|
||||
label = clutter_label_new_with_text ("Sans 18px", "Label+Group, 25% opacity");
|
||||
clutter_label_set_color (CLUTTER_LABEL (label), &label_color);
|
||||
label = clutter_text_new_with_text ("Sans 18px", "Label+Group, 25% opacity");
|
||||
clutter_text_set_color (CLUTTER_TEXT (label), &label_color);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("label 50%% + group 50%%.get_color()/1\n");
|
||||
clutter_label_get_color (CLUTTER_LABEL (label), &color_check);
|
||||
clutter_text_get_color (CLUTTER_TEXT (label), &color_check);
|
||||
g_assert (color_check.alpha == label_color.alpha);
|
||||
|
||||
clutter_container_add (CLUTTER_CONTAINER (group1), label, NULL);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("label 50%% + group 50%%.get_color()/2\n");
|
||||
clutter_label_get_color (CLUTTER_LABEL (label), &color_check);
|
||||
clutter_text_get_color (CLUTTER_TEXT (label), &color_check);
|
||||
g_assert (color_check.alpha == label_color.alpha);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("label 50%% + group 50%%.get_paint_opacity() = %d\n",
|
||||
clutter_actor_get_paint_opacity (label));
|
||||
g_assert (clutter_actor_get_paint_opacity (label) == 64);
|
||||
g_print ("label 50%% + group 50%%.get_paint_opacity() = 128\n");
|
||||
g_assert (clutter_actor_get_paint_opacity (label) == 128);
|
||||
|
||||
clutter_actor_destroy (label);
|
||||
|
||||
@ -133,9 +135,7 @@ test_paint_opacity (TestConformSimpleFixture *fixture,
|
||||
g_assert (color_check.alpha == rect_color.alpha);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("rect 100%%.get_paint_opacity() = %d\n",
|
||||
clutter_actor_get_paint_opacity (rect));
|
||||
|
||||
g_print ("rect 100%%.get_paint_opacity()\n");
|
||||
g_assert (clutter_actor_get_paint_opacity (rect) == 128);
|
||||
|
||||
clutter_actor_destroy (rect);
|
||||
|
@ -34,7 +34,7 @@ on_paint (ClutterActor *label, CallbackData *data)
|
||||
|
||||
/* Check whether the layout used for this paint is different from
|
||||
the layout used for the last paint */
|
||||
new_layout = clutter_label_get_layout (CLUTTER_LABEL (data->label));
|
||||
new_layout = clutter_text_get_layout (CLUTTER_TEXT (data->label));
|
||||
data->layout_changed = data->old_layout != new_layout;
|
||||
|
||||
if (data->old_layout)
|
||||
@ -71,7 +71,17 @@ check_result (CallbackData *data, const char *note,
|
||||
if (memcmp (&test_extents, &data->label_extents, sizeof (PangoRectangle)))
|
||||
{
|
||||
if (g_test_verbose ())
|
||||
g_print ("extents are different, ");
|
||||
g_print ("extents are different: expected: %d, %d, %d, %d "
|
||||
"-> text: %d, %d, %d, %d\n",
|
||||
test_extents.x / 1024,
|
||||
test_extents.y / 1024,
|
||||
test_extents.width / 1024,
|
||||
test_extents.height / 1024,
|
||||
data->label_extents.x / 1024,
|
||||
data->label_extents.y / 1024,
|
||||
data->label_extents.width / 1024,
|
||||
data->label_extents.height / 1024);
|
||||
|
||||
fail = TRUE;
|
||||
}
|
||||
else
|
||||
@ -119,29 +129,29 @@ do_tests (CallbackData *data)
|
||||
PangoAttribute *attr;
|
||||
|
||||
/* TEST 1: change the text */
|
||||
clutter_label_set_text (CLUTTER_LABEL (data->label), "Counter 0");
|
||||
clutter_text_set_text (CLUTTER_TEXT (data->label), "Counter 0");
|
||||
pango_layout_set_text (data->test_layout, "Counter 0", -1);
|
||||
check_result (data, "Change text", TRUE);
|
||||
g_assert (check_result (data, "Change text", TRUE) == FALSE);
|
||||
|
||||
/* TEST 2: change a single character */
|
||||
clutter_label_set_text (CLUTTER_LABEL (data->label), "Counter 1");
|
||||
clutter_text_set_text (CLUTTER_TEXT (data->label), "Counter 1");
|
||||
pango_layout_set_text (data->test_layout, "Counter 1", -1);
|
||||
check_result (data, "Change a single character", TRUE);
|
||||
g_assert (check_result (data, "Change a single character", TRUE) == FALSE);
|
||||
|
||||
/* TEST 3: move the label */
|
||||
clutter_actor_set_position (data->label, 10, 0);
|
||||
check_result (data, "Move the label", FALSE);
|
||||
g_assert (check_result (data, "Move the label", FALSE) == FALSE);
|
||||
|
||||
/* TEST 4: change the font */
|
||||
clutter_label_set_font_name (CLUTTER_LABEL (data->label), "Serif 15");
|
||||
clutter_text_set_font_name (CLUTTER_TEXT (data->label), "Serif 15");
|
||||
fd = pango_font_description_from_string ("Serif 15");
|
||||
pango_layout_set_font_description (data->test_layout, fd);
|
||||
pango_font_description_free (fd);
|
||||
check_result (data, "Change the font", TRUE);
|
||||
g_assert (check_result (data, "Change the font", TRUE) == FALSE);
|
||||
|
||||
/* TEST 5: change the color */
|
||||
clutter_label_set_color (CLUTTER_LABEL (data->label), &red);
|
||||
check_result (data, "Change the color", FALSE);
|
||||
clutter_text_set_color (CLUTTER_TEXT (data->label), &red);
|
||||
g_assert (check_result (data, "Change the color", FALSE) == FALSE);
|
||||
|
||||
/* TEST 6: change the attributes */
|
||||
attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
|
||||
@ -150,23 +160,23 @@ do_tests (CallbackData *data)
|
||||
attr_list = pango_attr_list_new ();
|
||||
pango_attr_list_insert (attr_list, attr);
|
||||
attr_list_copy = pango_attr_list_copy (attr_list);
|
||||
clutter_label_set_attributes (CLUTTER_LABEL (data->label), attr_list);
|
||||
clutter_text_set_attributes (CLUTTER_TEXT (data->label), attr_list);
|
||||
pango_layout_set_attributes (data->test_layout, attr_list_copy);
|
||||
pango_attr_list_unref (attr_list_copy);
|
||||
pango_attr_list_unref (attr_list);
|
||||
check_result (data, "Change the attributes", TRUE);
|
||||
g_assert (check_result (data, "Change the attributes", TRUE) == FALSE);
|
||||
|
||||
/* TEST 7: change the text again */
|
||||
clutter_label_set_attributes (CLUTTER_LABEL (data->label), NULL);
|
||||
clutter_label_set_text (CLUTTER_LABEL (data->label), long_text);
|
||||
clutter_text_set_attributes (CLUTTER_TEXT (data->label), NULL);
|
||||
clutter_text_set_text (CLUTTER_TEXT (data->label), long_text);
|
||||
pango_layout_set_attributes (data->test_layout, NULL);
|
||||
pango_layout_set_text (data->test_layout, long_text, -1);
|
||||
check_result (data, "Change the text again", TRUE);
|
||||
g_assert (check_result (data, "Change the text again", TRUE) == FALSE);
|
||||
|
||||
/* TEST 8: enable markup */
|
||||
clutter_label_set_use_markup (CLUTTER_LABEL (data->label), TRUE);
|
||||
clutter_text_set_use_markup (CLUTTER_TEXT (data->label), TRUE);
|
||||
pango_layout_set_markup (data->test_layout, long_text, -1);
|
||||
check_result (data, "Enable markup", TRUE);
|
||||
g_assert (check_result (data, "Enable markup", TRUE) == FALSE);
|
||||
|
||||
/* This part can't be a test because Clutter won't restrict the
|
||||
width if wrapping and ellipsizing is disabled so the extents will
|
||||
@ -178,39 +188,39 @@ do_tests (CallbackData *data)
|
||||
force_redraw (data);
|
||||
|
||||
/* TEST 9: enable ellipsize */
|
||||
clutter_label_set_ellipsize (CLUTTER_LABEL (data->label),
|
||||
clutter_text_set_ellipsize (CLUTTER_TEXT (data->label),
|
||||
PANGO_ELLIPSIZE_END);
|
||||
pango_layout_set_ellipsize (data->test_layout, PANGO_ELLIPSIZE_END);
|
||||
check_result (data, "Enable ellipsize", TRUE);
|
||||
clutter_label_set_ellipsize (CLUTTER_LABEL (data->label),
|
||||
g_assert (check_result (data, "Enable ellipsize", TRUE) == FALSE);
|
||||
clutter_text_set_ellipsize (CLUTTER_TEXT (data->label),
|
||||
PANGO_ELLIPSIZE_NONE);
|
||||
pango_layout_set_ellipsize (data->test_layout, PANGO_ELLIPSIZE_NONE);
|
||||
force_redraw (data);
|
||||
|
||||
/* TEST 10: enable line wrap */
|
||||
clutter_label_set_line_wrap (CLUTTER_LABEL (data->label), TRUE);
|
||||
clutter_text_set_line_wrap (CLUTTER_TEXT (data->label), TRUE);
|
||||
pango_layout_set_wrap (data->test_layout, PANGO_WRAP_WORD);
|
||||
check_result (data, "Enable line wrap", TRUE);
|
||||
g_assert (check_result (data, "Enable line wrap", TRUE) == FALSE);
|
||||
|
||||
/* TEST 11: change wrap mode */
|
||||
clutter_label_set_line_wrap_mode (CLUTTER_LABEL (data->label),
|
||||
clutter_text_set_line_wrap_mode (CLUTTER_TEXT (data->label),
|
||||
PANGO_WRAP_CHAR);
|
||||
pango_layout_set_wrap (data->test_layout, PANGO_WRAP_CHAR);
|
||||
check_result (data, "Change wrap mode", TRUE);
|
||||
g_assert (check_result (data, "Change wrap mode", TRUE) == FALSE);
|
||||
|
||||
/* TEST 12: enable justify */
|
||||
clutter_label_set_justify (CLUTTER_LABEL (data->label), TRUE);
|
||||
clutter_text_set_justify (CLUTTER_TEXT (data->label), TRUE);
|
||||
pango_layout_set_justify (data->test_layout, TRUE);
|
||||
/* Pango appears to have a bug which means that you can't change the
|
||||
justification after setting the text but this fixes it.
|
||||
See http://bugzilla.gnome.org/show_bug.cgi?id=551865 */
|
||||
pango_layout_context_changed (data->test_layout);
|
||||
check_result (data, "Enable justify", TRUE);
|
||||
g_assert (check_result (data, "Enable justify", TRUE) == FALSE);
|
||||
|
||||
/* TEST 13: change alignment */
|
||||
clutter_label_set_alignment (CLUTTER_LABEL (data->label), PANGO_ALIGN_RIGHT);
|
||||
clutter_text_set_alignment (CLUTTER_TEXT (data->label), PANGO_ALIGN_RIGHT);
|
||||
pango_layout_set_alignment (data->test_layout, PANGO_ALIGN_RIGHT);
|
||||
check_result (data, "Change alignment", TRUE);
|
||||
g_assert (check_result (data, "Change alignment", TRUE) == FALSE);
|
||||
|
||||
clutter_main_quit ();
|
||||
|
||||
@ -218,7 +228,7 @@ do_tests (CallbackData *data)
|
||||
}
|
||||
|
||||
static PangoLayout *
|
||||
make_layout_like_label (ClutterLabel *label)
|
||||
make_layout_like_label (ClutterText *label)
|
||||
{
|
||||
PangoLayout *label_layout, *new_layout;
|
||||
PangoContext *context;
|
||||
@ -226,7 +236,7 @@ make_layout_like_label (ClutterLabel *label)
|
||||
|
||||
/* Make another layout using the same context as the layout from the
|
||||
label */
|
||||
label_layout = clutter_label_get_layout (label);
|
||||
label_layout = clutter_text_get_layout (label);
|
||||
context = pango_layout_get_context (label_layout);
|
||||
new_layout = pango_layout_new (context);
|
||||
fd = pango_font_description_from_string (TEST_FONT);
|
||||
@ -237,7 +247,7 @@ make_layout_like_label (ClutterLabel *label)
|
||||
}
|
||||
|
||||
void
|
||||
test_label_cache (TestConformSimpleFixture *fixture,
|
||||
test_text_cache (TestConformSimpleFixture *fixture,
|
||||
gconstpointer _data)
|
||||
{
|
||||
CallbackData data;
|
||||
@ -246,9 +256,9 @@ test_label_cache (TestConformSimpleFixture *fixture,
|
||||
|
||||
data.stage = clutter_stage_get_default ();
|
||||
|
||||
data.label = clutter_label_new_with_text (TEST_FONT, "");
|
||||
data.label = clutter_text_new_with_text (TEST_FONT, "");
|
||||
|
||||
data.test_layout = make_layout_like_label (CLUTTER_LABEL (data.label));
|
||||
data.test_layout = make_layout_like_label (CLUTTER_TEXT (data.label));
|
||||
|
||||
g_signal_connect (data.label, "paint", G_CALLBACK (on_paint), &data);
|
||||
|
@ -6,7 +6,6 @@ UNIT_TESTS = \
|
||||
test-scale.c \
|
||||
test-actors.c \
|
||||
test-behave.c \
|
||||
test-entry.c \
|
||||
test-project.c \
|
||||
test-perspective.c \
|
||||
test-rotate.c \
|
||||
@ -39,7 +38,9 @@ UNIT_TESTS = \
|
||||
test-layout.c \
|
||||
test-animation.c \
|
||||
test-easing.c \
|
||||
test-binding-pool.c
|
||||
test-binding-pool.c \
|
||||
test-text.c \
|
||||
test-text-field.c
|
||||
|
||||
if X11_TESTS
|
||||
UNIT_TESTS += test-pixmap.c
|
||||
|
@ -305,8 +305,8 @@ test_clip_main (int argc, char **argv)
|
||||
data.hand = cogl_texture_new_from_file ("redhand.png", 64, FALSE,
|
||||
COGL_PIXEL_FORMAT_ANY, NULL);
|
||||
|
||||
label = clutter_label_new_with_text ("Sans 12px", instructions);
|
||||
clutter_label_set_line_wrap (CLUTTER_LABEL (label), TRUE);
|
||||
label = clutter_text_new_with_text ("Sans 12px", instructions);
|
||||
clutter_text_set_line_wrap (CLUTTER_TEXT (label), TRUE);
|
||||
clutter_actor_set_width (label, clutter_actor_get_width (data.stage) - 310);
|
||||
clutter_actor_set_y (label,
|
||||
clutter_actor_get_height (data.stage)
|
||||
|
@ -297,16 +297,16 @@ frame_cb (ClutterTimeline *timeline,
|
||||
}
|
||||
|
||||
static void
|
||||
update_toggle_text (ClutterLabel *button, gboolean val)
|
||||
update_toggle_text (ClutterText *button, gboolean val)
|
||||
{
|
||||
clutter_label_set_text (button, val ? "Enabled" : "Disabled");
|
||||
clutter_text_set_text (button, val ? "Enabled" : "Disabled");
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_toggle_click (ClutterActor *button, ClutterEvent *event,
|
||||
gboolean *toggle_val)
|
||||
{
|
||||
update_toggle_text (CLUTTER_LABEL (button), *toggle_val = !*toggle_val);
|
||||
update_toggle_text (CLUTTER_TEXT (button), *toggle_val = !*toggle_val);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -315,12 +315,12 @@ static ClutterActor *
|
||||
make_toggle (const char *label_text, gboolean *toggle_val)
|
||||
{
|
||||
ClutterActor *group = clutter_group_new ();
|
||||
ClutterActor *label = clutter_label_new_with_text ("Sans 14", label_text);
|
||||
ClutterActor *button = clutter_label_new_with_text ("Sans 14", "");
|
||||
ClutterActor *label = clutter_text_new_with_text ("Sans 14", label_text);
|
||||
ClutterActor *button = clutter_text_new_with_text ("Sans 14", "");
|
||||
|
||||
clutter_actor_set_reactive (button, TRUE);
|
||||
|
||||
update_toggle_text (CLUTTER_LABEL (button), *toggle_val);
|
||||
update_toggle_text (CLUTTER_TEXT (button), *toggle_val);
|
||||
|
||||
clutter_actor_set_position (button, clutter_actor_get_width (label) + 10, 0);
|
||||
clutter_container_add (CLUTTER_CONTAINER (group), label, button, NULL);
|
||||
@ -373,7 +373,7 @@ test_cogl_tex_polygon_main (int argc, char *argv[])
|
||||
clutter_actor_set_position (filtering_toggle, 0,
|
||||
clutter_actor_get_y (slicing_toggle)
|
||||
- clutter_actor_get_height (filtering_toggle));
|
||||
note = clutter_label_new_with_text ("Sans 10", "<- Click to change");
|
||||
note = clutter_text_new_with_text ("Sans 10", "<- Click to change");
|
||||
clutter_actor_set_position (note,
|
||||
clutter_actor_get_width (filtering_toggle) + 10,
|
||||
(clutter_actor_get_height (stage)
|
||||
|
@ -83,10 +83,10 @@ janus_group (const gchar *front_text,
|
||||
|
||||
group = clutter_group_new ();
|
||||
rectangle = clutter_rectangle_new_with_color (&slide_color);
|
||||
front = clutter_label_new_with_text ("Sans 50px", front_text);
|
||||
back = clutter_label_new_with_text ("Sans 50px", back_text);
|
||||
clutter_label_set_color (CLUTTER_LABEL (front), &red);
|
||||
clutter_label_set_color (CLUTTER_LABEL (back), &green);
|
||||
front = clutter_text_new_with_text ("Sans 50px", front_text);
|
||||
back = clutter_text_new_with_text ("Sans 50px", back_text);
|
||||
clutter_text_set_color (CLUTTER_TEXT (front), &red);
|
||||
clutter_text_set_color (CLUTTER_TEXT (back), &green);
|
||||
|
||||
clutter_actor_get_size (front, &width, &height);
|
||||
clutter_actor_get_size (back, &width2, &height2);
|
||||
@ -134,7 +134,7 @@ test_depth_main (int argc, char *argv[])
|
||||
clutter_stage_add (stage, group);
|
||||
clutter_actor_show (group);
|
||||
|
||||
label = clutter_label_new_with_text ("Mono 26", "Clutter");
|
||||
label = clutter_text_new_with_text ("Mono 26", "Clutter");
|
||||
clutter_actor_set_position (label, 120, 200);
|
||||
clutter_actor_show (label);
|
||||
|
||||
|
@ -41,7 +41,7 @@ on_button_press (ClutterActor *actor,
|
||||
current_mode + 1,
|
||||
n_easing_modes);
|
||||
|
||||
clutter_label_set_text (CLUTTER_LABEL (easing_mode_label), text);
|
||||
clutter_text_set_text (CLUTTER_TEXT (easing_mode_label), text);
|
||||
g_free (text);
|
||||
|
||||
clutter_actor_get_size (main_stage, &stage_width, &stage_height);
|
||||
@ -97,10 +97,10 @@ test_easing_main (int argc, char *argv[])
|
||||
current_mode + 1,
|
||||
n_easing_modes);
|
||||
|
||||
label = clutter_label_new ();
|
||||
label = clutter_text_new ();
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), label);
|
||||
clutter_label_set_font_name (CLUTTER_LABEL (label), "Sans 18px");
|
||||
clutter_label_set_text (CLUTTER_LABEL (label), text);
|
||||
clutter_text_set_font_name (CLUTTER_TEXT (label), "Sans 18px");
|
||||
clutter_text_set_text (CLUTTER_TEXT (label), text);
|
||||
clutter_actor_get_size (label, &label_width, &label_height);
|
||||
clutter_actor_set_position (label,
|
||||
stage_width - label_width - 10,
|
||||
|
@ -43,9 +43,9 @@ make_source(void)
|
||||
|
||||
clutter_group_add (source, actor);
|
||||
|
||||
actor = clutter_label_new_with_text ("Sans Bold 50px", "Clutter");
|
||||
actor = clutter_text_new_with_text ("Sans Bold 50px", "Clutter");
|
||||
|
||||
clutter_label_set_color (CLUTTER_LABEL (actor), &yellow);
|
||||
clutter_text_set_color (CLUTTER_TEXT (actor), &yellow);
|
||||
clutter_actor_set_y (actor, clutter_actor_get_height(source) + 5);
|
||||
clutter_group_add (source, actor);
|
||||
|
||||
|
@ -787,7 +787,7 @@ test_layout_main (int argc, char *argv[])
|
||||
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
|
||||
|
||||
instructions = clutter_label_new_with_text ("Sans 14",
|
||||
instructions = clutter_text_new_with_text ("Sans 14",
|
||||
"<b>Instructions:</b>\n"
|
||||
"a - add a new item\n"
|
||||
"d - remove last item\n"
|
||||
@ -799,7 +799,7 @@ test_layout_main (int argc, char *argv[])
|
||||
"s - use transformed box\n"
|
||||
"q - quit");
|
||||
|
||||
clutter_label_set_use_markup (CLUTTER_LABEL (instructions), TRUE);
|
||||
clutter_text_set_use_markup (CLUTTER_TEXT (instructions), TRUE);
|
||||
clutter_actor_set_position (instructions, 450, 10);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), instructions);
|
||||
|
||||
|
@ -50,10 +50,10 @@ on_button_press (ClutterActor *actor,
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (new_stage), tex);
|
||||
|
||||
stage_label = g_strdup_printf ("<b>Stage: %d</b>", ++n_stages);
|
||||
label = clutter_label_new_with_text ("Mono 12", stage_label);
|
||||
label = clutter_text_new_with_text ("Mono 12", stage_label);
|
||||
|
||||
clutter_label_set_color (CLUTTER_LABEL (label), &white);
|
||||
clutter_label_set_use_markup (CLUTTER_LABEL (label), TRUE);
|
||||
clutter_text_set_color (CLUTTER_TEXT (label), &white);
|
||||
clutter_text_set_use_markup (CLUTTER_TEXT (label), TRUE);
|
||||
width = (clutter_actor_get_width (new_stage)
|
||||
- clutter_actor_get_width (label)) / 2;
|
||||
height = (clutter_actor_get_height (new_stage)
|
||||
@ -110,7 +110,7 @@ test_multistage_main (int argc, char *argv[])
|
||||
G_CALLBACK (on_button_press),
|
||||
NULL);
|
||||
|
||||
label = clutter_label_new_with_text ("Mono 16", "Default stage");
|
||||
label = clutter_text_new_with_text ("Mono 16", "Default stage");
|
||||
width = (clutter_actor_get_width (stage_default)
|
||||
- clutter_actor_get_width (label))
|
||||
/ 2;
|
||||
|
@ -224,8 +224,8 @@ test_project_main (int argc, char *argv[])
|
||||
clutter_actor_set_rotation (rect, CLUTTER_Y_AXIS, 60, 0, 0, 0);
|
||||
clutter_group_add (CLUTTER_GROUP (main_stage), rect);
|
||||
|
||||
label = clutter_label_new_with_text ("Mono 8pt", "Drag the blue rectangles");
|
||||
clutter_label_set_color (CLUTTER_LABEL (label), &white);
|
||||
label = clutter_text_new_with_text ("Mono 8pt", "Drag the blue rectangles");
|
||||
clutter_text_set_color (CLUTTER_TEXT (label), &white);
|
||||
|
||||
clutter_actor_set_position (label, 10, 10);
|
||||
clutter_group_add (CLUTTER_GROUP (main_stage), label);
|
||||
|
@ -45,7 +45,7 @@ on_idle (gpointer data)
|
||||
font_names[rand () % FONT_NAME_COUNT],
|
||||
rand () % (MAX_FONT_SIZE - MIN_FONT_SIZE) + MIN_FONT_SIZE);
|
||||
|
||||
label = clutter_label_new_with_text (font_name, text);
|
||||
label = clutter_text_new_with_text (font_name, text);
|
||||
|
||||
if (clutter_actor_get_height (label) > line_height)
|
||||
line_height = clutter_actor_get_height (label);
|
||||
|
@ -33,8 +33,8 @@ test_rotate_main (int argc, char *argv[])
|
||||
clutter_actor_show (hand);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), hand);
|
||||
|
||||
label = clutter_label_new_with_text ("Mono 16", "The Wonder of the Spinning Hand");
|
||||
clutter_label_set_alignment (CLUTTER_LABEL (label), PANGO_ALIGN_CENTER);
|
||||
label = clutter_text_new_with_text ("Mono 16", "The Wonder of the Spinning Hand");
|
||||
clutter_text_set_alignment (CLUTTER_TEXT (label), PANGO_ALIGN_CENTER);
|
||||
clutter_actor_set_position (label, 150, 150);
|
||||
clutter_actor_set_size (label, 500, 100);
|
||||
clutter_actor_show (label);
|
||||
|
@ -354,7 +354,7 @@ test_shader_main (gint argc, gchar *argv[])
|
||||
if (!child2)
|
||||
g_error("pixbuf load failed: %s", error ? error->message : "Unknown");
|
||||
child3 = clutter_rectangle_new ();
|
||||
child4 = clutter_label_new_with_text ("Sans 20px", "Shady stuff");
|
||||
child4 = clutter_text_new_with_text ("Sans 20px", "Shady stuff");
|
||||
|
||||
clutter_rectangle_set_color (child3, &color);
|
||||
clutter_actor_set_size (child3, 50, 50);
|
||||
|
@ -23,14 +23,14 @@ make_label (void)
|
||||
gchar *text;
|
||||
gchar *argv[] = { "ls", "--help", NULL };
|
||||
|
||||
label = clutter_label_new ();
|
||||
clutter_label_set_font_name (CLUTTER_LABEL (label), "Sans 10");
|
||||
label = clutter_text_new ();
|
||||
clutter_text_set_font_name (CLUTTER_TEXT (label), "Sans 10");
|
||||
|
||||
if (g_spawn_sync (NULL, argv, NULL,
|
||||
G_SPAWN_STDERR_TO_DEV_NULL | G_SPAWN_SEARCH_PATH,
|
||||
NULL, NULL, &text, NULL, NULL, NULL))
|
||||
{
|
||||
clutter_label_set_text (CLUTTER_LABEL (label), text);
|
||||
clutter_text_set_text (CLUTTER_TEXT (label), text);
|
||||
g_free (text);
|
||||
}
|
||||
|
||||
|
117
tests/interactive/test-text-field.c
Normal file
117
tests/interactive/test-text-field.c
Normal file
@ -0,0 +1,117 @@
|
||||
#include <stdlib.h>
|
||||
#include <gmodule.h>
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#define FONT "Mono Bold 14px"
|
||||
|
||||
static void
|
||||
on_entry_paint (ClutterActor *actor,
|
||||
gpointer data)
|
||||
{
|
||||
ClutterActorBox allocation = { 0, };
|
||||
ClutterUnit width, height;
|
||||
|
||||
clutter_actor_get_allocation_box (actor, &allocation);
|
||||
width = allocation.x2 - allocation.x1;
|
||||
height = allocation.y2 - allocation.y1;
|
||||
|
||||
cogl_set_source_color4ub (255, 255, 255, 255);
|
||||
cogl_path_round_rectangle (0, 0,
|
||||
CLUTTER_UNITS_TO_FIXED (width),
|
||||
CLUTTER_UNITS_TO_FIXED (height),
|
||||
COGL_FIXED_FROM_INT (4),
|
||||
COGL_ANGLE_FROM_DEG (1.0));
|
||||
cogl_path_stroke ();
|
||||
}
|
||||
|
||||
static void
|
||||
on_entry_activate (ClutterText *text,
|
||||
gpointer data)
|
||||
{
|
||||
g_print ("Text activated: %s\n", clutter_text_get_text (text));
|
||||
}
|
||||
|
||||
static ClutterActor *
|
||||
create_label (const ClutterColor *color,
|
||||
const gchar *text)
|
||||
{
|
||||
ClutterActor *retval = clutter_text_new_full (FONT, text, color);
|
||||
|
||||
clutter_text_set_editable (CLUTTER_TEXT (retval), FALSE);
|
||||
clutter_text_set_selectable (CLUTTER_TEXT (retval), FALSE);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static ClutterActor *
|
||||
create_entry (const ClutterColor *color,
|
||||
const gchar *text,
|
||||
gunichar password_char,
|
||||
gint max_length)
|
||||
{
|
||||
ClutterActor *retval = clutter_text_new_full (FONT, text, color);
|
||||
ClutterColor selection = { 0, };
|
||||
|
||||
clutter_actor_set_width (retval, 200);
|
||||
clutter_actor_set_reactive (retval, TRUE);
|
||||
|
||||
clutter_color_darken (color, &selection);
|
||||
|
||||
clutter_text_set_editable (CLUTTER_TEXT (retval), TRUE);
|
||||
clutter_text_set_selectable (CLUTTER_TEXT (retval), TRUE);
|
||||
clutter_text_set_activatable (CLUTTER_TEXT (retval), TRUE);
|
||||
clutter_text_set_single_line_mode (CLUTTER_TEXT (retval), TRUE);
|
||||
clutter_text_set_password_char (CLUTTER_TEXT (retval), password_char);
|
||||
clutter_text_set_cursor_color (CLUTTER_TEXT (retval), &selection);
|
||||
clutter_text_set_max_length (CLUTTER_TEXT (retval), max_length);
|
||||
|
||||
g_signal_connect (retval, "activate",
|
||||
G_CALLBACK (on_entry_activate),
|
||||
NULL);
|
||||
g_signal_connect (retval, "paint",
|
||||
G_CALLBACK (on_entry_paint),
|
||||
NULL);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT gint
|
||||
test_text_field_main (gint argc,
|
||||
gchar **argv)
|
||||
{
|
||||
ClutterActor *stage;
|
||||
ClutterActor *text;
|
||||
ClutterColor entry_color = {0x33, 0xff, 0x33, 0xff};
|
||||
ClutterColor label_color = {0xff, 0xff, 0xff, 0xff};
|
||||
ClutterColor background_color = {0x00, 0x00, 0x00, 0xff};
|
||||
gint height;
|
||||
|
||||
clutter_init (&argc, &argv);
|
||||
|
||||
stage = clutter_stage_get_default ();
|
||||
clutter_stage_set_color (CLUTTER_STAGE (stage), &background_color);
|
||||
|
||||
text = create_label (&label_color, "Input field: ");
|
||||
clutter_actor_set_position (text, 10, 10);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
||||
|
||||
height = clutter_actor_get_height (text);
|
||||
|
||||
text = create_entry (&entry_color, "some text", 0, 0);
|
||||
clutter_actor_set_position (text, 200, 10);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
||||
|
||||
text = create_label (&label_color, "Password field: ");
|
||||
clutter_actor_set_position (text, 10, height + 12);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
||||
|
||||
text = create_entry (&entry_color, "password", '*', 8);
|
||||
clutter_actor_set_position (text, 200, height + 12);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
||||
|
||||
clutter_actor_show (stage);
|
||||
|
||||
clutter_main ();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
179
tests/interactive/test-text.c
Normal file
179
tests/interactive/test-text.c
Normal file
@ -0,0 +1,179 @@
|
||||
/* Try this text editor, it has issues but does work,
|
||||
* try ctrl+A, ctrl+C, ctrl+V, ctrl+X as well as selecting text with
|
||||
* mouse and keyboard, /Øyvind K
|
||||
*/
|
||||
|
||||
#include <gmodule.h>
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#define FONT "Mono Bold 22px"
|
||||
|
||||
static gchar *clipboard = NULL;
|
||||
|
||||
static gchar *runes =
|
||||
"ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ\n"
|
||||
"ᛋᚳᛖᚪᛚ᛫ᚦᛖᚪᚻ᛫ᛗᚪᚾᚾᚪ᛫ᚷᛖᚻᚹᛦᛚᚳ᛫ᛗᛁᚳᛚᚢᚾ᛫ᚻᛦᛏ᛫ᛞᚫᛚᚪᚾ\n"
|
||||
"ᚷᛁᚠ᛫ᚻᛖ᛫ᚹᛁᛚᛖ᛫ᚠᚩᚱ᛫ᛞᚱᛁᚻᛏᚾᛖ᛫ᛞᚩᛗᛖᛋ᛫ᚻᛚᛇᛏᚪᚾ᛬\n";
|
||||
|
||||
|
||||
static gboolean
|
||||
select_all (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
gint len;
|
||||
len = g_utf8_strlen (clutter_text_get_text (ttext), -1);
|
||||
|
||||
clutter_text_set_cursor_position (ttext, 0);
|
||||
clutter_text_set_selection_bound (ttext, len);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
copy (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
if (clipboard)
|
||||
g_free (clipboard);
|
||||
clipboard = clutter_text_get_selection (ttext);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
paste (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
const gchar *p;
|
||||
if (!clipboard)
|
||||
return TRUE;
|
||||
|
||||
for (p=clipboard; *p!='\0'; p=g_utf8_next_char (p))
|
||||
{
|
||||
clutter_text_insert_unichar (ttext, g_utf8_get_char_validated (p, 3));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
cut (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
clutter_text_action (ttext, "copy", NULL);
|
||||
clutter_text_action (ttext, "truncate-selection", NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
pageup (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
gint i;
|
||||
for (i=0;i<10;i++)
|
||||
clutter_text_action (ttext, "move-up", event);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
pagedown (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
gint i;
|
||||
for (i=0;i<10;i++)
|
||||
clutter_text_action (ttext, "move-down", event);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
cursor_event (ClutterText *text,
|
||||
ClutterGeometry *geometry)
|
||||
{
|
||||
gint y;
|
||||
|
||||
y = clutter_actor_get_y (CLUTTER_ACTOR (text));
|
||||
|
||||
if (y + geometry->y < 50)
|
||||
{
|
||||
clutter_actor_set_y (CLUTTER_ACTOR (text), y + 100);
|
||||
}
|
||||
else if (y + geometry->y > 720)
|
||||
{
|
||||
clutter_actor_set_y (CLUTTER_ACTOR (text), y - 100);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT gint
|
||||
test_text_main (gint argc,
|
||||
gchar **argv)
|
||||
{
|
||||
ClutterActor *stage;
|
||||
ClutterActor *text;
|
||||
ClutterColor text_color = {0x33, 0xff, 0x33, 0xff};
|
||||
ClutterColor cursor_color = {0xff, 0x33, 0x33, 0xff};
|
||||
ClutterColor background_color = {0x00, 0x00, 0x00, 0xff};
|
||||
clutter_init (&argc, &argv);
|
||||
|
||||
stage = clutter_stage_get_default ();
|
||||
clutter_stage_set_color (CLUTTER_STAGE (stage), &background_color);
|
||||
|
||||
text = clutter_text_new_full (FONT, "·", &text_color);
|
||||
|
||||
clutter_container_add (CLUTTER_CONTAINER (stage), text, NULL);
|
||||
clutter_actor_set_position (text, 40, 30);
|
||||
clutter_actor_set_width (text, 1024);
|
||||
clutter_text_set_line_wrap (CLUTTER_TEXT (text), TRUE);
|
||||
|
||||
clutter_actor_set_reactive (text, TRUE);
|
||||
clutter_stage_set_key_focus (CLUTTER_STAGE (stage), text);
|
||||
|
||||
clutter_text_set_editable (CLUTTER_TEXT (text), TRUE);
|
||||
clutter_text_set_selectable (CLUTTER_TEXT (text), TRUE);
|
||||
clutter_text_set_cursor_color (CLUTTER_TEXT (text), &cursor_color);
|
||||
|
||||
#if 0
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "select-all", select_all);
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "copy", copy);
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "paste", paste);
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "cut", cut);
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "pageup", pageup);
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "pagedown", pagedown);
|
||||
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_a, CLUTTER_CONTROL_MASK, "select-all");
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_c, CLUTTER_CONTROL_MASK, "copy");
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_v, CLUTTER_CONTROL_MASK, "paste");
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_x, CLUTTER_CONTROL_MASK, "cut");
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_Page_Up, 0, "pageup");
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_Page_Down, 0, "pagedown");
|
||||
#endif
|
||||
|
||||
if (argv[1])
|
||||
{
|
||||
gchar *utf8;
|
||||
g_file_get_contents (argv[1], &utf8, NULL, NULL);
|
||||
clutter_text_set_text (CLUTTER_TEXT (text), utf8);
|
||||
}
|
||||
else
|
||||
{
|
||||
clutter_text_set_text (CLUTTER_TEXT (text), runes);
|
||||
}
|
||||
|
||||
g_signal_connect (text, "cursor-event", G_CALLBACK (cursor_event), NULL);
|
||||
|
||||
clutter_actor_set_size (stage, 1024, 768);
|
||||
clutter_actor_show (stage);
|
||||
|
||||
clutter_main ();
|
||||
return 0;
|
||||
}
|
@ -42,7 +42,7 @@ test_thread_done_idle (gpointer user_data)
|
||||
|
||||
g_print ("Thread completed\n");
|
||||
|
||||
clutter_label_set_text (CLUTTER_LABEL (data->label), "Completed");
|
||||
clutter_text_set_text (CLUTTER_TEXT (data->label), "Completed");
|
||||
clutter_timeline_stop (data->timeline);
|
||||
|
||||
test_thread_data_free (data);
|
||||
@ -67,7 +67,7 @@ update_label_idle (gpointer data)
|
||||
|
||||
text = g_strdup_printf ("Count to %d", update->count);
|
||||
|
||||
clutter_label_set_text (CLUTTER_LABEL (update->thread_data->label), text);
|
||||
clutter_text_set_text (CLUTTER_TEXT (update->thread_data->label), text);
|
||||
clutter_actor_set_width (update->thread_data->label, -1);
|
||||
|
||||
if (update->count == 0)
|
||||
@ -151,7 +151,7 @@ on_key_press_event (ClutterStage *stage,
|
||||
switch (clutter_key_event_symbol (event))
|
||||
{
|
||||
case CLUTTER_s:
|
||||
clutter_label_set_text (CLUTTER_LABEL (help_label), "Press 'q' to quit");
|
||||
clutter_text_set_text (CLUTTER_TEXT (help_label), "Press 'q' to quit");
|
||||
|
||||
clutter_timeline_start (timeline);
|
||||
|
||||
@ -191,10 +191,10 @@ test_threads_main (int argc, char *argv[])
|
||||
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
|
||||
clutter_actor_set_size (stage, 600, 300);
|
||||
|
||||
count_label = clutter_label_new_with_text ("Mono 12", "Counter");
|
||||
count_label = clutter_text_new_with_text ("Mono 12", "Counter");
|
||||
clutter_actor_set_position (count_label, 350, 50);
|
||||
|
||||
help_label = clutter_label_new_with_text ("Mono 12", "Press 's' to start");
|
||||
help_label = clutter_text_new_with_text ("Mono 12", "Press 's' to start");
|
||||
clutter_actor_set_position (help_label, 50, 50);
|
||||
|
||||
rect = clutter_rectangle_new_with_color (&rect_color);
|
||||
|
@ -53,12 +53,11 @@ on_event (ClutterStage *stage,
|
||||
CLUTTER_UNITS_TO_DEVICE (xu2),
|
||||
CLUTTER_UNITS_TO_DEVICE (yu2));
|
||||
|
||||
clutter_label_set_text (CLUTTER_LABEL (label), txt);
|
||||
clutter_text_set_text (CLUTTER_TEXT (label), txt);
|
||||
g_free (txt);
|
||||
}
|
||||
else
|
||||
clutter_label_set_text (CLUTTER_LABEL (label),
|
||||
"Unprojection failed.");
|
||||
clutter_text_set_text (CLUTTER_TEXT (label), "Unprojection failed.");
|
||||
}
|
||||
break;
|
||||
|
||||
@ -78,7 +77,7 @@ test_unproject_main (int argc, char *argv[])
|
||||
int i, rotate_x = 0, rotate_y = 60, rotate_z = 0;
|
||||
ClutterColor stage_clr = { 0x0, 0x0, 0x0, 0xff },
|
||||
white = { 0xff, 0xff, 0xff, 0xff },
|
||||
blue = { 0, 0xff, 0xff, 0xff };
|
||||
blue = { 0x0, 0xff, 0xff, 0xff };
|
||||
|
||||
for (i = 0; i < argc; ++i)
|
||||
{
|
||||
@ -96,11 +95,12 @@ test_unproject_main (int argc, char *argv[])
|
||||
}
|
||||
else if (!strncmp (argv[i], "--help", 6))
|
||||
{
|
||||
printf ("%s [--rotage-x=degrees] [--rotage-y=degrees] "
|
||||
g_print ("%s [--rotage-x=degrees] "
|
||||
"[--rotage-y=degrees] "
|
||||
"[--rotage-z=degrees]\n",
|
||||
argv[0]);
|
||||
|
||||
exit (0);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,8 +126,8 @@ test_unproject_main (int argc, char *argv[])
|
||||
RECT_T, RECT_T + RECT_H,
|
||||
rotate_x, rotate_y, rotate_z);
|
||||
|
||||
label0 = clutter_label_new_with_text ("Mono 8pt", txt);
|
||||
clutter_label_set_color (CLUTTER_LABEL (label0), &white);
|
||||
label0 = clutter_text_new_with_text ("Mono 8pt", txt);
|
||||
clutter_text_set_color (CLUTTER_TEXT (label0), &white);
|
||||
|
||||
clutter_actor_set_position (label0, 10, 10);
|
||||
clutter_group_add (CLUTTER_GROUP (stage), label0);
|
||||
@ -135,9 +135,9 @@ test_unproject_main (int argc, char *argv[])
|
||||
g_free (txt);
|
||||
|
||||
label =
|
||||
clutter_label_new_with_text ("Mono 8pt", "Click around!");
|
||||
clutter_text_new_with_text ("Mono 8pt", "Click around!");
|
||||
|
||||
clutter_label_set_color (CLUTTER_LABEL (label), &blue);
|
||||
clutter_text_set_color (CLUTTER_TEXT (label), &blue);
|
||||
|
||||
clutter_actor_set_position (label, 10, 50);
|
||||
clutter_group_add (CLUTTER_GROUP (stage), label);
|
||||
|
@ -80,14 +80,14 @@ main (int argc, char *argv[])
|
||||
scale = 1.0;
|
||||
}
|
||||
|
||||
label = clutter_label_new_with_text (font_name, text);
|
||||
clutter_label_set_color (CLUTTER_LABEL (label), &label_color);
|
||||
label = clutter_text_new_with_text (font_name, text);
|
||||
clutter_text_set_color (CLUTTER_TEXT (label), &label_color);
|
||||
clutter_actor_set_position (label, (1.0*STAGE_WIDTH/COLS)*col,
|
||||
(1.0*STAGE_HEIGHT/ROWS)*row);
|
||||
/*clutter_actor_set_clip (label, 0,0, (1.0*STAGE_WIDTH/COLS),
|
||||
(1.0*STAGE_HEIGHT/ROWS));*/
|
||||
clutter_actor_set_scale (label, scale, scale);
|
||||
clutter_label_set_line_wrap (CLUTTER_LABEL (label), FALSE);
|
||||
clutter_text_set_line_wrap (CLUTTER_TEXT (label), FALSE);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), label);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user