mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 03:22:04 +00:00
Added a function to deal with ClutterKeyEvents. Handles the majority
of entry-related keyboard keys. However modifiers still need to be implemented.
This commit is contained in:
parent
4d0cfed2dc
commit
ac530eed12
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
||||
2007-06-01 Neil J. Patel <njp@o-hand.com>
|
||||
|
||||
* 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 <tf@openedhand.com>
|
||||
|
||||
* clutter/clutter-stage.c:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include <clutter/clutter-actor.h>
|
||||
#include <clutter/clutter-color.h>
|
||||
#include <clutter/clutter-event.h>
|
||||
#include <pango/pango.h>
|
||||
|
||||
|
||||
@ -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,
|
||||
|
@ -1,3 +1,9 @@
|
||||
2007-06-01 Neil J. Patel <njp@o-hand.com>
|
||||
|
||||
* clutter-sections.txt:
|
||||
* tmpl/clutter-entry.sgml:
|
||||
Updated for new functions.
|
||||
|
||||
2007-06-01 Tomas Frydrych <tf@openedhand.com>
|
||||
|
||||
* tmpl/clutter-alpha.sgml:
|
||||
|
@ -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
|
||||
|
@ -158,6 +158,15 @@ ClutterEntry
|
||||
@Returns:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION clutter_entry_handle_key_event ##### -->
|
||||
<para>
|
||||
|
||||
</para>
|
||||
|
||||
@entry:
|
||||
@kev:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION clutter_entry_add ##### -->
|
||||
<para>
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user