Finally fix scroll-follows-focus for color edit dialog (the tallest).

Trick was to add BS_NOTIFY property to dialog controls and look for
the WM_COMMAND->BN_SETFOCUS message.
This commit is contained in:
ehouse 2008-06-07 14:40:05 +00:00
parent fa1f65283f
commit 930ed69d6b
3 changed files with 106 additions and 106 deletions

View file

@ -316,11 +316,12 @@ deleteButtonBrushes( ColorsDlgState* cState )
}
} /* deleteButtonBrushes */
static void
static XP_Bool
wrapChooseColor( ColorsDlgState* cState, XP_U16 button )
{
XP_Bool handled = XP_FALSE;
if ( button >= DLBLTR_BUTTON && button <= PLAYER4_BUTTON ) {
XP_U16 index = button-DLBLTR_BUTTON;
XP_U16 index = button - DLBLTR_BUTTON;
#ifdef MY_COLOR_SEL
XP_U16 labelID = button + CLRSEL_LABEL_OFFSET;
@ -361,7 +362,9 @@ wrapChooseColor( ColorsDlgState* cState, XP_U16 button )
cState->brushes[index] = CreateSolidBrush( ccs.rgbResult );
}
#endif
handled = XP_TRUE;
}
return handled;
} /* wrapChooseColor */
static void
@ -414,25 +417,25 @@ ColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
break;
case WM_COMMAND:
wid = LOWORD(wParam);
switch( wid ) {
if ( BN_CLICKED == HIWORD(wParam) ) {
wid = LOWORD(wParam);
switch( wid ) {
case IDOK:
state->cancelled = XP_FALSE;
/* fallthrough */
case IDOK:
state->cancelled = XP_FALSE;
/* fallthrough */
case IDCANCEL:
deleteButtonBrushes( state );
EndDialog(hDlg, wid);
result = TRUE;
break;
case IDCANCEL:
deleteButtonBrushes( state );
EndDialog(hDlg, wid);
result = TRUE;
break;
default:
/* it's one of the color buttons. Set up with the
appropriate color and launch ChooseColor */
wrapChooseColor( state, wid );
result = TRUE;
break;
default:
/* it's one of the color buttons. Set up with the
appropriate color and launch ChooseColor */
result = wrapChooseColor( state, wid );
break;
}
}
}
}

View file

