From 20bcdea8165ea2010bb0e88baf6f0309d69e5ac7 Mon Sep 17 00:00:00 2001 From: ehouse Date: Mon, 13 Oct 2008 01:26:20 +0000 Subject: [PATCH] Trapped back key should exit dialog even if it has an edit control if that control does not have focus. Do that. And since I can't figure out how to use APIs available in CE to find edit controls dynamically each dialog proc has to pass its IDs in. May fix that later, in which case ceDlgSetEdits() should be removed. --- wince/Makefile | 2 ++ wince/ceaskpwd.c | 4 ++- wince/ceblank.c | 1 + wince/ceclrsel.c | 1 + wince/ceginfo.c | 3 +++ wince/ceprefs.c | 1 + wince/cesvdgms.c | 3 ++- wince/ceutil.c | 66 ++++++++++++++++++++++++++++++++++++++++-------- wince/ceutil.h | 11 ++++++-- 9 files changed, 78 insertions(+), 14 deletions(-) diff --git a/wince/Makefile b/wince/Makefile index 569ddbc68..55ab41869 100644 --- a/wince/Makefile +++ b/wince/Makefile @@ -64,6 +64,8 @@ CFLAGS += -D_WIN32_WCE=0x0400 -D_WIN32_IE=0x0400 -DUNDER_CE \ $(STANDALONE) $(USE_RAW_MINGW) -DDRAW_LINK_DIRECT \ -DXWFEATURE_TURNCHANGENOTIFY \ -fdollars-in-identifiers -D__W32API_USE_DLLIMPORT__ +# back key should raise focus on main board and backspace in edit controls +CFLAGS += -DOVERRIDE_BACKKEY RESFLAGS += -D_WIN32_WCE=400 LFLAGS += -Wl,--major-subsystem-version,4,--minor-subsystem-version,20 ifdef HAVE_COMMCTRL diff --git a/wince/ceaskpwd.c b/wince/ceaskpwd.c index abebffa2d..cd85d9391 100755 --- a/wince/ceaskpwd.c +++ b/wince/ceaskpwd.c @@ -21,7 +21,8 @@ #include "cemain.h" #include "ceutil.h" #include "debhacks.h" -#include /* swprintf */ +//##include /* swprintf */ +#include static void nameToLabel( HWND hDlg, const XP_UCHAR* name, XP_U16 labelID ) @@ -50,6 +51,7 @@ 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/wince/ceblank.c b/wince/ceblank.c index 658e49b6b..540368f8f 100755 --- a/wince/ceblank.c +++ b/wince/ceblank.c @@ -111,6 +111,7 @@ 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/wince/ceclrsel.c b/wince/ceclrsel.c index 692fbd122..706f7b8f1 100644 --- a/wince/ceclrsel.c +++ b/wince/ceclrsel.c @@ -145,6 +145,7 @@ 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/wince/ceginfo.c b/wince/ceginfo.c index e2a500ebe..2597d0227 100755 --- a/wince/ceginfo.c +++ b/wince/ceginfo.c @@ -520,6 +520,9 @@ 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/wince/ceprefs.c b/wince/ceprefs.c index 30aeba64e..14a97911c 100755 --- a/wince/ceprefs.c +++ b/wince/ceprefs.c @@ -275,6 +275,7 @@ 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/wince/cesvdgms.c b/wince/cesvdgms.c index 012ffe4a8..65acd7bfb 100644 --- a/wince/cesvdgms.c +++ b/wince/cesvdgms.c @@ -89,6 +89,7 @@ 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 { @@ -366,7 +367,7 @@ SavedGamesDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) state->inited = XP_FALSE; state->gameListId = LB_IF_PPC(state->dlgHdr.globals,IDC_SVGM_GAMELIST); - ceDlgSetup( &state->dlgHdr, hDlg, DLG_STATE_NONE|DLG_STATE_DONEONLY ); + ceDlgSetup( &state->dlgHdr, hDlg, DLG_STATE_DONEONLY ); ceDlgComboShowHide( &state->dlgHdr, IDC_SVGM_GAMELIST ); result = TRUE; diff --git a/wince/ceutil.c b/wince/ceutil.c index 7dbc89263..36f15bb2f 100755 --- a/wince/ceutil.c +++ b/wince/ceutil.c @@ -382,13 +382,31 @@ ceDlgSetup( CeDlgHdr* dlgHdr, HWND hDlg, DlgStateTask doWhat ) (void)SetScrollInfo( hDlg, SB_VERT, &sinfo, FALSE ); } #ifdef _WIN32_WCE - if ( IS_SMARTPHONE(globals) && ((doWhat & DLG_STATE_TRAPBACK) != 0) ) { + /* 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 ); } #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 ) { @@ -402,17 +420,40 @@ ceDlgComboShowHide( CeDlgHdr* dlgHdr, XP_U16 baseId ) } } +static XP_Bool +editHasFocus( const CeDlgHdr* dlgHdr ) +{ + XP_Bool found = XP_FALSE; + XP_U16 focusId = GetDlgCtrlID( GetFocus() ); + XP_U16 ii; + for ( ii = 0; ii < MAX_EDITS && !found; ++ii ) { + XP_U16 id = dlgHdr->edits[ii]; + if ( 0 == id ) { + break; + } else if ( id == focusId ) { + found = XP_TRUE; + } + } + return found; +} /* editHasFocus */ + XP_Bool ceDoDlgHandle( CeDlgHdr* dlgHdr, UINT message, WPARAM wParam, LPARAM lParam ) { XP_Bool handled = XP_FALSE; + switch( message ) { -#ifdef _WIN32_WCE +#ifdef OVERRIDE_BACKKEY case WM_HOTKEY: - XP_ASSERT( (dlgHdr->doWhat && DLG_STATE_TRAPBACK) != 0 ); if ( VK_TBACK == HIWORD(lParam) ) { - SHSendBackToFocusWindow( message, wParam, lParam ); - handled = TRUE; + if ( editHasFocus( dlgHdr ) ) { + SHSendBackToFocusWindow( message, wParam, lParam ); + handled = TRUE; + } else { + WPARAM cmd = (0 != (dlgHdr->doWhat & DLG_STATE_DONEONLY)) ? + IDOK : IDCANCEL; + SendMessage( dlgHdr->hDlg, WM_COMMAND, cmd, 0L ); + } } break; #endif @@ -709,13 +750,18 @@ ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 newId ) } } /* ceSetLeftSoftkey */ -#ifdef _WIN32_WCE +#ifdef OVERRIDE_BACKKEY void trapBackspaceKey( HWND hDlg ) { - /* Override back key so we can pass it to edit controls */ - SendMessage( SHFindMenuBar(hDlg), SHCMBM_OVERRIDEKEY, VK_TBACK, - MAKELPARAM (SHMBOF_NODEFAULT | SHMBOF_NOTIFY, - SHMBOF_NODEFAULT | SHMBOF_NOTIFY)); + /* Override back key so we can pass it to edit controls */ + SendMessage( SHFindMenuBar(hDlg), SHCMBM_OVERRIDEKEY, VK_TBACK, + MAKELPARAM (SHMBOF_NODEFAULT | SHMBOF_NOTIFY, + SHMBOF_NODEFAULT | SHMBOF_NOTIFY)); + /* To undo the above + SendMessage( SHFindMenuBar(hDlg), SHCMBM_OVERRIDEKEY, VK_TBACK, + MAKELPARAM( SHMBOF_NODEFAULT | SHMBOF_NOTIFY, + 0 ) ); + */ } #endif diff --git a/wince/ceutil.h b/wince/ceutil.h index 6cb00f593..411a6aae6 100755 --- a/wince/ceutil.h +++ b/wince/ceutil.h @@ -48,6 +48,7 @@ typedef enum { DLG_STATE_NONE = 0 , DLG_STATE_TRAPBACK = 1 , DLG_STATE_DONEONLY = 2 } DlgStateTask; +#define MAX_EDITS 8 /* the most any control has */ typedef struct CeDlgHdr { CEAppGlobals* globals; HWND hDlg; @@ -55,8 +56,10 @@ typedef struct CeDlgHdr { /* Below this line is private to ceutil.c */ DlgStateTask doWhat; XP_U16 nPage; + XP_U16 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); @@ -65,11 +68,15 @@ XP_Bool ceIsLandscape( CEAppGlobals* globals ); void ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 id ); -#ifdef _WIN32_WCE +#if defined _WIN32_WCE void ceSizeIfFullscreen( CEAppGlobals* globals, HWND hWnd ); -void trapBackspaceKey( HWND hDlg ); #else # define ceSizeIfFullscreen( globals, hWnd ) +#endif + +#ifdef OVERRIDE_BACKKEY +void trapBackspaceKey( HWND hDlg ); +#else # define trapBackspaceKey( hDlg ) #endif