Add checkmarks to four menuitems to show state; add fullScreen

menuitem to w32 version and give it something to do.
This commit is contained in:
ehouse 2008-11-10 18:49:26 +00:00
parent c65d2cf574
commit 17b139b2c7
5 changed files with 114 additions and 81 deletions

View file

@ -162,45 +162,25 @@ static XP_Bool isDefaultName( CEAppGlobals* globals, const XP_UCHAR* name );
static void ceSetTitleFromName( CEAppGlobals* globals );
#if defined DEBUG && ! defined _WIN32_WCE
#ifndef _WIN32_WCE
/* Very basic cmdline args meant at first to let me vary the size of the
* screen. Form is of arg=digits, with no spaces and digits having to be an
* integer. Right now only width and height work: e.g.
* "wine obj_win32_dbg/xwords4.exe height=240 width=320"
*/
static int g_dbWidth = 240;
static int g_dbHeight = 240;
static void
doCmd( const char* cmd )
static XP_Bool
tryIntParam( const char* buf, const char* param, XP_U16* value )
{
struct { char* p; int* v; } params[] = {
{ "width", &g_dbWidth },
{ "height", &g_dbHeight }
};
int i;
for ( i = 0; i < VSIZE(params); ++i ) {
char* p = params[i].p;
int len = strlen(p);
if ( 0 == strncmp( p, cmd, len ) ) {
cmd += len;
if ( *cmd == '=' ) {
++cmd;
*(params[i].v) = atoi(cmd);
break;
}
}
XP_U16 len = strlen( param );
XP_Bool found = 0 == strncmp( buf, param, len );
if ( found ) {
*value = atoi( &buf[len] );
}
if ( i == VSIZE(params) ) {
XP_LOGF( "failed to match cmdline arg \"%s\"", cmd );
}
} /* doCmd */
return found;
}
static void
parseCmdLine( const char* cmdline )
parseCmdLine( const char* cmdline, XP_U16* width, XP_U16* height )
{
XP_U16 ii;
for ( ii = 0; ; ++ii ) {
@ -215,10 +195,16 @@ parseCmdLine( const char* cmdline )
}
}
len = cmd - cmdline;
memcpy( buf, cmdline, cmd - cmdline );
buf[len] = '\0';
if ( ii > 0 ) { /* skip argv[0] */
doCmd( buf );
if ( len < sizeof(buf) ) {
memcpy( buf, cmdline, cmd - cmdline );
buf[len] = '\0';
if ( ii > 0 ) { /* skip argv[0] */
if ( tryIntParam( buf, "width=", width ) ) {
} else if ( tryIntParam( buf, "height=", height ) ) {
} else {
XP_LOGF( "failed to match cmdline arg \"%s\"", buf );
}
}
}
if ( ch == '\0' ) {
break;
@ -230,7 +216,11 @@ parseCmdLine( const char* cmdline )
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass (HINSTANCE, LPTSTR);
BOOL InitInstance (HINSTANCE, int);
BOOL InitInstance (HINSTANCE, int
#ifndef _WIN32_WCE
, XP_U16, XP_U16
#endif
);
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ceAbout (HWND, UINT, WPARAM, LPARAM);
@ -247,12 +237,17 @@ WinMain( HINSTANCE hInstance,
MSG msg;
HACCEL hAccelTable;
#if defined DEBUG && ! defined _WIN32_WCE
parseCmdLine( lpCmdLine );
#ifndef _WIN32_WCE
XP_U16 width, height;
parseCmdLine( lpCmdLine, &width, &height );
#endif
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow)) {
if (!InitInstance (hInstance, nCmdShow
#ifndef _WIN32_WCE
, width, height
#endif
)) {
return FALSE;
}
@ -543,15 +538,14 @@ figureBoardParms( CEAppGlobals* globals, const XP_U16 nRows,
rc.right = rc.left + FORCE_WIDTH;
rc.bottom = rc.top + FORCE_HEIGHT;
# else
# if defined DEBUG
if ( g_dbWidth != 0 ) {
rc.right = rc.left + g_dbWidth;
if ( !globals->appPrefs.fullScreen ) {
if ( globals->dbWidth != 0 ) {
rc.right = rc.left + globals->dbWidth;
}
if ( globals->dbHeight != 0 ) {
rc.bottom = rc.top + globals->dbHeight;
}
}
if ( g_dbHeight != 0 ) {
rc.bottom = rc.top + g_dbHeight;
}
# endif
# endif
#endif /* #ifndef _WIN32_WCE */
@ -767,6 +761,7 @@ cePositionBoard( CEAppGlobals* globals )
#if ! defined _WIN32_WCE && defined DEBUG
ceSetTitleFromName( globals );
#endif
ceCheckMenus( globals );
return erase;
} /* cePositionBoard */
@ -1252,7 +1247,11 @@ getOSInfo( CEAppGlobals* globals )
// create and display the main program window.
//
BOOL
InitInstance(HINSTANCE hInstance, int nCmdShow)
InitInstance(HINSTANCE hInstance, int nCmdShow
#ifndef _WIN32_WCE
,XP_U16 width, XP_U16 height
#endif
)
{
HWND hWnd;
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
@ -1301,16 +1300,16 @@ InitInstance(HINSTANCE hInstance, int nCmdShow)
XP_MEMSET( globals, 0, sizeof(*globals) );
MPASSIGN( globals->mpool, mpool );
#ifndef _WIN32_WCE
globals->dbWidth = width;
globals->dbHeight = height;
#endif
(void)ceGetPath( globals, DEFAULT_DIR_PATH_L, path, VSIZE(path) );
(void)CreateDirectory( path, 0 );
getOSInfo( globals );
#if defined DEBUG && !defined _WIN32_WCE
globals->dbWidth = g_dbWidth;
globals->dbHeight = g_dbHeight;
#endif
globals->vtMgr = make_vtablemgr( MPPARM_NOCOMMA(mpool) );
globals->hInst = hInstance;
@ -2167,7 +2166,6 @@ ceCheckHandleFocusKey( CEAppGlobals* globals, WPARAM wParam, LPARAM lParam,
} /* ceCheckHandleFocusKey */
#endif /* KEYBOARD_NAV */
#ifdef _WIN32_WCE
static void
ceToggleFullScreen( CEAppGlobals* globals )
{
@ -2177,7 +2175,6 @@ ceToggleFullScreen( CEAppGlobals* globals )
(void)cePositionBoard( globals );
} /* ceToggleFullScreen */
#endif
static void
doAbout( CEAppGlobals* globals )
@ -2294,11 +2291,9 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_FILE_PREFERENCES:
ceDoPrefsDlg( globals );
break;
#ifdef _WIN32_WCE
case ID_FILE_FULLSCREEN:
ceToggleFullScreen( globals );
break;
#endif
case ID_GAME_FINALSCORES:
if ( server_getGameIsOver( globals->game.server ) ) {
ceDisplayFinalScores( globals );
@ -2338,9 +2333,11 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_MOVE_FLIP:
draw = board_flip( globals->game.board );
ceCheckMenus( globals );
break;
case ID_MOVE_VALUES:
draw = board_toggle_showValues( globals->game.board );
ceCheckMenus( globals );
break;
case ID_MOVE_HINT:
@ -3101,7 +3098,7 @@ ce_util_trayHiddenChange( XW_UtilCtxt* uc, XW_TrayVisState XP_UNUSED(newState),
updateScrollInfo( globals, nHiddenRows );
}
#endif
ceCheckMenus( globals );
drawInsidePaint( globals, NULL );
} /* ce_util_trayHiddenChange */

View file

@ -128,6 +128,9 @@ typedef struct CEAppGlobals {
#endif
XP_U16 softKeyId; /* id of item now on left button */
#ifndef _WIN32_WCE
HMENU softKeyMenu; /* so can check/uncheck duplicated items */
#endif
struct CEDrawCtx* draw;
XWGame game;
@ -167,8 +170,8 @@ typedef struct CEAppGlobals {
XP_Bool hintPending;
XP_Bool doGlobalPrefs;
#if defined DEBUG && !defined _WIN32_WCE
int dbWidth, dbHeight;
#ifndef _WIN32_WCE
XP_U16 dbWidth, dbHeight;
#endif
wchar_t* specialDirs[N_CACHED_PATHS]; /* reserved for ceGetPath() */

View file

@ -679,13 +679,31 @@ setW32DummyMenu( CEAppGlobals* globals, HMENU menu, XP_U16 id, wchar_t* oldNm )
}
#endif
static HMENU
ceGetMenu( const CEAppGlobals* globals )
{
#ifdef _WIN32_WCE
TBBUTTONINFO info;
XP_MEMSET( &info, 0, sizeof(info) );
info.cbSize = sizeof(info);
info.dwMask = TBIF_LPARAM;
SendMessage( globals->hwndCB, TB_GETBUTTONINFO, IDM_MENU,
(LPARAM)&info );
return (HMENU)info.lParam;
#else
return GetMenu( globals->hWnd );
#endif
}
void
ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 newId )
{
if ( newId != globals->softKeyId ) {
wchar_t menuTxt[32]; /* text of newId menu */
HMENU menu;
#ifndef _WIN32_WCE
HMENU menu = ceGetMenu( globals );
#ifdef _WIN32_WCE
TBBUTTONINFO info;
#else
HMENU prevMenu;
XP_U16 prevPos;
#endif
@ -694,22 +712,6 @@ ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 newId )
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
/* Look up the text... */
if ( ceFindMenu( menu, newId,
#ifndef _WIN32_WCE
@ -717,12 +719,17 @@ ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 newId )
#endif
menuTxt, VSIZE(menuTxt) ) ) {
globals->softKeyId = newId;
#ifndef _WIN32_WCE
globals->softKeyMenu = prevMenu;
#endif
} else {
XP_LOGF( "%s: ceFindMenu failed", __func__ );
}
/* Make it the button */
#ifdef _WIN32_WCE
XP_MEMSET( &info, 0, sizeof(info) );
info.cbSize = sizeof(info);
info.dwMask = TBIF_TEXT | TBIF_COMMAND;
info.idCommand = newId;
info.pszText = menuTxt;
@ -731,8 +738,35 @@ ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 newId )
setW32DummyMenu( globals, menu, newId, menuTxt );
#endif
}
ceCheckMenus( globals ); /* in case left key was or should be checked */
} /* ceSetLeftSoftkey */
static void
checkOneItem( const CEAppGlobals* globals, XP_U16 id, XP_Bool check )
{
UINT uCheck = check ? MF_CHECKED : MF_UNCHECKED;
HMENU menu = ceGetMenu( globals );
(void)CheckMenuItem( menu, id, uCheck );
#ifndef _WIN32_WCE
if ( id == globals->softKeyId ) {
(void)CheckMenuItem( globals->softKeyMenu, id, uCheck );
}
#endif
}
void
ceCheckMenus( const CEAppGlobals* globals )
{
const BoardCtxt* board = globals->game.board;
checkOneItem( globals, ID_MOVE_VALUES, board_get_showValues( board ));
checkOneItem( globals, ID_MOVE_FLIP, board_get_flipped( board ) );
checkOneItem( globals, ID_FILE_FULLSCREEN, globals->appPrefs.fullScreen );
checkOneItem( globals, ID_MOVE_HIDETRAY,
TRAY_REVEALED != board_getTrayVisState( board ) );
} /* ceCheckMenus */
#ifdef OVERRIDE_BACKKEY
void
trapBackspaceKey( HWND hDlg )

View file

@ -42,6 +42,7 @@ XP_Bool ceGetChecked( HWND hDlg, XP_U16 resID );
void ceSetChecked( HWND hDlg, XP_U16 resID, XP_Bool check );
void ceCenterCtl( HWND hDlg, XP_U16 resID );
void ceCheckMenus( const CEAppGlobals* globals );
typedef enum {
PREFS_FILE_PATH_L

View file

@ -80,7 +80,7 @@ BEGIN
MENUITEM "Juggle", ID_MOVE_JUGGLE
MENUITEM "Flip", ID_MOVE_FLIP
MENUITEM "Trade", ID_MOVE_TRADE
MENUITEM "(un)Hide tray", ID_MOVE_HIDETRAY
MENUITEM "Hide tray", ID_MOVE_HIDETRAY
POPUP "Undo"
BEGIN
@ -96,7 +96,7 @@ BEGIN
MENUITEM "Limited hint", ID_MOVE_LIMITEDHINT
#endif
MENUITEM SEPARATOR
MENUITEM "Toggle values", ID_MOVE_VALUES
MENUITEM "Show values", ID_MOVE_VALUES
END
POPUP "Game"
@ -114,10 +114,8 @@ BEGIN
POPUP "File"
BEGIN
#ifdef _WIN32_WCE
MENUITEM "Full screen", ID_FILE_FULLSCREEN
MENUITEM SEPARATOR
#endif
MENUITEM "New game...", ID_FILE_NEWGAME
MENUITEM "Saved games...", ID_FILE_SAVEDGAMES
MENUITEM "Preferences...", ID_FILE_PREFERENCES