From 536de24e1dc43ddce5284506c4aa4ab6def2e769 Mon Sep 17 00:00:00 2001 From: ehouse Date: Sun, 13 Apr 2008 17:01:09 +0000 Subject: [PATCH] Put game name in title bar on launch as well as after opening saved game. Clear when opening unnamed/defaultnamed game --- wince/cemain.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/wince/cemain.c b/wince/cemain.c index 6f903aafd..b9a5f5b3c 100755 --- a/wince/cemain.c +++ b/wince/cemain.c @@ -155,6 +155,7 @@ static XP_Bool ceSetDictName( const wchar_t* wPath, XP_U16 index, void* ctxt ); static int messageBoxStream( CEAppGlobals* globals, XWStreamCtxt* stream, wchar_t* title, XP_U16 buttons ); static XP_Bool ceQueryFromStream( CEAppGlobals* globals, XWStreamCtxt* stream); +static XP_Bool isDefaultName( const XP_UCHAR* name ); #if defined DEBUG && ! defined _WIN32_WCE @@ -629,30 +630,36 @@ ceSetTitleFromName( CEAppGlobals* globals ) wchar_t widebuf[256]; wchar_t* colonPos; XP_UCHAR* baseStart; - XP_UCHAR* gameName; + const XP_UCHAR* gameName = globals->curGameName; XP_U16 len = (XP_U16)SendMessage( globals->hWnd, WM_GETTEXT, sizeof(widebuf), (long)widebuf ); colonPos = wcsstr( widebuf, L":" ); - if ( colonPos == NULL ) { - wcscat( widebuf, L":" ); - colonPos = widebuf + len; /* we'll write at the end */ - } - ++colonPos; /* skip the colon */ + /* if default name, remove any current name */ + if ( !gameName || isDefaultName( gameName ) ) { + if ( NULL != colonPos ) { + *colonPos = 0; + } + } else { + if ( colonPos == NULL ) { + wcscat( widebuf, L":" ); + colonPos = widebuf + len; /* we'll write at the end */ + } + ++colonPos; /* skip the colon */ - gameName = globals->curGameName; - baseStart = strrchr( gameName, '\\' ); - ++baseStart; - len = (XP_U16)XP_STRLEN( baseStart ); + baseStart = strrchr( gameName, '\\' ); + ++baseStart; + len = (XP_U16)XP_STRLEN( baseStart ); - MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, baseStart, len + 1, - colonPos, len + 1 ); + MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, baseStart, len + 1, + colonPos, len + 1 ); - /* now get rid of the ".xwg" */ - colonPos = wcsrchr( widebuf, '.' ); - if ( colonPos != NULL ) { - *colonPos = 0; + /* now get rid of the ".xwg" */ + colonPos = wcsrchr( widebuf, '.' ); + if ( colonPos != NULL ) { + *colonPos = 0; + } } SendMessage( globals->hWnd, WM_SETTEXT, 0, (long)widebuf ); @@ -996,6 +1003,8 @@ ceLoadSavedGame( CEAppGlobals* globals ) } stream_destroy( stream ); + + ceSetTitleFromName( globals ); } return success; @@ -1474,6 +1483,7 @@ ceDoNewGame( CEAppGlobals* globals ) #endif ceInitAndStartBoard( globals, XP_TRUE, addr ); + ceSetTitleFromName( globals ); changed = XP_TRUE; } @@ -1509,7 +1519,6 @@ ceChooseAndOpen( CEAppGlobals* globals ) globals->curGameName = name; if ( ceLoadSavedGame( globals ) ) { ceInitAndStartBoard( globals, XP_FALSE, NULL ); - ceSetTitleFromName( globals ); } else { XP_LOGF( "failed to open chosen game" ); } @@ -1593,7 +1602,7 @@ ceWriteToFile( XWStreamCtxt* stream, void* closure ) } /* ceWriteToFile */ static XP_Bool -isDefaultName( XP_UCHAR* name ) +isDefaultName( const XP_UCHAR* name ) { return 0 == XP_STRCMP( UNSAVEDGAMEFILENAME, name ); } /* isDefaultName */