diff --git a/xwords4/wince/cemain.c b/xwords4/wince/cemain.c index 03502da0a..27d15c05e 100755 --- a/xwords4/wince/cemain.c +++ b/xwords4/wince/cemain.c @@ -744,6 +744,8 @@ ceInitAndStartBoard( CEAppGlobals* globals, XP_Bool newGame, } #endif + ceSetLeftSoftkey( globals, ID_MOVE_TURNDONE ); + server_do( globals->game.server ); globals->isNewGame = FALSE; @@ -1345,6 +1347,7 @@ handleTradeCmd( CEAppGlobals* globals ) static XP_Bool handleJuggleCmd( CEAppGlobals* globals ) { + ceSetLeftSoftkey( globals, ID_MOVE_JUGGLE ); return board_juggleTray( globals->game.board ); } /* handleJuggleCmd */ @@ -1476,7 +1479,6 @@ ceDoNewGame( CEAppGlobals* globals ) #endif ceInitAndStartBoard( globals, XP_TRUE, addr ); - ceSetLeftSoftkey( globals, ID_MOVE_TURNDONE ); changed = XP_TRUE; } @@ -1532,6 +1534,8 @@ ceChooseAndOpen( CEAppGlobals* globals ) XP_LOGF( "failed to open chosen game" ); } } + } else { + XP_LOGF( "GetOpenFileName() failed" ); } } /* ceChooseAndOpen */ diff --git a/xwords4/wince/cemain.h b/xwords4/wince/cemain.h index b1bc43517..df0055cc0 100755 --- a/xwords4/wince/cemain.h +++ b/xwords4/wince/cemain.h @@ -92,11 +92,18 @@ typedef struct CEAppGlobals { #ifdef _WIN32_WCE SHACTIVATEINFO sai; XW_WinceVersion winceVersion; +#else + /* Store location of dummy button */ + HMENU dummyMenu; + XP_U16 dummyPos; +#endif struct { - XP_U16 curItem; + HMENU oldMenu; /* menu whose item is now on left button */ + XP_U16 oldId; /* id of item now on left button */ + XP_U16 oldPos; /* position of prev item within oldMenu */ + wchar_t oldName[32]; /* name of previous item */ } softkey; -#endif DrawCtx* draw; XWGame game; diff --git a/xwords4/wince/ceutil.c b/xwords4/wince/ceutil.c index 9bde20e89..f0df7abd7 100755 --- a/xwords4/wince/ceutil.c +++ b/xwords4/wince/ceutil.c @@ -1,6 +1,6 @@ /* -*- fill-column: 77; c-basic-offset: 4; compile-command: "make TARGET_OS=wince DEBUG=TRUE" -*- */ /* - * Copyright 2002-2004 by Eric House (xwords@eehouse.org). All rights reserved. + * Copyright 2002-2008 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 @@ -22,6 +22,7 @@ #include "ceutil.h" #include "cedefines.h" +#include "cedebug.h" #define BUF_SIZE 128 #define VPADDING 4 @@ -365,55 +366,135 @@ ceStackButtonsRight( CEAppGlobals* globals, HWND hDlg ) } } /* ceStackButtonsRight */ -#ifdef _WIN32_WCE -void -ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 id ) +static XP_Bool +ceFindMenu( HMENU menu, XP_U16 id, HMENU* foundMenu, XP_U16* foundPos, + wchar_t* foundBuf, XP_U16 bufLen ) { - HMENU menu; - XP_U16 curItem = globals->softkey.curItem; - /* temporary!! */ - if ( curItem == 0 ) { - curItem = ID_MOVE_TURNDONE; + XP_Bool found = XP_FALSE; + XP_U16 pos; + MENUITEMINFO minfo; + + XP_MEMSET( &minfo, 0, sizeof(minfo) ); + minfo.cbSize = sizeof(minfo); + + for ( pos = 0; !found; ++pos ) { + /* Set these each time through loop. GetMenuItemInfo can change + some of 'em. */ + minfo.fMask = MIIM_SUBMENU | MFT_STRING | MIIM_ID | MIIM_TYPE; + minfo.dwTypeData = foundBuf; + minfo.fType = MFT_STRING; + minfo.cch = bufLen; + + if ( !GetMenuItemInfo( menu, pos, TRUE, &minfo ) ) { + break; /* pos is too big */ + } else if ( NULL != minfo.hSubMenu ) { + found = ceFindMenu( minfo.hSubMenu, id, foundMenu, foundPos, + foundBuf, bufLen ); + } else if ( MFT_SEPARATOR == minfo.fType ) { + continue; + } else if ( minfo.wID == id ) { + found = XP_TRUE; + *foundPos = pos; + *foundMenu = menu; + } + } + return found; +} /* ceFindMenu */ + +#ifndef _WIN32_WCE +static void +setW32DummyMenu( CEAppGlobals* globals, HMENU menu, XP_U16 id, wchar_t* oldNm ) +{ + XP_LOGW( __func__, oldNm ); + if ( globals->dummyMenu == NULL ) { + HMENU tmenu; + XP_U16 tpos; + wchar_t ignore[32]; + if ( ceFindMenu( menu, W32_DUMMY_ID, &tmenu, &tpos, ignore, + VSIZE(ignore) ) ) { + globals->dummyMenu = tmenu; + globals->dummyPos = tpos; + } } - TBBUTTONINFO info; - XP_MEMSET( &info, 0, sizeof(info) ); - info.cbSize = sizeof(info); + if ( globals->dummyMenu != NULL ) { + MENUITEMINFO minfo; + XP_MEMSET( &minfo, 0, sizeof(minfo) ); + minfo.cbSize = sizeof(minfo); + minfo.fMask = MFT_STRING | MIIM_TYPE | MIIM_ID; + minfo.fType = MFT_STRING; + minfo.dwTypeData = oldNm; + minfo.cch = wcslen( oldNm ); + minfo.wID = id; - /* Also temporary!! */ - const wchar_t* txt = L"Mine"; - switch( id ) { - case ID_MOVE_TURNDONE: - txt = L"Turn done"; - break; - case ID_FILE_NEWGAME: - txt = L"New game"; - break; - case ID_MOVE_NEXTHINT: - txt = L"Next hint"; - break; - default: - XP_ASSERT(0); + if ( !SetMenuItemInfo( globals->dummyMenu, globals->dummyPos, + TRUE, &minfo ) ) { + XP_LOGF( "SetMenuItemInfo failed" ); + } } - - info.dwMask = TBIF_LPARAM; - SendMessage( globals->hwndCB, TB_GETBUTTONINFO, IDM_MENU, (LPARAM)&info ); - menu = (HMENU)info.lParam; /* Use to remove item being installed in - left button */ - - - /* First put any existing menu item back in the main menu! */ - - /* Then find, remember and remove the new */ - - /* Make it the button */ - - info.dwMask = TBIF_TEXT | TBIF_COMMAND; - info.idCommand = id; - info.pszText = txt; - SendMessage( globals->hwndCB, TB_SETBUTTONINFO, curItem, (LPARAM)&info ); - - /* Save for next time */ - globals->softkey.curItem = id; -} /* ceSetLeftSoftkey */ +} #endif + +void +ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 newId ) +{ + if ( newId != globals->softkey.oldId ) { + HMENU menu; + HMENU prevMenu; + XP_U16 prevPos; + XP_U16 oldId = globals->softkey.oldId; + if ( 0 == oldId ) { + oldId = ID_INITIAL_SOFTID; + } + +#ifdef _WIN32_WCE + TBBUTTONINFO info; + XP_MEMSET( &info, 0, sizeof(info) ); + info.cbSize = sizeof(info); +#endif + +#ifdef _WIN32_WCE + info.dwMask = TBIF_LPARAM; + SendMessage( globals->hwndCB, TB_GETBUTTONINFO, IDM_MENU, + (LPARAM)&info ); + menu = (HMENU)info.lParam; /* Use to remove item being installed in + left button */ +#else + menu = GetMenu( globals->hWnd ); +#endif + + /* First put any existing menu item back in the main menu! */ + if ( globals->softkey.oldMenu != 0 ) { + if ( ! InsertMenu( globals->softkey.oldMenu, + globals->softkey.oldPos, MF_BYPOSITION, + globals->softkey.oldId, + globals->softkey.oldName ) ) { + XP_LOGF( "%s: InsertMenu failed", __func__ ); + } + } + + /* Then find, remember and remove the new */ + if ( ceFindMenu( menu, newId, &prevMenu, &prevPos, + globals->softkey.oldName, + VSIZE(globals->softkey.oldName) ) ) { + if ( !DeleteMenu( prevMenu, prevPos, MF_BYPOSITION ) ) { + XP_LOGF( "%s: DeleteMenu failed", __func__ ); + } + globals->softkey.oldMenu = prevMenu; + globals->softkey.oldPos = prevPos; + globals->softkey.oldId = newId; + } else { + XP_LOGF( "%s: ceFindMenu failed", __func__ ); + } + + /* Make it the button */ +#ifdef _WIN32_WCE + info.dwMask = TBIF_TEXT | TBIF_COMMAND; + info.idCommand = newId; + info.pszText = globals->softkey.oldName; + SendMessage( globals->hwndCB, TB_SETBUTTONINFO, oldId, (LPARAM)&info ); +#else + setW32DummyMenu( globals, menu, newId, globals->softkey.oldName ); +#endif + } +} /* ceSetLeftSoftkey */ diff --git a/xwords4/wince/ceutil.h b/xwords4/wince/ceutil.h index 1184e7208..979ba1a0a 100755 --- a/xwords4/wince/ceutil.h +++ b/xwords4/wince/ceutil.h @@ -50,10 +50,6 @@ void ceStackButtonsRight( CEAppGlobals* globals, HWND hDlg ); /* Are we drawing things in landscape mode? */ XP_Bool ceIsLandscape( CEAppGlobals* globals ); -#ifdef _WIN32_WCE void ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 id ); -#else -# define ceSetLeftSoftkey( globals, id ) -#endif #endif diff --git a/xwords4/wince/resource.h b/xwords4/wince/resource.h index af71f2284..2476bb67e 100755 --- a/xwords4/wince/resource.h +++ b/xwords4/wince/resource.h @@ -185,12 +185,18 @@ #define ID_GAME_RESENDMSGS 40025 #define ID_FILE_FULLSCREEN 40026 +#define ID_INITIAL_SOFTID ID_MOVE_TURNDONE + +#ifndef _WIN32_WCE +# define W32_DUMMY_ID 40028 +#endif + #define ID_COLORS_RES 9999 #define ID_BONUS_RES 9998 #define IDM_MAIN_COMMAND1 40001 #define IDS_MENU 40002 -#define IDS_DONE 40003 +#define IDS_DUMMY 40003 #define IDS_CANCEL 40004 #define IDS_OK 40005 @@ -203,7 +209,7 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 125 -#define _APS_NEXT_COMMAND_VALUE 40028 +#define _APS_NEXT_COMMAND_VALUE 40029 #define _APS_NEXT_CONTROL_VALUE 1087 #define _APS_NEXT_SYMED_VALUE 101 #endif diff --git a/xwords4/wince/xwords4.rc b/xwords4/wince/xwords4.rc index ea6cee50e..e4f00270d 100755 --- a/xwords4/wince/xwords4.rc +++ b/xwords4/wince/xwords4.rc @@ -68,56 +68,62 @@ END IDM_MENU MENU DISCARDABLE BEGIN +#ifndef _WIN32_WCE + POPUP "Button" + BEGIN + MENUITEM "--", W32_DUMMY_ID + END +#endif POPUP "Menu" BEGIN - MENUITEM "Turn &done", ID_MOVE_TURNDONE - MENUITEM "&Juggle", ID_MOVE_JUGGLE - MENUITEM "Fli&p", ID_MOVE_FLIP - MENUITEM "&Trade", ID_MOVE_TRADE - MENUITEM "(un)&Hide tray", ID_MOVE_HIDETRAY - MENUITEM "Tile &values", ID_MOVE_VALUES + MENUITEM "Turn done", ID_MOVE_TURNDONE + MENUITEM "Juggle", ID_MOVE_JUGGLE + MENUITEM "Flip", ID_MOVE_FLIP + MENUITEM "Trade", ID_MOVE_TRADE + MENUITEM "(un)Hide tray", ID_MOVE_HIDETRAY + MENUITEM "Tile values", ID_MOVE_VALUES - POPUP "&Undo" + POPUP "Undo" BEGIN MENUITEM "Undo current", ID_MOVE_UNDOCURRENT - MENUITEM "Undo last (&z)", ID_MOVE_UNDOLAST + MENUITEM "Undo last", ID_MOVE_UNDOLAST END POPUP "Hint" BEGIN - MENUITEM "Next hint (&m)", ID_MOVE_NEXTHINT - MENUITEM "H&int", ID_MOVE_HINT + MENUITEM "Next hint", ID_MOVE_NEXTHINT + MENUITEM "Hint", ID_MOVE_HINT #ifdef XWFEATURE_SEARCHLIMIT - MENUITEM "Limited hint (&c)", ID_MOVE_LIMITEDHINT + MENUITEM "Limited hint", ID_MOVE_LIMITEDHINT #endif END - POPUP "&Game" + POPUP "Game" BEGIN MENUITEM "Tile counts and values", ID_GAME_TILECOUNTSANDVALUES MENUITEM "Tiles left", ID_GAME_TILESLEFT MENUITEM SEPARATOR MENUITEM "Game info", ID_GAME_GAMEINFO MENUITEM "History", ID_GAME_HISTORY - MENUITEM "Final sc&ores", ID_GAME_FINALSCORES + MENUITEM "Final scores", ID_GAME_FINALSCORES #if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH MENUITEM "Resend messages", ID_GAME_RESENDMSGS #endif END - POPUP "&File" + POPUP "File" BEGIN #ifdef _WIN32_WCE - MENUITEM "Fu&ll screen", ID_FILE_FULLSCREEN + MENUITEM "Full screen", ID_FILE_FULLSCREEN MENUITEM SEPARATOR #endif - MENUITEM "&New game", ID_FILE_NEWGAME - MENUITEM "Open &saved game", ID_FILE_SAVEDGAMES - MENUITEM "P&references", ID_FILE_PREFERENCES + MENUITEM "New game", ID_FILE_NEWGAME + MENUITEM "Open saved game", ID_FILE_SAVEDGAMES + MENUITEM "Preferences", ID_FILE_PREFERENCES MENUITEM SEPARATOR - MENUITEM "&About", ID_FILE_ABOUT + MENUITEM "About", ID_FILE_ABOUT MENUITEM SEPARATOR - MENUITEM "E&xit", ID_FILE_EXIT + MENUITEM "Exit", ID_FILE_EXIT END END END @@ -128,8 +134,8 @@ END IDM_MAIN_MENUBAR RCDATA BEGIN IDM_MENU, 2, - I_IMAGENONE, ID_MOVE_TURNDONE, TBSTATE_ENABLED, - TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE, IDS_DONE, 0, + I_IMAGENONE, ID_INITIAL_SOFTID, TBSTATE_ENABLED, + TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE, IDS_DUMMY, 0, NOMENU, I_IMAGENONE, IDM_MENU, TBSTATE_ENABLED, TBSTYLE_DROPDOWN | TBSTYLE_AUTOSIZE, IDS_MENU, 0, @@ -139,11 +145,11 @@ END IDM_OKCANCEL_MENUBAR RCDATA BEGIN 0, 2, - I_IMAGENONE, IDCANCEL, TBSTATE_ENABLED, - TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE, IDS_CANCEL, 0, - NOMENU, I_IMAGENONE, IDOK, TBSTATE_ENABLED, TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE, IDS_OK, 0, + NOMENU, + I_IMAGENONE, IDCANCEL, TBSTATE_ENABLED, + TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE, IDS_CANCEL, 0, NOMENU END #endif @@ -687,7 +693,7 @@ BEGIN IDC_XWORDS4 "XWORDS4" #endif IDS_MENU "Menu" - IDS_DONE "Done" + IDS_DUMMY "--" IDS_CANCEL "Cancel" IDS_OK "Ok" #ifdef _WIN32_WCE