diff --git a/xwords4/palm/Makefile b/xwords4/palm/Makefile index d93384234..a255f2f3f 100644 --- a/xwords4/palm/Makefile +++ b/xwords4/palm/Makefile @@ -1,5 +1,6 @@ # -*- mode: Makefile; compile-command: "make ARCH=68K_ONLY MEMDEBUG=TRUE"; -*- -# Copyright 2002 by Eric House (xwords@eehouse.org). All rights reserved. +# Copyright 2002-2006 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 @@ -163,16 +164,18 @@ BITMAP_RSRCS = \ # INCLUDES += -I/usr/local/share/palmdev/sdk-5r3/Extensions/ExpansionMgr INCLUDES += -I/usr/local/share/palmdev/sdk-5r3/include/Extensions/Bluetooth -# HS_DUO_SUPPORT = 1 +XWFEATURE_FIVEWAY = -DXWFEATURE_FIVEWAY -ifneq (x$(HS_DUO_SUPPORT)x, xx) - INCLUDES += -I/usr/local/share/palmdev/duoIncs - INCLUDES += -I/usr/local/share/palmdev/duoIncs/68K - INCLUDES += -I/usr/local/share/palmdev/duoIncs/68K/System - INCLUDES += -I/usr/local/share/palmdev/duoIncs/Common/System +ifneq (x$(XWFEATURE_FIVEWAY)x, xx) + INCLUDES += -I/usr/local/share/palmdev/Handspring5 + INCLUDES += -I/usr/local/share/palmdev/Handspring5/68K +# INCLUDES += -I/usr/local/share/palmdev/duoIncs +# INCLUDES += -I/usr/local/share/palmdev/duoIncs/68K +# INCLUDES += -I/usr/local/share/palmdev/duoIncs/68K/System +# INCLUDES += -I/usr/local/share/palmdev/duoIncs/Common/System - MYDEFS_68K += -DHS_DUO_SUPPORT - MYDEFS_ARM += -DHS_DUO_SUPPORT + MYDEFS_68K += $(XWFEATURE_FIVEWAY) + MYDEFS_ARM += $(XWFEATURE_FIVEWAY) FNAVS = ./fnav03e9.bin endif @@ -226,10 +229,8 @@ CFLAGS += -Wall -DAPPID=\'$(APPID)\' $(MYDEFS_68K) $(INCLUDES) $(TARGET): $(PLATFORM)/objs.prc $(PLATFORM)/res.prc $(PAR) -c -a 'resource|backup' -v 4 $@ $(NAME) $(TYPE) $(APPID) $^ -ifdef XW_UPLOAD_CMD - zip $(TARGET).zip $(TARGET) - $(XW_UPLOAD_CMD) $(TARGET) - $(XW_UPLOAD_CMD) $(TARGET).zip +ifdef XW_UPLOAD_SCRIPT + $(XW_UPLOAD_SCRIPT) $@ endif solo: diff --git a/xwords4/palm/common.rcp.pre b/xwords4/palm/common.rcp.pre index ad84214a6..137084ae7 100644 --- a/xwords4/palm/common.rcp.pre +++ b/xwords4/palm/common.rcp.pre @@ -95,11 +95,11 @@ NOFRAME MENUID XW_MAIN_MENU_ID BEGIN BUTTON "" XW_MAIN_FLIP_BUTTON_ID - AT (PALM_FLIP_LEFT PALM_BOARD_TOP FLIP_BUTTON_WIDTH + AT (PALM_FLIP_LEFT PALM_BOARD_TOP FLIP_BUTTON_WIDTH FLIP_BUTTON_HEIGHT) NOFRAME BUTTON "" XW_MAIN_VALUE_BUTTON_ID - AT (PALM_FLIP_LEFT PREVBOTTOM+2 - FLIP_BUTTON_WIDTH FLIP_BUTTON_HEIGHT+2) NOFRAME + AT (PALM_FLIP_LEFT PREVBOTTOM+2 + FLIP_BUTTON_WIDTH FLIP_BUTTON_HEIGHT+2) NOFRAME BUTTON "" XW_MAIN_HINT_BUTTON_ID AT (PALM_FLIP_LEFT PREVBOTTOM+2 FLIP_BUTTON_WIDTH FLIP_BUTTON_HEIGHT+3) NOFRAME @@ -129,7 +129,7 @@ BEGIN GADGET GREMLIN_BOARD_GADGET_IDAUTOID AT ( 0 5 152 135 ) GADGET GREMLIN_TRAY_GADGET_IDAUTOID AT ( 0 140 145 20 ) #endif -END +END /* XW_MAIN_FORM */ STRING ID 1000 "/palm/programs/Crosswords/" diff --git a/xwords4/palm/connsdlg.c b/xwords4/palm/connsdlg.c index f0d6f69aa..e5580de06 100644 --- a/xwords4/palm/connsdlg.c +++ b/xwords4/palm/connsdlg.c @@ -41,6 +41,7 @@ typedef struct ConnsDlgState { ListPtr connTypesList; XP_U16 serverRole; XP_Bool isNewGame; + CommsConnType conType; CommsAddrRec* addr; XP_BtAddr btAddr; /* since there's no field, save it here */ XP_BtAddrStr tmp; @@ -51,11 +52,12 @@ static void ctlsFromState( PalmAppGlobals* XP_UNUSED_BT(globals), ConnsDlgState* state ) { CommsAddrRec* addr = state->addr; + XP_Bool isNewGame = state->isNewGame; + state->conType = addr->conType; if ( 0 ) { #ifdef XWFEATURE_RELAY } else if ( addr->conType == COMMS_CONN_RELAY ) { - XP_Bool isNewGame = state->isNewGame; XP_UCHAR buf[16]; setFieldStr( XW_CONNS_RELAY_FIELD_ID, addr->u.ip_relay.hostName ); setFieldEditable( XW_CONNS_RELAY_FIELD_ID, isNewGame ); @@ -77,16 +79,18 @@ ctlsFromState( PalmAppGlobals* XP_UNUSED_BT(globals), ConnsDlgState* state ) } else { CtlSetLabel( ctrl, addr->u.bt.hostName ); } + CtlSetEnabled( ctrl, isNewGame ); #endif } } /* ctlsFromState */ -static XP_Bool +static void stateFromCtls( ConnsDlgState* state ) { - XP_Bool ok = XP_TRUE; CommsAddrRec* addr = state->addr; + addr->conType = state->conType; + if ( 0 ) { #ifdef XWFEATURE_RELAY } else if ( addr->conType == COMMS_CONN_RELAY ) { @@ -111,8 +115,6 @@ stateFromCtls( ConnsDlgState* state ) LOG_HEX( &addr->u.bt.btAddr, sizeof(addr->u.bt.btAddr), __FUNCTION__ ); #endif } - - return ok; } /* stateFromCtls */ static void @@ -144,9 +146,9 @@ updateFormCtls( FormPtr form, ConnsDlgState* state ) const XP_U16* on; XP_U16 i; - if ( state->addr->conType == COMMS_CONN_RELAY ) { + if ( state->conType == COMMS_CONN_RELAY ) { on = relayCtls; - } else if ( state->addr->conType == COMMS_CONN_BT + } else if ( state->conType == COMMS_CONN_BT #ifdef XWFEATURE_BLUETOOTH && state->serverRole == SERVER_ISCLIENT #endif @@ -249,15 +251,15 @@ ConnsFormHandleEvent( EventPtr event ) XP_MEMCPY( &state->btAddr, &state->addr->u.bt.btAddr, sizeof(state->btAddr) ); + ctlsFromState( globals, state ); + /* setup connection popup */ state->connTypesList = getActiveObjectPtr( XW_CONNS_TYPE_LIST_ID ); - XP_ASSERT( state->addr->conType == COMMS_CONN_IR - || state->addr->conType == COMMS_CONN_RELAY - || state->addr->conType == COMMS_CONN_BT ); + XP_ASSERT( state->conType == COMMS_CONN_IR + || state->conType == COMMS_CONN_RELAY + || state->conType == COMMS_CONN_BT ); setSelectorFromList( XW_CONNS_TYPE_TRIGGER_ID, state->connTypesList, - conTypeToSel(state->addr->conType) ); - - ctlsFromState( globals, state ); + conTypeToSel(state->conType) ); updateFormCtls( form, state ); @@ -272,7 +274,9 @@ ConnsFormHandleEvent( EventPtr event ) #ifdef XWFEATURE_BLUETOOTH case XW_CONNS_BT_HOSTTRIGGER_ID: - browseForDeviceName( globals, state ); + if ( state->isNewGame ) { + browseForDeviceName( globals, state ); + } break; #endif @@ -282,7 +286,7 @@ ConnsFormHandleEvent( EventPtr event ) if ( chosen >= 0 ) { setSelectorFromList( XW_CONNS_TYPE_TRIGGER_ID, state->connTypesList, chosen ); - state->addr->conType = selToConType( chosen ); + state->conType = selToConType( chosen ); updateFormCtls( form, state ); } } @@ -291,15 +295,12 @@ ConnsFormHandleEvent( EventPtr event ) case XW_CONNS_OK_BUTTON_ID: if ( !state->isNewGame ) { /* do nothing; same as cancel */ - } else if ( !stateFromCtls( state ) ) { - beep(); - break; } else { - EventType eventToPost; - eventToPost.eType = connsSettingChgEvent; + EventType eventToPost = { .eType = connsSettingChgEvent }; + stateFromCtls( state ); EvtAddEventToQueue( &eventToPost ); } - + /* FALLTHRU */ case XW_CONNS_CANCEL_BUTTON_ID: cleanupExit( globals ); break; diff --git a/xwords4/palm/l10n/xwords4_en_US.rcp.pre b/xwords4/palm/l10n/xwords4_en_US.rcp.pre index 4374dbf2c..bea54a50f 100644 --- a/xwords4/palm/l10n/xwords4_en_US.rcp.pre +++ b/xwords4/palm/l10n/xwords4_en_US.rcp.pre @@ -1,6 +1,7 @@ -/* -*-mode: c; fill-column: 78; -*- */ +/* -*-mode: c; fill-column: 78; compile-command: "cd ../ && make ARCH=68K_ONLY MEMDEBUG=TRUE"; -*- */ /***************************************************************************** - * Copyright 1999 - 2002 by Eric House (xwords@eehouse.org) and others. All rights reserved. + * Copyright 1999 - 2006 by Eric House (xwords@eehouse.org) and others. 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 @@ -173,6 +174,18 @@ END PLAYER_ROBCHECK( num, offset ) \ PLAYER_PASSFIELD( num, offset ) +#define PLAYER_ROW_ID( num ) \ + ID XW_REMOTE_##num##_CHECKBOX_ID \ + ID XW_PLAYERNAME_##num##_FIELD_ID \ + ID XW_ROBOT_##num##_CHECKBOX_ID \ + ID XW_PLAYERPASSWD_##num##_TRIGGER_ID \ + +#define PLAYER_ROW_NAV( num ) \ + ROW XW_REMOTE_##num##_CHECKBOX_ID \ + ROW XW_PLAYERNAME_##num##_FIELD_ID \ + XW_ROBOT_##num##_CHECKBOX_ID \ + XW_PLAYERPASSWD_##num##_TRIGGER_ID \ + //#define SERVER_GROUP_ID 2000 #define SERVER_HEIGHT 12 @@ -183,12 +196,12 @@ BEGIN #ifndef XWFEATURE_STANDALONE_ONLY LABEL "Connect:" AUTOID AT (LEFTCOL SERVER_TOP) - GADGET ID XW_SOLO_GADGET_ID AT (PREVRIGHT+2 SERVER_TOP 53 SERVER_HEIGHT) - USABLE + GADGET ID XW_SOLO_GADGET_ID + AT (PREVRIGHT+2 SERVER_TOP 55 SERVER_HEIGHT) USABLE GADGET ID XW_SERVER_GADGET_ID - AT (PREVRIGHT+1 SERVER_TOP 22 SERVER_HEIGHT) USABLE + AT (PREVRIGHT+1 SERVER_TOP 24 SERVER_HEIGHT) USABLE GADGET ID XW_CLIENT_GADGET_ID - AT (PREVRIGHT+1 SERVER_TOP 28 SERVER_HEIGHT) USABLE + AT (PREVRIGHT+1 SERVER_TOP 30 SERVER_HEIGHT) USABLE LIST "Stand-alone" "Host" "Guest" XW_SERVERTYPES_LIST_ID AT (0 0 1 1) VISIBLEITEMS 3 NONUSABLE #endif @@ -225,7 +238,51 @@ BEGIN BUTTON "Ok" XW_OK_BUTTON_ID RIGHT@154 PREVTOP AUTO AUTO BUTTON "Cancel" XW_CANCEL_BUTTON_ID RIGHT@PREVLEFT-5 PREVTOP 30 AUTO -END /* FORM XW_PLAYERINFO_FORM */ +END /* XW_NEWGAMES_FORM */ + +#ifdef XWFEATURE_FIVEWAY +NAVIGATION ID XW_NEWGAMES_FORM +INITIALSTATE kFrmNavHeaderFlagsObjectFocusStartState +#if 0 +BEGIN + ID XW_SOLO_GADGET_ID + ID XW_SERVER_GADGET_ID + ID XW_CLIENT_GADGET_ID + + ID XW_NPLAYERS_SELECTOR_ID + ID XW_GINFO_JUGGLE_ID + ID XW_PREFS_BUTTON_ID + + PLAYER_ROW_ID( 1 ) + PLAYER_ROW_ID( 2 ) + PLAYER_ROW_ID( 3 ) + PLAYER_ROW_ID( 4 ) + + ID XW_DICT_SELECTOR_ID + ID XW_CANCEL_BUTTON_ID + ID XW_OK_BUTTON_ID +#else +NAVIGATIONMAP +#ifndef XWFEATURE_STANDALONE_ONLY + ROW XW_SOLO_GADGET_ID + XW_SERVER_GADGET_ID + XW_CLIENT_GADGET_ID +#endif + ROW XW_NPLAYERS_SELECTOR_ID + XW_GINFO_JUGGLE_ID + XW_PREFS_BUTTON_ID + + PLAYER_ROW_NAV( 1 ) + PLAYER_ROW_NAV( 2 ) + PLAYER_ROW_NAV( 3 ) + PLAYER_ROW_NAV( 4 ) + + ROW XW_DICT_SELECTOR_ID + XW_CANCEL_BUTTON_ID + XW_OK_BUTTON_ID +#endif +END /* NAVIGATION ID XW_NEWGAMES_FORM */ +#endif #if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH || defined XWFEATURE_IR #define LEFTCOL 4 @@ -297,41 +354,43 @@ END /* XW_CONNS_FORM */ #define PREFS_MODE_TOP 15 #define PREFS_TOP 30 -#define DLG_TOP (52-TRAY_EDIT_ADJUST-SEARCHLIMIT_ADJUST) -#define DLG_HEIGHT (107+TRAY_EDIT_ADJUST+SEARCHLIMIT_ADJUST) +/* #define DLG_TOP (52-TRAY_EDIT_ADJUST-SEARCHLIMIT_ADJUST) */ +#define DLG_HEIGHT (112+TRAY_EDIT_ADJUST+SEARCHLIMIT_ADJUST) +#define DLG_TOP (160 - DLG_HEIGHT - 2) #define TIMER_TOP (74+SEARCHLIMIT_ADJUST) #define BUTTON_TOP (TIMER_TOP+16+TRAY_EDIT_ADJUST) +#define PREFS_LNHT 4 FORM ID XW_PREFS_FORM AT (2 DLG_TOP 156 DLG_HEIGHT) USABLE MODAL SAVEBEHIND DEFAULTBTNID XW_PREFS_CANCEL_BUTTON_ID BEGIN TITLE "Preferences" - GADGET ID XW_PREFS_APPWIDE_CHECKBX_ID - AT (LEFTCOL+8 PREFS_MODE_TOP 75 SERVER_HEIGHT) USABLE - GADGET ID XW_PREFS_ONEGAME_CHECKBX_ID - AT (PREVRIGHT+1 PREVTOP 50 SERVER_HEIGHT) USABLE - LIST "Application-wide" "This game" XW_PREFS_TYPES_LIST_ID + GADGET ID XW_PREFS_ALLGAMES_GADGET_ID + AT (LEFTCOL+8 PREFS_MODE_TOP 60 SERVER_HEIGHT) USABLE + GADGET ID XW_PREFS_ONEGAME_GADGET_ID + AT (PREVRIGHT+1 PREVTOP 60 SERVER_HEIGHT) USABLE + LIST "All games" "This game" XW_PREFS_TYPES_LIST_ID AT (0 0 1 1) VISIBLEITEMS 2 NONUSABLE /* global prefs */ CHECKBOX "Color played tiles" ID XW_PREFS_PLAYERCOLORS_CHECKBOX_ID \ AT (LEFTCOL PREFS_TOP AUTO AUTO) NONUSABLE CHECKBOX "Show progress bar" ID XW_PREFS_PROGRESSBAR_CHECKBOX_ID \ - AT (LEFTCOL PREVBOTTOM+3 AUTO AUTO) NONUSABLE + AT (LEFTCOL PREVBOTTOM+PREFS_LNHT AUTO AUTO) NONUSABLE CHECKBOX "Larger board" ID XW_PREFS_SHOWGRID_CHECKBOX_ID \ - AT (LEFTCOL PREVBOTTOM+3 AUTO AUTO) NONUSABLE + AT (LEFTCOL PREVBOTTOM+PREFS_LNHT AUTO AUTO) NONUSABLE CHECKBOX "Enable arrow cursor" ID XW_PREFS_SHOWARROW_CHECKBOX_ID \ - AT (LEFTCOL PREVBOTTOM+3 AUTO AUTO) NONUSABLE + AT (LEFTCOL PREVBOTTOM+PREFS_LNHT AUTO AUTO) NONUSABLE CHECKBOX "Explain robot scores" ID XW_PREFS_ROBOTSCORE_CHECKBOX_ID \ - AT (LEFTCOL PREVBOTTOM+3 AUTO AUTO) NONUSABLE + AT (LEFTCOL PREVBOTTOM+PREFS_LNHT AUTO AUTO) NONUSABLE /* single-game prefs */ CHECKBOX "Smart robot" ID XW_PREFS_ROBOTSMART_CHECKBOX_ID \ AT (LEFTCOL PREFS_TOP AUTO AUTO) NONUSABLE #ifdef XWFEATURE_SEARCHLIMIT CHECKBOX "Disallow hints" ID XW_PREFS_NOHINTS_CHECKBOX_ID \ - AT (LEFTCOL PREVBOTTOM+3 AUTO AUTO) NONUSABLE + AT (LEFTCOL PREVBOTTOM+PREFS_LNHT AUTO AUTO) NONUSABLE CHECKBOX "Local hints" ID XW_PREFS_HINTRECT_CHECKBOX_ID \ AT (PREVRIGHT+3 PREVTOP AUTO AUTO) NONUSABLE #else @@ -339,7 +398,8 @@ BEGIN AT (PREVRIGHT+3 PREVTOP AUTO AUTO) NONUSABLE #endif - LABEL "Phonies:" XW_PREFS_PHONIES_LABEL_ID AT (LEFTCOL PREVBOTTOM+3) + LABEL "Phonies:" XW_PREFS_PHONIES_LABEL_ID + AT (LEFTCOL PREVBOTTOM+PREFS_LNHT) POPUPTRIGGER "" ID XW_PREFS_PHONIES_TRIGGER_ID AT (PREVRIGHT+5 PREVTOP 72 12) LEFTANCHOR @@ -368,6 +428,40 @@ BEGIN /* buttons at the bottom */ BUTTON "Cancel" XW_PREFS_CANCEL_BUTTON_ID 42 BUTTON_TOP AUTO AUTO BUTTON "Ok" XW_PREFS_OK_BUTTON_ID PREVRIGHT+10 PREVTOP AUTO AUTO +END /* XW_PREFS_FORM */ + +NAVIGATION ID XW_PREFS_FORM +INITIALSTATE kFrmNavHeaderFlagsObjectFocusStartState +INITIALOBJECTID XW_PREFS_ONEGAME_GADGET_ID +NAVIGATIONMAP + ROW XW_PREFS_ALLGAMES_GADGET_ID + XW_PREFS_ONEGAME_GADGET_ID + + /* global prefs */ + ROW XW_PREFS_PLAYERCOLORS_CHECKBOX_ID + ROW XW_PREFS_PROGRESSBAR_CHECKBOX_ID + ROW XW_PREFS_SHOWGRID_CHECKBOX_ID + ROW XW_PREFS_SHOWARROW_CHECKBOX_ID + ROW XW_PREFS_ROBOTSCORE_CHECKBOX_ID + + /* Per-game prefs */ + ROW XW_PREFS_ROBOTSMART_CHECKBOX_ID + ROW XW_PREFS_NOHINTS_CHECKBOX_ID +#ifdef XWFEATURE_SEARCHLIMIT + XW_PREFS_HINTRECT_CHECKBOX_ID +#endif + ROW XW_PREFS_PHONIES_TRIGGER_ID + ROW XW_PREFS_BDSIZE_SELECTOR_ID + + ROW XW_PREFS_TIMERON_CHECKBOX_ID + XW_PREFS_TIMER_FIELD_ID +#ifdef FEATURE_TRAY_EDIT + ROW XW_PREFS_PICKTILES_CHECKBOX_ID +#endif + + /* cmd buttons */ + ROW XW_PREFS_CANCEL_BUTTON_ID + XW_PREFS_OK_BUTTON_ID END #define LEFT_EDGE 10 diff --git a/xwords4/palm/newgame.c b/xwords4/palm/newgame.c index 56cc08e10..f419a4d02 100644 --- a/xwords4/palm/newgame.c +++ b/xwords4/palm/newgame.c @@ -24,7 +24,7 @@ #include /* for nextFieldChr */ #include /* for GrfSetState */ #include -#ifdef HS_DUO_SUPPORT +#ifdef XWFEATURE_FIVEWAY # include #endif @@ -45,26 +45,14 @@ static void handlePasswordTrigger( PalmAppGlobals* globals, UInt16 controlID ); static void updatePlayerInfo( PalmAppGlobals* globals ); -static XP_Bool tryFieldNavigationKey( XP_U16 key ); static void loadNewGameState( PalmAppGlobals* globals ); static void unloadNewGameState( PalmAppGlobals* globals ); static void setNameThatFits( PalmNewGameState* state ); -#ifdef HS_DUO_SUPPORT -static XP_Bool tryDuoRockerKey( PalmAppGlobals* globals,XP_U16 key ); -static XP_Bool considerGadgetFocus( PalmNewGameState* state, EventType* event ); -#else -# define tryDuoRockerKey(g,key) XP_FALSE -#endif - -static XP_Bool onDisabledList( const PalmNewGameState* state, - XP_U16 controlID ); -static void modDisabledList( PalmNewGameState* state, XP_U16 controlID, - NewGameEnable enable ); static void palmEnableColProc( void* closure, XP_U16 player, - NewGameColumn col, NewGameEnable enable ); + NewGameColumn col, XP_TriEnable enable ); static void palmEnableAttrProc( void* closure, NewGameAttr attr, - NewGameEnable enable ); + XP_TriEnable enable ); static void palmGetColProc( void* closure, XP_U16 player, NewGameColumn col, NgCpCallbk cpcb, const void* cbClosure ); static void palmSetColProc( void* closure, XP_U16 player, NewGameColumn col, @@ -77,7 +65,8 @@ static void handleRobotChanged( PalmNewGameState* state, XP_U16 controlID, #ifndef XWFEATURE_STANDALONE_ONLY static void handleRemoteChanged( PalmNewGameState* state, XP_U16 controlID, XP_Bool on ); -static Boolean checkHiliteGadget(PalmAppGlobals* globals, EventType* event, +static Boolean checkHiliteGadget(PalmAppGlobals* globals, + const EventType* event, PalmNewGameState* state ); static void drawConnectGadgets( PalmAppGlobals* globals ); static void changeGadgetHilite( PalmAppGlobals* globals, UInt16 hiliteID ); @@ -87,10 +76,6 @@ static void changeGadgetHilite( PalmAppGlobals* globals, UInt16 hiliteID ); # define drawConnectGadgets( globals ) #endif -#define IS_SERVER_GADGET(id) \ - ((id) >= XW_SOLO_GADGET_ID && (id) <= XW_CLIENT_GADGET_ID) - - /***************************************************************************** * ****************************************************************************/ @@ -104,7 +89,7 @@ newGameHandleEvent( EventPtr event ) CurGameInfo* gi; PalmNewGameState* state; Int16 chosen; - XP_U16 controlID; + XP_U16 itemId; Boolean on; CALLBACK_PROLOGUE(); @@ -126,14 +111,9 @@ newGameHandleEvent( EventPtr event ) state->form = form; -#ifndef XWFEATURE_STANDALONE_ONLY - sizeGadgetsForStrings( form, - getActiveObjectPtr( XW_SERVERTYPES_LIST_ID ), - XW_SOLO_GADGET_ID ); -#endif loadNewGameState( globals ); if ( !globals->isNewGame ) { - modDisabledList( state, XW_DICT_SELECTOR_ID, NGEnableDisabled ); + disOrEnableTri( form, XW_DICT_SELECTOR_ID, TRI_ENAB_DISABLED ); } XP_ASSERT( !!state->dictName ); @@ -156,10 +136,13 @@ newGameHandleEvent( EventPtr event ) break; #endif -#ifdef HS_DUO_SUPPORT +#ifdef XWFEATURE_FIVEWAY + /* docs say to return HANDLED for both take and lost if the right + object */ case frmObjectFocusTakeEvent: case frmObjectFocusLostEvent: - result = considerGadgetFocus( state, event ); + result = considerGadgetFocus( event, XW_SOLO_GADGET_ID, + XW_CLIENT_GADGET_ID ); break; #endif @@ -167,41 +150,39 @@ newGameHandleEvent( EventPtr event ) result = checkHiliteGadget( globals, event, state ); break; +#ifdef XWFEATURE_FIVEWAY case keyDownEvent: - result = tryFieldNavigationKey( event->data.keyDown.chr ) - || tryDuoRockerKey( globals, event->data.keyDown.chr ); + itemId = getFocusOwner(); + result = tryRockerKey( event->data.keyDown.chr, itemId, + XW_SOLO_GADGET_ID, XW_CLIENT_GADGET_ID ); + if ( result ) { + changeGadgetHilite( globals, itemId ); + } break; +#endif case prefsChangedEvent: state->forwardChange = true; break; - case fldEnterEvent: - case ctlEnterEvent: - if ( onDisabledList( state, event->data.ctlEnter.controlID ) ) { - result = true; - beep(); - } - break; - case ctlSelectEvent: result = true; - controlID = event->data.ctlSelect.controlID; + itemId = event->data.ctlSelect.controlID; on = event->data.ctlSelect.on; - switch ( controlID ) { + switch ( itemId ) { case XW_ROBOT_1_CHECKBOX_ID: case XW_ROBOT_2_CHECKBOX_ID: case XW_ROBOT_3_CHECKBOX_ID: case XW_ROBOT_4_CHECKBOX_ID: - handleRobotChanged( state, controlID, on ); + handleRobotChanged( state, itemId, on ); break; #ifndef XWFEATURE_STANDALONE_ONLY case XW_REMOTE_1_CHECKBOX_ID: case XW_REMOTE_2_CHECKBOX_ID: case XW_REMOTE_3_CHECKBOX_ID: case XW_REMOTE_4_CHECKBOX_ID: - handleRemoteChanged( state, controlID, on ); + handleRemoteChanged( state, itemId, on ); break; #endif @@ -278,7 +259,7 @@ newGameHandleEvent( EventPtr event ) case XW_PLAYERPASSWD_2_TRIGGER_ID: case XW_PLAYERPASSWD_3_TRIGGER_ID: case XW_PLAYERPASSWD_4_TRIGGER_ID: - handlePasswordTrigger( globals, controlID ); + handlePasswordTrigger( globals, itemId ); break; default: /* one of the password selectors? */ @@ -329,106 +310,6 @@ setNameThatFits( PalmNewGameState* state ) (const char*)state->shortDictName ); } /* setNameThatFits */ -static Boolean -tryFieldNavigationKey( XP_U16 key ) -{ - FormPtr form; - Int16 curFocus, nextFocus, change; - UInt16 nObjects; - - if ( key == prevFieldChr ) { - change = -1; - } else if ( key == nextFieldChr ) { - change = 1; - } else { - return false; - } - - form = FrmGetActiveForm(); - curFocus = nextFocus = FrmGetFocus( form ); - nObjects = FrmGetNumberOfObjects(form); - - /* find the next (in either direction) usable field */ - for ( ; ; ) { - nextFocus += change; - - if ( nextFocus == nObjects ) { - nextFocus = 0; - } else if ( nextFocus < 0 ) { - nextFocus = nObjects-1; - } - - if ( nextFocus == curFocus ) { - break; - } else if ( FrmGetObjectType(form, nextFocus) != frmFieldObj ) { - continue; - } else { - FieldPtr field = FrmGetObjectPtr( form, nextFocus ); - FieldAttrType attrs; - FldGetAttributes( field, &attrs ); - if ( attrs.usable ) { - break; - } - } - } - - FrmSetFocus( form, nextFocus ); - return true; -} /* tryFieldNavigationKey */ - -#ifdef HS_DUO_SUPPORT -#ifdef DEBUG -static XP_UCHAR* -keyToStr( XP_U16 key ) -{ -#define keyCase(k) case (k): return #k - switch( key ) { - keyCase(vchrRockerUp); - keyCase(vchrRockerDown); - keyCase(vchrRockerLeft); - keyCase(vchrRockerRight); - keyCase(vchrRockerCenter); - default: - return "huh?"; - } -#undef keyCase -} -#endif - -static XP_Bool -tryDuoRockerKey( PalmAppGlobals* globals, XP_U16 key ) -{ - XP_Bool result = XP_FALSE; - XP_U16 focusID; - FormPtr form; - - switch( key ) { - case vchrRockerUp: - case vchrRockerDown: - case vchrRockerLeft: - case vchrRockerRight: - XP_LOGF( "got rocker key: %s", keyToStr(key) ); - result = XP_FALSE; - break; - case vchrRockerCenter: - /* if one of the gadgets is focussed, "tap" it. */ - XP_LOGF( "got rocker key: %s", keyToStr(key) ); - form = FrmGetActiveForm(); - focusID = FrmGetObjectId( form, FrmGetFocus( form ) ); - if ( IS_SERVER_GADGET( focusID ) ) { - changeGadgetHilite( globals, focusID ); - result = XP_TRUE; - } else { - XP_LOGF( "%d not server gadget", focusID ); - } - break; - default: - break; - } - return result; -} /* tryDuoRockerKey */ -#endif /* #ifdef HS_DUO_SUPPORT */ - /* * Copy the local state into global state. */ @@ -447,109 +328,25 @@ updatePlayerInfo( PalmAppGlobals* globals ) globals->newGameState.dictName ); } /* updatePlayerInfo */ -void -drawOneGadget( UInt16 id, char* text, Boolean hilite ) -{ - RectangleType divRect; - XP_U16 len = XP_STRLEN(text); - XP_U16 width = FntCharsWidth( text, len ); - XP_U16 left; - - getObjectBounds( id, &divRect ); - WinDrawRectangleFrame( rectangleFrame, &divRect ); - WinEraseRectangle( &divRect, 0 ); - left = divRect.topLeft.x; - left += (divRect.extent.x - width) / 2; - WinDrawChars( text, len, left, divRect.topLeft.y ); - if ( hilite ) { - WinInvertRectangle( &divRect, 0 ); - } -} /* drawOneGadget */ - /* Frame 'em, draw their text, and highlight the one that's selected */ #ifndef XWFEATURE_STANDALONE_ONLY -#ifdef HS_DUO_SUPPORT -static void -drawFocusRingOnGadget() -{ - FormPtr form = FrmGetActiveForm(); - XP_U16 focusID = FrmGetObjectId( form, FrmGetFocus(form) ); - if ( IS_SERVER_GADGET(focusID) ) { - Err err; - RectangleType rect; - - getObjectBounds( focusID, &rect ); - - err = HsNavDrawFocusRing( form, focusID, 0, &rect, - hsNavFocusRingStyleObjectTypeDefault, - false ); - XP_ASSERT( err == errNone ); - } -} /* drawFocusRingOnGadget */ -#endif - static void drawConnectGadgets( PalmAppGlobals* globals ) { - UInt16 i; + XP_U16 hiliteItem = globals->newGameState.curServerHilite + + XW_SOLO_GADGET_ID ; ListPtr list = getActiveObjectPtr( XW_SERVERTYPES_LIST_ID ); XP_ASSERT( !!list ); - for ( i = 0; i < 3; ++i ) { - char* text = LstGetSelectionText( list, i ); - Boolean hilite = i == globals->newGameState.curServerHilite; - drawOneGadget( i + XW_SOLO_GADGET_ID, text, hilite ); - } - -#ifdef HS_DUO_SUPPORT - drawFocusRingOnGadget(); + drawGadgetsFromList( list, XW_SOLO_GADGET_ID, XW_CLIENT_GADGET_ID, + hiliteItem ); +#ifdef XWFEATURE_FIVEWAY + drawFocusRingOnGadget( XW_SOLO_GADGET_ID, XW_CLIENT_GADGET_ID ); #endif - } /* drawConnectGadgets */ -#ifdef HS_DUO_SUPPORT -static XP_Bool -considerGadgetFocus( PalmNewGameState* state, EventType* event ) -{ - XP_Bool result = XP_FALSE; - XP_Bool isTake; - XP_U16 eType = event->eType; - FormPtr form = FrmGetActiveForm(); - XP_U16 objectID; - - XP_ASSERT( eType == frmObjectFocusTakeEvent - || eType == frmObjectFocusLostEvent ); - XP_ASSERT( event->data.frmObjectFocusTake.formID == FrmGetActiveFormID() ); - - - isTake = eType == frmObjectFocusTakeEvent; - if ( isTake ) { - objectID = event->data.frmObjectFocusTake.objectID; - } else { - objectID = event->data.frmObjectFocusLost.objectID; - } - - /* docs say to return HANDLED for both take and lost */ - result = IS_SERVER_GADGET( objectID ); - - if ( result ) { - Err err; - if ( isTake ) { - - FrmSetFocus(form, FrmGetObjectIndex(form, objectID)); - drawFocusRingOnGadget(); - result = XP_TRUE; -/* } else { */ -/* err = HsNavRemoveFocusRing( form ); */ - } - } - - return result; -} /* considerGadgetFocus */ -#endif - static void changeGadgetHilite( PalmAppGlobals* globals, UInt16 hiliteID ) { @@ -585,7 +382,7 @@ changeGadgetHilite( PalmAppGlobals* globals, UInt16 hiliteID ) } /* changeGadgetHilite */ static Boolean -checkHiliteGadget( PalmAppGlobals* globals, EventType* event, +checkHiliteGadget( PalmAppGlobals* globals, const EventType* event, PalmNewGameState* XP_UNUSED_DBG(state) ) { Boolean result = false; @@ -647,46 +444,6 @@ unloadNewGameState( PalmAppGlobals* globals ) state->ngc = NULL; } /* unloadNewGameState */ -static XP_S16 -findDisabled( const PalmNewGameState* state, XP_U16 controlID ) -{ - XP_U16 i; - XP_S16 loc = -1; - for ( i = 0; i < state->nDisabled; ++i ) { - if ( state->disabled[i] == controlID ) { - loc = i; - break; - } - } - return loc; -} - -static XP_Bool -onDisabledList( const PalmNewGameState* state, XP_U16 controlID ) -{ - return 0 <= findDisabled( state, controlID ); -} - -static void -modDisabledList( PalmNewGameState* state, XP_U16 controlID, - NewGameEnable enable ) -{ - XP_S16 loc = findDisabled( state, controlID ); - XP_Bool include = enable != NGEnableEnabled; - if ( loc < 0 && include ) { - /* not there but should be; add it */ - state->disabled[state->nDisabled++] = controlID; - XP_ASSERT( state->nDisabled < MAX_DISABLED ); - } else if ( loc >= 0 && !include ) { - /* is there; shouldn't be; remove it */ - state->disabled[loc] = state->disabled[--state->nDisabled]; - } else { - /* all's well */ - XP_ASSERT( (loc >= 0 && include) - || ( loc < 0 && !include ) ); - } -} - static XP_U16 getBaseForCol( NewGameColumn col ) { @@ -730,13 +487,15 @@ getControlForCol( XP_U16 player, NewGameColumn col ) static void palmEnableColProc( void* closure, XP_U16 player, NewGameColumn col, - NewGameEnable enable ) + XP_TriEnable enable ) { PalmAppGlobals* globals = (PalmAppGlobals*)closure; PalmNewGameState* state = &globals->newGameState; - XP_U16 objID = objIDForCol( player, col ); - disOrEnable( state->form, objID, enable != NGEnableHidden ); - modDisabledList( state, objID, enable ); + XP_U16 objID; + + /* If it's a field, there need to be three states */ + objID = objIDForCol( player, col ); + disOrEnableTri( state->form, objID, enable ); } /* Palm doesn't really do "disabled." Things are visible or not. But we @@ -746,11 +505,10 @@ palmEnableColProc( void* closure, XP_U16 player, NewGameColumn col, * control is technically enabled. */ static void -palmEnableAttrProc(void* closure, NewGameAttr attr, NewGameEnable ngEnable ) +palmEnableAttrProc(void* closure, NewGameAttr attr, XP_TriEnable ngEnable ) { PalmAppGlobals* globals = (PalmAppGlobals*)closure; PalmNewGameState* state = &globals->newGameState; - XP_Bool enable = XP_FALSE; /* make compiler happy */ XP_U16 objID = 0; switch ( attr ) { @@ -759,25 +517,21 @@ palmEnableAttrProc(void* closure, NewGameAttr attr, NewGameEnable ngEnable ) /* always enabled */ break; case NG_ATTR_REMHEADER: - enable = ngEnable != NGEnableHidden; objID = XW_LOCAL_LABEL_ID; break; #endif case NG_ATTR_NPLAYERS: - enable = ngEnable != NGEnableHidden; objID = XW_NPLAYERS_SELECTOR_ID; break; case NG_ATTR_NPLAYHEADER: break; case NG_ATTR_CANJUGGLE: - enable = ngEnable == NGEnableEnabled; objID = XW_GINFO_JUGGLE_ID; break; } if ( objID != 0 ) { - disOrEnable( state->form, objID, enable ); - modDisabledList( state, objID, ngEnable ); + disOrEnableTri( state->form, objID, ngEnable ); } } /* palmEnableAttrProc */ @@ -854,8 +608,6 @@ palmSetAttrProc( void* closure, NewGameAttr attr, const NGValue value ) #ifndef XWFEATURE_STANDALONE_ONLY case NG_ATTR_ROLE: state->curServerHilite = value.ng_role; - /* Don't do this until frmUpdateEvent's been received... */ -/* drawConnectGadgets( globals ); */ break; case NG_ATTR_REMHEADER: break; diff --git a/xwords4/palm/newgame.h b/xwords4/palm/newgame.h index 6bd7fa885..b2dc9f0dd 100644 --- a/xwords4/palm/newgame.h +++ b/xwords4/palm/newgame.h @@ -27,6 +27,4 @@ Boolean newGameHandleEvent( EventPtr event ); -void drawOneGadget( UInt16 id, char* text, Boolean hilite ); - #endif diff --git a/xwords4/palm/palmmain.h b/xwords4/palm/palmmain.h index e85f6a0c2..fab5c8f68 100644 --- a/xwords4/palm/palmmain.h +++ b/xwords4/palm/palmmain.h @@ -200,9 +200,6 @@ typedef struct PalmNewGameState { XP_UCHAR* dictName; XP_UCHAR shortDictName[32]; /* as long as a dict name can be */ - XP_U16 disabled[MAX_DISABLED]; - XP_U16 nDisabled; - XP_Bool forwardChange; Connectedness curServerHilite; #if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH diff --git a/xwords4/palm/palmutil.c b/xwords4/palm/palmutil.c index 1bf505c25..af82764bf 100644 --- a/xwords4/palm/palmutil.c +++ b/xwords4/palm/palmutil.c @@ -25,6 +25,9 @@ #include #include #include +#ifdef XWFEATURE_FIVEWAY +# include +#endif #include "strutils.h" #include "palmutil.h" @@ -118,6 +121,38 @@ disOrEnable( FormPtr form, UInt16 id, Boolean enable ) } } /* disOrEnable */ +void +disOrEnableTri( FormPtr form, UInt16 id, XP_TriEnable enable ) +{ + UInt16 index; + XP_ASSERT( enable != TRI_ENAB_NONE ); + + index = FrmGetObjectIndex( form, id ); + + if ( enable == TRI_ENAB_HIDDEN ) { + FrmHideObject( form, index ); + } else { + FormObjectKind typ = FrmGetObjectType( form, index ); + XP_Bool active = enable == TRI_ENAB_ENABLED; + + FrmShowObject( form, index ); + + switch( typ ) { + case frmFieldObj: + setFieldEditable( id, active ); + break; + case frmControlObj: + CtlSetEnabled( getActiveObjectPtr( id ), enable ); + break; + case frmLabelObj: /* what to do? */ + break; + default: + XP_WARNF( "%s: %d not handled", __FUNCTION__, (XP_U16)typ ); + XP_ASSERT(0); + } + } +} /* disOrEnableTri */ + void disOrEnableSet( FormPtr form, const UInt16* ids, Boolean enable ) { @@ -310,52 +345,8 @@ setSelectorFromList( UInt16 triggerID, ListPtr list, XP_S16 listSelIndex ) LstGetSelectionText( list, listSelIndex ) ); } /* setTriggerFromList */ -#define MAX_GADGET_COUNT 3 /* the most we need at this point */ -void -sizeGadgetsForStrings( FormPtr form, ListPtr list, XP_U16 firstGadgetID ) -{ - XP_U16 i; - XP_U16 nGadgets = LstGetNumberOfItems( list ); - XP_U16 strWidths[MAX_GADGET_COUNT]; - XP_U16 totalStrWidth, totalGadgetWidth; - XP_U16 left, extra; - RectangleType rects[MAX_GADGET_COUNT]; - RectangleType* rp; - - XP_ASSERT( nGadgets <= MAX_GADGET_COUNT ); - - totalStrWidth = totalGadgetWidth = 0; - for ( i = 0, rp = rects; i < nGadgets; ++i, ++rp ) { - XP_U16 len; - XP_UCHAR* txt = (XP_UCHAR*)LstGetSelectionText( list, i ); - - len = XP_STRLEN( (const char*)txt ); - totalStrWidth += strWidths[i] = FntCharsWidth( (const char*)txt, len ); - - getObjectBounds( firstGadgetID+i, rp ); - totalGadgetWidth += rp->extent.x; - } - - XP_ASSERT( totalGadgetWidth >= totalStrWidth ); - extra = (totalGadgetWidth - totalStrWidth) / nGadgets; - - left = rects[0].topLeft.x; - for ( i = 0, rp = rects; i < nGadgets; ++i, ++rp ) { - UInt16 index; - UInt16 width; - - rp->topLeft.x = left; - rp->extent.x = width = strWidths[i] + extra; - - index = FrmGetObjectIndex( form, firstGadgetID+i ); - FrmSetObjectBounds( form, index, rp ); - - left += width; - } -} /* sizeGadgetsForStrings */ - XP_Bool -penInGadget( EventPtr event, UInt16* whichGadget ) +penInGadget( const EventType* event, UInt16* whichGadget ) { UInt16 x = event->screenX; UInt16 y = event->screenY; @@ -381,6 +372,130 @@ penInGadget( EventPtr event, UInt16* whichGadget ) return result; } /* penInGadget */ +void +drawOneGadget( UInt16 id, const char* text, Boolean hilite ) +{ + RectangleType divRect; + XP_U16 len = XP_STRLEN(text); + XP_U16 width = FntCharsWidth( text, len ); + XP_U16 left; + + getObjectBounds( id, &divRect ); + WinDrawRectangleFrame( rectangleFrame, &divRect ); + WinEraseRectangle( &divRect, 0 ); + left = divRect.topLeft.x; + left += (divRect.extent.x - width) / 2; + WinDrawChars( text, len, left, divRect.topLeft.y ); + if ( hilite ) { + WinInvertRectangle( &divRect, 0 ); + } +} /* drawOneGadget */ + +#ifdef XWFEATURE_FIVEWAY +XP_U16 +getFocusOwner( void ) +{ + FormPtr form = FrmGetActiveForm(); + XP_U16 ownerID = FrmGetObjectId( form, FrmGetFocus( form ) ); + return ownerID; +} /* getFocusOwner */ + +void +drawFocusRingOnGadget( XP_U16 idLow, XP_U16 idHigh ) +{ + FormPtr form; + XP_S16 index; + XP_U16 focusID; + + LOG_FUNC(); + + form = FrmGetActiveForm(); + index = FrmGetFocus( form ); + XP_LOGF( "%s: FrmGetFocus=>%d", __FUNCTION__, index ); + if ( index >= 0 ) { + focusID = FrmGetObjectId( form, index ); + XP_LOGF( "%s: FrmGetObjectId=>%d", __FUNCTION__, focusID ); + + if ( (focusID >= idLow) && (focusID <= idHigh) ) { + Err err; + RectangleType rect; + + getObjectBounds( focusID, &rect ); + XP_LOGF( "focusID=%d; index=%d", focusID, index ); + XP_LOGF( "rect=%d,%d,%d,%d", rect.topLeft.x, rect.topLeft.y, + rect.extent.x, rect.extent.y ); + + /* growing the rect didn't work to fix glitches in ring drawing. */ + + err = HsNavDrawFocusRing( form, focusID, 0, &rect, + hsNavFocusRingStyleObjectTypeDefault, + false ); + if ( err != errNone ) { + XP_LOGF( "%s: err=%d (0x%x)", __FUNCTION__, err, err ); + } + XP_ASSERT( err == errNone ); /* firing */ + } + } + LOG_RETURN_VOID(); +} /* drawFocusRingOnGadget */ + +XP_Bool +considerGadgetFocus( const EventType* event, XP_U16 idLow, XP_U16 idHigh ) +{ + XP_Bool handled; + XP_U16 objectID; + + XP_ASSERT( event->eType == frmObjectFocusLostEvent + || event->eType == frmObjectFocusTakeEvent ); + XP_ASSERT( event->data.frmObjectFocusTake.formID == FrmGetActiveFormID() ); + XP_ASSERT( &event->data.frmObjectFocusTake.objectID + == &event->data.frmObjectFocusLost.objectID ); + + objectID = event->data.frmObjectFocusTake.objectID; + XP_LOGF( "%s: objectID=%d", __FUNCTION__, objectID ); + handled = (objectID >= idLow) && (objectID <= idHigh); + if ( handled ) { + if ( event->eType == frmObjectFocusTakeEvent ) { + FormPtr form = FrmGetActiveForm(); + FrmSetFocus( form, FrmGetObjectIndex(form, objectID) ); + drawFocusRingOnGadget( idLow, idHigh ); + } + } + + LOG_RETURNF( "%d", (XP_U16)handled ); + return handled; +} /* considerGadgetFocus */ + +XP_Bool +tryRockerKey( XP_U16 key, XP_U16 selGadget, XP_U16 idLow, XP_U16 idHigh ) +{ + XP_Bool result = XP_FALSE; + + if ( vchrRockerCenter == key ) { + if ( selGadget >= idLow && selGadget <= idHigh ) { + result = XP_TRUE; + } + } + return result; +} /* tryRockerKey */ +#endif + +void +drawGadgetsFromList( ListPtr list, XP_U16 idLow, XP_U16 idHigh, + XP_U16 hiliteItem ) +{ + XP_U16 i; + LOG_FUNC(); + XP_ASSERT( idLow <= idHigh ); + + for ( i = 0; idLow <= idHigh; ++i, ++idLow ) { + const char* text = LstGetSelectionText( list, i ); + Boolean hilite = idLow == hiliteItem; + drawOneGadget( idLow, text, hilite ); + } + LOG_RETURN_VOID(); +} /* drawGadgetsFromList */ + void setFormRefcon( void* refcon ) { diff --git a/xwords4/palm/palmutil.h b/xwords4/palm/palmutil.h index ec4beaada..3c25af5de 100644 --- a/xwords4/palm/palmutil.h +++ b/xwords4/palm/palmutil.h @@ -47,6 +47,8 @@ void setObjectBounds( UInt16 objectID, RectangleType* rectP ); void disOrEnable( FormPtr form, UInt16 id, Boolean enable ); void disOrEnableSet( FormPtr form, const UInt16* id, Boolean enable ); +void disOrEnableTri( FormPtr form, UInt16 id, XP_TriEnable enable ); + void centerControl( FormPtr form, UInt16 id ); void setBooleanCtrl( UInt16 objectID, Boolean isSet ); @@ -68,8 +70,20 @@ void setSelectorFromList( UInt16 selectorID, ListPtr list, short listSelIndex ); void sizeGadgetsForStrings( FormPtr form, ListPtr list, XP_U16 firstGadgetID ); +void drawGadgetsFromList( ListPtr list, XP_U16 idLow, XP_U16 idHigh, + XP_U16 hiliteItem ); -XP_Bool penInGadget( EventPtr event, UInt16* whichGadget ); +XP_Bool penInGadget( const EventType* event, UInt16* whichGadget ); +void drawOneGadget( UInt16 id, const char* text, Boolean hilite ); +# ifdef XWFEATURE_FIVEWAY +XP_U16 getFocusOwner( void ); +void drawFocusRingOnGadget( XP_U16 idLow, XP_U16 idHigh ); +XP_Bool considerGadgetFocus( const EventType* event, XP_U16 idLow, + XP_U16 idHigh ); + +XP_Bool tryRockerKey( XP_U16 key, XP_U16 selGadget, + XP_U16 idLow, XP_U16 idHigh ); +# endif void setFormRefcon( void* refcon ); void* getFormRefcon(); diff --git a/xwords4/palm/prefsdlg.c b/xwords4/palm/prefsdlg.c index 76b593d8b..62f20c13d 100644 --- a/xwords4/palm/prefsdlg.c +++ b/xwords4/palm/prefsdlg.c @@ -1,6 +1,7 @@ -/* -*-mode: C; fill-column: 77; c-basic-offset: 4; -*- */ -/* - * Copyright 1999 - 2001 by Eric House (xwords@eehouse.org). All rights reserved. +/* -*-mode: C; fill-column: 77; c-basic-offset: 4; compile-command: "make ARCH=68K_ONLY MEMDEBUG=TRUE"; -*- */ +/* + * Copyright 1999 - 2006 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 @@ -17,20 +18,22 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#ifdef XWFEATURE_FIVEWAY +# include +#endif + #include "prefsdlg.h" #include "callback.h" #include "palmutil.h" #include "xwords4defines.h" -#include "newgame.h" /* for drawOneGadget */ void localPrefsToGlobal( PalmAppGlobals* globals ); static void localPrefsToControls( PrefsDlgState* state ); static void drawPrefsTypeGadgets( PalmAppGlobals* globals ); static void showHidePrefsWidgets( PalmAppGlobals* globals, FormPtr form ); -static Boolean checkPrefsHiliteGadget( PalmAppGlobals* globals, FormPtr form, - EventType* event ); +static void checkPrefsHiliteGadget( PalmAppGlobals* globals, UInt16 selGadget ); static void controlsToLocalPrefs( PrefsDlgState* state ); -static Boolean dropCtlUnlessNewGame( PalmAppGlobals* globals, XP_U16 id ); +static XP_Bool ignoredUnlessNewgame( XP_U16 id ); Boolean PrefsFormHandleEvent( EventPtr event ) @@ -41,6 +44,7 @@ PrefsFormHandleEvent( EventPtr event ) FormPtr form; EventType eventToPost; Int16 chosen; + XP_U16 selGadget; CALLBACK_PROLOGUE(); globals = getFormRefcon(); @@ -55,10 +59,6 @@ PrefsFormHandleEvent( EventPtr event ) state = globals->prefsDlgState; } - sizeGadgetsForStrings( FrmGetActiveForm(), - getActiveObjectPtr( XW_PREFS_TYPES_LIST_ID ), - XW_PREFS_APPWIDE_CHECKBX_ID ); - state->playerBdSizeList = getActiveObjectPtr( XW_PREFS_BDSIZE_LIST_ID ); state->phoniesList = @@ -77,18 +77,32 @@ PrefsFormHandleEvent( EventPtr event ) break; case penDownEvent: - form = FrmGetActiveForm(); - result = checkPrefsHiliteGadget( globals, form, event ); + result = penInGadget( event, &selGadget ); + if ( result ) { + checkPrefsHiliteGadget( globals, selGadget ); + } break; - case fldEnterEvent: - result = dropCtlUnlessNewGame( globals, - event->data.fldEnter.fieldID ); +#ifdef XWFEATURE_FIVEWAY + case keyDownEvent: + selGadget = getFocusOwner(); + if ( tryRockerKey( event->data.keyDown.chr, selGadget, + XW_PREFS_ALLGAMES_GADGET_ID, + XW_PREFS_ONEGAME_GADGET_ID ) ) { + checkPrefsHiliteGadget( globals, selGadget ); + result = XP_TRUE; + } else if ( !globals->isNewGame + && vchrRockerCenter == event->data.keyDown.chr ) { + result = ignoredUnlessNewgame( selGadget ); + } break; - case ctlEnterEvent: - result = dropCtlUnlessNewGame( globals, - event->data.ctlSelect.controlID ); + + case frmObjectFocusTakeEvent: + case frmObjectFocusLostEvent: + result = considerGadgetFocus( event, XW_PREFS_ALLGAMES_GADGET_ID, + XW_PREFS_ONEGAME_GADGET_ID ); break; +#endif case ctlSelectEvent: result = true; @@ -147,13 +161,11 @@ PrefsFormHandleEvent( EventPtr event ) return result; } /* prefsFormHandleEvent */ -static Boolean -dropCtlUnlessNewGame( PalmAppGlobals* globals, XP_U16 id ) +static XP_Bool +ignoredUnlessNewgame( XP_U16 id ) { - Boolean result = false; - + XP_Bool ignored = XP_FALSE; switch ( id ) { - case XW_PREFS_NOHINTS_CHECKBOX_ID: case XW_PREFS_BDSIZE_SELECTOR_ID: case XW_PREFS_TIMERON_CHECKBOX_ID: @@ -161,19 +173,11 @@ dropCtlUnlessNewGame( PalmAppGlobals* globals, XP_U16 id ) #ifdef FEATURE_TRAY_EDIT case XW_PREFS_PICKTILES_CHECKBOX_ID: #endif - if ( globals->isNewGame ) { - break; - } - result = true; + ignored = XP_TRUE; break; } - - if ( result ) { - beep(); - } - - return result; -} /* dropCtlUnlessNewGame */ + return ignored; +} /* ignoredUnlessNewgame */ void GlobalPrefsToLocal( PalmAppGlobals* globals ) @@ -328,23 +332,37 @@ controlsToLocalPrefs( PrefsDlgState* state ) static void drawPrefsTypeGadgets( PalmAppGlobals* globals ) { - UInt16 i; - ListPtr list = getActiveObjectPtr( XW_PREFS_TYPES_LIST_ID ); - UInt16 active = globals->prefsDlgState->stateTypeIsGlobal? 0:1; + ListPtr list; + UInt16 active; + list = getActiveObjectPtr( XW_PREFS_TYPES_LIST_ID ); XP_ASSERT( !!list ); + XP_ASSERT( !!globals->prefsDlgState ); - for ( i = 0; i < 2; ++i ) { - char* text = LstGetSelectionText( list, i ); - drawOneGadget( i + XW_PREFS_APPWIDE_CHECKBX_ID, text, i==active ); - } + active = globals->prefsDlgState->stateTypeIsGlobal ? + XW_PREFS_ALLGAMES_GADGET_ID : XW_PREFS_ONEGAME_GADGET_ID; + + drawGadgetsFromList( list, XW_PREFS_ALLGAMES_GADGET_ID, + XW_PREFS_ONEGAME_GADGET_ID, active ); +#ifdef XWFEATURE_FIVEWAY + drawFocusRingOnGadget( XW_PREFS_ALLGAMES_GADGET_ID, + XW_PREFS_ONEGAME_GADGET_ID ); +#endif + LOG_RETURN_VOID(); } /* drawPrefsTypeGadgets */ static void -doOneSet( FormPtr form, XP_U16 first, XP_U16 last, XP_Bool enable ) +doOneSet( FormPtr form, XP_U16 first, XP_U16 last, XP_Bool enable, + XP_Bool isNewGame ) { while ( first <= last ) { - disOrEnable( form, first, enable ); + XP_TriEnable stat = enable? TRI_ENAB_ENABLED : TRI_ENAB_HIDDEN; + + if ( enable && !isNewGame && ignoredUnlessNewgame( first ) ) { + stat = TRI_ENAB_DISABLED; + } + disOrEnableTri( form, first, stat ); + ++first; } } /* doOneSet */ @@ -355,12 +373,14 @@ doOneSet( FormPtr form, XP_U16 first, XP_U16 last, XP_Bool enable ) static void showHidePrefsWidgets( PalmAppGlobals* globals, FormPtr form ) { - XP_Bool global = globals->prefsDlgState->stateTypeIsGlobal; - + XP_Bool isGlobal; + XP_Bool isNewGame = globals->isNewGame; XP_U16 firstToEnable, lastToEnable, firstToDisable, lastToDisable; + isGlobal = globals->prefsDlgState->stateTypeIsGlobal; + /* Need to do the disabling first */ - if ( global ) { + if ( isGlobal ) { firstToEnable = XW_PREFS_FIRST_GLOBAL_ID; lastToEnable = XW_PREFS_LAST_GLOBAL_ID; firstToDisable = XW_PREFS_FIRST_PERGAME_ID; @@ -372,35 +392,30 @@ showHidePrefsWidgets( PalmAppGlobals* globals, FormPtr form ) lastToEnable = XW_PREFS_LAST_PERGAME_ID; } - doOneSet( form, firstToDisable, lastToDisable, XP_FALSE ); - doOneSet( form, firstToEnable, lastToEnable, XP_TRUE ); + doOneSet( form, firstToDisable, lastToDisable, XP_FALSE, isNewGame ); + doOneSet( form, firstToEnable, lastToEnable, XP_TRUE, isNewGame ); - if ( !global ) { + if ( !isGlobal ) { Boolean on = getBooleanCtrl( XW_PREFS_TIMERON_CHECKBOX_ID ); disOrEnable( form, XW_PREFS_TIMER_FIELD_ID, on ); } } /* showHidePrefsWidgets */ -static Boolean -checkPrefsHiliteGadget( PalmAppGlobals* globals, FormPtr form, - EventType* event ) +static void +checkPrefsHiliteGadget( PalmAppGlobals* globals, UInt16 selGadget ) { + FormPtr form = FrmGetActiveForm(); Boolean result = false; - UInt16 selGadget; - result = penInGadget( event, &selGadget ); - if ( result ) { - XP_Bool globalChosen = selGadget == XW_PREFS_APPWIDE_CHECKBX_ID; + XP_Bool globalChosen = selGadget == XW_PREFS_ALLGAMES_GADGET_ID; + XP_LOGF( "%s: selGadget=%d", __FUNCTION__, selGadget ); - result = globalChosen != globals->prefsDlgState->stateTypeIsGlobal; + result = globalChosen != globals->prefsDlgState->stateTypeIsGlobal; - if ( result ) { - globals->prefsDlgState->stateTypeIsGlobal = globalChosen; + if ( result ) { + globals->prefsDlgState->stateTypeIsGlobal = globalChosen; - showHidePrefsWidgets( globals, form ); - drawPrefsTypeGadgets( globals ); - } + showHidePrefsWidgets( globals, form ); + drawPrefsTypeGadgets( globals ); } - - return result; } /* checkPrefsHiliteGadget */ diff --git a/xwords4/palm/xwords4defines.h b/xwords4/palm/xwords4defines.h index d58b9e189..6a219c6c0 100644 --- a/xwords4/palm/xwords4defines.h +++ b/xwords4/palm/xwords4defines.h @@ -256,8 +256,8 @@ /* * prefs dialog */ -#define XW_PREFS_APPWIDE_CHECKBX_ID 2700 -#define XW_PREFS_ONEGAME_CHECKBX_ID 2701 +#define XW_PREFS_ALLGAMES_GADGET_ID 2700 +#define XW_PREFS_ONEGAME_GADGET_ID 2701 #define XW_PREFS_TYPES_LIST_ID 2702 /* global */ @@ -408,8 +408,11 @@ # define DMCLOSEDATABASE(d) #endif +#define kFrmNavHeaderFlagsObjectFocusStartState 0x00000001 +#define kFrmNavHeaderFlagsAppFocusStartState 0x00000002 + /* versioning stuff */ -#define XW_PALM_VERSION_STRING "4.2a1" +#define XW_PALM_VERSION_STRING "4.2a2" #define CUR_PREFS_VERS 0x0405