mirror of
https://github.com/brl/mutter.git
synced 2024-11-23 00:20:42 -05:00
2008-03-06 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/clutter-entry.h: * clutter/clutter-entry.c: (clutter_entry_handle_key_event_internal), (clutter_entry_key_press), (clutter_entry_class_init), (clutter_entry_handle_key_event): Handle a default class handler for the key-press-event, so that giving key focus to an entry will automatically make it work. This deprecates the clutter_entry_handle_key_event() function. (#824) * tests/test-entry.c (main): Remove the handle_key_event() machinery, and just give focus to the entry.
This commit is contained in:
parent
781661e9c3
commit
daea8af85e
14
ChangeLog
14
ChangeLog
@ -1,3 +1,17 @@
|
||||
2008-03-06 Emmanuele Bassi <ebassi@openedhand.com>
|
||||
|
||||
* clutter/clutter-entry.h:
|
||||
* clutter/clutter-entry.c:
|
||||
(clutter_entry_handle_key_event_internal),
|
||||
(clutter_entry_key_press), (clutter_entry_class_init),
|
||||
(clutter_entry_handle_key_event): Handle a default class handler
|
||||
for the key-press-event, so that giving key focus to an entry will
|
||||
automatically make it work. This deprecates the
|
||||
clutter_entry_handle_key_event() function. (#824)
|
||||
|
||||
* tests/test-entry.c (main): Remove the handle_key_event()
|
||||
machinery, and just give focus to the entry.
|
||||
|
||||
2008-03-06 Chris Lord <chris@openedhand.com>
|
||||
|
||||
* clutter/clutter-model.c: (clutter_model_set_sorting_column):
|
||||
|
@ -30,11 +30,6 @@
|
||||
*
|
||||
* #ClutterEntry is a #ClutterTexture that allows single line text entry.
|
||||
*
|
||||
* In order to update the contents of the entry with the text inserted
|
||||
* by the user you should connect to the ClutterStage::key-press-event and
|
||||
* forward the #ClutterKeyEvent received by the #ClutterStage to the
|
||||
* #ClutterEntry you want to update, using clutter_entry_handle_key_event().
|
||||
*
|
||||
* #ClutterEntry is available since Clutter 0.4.
|
||||
*/
|
||||
|
||||
@ -498,6 +493,93 @@ clutter_entry_request_coords (ClutterActor *self,
|
||||
CLUTTER_ACTOR_CLASS (clutter_entry_parent_class)->request_coords (self, box);
|
||||
}
|
||||
|
||||
static inline void
|
||||
clutter_entry_handle_key_event_internal (ClutterEntry *entry,
|
||||
ClutterKeyEvent *event)
|
||||
{
|
||||
ClutterEntryPrivate *priv = entry->priv;
|
||||
gint pos = priv->position;
|
||||
gint len = 0;
|
||||
gint keyval = clutter_key_event_symbol (event);
|
||||
|
||||
if (priv->text)
|
||||
len = g_utf8_strlen (priv->text, -1);
|
||||
|
||||
switch (keyval)
|
||||
{
|
||||
case CLUTTER_Return:
|
||||
case CLUTTER_KP_Enter:
|
||||
case CLUTTER_ISO_Enter:
|
||||
g_signal_emit (entry, entry_signals[ACTIVATE], 0);
|
||||
break;
|
||||
|
||||
case CLUTTER_Escape:
|
||||
case CLUTTER_Up:
|
||||
case CLUTTER_KP_Up:
|
||||
case CLUTTER_Down:
|
||||
case CLUTTER_KP_Down:
|
||||
case CLUTTER_Shift_L:
|
||||
case CLUTTER_Shift_R:
|
||||
break;
|
||||
|
||||
case CLUTTER_BackSpace:
|
||||
if (pos != 0 && len != 0)
|
||||
clutter_entry_delete_chars (entry, 1);
|
||||
break;
|
||||
|
||||
case CLUTTER_Delete:
|
||||
case CLUTTER_KP_Delete:
|
||||
if (len && pos != -1)
|
||||
clutter_entry_delete_text (entry, pos, pos+1);;
|
||||
break;
|
||||
|
||||
case CLUTTER_Left:
|
||||
case CLUTTER_KP_Left:
|
||||
if (pos != 0 && len != 0)
|
||||
{
|
||||
if (pos == -1)
|
||||
clutter_entry_set_cursor_position (entry, len - 1);
|
||||
else
|
||||
clutter_entry_set_cursor_position (entry, pos - 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case CLUTTER_Right:
|
||||
case CLUTTER_KP_Right:
|
||||
if (pos != -1 && len != 0)
|
||||
{
|
||||
if (pos != len)
|
||||
clutter_entry_set_cursor_position (entry, pos + 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case CLUTTER_End:
|
||||
case CLUTTER_KP_End:
|
||||
clutter_entry_set_cursor_position (entry, -1);
|
||||
break;
|
||||
|
||||
case CLUTTER_Begin:
|
||||
case CLUTTER_Home:
|
||||
case CLUTTER_KP_Home:
|
||||
clutter_entry_set_cursor_position (entry, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
clutter_entry_insert_unichar (entry,
|
||||
clutter_keysym_to_unicode (keyval));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
clutter_entry_key_press (ClutterActor *actor,
|
||||
ClutterKeyEvent *event)
|
||||
{
|
||||
clutter_entry_handle_key_event_internal (CLUTTER_ENTRY (actor), event);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_entry_dispose (GObject *object)
|
||||
{
|
||||
@ -545,6 +627,7 @@ clutter_entry_class_init (ClutterEntryClass *klass)
|
||||
|
||||
actor_class->paint = clutter_entry_paint;
|
||||
actor_class->request_coords = clutter_entry_request_coords;
|
||||
actor_class->key_press_event = clutter_entry_key_press;
|
||||
|
||||
gobject_class->finalize = clutter_entry_finalize;
|
||||
gobject_class->dispose = clutter_entry_dispose;
|
||||
@ -744,9 +827,7 @@ clutter_entry_class_init (ClutterEntryClass *klass)
|
||||
* @entry: the actor which received the event
|
||||
*
|
||||
* The ::activate signal is emitted each time the entry is 'activated'
|
||||
* by the user, normally by pressing the 'Enter' key. This signal will
|
||||
* only be emitted when you are adding text to the entry via
|
||||
* clutter_entry_handle_key_event().
|
||||
* by the user, normally by pressing the 'Enter' key.
|
||||
*
|
||||
* Since: 0.4
|
||||
*/
|
||||
@ -1269,81 +1350,17 @@ clutter_entry_get_cursor_position (ClutterEntry *entry)
|
||||
* ClutterStage::key-press-event or ClutterStage::key-release-event.
|
||||
*
|
||||
* Since: 0.4
|
||||
*
|
||||
* Deprecated: 0.8: The key events will automatically be handled when
|
||||
* giving the key focus to an entry using clutter_stage_set_key_focus().
|
||||
*/
|
||||
void
|
||||
clutter_entry_handle_key_event (ClutterEntry *entry,
|
||||
ClutterKeyEvent *kev)
|
||||
{
|
||||
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:
|
||||
g_signal_emit (entry, entry_signals[ACTIVATE], 0);
|
||||
break;
|
||||
case CLUTTER_Escape:
|
||||
case CLUTTER_Up:
|
||||
case CLUTTER_KP_Up:
|
||||
case CLUTTER_Down:
|
||||
case CLUTTER_KP_Down:
|
||||
case CLUTTER_Shift_L:
|
||||
case CLUTTER_Shift_R:
|
||||
break;
|
||||
case CLUTTER_BackSpace:
|
||||
if (pos != 0 && len != 0)
|
||||
clutter_entry_delete_chars (entry, 1);
|
||||
break;
|
||||
case CLUTTER_Delete:
|
||||
case CLUTTER_KP_Delete:
|
||||
if (len && pos != -1)
|
||||
clutter_entry_delete_text (entry, pos, pos+1);;
|
||||
break;
|
||||
case CLUTTER_Left:
|
||||
case CLUTTER_KP_Left:
|
||||
if (pos != 0 && len != 0)
|
||||
{
|
||||
if (pos == -1)
|
||||
clutter_entry_set_cursor_position (entry, len - 1);
|
||||
else
|
||||
clutter_entry_set_cursor_position (entry, pos - 1);
|
||||
}
|
||||
break;
|
||||
case CLUTTER_Right:
|
||||
case CLUTTER_KP_Right:
|
||||
if (pos != -1 && len != 0)
|
||||
{
|
||||
if (pos != len)
|
||||
clutter_entry_set_cursor_position (entry, pos + 1);
|
||||
}
|
||||
break;
|
||||
case CLUTTER_End:
|
||||
case CLUTTER_KP_End:
|
||||
clutter_entry_set_cursor_position (entry, -1);
|
||||
break;
|
||||
case CLUTTER_Begin:
|
||||
case CLUTTER_Home:
|
||||
case CLUTTER_KP_Home:
|
||||
clutter_entry_set_cursor_position (entry, 0);
|
||||
break;
|
||||
default:
|
||||
clutter_entry_insert_unichar (entry,
|
||||
clutter_keysym_to_unicode (keyval));
|
||||
break;
|
||||
}
|
||||
clutter_entry_handle_key_event_internal (entry, kev);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,8 +129,6 @@ PangoAlignment clutter_entry_get_alignment (ClutterEntry *ent
|
||||
void clutter_entry_set_cursor_position (ClutterEntry *entry,
|
||||
gint position);
|
||||
gint clutter_entry_get_cursor_position (ClutterEntry *entry);
|
||||
void clutter_entry_handle_key_event (ClutterEntry *entry,
|
||||
ClutterKeyEvent *kev);
|
||||
void clutter_entry_insert_unichar (ClutterEntry *entry,
|
||||
gunichar wc);
|
||||
void clutter_entry_delete_chars (ClutterEntry *entry,
|
||||
@ -155,6 +153,11 @@ void clutter_entry_set_max_length (ClutterEntry *ent
|
||||
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 /* _HAVE_CLUTTER_ENTRY_H */
|
||||
|
@ -1,24 +1,5 @@
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#if 0
|
||||
static void
|
||||
on_entry_text_changed (ClutterEntry *entry)
|
||||
{
|
||||
g_print ("Text changed\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
on_key_release_cb (ClutterStage *stage, ClutterEvent *event, ClutterEntry *entry)
|
||||
{
|
||||
if (event->type == CLUTTER_KEY_RELEASE)
|
||||
{
|
||||
ClutterKeyEvent* kev = (ClutterKeyEvent *) event;
|
||||
clutter_entry_handle_key_event (entry, kev);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_entry_activated (ClutterEntry *entry, gpointer null)
|
||||
{
|
||||
@ -52,15 +33,10 @@ main (int argc, char *argv[])
|
||||
/*clutter_entry_set_max_length (CLUTTER_ENTRY (entry), 50);*/
|
||||
|
||||
clutter_group_add (CLUTTER_GROUP (stage), entry);
|
||||
clutter_stage_set_key_focus (CLUTTER_STAGE (stage), entry);
|
||||
|
||||
clutter_actor_show_all (stage);
|
||||
|
||||
g_signal_connect (stage, "key-release-event",
|
||||
G_CALLBACK (on_key_release_cb), entry);
|
||||
|
||||
/*
|
||||
g_signal_connect (entry, "text-changed",
|
||||
G_CALLBACK (on_entry_text_changed), NULL);
|
||||
*/
|
||||
g_signal_connect (entry, "activate",
|
||||
G_CALLBACK (on_entry_activated), NULL);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user