modify API for "portraitizing" dialogs, and space the buttons evenly

rather than stacking all from bottom.  This doesn't quit work on ce
since GetWindowInfo isn't available and IsWindowVisible does the wrong
thing.
This commit is contained in:
ehouse 2006-05-27 17:18:42 +00:00
parent 75431f774c
commit c2ddb62591
12 changed files with 147 additions and 92 deletions

View file

@ -71,16 +71,13 @@ ConnsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
CEAppGlobals* globals;
if ( message == WM_INITDIALOG ) {
XP_U16 buttons[] = { IDOK, IDCANCEL };
SetWindowLong( hDlg, GWL_USERDATA, lParam );
cState = (CeConnDlgState*)lParam;
globals = cState->globals;
ceControlsFromAddrRec( hDlg, cState );
ceStackButtonsRight( globals, hDlg, buttons,
sizeof(buttons)/sizeof(buttons[0]), 8 );
ceStackButtonsRight( globals, hDlg );
result = TRUE;
} else {

View file

@ -35,8 +35,6 @@
#define CE_TIMER_HT_HORIZ CE_SCORE_HEIGHT
#define CE_TIMER_HT_VERT CE_SCORE_WIDTH
#if 1 /* Palm-like case */
#define CE_SCORE_TOP 0
#define CE_SCORE_HEIGHT 15
#define CE_BOARD_TOP (CE_SCORE_TOP + CE_SCORE_HEIGHT)
@ -59,25 +57,15 @@
#define CE_TIMER_TOP CE_SCORE_TOP
#define CE_TIMER_HEIGHT CE_SCORE_HEIGHT
#else /* tweaked for ce's stupid keyboard button: score on bottom */
#define CE_BOARD_TOP 0
#define CE_BOARD_HEIGHT (CE_MAX_ROWS*CE_BOARD_SCALEV)
#define CE_TRAY_TOP (CE_BOARD_TOP + CE_BOARD_HEIGHT)
#define CE_TRAY_SCALEH 34
#define CE_TRAY_SCALEV 27
#define CE_TRAY_TOP_MAX CE_TRAY_TOP
#define CE_SCORE_TOP (CE_TRAY_TOP + CE_TRAY_SCALEV)
#define CE_SCORE_HEIGHT 18
#define CE_SCORE_LEFT CE_BOARD_LEFT_RH
#define CE_TIMER_LEFT (CE_SCORE_WIDTH + CE_SCORE_LEFT)
#define CE_TIMER_RIGHT (CE_TIMER_LEFT + CE_TIMER_WIDTH)
#define CE_TIMER_TOP CE_SCORE_TOP
#define CE_TIMER_HEIGHT CE_SCORE_HEIGHT
#define MIN_CELL_WIDTH 12
#define MIN_CELL_HEIGHT 12
#if defined _WIN32_WCE
# define MIN_TRAY_HEIGHT 28
# define CE_MIN_SCORE_WIDTH 24 /* for vertical score case */
#else
# define MIN_TRAY_HEIGHT 40
# define CE_MIN_SCORE_WIDTH 36
#endif
#endif

View file

@ -574,8 +574,6 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
#endif
if ( message == WM_INITDIALOG ) {
XP_U16 buttons[] = { IDOK, IDCANCEL };
SetWindowLong( hDlg, GWL_USERDATA, lParam );
giState = (GameInfoState*)lParam;
giState->hDlg = hDlg;
@ -590,8 +588,7 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
if ( giState->isNewGame ) {
(void)SetWindowText( hDlg, L"New game" );
}
ceStackButtonsRight( globals, hDlg, buttons,
sizeof(buttons)/sizeof(buttons[0]), 8 );
ceStackButtonsRight( globals, hDlg );
return TRUE;
} else {

View file

@ -447,16 +447,6 @@ hideScroller( CEAppGlobals* globals )
}
#endif
#define MIN_CELL_WIDTH 12
#define MIN_CELL_HEIGHT 12
#if defined _WIN32_WCE
# define MIN_TRAY_HEIGHT 28
# define CE_MIN_SCORE_WIDTH 24 /* for vertical score case */
#else
# define MIN_TRAY_HEIGHT 40
# define CE_MIN_SCORE_WIDTH 36
#endif
typedef struct CEBoardParms {
XP_U16 boardHScale;
XP_U16 boardVScale;
@ -630,8 +620,6 @@ cePositionBoard( CEAppGlobals* globals )
figureBoardParms( globals, nCols, &bparms );
globals->isLandscape = !bparms.horiz;
if ( globals->gameInfo.timerEnabled ) {
board_setTimerLoc( globals->game.board, bparms.timerLeft,
bparms.timerTop, bparms.timerWidth,
@ -1132,6 +1120,11 @@ InitInstance(HINSTANCE hInstance, int nCmdShow)
XP_MEMSET( globals, 0, sizeof(*globals) );
MPASSIGN( globals->mpool, mpool );
#if defined DEBUG && !defined _WIN32_WCE
globals->dbWidth = g_dbWidth;
globals->dbHeight = g_dbHeight;
#endif
globals->vtMgr = make_vtablemgr( MPPARM_NOCOMMA(mpool) );
len = wcslen( DEFAULT_DIR_NAME );
@ -2106,6 +2099,8 @@ ceMsgFromStream( CEAppGlobals* globals, XWStreamCtxt* stream,
{
StrBoxInit init;
XP_MEMSET( &init, 0, sizeof(init) );
init.title = title;
init.stream = stream;
init.isQuery = isQuery;

View file

@ -100,7 +100,10 @@ typedef struct CEAppGlobals {
XP_Bool penDown;
XP_Bool hintPending;
XP_Bool doGlobalPrefs;
XP_Bool isLandscape;
#if defined DEBUG && !defined _WIN32_WCE
int dbWidth, dbHeight;
#endif
#ifdef XWFEATURE_SEARCHLIMIT
XP_Bool askTrayLimits;

View file

@ -261,8 +261,6 @@ PrefsDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
CePrefsDlgState* pState;
if ( message == WM_INITDIALOG ) {
XP_U16 buttons[] = { IDOK, IDCANCEL };
SetWindowLong( hDlg, GWL_USERDATA, lParam );
pState = (CePrefsDlgState*)lParam;
globals = pState->globals;
@ -272,8 +270,7 @@ PrefsDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
loadControlsFromState( hDlg, pState );
adjustForChoice( hDlg, pState );
ceStackButtonsRight( globals, hDlg, buttons,
sizeof(buttons)/sizeof(buttons[0]), 8 );
ceStackButtonsRight( globals, hDlg );
return TRUE;

View file

@ -54,13 +54,12 @@ stuffTextInField( HWND hDlg, StrBoxInit* init )
LRESULT CALLBACK
StrBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT handled = FALSE;
CEAppGlobals* globals = NULL;
StrBoxInit* init;
XP_U16 id;
if ( message == WM_INITDIALOG ) {
XP_U16 buttons[] = { IDOK, IDCANCEL };
SetWindowLong( hDlg, GWL_USERDATA, (long)lParam );
init = (StrBoxInit*)lParam;
@ -70,24 +69,32 @@ StrBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
SendMessage( hDlg, WM_SETTEXT, 0, (long)init->title );
}
ceStackButtonsRight( globals, hDlg, buttons,
sizeof(buttons)/sizeof(buttons[0]), 8 );
if ( !init->isQuery ) {
ceShowOrHide( hDlg, IDCANCEL, XP_FALSE );
/* also want to expand the text box to the bottom */
if ( !globals->isLandscape ) {
if ( !ceIsLandscape( globals ) ) {
ceCenterCtl( hDlg, IDOK );
}
}
stuffTextInField( hDlg, init );
return TRUE;
ceStackButtonsRight( globals, hDlg );
handled = TRUE;
} else {
init = (StrBoxInit*)GetWindowLong( hDlg, GWL_USERDATA );
if ( !!init ) {
switch (message) {
case WM_COMMAND:
case WM_COMMAND:
/* If I add the text above in the WM_INITDIALOG section it
shows up selected though selStart and selEnd are 0. */
if ( !init->textIsSet ) {
init->textIsSet = XP_TRUE;
stuffTextInField( hDlg, init );
}
id = LOWORD(wParam);
switch( id ) {
@ -95,11 +102,11 @@ StrBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
case IDCANCEL:
init->result = id;
EndDialog(hDlg, id);
return TRUE;
handled = TRUE;
}
break;
}
}
}
return FALSE;
return handled;
} /* StrBox */

View file

@ -32,4 +32,5 @@ typedef struct StrBoxInit {
XWStreamCtxt* stream;
XP_U16 result;
XP_Bool isQuery;
XP_Bool textIsSet;
} StrBoxInit;

View file

@ -18,8 +18,11 @@
*/
#include "ceutil.h"
#include "cedefines.h"
#define BUF_SIZE 128
#define VPADDING 4
#define HPADDING 2
void
ceSetDlgItemText( HWND hDlg, XP_U16 id, const XP_UCHAR* buf )
@ -192,46 +195,111 @@ ceCenterCtl( HWND hDlg, XP_U16 resID )
}
} /* ceCenterCtl */
void
ceStackButtonsRight( CEAppGlobals* globals, HWND hDlg,
XP_U16* resIDs, XP_U16 nResIDs,
XP_U16 top )
XP_Bool
ceIsLandscape( CEAppGlobals* globals )
{
if ( globals->isLandscape ) {
XP_U16 width, height;
XP_Bool landscape;
XP_ASSERT( !!globals );
XP_ASSERT( !!globals->hWnd );
if ( 0 ) {
#if defined DEBUG && !defined _WIN32_WCE
} else if ( globals->dbWidth != 0 ) {
width = globals->dbWidth;
height = globals->dbHeight;
#endif
} else {
RECT rect;
XP_U16 left;
XP_U16 maxWidth = 0;
XP_U16 maxHt = 0;
GetClientRect( globals->hWnd, &rect );
width = (XP_U16)(rect.right - rect.left);
height = (XP_U16)(rect.bottom - rect.top);
}
GetClientRect( hDlg, &rect );
left = rect.right;
landscape = (height - CE_SCORE_HEIGHT)
< (width - CE_MIN_SCORE_WIDTH);
return landscape;
} /* ceIsLandscape */
/* Now move any and all buttons into position along the right side */
while ( nResIDs-- ) {
HWND itemH = GetDlgItem( hDlg, *resIDs++ );
XP_U16 ht, width;
GetClientRect( itemH, &rect );
/* Can't figure out how to do this on CE. IsWindowVisible doesn't work, and
GetWindowInfo isn't even there. */
static XP_Bool
ceIsVisible( HWND hwnd )
{
#ifdef _WIN32_WCE /* GetWindowInfo isn't on CE */
return XP_TRUE;
#else
XP_Bool visible = XP_FALSE;
WINDOWINFO wi;
wi.cbSize = sizeof(wi);
width = rect.right - rect.left;
if ( maxWidth < width ) {
maxWidth = width;
if ( !!hwnd && GetWindowInfo( hwnd, &wi ) ) {
visible = (wi.dwStyle & WS_VISIBLE) != 0;
}
return visible;
#endif
} /* ceIsVisible */
void
ceStackButtonsRight( CEAppGlobals* globals, HWND hDlg )
{
XP_ASSERT( !!globals );
if ( ceIsLandscape( globals ) ) {
XP_U16 resIDs[] = { IDOK, IDCANCEL };
RECT rect;
XP_U16 left, top;
XP_U16 butWidth, butHeight;
XP_U16 barHt, i, nButtons, spacing;
/* First, figure height and width to use */
butHeight = 0;
butWidth = 0;
nButtons = 0;
for ( i = 0; i < sizeof(resIDs)/sizeof(resIDs[0]); ++i ) {
HWND itemH = GetDlgItem( hDlg, resIDs[i] );
if ( ceIsVisible( itemH ) ) {
RECT buttonRect;
GetClientRect( itemH, &buttonRect );
if ( butWidth < buttonRect.right ) {
butWidth = buttonRect.right;
}
if ( butHeight < buttonRect.bottom ) {
butHeight = buttonRect.bottom;
}
++nButtons;
}
ht = rect.bottom - rect.top;
if ( maxHt < ht ) {
maxHt = ht;
}
(void)MoveWindow( itemH, left, top, width, ht, TRUE );
top += ht + (REPOS_BUTTON_VPAD*2);
}
maxWidth += 4; /* padding */
GetWindowRect( hDlg, &rect );
barHt = rect.bottom - rect.top;
GetClientRect( hDlg, &rect );
barHt -= rect.bottom;
spacing = rect.bottom - (nButtons * (butHeight + (VPADDING*2)));
spacing /= nButtons + 1;
top = spacing - (butHeight / 2) + VPADDING;
left = rect.right + HPADDING;
for ( i = 0; i < sizeof(resIDs)/sizeof(resIDs[0]); ++i ) {
HWND itemH = GetDlgItem( hDlg, resIDs[i] );
if ( ceIsVisible( itemH ) ) {
(void)MoveWindow( itemH, left, top, butWidth, butHeight, TRUE );
top += butHeight + spacing + (VPADDING * 2);
}
}
butWidth += HPADDING*2;
GetWindowRect( hDlg, &rect );
MoveWindow( hDlg, rect.left - (maxWidth/2), rect.top,
rect.right - rect.left + maxWidth,
rect.bottom - rect.top - maxHt - 2,
MoveWindow( hDlg, rect.left - (butWidth/2), rect.top,
rect.right - rect.left + butWidth,
rect.bottom - rect.top - butHeight - 2,
FALSE );
}
} /* ceStackButtonsRight */

View file

@ -45,8 +45,10 @@ void ceCenterCtl( HWND hDlg, XP_U16 resID );
/* If app's in portrait mode, resize with some buttons at right rather than
bottom */
void ceStackButtonsRight( CEAppGlobals* globals, HWND hDlg,
XP_U16* resIDs, XP_U16 nResIDs, XP_U16 top );
void ceStackButtonsRight( CEAppGlobals* globals, HWND hDlg );
/* Are we drawing things in landscape mode? */
XP_Bool ceIsLandscape( CEAppGlobals* globals );
#ifdef DEBUG
void XP_LOGW( const XP_UCHAR* prefix, const wchar_t* arg );

View file

@ -198,6 +198,6 @@
#endif
#define REPOS_BUTTON_HT 14
#define REPOS_BUTTON_WIDTH 39
#define REPOS_BUTTON_WIDTH 30
#define REPOS_BUTTON_VPAD 2
#define REPOS_BUTTON_HPAD 2

View file

@ -260,15 +260,15 @@ BEGIN
REPOS_BUTTON_WIDTH,REPOS_BUTTON_HT
END
IDD_STRBOX DIALOG DISCARDABLE 0, 25, 127, 110
IDD_STRBOX DIALOG DISCARDABLE 0, 25, 121, 97
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | /*WS_SYSMENU | */ DS_CENTER
CAPTION "Dialog"
FONT 8, "System"
BEGIN
EDITTEXT ID_EDITTEXT,6,5,115,80,ES_MULTILINE | ES_READONLY
EDITTEXT ID_EDITTEXT,3,5,115,76,ES_MULTILINE | ES_READONLY
| WS_VSCROLL
DEFPUSHBUTTON "OK",IDOK, 29,90,REPOS_BUTTON_WIDTH,REPOS_BUTTON_HT
DEFPUSHBUTTON "No",IDCANCEL,70,90,REPOS_BUTTON_WIDTH,REPOS_BUTTON_HT
DEFPUSHBUTTON "OK",IDOK, 29,84,19,REPOS_BUTTON_HT
DEFPUSHBUTTON "No",IDCANCEL,70,84,19,REPOS_BUTTON_HT
END
IDD_ASKBLANK DIALOG DISCARDABLE 0, 0, 131, 90