When fewer than 4 players shown in game info dialog, move controls

higher that are below player rows. On some screen sizes this prevents
those items from being off-screen. Note that this requires use of
DM_RESETSCROLL message to get Smartphone to recalc scroll info and
that DM_RESETSCROLL is not yet defined in cegcc.
This commit is contained in:
ehouse 2008-11-18 12:36:27 +00:00
parent 2a517c3d32
commit 0652a85acd
7 changed files with 126 additions and 57 deletions

View file

@ -152,6 +152,11 @@ cleanupGameInfoState( GameInfoState* giState )
XP_FREE( giState->dlgHdr.globals->mpool, giState->menuDicts );
giState->menuDicts = NULL;
}
if ( !!giState->moveIds ) {
XP_FREE( giState->dlgHdr.globals->mpool, giState->moveIds );
giState->moveIds = NULL;
}
} /* cleanupGameInfoState */
static void
@ -249,6 +254,64 @@ stateToGameInfo( GameInfoState* giState )
return success;
} /* stateToGameInfo */
#ifndef DM_RESETSCROLL
//http://www.nah6.com/~itsme/cvs-xdadevtools/itsutils/src/its_windows_message_list.txt
# define DM_RESETSCROLL 0x0402
#endif
static void
raiseForHiddenPlayers( GameInfoState* giState, XP_U16 nPlayers )
{
HWND hDlg = giState->dlgHdr.hDlg;
XP_U16 ii;
XP_S16 moveY;
if ( nPlayers != giState->prevNPlayers ) {
if ( !giState->moveIds ) {
XP_S16 ids[32];
HWND child;
RECT rect;
XP_U16 playersBottom;
ceGetItemRect( hDlg, NAME_EDIT4, &rect );
playersBottom = rect.bottom;
ceGetItemRect( hDlg, NAME_EDIT3, &rect );
giState->playersSpacing = playersBottom - rect.bottom;
for ( child = GetWindow( hDlg, GW_CHILD ), ii = 0;
!!child;
child = GetWindow( child, GW_HWNDNEXT ) ) {
XP_S16 resID = GetDlgCtrlID( child );
if ( resID > 0 ) {
ceGetItemRect( hDlg, resID, &rect );
if ( rect.top > playersBottom ) {
XP_ASSERT( ii < VSIZE(ids)-1 );
ids[ii] = resID;
++ii;
}
}
}
giState->moveIds = XP_MALLOC( giState->dlgHdr.globals->mpool,
sizeof(giState->moveIds[0]) * ii );
XP_MEMCPY( giState->moveIds, ids,
sizeof(giState->moveIds[0]) * ii );
giState->nMoveIds = ii;
}
moveY = giState->playersSpacing * (nPlayers - giState->prevNPlayers);
for ( ii = 0; ii < giState->nMoveIds; ++ii ) {
ceMoveItem( hDlg, giState->moveIds[ii], 0, moveY );
}
giState->prevNPlayers = nPlayers;
#ifdef _WIN32_WCE
if ( IS_SMARTPHONE(giState->dlgHdr.globals) ) {
SendMessage( hDlg, DM_RESETSCROLL, (WPARAM)FALSE, (LPARAM)TRUE );
}
#endif
}
}
static void
handlePrefsButton( HWND hDlg, CEAppGlobals* globals, GameInfoState* giState )
{
@ -433,6 +496,7 @@ ceSetAttrProc(void* closure, NewGameAttr attr, const NGValue value )
SendDlgItemMessage( giState->dlgHdr.hDlg, resID,
SETCURSEL(globals),
value.ng_u16 - 1, 0L );
raiseForHiddenPlayers( giState, value.ng_u16 );
break;
#ifndef XWFEATURE_STANDALONE_ONLY
case NG_ATTR_ROLE:
@ -491,12 +555,15 @@ checkUpdateCombo( GameInfoState* giState, XP_U16 id )
if ( (id == giState->nPlayersId)
&& giState->isNewGame ) { /* ignore if in info mode */
NGValue value;
value.ng_u16 = 1 + (XP_U16)
XP_U16 nPlayers = 1 + (XP_U16)
SendDlgItemMessage( giState->dlgHdr.hDlg, id,
GETCURSEL(giState->dlgHdr.globals), 0, 0L);
value.ng_u16 = nPlayers;
XP_ASSERT( !!giState->newGameCtx );
newg_attrChanged( giState->newGameCtx,
NG_ATTR_NPLAYERS, value );
raiseForHiddenPlayers( giState, nPlayers );
}
} /* checkUpdateCombo */
@ -517,6 +584,7 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
giState->nPlayersId = LB_IF_PPC(globals,IDC_NPLAYERSCOMBO);
giState->dictListId = LB_IF_PPC(globals,IDC_DICTLIST);
giState->prevNPlayers = MAX_NUM_PLAYERS;
ceDlgSetup( &giState->dlgHdr, hDlg, DLG_STATE_TRAPBACK );
ceDlgComboShowHide( &giState->dlgHdr, IDC_NPLAYERSCOMBO );

