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.
This commit is contained in:
ehouse 2008-10-13 05:46:45 +00:00
parent 20bcdea816
commit be93f274ee
8 changed files with 28 additions and 30 deletions

View file

@ -51,7 +51,6 @@ PasswdDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
pState = (PasswdDialogState*)lParam; pState = (PasswdDialogState*)lParam;
ceDlgSetup( &pState->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); ceDlgSetup( &pState->dlgHdr, hDlg, DLG_STATE_TRAPBACK );
ceDlgSetEdits( &pState->dlgHdr, PASS_EDIT, 0 );
nameToLabel( hDlg, pState->name, IDC_PWDLABEL ); nameToLabel( hDlg, pState->name, IDC_PWDLABEL );

View file

@ -111,7 +111,6 @@ BlankDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
#endif #endif
ceDlgSetup( &bState->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); ceDlgSetup( &bState->dlgHdr, hDlg, DLG_STATE_TRAPBACK );
ceDlgSetEdits( &bState->dlgHdr, IDC_PICKMSG, 0 );
ceDlgComboShowHide( &bState->dlgHdr, BLANKFACE_LIST ); ceDlgComboShowHide( &bState->dlgHdr, BLANKFACE_LIST );
loadLettersList( bState ); loadLettersList( bState );

View file

@ -145,7 +145,6 @@ EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
eState->inited = XP_FALSE; eState->inited = XP_FALSE;
ceDlgSetup( &eState->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); ceDlgSetup( &eState->dlgHdr, hDlg, DLG_STATE_TRAPBACK );
ceDlgSetEdits( &eState->dlgHdr, RED_EDIT, GREEN_EDIT, BLUE_EDIT, 0 );
wchar_t label[32]; wchar_t label[32];
XP_U16 len = SendDlgItemMessage( eState->parent, eState->labelID, XP_U16 len = SendDlgItemMessage( eState->parent, eState->labelID,

View file

@ -520,9 +520,6 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
giState->dictListId = LB_IF_PPC(globals,IDC_DICTLIST); giState->dictListId = LB_IF_PPC(globals,IDC_DICTLIST);
ceDlgSetup( &giState->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); 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_NPLAYERSCOMBO );
ceDlgComboShowHide( &giState->dlgHdr, IDC_DICTLIST ); ceDlgComboShowHide( &giState->dlgHdr, IDC_DICTLIST );

View file

@ -275,7 +275,6 @@ PrefsDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
pState->phonComboId = LB_IF_PPC(pState->dlgHdr.globals,PHONIES_COMBO); pState->phonComboId = LB_IF_PPC(pState->dlgHdr.globals,PHONIES_COMBO);
ceDlgSetup( &pState->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); ceDlgSetup( &pState->dlgHdr, hDlg, DLG_STATE_TRAPBACK );
ceDlgSetEdits( &pState->dlgHdr, TIMER_EDIT, 0 );
ceDlgComboShowHide( &pState->dlgHdr, PHONIES_COMBO ); ceDlgComboShowHide( &pState->dlgHdr, PHONIES_COMBO );
stuffPhoniesList( pState ); stuffPhoniesList( pState );

View file

@ -89,7 +89,6 @@ SaveNameDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
(void)SetDlgItemText( hDlg, IDC_SVGN_SELLAB, buf ); (void)SetDlgItemText( hDlg, IDC_SVGN_SELLAB, buf );
ceDlgSetup( &state->dlgHdr, hDlg, DLG_STATE_TRAPBACK ); ceDlgSetup( &state->dlgHdr, hDlg, DLG_STATE_TRAPBACK );
ceDlgSetEdits( &state->dlgHdr, IDC_SVGN_EDIT, 0 );
result = TRUE; result = TRUE;
} else { } else {

View file

@ -333,6 +333,26 @@ mkFullscreenWithSoftkeys( CEAppGlobals* globals, HWND hDlg, XP_U16 curHt,
return success; return success;
} /* mkFullscreenWithSoftkeys */ } /* 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 #endif
#define TITLE_HT 20 /* Need to get this from the OS */ #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 ); (void)SetScrollInfo( hDlg, SB_VERT, &sinfo, FALSE );
} }
dlgHdr->doWhat = doWhat;
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
/* Need to trap this for all dialogs, even if they don't have edit /* 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, controls. The need goes away if the main window stops trapping it,
but I don't understand why: trapping here is still required. */ but I don't understand why: trapping here is still required. */
if ( IS_SMARTPHONE(globals) ) { if ( IS_SMARTPHONE(globals) ) {
trapBackspaceKey( hDlg ); trapBackspaceKey( hDlg );
findEditCtrls( dlgHdr );
} }
#endif #endif
dlgHdr->doWhat = doWhat;
} /* ceDlgSetup */ } /* 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 void
ceDlgComboShowHide( CeDlgHdr* dlgHdr, XP_U16 baseId ) ceDlgComboShowHide( CeDlgHdr* dlgHdr, XP_U16 baseId )
{ {
@ -424,13 +431,13 @@ static XP_Bool
editHasFocus( const CeDlgHdr* dlgHdr ) editHasFocus( const CeDlgHdr* dlgHdr )
{ {
XP_Bool found = XP_FALSE; XP_Bool found = XP_FALSE;
XP_U16 focusId = GetDlgCtrlID( GetFocus() ); HWND focus = GetFocus();
XP_U16 ii; XP_U16 ii;
for ( ii = 0; ii < MAX_EDITS && !found; ++ii ) { for ( ii = 0; ii < MAX_EDITS && !found; ++ii ) {
XP_U16 id = dlgHdr->edits[ii]; HWND ctrl = dlgHdr->edits[ii];
if ( 0 == id ) { if ( NULL == ctrl ) {
break; break;
} else if ( id == focusId ) { } else if ( ctrl == focus ) {
found = XP_TRUE; found = XP_TRUE;
} }
} }

View file

@ -56,10 +56,9 @@ typedef struct CeDlgHdr {
/* Below this line is private to ceutil.c */ /* Below this line is private to ceutil.c */
DlgStateTask doWhat; DlgStateTask doWhat;
XP_U16 nPage; XP_U16 nPage;
XP_U16 edits[MAX_EDITS]; HWND edits[MAX_EDITS];
} CeDlgHdr; } CeDlgHdr;
void ceDlgSetup( CeDlgHdr* dlgHdr, HWND hDlg, DlgStateTask doWhat ); void ceDlgSetup( CeDlgHdr* dlgHdr, HWND hDlg, DlgStateTask doWhat );
void ceDlgSetEdits( CeDlgHdr* dlgHdr, XP_U16 firstEdit, ... );
void ceDlgComboShowHide( CeDlgHdr* dlgHdr, XP_U16 baseId ); void ceDlgComboShowHide( CeDlgHdr* dlgHdr, XP_U16 baseId );
XP_Bool ceDoDlgHandle( CeDlgHdr* dlgHdr, UINT message, WPARAM wParam, LPARAM lParam); XP_Bool ceDoDlgHandle( CeDlgHdr* dlgHdr, UINT message, WPARAM wParam, LPARAM lParam);