Make it possible to see comms dialog in read-only mode when role

selector is disabled (for game info use of new game dialog.)
This commit is contained in:
ehouse 2009-02-21 17:03:30 +00:00
parent ae0b8211fe
commit 7248ee8ad9
5 changed files with 64 additions and 27 deletions

View file

@ -23,6 +23,7 @@ PLATFORM = wince
TARGET_OS ?= win32
#TARGET_OS = wince
#NO_DRAW = -DNO_DRAW
# The preferred build environment for wince is now cegcc. Debian's
# pocketpc-sdk works in combination with the mingw projects headers,
@ -81,7 +82,6 @@ else # ifeq ($(TARGET_OS),wince)
ifeq ($(TARGET_OS),win32)
#STANDALONE = -DXWFEATURE_STANDALONE_ONLY
STANDALONE = -DPREV_WAS_STANDALONE_ONLY
# NO_DRAW = -DNO_DRAW
#BLUETOOTH = -DXWFEATURE_BLUETOOTH
#SMS = -DXWFEATURE_SMS
RELAY = -DXWFEATURE_RELAY -DUSE_BUFQUEUE

View file

@ -36,6 +36,7 @@ typedef struct _CeConnDlgState {
XP_U16 connComboId;
ConnDlgPair* types;
XP_Bool userCancelled;
XP_Bool forShowOnly;
} CeConnDlgState;
static CommsConnType indexToConType( const CeConnDlgState* state,
@ -180,6 +181,8 @@ ceControlsFromAddrRec( HWND hDlg, const CeConnDlgState* state )
XP_U16 ii;
CEAppGlobals* globals = state->dlgHdr.globals;
CommsConnType conType;
XP_U16 ids[32];
XP_S16 nIds = 0;
for ( ii = 0; ; ++ii ) {
ConnDlgPair* type = &state->types[ii];
@ -194,37 +197,53 @@ ceControlsFromAddrRec( HWND hDlg, const CeConnDlgState* state )
SendDlgItemMessage( hDlg, state->connComboId, SETCURSEL(globals),
conTypeToIndex(state, state->addrRec.conType), 0L );
ids[nIds++] = state->connComboId;
conType = state->addrRec.conType;
if ( state->addrRec.conType == COMMS_CONN_RELAY ) {
#ifdef XWFEATURE_RELAY
ceSetDlgItemText( hDlg, RELAYNAME_EDIT,
state->addrRec.u.ip_relay.hostName );
ids[nIds++] = RELAYNAME_EDIT;
ceSetDlgItemNum( hDlg, RELAYPORT_EDIT,
state->addrRec.u.ip_relay.port );
ids[nIds++] = RELAYPORT_EDIT;
ceSetDlgItemText( hDlg, COOKIE_EDIT,
state->addrRec.u.ip_relay.cookie );
ids[nIds++] = COOKIE_EDIT;
#endif
} else if ( state->addrRec.conType == COMMS_CONN_IP_DIRECT ) {
#ifdef XWFEATURE_IP_DIRECT
ceSetDlgItemText( hDlg, IPNAME_EDIT, state->addrRec.u.ip.hostName_ip );
ids[nIds++] = IPNAME_EDIT;
#endif
} else if ( state->addrRec.conType == COMMS_CONN_BT ) {
#ifdef XWFEATURE_BLUETOOTH
if ( state->role == SERVER_ISCLIENT ) {
ceSetDlgItemText( hDlg, IDC_BLUET_ADDR_EDIT,
state->addrRec.u.bt.hostName );
ids[nIds++] = IDC_BLUET_ADDR_EDIT;
}
#endif
} else if ( state->addrRec.conType == COMMS_CONN_SMS ) {
#ifdef XWFEATURE_SMS
ceSetDlgItemText( hDlg, IDC_SMS_PHONE_EDIT, state->addrRec.u.sms.phone );
ids[nIds++] = IDC_SMS_PHONE_EDIT;
ceSetDlgItemNum( hDlg, IDC_SMS_PORT_EDIT, state->addrRec.u.sms.port );
ids[nIds++] = IDC_SMS_PORT_EDIT;
#endif
} else {
XP_ASSERT(0);
}
}
XP_ASSERT( nIds < VSIZE(ids) );
if ( state->forShowOnly ) {
while ( nIds-- > 0 ) {
ceEnOrDisable( hDlg, ids[nIds], XP_FALSE );
}
}
} /* ceControlsFromAddrRec */
static LRESULT CALLBACK
ConnsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
@ -283,7 +302,7 @@ ConnsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
XP_Bool
WrapConnsDlg( HWND hDlg, CEAppGlobals* globals, const CommsAddrRec* addrRecIn,
CommsAddrRec* addrRecOut, DeviceRole role )
CommsAddrRec* addrRecOut, DeviceRole role, XP_Bool isNewGame )
{
XP_Bool result;
CeConnDlgState state;
@ -305,12 +324,13 @@ WrapConnsDlg( HWND hDlg, CEAppGlobals* globals, const CommsAddrRec* addrRecIn,
state.dlgHdr.globals = globals;
state.types = types;
state.role = role;
state.forShowOnly = !isNewGame;
XP_MEMCPY( &state.addrRec, addrRecIn, sizeof(state.addrRec) );
DialogBoxParam( globals->hInst, (LPCTSTR)IDD_CONNSSDLG, hDlg,
(DLGPROC)ConnsDlg, (long)&state );
result = !state.userCancelled;
result = isNewGame && !state.userCancelled;
if ( result ) {
XP_MEMCPY( addrRecOut, &state.addrRec, sizeof(*addrRecOut) );

View file

@ -26,7 +26,7 @@
#include "ceutil.h"
XP_Bool WrapConnsDlg( HWND hDlg, CEAppGlobals* globals,
const CommsAddrRec* addrRecIn,
CommsAddrRec* addrRecOut, DeviceRole role );
const CommsAddrRec* addrRecIn, CommsAddrRec* addrRecOut,
DeviceRole role, XP_Bool isNewGame );
#endif

View file

@ -89,6 +89,7 @@ messageToStr( UINT message )
CASE_STR( WM_EXITMENULOOP );
CASE_STR( WM_INITMENUPOPUP );
CASE_STR( WM_CANCELMODE );
CASE_STR( WM_ENTERIDLE );
default:
str = "<unknown>";
}

View file

@ -325,9 +325,11 @@ handlePrefsButton( HWND hDlg, CEAppGlobals* globals, GameInfoState* state )
#ifndef XWFEATURE_STANDALONE_ONLY
static void
handleConnOptionsButton( HWND hDlg, CEAppGlobals* globals,
DeviceRole role, GameInfoState* state )
handleConnOptionsButton( GameInfoState* state, DeviceRole role )
{
HWND hDlg = state->dlgHdr.hDlg;
CEAppGlobals* globals = state->dlgHdr.globals;
if ( role == SERVER_STANDALONE ) {
NGValue value;
role = (DeviceRole)SendDlgItemMessage( hDlg,
@ -338,17 +340,15 @@ handleConnOptionsButton( HWND hDlg, CEAppGlobals* globals,
newg_attrChanged( state->newGameCtx, NG_ATTR_ROLE, value );
}
if ( role != state->lastRole ) {
state->lastRole = role;
if ( role != SERVER_STANDALONE) {
if ( WrapConnsDlg( hDlg, globals, &state->prefsPrefs.addrRec,
&state->prefsPrefs.addrRec, role ) ) {
state->addrChanged = XP_TRUE;
}
state->lastRole = role;
if ( role != SERVER_STANDALONE) {
if ( WrapConnsDlg( hDlg, globals, &state->prefsPrefs.addrRec,
&state->prefsPrefs.addrRec, role,
state->isNewGame ) ) {
state->addrChanged = XP_TRUE;
}
}
}
} /* handleConnOptionsButton */
#endif
static XP_U16
@ -582,11 +582,26 @@ checkUpdateCombo( GameInfoState* state, XP_U16 id )
}
} else if ( id == state->roleComboId ) {
XP_ASSERT( SERVER_STANDALONE == 0 );
handleConnOptionsButton( hDlg, state->dlgHdr.globals,
SERVER_STANDALONE, state );
handleConnOptionsButton( state, SERVER_STANDALONE );
}
} /* checkUpdateCombo */
/* If we're mid-game and can't change role, click on role dropdown should
* still bring up conns dialog in read-only mode.
*/
static void
checkRoleClick( GameInfoState* state, XP_U16 xx, XP_U16 yy )
{
RECT rect;
ceGetItemRect( state->dlgHdr.hDlg, state->roleComboId, &rect );
/* Isn't there API for PtInRect? */
if ( xx > rect.left && xx < rect.right
&& yy > rect.top && yy < rect.bottom ) {
handleConnOptionsButton( state, state->lastRole );
}
} /* checkRoleClick */
LRESULT CALLBACK
GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
@ -659,6 +674,12 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
}
break;
case WM_LBUTTONUP:
if ( !state->isNewGame ) {
checkRoleClick( state, LOWORD(lParam), HIWORD(lParam) );
}
break;
case WM_COMMAND:
result = TRUE;
id = LOWORD(wParam);
@ -690,14 +711,9 @@ GameInfo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
case IDC_ROLECOMBO:
case IDC_ROLECOMBO_PPC:
if ( HIWORD(wParam) == CBN_SELCHANGE ) {
if ( state->isNewGame ) { /* ignore if in info
mode */
/* If we've switched to a state where we'll be
connecting */
handleConnOptionsButton( hDlg, globals,
SERVER_STANDALONE,
state );
}
/* If we've switched to a state where we'll be
connecting */
handleConnOptionsButton( state, SERVER_STANDALONE );
}
break;
#endif