When "dived" focus reaches and crosses border of object, return as if

not handled.  This causes the platform to handle the key event itself,
typically by moving the focus to the next top-level object.
This commit is contained in:
ehouse 2006-11-17 13:41:13 +00:00
parent 56f64f6f46
commit 74ccc0ed34
5 changed files with 82 additions and 45 deletions

View file

@ -2495,12 +2495,20 @@ flipKey( XP_Key key, XP_Bool flip ) {
switch( key ) {
case XP_CURSOR_KEY_DOWN:
result = XP_CURSOR_KEY_RIGHT; break;
case XP_CURSOR_KEY_ALTDOWN:
result = XP_CURSOR_KEY_ALTRIGHT; break;
case XP_CURSOR_KEY_UP:
result = XP_CURSOR_KEY_LEFT; break;
case XP_CURSOR_KEY_ALTUP:
result = XP_CURSOR_KEY_ALTLEFT; break;
case XP_CURSOR_KEY_LEFT:
result = XP_CURSOR_KEY_UP; break;
case XP_CURSOR_KEY_ALTLEFT:
result = XP_CURSOR_KEY_ALTUP; break;
case XP_CURSOR_KEY_RIGHT:
result = XP_CURSOR_KEY_DOWN; break;
case XP_CURSOR_KEY_ALTRIGHT:
result = XP_CURSOR_KEY_ALTDOWN; break;
default:
XP_ASSERT(0);
}
@ -2520,9 +2528,13 @@ board_handleKey( BoardCtxt* board, XP_Key key, XP_Bool* pHandled )
switch( key ) {
#ifdef KEYBOARD_NAV
case XP_CURSOR_KEY_DOWN:
case XP_CURSOR_KEY_ALTDOWN:
case XP_CURSOR_KEY_UP:
case XP_CURSOR_KEY_ALTUP:
case XP_CURSOR_KEY_LEFT:
case XP_CURSOR_KEY_ALTLEFT:
case XP_CURSOR_KEY_RIGHT:
case XP_CURSOR_KEY_ALTRIGHT:
if ( board->focusHasDived ) {
XP_Bool up = XP_FALSE;
if ( board->focussed == OBJ_BOARD ) {
@ -2539,7 +2551,7 @@ board_handleKey( BoardCtxt* board, XP_Key key, XP_Bool* pHandled )
board->focusHasDived = XP_FALSE;
invalFocusOwner( board );
} else {
handled = XP_TRUE;
handled = redraw;//XP_TRUE;
}
} else {
/* Do nothing. We don't handle transition among top-level

View file

@ -36,11 +36,16 @@ extern "C" {
typedef enum {
/* keep these three together: for the cursor */
XP_KEY_NONE,
XP_CURSOR_KEY_DOWN,
XP_CURSOR_KEY_RIGHT,
XP_CURSOR_KEY_DOWN,
XP_CURSOR_KEY_ALTDOWN,
XP_CURSOR_KEY_RIGHT,
XP_CURSOR_KEY_ALTRIGHT,
XP_CURSOR_KEY_UP,
XP_CURSOR_KEY_ALTUP,
XP_CURSOR_KEY_LEFT,
XP_CURSOR_KEY_ALTLEFT,
XP_CURSOR_KEY_DEL,
XP_RAISEFOCUS_KEY,
XP_RETURN_KEY,

View file

@ -638,23 +638,26 @@ board_juggleTray( BoardCtxt* board )
#ifdef KEYBOARD_NAV
XP_Bool
tray_moveCursor( BoardCtxt* board, XP_Key cursorKey, XP_Bool* up )
tray_moveCursor( BoardCtxt* board, XP_Key cursorKey, XP_Bool* pUp )
{
XP_Bool result;
XP_Bool draw = XP_FALSE;
XP_Bool up = XP_FALSE;
XP_U16 selPlayer = board->selPlayer;
XP_S16 pos;
switch (cursorKey ) {
switch ( cursorKey ) {
case XP_CURSOR_KEY_UP:
case XP_CURSOR_KEY_DOWN:
*up = XP_TRUE;
up = XP_TRUE;
break;
/* moving the divider needs to be hard to do accidentally since it
confuses users when juggle and hint stop working. But all things
must be possible via keyboard on devices that don't have
touchscreens. Probably need a new keytype XP_CURSOR_KEY_ALTDOWN
etc. */
/* result = board_moveDivider( board, XP_FALSE ); */
/* result = board_moveDivider( board, XP_TRUE ); */
case XP_CURSOR_KEY_ALTRIGHT:
case XP_CURSOR_KEY_ALTLEFT:
draw = board_moveDivider( board, cursorKey == XP_CURSOR_KEY_ALTRIGHT );
break;
case XP_CURSOR_KEY_RIGHT:
case XP_CURSOR_KEY_LEFT:
@ -665,7 +668,7 @@ tray_moveCursor( BoardCtxt* board, XP_Key cursorKey, XP_Bool* up )
for ( ; ; ) {
pos += (cursorKey == XP_CURSOR_KEY_RIGHT ? 1 : -1);
if ( pos < 0 || pos >= MAX_TRAY_TILES ) {
*up = XP_TRUE;
up = XP_TRUE;
} else {
/* Revisit this when able to never draw the cursor in a place
this won't allow it, e.g. when the tiles move after a
@ -683,14 +686,15 @@ tray_moveCursor( BoardCtxt* board, XP_Key cursorKey, XP_Bool* up )
break;
}
board_invalTrayTiles( board, 1 << board->trayCursorLoc[selPlayer] );
result = XP_TRUE;
draw = XP_TRUE;
break;
default:
XP_ASSERT(0);
draw = XP_FALSE;
break;
}
return result;
*pUp = up;
return draw;
} /* tray_moveCursor */
XP_Bool

View file

@ -67,6 +67,7 @@ static XP_Bool handleLeft( CursesAppGlobals* globals );
static XP_Bool handleRight( CursesAppGlobals* globals );
static XP_Bool handleUp( CursesAppGlobals* globals );
static XP_Bool handleDown( CursesAppGlobals* globals );
static XP_Bool handleFocusKey( CursesAppGlobals* globals, XP_Key key );
#ifdef MEM_DEBUG
@ -394,6 +395,19 @@ handleHide( CursesAppGlobals* globals )
return XP_TRUE;
} /* handleJuggle */
static XP_Bool
handleAltLeft( CursesAppGlobals* globals )
{
return handleFocusKey( globals, XP_CURSOR_KEY_ALTLEFT );
}
static XP_Bool
handleAltRight( CursesAppGlobals* globals )
{
return handleFocusKey( globals, XP_CURSOR_KEY_ALTRIGHT );
}
static XP_Bool
handleFlip( CursesAppGlobals* globals )
{
@ -461,41 +475,39 @@ static XP_Bool
shiftFocus( CursesAppGlobals* globals, XP_Key key )
{
BoardCtxt* board = globals->cGlobals.game.board;
BoardObjectType typ = board_getFocusOwner( board );
BoardObjectType nxt;
XP_Bool forward = key == XP_CURSOR_KEY_DOWN || key == XP_CURSOR_KEY_RIGHT;
XP_Bool handled;
XP_Bool handled = XP_FALSE;
switch( typ ) {
case OBJ_NONE:
XP_ASSERT( 0 ); /* not in curses anyway */
break;
case OBJ_SCORE:
if ( forward ) {
nxt = OBJ_TRAY;
do { /* allow break */
XP_Bool forward;
BoardObjectType nxt;
if ( key == XP_CURSOR_KEY_DOWN || key == XP_CURSOR_KEY_RIGHT ) {
forward = XP_TRUE;
} else if ( key == XP_CURSOR_KEY_UP || key == XP_CURSOR_KEY_LEFT ) {
forward = XP_FALSE;
} else {
nxt = OBJ_BOARD;
break;
}
break;
case OBJ_BOARD:
if ( forward ) {
nxt = OBJ_SCORE;
} else {
nxt = OBJ_TRAY;
switch( board_getFocusOwner( board ) ) {
case OBJ_NONE:
XP_ASSERT( 0 ); /* not in curses anyway */
break;
case OBJ_SCORE:
nxt = forward ? OBJ_TRAY : OBJ_BOARD;
break;
case OBJ_BOARD:
nxt = forward ? OBJ_SCORE : OBJ_TRAY;
break;
case OBJ_TRAY:
nxt = forward ? OBJ_BOARD : OBJ_SCORE;
break;
}
break;
case OBJ_TRAY:
if ( forward ) {
nxt = OBJ_BOARD;
} else {
nxt = OBJ_SCORE;
handled = board_focusChanged( board, nxt, XP_TRUE );
if ( handled ) {
changeMenuForFocus( globals, nxt );
}
break;
}
handled = board_focusChanged( board, nxt, XP_TRUE );
if ( handled ) {
changeMenuForFocus( globals, nxt );
}
} while ( 0 );
return handled;
}
@ -554,6 +566,8 @@ MenuList scoreMenuList[] = {
MenuList trayMenuList[] = {
{ handleJuggle, "Juggle", "G", 'G' },
{ handleHide, "[un]hIde", "I", 'I' },
{ handleAltLeft, "Divider left", "{", '{' },
{ handleAltRight, "Divider right", "}", '}' },
{ NULL, NULL, NULL, '\0'}
};
@ -754,6 +768,7 @@ blocking_gotEvent( CursesAppGlobals* globals, int* ch )
/* stdin first */
if ( (globals->fdArray[FD_STDIN].revents & POLLIN) != 0 ) {
int evtCh = fgetc(stdin);
XP_LOGF( "%s: got key: %x", __FUNCTION__, evtCh );
*ch = evtCh;
result = XP_TRUE;
--numEvents;

View file

@ -2521,6 +2521,7 @@ mainViewHandleEvent( EventPtr event )
case keyDownEvent: {
XP_Key xpkey = XP_KEY_NONE;
Int16 ch = event->data.keyDown.chr;
XP_Bool altOn = (event->data.keyDown.modifiers & shiftKeyMask) != 0;
switch ( ch ) {
case pageUpChr:
@ -2538,10 +2539,10 @@ mainViewHandleEvent( EventPtr event )
xpkey = XP_RETURN_KEY;
break;
case vchrRockerLeft:
xpkey = XP_CURSOR_KEY_LEFT;
xpkey = altOn ? XP_CURSOR_KEY_ALTLEFT : XP_CURSOR_KEY_LEFT;
break;
case vchrRockerRight:
xpkey = XP_CURSOR_KEY_RIGHT;
xpkey = altOn ? XP_CURSOR_KEY_ALTRIGHT : XP_CURSOR_KEY_RIGHT;
break;
case vchrRockerUp:
xpkey = XP_CURSOR_KEY_UP;