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

View file

@ -128,6 +128,9 @@ typedef struct CEAppGlobals {
#endif #endif
XP_U16 softKeyId; /* id of item now on left button */ 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; struct CEDrawCtx* draw;
XWGame game; XWGame game;
@ -167,8 +170,8 @@ typedef struct CEAppGlobals {
XP_Bool hintPending; XP_Bool hintPending;
XP_Bool doGlobalPrefs; XP_Bool doGlobalPrefs;
#if defined DEBUG && !defined _WIN32_WCE #ifndef _WIN32_WCE
int dbWidth, dbHeight; XP_U16 dbWidth, dbHeight;
#endif #endif
wchar_t* specialDirs[N_CACHED_PATHS]; /* reserved for ceGetPath() */ 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 #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 void
ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 newId ) ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 newId )
{ {
if ( newId != globals->softKeyId ) { if ( newId != globals->softKeyId ) {
wchar_t menuTxt[32]; /* text of newId menu */ wchar_t menuTxt[32]; /* text of newId menu */
HMENU menu; HMENU menu = ceGetMenu( globals );
#ifndef _WIN32_WCE #ifdef _WIN32_WCE
TBBUTTONINFO info;
#else
HMENU prevMenu; HMENU prevMenu;
XP_U16 prevPos; XP_U16 prevPos;
#endif #endif
@ -694,22 +712,6 @@ ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 newId )
oldId = ID_INITIAL_SOFTID; 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... */ /* Look up the text... */
if ( ceFindMenu( menu, newId, if ( ceFindMenu( menu, newId,
#ifndef _WIN32_WCE #ifndef _WIN32_WCE
@ -717,12 +719,17 @@ ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 newId )
#endif #endif
menuTxt, VSIZE(menuTxt) ) ) { menuTxt, VSIZE(menuTxt) ) ) {
globals->softKeyId = newId; globals->softKeyId = newId;
#ifndef _WIN32_WCE
globals->softKeyMenu = prevMenu;
#endif
} else { } else {
XP_LOGF( "%s: ceFindMenu failed", __func__ ); XP_LOGF( "%s: ceFindMenu failed", __func__ );
} }
/* Make it the button */ /* Make it the button */
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
XP_MEMSET( &info, 0, sizeof(info) );
info.cbSize = sizeof(info);
info.dwMask = TBIF_TEXT | TBIF_COMMAND; info.dwMask = TBIF_TEXT | TBIF_COMMAND;
info.idCommand = newId; info.idCommand = newId;
info.pszText = menuTxt; info.pszText = menuTxt;
@ -731,8 +738,35 @@ ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 newId )
setW32DummyMenu( globals, menu, newId, menuTxt ); setW32DummyMenu( globals, menu, newId, menuTxt );
#endif #endif
} }
ceCheckMenus( globals ); /* in case left key was or should be checked */
} /* ceSetLeftSoftkey */ } /* 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 #ifdef OVERRIDE_BACKKEY
void void
trapBackspaceKey( HWND hDlg ) 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 ceSetChecked( HWND hDlg, XP_U16 resID, XP_Bool check );
void ceCenterCtl( HWND hDlg, XP_U16 resID ); void ceCenterCtl( HWND hDlg, XP_U16 resID );
void ceCheckMenus( const CEAppGlobals* globals );
typedef enum { typedef enum {
PREFS_FILE_PATH_L PREFS_FILE_PATH_L

View file

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