From f329966a8ace674b897fae11000fb0cde6c8b33e Mon Sep 17 00:00:00 2001 From: ehouse Date: Fri, 12 Jan 2007 03:28:20 +0000 Subject: [PATCH] on keyDown, look at what keyUp will do and, if nothing, don't handle the event. This lets focus transfer work as before there was keyDown. --- xwords4/common/board.c | 79 +++++++++++++++++++++++++-------------- xwords4/common/boardp.h | 5 ++- xwords4/common/scorebdp.c | 7 ++-- xwords4/common/scorebdp.h | 5 ++- xwords4/common/tray.c | 23 ++++++++---- 5 files changed, 75 insertions(+), 44 deletions(-) diff --git a/xwords4/common/board.c b/xwords4/common/board.c index c2edcc16e..28059ca67 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -1,6 +1,6 @@ /* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */ /* - * Copyright 1997 - 2006 by Eric House (xwords@eehouse.org). All rights + * Copyright 1997 - 2007 by Eric House (xwords@eehouse.org). All rights * reserved. * * This program is free software; you can redistribute it and/or @@ -123,7 +123,7 @@ static XP_Bool moveKeyTileToBoard( BoardCtxt* board, XP_Key cursorKey, #ifdef KEYBOARD_NAV static XP_Bool board_moveCursor( BoardCtxt* board, XP_Key cursorKey, - XP_Bool* up ); + XP_Bool preflightOnly, XP_Bool* up ); static XP_Bool invalFocusOwner( BoardCtxt* board ); #endif #ifdef XWFEATURE_SEARCHLIMIT @@ -2584,7 +2584,45 @@ focusToCoords( BoardCtxt* board, XP_U16* xp, XP_U16* yp ) } return result; -} +} /* focusToCoords */ + +/* The focus keys are special because they can cause focus to leave one object + * and move to another (which the platform needs to be involved with). On + * palm, that only works if the keyDown handler claims not to have handled the + * event. So we must preflight, determining if the keyUp handler will handle + * the event should it get to it. If it wouldn't, then the platform wants a + * chance not to generate a keyUp event at all. + */ +static XP_Bool +handleFocusKeyUp( BoardCtxt* board, XP_Key key, XP_Bool preflightOnly, + XP_Bool* pHandled ) +{ + XP_Bool redraw = XP_FALSE; + if ( board->focusHasDived ) { + XP_Bool up = XP_FALSE; + if ( board->focussed == OBJ_BOARD ) { + redraw = board_moveCursor( board, flipKey( key, board->isFlipped ), + preflightOnly, &up ); + } else if ( board->focussed == OBJ_SCORE ) { + redraw = moveScoreCursor( board, key, preflightOnly, &up ); + } else if ( board->focussed == OBJ_TRAY ) { + redraw = tray_moveCursor( board, key, preflightOnly, &up ); + } + if ( up ) { + if ( !preflightOnly ) { + invalFocusOwner( board ); + board->focusHasDived = XP_FALSE; + invalFocusOwner( board ); + } + } else { + *pHandled = redraw; + } + } else { + /* Do nothing. We don't handle transition among top-level + focussed objects. Platform must. */ + } + return redraw; +} /* handleFocusKeyUp */ XP_Bool board_handleKeyDown( BoardCtxt* board, XP_Key key, XP_Bool* pHandled ) @@ -2592,14 +2630,17 @@ board_handleKeyDown( BoardCtxt* board, XP_Key key, XP_Bool* pHandled ) XP_Bool draw = XP_FALSE; XP_U16 x, y; + *pHandled = XP_FALSE; + if ( key == XP_RETURN_KEY ) { if ( focusToCoords( board, &x, &y ) ) { draw = handleLikeDown( board, board->focussed, x, y ); + *pHandled = draw; } + } else if ( board->focussed != OBJ_NONE ) { + draw = handleFocusKeyUp( board, key, XP_TRUE, pHandled ) || draw; } - *pHandled = (board->focussed != OBJ_NONE) && board->focusHasDived; - return draw; } @@ -2636,28 +2677,7 @@ board_handleKeyUp( BoardCtxt* board, XP_Key key, XP_Bool* pHandled ) 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 ) { - redraw = board_moveCursor( board, - flipKey( key, board->isFlipped ), - &up ); - } else if ( board->focussed == OBJ_SCORE ) { - redraw = moveScoreCursor( board, key, &up ); - } else if ( board->focussed == OBJ_TRAY ) { - redraw = tray_moveCursor( board, key, &up ); - } - if ( up ) { - invalFocusOwner( board ); - board->focusHasDived = XP_FALSE; - invalFocusOwner( board ); - } else { - handled = redraw;//XP_TRUE; - } - } else { - /* Do nothing. We don't handle transition among top-level - focussed objects. Platform must. */ - } + redraw = handleFocusKeyUp( board, key, XP_FALSE, &handled ); break; #endif @@ -2932,7 +2952,8 @@ stripAlt( XP_Key key, XP_Bool* wasAlt ) } /* stripAlt */ static XP_Bool -board_moveCursor( BoardCtxt* board, XP_Key cursorKey, XP_Bool* up ) +board_moveCursor( BoardCtxt* board, XP_Key cursorKey, XP_Bool preflightOnly, + XP_Bool* up ) { BdCursorLoc loc = board->bdCursor[board->selPlayer]; XP_U16 col = loc.col; @@ -2944,7 +2965,7 @@ board_moveCursor( BoardCtxt* board, XP_Key cursorKey, XP_Bool* up ) changed = figureNextLoc( board, cursorKey, XP_FALSE, altSet, &col, &row, up ); - if ( changed ) { + if ( changed && !preflightOnly ) { invalCell( board, loc.col, loc.row ); invalCell( board, col, row ); loc.col = col; diff --git a/xwords4/common/boardp.h b/xwords4/common/boardp.h index f34800b15..073b0dcce 100644 --- a/xwords4/common/boardp.h +++ b/xwords4/common/boardp.h @@ -1,6 +1,6 @@ /* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */ /* - * Copyright 1997 - 2000 by Eric House (xwords@eehouse.org). All rights reserved. + * Copyright 1997 - 2007 by Eric House (xwords@eehouse.org). All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -201,7 +201,8 @@ void board_selectPlayer( BoardCtxt* board, XP_U16 newPlayer ); #ifdef KEYBOARD_NAV XP_Key flipKey( XP_Key key, XP_Bool flip ); -XP_Bool tray_moveCursor( BoardCtxt* board, XP_Key cursorKey, XP_Bool* up ); +XP_Bool tray_moveCursor( BoardCtxt* board, XP_Key cursorKey, + XP_Bool preflightOnly, XP_Bool* up ); XP_Bool tray_keyAction( BoardCtxt* board ); DrawFocusState dfsFor( BoardCtxt* board, BoardObjectType obj ); void shiftFocusUp( BoardCtxt* board, XP_Key key ); diff --git a/xwords4/common/scorebdp.c b/xwords4/common/scorebdp.c index 588b4cafc..df8772431 100644 --- a/xwords4/common/scorebdp.c +++ b/xwords4/common/scorebdp.c @@ -1,6 +1,6 @@ /* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */ /* - * Copyright 1997 - 2006 by Eric House (xwords@eehouse.org). All rights reserved. + * Copyright 1997 - 2007 by Eric House (xwords@eehouse.org). All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -281,7 +281,8 @@ handlePenUpScore( BoardCtxt* board, XP_U16 x, XP_U16 y ) #ifdef KEYBOARD_NAV XP_Bool -moveScoreCursor( BoardCtxt* board, XP_Key key, XP_Bool* pUp ) +moveScoreCursor( BoardCtxt* board, XP_Key key, XP_Bool preflightOnly, + XP_Bool* pUp ) { XP_Bool result = XP_TRUE; XP_U16 nPlayers = board->gi->nPlayers; @@ -309,7 +310,7 @@ moveScoreCursor( BoardCtxt* board, XP_Key key, XP_Bool* pUp ) } if ( !up && ((scoreCursorLoc < 0) || (scoreCursorLoc >= nPlayers)) ) { up = XP_TRUE; - } else { + } else if ( !preflightOnly ) { board->scoreCursorLoc = scoreCursorLoc; board->scoreBoardInvalid = XP_TRUE; } diff --git a/xwords4/common/scorebdp.h b/xwords4/common/scorebdp.h index 2f1e06e84..285bf7e9e 100644 --- a/xwords4/common/scorebdp.h +++ b/xwords4/common/scorebdp.h @@ -1,6 +1,6 @@ /* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */ /* - * Copyright 1997 - 2006 by Eric House (xwords@eehouse.org). All rights reserved. + * Copyright 1997 - 2007 by Eric House (xwords@eehouse.org). All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -31,7 +31,8 @@ XP_Bool handlePenUpScore( BoardCtxt* board, XP_U16 x, XP_U16 y ); #endif #ifdef KEYBOARD_NAV -XP_Bool moveScoreCursor( BoardCtxt* board, XP_Key key, XP_Bool* up ); +XP_Bool moveScoreCursor( BoardCtxt* board, XP_Key key, XP_Bool preflightOnly, + XP_Bool* up ); #endif #endif diff --git a/xwords4/common/tray.c b/xwords4/common/tray.c index a767e2d05..2c0327612 100644 --- a/xwords4/common/tray.c +++ b/xwords4/common/tray.c @@ -1,6 +1,6 @@ /* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */ /* - * Copyright 1997 - 2006 by Eric House (xwords@eehouse.org). All rights reserved. + * Copyright 1997 - 2007 by Eric House (xwords@eehouse.org). All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -638,12 +638,14 @@ board_juggleTray( BoardCtxt* board ) #ifdef KEYBOARD_NAV XP_Bool -tray_moveCursor( BoardCtxt* board, XP_Key cursorKey, XP_Bool* pUp ) +tray_moveCursor( BoardCtxt* board, XP_Key cursorKey, XP_Bool preflightOnly, + XP_Bool* pUp ) { XP_Bool draw = XP_FALSE; XP_Bool up = XP_FALSE; XP_U16 selPlayer = board->selPlayer; XP_S16 pos; + TileBit what = 0; switch ( cursorKey ) { case XP_CURSOR_KEY_UP: @@ -657,12 +659,12 @@ tray_moveCursor( BoardCtxt* board, XP_Key cursorKey, XP_Bool* pUp ) etc. */ case XP_CURSOR_KEY_ALTRIGHT: case XP_CURSOR_KEY_ALTLEFT: - draw = board_moveDivider( board, cursorKey == XP_CURSOR_KEY_ALTRIGHT ); + draw = preflightOnly + || board_moveDivider( board, cursorKey == XP_CURSOR_KEY_ALTRIGHT ); break; case XP_CURSOR_KEY_RIGHT: case XP_CURSOR_KEY_LEFT: - board_invalTrayTiles( board, 1 << board->trayCursorLoc[selPlayer] ); - + what = what | (1 << board->trayCursorLoc[selPlayer]); pos = board->trayCursorLoc[selPlayer]; /* Loop in order to skip all empty tile slots but one */ for ( ; ; ) { @@ -680,12 +682,17 @@ tray_moveCursor( BoardCtxt* board, XP_Key cursorKey, XP_Bool* pUp ) continue; } } - board->trayCursorLoc[selPlayer] = pos; - board_invalTrayTiles( board, 1 << pos ); + if ( !preflightOnly ) { + board->trayCursorLoc[selPlayer] = pos; + what = what | (1 << pos); + } } break; } - board_invalTrayTiles( board, 1 << board->trayCursorLoc[selPlayer] ); + if ( !preflightOnly ) { + what = what | (1 << board->trayCursorLoc[selPlayer]); + board_invalTrayTiles( board, what ); + } draw = XP_TRUE; break; default: