From e178b7ccf53e4ad68a11e2fd8137de303e659351 Mon Sep 17 00:00:00 2001 From: ehouse Date: Sat, 10 May 2008 15:42:52 +0000 Subject: [PATCH] Use SHInitDialog on smartphone to create fullscreen dialogs. Move test for smartphone into util functions so can't forget it. This fixes scrolling on smartphone. --- xwords4/wince/ceclrsel.c | 10 +-- xwords4/wince/ceginfo.c | 9 +-- xwords4/wince/ceprefs.c | 8 +-- xwords4/wince/cestrbx.c | 4 +- xwords4/wince/cesvdgms.c | 8 +-- xwords4/wince/ceutil.c | 145 ++++++++++++++++++++++----------------- xwords4/wince/ceutil.h | 5 +- 7 files changed, 96 insertions(+), 93 deletions(-) diff --git a/xwords4/wince/ceclrsel.c b/xwords4/wince/ceclrsel.c index 8067a6af8..d43b54992 100644 --- a/xwords4/wince/ceclrsel.c +++ b/xwords4/wince/ceclrsel.c @@ -181,9 +181,7 @@ EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) switch (message) { case WM_VSCROLL: - if ( !IS_SMARTPHONE(eState->globals) ) { - ceDoDlgScroll( hDlg, wParam ); - } + ceDoDlgScroll( eState->globals, hDlg, wParam ); break; case WM_PAINT: { @@ -424,13 +422,11 @@ ColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) switch (message) { case WM_VSCROLL: - if ( !IS_SMARTPHONE(state->globals) ) { - ceDoDlgScroll( hDlg, wParam ); - } + ceDoDlgScroll( state->globals, hDlg, wParam ); break; case WM_DRAWITEM: /* passed when button has BS_OWNERDRAW style */ - ceDoDlgFocusScroll( hDlg, + ceDoDlgFocusScroll( state->globals, hDlg, /* Fake out ceDoDlgFocusScroll, passing ctrl itself */ (WPARAM)((DRAWITEMSTRUCT*)lParam)->hwndItem, (LPARAM)TRUE ); diff --git a/xwords4/wince/ceginfo.c b/xwords4/wince/ceginfo.c index 3a2458a53..1f8d94c66 100755 --- a/xwords4/wince/ceginfo.c +++ b/xwords4/wince/ceginfo.c @@ -523,17 +523,12 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) switch (message) { case WM_VSCROLL: - if ( !IS_SMARTPHONE(globals) ) { - ceDoDlgScroll( hDlg, wParam ); - result = TRUE; - } + result = ceDoDlgScroll( globals, hDlg, wParam ); break; /* WM_NEXTDLGCTL is worthless; prev obj still has focus */ case WM_NEXTDLGCTL: - if ( !IS_SMARTPHONE(globals) ) { - ceDoDlgFocusScroll( hDlg, wParam, lParam ); - } + ceDoDlgFocusScroll( globals, hDlg, wParam, lParam ); break; #ifdef OWNERDRAW_JUGGLE diff --git a/xwords4/wince/ceprefs.c b/xwords4/wince/ceprefs.c index f9314c284..e3247c693 100755 --- a/xwords4/wince/ceprefs.c +++ b/xwords4/wince/ceprefs.c @@ -272,15 +272,11 @@ PrefsDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) switch (message) { case WM_VSCROLL: - if ( !IS_SMARTPHONE(globals) ) { - ceDoDlgScroll( hDlg, wParam ); - } + ceDoDlgScroll( globals, hDlg, wParam ); break; case WM_NEXTDLGCTL: - if ( !IS_SMARTPHONE(globals) ) { - ceDoDlgFocusScroll( hDlg, wParam, lParam ); - } + ceDoDlgFocusScroll( globals, hDlg, wParam, lParam ); break; case WM_COMMAND: diff --git a/xwords4/wince/cestrbx.c b/xwords4/wince/cestrbx.c index a9b136ba3..0f9de0bb8 100755 --- a/xwords4/wince/cestrbx.c +++ b/xwords4/wince/cestrbx.c @@ -90,9 +90,7 @@ StrBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) switch (message) { case WM_VSCROLL: - if ( !IS_SMARTPHONE(globals) ) { - ceDoDlgScroll( hDlg, wParam ); - } + ceDoDlgScroll( globals, hDlg, wParam ); break; case WM_COMMAND: diff --git a/xwords4/wince/cesvdgms.c b/xwords4/wince/cesvdgms.c index 76adea387..740fc71d6 100644 --- a/xwords4/wince/cesvdgms.c +++ b/xwords4/wince/cesvdgms.c @@ -284,15 +284,11 @@ SavedGamesDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) switch (message) { case WM_VSCROLL: - if ( !IS_SMARTPHONE(state->globals) ) { - ceDoDlgScroll( hDlg, wParam ); - } + ceDoDlgScroll( state->globals, hDlg, wParam ); break; case WM_NEXTDLGCTL: - if ( !IS_SMARTPHONE(state->globals) ) { - ceDoDlgFocusScroll( hDlg, wParam, lParam ); - } + ceDoDlgFocusScroll( state->globals, hDlg, wParam, lParam ); break; case WM_COMMAND: diff --git a/xwords4/wince/ceutil.c b/xwords4/wince/ceutil.c index 5ebff415a..ac7dbf25a 100755 --- a/xwords4/wince/ceutil.c +++ b/xwords4/wince/ceutil.c @@ -294,22 +294,37 @@ static XP_Bool mkFullscreenWithSoftkeys( CEAppGlobals* globals, HWND hDlg ) { XP_Bool success = XP_FALSE; - SHMENUBARINFO mbi; XP_Bool fullScreen = XP_TRUE; /* probably want this TRUE for small-screened smartphones only. */ - if ( fullScreen ) { + + 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; } - 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 ( 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() ); + } } + return success; } /* mkFullscreenWithSoftkeys */ #endif @@ -414,36 +429,40 @@ adjustScrollPos( HWND hDlg, XP_S16 vertChange ) LOG_RETURN_VOID(); } /* adjustScrollPos */ -void -ceDoDlgScroll( HWND hDlg, WPARAM wParam ) +XP_Bool +ceDoDlgScroll( CEAppGlobals* globals, HWND hDlg, WPARAM wParam ) { - XP_S16 vertChange = 0; + XP_Bool handled = !IS_SMARTPHONE(globals); + if ( handled ) { + XP_S16 vertChange = 0; - switch ( LOWORD(wParam) ) { + switch ( LOWORD(wParam) ) { - case SB_LINEUP: // Scrolls one line up - vertChange = -1; - break; - case SB_PAGEUP: // - vertChange = -10; - break; + case SB_LINEUP: // Scrolls one line up + vertChange = -1; + break; + case SB_PAGEUP: // + vertChange = -10; + break; - case SB_LINEDOWN: // Scrolls one line down - vertChange = 1; - break; - case SB_PAGEDOWN: // Scrolls one page down - vertChange = 10; - break; + case SB_LINEDOWN: // Scrolls one line down + vertChange = 1; + break; + case SB_PAGEDOWN: // Scrolls one page down + vertChange = 10; + break; - case SB_THUMBTRACK: /* still dragging; don't redraw */ - case SB_THUMBPOSITION: - setScrollPos( hDlg, HIWORD(wParam) ); - break; - } - - if ( 0 != vertChange ) { - adjustScrollPos( hDlg, vertChange ); + case SB_THUMBTRACK: /* still dragging; don't redraw */ + case SB_THUMBPOSITION: + setScrollPos( hDlg, HIWORD(wParam) ); + break; + } + + if ( 0 != vertChange ) { + adjustScrollPos( hDlg, vertChange ); + } } + return handled; } /* ceDoDlgScroll */ @@ -462,7 +481,7 @@ ceDoDlgScroll( HWND hDlg, WPARAM wParam ) style receives the focus. */ void -ceDoDlgFocusScroll( HWND hDlg, WPARAM wParam, LPARAM lParam ) +ceDoDlgFocusScroll( CEAppGlobals* globals, HWND hDlg, WPARAM wParam, LPARAM lParam ) { /* Scroll the current focus owner into view. * @@ -480,39 +499,41 @@ ceDoDlgFocusScroll( HWND hDlg, WPARAM wParam, LPARAM lParam ) * scrolling to see how to fix it. */ - HWND nextCtrl; - if ( LOWORD(lParam) ) { - nextCtrl = (HWND)wParam; - } else { - BOOL previous = wParam != 0; - nextCtrl = GetNextDlgTabItem( hDlg, GetFocus(), previous ); - } + if ( !IS_SMARTPHONE(globals) ) { + HWND nextCtrl; + if ( LOWORD(lParam) ) { + nextCtrl = (HWND)wParam; + } else { + BOOL previous = wParam != 0; + nextCtrl = GetNextDlgTabItem( hDlg, GetFocus(), previous ); + } - if ( !!nextCtrl ) { - RECT rect; - XP_U16 dlgHeight, ctrlHeight, dlgTop; - XP_S16 ctrlPos; + if ( !!nextCtrl ) { + RECT rect; + XP_U16 dlgHeight, ctrlHeight, dlgTop; + XP_S16 ctrlPos; - GetClientRect( hDlg, &rect ); - dlgHeight = rect.bottom - rect.top; - XP_LOGF( "dlgHeight: %d", dlgHeight ); + GetClientRect( hDlg, &rect ); + dlgHeight = rect.bottom - rect.top; + XP_LOGF( "dlgHeight: %d", dlgHeight ); - GetWindowRect( hDlg, &rect ); - dlgTop = rect.top; + GetWindowRect( hDlg, &rect ); + dlgTop = rect.top; - GetWindowRect( nextCtrl, &rect ); - ctrlPos = rect.top - dlgTop - TITLE_HT; - ctrlHeight = rect.bottom - rect.top; + GetWindowRect( nextCtrl, &rect ); + ctrlPos = rect.top - dlgTop - TITLE_HT; + ctrlHeight = rect.bottom - rect.top; - XP_LOGF( "%p: ctrlPos is %d; height is %d", - nextCtrl, ctrlPos, ctrlHeight ); + 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 ); - } else if ( (ctrlPos + ctrlHeight) > dlgHeight ) { - XP_LOGF( "need to scroll it UP into view" ); - setScrollPos( hDlg, ctrlPos - ctrlHeight ); + if ( ctrlPos < 0 ) { + XP_LOGF( "need to scroll it DOWN into view" ); + adjustScrollPos( hDlg, ctrlPos ); + } else if ( (ctrlPos + ctrlHeight) > dlgHeight ) { + XP_LOGF( "need to scroll it UP into view" ); + setScrollPos( hDlg, ctrlPos - ctrlHeight ); + } } } } /* ceDoDlgFocusScroll */ diff --git a/xwords4/wince/ceutil.h b/xwords4/wince/ceutil.h index 0d06a8b3c..8cbb8af6f 100755 --- a/xwords4/wince/ceutil.h +++ b/xwords4/wince/ceutil.h @@ -50,8 +50,9 @@ void ceDlgSetup( CEAppGlobals* globals, HWND hDlg ); XP_Bool ceIsLandscape( CEAppGlobals* globals ); void ceSetLeftSoftkey( CEAppGlobals* globals, XP_U16 id ); -void ceDoDlgScroll( HWND hDlg, WPARAM wParam ); -void ceDoDlgFocusScroll( HWND hDlg, WPARAM wParam, LPARAM lParam ); +XP_Bool ceDoDlgScroll( CEAppGlobals* globals, HWND hDlg, WPARAM wParam ); +void ceDoDlgFocusScroll( CEAppGlobals* globals, HWND hDlg, + WPARAM wParam, LPARAM lParam ); #ifdef _WIN32_WCE void ceSizeIfFullscreen( CEAppGlobals* globals, HWND hWnd ); #else