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

View file

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

View file

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