From 4dde28bc28dee6a66e32aafacd798f0e74c3dc20 Mon Sep 17 00:00:00 2001 From: ehouse Date: Mon, 13 Oct 2008 05:46:45 +0000 Subject: [PATCH] Walk dialog's controls and make a list of Edit controls so that dialog procs don't have to pass them in. Compare handles rather than IDs. --- xwords4/wince/ceaskpwd.c | 1 - xwords4/wince/ceblank.c | 1 - xwords4/wince/ceclrsel.c | 1 - xwords4/wince/ceginfo.c | 3 --- xwords4/wince/ceprefs.c | 1 - xwords4/wince/cesvdgms.c | 1 - xwords4/wince/ceutil.c | 47 +++++++++++++++++++++++----------------- xwords4/wince/ceutil.h | 3 +-- 8 files changed, 28 insertions(+), 30 deletions(-) diff --git a/xwords4/wince/ceaskpwd.c b/xwords4/wince/ceaskpwd.c index cd85d9391..7a209a513 100755 --- a/xwords4/wince/ceaskpwd.c +++ b/xwords4/wince/ceaskpwd.c @@ -51,7 +51,6 @@ PasswdDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) pState = (PasswdDialogState*)lParam; ceDlgSetup( &pState->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); - ceDlgSetEdits( &pState->dlgHdr, PASS_EDIT, 0 ); nameToLabel( hDlg, pState->name, IDC_PWDLABEL ); diff --git a/xwords4/wince/ceblank.c b/xwords4/wince/ceblank.c index 540368f8f..658e49b6b 100755 --- a/xwords4/wince/ceblank.c +++ b/xwords4/wince/ceblank.c @@ -111,7 +111,6 @@ BlankDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) #endif ceDlgSetup( &bState->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); - ceDlgSetEdits( &bState->dlgHdr, IDC_PICKMSG, 0 ); ceDlgComboShowHide( &bState->dlgHdr, BLANKFACE_LIST ); loadLettersList( bState ); diff --git a/xwords4/wince/ceclrsel.c b/xwords4/wince/ceclrsel.c index 706f7b8f1..692fbd122 100644 --- a/xwords4/wince/ceclrsel.c +++ b/xwords4/wince/ceclrsel.c @@ -145,7 +145,6 @@ EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) eState->inited = XP_FALSE; ceDlgSetup( &eState->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); - ceDlgSetEdits( &eState->dlgHdr, RED_EDIT, GREEN_EDIT, BLUE_EDIT, 0 ); wchar_t label[32]; XP_U16 len = SendDlgItemMessage( eState->parent, eState->labelID, diff --git a/xwords4/wince/ceginfo.c b/xwords4/wince/ceginfo.c index 2597d0227..e2a500ebe 100755 --- a/xwords4/wince/ceginfo.c +++ b/xwords4/wince/ceginfo.c @@ -520,9 +520,6 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) giState->dictListId = LB_IF_PPC(globals,IDC_DICTLIST); ceDlgSetup( &giState->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); - ceDlgSetEdits( &giState->dlgHdr, NAME_EDIT1, PASS_EDIT1, NAME_EDIT2, - PASS_EDIT2, NAME_EDIT3, PASS_EDIT3, NAME_EDIT4, - PASS_EDIT4, 0 ); ceDlgComboShowHide( &giState->dlgHdr, IDC_NPLAYERSCOMBO ); ceDlgComboShowHide( &giState->dlgHdr, IDC_DICTLIST ); diff --git a/xwords4/wince/ceprefs.c b/xwords4/wince/ceprefs.c index 14a97911c..30aeba64e 100755 --- a/xwords4/wince/ceprefs.c +++ b/xwords4/wince/ceprefs.c @@ -275,7 +275,6 @@ PrefsDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) pState->phonComboId = LB_IF_PPC(pState->dlgHdr.globals,PHONIES_COMBO); ceDlgSetup( &pState->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); - ceDlgSetEdits( &pState->dlgHdr, TIMER_EDIT, 0 ); ceDlgComboShowHide( &pState->dlgHdr, PHONIES_COMBO ); stuffPhoniesList( pState ); diff --git a/xwords4/wince/cesvdgms.c b/xwords4/wince/cesvdgms.c index 65acd7bfb..0e73a929a 100644 --- a/xwords4/wince/cesvdgms.c +++ b/xwords4/wince/cesvdgms.c @@ -89,7 +89,6 @@ SaveNameDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) (void)SetDlgItemText( hDlg, IDC_SVGN_SELLAB, buf ); ceDlgSetup( &state->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); - ceDlgSetEdits( &state->dlgHdr, IDC_SVGN_EDIT, 0 ); result = TRUE; } else { diff --git a/xwords4/wince/ceutil.c b/xwords4/wince/ceutil.c index 36f15bb2f..df9a336eb 100755 --- a/xwords4/wince/ceutil.c +++ b/xwords4/wince/ceutil.c @@ -333,6 +333,26 @@ mkFullscreenWithSoftkeys( CEAppGlobals* globals, HWND hDlg, XP_U16 curHt, return success; } /* mkFullscreenWithSoftkeys */ + +static void +findEditCtrls( CeDlgHdr* dlgHdr ) +{ + HWND ctrl; + XP_U16 nEdits = 0; + + for ( ctrl = GetWindow( dlgHdr->hDlg, GW_CHILD ); + !!ctrl && nEdits < MAX_EDITS; + ctrl = GetWindow( ctrl, GW_HWNDNEXT ) ) { + wchar_t buf[32]; + if ( 0 != GetClassName( ctrl, buf, VSIZE(buf) ) + && !wcscmp( L"Edit", buf ) ) { + XP_ASSERT( nEdits < MAX_EDITS ); + dlgHdr->edits[nEdits++] = ctrl; + } + } + /* Sanity check: there are no Edits OR we're trapping them */ + XP_ASSERT( (nEdits == 0) || ((dlgHdr->doWhat & DLG_STATE_TRAPBACK) != 0) ); +} /* findEditCtrls */ #endif #define TITLE_HT 20 /* Need to get this from the OS */ @@ -381,32 +401,19 @@ ceDlgSetup( CeDlgHdr* dlgHdr, HWND hDlg, DlgStateTask doWhat ) (void)SetScrollInfo( hDlg, SB_VERT, &sinfo, FALSE ); } + dlgHdr->doWhat = doWhat; + #ifdef _WIN32_WCE /* Need to trap this for all dialogs, even if they don't have edit controls. The need goes away if the main window stops trapping it, but I don't understand why: trapping here is still required. */ if ( IS_SMARTPHONE(globals) ) { trapBackspaceKey( hDlg ); + findEditCtrls( dlgHdr ); } #endif - dlgHdr->doWhat = doWhat; } /* ceDlgSetup */ -void -ceDlgSetEdits( CeDlgHdr* dlgHdr, XP_U16 firstEdit, ... ) -{ - XP_U16 ii; - va_list ap; - va_start( ap, firstEdit ); - XP_ASSERT( (dlgHdr->doWhat & DLG_STATE_TRAPBACK) != 0 ); - - for ( ii = 0; firstEdit != 0 && ii < MAX_EDITS; ++ii ) { - dlgHdr->edits[ii] = firstEdit; - firstEdit = va_arg( ap, int ); - } - va_end(ap); -} - void ceDlgComboShowHide( CeDlgHdr* dlgHdr, XP_U16 baseId ) { @@ -424,13 +431,13 @@ static XP_Bool editHasFocus( const CeDlgHdr* dlgHdr ) { XP_Bool found = XP_FALSE; - XP_U16 focusId = GetDlgCtrlID( GetFocus() ); + HWND focus = GetFocus(); XP_U16 ii; for ( ii = 0; ii < MAX_EDITS && !found; ++ii ) { - XP_U16 id = dlgHdr->edits[ii]; - if ( 0 == id ) { + HWND ctrl = dlgHdr->edits[ii]; + if ( NULL == ctrl ) { break; - } else if ( id == focusId ) { + } else if ( ctrl == focus ) { found = XP_TRUE; } } diff --git a/xwords4/wince/ceutil.h b/xwords4/wince/ceutil.h index 411a6aae6..da01e8204 100755 --- a/xwords4/wince/ceutil.h +++ b/xwords4/wince/ceutil.h @@ -56,10 +56,9 @@ typedef struct CeDlgHdr { /* Below this line is private to ceutil.c */ DlgStateTask doWhat; XP_U16 nPage; - XP_U16 edits[MAX_EDITS]; + HWND edits[MAX_EDITS]; } CeDlgHdr; void ceDlgSetup( CeDlgHdr* dlgHdr, HWND hDlg, DlgStateTask doWhat ); -void ceDlgSetEdits( CeDlgHdr* dlgHdr, XP_U16 firstEdit, ... ); void ceDlgComboShowHide( CeDlgHdr* dlgHdr, XP_U16 baseId ); XP_Bool ceDoDlgHandle( CeDlgHdr* dlgHdr, UINT message, WPARAM wParam, LPARAM lParam);