View file

@ -45,6 +45,13 @@ typedef struct GameInfoState {
XP_Bool colorsChanged;
XP_Bool addrChanged;
CePrefsPrefs prefsPrefs;
/* Support for repositioning lower items based on num players */
XP_U16* moveIds;
XP_U16 nMoveIds;
XP_U16 prevNPlayers;
XP_U16 playersSpacing;
} GameInfoState;

View file

@ -1335,8 +1335,8 @@ InitInstance(HINSTANCE hInstance, int nCmdShow
GetWindowRect( globals->hwndCB, &rcmb );
rc.bottom -= (rcmb.bottom - rcmb.top);
MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left,
rc.bottom-rc.top, FALSE);
MoveWindow( hWnd, rc.left, rc.top, rc.right-rc.left,
rc.bottom-rc.top, FALSE );
}
#endif

View file

@ -156,48 +156,51 @@ ceGetChecked( HWND hDlg, XP_U16 resID )
/* Return dlg-relative rect.
*/
static void
GetItemRect( HWND hDlg, XP_U16 resID, RECT* rect )
void
ceGetItemRect( HWND hDlg, XP_U16 resID, RECT* rect )
{
RECT dlgRect;
HWND itemH = GetDlgItem( hDlg, resID );
XP_U16 clientHt, winHt;
HWND itemH;
POINT pt = { .x = 0, .y = 0 };
ScreenToClient( hDlg, &pt );
GetClientRect( hDlg, &dlgRect );
clientHt = dlgRect.bottom;
GetWindowRect( hDlg, &dlgRect );
winHt = dlgRect.bottom - dlgRect.top;
itemH = GetDlgItem( hDlg, resID );
GetWindowRect( itemH, rect );
(void)OffsetRect( rect, pt.x, pt.y );
} /* ceGetItemRect */
/* GetWindowRect includes the title bar, but functions like MoveWindow
set relative to the client area below it. So subtract out the
difference between window ht and client rect ht -- the title bar --
when returning the item's rect. */
(void)OffsetRect( rect, -dlgRect.left,
-(dlgRect.top + winHt - clientHt) );
} /* GetItemRect */
void
ceMoveItem( HWND hDlg, XP_U16 resID, XP_S16 byX, XP_S16 byY )
{
RECT rect;
HWND itemH = GetDlgItem( hDlg, resID );
ceGetItemRect( hDlg, resID, &rect );
if ( !MoveWindow( itemH, rect.left + byX, rect.top + byY,
rect.right - rect.left, rect.bottom - rect.top,
TRUE ) ) {
XP_LOGF( "MoveWindow=>%ld", GetLastError() );
}
} /* ceMoveItem */
#if 0
/* This has not been tested with ceMoveItem... */
void
ceCenterCtl( HWND hDlg, XP_U16 resID )
{
RECT buttonR, dlgR;
HWND itemH = GetDlgItem( hDlg, resID );
XP_U16 newX, buttonWidth;
XP_U16 buttonWidth;
XP_S16 byX;
GetClientRect( hDlg, &dlgR );
XP_ASSERT( dlgR.left == 0 && dlgR.top == 0 );
GetItemRect( hDlg, resID, &buttonR );
ceGetItemRect( hDlg, resID, &buttonR );
buttonWidth = buttonR.right - buttonR.left;
newX = ( dlgR.right - buttonWidth ) / 2;
byX = buttonR.left - ((dlgR.right - buttonWidth) / 2);
if ( !MoveWindow( itemH, newX, buttonR.top,
buttonWidth,
buttonR.bottom - buttonR.top, TRUE ) ) {
XP_LOGF( "MoveWindow=>%ld", GetLastError() );
}
ceMoveItem( hDlg, resID, byX, 0 );
} /* ceCenterCtl */
#endif
/* XP_Bool */
/* ceIsLandscape( CEAppGlobals* globals ) */

View file