@ -31,9 +31,7 @@
#define HPADDING_R 3
static XP_Bool ceDoDlgScroll( CeDlgHdr* dlgHdr, WPARAM wParam );
static void ceDoDlgFocusScroll( CEAppGlobals* globals, HWND hDlg,
WPARAM wParam, LPARAM lParam );
static void ceDoDlgFocusScroll( CeDlgHdr* dlgHdr, HWND nextCtrl );
void
ceSetDlgItemText( HWND hDlg, XP_U16 id, const XP_UCHAR* buf )
@ -262,74 +260,82 @@ ceIsFullScreen( CEAppGlobals* globals, HWND hWnd )
return screenHt == 0;
} /* ceIsFullScreen */
static void
ceSize( CEAppGlobals* globals, HWND hWnd, XP_Bool fullScreen )
{
RECT rect;
XP_U16 cbHeight = 0;
if ( !!globals->hwndCB ) {
GetWindowRect( globals->hwndCB, &rect );
cbHeight = rect.bottom - rect.top;
}
/* I'm leaving the SIP/cmdbar in place until I can figure out how to
get menu events with it hidden -- and also the UI for making sure
users don't get stuck in fullscreen mode not knowing how to reach
menus to get out. Later, add SHFS_SHOWSIPBUTTON and
SHFS_HIDESIPBUTTON to the sets shown and hidden below.*/
if ( fullScreen ) {
SHFullScreen( hWnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON );
SetRect( &rect, 0, 0, GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN) );
} else {
SHFullScreen( hWnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON );
SystemParametersInfo( SPI_GETWORKAREA, 0, &rect, FALSE );
if ( IS_SMARTPHONE(globals) ) {
cbHeight = 0;
}
}
rect.bottom -= cbHeight;
MoveWindow( hWnd, rect.left, rect.top, rect.right - rect.left,
rect.bottom - rect.top, TRUE );
} /* ceSize */
void
ceSizeIfFullscreen( CEAppGlobals* globals, HWND hWnd )
{
if ( globals->appPrefs.fullScreen != ceIsFullScreen(globals, hWnd) ) {
RECT rect;
XP_U16 cbHeight = 0;
if ( !!globals->hwndCB && hWnd == globals->hWnd ) {
GetWindowRect( globals->hwndCB, &rect );
cbHeight = rect.bottom - rect.top;
}
/* I'm leaving the SIP/cmdbar in place until I can figure out how to
get menu events with it hidden -- and also the UI for making sure
users don't get stuck in fullscreen mode not knowing how to reach
menus to get out. Later, add SHFS_SHOWSIPBUTTON and
SHFS_HIDESIPBUTTON to the sets shown and hidden below.*/
if ( globals->appPrefs.fullScreen ) {
SHFullScreen( hWnd, SHFS_HIDETASKBAR | SHFS_HIDESTARTICON );
SetRect( &rect, 0, 0, GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN) );
} else {
SHFullScreen( hWnd, SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON );
SystemParametersInfo( SPI_GETWORKAREA, 0, &rect, FALSE );
if ( IS_SMARTPHONE(globals) ) {
cbHeight = 0;
}
}
rect.bottom -= cbHeight;
MoveWindow( hWnd, rect.left, rect.top, rect.right - rect.left,
rect.bottom - rect.top, TRUE );
ceSize( globals, hWnd, globals->appPrefs.fullScreen );
}
} /* ceSizeIfFullscreen */
}
static XP_Bool
mkFullscreenWithSoftkeys( CEAppGlobals* globals, HWND hDlg )
mkFullscreenWithSoftkeys( CEAppGlobals* globals, HWND hDlg, XP_U16 curHt )
{
XP_Bool success = XP_FALSE;
XP_Bool fullScreen = XP_TRUE; /* probably want this TRUE for
small-screened smartphones only. */
if ( IS_SMARTPHONE(globals) ) {
SHINITDLGINFO info;
XP_MEMSET( &info, 0, sizeof(info) );
info.dwMask = SHIDIM_FLAGS;
info.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
info.hDlg = hDlg;
success = SHInitDialog( &info );
if ( !success ) {
XP_LOGF( "SHInitDialog failed: %ld", GetLastError() );
}
} else if ( fullScreen ) {
ceSizeIfFullscreen( globals, hDlg );
success = XP_TRUE;
}
SHMENUBARINFO mbi;
XP_MEMSET( &mbi, 0, sizeof(mbi) );
mbi.cbSize = sizeof(mbi);
mbi.hwndParent = hDlg;
mbi.nToolBarId = IDM_OKCANCEL_MENUBAR;
mbi.hInstRes = globals->hInst;
success = SHCreateMenuBar( &mbi );
if ( !success ) {
XP_LOGF( "SHCreateMenuBar failed: %ld", GetLastError() );
} else {
if ( success ) {
SHMENUBARINFO mbi;
XP_MEMSET( &mbi, 0, sizeof(mbi) );
mbi.cbSize = sizeof(mbi);
mbi.hwndParent = hDlg;
mbi.nToolBarId = IDM_OKCANCEL_MENUBAR;
mbi.hInstRes = globals->hInst;
success = SHCreateMenuBar( &mbi );
if ( !success ) {
XP_LOGF( "SHCreateMenuBar failed: %ld", GetLastError() );
if ( IS_SMARTPHONE(globals) ) {
SHINITDLGINFO info;
XP_MEMSET( &info, 0, sizeof(info) );
info.dwMask = SHIDIM_FLAGS;
info.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
info.hDlg = hDlg;
success = SHInitDialog( &info );
if ( !success ) {
XP_LOGF( "SHInitDialog failed: %ld", GetLastError() );
}
} else {
XP_U16 screenHt = GetSystemMetrics(SM_CYFULLSCREEN);
RECT rect;
GetWindowRect( mbi.hwndMB, &rect );
screenHt -= (rect.bottom - rect.top);
if ( screenHt < curHt ) {
ceSize( globals, hDlg, XP_TRUE );
}
}
}
@ -355,7 +361,7 @@ ceDlgSetup( CeDlgHdr* dlgHdr, HWND hDlg, DlgStateTask doWhat )
vHeight = rect.bottom; /* This is before we've resized it */
#ifdef _WIN32_WCE
(void)mkFullscreenWithSoftkeys( globals, hDlg );
(void)mkFullscreenWithSoftkeys( globals, hDlg, vHeight );
#elif defined DEBUG
/* Force it to be small so we can test scrolling etc. */
if ( globals->dbWidth > 0 && globals->dbHeight > 0) {
@ -389,11 +395,11 @@ 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) ) {
trapBackspaceKey( hDlg );
}
#endif
dlgHdr->doWhat = doWhat;
} /* ceDlgSetup */
@ -415,9 +421,13 @@ ceDoDlgHandle( CeDlgHdr* dlgHdr, UINT message, WPARAM wParam, LPARAM lParam )
handled = ceDoDlgScroll( dlgHdr, wParam );
break;
case WM_NEXTDLGCTL:
ceDoDlgFocusScroll( dlgHdr->globals, dlgHdr->hDlg, wParam, lParam );
handled = TRUE;
case WM_COMMAND:
if ( BN_SETFOCUS == HIWORD(wParam) ) {
ceDoDlgFocusScroll( dlgHdr, (HWND)lParam );
handled = TRUE;
} else if ( BN_KILLFOCUS == HIWORD(wParam) ) { /* dialogs shouldn't have to handle this */
handled = TRUE;
}
break;
}
return handled;
@ -429,8 +439,6 @@ setScrollPos( HWND hDlg, XP_S16 newPos )
SCROLLINFO sinfo;
XP_S16 vertChange;
XP_LOGF( "%s(%d)", __func__, newPos );
XP_MEMSET( &sinfo, 0, sizeof(sinfo) );
sinfo.cbSize = sizeof(sinfo);
sinfo.fMask = SIF_POS;
@ -453,13 +461,11 @@ setScrollPos( HWND hDlg, XP_S16 newPos )
XP_LOGF( "%s: change dropped", __func__ );
}
}
LOG_RETURN_VOID();
} /* setScrollPos */
static void
adjustScrollPos( HWND hDlg, XP_S16 vertChange )
{
XP_LOGF( "%s(%d)", __func__, vertChange );
if ( vertChange != 0 ) {
SCROLLINFO sinfo;
@ -525,7 +531,7 @@ ceDoDlgScroll( CeDlgHdr* dlgHdr, WPARAM wParam )
style receives the focus. */
static void
ceDoDlgFocusScroll( CEAppGlobals* globals, HWND hDlg, WPARAM wParam, LPARAM lParam )
ceDoDlgFocusScroll( CeDlgHdr* dlgHdr, HWND nextCtrl )
{
/* Scroll the current focus owner into view.
*
@ -543,14 +549,8 @@ ceDoDlgFocusScroll( CEAppGlobals* globals, HWND hDlg, WPARAM wParam, LPARAM lPar
* scrolling to see how to fix it.
*/
if ( !IS_SMARTPHONE(globals) ) {
HWND nextCtrl;
if ( LOWORD(lParam) ) {
nextCtrl = (HWND)wParam;
} else {
BOOL previous = wParam != 0;
nextCtrl = GetNextDlgTabItem( hDlg, GetFocus(), previous );
}
if ( !IS_SMARTPHONE(dlgHdr->globals) ) {
HWND hDlg = dlgHdr->hDlg;
if ( !!nextCtrl ) {
RECT rect;
@ -568,9 +568,6 @@ ceDoDlgFocusScroll( CEAppGlobals* globals, HWND hDlg, WPARAM wParam, LPARAM lPar
ctrlPos = rect.top - dlgTop - TITLE_HT;
ctrlHeight = rect.bottom - rect.top;
XP_LOGF( "%p: ctrlPos is %d; height is %d",
nextCtrl, ctrlPos, ctrlHeight );
if ( ctrlPos < 0 ) {
XP_LOGF( "need to scroll it DOWN into view" );
adjustScrollPos( hDlg, ctrlPos );

View file

@ -536,9 +536,9 @@ CAPTION "Preferences"
FONT 8, "System"
BEGIN
CONTROL "This game",IDC_RADIOLOCAL,"Button",
BS_AUTORADIOBUTTON | WS_GROUP,4,PR_ROW1,45,10
BS_AUTORADIOBUTTON | WS_GROUP,4,PR_ROW1,47,10
CONTROL "All games",IDC_RADIOGLOBAL,"Button",
BS_AUTORADIOBUTTON,50,PR_ROW1,53,10
BS_AUTORADIOBUTTON,52,PR_ROW1,53,10
CONTROL "Color played tiles",IDC_CHECKCOLORPLAYED,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP | WS_GROUP,8,PR_ROW2,90,PREFS_ROW_HT
CONTROL "Enable cursor",IDC_CHECKSHOWCURSOR,"Button",
@ -686,7 +686,7 @@ END
and have a separate button to trigger the edit dialog. */
#define COLOR_SAMPLE(id1,id2,xx,yy) \
PUSHBUTTON "",id2,xx,yy,CLR_BUT_WIDTH,CLR_BUT_HT,BS_OWNERDRAW \
PUSHBUTTON "Edit",id1,xx+CLR_SAMPLE_WIDTH+4,yy,20,CLR_BUT_HT
PUSHBUTTON "Edit",id1,xx+CLR_SAMPLE_WIDTH+4,yy,20,CLR_BUT_HT,BS_NOTIFY
IDD_COLORSDLG DIALOG DISCARDABLE 0, 20, CLR_WIDTH, COLORSDLG_HT
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | DS_CENTER | WS_VSCROLL
@ -720,9 +720,9 @@ BEGIN
#ifndef _WIN32_WCE
DEFPUSHBUTTON "OK",IDOK,CLR_OK_LEFT,CLR_BUTTON_ROW,
REPOS_BUTTON_WIDTH,BUTTON_HT
REPOS_BUTTON_WIDTH,BUTTON_HT,BS_NOTIFY
PUSHBUTTON "Cancel",IDCANCEL,CLR_CANCEL_LEFT,CLR_BUTTON_ROW,
REPOS_BUTTON_WIDTH,BUTTON_HT
REPOS_BUTTON_WIDTH,BUTTON_HT,BS_NOTIFY
#endif
END