2009-04-05 22:18:46 +02:00
|
|
|
/* -*- fill-column: 77; compile-command: "make -j2 TARGET_OS=wince DEBUG=TRUE" -*- */
|
2003-11-20 17:26:35 +01:00
|
|
|
/*
|
2009-01-04 01:00:45 +01:00
|
|
|
* Copyright 2002-2009 by Eric House (xwords@eehouse.org). All rights
|
|
|
|
* reserved.
|
2003-11-20 17:26:35 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
2004-01-30 06:48:24 +01:00
|
|
|
* Derived from code generated by M$'s eVC++.
|
2003-11-20 17:26:35 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "xwords4.h"
|
|
|
|
#include <commctrl.h>
|
|
|
|
#include <commdlg.h>
|
|
|
|
#include <stdio.h>
|
2006-05-12 09:17:35 +02:00
|
|
|
#include <time.h> /* time() */
|
2003-11-20 17:26:35 +01:00
|
|
|
#include <winuser.h>
|
2006-02-17 08:30:54 +01:00
|
|
|
#ifdef _WIN32_WCE
|
2005-11-27 21:16:43 +01:00
|
|
|
# include <aygshell.h>
|
|
|
|
#endif
|
2008-05-11 22:29:43 +02:00
|
|
|
/* #include <imm.h> */
|
2003-11-20 17:26:35 +01:00
|
|
|
#include "strutils.h"
|
|
|
|
|
|
|
|
#include "memstream.h"
|
|
|
|
|
|
|
|
#include "cemain.h"
|
|
|
|
#include "cedefines.h"
|
|
|
|
|
|
|
|
#include "ceginfo.h"
|
|
|
|
#include "cestrbx.h"
|
|
|
|
#include "cedict.h"
|
|
|
|
#include "ceblank.h"
|
|
|
|
#include "ceprefs.h"
|
|
|
|
#include "ceaskpwd.h"
|
|
|
|
#include "ceutil.h"
|
|
|
|
#include "ceir.h"
|
2004-03-28 03:14:34 +02:00
|
|
|
#include "ceclrsel.h"
|
2004-07-10 19:46:36 +02:00
|
|
|
#include "cehntlim.h"
|
2008-02-16 18:36:46 +01:00
|
|
|
#include "cedebug.h"
|
2003-11-20 17:26:35 +01:00
|
|
|
#include "LocalizedStrIncludes.h"
|
2006-01-28 20:02:04 +01:00
|
|
|
#include "debhacks.h"
|
2008-03-24 13:41:12 +01:00
|
|
|
#include "cesvdgms.h"
|
2008-09-01 17:10:28 +02:00
|
|
|
#include "cedraw.h"
|
2009-01-05 15:13:40 +01:00
|
|
|
#include "cesms.h"
|
2009-01-31 19:06:09 +01:00
|
|
|
#include "cesockwr.h"
|
2009-04-09 15:48:38 +02:00
|
|
|
#include "ceresstr.h"
|
2009-12-23 07:01:26 +01:00
|
|
|
#include "ceconnmg.h"
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2007-01-19 09:24:02 +01:00
|
|
|
#include "dbgutil.h"
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
#define MAX_LOADSTRING 100
|
2006-02-15 14:09:36 +01:00
|
|
|
|
2008-10-08 06:42:16 +02:00
|
|
|
#define MAX_SCROLLBAR_WIDTH 12
|
2008-09-28 19:50:04 +02:00
|
|
|
#define MIN_SCROLLBAR_WIDTH 6
|
2005-02-05 22:43:16 +01:00
|
|
|
#define SCROLLBARID 0x4321 /* needs to be unique! */
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
#ifdef MEM_DEBUG
|
|
|
|
# define MEMPOOL globals->mpool,
|
|
|
|
#else
|
|
|
|
# define MEMPOOL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct FileWriteState {
|
|
|
|
CEAppGlobals* globals;
|
|
|
|
XP_UCHAR* path;
|
|
|
|
} FileWriteState;
|
|
|
|
|
|
|
|
/* forward util function decls */
|
2009-01-05 15:13:40 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2006-09-15 09:39:57 +02:00
|
|
|
static XP_S16 ce_send_proc( const XP_U8* buf, XP_U16 len,
|
2005-07-30 04:02:49 +02:00
|
|
|
const CommsAddrRec* addr,
|
2005-07-23 17:31:21 +02:00
|
|
|
void* closure );
|
2009-09-15 15:04:34 +02:00
|
|
|
static void ce_relay_status( void* closure,
|
|
|
|
CommsRelayState newState );
|
2009-12-14 05:12:20 +01:00
|
|
|
static void ce_relay_connd( void* closure, XP_Bool allHere,
|
|
|
|
XP_U16 nMissing );
|
2009-12-04 10:09:07 +01:00
|
|
|
static void ce_relay_error( void* closure, XWREASON relayErr );
|
|
|
|
|
2009-09-15 15:04:34 +02:00
|
|
|
|
2009-09-13 01:31:48 +02:00
|
|
|
# ifdef COMMS_HEARTBEAT
|
2007-12-03 02:18:13 +01:00
|
|
|
static void ce_reset_proc( void* closure );
|
2009-09-13 01:31:48 +02:00
|
|
|
# endif
|
2007-12-03 02:18:13 +01:00
|
|
|
#endif
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static VTableMgr* ce_util_getVTManager( XW_UtilCtxt* uc );
|
|
|
|
static void ce_util_userError( XW_UtilCtxt* uc, UtilErrID id );
|
2004-02-17 06:00:13 +01:00
|
|
|
static XP_Bool ce_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id,
|
|
|
|
XWStreamCtxt* stream );
|
2003-11-20 17:26:35 +01:00
|
|
|
static XWBonusType ce_util_getSquareBonus( XW_UtilCtxt* uc,
|
2008-05-06 14:49:37 +02:00
|
|
|
const ModelCtxt* model,
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_U16 col, XP_U16 row );
|
2005-02-05 22:43:16 +01:00
|
|
|
static XP_S16 ce_util_userPickTile( XW_UtilCtxt* uc, const PickInfo* pi,
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_U16 playerNum,
|
2009-04-07 06:23:56 +02:00
|
|
|
const XP_UCHAR** texts, XP_U16 nTiles );
|
2003-11-20 17:26:35 +01:00
|
|
|
static XP_Bool ce_util_askPassword( XW_UtilCtxt* uc, const XP_UCHAR* name,
|
|
|
|
XP_UCHAR* buf, XP_U16* len );
|
2005-11-27 21:16:43 +01:00
|
|
|
static void ce_util_trayHiddenChange( XW_UtilCtxt* uc,
|
2006-05-19 15:44:05 +02:00
|
|
|
XW_TrayVisState newState,
|
|
|
|
XP_U16 nVisibleRows );
|
2003-11-20 17:26:35 +01:00
|
|
|
static void ce_util_yOffsetChange( XW_UtilCtxt* uc, XP_U16 oldOffset,
|
|
|
|
XP_U16 newOffset );
|
2008-02-26 14:49:41 +01:00
|
|
|
static void ce_util_turnChanged( XW_UtilCtxt* uc );
|
2003-11-20 17:26:35 +01:00
|
|
|
static void ce_util_notifyGameOver( XW_UtilCtxt* uc );
|
|
|
|
static XP_Bool ce_util_hiliteCell( XW_UtilCtxt* uc, XP_U16 col,
|
|
|
|
XP_U16 row );
|
|
|
|
static XP_Bool ce_util_engineProgressCallback( XW_UtilCtxt* uc );
|
2005-06-23 16:09:20 +02:00
|
|
|
static void ce_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why, XP_U16 when,
|
2007-05-26 16:14:01 +02:00
|
|
|
XWTimerProc proc, void* closure);
|
2009-09-21 14:49:08 +02:00
|
|
|
static void ce_util_clearTimer( XW_UtilCtxt* uc, XWTimerReason why );
|
2008-04-08 05:55:53 +02:00
|
|
|
static XP_Bool ce_util_altKeyDown( XW_UtilCtxt* uc );
|
2003-11-20 17:26:35 +01:00
|
|
|
static void ce_util_requestTime( XW_UtilCtxt* uc );
|
|
|
|
static XP_U32 ce_util_getCurSeconds( XW_UtilCtxt* uc );
|
|
|
|
static DictionaryCtxt* ce_util_makeEmptyDict( XW_UtilCtxt* uc );
|
2006-10-28 16:56:04 +02:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2003-11-20 17:26:35 +01:00
|
|
|
static XWStreamCtxt* ce_util_makeStreamFromAddr( XW_UtilCtxt* uc,
|
2008-01-05 17:37:49 +01:00
|
|
|
XP_PlayerAddr channelNo );
|
2003-11-20 17:26:35 +01:00
|
|
|
#endif
|
2007-02-03 18:54:20 +01:00
|
|
|
static const XP_UCHAR* ce_util_getUserString( XW_UtilCtxt* uc,
|
|
|
|
XP_U16 stringCode );
|
2003-11-20 17:26:35 +01:00
|
|
|
static XP_Bool ce_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi,
|
|
|
|
XP_U16 turn, XP_Bool turnLost );
|
2008-10-24 11:05:13 +02:00
|
|
|
static void ce_util_remSelected( XW_UtilCtxt* uc );
|
2009-03-08 21:01:47 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2005-07-23 17:31:21 +02:00
|
|
|
static void ce_util_addrChange( XW_UtilCtxt* uc, const CommsAddrRec* oldAddr,
|
|
|
|
const CommsAddrRec* newAddr );
|
|
|
|
#endif
|
|
|
|
|
2004-07-10 19:46:36 +02:00
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
static XP_Bool ce_util_getTraySearchLimits( XW_UtilCtxt* uc, XP_U16* min,
|
|
|
|
XP_U16* max );
|
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
#ifdef SHOW_PROGRESS
|
|
|
|
static void ce_util_engineStarting( XW_UtilCtxt* uc );
|
|
|
|
static void ce_util_engineStopping( XW_UtilCtxt* uc );
|
|
|
|
#endif
|
|
|
|
|
2004-02-17 06:00:13 +01:00
|
|
|
static XP_Bool ceMsgFromStream( CEAppGlobals* globals, XWStreamCtxt* stream,
|
2009-04-11 17:45:59 +02:00
|
|
|
const wchar_t* title, XP_U16 buttons,
|
2004-02-17 06:00:13 +01:00
|
|
|
XP_Bool destroy );
|
2008-05-25 17:08:03 +02:00
|
|
|
static void RECTtoXPR( XP_Rect* dest, const RECT* src );
|
2009-12-04 10:09:07 +01:00
|
|
|
static XP_Bool ceDoNewGame( CEAppGlobals* globals, GIShow showWhat );
|
2004-01-10 19:11:28 +01:00
|
|
|
static XP_Bool ceSaveCurGame( CEAppGlobals* globals, XP_Bool autoSave );
|
2008-08-01 12:47:32 +02:00
|
|
|
static void closeGame( CEAppGlobals* globals );
|
2008-02-23 23:06:05 +01:00
|
|
|
static void ceInitPrefs( CEAppGlobals* globals, CEAppPrefs* prefs );
|
2004-05-26 06:48:25 +02:00
|
|
|
static void updateForColors( CEAppGlobals* globals );
|
2008-09-28 18:48:30 +02:00
|
|
|
static XWStreamCtxt* make_generic_stream( const CEAppGlobals* globals );
|
2009-11-22 18:58:59 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2005-08-21 16:36:11 +02:00
|
|
|
static void ce_send_on_close( XWStreamCtxt* stream, void* closure );
|
2006-05-28 16:53:02 +02:00
|
|
|
#endif
|
2006-04-19 06:56:00 +02:00
|
|
|
static XP_Bool ceSetDictName( const wchar_t* wPath, XP_U16 index, void* ctxt );
|
2008-03-15 22:56:37 +01:00
|
|
|
static int messageBoxStream( CEAppGlobals* globals, XWStreamCtxt* stream,
|
2009-04-11 17:45:59 +02:00
|
|
|
const wchar_t* title, XP_U16 buttons );
|
2006-05-05 14:51:08 +02:00
|
|
|
static XP_Bool ceQueryFromStream( CEAppGlobals* globals, XWStreamCtxt* stream);
|
2009-12-27 03:54:30 +01:00
|
|
|
static int ceOopsId( CEAppGlobals* globals, XP_U16 strId, SkipAlertBits sab );
|
|
|
|
static int ceOops( CEAppGlobals* globals, const XP_UCHAR* str,
|
|
|
|
SkipAlertBits sab );
|
2008-10-25 20:08:36 +02:00
|
|
|
static XP_Bool isDefaultName( CEAppGlobals* globals, const XP_UCHAR* name );
|
2008-09-28 19:50:04 +02:00
|
|
|
static void ceSetTitleFromName( CEAppGlobals* globals );
|
2008-12-01 14:11:58 +01:00
|
|
|
static void removeScrollbar( CEAppGlobals* globals );
|
2009-12-21 07:36:04 +01:00
|
|
|
static void ceToggleFullScreen( CEAppGlobals* globals );
|
2008-02-16 18:36:46 +01:00
|
|
|
|
2006-04-19 06:56:00 +02:00
|
|
|
|
2008-11-10 19:49:26 +01:00
|
|
|
#ifndef _WIN32_WCE
|
2006-05-12 09:54:59 +02:00
|
|
|
/* Very basic cmdline args meant at first to let me vary the size of the
|
|
|
|
* screen. Form is of arg=digits, with no spaces and digits having to be an
|
|
|
|
* integer. Right now only width and height work: e.g.
|
|
|
|
* "wine obj_win32_dbg/xwords4.exe height=240 width=320"
|
|
|
|
*/
|
2008-11-10 19:49:26 +01:00
|
|
|
static XP_Bool
|
|
|
|
tryIntParam( const char* buf, const char* param, XP_U16* value )
|
2006-05-12 09:54:59 +02:00
|
|
|
{
|
2008-11-10 19:49:26 +01:00
|
|
|
XP_U16 len = strlen( param );
|
|
|
|
XP_Bool found = 0 == strncmp( buf, param, len );
|
|
|
|
if ( found ) {
|
|
|
|
*value = atoi( &buf[len] );
|
2006-05-12 09:54:59 +02:00
|
|
|
}
|
2008-11-10 19:49:26 +01:00
|
|
|
return found;
|
|
|
|
}
|
2006-05-12 09:54:59 +02:00
|
|
|
|
2009-04-09 15:48:38 +02:00
|
|
|
static XP_Bool
|
|
|
|
tryCharParam( const char* buf, const char* param, char* out )
|
|
|
|
{
|
|
|
|
XP_U16 len = strlen( param );
|
|
|
|
XP_Bool found = 0 == strncmp( buf, param, len );
|
|
|
|
if ( found ) {
|
|
|
|
int ii;
|
|
|
|
for ( ii = len; buf[ii] != ' ' && buf[ii] != 0 ; ++ii ) {
|
|
|
|
}
|
|
|
|
memcpy( out, &buf[len], ii - len );
|
|
|
|
out[ii-len] = 0;
|
|
|
|
XP_LOGF( "%s: \"%s\"", __func__, out );
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2006-05-12 09:54:59 +02:00
|
|
|
static void
|
2009-04-09 15:48:38 +02:00
|
|
|
parseCmdLine( const char* cmdline, XP_U16* width, XP_U16* height,
|
|
|
|
char* dll )
|
2006-05-12 09:54:59 +02:00
|
|
|
{
|
2008-09-28 19:50:04 +02:00
|
|
|
XP_U16 ii;
|
|
|
|
for ( ii = 0; ; ++ii ) {
|
2006-05-12 09:54:59 +02:00
|
|
|
const char* cmd;
|
|
|
|
char ch;
|
|
|
|
char buf[64];
|
|
|
|
int len;
|
|
|
|
for ( cmd = cmdline ; ; ++cmd ) {
|
|
|
|
ch = *cmd;
|
|
|
|
if ( ch == '\0' || ch == ' ' ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
len = cmd - cmdline;
|
2008-11-10 19:49:26 +01:00
|
|
|
if ( len < sizeof(buf) ) {
|
|
|
|
memcpy( buf, cmdline, cmd - cmdline );
|
|
|
|
buf[len] = '\0';
|
|
|
|
if ( ii > 0 ) { /* skip argv[0] */
|
|
|
|
if ( tryIntParam( buf, "width=", width ) ) {
|
|
|
|
} else if ( tryIntParam( buf, "height=", height ) ) {
|
2009-04-09 15:48:38 +02:00
|
|
|
} else if ( tryCharParam( buf, "dll=", dll ) ) {
|
2008-11-10 19:49:26 +01:00
|
|
|
} else {
|
|
|
|
XP_LOGF( "failed to match cmdline arg \"%s\"", buf );
|
|
|
|
}
|
|
|
|
}
|
2008-09-28 19:50:04 +02:00
|
|
|
}
|
2006-05-12 09:54:59 +02:00
|
|
|
if ( ch == '\0' ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cmdline = ++cmd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
// Forward declarations of functions included in this code module:
|
|
|
|
ATOM MyRegisterClass (HINSTANCE, LPTSTR);
|
2008-11-10 19:49:26 +01:00
|
|
|
BOOL InitInstance (HINSTANCE, int
|
|
|
|
#ifndef _WIN32_WCE
|
2009-04-09 15:48:38 +02:00
|
|
|
, XP_U16, XP_U16, const char*
|
2008-11-10 19:49:26 +01:00
|
|
|
#endif
|
|
|
|
);
|
2003-11-20 17:26:35 +01:00
|
|
|
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
|
2008-02-16 18:36:46 +01:00
|
|
|
LRESULT CALLBACK ceAbout (HWND, UINT, WPARAM, LPARAM);
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
int WINAPI
|
|
|
|
WinMain( HINSTANCE hInstance,
|
2006-08-16 15:44:44 +02:00
|
|
|
HINSTANCE XP_UNUSED(hPrevInstance),
|
2008-11-22 17:43:55 +01:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
LPWSTR XP_UNUSED_CE(lpCmdLine),
|
|
|
|
#else
|
|
|
|
LPSTR lpCmdLine,
|
2005-11-27 21:16:43 +01:00
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
int nCmdShow)
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
HACCEL hAccelTable;
|
|
|
|
|
2008-11-10 19:49:26 +01:00
|
|
|
#ifndef _WIN32_WCE
|
2008-11-13 06:46:21 +01:00
|
|
|
XP_U16 width = 320, height = 320;
|
2009-04-19 19:33:39 +02:00
|
|
|
char dll[MAX_PATH] = {0};
|
2009-04-09 15:48:38 +02:00
|
|
|
parseCmdLine( lpCmdLine, &width, &height, dll );
|
2006-05-12 09:54:59 +02:00
|
|
|
#endif
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
// Perform application initialization:
|
2008-11-10 19:49:26 +01:00
|
|
|
if (!InitInstance (hInstance, nCmdShow
|
|
|
|
#ifndef _WIN32_WCE
|
2009-04-09 15:48:38 +02:00
|
|
|
, width, height, dll
|
2008-11-10 19:49:26 +01:00
|
|
|
#endif
|
|
|
|
)) {
|
2003-11-20 17:26:35 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_XWORDS4);
|
|
|
|
|
2005-07-30 04:02:49 +02:00
|
|
|
// Main message loop. Return of 0 indicates quit message. Return of -1
|
|
|
|
// indicates major error (so we just bail.)
|
|
|
|
while ( 0 < GetMessage(&msg, NULL, 0, 0) ) {
|
2003-11-20 17:26:35 +01:00
|
|
|
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-30 04:02:49 +02:00
|
|
|
/* This would be a good place to free up memory, close sockets, etc. */
|
|
|
|
|
2006-05-30 07:12:02 +02:00
|
|
|
LOG_RETURNF( "%d", msg.wParam );
|
2003-11-20 17:26:35 +01:00
|
|
|
return msg.wParam;
|
|
|
|
}
|
|
|
|
|
2006-01-28 20:02:04 +01:00
|
|
|
#ifdef __GNUC__
|
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
2006-01-31 07:41:16 +01:00
|
|
|
LOG_FUNC();
|
2006-01-28 20:02:04 +01:00
|
|
|
|
|
|
|
return WinMain( GetModuleHandle(NULL), 0,
|
2008-11-22 17:43:55 +01:00
|
|
|
#ifdef _WIN32_WCE
|
2006-01-28 20:02:04 +01:00
|
|
|
GetCommandLineW(),
|
2008-11-22 17:43:55 +01:00
|
|
|
#else
|
2006-01-28 20:02:04 +01:00
|
|
|
GetCommandLineA(),
|
|
|
|
#endif
|
2006-01-31 07:41:16 +01:00
|
|
|
SW_SHOWDEFAULT );
|
2006-01-28 20:02:04 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
//
|
|
|
|
// FUNCTION: MyRegisterClass()
|
|
|
|
//
|
|
|
|
// PURPOSE: Registers the window class.
|
|
|
|
//
|
|
|
|
// COMMENTS:
|
|
|
|
//
|
|
|
|
// It is important to call this function so that the application
|
|
|
|
// will get 'well formed' small icons associated with it.
|
|
|
|
//
|
|
|
|
ATOM
|
|
|
|
MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
|
|
|
|
{
|
|
|
|
WNDCLASS wc;
|
|
|
|
|
2005-11-27 23:06:04 +01:00
|
|
|
XP_MEMSET( &wc, 0, sizeof(wc) );
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
wc.lpfnWndProc = (WNDPROC) WndProc;
|
|
|
|
wc.cbWndExtra = sizeof(CEAppGlobals*);
|
|
|
|
wc.hInstance = hInstance;
|
|
|
|
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_XWORDS4));
|
|
|
|
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
|
2009-09-07 20:22:52 +02:00
|
|
|
#ifndef _WIN32_WCE
|
|
|
|
wc.lpszMenuName = (LPCTSTR)IDM_MENU;
|
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
wc.lpszClassName = szWindowClass;
|
|
|
|
|
|
|
|
return RegisterClass(&wc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ceInitUtilFuncs( CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
UtilVtable* vtable = globals->util.vtable =
|
|
|
|
XP_MALLOC( globals->mpool, sizeof( UtilVtable ) );
|
|
|
|
globals->util.closure = (void*)globals;
|
|
|
|
globals->util.gameInfo = &globals->gameInfo;
|
|
|
|
|
|
|
|
MPASSIGN( globals->util.mpool, globals->mpool );
|
|
|
|
|
|
|
|
vtable->m_util_getVTManager = ce_util_getVTManager;
|
|
|
|
vtable->m_util_userError = ce_util_userError;
|
|
|
|
vtable->m_util_getSquareBonus = ce_util_getSquareBonus;
|
|
|
|
vtable->m_util_userQuery = ce_util_userQuery;
|
|
|
|
vtable->m_util_userPickTile = ce_util_userPickTile;
|
|
|
|
vtable->m_util_askPassword = ce_util_askPassword;
|
|
|
|
vtable->m_util_trayHiddenChange = ce_util_trayHiddenChange;
|
|
|
|
vtable->m_util_yOffsetChange = ce_util_yOffsetChange;
|
2008-02-26 14:49:41 +01:00
|
|
|
vtable->m_util_turnChanged = ce_util_turnChanged;
|
2003-11-20 17:26:35 +01:00
|
|
|
vtable->m_util_notifyGameOver = ce_util_notifyGameOver;
|
|
|
|
vtable->m_util_hiliteCell = ce_util_hiliteCell;
|
|
|
|
vtable->m_util_engineProgressCallback = ce_util_engineProgressCallback;
|
|
|
|
vtable->m_util_setTimer = ce_util_setTimer;
|
2009-09-21 14:49:08 +02:00
|
|
|
vtable->m_util_clearTimer = ce_util_clearTimer;
|
2008-04-08 05:55:53 +02:00
|
|
|
vtable->m_util_altKeyDown = ce_util_altKeyDown;
|
2003-11-20 17:26:35 +01:00
|
|
|
vtable->m_util_requestTime = ce_util_requestTime;
|
|
|
|
vtable->m_util_getCurSeconds = ce_util_getCurSeconds;
|
|
|
|
vtable->m_util_makeEmptyDict = ce_util_makeEmptyDict;
|
|
|
|
vtable->m_util_getUserString = ce_util_getUserString;
|
|
|
|
vtable->m_util_warnIllegalWord = ce_util_warnIllegalWord;
|
2008-10-24 11:05:13 +02:00
|
|
|
vtable->m_util_remSelected = ce_util_remSelected;
|
2006-10-10 03:34:37 +02:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2005-07-23 17:31:21 +02:00
|
|
|
vtable->m_util_addrChange = ce_util_addrChange;
|
2005-08-21 16:36:11 +02:00
|
|
|
vtable->m_util_makeStreamFromAddr = ce_util_makeStreamFromAddr;
|
2005-07-23 17:31:21 +02:00
|
|
|
#endif
|
2004-07-10 19:46:36 +02:00
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
vtable->m_util_getTraySearchLimits = ce_util_getTraySearchLimits;
|
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
#ifdef SHOW_PROGRESS
|
|
|
|
vtable->m_util_engineStarting = ce_util_engineStarting;
|
|
|
|
vtable->m_util_engineStopping = ce_util_engineStopping;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} /* ceInitUtilFuncs */
|
|
|
|
|
2005-02-05 22:43:16 +01:00
|
|
|
#ifdef CEFEATURE_CANSCROLL
|
2005-06-13 16:29:49 +02:00
|
|
|
# define SCROLL_SHRINK 1
|
2006-05-14 17:28:57 +02:00
|
|
|
|
|
|
|
static void
|
2008-08-01 12:37:52 +02:00
|
|
|
updateScrollInfo( CEAppGlobals* globals, XP_U16 nHidden )
|
2006-05-14 17:28:57 +02:00
|
|
|
{
|
|
|
|
SCROLLINFO sinfo;
|
|
|
|
|
|
|
|
XP_MEMSET( &sinfo, 0, sizeof(sinfo) );
|
|
|
|
sinfo.cbSize = sizeof(sinfo);
|
|
|
|
sinfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE;
|
2008-08-01 12:37:52 +02:00
|
|
|
sinfo.nMax = model_numRows( globals->game.model );
|
|
|
|
sinfo.nPage = sinfo.nMax - nHidden + 1;
|
2006-05-14 17:28:57 +02:00
|
|
|
|
2008-08-01 12:37:52 +02:00
|
|
|
(void)SetScrollInfo( globals->scrollHandle, SB_CTL, &sinfo, TRUE );
|
2006-05-14 17:28:57 +02:00
|
|
|
}
|
|
|
|
|
2008-09-28 19:50:04 +02:00
|
|
|
LRESULT CALLBACK
|
|
|
|
scrollWindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)GetWindowLongPtr( hWnd, GWL_USERDATA );
|
|
|
|
LRESULT result = 1;
|
|
|
|
|
|
|
|
/* XP_LOGF( "%s: event=%s (%d)", __func__, messageToStr(message), message ); */
|
|
|
|
|
|
|
|
/* Trap key events. Left and right always shift the focus off. Up and
|
|
|
|
down shift focus off IFF they're going to be no-ops on the theory that
|
|
|
|
the user needs to get some visual feedback and on some devices the
|
|
|
|
scrollbar isn't even drawn differently when focussed. */
|
|
|
|
if ( WM_KEYDOWN == message ) {
|
|
|
|
XP_Bool setFocus = XP_FALSE;
|
|
|
|
|
|
|
|
if ( (VK_RIGHT == wParam) ||
|
|
|
|
(VK_LEFT == wParam) ||
|
|
|
|
(VK_TAB == wParam) ) {
|
|
|
|
setFocus = XP_TRUE;
|
|
|
|
} else if ( (VK_UP == wParam) || (VK_DOWN == wParam) ) {
|
|
|
|
SCROLLINFO sinfo;
|
|
|
|
sinfo.cbSize = sizeof(sinfo);
|
|
|
|
sinfo.fMask = SIF_POS | SIF_RANGE | SIF_PAGE;
|
|
|
|
GetScrollInfo( globals->scrollHandle, SB_CTL, &sinfo );
|
|
|
|
|
|
|
|
if ( (VK_UP == wParam) && (sinfo.nPos <= sinfo.nMin) ) {
|
|
|
|
setFocus = XP_TRUE;
|
|
|
|
} else if ( (VK_DOWN == wParam)
|
|
|
|
&& (sinfo.nPos > (sinfo.nMax - sinfo.nPage)) ) {
|
|
|
|
setFocus = XP_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( setFocus ) {
|
|
|
|
SetFocus( globals->hWnd );
|
|
|
|
result = 0;
|
2008-10-31 05:36:44 +01:00
|
|
|
globals->keyDown = XP_TRUE;
|
2008-09-28 19:50:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( 0 != result ) {
|
|
|
|
result = CallWindowProc( globals->oldScrollProc, hWnd, message,
|
|
|
|
wParam, lParam );
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} /* scrollWindowProc */
|
|
|
|
|
2005-02-05 22:43:16 +01:00
|
|
|
static void
|
2008-09-28 19:50:04 +02:00
|
|
|
makeScrollbar( CEAppGlobals* globals, XP_U16 nHidden, XP_U16 xx, XP_U16 yy,
|
2005-06-13 16:29:49 +02:00
|
|
|
XP_U16 width, XP_U16 height )
|
2005-02-05 22:43:16 +01:00
|
|
|
{
|
2008-09-28 19:50:04 +02:00
|
|
|
HWND hwndSB;
|
2008-10-12 01:56:04 +02:00
|
|
|
#ifdef _WIN32_WCE
|
2008-10-09 14:12:25 +02:00
|
|
|
RECT tmp;
|
|
|
|
XP_U16 rectHt;
|
2008-10-12 01:56:04 +02:00
|
|
|
#endif
|
2008-10-09 14:12:25 +02:00
|
|
|
|
|
|
|
++xx;
|
|
|
|
width -= 2; /* make narrower: on CE will erase cell border */
|
|
|
|
|
2008-10-07 06:00:37 +02:00
|
|
|
#ifdef _WIN32_WCE
|
2008-10-09 14:12:25 +02:00
|
|
|
tmp.left = xx;
|
|
|
|
tmp.right = xx + width;
|
|
|
|
rectHt = height / 10; /* each focus rect to be 1/10th height */
|
2008-10-01 10:31:43 +02:00
|
|
|
|
|
|
|
tmp.top = yy;
|
|
|
|
tmp.bottom = yy + rectHt;
|
|
|
|
XP_MEMCPY( &globals->scrollRects[0], &tmp, sizeof(globals->scrollRects[0]) );
|
|
|
|
|
|
|
|
tmp.bottom = yy + height;
|
|
|
|
tmp.top = tmp.bottom - rectHt;
|
|
|
|
XP_MEMCPY( &globals->scrollRects[1], &tmp, sizeof(globals->scrollRects[1]) );
|
|
|
|
|
|
|
|
yy += rectHt;
|
2008-10-08 06:42:16 +02:00
|
|
|
height -= rectHt * 2; /* above and below */
|
2008-10-07 06:00:37 +02:00
|
|
|
#endif
|
2008-10-09 14:12:25 +02:00
|
|
|
|
2008-09-28 19:50:04 +02:00
|
|
|
/* Need to destroy it, or resize it, because board size may be changing
|
|
|
|
in case where portrait display's been flipped. */
|
2008-12-01 14:11:58 +01:00
|
|
|
removeScrollbar( globals );
|
2006-05-14 17:28:57 +02:00
|
|
|
|
2008-09-28 19:50:04 +02:00
|
|
|
hwndSB = CreateWindow( TEXT("SCROLLBAR"), // Class name
|
|
|
|
NULL, // Window text
|
|
|
|
// Window style
|
|
|
|
SBS_VERT|WS_VISIBLE|WS_CHILD,
|
2008-10-01 10:31:43 +02:00
|
|
|
xx, yy, width, height, globals->hWnd,
|
|
|
|
(HMENU)SCROLLBARID, // The control identifier
|
2008-09-28 19:50:04 +02:00
|
|
|
globals->hInst, // The instance handle
|
|
|
|
NULL ); // s'pposed to be NULL
|
2005-06-13 16:29:49 +02:00
|
|
|
|
2008-09-28 19:50:04 +02:00
|
|
|
globals->scrollHandle = hwndSB;
|
2005-02-05 22:43:16 +01:00
|
|
|
|
2008-09-28 19:50:04 +02:00
|
|
|
globals->oldScrollProc = (WNDPROC) GetWindowLongPtr( hwndSB,
|
|
|
|
GWL_WNDPROC );
|
|
|
|
XP_ASSERT( 0 == GetWindowLongPtr( hwndSB, GWL_USERDATA ) );
|
|
|
|
SetWindowLongPtr( hwndSB, GWL_WNDPROC, (LPARAM)scrollWindowProc );
|
|
|
|
SetWindowLongPtr( hwndSB, GWL_USERDATA, (LPARAM)globals );
|
2005-06-13 16:29:49 +02:00
|
|
|
|
2008-09-28 19:50:04 +02:00
|
|
|
updateScrollInfo( globals, nHidden );
|
|
|
|
EnableWindow( hwndSB, nHidden > 0 );
|
2005-06-13 16:29:49 +02:00
|
|
|
|
|
|
|
ShowWindow( globals->scrollHandle, SW_SHOW );
|
2008-09-28 19:50:04 +02:00
|
|
|
} /* makeScrollbar */
|
2005-02-05 22:43:16 +01:00
|
|
|
|
|
|
|
static void
|
2008-09-28 19:50:04 +02:00
|
|
|
removeScrollbar( CEAppGlobals* globals )
|
2005-02-05 22:43:16 +01:00
|
|
|
{
|
|
|
|
if ( !!globals->scrollHandle ) {
|
2008-09-28 19:50:04 +02:00
|
|
|
DestroyWindow( globals->scrollHandle );
|
|
|
|
globals->scrollHandle = NULL;
|
2008-12-01 14:11:58 +01:00
|
|
|
globals->scrollerHasFocus = XP_FALSE;
|
2005-02-05 22:43:16 +01:00
|
|
|
}
|
2008-09-28 19:50:04 +02:00
|
|
|
} /* removeScrollbar */
|
2005-02-05 22:43:16 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct CEBoardParms {
|
2008-09-09 14:31:02 +02:00
|
|
|
XP_U16 scrnWidth;
|
2008-10-08 06:42:16 +02:00
|
|
|
XP_U16 scrnHeight;
|
|
|
|
XP_U16 adjLeft;
|
|
|
|
XP_U16 adjTop;
|
2008-09-09 14:31:02 +02:00
|
|
|
|
2005-02-05 22:43:16 +01:00
|
|
|
XP_U16 boardHScale;
|
|
|
|
XP_U16 boardVScale;
|
2006-05-09 04:01:27 +02:00
|
|
|
XP_U16 boardTop;
|
2005-02-05 22:43:16 +01:00
|
|
|
XP_U16 trayTop;
|
2006-05-09 04:01:27 +02:00
|
|
|
|
|
|
|
XP_U16 trayHeight;
|
|
|
|
XP_U16 trayWidth;
|
|
|
|
|
|
|
|
XP_U16 timerLeft, timerTop, timerWidth, timerHeight;
|
2009-09-15 15:04:34 +02:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
|
|
|
XP_U16 netstatLeft, netstatTop, netstatWidth, netstatHeight;
|
|
|
|
#endif
|
2006-05-09 04:01:27 +02:00
|
|
|
|
|
|
|
XP_U16 boardLeft, trayLeft;
|
2005-02-05 22:43:16 +01:00
|
|
|
XP_U16 scoreWidth;
|
|
|
|
XP_U16 scoreHeight;
|
2008-09-28 19:50:04 +02:00
|
|
|
XP_U16 scrollWidth;
|
2006-05-09 04:01:27 +02:00
|
|
|
XP_Bool horiz;
|
2008-09-28 19:50:04 +02:00
|
|
|
#ifdef CEFEATURE_CANSCROLL
|
|
|
|
XP_Bool needsScroller;
|
|
|
|
#endif
|
2005-02-05 22:43:16 +01:00
|
|
|
} CEBoardParms;
|
|
|
|
|
|
|
|
static void
|
2008-10-08 06:42:16 +02:00
|
|
|
figureBoardParms( CEAppGlobals* globals, const XP_U16 nRows,
|
|
|
|
CEBoardParms* bparms )
|
2005-02-05 22:43:16 +01:00
|
|
|
{
|
|
|
|
RECT rc;
|
2006-05-09 04:01:27 +02:00
|
|
|
XP_U16 scrnWidth, scrnHeight;
|
2008-10-08 06:42:16 +02:00
|
|
|
XP_U16 trayHeight, scoreWidth, scoreHeight;
|
2008-09-28 19:50:04 +02:00
|
|
|
XP_U16 hScale, vScale, nVisibleRows;
|
2008-10-20 03:24:59 +02:00
|
|
|
XP_U16 tmp;
|
2006-05-09 04:01:27 +02:00
|
|
|
XP_Bool horiz;
|
|
|
|
XP_U16 scrollWidth = 0;
|
2008-10-08 06:42:16 +02:00
|
|
|
XP_U16 adjLeft, adjTop;
|
2005-02-05 22:43:16 +01:00
|
|
|
|
2009-09-20 22:49:37 +02:00
|
|
|
XP_MEMSET( bparms, 0, sizeof(*bparms) );
|
|
|
|
|
2005-02-05 22:43:16 +01:00
|
|
|
GetClientRect( globals->hWnd, &rc );
|
2006-05-09 04:01:27 +02:00
|
|
|
#ifndef _WIN32_WCE
|
2008-01-20 16:36:17 +01:00
|
|
|
# if defined FORCE_HEIGHT && defined FORCE_WIDTH
|
2006-05-12 09:54:59 +02:00
|
|
|
rc.right = rc.left + FORCE_WIDTH;
|
|
|
|
rc.bottom = rc.top + FORCE_HEIGHT;
|
2008-01-20 16:36:17 +01:00
|
|
|
# else
|
2008-11-10 19:49:26 +01:00
|
|
|
if ( !globals->appPrefs.fullScreen ) {
|
|
|
|
if ( globals->dbWidth != 0 ) {
|
|
|
|
rc.right = rc.left + globals->dbWidth;
|
|
|
|
}
|
|
|
|
if ( globals->dbHeight != 0 ) {
|
|
|
|
rc.bottom = rc.top + globals->dbHeight;
|
|
|
|
}
|
2006-05-09 04:01:27 +02:00
|
|
|
}
|
2008-01-20 16:36:17 +01:00
|
|
|
# endif
|
|
|
|
#endif /* #ifndef _WIN32_WCE */
|
2006-05-09 04:01:27 +02:00
|
|
|
|
|
|
|
scrnWidth = (XP_U16)(rc.right - rc.left);
|
|
|
|
scrnHeight = (XP_U16)(rc.bottom - rc.top);
|
2008-10-08 06:42:16 +02:00
|
|
|
|
2008-09-28 19:50:04 +02:00
|
|
|
XP_LOGF( "%s: scrnWidth: %d, scrnHeight: %d", __func__,
|
|
|
|
scrnWidth, scrnHeight );
|
2006-05-09 04:01:27 +02:00
|
|
|
|
2008-10-08 06:42:16 +02:00
|
|
|
/* Figure layout style based on proportion UNLESS there's just no room
|
|
|
|
for anything but 15 columns on the board -- because vertically is the
|
|
|
|
only dimension in which we can scroll. */
|
|
|
|
if ( scrnWidth <= (MIN_CELL_WIDTH * (nRows+2)) ) {
|
|
|
|
horiz = XP_TRUE;
|
|
|
|
} else {
|
|
|
|
horiz = scrnHeight >= scrnWidth;
|
|
|
|
}
|
2005-02-05 22:43:16 +01:00
|
|
|
|
2008-10-26 16:01:05 +01:00
|
|
|
/* vScale. Tray must be a few pixels taller than cells to use same
|
|
|
|
sized, minimum-sized font. Subtract out that difference here and it's
|
|
|
|
guaranteed that tray will wind up at least that much taller later
|
|
|
|
though for the rest of the calculation we reserve only a cell's height
|
|
|
|
for it. */
|
|
|
|
vScale = (scrnHeight - (MIN_TRAY_HEIGHT-MIN_CELL_HEIGHT))
|
|
|
|
/ (nRows + (horiz?2:1)); /* horiz means scoreboard *and* tray */
|
2008-10-20 03:24:59 +02:00
|
|
|
if ( vScale >= MIN_CELL_HEIGHT ) {
|
2008-10-26 16:01:05 +01:00
|
|
|
nVisibleRows = nRows; /* no scrolling needed */
|
2008-10-20 03:24:59 +02:00
|
|
|
} else {
|
|
|
|
XP_U16 nRowsPossible = (scrnHeight-MIN_TRAY_HEIGHT) / MIN_CELL_HEIGHT;
|
2008-10-26 16:01:05 +01:00
|
|
|
XP_S16 num2Scroll;
|
|
|
|
num2Scroll = (nRows + (horiz?1:0)) - nRowsPossible; /* 1: scoreboard */
|
|
|
|
XP_ASSERT( num2Scroll > 0 );
|
|
|
|
if ( num2Scroll < 0 ) { /* no-scroll case should be caught above */
|
2008-10-20 03:24:59 +02:00
|
|
|
num2Scroll = 0;
|
|
|
|
}
|
|
|
|
nVisibleRows = nRows - num2Scroll;
|
|
|
|
vScale = (scrnHeight-MIN_TRAY_HEIGHT) / (nVisibleRows + (horiz? 1:0));
|
2008-09-28 19:50:04 +02:00
|
|
|
}
|
|
|
|
|
2008-10-08 06:42:16 +02:00
|
|
|
tmp = nRows + (horiz ? 0 : 2);
|
|
|
|
hScale = scrnWidth / tmp;
|
2006-05-09 04:01:27 +02:00
|
|
|
|
2008-10-08 06:42:16 +02:00
|
|
|
if ( vScale > hScale ) {
|
|
|
|
vScale = XP_MAX( MIN_CELL_HEIGHT, hScale );
|
|
|
|
} else if ( hScale > vScale ) {
|
|
|
|
hScale = XP_MAX( MIN_CELL_WIDTH, vScale );
|
2008-09-28 19:50:04 +02:00
|
|
|
}
|
|
|
|
|
2008-10-08 06:42:16 +02:00
|
|
|
/* Figure out tray size */
|
2008-10-20 03:24:59 +02:00
|
|
|
tmp = vScale * (nVisibleRows + (horiz? 1:0));
|
2008-10-08 06:42:16 +02:00
|
|
|
trayHeight = XP_MIN( vScale * 2, scrnHeight - tmp );
|
2008-09-28 19:50:04 +02:00
|
|
|
|
|
|
|
#ifdef CEFEATURE_CANSCROLL
|
2008-10-08 06:42:16 +02:00
|
|
|
/* Does this need to be in a loop? */
|
|
|
|
while ( nVisibleRows < nRows && hScale > MIN_CELL_WIDTH ) { /* need scroller? (while allows break) */
|
|
|
|
scrollWidth = scrnWidth - (tmp * hScale);
|
|
|
|
if ( scrollWidth >= MIN_SCROLLBAR_WIDTH ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
--hScale;
|
|
|
|
}
|
|
|
|
if ( scrollWidth > MAX_SCROLLBAR_WIDTH ) {
|
|
|
|
scrollWidth = MAX_SCROLLBAR_WIDTH;
|
2008-09-28 19:50:04 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( horiz ) {
|
2008-10-08 06:42:16 +02:00
|
|
|
scoreWidth = scrollWidth + (hScale * nRows);
|
|
|
|
scoreHeight = vScale - SCORE_TWEAK;
|
|
|
|
trayHeight += SCORE_TWEAK;
|
2006-05-09 04:01:27 +02:00
|
|
|
} else {
|
2008-10-08 06:42:16 +02:00
|
|
|
scoreWidth = XP_MIN( 2*hScale, scrnWidth - (hScale * nRows) );
|
|
|
|
scoreHeight = (nVisibleRows * vScale) + trayHeight;
|
2005-02-05 22:43:16 +01:00
|
|
|
}
|
2008-10-20 03:24:59 +02:00
|
|
|
/* XP_LOGF( "hScale=%d; vScale=%d; trayHeight=%d", hScale, vScale, trayHeight ); */
|
2005-02-05 22:43:16 +01:00
|
|
|
|
2009-09-15 15:04:34 +02:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
|
|
|
if ( !!globals->game.comms ) {
|
|
|
|
/* If we're horizontal, steal from the right of the scoreboard. If
|
|
|
|
vertical, from the bottom. */
|
|
|
|
if ( horiz ) {
|
|
|
|
bparms->netstatWidth = hScale;
|
|
|
|
scoreWidth -= bparms->netstatWidth;
|
|
|
|
bparms->netstatLeft = scoreWidth;
|
|
|
|
bparms->netstatTop = 0;
|
|
|
|
bparms->netstatHeight = scoreHeight;
|
|
|
|
} else {
|
|
|
|
bparms->netstatLeft = 0;
|
|
|
|
bparms->netstatHeight = vScale;
|
|
|
|
scoreHeight -= bparms->netstatHeight;
|
|
|
|
bparms->netstatTop = scoreHeight;
|
|
|
|
bparms->netstatWidth = scoreWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-02-05 22:43:16 +01:00
|
|
|
if ( globals->gameInfo.timerEnabled ) {
|
2006-05-09 04:01:27 +02:00
|
|
|
if ( horiz ) {
|
2008-09-28 19:50:04 +02:00
|
|
|
bparms->timerWidth = scoreWidth / 6; /* arbitrarily, one sixth */
|
|
|
|
scoreWidth -= bparms->timerWidth;
|
2006-05-09 04:01:27 +02:00
|
|
|
bparms->timerLeft = scoreWidth;
|
|
|
|
bparms->timerTop = 0;
|
2008-09-28 19:50:04 +02:00
|
|
|
bparms->timerHeight = scoreHeight;
|
2006-05-09 04:01:27 +02:00
|
|
|
} else {
|
|
|
|
bparms->timerLeft = 0;
|
2008-09-28 19:50:04 +02:00
|
|
|
bparms->timerHeight = vScale * 2;
|
2008-11-13 06:46:21 +01:00
|
|
|
bparms->timerTop = scoreHeight - bparms->timerHeight;
|
2006-05-09 04:01:27 +02:00
|
|
|
bparms->timerWidth = scoreWidth;
|
|
|
|
|
|
|
|
scoreHeight -= bparms->timerHeight;
|
|
|
|
}
|
2005-02-05 22:43:16 +01:00
|
|
|
}
|
2006-05-09 04:01:27 +02:00
|
|
|
|
2008-10-08 06:42:16 +02:00
|
|
|
globals->cellHt = vScale;
|
|
|
|
|
|
|
|
/* figure actual width and height */
|
|
|
|
tmp = scrollWidth + (hScale * nRows) + (horiz ? 0 : scoreWidth);
|
|
|
|
adjLeft = (scrnWidth - tmp)/2;
|
|
|
|
tmp = trayHeight + (vScale * nVisibleRows) + (horiz?scoreHeight:0);
|
|
|
|
adjTop = (scrnHeight - tmp)/2;
|
|
|
|
|
2008-09-09 14:31:02 +02:00
|
|
|
bparms->scrnWidth = scrnWidth;
|
2008-10-08 06:42:16 +02:00
|
|
|
bparms->scrnHeight = scrnHeight;
|
|
|
|
bparms->adjLeft = adjLeft;
|
|
|
|
bparms->adjTop = adjTop;
|
2005-02-05 22:43:16 +01:00
|
|
|
bparms->boardHScale = hScale;
|
|
|
|
bparms->boardVScale = vScale;
|
2008-10-08 06:42:16 +02:00
|
|
|
bparms->boardTop = adjTop + (horiz? scoreHeight : 0);
|
2008-10-20 03:24:59 +02:00
|
|
|
bparms->trayTop = bparms->boardTop + (nVisibleRows * vScale) + 1;
|
|
|
|
bparms->trayHeight = trayHeight - 1;
|
2008-10-08 06:42:16 +02:00
|
|
|
bparms->trayWidth = (hScale * nRows) + scrollWidth;
|
|
|
|
bparms->boardLeft = adjLeft + (horiz ? 0 : scoreWidth);
|
|
|
|
bparms->trayLeft = bparms->boardLeft;//horiz? 0 : scoreWidth;
|
2005-02-05 22:43:16 +01:00
|
|
|
bparms->scoreWidth = scoreWidth;
|
2006-05-09 04:01:27 +02:00
|
|
|
bparms->scoreHeight = scoreHeight;
|
2008-09-28 19:50:04 +02:00
|
|
|
bparms->scrollWidth = scrollWidth;
|
2006-05-09 04:01:27 +02:00
|
|
|
bparms->horiz = horiz;
|
2008-09-28 19:50:04 +02:00
|
|
|
|
2005-02-05 22:43:16 +01:00
|
|
|
#ifdef CEFEATURE_CANSCROLL
|
2008-10-08 06:42:16 +02:00
|
|
|
bparms->needsScroller = scrollWidth > 0;
|
2008-09-28 19:50:04 +02:00
|
|
|
if ( bparms->needsScroller ) {
|
|
|
|
XP_U16 boardRight;
|
|
|
|
boardRight = bparms->boardLeft + (nRows * hScale);
|
|
|
|
makeScrollbar( globals, nRows - nVisibleRows,
|
|
|
|
boardRight, bparms->boardTop,
|
|
|
|
scrollWidth,
|
|
|
|
vScale * nVisibleRows );
|
2005-02-05 22:43:16 +01:00
|
|
|
} else {
|
2008-09-28 19:50:04 +02:00
|
|
|
removeScrollbar( globals );
|
2005-02-05 22:43:16 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} /* figureBoardParms */
|
|
|
|
|
2008-09-09 14:31:02 +02:00
|
|
|
static void
|
|
|
|
setOwnedRects( CEAppGlobals* globals, XP_U16 nRows,
|
|
|
|
const CEBoardParms* bparms )
|
|
|
|
{
|
2008-10-08 06:42:16 +02:00
|
|
|
RECT tmp;
|
|
|
|
XP_U16 scrollWidth = bparms->scrollWidth;
|
|
|
|
|
|
|
|
XP_MEMSET( &globals->ownedRects, 0, sizeof(globals->ownedRects) );
|
|
|
|
|
|
|
|
tmp.top = bparms->adjTop; /* Same for both */
|
|
|
|
tmp.bottom = bparms->trayTop + bparms->trayHeight; /* Same for both */
|
|
|
|
|
|
|
|
tmp.left = 0;
|
|
|
|
tmp.right = bparms->adjLeft;
|
|
|
|
XP_MEMCPY( &globals->ownedRects[OWNED_RECT_LEFT], &tmp,
|
|
|
|
sizeof(globals->ownedRects[OWNED_RECT_LEFT]) );
|
|
|
|
|
|
|
|
tmp.left = tmp.right + (bparms->boardHScale * nRows) + scrollWidth;
|
|
|
|
tmp.right = bparms->scrnWidth;
|
|
|
|
XP_MEMCPY( &globals->ownedRects[OWNED_RECT_RIGHT], &tmp,
|
|
|
|
sizeof(globals->ownedRects[OWNED_RECT_RIGHT]) );
|
|
|
|
|
|
|
|
tmp.left = 0;
|
|
|
|
tmp.top = 0;
|
|
|
|
tmp.right = bparms->scrnWidth;
|
|
|
|
tmp.bottom = bparms->adjTop;
|
|
|
|
XP_MEMCPY( &globals->ownedRects[OWNED_RECT_TOP], &tmp,
|
|
|
|
sizeof(globals->ownedRects[OWNED_RECT_TOP]) );
|
|
|
|
|
|
|
|
tmp.top = bparms->trayTop + bparms->trayHeight;
|
|
|
|
tmp.bottom = bparms->scrnHeight;
|
|
|
|
XP_MEMCPY( &globals->ownedRects[OWNED_RECT_BOTTOM], &tmp,
|
|
|
|
sizeof(globals->ownedRects[OWNED_RECT_BOTTOM]) );
|
2008-09-09 14:31:02 +02:00
|
|
|
} /* setOwnedRects */
|
|
|
|
|
2008-09-28 19:50:04 +02:00
|
|
|
|
|
|
|
/* PENDING cePositionBoard gets called a lot when the screen size hasn't
|
|
|
|
changed. It'd be better to cache the size used to do layout and not
|
|
|
|
repeat those steps (including possibly nuking and rebuilding a
|
|
|
|
scrollbar). */
|
2003-11-20 17:26:35 +01:00
|
|
|
static XP_Bool
|
|
|
|
cePositionBoard( CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
XP_Bool erase = XP_FALSE;
|
2005-02-05 22:43:16 +01:00
|
|
|
XP_U16 nCols;
|
|
|
|
CEBoardParms bparms;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
XP_ASSERT( !!globals->game.model );
|
|
|
|
nCols = model_numCols( globals->game.model );
|
|
|
|
XP_ASSERT( nCols <= CE_MAX_ROWS );
|
|
|
|
|
2005-02-05 22:43:16 +01:00
|
|
|
figureBoardParms( globals, nCols, &bparms );
|
2008-09-09 14:31:02 +02:00
|
|
|
setOwnedRects( globals, nCols, &bparms );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2009-09-24 06:26:28 +02:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2009-09-15 15:04:34 +02:00
|
|
|
if ( !!globals->game.comms ) {
|
|
|
|
globals->relayStatusR.left = bparms.adjLeft + bparms.netstatLeft;
|
|
|
|
globals->relayStatusR.top = bparms.adjTop + bparms.netstatTop;
|
|
|
|
globals->relayStatusR.right = globals->relayStatusR.left
|
|
|
|
+ bparms.netstatWidth;
|
|
|
|
globals->relayStatusR.bottom = globals->relayStatusR.top
|
|
|
|
+ bparms.netstatHeight;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-05-09 04:01:27 +02:00
|
|
|
if ( globals->gameInfo.timerEnabled ) {
|
2008-11-13 06:46:21 +01:00
|
|
|
board_setTimerLoc( globals->game.board,
|
|
|
|
bparms.adjLeft + bparms.timerLeft,
|
|
|
|
bparms.adjTop + bparms.timerTop, bparms.timerWidth,
|
2006-05-09 04:01:27 +02:00
|
|
|
bparms.timerHeight );
|
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2006-05-09 04:01:27 +02:00
|
|
|
board_setPos( globals->game.board, bparms.boardLeft,
|
|
|
|
bparms.boardTop, XP_FALSE );
|
2006-05-11 05:01:39 +02:00
|
|
|
board_setScale( globals->game.board, bparms.boardHScale,
|
|
|
|
bparms.boardVScale );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-10-08 06:42:16 +02:00
|
|
|
board_setScoreboardLoc( globals->game.board, bparms.adjLeft, bparms.adjTop,
|
|
|
|
bparms.scoreWidth,
|
2006-05-09 04:01:27 +02:00
|
|
|
bparms.scoreHeight, bparms.horiz );
|
2003-11-20 17:26:35 +01:00
|
|
|
board_setShowColors( globals->game.board, globals->appPrefs.showColors );
|
2005-01-23 09:15:29 +01:00
|
|
|
board_setYOffset( globals->game.board, 0 );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
board_prefsChanged( globals->game.board, &globals->appPrefs.cp );
|
|
|
|
|
2006-05-09 04:01:27 +02:00
|
|
|
board_setTrayLoc( globals->game.board, bparms.trayLeft, bparms.trayTop,
|
2008-09-28 19:50:04 +02:00
|
|
|
bparms.trayWidth, bparms.trayHeight,
|
|
|
|
bparms.trayWidth/40 ); /* 1/8 of a tile width, roughly */
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
server_prefsChanged( globals->game.server, &globals->appPrefs.cp );
|
|
|
|
|
2008-09-28 19:50:04 +02:00
|
|
|
#if ! defined _WIN32_WCE && defined DEBUG
|
|
|
|
ceSetTitleFromName( globals );
|
|
|
|
#endif
|
2008-11-10 19:49:26 +01:00
|
|
|
ceCheckMenus( globals );
|
2003-11-20 17:26:35 +01:00
|
|
|
return erase;
|
|
|
|
} /* cePositionBoard */
|
|
|
|
|
2008-12-13 08:29:47 +01:00
|
|
|
/* Set the title. If there's a game name, replace the window title with that
|
|
|
|
* in case both won't fit. If there's no name yet, install the app name as
|
|
|
|
* title.
|
2003-11-20 17:26:35 +01:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ceSetTitleFromName( CEAppGlobals* globals )
|
|
|
|
{
|
2008-12-13 08:29:47 +01:00
|
|
|
wchar_t widebuf[64];
|
2008-04-13 19:01:09 +02:00
|
|
|
const XP_UCHAR* gameName = globals->curGameName;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-04-13 19:01:09 +02:00
|
|
|
/* if default name, remove any current name */
|
2008-10-25 20:08:36 +02:00
|
|
|
if ( !gameName || isDefaultName( globals, gameName ) ) {
|
2009-04-11 17:45:59 +02:00
|
|
|
LoadString( globals->locInst, IDS_APP_TITLE, widebuf, VSIZE(widebuf) );
|
2008-04-13 19:01:09 +02:00
|
|
|
} else {
|
2008-12-13 08:29:47 +01:00
|
|
|
wchar_t* dotPos;
|
|
|
|
XP_UCHAR* baseStart = 1 + strrchr( gameName, '\\' );
|
|
|
|
XP_U16 len = (XP_U16)XP_STRLEN( baseStart );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-04-13 19:01:09 +02:00
|
|
|
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, baseStart, len + 1,
|
2008-12-13 08:29:47 +01:00
|
|
|
widebuf, len + 1 );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-04-13 19:01:09 +02:00
|
|
|
/* now get rid of the ".xwg" */
|
2008-12-13 08:29:47 +01:00
|
|
|
dotPos = wcsrchr( widebuf, '.' );
|
|
|
|
if ( dotPos != NULL ) {
|
|
|
|
*dotPos = 0;
|
2008-04-13 19:01:09 +02:00
|
|
|
}
|
2008-09-29 07:07:35 +02:00
|
|
|
}
|
2008-09-28 19:50:04 +02:00
|
|
|
|
|
|
|
#if ! defined _WIN32_WCE && defined DEBUG
|
2008-09-29 07:07:35 +02:00
|
|
|
swprintf( &widebuf[wcslen(widebuf)], L":%dx%d",
|
|
|
|
globals->dbWidth, globals->dbHeight );
|
2008-09-28 19:50:04 +02:00
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
SendMessage( globals->hWnd, WM_SETTEXT, 0, (long)widebuf );
|
|
|
|
} /* ceSetTitleFromName */
|
|
|
|
|
2009-09-13 01:31:48 +02:00
|
|
|
static void
|
|
|
|
ceInitTProcs( CEAppGlobals* globals, TransportProcs* procs )
|
|
|
|
{
|
|
|
|
XP_MEMSET( procs, 0, sizeof(*procs) );
|
|
|
|
procs->send = ce_send_proc;
|
|
|
|
#ifdef COMMS_HEARTBEAT
|
|
|
|
procs->reset = ce_reset_proc;
|
|
|
|
#endif
|
2009-11-22 18:58:59 +01:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2009-09-15 15:04:34 +02:00
|
|
|
procs->rstatus = ce_relay_status;
|
2009-12-14 05:12:20 +01:00
|
|
|
procs->rconnd = ce_relay_connd;
|
2009-12-04 10:09:07 +01:00
|
|
|
procs->rerror = ce_relay_error;
|
2009-11-22 18:58:59 +01:00
|
|
|
#endif
|
2009-09-13 01:31:48 +02:00
|
|
|
procs->closure = globals;
|
|
|
|
}
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static void
|
2008-02-16 17:02:49 +01:00
|
|
|
ceInitAndStartBoard( CEAppGlobals* globals, XP_Bool newGame,
|
|
|
|
const CommsAddrRec* XP_UNUSED_STANDALONE(addr) )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
DictionaryCtxt* dict;
|
2008-09-09 14:31:02 +02:00
|
|
|
DictionaryCtxt* toBeDestroyed = NULL;
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_UCHAR* newDictName = globals->gameInfo.dictName;
|
|
|
|
|
|
|
|
/* This needs to happen even when !newGame because it's how the dict
|
|
|
|
slots in PlayerInfo get loaded. That really ought to happen earlier,
|
|
|
|
though. */
|
|
|
|
XP_ASSERT( !!globals->game.model );
|
|
|
|
dict = model_getDictionary( globals->game.model );
|
|
|
|
|
|
|
|
if ( !!dict ) {
|
2006-10-22 21:44:30 +02:00
|
|
|
const XP_UCHAR* curDictName = dict_getName( dict );
|
2003-11-20 17:26:35 +01:00
|
|
|
if ( !!newDictName &&
|
|
|
|
( !curDictName || 0 != strcmp( curDictName, newDictName ) ) ) {
|
2008-09-09 14:31:02 +02:00
|
|
|
toBeDestroyed = dict;
|
2003-11-20 17:26:35 +01:00
|
|
|
dict = NULL;
|
|
|
|
} else {
|
2006-09-15 09:39:57 +02:00
|
|
|
replaceStringIfDifferent( globals->mpool,
|
|
|
|
&globals->gameInfo.dictName,
|
2003-11-20 17:26:35 +01:00
|
|
|
curDictName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !dict ) {
|
|
|
|
#ifdef STUBBED_DICT
|
|
|
|
dict = make_stubbed_dict( MPPARM_NOCOMMA(globals->mpool) );
|
|
|
|
#else
|
2004-01-17 23:10:23 +01:00
|
|
|
XP_ASSERT( !!newDictName );
|
2006-05-30 07:12:02 +02:00
|
|
|
XP_LOGF( "calling ce_dictionary_make" );
|
2006-04-25 06:25:08 +02:00
|
|
|
dict = ce_dictionary_make( globals, newDictName);
|
2003-11-20 17:26:35 +01:00
|
|
|
#endif
|
|
|
|
XP_ASSERT( !!dict );
|
|
|
|
model_setDictionary( globals->game.model, dict );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( newGame ) {
|
2009-09-13 01:31:48 +02:00
|
|
|
TransportProcs procs;
|
|
|
|
ceInitTProcs( globals, &procs );
|
2005-06-13 16:29:49 +02:00
|
|
|
game_reset( MEMPOOL &globals->game, &globals->gameInfo, &globals->util,
|
2009-09-13 01:31:48 +02:00
|
|
|
0, &globals->appPrefs.cp, &procs );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2006-10-28 16:56:04 +02:00
|
|
|
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
2009-10-24 17:12:45 +02:00
|
|
|
if ( !!addr && !!globals->game.comms ) {
|
2005-07-23 17:31:21 +02:00
|
|
|
comms_setAddr( globals->game.comms, addr );
|
|
|
|
}
|
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
XP_ASSERT( !!globals->game.board );
|
2008-03-15 16:39:58 +01:00
|
|
|
ceSizeIfFullscreen( globals, globals->hWnd );
|
2003-11-20 17:26:35 +01:00
|
|
|
(void)cePositionBoard( globals );
|
|
|
|
|
|
|
|
board_invalAll( globals->game.board );
|
|
|
|
InvalidateRect( globals->hWnd, NULL, TRUE /* erase */ );
|
|
|
|
|
2009-02-01 17:43:01 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2009-01-31 19:06:09 +01:00
|
|
|
if ( !!globals->game.comms ) {
|
|
|
|
comms_start( globals->game.comms );
|
2005-08-21 16:36:11 +02:00
|
|
|
}
|
2009-02-01 17:43:01 +01:00
|
|
|
if ( newGame && globals->gameInfo.serverRole == SERVER_ISCLIENT ) {
|
|
|
|
XWStreamCtxt* stream;
|
|
|
|
XP_ASSERT( !!globals->game.comms );
|
|
|
|
stream = make_generic_stream( globals );
|
|
|
|
stream_setOnCloseProc( stream, ce_send_on_close );
|
|
|
|
server_initClientConnection( globals->game.server, stream );
|
|
|
|
}
|
|
|
|
#endif
|
2005-08-21 16:36:11 +02:00
|
|
|
|
2008-03-10 02:47:46 +01:00
|
|
|
ceSetLeftSoftkey( globals, ID_MOVE_TURNDONE );
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
server_do( globals->game.server );
|
|
|
|
|
|
|
|
globals->isNewGame = FALSE;
|
2008-09-09 14:31:02 +02:00
|
|
|
|
|
|
|
if ( !!toBeDestroyed ) {
|
|
|
|
dict_destroy( toBeDestroyed );
|
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ceInitAndStartBoard */
|
|
|
|
|
2009-04-14 05:33:46 +02:00
|
|
|
static XP_UCHAR*
|
2009-09-20 22:49:37 +02:00
|
|
|
ceReadString( const CEAppGlobals* XP_UNUSED_DBG(globals), HANDLE fileH )
|
2009-04-14 05:33:46 +02:00
|
|
|
{
|
|
|
|
XP_U16 nameLen;
|
|
|
|
XP_UCHAR* name = NULL;
|
|
|
|
XP_U32 nRead;
|
|
|
|
|
|
|
|
if ( ReadFile( fileH, &nameLen, sizeof(nameLen), &nRead, NULL )
|
|
|
|
&& nameLen > 0 ) {
|
|
|
|
name = XP_MALLOC( globals->mpool, nameLen + 1 );
|
|
|
|
ReadFile( fileH, name, nameLen, &nRead, NULL );
|
|
|
|
name[nameLen] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
} /* ceReadString */
|
|
|
|
|
|
|
|
static void
|
|
|
|
ceWriteString( const XP_UCHAR* str, HANDLE fileH )
|
|
|
|
{
|
|
|
|
XP_U32 nWritten;
|
|
|
|
XP_U16 len = !!str? XP_STRLEN( str ) : 0;
|
|
|
|
WriteFile( fileH, &len, sizeof(len), &nWritten, NULL );
|
|
|
|
if ( 0 < len ) {
|
|
|
|
WriteFile( fileH, str, len, &nWritten, NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static void
|
|
|
|
ceSavePrefs( CEAppGlobals* globals )
|
|
|
|
{
|
2004-01-30 06:48:24 +01:00
|
|
|
HANDLE fileH;
|
2008-10-25 20:08:36 +02:00
|
|
|
wchar_t path[CE_MAX_PATH_LEN];
|
2004-01-30 06:48:24 +01:00
|
|
|
|
2008-10-25 20:08:36 +02:00
|
|
|
(void)ceGetPath( globals, PREFS_FILE_PATH_L, path, VSIZE(path) );
|
|
|
|
fileH = CreateFile( path, GENERIC_WRITE, 0, NULL,
|
2004-01-30 06:48:24 +01:00
|
|
|
OPEN_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL );
|
2003-11-20 17:26:35 +01:00
|
|
|
if ( fileH != INVALID_HANDLE_VALUE ) {
|
|
|
|
XP_U32 nWritten;
|
|
|
|
|
|
|
|
SetFilePointer( fileH, 0, 0, FILE_BEGIN );
|
|
|
|
/* write prefs, including version num */
|
|
|
|
WriteFile( fileH, &globals->appPrefs, sizeof(globals->appPrefs),
|
|
|
|
&nWritten, NULL );
|
|
|
|
|
2009-04-14 05:33:46 +02:00
|
|
|
ceWriteString( globals->curGameName, fileH );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2006-05-05 14:51:08 +02:00
|
|
|
WriteFile( fileH, &globals->flags, sizeof(globals->flags), &nWritten,
|
|
|
|
NULL );
|
|
|
|
|
2009-04-14 05:33:46 +02:00
|
|
|
ceWriteString( globals->langFileName, fileH );
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
SetEndOfFile( fileH ); /* truncate anything previously there */
|
|
|
|
|
2006-02-06 05:41:14 +01:00
|
|
|
CloseHandle( fileH ); /* am I not supposed to do this? PENDING */
|
2009-09-07 20:22:52 +02:00
|
|
|
XP_LOGW( "prefs file written", path );
|
2004-01-30 06:48:24 +01:00
|
|
|
} else {
|
2005-06-13 16:29:49 +02:00
|
|
|
logLastError( "failed to create prefs file" );
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
} /* ceSavePrefs */
|
|
|
|
|
2008-02-23 23:06:05 +01:00
|
|
|
static XP_Bool
|
|
|
|
peekVersion( HANDLE fileH, XP_U16* version )
|
|
|
|
{
|
|
|
|
XP_Bool success = XP_FALSE;
|
|
|
|
XP_U32 nRead;
|
|
|
|
success = ReadFile( fileH, version, sizeof(*version), &nRead, NULL );
|
|
|
|
if ( success ) {
|
|
|
|
SetFilePointer( fileH, -nRead, 0, FILE_CURRENT );
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
} /* peekVersion */
|
|
|
|
|
|
|
|
static XP_Bool
|
|
|
|
canUpdatePrefs( CEAppGlobals* globals, HANDLE fileH, XP_U16 curVersion,
|
|
|
|
CEAppPrefs* prefs )
|
|
|
|
{
|
|
|
|
XP_Bool success = XP_FALSE;
|
|
|
|
LOG_FUNC();
|
|
|
|
if ( (curVersion == 0x0002) && (CUR_CE_PREFS_FLAGS == 0x0003) ) {
|
|
|
|
CEAppPrefs0002 oldPrefs;
|
|
|
|
XP_U32 nRead;
|
|
|
|
if ( ReadFile( fileH, &oldPrefs, sizeof(oldPrefs), &nRead, NULL ) ) {
|
|
|
|
ceInitPrefs( globals, prefs );
|
|
|
|
|
|
|
|
XP_MEMCPY( &prefs->cp, &oldPrefs.cp, sizeof(prefs->cp) );
|
|
|
|
prefs->showColors = oldPrefs.showColors;
|
|
|
|
|
|
|
|
XP_MEMCPY( &prefs->colors[0], &oldPrefs.colors[0],
|
|
|
|
CE_FOCUS_COLOR*sizeof(prefs->colors[0]));
|
2008-12-02 14:47:18 +01:00
|
|
|
XP_ASSERT( CE_PLAYER0_COLOR - 1 == CE_FOCUS_COLOR );
|
|
|
|
XP_MEMCPY( &prefs->colors[CE_PLAYER0_COLOR],
|
2008-02-23 23:06:05 +01:00
|
|
|
&oldPrefs.colors[CE_FOCUS_COLOR],
|
2008-12-02 14:47:18 +01:00
|
|
|
(CE_NUM_COLORS-CE_PLAYER0_COLOR)
|
2008-02-23 23:06:05 +01:00
|
|
|
* sizeof(prefs->colors[0]));
|
|
|
|
success = XP_TRUE;
|
|
|
|
} else {
|
|
|
|
XP_LOGF( "%s: ReadFile bad", __func__ );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
XP_LOGF( "%s: can't convert from %d to %d", __func__,
|
|
|
|
curVersion, CUR_CE_PREFS_FLAGS );
|
|
|
|
}
|
|
|
|
LOG_RETURNF( "%d", (int)success );
|
|
|
|
return success;
|
|
|
|
} /* canUpdatePrefs */
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static XP_Bool
|
|
|
|
ceLoadPrefs( CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
XP_Bool result = XP_FALSE;
|
2004-01-30 06:48:24 +01:00
|
|
|
HANDLE fileH;
|
2008-10-25 20:08:36 +02:00
|
|
|
wchar_t path[CE_MAX_PATH_LEN];
|
2004-01-30 06:48:24 +01:00
|
|
|
|
2008-10-25 20:08:36 +02:00
|
|
|
(void)ceGetPath( globals, PREFS_FILE_PATH_L, path, VSIZE(path) );
|
|
|
|
fileH = CreateFile( path, GENERIC_READ, 0, NULL,
|
2009-09-07 20:22:52 +02:00
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_HIDDEN, NULL );
|
2003-11-20 17:26:35 +01:00
|
|
|
if ( fileH != INVALID_HANDLE_VALUE ) {
|
|
|
|
XP_U32 fileSize = GetFileSize( fileH, NULL );
|
2008-02-23 23:06:05 +01:00
|
|
|
XP_U16 curVersion;
|
2008-09-28 19:50:04 +02:00
|
|
|
if ( fileSize >= sizeof(curVersion) && peekVersion( fileH,
|
|
|
|
&curVersion ) ) {
|
2009-12-27 03:54:30 +01:00
|
|
|
CEAppPrefs tmpPrefs = {0};
|
2008-02-23 23:06:05 +01:00
|
|
|
if ( curVersion == CUR_CE_PREFS_FLAGS ) {
|
|
|
|
if ( fileSize >= sizeof( CEAppPrefs ) ) {
|
|
|
|
XP_U32 bytesRead;
|
|
|
|
if ( ReadFile( fileH, &tmpPrefs, sizeof(tmpPrefs),
|
|
|
|
&bytesRead, NULL ) ) {
|
2008-03-24 13:41:12 +01:00
|
|
|
XP_ASSERT( tmpPrefs.versionFlags == CUR_CE_PREFS_FLAGS );
|
|
|
|
result = XP_TRUE;
|
2008-02-23 23:06:05 +01:00
|
|
|
}
|
|
|
|
}
|
2008-03-24 13:41:12 +01:00
|
|
|
} else if ( canUpdatePrefs( globals, fileH, curVersion,
|
|
|
|
&tmpPrefs ) ) {
|
2008-02-23 23:06:05 +01:00
|
|
|
result = XP_TRUE;
|
|
|
|
} else {
|
|
|
|
XP_LOGF( "%s: old prefs; cannot read.", __func__ );
|
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-02-23 23:06:05 +01:00
|
|
|
if ( result ) {
|
|
|
|
XP_U16 flags;
|
|
|
|
XP_U32 nRead;
|
|
|
|
|
|
|
|
XP_MEMCPY( &globals->appPrefs, &tmpPrefs,
|
2003-11-20 17:26:35 +01:00
|
|
|
sizeof(globals->appPrefs) );
|
2006-05-05 14:51:08 +02:00
|
|
|
|
2009-04-14 05:33:46 +02:00
|
|
|
globals->curGameName = ceReadString( globals, fileH );
|
2008-02-23 23:06:05 +01:00
|
|
|
|
|
|
|
if ( ReadFile( fileH, &flags, sizeof(flags), &nRead,
|
|
|
|
NULL )
|
|
|
|
&& nRead == sizeof(flags) ) {
|
|
|
|
} else {
|
|
|
|
flags = 0;
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
2008-02-23 23:06:05 +01:00
|
|
|
globals->flags = flags;
|
2009-04-14 05:33:46 +02:00
|
|
|
|
|
|
|
globals->langFileName = ceReadString( globals, fileH );
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CloseHandle( fileH );
|
2004-01-30 06:48:24 +01:00
|
|
|
} else {
|
|
|
|
XP_LOGF( "ceLoadPrefs: prefs file not found" );
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
return result; /* none found */
|
|
|
|
} /* ceLoadPrefs */
|
|
|
|
|
2004-11-09 03:40:36 +01:00
|
|
|
static XWStreamCtxt*
|
2008-09-28 18:48:30 +02:00
|
|
|
make_generic_stream( const CEAppGlobals* globals )
|
2004-11-09 03:40:36 +01:00
|
|
|
{
|
|
|
|
return mem_stream_make( MPPARM(globals->mpool) globals->vtMgr,
|
2008-09-28 18:48:30 +02:00
|
|
|
(void*)globals, 0, NULL );
|
2004-11-09 03:40:36 +01:00
|
|
|
} /* make_generic_stream */
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static XWStreamCtxt*
|
2008-09-28 18:48:30 +02:00
|
|
|
fileToStream( const CEAppGlobals* globals, const XP_UCHAR* path )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
XWStreamCtxt* stream = NULL;
|
|
|
|
HANDLE fileH;
|
|
|
|
wchar_t widebuf[257];
|
|
|
|
XP_U16 len;
|
|
|
|
|
|
|
|
len = (XP_U16)XP_STRLEN( path );
|
|
|
|
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, path, len + 1,
|
|
|
|
widebuf, len + 1 );
|
|
|
|
|
|
|
|
fileH = CreateFile( widebuf, GENERIC_READ, 0, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
|
|
|
|
|
|
|
|
if ( fileH != INVALID_HANDLE_VALUE ) {
|
|
|
|
XP_U32 len = GetFileSize( fileH, NULL );
|
|
|
|
XP_U32 nRead;
|
|
|
|
XP_UCHAR* buf = XP_MALLOC( globals->mpool, len );
|
|
|
|
|
|
|
|
XP_DEBUGF( "fileSize = %ld", len );
|
|
|
|
|
|
|
|
ReadFile( fileH, buf, len, &nRead, NULL );
|
|
|
|
CloseHandle( fileH );
|
|
|
|
|
2004-11-09 03:40:36 +01:00
|
|
|
stream = make_generic_stream( globals );
|
2003-11-20 17:26:35 +01:00
|
|
|
stream_open( stream );
|
|
|
|
stream_putBytes( stream, buf, (XP_U16)nRead );
|
|
|
|
|
|
|
|
XP_FREE( globals->mpool, buf );
|
|
|
|
}
|
|
|
|
|
|
|
|
XP_DEBUGF( "fileToStream => 0x%lx", (unsigned long)stream );
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
} /* fileToStream */
|
|
|
|
|
|
|
|
static XP_Bool
|
|
|
|
ceLoadSavedGame( CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
XP_Bool success = XP_FALSE;
|
|
|
|
XWStreamCtxt* stream;
|
|
|
|
|
2006-02-06 05:41:14 +01:00
|
|
|
LOG_FUNC();
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
stream = fileToStream( globals, globals->curGameName );
|
|
|
|
success = stream != NULL;
|
|
|
|
if ( success ) {
|
|
|
|
DictionaryCtxt* dict;
|
2008-09-10 14:18:30 +02:00
|
|
|
XP_U8 flags = stream_getU8( stream );
|
|
|
|
XP_Bool hasDict = (flags & 0x01) != 0;
|
|
|
|
flags >>= 1;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
if ( hasDict ) {
|
2004-01-17 23:10:23 +01:00
|
|
|
#ifdef STUBBED_DICT
|
|
|
|
XP_ASSERT(0); /* just don't do this!!!! */
|
|
|
|
#else
|
2008-09-28 18:48:30 +02:00
|
|
|
XP_UCHAR* dictName = stringFromStream( globals->mpool, stream );
|
|
|
|
dict = ce_dictionary_make( globals, dictName );
|
2005-06-30 03:48:07 +02:00
|
|
|
success = dict != NULL;
|
2008-09-28 18:48:30 +02:00
|
|
|
if ( !success ) {
|
|
|
|
XP_UCHAR buf[128];
|
2009-04-11 17:45:59 +02:00
|
|
|
snprintf( buf, VSIZE(buf),
|
|
|
|
ceGetResString( globals, IDS_CANNOTOPEN_DICT ),
|
2008-09-28 18:48:30 +02:00
|
|
|
dictName );
|
|
|
|
buf[VSIZE(buf)-1] = '\0';
|
2009-12-27 03:54:30 +01:00
|
|
|
ceOops( globals, buf, SAB_NONE );
|
2008-12-11 14:48:59 +01:00
|
|
|
|
2008-09-28 18:48:30 +02:00
|
|
|
}
|
|
|
|
XP_FREE( globals->mpool, dictName );
|
2004-01-17 23:10:23 +01:00
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
} else {
|
|
|
|
dict = NULL;
|
|
|
|
}
|
|
|
|
|
2005-06-30 03:48:07 +02:00
|
|
|
if ( success ) {
|
2009-09-13 01:31:48 +02:00
|
|
|
TransportProcs procs;
|
|
|
|
|
2008-11-08 17:25:49 +01:00
|
|
|
if ( flags >= CE_GAMEFILE_VERSION1 ) {
|
|
|
|
ce_draw_fromStream( globals->draw, stream, flags );
|
2008-09-28 18:48:30 +02:00
|
|
|
}
|
|
|
|
|
2005-06-30 03:48:07 +02:00
|
|
|
XP_DEBUGF( "calling game_makeFromStream" );
|
2009-09-13 01:31:48 +02:00
|
|
|
ceInitTProcs( globals, &procs );
|
2008-09-28 18:48:30 +02:00
|
|
|
success = game_makeFromStream( MEMPOOL stream, &globals->game,
|
|
|
|
&globals->gameInfo, dict,
|
|
|
|
&globals->util,
|
|
|
|
(DrawCtx*)globals->draw,
|
2009-09-13 01:31:48 +02:00
|
|
|
&globals->appPrefs.cp, &procs );
|
2008-09-28 18:48:30 +02:00
|
|
|
if ( success ) {
|
|
|
|
ceSetTitleFromName( globals );
|
2008-12-11 14:48:59 +01:00
|
|
|
} else {
|
|
|
|
if ( !!dict ) {
|
|
|
|
dict_destroy( dict );
|
|
|
|
}
|
2009-12-27 03:54:30 +01:00
|
|
|
ceOopsId( globals, IDS_CANNOTOPEN_GAME, SAB_NONE );
|
2008-09-28 18:48:30 +02:00
|
|
|
}
|
2005-06-30 03:48:07 +02:00
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
stream_destroy( stream );
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
} /* ceLoadSavedGame */
|
|
|
|
|
2004-03-28 03:14:34 +02:00
|
|
|
static void
|
2008-02-23 23:06:05 +01:00
|
|
|
colorsFromRsrc( const CEAppGlobals* globals, CEAppPrefs* prefs )
|
2004-03-28 03:14:34 +02:00
|
|
|
{
|
|
|
|
XP_U16 i;
|
|
|
|
HGLOBAL globH;
|
|
|
|
HRSRC rsrcH;
|
|
|
|
XP_U16* ptr;
|
|
|
|
|
|
|
|
rsrcH = FindResource( globals->hInst, MAKEINTRESOURCE(ID_COLORS_RES),
|
|
|
|
TEXT("CLRS") );
|
|
|
|
globH = LoadResource( globals->hInst, rsrcH );
|
|
|
|
ptr = (XP_U16*)globH;
|
|
|
|
|
2007-01-19 07:43:52 +01:00
|
|
|
for ( i = 0; i < CE_NUM_COLORS; ++i ) {
|
2004-03-28 03:14:34 +02:00
|
|
|
XP_U8 r = (XP_U8)*ptr++;
|
|
|
|
XP_U8 g = (XP_U8)*ptr++;
|
|
|
|
XP_U8 b = (XP_U8)*ptr++;
|
2008-02-23 23:06:05 +01:00
|
|
|
prefs->colors[i] = RGB( r, g, b );
|
2004-03-28 03:14:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DeleteObject( globH );
|
|
|
|
} /* colorsFromRsrc */
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static void
|
2008-02-23 23:06:05 +01:00
|
|
|
ceInitPrefs( CEAppGlobals* globals, CEAppPrefs* prefs )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
2008-02-23 23:06:05 +01:00
|
|
|
prefs->versionFlags = CUR_CE_PREFS_FLAGS;
|
|
|
|
prefs->showColors = XP_TRUE;
|
|
|
|
prefs->fullScreen = XP_FALSE;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-02-23 23:06:05 +01:00
|
|
|
prefs->cp.showBoardArrow = XP_TRUE;
|
|
|
|
prefs->cp.showRobotScores = XP_FALSE;
|
2004-03-28 03:14:34 +02:00
|
|
|
|
2008-02-23 23:06:05 +01:00
|
|
|
colorsFromRsrc( globals, prefs );
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ceInitPrefs */
|
|
|
|
|
2008-02-16 18:36:46 +01:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
static void
|
|
|
|
getOSInfo( CEAppGlobals* globals )
|
|
|
|
{
|
2008-03-15 16:39:58 +01:00
|
|
|
OSVERSIONINFO ver = {0};
|
2008-02-16 18:36:46 +01:00
|
|
|
TCHAR buf[128];
|
2008-03-15 16:39:58 +01:00
|
|
|
XW_WinceVersion winceVersion = WINCE_UNKNOWN;
|
2008-02-16 18:36:46 +01:00
|
|
|
|
2008-03-15 16:39:58 +01:00
|
|
|
if ( GetVersionEx( &ver )) {
|
|
|
|
XP_LOGF( "version = %ld.%ld", ver.dwMajorVersion, ver.dwMinorVersion );
|
|
|
|
} else {
|
|
|
|
XP_WARNF( "GetVersionEx failed" );
|
|
|
|
}
|
2008-02-16 18:36:46 +01:00
|
|
|
|
|
|
|
if ( SystemParametersInfo( SPI_GETPLATFORMTYPE, sizeof(buf), buf, FALSE ) ) {
|
2008-03-15 16:39:58 +01:00
|
|
|
if ( 0 == lstrcmp( buf, L"PocketPC") ) {
|
2008-02-16 18:36:46 +01:00
|
|
|
// We are on a Pocket PC, so check the OS version,
|
|
|
|
// Pocket PC 2003 used WinCE 4.2
|
2008-03-15 16:39:58 +01:00
|
|
|
if ( ver.dwMajorVersion < 4 ) {
|
|
|
|
winceVersion = WINCE_PPC_V1;
|
|
|
|
} else if ( ver.dwMajorVersion == 4 ) {
|
|
|
|
winceVersion = WINCE_PPC_2003;
|
2008-02-16 18:36:46 +01:00
|
|
|
} else if ( ver.dwMajorVersion > 4 ) {
|
2008-03-15 16:39:58 +01:00
|
|
|
winceVersion = WINCE_PPC_2005;
|
|
|
|
}
|
|
|
|
} else if ( 0 == lstrcmp( buf, L"SmartPhone") ) {
|
|
|
|
if ( ver.dwMajorVersion < 4 ) {
|
|
|
|
winceVersion = WINCE_SMARTPHONE_V1;
|
|
|
|
} else if ( ver.dwMajorVersion == 4 ) {
|
|
|
|
winceVersion = WINCE_SMARTPHONE_2003;
|
|
|
|
} else if ( ver.dwMajorVersion > 4 ) {
|
|
|
|
winceVersion = WINCE_SMARTPHONE_2005;
|
2008-02-16 18:36:46 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
XP_LOGW( "unknown OS type", buf );
|
|
|
|
}
|
2008-03-15 16:39:58 +01:00
|
|
|
} else if ( GetLastError() == ERROR_ACCESS_DENIED ) {
|
|
|
|
if ( ver.dwMajorVersion < 4 ) {
|
|
|
|
winceVersion = WINCE_SMARTPHONE_V1;
|
|
|
|
} else {
|
|
|
|
winceVersion = WINCE_SMARTPHONE_2003;
|
|
|
|
}
|
2008-02-16 18:36:46 +01:00
|
|
|
}
|
2008-03-15 16:39:58 +01:00
|
|
|
|
|
|
|
XP_ASSERT( winceVersion != WINCE_UNKNOWN );
|
|
|
|
globals->winceVersion = winceVersion;
|
|
|
|
XP_LOGF( "%s: set version to %d", __func__, winceVersion );
|
|
|
|
} /* getOSInfo */
|
2008-02-16 18:36:46 +01:00
|
|
|
#else
|
|
|
|
#define getOSInfo( g )
|
|
|
|
#endif
|
|
|
|
|
2009-12-21 07:43:21 +01:00
|
|
|
|
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2009-12-23 07:01:26 +01:00
|
|
|
#if defined _WIN32_WCE && ! defined CEGCC_DOES_CONNMGR
|
2009-12-21 07:43:21 +01:00
|
|
|
# define LOAD_PTR( typ, name ) { \
|
|
|
|
typ proc; \
|
|
|
|
proc = (typ)GetProcAddress( hcellDll, TEXT(#name));\
|
|
|
|
XP_ASSERT( !!proc ); \
|
|
|
|
globals->cmProcs.name = proc; \
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
initConnMgr( CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
HINSTANCE hcellDll = LoadLibrary(TEXT("cellcore.dll"));
|
2009-12-28 00:53:41 +01:00
|
|
|
XP_ASSERT( !!hcellDll );
|
2009-12-21 07:43:21 +01:00
|
|
|
if ( !!hcellDll ) {
|
|
|
|
globals->hcellDll = hcellDll;
|
|
|
|
|
|
|
|
LOAD_PTR( ConnMgrEstablishConnectionProc, ConnMgrEstablishConnection );
|
|
|
|
LOAD_PTR( ConnMgrConnectionStatusProc, ConnMgrConnectionStatus );
|
|
|
|
LOAD_PTR( ConnMgrMapURLProc, ConnMgrMapURL );
|
|
|
|
LOAD_PTR( ConnMgrReleaseConnectionProc, ConnMgrReleaseConnection );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# undef LOAD_PTR
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
//
|
|
|
|
// FUNCTION: InitInstance(HANDLE, int)
|
|
|
|
//
|
|
|
|
// PURPOSE: Saves instance handle and creates main window
|
|
|
|
//
|
|
|
|
// COMMENTS:
|
|
|
|
//
|
|
|
|
// In this function, we save the instance handle in a global variable and
|
|
|
|
// create and display the main program window.
|
|
|
|
//
|
|
|
|
BOOL
|
2008-11-10 19:49:26 +01:00
|
|
|
InitInstance(HINSTANCE hInstance, int nCmdShow
|
|
|
|
#ifndef _WIN32_WCE
|
2009-04-09 15:48:38 +02:00
|
|
|
,XP_U16 width, XP_U16 height, const char* dll
|
2008-11-10 19:49:26 +01:00
|
|
|
#endif
|
|
|
|
)
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
HWND hWnd;
|
|
|
|
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
|
|
|
|
TCHAR szWindowClass[MAX_LOADSTRING]; // The window class name
|
|
|
|
CEAppGlobals* globals;
|
2009-04-14 05:33:46 +02:00
|
|
|
BOOL result = FALSE;
|
2003-12-09 06:18:47 +01:00
|
|
|
XP_Bool oldGameLoaded;
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_Bool prevStateExists;
|
2003-12-09 06:18:47 +01:00
|
|
|
XP_Bool newDone = XP_FALSE;
|
2008-10-25 20:08:36 +02:00
|
|
|
wchar_t path[CE_MAX_PATH_LEN];
|
2003-11-20 17:26:35 +01:00
|
|
|
MPSLOT;
|
|
|
|
|
2009-03-08 21:01:47 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2005-11-27 21:16:43 +01:00
|
|
|
{
|
|
|
|
WORD wVersionRequested;
|
|
|
|
WSADATA wsaData;
|
|
|
|
int err;
|
|
|
|
wVersionRequested = MAKEWORD( 2, 2 );
|
|
|
|
err = WSAStartup( wVersionRequested, &wsaData );
|
|
|
|
if ( err != 0 ) {
|
|
|
|
/* Tell the user that we could not find a usable */
|
|
|
|
/* WinSock DLL. */
|
2006-02-06 05:41:14 +01:00
|
|
|
XP_LOGF( "unable to load winsock" );
|
2005-11-27 21:16:43 +01:00
|
|
|
}
|
|
|
|
}
|
2006-02-06 05:41:14 +01:00
|
|
|
#endif
|
2005-11-27 21:16:43 +01:00
|
|
|
|
2004-01-10 19:11:28 +01:00
|
|
|
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
|
|
|
|
LoadString(hInstance, IDC_XWORDS4, szWindowClass, MAX_LOADSTRING);
|
|
|
|
|
2008-10-25 20:08:36 +02:00
|
|
|
// If it is already running, then focus on the window. Skip title in
|
|
|
|
// search as we change title to include game name
|
|
|
|
hWnd = FindWindow( szWindowClass, NULL );
|
2004-01-10 19:11:28 +01:00
|
|
|
if ( hWnd ) {
|
2009-09-22 05:49:26 +02:00
|
|
|
XP_LOGF( "Looks like I'm running already; "
|
|
|
|
"calling SetForegroundWindow and exiting" );
|
2004-01-10 19:11:28 +01:00
|
|
|
SetForegroundWindow( (HWND)((ULONG) hWnd | 0x00000001) );
|
2008-02-16 17:02:49 +01:00
|
|
|
goto exit;
|
2009-04-09 15:48:38 +02:00
|
|
|
}
|
2004-01-10 19:11:28 +01:00
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
#ifdef MEM_DEBUG
|
|
|
|
mpool = mpool_make();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
globals = (CEAppGlobals*)XP_MALLOC( mpool, sizeof(*globals) );
|
2008-03-15 16:39:58 +01:00
|
|
|
XP_DEBUGF( "globals created: 0x%p", globals );
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_MEMSET( globals, 0, sizeof(*globals) );
|
|
|
|
MPASSIGN( globals->mpool, mpool );
|
2009-04-09 15:48:38 +02:00
|
|
|
|
2008-11-10 19:49:26 +01:00
|
|
|
#ifndef _WIN32_WCE
|
|
|
|
globals->dbWidth = width;
|
|
|
|
globals->dbHeight = height;
|
|
|
|
#endif
|
|
|
|
|
2008-10-25 20:08:36 +02:00
|
|
|
(void)ceGetPath( globals, DEFAULT_DIR_PATH_L, path, VSIZE(path) );
|
|
|
|
(void)CreateDirectory( path, 0 );
|
|
|
|
|
2008-02-16 18:36:46 +01:00
|
|
|
getOSInfo( globals );
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
globals->vtMgr = make_vtablemgr( MPPARM_NOCOMMA(mpool) );
|
|
|
|
|
|
|
|
globals->hInst = hInstance;
|
|
|
|
// Initialize global strings
|
|
|
|
MyRegisterClass(hInstance, szWindowClass);
|
|
|
|
|
2009-04-14 05:33:46 +02:00
|
|
|
prevStateExists = ceLoadPrefs( globals );
|
|
|
|
if ( !prevStateExists ) {
|
|
|
|
ceInitPrefs( globals, &globals->appPrefs );
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef _WIN32_WCE
|
|
|
|
srand( time(NULL) );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2009-04-14 05:33:46 +02:00
|
|
|
/* Was a language file named in preferences? If so, and if none was
|
|
|
|
provided on the cmdline, load it (if it exists; if it doesn't, act as
|
|
|
|
if none set). */
|
2009-04-19 19:33:39 +02:00
|
|
|
if ( !!dll && !!dll[0] ) {
|
2009-04-14 05:33:46 +02:00
|
|
|
replaceStringIfDifferent( globals->mpool, &globals->langFileName, dll );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( !!globals->langFileName && !globals->locInst ) {
|
|
|
|
HINSTANCE inst = ceLoadResFile( globals->langFileName );
|
|
|
|
if ( !!inst ) {
|
|
|
|
globals->locInst = inst;
|
|
|
|
} else {
|
|
|
|
XP_FREE( globals->mpool, globals->langFileName );
|
|
|
|
globals->langFileName = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !globals->locInst ) {
|
|
|
|
globals->locInst = globals->hInst;
|
|
|
|
}
|
|
|
|
|
|
|
|
hWnd = CreateWindow( szWindowClass, szTitle, WS_VISIBLE,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT, NULL, NULL, hInstance, globals );
|
2008-02-16 17:02:49 +01:00
|
|
|
if (!hWnd) {
|
|
|
|
goto exit;
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
2009-04-14 05:33:46 +02:00
|
|
|
globals->hWnd = hWnd;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2006-02-06 05:41:14 +01:00
|
|
|
#ifdef _WIN32_WCE
|
2008-03-15 19:32:22 +01:00
|
|
|
if ( globals->hwndCB && !IS_SMARTPHONE(globals) ) {
|
2004-12-17 08:45:30 +01:00
|
|
|
RECT rc, rcmb;
|
|
|
|
|
|
|
|
GetWindowRect( hWnd, &rc );
|
|
|
|
GetWindowRect( globals->hwndCB, &rcmb );
|
|
|
|
rc.bottom -= (rcmb.bottom - rcmb.top);
|
|
|
|
|
2008-11-18 13:36:27 +01:00
|
|
|
MoveWindow( hWnd, rc.left, rc.top, rc.right-rc.left,
|
|
|
|
rc.bottom-rc.top, FALSE );
|
2004-12-17 08:45:30 +01:00
|
|
|
}
|
2005-11-27 21:16:43 +01:00
|
|
|
#endif
|
2005-11-28 00:11:05 +01:00
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
ceInitUtilFuncs( globals );
|
|
|
|
|
2008-12-12 14:42:52 +01:00
|
|
|
gi_initPlayerInfo( MPPARM(mpool) &globals->gameInfo, NULL );
|
2006-05-30 07:12:02 +02:00
|
|
|
|
2009-04-14 05:33:46 +02:00
|
|
|
|
|
|
|
#ifndef _WIN32_WCE
|
|
|
|
SetMenu( hWnd, LoadMenu( globals->locInst, MAKEINTRESOURCE(IDM_MENU) ) );
|
|
|
|
#endif
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
/* choose one. If none found it's an error. */
|
2004-01-17 23:10:23 +01:00
|
|
|
#ifndef STUBBED_DICT
|
2008-10-29 09:46:02 +01:00
|
|
|
result = 1 == ceLocateNDicts( globals, 1, ceSetDictName,
|
2006-04-22 16:05:09 +02:00
|
|
|
globals );
|
2004-01-10 19:11:28 +01:00
|
|
|
if ( !result ) {
|
2008-06-13 07:25:20 +02:00
|
|
|
wchar_t buf[512];
|
2009-04-11 17:45:59 +02:00
|
|
|
(void)LoadString( globals->locInst, (UINT)IDS_DICTLOC, buf, VSIZE(buf) );
|
2008-12-07 06:21:13 +01:00
|
|
|
assertOnTop( globals->hWnd );
|
2009-04-11 17:45:59 +02:00
|
|
|
MessageBox( globals->hWnd, buf,
|
|
|
|
ceGetResStringL( globals, IDS_NODICT_L ),
|
2008-12-07 17:24:26 +01:00
|
|
|
MB_OK | MB_ICONHAND );
|
2008-02-16 17:02:49 +01:00
|
|
|
goto exit;
|
2004-01-10 19:11:28 +01:00
|
|
|
}
|
2009-04-14 05:33:46 +02:00
|
|
|
#else
|
|
|
|
result = TRUE;
|
2004-01-17 23:10:23 +01:00
|
|
|
#endif
|
2004-01-10 19:11:28 +01:00
|
|
|
|
2009-12-28 00:53:41 +01:00
|
|
|
#if defined _WIN32_WCE && ! defined CEGCC_DOES_CONNMGR
|
|
|
|
initConnMgr( globals );
|
|
|
|
#endif
|
2009-04-14 05:33:46 +02:00
|
|
|
|
2004-04-03 18:39:18 +02:00
|
|
|
/* must load prefs before creating draw ctxt */
|
2004-03-28 03:14:34 +02:00
|
|
|
globals->draw = ce_drawctxt_make( MPPARM(globals->mpool)
|
|
|
|
hWnd, globals );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2004-04-03 18:39:18 +02:00
|
|
|
oldGameLoaded = prevStateExists && ceLoadSavedGame( globals );
|
|
|
|
|
2004-03-28 03:14:34 +02:00
|
|
|
if ( !oldGameLoaded ) {
|
2009-09-13 01:31:48 +02:00
|
|
|
TransportProcs procs;
|
|
|
|
ceInitTProcs( globals, &procs );
|
2003-11-20 17:26:35 +01:00
|
|
|
game_makeNewGame( MPPARM(mpool) &globals->game, &globals->gameInfo,
|
2009-02-07 19:20:16 +01:00
|
|
|
&globals->util, (DrawCtx*)globals->draw, 0,
|
2009-09-13 01:31:48 +02:00
|
|
|
&globals->appPrefs.cp, &procs );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2009-12-04 10:09:07 +01:00
|
|
|
/* calls ceInitAndStartBoard */
|
|
|
|
newDone = ceDoNewGame( globals, GI_NEW_GAME );
|
2004-01-10 19:11:28 +01:00
|
|
|
if ( !newDone ) {
|
|
|
|
result = FALSE;
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-01 00:07:29 +02:00
|
|
|
trapBackspaceKey( hWnd );
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
ShowWindow(hWnd, nCmdShow);
|
|
|
|
UpdateWindow(hWnd);
|
2006-02-17 08:30:54 +01:00
|
|
|
#ifdef _WIN32_WCE
|
2003-11-20 17:26:35 +01:00
|
|
|
if (globals->hwndCB) {
|
|
|
|
CommandBar_Show(globals->hwndCB, TRUE);
|
|
|
|
}
|
2005-11-27 21:16:43 +01:00
|
|
|
#endif
|
2003-12-09 06:18:47 +01:00
|
|
|
if ( result && !newDone ) {
|
2008-02-16 17:02:49 +01:00
|
|
|
ceInitAndStartBoard( globals, !oldGameLoaded, NULL );
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
|
2008-02-16 17:02:49 +01:00
|
|
|
exit:
|
2003-11-20 17:26:35 +01:00
|
|
|
return result;
|
|
|
|
} /* InitInstance */
|
|
|
|
|
2006-04-19 06:56:00 +02:00
|
|
|
static XP_Bool
|
2006-08-16 15:44:44 +02:00
|
|
|
ceSetDictName( const wchar_t* XP_UNUSED(wPath), XP_U16 XP_UNUSED_DBG(index),
|
|
|
|
void* XP_UNUSED(ctxt) )
|
2006-04-19 06:56:00 +02:00
|
|
|
{
|
2006-05-30 07:12:02 +02:00
|
|
|
/* CEAppGlobals* globals = (CEAppGlobals*)ctxt; */
|
|
|
|
/* XP_UCHAR* str; */
|
|
|
|
/* XP_UCHAR buf[CE_MAX_PATH_LEN]; */
|
2006-04-19 06:56:00 +02:00
|
|
|
XP_ASSERT( index == 0 ); /* we said one only! */
|
|
|
|
|
2006-05-30 07:12:02 +02:00
|
|
|
/* WideCharToMultiByte( CP_ACP, 0, wPath, -1, */
|
|
|
|
/* buf, sizeof(buf)-1, NULL, NULL ); */
|
2006-04-19 06:56:00 +02:00
|
|
|
|
2007-12-02 20:13:25 +01:00
|
|
|
/* XP_LOGF( "%s: got path \"%s\"", __func__, buf ); */
|
2006-05-30 07:12:02 +02:00
|
|
|
/* str = copyString( MPPARM(globals->mpool) buf ); */
|
2007-12-02 20:13:25 +01:00
|
|
|
/* XP_LOGF( "%s: got %p", __func__, str ); /\* this is leaking *\/ */
|
2006-05-30 07:12:02 +02:00
|
|
|
/* XP_ASSERT( NULL == globals->gameInfo.dictName ); */
|
|
|
|
/* globals->gameInfo.dictName = str; */
|
2006-04-25 06:25:08 +02:00
|
|
|
return XP_FALSE;
|
2006-04-19 06:56:00 +02:00
|
|
|
} /* ceSetDictName */
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static XP_Bool
|
|
|
|
ceHandleHintRequest( CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
XP_Bool notDone;
|
|
|
|
XP_Bool draw;
|
|
|
|
XP_ASSERT( !!globals->game.board );
|
|
|
|
|
2004-12-11 05:25:45 +01:00
|
|
|
draw = board_requestHint( globals->game.board,
|
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
globals->askTrayLimits,
|
|
|
|
#endif
|
2004-07-10 19:46:36 +02:00
|
|
|
¬Done );
|
2003-11-20 17:26:35 +01:00
|
|
|
globals->hintPending = notDone;
|
2008-02-26 14:49:41 +01:00
|
|
|
if ( draw ) { /* don't turn on if disallowed */
|
|
|
|
ceSetLeftSoftkey( globals, ID_MOVE_NEXTHINT );
|
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
return draw;
|
|
|
|
} /* ceHandleHintRequest */
|
|
|
|
|
|
|
|
static XP_Bool
|
|
|
|
handleTradeCmd( CEAppGlobals* globals )
|
|
|
|
{
|
2008-05-11 17:25:04 +02:00
|
|
|
XP_Bool success = board_beginTrade( globals->game.board );
|
|
|
|
if ( success ) {
|
|
|
|
ceSetLeftSoftkey( globals, ID_MOVE_TURNDONE );
|
|
|
|
}
|
|
|
|
return success;
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* handleTradeCmd */
|
|
|
|
|
|
|
|
static XP_Bool
|
|
|
|
handleJuggleCmd( CEAppGlobals* globals )
|
|
|
|
{
|
2008-03-10 02:47:46 +01:00
|
|
|
ceSetLeftSoftkey( globals, ID_MOVE_JUGGLE );
|
2003-11-20 17:26:35 +01:00
|
|
|
return board_juggleTray( globals->game.board );
|
|
|
|
} /* handleJuggleCmd */
|
|
|
|
|
|
|
|
static XP_Bool
|
|
|
|
handleHidetrayCmd( CEAppGlobals* globals )
|
|
|
|
{
|
2008-04-08 05:55:53 +02:00
|
|
|
XP_Bool result;
|
2003-11-20 17:26:35 +01:00
|
|
|
XW_TrayVisState curState = board_getTrayVisState( globals->game.board );
|
2008-04-08 05:55:53 +02:00
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
if ( curState == TRAY_REVEALED ) {
|
2008-04-08 05:55:53 +02:00
|
|
|
result = board_hideTray( globals->game.board );
|
2003-11-20 17:26:35 +01:00
|
|
|
} else {
|
2008-04-08 05:55:53 +02:00
|
|
|
result = board_showTray( globals->game.board );
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
2008-04-08 05:55:53 +02:00
|
|
|
|
|
|
|
ceSetLeftSoftkey( globals, ID_MOVE_HIDETRAY );
|
|
|
|
return result;
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* handleHidetrayCmd */
|
|
|
|
|
|
|
|
static XP_Bool
|
|
|
|
handleDoneCmd( CEAppGlobals* globals)
|
|
|
|
{
|
|
|
|
return board_commitTurn( globals->game.board );
|
|
|
|
} /* handleDoneCmd */
|
|
|
|
|
|
|
|
static void
|
|
|
|
ceCountsAndValues( CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
if ( !!globals->game.server ) {
|
2004-11-09 03:40:36 +01:00
|
|
|
XWStreamCtxt* stream = make_generic_stream( globals );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2004-12-18 02:03:26 +01:00
|
|
|
server_formatDictCounts( globals->game.server, stream, 3 );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2009-04-11 17:45:59 +02:00
|
|
|
(void)ceMsgFromStream( globals, stream,
|
|
|
|
ceGetResStringL( globals, IDS_COUNTSVALS_L ),
|
2008-12-07 17:24:26 +01:00
|
|
|
MB_OK | MB_ICONINFORMATION, XP_TRUE );
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
} /* ceCountsAndValues */
|
|
|
|
|
2004-11-09 03:40:36 +01:00
|
|
|
static void
|
|
|
|
ceTilesLeft( CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
if ( !!globals->game.board ) {
|
|
|
|
XWStreamCtxt* stream = make_generic_stream( globals );
|
|
|
|
board_formatRemainingTiles( globals->game.board, stream );
|
|
|
|
|
2009-04-11 17:45:59 +02:00
|
|
|
(void)ceMsgFromStream( globals, stream,
|
|
|
|
ceGetResStringL( globals, IDS_REMTILES_L ),
|
2008-12-07 17:24:26 +01:00
|
|
|
MB_OK | MB_ICONINFORMATION, XP_TRUE );
|
2004-11-09 03:40:36 +01:00
|
|
|
}
|
|
|
|
} /* ceTilesLeft */
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static void
|
|
|
|
ceDoHistory( CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
XP_Bool gameOver = server_getGameIsOver(globals->game.server);
|
|
|
|
XWStreamCtxt* stream;
|
|
|
|
|
2004-11-09 03:40:36 +01:00
|
|
|
stream = make_generic_stream( globals );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
model_writeGameHistory( globals->game.model, stream,
|
|
|
|
globals->game.server, gameOver );
|
2009-04-11 17:45:59 +02:00
|
|
|
(void)ceMsgFromStream( globals, stream,
|
|
|
|
ceGetResStringL( globals, IDS_GAMEHIST_L ),
|
2008-12-07 17:24:26 +01:00
|
|
|
MB_OK | MB_ICONINFORMATION, XP_TRUE );
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ceDoHistory */
|
|
|
|
|
2009-11-22 18:58:59 +01:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2009-09-22 05:49:26 +02:00
|
|
|
static CeNetState
|
|
|
|
ceFlattenState( const CEAppGlobals* globals )
|
2009-09-15 15:04:34 +02:00
|
|
|
{
|
|
|
|
/* Idea is to give user a clue how the network connection's coming.
|
|
|
|
Relay only matters if we have a socket open. So use that first. */
|
|
|
|
CommsRelayState relayState = globals->relayState;
|
|
|
|
CeConnState socketState = globals->socketState;
|
2009-09-22 05:49:26 +02:00
|
|
|
CeNetState state = CENSTATE_NONE;
|
2009-09-15 15:04:34 +02:00
|
|
|
|
|
|
|
if ( socketState == CE_IPST_CONNECTED ) {
|
|
|
|
switch( relayState ) {
|
2009-09-22 05:49:26 +02:00
|
|
|
case COMMS_RELAYSTATE_UNCONNECTED:
|
2009-12-04 10:09:07 +01:00
|
|
|
case COMMS_RELAYSTATE_DENIED:
|
2009-09-22 05:49:26 +02:00
|
|
|
case COMMS_RELAYSTATE_CONNECT_PENDING:
|
|
|
|
state = CENSTATE_TRYING_RELAY;
|
|
|
|
break;
|
|
|
|
case COMMS_RELAYSTATE_CONNECTED:
|
2009-11-09 04:29:13 +01:00
|
|
|
case COMMS_RELAYSTATE_RECONNECTED:
|
2009-09-22 05:49:26 +02:00
|
|
|
state = CENSTATE_HAVE_RELAY;
|
|
|
|
break;
|
|
|
|
case COMMS_RELAYSTATE_ALLCONNECTED:
|
|
|
|
state = CENSTATE_ALL_HERE;
|
|
|
|
break;
|
2009-09-15 15:04:34 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch( socketState ) {
|
|
|
|
case CE_IPST_START:
|
2009-12-21 07:43:21 +01:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
case CE_IPST_OPENING_NETWORK:
|
|
|
|
case CE_IPST_NETWORK_OPENED:
|
|
|
|
#endif
|
2009-12-27 20:04:29 +01:00
|
|
|
/* state = CENSTATE_NONE; */
|
|
|
|
break;
|
2009-09-24 06:26:28 +02:00
|
|
|
case CE_IPST_RESOLVINGHOST:
|
2009-09-22 05:49:26 +02:00
|
|
|
case CE_IPST_HOSTRESOLVED:
|
|
|
|
case CE_IPST_CONNECTING:
|
|
|
|
case CE_IPST_CONNECTED:
|
|
|
|
state = CENSTATE_TRYING_RELAY;
|
|
|
|
break;
|
2009-09-15 15:04:34 +02:00
|
|
|
}
|
|
|
|
}
|
2009-09-22 05:49:26 +02:00
|
|
|
return state;
|
|
|
|
} /* ceFlattenState */
|
2009-11-22 18:58:59 +01:00
|
|
|
#endif
|
2009-09-15 15:04:34 +02:00
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static void
|
2008-09-01 17:10:28 +02:00
|
|
|
drawInsidePaint( CEAppGlobals* globals, const RECT* invalR )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
HDC hdc;
|
|
|
|
|
2006-05-14 17:28:57 +02:00
|
|
|
hdc = GetDC( globals->hWnd );
|
2004-02-12 05:35:10 +01:00
|
|
|
if ( !hdc ) {
|
2007-12-02 20:13:25 +01:00
|
|
|
logLastError( __func__ );
|
2004-02-12 05:35:10 +01:00
|
|
|
} else {
|
2008-12-06 23:14:40 +01:00
|
|
|
int oldMode = SetBkMode( hdc, TRANSPARENT );
|
2004-02-13 14:49:25 +01:00
|
|
|
HDC prevHDC = globals->hdc;
|
2004-02-12 05:35:10 +01:00
|
|
|
globals->hdc = hdc;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-09-01 17:10:28 +02:00
|
|
|
if ( !!invalR ) {
|
2008-09-09 14:31:02 +02:00
|
|
|
XP_U16 ii;
|
2008-10-01 10:31:43 +02:00
|
|
|
RECT interR;
|
2008-09-09 14:31:02 +02:00
|
|
|
for ( ii = 0; ii < N_OWNED_RECTS; ++ii ) {
|
|
|
|
if ( IntersectRect( &interR, invalR,
|
|
|
|
&globals->ownedRects[ii] ) ) {
|
|
|
|
ce_draw_erase( globals->draw, &interR );
|
|
|
|
}
|
|
|
|
}
|
2009-09-15 15:04:34 +02:00
|
|
|
|
2009-09-24 06:26:28 +02:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2009-09-15 15:04:34 +02:00
|
|
|
if ( IntersectRect( &interR, invalR, &globals->relayStatusR ) ) {
|
2009-09-22 05:49:26 +02:00
|
|
|
CeNetState state = ceFlattenState( globals );
|
|
|
|
ce_draw_status( globals->draw, &globals->relayStatusR, state );
|
2009-09-15 15:04:34 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-07 06:00:37 +02:00
|
|
|
#ifdef _WIN32_WCE
|
2008-10-01 10:31:43 +02:00
|
|
|
for ( ii = 0; ii < VSIZE(globals->scrollRects); ++ii ) {
|
|
|
|
if ( IntersectRect( &interR, invalR,
|
|
|
|
&globals->scrollRects[ii] ) ) {
|
|
|
|
if ( globals->scrollerHasFocus ) {
|
|
|
|
ce_draw_focus( globals->draw, &interR );
|
|
|
|
} else {
|
|
|
|
ce_draw_erase( globals->draw, &interR );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-07 06:00:37 +02:00
|
|
|
#endif
|
2008-09-01 17:10:28 +02:00
|
|
|
}
|
|
|
|
|
2004-02-12 05:35:10 +01:00
|
|
|
board_draw( globals->game.board );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-12-06 23:14:40 +01:00
|
|
|
(void)SetBkMode( hdc, oldMode );
|
2004-02-13 14:49:25 +01:00
|
|
|
globals->hdc = prevHDC;
|
2004-02-12 05:35:10 +01:00
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* drawInsidePaint */
|
|
|
|
|
|
|
|
static void
|
|
|
|
ceDisplayFinalScores( CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
XWStreamCtxt* stream;
|
|
|
|
|
2004-11-09 03:40:36 +01:00
|
|
|
stream = make_generic_stream( globals );
|
2003-11-20 17:26:35 +01:00
|
|
|
server_writeFinalScores( globals->game.server, stream );
|
|
|
|
stream_putU8( stream, '\0' );
|
|
|
|
|
2009-04-11 17:45:59 +02:00
|
|
|
(void)ceMsgFromStream( globals, stream,
|
|
|
|
ceGetResStringL( globals, IDS_FINALSCORE_L),
|
2008-12-07 17:24:26 +01:00
|
|
|
MB_OK | MB_ICONINFORMATION, XP_TRUE );
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ceDisplayFinalScores */
|
|
|
|
|
2009-10-02 07:48:48 +02:00
|
|
|
static void
|
|
|
|
ceWarnLangChange( CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
const wchar_t* msg = ceGetResStringL( globals,
|
|
|
|
IDS_LANG_CHANGE_RESTART );
|
2009-12-16 03:46:00 +01:00
|
|
|
MessageBox( globals->hWnd, msg,
|
|
|
|
ceGetResStringL( globals, IDS_FYI_L ),
|
|
|
|
MB_OK | MB_ICONINFORMATION );
|
2009-10-02 07:48:48 +02:00
|
|
|
}
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static XP_Bool
|
2009-12-04 10:09:07 +01:00
|
|
|
ceDoNewGame( CEAppGlobals* globals, GIShow showWhat )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
2005-07-23 17:31:21 +02:00
|
|
|
CommsAddrRec* addr = NULL;
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_Bool changed = XP_FALSE;
|
2009-10-17 05:38:37 +02:00
|
|
|
CePrefsPrefs prefsPrefs;
|
|
|
|
XP_UCHAR newDictName[CE_MAX_PATH_LEN+1];
|
|
|
|
GInfoResults results;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2009-12-04 10:09:07 +01:00
|
|
|
if ( WrapGameInfoDialog( globals, showWhat, &prefsPrefs, newDictName,
|
2009-10-17 05:38:37 +02:00
|
|
|
VSIZE(newDictName), &results )
|
2004-01-17 23:10:23 +01:00
|
|
|
#ifndef STUBBED_DICT
|
2009-10-17 05:38:37 +02:00
|
|
|
&& ( newDictName[0] != '\0' )
|
2004-01-17 23:10:23 +01:00
|
|
|
#endif
|
|
|
|
) {
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-10-12 01:56:04 +02:00
|
|
|
if ( globals->curGameName != NULL ) {
|
|
|
|
XP_FREE( globals->mpool, globals->curGameName );
|
|
|
|
globals->curGameName = NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-17 05:38:37 +02:00
|
|
|
if ( results.prefsChanged ) {
|
2005-07-23 17:31:21 +02:00
|
|
|
loadCurPrefsFromState( globals, &globals->appPrefs,
|
2009-10-17 05:38:37 +02:00
|
|
|
&globals->gameInfo, &prefsPrefs );
|
|
|
|
if ( results.colorsChanged ) {
|
2004-05-26 06:48:25 +02:00
|
|
|
updateForColors( globals );
|
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
2009-10-02 07:48:48 +02:00
|
|
|
|
2009-10-17 05:38:37 +02:00
|
|
|
if ( results.langChanged ) {
|
2009-10-02 07:48:48 +02:00
|
|
|
ceWarnLangChange( globals );
|
|
|
|
}
|
|
|
|
|
2006-10-28 16:56:04 +02:00
|
|
|
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
2009-10-17 05:38:37 +02:00
|
|
|
if ( results.addrChanged ) {
|
|
|
|
addr = &prefsPrefs.addrRec;
|
2005-07-23 17:31:21 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-02-16 17:02:49 +01:00
|
|
|
ceInitAndStartBoard( globals, XP_TRUE, addr );
|
2008-04-13 19:01:09 +02:00
|
|
|
ceSetTitleFromName( globals );
|
2003-11-20 17:26:35 +01:00
|
|
|
changed = XP_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return changed;
|
2006-01-31 07:41:16 +01:00
|
|
|
} /* ceDoNewGame */
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
ceChooseAndOpen( CEAppGlobals* globals )
|
|
|
|
{
|
2008-12-07 06:21:13 +01:00
|
|
|
assertOnTop( globals->hWnd );
|
2008-06-26 06:17:14 +02:00
|
|
|
// Save in case we'll be duplicating it
|
2008-12-06 21:28:01 +01:00
|
|
|
again:
|
2008-12-08 06:51:21 +01:00
|
|
|
if ( ceSaveCurGame( globals, XP_FALSE ) ) {
|
2008-12-06 21:28:01 +01:00
|
|
|
SavedGamesResult choice;
|
|
|
|
wchar_t newName[256];
|
|
|
|
newName[0] = 0;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-06-26 06:17:14 +02:00
|
|
|
ceSetTitleFromName( globals ); /* in case we named it above */
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-12-06 21:28:01 +01:00
|
|
|
choice = ceSavedGamesDlg( globals, globals->curGameName, newName,
|
|
|
|
VSIZE(newName) );
|
|
|
|
if ( CE_SVGAME_CANCEL != choice ) {
|
2008-06-26 06:17:14 +02:00
|
|
|
XP_UCHAR* name;
|
|
|
|
XP_U16 len;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-12-06 21:28:01 +01:00
|
|
|
len = wcslen(newName);
|
2008-06-26 06:17:14 +02:00
|
|
|
name = XP_MALLOC( globals->mpool, len + 1 );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-12-06 21:28:01 +01:00
|
|
|
WideCharToMultiByte( CP_ACP, 0, newName, len + 1,
|
2008-06-26 06:17:14 +02:00
|
|
|
name, len + 1, NULL, NULL );
|
|
|
|
|
|
|
|
if ( globals->curGameName != NULL
|
2008-09-28 18:48:30 +02:00
|
|
|
&& 0 == XP_STRCMP( name, globals->curGameName ) ){
|
|
|
|
/* User chose already-open game; no-op */
|
2008-06-26 06:17:14 +02:00
|
|
|
XP_FREE( globals->mpool, name );
|
2008-09-28 18:48:30 +02:00
|
|
|
} else {
|
|
|
|
/* Save old name in case fail to open new, e.g. because dict
|
|
|
|
not there */
|
|
|
|
XP_UCHAR* oldName;
|
|
|
|
|
|
|
|
/* Need to save a second time, with auto-save, in case user
|
|
|
|
wants to overwrite yet chooses a game whose dict is
|
|
|
|
missing -- since then we'll be re-opening this game! */
|
|
|
|
ceSaveCurGame( globals, XP_TRUE ); /* may change curGameName */
|
|
|
|
|
|
|
|
oldName = globals->curGameName;
|
|
|
|
globals->curGameName = NULL; /* prevent being destroyed */
|
2008-08-01 12:47:32 +02:00
|
|
|
closeGame( globals );
|
2008-06-26 06:17:14 +02:00
|
|
|
|
2008-12-06 21:28:01 +01:00
|
|
|
if ( CE_SVGAME_RENAME == choice ) {
|
|
|
|
XP_U16 len = 1 + XP_STRLEN( oldName );
|
|
|
|
wchar_t widebuf[len];
|
|
|
|
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, oldName, len,
|
|
|
|
widebuf, len );
|
|
|
|
(void)MoveFile( widebuf, newName );
|
|
|
|
}
|
|
|
|
|
2008-06-26 06:17:14 +02:00
|
|
|
globals->curGameName = name;
|
|
|
|
if ( ceLoadSavedGame( globals ) ) {
|
2008-09-28 18:48:30 +02:00
|
|
|
XP_FREE( globals->mpool, oldName );
|
2008-06-26 06:17:14 +02:00
|
|
|
} else {
|
2008-12-06 21:28:01 +01:00
|
|
|
XP_ASSERT( CE_SVGAME_RENAME != choice );
|
2008-06-26 06:17:14 +02:00
|
|
|
XP_LOGF( "failed to open chosen game" );
|
2008-09-28 18:48:30 +02:00
|
|
|
XP_FREE( globals->mpool, globals->curGameName );
|
|
|
|
globals->curGameName = oldName;
|
|
|
|
if ( !ceLoadSavedGame( globals ) ) {
|
|
|
|
XP_LOGF( "failed to open old game too!!!" );
|
|
|
|
}
|
2008-06-26 06:17:14 +02:00
|
|
|
}
|
2008-09-28 18:48:30 +02:00
|
|
|
ceInitAndStartBoard( globals, XP_FALSE, NULL );
|
2008-12-06 21:28:01 +01:00
|
|
|
if ( CE_SVGAME_RENAME == choice ) {
|
|
|
|
goto again;
|
|
|
|
}
|
2006-04-25 06:25:08 +02:00
|
|
|
}
|
2008-06-26 06:17:14 +02:00
|
|
|
} else {
|
|
|
|
XP_LOGF( "GetOpenFileName() failed" );
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* ceChooseAndOpen */
|
|
|
|
|
2004-04-14 06:00:28 +02:00
|
|
|
static void
|
|
|
|
updateForColors( CEAppGlobals* globals )
|
|
|
|
{
|
2008-09-01 17:10:28 +02:00
|
|
|
ce_draw_update( globals->draw );
|
2004-04-14 06:00:28 +02:00
|
|
|
if ( !!globals->game.board ) {
|
|
|
|
board_invalAll( globals->game.board );
|
|
|
|
}
|
|
|
|
} /* updateForColors */
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static void
|
|
|
|
ceDoPrefsDlg( CEAppGlobals* globals )
|
|
|
|
{
|
2004-04-14 06:00:28 +02:00
|
|
|
CePrefsPrefs prefsPrefs;
|
2009-10-02 07:48:48 +02:00
|
|
|
XP_Bool colorsChanged, langChanged;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2005-07-23 17:31:21 +02:00
|
|
|
loadStateFromCurPrefs( globals, &globals->appPrefs, &globals->gameInfo,
|
2003-11-20 17:26:35 +01:00
|
|
|
&prefsPrefs );
|
|
|
|
|
2008-12-07 06:21:13 +01:00
|
|
|
assertOnTop( globals->hWnd );
|
2009-08-29 15:37:37 +02:00
|
|
|
if ( WrapPrefsDialog( globals->hWnd, globals, &prefsPrefs,
|
2009-10-02 07:48:48 +02:00
|
|
|
XP_FALSE, &colorsChanged, &langChanged ) ) {
|
2005-07-23 17:31:21 +02:00
|
|
|
loadCurPrefsFromState( globals, &globals->appPrefs, &globals->gameInfo,
|
2003-11-20 17:26:35 +01:00
|
|
|
&prefsPrefs );
|
|
|
|
|
|
|
|
(void)cePositionBoard( globals );
|
|
|
|
|
2009-08-29 15:37:37 +02:00
|
|
|
if ( colorsChanged ) {
|
2004-04-14 06:00:28 +02:00
|
|
|
updateForColors( globals );
|
|
|
|
}
|
2009-10-02 07:48:48 +02:00
|
|
|
|
|
|
|
if ( langChanged ) {
|
|
|
|
ceWarnLangChange( globals );
|
|
|
|
}
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
/* need to reflect vars set in state into globals, and update/inval
|
|
|
|
as appropriate. */
|
|
|
|
}
|
|
|
|
} /* ceDoPrefsDlg */
|
|
|
|
|
|
|
|
static void
|
|
|
|
ceWriteToFile( XWStreamCtxt* stream, void* closure )
|
|
|
|
{
|
|
|
|
FileWriteState* fwState = (FileWriteState*)closure;
|
2006-05-28 16:53:02 +02:00
|
|
|
#ifdef MEM_DEBUG
|
2003-11-20 17:26:35 +01:00
|
|
|
CEAppGlobals* globals = fwState->globals;
|
2006-05-28 16:53:02 +02:00
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_UCHAR* path = fwState->path;
|
2008-10-12 01:56:04 +02:00
|
|
|
XP_U16 len = (XP_U16)XP_STRLEN( path ) + 1; /* 1: null byte */
|
|
|
|
wchar_t widebuf[len];
|
2003-11-20 17:26:35 +01:00
|
|
|
HANDLE fileH;
|
|
|
|
|
2008-10-12 01:56:04 +02:00
|
|
|
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, path, len, widebuf, len );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
fileH = CreateFile( widebuf, GENERIC_WRITE, 0, NULL,
|
|
|
|
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
|
|
|
|
|
|
|
|
if ( fileH != INVALID_HANDLE_VALUE ) {
|
2008-10-12 01:56:04 +02:00
|
|
|
XP_UCHAR* buf;
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_U32 nWritten;
|
2008-10-12 01:56:04 +02:00
|
|
|
|
|
|
|
len = stream_getSize( stream );
|
|
|
|
buf = XP_MALLOC( globals->mpool, len );
|
2003-11-20 17:26:35 +01:00
|
|
|
stream_getBytes( stream, buf, len );
|
|
|
|
|
|
|
|
WriteFile( fileH, buf, len, &nWritten, NULL );
|
|
|
|
SetEndOfFile( fileH );
|
|
|
|
CloseHandle( fileH );
|
|
|
|
|
|
|
|
XP_FREE( globals->mpool, buf );
|
|
|
|
}
|
|
|
|
} /* ceWriteToFile */
|
|
|
|
|
2004-01-10 19:11:28 +01:00
|
|
|
static XP_Bool
|
2008-10-25 20:08:36 +02:00
|
|
|
isDefaultName( CEAppGlobals* globals, const XP_UCHAR* name )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
2008-10-25 20:08:36 +02:00
|
|
|
wchar_t path[CE_MAX_PATH_LEN];
|
|
|
|
(void)ceGetPath( globals, DEFAULT_GAME_PATH, path, VSIZE(path) );
|
|
|
|
return 0 == XP_STRCMP( path, name );
|
2004-01-10 19:11:28 +01:00
|
|
|
} /* isDefaultName */
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
static XP_Bool
|
2004-01-10 19:11:28 +01:00
|
|
|
ceSaveCurGame( CEAppGlobals* globals, XP_Bool autoSave )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
XP_Bool confirmed = XP_FALSE;
|
|
|
|
/* If it doesn't yet have a name, get a path at which to save it. User
|
|
|
|
has a chance to cancel this. But if there is a name go ahead and save
|
|
|
|
using it and don't bother giving cancel chance -- since there's no
|
|
|
|
harm in making 'em restart. Not sure how this changes when IR's
|
|
|
|
involved. */
|
|
|
|
XP_UCHAR* name = globals->curGameName;
|
2008-10-25 20:08:36 +02:00
|
|
|
if ( name == NULL || isDefaultName( globals, name ) ) {
|
2004-01-10 19:11:28 +01:00
|
|
|
XP_UCHAR* newName = NULL;
|
|
|
|
|
|
|
|
if ( autoSave ) {
|
2008-10-25 20:08:36 +02:00
|
|
|
XP_U16 len;
|
|
|
|
wchar_t path[CE_MAX_PATH_LEN];
|
|
|
|
len = 1 + ceGetPath( globals, DEFAULT_GAME_PATH,
|
|
|
|
path, VSIZE(path) );
|
2004-01-10 19:11:28 +01:00
|
|
|
newName = XP_MALLOC( globals->mpool, len );
|
2008-10-25 20:08:36 +02:00
|
|
|
XP_MEMCPY( newName, path, len );
|
2004-01-30 06:48:24 +01:00
|
|
|
|
2004-01-10 19:11:28 +01:00
|
|
|
confirmed = XP_TRUE;
|
|
|
|
} else {
|
2008-06-26 06:17:14 +02:00
|
|
|
wchar_t nameBuf[MAX_PATH];
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2009-04-07 06:23:56 +02:00
|
|
|
confirmed = ceConfirmUniqueName( globals, globals->hWnd,
|
|
|
|
IDS_SAVENAME, nameBuf,
|
|
|
|
VSIZE(nameBuf) );
|
2004-01-10 19:11:28 +01:00
|
|
|
if ( confirmed ) {
|
|
|
|
XP_U16 len = wcslen(nameBuf);
|
|
|
|
newName = XP_MALLOC( globals->mpool, len + 1 );
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, nameBuf, len + 1,
|
2004-01-29 05:49:34 +01:00
|
|
|
newName, len + 1, NULL, NULL );
|
2004-01-10 19:11:28 +01:00
|
|
|
}
|
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
if ( confirmed ) {
|
2004-01-10 19:11:28 +01:00
|
|
|
XP_ASSERT( !!newName );
|
|
|
|
if ( !!globals->curGameName ) {
|
|
|
|
XP_FREE( globals->mpool, globals->curGameName );
|
|
|
|
}
|
|
|
|
globals->curGameName = newName;
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
confirmed = XP_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( confirmed ) {
|
|
|
|
if ( !!globals->game.server ) {
|
|
|
|
XWStreamCtxt* memStream;
|
|
|
|
DictionaryCtxt* dict;
|
|
|
|
FileWriteState fwState;
|
2006-10-22 21:44:30 +02:00
|
|
|
const char* dictName;
|
2008-09-10 14:18:30 +02:00
|
|
|
XP_U8 flags;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
fwState.path = globals->curGameName;
|
|
|
|
fwState.globals = globals;
|
|
|
|
board_hideTray( globals->game.board ); /* so won't be visible when
|
|
|
|
next opened */
|
|
|
|
memStream = mem_stream_make( MEMPOOL globals->vtMgr, &fwState, 0,
|
|
|
|
ceWriteToFile );
|
|
|
|
stream_open( memStream );
|
|
|
|
|
|
|
|
/* the dictionary */
|
|
|
|
dict = model_getDictionary( globals->game.model );
|
2004-01-22 04:21:19 +01:00
|
|
|
#ifdef STUBBED_DICT /* don't check this in!!! */
|
|
|
|
dictName = NULL;
|
|
|
|
#else
|
2003-11-20 17:26:35 +01:00
|
|
|
dictName = !!dict? dict_getName( dict ) : NULL;
|
2004-01-22 04:21:19 +01:00
|
|
|
#endif
|
2008-09-10 14:18:30 +02:00
|
|
|
flags = !!dictName? 0x01 : 0x00;
|
|
|
|
flags |= CE_GAMEFILE_VERSION << 1;
|
|
|
|
stream_putU8( memStream, flags );
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
if ( !!dictName ) {
|
|
|
|
stringToStream( memStream, dictName );
|
|
|
|
}
|
|
|
|
|
2008-09-10 14:18:30 +02:00
|
|
|
ce_draw_toStream( globals->draw, memStream );
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
game_saveToStream( &globals->game, &globals->gameInfo, memStream );
|
|
|
|
|
|
|
|
stream_destroy( memStream );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return confirmed;
|
|
|
|
} /* ceSaveCurGame */
|
|
|
|
|
2008-10-13 03:17:13 +02:00
|
|
|
static void
|
|
|
|
ceSaveAndExit( CEAppGlobals* globals )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
2009-12-18 05:24:55 +01:00
|
|
|
globals->exiting = XP_TRUE;
|
2008-10-13 03:17:13 +02:00
|
|
|
(void)ceSaveCurGame( globals, XP_TRUE );
|
|
|
|
ceSavePrefs( globals );
|
2009-12-21 07:36:04 +01:00
|
|
|
|
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
if ( !globals->appPrefs.fullScreen ) {
|
|
|
|
/* For some reason a Treo700w crashes on exit if not in full-screen
|
|
|
|
mode. Dunno if it's a bug in the software on that device or in
|
|
|
|
Wince 5.0 or my code, but going into fullscreen mode (after saving
|
|
|
|
prefs so it doesn't stick) fixes it. Need to track down why, what
|
|
|
|
part of the mode change matters. So far I know I can't remove
|
|
|
|
cePositionBoard()... */
|
|
|
|
#if 0
|
|
|
|
globals->appPrefs.fullScreen = !globals->appPrefs.fullScreen;
|
|
|
|
ceSizeIfFullscreen( globals, globals->hWnd );
|
|
|
|
(void)cePositionBoard( globals );
|
|
|
|
#else
|
|
|
|
ceToggleFullScreen( globals );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-13 03:17:13 +02:00
|
|
|
DestroyWindow(globals->hWnd);
|
|
|
|
} /* ceSaveAndExit */
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2008-08-01 12:47:32 +02:00
|
|
|
static void
|
|
|
|
closeGame( CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
game_dispose( &globals->game );
|
|
|
|
gi_disposePlayerInfo( MPPARM(globals->mpool) &globals->gameInfo );
|
|
|
|
|
2008-09-28 18:48:30 +02:00
|
|
|
if ( !!globals->curGameName ) {
|
2008-08-01 12:47:32 +02:00
|
|
|
XP_FREE( globals->mpool, globals->curGameName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-30 07:12:02 +02:00
|
|
|
static void
|
|
|
|
freeGlobals( CEAppGlobals* globals )
|
|
|
|
{
|
2008-10-29 09:46:02 +01:00
|
|
|
XP_U16 ii;
|
2006-05-30 07:12:02 +02:00
|
|
|
MPSLOT;
|
|
|
|
|
|
|
|
MPASSIGN( mpool, globals->mpool );
|
|
|
|
|
2008-09-01 17:10:28 +02:00
|
|
|
draw_destroyCtxt( (DrawCtx*)globals->draw );
|
2006-05-30 07:12:02 +02:00
|
|
|
|
2008-08-01 12:47:32 +02:00
|
|
|
closeGame( globals );
|
2006-05-30 07:12:02 +02:00
|
|
|
|
2009-03-08 21:01:47 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2009-02-07 19:20:16 +01:00
|
|
|
if ( !!globals->socketWrap ) {
|
|
|
|
ce_sockwrap_delete( globals->socketWrap );
|
|
|
|
globals->socketWrap = NULL;
|
|
|
|
}
|
2009-03-08 21:01:47 +01:00
|
|
|
WSACleanup();
|
2009-12-21 07:43:21 +01:00
|
|
|
|
2009-12-23 07:01:26 +01:00
|
|
|
# if defined _WIN32_WCE && ! defined CEGCC_DOES_CONNMGR
|
2009-12-21 07:43:21 +01:00
|
|
|
if ( !!globals->hcellDll ) {
|
|
|
|
FreeLibrary( globals->hcellDll );
|
|
|
|
globals->hcellDll = NULL;
|
|
|
|
}
|
|
|
|
# endif
|
2009-03-08 21:01:47 +01:00
|
|
|
#endif
|
2009-02-07 19:20:16 +01:00
|
|
|
|
2006-05-30 07:12:02 +02:00
|
|
|
if ( !!globals->vtMgr ) {
|
|
|
|
vtmgr_destroy( MPPARM(mpool) globals->vtMgr );
|
|
|
|
}
|
|
|
|
if ( !!globals->util.vtable ) {
|
|
|
|
XP_FREE( mpool, globals->util.vtable );
|
|
|
|
}
|
2008-10-29 09:46:02 +01:00
|
|
|
for ( ii = 0; ii < N_CACHED_PATHS; ++ii ) {
|
|
|
|
if ( !!globals->specialDirs[ii] ) {
|
|
|
|
XP_FREE( mpool, globals->specialDirs[ii] );
|
|
|
|
}
|
2008-10-25 20:08:36 +02:00
|
|
|
}
|
2006-05-30 07:12:02 +02:00
|
|
|
|
2009-04-09 15:48:38 +02:00
|
|
|
ceFreeResStrings( globals );
|
2009-04-14 05:33:46 +02:00
|
|
|
if ( globals->locInst != globals->hInst ) {
|
|
|
|
ceCloseResFile( globals->locInst );
|
|
|
|
}
|
|
|
|
if ( globals->langFileName != NULL ) {
|
|
|
|
XP_FREE( globals->mpool, globals->langFileName );
|
|
|
|
globals->langFileName = NULL;
|
|
|
|
}
|
2009-04-09 15:48:38 +02:00
|
|
|
|
2006-05-30 07:12:02 +02:00
|
|
|
XP_FREE( globals->mpool, globals );
|
|
|
|
mpool_destroy( mpool );
|
|
|
|
} /* freeGlobals */
|
|
|
|
|
2006-05-12 09:17:35 +02:00
|
|
|
#ifdef _WIN32_WCE
|
2004-12-17 08:45:30 +01:00
|
|
|
static HWND
|
|
|
|
makeCommandBar( HWND hwnd, HINSTANCE hInst )
|
|
|
|
{
|
|
|
|
SHMENUBARINFO mbi;
|
2009-04-19 19:33:39 +02:00
|
|
|
HWND result = NULL;
|
2004-12-17 08:45:30 +01:00
|
|
|
|
2006-02-06 05:41:14 +01:00
|
|
|
XP_MEMSET( &mbi, 0, sizeof(mbi) );
|
|
|
|
mbi.cbSize = sizeof(mbi);
|
2004-12-17 08:45:30 +01:00
|
|
|
mbi.hwndParent = hwnd;
|
2008-02-05 05:57:58 +01:00
|
|
|
mbi.nToolBarId = IDM_MAIN_MENUBAR;
|
2004-12-17 08:45:30 +01:00
|
|
|
mbi.hInstRes = hInst;
|
2008-02-05 05:57:58 +01:00
|
|
|
/* Don't set dwFlags if you want the Wince5 two-button softkey menu. */
|
|
|
|
/* mbi.dwFlags = SHCMBF_HMENU; */
|
2008-01-20 16:36:17 +01:00
|
|
|
|
2005-06-13 16:29:49 +02:00
|
|
|
//mbi.dwFlags = SHCMBF_HIDESIPBUTTON; /* eeh added. Why??? */
|
2004-12-17 08:45:30 +01:00
|
|
|
|
2009-04-19 19:33:39 +02:00
|
|
|
if ( SHCreateMenuBar(&mbi) ) {
|
|
|
|
result = mbi.hwndMB;
|
|
|
|
} else {
|
2008-01-20 16:36:17 +01:00
|
|
|
/* will want to use this to change menubar: SHEnableSoftkey? */
|
2004-12-17 08:45:30 +01:00
|
|
|
XP_LOGF( "SHCreateMenuBar failed" );
|
|
|
|
}
|
|
|
|
|
2009-04-19 19:33:39 +02:00
|
|
|
return result;
|
2004-12-17 08:45:30 +01:00
|
|
|
} /* makeCommandBar */
|
2006-05-12 09:17:35 +02:00
|
|
|
#endif
|
2004-12-17 08:45:30 +01:00
|
|
|
|
2005-02-05 22:43:16 +01:00
|
|
|
#ifdef CEFEATURE_CANSCROLL
|
|
|
|
static XP_Bool
|
|
|
|
handleScroll( CEAppGlobals* globals, XP_S16 pos, /* only valid for THUMB* */
|
|
|
|
XP_S16 code, HWND wnd )
|
|
|
|
{
|
|
|
|
XP_Bool result = XP_FALSE;
|
|
|
|
|
|
|
|
if ( wnd == globals->scrollHandle ) {
|
|
|
|
XP_U16 curYOffset = board_getYOffset( globals->game.board );
|
2008-09-28 19:50:04 +02:00
|
|
|
XP_S16 newOffset = curYOffset;
|
2005-02-05 22:43:16 +01:00
|
|
|
|
|
|
|
XP_ASSERT( !!globals->game.board );
|
|
|
|
|
|
|
|
switch ( code ) {
|
|
|
|
/* case SB_BOTTOM: // Scrolls to the lower right */
|
|
|
|
/* case SB_ENDSCROLL: // Ends scroll */
|
|
|
|
|
|
|
|
case SB_LINEUP: // Scrolls one line up
|
|
|
|
case SB_PAGEUP: //
|
2008-09-28 19:50:04 +02:00
|
|
|
--newOffset;
|
2005-02-05 22:43:16 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SB_LINEDOWN: // Scrolls one line down
|
|
|
|
case SB_PAGEDOWN: // Scrolls one page down
|
2008-09-28 19:50:04 +02:00
|
|
|
++newOffset;
|
2005-02-05 22:43:16 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SB_THUMBTRACK: /* still dragging; don't redraw */
|
|
|
|
case SB_THUMBPOSITION:
|
|
|
|
newOffset = pos;
|
|
|
|
default:
|
2008-09-28 19:50:04 +02:00
|
|
|
break;
|
|
|
|
/* do nothing: leave newOffset == curYOffset */
|
2005-02-05 22:43:16 +01:00
|
|
|
}
|
|
|
|
|
2008-04-08 05:55:53 +02:00
|
|
|
result = curYOffset != newOffset
|
|
|
|
&& board_setYOffset( globals->game.board, newOffset );
|
2005-02-05 22:43:16 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} /* handleScroll */
|
|
|
|
#endif
|
|
|
|
|
2008-03-31 02:25:18 +02:00
|
|
|
static XP_Bool
|
2005-06-23 16:09:20 +02:00
|
|
|
ceFireTimer( CEAppGlobals* globals, XWTimerReason why )
|
|
|
|
{
|
2008-03-31 02:25:18 +02:00
|
|
|
XP_Bool draw = XP_FALSE;
|
2009-09-21 14:49:08 +02:00
|
|
|
TimerData* timer = &globals->timerData[why];
|
|
|
|
XWTimerProc proc = timer->proc;
|
2005-08-21 16:07:29 +02:00
|
|
|
|
2008-02-16 18:36:46 +01:00
|
|
|
if ( !!proc ) {
|
2009-09-21 14:49:08 +02:00
|
|
|
timer->proc = NULL;
|
|
|
|
draw = (*proc)( timer->closure, why );
|
2008-03-31 02:25:18 +02:00
|
|
|
/* Setting draw after firing timer allows scrolling to happen
|
|
|
|
while pen is held down. This is a hack. Perhaps having
|
|
|
|
the timer proc return whether drawing is needed would be
|
|
|
|
more consistent. */
|
2008-02-16 18:36:46 +01:00
|
|
|
} else {
|
|
|
|
XP_LOGF( "skipped timer; alread fired?" );
|
|
|
|
}
|
2008-03-31 02:25:18 +02:00
|
|
|
return draw;
|
2005-08-21 16:07:29 +02:00
|
|
|
} /* ceFireTimer */
|
2005-06-23 16:09:20 +02:00
|
|
|
|
2008-02-16 18:36:46 +01:00
|
|
|
/* WM_TIMER messages are low-priority. Hold a key down and key events will
|
|
|
|
* crowd it out of the queue so that the app doesn't see it until the key is
|
|
|
|
* released. There are more reliable timers, but they seem to require
|
|
|
|
* advanced techniques like semaphores. At least one article recommends
|
|
|
|
* polling over going to those lengths. This is better that polling. I hope
|
|
|
|
* it's enough.
|
|
|
|
*/
|
|
|
|
static XP_Bool
|
|
|
|
checkFireLateKeyTimer( CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
XP_Bool drop = XP_FALSE;
|
2009-09-21 14:49:08 +02:00
|
|
|
XWTimerReason why;
|
2008-02-16 18:36:46 +01:00
|
|
|
XP_U32 now = GetCurrentTime();
|
|
|
|
|
2009-09-21 14:49:08 +02:00
|
|
|
for ( why = 1; why < NUM_TIMERS_PLUS_ONE; ++why ) {
|
|
|
|
TimerData* timer = &globals->timerData[why];
|
|
|
|
if ( !!timer->proc && now >= timer->when ) {
|
|
|
|
(void)ceFireTimer( globals, why );
|
|
|
|
drop = XP_TRUE;
|
2008-02-16 18:36:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return drop;
|
|
|
|
} /* checkFireLateKeyTimer */
|
|
|
|
|
2006-07-07 10:39:31 +02:00
|
|
|
static XP_Bool
|
|
|
|
checkPenDown( CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
XP_Bool draw = globals->penDown;
|
|
|
|
if ( draw ) {
|
|
|
|
draw = board_handlePenUp( globals->game.board, 0x7FFF, 0x7FFF );
|
|
|
|
globals->penDown = XP_FALSE;
|
|
|
|
}
|
|
|
|
return draw;
|
|
|
|
} /* checkPenDown */
|
|
|
|
|
2007-01-19 09:24:02 +01:00
|
|
|
#ifdef KEYBOARD_NAV
|
|
|
|
|
|
|
|
static XP_Bool
|
2008-02-16 18:36:46 +01:00
|
|
|
ceCheckHandleFocusKey( CEAppGlobals* globals, WPARAM wParam, LPARAM lParam,
|
|
|
|
XP_Bool keyDown, XP_Bool* handledP )
|
2007-01-19 09:24:02 +01:00
|
|
|
{
|
2008-02-16 18:36:46 +01:00
|
|
|
XP_Bool draw = XP_FALSE;
|
2007-01-19 09:24:02 +01:00
|
|
|
|
2008-10-31 05:36:44 +01:00
|
|
|
/* Sometimes, e.g. after a menu is released, we get KEY_UP not preceeded
|
|
|
|
by KEY_DOWN. Just drop those. */
|
|
|
|
if ( !keyDown && !globals->keyDown ) {
|
2009-12-23 07:01:26 +01:00
|
|
|
/* drop key; don't log as it happens all the time */
|
2008-10-31 05:36:44 +01:00
|
|
|
} else {
|
|
|
|
XP_Bool isRepeat = keyDown && ((HIWORD(lParam) & KF_REPEAT) != 0);
|
|
|
|
XP_Key key;
|
|
|
|
XP_S16 incr = 0;
|
|
|
|
|
|
|
|
switch ( wParam ) {
|
|
|
|
case VK_UP:
|
|
|
|
key = XP_CURSOR_KEY_UP;
|
|
|
|
incr = -1;
|
|
|
|
break;
|
|
|
|
case VK_RIGHT:
|
|
|
|
key = XP_CURSOR_KEY_RIGHT;
|
|
|
|
incr = 1;
|
|
|
|
break;
|
|
|
|
case VK_DOWN:
|
|
|
|
key = XP_CURSOR_KEY_DOWN;
|
|
|
|
incr = 1;
|
|
|
|
break;
|
|
|
|
case VK_LEFT:
|
|
|
|
key = XP_CURSOR_KEY_LEFT;
|
|
|
|
incr = -1;
|
|
|
|
break;
|
|
|
|
case 0x0d:
|
|
|
|
case 0x5d: /* center key on WinMo5 Treo (at least) -- but also ']'*/
|
|
|
|
case VK_HOME:
|
2008-01-20 16:36:17 +01:00
|
|
|
key = XP_RETURN_KEY;
|
2008-02-16 18:36:46 +01:00
|
|
|
if ( isRepeat ) {
|
|
|
|
(void)checkFireLateKeyTimer( globals );
|
|
|
|
}
|
2008-01-20 16:36:17 +01:00
|
|
|
break;
|
2007-01-19 09:24:02 +01:00
|
|
|
|
2008-02-16 18:36:46 +01:00
|
|
|
/* Still need to produce these somehow */
|
2008-10-31 05:36:44 +01:00
|
|
|
/* XP_CURSOR_KEY_ALTRIGHT, */
|
|
|
|
/* XP_CURSOR_KEY_ALTUP, */
|
|
|
|
/* XP_CURSOR_KEY_ALTLEFT, */
|
|
|
|
/* XP_CURSOR_KEY_ALTDOWN, */
|
2007-01-19 09:24:02 +01:00
|
|
|
|
2008-10-31 05:36:44 +01:00
|
|
|
default:
|
|
|
|
key = XP_KEY_NONE;
|
|
|
|
break;
|
2008-02-16 18:36:46 +01:00
|
|
|
}
|
|
|
|
|
2008-10-31 05:36:44 +01:00
|
|
|
if ( key != XP_KEY_NONE ) {
|
|
|
|
BoardCtxt* board = globals->game.board;
|
|
|
|
|
|
|
|
if ( isRepeat ) {
|
|
|
|
draw = board_handleKeyRepeat( board, key, handledP );
|
|
|
|
} else if ( keyDown ) {
|
|
|
|
draw = board_handleKeyDown( board, key, handledP );
|
2008-09-28 19:50:04 +02:00
|
|
|
} else {
|
2008-10-31 05:36:44 +01:00
|
|
|
draw = board_handleKeyUp( board, key, handledP );
|
2008-09-28 19:50:04 +02:00
|
|
|
}
|
|
|
|
|
2008-10-31 05:36:44 +01:00
|
|
|
if ( !*handledP && incr != 0 && !keyDown ) {
|
|
|
|
BoardObjectType orderScroll[] = {
|
|
|
|
OBJ_SCORE, OBJ_BOARD, OBJ_NONE, OBJ_TRAY };
|
|
|
|
BoardObjectType orderNoScroll[] = {
|
|
|
|
OBJ_SCORE, OBJ_BOARD, OBJ_TRAY };
|
|
|
|
BoardObjectType* order;
|
|
|
|
XP_U16 orderLen;
|
|
|
|
BoardObjectType cur = board_getFocusOwner( board );
|
|
|
|
XP_U16 index = 0;
|
|
|
|
|
|
|
|
if ( !!globals->scrollHandle ) {
|
|
|
|
order = orderScroll;
|
|
|
|
orderLen = VSIZE(orderScroll);
|
|
|
|
} else {
|
|
|
|
order = orderNoScroll;
|
|
|
|
orderLen = VSIZE(orderNoScroll);
|
2007-01-19 09:24:02 +01:00
|
|
|
}
|
2008-10-31 05:36:44 +01:00
|
|
|
|
|
|
|
if ( !!globals->scrollHandle || (cur != OBJ_NONE) ) {
|
|
|
|
for ( ; ; ) {
|
|
|
|
if ( order[index] == cur ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++index;
|
|
|
|
XP_ASSERT( index < orderLen );
|
|
|
|
}
|
|
|
|
index = (index + orderLen + incr) % orderLen;
|
2008-09-28 19:50:04 +02:00
|
|
|
}
|
2008-10-31 05:36:44 +01:00
|
|
|
draw = board_focusChanged( board, order[index], XP_TRUE );
|
|
|
|
|
|
|
|
if ( !!globals->scrollHandle ) {
|
|
|
|
XP_Bool scrollerHasFocus = globals->scrollerHasFocus;
|
|
|
|
if ( order[index] == OBJ_NONE ) {
|
|
|
|
XP_ASSERT( !scrollerHasFocus );
|
|
|
|
SetFocus( globals->scrollHandle );
|
|
|
|
scrollerHasFocus = XP_TRUE;
|
|
|
|
} else if ( scrollerHasFocus ) {
|
|
|
|
SetFocus( globals->hWnd );
|
|
|
|
scrollerHasFocus = XP_FALSE;
|
|
|
|
}
|
|
|
|
if ( scrollerHasFocus != globals->scrollerHasFocus ) {
|
|
|
|
globals->scrollerHasFocus = scrollerHasFocus;
|
2008-10-07 06:00:37 +02:00
|
|
|
#ifdef _WIN32_WCE
|
2008-10-31 05:36:44 +01:00
|
|
|
InvalidateRect( globals->hWnd, &globals->scrollRects[0], FALSE );
|
|
|
|
InvalidateRect( globals->hWnd, &globals->scrollRects[1], FALSE );
|
2008-10-07 06:00:37 +02:00
|
|
|
#else
|
2008-10-31 05:36:44 +01:00
|
|
|
InvalidateRect( globals->scrollHandle, NULL, FALSE );
|
2008-10-07 06:00:37 +02:00
|
|
|
#endif
|
2008-10-31 05:36:44 +01:00
|
|
|
}
|
2008-10-09 14:12:25 +02:00
|
|
|
}
|
2008-09-28 19:50:04 +02:00
|
|
|
}
|
2007-01-19 09:24:02 +01:00
|
|
|
}
|
|
|
|
}
|
2008-10-31 05:36:44 +01:00
|
|
|
globals->keyDown = keyDown;
|
2007-01-19 09:24:02 +01:00
|
|
|
return draw;
|
2008-02-16 18:36:46 +01:00
|
|
|
} /* ceCheckHandleFocusKey */
|
2007-01-19 09:24:02 +01:00
|
|
|
#endif /* KEYBOARD_NAV */
|
|
|
|
|
2008-02-16 18:36:46 +01:00
|
|
|
static void
|
|
|
|
ceToggleFullScreen( CEAppGlobals* globals )
|
|
|
|
{
|
|
|
|
globals->appPrefs.fullScreen = !globals->appPrefs.fullScreen;
|
|
|
|
|
2008-03-15 16:39:58 +01:00
|
|
|
ceSizeIfFullscreen( globals, globals->hWnd );
|
2008-01-20 16:36:17 +01:00
|
|
|
|
|
|
|
(void)cePositionBoard( globals );
|
|
|
|
} /* ceToggleFullScreen */
|
|
|
|
|
2008-03-15 20:24:59 +01:00
|
|
|
static void
|
|
|
|
doAbout( CEAppGlobals* globals )
|
|
|
|
{
|
2008-06-13 07:25:20 +02:00
|
|
|
wchar_t buf[1024];
|
2009-04-11 17:45:59 +02:00
|
|
|
(void)LoadString( globals->locInst, (UINT)IDS_ABOUT, buf, VSIZE(buf) );
|
2008-12-07 06:21:13 +01:00
|
|
|
assertOnTop( globals->hWnd );
|
2009-04-11 17:45:59 +02:00
|
|
|
MessageBox( globals->hWnd, buf, ceGetResStringL( globals, IDS_ABOUT_L ),
|
2008-12-07 17:24:26 +01:00
|
|
|
MB_OK | MB_ICONINFORMATION );
|
2008-03-15 20:24:59 +01:00
|
|
|
}
|
|
|
|
|
2009-12-21 16:31:06 +01:00
|
|
|
#ifdef _WIN32_WCE
|
2009-12-21 07:43:21 +01:00
|
|
|
static void
|
|
|
|
connEvtAndError( CEAppGlobals* globals, WPARAM wParam )
|
|
|
|
{
|
|
|
|
ConnMgrErr userErr;
|
|
|
|
ce_connmgr_event( globals->socketWrap, wParam, &userErr );
|
|
|
|
switch( userErr ) {
|
|
|
|
case CONN_ERR_NONE:
|
|
|
|
break;
|
|
|
|
case CONN_ERR_PHONE_OFF:
|
2009-12-27 03:54:30 +01:00
|
|
|
ceOopsId( globals, IDS_PHONE_OFF, SAB_PHONEOFF );
|
2009-12-21 07:43:21 +01:00
|
|
|
break;
|
|
|
|
case CONN_ERR_NONET:
|
2009-12-27 03:54:30 +01:00
|
|
|
ceOopsId( globals, IDS_NETWORK_FAILED, SAB_NETFAILED );
|
2009-12-21 07:43:21 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-12-21 16:31:06 +01:00
|
|
|
#endif
|
2009-12-21 07:43:21 +01:00
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
LRESULT CALLBACK
|
|
|
|
WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2008-02-16 18:36:46 +01:00
|
|
|
LRESULT result = 0;
|
2006-07-07 10:39:31 +02:00
|
|
|
int wmId;
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_Bool draw = XP_FALSE;
|
|
|
|
XWTimerReason why;
|
|
|
|
CEAppGlobals* globals;
|
2008-06-01 00:07:29 +02:00
|
|
|
XP_Bool handled = XP_FALSE;
|
2008-02-16 18:36:46 +01:00
|
|
|
XP_Bool callDefault = XP_FALSE;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
if ( message == WM_CREATE ) {
|
|
|
|
globals = ((CREATESTRUCT*)lParam)->lpCreateParams;
|
2008-09-28 19:50:04 +02:00
|
|
|
SetWindowLongPtr( hWnd, GWL_USERDATA, (long)globals );
|
2006-02-06 05:41:14 +01:00
|
|
|
#ifdef _WIN32_WCE
|
2009-04-11 17:45:59 +02:00
|
|
|
globals->hwndCB = makeCommandBar( hWnd, globals->locInst );
|
2005-11-27 21:16:43 +01:00
|
|
|
#endif
|
2005-06-13 16:29:49 +02:00
|
|
|
|
2006-02-17 08:30:54 +01:00
|
|
|
#ifdef _WIN32_WCE
|
2005-06-13 16:29:49 +02:00
|
|
|
globals->sai.cbSize = sizeof(globals->sai);
|
2005-11-27 21:16:43 +01:00
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
} else {
|
2008-02-16 18:36:46 +01:00
|
|
|
/* XP_LOGF( "%s: event=%s (%d)", __func__, messageToStr(message), message ); */
|
2008-09-28 19:50:04 +02:00
|
|
|
globals = (CEAppGlobals*)GetWindowLongPtr( hWnd, GWL_USERDATA );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
switch (message) {
|
2004-12-17 08:45:30 +01:00
|
|
|
|
2006-02-17 08:30:54 +01:00
|
|
|
#ifdef _WIN32_WCE
|
2004-12-17 08:45:30 +01:00
|
|
|
case WM_ACTIVATE:
|
|
|
|
// Notify shell of our activate message
|
|
|
|
SHHandleWMActivate( hWnd, wParam, lParam, &globals->sai, FALSE );
|
2009-12-23 07:01:26 +01:00
|
|
|
if ( !!globals && !!globals->game.board ) {
|
|
|
|
if ( ceSizeIfFullscreen( globals, globals->hWnd ) ) {
|
|
|
|
(void)cePositionBoard( globals );
|
|
|
|
}
|
|
|
|
}
|
2004-12-17 08:45:30 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_SETTINGCHANGE:
|
|
|
|
SHHandleWMSettingChange( hWnd, wParam, lParam, &globals->sai );
|
2006-04-02 23:52:15 +02:00
|
|
|
if ( !!globals && !!globals->game.model ) {
|
|
|
|
cePositionBoard( globals );
|
|
|
|
board_invalAll( globals->game.board );
|
|
|
|
draw = XP_TRUE;
|
|
|
|
}
|
2004-12-17 08:45:30 +01:00
|
|
|
break;
|
2008-01-20 16:36:17 +01:00
|
|
|
#endif
|
2004-12-17 08:45:30 +01:00
|
|
|
|
2005-02-05 22:43:16 +01:00
|
|
|
#ifdef CEFEATURE_CANSCROLL
|
2008-10-07 06:00:37 +02:00
|
|
|
# ifndef _WIN32_WCE
|
|
|
|
/* WM_CTLCOLORSCROLLBAR aren't delivered on CE. Some say can
|
|
|
|
* work around using WM_PAINT or WM_ERASEBKGND but no luck
|
|
|
|
* yet. */
|
|
|
|
case WM_CTLCOLORSCROLLBAR:
|
|
|
|
if ( (HWND)lParam == globals->scrollHandle ) {
|
|
|
|
if ( globals->scrollerHasFocus ) {
|
|
|
|
return (LRESULT)ce_draw_getFocusBrush( globals->draw );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
# endif
|
2005-02-05 22:43:16 +01:00
|
|
|
case WM_VSCROLL:
|
2006-07-07 10:39:31 +02:00
|
|
|
draw = checkPenDown( globals );
|
2005-02-05 22:43:16 +01:00
|
|
|
draw = handleScroll( globals, (short int)HIWORD(wParam),
|
|
|
|
(short int)LOWORD(wParam),
|
2006-07-07 10:39:31 +02:00
|
|
|
(HWND)lParam ) || draw;
|
2005-02-05 22:43:16 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
case WM_COMMAND:
|
2006-07-07 10:39:31 +02:00
|
|
|
(void)checkPenDown( globals );
|
|
|
|
wmId = LOWORD(wParam);
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
// Parse the menu selections:
|
|
|
|
switch (wmId) {
|
|
|
|
case ID_FILE_ABOUT:
|
2008-03-15 20:24:59 +01:00
|
|
|
doAbout( globals );
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
2009-04-19 19:33:39 +02:00
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
case ID_GAME_GAMEINFO: {
|
2009-10-17 05:38:37 +02:00
|
|
|
GInfoResults results;
|
|
|
|
CePrefsPrefs prefsPrefs;
|
|
|
|
XP_UCHAR dictName[CE_MAX_PATH_LEN+1];
|
|
|
|
|
2009-12-04 10:09:07 +01:00
|
|
|
if ( WrapGameInfoDialog( globals, GI_INFO_ONLY, &prefsPrefs,
|
2009-10-17 05:38:37 +02:00
|
|
|
dictName, VSIZE(dictName),
|
|
|
|
&results ) ) {
|
|
|
|
if ( results.prefsChanged ) {
|
2004-04-14 06:00:28 +02:00
|
|
|
updateForColors( globals );
|
2009-10-02 07:48:48 +02:00
|
|
|
}
|
2009-10-17 05:38:37 +02:00
|
|
|
if ( results.langChanged ) {
|
2009-10-02 07:48:48 +02:00
|
|
|
ceWarnLangChange( globals );
|
2006-06-15 14:39:54 +02:00
|
|
|
}
|
|
|
|
draw = server_do( globals->game.server );
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
2004-04-14 06:00:28 +02:00
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_FILE_NEWGAME:
|
2004-01-10 19:11:28 +01:00
|
|
|
XP_LOGF( "ID_FILE_NEWGAME" );
|
|
|
|
if ( ceSaveCurGame( globals, XP_FALSE )
|
2009-04-11 17:45:59 +02:00
|
|
|
|| queryBoxChar( globals, hWnd,
|
|
|
|
ceGetResString( globals,
|
|
|
|
IDS_OVERWRITE ) ) ) {
|
2009-12-04 10:09:07 +01:00
|
|
|
draw = ceDoNewGame( globals, GI_NEW_GAME );
|
2004-01-10 19:11:28 +01:00
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_FILE_SAVEDGAMES:
|
|
|
|
ceChooseAndOpen( globals );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_FILE_PREFERENCES:
|
|
|
|
ceDoPrefsDlg( globals );
|
|
|
|
break;
|
2008-01-20 16:36:17 +01:00
|
|
|
case ID_FILE_FULLSCREEN:
|
|
|
|
ceToggleFullScreen( globals );
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
case ID_GAME_FINALSCORES:
|
|
|
|
if ( server_getGameIsOver( globals->game.server ) ) {
|
|
|
|
ceDisplayFinalScores( globals );
|
2009-04-11 17:45:59 +02:00
|
|
|
} else if ( queryBoxChar( globals, hWnd,
|
|
|
|
ceGetResString( globals,
|
|
|
|
IDS_ENDNOW ) ) ) {
|
2003-11-20 17:26:35 +01:00
|
|
|
server_endGame( globals->game.server );
|
|
|
|
draw = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-09-11 09:44:27 +02:00
|
|
|
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
|
|
|
case ID_GAME_RESENDMSGS:
|
|
|
|
if ( !!globals->game.comms ) {
|
|
|
|
(void)comms_resendAll( globals->game.comms );
|
|
|
|
} else {
|
2009-12-27 03:54:30 +01:00
|
|
|
ceOopsId( globals, IDS_RESEND_STANDALONE, SAB_NONE );
|
2009-09-11 09:44:27 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
case ID_GAME_TILECOUNTSANDVALUES:
|
|
|
|
ceCountsAndValues( globals );
|
|
|
|
break;
|
|
|
|
|
2004-11-09 03:40:36 +01:00
|
|
|
case ID_GAME_TILESLEFT:
|
|
|
|
ceTilesLeft( globals );
|
|
|
|
break;
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
case ID_GAME_HISTORY:
|
|
|
|
ceDoHistory( globals );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_MOVE_TRADE:
|
|
|
|
draw = handleTradeCmd( globals );
|
|
|
|
break;
|
|
|
|
case ID_MOVE_JUGGLE:
|
|
|
|
draw = handleJuggleCmd( globals );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_MOVE_HIDETRAY:
|
|
|
|
draw = handleHidetrayCmd( globals );
|
|
|
|
break;
|
|
|
|
case ID_MOVE_TURNDONE:
|
|
|
|
draw = handleDoneCmd( globals);
|
|
|
|
break;
|
|
|
|
|
2006-07-07 10:39:31 +02:00
|
|
|
case ID_MOVE_FLIP:
|
2003-11-20 17:26:35 +01:00
|
|
|
draw = board_flip( globals->game.board );
|
2008-11-10 19:49:26 +01:00
|
|
|
ceCheckMenus( globals );
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
2008-01-20 16:36:17 +01:00
|
|
|
case ID_MOVE_VALUES:
|
2003-11-20 17:26:35 +01:00
|
|
|
draw = board_toggle_showValues( globals->game.board );
|
2008-12-03 14:40:07 +01:00
|
|
|
ceSetLeftSoftkey( globals, ID_MOVE_VALUES );
|
2008-11-10 19:49:26 +01:00
|
|
|
ceCheckMenus( globals );
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_MOVE_HINT:
|
2004-07-10 19:46:36 +02:00
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
case ID_MOVE_LIMITEDHINT:
|
|
|
|
globals->askTrayLimits = wmId == ID_MOVE_LIMITEDHINT;
|
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
board_resetEngine( globals->game.board );
|
2004-07-10 19:46:36 +02:00
|
|
|
/* fallthru */
|
2003-11-20 17:26:35 +01:00
|
|
|
case ID_MOVE_NEXTHINT:
|
|
|
|
draw = ceHandleHintRequest( globals );
|
|
|
|
break;
|
|
|
|
|
2008-02-05 05:57:58 +01:00
|
|
|
case ID_FILE_EXIT:
|
2008-10-13 03:17:13 +02:00
|
|
|
ceSaveAndExit( globals ); /* autosaves; no user interaction */
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_MOVE_UNDOCURRENT:
|
|
|
|
draw = board_replaceTiles( globals->game.board );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_MOVE_UNDOLAST:
|
|
|
|
draw = server_handleUndo( globals->game.server );
|
2009-10-24 17:12:45 +02:00
|
|
|
ceSetLeftSoftkey( globals, ID_MOVE_UNDOLAST );
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-02-16 18:36:46 +01:00
|
|
|
callDefault = XP_TRUE;
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_PAINT:
|
2008-05-25 17:08:03 +02:00
|
|
|
if ( !!globals ) {
|
|
|
|
RECT winrect;
|
|
|
|
if ( GetUpdateRect( hWnd, &winrect, FALSE ) ) {
|
|
|
|
if ( !!globals->game.board ) {
|
2008-09-18 05:50:04 +02:00
|
|
|
XP_Rect xprect;
|
2008-05-25 17:08:03 +02:00
|
|
|
/* When an obscuring window goes away, the update region
|
|
|
|
needs to be redrawn. This allows invalidating it. */
|
|
|
|
|
2008-09-18 05:50:04 +02:00
|
|
|
RECTtoXPR( &xprect, &winrect );
|
|
|
|
board_invalRect( globals->game.board, &xprect );
|
2008-05-25 17:08:03 +02:00
|
|
|
|
|
|
|
XP_ASSERT( globals->hWnd == hWnd );
|
2008-09-01 17:10:28 +02:00
|
|
|
drawInsidePaint( globals, &winrect );
|
2008-05-25 17:08:03 +02:00
|
|
|
}
|
|
|
|
if ( !ValidateRect( hWnd, &winrect ) ) {
|
|
|
|
logLastError( "WM_PAINT:ValidateRect" );
|
|
|
|
}
|
2004-02-12 05:35:10 +01:00
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_LBUTTONDOWN:
|
2006-07-07 10:39:31 +02:00
|
|
|
draw = checkPenDown( globals );
|
2003-11-20 17:26:35 +01:00
|
|
|
globals->penDown = XP_TRUE;
|
|
|
|
draw = board_handlePenDown( globals->game.board, LOWORD(lParam),
|
2006-07-07 10:39:31 +02:00
|
|
|
HIWORD(lParam), &handled )
|
|
|
|
|| draw;
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
if ( globals->penDown ) {
|
|
|
|
draw = board_handlePenMove( globals->game.board,
|
|
|
|
LOWORD(lParam),
|
|
|
|
HIWORD(lParam) );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
if ( globals->penDown ) {
|
|
|
|
draw = board_handlePenUp( globals->game.board, LOWORD(lParam),
|
2006-07-01 16:22:09 +02:00
|
|
|
HIWORD(lParam) );
|
2003-11-20 17:26:35 +01:00
|
|
|
globals->penDown = XP_FALSE;
|
|
|
|
}
|
2008-06-01 00:07:29 +02:00
|
|
|
break;
|
|
|
|
|
2008-10-13 03:17:13 +02:00
|
|
|
#ifdef OVERRIDE_BACKKEY
|
2008-06-01 00:07:29 +02:00
|
|
|
/* Make the back key mean raise focus, but only if dived.
|
|
|
|
Otherwise allow the OS to do what it wants. Which means
|
|
|
|
exit? */
|
|
|
|
case WM_HOTKEY:
|
2008-10-13 03:17:13 +02:00
|
|
|
if ( (VK_TBACK == HIWORD(lParam)) && !!globals->game.board ) {
|
|
|
|
draw = board_handleKey( globals->game.board,
|
|
|
|
XP_RAISEFOCUS_KEY, &handled );
|
|
|
|
if ( !draw && !handled
|
|
|
|
/* Hack alert. Winders sends two WM_HOTKEY events per
|
|
|
|
press of the key. (lParam isn't well documented for
|
|
|
|
this event, but likely they're down and up.)
|
|
|
|
Unfiltered, the first raises focus and the second
|
|
|
|
exits the app. Bad. So we'll only raise if the
|
|
|
|
first was not handled. Note that this may well break
|
|
|
|
on devices I haven't tested on, later, whenever. */
|
2008-10-18 21:38:31 +02:00
|
|
|
&& (0 == (BACK_KEY_UP_MAYBE & LOWORD(lParam))) ) {
|
2008-10-13 03:17:13 +02:00
|
|
|
XP_LOGF( "calling ceSaveAndExit for VK_TBACK" );
|
|
|
|
/* I'm actually exiting the app rather than minimize. As
|
|
|
|
it stands, minimizing means that even if I relaunch
|
|
|
|
the app and quit properly I can't delete the .exe,
|
|
|
|
suggesting that the minimized guy isn't getting
|
|
|
|
reassociated when I relaunch. Until I fix that
|
|
|
|
exiting is best.
|
|
|
|
*/
|
|
|
|
ceSaveAndExit( globals );
|
|
|
|
/* SHNavigateBack() is the right way to handle this, but
|
|
|
|
isn't available via cegcc yet. Others have suggested
|
|
|
|
this as well as ShowWindow( hWnd, SW_MINIMIZE );
|
|
|
|
or SetWindowPos( hWnd, &CWnd::wndBottom, 0, 0, 0, 0,
|
|
|
|
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
|
|
|
|
*/
|
2008-06-01 00:07:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2007-01-19 09:24:02 +01:00
|
|
|
#ifdef KEYBOARD_NAV
|
2008-01-20 16:36:17 +01:00
|
|
|
case WM_KEYDOWN:
|
2007-01-19 09:24:02 +01:00
|
|
|
case WM_KEYUP:
|
2008-02-16 18:36:46 +01:00
|
|
|
draw = ceCheckHandleFocusKey( globals, wParam, lParam,
|
|
|
|
message==WM_KEYDOWN, &handled );
|
2007-01-19 09:24:02 +01:00
|
|
|
break;
|
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
case WM_CHAR:
|
|
|
|
if ( wParam == 0x08 ) {
|
|
|
|
wParam = XP_CURSOR_KEY_DEL;
|
2007-01-19 09:24:02 +01:00
|
|
|
#ifdef KEYBOARD_NAV
|
|
|
|
} else if ( wParam == ' ' ) {
|
|
|
|
wParam = XP_RAISEFOCUS_KEY;
|
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
2007-01-19 09:24:02 +01:00
|
|
|
draw = board_handleKey( globals->game.board, wParam, &handled )
|
|
|
|
|| board_handleKey( globals->game.board, wParam - ('a'-'A'),
|
|
|
|
&handled );
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_TIMER:
|
|
|
|
why = (XWTimerReason)wParam;
|
2005-07-13 14:35:38 +02:00
|
|
|
if ( why == TIMER_PENDOWN || why == TIMER_TIMERTICK
|
2009-02-01 16:50:58 +01:00
|
|
|
#if defined XWFEATURE_RELAY || defined COMMS_HEARTBEAT
|
2009-02-01 17:20:18 +01:00
|
|
|
|| why == TIMER_COMMS
|
2005-07-13 14:35:38 +02:00
|
|
|
#endif
|
|
|
|
) {
|
2005-08-21 16:07:29 +02:00
|
|
|
XP_ASSERT( why < NUM_TIMERS_PLUS_ONE );
|
2005-06-23 16:09:20 +02:00
|
|
|
|
|
|
|
/* Kill since they otherwise repeat, but kill before firing
|
|
|
|
as fired proc may set another. */
|
2009-09-21 14:49:08 +02:00
|
|
|
(void)KillTimer( hWnd, globals->timerData[why].id );
|
2005-06-23 16:09:20 +02:00
|
|
|
|
2008-03-31 02:25:18 +02:00
|
|
|
draw = ceFireTimer( globals, why );
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-05-11 22:29:43 +02:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
/* case WM_SETFOCUS: */
|
|
|
|
/* hC = ImmGetContext( hWnd ); */
|
|
|
|
/* globals->imeWasOpen = ImmGetOpenStatus( hC ); */
|
|
|
|
/* ImmSetOpenStatus( hC, TRUE ); */
|
|
|
|
/* ImmEscape( NULL, hC, IME_ESC_SET_MODE, (LPVOID)IM_SPELL ); */
|
|
|
|
/* break; */
|
|
|
|
/* case WM_KILLFOCUS: */
|
|
|
|
/* ImmSetOpenStatus( hC, globals->imeWasOpen ); */
|
|
|
|
/* break; */
|
|
|
|
|
|
|
|
/* The code above this point works to turn 12-key->text
|
|
|
|
translation on, but not to turn it off, so other apps wind up
|
|
|
|
with it on after Crosswords quits. The recommended code is
|
2008-12-01 14:11:58 +01:00
|
|
|
below, but includes constants not in the version of cegcc I'm
|
2008-05-11 22:29:43 +02:00
|
|
|
using. Need to look into upgrading, but that requires a lot
|
|
|
|
of changes. Post B2.... */
|
|
|
|
|
|
|
|
/* DWORD dwRes = SendMessage((HWND)wParam, WM_IME_REQUEST, IMR_ISIMEAWARE, 0); */
|
|
|
|
/* hC = ImmGetContext( hWnd ); */
|
|
|
|
/* if ( (dwRes & IMEAF_AWARE) == IMEAF_AWARE ) { */
|
|
|
|
/* ImmEscape( NULL, hC, IME_ESC_RETAIN_MODE_ICON, (LPVOID)TRUE); */
|
|
|
|
/* } */
|
|
|
|
/* ImmSetOpenStatus( hC, FALSE); */
|
|
|
|
/* } */
|
|
|
|
/* break; */
|
|
|
|
/* case WM_IME_REQUEST: */
|
|
|
|
/* if ( wParam == IMR_ISIMEAWARE ) { */
|
|
|
|
/* return IMEAF_AWARE; */
|
|
|
|
/* } */
|
|
|
|
/* break; */
|
|
|
|
#endif
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
case WM_DESTROY:
|
2006-02-17 08:30:54 +01:00
|
|
|
#ifdef _WIN32_WCE
|
2004-06-25 09:19:05 +02:00
|
|
|
CommandBar_Destroy(globals->hwndCB); /* supposedly not needed */
|
2005-11-27 21:16:43 +01:00
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
PostQuitMessage(0);
|
2006-05-30 07:12:02 +02:00
|
|
|
freeGlobals( globals );
|
2009-12-18 05:24:55 +01:00
|
|
|
globals = NULL;
|
|
|
|
SetWindowLongPtr( hWnd, GWL_USERDATA, 0L );
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case XWWM_TIME_RQST:
|
2004-01-22 04:21:19 +01:00
|
|
|
draw = server_do( globals->game.server );
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
|
2008-10-24 11:05:13 +02:00
|
|
|
case XWWM_REM_SEL:
|
|
|
|
ceTilesLeft( globals );
|
|
|
|
break;
|
|
|
|
|
2009-12-04 10:09:07 +01:00
|
|
|
case XWWM_RELAY_REQ_NEW:
|
2009-12-14 05:12:20 +01:00
|
|
|
draw = ceDoNewGame( globals, GI_NEW_GAME );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XWWM_RELAY_REQ_CONN:
|
2009-12-04 10:09:07 +01:00
|
|
|
draw = ceDoNewGame( globals, GI_GOTO_CONNS );
|
|
|
|
break;
|
|
|
|
|
2005-07-30 04:02:49 +02:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2009-01-31 19:06:09 +01:00
|
|
|
case XWWM_HOSTNAME_ARRIVED:
|
2009-09-21 00:23:56 +02:00
|
|
|
/* drop it if we're standalone now */
|
|
|
|
if ( !!globals->socketWrap ) {
|
|
|
|
ce_sockwrap_hostname( globals->socketWrap, wParam, lParam );
|
|
|
|
}
|
2009-01-31 19:06:09 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case XWWM_SOCKET_EVT:
|
2009-09-21 00:23:56 +02:00
|
|
|
if ( !!globals->socketWrap ) {
|
|
|
|
draw = ce_sockwrap_event( globals->socketWrap, wParam, lParam );
|
|
|
|
}
|
2005-07-30 04:02:49 +02:00
|
|
|
break;
|
2009-12-21 07:43:21 +01:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
case XWWM_CONNMGR_EVT:
|
|
|
|
connEvtAndError( globals, wParam );
|
|
|
|
break;
|
|
|
|
#endif
|
2005-07-30 04:02:49 +02:00
|
|
|
#endif
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
default:
|
2008-02-16 18:36:46 +01:00
|
|
|
callDefault = XP_TRUE;
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-16 18:36:46 +01:00
|
|
|
if ( callDefault ) {
|
|
|
|
result = DefWindowProc(hWnd, message, wParam, lParam );
|
|
|
|
} else if ( draw ) {
|
2003-11-20 17:26:35 +01:00
|
|
|
/* This is stupid. We can't just say "draw" because windoze clips
|
|
|
|
drawing to the inval rect, and the board isn't set up to tell us
|
|
|
|
what its inval rect is. So we inval everything, and then when the
|
|
|
|
WM_PAINT message comes we inval the whole board because there's a
|
|
|
|
huge inval rect. Dumb. Need to figure out how to have the
|
|
|
|
methods in cedraw.c set the clip region to encompass the object
|
|
|
|
being drawn -- taking board's word for it -- or the intersection
|
|
|
|
of that with the actual clip rgn in the case where some window's
|
|
|
|
gone away and revealed a large rect board didn't know about. That
|
|
|
|
was the source of some trouble on Palm, and CE's so fast this
|
|
|
|
works. But it's stupid. */
|
2004-02-12 05:35:10 +01:00
|
|
|
RECT r = { 100, 100, 102, 102 };
|
|
|
|
InvalidateRect( globals->hWnd, &r, FALSE /* erase */ );
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
|
2008-02-16 18:36:46 +01:00
|
|
|
return result;
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* WndProc */
|
|
|
|
|
|
|
|
// Mesage handler for the About box.
|
|
|
|
LRESULT CALLBACK
|
2008-02-16 18:36:46 +01:00
|
|
|
ceAbout(HWND hDlg, UINT message, WPARAM wParam, LPARAM XP_UNUSED(lParam))
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
switch (message) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
2008-02-16 18:36:46 +01:00
|
|
|
if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL)) {
|
|
|
|
EndDialog(hDlg, LOWORD(wParam));
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2008-02-16 18:36:46 +01:00
|
|
|
} /* ceAbout */
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2004-02-17 06:00:13 +01:00
|
|
|
static XP_Bool
|
2003-11-20 17:26:35 +01:00
|
|
|
ceMsgFromStream( CEAppGlobals* globals, XWStreamCtxt* stream,
|
2009-04-11 17:45:59 +02:00
|
|
|
const wchar_t* title, XP_U16 buttons, XP_Bool destroy )
|
2008-03-15 22:56:37 +01:00
|
|
|
{
|
|
|
|
/* It seems we want to use messagebox for everything on smartphone and
|
|
|
|
Windows, but not on PPC since it doesn't scroll and doesn't use
|
|
|
|
softkeys. Well, on Windows since there's no scrolling limit by
|
|
|
|
size */
|
|
|
|
XP_Bool saidYes;
|
|
|
|
XP_Bool useMB;
|
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
useMB = IS_SMARTPHONE(globals);
|
|
|
|
#else
|
|
|
|
useMB = stream_getSize(stream) <= 256; /* arbitrary... */
|
|
|
|
#endif
|
|
|
|
if ( useMB ) {
|
|
|
|
int result = messageBoxStream( globals, stream, title, buttons );
|
|
|
|
saidYes = (IDOK == result) | (IDRETRY == result) | (IDYES == result);
|
|
|
|
} else {
|
2009-10-01 06:15:18 +02:00
|
|
|
saidYes = WrapStrBox( globals, title, stream, buttons );
|
2008-03-15 22:56:37 +01:00
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
if ( destroy ) {
|
|
|
|
stream_destroy( stream );
|
|
|
|
}
|
2004-02-14 07:13:18 +01:00
|
|
|
|
2008-03-15 22:56:37 +01:00
|
|
|
return saidYes;
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ceMsgFromStream */
|
|
|
|
|
|
|
|
static XP_UCHAR*
|
|
|
|
ceStreamToStrBuf( MPFORMAL XWStreamCtxt* stream )
|
|
|
|
{
|
|
|
|
XP_U16 len = stream_getSize( stream );
|
|
|
|
XP_UCHAR* buf = XP_MALLOC( mpool, len + 1 );
|
|
|
|
stream_getBytes( stream, buf, len );
|
|
|
|
buf[len] = '\0';
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
} /* ceStreamToStrBuf */
|
|
|
|
|
2009-09-11 09:44:27 +02:00
|
|
|
static int
|
2009-12-27 03:54:30 +01:00
|
|
|
ceOops( CEAppGlobals* globals, const XP_UCHAR* str, SkipAlertBits bit )
|
2009-09-11 09:44:27 +02:00
|
|
|
{
|
2009-12-14 05:12:20 +01:00
|
|
|
return ceMessageBoxChar( globals, str, NULL,
|
2009-12-27 03:54:30 +01:00
|
|
|
MB_OK | MB_ICONHAND, bit );
|
2009-09-11 09:44:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-12-27 03:54:30 +01:00
|
|
|
ceOopsId( CEAppGlobals* globals, XP_U16 strId, SkipAlertBits bit )
|
2009-09-11 09:44:27 +02:00
|
|
|
{
|
2009-12-27 03:54:30 +01:00
|
|
|
return ceOops( globals, ceGetResString( globals, strId ), bit );
|
2009-09-11 09:44:27 +02:00
|
|
|
}
|
|
|
|
|
2008-03-15 22:56:37 +01:00
|
|
|
static int
|
2009-04-11 17:45:59 +02:00
|
|
|
messageBoxStream( CEAppGlobals* globals, XWStreamCtxt* stream,
|
|
|
|
const wchar_t* title, XP_U16 buttons )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
XP_UCHAR* buf = ceStreamToStrBuf( MPPARM(globals->mpool) stream );
|
2008-12-07 06:21:13 +01:00
|
|
|
int result;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2009-12-27 03:54:30 +01:00
|
|
|
result = ceMessageBoxChar( globals, buf, title, buttons, SAB_NONE );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
XP_FREE( globals->mpool, buf );
|
2008-03-15 22:56:37 +01:00
|
|
|
return result;
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* messageBoxStream */
|
|
|
|
|
2008-06-26 06:17:14 +02:00
|
|
|
XP_Bool
|
2009-04-11 17:45:59 +02:00
|
|
|
queryBoxChar( CEAppGlobals* globals, HWND hWnd, const XP_UCHAR* msg )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
wchar_t widebuf[128];
|
|
|
|
XP_U16 answer;
|
|
|
|
|
2009-09-11 09:44:27 +02:00
|
|
|
(void)MultiByteToWideChar( CP_UTF8, 0, msg, -1, widebuf, VSIZE(widebuf) );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2009-04-11 17:45:59 +02:00
|
|
|
answer = MessageBox( hWnd, widebuf,
|
|
|
|
ceGetResStringL( globals, IDS_QUESTION_L ),
|
2008-12-07 17:24:26 +01:00
|
|
|
MB_YESNO | MB_ICONQUESTION );
|
2003-11-20 17:26:35 +01:00
|
|
|
return answer == IDOK || answer == IDYES;
|
|
|
|
} /* queryBoxChar */
|
|
|
|
|
2004-02-14 07:13:18 +01:00
|
|
|
static XP_Bool
|
|
|
|
ceQueryFromStream( CEAppGlobals* globals, XWStreamCtxt* stream )
|
|
|
|
{
|
2009-04-11 17:45:59 +02:00
|
|
|
return ceMsgFromStream( globals, stream,
|
|
|
|
ceGetResStringL( globals, IDS_QUESTION_L ),
|
2008-12-07 17:24:26 +01:00
|
|
|
MB_OKCANCEL | MB_ICONQUESTION, XP_FALSE );
|
2004-02-14 07:13:18 +01:00
|
|
|
} /* ceQueryFromStream */
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static void
|
2008-05-25 17:08:03 +02:00
|
|
|
RECTtoXPR( XP_Rect* dest, const RECT* src )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
dest->top = (short)src->top;
|
|
|
|
dest->left = (short)src->left;
|
|
|
|
dest->width = (short)(src->right - src->left);
|
|
|
|
dest->height = (short)(src->bottom - src->top);
|
|
|
|
} /* RECTtoXPR */
|
|
|
|
|
|
|
|
void
|
2008-02-17 22:48:48 +01:00
|
|
|
wince_assert( XP_UCHAR* XP_UNUSED_LOG(s), int XP_UNUSED_LOG(line),
|
2009-01-17 19:44:45 +01:00
|
|
|
const char* XP_UNUSED_LOG(fileName),
|
|
|
|
const char* XP_UNUSED_LOG(func) )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
2009-01-17 19:44:45 +01:00
|
|
|
XP_WARNF( "ASSERTION FAILED %s: %s in file %s, line %d\n", s,
|
|
|
|
func, fileName, line );
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* wince_assert */
|
|
|
|
|
2008-02-17 22:48:48 +01:00
|
|
|
#ifdef ENABLE_LOGGING
|
2003-11-20 17:26:35 +01:00
|
|
|
static void
|
2008-02-17 22:48:48 +01:00
|
|
|
makeTimeStamp( XP_UCHAR* timeStamp, XP_U16 XP_UNUSED_DBG(size) )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
SYSTEMTIME st;
|
2005-07-30 04:02:49 +02:00
|
|
|
DWORD tid;
|
|
|
|
|
2006-02-06 05:41:14 +01:00
|
|
|
tid = GetCurrentThreadId();
|
2005-07-30 04:02:49 +02:00
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
GetLocalTime( &st );
|
2005-07-30 04:02:49 +02:00
|
|
|
sprintf( timeStamp, "<%lx>%d:%.2d:%.2d ", tid, st.wHour, st.wMinute,
|
|
|
|
st.wSecond );
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_ASSERT( size > strlen(timeStamp) );
|
|
|
|
} /* makeTimeStamp */
|
|
|
|
|
2008-07-24 06:16:48 +02:00
|
|
|
void
|
|
|
|
wince_warnf(const XP_UCHAR* format, ...)
|
|
|
|
{
|
|
|
|
XP_UCHAR buf[256];
|
|
|
|
va_list ap;
|
|
|
|
XP_U16 slen;
|
|
|
|
|
|
|
|
va_start( ap, format );
|
|
|
|
vsnprintf( buf, sizeof(buf), format, ap );
|
|
|
|
va_end(ap);
|
|
|
|
|
2009-01-17 19:44:45 +01:00
|
|
|
wince_debugf( "%s", buf );
|
|
|
|
|
2008-07-24 06:16:48 +02:00
|
|
|
slen = strlen(buf)+1;
|
|
|
|
wchar_t widebuf[slen];
|
|
|
|
|
|
|
|
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, buf, slen,
|
|
|
|
widebuf, slen );
|
|
|
|
|
2008-12-07 17:24:26 +01:00
|
|
|
MessageBox( NULL, widebuf, L"WARNF", MB_OK | MB_ICONHAND );
|
2008-07-24 06:16:48 +02:00
|
|
|
} /* wince_warnf */
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
void
|
2008-03-15 16:39:58 +01:00
|
|
|
wince_debugf(const XP_UCHAR* format, ...)
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
2006-10-10 03:34:37 +02:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2005-08-21 16:54:49 +02:00
|
|
|
static HANDLE s_logMutex = NULL;
|
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_UCHAR buf[256];
|
2005-08-21 16:54:49 +02:00
|
|
|
XP_UCHAR timeStamp[32];
|
|
|
|
XP_U16 nBytes;
|
|
|
|
XP_U32 nWritten;
|
|
|
|
HANDLE fileH;
|
2003-11-20 17:26:35 +01:00
|
|
|
va_list ap;
|
2005-11-27 21:16:43 +01:00
|
|
|
wchar_t* logFileName;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
va_start( ap, format );
|
|
|
|
vsprintf( buf, format, ap );
|
|
|
|
va_end(ap);
|
|
|
|
|
2005-08-21 16:54:49 +02:00
|
|
|
/* Create logfile if necessary and write to it in ascii. If there are
|
|
|
|
multiple threads, protect with mutex. */
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2006-10-10 03:34:37 +02:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2005-08-21 16:54:49 +02:00
|
|
|
if ( s_logMutex == NULL ) {
|
|
|
|
s_logMutex = CreateMutex( NULL, FALSE, NULL );
|
|
|
|
}
|
|
|
|
if ( WaitForSingleObject( s_logMutex, 200L ) == WAIT_OBJECT_0 ) {
|
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
makeTimeStamp(timeStamp, sizeof(timeStamp));
|
|
|
|
|
2008-11-22 17:43:55 +01:00
|
|
|
#ifdef _WIN32_WCE
|
2008-10-24 10:36:44 +02:00
|
|
|
logFileName = L"\\My Documents\\" LCROSSWORDS_DIR L"\\xwDbgLog.txt";
|
2008-11-22 17:43:55 +01:00
|
|
|
#else
|
2005-11-27 21:16:43 +01:00
|
|
|
logFileName = L"xwDbgLog.txt";
|
|
|
|
#endif
|
|
|
|
fileH = CreateFile( logFileName,
|
2004-01-10 19:11:28 +01:00
|
|
|
GENERIC_WRITE, 0, NULL,
|
2003-11-20 17:26:35 +01:00
|
|
|
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
|
|
|
|
|
|
|
|
#ifdef _WIN32_WCE_EMULATION
|
|
|
|
strcat( buf, "\n" );
|
|
|
|
#else
|
|
|
|
strcat( buf, XP_CR );
|
|
|
|
#endif
|
|
|
|
SetFilePointer( fileH, 0, 0, FILE_END );
|
2006-01-31 07:41:16 +01:00
|
|
|
#ifdef DEBUG_TS
|
2003-11-20 17:26:35 +01:00
|
|
|
nBytes = strlen( timeStamp );
|
|
|
|
WriteFile( fileH, timeStamp, nBytes, &nWritten, NULL );
|
2006-01-31 07:41:16 +01:00
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
nBytes = strlen( buf );
|
|
|
|
WriteFile( fileH, buf, nBytes, &nWritten, NULL );
|
|
|
|
CloseHandle( fileH );
|
2006-10-10 03:34:37 +02:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2005-08-21 16:54:49 +02:00
|
|
|
ReleaseMutex( s_logMutex );
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} /* wince_debugf */
|
2008-02-17 22:48:48 +01:00
|
|
|
#endif /* ENABLE_LOGGING */
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
XP_U16
|
2007-02-03 18:54:20 +01:00
|
|
|
wince_snprintf( XP_UCHAR* buf, XP_U16 len, const XP_UCHAR* format, ... )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start( ap, format );
|
|
|
|
|
2004-12-18 02:03:26 +01:00
|
|
|
_vsnprintf( buf, len, format, ap );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
/* FormatMessage( */
|
|
|
|
/* FORMAT_MESSAGE_FROM_STRING, */
|
|
|
|
/* format, */
|
|
|
|
/* 0, */
|
|
|
|
/* 0, // Default language */
|
|
|
|
/* (LPTSTR)buf, */
|
|
|
|
/* len, &ap ); */
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return strlen(buf);
|
|
|
|
} /* wince_snprintf */
|
|
|
|
|
2007-12-03 02:18:13 +01:00
|
|
|
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
2009-01-31 19:06:09 +01:00
|
|
|
static XP_Bool
|
2005-07-30 04:02:49 +02:00
|
|
|
got_data_proc( XP_U8* data, XP_U16 len, void* closure )
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)closure;
|
|
|
|
XWStreamCtxt* stream;
|
2009-09-20 22:49:37 +02:00
|
|
|
XP_Bool draw = XP_FALSE;
|
2005-07-30 04:02:49 +02:00
|
|
|
|
|
|
|
stream = make_generic_stream( globals );
|
|
|
|
stream_putBytes( stream, data, len );
|
|
|
|
|
2009-01-31 19:06:09 +01:00
|
|
|
XP_ASSERT( !!globals->game.comms );
|
|
|
|
if ( comms_checkIncomingStream( globals->game.comms, stream, NULL ) ) {
|
|
|
|
draw = server_receiveMessage( globals->game.server, stream );
|
|
|
|
}
|
|
|
|
stream_destroy( stream );
|
|
|
|
ce_util_requestTime( &globals->util );
|
|
|
|
|
|
|
|
return draw;
|
2005-07-30 04:02:49 +02:00
|
|
|
} /* got_data_proc */
|
2009-09-15 15:04:34 +02:00
|
|
|
|
|
|
|
static void
|
2009-09-20 21:00:54 +02:00
|
|
|
sock_state_change( void* closure, CeConnState oldState, CeConnState newState )
|
2009-09-15 15:04:34 +02:00
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)closure;
|
2009-09-20 21:00:54 +02:00
|
|
|
globals->socketState = newState;
|
2009-09-15 15:04:34 +02:00
|
|
|
InvalidateRect( globals->hWnd, &globals->relayStatusR, TRUE /* erase */ );
|
2009-09-20 21:00:54 +02:00
|
|
|
|
|
|
|
if ( newState < oldState ) {
|
|
|
|
comms_transportFailed( globals->game.comms );
|
|
|
|
}
|
2009-09-15 15:04:34 +02:00
|
|
|
}
|
2006-10-28 16:56:04 +02:00
|
|
|
#endif
|
2005-07-30 04:02:49 +02:00
|
|
|
|
2007-12-03 02:18:13 +01:00
|
|
|
#ifdef COMMS_HEARTBEAT
|
|
|
|
static void
|
2009-09-20 23:11:58 +02:00
|
|
|
ce_reset_proc( void* XP_UNUSED(closure) )
|
2007-12-03 02:18:13 +01:00
|
|
|
{
|
|
|
|
LOG_FUNC();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-01-05 15:13:40 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2009-11-22 18:58:59 +01:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2009-09-15 15:04:34 +02:00
|
|
|
static void
|
|
|
|
ce_relay_status( void* closure, CommsRelayState newState )
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)closure;
|
|
|
|
globals->relayState = newState;
|
|
|
|
InvalidateRect( globals->hWnd, &globals->relayStatusR, TRUE /* erase */ );
|
|
|
|
}
|
2009-12-04 10:09:07 +01:00
|
|
|
|
|
|
|
static void
|
2009-12-14 05:12:20 +01:00
|
|
|
ce_relay_connd( void* closure, XP_Bool allHere, XP_U16 nMissing )
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)closure;
|
|
|
|
XP_U16 strID = 0;
|
2009-12-27 03:54:30 +01:00
|
|
|
SkipAlertBits bit = SAB_NONE;
|
2009-12-14 05:12:20 +01:00
|
|
|
|
|
|
|
if ( allHere ) {
|
|
|
|
strID = IDS_RELAY_ALLHERE;
|
2009-12-27 20:04:29 +01:00
|
|
|
bit = SAB_ALL_HERE;
|
2009-12-14 05:12:20 +01:00
|
|
|
} else {
|
|
|
|
DeviceRole role = globals->gameInfo.serverRole;
|
|
|
|
if ( role == SERVER_ISSERVER ) {
|
|
|
|
strID = IDS_RELAY_HOST_WAITINGD;
|
2009-12-27 03:54:30 +01:00
|
|
|
bit = SAB_HOST_CONND;
|
2009-12-14 05:12:20 +01:00
|
|
|
} else if ( nMissing > 0 ) {
|
|
|
|
strID = IDS_RELAY_GUEST_WAITINGD;
|
2009-12-27 03:54:30 +01:00
|
|
|
bit = SAB_CLIENT_CONND;
|
2009-12-14 05:12:20 +01:00
|
|
|
} else {
|
|
|
|
/* an allHere message should be coming immediately, so no
|
|
|
|
notification now. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( 0 != strID ) {
|
|
|
|
XP_UCHAR buf[256];
|
|
|
|
const XP_UCHAR* fmt = ceGetResString( globals, strID );
|
|
|
|
XP_SNPRINTF( buf, VSIZE(buf), fmt, nMissing );
|
|
|
|
ceMessageBoxChar( globals, buf, ceGetResStringL( globals, IDS_FYI_L ),
|
2009-12-27 03:54:30 +01:00
|
|
|
MB_OK | MB_ICONHAND, bit );
|
2009-12-14 05:12:20 +01:00
|
|
|
}
|
|
|
|
} /* ce_relay_connd */
|
|
|
|
|
|
|
|
static void
|
|
|
|
ce_relay_error( void* closure, XWREASON relayErr )
|
2009-12-04 10:09:07 +01:00
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)closure;
|
2009-12-14 05:12:20 +01:00
|
|
|
UINT evt;
|
|
|
|
|
|
|
|
switch( relayErr ) {
|
|
|
|
case XWRELAY_ERROR_NO_ROOM:
|
|
|
|
case XWRELAY_ERROR_DUP_ROOM:
|
|
|
|
evt = XWWM_RELAY_REQ_CONN;
|
|
|
|
break;
|
|
|
|
case XWRELAY_ERROR_TOO_MANY:
|
|
|
|
evt = XWWM_RELAY_REQ_NEW;
|
|
|
|
break;
|
|
|
|
default:
|
2009-12-16 03:46:00 +01:00
|
|
|
evt = 0; /* silence compiler */
|
2009-12-14 05:12:20 +01:00
|
|
|
XP_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
PostMessage( globals->hWnd, evt, 0, 0 );
|
2009-12-04 10:09:07 +01:00
|
|
|
}
|
2009-11-22 18:58:59 +01:00
|
|
|
#endif
|
2009-09-15 15:04:34 +02:00
|
|
|
|
2005-07-23 17:31:21 +02:00
|
|
|
static XP_S16
|
2009-01-05 15:13:40 +01:00
|
|
|
ce_send_proc( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addrp,
|
2006-09-15 09:39:57 +02:00
|
|
|
void* closure )
|
2005-07-23 17:31:21 +02:00
|
|
|
{
|
2009-01-05 15:13:40 +01:00
|
|
|
XP_S16 nSent = -1;
|
2005-07-30 04:02:49 +02:00
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)closure;
|
2009-01-05 15:13:40 +01:00
|
|
|
LOG_FUNC();
|
2009-12-18 05:24:55 +01:00
|
|
|
if ( !globals->exiting ) {
|
|
|
|
CommsAddrRec addr;
|
2009-01-05 15:13:40 +01:00
|
|
|
|
2009-12-18 05:24:55 +01:00
|
|
|
XP_ASSERT( !!globals->game.comms );
|
2009-09-21 14:49:08 +02:00
|
|
|
|
2009-12-18 05:24:55 +01:00
|
|
|
if ( !addrp ) {
|
|
|
|
comms_getAddr( globals->game.comms, &addr );
|
|
|
|
addrp = &addr;
|
|
|
|
}
|
2009-01-05 15:13:40 +01:00
|
|
|
|
2009-12-18 05:24:55 +01:00
|
|
|
XP_ASSERT( !!addrp ); /* firing */
|
|
|
|
switch( addrp->conType ) {
|
2009-01-05 15:13:40 +01:00
|
|
|
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
2009-12-18 05:24:55 +01:00
|
|
|
case COMMS_CONN_IP_DIRECT:
|
|
|
|
break;
|
|
|
|
case COMMS_CONN_RELAY:
|
|
|
|
if ( !globals->exiting ) {
|
|
|
|
if ( !globals->socketWrap ) {
|
2009-12-21 07:43:21 +01:00
|
|
|
globals->socketWrap
|
|
|
|
= ce_sockwrap_new( MPPARM(globals->mpool)
|
|
|
|
globals->hWnd,
|
|
|
|
got_data_proc,sock_state_change,
|
2009-12-23 07:01:26 +01:00
|
|
|
#if defined _WIN32_WCE && ! defined CEGCC_DOES_CONNMGR
|
2009-12-21 16:31:06 +01:00
|
|
|
&globals->cmProcs,
|
|
|
|
#endif
|
|
|
|
globals );
|
2009-12-18 05:24:55 +01:00
|
|
|
}
|
2005-07-30 04:02:49 +02:00
|
|
|
|
2009-12-18 05:24:55 +01:00
|
|
|
nSent = ce_sockwrap_send( globals->socketWrap, buf, len, addrp );
|
|
|
|
break;
|
2009-01-05 15:13:40 +01:00
|
|
|
#endif
|
|
|
|
#ifdef XWFEATURE_SMS
|
2009-12-18 05:24:55 +01:00
|
|
|
case COMMS_CONN_SMS:
|
|
|
|
nSent = ce_sms_send( globals, buf, len, addrp );
|
|
|
|
break;
|
2009-01-05 15:13:40 +01:00
|
|
|
#endif
|
2009-12-18 05:24:55 +01:00
|
|
|
default:
|
|
|
|
XP_LOGF( "unexpected conType %d", addrp->conType );
|
|
|
|
XP_ASSERT( 0 );
|
|
|
|
}
|
|
|
|
}
|
2005-07-30 04:02:49 +02:00
|
|
|
}
|
2009-01-05 15:13:40 +01:00
|
|
|
return nSent;
|
2005-07-23 17:31:21 +02:00
|
|
|
} /* ce_send_proc */
|
2005-08-21 16:36:11 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
ce_send_on_close( XWStreamCtxt* stream, void* closure )
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)closure;
|
|
|
|
|
|
|
|
XP_ASSERT( !!globals->game.comms );
|
|
|
|
comms_send( globals->game.comms, stream );
|
|
|
|
}
|
2005-07-30 04:02:49 +02:00
|
|
|
#endif
|
2005-07-23 17:31:21 +02:00
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static VTableMgr*
|
|
|
|
ce_util_getVTManager( XW_UtilCtxt* uc )
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
|
|
|
return globals->vtMgr;
|
|
|
|
} /* ce_util_getVTManager */
|
|
|
|
|
|
|
|
static void
|
|
|
|
ce_util_userError( XW_UtilCtxt* uc, UtilErrID id )
|
|
|
|
{
|
2009-04-09 15:48:38 +02:00
|
|
|
XP_U16 resID = 0;
|
2009-12-27 03:54:30 +01:00
|
|
|
SkipAlertBits sab = SAB_NONE;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
switch( id ) {
|
|
|
|
case ERR_TILES_NOT_IN_LINE:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_TILES_NOT_IN_LINE;
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
case ERR_NO_EMPTIES_IN_TURN:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_NO_EMPTIES_IN_TURN;
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ERR_TWO_TILES_FIRST_MOVE:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_TWO_TILES_FIRST_MOVE;
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
case ERR_TILES_MUST_CONTACT:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_TILES_MUST_CONTACT;
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
case ERR_NOT_YOUR_TURN:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_NOT_YOUR_TURN;
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
case ERR_NO_PEEK_ROBOT_TILES:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_NO_PEEK_ROBOT_TILES;
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
case ERR_CANT_TRADE_MID_MOVE:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_CANT_TRADE_MID_MOVE;
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
case ERR_TOO_FEW_TILES_LEFT_TO_TRADE:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_TOO_FEW_TILES_LEFT_TO_TRADE;
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
2004-05-15 03:07:34 +02:00
|
|
|
case ERR_CANT_UNDO_TILEASSIGN:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_CANT_UNDO_TILEASSIGN;
|
2004-05-15 03:07:34 +02:00
|
|
|
break;
|
|
|
|
|
2008-07-24 06:16:48 +02:00
|
|
|
case ERR_CANT_HINT_WHILE_DISABLED:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_CANT_HINT_WHILE_DISABLED;
|
2008-07-24 06:16:48 +02:00
|
|
|
break;
|
|
|
|
|
2008-01-05 17:37:49 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
|
|
|
case ERR_NO_PEEK_REMOTE_TILES:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_NO_PEEK_REMOTE_TILES;
|
2008-01-05 17:37:49 +01:00
|
|
|
break;
|
|
|
|
case ERR_REG_UNEXPECTED_USER:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_REG_UNEXPECTED_USER;
|
2008-01-05 17:37:49 +01:00
|
|
|
break;
|
|
|
|
case ERR_SERVER_DICT_WINS:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_SERVER_DICT_WINS;
|
2008-01-05 17:37:49 +01:00
|
|
|
break;
|
|
|
|
case ERR_REG_SERVER_SANS_REMOTE:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_REG_SERVER_SANS_REMOTE;
|
2008-01-05 17:37:49 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2006-10-10 03:34:37 +02:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2009-11-22 18:58:59 +01:00
|
|
|
case ERR_RELAY_BASE + XWRELAY_ERROR_OLDFLAGS:
|
|
|
|
resID = IDS_XWRELAY_RELAY_INCOMPAT;
|
|
|
|
break;
|
2005-09-07 14:31:32 +02:00
|
|
|
case ERR_RELAY_BASE + XWRELAY_ERROR_TIMEOUT:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_XWRELAY_ERROR_TIMEOUT;
|
2005-09-07 14:31:32 +02:00
|
|
|
break;
|
|
|
|
case ERR_RELAY_BASE + XWRELAY_ERROR_HEART_YOU:
|
2009-12-27 03:54:30 +01:00
|
|
|
sab = SAB_HEART_YOU;
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_ERROR_HEART_YOU;
|
2005-09-07 14:31:32 +02:00
|
|
|
break;
|
|
|
|
case ERR_RELAY_BASE + XWRELAY_ERROR_HEART_OTHER:
|
|
|
|
case ERR_RELAY_BASE + XWRELAY_ERROR_LOST_OTHER:
|
2009-09-20 21:00:54 +02:00
|
|
|
case ERR_RELAY_BASE + XWRELAY_ERROR_OTHER_DISCON:
|
2009-12-27 03:54:30 +01:00
|
|
|
sab = SAB_HEART_OTHER;
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_XWRELAY_ERROR_HEART_OTHER;
|
2005-09-07 14:31:32 +02:00
|
|
|
break;
|
2009-12-04 10:09:07 +01:00
|
|
|
|
|
|
|
case ERR_RELAY_BASE + XWRELAY_ERROR_NO_ROOM:
|
|
|
|
resID = IDS_ERROR_NO_ROOM;
|
|
|
|
break;
|
|
|
|
case ERR_RELAY_BASE + XWRELAY_ERROR_DUP_ROOM:
|
|
|
|
resID = IDS_ERROR_DUP_ROOM;
|
|
|
|
break;
|
2009-12-14 05:12:20 +01:00
|
|
|
case ERR_RELAY_BASE + XWRELAY_ERROR_TOO_MANY:
|
|
|
|
resID = IDS_ERROR_TOO_MANY;
|
|
|
|
break;
|
2009-12-04 10:09:07 +01:00
|
|
|
|
2009-04-09 15:48:38 +02:00
|
|
|
/* Same string as above for now */
|
|
|
|
/* resID = IDS_XWRELAY_ERROR_LOST_OTHER; */
|
|
|
|
/* break; */
|
2006-02-06 05:41:14 +01:00
|
|
|
#endif
|
2005-09-07 14:31:32 +02:00
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
default:
|
2009-04-09 15:48:38 +02:00
|
|
|
XP_WARNF( "unknown error code: %d", id );
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-04-09 15:48:38 +02:00
|
|
|
if ( 0 != resID ) {
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
2009-12-27 03:54:30 +01:00
|
|
|
ceOopsId( globals, resID, sab );
|
2009-04-09 15:48:38 +02:00
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ce_util_userError */
|
|
|
|
|
2004-02-17 06:00:13 +01:00
|
|
|
static XP_Bool
|
2003-11-20 17:26:35 +01:00
|
|
|
ce_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id, XWStreamCtxt* stream )
|
|
|
|
{
|
2009-04-09 15:48:38 +02:00
|
|
|
const char* query = NULL;
|
2003-11-20 17:26:35 +01:00
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
|
|
|
|
|
|
|
switch( id ) {
|
|
|
|
case QUERY_COMMIT_TURN:
|
2004-02-17 06:00:13 +01:00
|
|
|
return ceQueryFromStream( globals, stream );
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
case QUERY_COMMIT_TRADE:
|
2009-04-11 17:45:59 +02:00
|
|
|
query = ceGetResString( globals, IDS_QUERY_TRADE );
|
2008-12-07 06:21:13 +01:00
|
|
|
assertOnTop( globals->hWnd );
|
2009-04-11 17:45:59 +02:00
|
|
|
return queryBoxChar( globals, globals->hWnd, query );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
case QUERY_ROBOT_MOVE:
|
2009-04-11 17:45:59 +02:00
|
|
|
return ceMsgFromStream( globals, stream,
|
|
|
|
ceGetResStringL( globals, IDS_FYI_L),
|
2008-12-07 17:24:26 +01:00
|
|
|
MB_OK | MB_ICONINFORMATION, XP_FALSE );
|
2004-02-17 06:00:13 +01:00
|
|
|
|
|
|
|
case QUERY_ROBOT_TRADE:
|
2009-04-11 17:45:59 +02:00
|
|
|
messageBoxStream( globals, stream,
|
|
|
|
ceGetResStringL( globals, IDS_FYI_L),
|
|
|
|
MB_OK | MB_ICONINFORMATION);
|
2003-11-20 17:26:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
XP_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
2004-02-17 06:00:13 +01:00
|
|
|
return XP_FALSE;
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ce_util_userQuery */
|
|
|
|
|
|
|
|
static XWBonusType
|
2008-05-06 14:49:37 +02:00
|
|
|
ce_util_getSquareBonus( XW_UtilCtxt* uc, const ModelCtxt* XP_UNUSED(model),
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_U16 col, XP_U16 row )
|
|
|
|
{
|
|
|
|
XP_U16 index;
|
2004-01-29 05:49:34 +01:00
|
|
|
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
|
|
|
|
|
|
|
if ( !globals->bonusInfo ) {
|
|
|
|
HRSRC rsrcH;
|
|
|
|
HGLOBAL globH;
|
|
|
|
|
|
|
|
rsrcH = FindResource( globals->hInst, MAKEINTRESOURCE(ID_BONUS_RES),
|
|
|
|
TEXT("BONS") );
|
|
|
|
if ( !!rsrcH ) {
|
|
|
|
globH = LoadResource( globals->hInst, rsrcH );
|
|
|
|
|
|
|
|
if ( !!globH ) {
|
|
|
|
globals->bonusInfo = (XP_U16*)globH;
|
|
|
|
/* We don't want to call DeleteObject here, but should when
|
|
|
|
the app closes. Or does Wince free up all memory
|
|
|
|
associated with a process when it closes? PENDING(eeh) */
|
|
|
|
// DeleteObject( globH );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
if ( col > 7 ) col = 14 - col;
|
|
|
|
if ( row > 7 ) row = 14 - row;
|
|
|
|
index = (row*8) + col;
|
2004-01-30 06:48:24 +01:00
|
|
|
|
2004-01-29 05:49:34 +01:00
|
|
|
if ( !globals->bonusInfo || (index >= 8*8) ) {
|
|
|
|
XP_ASSERT( 0 );
|
|
|
|
return (XWBonusType)BONUS_NONE;
|
2003-11-20 17:26:35 +01:00
|
|
|
} else {
|
2004-01-29 05:49:34 +01:00
|
|
|
/* This is probably a bit slow. Consider caching the resource in
|
|
|
|
memory with one bonus value per byte. */
|
|
|
|
XP_U16 value = globals->bonusInfo[index/4];
|
|
|
|
value >>= ((3 - (index % 4)) * 4);
|
|
|
|
return value & 0x0F;
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
} /* ce_util_getSquareBonus */
|
|
|
|
|
|
|
|
static XP_S16
|
2005-02-05 22:43:16 +01:00
|
|
|
ce_util_userPickTile( XW_UtilCtxt* uc, const PickInfo* pi,
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_U16 playerNum,
|
2009-04-07 06:23:56 +02:00
|
|
|
const XP_UCHAR** texts, XP_U16 nTiles )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
2009-10-23 10:54:54 +02:00
|
|
|
return WrapBlankDlg( globals, pi, playerNum, texts, nTiles );
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ce_util_userPickTile */
|
|
|
|
|
|
|
|
static XP_Bool
|
|
|
|
ce_util_askPassword( XW_UtilCtxt* uc, const XP_UCHAR* name,
|
|
|
|
XP_UCHAR* buf, XP_U16* len )
|
|
|
|
{
|
|
|
|
PasswdDialogState state;
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
|
|
|
XP_MEMSET( &state, 0, sizeof(state) );
|
|
|
|
|
2008-06-05 06:29:28 +02:00
|
|
|
state.dlgHdr.globals = globals;
|
2003-11-20 17:26:35 +01:00
|
|
|
state.name = name;
|
|
|
|
state.buf = buf;
|
|
|
|
state.lenp = len;
|
|
|
|
|
2008-12-07 06:21:13 +01:00
|
|
|
assertOnTop( globals->hWnd );
|
2009-04-11 17:45:59 +02:00
|
|
|
DialogBoxParam( globals->locInst, (LPCTSTR)IDD_ASKPASS, globals->hWnd,
|
2006-02-06 05:41:14 +01:00
|
|
|
(DLGPROC)PasswdDlg, (long)&state );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
return !state.userCancelled;
|
|
|
|
} /* ce_util_askPassword */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
ce_util_trayHiddenChange( XW_UtilCtxt* uc, XW_TrayVisState XP_UNUSED(newState),
|
2006-05-19 15:44:05 +02:00
|
|
|
XP_U16 nVisibleRows )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
2004-02-13 14:49:25 +01:00
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
2006-05-20 08:22:33 +02:00
|
|
|
XP_U16 nHiddenRows;
|
2005-02-05 22:43:16 +01:00
|
|
|
|
|
|
|
#ifdef CEFEATURE_CANSCROLL
|
|
|
|
/* If there's a scrollbar, hide/show it. It wants to be
|
|
|
|
active/visible only when the tray is NOT hidden */
|
2006-05-19 15:44:05 +02:00
|
|
|
|
2005-02-05 22:43:16 +01:00
|
|
|
if ( !!globals->scrollHandle ) {
|
2006-05-20 08:22:33 +02:00
|
|
|
nHiddenRows = model_numRows( globals->game.model ) - nVisibleRows;
|
2008-08-01 12:37:52 +02:00
|
|
|
updateScrollInfo( globals, nHiddenRows );
|
2005-02-05 22:43:16 +01:00
|
|
|
}
|
|
|
|
#endif
|
2008-11-10 19:49:26 +01:00
|
|
|
ceCheckMenus( globals );
|
2008-09-01 17:10:28 +02:00
|
|
|
drawInsidePaint( globals, NULL );
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ce_util_trayHiddenChange */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
ce_util_yOffsetChange( XW_UtilCtxt* uc, XP_U16 XP_UNUSED(oldOffset),
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_U16 newOffset )
|
|
|
|
{
|
2005-02-05 22:43:16 +01:00
|
|
|
#ifdef CEFEATURE_CANSCROLL
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
2008-03-15 22:56:37 +01:00
|
|
|
if ( !!globals->scrollHandle ) {
|
|
|
|
(void)SetScrollPos( globals->scrollHandle, SB_CTL, newOffset, XP_TRUE );
|
|
|
|
}
|
2005-02-05 22:43:16 +01:00
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ce_util_yOffsetChange */
|
|
|
|
|
2008-02-26 14:49:41 +01:00
|
|
|
static void
|
|
|
|
ce_util_turnChanged( XW_UtilCtxt* uc )
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
|
|
|
ceSetLeftSoftkey( globals, ID_MOVE_TURNDONE );
|
|
|
|
}
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static void
|
|
|
|
ce_util_notifyGameOver( XW_UtilCtxt* uc )
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
2008-09-01 17:10:28 +02:00
|
|
|
drawInsidePaint( globals, NULL );
|
2003-11-20 17:26:35 +01:00
|
|
|
ceDisplayFinalScores( globals );
|
2008-02-26 14:49:41 +01:00
|
|
|
|
|
|
|
ceSetLeftSoftkey( globals, ID_FILE_NEWGAME );
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ce_util_notifyGameOver */
|
|
|
|
|
|
|
|
static XP_Bool
|
2006-08-16 15:44:44 +02:00
|
|
|
ce_util_hiliteCell( XW_UtilCtxt* XP_UNUSED(uc), XP_U16 XP_UNUSED(col),
|
|
|
|
XP_U16 XP_UNUSED(row) )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
return XP_TRUE;
|
|
|
|
} /* ce_util_hiliteCell */
|
|
|
|
|
|
|
|
static XP_Bool
|
2006-08-16 15:44:44 +02:00
|
|
|
ce_util_engineProgressCallback( XW_UtilCtxt* XP_UNUSED(uc) )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
return XP_TRUE;
|
|
|
|
} /* ce_util_engineProgressCallback */
|
|
|
|
|
|
|
|
static void
|
2006-10-28 16:56:04 +02:00
|
|
|
ce_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why,
|
2008-02-16 17:02:49 +01:00
|
|
|
XP_U16 XP_UNUSED_STANDALONE(when), XWTimerProc proc,
|
|
|
|
void* closure )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
2004-06-16 06:16:22 +02:00
|
|
|
XP_U32 timerID;
|
2004-06-25 09:19:05 +02:00
|
|
|
XP_U32 howLong;
|
2009-09-21 14:49:08 +02:00
|
|
|
TimerData* timer = &globals->timerData[why];
|
2004-06-25 09:19:05 +02:00
|
|
|
|
2005-08-21 16:07:29 +02:00
|
|
|
XP_ASSERT( why < NUM_TIMERS_PLUS_ONE );
|
2009-09-21 14:49:08 +02:00
|
|
|
timer->proc = proc;
|
|
|
|
timer->closure = closure;
|
2005-06-23 16:09:20 +02:00
|
|
|
|
|
|
|
switch ( why ) {
|
|
|
|
case TIMER_PENDOWN:
|
2004-06-25 09:19:05 +02:00
|
|
|
howLong = 400;
|
2005-06-23 16:09:20 +02:00
|
|
|
break;
|
|
|
|
case TIMER_TIMERTICK:
|
2004-06-25 09:19:05 +02:00
|
|
|
howLong = 1000; /* 1 second */
|
2005-06-23 16:09:20 +02:00
|
|
|
break;
|
2009-01-04 01:00:45 +01:00
|
|
|
#if defined XWFEATURE_RELAY || defined COMMS_HEARTBEAT
|
2009-02-01 17:20:18 +01:00
|
|
|
case TIMER_COMMS:
|
2005-06-23 16:09:20 +02:00
|
|
|
howLong = when * 1000;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2004-06-16 06:16:22 +02:00
|
|
|
XP_ASSERT(0);
|
2004-06-25 09:19:05 +02:00
|
|
|
return;
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
2008-02-16 18:36:46 +01:00
|
|
|
|
2009-09-21 14:49:08 +02:00
|
|
|
timer->when = GetCurrentTime() + howLong;
|
2008-02-16 18:36:46 +01:00
|
|
|
|
2004-06-25 09:19:05 +02:00
|
|
|
timerID = SetTimer( globals->hWnd, why, howLong, NULL);
|
|
|
|
|
2009-09-21 14:49:08 +02:00
|
|
|
timer->id = timerID;
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ce_util_setTimer */
|
|
|
|
|
2009-09-21 14:49:08 +02:00
|
|
|
static void
|
|
|
|
ce_util_clearTimer( XW_UtilCtxt* uc, XWTimerReason why )
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
|
|
|
TimerData* timer = &globals->timerData[why];
|
|
|
|
if ( !!timer->proc ) {
|
|
|
|
timer->proc = NULL;
|
|
|
|
KillTimer( globals->hWnd, timer->id );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-08 05:55:53 +02:00
|
|
|
static XP_Bool
|
|
|
|
ce_util_altKeyDown( XW_UtilCtxt* XP_UNUSED(uc) )
|
|
|
|
{
|
|
|
|
return GetKeyState(VK_LSHIFT) < 0
|
|
|
|
|| GetKeyState(VK_RSHIFT) < 0;
|
|
|
|
}
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
static void
|
|
|
|
ce_util_requestTime( XW_UtilCtxt* uc )
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
|
|
|
|
|
|
|
PostMessage( globals->hWnd, XWWM_TIME_RQST, 0, 0 );
|
|
|
|
} /* palm_util_requestTime */
|
|
|
|
|
|
|
|
static XP_U32
|
2006-08-16 15:44:44 +02:00
|
|
|
ce_util_getCurSeconds( XW_UtilCtxt* XP_UNUSED(uc) )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
2008-02-16 18:36:46 +01:00
|
|
|
/* This function is never called! */
|
|
|
|
XP_U32 ticks = GetCurrentTime();
|
|
|
|
ticks /= 1000;
|
|
|
|
LOG_RETURNF( "%ld", ticks );
|
|
|
|
return ticks;
|
|
|
|
/* return 0L; */
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ce_util_getCurSeconds */
|
|
|
|
|
|
|
|
static DictionaryCtxt*
|
|
|
|
ce_util_makeEmptyDict( XW_UtilCtxt* uc )
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
2004-01-17 23:10:23 +01:00
|
|
|
#ifdef STUBBED_DICT
|
|
|
|
return make_stubbed_dict( MPPARM_NOCOMMA(globals->mpool) );
|
|
|
|
#else
|
2005-06-30 03:48:07 +02:00
|
|
|
return ce_dictionary_make_empty( globals );
|
2004-01-17 23:10:23 +01:00
|
|
|
#endif
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ce_util_makeEmptyDict */
|
|
|
|
|
2006-10-10 03:34:37 +02:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2003-11-20 17:26:35 +01:00
|
|
|
static XWStreamCtxt*
|
2008-01-05 17:37:49 +01:00
|
|
|
ce_util_makeStreamFromAddr( XW_UtilCtxt* uc, XP_PlayerAddr channelNo )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
2005-07-30 04:02:49 +02:00
|
|
|
XWStreamCtxt* stream;
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
|
|
|
|
|
|
|
stream = make_generic_stream( globals );
|
2005-08-21 16:36:11 +02:00
|
|
|
stream_setOnCloseProc( stream, ce_send_on_close );
|
2005-07-30 04:02:49 +02:00
|
|
|
stream_setAddress( stream, channelNo );
|
|
|
|
|
|
|
|
return stream;
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ce_util_makeStreamFromAddr */
|
|
|
|
#endif
|
|
|
|
|
2007-02-03 18:54:20 +01:00
|
|
|
static const XP_UCHAR*
|
2009-04-09 15:48:38 +02:00
|
|
|
ce_util_getUserString( XW_UtilCtxt* uc, XP_U16 stringCode )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
2009-04-09 15:48:38 +02:00
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
|
|
|
XP_U16 resID = 0;
|
|
|
|
const XP_UCHAR* result = NULL;
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
switch( stringCode ) {
|
|
|
|
case STRD_REMAINING_TILES_ADD:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_REMAINING_TILES_ADD;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
case STRD_UNUSED_TILES_SUB:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_UNUSED_TILES_SUB;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
case STR_BONUS_ALL:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_BONUS_ALL;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
case STRD_TURN_SCORE:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_TURN_SCORE;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
case STR_COMMIT_CONFIRM:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_COMMIT_CONFIRM;
|
|
|
|
break;
|
2004-05-01 16:30:34 +02:00
|
|
|
case STR_LOCAL_NAME:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_LOCAL_NAME;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
case STR_NONLOCAL_NAME:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_NONLOCAL_NAME;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
case STRD_TIME_PENALTY_SUB:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_TIME_PENALTY_SUB;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
case STRD_CUMULATIVE_SCORE:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_CUMULATIVE_SCORE;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
case STRS_MOVE_ACROSS:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_MOVE_ACROSS;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
case STRS_MOVE_DOWN:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_MOVE_DOWN;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
case STRS_TRAY_AT_START:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_TRAY_AT_START;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
case STRS_NEW_TILES:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_NEW_TILES;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
case STRSS_TRADED_FOR:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_TRADED_FOR;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
case STR_PASS:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_PASS;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
case STR_PHONY_REJECTED:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_PHONY_REJECTED;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
case STRD_ROBOT_TRADED:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_ROBOT_TRADED;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
case STR_ROBOT_MOVED:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_ROBOT_MOVED;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
case STR_REMOTE_MOVED:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_REMOTE_MOVED;
|
|
|
|
break;
|
2003-11-20 17:26:35 +01:00
|
|
|
|
2004-05-13 04:13:48 +02:00
|
|
|
case STR_PASSED:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_PASSED;
|
|
|
|
break;
|
2004-05-13 04:13:48 +02:00
|
|
|
case STRSD_SUMMARYSCORED:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_SUMMARYSCORED;
|
|
|
|
break;
|
2004-05-13 04:13:48 +02:00
|
|
|
case STRD_TRADED:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_TRADED;
|
|
|
|
break;
|
2004-05-13 04:13:48 +02:00
|
|
|
case STR_LOSTTURN:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_LOSTTURN;
|
|
|
|
break;
|
2004-05-13 04:13:48 +02:00
|
|
|
|
2006-06-10 18:15:31 +02:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
|
|
|
case STR_LOCALPLAYERS:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_LOCALPLAYERS;
|
|
|
|
break;
|
2006-06-10 18:15:31 +02:00
|
|
|
#endif
|
|
|
|
case STR_TOTALPLAYERS:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_TOTALPLAYERS;
|
|
|
|
break;
|
2006-06-10 18:15:31 +02:00
|
|
|
|
2004-11-09 03:40:36 +01:00
|
|
|
case STRS_VALUES_HEADER:
|
2009-04-09 15:48:38 +02:00
|
|
|
resID = IDS_VALUES_HEADER;
|
|
|
|
break;
|
2004-11-09 03:40:36 +01:00
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
default:
|
2009-04-09 15:48:38 +02:00
|
|
|
XP_WARNF( "id for stringCode %d not found", stringCode );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( 0 != resID ) {
|
|
|
|
result = ceGetResString( globals, resID );
|
|
|
|
} else {
|
|
|
|
XP_WARNF( "%s: no resource for id %d", __func__, stringCode );
|
|
|
|
result = "";
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
2009-04-09 15:48:38 +02:00
|
|
|
return result;
|
2003-11-20 17:26:35 +01:00
|
|
|
} /* ce_util_getUserString */
|
|
|
|
|
|
|
|
static void
|
2004-01-29 05:49:34 +01:00
|
|
|
ce_formatBadWords( BadWordInfo* bwi, XP_UCHAR buf[], XP_U16 bufsiz )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
XP_U16 i;
|
|
|
|
|
|
|
|
for ( i = 0, buf[0] = '\0'; ; ) {
|
2009-04-11 17:45:59 +02:00
|
|
|
XP_UCHAR wordBuf[24];
|
2003-11-20 17:26:35 +01:00
|
|
|
sprintf( wordBuf, "\"%s\"", bwi->words[i] );
|
2004-01-29 05:49:34 +01:00
|
|
|
XP_ASSERT( strlen(wordBuf) < sizeof(wordBuf)-1 );
|
|
|
|
strncat( buf, wordBuf, bufsiz - 1 );
|
2003-11-20 17:26:35 +01:00
|
|
|
if ( ++i == bwi->nWords ) {
|
|
|
|
break;
|
|
|
|
}
|
2004-01-29 05:49:34 +01:00
|
|
|
bufsiz -= strlen( wordBuf );
|
|
|
|
strncat( buf, ", ", bufsiz - 1 );
|
|
|
|
bufsiz -= 2;
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
} /* ce_formatBadWords */
|
|
|
|
|
|
|
|
static XP_Bool
|
|
|
|
ce_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi,
|
2006-08-16 15:44:44 +02:00
|
|
|
XP_U16 XP_UNUSED(turn), XP_Bool turnLost )
|
2003-11-20 17:26:35 +01:00
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
|
|
|
XP_UCHAR wordsBuf[256];
|
|
|
|
XP_UCHAR msgBuf[256];
|
2009-04-11 17:45:59 +02:00
|
|
|
const XP_UCHAR* fmt;
|
2003-11-20 17:26:35 +01:00
|
|
|
XP_Bool isOk;
|
|
|
|
|
2004-01-29 05:49:34 +01:00
|
|
|
ce_formatBadWords( bwi, wordsBuf, sizeof(wordsBuf) );
|
2009-04-11 17:45:59 +02:00
|
|
|
fmt = ceGetResString( globals, IDS_WRDNOTFOUND );
|
|
|
|
snprintf( msgBuf, VSIZE(msgBuf), fmt, wordsBuf );
|
2003-11-20 17:26:35 +01:00
|
|
|
|
|
|
|
if ( turnLost ) {
|
2009-10-17 06:10:28 +02:00
|
|
|
ceMessageBoxChar( globals, msgBuf,
|
2009-04-11 17:45:59 +02:00
|
|
|
ceGetResStringL( globals, IDS_ILLEGALWRD_L ),
|
2009-12-27 03:54:30 +01:00
|
|
|
MB_OK | MB_ICONHAND, SAB_NONE );
|
2003-11-20 17:26:35 +01:00
|
|
|
isOk = XP_TRUE;
|
|
|
|
} else {
|
2009-04-11 17:45:59 +02:00
|
|
|
const XP_UCHAR* str = ceGetResString( globals, IDS_USEANYWAY );
|
|
|
|
XP_U16 len = strlen( msgBuf );
|
|
|
|
XP_SNPRINTF( &msgBuf[len], VSIZE(msgBuf)-len, " %s", str );
|
2008-12-07 06:21:13 +01:00
|
|
|
assertOnTop( globals->hWnd );
|
2009-04-11 17:45:59 +02:00
|
|
|
isOk = queryBoxChar( globals, globals->hWnd, msgBuf );
|
2003-11-20 17:26:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return isOk;
|
|
|
|
} /* ce_util_warnIllegalWord */
|
|
|
|
|
2008-10-24 11:05:13 +02:00
|
|
|
static void
|
|
|
|
ce_util_remSelected( XW_UtilCtxt* uc )
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
|
|
|
PostMessage( globals->hWnd, XWWM_REM_SEL, 0, 0 );
|
|
|
|
}
|
|
|
|
|
2009-01-05 15:13:40 +01:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2005-07-23 17:31:21 +02:00
|
|
|
static void
|
2009-03-06 14:43:03 +01:00
|
|
|
ce_util_addrChange( XW_UtilCtxt* uc,
|
2009-09-20 22:49:37 +02:00
|
|
|
const CommsAddrRec* XP_UNUSED_DBG(oldAddr),
|
2009-03-06 14:43:03 +01:00
|
|
|
const CommsAddrRec* newAddr )
|
2005-07-23 17:31:21 +02:00
|
|
|
{
|
2009-03-06 14:43:03 +01:00
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
|
|
|
|
|
|
|
XP_LOGF( "%s: old: %s -> new: %s", __func__,
|
|
|
|
ConnType2Str( oldAddr->conType ),
|
|
|
|
ConnType2Str( newAddr->conType ) );
|
|
|
|
|
|
|
|
/* A lot more needs to be tested for and done here... */
|
|
|
|
if ( COMMS_CONN_NONE == newAddr->conType ) {
|
|
|
|
if ( !!globals->socketWrap ) {
|
|
|
|
ce_sockwrap_delete( globals->socketWrap );
|
|
|
|
globals->socketWrap = NULL;
|
|
|
|
}
|
|
|
|
}
|
2005-07-23 17:31:21 +02:00
|
|
|
} /* ce_util_addrChange */
|
|
|
|
#endif
|
|
|
|
|
2004-07-10 19:46:36 +02:00
|
|
|
#ifdef XWFEATURE_SEARCHLIMIT
|
|
|
|
static XP_Bool
|
|
|
|
ce_util_getTraySearchLimits( XW_UtilCtxt* uc, XP_U16* min, XP_U16* max )
|
|
|
|
{
|
|
|
|
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
|
|
|
|
HintLimitsState hls;
|
|
|
|
|
|
|
|
XP_MEMSET( &hls, 0, sizeof(hls) );
|
|
|
|
|
2008-06-05 06:29:28 +02:00
|
|
|
hls.dlgHdr.globals = globals;
|
2004-07-10 19:46:36 +02:00
|
|
|
hls.min = *min;
|
|
|
|
hls.max = *max;
|
|
|
|
|
2008-12-07 06:21:13 +01:00
|
|
|
assertOnTop( globals->hWnd );
|
2009-04-11 17:45:59 +02:00
|
|
|
DialogBoxParam( globals->locInst, (LPCTSTR)IDD_ASKHINTLIMTS, globals->hWnd,
|
2006-02-06 05:41:14 +01:00
|
|
|
(DLGPROC)HintLimitsDlg, (long)&hls );
|
2004-07-10 19:46:36 +02:00
|
|
|
|
|
|
|
if ( !hls.cancelled ) {
|
|
|
|
*min = hls.min;
|
|
|
|
*max = hls.max;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !hls.cancelled;
|
|
|
|
} /* ce_util_getTraySearchLimits */
|
|
|
|
#endif
|
|
|
|
|
2003-11-20 17:26:35 +01:00
|
|
|
#ifdef SHOW_PROGRESS
|
2008-07-24 06:16:48 +02:00
|
|
|
blah blah -- these are not in use
|
2003-11-20 17:26:35 +01:00
|
|
|
static void
|
|
|
|
ce_util_engineStarting( XW_UtilCtxt* uc )
|
|
|
|
{
|
|
|
|
} /* ce_util_engineStarting */
|
|
|
|
|
|
|
|
static void
|
|
|
|
ce_util_engineStopping( XW_UtilCtxt* uc )
|
|
|
|
{
|
|
|
|
} /* ce_util_engineStopping */
|
|
|
|
#endif
|