From c79101060387be65df974f1a6ecfeb55de09b580 Mon Sep 17 00:00:00 2001 From: ehouse Date: Sun, 7 Dec 2008 01:30:18 +0000 Subject: [PATCH] Don't let smartphone users set hintlimits checkbox, and explain why. Fix bug calling MessageBox with main window ptr from dialog. Include name of preexisting file when warning user who enters it while saving/renaming. --- xwords4/wince/cemain.c | 33 ++++----------------------------- xwords4/wince/cemain.h | 2 -- xwords4/wince/ceprefs.c | 18 +++++++++++++++--- xwords4/wince/cesvdgms.c | 7 +++++-- xwords4/wince/ceutil.c | 19 +++++++++++++++++++ xwords4/wince/ceutil.h | 3 +++ 6 files changed, 46 insertions(+), 36 deletions(-) diff --git a/xwords4/wince/cemain.c b/xwords4/wince/cemain.c index 0de1b6dc5..1c6353b52 100755 --- a/xwords4/wince/cemain.c +++ b/xwords4/wince/cemain.c @@ -1115,7 +1115,7 @@ ceLoadSavedGame( CEAppGlobals* globals ) snprintf( buf, VSIZE(buf), "Unable to open dictionary: %s", dictName ); buf[VSIZE(buf)-1] = '\0'; - messageBoxChar( globals, buf, L"Oops!", MB_OK ); + ceMessageBoxChar( globals, NULL, buf, L"Oops!", MB_OK ); } XP_FREE( globals->mpool, dictName ); #endif @@ -2644,31 +2644,6 @@ ceMsgFromStream( CEAppGlobals* globals, XWStreamCtxt* stream, return saidYes; } /* ceMsgFromStream */ -int -messageBoxChar( CEAppGlobals* globals, XP_UCHAR* str, wchar_t* title, - XP_U16 buttons ) -{ - wchar_t* widebuf; - XP_U32 len, wsize; - int result; - - /* first get the length required, then alloc and go */ - len = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, str, strlen(str), - NULL, 0 ); - wsize = (len+1) * sizeof( wchar_t ); - - widebuf = XP_MALLOC( globals->mpool, wsize ); - - XP_MEMSET( widebuf, 0, wsize ); - MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, str, strlen(str), - widebuf, len ); - - result = MessageBox( globals->hWnd, widebuf, title, buttons ); - - XP_FREE( globals->mpool, widebuf ); - return result; -} /* messageBoxChar */ - static XP_UCHAR* ceStreamToStrBuf( MPFORMAL XWStreamCtxt* stream ) { @@ -2686,7 +2661,7 @@ messageBoxStream( CEAppGlobals* globals, XWStreamCtxt* stream, wchar_t* title, { XP_UCHAR* buf = ceStreamToStrBuf( MPPARM(globals->mpool) stream ); - int result = messageBoxChar( globals, buf, title, buttons ); + int result = ceMessageBoxChar( globals, NULL, buf, title, buttons ); XP_FREE( globals->mpool, buf ); return result; @@ -2986,7 +2961,7 @@ ce_util_userError( XW_UtilCtxt* uc, UtilErrID id ) break; } - messageBoxChar( globals, message, L"Oops!", MB_OK ); + ceMessageBoxChar( globals, NULL, message, L"Oops!", MB_OK ); } /* ce_util_userError */ static XP_Bool @@ -3354,7 +3329,7 @@ ce_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi, sprintf( msgBuf, "Word[s] %s not found in dictionary.", wordsBuf ); if ( turnLost ) { - messageBoxChar( globals, msgBuf, L"Illegal word", MB_OK ); + ceMessageBoxChar( globals, NULL, msgBuf, L"Illegal word", MB_OK ); isOk = XP_TRUE; } else { strcat( msgBuf, " Use it anyway?" ); diff --git a/xwords4/wince/cemain.h b/xwords4/wince/cemain.h index 5cb6131a6..ed2742377 100755 --- a/xwords4/wince/cemain.h +++ b/xwords4/wince/cemain.h @@ -195,8 +195,6 @@ enum { #define CE_NUM_EDITABLE_COLORS CE_BLACK_COLOR -int messageBoxChar( CEAppGlobals* globals, XP_UCHAR* str, wchar_t* title, - XP_U16 buttons ); XP_Bool queryBoxChar( CEAppGlobals* globals, const XP_UCHAR* msg ); /* These allow LISTBOX and COMBOBOX to be used by the same code */ diff --git a/xwords4/wince/ceprefs.c b/xwords4/wince/ceprefs.c index 266878284..14a67570a 100755 --- a/xwords4/wince/ceprefs.c +++ b/xwords4/wince/ceprefs.c @@ -201,7 +201,9 @@ loadControlsFromState( CePrefsDlgState* pState ) ceSetChecked( hDlg, IDC_PICKTILES, prefsPrefs->gp.allowPickTiles ); #endif #ifdef XWFEATURE_SEARCHLIMIT - ceSetChecked( hDlg, IDC_CHECKHINTSLIMITS, prefsPrefs->gp.allowHintRect ); + if ( !IS_SMARTPHONE(globals) ) { + ceSetChecked( hDlg, IDC_CHECKHINTSLIMITS, prefsPrefs->gp.allowHintRect ); + } #endif /* timer */ ceSetDlgItemNum( hDlg, TIMER_EDIT, prefsPrefs->gp.gameSeconds / 60 ); @@ -231,6 +233,7 @@ ceControlsToPrefs( CePrefsDlgState* state ) XP_S16 selIndex; CePrefsPrefs* prefsPrefs = &state->prefsPrefs; HWND hDlg = state->dlgHdr.hDlg; + CEAppGlobals* globals = state->dlgHdr.globals; prefsPrefs->showColors = ceGetChecked( hDlg, IDC_CHECKCOLORPLAYED ); prefsPrefs->gp.robotSmartness @@ -238,7 +241,7 @@ ceControlsToPrefs( CePrefsDlgState* state ) prefsPrefs->gp.hintsNotAllowed = !ceGetChecked( hDlg, IDC_CHECKHINTSOK ); selIndex = (XP_U16)SendDlgItemMessage( hDlg, state->phonComboId, - GETCURSEL(state->dlgHdr.globals), + GETCURSEL(globals), 0, 0 ); if ( selIndex != LB_ERR ) { prefsPrefs->gp.phoniesAction = (XWPhoniesChoice)selIndex; @@ -260,7 +263,9 @@ ceControlsToPrefs( CePrefsDlgState* state ) prefsPrefs->gp.allowPickTiles = ceGetChecked( hDlg, IDC_PICKTILES ); #endif #ifdef XWFEATURE_SEARCHLIMIT - prefsPrefs->gp.allowHintRect = ceGetChecked( hDlg, IDC_CHECKHINTSLIMITS ); + if ( !IS_SMARTPHONE(globals) ) { + prefsPrefs->gp.allowHintRect = ceGetChecked( hDlg, IDC_CHECKHINTSLIMITS ); + } #endif } /* ceControlsToPrefs */ @@ -326,6 +331,13 @@ PrefsDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) BM_GETCHECK, 0, 0 ); ceShowOrHide( hDlg, IDC_CHECKHINTSLIMITS, timerOn ); break; + case IDC_CHECKHINTSLIMITS: + if ( IS_SMARTPHONE(globals) ) { + ceMessageBoxChar( globals, hDlg, "This feature requires a " + "touch screen.", L"Sorry", MB_OK ); + ceSetChecked( hDlg, IDC_CHECKHINTSLIMITS, XP_FALSE ); + } + break; #endif case IDOK: diff --git a/xwords4/wince/cesvdgms.c b/xwords4/wince/cesvdgms.c index dbdfc0fa3..75085c750 100644 --- a/xwords4/wince/cesvdgms.c +++ b/xwords4/wince/cesvdgms.c @@ -119,8 +119,11 @@ SaveNameDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) (void)GetDlgItemText( hDlg, IDC_SVGN_EDIT, buf, VSIZE(buf) ); if ( ceFileExists( globals, buf ) ) { - messageBoxChar( globals, - "File exists", L"Oops!", MB_OK ); + wchar_t widebuf[128]; + snwprintf( widebuf, VSIZE(widebuf), + L"File \"%s\" already exists.", buf ); + result = MessageBox( hDlg, widebuf, L"Oops!", MB_OK ); + (void)SetDlgItemText( hDlg, IDC_SVGN_EDIT, state->buf ); break; } len = ceGetPath( globals, DEFAULT_DIR_PATH_L, diff --git a/xwords4/wince/ceutil.c b/xwords4/wince/ceutil.c index 0b73d21bc..3d0363e43 100755 --- a/xwords4/wince/ceutil.c +++ b/xwords4/wince/ceutil.c @@ -870,3 +870,22 @@ ceGetPath( CEAppGlobals* globals, CePathType typ, } return len; } /* ceGetPath */ + +int +ceMessageBoxChar( CEAppGlobals* globals, HWND parent, XP_UCHAR* str, + wchar_t* title, XP_U16 buttons ) +{ + /* Get the length required, then alloc and go. This is technically + correct, but everywhere else I assume a 2:1 ratio for wchar_t:char. */ + XP_U16 clen = 1 + strlen(str); + XP_U32 wlen = 1 + MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, str, + clen, NULL, 0 ); + wchar_t widebuf[wlen]; + + MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, str, clen, widebuf, wlen ); + + if ( !parent ) { + parent = globals->hWnd; + } + return MessageBox( parent, widebuf, title, buttons ); +} /* ceMessageBoxChar */ diff --git a/xwords4/wince/ceutil.h b/xwords4/wince/ceutil.h index 7bcf7b162..c53855c4c 100755 --- a/xwords4/wince/ceutil.h +++ b/xwords4/wince/ceutil.h @@ -47,6 +47,9 @@ void ceCheckMenus( const CEAppGlobals* globals ); void ceGetItemRect( HWND hDlg, XP_U16 resID, RECT* rect ); void ceMoveItem( HWND hDlg, XP_U16 resID, XP_S16 byX, XP_S16 byY ); +int ceMessageBoxChar( CEAppGlobals* globals, HWND parent, XP_UCHAR* str, + wchar_t* title, XP_U16 buttons ); + typedef enum { PREFS_FILE_PATH_L ,DEFAULT_DIR_PATH_L