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; CEAppGlobals* globals;
if ( message == WM_INITDIALOG ) { if ( message == WM_INITDIALOG ) {
XP_U16 buttons[] = { IDOK, IDCANCEL };
SetWindowLong( hDlg, GWL_USERDATA, lParam ); SetWindowLong( hDlg, GWL_USERDATA, lParam );
cState = (CeConnDlgState*)lParam; cState = (CeConnDlgState*)lParam;
globals = cState->globals; globals = cState->globals;
ceControlsFromAddrRec( hDlg, cState ); ceControlsFromAddrRec( hDlg, cState );
ceStackButtonsRight( globals, hDlg, buttons, ceStackButtonsRight( globals, hDlg );
sizeof(buttons)/sizeof(buttons[0]), 8 );
result = TRUE; result = TRUE;
} else { } else {

View file

@ -35,8 +35,6 @@
#define CE_TIMER_HT_HORIZ CE_SCORE_HEIGHT #define CE_TIMER_HT_HORIZ CE_SCORE_HEIGHT
#define CE_TIMER_HT_VERT CE_SCORE_WIDTH #define CE_TIMER_HT_VERT CE_SCORE_WIDTH
#if 1 /* Palm-like case */
#define CE_SCORE_TOP 0 #define CE_SCORE_TOP 0
#define CE_SCORE_HEIGHT 15 #define CE_SCORE_HEIGHT 15
#define CE_BOARD_TOP (CE_SCORE_TOP + CE_SCORE_HEIGHT) #define CE_BOARD_TOP (CE_SCORE_TOP + CE_SCORE_HEIGHT)
@ -59,25 +57,15 @@
#define CE_TIMER_TOP CE_SCORE_TOP #define CE_TIMER_TOP CE_SCORE_TOP
#define CE_TIMER_HEIGHT CE_SCORE_HEIGHT #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
#endif #endif

View file

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

View file

@ -447,16 +447,6 @@ hideScroller( CEAppGlobals* globals )
} }
#endif #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 { typedef struct CEBoardParms {
XP_U16 boardHScale; XP_U16 boardHScale;
XP_U16 boardVScale; XP_U16 boardVScale;
@ -630,8 +620,6 @@ cePositionBoard( CEAppGlobals* globals )
figureBoardParms( globals, nCols, &bparms ); figureBoardParms( globals, nCols, &bparms );
globals->isLandscape = !bparms.horiz;
if ( globals->gameInfo.timerEnabled ) { if ( globals->gameInfo.timerEnabled ) {
board_setTimerLoc( globals->game.board, bparms.timerLeft, board_setTimerLoc( globals->game.board, bparms.timerLeft,
bparms.timerTop, bparms.timerWidth, bparms.timerTop, bparms.timerWidth,
@ -1132,6 +1120,11 @@ InitInstance(HINSTANCE hInstance, int nCmdShow)
XP_MEMSET( globals, 0, sizeof(*globals) ); XP_MEMSET( globals, 0, sizeof(*globals) );
MPASSIGN( globals->mpool, mpool ); 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) ); globals->vtMgr = make_vtablemgr( MPPARM_NOCOMMA(mpool) );
len = wcslen( DEFAULT_DIR_NAME ); len = wcslen( DEFAULT_DIR_NAME );
@ -2106,6 +2099,8 @@ ceMsgFromStream( CEAppGlobals* globals, XWStreamCtxt* stream,
{ {
StrBoxInit init; StrBoxInit init;
XP_MEMSET( &init, 0, sizeof(init) );
init.title = title; init.title = title;
init.stream = stream; init.stream = stream;
init.isQuery = isQuery; init.isQuery = isQuery;

View file

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

View file

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

View file

@ -54,13 +54,12 @@ stuffTextInField( HWND hDlg, StrBoxInit* init )
LRESULT CALLBACK LRESULT CALLBACK
StrBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) StrBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{ {
LRESULT handled = FALSE;
CEAppGlobals* globals = NULL; CEAppGlobals* globals = NULL;
StrBoxInit* init; StrBoxInit* init;
XP_U16 id; XP_U16 id;
if ( message == WM_INITDIALOG ) { if ( message == WM_INITDIALOG ) {
XP_U16 buttons[] = { IDOK, IDCANCEL };
SetWindowLong( hDlg, GWL_USERDATA, (long)lParam ); SetWindowLong( hDlg, GWL_USERDATA, (long)lParam );
init = (StrBoxInit*)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 ); SendMessage( hDlg, WM_SETTEXT, 0, (long)init->title );
} }
ceStackButtonsRight( globals, hDlg, buttons,
sizeof(buttons)/sizeof(buttons[0]), 8 );
if ( !init->isQuery ) { if ( !init->isQuery ) {
ceShowOrHide( hDlg, IDCANCEL, XP_FALSE ); ceShowOrHide( hDlg, IDCANCEL, XP_FALSE );
/* also want to expand the text box to the bottom */ /* also want to expand the text box to the bottom */
if ( !globals->isLandscape ) { if ( !ceIsLandscape( globals ) ) {
ceCenterCtl( hDlg, IDOK ); ceCenterCtl( hDlg, IDOK );
} }
} }
stuffTextInField( hDlg, init );
return TRUE; ceStackButtonsRight( globals, hDlg );
handled = TRUE;
} else { } else {
init = (StrBoxInit*)GetWindowLong( hDlg, GWL_USERDATA ); init = (StrBoxInit*)GetWindowLong( hDlg, GWL_USERDATA );
if ( !!init ) { if ( !!init ) {
switch (message) { 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); id = LOWORD(wParam);
switch( id ) { switch( id ) {
@ -95,11 +102,11 @@ StrBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
case IDCANCEL: case IDCANCEL:
init->result = id; init->result = id;
EndDialog(hDlg, id); EndDialog(hDlg, id);
return TRUE; handled = TRUE;
} }
break; break;
} }
} }
} }
return FALSE; return handled;
} /* StrBox */ } /* StrBox */

