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.
This commit is contained in:
ehouse 2008-10-13 01:26:20 +00:00
parent 6b6d5d79d0
commit 20bcdea816
9 changed files with 78 additions and 14 deletions

View file

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

View file

@ -21,7 +21,8 @@
#include "cemain.h"
#include "ceutil.h"
#include "debhacks.h"
#include <stdio.h> /* swprintf */
//##include <stdio.h> /* swprintf */
#include <wchar.h>
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 );

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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