mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-28 07:58:08 +01:00
Use SHGetSpecialFolderPath to locate dicts in /Document Files/Crosswords; reserve 1-pixel space around Rem: text
This commit is contained in:
parent
91b20350f7
commit
cbdf8edcf5
8 changed files with 69 additions and 50 deletions
|
@ -30,6 +30,7 @@
|
|||
#include "cedict.h"
|
||||
#include "debhacks.h"
|
||||
#include "cedebug.h"
|
||||
#include "ceutil.h"
|
||||
|
||||
typedef struct CEDictionaryCtxt {
|
||||
DictionaryCtxt super;
|
||||
|
@ -651,13 +652,19 @@ getDictDir( wchar_t* buf, XP_U16 bufLen )
|
|||
} /* getDictDir */
|
||||
|
||||
XP_U16
|
||||
ceLocateNDicts( MPFORMAL XP_U16 nSought, OnePathCB cb, void* ctxt )
|
||||
ceLocateNDicts( CEAppGlobals* globals, XP_U16 nSought, OnePathCB cb,
|
||||
void* ctxt )
|
||||
{
|
||||
XP_U16 nFound = 0;
|
||||
wchar_t path[CE_MAX_PATH_LEN+1];
|
||||
|
||||
if ( getDictDir( path, VSIZE(path) ) ) {
|
||||
locateOneDir( MPPARM(mpool) path, cb, ctxt, nSought, &nFound );
|
||||
locateOneDir( MPPARM(globals->mpool) path, cb, ctxt, nSought, &nFound );
|
||||
}
|
||||
|
||||
if ( nFound < nSought ) {
|
||||
ceGetPath( globals, PROGFILES_PATH, path, VSIZE(path) );
|
||||
locateOneDir( MPPARM(globals->mpool) path, cb, ctxt, nSought, &nFound );
|
||||
}
|
||||
|
||||
if ( nFound < nSought ) {
|
||||
|
@ -673,7 +680,8 @@ ceLocateNDicts( MPFORMAL XP_U16 nSought, OnePathCB cb, void* ctxt )
|
|||
wsprintf( path, L"\\%s\\Crosswords", data.cFileName );
|
||||
|
||||
XP_LOGW( "looking in:", path );
|
||||
locateOneDir( MPPARM(mpool) path, cb, ctxt, nSought, &nFound );
|
||||
locateOneDir( MPPARM(globals->mpool) path, cb, ctxt,
|
||||
nSought, &nFound );
|
||||
}
|
||||
if ( nFound >= nSought ) {
|
||||
break;
|
||||
|
@ -725,7 +733,7 @@ findAlternateDict( CEAppGlobals* XP_UNUSED_DBG(globals), wchar_t* path )
|
|||
data.sought = wbname( shortPath, sizeof(shortPath), path );
|
||||
data.result = path;
|
||||
|
||||
(void)ceLocateNDicts( MPPARM(globals->mpool) CE_MAXDICTS, matchShortName,
|
||||
(void)ceLocateNDicts( globals, CE_MAXDICTS, matchShortName,
|
||||
&data );
|
||||
return data.found;
|
||||
} /* findAlternateDict */
|
||||
|
|
|
@ -40,7 +40,8 @@ typedef XP_Bool (*OnePathCB)( const wchar_t* wPath, XP_U16 index, void* ctxt );
|
|||
* dict files. Return the number actually found. Caller is responsible for
|
||||
* making sure bufs contains nSought slots.
|
||||
*/
|
||||
XP_U16 ceLocateNDicts( MPFORMAL XP_U16 nSought, OnePathCB cb, void* ctxt );
|
||||
XP_U16 ceLocateNDicts( CEAppGlobals* globals, XP_U16 nSought,
|
||||
OnePathCB cb, void* ctxt );
|
||||
|
||||
/* return just the name, no extension, of dict, written to buf, pointed to by
|
||||
return value (which is into buf, but not necessarily the first char.) */
|
||||
|
|
|
@ -226,14 +226,14 @@ ceDrawTextClipped( HDC hdc, wchar_t* buf, XP_S16 len, XP_Bool clip,
|
|||
XP_U16 width, XP_U16 hJust )
|
||||
{
|
||||
RECT rect = {
|
||||
.left = left,
|
||||
.top = top,
|
||||
.bottom = top + fce->glyphHt,
|
||||
.right = left + width
|
||||
.left = left,
|
||||
.top = top,
|
||||
.bottom = top + fce->glyphHt,
|
||||
.right = left + width
|
||||
};
|
||||
|
||||
if ( clip ) {
|
||||
ceClipToRect( hdc, &rect );
|
||||
ceClipToRect( hdc, &rect );
|
||||
}
|
||||
rect.top -= fce->offset;
|
||||
/* XP_LOGF( "%s: drawing left: %ld, top: %ld, right: %ld, bottom: %ld", */
|
||||
|
@ -1171,7 +1171,7 @@ DRAW_FUNC_NAME(measureRemText)( DrawCtx* p_dctx, const XP_Rect* xprect,
|
|||
|
||||
formatRemText( nTilesLeft, dctx->scoreIsVertical, buf );
|
||||
|
||||
height = xprect->height-2;
|
||||
height = xprect->height - 2; /* space for border */
|
||||
if ( height > globals->cellHt - CELL_BORDER ) {
|
||||
height = globals->cellHt - CELL_BORDER;
|
||||
}
|
||||
|
@ -1180,6 +1180,10 @@ DRAW_FUNC_NAME(measureRemText)( DrawCtx* p_dctx, const XP_Rect* xprect,
|
|||
ceMeasureText( dctx, hdc, fce, buf, 0, widthP, heightP );
|
||||
|
||||
(void)SelectObject( hdc, oldFont );
|
||||
|
||||
/* Put back the 2 we took above */
|
||||
*heightP += 2;
|
||||
*widthP += 2;
|
||||
} else {
|
||||
*widthP = *heightP = 0;
|
||||
}
|
||||
|
|
|
@ -186,8 +186,7 @@ loadFromGameInfo( GameInfoState* giState )
|
|||
(XP_U16)XP_STRLEN(gi->dictName)+1 );
|
||||
}
|
||||
if ( giState->isNewGame ) {
|
||||
(void)ceLocateNDicts( MPPARM(giState->dlgHdr.globals->mpool)
|
||||
CE_MAXDICTS, addDictToState, giState );
|
||||
(void)ceLocateNDicts( globals, CE_MAXDICTS, addDictToState, giState );
|
||||
} else {
|
||||
wchar_t wPath[CE_MAX_PATH_LEN+1];
|
||||
XP_ASSERT( gi->dictName[0] != '\0' );
|
||||
|
|
|
@ -1349,7 +1349,7 @@ InitInstance(HINSTANCE hInstance, int nCmdShow)
|
|||
|
||||
/* choose one. If none found it's an error. */
|
||||
#ifndef STUBBED_DICT
|
||||
result = 1 == ceLocateNDicts( MPPARM(mpool) 1, ceSetDictName,
|
||||
result = 1 == ceLocateNDicts( globals, 1, ceSetDictName,
|
||||
globals );
|
||||
if ( !result ) {
|
||||
wchar_t buf[512];
|
||||
|
@ -1866,6 +1866,7 @@ closeGame( CEAppGlobals* globals )
|
|||
static void
|
||||
freeGlobals( CEAppGlobals* globals )
|
||||
{
|
||||
XP_U16 ii;
|
||||
MPSLOT;
|
||||
|
||||
MPASSIGN( mpool, globals->mpool );
|
||||
|
@ -1880,8 +1881,10 @@ freeGlobals( CEAppGlobals* globals )
|
|||
if ( !!globals->util.vtable ) {
|
||||
XP_FREE( mpool, globals->util.vtable );
|
||||
}
|
||||
if ( !!globals->specialDir ) {
|
||||
XP_FREE( mpool, globals->specialDir );
|
||||
for ( ii = 0; ii < N_CACHED_PATHS; ++ii ) {
|
||||
if ( !!globals->specialDirs[ii] ) {
|
||||
XP_FREE( mpool, globals->specialDirs[ii] );
|
||||
}
|
||||
}
|
||||
|
||||
XP_FREE( globals->mpool, globals );
|
||||
|
|
|
@ -29,13 +29,14 @@
|
|||
#include "mempool.h"
|
||||
#include "cesockwr.h"
|
||||
|
||||
#define LCROSSWORDS_DIR_NODBG L"Crosswords"
|
||||
#define CE_GAMEFILE_VERSION 0x01 /* means draw gets to save/restore */
|
||||
#ifdef DEBUG
|
||||
# define CROSSWORDS_DIR "Cross_dbg"
|
||||
# define LCROSSWORDS_DIR L"Cross_dbg"
|
||||
#else
|
||||
# define CROSSWORDS_DIR "Crosswords"
|
||||
# define LCROSSWORDS_DIR L"Crosswords"
|
||||
# define LCROSSWORDS_DIR LCROSSWORDS_DIR_NODBG
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32_WCE
|
||||
|
@ -101,6 +102,12 @@ enum { OWNED_RECT_LEFT
|
|||
,N_OWNED_RECTS
|
||||
};
|
||||
|
||||
enum {
|
||||
MY_DOCS_CACHE,
|
||||
PROGFILES_CACHE,
|
||||
N_CACHED_PATHS
|
||||
};
|
||||
|
||||
typedef struct CEAppGlobals {
|
||||
HINSTANCE hInst;
|
||||
HDC hdc; /* to pass drawing ctxt to draw code */
|
||||
|
@ -160,7 +167,7 @@ typedef struct CEAppGlobals {
|
|||
int dbWidth, dbHeight;
|
||||
#endif
|
||||
|
||||
wchar_t* specialDir; /* reserved for ceGetPath() */
|
||||
wchar_t* specialDirs[N_CACHED_PATHS]; /* reserved for ceGetPath() */
|
||||
|
||||
#ifdef XWFEATURE_SEARCHLIMIT
|
||||
XP_Bool askTrayLimits;
|
||||
|
|
|
@ -747,47 +747,38 @@ trapBackspaceKey( HWND hDlg )
|
|||
}
|
||||
#endif
|
||||
|
||||
/* cegcc headers define this to SHGetSpecialFolderPathW, but that's not
|
||||
* what's in the library... */
|
||||
#ifdef SHGetSpecialFolderPath
|
||||
# undef SHGetSpecialFolderPath
|
||||
#endif
|
||||
/* Bugs in mingw32ce headers force defining _WIN32_IE, which causes
|
||||
* SHGetSpecialFolderPath to be defined as SHGetSpecialFolderPathW which
|
||||
* is not on Wince. Once I turn off _WIN32_IE this can go away. */
|
||||
#ifdef _WIN32_IE
|
||||
# ifdef SHGetSpecialFolderPath
|
||||
# undef SHGetSpecialFolderPath
|
||||
# endif
|
||||
BOOL SHGetSpecialFolderPath( HWND hwndOwner,
|
||||
LPTSTR lpszPath,
|
||||
int nFolder,
|
||||
BOOL fCreate );
|
||||
#endif
|
||||
|
||||
static void
|
||||
lookupSpecialDir( wchar_t* bufW )
|
||||
lookupSpecialDir( wchar_t* bufW, XP_U16 indx )
|
||||
{
|
||||
bufW[0] = 0;
|
||||
#ifdef _WIN32_WCE
|
||||
#if 0
|
||||
BOOL (*mySHGetSpecialFolderPath)( HWND hwndOwner,
|
||||
LPTSTR lpszPath,
|
||||
int nFolder,
|
||||
BOOL fCreate );
|
||||
HMODULE module;
|
||||
|
||||
module = LoadLibrary( L"coredll" );
|
||||
if ( !!module ) {
|
||||
mySHGetSpecialFolderPath = GetProcAddress( module,
|
||||
L"SHGetSpecialFolderPath" );
|
||||
if ( !!mySHGetSpecialFolderPath ) {
|
||||
HRESULT res = (*mySHGetSpecialFolderPath)( NULL, bufW,
|
||||
CSIDL_PERSONAL, TRUE );
|
||||
}
|
||||
FreeLibrary( module );
|
||||
}
|
||||
#else
|
||||
SHGetSpecialFolderPath( NULL, bufW, CSIDL_PERSONAL, TRUE );
|
||||
#endif
|
||||
SHGetSpecialFolderPath( NULL, bufW,
|
||||
(indx == MY_DOCS_CACHE)?
|
||||
CSIDL_PERSONAL : CSIDL_PROGRAM_FILES,
|
||||
TRUE );
|
||||
if ( 0 == bufW[0] ) {
|
||||
XP_WARNF( "SHGetSpecialFolderPath hack failed" );
|
||||
XP_WARNF( "SHGetSpecialFolderPath failed" );
|
||||
wcscpy( bufW, L"\\My Documents" );
|
||||
}
|
||||
#endif
|
||||
wcscat( bufW, L"\\" LCROSSWORDS_DIR L"\\" );
|
||||
if ( indx == PROGFILES_CACHE ) {
|
||||
wcscat( bufW, L"\\" LCROSSWORDS_DIR_NODBG );
|
||||
} else {
|
||||
wcscat( bufW, L"\\" LCROSSWORDS_DIR L"\\" );
|
||||
}
|
||||
}
|
||||
|
||||
XP_U16
|
||||
|
@ -796,17 +787,18 @@ ceGetPath( CEAppGlobals* globals, CePathType typ,
|
|||
{
|
||||
XP_U16 len;
|
||||
wchar_t bufW[CE_MAX_PATH_LEN];
|
||||
wchar_t* specialDir = globals->specialDir;
|
||||
XP_U16 cacheIndx = typ == PROGFILES_PATH ? PROGFILES_CACHE : MY_DOCS_CACHE;
|
||||
wchar_t* specialDir = globals->specialDirs[cacheIndx];
|
||||
XP_Bool asAscii = XP_FALSE;
|
||||
|
||||
if ( !specialDir ) {
|
||||
wchar_t buf[128];
|
||||
XP_U16 len;
|
||||
lookupSpecialDir( buf );
|
||||
lookupSpecialDir( buf, cacheIndx );
|
||||
len = 1 + wcslen( buf );
|
||||
specialDir = XP_MALLOC( globals->mpool, len * sizeof(specialDir[0]) );
|
||||
wcscpy( specialDir, buf );
|
||||
globals->specialDir = specialDir;
|
||||
globals->specialDirs[cacheIndx] = specialDir;
|
||||
}
|
||||
|
||||
wcscpy( bufW, specialDir );
|
||||
|
@ -822,11 +814,15 @@ ceGetPath( CEAppGlobals* globals, CePathType typ,
|
|||
asAscii = XP_TRUE;
|
||||
wcscat( bufW, L"_newgame" );
|
||||
break;
|
||||
|
||||
case PROGFILES_PATH:
|
||||
/* nothing to do */
|
||||
break;
|
||||
}
|
||||
|
||||
len = wcslen( bufW );
|
||||
if ( asAscii ) {
|
||||
(void)WideCharToMultiByte( CP_ACP, 0, bufW, len,
|
||||
(void)WideCharToMultiByte( CP_ACP, 0, bufW, len + 1,
|
||||
(char*)bufOut, bufLen, NULL, NULL );
|
||||
} else {
|
||||
wcscpy( (wchar_t*)bufOut, bufW );
|
||||
|
|
|
@ -47,6 +47,7 @@ typedef enum {
|
|||
PREFS_FILE_PATH_L
|
||||
,DEFAULT_DIR_PATH_L
|
||||
,DEFAULT_GAME_PATH
|
||||
,PROGFILES_PATH
|
||||
} CePathType;
|
||||
XP_U16 ceGetPath( CEAppGlobals* globals, CePathType typ,
|
||||
void* buf, XP_U16 bufLen );
|
||||
|
|
Loading…
Add table
Reference in a new issue