diff --git a/ChangeLog b/ChangeLog index c2308ce3a..d09ccbfa0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-06-01 Neil J. Patel + + * clutter/clutter-effect.h: + * clutter/clutter-entry.c: (clutter_entry_handle_key_event), + (clutter_entry_add): + * clutter/clutter-entry.h: + * examples/test-entry.c: (on_key_release_cb): + Added a function to deal with ClutterKeyEvents. Handles the majority + of entry-related keyboard keys. However modifiers still need to be + implemented. + 2007-06-01 Tomas Frydrych * clutter/clutter-stage.c: diff --git a/clutter/clutter-effect.h b/clutter/clutter-effect.h index 8a3e4434b..ff37fee1e 100644 --- a/clutter/clutter-effect.h +++ b/clutter/clutter-effect.h @@ -57,14 +57,17 @@ typedef void (*ClutterEffectCompleteFunc) (ClutterActor *actor, #define CLUTTER_EFFECT_TEMPLATE_GET_CLASS(obj) \ (G_TYPE_INSTANCE_GET_CLASS ((obj), \ CLUTTER_TYPE_EFFECT_TEMPLATE, ClutterEffectTemplateClass)) + +typedef struct _ClutterEffectTemplate ClutterEffectTemplate; +typedef struct _ClutterEffectTemplateClass ClutterEffectTemplateClass; -typedef struct { +struct _ClutterEffectTemplate{ GObject parent; -} ClutterEffectTemplate; +}; -typedef struct { +struct _ClutterEffectTemplateClass{ GObjectClass parent_class; -} ClutterEffectTemplateClass; +}; GType clutter_effect_template_get_type (void); @@ -101,5 +104,3 @@ G_END_DECLS #endif /* _CLUTTER_EFFECT */ -G_END_DECLS - diff --git a/clutter/clutter-entry.c b/clutter/clutter-entry.c index 9ccaf6d58..694b3afa0 100644 --- a/clutter/clutter-entry.c +++ b/clutter/clutter-entry.c @@ -26,21 +26,22 @@ /** * SECTION:clutter-entry - * @short_description: Actor for displaying text + * @short_description: A single line text entry actor * - * #ClutterEntry is a #ClutterTexture that displays text. + * #ClutterEntry is a #ClutterTexture that allows single line text entry */ #include "config.h" #include "clutter-entry.h" -#include "clutter-main.h" -#include "clutter-enum-types.h" -#include "clutter-private.h" -#include "clutter-debug.h" -#include "clutter-units.h" -#include "clutter-rectangle.h" +#include "clutter-debug.h" +#include "clutter-enum-types.h" +#include "clutter-keysyms.h" +#include "clutter-main.h" +#include "clutter-private.h" +#include "clutter-rectangle.h" +#include "clutter-units.h" #include "pangoclutter.h" #define DEFAULT_FONT_NAME "Sans 10" @@ -821,6 +822,88 @@ clutter_entry_get_position (ClutterEntry *entry) return priv->position; } +/** + * clutter_entry_handle_key_event: + * @entry: a #ClutterEntry + * @kev: a #ClutterKeyEvent + * + * This function will handle a #ClutterKeyEvent, like those returned in a + * key-press/release-event, and will translate it for the @entry. This includes + * non-alphanumeric keys, such as the arrows keys, which will move the + * input cursor. + * + **/ +void +clutter_entry_handle_key_event (ClutterEntry *entry, ClutterKeyEvent *kev) +{ + ClutterEntryPrivate *priv; + gint pos = 0; + gint len = 0; + gint keyval = clutter_key_event_symbol (kev); + + g_return_if_fail (CLUTTER_IS_ENTRY (entry)); + + priv = entry->priv; + + pos = priv->position; + if (priv->text) + len = g_utf8_strlen (priv->text, -1); + + switch (keyval) + { + case CLUTTER_Return: + case CLUTTER_KP_Enter: + case CLUTTER_ISO_Enter: + case CLUTTER_Escape: + case CLUTTER_Shift_L: + case CLUTTER_Shift_R: + break; + case CLUTTER_BackSpace: + if (pos != 0 && len != 0) + clutter_entry_remove (entry, 1); + break; + case CLUTTER_Delete: + case CLUTTER_KP_Delete: + if (len && pos != -1) + { + clutter_entry_delete_text (entry, pos, pos+1);; + } + break; + case CLUTTER_Left: + case CLUTTER_KP_Left: + if (pos != 0 && len != 0) + { + if (pos == -1) + { + clutter_entry_set_position (entry, len-1); + } + else + clutter_entry_set_position (entry, pos - 1); + } + break; + case CLUTTER_Right: + case CLUTTER_KP_Right: + if (pos != -1 && len != 0) + { + if (pos != len) + clutter_entry_set_position (entry, pos +1); + } + break; + case CLUTTER_End: + case CLUTTER_KP_End: + clutter_entry_set_position (entry, -1); + break; + case CLUTTER_Begin: + case CLUTTER_Home: + case CLUTTER_KP_Home: + clutter_entry_set_position (entry, 0); + break; + default: + clutter_entry_add (entry, clutter_keysym_to_unicode (keyval)); + break; + } +} + /** * clutter_entry_add: * @entry: a #ClutterEntry @@ -848,7 +931,7 @@ clutter_entry_add (ClutterEntry *entry, gunichar wc) clutter_entry_set_text (entry, new->str); - if (priv->position > 0) + if (priv->position >= 0) clutter_entry_set_position (entry, priv->position + 1); g_string_free (new, TRUE); diff --git a/clutter/clutter-entry.h b/clutter/clutter-entry.h index bdcd61396..af3938834 100644 --- a/clutter/clutter-entry.h +++ b/clutter/clutter-entry.h @@ -29,6 +29,7 @@ #include #include +#include #include @@ -106,6 +107,8 @@ PangoAlignment clutter_entry_get_alignment (ClutterEntry *entr void clutter_entry_set_position (ClutterEntry *entry, gint position); gint clutter_entry_get_position (ClutterEntry *entry); +void clutter_entry_handle_key_event (ClutterEntry *entry, + ClutterKeyEvent *kev); void clutter_entry_add (ClutterEntry *entry, gunichar wc); void clutter_entry_remove (ClutterEntry *entry, diff --git a/doc/reference/ChangeLog b/doc/reference/ChangeLog index 5904191ab..03184fc98 100644 --- a/doc/reference/ChangeLog +++ b/doc/reference/ChangeLog @@ -1,3 +1,9 @@ +2007-06-01 Neil J. Patel + + * clutter-sections.txt: + * tmpl/clutter-entry.sgml: + Updated for new functions. + 2007-06-01 Tomas Frydrych * tmpl/clutter-alpha.sgml: diff --git a/doc/reference/clutter-sections.txt b/doc/reference/clutter-sections.txt index 1cd38ab93..545dbebe2 100644 --- a/doc/reference/clutter-sections.txt +++ b/doc/reference/clutter-sections.txt @@ -776,6 +776,7 @@ clutter_entry_set_alignment clutter_entry_get_alignment clutter_entry_set_position clutter_entry_get_position +clutter_entry_handle_key_event clutter_entry_add clutter_entry_remove clutter_entry_insert_text diff --git a/doc/reference/tmpl/clutter-entry.sgml b/doc/reference/tmpl/clutter-entry.sgml index 78a844aa1..2b6e78f6d 100644 --- a/doc/reference/tmpl/clutter-entry.sgml +++ b/doc/reference/tmpl/clutter-entry.sgml @@ -158,6 +158,15 @@ ClutterEntry @Returns: + + + + + +@entry: +@kev: + + diff --git a/examples/test-entry.c b/examples/test-entry.c index d7faad6a5..bcf689f47 100644 --- a/examples/test-entry.c +++ b/examples/test-entry.c @@ -3,52 +3,11 @@ void on_key_release_cb (ClutterStage *stage, ClutterEvent *event, ClutterEntry *entry) { - if (event->type == CLUTTER_KEY_RELEASE) { + if (event->type == CLUTTER_KEY_RELEASE) + { ClutterKeyEvent* kev = (ClutterKeyEvent *) event; - guint key = clutter_key_event_symbol (kev); - - gint pos = clutter_entry_get_position (entry); - gint len = g_utf8_strlen (clutter_entry_get_text (entry), -1); - - switch (key) - { - case CLUTTER_Return: - case CLUTTER_KP_Enter: - case CLUTTER_ISO_Enter: - break; - case CLUTTER_Escape: - clutter_main_quit (); - break; - case CLUTTER_BackSpace: - clutter_entry_remove (entry, 1); - break; - case CLUTTER_Left: - if (pos != 0) - { - if (pos == -1) - { - clutter_entry_set_position (entry, len-1); - } - else - clutter_entry_set_position (entry, pos - 1); - } - break; - case CLUTTER_Right: - if (pos != -1) - { - if (pos != len) - clutter_entry_set_position (entry, pos +1); - } - break; - case CLUTTER_Up: - clutter_entry_insert_text (entry, "insert", 5); - break; - case CLUTTER_Down: - clutter_entry_delete_text (entry, 5, 11); - default: - clutter_entry_add (entry, clutter_key_event_unicode (kev)); - break; - } + clutter_entry_handle_key_event (entry, kev); + return; } }