2008-08-27 14:16:33 +02:00
|
|
|
/* -*- fill-column: 77; compile-command: "make TARGET_OS=wince DEBUG=TRUE" -*- */
|
2008-03-23 20:25:49 +01:00
|
|
|
/*
|
2008-08-27 14:16:33 +02:00
|
|
|
* Copyright 2004-2008 by Eric House (xwords@eehouse.org). All rights
|
|
|
|
* reserved.
|
2008-03-23 20:25:49 +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 <windowsx.h>
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include <commdlg.h>
|
2008-06-07 16:42:20 +02:00
|
|
|
#ifdef _win32_wce
|
2008-06-01 00:07:29 +02:00
|
|
|
#include <aygshell.h>
|
2008-06-07 16:42:20 +02:00
|
|
|
#endif
|
2008-03-23 20:25:49 +01:00
|
|
|
|
|
|
|
#include "cemain.h"
|
|
|
|
#include "cesvdgms.h"
|
|
|
|
#include "ceutil.h"
|
|
|
|
#include "cedebug.h"
|
2008-06-01 00:07:29 +02:00
|
|
|
#include "debhacks.h"
|
2008-03-23 20:25:49 +01:00
|
|
|
|
2008-04-13 19:14:16 +02:00
|
|
|
typedef struct CeSaveGameNameState {
|
2008-06-05 06:29:28 +02:00
|
|
|
CeDlgHdr dlgHdr;
|
2008-03-23 20:25:49 +01:00
|
|
|
wchar_t* buf;
|
|
|
|
XP_U16 buflen;
|
2008-06-26 06:17:14 +02:00
|
|
|
XP_U16 lableTextId;
|
2008-03-23 20:25:49 +01:00
|
|
|
XP_Bool cancelled;
|
|
|
|
XP_Bool inited;
|
2008-04-13 19:14:16 +02:00
|
|
|
} CeSaveGameNameState;
|
2008-03-23 20:25:49 +01:00
|
|
|
|
|
|
|
static XP_Bool
|
|
|
|
ceFileExists( const wchar_t* name )
|
|
|
|
{
|
|
|
|
wchar_t buf[128];
|
|
|
|
DWORD attributes;
|
|
|
|
swprintf( buf, DEFAULT_DIR_NAME L"\\%s.xwg", name );
|
|
|
|
|
|
|
|
attributes = GetFileAttributes( buf );
|
|
|
|
return attributes != 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
makeUniqueName( wchar_t* buf, XP_U16 bufLen )
|
|
|
|
{
|
2008-03-31 02:26:18 +02:00
|
|
|
XP_U16 ii;
|
|
|
|
for ( ii = 1; ii < 100; ++ii ) {
|
2008-04-13 19:14:16 +02:00
|
|
|
int len = swprintf( buf, L"Untitled%d", ii );
|
|
|
|
XP_ASSERT( len < bufLen );
|
2008-03-23 20:25:49 +01:00
|
|
|
if ( !ceFileExists( buf ) ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* If we fall out of the loop, the user will be asked to confirm delete
|
|
|
|
of Untitled99 or somesuch. That's ok.... */
|
|
|
|
} /* makeUniqueName */
|
|
|
|
|
|
|
|
static LRESULT CALLBACK
|
|
|
|
SaveNameDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
|
|
|
|
{
|
2008-04-13 19:14:16 +02:00
|
|
|
CeSaveGameNameState* state;
|
2008-03-23 20:25:49 +01:00
|
|
|
XP_U16 wid;
|
|
|
|
BOOL result = FALSE;
|
|
|
|
|
|
|
|
if ( message == WM_INITDIALOG ) {
|
2008-09-27 17:05:26 +02:00
|
|
|
SetWindowLongPtr( hDlg, GWL_USERDATA, lParam );
|
2008-03-23 20:25:49 +01:00
|
|
|
|
2008-04-13 19:14:16 +02:00
|
|
|
state = (CeSaveGameNameState*)lParam;
|
2008-03-23 20:25:49 +01:00
|
|
|
state->cancelled = XP_TRUE;
|
|
|
|
state->inited = XP_FALSE;
|
|
|
|
|
2008-06-26 06:17:14 +02:00
|
|
|
wchar_t buf[128];
|
|
|
|
LoadString( state->dlgHdr.globals->hInst, state->lableTextId,
|
|
|
|
buf, VSIZE(buf) );
|
|
|
|
(void)SetDlgItemText( hDlg, IDC_SVGN_SELLAB, buf );
|
|
|
|
|
2008-06-05 06:29:28 +02:00
|
|
|
ceDlgSetup( &state->dlgHdr, hDlg, DLG_STATE_TRAPBACK );
|
2008-03-23 20:25:49 +01:00
|
|
|
|
|
|
|
result = TRUE;
|
|
|
|
} else {
|
2008-09-27 17:05:26 +02:00
|
|
|
state = (CeSaveGameNameState*)GetWindowLongPtr( hDlg, GWL_USERDATA );
|
2008-03-23 20:25:49 +01:00
|
|
|
if ( !!state ) {
|
|
|
|
if ( !state->inited ) {
|
|
|
|
state->inited = XP_TRUE;
|
2008-04-13 19:14:16 +02:00
|
|
|
(void)SetDlgItemText( hDlg, IDC_SVGN_EDIT, state->buf );
|
2008-03-23 20:25:49 +01:00
|
|
|
}
|
|
|
|
|
2008-06-05 06:29:28 +02:00
|
|
|
if ( ceDoDlgHandle( &state->dlgHdr, message, wParam, lParam) ) {
|
|
|
|
result = TRUE;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
switch (message) {
|
|
|
|
case WM_COMMAND:
|
|
|
|
wid = LOWORD(wParam);
|
|
|
|
switch( wid ) {
|
|
|
|
case IDOK: {
|
|
|
|
wchar_t buf[128];
|
|
|
|
(void)GetDlgItemText( hDlg, IDC_SVGN_EDIT, buf,
|
|
|
|
VSIZE(buf) );
|
|
|
|
if ( ceFileExists( buf ) ) {
|
2008-08-27 14:16:33 +02:00
|
|
|
messageBoxChar( state->dlgHdr.globals,
|
|
|
|
"File exists", L"Oops!", MB_OK );
|
2008-06-05 06:29:28 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-08-27 14:16:33 +02:00
|
|
|
swprintf( state->buf, DEFAULT_DIR_NAME L"\\%s.xwg",
|
|
|
|
buf );
|
2008-06-05 06:29:28 +02:00
|
|
|
XP_LOGW( __func__, state->buf );
|
|
|
|
/* fallthru */
|
|
|
|
state->cancelled = XP_FALSE;
|
|
|
|
}
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hDlg, wid);
|
|
|
|
result = TRUE;
|
2008-03-23 20:25:49 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2008-04-13 19:14:16 +02:00
|
|
|
} /* SaveNameDlg */
|
2008-03-23 20:25:49 +01:00
|
|
|
|
|
|
|
XP_Bool
|
2008-07-28 07:02:39 +02:00
|
|
|
ceConfirmUniqueName( CEAppGlobals* globals, XP_U16 strId, wchar_t* buf,
|
|
|
|
XP_U16 buflen )
|
2008-03-23 20:25:49 +01:00
|
|
|
{
|
2008-04-13 19:14:16 +02:00
|
|
|
CeSaveGameNameState state;
|
2008-03-23 20:25:49 +01:00
|
|
|
|
|
|
|
LOG_FUNC();
|
|
|
|
|
|
|
|
makeUniqueName( buf, buflen );
|
|
|
|
|
|
|
|
XP_MEMSET( &state, 0, sizeof(state) );
|
2008-06-05 06:29:28 +02:00
|
|
|
state.dlgHdr.globals = globals;
|
2008-03-23 20:25:49 +01:00
|
|
|
state.buf = buf;
|
|
|
|
state.buflen = buflen;
|
2008-06-26 06:17:14 +02:00
|
|
|
state.lableTextId = strId;
|
2008-03-23 20:25:49 +01:00
|
|
|
(void)DialogBoxParam( globals->hInst, (LPCTSTR)IDD_SAVENAMEDLG,
|
|
|
|
globals->hWnd,
|
|
|
|
(DLGPROC)SaveNameDlg, (long)&state );
|
|
|
|
XP_LOGW( __func__, buf );
|
|
|
|
return !state.cancelled;
|
|
|
|
} /* ceConfirmUniqueName */
|
|
|
|
|
2008-04-13 19:14:16 +02:00
|
|
|
typedef struct CeSavedGamesState {
|
2008-06-05 06:29:28 +02:00
|
|
|
CeDlgHdr dlgHdr;
|
2008-03-23 20:25:49 +01:00
|
|
|
wchar_t* buf;
|
|
|
|
XP_U16 buflen;
|
|
|
|
XP_S16 sel;
|
2008-06-26 06:17:14 +02:00
|
|
|
XP_U16 openGameIndex;
|
2008-03-23 20:25:49 +01:00
|
|
|
wchar_t curName[128];
|
2008-04-13 19:14:16 +02:00
|
|
|
XP_U16 nItems;
|
2008-03-23 20:25:49 +01:00
|
|
|
|
2008-08-27 14:16:33 +02:00
|
|
|
XP_U16 gameListId;
|
2008-04-13 19:14:16 +02:00
|
|
|
XP_Bool opened;
|
2008-03-23 20:25:49 +01:00
|
|
|
XP_Bool inited;
|
2008-06-26 06:17:14 +02:00
|
|
|
XP_Bool relaunch;
|
2008-04-13 19:14:16 +02:00
|
|
|
} CeSavedGamesState;
|
2008-03-23 20:25:49 +01:00
|
|
|
|
|
|
|
/* Probably belongs as a utility */
|
|
|
|
static void
|
2008-08-27 14:16:33 +02:00
|
|
|
getCBText( CeSavedGamesState* state, XP_U16 id, XP_U16 sel, wchar_t* buf,
|
|
|
|
XP_U16* lenp )
|
2008-03-23 20:25:49 +01:00
|
|
|
{
|
2008-08-27 14:16:33 +02:00
|
|
|
HWND hDlg = state->dlgHdr.hDlg;
|
|
|
|
CEAppGlobals* globals = state->dlgHdr.globals;
|
|
|
|
XP_U16 len;
|
|
|
|
|
|
|
|
len = SendDlgItemMessage( hDlg, id, GETLBTEXTLEN(globals), sel, 0L );
|
|
|
|
|
2008-03-23 20:25:49 +01:00
|
|
|
if ( len < *lenp ) {
|
2008-08-27 14:16:33 +02:00
|
|
|
(void)SendDlgItemMessage( hDlg, id, GETLBTEXT(globals), sel,
|
|
|
|
(LPARAM)buf );
|
2008-03-23 20:25:49 +01:00
|
|
|
} else {
|
|
|
|
XP_ASSERT( 0 );
|
|
|
|
}
|
|
|
|
*lenp = len;
|
|
|
|
} /* getCBText */
|
|
|
|
|
|
|
|
static void
|
2008-06-26 06:17:14 +02:00
|
|
|
getFullSelPath( CeSavedGamesState* state, wchar_t* buf, XP_U16 buflen )
|
2008-03-23 20:25:49 +01:00
|
|
|
{
|
2008-06-26 06:17:14 +02:00
|
|
|
XP_U16 len;
|
|
|
|
lstrcpy( buf, DEFAULT_DIR_NAME L"\\" );
|
|
|
|
len = lstrlen( buf );
|
|
|
|
buflen -= len;
|
2008-08-27 14:16:33 +02:00
|
|
|
getCBText( state, state->gameListId, state->sel, &buf[len], &buflen );
|
2008-06-26 06:17:14 +02:00
|
|
|
lstrcat( buf, L".xwg" );
|
|
|
|
}
|
2008-03-23 20:25:49 +01:00
|
|
|
|
|
|
|
static void
|
2008-04-13 19:14:16 +02:00
|
|
|
setButtons( CeSavedGamesState* state )
|
|
|
|
{
|
2008-06-26 06:17:14 +02:00
|
|
|
XP_Bool curSelected = state->openGameIndex == state->sel;
|
|
|
|
XP_Bool haveItem = state->nItems > 0;
|
|
|
|
HWND hDlg = state->dlgHdr.hDlg;
|
|
|
|
|
|
|
|
ceEnOrDisable( hDlg, IDC_SVGM_OPEN, haveItem && !curSelected );
|
|
|
|
ceEnOrDisable( hDlg, IDC_SVGM_DUP, haveItem );
|
|
|
|
ceEnOrDisable( hDlg, IDC_SVGM_DEL, haveItem && !curSelected );
|
|
|
|
ceEnOrDisable( hDlg, IDC_SVGM_CHANGE, haveItem && !curSelected );
|
2008-04-13 19:14:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
initSavedGamesData( CeSavedGamesState* state )
|
2008-03-23 20:25:49 +01:00
|
|
|
{
|
|
|
|
HANDLE fileH;
|
2008-07-28 07:02:39 +02:00
|
|
|
HWND hDlg = state->dlgHdr.hDlg;
|
2008-08-27 14:16:33 +02:00
|
|
|
CEAppGlobals* globals = state->dlgHdr.globals;
|
2008-03-23 20:25:49 +01:00
|
|
|
WIN32_FIND_DATA data;
|
|
|
|
wchar_t path[256];
|
2008-07-28 07:02:39 +02:00
|
|
|
XP_S16 curSel = -1;
|
2008-06-26 06:17:14 +02:00
|
|
|
XP_U16 ii;
|
2008-07-28 07:02:39 +02:00
|
|
|
XP_U16 nItems = 0;
|
2008-03-23 20:25:49 +01:00
|
|
|
|
|
|
|
XP_MEMSET( &data, 0, sizeof(data) );
|
|
|
|
lstrcpy( path, DEFAULT_DIR_NAME L"\\" );
|
|
|
|
lstrcat( path, L"*.xwg" );
|
|
|
|
|
|
|
|
fileH = FindFirstFile( path, &data );
|
|
|
|
for ( ii = 0; fileH != INVALID_HANDLE_VALUE; ++ii ) {
|
|
|
|
XP_U16 len = wcslen( data.cFileName );
|
2008-07-28 07:02:39 +02:00
|
|
|
XP_U16 item;
|
|
|
|
XP_Bool isCurGame = 0 == wcscmp( state->curName, data.cFileName );
|
2008-03-23 20:25:49 +01:00
|
|
|
|
2008-07-28 07:02:39 +02:00
|
|
|
XP_ASSERT( data.cFileName[len-4] == '.');
|
|
|
|
data.cFileName[len-4] = 0;
|
|
|
|
|
|
|
|
/* Insert in sorted order. This should be fast enough for reasonable
|
|
|
|
numbers of saved games. */
|
|
|
|
for ( item = 0; item < nItems; ++item ) {
|
|
|
|
wchar_t buf[256];
|
2008-08-27 14:16:33 +02:00
|
|
|
(void)SendDlgItemMessage( hDlg, state->gameListId,
|
|
|
|
GETLBTEXT(globals), item,
|
2008-07-28 07:02:39 +02:00
|
|
|
(LPARAM)buf );
|
|
|
|
/* Does the current item belong above the one we're inserting? */
|
|
|
|
if ( 0 <= wcscmp( buf, data.cFileName ) ) {
|
|
|
|
break;
|
2008-06-26 06:17:14 +02:00
|
|
|
}
|
2008-03-23 20:25:49 +01:00
|
|
|
}
|
2008-08-27 14:16:33 +02:00
|
|
|
(void)SendDlgItemMessage( hDlg, state->gameListId,
|
|
|
|
INSERTSTRING(globals),
|
2008-07-28 07:02:39 +02:00
|
|
|
item, (LPARAM)data.cFileName );
|
2008-03-23 20:25:49 +01:00
|
|
|
|
2008-07-28 07:02:39 +02:00
|
|
|
/* Remember which entry matches the currently opened game, and adjust
|
|
|
|
if it's changed. We may be incrementing an uninitialized curSel,
|
|
|
|
but that's ok as isCurGame is guaranteed to be true exactly once
|
|
|
|
through. */
|
|
|
|
if ( isCurGame ) {
|
|
|
|
curSel = item;
|
|
|
|
} else if ( curSel >= item ) {
|
|
|
|
++curSel; /* since we've moved it up */
|
|
|
|
}
|
2008-03-23 20:25:49 +01:00
|
|
|
|
2008-07-28 07:02:39 +02:00
|
|
|
++nItems;
|
2008-04-13 19:14:16 +02:00
|
|
|
|
2008-03-23 20:25:49 +01:00
|
|
|
if ( !FindNextFile( fileH, &data ) ) {
|
|
|
|
XP_ASSERT( GetLastError() == ERROR_NO_MORE_FILES );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-28 07:02:39 +02:00
|
|
|
state->nItems = nItems;
|
|
|
|
state->openGameIndex = curSel;
|
|
|
|
|
2008-08-27 14:16:33 +02:00
|
|
|
SendDlgItemMessage( hDlg, state->gameListId,
|
|
|
|
SETCURSEL(globals), curSel, 0 );
|
2008-03-23 20:25:49 +01:00
|
|
|
state->sel = curSel;
|
|
|
|
|
2008-04-13 19:14:16 +02:00
|
|
|
setButtons( state );
|
|
|
|
|
2008-03-23 20:25:49 +01:00
|
|
|
LOG_RETURN_VOID();
|
|
|
|
} /* initSavedGamesData */
|
|
|
|
|
2008-06-26 06:17:14 +02:00
|
|
|
static XP_Bool
|
|
|
|
renameSelected( CeSavedGamesState* state )
|
|
|
|
{
|
|
|
|
wchar_t path[MAX_PATH];
|
|
|
|
XP_Bool confirmed = ceConfirmUniqueName( state->dlgHdr.globals, IDS_RENAME,
|
|
|
|
path, VSIZE(path) );
|
|
|
|
if ( confirmed ) {
|
|
|
|
wchar_t curPath[MAX_PATH];
|
|
|
|
getFullSelPath( state, curPath, VSIZE(curPath) );
|
|
|
|
confirmed = MoveFile( curPath, path );
|
|
|
|
}
|
|
|
|
return confirmed;
|
|
|
|
} /* renameSelected */
|
2008-04-13 19:14:16 +02:00
|
|
|
|
2008-06-26 06:17:14 +02:00
|
|
|
static XP_Bool
|
|
|
|
duplicateSelected( CeSavedGamesState* state )
|
|
|
|
{
|
|
|
|
wchar_t newPath[MAX_PATH];
|
|
|
|
XP_Bool confirmed;
|
|
|
|
|
|
|
|
confirmed = ceConfirmUniqueName( state->dlgHdr.globals, IDS_DUPENAME,
|
|
|
|
newPath, VSIZE(newPath) );
|
|
|
|
if ( confirmed ) {
|
|
|
|
wchar_t curPath[MAX_PATH];
|
|
|
|
getFullSelPath( state, curPath, VSIZE(curPath) );
|
|
|
|
confirmed = CopyFile( curPath, newPath, TRUE ); /* TRUE is what??? */
|
|
|
|
}
|
|
|
|
return confirmed;
|
|
|
|
} /* duplicateSelected */
|
2008-04-13 19:14:16 +02:00
|
|
|
|
2008-06-26 06:17:14 +02:00
|
|
|
static XP_Bool
|
|
|
|
deleteSelected( CeSavedGamesState* state )
|
|
|
|
{
|
|
|
|
wchar_t buf[128];
|
|
|
|
wchar_t path[128];
|
|
|
|
XP_U16 len = VSIZE(buf);
|
|
|
|
|
|
|
|
/* confirm first!!!! */
|
|
|
|
XP_Bool confirmed = queryBoxChar( state->dlgHdr.globals,
|
|
|
|
"Are you certain you want to delete the "
|
|
|
|
"selected game? This action cannot be "
|
|
|
|
"undone.");
|
|
|
|
if ( confirmed ) {
|
2008-08-27 14:16:33 +02:00
|
|
|
getCBText( state, state->gameListId,
|
|
|
|
state->sel, buf, &len );
|
2008-06-26 06:17:14 +02:00
|
|
|
swprintf( path, DEFAULT_DIR_NAME L"\\%s.xwg", buf );
|
|
|
|
confirmed = DeleteFile( path );
|
|
|
|
if ( confirmed ) {
|
|
|
|
state->sel = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return confirmed;
|
|
|
|
} /* deleteSelected */
|
2008-04-13 19:14:16 +02:00
|
|
|
|
2008-08-27 14:16:33 +02:00
|
|
|
static XP_Bool
|
|
|
|
tryGameChanged( CeSavedGamesState* state )
|
|
|
|
{
|
|
|
|
XP_S16 sel = SendDlgItemMessage( state->dlgHdr.hDlg, state->gameListId,
|
|
|
|
GETCURSEL(state->dlgHdr.globals), 0, 0L);
|
|
|
|
XP_Bool changing = sel >= 0 && state->sel != sel;
|
|
|
|
if ( changing ) {
|
|
|
|
state->sel = sel;
|
|
|
|
setButtons( state );
|
|
|
|
}
|
|
|
|
return changing;
|
|
|
|
} /* tryGameChanged */
|
|
|
|
|
2008-03-23 20:25:49 +01:00
|
|
|
static LRESULT CALLBACK
|
|
|
|
SavedGamesDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
|
|
|
|
{
|
2008-04-13 19:14:16 +02:00
|
|
|
CeSavedGamesState* state;
|
2008-03-23 20:25:49 +01:00
|
|
|
BOOL result = FALSE;
|
|
|
|
|
|
|
|
if ( message == WM_INITDIALOG ) {
|
2008-09-27 17:05:26 +02:00
|
|
|
SetWindowLongPtr( hDlg, GWL_USERDATA, lParam );
|
2008-03-23 20:25:49 +01:00
|
|
|
|
2008-04-13 19:14:16 +02:00
|
|
|
state = (CeSavedGamesState*)lParam;
|
2008-03-23 20:25:49 +01:00
|
|
|
state->inited = XP_FALSE;
|
2008-08-27 14:16:33 +02:00
|
|
|
state->gameListId = LB_IF_PPC(state->dlgHdr.globals,IDC_SVGM_GAMELIST);
|
2008-03-23 20:25:49 +01:00
|
|
|
|
2008-06-26 06:17:14 +02:00
|
|
|
ceDlgSetup( &state->dlgHdr, hDlg, DLG_STATE_NONE|DLG_STATE_DONEONLY );
|
2008-08-27 14:16:33 +02:00
|
|
|
ceDlgComboShowHide( &state->dlgHdr, IDC_SVGM_GAMELIST );
|
2008-03-23 20:25:49 +01:00
|
|
|
|
|
|
|
result = TRUE;
|
|
|
|
} else {
|
2008-09-27 17:05:26 +02:00
|
|
|
state = (CeSavedGamesState*)GetWindowLongPtr( hDlg, GWL_USERDATA );
|
2008-03-23 20:25:49 +01:00
|
|
|
if ( !!state ) {
|
|
|
|
|
|
|
|
if ( !state->inited ) {
|
|
|
|
state->inited = XP_TRUE;
|
|
|
|
initSavedGamesData( state );
|
|
|
|
}
|
|
|
|
|
2008-06-05 06:29:28 +02:00
|
|
|
if ( ceDoDlgHandle( &state->dlgHdr, message, wParam, lParam) ) {
|
|
|
|
result = TRUE;
|
2008-08-27 14:16:33 +02:00
|
|
|
} else if ( WM_NOTIFY == message ) {
|
|
|
|
result = tryGameChanged( state );
|
2008-06-26 06:17:14 +02:00
|
|
|
} else if ( message == WM_COMMAND ) {
|
|
|
|
XP_U16 wid = LOWORD(wParam);
|
2008-08-27 14:16:33 +02:00
|
|
|
|
|
|
|
if ( CBN_SELCHANGE == HIWORD(wParam) ) {
|
|
|
|
if (state->gameListId == wid ) {
|
|
|
|
result = tryGameChanged( state );
|
2008-06-26 06:17:14 +02:00
|
|
|
}
|
|
|
|
} else if ( BN_CLICKED == HIWORD(wParam) ) {
|
2008-06-05 06:29:28 +02:00
|
|
|
switch( wid ) {
|
2008-06-26 06:17:14 +02:00
|
|
|
case IDC_SVGM_DUP:
|
|
|
|
state->relaunch = duplicateSelected( state );
|
|
|
|
break;
|
|
|
|
case IDC_SVGM_CHANGE:
|
|
|
|
state->relaunch = renameSelected( state );
|
|
|
|
break;
|
|
|
|
case IDC_SVGM_DEL:
|
|
|
|
state->relaunch = deleteSelected( state );
|
2008-06-05 06:29:28 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_SVGM_OPEN: {
|
|
|
|
wchar_t buf[128];
|
|
|
|
XP_U16 len = VSIZE(buf);
|
2008-08-27 14:16:33 +02:00
|
|
|
getCBText( state, state->gameListId, state->sel,
|
2008-06-05 06:29:28 +02:00
|
|
|
buf, &len );
|
2008-08-27 14:16:33 +02:00
|
|
|
swprintf( state->buf, DEFAULT_DIR_NAME L"\\%s.xwg",
|
|
|
|
buf );
|
2008-06-05 06:29:28 +02:00
|
|
|
XP_LOGW( "returning", state->buf );
|
|
|
|
state->opened = XP_TRUE;
|
|
|
|
}
|
|
|
|
/* fallthrough */
|
2008-06-26 06:17:14 +02:00
|
|
|
case IDOK: /* Done button */
|
2008-06-05 06:29:28 +02:00
|
|
|
EndDialog(hDlg, wid);
|
|
|
|
result = TRUE;
|
|
|
|
break;
|
2008-03-23 20:25:49 +01:00
|
|
|
}
|
2008-06-26 06:17:14 +02:00
|
|
|
|
|
|
|
if ( state->relaunch ) {
|
|
|
|
EndDialog( hDlg, wid );
|
|
|
|
result = TRUE;
|
|
|
|
}
|
2008-03-23 20:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} /* SavedGamesDlg */
|
|
|
|
|
|
|
|
XP_Bool
|
|
|
|
ceSavedGamesDlg( CEAppGlobals* globals, const XP_UCHAR* curPath,
|
|
|
|
wchar_t* buf, XP_U16 buflen )
|
|
|
|
{
|
2008-04-13 19:14:16 +02:00
|
|
|
CeSavedGamesState state;
|
2008-03-23 20:25:49 +01:00
|
|
|
|
|
|
|
LOG_FUNC();
|
|
|
|
|
|
|
|
XP_MEMSET( &state, 0, sizeof(state) ); /* sets cancelled */
|
2008-06-05 06:29:28 +02:00
|
|
|
state.dlgHdr.globals = globals;
|
2008-03-23 20:25:49 +01:00
|
|
|
state.buf = buf;
|
|
|
|
state.buflen = buflen;
|
2008-06-26 06:17:14 +02:00
|
|
|
state.sel = -1;
|
2008-03-23 20:25:49 +01:00
|
|
|
|
|
|
|
if ( !!curPath ) {
|
|
|
|
wchar_t shortName[128];
|
|
|
|
XP_U16 len;
|
|
|
|
XP_LOGF( curPath );
|
|
|
|
|
|
|
|
len = (XP_U16)XP_STRLEN( curPath );
|
|
|
|
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, curPath, len + 1,
|
|
|
|
shortName, len + 1 );
|
|
|
|
len = wcslen( DEFAULT_DIR_NAME L"\\" );
|
|
|
|
lstrcpy( state.curName, shortName+len );
|
|
|
|
XP_LOGW( "shortName", state.curName );
|
|
|
|
}
|
|
|
|
|
2008-06-26 06:17:14 +02:00
|
|
|
for ( ; ; ) {
|
|
|
|
(void)DialogBoxParam( globals->hInst, (LPCTSTR)IDD_SAVEDGAMESDLG,
|
|
|
|
globals->hWnd,
|
|
|
|
(DLGPROC)SavedGamesDlg, (long)&state );
|
2008-03-23 20:25:49 +01:00
|
|
|
|
2008-06-26 06:17:14 +02:00
|
|
|
if ( !state.relaunch ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
state.relaunch = XP_FALSE;
|
|
|
|
}
|
2008-03-23 20:25:49 +01:00
|
|
|
XP_LOGW( __func__, buf );
|
|
|
|
|
2008-04-13 19:14:16 +02:00
|
|
|
return state.opened;
|
2008-06-26 06:17:14 +02:00
|
|
|
} /* ceSavedGamesDlg */
|