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;
ceDlgSetup( &pState->dlgHdr, hDlg, DLG_STATE_TRAPBACK );
ceDlgSetEdits( &pState->dlgHdr, PASS_EDIT, 0 );
nameToLabel( hDlg, pState->name, IDC_PWDLABEL );

View file

@ -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 );

View file

@ -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,

View file

@ -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 );

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);
ceDlgSetup( &pState->dlgHdr, hDlg, DLG_STATE_TRAPBACK );
ceDlgSetEdits( &pState->dlgHdr, TIMER_EDIT, 0 );
ceDlgComboShowHide( &pState->dlgHdr, PHONIES_COMBO );
stuffPhoniesList( pState );

View file

@ -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 {

View file

@ -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;
}
}

View file

@ -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);