@ -44,6 +44,9 @@ void ceSetChecked( HWND hDlg, XP_U16 resID, XP_Bool check );
void ceCenterCtl( HWND hDlg, XP_U16 resID );
void ceCheckMenus( const CEAppGlobals* globals );
void ceGetItemRect( HWND hDlg, XP_U16 resID, RECT* rect );
void ceMoveItem( HWND hDlg, XP_U16 resID, XP_S16 byX, XP_S16 byY );
typedef enum {
PREFS_FILE_PATH_L
,DEFAULT_DIR_PATH_L

View file

@ -267,6 +267,8 @@
#define IDC_NPLAYERSUPDOWN 1219
#define IDC_NPLAYERSCOMBO_PPC 1220
#define IDC_DICTLABEL 1221
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED

View file

@ -237,6 +237,15 @@ END
#undef UPDOWN_CLASS
#define UPDOWN_CLASS "msctls_updown32"
#define CE_PLAYER_ROW(nameEdit,playerRow,robotCheck,passEdit) \
EDITTEXT nameEdit,GAME_NAME_LEFT,playerRow,GAME_NAME_WIDTH,ROW_HEIGHT, \
ES_AUTOHSCROLL \
CONTROL "",robotCheck,"Button",BS_AUTOCHECKBOX | WS_TABSTOP, \
GAME_ROBOT_LEFT,playerRow,CHECK_WIDTH,ROW_HEIGHT \
EDITTEXT passEdit,GAME_PWD_LEFT,playerRow,15,ROW_HEIGHT, \
ES_PASSWORD | ES_AUTOHSCROLL \
IDD_GAMEINFO DIALOG DISCARDABLE 0, 0, 116, GAMEINFO_HEIGHT
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | DS_CENTER | WS_VSCROLL
CAPTION "Game info"
@ -264,6 +273,7 @@ BEGIN
LABELS_ROW,19,8,SS_NOPREFIX
LTEXT "Robot",IDC_STATIC,GAME_ROBOTLABEL_LEFT-7,LABELS_ROW,20,8
LTEXT "Pwd",IDC_STATIC,GAME_PWDLABEL_LEFT,LABELS_ROW,16,8
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
LTEXT "Remote",IDC_REMOTE_LABEL,LEFT_COL,LABELS_ROW,25,8,SS_NOPREFIX
CONTROL "",REMOTE_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
@ -275,36 +285,12 @@ BEGIN
CONTROL "",REMOTE_CHECK4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
GAME_REMOTE_LEFT, PLAYER_ROW_4,CHECK_WIDTH,ROW_HEIGHT
#endif
EDITTEXT NAME_EDIT1,GAME_NAME_LEFT,PLAYER_ROW_1,GAME_NAME_WIDTH,ROW_HEIGHT,
ES_AUTOHSCROLL
CONTROL "",ROBOT_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
GAME_ROBOT_LEFT,PLAYER_ROW_1,CHECK_WIDTH,ROW_HEIGHT
EDITTEXT PASS_EDIT1,GAME_PWD_LEFT,PLAYER_ROW_1,15,ROW_HEIGHT,
ES_PASSWORD | ES_AUTOHSCROLL | WS_TABSTOP
CE_PLAYER_ROW( NAME_EDIT1, PLAYER_ROW_1, ROBOT_CHECK1, PASS_EDIT1 )
CE_PLAYER_ROW( NAME_EDIT2, PLAYER_ROW_2, ROBOT_CHECK2, PASS_EDIT2 )
CE_PLAYER_ROW( NAME_EDIT3, PLAYER_ROW_3, ROBOT_CHECK3, PASS_EDIT3 )
CE_PLAYER_ROW( NAME_EDIT4, PLAYER_ROW_4, ROBOT_CHECK4, PASS_EDIT4 )
EDITTEXT NAME_EDIT2,GAME_NAME_LEFT,PLAYER_ROW_2,GAME_NAME_WIDTH,ROW_HEIGHT,
ES_AUTOHSCROLL
CONTROL "",ROBOT_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
GAME_ROBOT_LEFT,PLAYER_ROW_2,CHECK_WIDTH,ROW_HEIGHT
EDITTEXT PASS_EDIT2,GAME_PWD_LEFT,PLAYER_ROW_2,15,ROW_HEIGHT,
ES_PASSWORD | ES_AUTOHSCROLL
EDITTEXT NAME_EDIT3,GAME_NAME_LEFT,PLAYER_ROW_3,GAME_NAME_WIDTH,ROW_HEIGHT,
ES_AUTOHSCROLL
CONTROL "",ROBOT_CHECK3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
GAME_ROBOT_LEFT,PLAYER_ROW_3,CHECK_WIDTH,ROW_HEIGHT
EDITTEXT PASS_EDIT3,GAME_PWD_LEFT,PLAYER_ROW_3,15,ROW_HEIGHT,
ES_PASSWORD | ES_AUTOHSCROLL
EDITTEXT NAME_EDIT4,GAME_NAME_LEFT,PLAYER_ROW_4,GAME_NAME_WIDTH,ROW_HEIGHT,
ES_AUTOHSCROLL | NOT WS_VISIBLE
CONTROL "",ROBOT_CHECK4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
GAME_ROBOT_LEFT, PLAYER_ROW_4,CHECK_WIDTH,ROW_HEIGHT
EDITTEXT PASS_EDIT4,GAME_PWD_LEFT,PLAYER_ROW_4,15,ROW_HEIGHT,
ES_PASSWORD | ES_AUTOHSCROLL
LTEXT "Dictionary:",IDC_STATIC,LEFT_COL,DICTPICK_LAB_ROW,36,8,
LTEXT "Dictionary:",IDC_DICTLABEL,LEFT_COL,DICTPICK_LAB_ROW,36,8,
SS_NOPREFIX
#ifdef _WIN32_WCE
LISTBOX IDC_DICTLIST, LEFT_COL+10,DICTPICK_ROW,70,12,LISTBOX_CONTROL_FLAGS