From a29ab639fc54f1a97a156c2b5a5666f3a4c82fee Mon Sep 17 00:00:00 2001 From: ehouse Date: Thu, 5 Jun 2008 04:29:28 +0000 Subject: [PATCH] rename and reorganize/simplify dialog-handling code common to all dialogs, handling scrolling and backspace key (smartphone only) and scroll-by-focus in a single place. --- xwords4/wince/ceaskpwd.c | 15 +-- xwords4/wince/ceaskpwd.h | 3 +- xwords4/wince/ceblank.c | 23 +--- xwords4/wince/ceblank.h | 3 +- xwords4/wince/ceclrsel.c | 99 +++++++-------- xwords4/wince/cecondlg.c | 6 +- xwords4/wince/cecondlg.h | 2 +- xwords4/wince/ceginfo.c | 264 +++++++++++++++++++-------------------- xwords4/wince/ceginfo.h | 4 +- xwords4/wince/cehntlim.c | 9 +- xwords4/wince/cehntlim.h | 3 +- xwords4/wince/cemain.c | 26 ++-- xwords4/wince/ceprefs.c | 91 ++++++-------- xwords4/wince/ceprefs.h | 3 +- xwords4/wince/cestrbx.c | 69 +++++----- xwords4/wince/cestrbx.h | 7 +- xwords4/wince/cesvdgms.c | 162 +++++++++++------------- xwords4/wince/ceutil.c | 57 +++++++-- xwords4/wince/ceutil.h | 15 ++- 19 files changed, 421 insertions(+), 440 deletions(-) diff --git a/xwords4/wince/ceaskpwd.c b/xwords4/wince/ceaskpwd.c index 3a384d184..6fbad9ae5 100755 --- a/xwords4/wince/ceaskpwd.c +++ b/xwords4/wince/ceaskpwd.c @@ -49,8 +49,7 @@ PasswdDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) SetWindowLong( hDlg, GWL_USERDATA, lParam ); pState = (PasswdDialogState*)lParam; - ceDlgSetup( pState->globals, hDlg ); - trapBackspaceKey( hDlg ); + ceDlgSetup( &pState->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); nameToLabel( hDlg, pState->name, IDC_PWDLABEL ); @@ -59,15 +58,11 @@ PasswdDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) pState = (PasswdDialogState*)GetWindowLong( hDlg, GWL_USERDATA ); if ( !!pState ) { + if ( ceDoDlgHandle( &pState->dlgHdr, message, wParam, lParam ) ) { + return TRUE; + } + switch ( message ) { -#ifdef _WIN32_WCE - case WM_HOTKEY: - if ( VK_TBACK == HIWORD(lParam) ) { - SHSendBackToFocusWindow( message, wParam, lParam ); - return TRUE; - } - break; -#endif case WM_COMMAND: id = LOWORD(wParam); switch( id ) { diff --git a/xwords4/wince/ceaskpwd.h b/xwords4/wince/ceaskpwd.h index 807e1e6bb..e29c8de6b 100755 --- a/xwords4/wince/ceaskpwd.h +++ b/xwords4/wince/ceaskpwd.h @@ -22,9 +22,10 @@ #include "stdafx.h" #include "cemain.h" +#include "ceutil.h" typedef struct PasswdDialogState { - CEAppGlobals* globals; + CeDlgHdr dlgHdr; const XP_UCHAR* name; XP_UCHAR* buf; XP_U16* lenp; diff --git a/xwords4/wince/ceblank.c b/xwords4/wince/ceblank.c index fc86fd9e3..3bf731ed4 100755 --- a/xwords4/wince/ceblank.c +++ b/xwords4/wince/ceblank.c @@ -56,7 +56,7 @@ showCurTray( HWND hDlg, BlankDialogState* bState ) wchar_t widebuf[48]; XP_UCHAR* name; - name = bState->globals->gameInfo.players[bState->playerNum].name; + name = bState->dlgHdr.globals->gameInfo.players[bState->playerNum].name; lenSoFar += XP_SNPRINTF( labelBuf + lenSoFar, sizeof(labelBuf) - lenSoFar, @@ -103,29 +103,18 @@ BlankDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) ceShowOrHide( hDlg, IDC_BACKUP, bState->canBackup ); #endif - ceDlgSetup( bState->globals, hDlg ); - trapBackspaceKey( hDlg ); + ceDlgSetup( &bState->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); loadLettersList( hDlg, bState ); } else { bState = (BlankDialogState*)GetWindowLong( hDlg, GWL_USERDATA ); if ( !!bState ) { + if ( ceDoDlgHandle( &bState->dlgHdr, message, wParam, lParam) ) { + return TRUE; + } + switch ( message ) { -/* case WM_KEYDOWN: /\* key down. Select a list item? *\/ */ -/* XP_LOGF( "got WM_KEYDOWN" ); */ -/* break; */ -#ifdef _WIN32_WCE - case WM_HOTKEY: - if ( VK_TBACK == HIWORD(lParam) ) { - if ( bState->canBackup ) { - bState->result = PICKER_BACKUP; - EndDialog( hDlg, IDC_BACKUP ); - return TRUE; - } - } - break; -#endif case WM_COMMAND: id = LOWORD(wParam); if ( 0 ) { diff --git a/xwords4/wince/ceblank.h b/xwords4/wince/ceblank.h index 2e714a155..6e7be5642 100755 --- a/xwords4/wince/ceblank.h +++ b/xwords4/wince/ceblank.h @@ -22,9 +22,10 @@ #include "stdafx.h" #include "cemain.h" +#include "ceutil.h" typedef struct BlankDialogState { - CEAppGlobals* globals; + CeDlgHdr dlgHdr; const PickInfo* pi; XP_U16 playerNum; const XP_UCHAR4* texts; diff --git a/xwords4/wince/ceclrsel.c b/xwords4/wince/ceclrsel.c index 5987a2f11..f0ff438ae 100644 --- a/xwords4/wince/ceclrsel.c +++ b/xwords4/wince/ceclrsel.c @@ -31,8 +31,7 @@ static void colorButton( DRAWITEMSTRUCT* dis, HBRUSH brush ); #ifdef MY_COLOR_SEL typedef struct ClrEditDlgState { - CEAppGlobals* globals; - + CeDlgHdr dlgHdr; HWND parent; HWND sampleButton; XP_U16 labelID; @@ -145,8 +144,7 @@ EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) eState->cancelled = XP_TRUE; eState->inited = XP_FALSE; - ceDlgSetup( eState->globals, hDlg ); - trapBackspaceKey( hDlg ); + ceDlgSetup( &eState->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); wchar_t label[32]; XP_U16 len = SendDlgItemMessage( eState->parent, eState->labelID, @@ -176,11 +174,11 @@ EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) initChooseColor( eState, hDlg ); } - switch (message) { + if ( ceDoDlgHandle( &eState->dlgHdr, message, wParam, lParam) ) { + return TRUE; + } - case WM_VSCROLL: - ceDoDlgScroll( eState->globals, hDlg, wParam ); - break; + switch (message) { case WM_DRAWITEM: colorButtonFromState( eState, (DRAWITEMSTRUCT*)lParam ); @@ -198,14 +196,6 @@ EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) break; } break; -#ifdef _WIN32_WCE - case WM_HOTKEY: - if ( VK_TBACK == HIWORD(lParam) ) { - SHSendBackToFocusWindow( message, wParam, lParam ); - return TRUE; - } - break; -#endif case WM_COMMAND: wid = LOWORD(wParam); switch( wid ) { @@ -234,24 +224,23 @@ EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) } /* EditColorsDlg */ static XP_Bool -myChooseColor( CEAppGlobals* globals, HWND parent, XP_U16 labelID, - COLORREF* cref ) +myChooseColor( CeDlgHdr* dlgHdr, XP_U16 labelID, COLORREF* cref ) { ClrEditDlgState state; int result; XP_MEMSET( &state, 0, sizeof(state) ); - state.globals = globals; + state.dlgHdr.globals = dlgHdr->globals; state.red = GetRValue(*cref); state.green = GetGValue(*cref); state.blue = GetBValue(*cref); state.labelID = labelID; - state.parent = parent; + state.parent = dlgHdr->hDlg; XP_LOGF( "setting up IDD_COLOREDITDLG" ); - result = DialogBoxParam( globals->hInst, (LPCTSTR)IDD_COLOREDITDLG, - parent, (DLGPROC)EditColorsDlg, (long)&state ); + result = DialogBoxParam( dlgHdr->globals->hInst, (LPCTSTR)IDD_COLOREDITDLG, + dlgHdr->hDlg, (DLGPROC)EditColorsDlg, (long)&state ); XP_LOGF( "DialogBoxParam=>%d", result ); @@ -275,8 +264,7 @@ colorButton( DRAWITEMSTRUCT* dis, HBRUSH brush ) } typedef struct ColorsDlgState { - HWND hDlg; - CEAppGlobals* globals; + CeDlgHdr dlgHdr; COLORREF* inColors; COLORREF colors[CE_NUM_EDITABLE_COLORS]; @@ -299,7 +287,7 @@ initColorData( ColorsDlgState* cState ) for ( i = 0; i < CE_NUM_EDITABLE_COLORS; ++i ) { COLORREF ref = cState->inColors[i]; - HWND button = GetDlgItem( cState->hDlg, FIRST_BUTTON + i ); + HWND button = GetDlgItem( cState->dlgHdr.hDlg, FIRST_BUTTON + i ); cState->colors[i] = ref; cState->brushes[i] = CreateSolidBrush( ref ); cState->buttons[i] = button; @@ -338,7 +326,7 @@ wrapChooseColor( ColorsDlgState* cState, XP_U16 button ) XP_U16 labelID = button + CLRSEL_LABEL_OFFSET; COLORREF clrref = cState->colors[index]; - if ( myChooseColor( cState->globals, cState->hDlg, labelID, &clrref ) ) { + if ( myChooseColor( &cState->dlgHdr, labelID, &clrref ) ) { cState->colors[index] = clrref; DeleteObject( cState->brushes[index] ); cState->brushes[index] = CreateSolidBrush( clrref ); @@ -359,7 +347,7 @@ wrapChooseColor( ColorsDlgState* cState, XP_U16 button ) } ccs.lStructSize = sizeof(ccs); - ccs.hwndOwner = cState->hDlg; + ccs.hwndOwner = cState->dlgHdr.hDlg; ccs.rgbResult = cState->colors[index]; ccs.lpCustColors = arr; @@ -397,9 +385,8 @@ ColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) state = (ColorsDlgState*)lParam; state->cancelled = XP_TRUE; state->inited = XP_FALSE; - state->hDlg = hDlg; - ceDlgSetup( state->globals, hDlg ); + ceDlgSetup( &state->dlgHdr, hDlg, DLG_STATE_NONE ); result = TRUE; } else { @@ -416,37 +403,37 @@ ColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) /* __func__, messageToStr(message), message, */ /* wParam, lParam ); */ - switch (message) { - - case WM_VSCROLL: - ceDoDlgScroll( state->globals, hDlg, wParam ); - break; - - case WM_DRAWITEM: - ceDrawColorButton( state, (DRAWITEMSTRUCT*)lParam ); + if ( ceDoDlgHandle( &state->dlgHdr, message, wParam, lParam) ) { result = TRUE; - break; + } else { + switch (message) { - case WM_COMMAND: - wid = LOWORD(wParam); - switch( wid ) { - - case IDOK: - state->cancelled = XP_FALSE; - /* fallthrough */ - - case IDCANCEL: - deleteButtonBrushes( state ); - EndDialog(hDlg, wid); + case WM_DRAWITEM: + ceDrawColorButton( state, (DRAWITEMSTRUCT*)lParam ); result = TRUE; break; - default: - /* it's one of the color buttons. Set up with the - appropriate color and launch ChooseColor */ - wrapChooseColor( state, wid ); - result = TRUE; - break; + case WM_COMMAND: + wid = LOWORD(wParam); + switch( wid ) { + + case IDOK: + state->cancelled = XP_FALSE; + /* fallthrough */ + + case IDCANCEL: + deleteButtonBrushes( state ); + EndDialog(hDlg, wid); + result = TRUE; + break; + + default: + /* it's one of the color buttons. Set up with the + appropriate color and launch ChooseColor */ + wrapChooseColor( state, wid ); + result = TRUE; + break; + } } } } @@ -461,7 +448,7 @@ ceDoColorsEdit( HWND hwnd, CEAppGlobals* globals, COLORREF* colors ) ColorsDlgState state; XP_MEMSET( &state, 0, sizeof(state) ); - state.globals = globals; + state.dlgHdr.globals = globals; state.inColors = colors; (void)DialogBoxParam( globals->hInst, (LPCTSTR)IDD_COLORSDLG, hwnd, diff --git a/xwords4/wince/cecondlg.c b/xwords4/wince/cecondlg.c index 632fda69e..01b08af82 100755 --- a/xwords4/wince/cecondlg.c +++ b/xwords4/wince/cecondlg.c @@ -167,24 +167,22 @@ ConnsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) LRESULT result = FALSE; CeConnDlgState* cState; - CEAppGlobals* globals; if ( message == WM_INITDIALOG ) { SetWindowLong( hDlg, GWL_USERDATA, lParam ); cState = (CeConnDlgState*)lParam; - globals = cState->globals; adjustForConnType( hDlg, cState ); ceControlsFromAddrRec( hDlg, cState ); - ceDlgSetup( globals, hDlg ); + ceDlgSetup( &cState->dlgState, hDlg, DLG_STATE_NONE ); result = TRUE; } else { cState = (CeConnDlgState*)GetWindowLong( hDlg, GWL_USERDATA ); if ( !!cState ) { - globals = cState->globals; + CEAppGlobals* globals = cState->dlgHdr.globals; if ( message == WM_COMMAND ) { XP_U16 id = LOWORD(wParam); diff --git a/xwords4/wince/cecondlg.h b/xwords4/wince/cecondlg.h index 2f28dcf7e..5601b041b 100755 --- a/xwords4/wince/cecondlg.h +++ b/xwords4/wince/cecondlg.h @@ -24,9 +24,9 @@ #include "cemain.h" typedef struct CeConnDlgState { + CeDlgHdr dlgHdr; CommsAddrRec addrRec; DeviceRole role; - CEAppGlobals* globals; XP_Bool userCancelled; } CeConnDlgState; diff --git a/xwords4/wince/ceginfo.c b/xwords4/wince/ceginfo.c index 56f437211..a7d9b75a8 100755 --- a/xwords4/wince/ceginfo.c +++ b/xwords4/wince/ceginfo.c @@ -77,7 +77,7 @@ addDictToState( const wchar_t* wPath, XP_U16 XP_UNUSED(index), void* ctxt ) if ( loc >= 0 ) { /* make a copy of the long name */ len = wcslen( wPath ) + 1; - wstr = (wchar_t*)XP_MALLOC( giState->globals->mpool, + wstr = (wchar_t*)XP_MALLOC( giState->dlgHdr.globals->mpool, len * sizeof(wstr[0]) ); XP_MEMCPY( wstr, wPath, len*sizeof(wstr[0]) ); @@ -86,13 +86,13 @@ addDictToState( const wchar_t* wPath, XP_U16 XP_UNUSED(index), void* ctxt ) XP_ASSERT( giState->capMenuDicts == 0 ); giState->capMenuDicts = MENUDICTS_INCR; giState->menuDicts - = (wchar_t**)XP_MALLOC( giState->globals->mpool, + = (wchar_t**)XP_MALLOC( giState->dlgHdr.globals->mpool, giState->capMenuDicts * sizeof(giState->menuDicts[0]) ); } else if ( giState->nMenuDicts == giState->capMenuDicts ) { giState->capMenuDicts += MENUDICTS_INCR; giState->menuDicts - = (wchar_t**)XP_REALLOC( giState->globals->mpool, + = (wchar_t**)XP_REALLOC( giState->dlgHdr.globals->mpool, giState->menuDicts, giState->capMenuDicts * sizeof(giState->menuDicts[0]) ); @@ -122,7 +122,7 @@ addDictsToMenu( GameInfoState* giState ) for ( i = 0; i < nMenuDicts; ++i ) { wchar_t* wPath = giState->menuDicts[i]; shortname = wbname( shortPath, sizeof(shortPath), wPath ); - SendDlgItemMessage( giState->hDlg, IDC_DICTLIST, ADDSTRING, 0, + SendDlgItemMessage( giState->dlgHdr.hDlg, IDC_DICTLIST, ADDSTRING, 0, (long)shortname ); if ( giState->newDictName[0] != 0 && sel == 0 ) { @@ -135,7 +135,7 @@ addDictsToMenu( GameInfoState* giState ) } } - SendDlgItemMessage( giState->hDlg, IDC_DICTLIST, SETCURSEL, sel, 0L ); + SendDlgItemMessage( giState->dlgHdr.hDlg, IDC_DICTLIST, SETCURSEL, sel, 0L ); } /* addDictsToMenu */ static void @@ -145,18 +145,18 @@ cleanupGameInfoState( GameInfoState* giState ) XP_U16 nMenuDicts = giState->nMenuDicts; XP_U16 i; for ( i = 0; i < nMenuDicts; ++i ) { - XP_FREE( giState->globals->mpool, giState->menuDicts[i] ); + XP_FREE( giState->dlgHdr.globals->mpool, giState->menuDicts[i] ); } - XP_FREE( giState->globals->mpool, giState->menuDicts ); + XP_FREE( giState->dlgHdr.globals->mpool, giState->menuDicts ); giState->menuDicts = NULL; } } /* cleanupGameInfoState */ static void -loadFromGameInfo( HWND hDlg, CEAppGlobals* globals, GameInfoState* giState ) +loadFromGameInfo( GameInfoState* giState ) { XP_U16 i; - CurGameInfo* gi = &globals->gameInfo; + CurGameInfo* gi = &giState->dlgHdr.globals->gameInfo; #if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH wchar_t* roles[] = { L"Standalone", L"Host", L"Guest" }; @@ -170,7 +170,7 @@ loadFromGameInfo( HWND hDlg, CEAppGlobals* globals, GameInfoState* giState ) wchar_t widebuf[8]; /* put a string in the moronic combobox */ swprintf( widebuf, L"%d", i + 1 ); - SendDlgItemMessage( hDlg, IDC_NPLAYERSCOMBO, ADDSTRING, 0, + SendDlgItemMessage( giState->dlgHdr.hDlg, IDC_NPLAYERSCOMBO, ADDSTRING, 0, (long)widebuf ); } @@ -182,7 +182,7 @@ loadFromGameInfo( HWND hDlg, CEAppGlobals* globals, GameInfoState* giState ) (XP_U16)XP_STRLEN(gi->dictName)+1 ); } if ( giState->isNewGame ) { - (void)ceLocateNDicts( MPPARM(globals->mpool) + (void)ceLocateNDicts( MPPARM(giState->dlgHdr.globals->mpool) CE_MAXDICTS, addDictToState, giState ); } else { wchar_t wPath[CE_MAX_PATH_LEN+1]; @@ -195,14 +195,16 @@ loadFromGameInfo( HWND hDlg, CEAppGlobals* globals, GameInfoState* giState ) #endif if ( !giState->isNewGame ) { - ceEnOrDisable( hDlg, IDC_DICTLIST, XP_FALSE ); + ceEnOrDisable( giState->dlgHdr.hDlg, IDC_DICTLIST, XP_FALSE ); } } /* loadFromGameInfo */ static XP_Bool -stateToGameInfo( HWND hDlg, CEAppGlobals* globals, GameInfoState* giState ) +stateToGameInfo( GameInfoState* giState ) { + CEAppGlobals* globals = giState->dlgHdr.globals; CurGameInfo* gi = &globals->gameInfo; + HWND hDlg = giState->dlgHdr.hDlg; XP_Bool timerOn; XP_Bool success = newg_store( giState->newGameCtx, gi, XP_TRUE ); @@ -346,7 +348,7 @@ ceEnableColProc( void* closure, XP_U16 player, NewGameColumn col, { GameInfoState* giState = (GameInfoState*)closure; XP_U16 resID = resIDForCol( player, col ); - doForNWEnable( giState->hDlg, resID, enable ); + doForNWEnable( giState->dlgHdr.hDlg, resID, enable ); } static void @@ -354,7 +356,7 @@ ceEnableAttrProc( void* closure, NewGameAttr attr, XP_TriEnable enable ) { GameInfoState* giState = (GameInfoState*)closure; XP_U16 resID = resIDForAttr( attr ); - doForNWEnable( giState->hDlg, resID, enable ); + doForNWEnable( giState->dlgHdr.hDlg, resID, enable ); } /* ceEnableAttrProc */ static void @@ -372,12 +374,12 @@ ceGetColProc( void* closure, XP_U16 player, NewGameColumn col, case NG_COL_REMOTE: #endif case NG_COL_ROBOT: - value.ng_bool = ceGetChecked( giState->hDlg, resID ); + value.ng_bool = ceGetChecked( giState->dlgHdr.hDlg, resID ); break; case NG_COL_NAME: case NG_COL_PASSWD: len = sizeof(txt); - ceGetDlgItemText( giState->hDlg, resID, txt, &len ); + ceGetDlgItemText( giState->dlgHdr.hDlg, resID, txt, &len ); value.ng_cp = &txt[0]; break; default: @@ -403,13 +405,13 @@ ceSetColProc( void* closure, XP_U16 player, NewGameColumn col, } else { cp = value.ng_cp; } - ceSetDlgItemText( giState->hDlg, resID, cp ); + ceSetDlgItemText( giState->dlgHdr.hDlg, resID, cp ); break; #ifndef XWFEATURE_STANDALONE_ONLY case NG_COL_REMOTE: #endif case NG_COL_ROBOT: - ceSetChecked( giState->hDlg, resID, value.ng_bool ); + ceSetChecked( giState->dlgHdr.hDlg, resID, value.ng_bool ); break; default: XP_ASSERT(0); @@ -424,17 +426,17 @@ ceSetAttrProc(void* closure, NewGameAttr attr, const NGValue value ) switch ( attr ) { case NG_ATTR_NPLAYERS: - SendDlgItemMessage( giState->hDlg, resID, SETCURSEL, + SendDlgItemMessage( giState->dlgHdr.hDlg, resID, SETCURSEL, value.ng_u16 - 1, 0L ); break; #ifndef XWFEATURE_STANDALONE_ONLY case NG_ATTR_ROLE: - SendDlgItemMessage( giState->hDlg, resID, SETCURSEL, + SendDlgItemMessage( giState->dlgHdr.hDlg, resID, SETCURSEL, value.ng_role, 0L ); break; #endif case NG_ATTR_NPLAYHEADER: - ceSetDlgItemText( giState->hDlg, resID, value.ng_cp ); + ceSetDlgItemText( giState->dlgHdr.hDlg, resID, value.ng_cp ); break; default: break; @@ -456,7 +458,7 @@ handleColChecked( GameInfoState* giState, XP_U16 id, XP_U16 base ) NGValue value; XP_U16 player = playerFromID( id, base ); - value.ng_bool = ceGetChecked( giState->hDlg, id ); + value.ng_bool = ceGetChecked( giState->dlgHdr.hDlg, id ); newg_colChanged( giState->newGameCtx, player ); } @@ -492,11 +494,9 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) if ( message == WM_INITDIALOG ) { SetWindowLong( hDlg, GWL_USERDATA, lParam ); giState = (GameInfoState*)lParam; - giState->hDlg = hDlg; - globals = giState->globals; + globals = giState->dlgHdr.globals; - ceDlgSetup( globals, hDlg ); - trapBackspaceKey( hDlg ); + ceDlgSetup( &giState->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); giState->newGameCtx = newg_make( MPPARM(globals->mpool) giState->isNewGame, @@ -508,7 +508,7 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) ceSetAttrProc, giState ); - loadFromGameInfo( hDlg, globals, giState ); + loadFromGameInfo( giState ); loadStateFromCurPrefs( globals, &globals->appPrefs, &globals->gameInfo, &giState->prefsPrefs ); @@ -521,131 +521,119 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) } else { giState = (GameInfoState*)GetWindowLong( hDlg, GWL_USERDATA ); if ( !!giState ) { - globals = giState->globals; + globals = giState->dlgHdr.globals; - switch (message) { -#ifdef _WIN32_WCE - case WM_HOTKEY: - if ( VK_TBACK == HIWORD(lParam) ) { - SHSendBackToFocusWindow( message, wParam, lParam ); - result = TRUE; - } - break; -#endif - case WM_VSCROLL: - result = ceDoDlgScroll( globals, hDlg, wParam ); - break; - - /* WM_NEXTDLGCTL is worthless; prev obj still has focus */ - case WM_NEXTDLGCTL: - ceDoDlgFocusScroll( globals, hDlg, wParam, lParam ); - break; + XP_ASSERT( hDlg == giState->dlgHdr.hDlg ); + result = ceDoDlgHandle( &giState->dlgHdr, message, wParam, lParam ); + if ( !result ) { + switch (message) { #ifdef OWNERDRAW_JUGGLE - case WM_DRAWITEM: /* for BS_OWNERDRAW style */ - ceDrawIconButton( globals, (DRAWITEMSTRUCT*)lParam ); - result = TRUE; - break; + case WM_DRAWITEM: /* for BS_OWNERDRAW style */ + ceDrawIconButton( globals, (DRAWITEMSTRUCT*)lParam ); + result = TRUE; + break; #endif - case WM_COMMAND: - result = TRUE; - id = LOWORD(wParam); - switch( id ) { + case WM_COMMAND: + result = TRUE; + id = LOWORD(wParam); + switch( id ) { - case ROBOT_CHECK1: - case ROBOT_CHECK2: - case ROBOT_CHECK3: - case ROBOT_CHECK4: - handleColChecked( giState, id, ROBOT_CHECK1 ); - break; + case ROBOT_CHECK1: + case ROBOT_CHECK2: + case ROBOT_CHECK3: + case ROBOT_CHECK4: + handleColChecked( giState, id, ROBOT_CHECK1 ); + break; #ifndef XWFEATURE_STANDALONE_ONLY - case REMOTE_CHECK1: - case REMOTE_CHECK2: - case REMOTE_CHECK3: - case REMOTE_CHECK4: - handleColChecked( giState, id, REMOTE_CHECK1 ); - break; + case REMOTE_CHECK1: + case REMOTE_CHECK2: + case REMOTE_CHECK3: + case REMOTE_CHECK4: + handleColChecked( giState, id, REMOTE_CHECK1 ); + break; #endif - case IDC_NPLAYERSCOMBO: - if ( HIWORD(wParam) == CBN_SELCHANGE ) { - if ( giState->isNewGame ) { /* ignore if in info - mode */ - NGValue value; - value.ng_u16 = 1 + (XP_U16) - SendDlgItemMessage( hDlg, - IDC_NPLAYERSCOMBO, - GETCURSEL, 0, 0L); - newg_attrChanged( giState->newGameCtx, - NG_ATTR_NPLAYERS, value ); - } - } - break; - -#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH - case IDC_ROLECOMBO: - if ( HIWORD(wParam) == CBN_SELCHANGE ) { - if ( giState->isNewGame ) { /* ignore if in info - mode */ - NGValue value; - value.ng_role = - (DeviceRole)SendDlgItemMessage( hDlg, - IDC_ROLECOMBO, - CB_GETCURSEL, 0, - 0L); - newg_attrChanged( giState->newGameCtx, - NG_ATTR_ROLE, value ); - /* If we've switched to a state where we'll be - connecting */ - if ( value.ng_role != SERVER_STANDALONE ) { - handleConnOptionsButton( hDlg, globals, - value.ng_role, - giState ); + case IDC_NPLAYERSCOMBO: + if ( HIWORD(wParam) == CBN_SELCHANGE ) { + if ( giState->isNewGame ) { /* ignore if in info + mode */ + NGValue value; + value.ng_u16 = 1 + (XP_U16) + SendDlgItemMessage( hDlg, + IDC_NPLAYERSCOMBO, + GETCURSEL, 0, 0L); + newg_attrChanged( giState->newGameCtx, + NG_ATTR_NPLAYERS, value ); } } - } - break; -#endif - case GIJUGGLE_BUTTON: - XP_ASSERT( giState->isNewGame ); - /* Juggle vs switch. On Win32, updates are coalesced so - you don't see anything on screen if you change a field - then change it back. In terms of messages, all we see - here is a WM_CTLCOLOREDIT for each field being - changed. If I post a custom event here, it comes in - *before* the WM_CTLCOLOREDIT events. Short of a - timer, which starts a race with the user, I see no way - to get notified after the drawing's done. So for now, - we switch rather than juggle: call juggle until - something actually happens. */ - while ( !newg_juggle( giState->newGameCtx ) ) { - } - break; - - case OPTIONS_BUTTON: - handlePrefsButton( hDlg, globals, giState ); - break; - - case IDOK: - if ( !stateToGameInfo( hDlg, globals, giState ) ) { break; + +#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH + case IDC_ROLECOMBO: + if ( HIWORD(wParam) == CBN_SELCHANGE ) { + if ( giState->isNewGame ) { /* ignore if in info + mode */ + NGValue value; + value.ng_role = + (DeviceRole)SendDlgItemMessage( hDlg, + IDC_ROLECOMBO, + CB_GETCURSEL, 0, + 0L); + newg_attrChanged( giState->newGameCtx, + NG_ATTR_ROLE, value ); + /* If we've switched to a state where we'll be + connecting */ + if ( value.ng_role != SERVER_STANDALONE ) { + handleConnOptionsButton( hDlg, globals, + value.ng_role, + giState ); + } + } + } + break; +#endif + case GIJUGGLE_BUTTON: + XP_ASSERT( giState->isNewGame ); + /* Juggle vs switch. On Win32, updates are coalesced so + you don't see anything on screen if you change a field + then change it back. In terms of messages, all we see + here is a WM_CTLCOLOREDIT for each field being + changed. If I post a custom event here, it comes in + *before* the WM_CTLCOLOREDIT events. Short of a + timer, which starts a race with the user, I see no way + to get notified after the drawing's done. So for now, + we switch rather than juggle: call juggle until + something actually happens. */ + while ( !newg_juggle( giState->newGameCtx ) ) { + } + break; + + case OPTIONS_BUTTON: + handlePrefsButton( hDlg, globals, giState ); + break; + + case IDOK: + if ( !stateToGameInfo( giState ) ) { + break; + } + case IDCANCEL: + EndDialog(hDlg, id); + giState->userCancelled = id == IDCANCEL; + cleanupGameInfoState( giState ); + newg_destroy( giState->newGameCtx ); } - case IDCANCEL: - EndDialog(hDlg, id); - giState->userCancelled = id == IDCANCEL; - cleanupGameInfoState( giState ); - newg_destroy( giState->newGameCtx ); + break; + default: + result = FALSE; + /* case WM_CLOSE: */ + /* EndDialog(hDlg, id); */ + /* return TRUE; */ + /* default: */ + /* return DefWindowProc(hDlg, message, wParam, lParam); */ } - break; - default: - result = FALSE; - /* case WM_CLOSE: */ - /* EndDialog(hDlg, id); */ - /* return TRUE; */ - /* default: */ - /* return DefWindowProc(hDlg, message, wParam, lParam); */ } } } diff --git a/xwords4/wince/ceginfo.h b/xwords4/wince/ceginfo.h index 6f8629687..93382c0d3 100755 --- a/xwords4/wince/ceginfo.h +++ b/xwords4/wince/ceginfo.h @@ -24,11 +24,11 @@ #include "cemain.h" #include "ceprefs.h" #include "cedict.h" +#include "ceutil.h" #include "nwgamest.h" typedef struct GameInfoState { - CEAppGlobals* globals; - HWND hDlg; + CeDlgHdr dlgHdr; NewGameCtx* newGameCtx; XP_UCHAR newDictName[CE_MAX_PATH_LEN+1]; diff --git a/xwords4/wince/cehntlim.c b/xwords4/wince/cehntlim.c index 4fca6fdc6..385dc285c 100755 --- a/xwords4/wince/cehntlim.c +++ b/xwords4/wince/cehntlim.c @@ -21,7 +21,6 @@ #include #include "cehntlim.h" -#include "ceutil.h" static void initComboBox( HWND hDlg, XP_U16 id, XP_U16 startVal ) @@ -55,15 +54,13 @@ LRESULT CALLBACK HintLimitsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { HintLimitsState* hState; - CEAppGlobals* globals; XP_U16 id; if ( message == WM_INITDIALOG ) { SetWindowLong( hDlg, GWL_USERDATA, lParam ); hState = (HintLimitsState*)lParam; - globals = hState->globals; - ceDlgSetup( globals, hDlg ); + ceDlgSetup( &hState->dlgHdr, hDlg, DLG_STATE_NONE ); return TRUE; } else { @@ -76,6 +73,10 @@ HintLimitsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) hState->inited = XP_TRUE; } + if ( ceDoDlgHandle( &hState->dlgHdr, message, wParam, lParam) ) { + return TRUE; + } + switch ( message ) { case WM_COMMAND: id = LOWORD(wParam); diff --git a/xwords4/wince/cehntlim.h b/xwords4/wince/cehntlim.h index 78fdad559..791556c1e 100755 --- a/xwords4/wince/cehntlim.h +++ b/xwords4/wince/cehntlim.h @@ -23,9 +23,10 @@ #ifdef XWFEATURE_SEARCHLIMIT #include "cemain.h" +#include "ceutil.h" typedef struct HintLimitsState { - CEAppGlobals* globals; + CeDlgHdr dlgHdr; XP_U16 min, max; XP_Bool inited; XP_Bool cancelled; diff --git a/xwords4/wince/cemain.c b/xwords4/wince/cemain.c index cbc4e3c06..b221e9a05 100755 --- a/xwords4/wince/cemain.c +++ b/xwords4/wince/cemain.c @@ -1464,7 +1464,7 @@ ceDoNewGame( CEAppGlobals* globals ) } XP_MEMSET( &giState, 0, sizeof(giState) ); - giState.globals = globals; + giState.dlgHdr.globals = globals; giState.isNewGame = XP_TRUE; DialogBoxParam( globals->hInst, (LPCTSTR)IDD_GAMEINFO, globals->hWnd, @@ -2054,7 +2054,7 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) GameInfoState state; XP_MEMSET( &state, 0, sizeof(state) ); - state.globals = globals; + state.dlgHdr.globals = globals; DialogBoxParam(globals->hInst, (LPCTSTR)IDD_GAMEINFO, hWnd, (DLGPROC)GameInfo, (long)&state ); @@ -2376,18 +2376,18 @@ ceMsgFromStream( CEAppGlobals* globals, XWStreamCtxt* stream, int result = messageBoxStream( globals, stream, title, buttons ); saidYes = (IDOK == result) | (IDRETRY == result) | (IDYES == result); } else { - StrBoxInit init; + StrBoxState state; - XP_MEMSET( &init, 0, sizeof(init) ); + XP_MEMSET( &state, 0, sizeof(state) ); - init.title = title; - init.stream = stream; - init.isQuery = buttons != MB_OK; - init.globals = globals; + state.title = title; + state.stream = stream; + state.isQuery = buttons != MB_OK; + state.dlgHdr.globals = globals; DialogBoxParam( globals->hInst, (LPCTSTR)IDD_STRBOX, globals->hWnd, - (DLGPROC)StrBox, (long)&init ); - saidYes = init.result == IDOK; + (DLGPROC)StrBox, (long)&state ); + saidYes = state.result == IDOK; } if ( destroy ) { @@ -2798,7 +2798,7 @@ ce_util_userPickTile( XW_UtilCtxt* uc, const PickInfo* pi, CEAppGlobals* globals = (CEAppGlobals*)uc->closure; XP_MEMSET( &state, 0, sizeof(state) ); - state.globals = globals; + state.dlgHdr.globals = globals; state.texts = texts; state.nTiles = nTiles; state.playerNum = playerNum; @@ -2817,7 +2817,7 @@ ce_util_askPassword( XW_UtilCtxt* uc, const XP_UCHAR* name, CEAppGlobals* globals = (CEAppGlobals*)uc->closure; XP_MEMSET( &state, 0, sizeof(state) ); - state.globals = globals; + state.dlgHdr.globals = globals; state.name = name; state.buf = buf; state.lenp = len; @@ -3111,7 +3111,7 @@ ce_util_getTraySearchLimits( XW_UtilCtxt* uc, XP_U16* min, XP_U16* max ) XP_MEMSET( &hls, 0, sizeof(hls) ); - hls.globals = globals; + hls.dlgHdr.globals = globals; hls.min = *min; hls.max = *max; diff --git a/xwords4/wince/ceprefs.c b/xwords4/wince/ceprefs.c index de3df1a0a..c5d1ab9d8 100755 --- a/xwords4/wince/ceprefs.c +++ b/xwords4/wince/ceprefs.c @@ -77,7 +77,7 @@ adjustForChoice( HWND hDlg, CePrefsDlgState* state ) #endif }; XP_U16 resID; - XP_Bool doGlobalPrefs = state->globals->doGlobalPrefs; + XP_Bool doGlobalPrefs = state->dlgHdr.globals->doGlobalPrefs; resID = doGlobalPrefs? IDC_RADIOGLOBAL:IDC_RADIOLOCAL; SendDlgItemMessage( hDlg, resID, BM_SETCHECK, BST_CHECKED, 0L ); @@ -248,81 +248,64 @@ ceControlsToPrefs( HWND hDlg, CePrefsPrefs* prefsPrefs ) LRESULT CALLBACK PrefsDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - CEAppGlobals* globals; XP_U16 id; CePrefsDlgState* pState; if ( message == WM_INITDIALOG ) { SetWindowLong( hDlg, GWL_USERDATA, lParam ); pState = (CePrefsDlgState*)lParam; - globals = pState->globals; stuffPhoniesList( hDlg ); loadControlsFromState( hDlg, pState ); adjustForChoice( hDlg, pState ); - ceDlgSetup( globals, hDlg ); - trapBackspaceKey( hDlg ); - + ceDlgSetup( &pState->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); return TRUE; } else { - XP_Bool timerOn; pState = (CePrefsDlgState*)GetWindowLong( hDlg, GWL_USERDATA ); if ( !!pState ) { - globals = pState->globals; + if ( !ceDoDlgHandle( &pState->dlgHdr, message, wParam, lParam ) ) { + CEAppGlobals* globals = pState->dlgHdr.globals; + XP_Bool timerOn; - switch (message) { - case WM_VSCROLL: - ceDoDlgScroll( globals, hDlg, wParam ); - break; -#ifdef _WIN32_WCE - case WM_HOTKEY: - if ( VK_TBACK == HIWORD(lParam) ) { - SHSendBackToFocusWindow( message, wParam, lParam ); - return TRUE; - } - break; -#endif - case WM_NEXTDLGCTL: - ceDoDlgFocusScroll( globals, hDlg, wParam, lParam ); - break; + switch (message) { + case WM_COMMAND: + id = LOWORD(wParam); + switch( id ) { - case WM_COMMAND: - id = LOWORD(wParam); - switch( id ) { + case IDC_RADIOGLOBAL: + case IDC_RADIOLOCAL: + globals->doGlobalPrefs = id == IDC_RADIOGLOBAL; + adjustForChoice( hDlg, pState ); + break; - case IDC_RADIOGLOBAL: - case IDC_RADIOLOCAL: - pState->globals->doGlobalPrefs = id == IDC_RADIOGLOBAL; - adjustForChoice( hDlg, pState ); - break; - - case TIMER_CHECK: - timerOn = SendDlgItemMessage( hDlg, TIMER_CHECK, BM_GETCHECK, - 0, 0 ); - setTimerCtls( hDlg, timerOn ); - break; - case IDC_PREFCOLORS: - pState->colorsChanged = - ceDoColorsEdit( hDlg, pState->globals, - pState->prefsPrefs.colors ); - break; + case TIMER_CHECK: + timerOn = SendDlgItemMessage( hDlg, TIMER_CHECK, + BM_GETCHECK, 0, 0 ); + setTimerCtls( hDlg, timerOn ); + break; + case IDC_PREFCOLORS: + pState->colorsChanged = + ceDoColorsEdit( hDlg, globals, + pState->prefsPrefs.colors ); + break; #ifdef XWFEATURE_SEARCHLIMIT - case IDC_CHECKNOHINTS: - timerOn = SendDlgItemMessage( hDlg, IDC_CHECKNOHINTS, - BM_GETCHECK, 0, 0 ); - ceShowOrHide( hDlg, IDC_CHECKHINTSLIMITS, !timerOn ); - break; + case IDC_CHECKNOHINTS: + timerOn = SendDlgItemMessage( hDlg, IDC_CHECKNOHINTS, + BM_GETCHECK, 0, 0 ); + ceShowOrHide( hDlg, IDC_CHECKHINTSLIMITS, !timerOn ); + break; #endif - case IDOK: - ceControlsToPrefs( hDlg, &pState->prefsPrefs ); - case IDCANCEL: - EndDialog(hDlg, id); - pState->userCancelled = id == IDCANCEL; - return TRUE; + case IDOK: + ceControlsToPrefs( hDlg, &pState->prefsPrefs ); + case IDCANCEL: + EndDialog(hDlg, id); + pState->userCancelled = id == IDCANCEL; + return TRUE; + } } } } @@ -341,7 +324,7 @@ WrapPrefsDialog( HWND hDlg, CEAppGlobals* globals, CePrefsDlgState* state, XP_Bool result; XP_MEMSET( state, 0, sizeof(*state) ); - state->globals = globals; + state->dlgHdr.globals = globals; state->isNewGame = isNewGame; XP_MEMCPY( &state->prefsPrefs, prefsPrefs, sizeof( state->prefsPrefs ) ); diff --git a/xwords4/wince/ceprefs.h b/xwords4/wince/ceprefs.h index 60b89f78a..eae64e716 100755 --- a/xwords4/wince/ceprefs.h +++ b/xwords4/wince/ceprefs.h @@ -22,6 +22,7 @@ #include "stdafx.h" #include "cemain.h" +#include "ceutil.h" typedef struct CeGamePrefs { XP_U16 gameSeconds; @@ -55,7 +56,7 @@ typedef struct CePrefsPrefs { } CePrefsPrefs; typedef struct CePrefsDlgState { - CEAppGlobals* globals; + CeDlgHdr dlgHdr; CePrefsPrefs prefsPrefs; XP_Bool userCancelled; diff --git a/xwords4/wince/cestrbx.c b/xwords4/wince/cestrbx.c index 0f9de0bb8..8847a4d04 100755 --- a/xwords4/wince/cestrbx.c +++ b/xwords4/wince/cestrbx.c @@ -22,18 +22,18 @@ #include "ceutil.h" static void -stuffTextInField( HWND hDlg, StrBoxInit* init ) +stuffTextInField( HWND hDlg, StrBoxState* state ) { - XP_U16 nBytes = stream_getSize(init->stream); + XP_U16 nBytes = stream_getSize(state->stream); XP_U16 len, crlen; XP_UCHAR* sbuf; wchar_t* wbuf; #ifdef MEM_DEBUG - CEAppGlobals* globals = init->globals; + CEAppGlobals* globals = state->dlgHdr.globals; #endif sbuf = XP_MALLOC( globals->mpool, nBytes + 1 ); - stream_getBytes( init->stream, sbuf, nBytes ); + stream_getBytes( state->stream, sbuf, nBytes ); crlen = strlen(XP_CR); if ( 0 == strncmp( XP_CR, &sbuf[nBytes-crlen], crlen ) ) { @@ -58,60 +58,57 @@ StrBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { LRESULT handled = FALSE; CEAppGlobals* globals = NULL; - StrBoxInit* init; + StrBoxState* state; XP_U16 id; if ( message == WM_INITDIALOG ) { SetWindowLong( hDlg, GWL_USERDATA, (long)lParam ); - init = (StrBoxInit*)lParam; + state = (StrBoxState*)lParam; - globals = init->globals; - - if ( !!init->title ) { - SendMessage( hDlg, WM_SETTEXT, 0, (long)init->title ); + if ( !!state->title ) { + SendMessage( hDlg, WM_SETTEXT, 0, (long)state->title ); } - if ( !init->isQuery ) { + if ( !state->isQuery ) { ceShowOrHide( hDlg, IDCANCEL, XP_FALSE ); /* also want to expand the text box to the bottom */ - if ( !ceIsLandscape( globals ) ) { + if ( !ceIsLandscape( state->dlgHdr.globals ) ) { ceCenterCtl( hDlg, IDOK ); } } - ceDlgSetup( globals, hDlg ); + ceDlgSetup( &state->dlgHdr, hDlg, DLG_STATE_NONE ); handled = TRUE; } else { - init = (StrBoxInit*)GetWindowLong( hDlg, GWL_USERDATA ); + state = (StrBoxState*)GetWindowLong( hDlg, GWL_USERDATA ); - if ( !!init ) { + if ( !!state ) { + if ( ceDoDlgHandle( &state->dlgHdr, message, wParam, lParam) ) { + handled = TRUE; + } else { + switch (message) { - switch (message) { + case WM_COMMAND: - case WM_VSCROLL: - ceDoDlgScroll( globals, hDlg, wParam ); - break; + /* If I add the text above in the WM_INITDIALOG section it + shows up selected though selStart and selEnd are 0. */ + if ( !state->textIsSet ) { + state->textIsSet = XP_TRUE; + stuffTextInField( hDlg, state ); + } - case WM_COMMAND: + id = LOWORD(wParam); + switch( id ) { - /* If I add the text above in the WM_INITDIALOG section it - shows up selected though selStart and selEnd are 0. */ - if ( !init->textIsSet ) { - init->textIsSet = XP_TRUE; - stuffTextInField( hDlg, init ); - } - - id = LOWORD(wParam); - switch( id ) { - - case IDOK: - case IDCANCEL: - init->result = id; - EndDialog(hDlg, id); - handled = TRUE; + case IDOK: + case IDCANCEL: + state->result = id; + EndDialog(hDlg, id); + handled = TRUE; + } + break; } - break; } } } diff --git a/xwords4/wince/cestrbx.h b/xwords4/wince/cestrbx.h index d44e985ce..74eae0a09 100755 --- a/xwords4/wince/cestrbx.h +++ b/xwords4/wince/cestrbx.h @@ -21,16 +21,17 @@ #include "xwstream.h" #include "cemain.h" +#include "ceutil.h" LRESULT CALLBACK StrBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); -typedef struct StrBoxInit { - CEAppGlobals* globals; +typedef struct StrBoxState { + CeDlgHdr dlgHdr; wchar_t* title; XWStreamCtxt* stream; XP_U16 result; XP_Bool isQuery; XP_Bool textIsSet; -} StrBoxInit; +} StrBoxState; diff --git a/xwords4/wince/cesvdgms.c b/xwords4/wince/cesvdgms.c index 55a33653a..537b3677b 100644 --- a/xwords4/wince/cesvdgms.c +++ b/xwords4/wince/cesvdgms.c @@ -29,7 +29,7 @@ #include "debhacks.h" typedef struct CeSaveGameNameState { - CEAppGlobals* globals; + CeDlgHdr dlgHdr; wchar_t* buf; XP_U16 buflen; XP_Bool cancelled; @@ -83,8 +83,7 @@ SaveNameDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) state->cancelled = XP_TRUE; state->inited = XP_FALSE; - ceDlgSetup( state->globals, hDlg ); - trapBackspaceKey( hDlg ); + ceDlgSetup( &state->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); result = TRUE; } else { @@ -95,36 +94,33 @@ SaveNameDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) (void)SetDlgItemText( hDlg, IDC_SVGN_EDIT, state->buf ); } - switch (message) { -#ifdef _WIN32_WCE - case WM_HOTKEY: - if ( VK_TBACK == HIWORD(lParam) ) { - SHSendBackToFocusWindow( message, wParam, lParam ); - result = TRUE; - } - break; -#endif - case WM_COMMAND: - wid = LOWORD(wParam); - switch( wid ) { - case IDOK: { - wchar_t buf[128]; - (void)GetDlgItemText( hDlg, IDC_SVGN_EDIT, buf, - VSIZE(buf) ); - if ( ceFileExists( buf ) ) { - messageBoxChar( state->globals, "File exists", - L"Oops!", MB_OK ); + if ( ceDoDlgHandle( &state->dlgHdr, message, wParam, lParam) ) { + result = TRUE; + } else { + + switch (message) { + case WM_COMMAND: + wid = LOWORD(wParam); + switch( wid ) { + case IDOK: { + wchar_t buf[128]; + (void)GetDlgItemText( hDlg, IDC_SVGN_EDIT, buf, + VSIZE(buf) ); + if ( ceFileExists( buf ) ) { + messageBoxChar( state->dlgHdr.globals, "File exists", + L"Oops!", MB_OK ); + break; + } + swprintf( state->buf, DEFAULT_DIR_NAME L"\\%s.xwg", buf ); + XP_LOGW( __func__, state->buf ); + /* fallthru */ + state->cancelled = XP_FALSE; + } + case IDCANCEL: + EndDialog(hDlg, wid); + result = TRUE; break; } - swprintf( state->buf, DEFAULT_DIR_NAME L"\\%s.xwg", buf ); - XP_LOGW( __func__, state->buf ); - /* fallthru */ - state->cancelled = XP_FALSE; - } - case IDCANCEL: - EndDialog(hDlg, wid); - result = TRUE; - break; } } } @@ -142,7 +138,7 @@ ceConfirmUniqueName( CEAppGlobals* globals, wchar_t* buf, XP_U16 buflen ) makeUniqueName( buf, buflen ); XP_MEMSET( &state, 0, sizeof(state) ); - state.globals = globals; + state.dlgHdr.globals = globals; state.buf = buf; state.buflen = buflen; (void)DialogBoxParam( globals->hInst, (LPCTSTR)IDD_SAVENAMEDLG, @@ -153,8 +149,7 @@ ceConfirmUniqueName( CEAppGlobals* globals, wchar_t* buf, XP_U16 buflen ) } /* ceConfirmUniqueName */ typedef struct CeSavedGamesState { - CEAppGlobals* globals; - HWND hDlg; + CeDlgHdr dlgHdr; wchar_t* buf; XP_U16 buflen; XP_S16 sel; @@ -197,7 +192,7 @@ static void setButtons( CeSavedGamesState* state ) { /* Open button disabled by default in case no games */ - ceEnOrDisable( state->hDlg, IDC_SVGM_OPEN, state->nItems > 0 ); + ceEnOrDisable( state->dlgHdr.hDlg, IDC_SVGM_OPEN, state->nItems > 0 ); /* ceEnOrDisable( state->hDlg, IDC_SVGM_DEL, state->nItems > 0 ); */ } @@ -225,7 +220,7 @@ initSavedGamesData( CeSavedGamesState* state ) XP_ASSERT( data.cFileName[len-4] == '.'); data.cFileName[len-4] = 0; - SendDlgItemMessage( state->hDlg, IDC_SVGM_GAMELIST, ADDSTRING, + SendDlgItemMessage( state->dlgHdr.hDlg, IDC_SVGM_GAMELIST, ADDSTRING, 0, (LPARAM)data.cFileName ); ++state->nItems; @@ -236,7 +231,7 @@ initSavedGamesData( CeSavedGamesState* state ) } } - SendDlgItemMessage( state->hDlg, IDC_SVGM_GAMELIST, SETCURSEL, curSel, 0 ); + SendDlgItemMessage( state->dlgHdr.hDlg, IDC_SVGM_GAMELIST, SETCURSEL, curSel, 0 ); state->sel = curSel; setEditFromSel( state ); @@ -277,10 +272,9 @@ SavedGamesDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) SetWindowLong( hDlg, GWL_USERDATA, lParam ); state = (CeSavedGamesState*)lParam; - state->hDlg = hDlg; state->inited = XP_FALSE; - ceDlgSetup( state->globals, hDlg ); + ceDlgSetup( &state->dlgHdr, hDlg, DLG_STATE_NONE ); result = TRUE; } else { @@ -292,56 +286,52 @@ SavedGamesDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) initSavedGamesData( state ); } - switch (message) { + if ( ceDoDlgHandle( &state->dlgHdr, message, wParam, lParam) ) { + result = TRUE; + } else { + switch (message) { - case WM_VSCROLL: - ceDoDlgScroll( state->globals, hDlg, wParam ); - break; + case WM_COMMAND: + wid = LOWORD(wParam); + switch( wid ) { - case WM_NEXTDLGCTL: - ceDoDlgFocusScroll( state->globals, hDlg, wParam, lParam ); - break; - - case WM_COMMAND: - wid = LOWORD(wParam); - switch( wid ) { - - case IDC_SVGM_GAMELIST: - if ( HIWORD(wParam) == CBN_SELCHANGE ) { - XP_S16 sel = SendDlgItemMessage( state->hDlg, - IDC_SVGM_GAMELIST, - GETCURSEL, 0, 0L); - if ( sel >= 0 ) { - state->sel = sel; - setEditFromSel( state ); + case IDC_SVGM_GAMELIST: + if ( HIWORD(wParam) == CBN_SELCHANGE ) { + XP_S16 sel = SendDlgItemMessage( hDlg, + IDC_SVGM_GAMELIST, + GETCURSEL, 0, 0L); + if ( sel >= 0 ) { + state->sel = sel; + setEditFromSel( state ); + } } + break; + + /* case IDC_SVGM_DUP: */ + /* case IDC_SVGM_CHANGE: */ + /* notImpl( state->globals ); */ + /* break; */ + /* case IDC_SVGM_DEL: */ + /* deleteSelected( state ); */ + /* break; */ + + case IDC_SVGM_OPEN: { + wchar_t buf[128]; + XP_U16 len = VSIZE(buf); + getCBText( hDlg, IDC_SVGM_GAMELIST, state->sel, + buf, &len ); + swprintf( state->buf, DEFAULT_DIR_NAME L"\\%s.xwg", buf ); + XP_LOGW( "returning", state->buf ); + state->opened = XP_TRUE; + } + /* fallthrough */ + case IDOK: + /* fallthrough */ + case IDCANCEL: + EndDialog(hDlg, wid); + result = TRUE; + break; } - break; - -/* case IDC_SVGM_DUP: */ -/* case IDC_SVGM_CHANGE: */ -/* notImpl( state->globals ); */ -/* break; */ -/* case IDC_SVGM_DEL: */ -/* deleteSelected( state ); */ -/* break; */ - - case IDC_SVGM_OPEN: { - wchar_t buf[128]; - XP_U16 len = VSIZE(buf); - getCBText( state->hDlg, IDC_SVGM_GAMELIST, state->sel, - buf, &len ); - swprintf( state->buf, DEFAULT_DIR_NAME L"\\%s.xwg", buf ); - XP_LOGW( "returning", state->buf ); - state->opened = XP_TRUE; - } - /* fallthrough */ - case IDOK: - /* fallthrough */ - case IDCANCEL: - EndDialog(hDlg, wid); - result = TRUE; - break; } } } @@ -359,7 +349,7 @@ ceSavedGamesDlg( CEAppGlobals* globals, const XP_UCHAR* curPath, LOG_FUNC(); XP_MEMSET( &state, 0, sizeof(state) ); /* sets cancelled */ - state.globals = globals; + state.dlgHdr.globals = globals; state.buf = buf; state.buflen = buflen; diff --git a/xwords4/wince/ceutil.c b/xwords4/wince/ceutil.c index 1f593680a..8337eb628 100755 --- a/xwords4/wince/ceutil.c +++ b/xwords4/wince/ceutil.c @@ -30,6 +30,11 @@ #define HPADDING_L 2 #define HPADDING_R 3 +static XP_Bool ceDoDlgScroll( CeDlgHdr* dlgHdr, WPARAM wParam ); +static void ceDoDlgFocusScroll( CEAppGlobals* globals, HWND hDlg, + WPARAM wParam, LPARAM lParam ); + + void ceSetDlgItemText( HWND hDlg, XP_U16 id, const XP_UCHAR* buf ) { @@ -334,11 +339,16 @@ mkFullscreenWithSoftkeys( CEAppGlobals* globals, HWND hDlg ) #define TITLE_HT 20 /* Need to get this from the OS */ void -ceDlgSetup( CEAppGlobals* globals, HWND hDlg ) +ceDlgSetup( CeDlgHdr* dlgHdr, HWND hDlg, DlgStateTask doWhat ) { - XP_ASSERT( !!globals ); RECT rect; XP_U16 vHeight; + CEAppGlobals* globals = dlgHdr->globals; + + dlgHdr->hDlg = hDlg; + + XP_ASSERT( !!globals ); + XP_ASSERT( !!hDlg ); GetClientRect( hDlg, &rect ); XP_ASSERT( rect.top == 0 ); @@ -380,8 +390,39 @@ ceDlgSetup( CEAppGlobals* globals, HWND hDlg ) (void)SetScrollInfo( hDlg, SB_VERT, &sinfo, FALSE ); } + if ( IS_SMARTPHONE(globals) && ((doWhat & DLG_STATE_TRAPBACK) != 0) ) { + trapBackspaceKey( hDlg ); + } + + dlgHdr->doWhat = doWhat; } /* ceDlgSetup */ +XP_Bool +ceDoDlgHandle( CeDlgHdr* dlgHdr, UINT message, WPARAM wParam, LPARAM lParam ) +{ + XP_Bool handled = XP_FALSE; + switch( message ) { +#ifdef _WIN32_WCE + case WM_HOTKEY: + XP_ASSERT( (dlgHdr->doWhat && DLG_STATE_TRAPBACK) != 0 ); + if ( VK_TBACK == HIWORD(lParam) ) { + SHSendBackToFocusWindow( message, wParam, lParam ); + handled = TRUE; + } + break; +#endif + case WM_VSCROLL: + handled = ceDoDlgScroll( dlgHdr, wParam ); + break; + + case WM_NEXTDLGCTL: + ceDoDlgFocusScroll( dlgHdr->globals, dlgHdr->hDlg, wParam, lParam ); + handled = TRUE; + break; + } + return handled; +} + static void setScrollPos( HWND hDlg, XP_S16 newPos ) { @@ -432,10 +473,10 @@ adjustScrollPos( HWND hDlg, XP_S16 vertChange ) LOG_RETURN_VOID(); } /* adjustScrollPos */ -XP_Bool -ceDoDlgScroll( CEAppGlobals* globals, HWND hDlg, WPARAM wParam ) +static XP_Bool +ceDoDlgScroll( CeDlgHdr* dlgHdr, WPARAM wParam ) { - XP_Bool handled = !IS_SMARTPHONE(globals); + XP_Bool handled = !IS_SMARTPHONE(dlgHdr->globals); if ( handled ) { XP_S16 vertChange = 0; @@ -457,12 +498,12 @@ ceDoDlgScroll( CEAppGlobals* globals, HWND hDlg, WPARAM wParam ) case SB_THUMBTRACK: /* still dragging; don't redraw */ case SB_THUMBPOSITION: - setScrollPos( hDlg, HIWORD(wParam) ); + setScrollPos( dlgHdr->hDlg, HIWORD(wParam) ); break; } if ( 0 != vertChange ) { - adjustScrollPos( hDlg, vertChange ); + adjustScrollPos( dlgHdr->hDlg, vertChange ); } } return handled; @@ -483,7 +524,7 @@ ceDoDlgScroll( CEAppGlobals* globals, HWND hDlg, WPARAM wParam ) indicates whether the next or previous control with the WS_TABSTOP style receives the focus. */ -void +static void ceDoDlgFocusScroll( CEAppGlobals* globals, HWND hDlg, WPARAM wParam, LPARAM lParam ) { /* Scroll the current focus owner into view. diff --git a/xwords4/wince/ceutil.h b/xwords4/wince/ceutil.h index 9081a18f0..ebbdf8629 100755 --- a/xwords4/wince/ceutil.h +++ b/xwords4/wince/ceutil.h @@ -44,15 +44,22 @@ void ceSetChecked( HWND hDlg, XP_U16 resID, XP_Bool check ); void ceCenterCtl( HWND hDlg, XP_U16 resID ); /* set vHeight to 0 to turn off scrolling */ -void ceDlgSetup( CEAppGlobals* globals, HWND hDlg ); +typedef enum { DLG_STATE_NONE = 0, DLG_STATE_TRAPBACK = 1 } DlgStateTask; +typedef struct CeDlgHdr { + CEAppGlobals* globals; + HWND hDlg; + + /* Below this line is private to ceutil.c */ + DlgStateTask doWhat; +} CeDlgHdr; +void ceDlgSetup( CeDlgHdr* dlgHdr, HWND hDlg, DlgStateTask doWhat ); +XP_Bool ceDoDlgHandle( CeDlgHdr* dlgHdr, UINT message, WPARAM wParam, LPARAM lParam); /* Are we drawing things in landscape mode? */ XP_Bool ceIsLandscape( CEAppGlobals* globals ); void ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 id ); -XP_Bool ceDoDlgScroll( CEAppGlobals* globals, HWND hDlg, WPARAM wParam ); -void ceDoDlgFocusScroll( CEAppGlobals* globals, HWND hDlg, - WPARAM wParam, LPARAM lParam ); + #ifdef _WIN32_WCE void ceSizeIfFullscreen( CEAppGlobals* globals, HWND hWnd ); void trapBackspaceKey( HWND hDlg );