2009-09-04 14:32:16 +02:00
|
|
|
/* -*- fill-column: 77; compile-command: "make -j2 TARGET_OS=wince DEBUG=TRUE" -*- */
|
2003-11-20 05:40:34 +01:00
|
|
|
/*
|
2009-01-17 19:41:15 +01:00
|
|
|
* Copyright 2002-2009 by Eric House (xwords@eehouse.org). All rights
|
|
|
|
* reserved.
|
2003-11-20 05:40:34 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ceblank.h"
|
|
|
|
#include "cemain.h"
|
|
|
|
#include "ceutil.h"
|
2008-06-01 00:07:29 +02:00
|
|
|
#include "debhacks.h"
|
2009-10-23 10:54:54 +02:00
|
|
|
#include "cedebug.h"
|
|
|
|
|
|
|
|
typedef struct BlankDialogState {
|
|
|
|
CeDlgHdr dlgHdr;
|
|
|
|
const PickInfo* pi;
|
|
|
|
XP_U16 playerNum;
|
|
|
|
const XP_UCHAR** texts;
|
|
|
|
XP_U16 nTiles;
|
|
|
|
XP_S16 result;
|
|
|
|
XP_Bool canBackup;
|
|
|
|
} BlankDialogState;
|
2003-11-20 05:40:34 +01:00
|
|
|
|
|
|
|
static void
|
2008-08-27 14:16:33 +02:00
|
|
|
loadLettersList( BlankDialogState* bState )
|
2003-11-20 05:40:34 +01:00
|
|
|
{
|
2009-09-04 14:32:16 +02:00
|
|
|
XP_U16 ii;
|
2003-11-20 05:40:34 +01:00
|
|
|
XP_U16 nTiles = bState->nTiles;
|
2008-08-27 14:16:33 +02:00
|
|
|
HWND hDlg = bState->dlgHdr.hDlg;
|
|
|
|
CEAppGlobals* globals = bState->dlgHdr.globals;
|
2009-04-07 06:23:56 +02:00
|
|
|
const XP_UCHAR** texts = bState->texts;
|
2003-11-20 05:40:34 +01:00
|
|
|
|
2009-09-04 14:32:16 +02:00
|
|
|
for ( ii = 0; ii < nTiles; ++ii ) {
|
2003-11-20 05:40:34 +01:00
|
|
|
XP_U16 len;
|
|
|
|
wchar_t widebuf[4];
|
|
|
|
|
2009-10-23 10:54:54 +02:00
|
|
|
len = MultiByteToWideChar( CP_UTF8, 0, texts[ii], strlen(texts[ii]),
|
2007-05-26 16:03:07 +02:00
|
|
|
widebuf, VSIZE(widebuf) );
|
2003-11-20 05:40:34 +01:00
|
|
|
widebuf[len] = 0;
|
|
|
|
|
2008-08-27 14:16:33 +02:00
|
|
|
SendDlgItemMessage( hDlg, LB_IF_PPC(globals,BLANKFACE_LIST),
|
|
|
|
ADDSTRING(globals), 0, (long)widebuf );
|
2003-11-20 05:40:34 +01:00
|
|
|
}
|
2008-08-27 14:16:33 +02:00
|
|
|
|
|
|
|
SendDlgItemMessage( hDlg, LB_IF_PPC(globals,BLANKFACE_LIST),
|
|
|
|
SETCURSEL(globals), 0, 0 );
|
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
SendDlgItemMessage( hDlg, BLANKFACE_LIST_PPC, LB_SETANCHORINDEX, 0, 0 );
|
|
|
|
#endif
|
2003-11-20 05:40:34 +01:00
|
|
|
} /* loadLettersList */
|
|
|
|
|
2003-12-09 06:16:11 +01:00
|
|
|
#ifdef FEATURE_TRAY_EDIT
|
|
|
|
static void
|
|
|
|
showCurTray( HWND hDlg, BlankDialogState* bState )
|
|
|
|
{
|
|
|
|
if ( bState->pi->why == PICK_FOR_CHEAT ) {
|
2005-06-23 16:12:09 +02:00
|
|
|
const PickInfo* pi = bState->pi;
|
2003-12-09 06:16:11 +01:00
|
|
|
XP_U16 lenSoFar = 0;
|
|
|
|
XP_U16 i;
|
|
|
|
XP_UCHAR labelBuf[48];
|
|
|
|
wchar_t widebuf[48];
|
|
|
|
XP_UCHAR* name;
|
2009-04-05 22:18:46 +02:00
|
|
|
CEAppGlobals* globals = bState->dlgHdr.globals;
|
2003-12-09 06:16:11 +01:00
|
|
|
|
2009-04-05 22:18:46 +02:00
|
|
|
name = globals->gameInfo.players[bState->playerNum].name;
|
2003-12-09 06:16:11 +01:00
|
|
|
|
|
|
|
lenSoFar += XP_SNPRINTF( labelBuf + lenSoFar,
|
|
|
|
sizeof(labelBuf) - lenSoFar,
|
|
|
|
"%d of %d for %s" XP_CR "Cur",
|
2004-05-15 03:06:39 +02:00
|
|
|
pi->thisPick + 1, pi->nTotal, name );
|
2003-12-09 06:16:11 +01:00
|
|
|
|
|
|
|
for ( i = 0; i < pi->nCurTiles; ++i ) {
|
|
|
|
lenSoFar += XP_SNPRINTF( labelBuf+lenSoFar,
|
|
|
|
sizeof(labelBuf)-lenSoFar, "%s%s",
|
|
|
|
i==0?": ":", ", pi->curTiles[i] );
|
|
|
|
}
|
|
|
|
|
2009-10-23 10:54:54 +02:00
|
|
|
(void)MultiByteToWideChar( CP_UTF8, 0, labelBuf, lenSoFar + 1, widebuf,
|
2007-05-26 16:03:07 +02:00
|
|
|
VSIZE(widebuf) + sizeof(widebuf[0]) );
|
2003-12-09 06:16:11 +01:00
|
|
|
|
|
|
|
SetDlgItemText( hDlg,IDC_PICKMSG, widebuf );
|
|
|
|
}
|
|
|
|
} /* showCurTray */
|
|
|
|
#endif
|
|
|
|
|
2009-10-23 10:54:54 +02:00
|
|
|
static LRESULT CALLBACK
|
2003-11-20 05:40:34 +01:00
|
|
|
BlankDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
BlankDialogState* bState;
|
|
|
|
XP_U16 id;
|
2009-01-17 19:41:15 +01:00
|
|
|
LRESULT result = FALSE; /* default */
|
2003-11-20 05:40:34 +01:00
|
|
|
|
|
|
|
if ( message == WM_INITDIALOG ) {
|
2008-09-27 17:05:26 +02:00
|
|
|
SetWindowLongPtr( hDlg, GWL_USERDATA, lParam );
|
2003-11-20 05:40:34 +01:00
|
|
|
bState = (BlankDialogState*)lParam;
|
|
|
|
|
2003-12-09 06:16:11 +01:00
|
|
|
#ifdef FEATURE_TRAY_EDIT
|
|
|
|
if ( bState->pi->why == PICK_FOR_CHEAT ) {
|
|
|
|
showCurTray( hDlg, bState );
|
|
|
|
ceShowOrHide( hDlg, IDC_BPICK, XP_FALSE );
|
|
|
|
} else {
|
|
|
|
XP_ASSERT( bState->pi->why == PICK_FOR_BLANK );
|
|
|
|
ceShowOrHide( hDlg, IDC_CPICK, XP_FALSE );
|
2004-02-14 07:03:53 +01:00
|
|
|
ceShowOrHide( hDlg, IDC_PICKMSG, XP_FALSE );
|
2003-12-09 06:16:11 +01:00
|
|
|
}
|
2008-06-01 00:07:29 +02:00
|
|
|
bState->canBackup = (bState->pi->why == PICK_FOR_CHEAT)
|
|
|
|
&& (bState->pi->thisPick > 0);
|
|
|
|
ceShowOrHide( hDlg, IDC_BACKUP, bState->canBackup );
|
2003-12-09 06:16:11 +01:00
|
|
|
#endif
|
|
|
|
|
2008-06-05 06:29:28 +02:00
|
|
|
ceDlgSetup( &bState->dlgHdr, hDlg, DLG_STATE_TRAPBACK );
|
2008-08-27 14:16:33 +02:00
|
|
|
ceDlgComboShowHide( &bState->dlgHdr, BLANKFACE_LIST );
|
2008-03-24 13:41:12 +01:00
|
|
|
|
2008-08-27 14:16:33 +02:00
|
|
|
loadLettersList( bState );
|
2009-01-17 19:41:15 +01:00
|
|
|
result = TRUE;
|
2003-11-20 05:40:34 +01:00
|
|
|
} else {
|
2008-09-27 17:05:26 +02:00
|
|
|
bState = (BlankDialogState*)GetWindowLongPtr( hDlg, GWL_USERDATA );
|
2004-05-26 06:39:29 +02:00
|
|
|
if ( !!bState ) {
|
2003-11-20 05:40:34 +01:00
|
|
|
|
2008-06-05 06:29:28 +02:00
|
|
|
if ( ceDoDlgHandle( &bState->dlgHdr, message, wParam, lParam) ) {
|
2009-01-17 19:41:15 +01:00
|
|
|
result = TRUE;
|
|
|
|
goto exit;
|
2008-06-05 06:29:28 +02:00
|
|
|
}
|
|
|
|
|
2004-05-26 06:39:29 +02:00
|
|
|
switch ( message ) {
|
|
|
|
case WM_COMMAND:
|
|
|
|
id = LOWORD(wParam);
|
|
|
|
if ( 0 ) {
|
2004-02-14 07:03:53 +01:00
|
|
|
#ifdef FEATURE_TRAY_EDIT
|
2008-06-01 00:07:29 +02:00
|
|
|
} else if ( id == IDCANCEL ) {
|
2004-05-26 06:39:29 +02:00
|
|
|
bState->result = PICKER_PICKALL;
|
|
|
|
} else if ( id == IDC_BACKUP ) {
|
|
|
|
bState->result = PICKER_BACKUP;
|
2004-02-14 07:03:53 +01:00
|
|
|
#endif
|
2004-05-26 06:39:29 +02:00
|
|
|
} else if ( id == IDOK ) {
|
2008-08-27 14:16:33 +02:00
|
|
|
CEAppGlobals* globals = bState->dlgHdr.globals;
|
|
|
|
bState->result = (XP_S16)
|
|
|
|
SendDlgItemMessage( hDlg,
|
|
|
|
LB_IF_PPC(globals,BLANKFACE_LIST),
|
|
|
|
GETCURSEL(globals), 0, 0 );
|
2004-05-26 06:39:29 +02:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
EndDialog( hDlg, id );
|
2009-01-17 19:41:15 +01:00
|
|
|
result = TRUE;
|
2003-11-20 05:40:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-17 19:41:15 +01:00
|
|
|
exit:
|
|
|
|
return result;
|
2003-11-20 05:40:34 +01:00
|
|
|
} /* BlankDlg */
|
2009-10-23 10:54:54 +02:00
|
|
|
|
|
|
|
XP_Bool
|
|
|
|
WrapBlankDlg( CEAppGlobals* globals, const PickInfo* pi,
|
|
|
|
XP_U16 playerNum, const XP_UCHAR** texts, XP_U16 nTiles )
|
|
|
|
{
|
|
|
|
BlankDialogState state;
|
|
|
|
XP_MEMSET( &state, 0, sizeof(state) );
|
|
|
|
|
|
|
|
state.dlgHdr.globals = globals;
|
|
|
|
state.texts = texts;
|
|
|
|
state.nTiles = nTiles;
|
|
|
|
state.playerNum = playerNum;
|
|
|
|
state.pi = pi;
|
|
|
|
|
|
|
|
assertOnTop( globals->hWnd );
|
|
|
|
DialogBoxParam( globals->locInst, (LPCTSTR)IDD_ASKBLANK, globals->hWnd,
|
|
|
|
(DLGPROC)BlankDlg, (long)&state );
|
|
|
|
return state.result;
|
|
|
|
}
|