| 1 |
/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */ |
| 2 |
|
| 3 |
/* AbiSource Application Framework |
| 4 |
* Copyright (C) 1998-2000 AbiSource, Inc. |
| 5 |
* BIDI Copyright (c) 2001-2004 Tomas Frydrych |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU General Public License |
| 9 |
* as published by the Free Software Foundation; either version 2 |
| 10 |
* of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 20 |
* 02110-1301 USA. |
| 21 |
*/ |
| 22 |
|
| 23 |
#define WIN32_LEAN_AND_MEAN |
| 24 |
|
| 25 |
#ifdef HAVE_CONFIG_H |
| 26 |
#include "config.h" |
| 27 |
#endif |
| 28 |
|
| 29 |
#include <windows.h> |
| 30 |
#include <direct.h> |
| 31 |
#include "ut_assert.h" |
| 32 |
#include "ut_debugmsg.h" |
| 33 |
#include "ut_path.h" |
| 34 |
#include "ut_Win32Uuid.h" |
| 35 |
#include "ut_Win32LocaleString.h" |
| 36 |
#include "xap_Win32App.h" |
| 37 |
#include "xap_Win32Clipboard.h" |
| 38 |
#include "xap_Frame.h" |
| 39 |
#include "xap_Win32FrameImpl.h" |
| 40 |
#include "xap_Win32Toolbar_Icons.h" |
| 41 |
#include "xap_Win32_TB_CFactory.h" |
| 42 |
#include "xap_Win32Slurp.h" |
| 43 |
#include "xap_Win32EncodingManager.h" |
| 44 |
#include "xap_Prefs.h" |
| 45 |
#include "gr_Win32Graphics.h" |
| 46 |
#include "gr_Win32USPGraphics.h" |
| 47 |
|
| 48 |
#include <locale.h> |
| 49 |
|
| 50 |
#ifdef _MSC_VER |
| 51 |
#pragma warning(disable:4355) // 'this' used in base member initializer list |
| 52 |
#endif |
| 53 |
|
| 54 |
#ifdef __MINGW32__ |
| 55 |
#include <w32api.h> |
| 56 |
#endif |
| 57 |
|
| 58 |
char XAP_Win32App::m_buffer[MAX_CONVBUFFER*6] = ""; |
| 59 |
WCHAR XAP_Win32App::m_wbuffer[MAX_CONVBUFFER] = L""; |
| 60 |
|
| 61 |
// do not want to include wv.h here, since it defines some types that |
| 62 |
// overlap with stuff in windov.h |
| 63 |
extern "C" {const char * wvLIDToLangConverter(UT_uint16);} |
| 64 |
|
| 65 |
/*****************************************************************/ |
| 66 |
|
| 67 |
XAP_Win32App::XAP_Win32App(HINSTANCE hInstance, const char * szAppName) |
| 68 |
: XAP_App(szAppName), |
| 69 |
m_hInstance(hInstance), |
| 70 |
m_dialogFactory(this) |
| 71 |
{ |
| 72 |
UT_return_if_fail(hInstance); |
| 73 |
|
| 74 |
_setAbiSuiteLibDir(); |
| 75 |
_setBidiOS(); |
| 76 |
|
| 77 |
// create an instance of UT_UUIDGenerator or appropriate derrived class |
| 78 |
_setUUIDGenerator(new UT_Win32UUIDGenerator()); |
| 79 |
|
| 80 |
// for some reason on win32 the locale used by things like |
| 81 |
// strftime is not set correctly; what's worse, MS setlocale does |
| 82 |
// not recognise standard ISO language and country codes. So, here |
| 83 |
// we retrieve the long language and country name for the users |
| 84 |
// default locale and pass these to setlocale. As long as folk use |
| 85 |
// UT_LocaleTransactor to temporarily change to some other locale, |
| 86 |
// this will ensure the C lib uses correct locale. Tomas Feb 5, 2004 |
| 87 |
UT_String s; |
| 88 |
char buf[100]; |
| 89 |
|
| 90 |
GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SENGLANGUAGE, &buf[0], 100); |
| 91 |
s += buf; |
| 92 |
s += "_"; |
| 93 |
|
| 94 |
GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SENGCOUNTRY, &buf[0], 100); |
| 95 |
s += buf; |
| 96 |
setlocale(LC_ALL, s.c_str()); |
| 97 |
|
| 98 |
// register graphics allocator |
| 99 |
GR_GraphicsFactory * pGF = getGraphicsFactory(); |
| 100 |
UT_ASSERT_HARMLESS( pGF ); |
| 101 |
|
| 102 |
if(pGF) |
| 103 |
{ |
| 104 |
bool bSuccess = pGF->registerClass(GR_Win32Graphics::graphicsAllocator, |
| 105 |
GR_Win32Graphics::graphicsDescriptor, |
| 106 |
GR_Win32Graphics::s_getClassId()); |
| 107 |
|
| 108 |
// we are in deep trouble if this did not succeed |
| 109 |
UT_return_if_fail( bSuccess ); |
| 110 |
|
| 111 |
// this is our fall back ... |
| 112 |
pGF->registerAsDefault(GR_Win32Graphics::s_getClassId(), true); |
| 113 |
pGF->registerAsDefault(GR_Win32Graphics::s_getClassId(), false); |
| 114 |
|
| 115 |
// try to load Uniscribe; if we succeed we will make USP |
| 116 |
// graphics the default |
| 117 |
|
| 118 |
#if ABI_OPT_DISABLE_USP |
| 119 |
HINSTANCE hUniscribe = NULL; |
| 120 |
#else |
| 121 |
HINSTANCE hUniscribe = LoadLibraryW(L"usp10.dll"); |
| 122 |
#endif |
| 123 |
|
| 124 |
if(hUniscribe && (NULL == g_getenv("ABIWORD_DISABLE_UNISCRIBE"))) |
| 125 |
{ |
| 126 |
// register Uniscribe graphics and make it the default |
| 127 |
bSuccess = pGF->registerClass(GR_Win32USPGraphics::graphicsAllocator, |
| 128 |
GR_Win32USPGraphics::graphicsDescriptor, |
| 129 |
GR_Win32USPGraphics::s_getClassId()); |
| 130 |
|
| 131 |
UT_ASSERT_HARMLESS( bSuccess ); |
| 132 |
if(bSuccess) |
| 133 |
{ |
| 134 |
pGF->registerAsDefault(GR_Win32USPGraphics::s_getClassId(), true); |
| 135 |
pGF->registerAsDefault(GR_Win32USPGraphics::s_getClassId(), false); |
| 136 |
|
| 137 |
// now g_free the library (GR_Win32USPGraphics will load it |
| 138 |
// on its own behalf |
| 139 |
|
| 140 |
FreeLibrary(hUniscribe); |
| 141 |
} |
| 142 |
} |
| 143 |
else |
| 144 |
{ |
| 145 |
UT_DEBUGMSG(("XAP_Win32App: could not load Uniscribe library")); |
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
XAP_Win32App::~XAP_Win32App(void) |
| 151 |
{ |
| 152 |
m_pSlurp->disconnectSlurper(); |
| 153 |
DELETEP(m_pSlurp); |
| 154 |
} |
| 155 |
|
| 156 |
HINSTANCE XAP_Win32App::getInstance() const |
| 157 |
{ |
| 158 |
return m_hInstance; |
| 159 |
} |
| 160 |
|
| 161 |
bool XAP_Win32App::initialize(const char * szKeyBindingsKey, const char * szKeyBindingsDefaultValue) |
| 162 |
{ |
| 163 |
// let our base class do it's thing. |
| 164 |
|
| 165 |
XAP_App::initialize(szKeyBindingsKey, szKeyBindingsDefaultValue); |
| 166 |
|
| 167 |
// do anything else we need here... |
| 168 |
|
| 169 |
m_pSlurp = new XAP_Win32Slurp(this); |
| 170 |
m_pSlurp->connectSlurper(); |
| 171 |
WCHAR bufExePathname[2048]; |
| 172 |
GetModuleFileNameW(NULL,bufExePathname,G_N_ELEMENTS(bufExePathname)); |
| 173 |
|
| 174 |
// TODO these are Application-Specific values. Move them out of here. |
| 175 |
m_pSlurp->stuffRegistry(".abw",getApplicationName(),bufExePathname,"application/abiword"); |
| 176 |
m_pSlurp->stuffRegistry(".zabw",getApplicationName(),bufExePathname,"application/abiword-compressed"); |
| 177 |
|
| 178 |
return true; |
| 179 |
} |
| 180 |
|
| 181 |
void XAP_Win32App::reallyExit(void) |
| 182 |
{ |
| 183 |
PostQuitMessage (0); |
| 184 |
} |
| 185 |
|
| 186 |
UT_sint32 XAP_Win32App::makeDirectory(const char * szPath, const UT_sint32 /*mode*/ ) const |
| 187 |
{ |
| 188 |
return mkdir(szPath); |
| 189 |
} |
| 190 |
|
| 191 |
XAP_DialogFactory * XAP_Win32App::getDialogFactory(void) |
| 192 |
{ |
| 193 |
return &m_dialogFactory; |
| 194 |
} |
| 195 |
|
| 196 |
XAP_Toolbar_ControlFactory * XAP_Win32App::getControlFactory(void) |
| 197 |
{ |
| 198 |
return &m_controlFactory; |
| 199 |
} |
| 200 |
|
| 201 |
UT_uint32 XAP_Win32App::_getExeDir(LPWSTR pDirBuf, UT_uint32 iBufLen) |
| 202 |
{ |
| 203 |
UT_uint32 iResult = GetModuleFileNameW(NULL, pDirBuf, iBufLen); |
| 204 |
|
| 205 |
if (iResult > 0) |
| 206 |
{ |
| 207 |
LPWSTR p = pDirBuf + wcslen(pDirBuf); |
| 208 |
while (*p != '\\') |
| 209 |
{ |
| 210 |
p--; |
| 211 |
} |
| 212 |
UT_ASSERT(p > pDirBuf); |
| 213 |
p++; |
| 214 |
*p = 0; |
| 215 |
iResult = (p - pDirBuf); |
| 216 |
} |
| 217 |
|
| 218 |
return iResult; |
| 219 |
} |
| 220 |
|
| 221 |
static bool isWriteable(LPWSTR lpPath) |
| 222 |
{ |
| 223 |
bool result = false; |
| 224 |
DWORD len = lstrlenW(lpPath); |
| 225 |
DWORD rem = MAX_PATH - len - 1; |
| 226 |
DWORD err; |
| 227 |
if (rem < 13) return false; |
| 228 |
|
| 229 |
lstrcpyW(&lpPath[len],L"/abiword.flg"); |
| 230 |
if (CreateDirectoryW(lpPath,NULL)) { |
| 231 |
RemoveDirectoryW(lpPath); |
| 232 |
err=GetLastError(); |
| 233 |
if (err != ERROR_ACCESS_DENIED) result=true; |
| 234 |
} else { |
| 235 |
err=GetLastError(); |
| 236 |
} |
| 237 |
lpPath[len]=0; |
| 238 |
return result; |
| 239 |
} |
| 240 |
|
| 241 |
const char * XAP_Win32App::getUserPrivateDirectory(void) |
| 242 |
{ |
| 243 |
/* return a pointer to a static buffer */ |
| 244 |
|
| 245 |
LPCWSTR szAbiDir = L"AbiSuite"; |
| 246 |
|
| 247 |
bool path_ok = false; |
| 248 |
|
| 249 |
static WCHAR wbuf[PATH_MAX]; |
| 250 |
static char buf[PATH_MAX*6]; |
| 251 |
memset(buf,0,sizeof(buf)); |
| 252 |
|
| 253 |
DWORD len, len1, len2; |
| 254 |
|
| 255 |
UT_Win32LocaleString str; |
| 256 |
UT_UTF8String utf8; |
| 257 |
|
| 258 |
// On W2K and later, APPDATA seems to be set to the directory containing per-user |
| 259 |
// information. |
| 260 |
|
| 261 |
len = GetEnvironmentVariableW(L"APPDATA",wbuf,PATH_MAX); |
| 262 |
if (len) |
| 263 |
{ |
| 264 |
if (isWriteable(wbuf)) path_ok=true; |
| 265 |
#ifdef DEBUG |
| 266 |
str.fromLocale(wbuf); |
| 267 |
utf8=str.utf8_str(); |
| 268 |
UT_DEBUGMSG(("Getting preferences directory from USERPROFILE [%s].\n",utf8.utf8_str())); |
| 269 |
#endif |
| 270 |
} |
| 271 |
|
| 272 |
if (!path_ok) |
| 273 |
{ |
| 274 |
// On NT, USERPROFILE seems to be modern equivalent of $HOME |
| 275 |
|
| 276 |
len = GetEnvironmentVariableW(L"USERPROFILE",wbuf,PATH_MAX); |
| 277 |
if (len) |
| 278 |
{ |
| 279 |
if (isWriteable(wbuf)) path_ok=true; |
| 280 |
#ifdef DEBUG |
| 281 |
str.fromLocale(wbuf); |
| 282 |
utf8=str.utf8_str(); |
| 283 |
UT_DEBUGMSG(("Getting preferences directory from USERPROFILE [%s].\n",utf8.utf8_str())); |
| 284 |
#endif |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
if (!path_ok) |
| 289 |
{ |
| 290 |
// If that doesn't work, look for HOMEDRIVE and HOMEPATH. HOMEPATH |
| 291 |
// is mentioned in the GetWindowsDirectory() documentation at least. |
| 292 |
// These may be set if the SysAdmin did so in the Admin tool.... |
| 293 |
|
| 294 |
len1 = GetEnvironmentVariableW(L"HOMEDRIVE",wbuf,PATH_MAX); |
| 295 |
len2 = GetEnvironmentVariableW(L"HOMEPATH",&wbuf[len1],PATH_MAX-len1); |
| 296 |
if (len1 && len2) |
| 297 |
{ |
| 298 |
if (isWriteable(wbuf)) path_ok=true; |
| 299 |
#ifdef DEBUG |
| 300 |
str.fromLocale(wbuf); |
| 301 |
utf8=str.utf8_str(); |
| 302 |
UT_DEBUGMSG(("Getting preferences directory from HOMEDRIVE and HOMEPATH [%s].\n",utf8.utf8_str())); |
| 303 |
#endif |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
if (!path_ok) |
| 308 |
{ |
| 309 |
// If that doesn't work, let's just stick it in the WINDOWS directory. |
| 310 |
|
| 311 |
len = GetWindowsDirectoryW(wbuf,PATH_MAX); |
| 312 |
if (len) |
| 313 |
{ |
| 314 |
if (isWriteable(wbuf)) path_ok=true; |
| 315 |
#ifdef DEBUG |
| 316 |
str.fromLocale(wbuf); |
| 317 |
utf8=str.utf8_str(); |
| 318 |
UT_DEBUGMSG(("Getting preferences directory from GetWindowsDirectory() [%s].\n",utf8.utf8_str())); |
| 319 |
#endif |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
if (!path_ok) |
| 324 |
{ |
| 325 |
// If that doesn't work, stick it in "C:\"... |
| 326 |
|
| 327 |
lstrcpyW(wbuf,L"C:\\"); |
| 328 |
if (isWriteable(wbuf)) path_ok=true; |
| 329 |
UT_DEBUGMSG(("Getting preferences directory defaulted to C:\\.\n")); |
| 330 |
} |
| 331 |
|
| 332 |
if (!path_ok) |
| 333 |
{ |
| 334 |
// As penultimate resort try to use temporary dir |
| 335 |
|
| 336 |
len = GetTempPathW(MAX_PATH,wbuf); |
| 337 |
if (len) |
| 338 |
{ |
| 339 |
if (isWriteable(wbuf)) path_ok=true; |
| 340 |
#ifdef DEBUG |
| 341 |
str.fromLocale(wbuf); |
| 342 |
utf8=str.utf8_str(); |
| 343 |
UT_DEBUGMSG(("Getting preferences directory from GetTempPath() [%s].\n",utf8.utf8_str())); |
| 344 |
#endif |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
if (!path_ok) |
| 349 |
{ |
| 350 |
// As last resort trying to use TMP dir |
| 351 |
|
| 352 |
len = GetEnvironmentVariableW(L"TMP",wbuf,PATH_MAX); |
| 353 |
if (len) |
| 354 |
{ |
| 355 |
if (isWriteable(wbuf)) path_ok=true; |
| 356 |
#ifdef DEBUG |
| 357 |
str.fromLocale(wbuf); |
| 358 |
utf8=str.utf8_str(); |
| 359 |
UT_DEBUGMSG(("Getting preferences directory from TMP [%s].\n",utf8.utf8_str())); |
| 360 |
#endif |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
UT_ASSERT(path_ok=true) |
| 365 |
|
| 366 |
if (lstrlenW(wbuf)+lstrlenW(szAbiDir)+2 >= PATH_MAX) |
| 367 |
return NULL; |
| 368 |
|
| 369 |
if (wbuf[lstrlenW(wbuf)-1] != L'\\') |
| 370 |
lstrcatW(wbuf,L"\\"); |
| 371 |
lstrcatW(wbuf,szAbiDir); |
| 372 |
|
| 373 |
#ifdef NO_WIN32_UNICODE_SUPPORT_YET |
| 374 |
WideCharToMultiByte(CP_ACP,0,wbuf,-1,buf,MAX_PATH,"_",NULL); |
| 375 |
#else |
| 376 |
str.fromLocale(wbuf); |
| 377 |
utf8=str.utf8_str(); |
| 378 |
strcpy(buf,utf8.utf8_str()); |
| 379 |
#endif |
| 380 |
|
| 381 |
return buf; |
| 382 |
} |
| 383 |
|
| 384 |
static void s_buildDirName(const UT_Vector& vDirComponents, UT_uint32 iComponentsNeeded, char* pDirBuf) |
| 385 |
{ |
| 386 |
UT_ASSERT(iComponentsNeeded <= static_cast<UT_uint32>(vDirComponents.getItemCount())); |
| 387 |
|
| 388 |
if(iComponentsNeeded == 0) |
| 389 |
{ |
| 390 |
strcpy(pDirBuf, "\\"); |
| 391 |
return; |
| 392 |
} |
| 393 |
|
| 394 |
UT_uint32 i = 0; |
| 395 |
strcpy(pDirBuf, (const char*) vDirComponents.getNthItem(i++)); |
| 396 |
|
| 397 |
while(--iComponentsNeeded) |
| 398 |
{ |
| 399 |
strcat(pDirBuf, "\\"); |
| 400 |
strcat(pDirBuf, (const char*) vDirComponents.getNthItem(i++)); |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
void XAP_Win32App::_setAbiSuiteLibDir(void) |
| 405 |
{ |
| 406 |
char *utf8; |
| 407 |
WCHAR buf[PATH_MAX]; |
| 408 |
|
| 409 |
// see if ABIWORD_DATADIR was set in the environment |
| 410 |
if (GetEnvironmentVariableW(L"ABIWORD_DATADIR",buf,sizeof(buf)) > 0) |
| 411 |
{ |
| 412 |
utf8 = (char*) getUTF8String(buf); |
| 413 |
char * p = utf8; |
| 414 |
int len = strlen(p); |
| 415 |
if ( (p[0]=='"') && (p[len-1]=='"') ) |
| 416 |
{ |
| 417 |
// trim leading and trailing DQUOTES |
| 418 |
p[len-1]=0; |
| 419 |
p++; |
| 420 |
len -= 2; |
| 421 |
} |
| 422 |
if (p[len-1]=='\\') // trim trailing slash |
| 423 |
p[len-1] = 0; |
| 424 |
XAP_App::_setAbiSuiteLibDir(p); |
| 425 |
return; |
| 426 |
} |
| 427 |
|
| 428 |
if (_getExeDir(buf,sizeof(buf)) > 0) |
| 429 |
{ |
| 430 |
char *base; |
| 431 |
size_t len, baselen; |
| 432 |
|
| 433 |
utf8 = (char*) getUTF8String(buf); |
| 434 |
|
| 435 |
len = strlen(utf8); |
| 436 |
base = g_path_get_basename(utf8); |
| 437 |
baselen = strlen(base); |
| 438 |
g_free (base), base = NULL; |
| 439 |
if (len+1 > baselen && utf8[len - baselen - 2] == '\\') |
| 440 |
utf8[len - baselen - 2] = 0; |
| 441 |
else utf8[len - baselen - 1] = '\0'; |
| 442 |
#ifdef _MSC_VER |
| 443 |
XAP_App::_setAbiSuiteLibDir(utf8); |
| 444 |
#else |
| 445 |
gchar * dir = g_build_filename(utf8, "share", PACKAGE "-" ABIWORD_SERIES, NULL); |
| 446 |
XAP_App::_setAbiSuiteLibDir(dir); |
| 447 |
g_free (dir), dir = NULL; |
| 448 |
#endif |
| 449 |
return; |
| 450 |
} |
| 451 |
|
| 452 |
// otherwise, use the hard-coded value |
| 453 |
XAP_App::_setAbiSuiteLibDir(getAbiSuiteHome()); |
| 454 |
return; |
| 455 |
} |
| 456 |
|
| 457 |
void XAP_Win32App::enableAllTopLevelWindows(bool b) |
| 458 |
{ |
| 459 |
UT_uint32 iCount = m_vecFrames.getItemCount(); |
| 460 |
|
| 461 |
for (UT_uint32 ndx=0; ndx<iCount; ndx++) |
| 462 |
{ |
| 463 |
XAP_Frame * pFrame = (XAP_Frame *) m_vecFrames.getNthItem(ndx); |
| 464 |
|
| 465 |
EnableWindow(static_cast<XAP_Win32FrameImpl*>(pFrame->getFrameImpl())->getTopLevelWindow(), b); |
| 466 |
} |
| 467 |
} |
| 468 |
|
| 469 |
// This function gets saved geometry from preference file, attempts to validate |
| 470 |
// and sets window's placement. It returns the flag that should be called to |
| 471 |
// ShowWindow on the first call. |
| 472 |
UT_sint32 XAP_Win32App::setupWindowFromPrefs(UT_sint32 iCmdShow, HWND hwndFrame) |
| 473 |
{ |
| 474 |
UT_uint32 iHeight, iWidth; |
| 475 |
UT_sint32 x,y; |
| 476 |
UT_uint32 flag; |
| 477 |
|
| 478 |
// if width & height are <= 0 then assume invalid values so just use system defaults |
| 479 |
if (getGeometry(&x,&y,&iWidth,&iHeight,&flag) && (iWidth > 0) && (iHeight > 0)) |
| 480 |
{ |
| 481 |
WINDOWPLACEMENT wndPlacement; |
| 482 |
wndPlacement.length = sizeof(WINDOWPLACEMENT); // must do |
| 483 |
// get current windowplacement info, so anything we don't set is correct |
| 484 |
if (!GetWindowPlacement(hwndFrame, &wndPlacement)) |
| 485 |
{ |
| 486 |
memset(&wndPlacement, 0, sizeof(WINDOWPLACEMENT)); |
| 487 |
wndPlacement.length = sizeof(WINDOWPLACEMENT); |
| 488 |
} |
| 489 |
if (flag && (flag <= SW_MAX)) // validate flag |
| 490 |
{ |
| 491 |
wndPlacement.showCmd = flag; |
| 492 |
iCmdShow = flag; /* SW_SHOW; */ |
| 493 |
} |
| 494 |
else |
| 495 |
{ |
| 496 |
wndPlacement.showCmd = iCmdShow; /* SW_SHOWNORMAL; */ |
| 497 |
} |
| 498 |
wndPlacement.rcNormalPosition.left = x; |
| 499 |
wndPlacement.rcNormalPosition.top = y; |
| 500 |
wndPlacement.rcNormalPosition.right = x + iWidth; |
| 501 |
wndPlacement.rcNormalPosition.bottom = y + iHeight; |
| 502 |
SetWindowPlacement(hwndFrame, &wndPlacement); |
| 503 |
} |
| 504 |
|
| 505 |
return iCmdShow; |
| 506 |
} |
| 507 |
|
| 508 |
/* |
| 509 |
most of the code in the following function comes from Mozilla |
| 510 |
*/ |
| 511 |
void XAP_Win32App::_setBidiOS(void) |
| 512 |
{ |
| 513 |
|
| 514 |
m_eBidiOS = XAP_App::BIDI_SUPPORT_NONE; |
| 515 |
/* |
| 516 |
I have run into problems with the built-in win32 bidi support -- it is inconsistent |
| 517 |
It treats some fonts (i.e., the MS fonts) correctly, but some common Hebrew fonts |
| 518 |
it will not reorder. Consequently, I felt that the best solution would be to disable |
| 519 |
the win32 bidi altogether and treating it as a non-bidi system, but there does |
| 520 |
not seem to be a simple way of doing this |
| 521 |
|
| 522 |
I am going to have another shot at disabling the built-in support |
| 523 |
for the main window, and leaving it for the GUI only. The main |
| 524 |
changes are in gr_Win32Graphics class. Tomas, Jan 19th, 2003 |
| 525 |
*/ |
| 526 |
const UT_UCS2Char araAin = 0x0639; |
| 527 |
const UT_UCS2Char one = 0x0031; |
| 528 |
|
| 529 |
int distanceArray[2]; |
| 530 |
UT_UCS2Char glyphArray[2]; |
| 531 |
UT_UCS2Char outStr[] = {0, 0}; |
| 532 |
|
| 533 |
GCP_RESULTSW gcpResult; |
| 534 |
gcpResult.lStructSize = sizeof(GCP_RESULTS); |
| 535 |
gcpResult.lpOutString = (LPWSTR) outStr; // Output string |
| 536 |
gcpResult.lpOrder = NULL; // Ordering indices |
| 537 |
gcpResult.lpDx = distanceArray; // Distances between character cells |
| 538 |
gcpResult.lpCaretPos = NULL; // Caret positions |
| 539 |
gcpResult.lpClass = NULL; // Character classifications |
| 540 |
// w32api changed lpGlyphs from UINT * to LPWSTR to match MS PSDK in w32api v2.4 |
| 541 |
#ifdef __MINGW32__ |
| 542 |
#if (__W32API_MAJOR_VERSION == 2 && __W32API_MINOR_VERSION < 4) |
| 543 |
gcpResult.lpGlyphs = (UINT *) glyphArray; // Character glyphs |
| 544 |
#else |
| 545 |
gcpResult.lpGlyphs = (LPWSTR) glyphArray; // Character glyphs |
| 546 |
#endif |
| 547 |
#else |
| 548 |
gcpResult.lpGlyphs = (LPWSTR) glyphArray; // Character glyphs |
| 549 |
#endif |
| 550 |
gcpResult.nGlyphs = 2; // Array size |
| 551 |
|
| 552 |
UT_UCS2Char inStr[] = {araAin, one}; |
| 553 |
|
| 554 |
HDC displayDC = GetDC(NULL); |
| 555 |
|
| 556 |
if(!displayDC) |
| 557 |
{ |
| 558 |
return; |
| 559 |
} |
| 560 |
|
| 561 |
if (GetCharacterPlacementW(displayDC, (LPCWSTR)inStr, 2, 0, &gcpResult, GCP_REORDER) |
| 562 |
&& (inStr[0] == outStr[1]) ) |
| 563 |
{ |
| 564 |
m_eBidiOS = XAP_App::BIDI_SUPPORT_GUI; |
| 565 |
UT_DEBUGMSG(("System has bidi and glyph shaping\n")); |
| 566 |
} |
| 567 |
else |
| 568 |
{ |
| 569 |
const UT_UCSChar hebAlef = 0x05D0; |
| 570 |
inStr[0] = hebAlef; |
| 571 |
inStr[1] = one; |
| 572 |
if (GetCharacterPlacementW(displayDC, (LPCWSTR)inStr, 2, 0, &gcpResult, GCP_REORDER) |
| 573 |
&& (inStr[0] == outStr[1]) ) |
| 574 |
{ |
| 575 |
m_eBidiOS = XAP_App::BIDI_SUPPORT_GUI; |
| 576 |
UT_DEBUGMSG(("System has bidi\n")); |
| 577 |
} |
| 578 |
} |
| 579 |
|
| 580 |
ReleaseDC(NULL,displayDC); |
| 581 |
} |
| 582 |
|
| 583 |
const char * XAP_Win32App::getDefaultEncoding () const |
| 584 |
{ |
| 585 |
return "UTF-8"; |
| 586 |
} |
| 587 |
|
| 588 |
const WCHAR * XAP_Win32App::getWideString (const char * utf8input) |
| 589 |
{ |
| 590 |
int wlen = MultiByteToWideChar(CP_UTF8, 0, utf8input, -1, NULL, 0); |
| 591 |
UT_ASSERT(wlen); |
| 592 |
if (wlen && (wlen < MAX_CONVBUFFER)) { |
| 593 |
wlen = MultiByteToWideChar(CP_UTF8, 0, utf8input, -1, m_wbuffer, MAX_CONVBUFFER); |
| 594 |
UT_ASSERT(wlen); |
| 595 |
return m_wbuffer; |
| 596 |
} |
| 597 |
else |
| 598 |
{ |
| 599 |
UT_ASSERT(wlen < MAX_CONVBUFFER); |
| 600 |
UT_DEBUGMSG(("getWideString:converted string too long %d", wlen)); |
| 601 |
return NULL; |
| 602 |
} |
| 603 |
} |
| 604 |
|
| 605 |
const char * XAP_Win32App::getUTF8String (const WCHAR * p_str) |
| 606 |
{ |
| 607 |
int len = WideCharToMultiByte(CP_UTF8, 0, p_str, -1, NULL, 0, NULL, NULL); |
| 608 |
UT_ASSERT(len); |
| 609 |
if (len && (len < MAX_CONVBUFFER*6)) { |
| 610 |
len = WideCharToMultiByte(CP_UTF8, 0, p_str, -1, m_buffer, MAX_CONVBUFFER*6, NULL, NULL); |
| 611 |
UT_ASSERT(len); |
| 612 |
return m_buffer; |
| 613 |
} |
| 614 |
else |
| 615 |
{ |
| 616 |
UT_ASSERT(len < MAX_CONVBUFFER*6); |
| 617 |
UT_DEBUGMSG(("getUTF8String:converted string too long %d", len)); |
| 618 |
return NULL; |
| 619 |
} |
| 620 |
} |
| 621 |
|
| 622 |
|
| 623 |
void XAP_Win32App::getDefaultGeometry(UT_uint32& width, UT_uint32& height, UT_uint32& flags) |
| 624 |
{ |
| 625 |
flags |= PREF_FLAG_GEOMETRY_MAXIMIZED; |
| 626 |
|
| 627 |
width = GetSystemMetrics(SM_CXFULLSCREEN); |
| 628 |
height = GetSystemMetrics(SM_CYFULLSCREEN); |
| 629 |
} |
| 630 |
|
| 631 |
const char * XAP_Win32App::_getKbdLanguage() |
| 632 |
{ |
| 633 |
// make sure that m_hkl is in sync with the current value |
| 634 |
m_hkl = GetKeyboardLayout(0); |
| 635 |
|
| 636 |
WORD langID = LANGIDFROMLCID(LOWORD(m_hkl)); |
| 637 |
const char * pszLang = wvLIDToLangConverter((unsigned short)langID); |
| 638 |
UT_DEBUGMSG(("XAP_Win32App::_getKbdLanguage: %s\n",pszLang)); |
| 639 |
return pszLang; |
| 640 |
} |
| 641 |
|
| 642 |
// wrapper around XAP_App::setKbdLanguage(const char *) |
| 643 |
void XAP_Win32App::setKbdLanguage(HKL hkl) |
| 644 |
{ |
| 645 |
m_hkl = hkl; |
| 646 |
|
| 647 |
WORD langID = LANGIDFROMLCID(LOWORD(hkl)); |
| 648 |
const char * pszLang = wvLIDToLangConverter((unsigned short)langID); |
| 649 |
UT_DEBUGMSG(("XAP_Win32App::setKbdLanguage: %s\n",pszLang)); |
| 650 |
|
| 651 |
// set the language |
| 652 |
XAP_App::setKbdLanguage(pszLang); |
| 653 |
} |
| 654 |
|
| 655 |
|