St: add keyboard support to StClickable and StButton

Allow triggering clicks with space/return

https://bugzilla.gnome.org/show_bug.cgi?id=633853
This commit is contained in:
Dan Winship 2010-10-13 15:53:42 -04:00
parent 4f1f226828
commit 35f806df4e
2 changed files with 65 additions and 0 deletions

View File

@ -195,6 +195,36 @@ st_button_button_release (ClutterActor *actor,
return FALSE; return FALSE;
} }
static gboolean
st_button_key_press (ClutterActor *actor,
ClutterKeyEvent *event)
{
st_widget_hide_tooltip (ST_WIDGET (actor));
if (event->keyval == CLUTTER_KEY_space ||
event->keyval == CLUTTER_KEY_Return)
{
st_button_press (ST_BUTTON (actor));
return TRUE;
}
return FALSE;
}
static gboolean
st_button_key_release (ClutterActor *actor,
ClutterKeyEvent *event)
{
if (event->keyval == CLUTTER_KEY_space ||
event->keyval == CLUTTER_KEY_Return)
{
st_button_release (ST_BUTTON (actor), TRUE);
return TRUE;
}
return FALSE;
}
static gboolean static gboolean
st_button_enter (ClutterActor *actor, st_button_enter (ClutterActor *actor,
ClutterCrossingEvent *event) ClutterCrossingEvent *event)
@ -315,6 +345,8 @@ st_button_class_init (StButtonClass *klass)
actor_class->button_press_event = st_button_button_press; actor_class->button_press_event = st_button_button_press;
actor_class->button_release_event = st_button_button_release; actor_class->button_release_event = st_button_button_release;
actor_class->key_press_event = st_button_key_press;
actor_class->key_release_event = st_button_key_release;
actor_class->enter_event = st_button_enter; actor_class->enter_event = st_button_enter;
actor_class->leave_event = st_button_leave; actor_class->leave_event = st_button_leave;

View File

@ -158,6 +158,37 @@ st_clickable_button_release_event (ClutterActor *actor,
return TRUE; return TRUE;
} }
static gboolean
st_clickable_key_press_event (ClutterActor *actor,
ClutterKeyEvent *event)
{
StClickable *self = ST_CLICKABLE (actor);
if (event->keyval == CLUTTER_KEY_space ||
event->keyval == CLUTTER_KEY_Return)
{
set_pressed (self, TRUE);
return TRUE;
}
return FALSE;
}
static gboolean
st_clickable_key_release_event (ClutterActor *actor,
ClutterKeyEvent *event)
{
StClickable *self = ST_CLICKABLE (actor);
if (event->keyval != CLUTTER_KEY_space &&
event->keyval != CLUTTER_KEY_Return)
return FALSE;
set_pressed (self, FALSE);
g_signal_emit (G_OBJECT (self), st_clickable_signals[CLICKED], 0, event);
return TRUE;
}
/** /**
* st_clickable_fake_release: * st_clickable_fake_release:
* @box: * @box:
@ -240,6 +271,8 @@ st_clickable_class_init (StClickableClass *klass)
actor_class->leave_event = st_clickable_leave_event; actor_class->leave_event = st_clickable_leave_event;
actor_class->button_press_event = st_clickable_button_press_event; actor_class->button_press_event = st_clickable_button_press_event;
actor_class->button_release_event = st_clickable_button_release_event; actor_class->button_release_event = st_clickable_button_release_event;
actor_class->key_press_event = st_clickable_key_press_event;
actor_class->key_release_event = st_clickable_key_release_event;
/** /**
* StClickable::clicked * StClickable::clicked