View file

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

View file

@ -18,8 +18,11 @@
*/ */
#include "ceutil.h" #include "ceutil.h"
#include "cedefines.h"
#define BUF_SIZE 128 #define BUF_SIZE 128
#define VPADDING 4
#define HPADDING 2
void void
ceSetDlgItemText( HWND hDlg, XP_U16 id, const XP_UCHAR* buf ) ceSetDlgItemText( HWND hDlg, XP_U16 id, const XP_UCHAR* buf )
@ -192,46 +195,111 @@ ceCenterCtl( HWND hDlg, XP_U16 resID )
} }
} /* ceCenterCtl */ } /* ceCenterCtl */
void XP_Bool
ceStackButtonsRight( CEAppGlobals* globals, HWND hDlg, ceIsLandscape( CEAppGlobals* globals )
XP_U16* resIDs, XP_U16 nResIDs,
XP_U16 top )
{ {
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; RECT rect;
XP_U16 left; GetClientRect( globals->hWnd, &rect );
XP_U16 maxWidth = 0; width = (XP_U16)(rect.right - rect.left);
XP_U16 maxHt = 0; height = (XP_U16)(rect.bottom - rect.top);
}
GetClientRect( hDlg, &rect ); landscape = (height - CE_SCORE_HEIGHT)
left = rect.right; < (width - CE_MIN_SCORE_WIDTH);
return landscape;
} /* ceIsLandscape */
/* Now move any and all buttons into position along the right side */ /* Can't figure out how to do this on CE. IsWindowVisible doesn't work, and
while ( nResIDs-- ) { GetWindowInfo isn't even there. */
HWND itemH = GetDlgItem( hDlg, *resIDs++ ); static XP_Bool
XP_U16 ht, width; ceIsVisible( HWND hwnd )
GetClientRect( itemH, &rect ); {
#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 ( !!hwnd && GetWindowInfo( hwnd, &wi ) ) {
if ( maxWidth < width ) { visible = (wi.dwStyle & WS_VISIBLE) != 0;
maxWidth = width; }
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 ); GetWindowRect( hDlg, &rect );
MoveWindow( hDlg, rect.left - (maxWidth/2), rect.top,
rect.right - rect.left + maxWidth, MoveWindow( hDlg, rect.left - (butWidth/2), rect.top,
rect.bottom - rect.top - maxHt - 2, rect.right - rect.left + butWidth,
rect.bottom - rect.top - butHeight - 2,
FALSE ); FALSE );
} }
} /* ceStackButtonsRight */ } /* 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 /* If app's in portrait mode, resize with some buttons at right rather than
bottom */ bottom */
void ceStackButtonsRight( CEAppGlobals* globals, HWND hDlg, void ceStackButtonsRight( CEAppGlobals* globals, HWND hDlg );
XP_U16* resIDs, XP_U16 nResIDs, XP_U16 top );
/* Are we drawing things in landscape mode? */
XP_Bool ceIsLandscape( CEAppGlobals* globals );
#ifdef DEBUG #ifdef DEBUG
void XP_LOGW( const XP_UCHAR* prefix, const wchar_t* arg ); void XP_LOGW( const XP_UCHAR* prefix, const wchar_t* arg );

View file

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

View file

@ -260,15 +260,15 @@ BEGIN
REPOS_BUTTON_WIDTH,REPOS_BUTTON_HT REPOS_BUTTON_WIDTH,REPOS_BUTTON_HT
END 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 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | /*WS_SYSMENU | */ DS_CENTER
CAPTION "Dialog" CAPTION "Dialog"
FONT 8, "System" FONT 8, "System"
BEGIN 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 | WS_VSCROLL
DEFPUSHBUTTON "OK",IDOK, 29,90,REPOS_BUTTON_WIDTH,REPOS_BUTTON_HT DEFPUSHBUTTON "OK",IDOK, 29,84,19,REPOS_BUTTON_HT
DEFPUSHBUTTON "No",IDCANCEL,70,90,REPOS_BUTTON_WIDTH,REPOS_BUTTON_HT DEFPUSHBUTTON "No",IDCANCEL,70,84,19,REPOS_BUTTON_HT
END END
IDD_ASKBLANK DIALOG DISCARDABLE 0, 0, 131, 90 IDD_ASKBLANK DIALOG DISCARDABLE 0, 0, 131, 90