Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4787 lines
132 KiB

  1. /*
  2. * Unicode <--> MultiByte conversions, OLE, and other system functions
  3. *
  4. * Copyright (c) 1995-1998, Microsoft Corporation. All rights reserved.
  5. */
  6. #include <objbase.h> // CoCreateInstance define
  7. #include "aimm.h" // AIMM i/f
  8. #include "aimm_i.c" // AIMM CLSID etc
  9. #include "_font.h"
  10. #include "_uspi.h"
  11. #define MAX_HKLS 256 // It will be a while before we have more KBs
  12. static HINSTANCE g_hOleAut32 = NULL;
  13. static HINSTANCE g_hOle32 = NULL;
  14. #ifndef NOACCESSIBILITY
  15. static HINSTANCE g_hAcc = NULL;
  16. static HINSTANCE g_hUser32 = NULL;
  17. #endif
  18. class CIMM32_PROC
  19. {
  20. public:
  21. void *ImmGetCompositionStringA;
  22. void *ImmGetCompositionStringW;
  23. void *ImmGetContext;
  24. void *ImmSetCompositionFontA;
  25. void *ImmSetCompositionWindow;
  26. void *ImmReleaseContext;
  27. void *ImmGetProperty;
  28. void *ImmGetCandidateWindow;
  29. void *ImmSetCandidateWindow;
  30. void *ImmNotifyIME;
  31. void *ImmAssociateContext;
  32. void *ImmGetVirtualKey;
  33. void *ImmEscapeA;
  34. void *ImmEscapeW;
  35. void *ImmGetOpenStatus;
  36. void *ImmSetOpenStatus;
  37. void *ImmGetConversionStatus;
  38. void *ImmSetConversionStatus;
  39. void *ImmGetDefaultIMEWnd;
  40. void *ImmSetCompositionStringW;
  41. };
  42. static CIMM32_PROC g_IMM32Proc;
  43. class CIMESHARE_PROC
  44. {
  45. public:
  46. void *FSupportSty;
  47. void *PIMEStyleFromAttr;
  48. void *PColorStyleTextFromIMEStyle;
  49. void *PColorStyleBackFromIMEStyle;
  50. void *FBoldIMEStyle;
  51. void *FItalicIMEStyle;
  52. void *FUlIMEStyle;
  53. void *IdUlIMEStyle;
  54. void *RGBFromIMEColorStyle;
  55. };
  56. static CIMESHARE_PROC g_IMEShareProc;
  57. class COLEAUT32_PROC
  58. {
  59. public:
  60. void *LoadRegTypeLib;
  61. void *LoadTypeLib;
  62. void *LoadTypeLibEx;
  63. void *SysAllocString;
  64. void *SysAllocStringLen;
  65. void *SysFreeString;
  66. void *SysStringLen;
  67. void *VariantInit;
  68. };
  69. static COLEAUT32_PROC g_OleAut32Proc;
  70. class COLE32_PROC
  71. {
  72. public:
  73. void *OleCreateFromData;
  74. void *CoTaskMemFree;
  75. void *CreateBindCtx;
  76. void *OleDuplicateData;
  77. void *CoTreatAsClass;
  78. void *ProgIDFromCLSID;
  79. void *OleConvertIStorageToOLESTREAM;
  80. void *OleConvertIStorageToOLESTREAMEx;
  81. void *OleSave;
  82. void *StgCreateDocfileOnILockBytes;
  83. void *CreateILockBytesOnHGlobal;
  84. void *OleCreateLinkToFile;
  85. void *CoTaskMemAlloc;
  86. void *CoTaskMemRealloc;
  87. void *OleInitialize;
  88. void *OleUninitialize;
  89. void *OleSetClipboard;
  90. void *OleFlushClipboard;
  91. void *OleIsCurrentClipboard;
  92. void *DoDragDrop;
  93. void *OleGetClipboard;
  94. void *RegisterDragDrop;
  95. void *OleCreateLinkFromData;
  96. void *OleCreateStaticFromData;
  97. void *OleDraw;
  98. void *OleSetContainedObject;
  99. void *CoDisconnectObject;
  100. void *WriteFmtUserTypeStg;
  101. void *WriteClassStg;
  102. void *SetConvertStg;
  103. void *ReadFmtUserTypeStg;
  104. void *ReadClassStg;
  105. void *OleRun;
  106. void *RevokeDragDrop;
  107. void *CreateStreamOnHGlobal;
  108. void *GetHGlobalFromStream;
  109. void *OleCreateDefaultHandler;
  110. void *CLSIDFromProgID;
  111. void *OleConvertOLESTREAMToIStorage;
  112. void *OleLoad;
  113. void *ReleaseStgMedium;
  114. void *CoCreateInstance;
  115. };
  116. static COLE32_PROC g_Ole32Proc;
  117. class CConvertStr
  118. {
  119. public:
  120. operator char *();
  121. protected:
  122. CConvertStr();
  123. ~CConvertStr();
  124. void Free();
  125. LPSTR _pstr;
  126. char _ach[MAX_PATH * 2];
  127. };
  128. inline CConvertStr::operator char *()
  129. {
  130. return _pstr;
  131. }
  132. inline CConvertStr::CConvertStr()
  133. {
  134. _pstr = NULL;
  135. }
  136. inline CConvertStr::~CConvertStr()
  137. {
  138. Free();
  139. }
  140. class CStrIn : public CConvertStr
  141. {
  142. public:
  143. CStrIn(LPCWSTR pwstr, UINT CodePage = CP_ACP);
  144. CStrIn(LPCWSTR pwstr, int cwch, UINT CodePage = CP_ACP);
  145. int strlen();
  146. protected:
  147. CStrIn();
  148. void Init(LPCWSTR pwstr, int cwch, UINT CodePage = CP_ACP);
  149. int _cchLen;
  150. };
  151. inline CStrIn::CStrIn()
  152. {
  153. }
  154. inline int CStrIn::strlen()
  155. {
  156. return _cchLen;
  157. }
  158. class CStrOut : public CConvertStr
  159. {
  160. public:
  161. CStrOut(LPWSTR pwstr, int cwchBuf);
  162. ~CStrOut();
  163. int BufSize();
  164. int Convert();
  165. private:
  166. LPWSTR _pwstr;
  167. int _cwchBuf;
  168. };
  169. inline int CStrOut::BufSize()
  170. {
  171. return _cwchBuf * 2;
  172. }
  173. //
  174. // Multi-Byte ---> Unicode conversion
  175. //
  176. class CStrOutW : public CConvertStrW
  177. {
  178. public:
  179. CStrOutW(LPSTR pstr, int cchBuf, UINT uiCodePage);
  180. ~CStrOutW();
  181. int BufSize();
  182. int Convert();
  183. private:
  184. LPSTR _pstr;
  185. int _cchBuf;
  186. UINT _uiCodePage;
  187. };
  188. inline int CStrOutW::BufSize()
  189. {
  190. return _cchBuf;
  191. }
  192. DWORD CW32System::AddRef()
  193. {
  194. return ++_cRefs;
  195. }
  196. DWORD CW32System::Release()
  197. {
  198. DWORD culRefs = --_cRefs;
  199. if(culRefs == 0)
  200. {
  201. FreeIME();
  202. if (g_hOle32)
  203. {
  204. EnterCriticalSection(&g_CriticalSection);
  205. OleUninitialize();
  206. FreeLibrary(g_hOle32);
  207. g_hOle32 = NULL;
  208. memset(&g_Ole32Proc, 0, sizeof(g_Ole32Proc));
  209. LeaveCriticalSection(&g_CriticalSection);
  210. }
  211. }
  212. return culRefs;
  213. }
  214. ATOM WINAPI CW32System::RegisterREClass(
  215. const WNDCLASSW *lpWndClass,
  216. const char *szAnsiClassName,
  217. WNDPROC AnsiWndProc
  218. )
  219. {
  220. WNDCLASSA wc;
  221. ATOM atom;
  222. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "RegisterREClass");
  223. // First register the normal window class.
  224. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  225. {
  226. atom = ::RegisterClass(lpWndClass);
  227. if (!atom && GetLastError() == ERROR_CLASS_ALREADY_EXISTS)
  228. atom = FindAtom(lpWndClass->lpszClassName);
  229. }
  230. else
  231. {
  232. // On WIndows 95 we need to convert the window class name.
  233. CStrIn strMenuName(lpWndClass->lpszMenuName);
  234. CStrIn strClassName(lpWndClass->lpszClassName);
  235. Assert(sizeof(wc) == sizeof(*lpWndClass));
  236. memcpy(&wc, lpWndClass, sizeof(wc));
  237. wc.lpszMenuName = strMenuName;
  238. wc.lpszClassName = strClassName;
  239. atom = ::RegisterClassA(&wc);
  240. if (!atom && GetLastError() == ERROR_CLASS_ALREADY_EXISTS)
  241. atom = FindAtomA(wc.lpszClassName);
  242. }
  243. if (!atom || !szAnsiClassName)
  244. return atom;
  245. // Now REgister the ANSI window class name i.e. RICHEDIT20A
  246. wc.style = lpWndClass->style;
  247. wc.cbClsExtra = lpWndClass->cbClsExtra;
  248. wc.cbWndExtra = lpWndClass->cbWndExtra;
  249. wc.hInstance = lpWndClass->hInstance;
  250. wc.hIcon = lpWndClass->hIcon;
  251. wc.hCursor = lpWndClass->hIcon;
  252. wc.hbrBackground = lpWndClass->hbrBackground;
  253. wc.lpszMenuName = NULL;
  254. wc.lpfnWndProc = AnsiWndProc;
  255. wc.lpszClassName = szAnsiClassName;
  256. atom = ::RegisterClassA(&wc);
  257. if (!atom && GetLastError() == ERROR_CLASS_ALREADY_EXISTS)
  258. atom = FindAtomA(szAnsiClassName);
  259. return atom;
  260. }
  261. LONG ValidateTextRange(TEXTRANGE *pstrg);
  262. LRESULT CW32System::ANSIWndProc(
  263. HWND hwnd,
  264. UINT msg,
  265. WPARAM wparam,
  266. LPARAM lparam,
  267. BOOL fIs10Mode)
  268. {
  269. TRACEBEGIN(TRCSUBSYSHOST, TRCSCOPEINTERN, "RichEditANSIWndProc");
  270. #ifdef DEBUG
  271. Tracef(TRCSEVINFO, "hwnd %lx, msg %lx, wparam %lx, lparam %lx", hwnd, msg, wparam, lparam);
  272. #endif // DEBUG
  273. LRESULT lres;
  274. switch( msg )
  275. {
  276. case EM_REPLACESEL:
  277. case WM_SETTEXT:
  278. {
  279. SETTEXTEX st = {ST_CHECKPROTECTION, 0};
  280. if(msg == EM_REPLACESEL)
  281. {
  282. st.flags = wparam ? ST_CHECKPROTECTION | ST_SELECTION | ST_KEEPUNDO | ST_10REPLACESEL
  283. : ST_CHECKPROTECTION | ST_SELECTION | ST_10REPLACESEL;
  284. }
  285. else if (fIs10Mode)
  286. st.flags |= ST_10WM_SETTEXT; // 1.0 Mode WM_SETTEXT
  287. return RichEditWndProc(hwnd, EM_SETTEXTEX, (WPARAM)&st, lparam);
  288. }
  289. case EM_FINDTEXT:
  290. case EM_FINDTEXTEX:
  291. {
  292. // We cheat a little here because FINDTEXT and FINDTEXTEX overlap
  293. // with the exception of the extra out param chrgText in FINDTEXTEX
  294. FINDTEXTEXW ftexw;
  295. FINDTEXTA *pfta = (FINDTEXTA *)lparam;
  296. CStrInW strinw(pfta->lpstrText, W32->GetKeyboardCodePage());
  297. ftexw.chrg = pfta->chrg;
  298. ftexw.lpstrText = (WCHAR *)strinw;
  299. lres = RichEditWndProc(hwnd, msg, wparam, (LPARAM)&ftexw);
  300. if(msg == EM_FINDTEXTEX)
  301. {
  302. // In the FINDTEXTEX case, the extra field in the
  303. // FINDTEXTEX data structure is an out parameter indicating
  304. // the range where the text was found. Update the 'real'
  305. // [in, out] parameter accordingly.
  306. ((FINDTEXTEXA *)lparam)->chrgText = ftexw.chrgText;
  307. }
  308. return lres;
  309. }
  310. break;
  311. case EM_GETSELTEXT:
  312. {
  313. GETTEXTEX gt;
  314. const char chDefault = ' ';
  315. gt.cb = (unsigned)-1; // Client claims to have enuf room
  316. gt.flags = GT_SELECTION; // Get selected text
  317. gt.codepage = (unsigned)-1; // Use default CCharFormat codepage
  318. gt.lpDefaultChar = &chDefault; // Translate other chars into blanks
  319. gt.lpUsedDefChar = NULL;
  320. return RichEditWndProc(hwnd, EM_GETTEXTEX, (WPARAM)&gt, lparam);
  321. }
  322. break;
  323. // case WM_GETTEXT: Handled by Ansi filter
  324. // case WM_GETTEXTLENGTH: Handled by Ansi filter
  325. case EM_GETTEXTRANGE:
  326. {
  327. TEXTRANGEA *ptrg = (TEXTRANGEA *)lparam;
  328. LONG clInBuffer = ValidateTextRange((TEXTRANGEW *) ptrg);
  329. // If size is -1, this means that the size required is the total
  330. // size of the the text.
  331. if(-1 == clInBuffer)
  332. {
  333. // We can get this length either by digging the data out of the
  334. // various structures below us or we can take advantage of the
  335. // WM_GETTEXTLENGTH message. The first might be slightly
  336. // faster but the second definitely save code size. So we
  337. // will go with the second.
  338. clInBuffer = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0);
  339. }
  340. if(0 == clInBuffer)
  341. {
  342. // The buffer was invalid for some reason or there was not data
  343. // to copy. In any case, we are done.
  344. return 0;
  345. }
  346. // Verify that the output buffer is big enough.
  347. if(IsBadWritePtr(ptrg->lpstrText, clInBuffer + 1))
  348. {
  349. // Not enough space so don't copy any
  350. return 0;
  351. }
  352. // For EM_GETTEXTRANGE case, we again don't know how big the
  353. // incoming buffer is, only that it should be *at least* as
  354. // great as cpMax - cpMin in the text range structure. We also
  355. // know that anything *bigger* than (cpMax - cpMin)*2 bytes is
  356. // uncessary. So we'll just assume that it's "big enough"
  357. // and let WideCharToMultiByte scribble as much as it needs.
  358. // Memory shortages are the caller's responsibility (courtesy
  359. // of the RichEdit 1.0 design).
  360. CStrOutW stroutw(ptrg->lpstrText, (clInBuffer + 1) * sizeof(WCHAR),
  361. RichEditWndProc(hwnd, EM_GETCODEPAGE, 0, 0));
  362. TEXTRANGEW trgw;
  363. trgw.chrg = ptrg->chrg;
  364. trgw.lpstrText = (WCHAR *)stroutw;
  365. RichEditWndProc(hwnd, EM_GETTEXTRANGE, wparam, (LPARAM)&trgw);
  366. return stroutw.Convert(); // Return count of BYTEs converted
  367. }
  368. case EM_GETLINE:
  369. {
  370. // The size is indicated by the first word of the memory pointed
  371. // to by lparam
  372. WORD size = *(WORD *)lparam;
  373. CStrOutW stroutw((char *)lparam, (DWORD)size,
  374. RichEditWndProc(hwnd, EM_GETCODEPAGE, 0, 0));
  375. WCHAR *pwsz = (WCHAR *)stroutw;
  376. *(WORD *)pwsz = size;
  377. lres = RichEditWndProc(hwnd, msg, wparam, (LPARAM)pwsz);
  378. if (lres < size)
  379. *(pwsz+lres) = L'\0'; // EM_GETLINE does not return NULL-terminated string.
  380. LONG cach = stroutw.Convert();
  381. // Note: should probably return cach for 3.0 too, i.e.,
  382. // just like EM_GETTEXTRANGE above
  383. return fIs10Mode ? cach : lres; // If 1.0, return count of BYTEs converted
  384. }
  385. #ifdef DEBUG
  386. case WM_NCCREATE:
  387. case WM_CREATE:
  388. // These messages should be handled higher up so let everyone
  389. // know we got to the wrong place!
  390. AssertSz(FALSE, "CW32System::ANSIWndProc got WM_CREATE or WM_NCCREATE");
  391. break;
  392. #endif // DEBUG
  393. }
  394. return RichEditWndProc(hwnd, msg, wparam, lparam);
  395. }
  396. // Note that AnsiFilter could be refined so that we could get rid
  397. // of the ANSI window proc.
  398. void CW32System::AnsiFilter(
  399. UINT & msg,
  400. WPARAM &wparam,
  401. LPARAM lparam,
  402. void *pvoid,
  403. BOOL f10Mode
  404. )
  405. {
  406. GETTEXTEX *pgt;
  407. GETTEXTLENGTHEX *pgtl;
  408. WM_CHAR_INFO *pwmci;
  409. bool fAltNumPad = (GetKeyboardFlags() & ALTNUMPAD) != 0;
  410. UINT cpg = GetKeyboardCodePage(0xFFFFFFFF);
  411. switch (msg)
  412. {
  413. case WM_CHAR:
  414. pwmci = (WM_CHAR_INFO *) pvoid;
  415. pwmci->_fTrailByte = false;
  416. pwmci->_fLeadByte = false;
  417. pwmci->_fIMEChar = false;
  418. if (pwmci->_fAccumulate) {
  419. // We could do some validation here.
  420. pwmci->_fTrailByte = true;
  421. return;
  422. }
  423. // WM_CHAR > 256 on Win95; assumed to be Unicode
  424. if(fAltNumPad)
  425. {
  426. DWORD Number = GetKeyPadNumber();
  427. if(Number >= 256 || GetKeyboardFlags() & ALT0)
  428. {
  429. wparam = Number;
  430. if(!IN_RANGE(1250, cpg, 1258)) // Use 1252 for DBCS
  431. cpg = 1252; // codepages
  432. }
  433. }
  434. if(IN_RANGE(128, wparam, 255))
  435. {
  436. bool fShift = (GetKeyboardFlags() & SHIFT) != 0;
  437. bool fCtrl = (GetKeyboardFlags() & CTRL) != 0;
  438. // If fAltNumPad is set, wparam is HiAnsi
  439. // If Shift + Alt + Ctrl, it is repeat event from Win3.1 IME
  440. if ((!fAltNumPad || (fShift && fCtrl)) && GetTrailBytesCount((BYTE) wparam, cpg))
  441. {
  442. pwmci->_fLeadByte = true;
  443. return;
  444. }
  445. WPARAM wparamNew = 0;
  446. switch ( cpg )
  447. {
  448. case CP_JAPAN:
  449. // for Japanese codepage, need to translate SBC if KANA mode is on
  450. if ((GetKeyState(VK_KANA) & 1) || f10Mode)
  451. break;
  452. // If not in KANA mode, then fall thru to use 1252 codepage...
  453. case CP_KOREAN:
  454. case CP_CHINESE_TRAD:
  455. case CP_CHINESE_SIM:
  456. // use English codepage since there is no HiAnsi conversion for
  457. // FE systems
  458. cpg = 1252;
  459. break;
  460. }
  461. if (cpg == 1252 && !IN_RANGE(0x80, wparam, 0x9f))
  462. return;
  463. // Convert single byte WM_CHAR messages to Unicode
  464. if(UnicodeFromMbcs((LPWSTR)&wparamNew, 1, (char *)&wparam, 1,
  465. cpg) == 1 )
  466. {
  467. wparam = wparamNew;
  468. if (fAltNumPad)
  469. SetKeyPadNumber(wparam);
  470. }
  471. }
  472. else if(lparam == 1 && _dwPlatformId == VER_PLATFORM_WIN32_NT &&
  473. wparam > 256 && !fAltNumPad)
  474. {
  475. // On WinNT s/w generated WM_CHAR, this should be WM_IME_CHAR message
  476. // for some Chinese Level 2 IME.
  477. if ( cpg == CP_CHINESE_SIM || cpg == CP_CHINESE_TRAD )
  478. {
  479. BYTE bTrailByte = wparam >> 8;
  480. BYTE bLeadByte = wparam;
  481. wparam = (bLeadByte << 8) | bTrailByte;
  482. pwmci->_fIMEChar = true;
  483. }
  484. }
  485. return;
  486. case WM_GETTEXT:
  487. // EVIL HACK ALERT: on Win95, WM_GETTEXT should always be treated
  488. // as an ANSI message.
  489. pgt = (GETTEXTEX *) pvoid;
  490. pgt->cb = wparam;
  491. pgt->flags = GT_USECRLF;
  492. pgt->codepage = 0;
  493. pgt->lpDefaultChar = NULL;
  494. pgt->lpUsedDefChar = NULL;
  495. msg = EM_GETTEXTEX;
  496. wparam = (WPARAM) pgt;
  497. return;
  498. case WM_GETTEXTLENGTH:
  499. // EVIL HACK ALERT: on Win95, WM_GETEXTLENGTH should always
  500. // be treated an ANSI message because some old apps will send
  501. // this message to arbitrary windows (e.g., accessibility aps)
  502. pgtl = (GETTEXTLENGTHEX *) pvoid;
  503. pgtl->flags = GTL_NUMBYTES | GTL_PRECISE | GTL_USECRLF;
  504. pgtl->codepage = 0;
  505. msg = EM_GETTEXTLENGTHEX;
  506. wparam = (WPARAM) pgtl;
  507. return;
  508. }
  509. }
  510. HGLOBAL WINAPI CW32System::GlobalAlloc( UINT uFlags, DWORD dwBytes )
  511. {
  512. return ::GlobalAlloc( uFlags, dwBytes );
  513. }
  514. HGLOBAL WINAPI CW32System::GlobalFree( HGLOBAL hMem )
  515. {
  516. return hMem ? ::GlobalFree( hMem ) : NULL;
  517. }
  518. UINT WINAPI CW32System::GlobalFlags( HGLOBAL hMem )
  519. {
  520. return ::GlobalFlags( hMem );
  521. }
  522. HGLOBAL WINAPI CW32System::GlobalReAlloc( HGLOBAL hMem, DWORD dwBytes, UINT uFlags )
  523. {
  524. return ::GlobalReAlloc( hMem, dwBytes, uFlags );
  525. }
  526. DWORD WINAPI CW32System::GlobalSize( HGLOBAL hMem )
  527. {
  528. return ::GlobalSize( hMem );
  529. }
  530. LPVOID WINAPI CW32System::GlobalLock( HGLOBAL hMem )
  531. {
  532. return ::GlobalLock( hMem );
  533. }
  534. HGLOBAL WINAPI CW32System::GlobalHandle( LPCVOID pMem )
  535. {
  536. return ::GlobalHandle( pMem );
  537. }
  538. BOOL WINAPI CW32System::GlobalUnlock( HGLOBAL hMem )
  539. {
  540. return ::GlobalUnlock( hMem );
  541. }
  542. /*
  543. * CW32System::CheckChangeKeyboardLayout (bCharSet)
  544. *
  545. * @mfunc
  546. * Change keyboard for new charset, or charset at new character position.
  547. *
  548. * @rdesc
  549. * Keyboard hkl selected. 0 if failed to find keyboard
  550. *
  551. * @comm
  552. * Using only the currently loaded KBs, locate one that will support
  553. * bCharSet. This is called anytime a character format change occurs,
  554. * or the caret position changes.
  555. *
  556. * @devnote
  557. * The current KB is preferred. If a previous association was made,
  558. * see if the KB is still loaded in the system and if so use it.
  559. * Otherwise, locate a suitable KB, preferring KB's that have
  560. * the same charset ID as their default, preferred charset. If no
  561. * match can be found, nothing changes.
  562. */
  563. HKL CW32System::CheckChangeKeyboardLayout(
  564. BYTE bCharSet)
  565. {
  566. return ActivateKeyboard(ScriptIndexFromCharSet(bCharSet));
  567. }
  568. HKL CW32System::GetKeyboardLayout (
  569. DWORD dwThreadID)
  570. {
  571. if(dwThreadID == 0x0FFFFFFFF)
  572. RefreshKeyboardLayout();
  573. return _hklCurrent;
  574. }
  575. /*
  576. * CW32System::RefreshKeyboardLayout ()
  577. *
  578. * @mfunc
  579. * Update _hklCurrent with current keyboard layout and update
  580. * entry for corresponding script.
  581. */
  582. void CW32System::RefreshKeyboardLayout ()
  583. {
  584. INT iScript;
  585. _hklCurrent = ::GetKeyboardLayout(0);
  586. GetCharSet(ConvertLanguageIDtoCodePage(PRIMARYLANGID(_hklCurrent)), &iScript);
  587. SetPreferredKbd(iScript, _hklCurrent);
  588. }
  589. /*
  590. * CW32System::ActivateKeyboard (iScript)
  591. *
  592. * @mfunc
  593. * Change keyboard to that for iScript
  594. *
  595. * @rdesc
  596. * Keyboard hkl selected. 0 if no keyboard assigned to iScript
  597. */
  598. HKL CW32System::ActivateKeyboard(
  599. LONG iScript)
  600. {
  601. HKL hkl = 0;
  602. if((unsigned)iScript < NCHARSETS)
  603. {
  604. hkl = GetPreferredKbd(iScript);
  605. if(hkl && hkl != _hklCurrent && ActivateKeyboardLayout(hkl, 0))
  606. _hklCurrent = hkl;
  607. }
  608. return hkl;
  609. }
  610. /*
  611. * CW32System::FindDirectionalKeyboard (fRTL)
  612. *
  613. * @mfunc
  614. * Find first keyboard with direction given by fRTL
  615. *
  616. * @rdesc
  617. * HKL of keyboard selected. 0 if no keyboard for direction given by fRTL
  618. */
  619. HKL CW32System::FindDirectionalKeyboard(
  620. BOOL fRTL)
  621. {
  622. Assert(ARABIC_INDEX == (HEBREW_INDEX | 1));
  623. int iKB;
  624. if(fRTL)
  625. {
  626. GetCharSet(GetACP(), &iKB);
  627. if(!IN_RANGE(HEBREW_INDEX, iKB, ARABIC_INDEX))
  628. iKB = _hkl[HEBREW_INDEX] ? HEBREW_INDEX :
  629. _hkl[ARABIC_INDEX] ? ARABIC_INDEX : -1;
  630. }
  631. else
  632. for(iKB = 0;
  633. iKB < NCHARSETS && (!_hkl[iKB] || IN_RANGE(HEBREW_INDEX, iKB, ARABIC_INDEX));
  634. iKB++)
  635. ;
  636. return ActivateKeyboard(iKB);
  637. }
  638. enum DLL_ENUM{
  639. DLL_OLEAUT32,
  640. DLL_OLE32,
  641. #ifndef NOACCESSIBILITY
  642. DLL_ACC,
  643. DLL_USER32
  644. #endif
  645. };
  646. static void SetProcAddr(
  647. void * & pfunc,
  648. DLL_ENUM which,
  649. char * fname )
  650. {
  651. HINSTANCE hdll = NULL;
  652. EnterCriticalSection(&g_CriticalSection);
  653. if (pfunc == NULL)
  654. {
  655. switch (which)
  656. {
  657. case DLL_OLEAUT32:
  658. if (g_hOleAut32 == NULL)
  659. g_hOleAut32 = W32->LoadLibrary(L"oleaut32.dll" );
  660. hdll = g_hOleAut32;
  661. break;
  662. case DLL_OLE32:
  663. if (g_hOle32 == NULL)
  664. {
  665. g_hOle32 = W32->LoadLibrary(L"ole32.dll");
  666. CW32System::OleInitialize(NULL);
  667. }
  668. hdll = g_hOle32;
  669. break;
  670. #ifndef NOACCESSIBILITY
  671. case DLL_ACC:
  672. if (g_hAcc == NULL)
  673. g_hAcc = W32->LoadLibrary(L"oleacc.dll");
  674. hdll = g_hAcc;
  675. break;
  676. case DLL_USER32:
  677. if (g_hUser32 == NULL)
  678. g_hUser32 = W32->LoadLibrary(L"user32.dll");
  679. hdll = g_hUser32;
  680. break;
  681. #endif
  682. }
  683. Assert(hdll != NULL || which == DLL_USER32);
  684. pfunc = GetProcAddress( hdll, fname );
  685. }
  686. AssertSz(pfunc != NULL || which == DLL_USER32, fname);
  687. LeaveCriticalSection(&g_CriticalSection);
  688. }
  689. void CW32System::FreeOle()
  690. {
  691. if (g_hOleAut32 || g_hOle32) {
  692. EnterCriticalSection(&g_CriticalSection);
  693. if (g_hOleAut32 != NULL && FreeLibrary(g_hOleAut32)) {
  694. g_hOleAut32 = NULL;
  695. memset(&g_OleAut32Proc, 0, sizeof(g_OleAut32Proc));
  696. }
  697. if (g_hOle32 != NULL && FreeLibrary(g_hOle32)) {
  698. g_hOle32 = NULL;
  699. memset(&g_Ole32Proc, 0, sizeof(g_Ole32Proc));
  700. }
  701. LeaveCriticalSection(&g_CriticalSection);
  702. }
  703. }
  704. enum IME_DLL_ENUM{
  705. DLL_IMM32,
  706. DLL_IMESHARE
  707. };
  708. static HINSTANCE hIMM32 = NULL;
  709. static HINSTANCE hIMEShare = NULL;
  710. static void SetIMEProcAddr( void * &pfunc, IME_DLL_ENUM which, char * fname )
  711. {
  712. HINSTANCE hdll = NULL;
  713. EnterCriticalSection(&g_CriticalSection);
  714. if (pfunc == NULL)
  715. {
  716. switch (which) {
  717. case DLL_IMM32 :
  718. if (hIMM32 == NULL)
  719. hIMM32 = W32->LoadLibrary(L"imm32.dll" );
  720. Assert( hIMM32 != NULL );
  721. hdll = hIMM32;
  722. break;
  723. case DLL_IMESHARE :
  724. if (hIMEShare == NULL)
  725. hIMEShare = W32->LoadLibrary(L"imeshare.dll" );
  726. else if (hIMEShare == (HINSTANCE)INVALID_HANDLE_VALUE)
  727. goto Exit;
  728. hdll = hIMEShare;
  729. // set to invalid handle if we have tried loading it.
  730. // this is to avoid loading it again and again in case
  731. // imeshare.dll is not in the system.
  732. if (hIMEShare == NULL)
  733. hIMEShare = (HINSTANCE)INVALID_HANDLE_VALUE;
  734. break;
  735. }
  736. if (hdll)
  737. {
  738. pfunc = GetProcAddress( hdll, fname );
  739. Assert(pfunc != NULL );
  740. }
  741. }
  742. Exit:
  743. LeaveCriticalSection(&g_CriticalSection);
  744. }
  745. static IActiveIMMApp *pAIMM = (IActiveIMMApp *) NULL;
  746. typedef IMESHAREAPI void (IMECDECL*FEND_CAST)(void);
  747. void CW32System::FreeIME()
  748. {
  749. if (hIMM32 || hIMEShare || pAIMM) {
  750. EnterCriticalSection(&g_CriticalSection);
  751. if (hIMM32 != NULL && FreeLibrary(hIMM32)) {
  752. hIMM32 = NULL;
  753. memset(&g_IMM32Proc, 0, sizeof(g_IMM32Proc));
  754. }
  755. if (hIMEShare != NULL && hIMEShare != (HINSTANCE)INVALID_HANDLE_VALUE) {
  756. // clean up IMMShare before leaving
  757. if ( _pIMEShare )
  758. {
  759. _pIMEShare->FDeleteIMEShare();
  760. _pIMEShare = NULL;
  761. }
  762. else
  763. {
  764. // This is old IMEShare, end it the old way
  765. void *pEndIMEShareFunc;
  766. pEndIMEShareFunc = GetProcAddress( hIMEShare, "EndIMEShare" );
  767. if (pEndIMEShareFunc)
  768. {
  769. ( (FEND_CAST)pEndIMEShareFunc)();
  770. }
  771. }
  772. FreeLibrary(hIMEShare);
  773. hIMEShare = NULL;
  774. memset(&g_IMEShareProc, 0, sizeof(g_IMEShareProc));
  775. }
  776. if (pAIMM != (IActiveIMMApp *)NULL && pAIMM != (IActiveIMMApp *)INVALID_HANDLE_VALUE)
  777. {
  778. pAIMM->Release();
  779. pAIMM = (IActiveIMMApp *)NULL;
  780. }
  781. _fHaveAIMM = FALSE;
  782. _fHaveIMMEShare = FALSE;
  783. _fHaveIMMProcs = FALSE;
  784. LeaveCriticalSection(&g_CriticalSection);
  785. }
  786. }
  787. // return TRUE if we load AIMM
  788. BOOL CW32System::LoadAIMM()
  789. {
  790. HRESULT hResult;
  791. // return if AIMM has been loaded
  792. if (_fHaveAIMM)
  793. return TRUE;
  794. if (pAIMM == (IActiveIMMApp *)INVALID_HANDLE_VALUE)
  795. return FALSE;
  796. EnterCriticalSection(&g_CriticalSection);
  797. // load if it has not been loaded
  798. // Try with new W2K/COM+ CLSCTX_NO_CODE_DOWNLOAD flag
  799. hResult = CW32System::CoCreateInstance(CLSID_CActiveIMM,
  800. NULL, CLSCTX_INPROC_SERVER | CLSCTX_NO_CODE_DOWNLOAD, IID_IActiveIMMApp, (LPVOID *)&pAIMM);
  801. if (hResult == E_INVALIDARG) // Try again if CLSCTX_NO_CODE_DOWNLOAD not support
  802. hResult = CW32System::CoCreateInstance(CLSID_CActiveIMM,
  803. NULL, CLSCTX_INPROC_SERVER, IID_IActiveIMMApp, (LPVOID *)&pAIMM);
  804. _fHaveAIMM = TRUE;
  805. if (FAILED(hResult))
  806. {
  807. _fHaveAIMM = FALSE;
  808. pAIMM = (IActiveIMMApp *)INVALID_HANDLE_VALUE;
  809. }
  810. LeaveCriticalSection(&g_CriticalSection);
  811. return _fHaveAIMM;
  812. }
  813. // Return the Aimm object and AddRef()
  814. BOOL CW32System::GetAimmObject(IUnknown **ppAimm)
  815. {
  816. *ppAimm = NULL;
  817. if (pAIMM != NULL && pAIMM != (IActiveIMMApp *)INVALID_HANDLE_VALUE)
  818. {
  819. pAIMM->AddRef();
  820. *ppAimm = pAIMM;
  821. return TRUE;
  822. }
  823. return FALSE;
  824. }
  825. // return TRUE if we have IMEShare in system
  826. // else return FALSE
  827. typedef IMESHAREAPI BOOL (IMECDECL*FINIT_CAST)(void);
  828. typedef IMESHAREAPI CIMEShare * (IMECDECL*FPIME_CAST)(void);
  829. BOOL CW32System::HaveIMEShare()
  830. {
  831. // return if IMEShare has been loaded
  832. if (_fHaveIMMEShare)
  833. return TRUE;
  834. if (hIMEShare == (HINSTANCE)INVALID_HANDLE_VALUE)
  835. return FALSE;
  836. EnterCriticalSection(&g_CriticalSection);
  837. // load if it has not been loaded
  838. hIMEShare = W32->LoadLibrary(L"imeshare.dll");
  839. _fHaveIMMEShare = TRUE;
  840. // load fail, setup INVALID_HANDLE_VALUE
  841. if (hIMEShare == NULL)
  842. {
  843. hIMEShare = (HINSTANCE)INVALID_HANDLE_VALUE;
  844. _fHaveIMMEShare = FALSE;
  845. }
  846. else
  847. {
  848. // get the new IMEshare object and init the DLL
  849. void *pPIMEShareCreate;
  850. pPIMEShareCreate = GetProcAddress( hIMEShare, "PIMEShareCreate" );
  851. if (pPIMEShareCreate)
  852. {
  853. _pIMEShare = ( (FPIME_CAST)pPIMEShareCreate) ();
  854. if ( _pIMEShare == NULL )
  855. _fHaveIMMEShare = FALSE;
  856. else
  857. {
  858. // Setup underline styles that RE supports
  859. for (int i = IMESTY_UL_MIN; i <= IMESTY_UL_MAX; i++)
  860. {
  861. if (i == 2004 || i == 2007 || i == 2008 ||
  862. i == 2009 || i == 2010) // Obsolete styles
  863. continue;
  864. _pIMEShare->FSupportSty(i, i);
  865. }
  866. }
  867. }
  868. else
  869. {
  870. // This is old IMEShare, init it the old way
  871. void *pInitFunc;
  872. pInitFunc = GetProcAddress( hIMEShare, "FInitIMEShare" );
  873. if (pInitFunc)
  874. {
  875. _fHaveIMMEShare = ( (FINIT_CAST)pInitFunc)();
  876. }
  877. else
  878. // init failed, forget it
  879. _fHaveIMMEShare = FALSE;
  880. }
  881. if (_fHaveIMMEShare == FALSE)
  882. {
  883. // Init failed, forget it
  884. FreeLibrary(hIMEShare);
  885. hIMEShare = (HINSTANCE)INVALID_HANDLE_VALUE;
  886. }
  887. }
  888. LeaveCriticalSection(&g_CriticalSection);
  889. return _fHaveIMMEShare;
  890. }
  891. BOOL CW32System::getIMEShareObject(CIMEShare **ppIMEShare)
  892. {
  893. *ppIMEShare = _pIMEShare;
  894. return (_pIMEShare != NULL);
  895. }
  896. HRESULT CW32System::AIMMDefWndProc(HWND hWnd, UINT msg, WPARAM wparam, LPARAM lparam, LRESULT *plres)
  897. {
  898. if (pAIMM != NULL && pAIMM != (IActiveIMMApp *)INVALID_HANDLE_VALUE)
  899. {
  900. HRESULT hResult;
  901. LRESULT localLRes;
  902. hResult = pAIMM->OnDefWindowProc(hWnd, msg, wparam, lparam, &localLRes);
  903. if (hResult == S_OK)
  904. {
  905. *plres = localLRes;
  906. return S_OK;
  907. }
  908. }
  909. return S_FALSE;
  910. }
  911. HRESULT CW32System::AIMMGetCodePage(HKL hKL, UINT *uCodePage)
  912. {
  913. if (pAIMM != NULL && pAIMM != (IActiveIMMApp *)INVALID_HANDLE_VALUE)
  914. {
  915. HRESULT hResult;
  916. hResult = pAIMM->GetCodePageA(hKL, uCodePage);
  917. if (SUCCEEDED(hResult))
  918. return S_OK;
  919. }
  920. return S_FALSE;
  921. }
  922. HRESULT CW32System::AIMMActivate(BOOL fRestoreLayout)
  923. {
  924. if (pAIMM != NULL && pAIMM != (IActiveIMMApp *)INVALID_HANDLE_VALUE)
  925. {
  926. HRESULT hResult;
  927. hResult = pAIMM->Activate(fRestoreLayout);
  928. if (SUCCEEDED(hResult))
  929. return S_OK;
  930. }
  931. return S_FALSE;
  932. }
  933. HRESULT CW32System::AIMMDeactivate(void)
  934. {
  935. if (pAIMM != NULL && pAIMM != (IActiveIMMApp *)INVALID_HANDLE_VALUE)
  936. {
  937. HRESULT hResult;
  938. hResult = pAIMM->Deactivate();
  939. if (SUCCEEDED(hResult))
  940. return S_OK;
  941. }
  942. return S_FALSE;
  943. }
  944. HRESULT CW32System::AIMMFilterClientWindows(ATOM *aaClassList, UINT uSize)
  945. {
  946. if (pAIMM != NULL && pAIMM != (IActiveIMMApp *)INVALID_HANDLE_VALUE)
  947. {
  948. HRESULT hResult;
  949. hResult = pAIMM->FilterClientWindows(aaClassList, uSize);
  950. if (SUCCEEDED(hResult))
  951. return S_OK;
  952. }
  953. return S_FALSE;
  954. }
  955. #define RE_OLEAUTAPI(name) DECLSPEC_IMPORT HRESULT (STDAPICALLTYPE *name)
  956. #define RE_OLEAUTAPI_(type, name) DECLSPEC_IMPORT type (STDAPICALLTYPE *name)
  957. typedef RE_OLEAUTAPI(LRTL_CAST)(REFGUID, WORD, WORD, LCID, ITypeLib **);
  958. HRESULT CW32System::LoadRegTypeLib (
  959. REFGUID rguid,
  960. WORD wmajor,
  961. WORD wminor,
  962. LCID lcid,
  963. ITypeLib ** pptlib
  964. )
  965. {
  966. if (g_OleAut32Proc.LoadRegTypeLib == NULL)
  967. SetProcAddr( g_OleAut32Proc.LoadRegTypeLib, DLL_OLEAUT32, "LoadRegTypeLib" );
  968. return ((LRTL_CAST)g_OleAut32Proc.LoadRegTypeLib)(rguid, wmajor, wminor, lcid, pptlib);
  969. }
  970. typedef RE_OLEAUTAPI(LTL_CAST)(const OLECHAR *, ITypeLib **);
  971. HRESULT CW32System::LoadTypeLib ( const OLECHAR *szfile, ITypeLib **pptlib )
  972. {
  973. if (g_OleAut32Proc.LoadTypeLib == NULL)
  974. SetProcAddr( g_OleAut32Proc.LoadTypeLib, DLL_OLEAUT32, "LoadTypeLib" );
  975. return ((LTL_CAST)g_OleAut32Proc.LoadTypeLib)(szfile, pptlib);
  976. }
  977. typedef RE_OLEAUTAPI(LTLEX_CAST)(const OLECHAR *, REGKIND, ITypeLib **);
  978. HRESULT CW32System::LoadTypeLibEx ( const OLECHAR *szfile, REGKIND regkind, ITypeLib **pptlib )
  979. {
  980. if (g_OleAut32Proc.LoadTypeLibEx == NULL)
  981. SetProcAddr( g_OleAut32Proc.LoadTypeLibEx, DLL_OLEAUT32, "LoadTypeLibEx" );
  982. return ((LTLEX_CAST)g_OleAut32Proc.LoadTypeLibEx)(szfile, regkind, pptlib);
  983. }
  984. typedef RE_OLEAUTAPI_(BSTR, SAS_CAST)(const OLECHAR *);
  985. BSTR CW32System::SysAllocString ( const OLECHAR * sz )
  986. {
  987. if (g_OleAut32Proc.SysAllocString == NULL)
  988. SetProcAddr( g_OleAut32Proc.SysAllocString, DLL_OLEAUT32, "SysAllocString" );
  989. return ((SAS_CAST)g_OleAut32Proc.SysAllocString)(sz);
  990. }
  991. typedef RE_OLEAUTAPI_(BSTR, SASL_CAST)(const OLECHAR *, UINT);
  992. BSTR CW32System::SysAllocStringLen ( const OLECHAR *pch, UINT cch )
  993. {
  994. if (g_OleAut32Proc.SysAllocStringLen == NULL)
  995. SetProcAddr( g_OleAut32Proc.SysAllocStringLen, DLL_OLEAUT32, "SysAllocStringLen" );
  996. return ((SASL_CAST)g_OleAut32Proc.SysAllocStringLen)(pch, cch);
  997. }
  998. typedef RE_OLEAUTAPI_(void, SFS_CAST)(BSTR);
  999. void CW32System::SysFreeString ( BSTR bstr )
  1000. {
  1001. if (g_OleAut32Proc.SysFreeString == NULL)
  1002. SetProcAddr( g_OleAut32Proc.SysFreeString, DLL_OLEAUT32, "SysFreeString" );
  1003. ((SFS_CAST)g_OleAut32Proc.SysFreeString)(bstr);
  1004. }
  1005. typedef RE_OLEAUTAPI_(UINT, SSL_CAST)(BSTR);
  1006. UINT CW32System::SysStringLen ( BSTR bstr )
  1007. {
  1008. if (g_OleAut32Proc.SysStringLen == NULL)
  1009. SetProcAddr( g_OleAut32Proc.SysStringLen, DLL_OLEAUT32, "SysStringLen" );
  1010. return ((SSL_CAST)g_OleAut32Proc.SysStringLen)(bstr);
  1011. }
  1012. typedef RE_OLEAUTAPI_(void, VI_CAST)(VARIANTARG *);
  1013. void CW32System::VariantInit ( VARIANTARG * pvarg )
  1014. {
  1015. if (g_OleAut32Proc.VariantInit == NULL)
  1016. SetProcAddr( g_OleAut32Proc.VariantInit, DLL_OLEAUT32, "VariantInit" );
  1017. ((VI_CAST)g_OleAut32Proc.VariantInit)(pvarg);
  1018. }
  1019. #define RE_OLE32API(name) DECLSPEC_IMPORT HRESULT (STDAPICALLTYPE *name)
  1020. #define RE_OLE32API_(type, name) DECLSPEC_IMPORT type (STDAPICALLTYPE *name)
  1021. typedef RE_OLE32API(OCFD_CAST)(LPDATAOBJECT, REFIID, DWORD,
  1022. LPFORMATETC, LPOLECLIENTSITE,
  1023. LPSTORAGE, void **);
  1024. HRESULT CW32System::OleCreateFromData (
  1025. LPDATAOBJECT pDataObj,
  1026. REFIID riid,
  1027. DWORD renderopt,
  1028. LPFORMATETC pfetc,
  1029. LPOLECLIENTSITE pClientSite,
  1030. LPSTORAGE pStg,
  1031. void **ppvObj
  1032. )
  1033. {
  1034. if (g_Ole32Proc.OleCreateFromData == NULL)
  1035. SetProcAddr( g_Ole32Proc.OleCreateFromData, DLL_OLE32, "OleCreateFromData" );
  1036. return ((OCFD_CAST)g_Ole32Proc.OleCreateFromData)(pDataObj, riid, renderopt, pfetc, pClientSite, pStg, ppvObj);
  1037. }
  1038. typedef RE_OLE32API_(void, CTMF_CAST)(LPVOID);
  1039. void CW32System::CoTaskMemFree ( LPVOID pv )
  1040. {
  1041. if (g_Ole32Proc.CoTaskMemFree == NULL)
  1042. SetProcAddr( g_Ole32Proc.CoTaskMemFree, DLL_OLE32, "CoTaskMemFree" );
  1043. ((CTMF_CAST)g_Ole32Proc.CoTaskMemFree)(pv);
  1044. }
  1045. typedef RE_OLE32API(CBC_CAST)(DWORD, LPBC *);
  1046. HRESULT CW32System::CreateBindCtx ( DWORD reserved, LPBC * ppbc )
  1047. {
  1048. if (g_Ole32Proc.CreateBindCtx == NULL)
  1049. SetProcAddr( g_Ole32Proc.CreateBindCtx, DLL_OLE32, "CreateBindCtx" );
  1050. return ((CBC_CAST)g_Ole32Proc.CreateBindCtx)(reserved, ppbc);
  1051. }
  1052. typedef RE_OLE32API_(HANDLE, ODD_CAST)(HANDLE, CLIPFORMAT, UINT);
  1053. HANDLE CW32System::OleDuplicateData ( HANDLE hSrc, CLIPFORMAT cfFormat, UINT uFlags )
  1054. {
  1055. if (g_Ole32Proc.OleDuplicateData == NULL)
  1056. SetProcAddr( g_Ole32Proc.OleDuplicateData, DLL_OLE32, "OleDuplicateData" );
  1057. return ((ODD_CAST)g_Ole32Proc.OleDuplicateData)(hSrc, cfFormat, uFlags);
  1058. }
  1059. typedef RE_OLE32API(CTAC_CAST)(REFCLSID, REFCLSID);
  1060. HRESULT CW32System::CoTreatAsClass ( REFCLSID clsidold, REFCLSID clsidnew )
  1061. {
  1062. if (g_Ole32Proc.CoTreatAsClass == NULL)
  1063. SetProcAddr( g_Ole32Proc.CoTreatAsClass, DLL_OLE32, "CoTreatAsClass" );
  1064. return ((CTAC_CAST)g_Ole32Proc.CoTreatAsClass)(clsidold, clsidnew);
  1065. }
  1066. typedef RE_OLE32API(PIFC_CAST)(REFCLSID, LPOLESTR *);
  1067. HRESULT CW32System::ProgIDFromCLSID ( REFCLSID clsid, LPOLESTR * lplpszProgId )
  1068. {
  1069. if (g_Ole32Proc.ProgIDFromCLSID == NULL)
  1070. SetProcAddr( g_Ole32Proc.ProgIDFromCLSID, DLL_OLE32, "ProgIDFromCLSID" );
  1071. return ((PIFC_CAST)g_Ole32Proc.ProgIDFromCLSID)(clsid, lplpszProgId);
  1072. }
  1073. typedef RE_OLE32API(OCITO_CAST)(LPSTORAGE, LPOLESTREAM);
  1074. HRESULT CW32System::OleConvertIStorageToOLESTREAM ( LPSTORAGE pstg, LPOLESTREAM lpolestream)
  1075. {
  1076. if (g_Ole32Proc.OleConvertIStorageToOLESTREAM == NULL)
  1077. SetProcAddr( g_Ole32Proc.OleConvertIStorageToOLESTREAM, DLL_OLE32, "OleConvertIStorageToOLESTREAM" );
  1078. return ((OCITO_CAST)g_Ole32Proc.OleConvertIStorageToOLESTREAM)(pstg, lpolestream);
  1079. }
  1080. typedef RE_OLE32API(OCITOX_CAST)(LPSTORAGE, CLIPFORMAT, LONG, LONG, DWORD, LPSTGMEDIUM, LPOLESTREAM);
  1081. HRESULT CW32System::OleConvertIStorageToOLESTREAMEx (
  1082. LPSTORAGE pstg,
  1083. CLIPFORMAT cf,
  1084. LONG lwidth,
  1085. LONG lheight,
  1086. DWORD dwsize,
  1087. LPSTGMEDIUM pmedium,
  1088. LPOLESTREAM lpolestream
  1089. )
  1090. {
  1091. if (g_Ole32Proc.OleConvertIStorageToOLESTREAMEx == NULL)
  1092. SetProcAddr( g_Ole32Proc.OleConvertIStorageToOLESTREAMEx, DLL_OLE32, "OleConvertIStorageToOLESTREAMEx" );
  1093. return ((OCITOX_CAST)g_Ole32Proc.OleConvertIStorageToOLESTREAMEx)
  1094. (pstg,cf, lwidth, lheight, dwsize, pmedium, lpolestream);
  1095. }
  1096. typedef RE_OLE32API(OS_CAST)(LPPERSISTSTORAGE, LPSTORAGE, BOOL);
  1097. HRESULT CW32System::OleSave ( LPPERSISTSTORAGE pPS, LPSTORAGE pstg, BOOL fSameAsLoad )
  1098. {
  1099. if (g_Ole32Proc.OleSave == NULL)
  1100. SetProcAddr( g_Ole32Proc.OleSave, DLL_OLE32, "OleSave" );
  1101. return ((OS_CAST)g_Ole32Proc.OleSave)(pPS, pstg, fSameAsLoad);
  1102. }
  1103. typedef RE_OLE32API(SCDOI_CAST)(ILockBytes *, DWORD, DWORD, IStorage **);
  1104. HRESULT CW32System::StgCreateDocfileOnILockBytes (
  1105. ILockBytes *plkbyt,
  1106. DWORD grfmode,
  1107. DWORD res,
  1108. IStorage **ppstg
  1109. )
  1110. {
  1111. if (g_Ole32Proc.StgCreateDocfileOnILockBytes == NULL)
  1112. SetProcAddr( g_Ole32Proc.StgCreateDocfileOnILockBytes, DLL_OLE32, "StgCreateDocfileOnILockBytes" );
  1113. return ((SCDOI_CAST)g_Ole32Proc.StgCreateDocfileOnILockBytes)(plkbyt, grfmode, res, ppstg);
  1114. }
  1115. typedef RE_OLE32API(CIOH_CAST)(HGLOBAL, BOOL, ILockBytes **);
  1116. HRESULT CW32System::CreateILockBytesOnHGlobal ( HGLOBAL hGlobal, BOOL fDel, ILockBytes **pplkbyt )
  1117. {
  1118. if (g_Ole32Proc.CreateILockBytesOnHGlobal == NULL)
  1119. SetProcAddr( g_Ole32Proc.CreateILockBytesOnHGlobal, DLL_OLE32, "CreateILockBytesOnHGlobal" );
  1120. return ((CIOH_CAST)g_Ole32Proc.CreateILockBytesOnHGlobal)(hGlobal, fDel, pplkbyt);
  1121. }
  1122. typedef RE_OLE32API(OCLTF_CAST)(LPCOLESTR, REFIID, DWORD, LPFORMATETC,
  1123. LPOLECLIENTSITE, LPSTORAGE, void **);
  1124. HRESULT CW32System::OleCreateLinkToFile(
  1125. LPCOLESTR pstr,
  1126. REFIID rid,
  1127. DWORD renderopt,
  1128. LPFORMATETC pfetc,
  1129. LPOLECLIENTSITE psite,
  1130. LPSTORAGE pstg,
  1131. void **ppstg
  1132. )
  1133. {
  1134. if (g_Ole32Proc.OleCreateLinkToFile == NULL)
  1135. SetProcAddr( g_Ole32Proc.OleCreateLinkToFile, DLL_OLE32, "OleCreateLinkToFile" );
  1136. return ((OCLTF_CAST)g_Ole32Proc.OleCreateLinkToFile)(pstr, rid, renderopt, pfetc, psite, pstg, ppstg);
  1137. }
  1138. typedef RE_OLE32API_(LPVOID, CTMA_CAST)(ULONG);
  1139. LPVOID CW32System::CoTaskMemAlloc ( ULONG cb )
  1140. {
  1141. if (g_Ole32Proc.CoTaskMemAlloc == NULL)
  1142. SetProcAddr( g_Ole32Proc.CoTaskMemAlloc, DLL_OLE32, "CoTaskMemAlloc" );
  1143. return ((CTMA_CAST)g_Ole32Proc.CoTaskMemAlloc)(cb);
  1144. }
  1145. typedef RE_OLE32API_(LPVOID, CTMR_CAST)(LPVOID, ULONG);
  1146. LPVOID CW32System::CoTaskMemRealloc ( LPVOID pv, ULONG cv)
  1147. {
  1148. if (g_Ole32Proc.CoTaskMemRealloc == NULL)
  1149. SetProcAddr( g_Ole32Proc.CoTaskMemRealloc, DLL_OLE32, "CoTaskMemRealloc" );
  1150. return ((CTMR_CAST)g_Ole32Proc.CoTaskMemRealloc)(pv, cv);
  1151. }
  1152. typedef RE_OLE32API(OI_CAST)(LPVOID);
  1153. HRESULT CW32System::OleInitialize ( LPVOID pvres )
  1154. {
  1155. if (g_Ole32Proc.OleInitialize == NULL)
  1156. SetProcAddr( g_Ole32Proc.OleInitialize, DLL_OLE32, "OleInitialize" );
  1157. return ((OI_CAST)g_Ole32Proc.OleInitialize)(pvres);
  1158. }
  1159. typedef RE_OLE32API_(void, OUI_CAST)( void );
  1160. void CW32System::OleUninitialize ( void )
  1161. {
  1162. if (g_Ole32Proc.OleUninitialize == NULL)
  1163. SetProcAddr( g_Ole32Proc.OleUninitialize, DLL_OLE32, "OleUninitialize" );
  1164. ((OUI_CAST)g_Ole32Proc.OleUninitialize)();
  1165. }
  1166. typedef RE_OLE32API(OSC_CAST)(IDataObject *);
  1167. HRESULT CW32System::OleSetClipboard ( IDataObject *pdo )
  1168. {
  1169. if (g_Ole32Proc.OleSetClipboard == NULL)
  1170. SetProcAddr( g_Ole32Proc.OleSetClipboard, DLL_OLE32, "OleSetClipboard" );
  1171. return ((OSC_CAST)g_Ole32Proc.OleSetClipboard)(pdo);
  1172. }
  1173. typedef RE_OLE32API(OFC_CAST)(void);
  1174. HRESULT CW32System::OleFlushClipboard ( void )
  1175. {
  1176. if (g_Ole32Proc.OleFlushClipboard == NULL)
  1177. SetProcAddr( g_Ole32Proc.OleFlushClipboard, DLL_OLE32, "OleFlushClipboard" );
  1178. return ((OFC_CAST)g_Ole32Proc.OleFlushClipboard)();
  1179. }
  1180. typedef RE_OLE32API(OICC_CAST)(IDataObject *);
  1181. HRESULT CW32System::OleIsCurrentClipboard ( IDataObject *pdo )
  1182. {
  1183. if (g_Ole32Proc.OleIsCurrentClipboard == NULL)
  1184. SetProcAddr( g_Ole32Proc.OleIsCurrentClipboard, DLL_OLE32, "OleIsCurrentClipboard" );
  1185. return ((OICC_CAST)g_Ole32Proc.OleIsCurrentClipboard)(pdo);
  1186. }
  1187. typedef RE_OLE32API(DDD_CAST)(IDataObject *, IDropSource *,
  1188. DWORD, DWORD *);
  1189. HRESULT CW32System::DoDragDrop ( IDataObject *pdo, IDropSource *pds, DWORD dweffect, DWORD *pdweffect )
  1190. {
  1191. if (g_Ole32Proc.DoDragDrop == NULL)
  1192. SetProcAddr( g_Ole32Proc.DoDragDrop, DLL_OLE32, "DoDragDrop" );
  1193. return ((DDD_CAST)g_Ole32Proc.DoDragDrop)(pdo, pds, dweffect, pdweffect);
  1194. }
  1195. typedef RE_OLE32API(OGC_CAST)(IDataObject **);
  1196. HRESULT CW32System::OleGetClipboard ( IDataObject **ppdo )
  1197. {
  1198. if (g_Ole32Proc.OleGetClipboard == NULL)
  1199. SetProcAddr( g_Ole32Proc.OleGetClipboard, DLL_OLE32, "OleGetClipboard" );
  1200. return ((OGC_CAST)g_Ole32Proc.OleGetClipboard)(ppdo);
  1201. }
  1202. typedef RE_OLE32API(RDD_CAST)(HWND, IDropTarget *);
  1203. HRESULT CW32System::RegisterDragDrop ( HWND hwnd, IDropTarget *pdt )
  1204. {
  1205. if (g_Ole32Proc.RegisterDragDrop == NULL)
  1206. SetProcAddr( g_Ole32Proc.RegisterDragDrop, DLL_OLE32, "RegisterDragDrop" );
  1207. return ((RDD_CAST)g_Ole32Proc.RegisterDragDrop)(hwnd, pdt);
  1208. }
  1209. typedef RE_OLE32API(OCLFD_CAST)(IDataObject *, REFIID, DWORD,
  1210. LPFORMATETC, IOleClientSite *,
  1211. IStorage *, void **);
  1212. HRESULT CW32System::OleCreateLinkFromData (
  1213. IDataObject *pdo,
  1214. REFIID rid,
  1215. DWORD renderopt,
  1216. LPFORMATETC pfetc,
  1217. IOleClientSite *psite,
  1218. IStorage *pstg,
  1219. void **ppv
  1220. )
  1221. {
  1222. if (g_Ole32Proc.OleCreateLinkFromData == NULL)
  1223. SetProcAddr( g_Ole32Proc.OleCreateLinkFromData, DLL_OLE32, "OleCreateLinkFromData" );
  1224. return ((OCLFD_CAST)g_Ole32Proc.OleCreateLinkFromData)
  1225. (pdo, rid, renderopt, pfetc, psite, pstg, ppv);
  1226. }
  1227. typedef RE_OLE32API(OCSFD_CAST)(IDataObject *, REFIID, DWORD,
  1228. LPFORMATETC, IOleClientSite *,
  1229. IStorage *, void **);
  1230. HRESULT CW32System::OleCreateStaticFromData (
  1231. IDataObject *pdo,
  1232. REFIID rid,
  1233. DWORD renderopt,
  1234. LPFORMATETC pfetc,
  1235. IOleClientSite *psite,
  1236. IStorage *pstg,
  1237. void **ppv
  1238. )
  1239. {
  1240. if (g_Ole32Proc.OleCreateStaticFromData == NULL)
  1241. SetProcAddr( g_Ole32Proc.OleCreateStaticFromData, DLL_OLE32, "OleCreateStaticFromData" );
  1242. return ((OCSFD_CAST)g_Ole32Proc.OleCreateStaticFromData)
  1243. (pdo, rid, renderopt, pfetc, psite, pstg, ppv);
  1244. }
  1245. typedef RE_OLE32API(OD_CAST)(IUnknown *, DWORD, HDC, LPCRECT);
  1246. HRESULT CW32System::OleDraw ( IUnknown *punk, DWORD dwAspect, HDC hdc, LPCRECT prect )
  1247. {
  1248. if (g_Ole32Proc.OleDraw == NULL)
  1249. SetProcAddr( g_Ole32Proc.OleDraw, DLL_OLE32, "OleDraw" );
  1250. return ((OD_CAST)g_Ole32Proc.OleDraw)(punk, dwAspect, hdc, prect);
  1251. }
  1252. typedef RE_OLE32API(OSCO_CAST)(IUnknown *, BOOL);
  1253. HRESULT CW32System::OleSetContainedObject ( IUnknown *punk, BOOL fContained )
  1254. {
  1255. if (g_Ole32Proc.OleSetContainedObject == NULL)
  1256. SetProcAddr( g_Ole32Proc.OleSetContainedObject, DLL_OLE32, "OleSetContainedObject" );
  1257. return ((OSCO_CAST)g_Ole32Proc.OleSetContainedObject)(punk, fContained);
  1258. }
  1259. typedef RE_OLE32API(CDO_CAST)(IUnknown *, DWORD);
  1260. HRESULT CW32System::CoDisconnectObject ( IUnknown *punk, DWORD dwres )
  1261. {
  1262. if (g_Ole32Proc.CoDisconnectObject == NULL)
  1263. SetProcAddr( g_Ole32Proc.CoDisconnectObject, DLL_OLE32, "CoDisconnectObject" );
  1264. return ((CDO_CAST)g_Ole32Proc.CoDisconnectObject)(punk, dwres);
  1265. }
  1266. typedef RE_OLE32API(WFUTS_CAST)(IStorage *, CLIPFORMAT, LPOLESTR);
  1267. HRESULT CW32System::WriteFmtUserTypeStg ( IStorage *pstg, CLIPFORMAT cf, LPOLESTR pstr)
  1268. {
  1269. if (g_Ole32Proc.WriteFmtUserTypeStg == NULL)
  1270. SetProcAddr( g_Ole32Proc.WriteFmtUserTypeStg, DLL_OLE32, "WriteFmtUserTypeStg" );
  1271. return ((WFUTS_CAST)g_Ole32Proc.WriteFmtUserTypeStg)(pstg, cf, pstr);
  1272. }
  1273. typedef RE_OLE32API(WCS_CAST)(IStorage *, REFCLSID);
  1274. HRESULT CW32System::WriteClassStg ( IStorage *pstg, REFCLSID rid )
  1275. {
  1276. if (g_Ole32Proc.WriteClassStg == NULL)
  1277. SetProcAddr( g_Ole32Proc.WriteClassStg, DLL_OLE32, "WriteClassStg" );
  1278. return ((WCS_CAST)g_Ole32Proc.WriteClassStg)(pstg, rid);
  1279. }
  1280. typedef RE_OLE32API(SCS_CAST)(IStorage *, BOOL);
  1281. HRESULT CW32System::SetConvertStg ( IStorage *pstg, BOOL fConv )
  1282. {
  1283. if (g_Ole32Proc.SetConvertStg == NULL)
  1284. SetProcAddr( g_Ole32Proc.SetConvertStg, DLL_OLE32, "SetConvertStg" );
  1285. return ((SCS_CAST)g_Ole32Proc.SetConvertStg)(pstg, fConv);
  1286. }
  1287. typedef RE_OLE32API(RFUTS_CAST)(IStorage *, CLIPFORMAT *, LPOLESTR *);
  1288. HRESULT CW32System::ReadFmtUserTypeStg ( IStorage *pstg, CLIPFORMAT *pcf, LPOLESTR *pstr )
  1289. {
  1290. if (g_Ole32Proc.ReadFmtUserTypeStg == NULL)
  1291. SetProcAddr( g_Ole32Proc.ReadFmtUserTypeStg, DLL_OLE32, "ReadFmtUserTypeStg" );
  1292. return ((RFUTS_CAST)g_Ole32Proc.ReadFmtUserTypeStg)(pstg, pcf, pstr);
  1293. }
  1294. typedef RE_OLE32API(RCS_CAST)(IStorage *, CLSID *);
  1295. HRESULT CW32System::ReadClassStg ( IStorage *pstg, CLSID *pclsid )
  1296. {
  1297. if (g_Ole32Proc.ReadClassStg == NULL)
  1298. SetProcAddr( g_Ole32Proc.ReadClassStg, DLL_OLE32, "ReadClassStg" );
  1299. return ((RCS_CAST)g_Ole32Proc.ReadClassStg)(pstg, pclsid);
  1300. }
  1301. typedef RE_OLE32API(OR_CAST)(IUnknown *);
  1302. HRESULT CW32System::OleRun ( IUnknown *punk )
  1303. {
  1304. if (g_Ole32Proc.OleRun == NULL)
  1305. SetProcAddr( g_Ole32Proc.OleRun, DLL_OLE32, "OleRun" );
  1306. return ((OR_CAST)g_Ole32Proc.OleRun)(punk);
  1307. }
  1308. typedef RE_OLE32API(RevDD_CAST)(HWND);
  1309. HRESULT CW32System::RevokeDragDrop ( HWND hwnd )
  1310. {
  1311. if (g_Ole32Proc.RevokeDragDrop == NULL)
  1312. SetProcAddr( g_Ole32Proc.RevokeDragDrop, DLL_OLE32, "RevokeDragDrop" );
  1313. return ((RevDD_CAST)g_Ole32Proc.RevokeDragDrop)(hwnd);
  1314. }
  1315. typedef RE_OLE32API(CSOH_CAST)(HGLOBAL, BOOL, IStream **);
  1316. HRESULT CW32System::CreateStreamOnHGlobal ( HGLOBAL hglobal, BOOL fDel, IStream **ppstrm )
  1317. {
  1318. if (g_Ole32Proc.CreateStreamOnHGlobal == NULL)
  1319. SetProcAddr( g_Ole32Proc.CreateStreamOnHGlobal, DLL_OLE32, "CreateStreamOnHGlobal" );
  1320. return ((CSOH_CAST)g_Ole32Proc.CreateStreamOnHGlobal)(hglobal, fDel, ppstrm);
  1321. }
  1322. typedef RE_OLE32API(GHFS_CAST)(IStream *, HGLOBAL *);
  1323. HRESULT CW32System::GetHGlobalFromStream ( IStream *pstrm, HGLOBAL *phglobal )
  1324. {
  1325. if (g_Ole32Proc.GetHGlobalFromStream == NULL)
  1326. SetProcAddr( g_Ole32Proc.GetHGlobalFromStream, DLL_OLE32, "GetHGlobalFromStream" );
  1327. return ((GHFS_CAST)g_Ole32Proc.GetHGlobalFromStream)(pstrm, phglobal);
  1328. }
  1329. typedef RE_OLE32API(OCDH_CAST)(REFCLSID, IUnknown *, REFIID, void **);
  1330. HRESULT CW32System::OleCreateDefaultHandler (
  1331. REFCLSID clsid,
  1332. IUnknown *punk,
  1333. REFIID riid,
  1334. void **ppv
  1335. )
  1336. {
  1337. if (g_Ole32Proc.OleCreateDefaultHandler == NULL)
  1338. SetProcAddr( g_Ole32Proc.OleCreateDefaultHandler, DLL_OLE32, "OleCreateDefaultHandler" );
  1339. return ((OCDH_CAST)g_Ole32Proc.OleCreateDefaultHandler)(clsid, punk, riid, ppv);
  1340. }
  1341. typedef RE_OLE32API(CFPI_CAST)(LPCOLESTR, LPCLSID);
  1342. HRESULT CW32System::CLSIDFromProgID ( LPCOLESTR pstr, LPCLSID pclsid )
  1343. {
  1344. if (g_Ole32Proc.CLSIDFromProgID == NULL)
  1345. SetProcAddr( g_Ole32Proc.CLSIDFromProgID, DLL_OLE32, "CLSIDFromProgID" );
  1346. return ((CFPI_CAST)g_Ole32Proc.CLSIDFromProgID)(pstr, pclsid);
  1347. }
  1348. typedef RE_OLE32API(OCOTI_CAST)(LPOLESTREAM, IStorage *,
  1349. const DVTARGETDEVICE *);
  1350. HRESULT CW32System::OleConvertOLESTREAMToIStorage (
  1351. LPOLESTREAM pstrm,
  1352. IStorage *pstg,
  1353. const DVTARGETDEVICE *ptd
  1354. )
  1355. {
  1356. if (g_Ole32Proc.OleConvertOLESTREAMToIStorage == NULL)
  1357. SetProcAddr( g_Ole32Proc.OleConvertOLESTREAMToIStorage, DLL_OLE32, "OleConvertOLESTREAMToIStorage" );
  1358. return ((OCOTI_CAST)g_Ole32Proc.OleConvertOLESTREAMToIStorage)(pstrm, pstg, ptd);
  1359. }
  1360. typedef RE_OLE32API(OL_CAST)(IStorage *, REFIID, IOleClientSite *, void **);
  1361. HRESULT CW32System::OleLoad (
  1362. IStorage *pstg,
  1363. REFIID riid,
  1364. IOleClientSite *psite,
  1365. void **ppv
  1366. )
  1367. {
  1368. if (g_Ole32Proc.OleLoad == NULL)
  1369. SetProcAddr( g_Ole32Proc.OleLoad, DLL_OLE32, "OleLoad" );
  1370. return ((OL_CAST)g_Ole32Proc.OleLoad)(pstg, riid, psite, ppv);
  1371. }
  1372. typedef RE_OLE32API(RSM_CAST)(LPSTGMEDIUM);
  1373. HRESULT CW32System::ReleaseStgMedium ( LPSTGMEDIUM pmedium )
  1374. {
  1375. if (g_Ole32Proc.ReleaseStgMedium == NULL)
  1376. SetProcAddr( g_Ole32Proc.ReleaseStgMedium, DLL_OLE32, "ReleaseStgMedium" );
  1377. return ((RSM_CAST)g_Ole32Proc.ReleaseStgMedium)(pmedium);
  1378. }
  1379. typedef RE_OLE32API(CCI_CAST)(REFCLSID, LPUNKNOWN, DWORD, REFIID, LPVOID);
  1380. HRESULT CW32System::CoCreateInstance (REFCLSID rclsid, LPUNKNOWN pUnknown,
  1381. DWORD dwClsContext, REFIID riid, LPVOID *ppv)
  1382. {
  1383. if (g_Ole32Proc.CoCreateInstance == NULL)
  1384. SetProcAddr( g_Ole32Proc.CoCreateInstance, DLL_OLE32, "CoCreateInstance" );
  1385. return ((CCI_CAST)g_Ole32Proc.CoCreateInstance)(rclsid, pUnknown, dwClsContext, riid, ppv);
  1386. }
  1387. BOOL CW32System::ImmInitialize( void )
  1388. {
  1389. // MAC Only function.
  1390. return FALSE;
  1391. }
  1392. void CW32System::ImmTerminate( void )
  1393. {
  1394. // MAC only function.
  1395. return;
  1396. }
  1397. #ifndef NOACCESSIBILITY
  1398. typedef HRESULT (WINAPI *ACC_VC_CAST)(VARIANTARG FAR*, VARIANTARG FAR*);
  1399. HRESULT CW32System::VariantCopy(VARIANTARG FAR* pvargDest, VARIANTARG FAR* pvargSrc)
  1400. {
  1401. static void *pVariantCopy = NULL;
  1402. if (pVariantCopy == NULL)
  1403. SetProcAddr( pVariantCopy, DLL_OLEAUT32, "VariantCopy" );
  1404. if (pVariantCopy)
  1405. return ((ACC_VC_CAST)pVariantCopy)(pvargDest, pvargSrc);
  1406. return (E_NOINTERFACE);
  1407. }
  1408. typedef LRESULT (WINAPI *ACC_LFO_CAST)(REFIID, WPARAM, LPUNKNOWN);
  1409. LRESULT CW32System::LResultFromObject(REFIID riid, WPARAM wParam, LPUNKNOWN punk)
  1410. {
  1411. static void *pLResultFromObject = NULL;
  1412. if (pLResultFromObject == NULL)
  1413. SetProcAddr( pLResultFromObject, DLL_ACC, "LresultFromObject" );
  1414. if (pLResultFromObject)
  1415. return ((ACC_LFO_CAST)pLResultFromObject)(riid, wParam, punk);
  1416. return E_NOINTERFACE;
  1417. }
  1418. typedef HRESULT (WINAPI *ACC_AOFW_CAST)(HWND, DWORD, REFIID, void **);
  1419. HRESULT CW32System::AccessibleObjectFromWindow (HWND hWnd, DWORD dwID, REFIID riidInterface, void ** ppvObject)
  1420. {
  1421. static void *pAccessibleObjectFromWindow = NULL;
  1422. if (pAccessibleObjectFromWindow == NULL)
  1423. SetProcAddr( pAccessibleObjectFromWindow, DLL_ACC, "AccessibleObjectFromWindow" );
  1424. if (pAccessibleObjectFromWindow)
  1425. return ((ACC_AOFW_CAST)pAccessibleObjectFromWindow)(hWnd, dwID, riidInterface, ppvObject);
  1426. return (E_NOINTERFACE);
  1427. }
  1428. typedef BOOL (WINAPI *ACC_BI_CAST)(BOOL);
  1429. BOOL CW32System::BlockInput (BOOL fBlock)
  1430. {
  1431. static void *pBlockInput = NULL;
  1432. if (pBlockInput == NULL)
  1433. SetProcAddr( pBlockInput, DLL_USER32, "BlockInput" );
  1434. if (pBlockInput)
  1435. return ((ACC_BI_CAST)pBlockInput)(fBlock);
  1436. return FALSE;
  1437. }
  1438. typedef UINT (WINAPI *ACC_SI_CAST)(UINT, LPINPUT, int);
  1439. UINT CW32System::SendInput (UINT nInputs, LPINPUT pInputs, int cbSize)
  1440. {
  1441. static void *pSendInput = NULL;
  1442. if (pSendInput == NULL)
  1443. SetProcAddr( pSendInput, DLL_USER32, "SendInput" );
  1444. if (pSendInput)
  1445. return ((ACC_SI_CAST)pSendInput)(nInputs, pInputs, cbSize);
  1446. return 0;
  1447. }
  1448. typedef VOID (WINAPI *ACC_NWE_CAST)(DWORD, HWND, LONG, LONG);
  1449. VOID CW32System::NotifyWinEvent(DWORD dwEvent, HWND hWnd, LONG lObjectType, LONG lObjectId)
  1450. {
  1451. static void *pNotfiyWinEvent = NULL;
  1452. if (pNotfiyWinEvent == INVALID_HANDLE_VALUE)
  1453. return;
  1454. if (pNotfiyWinEvent == NULL)
  1455. SetProcAddr( pNotfiyWinEvent, DLL_USER32, "NotifyWinEvent" );
  1456. if (pNotfiyWinEvent)
  1457. ((ACC_NWE_CAST)pNotfiyWinEvent)(dwEvent, hWnd, lObjectType, lObjectId);
  1458. else
  1459. pNotfiyWinEvent = INVALID_HANDLE_VALUE;
  1460. }
  1461. #endif
  1462. typedef LONG (WINAPI*IGCSA_CAST)(HIMC, DWORD, LPVOID, DWORD);
  1463. LONG CW32System::ImmGetCompositionStringA (
  1464. HIMC hIMC,
  1465. DWORD dwIndex,
  1466. LPVOID lpBuf,
  1467. DWORD dwBufLen,
  1468. BOOL bAimmActivated)
  1469. {
  1470. if (bAimmActivated)
  1471. {
  1472. HRESULT hResult;
  1473. LONG lCopied = 0;
  1474. hResult = pAIMM->GetCompositionStringA(hIMC, dwIndex, dwBufLen, &lCopied, lpBuf);
  1475. return (SUCCEEDED(hResult) ? lCopied : 0);
  1476. }
  1477. if (g_IMM32Proc.ImmGetCompositionStringA == NULL)
  1478. SetIMEProcAddr( g_IMM32Proc.ImmGetCompositionStringA, DLL_IMM32, "ImmGetCompositionStringA" );
  1479. return ((IGCSA_CAST)g_IMM32Proc.ImmGetCompositionStringA)(hIMC, dwIndex, lpBuf, dwBufLen);
  1480. }
  1481. typedef LONG (WINAPI*IGCSW_CAST)(HIMC, DWORD, LPVOID, DWORD);
  1482. LONG CW32System::ImmGetCompositionStringW (
  1483. HIMC hIMC,
  1484. DWORD dwIndex,
  1485. LPVOID lpBuf,
  1486. DWORD dwBufLen,
  1487. BOOL bAimmActivated)
  1488. {
  1489. if (bAimmActivated)
  1490. {
  1491. HRESULT hResult;
  1492. LONG lCopied = 0;
  1493. hResult = pAIMM->GetCompositionStringW(hIMC, dwIndex, dwBufLen, &lCopied, lpBuf);
  1494. return (SUCCEEDED(hResult) ? lCopied : 0);
  1495. }
  1496. if (g_IMM32Proc.ImmGetCompositionStringW == NULL)
  1497. SetIMEProcAddr( g_IMM32Proc.ImmGetCompositionStringW, DLL_IMM32, "ImmGetCompositionStringW" );
  1498. return ((IGCSW_CAST)g_IMM32Proc.ImmGetCompositionStringW)(hIMC, dwIndex, lpBuf, dwBufLen);
  1499. }
  1500. typedef HIMC (WINAPI*IGC_CAST)(HWND);
  1501. HIMC CW32System::ImmGetContext ( HWND hWnd )
  1502. {
  1503. if (IsAIMMLoaded())
  1504. {
  1505. HRESULT hResult;
  1506. HIMC hIMC = 0;
  1507. hResult = pAIMM->GetContext(hWnd, &hIMC);
  1508. return (SUCCEEDED(hResult) ? hIMC : 0);
  1509. }
  1510. if (g_IMM32Proc.ImmGetContext == NULL)
  1511. SetIMEProcAddr( g_IMM32Proc.ImmGetContext, DLL_IMM32, "ImmGetContext" );
  1512. return ((IGC_CAST)g_IMM32Proc.ImmGetContext)(hWnd);
  1513. }
  1514. typedef BOOL (WINAPI*ISCFA_CAST)(HIMC, LPLOGFONTA);
  1515. BOOL CW32System::ImmSetCompositionFontA (
  1516. HIMC hIMC,
  1517. LPLOGFONTA lpLogFontA,
  1518. BOOL bAimmActivated)
  1519. {
  1520. if (bAimmActivated)
  1521. {
  1522. HRESULT hResult;
  1523. hResult = pAIMM->SetCompositionFontA(hIMC, lpLogFontA);
  1524. return (SUCCEEDED(hResult));
  1525. }
  1526. if (g_IMM32Proc.ImmSetCompositionFontA == NULL)
  1527. SetIMEProcAddr( g_IMM32Proc.ImmSetCompositionFontA, DLL_IMM32, "ImmSetCompositionFontA" );
  1528. return ((ISCFA_CAST)g_IMM32Proc.ImmSetCompositionFontA)(hIMC, lpLogFontA);
  1529. }
  1530. typedef BOOL (WINAPI*ISCW_CAST)(HIMC, LPCOMPOSITIONFORM);
  1531. BOOL CW32System::ImmSetCompositionWindow (
  1532. HIMC hIMC,
  1533. LPCOMPOSITIONFORM lpCompForm,
  1534. BOOL bAimmActivated)
  1535. {
  1536. if (bAimmActivated)
  1537. {
  1538. HRESULT hResult;
  1539. hResult = pAIMM->SetCompositionWindow(hIMC, lpCompForm);
  1540. return (SUCCEEDED(hResult));
  1541. }
  1542. if (g_IMM32Proc.ImmSetCompositionWindow == NULL)
  1543. SetIMEProcAddr( g_IMM32Proc.ImmSetCompositionWindow, DLL_IMM32, "ImmSetCompositionWindow" );
  1544. return ((ISCW_CAST)g_IMM32Proc.ImmSetCompositionWindow)(hIMC, lpCompForm);
  1545. }
  1546. typedef BOOL (WINAPI*IRC_CAST)(HWND, HIMC);
  1547. BOOL CW32System::ImmReleaseContext (
  1548. HWND hWnd,
  1549. HIMC hIMC)
  1550. {
  1551. if (IsAIMMLoaded())
  1552. {
  1553. HRESULT hResult;
  1554. hResult = pAIMM->ReleaseContext(hWnd, hIMC);
  1555. return (SUCCEEDED(hResult));
  1556. }
  1557. if (g_IMM32Proc.ImmReleaseContext == NULL)
  1558. SetIMEProcAddr( g_IMM32Proc.ImmReleaseContext, DLL_IMM32, "ImmReleaseContext" );
  1559. return ((IRC_CAST)g_IMM32Proc.ImmReleaseContext)(hWnd, hIMC);
  1560. }
  1561. typedef DWORD (WINAPI*IGP_CAST)(HKL, DWORD);
  1562. DWORD CW32System::ImmGetProperty (
  1563. HKL hKL,
  1564. DWORD dwIndex,
  1565. BOOL bAimmActivated)
  1566. {
  1567. if (bAimmActivated)
  1568. {
  1569. HRESULT hResult;
  1570. DWORD dwProperties=0;
  1571. hResult = pAIMM->GetProperty(hKL, dwIndex, &dwProperties);
  1572. return (SUCCEEDED(hResult) ? dwProperties : 0);
  1573. }
  1574. if (g_IMM32Proc.ImmGetProperty == NULL)
  1575. SetIMEProcAddr( g_IMM32Proc.ImmGetProperty, DLL_IMM32, "ImmGetProperty" );
  1576. return ((IGP_CAST)g_IMM32Proc.ImmGetProperty)(hKL, dwIndex);
  1577. }
  1578. typedef BOOL (WINAPI*IGCW_CAST)(HIMC, DWORD, LPCANDIDATEFORM);
  1579. BOOL CW32System::ImmGetCandidateWindow (
  1580. HIMC hIMC,
  1581. DWORD dwIndex,
  1582. LPCANDIDATEFORM lpCandidate,
  1583. BOOL bAimmActivated)
  1584. {
  1585. if (bAimmActivated)
  1586. {
  1587. HRESULT hResult;
  1588. hResult = pAIMM->GetCandidateWindow(hIMC, dwIndex, lpCandidate);
  1589. return (SUCCEEDED(hResult));
  1590. }
  1591. if (g_IMM32Proc.ImmGetCandidateWindow == NULL)
  1592. SetIMEProcAddr( g_IMM32Proc.ImmGetCandidateWindow, DLL_IMM32, "ImmGetCandidateWindow" );
  1593. return ((IGCW_CAST)g_IMM32Proc.ImmGetCandidateWindow)(hIMC, dwIndex, lpCandidate);
  1594. }
  1595. typedef BOOL (WINAPI*ISCAW_CAST)(HIMC, LPCANDIDATEFORM);
  1596. BOOL CW32System::ImmSetCandidateWindow (
  1597. HIMC hIMC,
  1598. LPCANDIDATEFORM lpCandidate ,
  1599. BOOL bAimmActivated)
  1600. {
  1601. if (bAimmActivated)
  1602. {
  1603. HRESULT hResult;
  1604. hResult = pAIMM->SetCandidateWindow(hIMC, lpCandidate);
  1605. return (SUCCEEDED(hResult));
  1606. }
  1607. if (g_IMM32Proc.ImmSetCandidateWindow == NULL)
  1608. SetIMEProcAddr( g_IMM32Proc.ImmSetCandidateWindow, DLL_IMM32, "ImmSetCandidateWindow" );
  1609. return ((ISCAW_CAST)g_IMM32Proc.ImmSetCandidateWindow)(hIMC, lpCandidate);
  1610. }
  1611. typedef BOOL (WINAPI*INIME_CAST)(HIMC, DWORD, DWORD, DWORD);
  1612. BOOL CW32System::ImmNotifyIME (
  1613. HIMC hIMC,
  1614. DWORD dwAction,
  1615. DWORD dwIndex,
  1616. DWORD dwValue,
  1617. BOOL bAimmActivated)
  1618. {
  1619. if (bAimmActivated)
  1620. {
  1621. HRESULT hResult;
  1622. hResult = pAIMM->NotifyIME(hIMC, dwAction, dwIndex, dwValue);
  1623. return (SUCCEEDED(hResult));
  1624. }
  1625. if (g_IMM32Proc.ImmNotifyIME == NULL)
  1626. SetIMEProcAddr( g_IMM32Proc.ImmNotifyIME, DLL_IMM32, "ImmNotifyIME" );
  1627. return ((INIME_CAST)g_IMM32Proc.ImmNotifyIME)(hIMC, dwAction, dwIndex, dwValue);
  1628. }
  1629. typedef HIMC (WINAPI*IAC_CAST)(HWND, HIMC);
  1630. HIMC CW32System::ImmAssociateContext (
  1631. HWND hWnd,
  1632. HIMC hIMC,
  1633. BOOL bAimmActivated)
  1634. {
  1635. if (bAimmActivated)
  1636. {
  1637. HRESULT hResult;
  1638. HIMC hPreviousIMC=0;
  1639. hResult = pAIMM->AssociateContext(hWnd, hIMC, &hPreviousIMC);
  1640. return (SUCCEEDED(hResult) ? hPreviousIMC : 0);
  1641. }
  1642. if (g_IMM32Proc.ImmAssociateContext == NULL)
  1643. SetIMEProcAddr( g_IMM32Proc.ImmAssociateContext, DLL_IMM32, "ImmAssociateContext" );
  1644. return ((IAC_CAST)g_IMM32Proc.ImmAssociateContext)(hWnd, hIMC);
  1645. }
  1646. typedef UINT (WINAPI*IGVK_CAST)(HWND);
  1647. UINT CW32System::ImmGetVirtualKey (
  1648. HWND hWnd,
  1649. BOOL bAimmActivated)
  1650. {
  1651. if (bAimmActivated)
  1652. {
  1653. HRESULT hResult;
  1654. UINT uVirtualKey=0;
  1655. hResult = pAIMM->GetVirtualKey(hWnd, &uVirtualKey);
  1656. return (SUCCEEDED(hResult) ? uVirtualKey : 0);
  1657. }
  1658. if (g_IMM32Proc.ImmGetVirtualKey == NULL)
  1659. SetIMEProcAddr( g_IMM32Proc.ImmGetVirtualKey, DLL_IMM32, "ImmGetVirtualKey" );
  1660. return ((IGVK_CAST)g_IMM32Proc.ImmGetVirtualKey)(hWnd);
  1661. }
  1662. // NOTE: We only use ImmEscape for IME_ESC_HANJA_MODE.
  1663. // Need to fix up if other methods are used.
  1664. typedef HIMC (WINAPI*IES_CAST)(HKL, HIMC, UINT, LPVOID );
  1665. HIMC CW32System::ImmEscape (
  1666. HKL hKL,
  1667. HIMC hIMC,
  1668. UINT uEscape,
  1669. LPVOID lpData,
  1670. BOOL bAimmActivated)
  1671. {
  1672. char szaHangeul[3] = {0, 0, 0};
  1673. // Aimm only support A version..
  1674. if (!OnWin9x() && !bAimmActivated)
  1675. goto USE_W_VERSION;
  1676. if (MbcsFromUnicode(szaHangeul, sizeof(szaHangeul),
  1677. (LPCWSTR)lpData, 1, CP_KOREAN, UN_NOOBJECTS) <= 0)
  1678. return FALSE;
  1679. if (bAimmActivated)
  1680. {
  1681. HRESULT hResult;
  1682. LRESULT lResult=0;
  1683. hResult = pAIMM->EscapeA(hKL, hIMC, uEscape, (LPVOID)szaHangeul, &lResult);
  1684. return (SUCCEEDED(hResult) ? (HIMC)lResult : 0);
  1685. }
  1686. if (g_IMM32Proc.ImmEscapeA == NULL)
  1687. SetIMEProcAddr( g_IMM32Proc.ImmEscapeA, DLL_IMM32, "ImmEscapeA" );
  1688. return ((IES_CAST)g_IMM32Proc.ImmEscapeA)(hKL, hIMC, uEscape, (LPVOID)szaHangeul);
  1689. USE_W_VERSION:
  1690. if (g_IMM32Proc.ImmEscapeW == NULL)
  1691. SetIMEProcAddr( g_IMM32Proc.ImmEscapeW, DLL_IMM32, "ImmEscapeW" );
  1692. return ((IES_CAST)g_IMM32Proc.ImmEscapeW)(hKL, hIMC, uEscape, lpData);
  1693. }
  1694. typedef BOOL (WINAPI*IGOS_CAST)(HIMC);
  1695. BOOL CW32System::ImmGetOpenStatus (
  1696. HIMC hIMC,
  1697. BOOL bAimmActivated)
  1698. {
  1699. if (bAimmActivated)
  1700. {
  1701. HRESULT hResult;
  1702. // AIMM is returning S_OK for OpenStatus == TRUE.
  1703. hResult = pAIMM->GetOpenStatus(hIMC);
  1704. return (hResult == S_OK);
  1705. }
  1706. if (g_IMM32Proc.ImmGetOpenStatus == NULL)
  1707. SetIMEProcAddr( g_IMM32Proc.ImmGetOpenStatus, DLL_IMM32, "ImmGetOpenStatus" );
  1708. return ((IGOS_CAST)g_IMM32Proc.ImmGetOpenStatus)(hIMC);
  1709. }
  1710. typedef BOOL (WINAPI*ISOS_CAST)(HIMC, BOOL);
  1711. BOOL CW32System::ImmSetOpenStatus (
  1712. HIMC hIMC,
  1713. BOOL fOpen,
  1714. BOOL bAimmActivated)
  1715. {
  1716. if (bAimmActivated)
  1717. {
  1718. HRESULT hResult;
  1719. hResult = pAIMM->SetOpenStatus(hIMC, fOpen);
  1720. return (SUCCEEDED(hResult));
  1721. }
  1722. if (g_IMM32Proc.ImmSetOpenStatus == NULL)
  1723. SetIMEProcAddr( g_IMM32Proc.ImmSetOpenStatus, DLL_IMM32, "ImmSetOpenStatus" );
  1724. return ((ISOS_CAST)g_IMM32Proc.ImmSetOpenStatus)(hIMC, fOpen);
  1725. }
  1726. typedef BOOL (WINAPI*IGCS_CAST)(HIMC , LPDWORD , LPDWORD );
  1727. BOOL CW32System::ImmGetConversionStatus (
  1728. HIMC hIMC,
  1729. LPDWORD pdwConversion,
  1730. LPDWORD pdwSentence,
  1731. BOOL bAimmActivated)
  1732. {
  1733. if (bAimmActivated)
  1734. {
  1735. HRESULT hResult;
  1736. hResult = pAIMM->GetConversionStatus(hIMC, pdwConversion, pdwSentence);
  1737. return (SUCCEEDED(hResult));
  1738. }
  1739. if (g_IMM32Proc.ImmGetConversionStatus == NULL)
  1740. SetIMEProcAddr( g_IMM32Proc.ImmGetConversionStatus, DLL_IMM32, "ImmGetConversionStatus" );
  1741. return ((IGCS_CAST)g_IMM32Proc.ImmGetConversionStatus)(hIMC, pdwConversion, pdwSentence);
  1742. }
  1743. typedef BOOL (WINAPI*ISCS_CAST)(HIMC , DWORD , DWORD );
  1744. BOOL CW32System::ImmSetConversionStatus (
  1745. HIMC hIMC,
  1746. DWORD dwConversion,
  1747. DWORD dwSentence,
  1748. BOOL bAimmActivated)
  1749. {
  1750. if (bAimmActivated)
  1751. {
  1752. HRESULT hResult;
  1753. hResult = pAIMM->SetConversionStatus(hIMC, dwConversion, dwSentence);
  1754. return (SUCCEEDED(hResult));
  1755. }
  1756. if (g_IMM32Proc.ImmSetConversionStatus == NULL)
  1757. SetIMEProcAddr( g_IMM32Proc.ImmSetConversionStatus, DLL_IMM32, "ImmSetConversionStatus" );
  1758. return ((ISCS_CAST)g_IMM32Proc.ImmSetConversionStatus)(hIMC, dwConversion, dwSentence);
  1759. }
  1760. typedef HWND (WINAPI*IGDW_CAST)( HWND );
  1761. HWND CW32System::ImmGetDefaultIMEWnd (
  1762. HWND hWnd,
  1763. BOOL bAimmActivated)
  1764. {
  1765. if (bAimmActivated)
  1766. {
  1767. HRESULT hResult;
  1768. HWND hIMEWnd;
  1769. hResult = pAIMM->GetDefaultIMEWnd(hWnd, &hIMEWnd);
  1770. return SUCCEEDED(hResult) ? hIMEWnd : NULL;
  1771. }
  1772. if (g_IMM32Proc.ImmGetDefaultIMEWnd == NULL)
  1773. SetIMEProcAddr( g_IMM32Proc.ImmGetDefaultIMEWnd, DLL_IMM32, "ImmGetDefaultIMEWnd" );
  1774. return ((IGDW_CAST)g_IMM32Proc.ImmGetDefaultIMEWnd)(hWnd);
  1775. }
  1776. typedef BOOL (WINAPI*ISCSW_CAST)(HIMC, DWORD, LPVOID, DWORD, LPVOID, DWORD);
  1777. BOOL CW32System::ImmSetCompositionStringW (
  1778. HIMC hIMC,
  1779. DWORD dwIndex,
  1780. LPVOID lpBuf,
  1781. DWORD dwBufLen,
  1782. LPVOID lpRead,
  1783. DWORD dwReadLen)
  1784. {
  1785. if (g_IMM32Proc.ImmSetCompositionStringW == NULL)
  1786. SetIMEProcAddr( g_IMM32Proc.ImmSetCompositionStringW, DLL_IMM32, "ImmSetCompositionStringW" );
  1787. return ((ISCSW_CAST)g_IMM32Proc.ImmSetCompositionStringW)(hIMC, dwIndex, lpBuf, dwBufLen, lpRead, dwReadLen);
  1788. }
  1789. typedef IMESHAREAPI BOOL (*FSS_CAST)(UINT, UINT);
  1790. BOOL CW32System::FSupportSty ( UINT uSty, UINT uStyAltered)
  1791. {
  1792. if (g_IMEShareProc.FSupportSty == NULL)
  1793. SetIMEProcAddr( g_IMEShareProc.FSupportSty, DLL_IMESHARE, "FSupportSty" );
  1794. return ((FSS_CAST)g_IMEShareProc.FSupportSty)(uSty, uStyAltered);
  1795. }
  1796. typedef IMESHAREAPI const IMESTYLE * (IMECDECL*PISFA_CAST)(const UINT);
  1797. const IMESTYLE * CW32System::PIMEStyleFromAttr ( const UINT uAttr)
  1798. {
  1799. if (g_IMEShareProc.PIMEStyleFromAttr == NULL)
  1800. SetIMEProcAddr( g_IMEShareProc.PIMEStyleFromAttr, DLL_IMESHARE, "PIMEStyleFromAttr" );
  1801. return ((PISFA_CAST)g_IMEShareProc.PIMEStyleFromAttr)( uAttr );
  1802. }
  1803. typedef IMESHAREAPI const IMECOLORSTY * (IMECDECL*PCSTFIS_CAST)(const IMESTYLE *);
  1804. const IMECOLORSTY * CW32System::PColorStyleTextFromIMEStyle ( const IMESTYLE * pIMEStyle)
  1805. {
  1806. if (g_IMEShareProc.PColorStyleTextFromIMEStyle == NULL)
  1807. SetIMEProcAddr( g_IMEShareProc.PColorStyleTextFromIMEStyle, DLL_IMESHARE, "PColorStyleTextFromIMEStyle" );
  1808. return ((PCSTFIS_CAST)g_IMEShareProc.PColorStyleTextFromIMEStyle)( pIMEStyle );
  1809. }
  1810. typedef IMESHAREAPI const IMECOLORSTY * (IMECDECL*PCSBFIS_CAST)(const IMESTYLE *);
  1811. const IMECOLORSTY * CW32System::PColorStyleBackFromIMEStyle ( const IMESTYLE * pIMEStyle)
  1812. {
  1813. if (g_IMEShareProc.PColorStyleBackFromIMEStyle == NULL)
  1814. SetIMEProcAddr( g_IMEShareProc.PColorStyleBackFromIMEStyle, DLL_IMESHARE, "PColorStyleBackFromIMEStyle" );
  1815. return ((PCSBFIS_CAST)g_IMEShareProc.PColorStyleBackFromIMEStyle)( pIMEStyle );
  1816. }
  1817. typedef IMESHAREAPI BOOL (IMECDECL*FBIS_CAST)(const IMESTYLE *);
  1818. BOOL CW32System::FBoldIMEStyle ( const IMESTYLE * pIMEStyle)
  1819. {
  1820. if (g_IMEShareProc.FBoldIMEStyle == NULL)
  1821. SetIMEProcAddr( g_IMEShareProc.FBoldIMEStyle, DLL_IMESHARE, "FBoldIMEStyle" );
  1822. return ((FBIS_CAST)g_IMEShareProc.FBoldIMEStyle)( pIMEStyle );
  1823. }
  1824. typedef IMESHAREAPI BOOL (IMECDECL*FIIS_CAST)(const IMESTYLE * );
  1825. BOOL CW32System::FItalicIMEStyle ( const IMESTYLE * pIMEStyle)
  1826. {
  1827. if (g_IMEShareProc.FItalicIMEStyle == NULL)
  1828. SetIMEProcAddr( g_IMEShareProc.FItalicIMEStyle, DLL_IMESHARE, "FItalicIMEStyle" );
  1829. return ((FIIS_CAST)g_IMEShareProc.FItalicIMEStyle)( pIMEStyle );
  1830. }
  1831. typedef IMESHAREAPI BOOL (IMECDECL*FUIS_CAST)(const IMESTYLE *);
  1832. BOOL CW32System::FUlIMEStyle ( const IMESTYLE * pIMEStyle)
  1833. {
  1834. if (g_IMEShareProc.FUlIMEStyle == NULL)
  1835. SetIMEProcAddr( g_IMEShareProc.FUlIMEStyle, DLL_IMESHARE, "FUlIMEStyle" );
  1836. return ((FUIS_CAST)g_IMEShareProc.FUlIMEStyle)( pIMEStyle );
  1837. }
  1838. typedef IMESHAREAPI UINT (IMECDECL*IUIS_CAST)(const IMESTYLE *);
  1839. UINT CW32System::IdUlIMEStyle ( const IMESTYLE * pIMEStyle)
  1840. {
  1841. if (g_IMEShareProc.IdUlIMEStyle == NULL)
  1842. SetIMEProcAddr( g_IMEShareProc.IdUlIMEStyle, DLL_IMESHARE, "IdUlIMEStyle" );
  1843. return ((IUIS_CAST)g_IMEShareProc.IdUlIMEStyle)( pIMEStyle );;
  1844. }
  1845. typedef IMESHAREAPI COLORREF (IMECDECL*RFICS_CAST)(const IMECOLORSTY *);
  1846. COLORREF CW32System::RGBFromIMEColorStyle ( const IMECOLORSTY * pColorStyle )
  1847. {
  1848. if (g_IMEShareProc.RGBFromIMEColorStyle == NULL)
  1849. SetIMEProcAddr( g_IMEShareProc.RGBFromIMEColorStyle, DLL_IMESHARE, "RGBFromIMEColorStyle" );
  1850. return ((RFICS_CAST)g_IMEShareProc.RGBFromIMEColorStyle)( pColorStyle );
  1851. }
  1852. CONVERTMODE WINAPI CW32System::DetermineConvertMode( HDC hdc, BYTE tmCharSet )
  1853. {
  1854. CONVERTMODE cm = CVT_NONE;
  1855. // Some fonts have problems under Win95 with the GetCharWidthW call; this
  1856. // is a simple heuristic to determine if this problem exists.
  1857. if (OnWin9x())
  1858. {
  1859. INT widthA, widthW;
  1860. BOOL fResA, fResW;
  1861. // FE font on Non-FE Win95 cannot use
  1862. // GetCharWidthW and ExtTextOutW
  1863. if(IsFECharSet(tmCharSet) && OnWin95FE())
  1864. // always use ANSI call for DBC fonts.
  1865. cm = CVT_WCTMB;
  1866. else
  1867. {
  1868. fResA = GetCharWidthA( hdc, ' ', ' ', &widthA );
  1869. fResW = GetCharWidthW( hdc, L' ', L' ', &widthW );
  1870. if ( fResA && fResW && widthA != widthW )
  1871. cm = CVT_WCTMB;
  1872. else
  1873. {
  1874. fResA = GetCharWidthA( hdc, 'a', 'a', &widthA );
  1875. fResW = GetCharWidthW( hdc, L'a', L'a', &widthW );
  1876. if ( fResA && fResW && widthA != widthW )
  1877. cm = CVT_WCTMB;
  1878. }
  1879. }
  1880. }
  1881. return cm;
  1882. }
  1883. void WINAPI CW32System::CalcUnderlineInfo(HDC hdc, CCcs *pcccs, TEXTMETRIC *ptm )
  1884. {
  1885. OUTLINETEXTMETRICA *potm;
  1886. unsigned cb;
  1887. CTempBuf tb;
  1888. if (ptm->tmPitchAndFamily & TMPF_TRUETYPE)
  1889. {
  1890. cb = GetOutlineTextMetricsA(hdc, 0, NULL);
  1891. if ((cb != 0)
  1892. && ((potm = (OUTLINETEXTMETRICA *) tb.GetBuf(cb)) != NULL)
  1893. && GetOutlineTextMetricsA(hdc, cb, potm))
  1894. {
  1895. pcccs->_dyULOffset = -potm->otmsUnderscorePosition;
  1896. pcccs->_dyULWidth = (short) max(1, potm->otmsUnderscoreSize);
  1897. pcccs->_dySOOffset = -potm->otmsStrikeoutPosition;
  1898. pcccs->_dySOWidth = (short) max(1, (int)potm->otmsStrikeoutSize);
  1899. return;
  1900. }
  1901. }
  1902. // Default calculation of size of underline
  1903. SHORT dyDescent = pcccs->_yDescent;
  1904. if (0 == dyDescent)
  1905. {
  1906. dyDescent = pcccs->_yHeight >> 3;
  1907. }
  1908. pcccs->_dyULWidth = (short) max(1, dyDescent / 4);
  1909. pcccs->_dyULOffset = (dyDescent - 3 * pcccs->_dyULWidth + 1) / 2;
  1910. if ((0 == pcccs->_dyULOffset) && (dyDescent > 1))
  1911. {
  1912. pcccs->_dyULOffset = 1;
  1913. }
  1914. pcccs->_dySOOffset = -ptm->tmAscent / 3;
  1915. pcccs->_dySOWidth = pcccs->_dyULWidth;
  1916. return;
  1917. }
  1918. BOOL WINAPI CW32System::ShowScrollBar( HWND hWnd, int wBar, BOOL bShow, LONG )
  1919. {
  1920. return ::ShowScrollBar( hWnd, wBar, bShow );
  1921. }
  1922. BOOL WINAPI CW32System::EnableScrollBar( HWND hWnd, UINT wSBflags, UINT wArrows )
  1923. {
  1924. return ::EnableScrollBar( hWnd, wSBflags, wArrows );
  1925. }
  1926. /*
  1927. * ReExtTextOutW(uiCodePage, hdc, x, y, fuOptions, lprc, lpString, cch ,lpDx, uiCodePage)
  1928. *
  1929. * @mfunc
  1930. * Patch around the Win95 FE bug and MetaFile problem.
  1931. *
  1932. * @rdesc
  1933. * Returns whatever ExtTextOut returns
  1934. */
  1935. BOOL ReExtTextOutW(
  1936. HDC hdc, //@parm handle to device context
  1937. int xp, //@parm x-coordinate of reference point
  1938. int yp, //@parm y-coordinate of reference point
  1939. UINT fuOptions, //@parm text-output options
  1940. CONST RECT *lprect, //@parm optional clipping and/or opaquing rectangle
  1941. const WCHAR *lpwchString, //@parm points to string
  1942. UINT cchCount, //@parm number of characters in string
  1943. CONST INT *lpDx, //@parm Ptr to array of intercharacter spacing values
  1944. UINT uiCodePage) //@parm CodePage for converting to Ansi
  1945. {
  1946. // This is a portion of Word code adapted for our needs.
  1947. // This is a work around for Win95FE bugs that cause GPFs in GDI if multiple
  1948. // characters above Unicode 0x7F are passed to ExtTextOutW.
  1949. // Also, when uiCodePage is non-zero, we want to output all characters using
  1950. // ExtTextOutA - each character at a time.
  1951. Assert(lpDx);
  1952. int cch;
  1953. const WCHAR *lpwchT = lpwchString;
  1954. const WCHAR *lpwchStart = lpwchT;
  1955. const WCHAR *lpwchEnd = lpwchString + cchCount;
  1956. CONST int *lpdxpCur;
  1957. BOOL fRet = 0;
  1958. while (lpwchT < lpwchEnd)
  1959. {
  1960. // characters less than 0x007F do not need special treatment
  1961. // we output then in contiguous runs
  1962. if (*lpwchT > 0x007F || uiCodePage)
  1963. {
  1964. if ((cch = lpwchT - lpwchStart) > 0)
  1965. {
  1966. lpdxpCur = lpDx + (lpwchStart - lpwchString);
  1967. // Output the run of chars less than 0x7F
  1968. fRet = ExtTextOutW(hdc, xp, yp, fuOptions, lprect, lpwchStart, cch, lpdxpCur);
  1969. if (!fRet)
  1970. return fRet;
  1971. fuOptions &= ~ETO_OPAQUE; // Don't erase mutliple times!!!
  1972. // Advance
  1973. while (cch--)
  1974. xp += *lpdxpCur++;
  1975. lpwchStart = lpwchT;
  1976. }
  1977. // Output chars above 0x7F one at a time to prevent Win95 FE GPF
  1978. lpdxpCur = lpDx + (lpwchStart - lpwchString);
  1979. if (uiCodePage)
  1980. {
  1981. // Need to convert to Ansi and use ExtTextOutA
  1982. char chAnsi[2];
  1983. int cbConv = WideCharToMultiByte(uiCodePage, 0, lpwchStart, 1,
  1984. chAnsi, 2, NULL, NULL);
  1985. if (cbConv <= 0)
  1986. {
  1987. chAnsi[0] = '?';
  1988. cbConv = 1;
  1989. }
  1990. fRet = ExtTextOutA(hdc, xp, yp, fuOptions, lprect, chAnsi, cbConv, lpdxpCur);
  1991. }
  1992. else
  1993. fRet = ExtTextOutW(hdc, xp, yp, fuOptions, lprect, lpwchStart, 1, lpdxpCur);
  1994. if (!fRet)
  1995. return fRet;
  1996. fuOptions &= ~ETO_OPAQUE; // Don't erase multiple times!!!
  1997. // Advance
  1998. if (lpdxpCur)
  1999. xp += *lpdxpCur;
  2000. lpwchStart++;
  2001. }
  2002. lpwchT++;
  2003. }
  2004. // output the final run; also, if we were called with cchCount == 0,
  2005. // make a call here to erase the rectangle
  2006. if ((cch = lpwchT - lpwchStart) > 0 || !cchCount)
  2007. fRet = ExtTextOutW(hdc, xp, yp, fuOptions, lprect, lpwchStart, cch, lpDx + (lpwchStart - lpwchString));
  2008. return fRet;
  2009. }
  2010. void WINAPI CW32System::REExtTextOut(
  2011. CONVERTMODE cm,
  2012. UINT uiCodePage,
  2013. HDC hdc,
  2014. int x,
  2015. int y,
  2016. UINT fuOptions,
  2017. CONST RECT *lprc,
  2018. const WCHAR *lpString,
  2019. UINT cch,
  2020. CONST INT *lpDx,
  2021. BOOL FEFontOnNonFEWin9x
  2022. )
  2023. {
  2024. bool fConvert = false;
  2025. BOOL fForceGdiFont = FALSE;
  2026. HFONT hfont = NULL, hfontCur = NULL;
  2027. // In order to get the EURO character to print, we need to force the
  2028. // printer to use the glyphs inside GDI
  2029. if(lpString[0] == EURO &&
  2030. (GetDeviceCaps(hdc, TECHNOLOGY) != DT_RASDISPLAY || W32->IsEnhancedMetafileDC(hdc)))
  2031. {
  2032. fForceGdiFont = TRUE;
  2033. hfontCur = SelectFont(hdc, GetStockObject(ANSI_VAR_FONT));
  2034. LOGFONT lf;
  2035. GetObject(hfontCur, sizeof(LOGFONT), &lf);
  2036. lf.lfOutPrecision = OnWin9x() ? OUT_TT_ONLY_PRECIS : OUT_SCREEN_OUTLINE_PRECIS;
  2037. hfont = CreateFontIndirect(&lf);
  2038. SelectObject(hdc, hfont);
  2039. }
  2040. if(OnWin9x())
  2041. {
  2042. // To get around some Win95 printer device problems with ExtTextOutW,
  2043. // use ExtTextOutA if string is ASCII or if it's 1252 and any
  2044. // nonASCII chars are between 0xA0 and 0xFF.
  2045. for(UINT i = 0;
  2046. i < cch &&
  2047. (lpString[i] <= 0x7F ||
  2048. IN_RANGE(0xA0, lpString[i], 0xFF) && uiCodePage == 1252);
  2049. i++)
  2050. ;
  2051. if(i == cch) // All ASCII or ANSI: setup to truncate
  2052. { // to low byte and use ExtTextOutA
  2053. cm = CVT_LOWBYTE;
  2054. fConvert = true;
  2055. }
  2056. }
  2057. if (fConvert || !FEFontOnNonFEWin9x && cm != CVT_NONE)
  2058. {
  2059. if (cm == CVT_WCTMB)
  2060. {
  2061. if (IsFECodePage(uiCodePage))
  2062. {
  2063. if (OnWinNTNonFE() || (OnWin9x() && !OnWin95()))
  2064. {
  2065. // On NonFE NT4 and Win98, we need to textout each char using
  2066. // ExtTextOutA
  2067. ReExtTextOutW(hdc, x, y, fuOptions, lprc, lpString, cch, lpDx, uiCodePage);
  2068. goto LExit;
  2069. }
  2070. }
  2071. }
  2072. // Need to convert and use ExtTextOutA
  2073. CTempCharBuf tcb;
  2074. CTempBuf tDx;
  2075. // Double the buffer size
  2076. int cbString = (cm == CVT_LOWBYTE) ? cch : cch * 2;
  2077. // String buffer for converted string - allocate on the stack
  2078. char *psz = tcb.GetBuf(cbString);
  2079. INT *pTempDx = NULL;
  2080. if (NULL == psz)
  2081. {
  2082. // Could not allocate buffer
  2083. goto LExit;
  2084. }
  2085. int cbConv = 0;
  2086. if(cm == CVT_WCTMB)
  2087. {
  2088. cbConv = WideCharToMultiByte(uiCodePage, 0, lpString, cch,
  2089. psz, cbString, NULL, NULL);
  2090. if(!cbConv)
  2091. {
  2092. // The conversion failed for one reason or another. We should
  2093. // make every effort to use WCTMB before we fall back to
  2094. // taking the low-byte of every wchar (below), otherwise we
  2095. // risk dropping the high-bytes and displaying garbage.
  2096. // Use the cpg from the font, since the uiCodePage passed is
  2097. // the requested codepage and the font-mapper may very well
  2098. // have mapped to a different one.
  2099. TEXTMETRIC tm;
  2100. uiCodePage = (GetTextMetrics(hdc, &tm) &&
  2101. tm.tmCharSet != DEFAULT_CHARSET &&
  2102. (UINT)GetCodePage(tm.tmCharSet) != uiCodePage) ?
  2103. GetCodePage(tm.tmCharSet) : 1252;
  2104. cbConv = WideCharToMultiByte(uiCodePage, 0, lpString, cch,
  2105. psz, cbString, NULL, NULL);
  2106. }
  2107. if (cbConv > 0 && lpDx)
  2108. {
  2109. pTempDx = (INT *)tDx.GetBuf(cbConv * sizeof(INT));
  2110. if (pTempDx)
  2111. {
  2112. // Repack lpDx to handle DBC
  2113. INT *pDx = pTempDx;
  2114. CONST INT*pInputDx = lpDx;
  2115. char *pTempChar = psz;
  2116. INT cNumBytes = cbConv;
  2117. while (cNumBytes > 0)
  2118. {
  2119. cNumBytes--;
  2120. if (GetTrailBytesCount(*pTempChar++, uiCodePage))
  2121. {
  2122. *pDx++ = *pInputDx++;
  2123. *pDx++ = 0;
  2124. cNumBytes--;
  2125. pTempChar++;
  2126. }
  2127. else
  2128. *pDx++ = *pInputDx++;
  2129. }
  2130. }
  2131. }
  2132. }
  2133. else
  2134. {
  2135. Assert(cm == CVT_LOWBYTE);
  2136. // drop through and convert using only low-bytes of WCHAR's
  2137. }
  2138. // WCTMB failed OR cm == CVT_LOWBYTE
  2139. if(!cbConv) // Convert WCHARs to CHARs
  2140. {
  2141. // FUTURE: We come here for both SYMBOL_CHARSET fonts and for
  2142. // DBCS bytes stuffed into wchar's (one byte per wchar) when
  2143. // the requested code page is not installed on the machine and
  2144. // the MBTWC fails. Instead, we could have another conversion
  2145. // mode that collects each DBCS char as a single wchar and then
  2146. // remaps to a DBCS string for ExtTextOutA. This would allow us
  2147. // to display text if the system has the right font even tho it
  2148. // doesn't have the right cpg.
  2149. // If we are converting this WCHAR buffer in this manner
  2150. // (by taking only the low-byte's of the WCHAR's), it is
  2151. // because:
  2152. // 1) cm == CVT_LOWBYTE
  2153. // 2) WCTMB above failed for some reason or another. It may
  2154. // be the case that the string is entirely ASCII in which
  2155. // case dropping the high-bytes is not a big deal (otherwise
  2156. // we assert).
  2157. cbConv = cch;
  2158. while(cch--)
  2159. {
  2160. #ifdef DEBUG
  2161. if (uiCodePage != CP_SYMBOL && lpString[cch] > 0xFF)
  2162. Tracef(TRCSEVWARN, "Non-zero high-byte WCHAR: %x", lpString[cch]);
  2163. #endif
  2164. psz[cch] = lpString[cch];
  2165. }
  2166. }
  2167. ::ExtTextOutA(hdc, x, y, fuOptions, lprc, psz, cbConv, pTempDx ? pTempDx : lpDx);
  2168. goto LExit;
  2169. }
  2170. if (OnWin9xFE() || FEFontOnNonFEWin9x)
  2171. ReExtTextOutW(hdc, x, y, fuOptions, lprc, lpString, cch, lpDx, 0);
  2172. else
  2173. ::ExtTextOutW(hdc, x, y, fuOptions, lprc, lpString, cch, lpDx);
  2174. LExit:
  2175. if (fForceGdiFont)
  2176. {
  2177. SelectObject(hdc, hfontCur);
  2178. SideAssert(DeleteObject(hfont));
  2179. }
  2180. }
  2181. void WINAPI CW32System::REGetCharWidth(
  2182. HDC hdc,
  2183. WCHAR ch,
  2184. SHORT * pWidth,
  2185. UINT cpg,
  2186. SHORT xOverhang,
  2187. INT iDefWidth)
  2188. {
  2189. BOOL fForceGdiFont = FALSE;
  2190. HFONT hfont = NULL, hfontCur = NULL;
  2191. int iwidth;
  2192. *pWidth = 0;
  2193. if ((cpg == CP_SYMBOL || ch <= 127) && ::GetCharWidthA(hdc, ch, ch, &iwidth))
  2194. {
  2195. *pWidth = (SHORT)iwidth;
  2196. goto Done;
  2197. }
  2198. if(ch == EURO && (GetDeviceCaps(hdc, TECHNOLOGY) != DT_RASDISPLAY || W32->IsEnhancedMetafileDC(hdc)))
  2199. {
  2200. fForceGdiFont = TRUE;
  2201. hfontCur = SelectFont(hdc, GetStockObject(ANSI_VAR_FONT));
  2202. LOGFONT lf;
  2203. GetObject(hfontCur, sizeof(LOGFONT), &lf);
  2204. lf.lfOutPrecision = OnWin9x() ? OUT_TT_ONLY_PRECIS : OUT_SCREEN_OUTLINE_PRECIS;
  2205. hfont = CreateFontIndirect(&lf);
  2206. SelectObject(hdc, hfont);
  2207. }
  2208. // For most workarounds, we will use the workarounds on all the OSs.
  2209. // We only use specific workaround is MBTWC conversion is needed.
  2210. // This is a workaround for Win95 FE bugs
  2211. // FUTURE (keithcu) This logic could be simplified.
  2212. if (OnWin95() && !IN_RANGE(0x80, ch, 0xFF) && // Not high ANSI?
  2213. (cpg == CP_CHINESE_TRAD || cpg == CP_CHINESE_SIM)) // Chinese CodePage?
  2214. {
  2215. int numOfDBCS = 0;
  2216. ::GetCharWidthW(hdc, 0x4e00, 0x4e00, &iwidth);
  2217. *pWidth = (SHORT)iwidth;
  2218. if (IN_RANGE(0x4e00, ch, 0x9fff))
  2219. goto Done;
  2220. // Use WCTMB heuristic
  2221. char ansiChar[2];
  2222. BOOL bDefCharUsed = FALSE;
  2223. numOfDBCS = ::WideCharToMultiByte( cpg, 0, &ch, 1, ansiChar, 2, NULL, &bDefCharUsed);
  2224. WORD wDBCS = (BYTE)ansiChar[0];
  2225. if (2 == numOfDBCS)
  2226. wDBCS = (BYTE)ansiChar[0] << 8 | (BYTE)ansiChar[1];
  2227. if (numOfDBCS > 0 && ::GetCharWidthA( hdc, wDBCS, wDBCS, &iwidth))
  2228. {
  2229. *pWidth = (SHORT)iwidth;
  2230. goto Done;
  2231. }
  2232. }
  2233. //Win '95 GPFs if you pass in 0xFFFF
  2234. if (ch == 0xFFFF)
  2235. ch = 0xFFFE;
  2236. if (::GetCharWidthW(hdc, ch, ch, &iwidth))
  2237. *pWidth = (SHORT)iwidth;
  2238. if(fForceGdiFont)
  2239. {
  2240. SelectObject(hdc, hfontCur);
  2241. SideAssert(DeleteObject(hfont));
  2242. }
  2243. Done:
  2244. *pWidth -= xOverhang;
  2245. if (0 >= *pWidth)
  2246. {
  2247. // Sometimes GetCharWidth will return a zero length for small
  2248. // characters. When this happens we will use the default width
  2249. // for the font if that is non-zero otherwise we just us 1 because
  2250. // this is the smallest valid value.
  2251. // This code can also be triggered if the overhang is bigger than the
  2252. // width returned by the OS call to get the character width.
  2253. if (0 == iDefWidth)
  2254. *pWidth = 1;
  2255. else
  2256. *pWidth = (SHORT)iDefWidth;
  2257. }
  2258. }
  2259. BOOL WINAPI CW32System::IsEnhancedMetafileDC( HDC hDC )
  2260. {
  2261. BOOL fEMFDC = FALSE;
  2262. DWORD dwObjectType;
  2263. dwObjectType = ::GetObjectType( hDC );
  2264. if ( OBJ_ENHMETADC == dwObjectType || OBJ_ENHMETAFILE == dwObjectType )
  2265. fEMFDC = TRUE;
  2266. else if ( OnWin95() && OBJ_DC == dwObjectType )
  2267. {
  2268. // HACK Alert, Enhanced Metafile DC does not support any Escape function
  2269. // and shoudl return 0.
  2270. int iEscapeFuction = QUERYESCSUPPORT;
  2271. if ( Escape( hDC, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&iEscapeFuction, NULL) == 0 )
  2272. fEMFDC = TRUE;
  2273. }
  2274. return fEMFDC;
  2275. }
  2276. HPALETTE WINAPI CW32System::ManagePalette(
  2277. HDC hdc,
  2278. CONST LOGPALETTE *plogpal,
  2279. HPALETTE &hpalOld,
  2280. HPALETTE &hpalNew
  2281. )
  2282. {
  2283. if (hpalNew == NULL)
  2284. {
  2285. hpalNew = ::CreatePalette(plogpal);
  2286. if (hpalNew != NULL)
  2287. {
  2288. hpalOld = ::SelectPalette(hdc, hpalNew, TRUE);
  2289. ::RealizePalette(hdc);
  2290. }
  2291. }
  2292. else
  2293. {
  2294. // A new palette was created previously and we are restoring the old one
  2295. ::SelectPalette(hdc, hpalOld, TRUE);
  2296. ::RealizePalette(hdc);
  2297. DeleteObject(hpalNew);
  2298. hpalNew = NULL;
  2299. }
  2300. return hpalNew;
  2301. }
  2302. int WINAPI CW32System::GetMapMode(HDC hdc)
  2303. {
  2304. return ::GetMapMode(hdc);
  2305. }
  2306. BOOL WINAPI CW32System::WinLPtoDP(HDC hdc, LPPOINT lppoints, int nCount)
  2307. {
  2308. return ::LPtoDP(hdc, lppoints, nCount);
  2309. }
  2310. long WINAPI CW32System::WvsprintfA( LONG cbBuf, LPSTR szBuf, LPCSTR szFmt, va_list arglist )
  2311. {
  2312. LONG cb;
  2313. cb = ::wvsprintfA( szBuf, szFmt, arglist );
  2314. Assert(cb < cbBuf);
  2315. return cb;
  2316. }
  2317. int WINAPI CW32System::MulDiv(int nNumber, int nNumerator, int nDenominator)
  2318. {
  2319. if ((nNumerator && nNumerator == nDenominator) || (nDenominator && !nNumber))
  2320. return nNumber;
  2321. return ::MulDiv(nNumber, nNumerator, nDenominator);
  2322. }
  2323. /*
  2324. * GetFacePriorityCharSet(WCHAR* szFaceName)
  2325. *
  2326. * @func
  2327. * return charset *really* supported by given facename
  2328. */
  2329. int CALLBACK GetFacePriCharSetProc (
  2330. ENUMLOGFONTEX *lpelfe,
  2331. NEWTEXTMETRIC *lpntm,
  2332. int iFontType,
  2333. LPARAM lParam)
  2334. {
  2335. Assert (lParam);
  2336. *(BYTE*)lParam = lpntm->tmCharSet;
  2337. return 0;
  2338. }
  2339. void CW32System::GetFacePriCharSet(HDC hdc, LOGFONT* plf)
  2340. {
  2341. ::EnumFontFamiliesEx(hdc, plf, (FONTENUMPROC)GetFacePriCharSetProc, (LPARAM)&plf->lfCharSet, 0);
  2342. }
  2343. /*
  2344. * CW32System::ReadRegDigitSubstitionMode(void)
  2345. *
  2346. * @mfunc
  2347. * Get the digit substitution mode (available on BiDi/Thai platforms)
  2348. *
  2349. * @rdesc
  2350. * 0 - Context (digit shape follows preceding run or CHARFORMAT's charset
  2351. * 1 - None (digits always show as European digit shape)
  2352. * 2 - National (digits always show as user locale's native shape)
  2353. */
  2354. BYTE CW32System::ReadRegDigitSubstitutionMode()
  2355. {
  2356. HKEY hk;
  2357. DWORD keyDataType;
  2358. DWORD dwDataSize;
  2359. BYTE rgbValue[2];
  2360. BYTE bDigitMode;
  2361. bDigitMode = DIGITS_NOTIMPL; // assume "Not Implemented"
  2362. // Perform platform check before reading registry
  2363. if (!OnWin9xFE() && !OnWinNTFE() &&
  2364. IsComplexScriptLcid(GetThreadLocale()))
  2365. {
  2366. if(RegOpenKeyExA(HKEY_CURRENT_USER,
  2367. "Control Panel\\International",
  2368. 0, // reserved
  2369. KEY_QUERY_VALUE,
  2370. &hk) == ERROR_SUCCESS)
  2371. {
  2372. dwDataSize = 2;
  2373. if (RegQueryValueExA(hk,
  2374. "NumShape",
  2375. NULL, // reserved
  2376. &keyDataType,
  2377. (LPBYTE) &rgbValue,
  2378. &dwDataSize) == ERROR_SUCCESS)
  2379. {
  2380. if (rgbValue[0] > 0x2f)
  2381. bDigitMode = rgbValue[0] - 0x30 + 1;
  2382. if (bDigitMode > DIGITS_NATIONAL)
  2383. bDigitMode = DIGITS_NONE;
  2384. }
  2385. RegCloseKey(hk);
  2386. }
  2387. }
  2388. return bDigitMode;
  2389. }
  2390. #ifdef DEBUG
  2391. /*
  2392. * TestGetCharFlags125x(iFirst, iLast)
  2393. *
  2394. * @func
  2395. * Unit test function for GetCharFlags125x(). Assert if GetCharFlags125x()
  2396. * claims that any char in Unicode range iFirst thru iLast 1) should
  2397. * roundtrip multibyte conversion using a codepage in the range 1250-1258
  2398. * when it doesn't, or 2) shouldn't roundtrip when it does.
  2399. */
  2400. BOOL TestGetCharFlags125x(
  2401. int iFirst,
  2402. int iLast)
  2403. {
  2404. LONG cch = iLast - iFirst + 1;
  2405. LONG i;
  2406. Assert(cch <= 0x700 - 0xA0);
  2407. char rgach[0x700 - 0xA0];
  2408. WCHAR rgch [0x700 - 0xA0];
  2409. WCHAR * pch;
  2410. for(i = iFirst, pch = rgch; i <= iLast; pch++, i++)
  2411. *pch = (WCHAR)i;
  2412. for(int CodePage = 1250; CodePage <= 1258; CodePage++)
  2413. {
  2414. if(cch != WideCharToMultiByte(CodePage, 0, rgch, cch, rgach, cch, "\0", NULL) ||
  2415. cch != MultiByteToWideChar(CodePage, 0, rgach, cch, rgch, cch))
  2416. {
  2417. continue; // Missing code page
  2418. }
  2419. // 1250 1251 1252 1253 1254 1255 1256 1257 1258
  2420. const static WORD rgMask[] = {0x2, 0x4, 0x1, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100};
  2421. DWORD dwMask = rgMask[CodePage - 1250] << 8;
  2422. for(i = iFirst, pch = rgch; i <= iLast; pch++, i++)
  2423. {
  2424. AssertSz(!((*pch != (WCHAR)i) ^ !(W32->GetCharFlags125x(i) & dwMask)),
  2425. "GetCharFlags125x() failure");
  2426. *pch = (WCHAR)i; // Restore value
  2427. }
  2428. }
  2429. return TRUE; // Above AssertSz() reports any errors
  2430. }
  2431. #endif
  2432. /*
  2433. * CW32System::InitSysParams(fUpdate)
  2434. *
  2435. * @mfunc
  2436. * This method is used to initialize certain system wide parameters that
  2437. * that are used in richedit. This can also be used as an update method
  2438. * if we ever handle system parameter change notifications. The update
  2439. * parameter id provided for this purpose. Also note that if we ever support
  2440. * SysParam updating, we may have to protect access with locks.
  2441. */
  2442. void CW32System::InitSysParams(BOOL fUpdate)
  2443. {
  2444. TRACEBEGIN(TRCSUBSYSUTIL, TRCSCOPEINTERN, "CW32System::InitSysParams");
  2445. CLock lock;
  2446. if (!_fSysParamsOk || fUpdate)
  2447. {
  2448. _fSysParamsOk = TRUE;
  2449. const LONG dxSelBarDefaultSize = 8;
  2450. HDC hdc = GetScreenDC();
  2451. HFONT hfontOld;
  2452. TEXTMETRIC tm;
  2453. _xPerInchScreenDC = GetDeviceCaps(hdc, LOGPIXELSX);
  2454. if (_xPerInchScreenDC == 0)
  2455. _xPerInchScreenDC = 0x60;
  2456. _yPerInchScreenDC = GetDeviceCaps(hdc, LOGPIXELSY);
  2457. if (_yPerInchScreenDC == 0)
  2458. _yPerInchScreenDC = 0x60;
  2459. int cPalette = GetDeviceCaps(hdc, SIZEPALETTE);
  2460. // 256 colors is where we seem to need to use the palette.
  2461. if (256 == cPalette)
  2462. {
  2463. _fUsePalette = TRUE;
  2464. }
  2465. // calculate a himetric selection bar for the window's host.
  2466. _dxSelBar = W32->DXtoHimetricX(dxSelBarDefaultSize, _xPerInchScreenDC);
  2467. RefreshKeyboardLayout();
  2468. _hSystemFont = (HFONT)GetStockObject(SYSTEM_FONT);
  2469. hfontOld = SelectFont(hdc, _hSystemFont);
  2470. if(hfontOld)
  2471. {
  2472. W32->GetTextMetrics(hdc, &tm);
  2473. _xWidthSys = (INT) tm.tmAveCharWidth;
  2474. _yHeightSys = (INT) tm.tmHeight;
  2475. _ySysFontLeading = (INT) tm.tmInternalLeading;
  2476. _bSysCharSet = tm.tmCharSet;
  2477. SelectFont(hdc, hfontOld);
  2478. }
  2479. _nScrollInset = (WORD)GetProfileIntA("windows", "ScrollInset",
  2480. DD_DEFSCROLLINSET);
  2481. _nDragDelay = (WORD)GetProfileIntA("windows", "DragDelay",
  2482. DD_DEFDRAGDELAY);
  2483. _nDragMinDist = (WORD)GetProfileIntA("windows", "DragMinDist",
  2484. DD_DEFDRAGMINDIST);
  2485. _nScrollDelay = (WORD)GetProfileIntA("windows", "ScrollDelay",
  2486. DD_DEFSCROLLDELAY);
  2487. _nScrollInterval = (WORD)GetProfileIntA("windows", "ScrollInterval",
  2488. DD_DEFSCROLLINTERVAL);
  2489. _nScrollVAmount = (WORD)(GetYPerInchScreenDC()*DEFSCROLLVAMOUNT)/100;
  2490. _nScrollHAmount = (GetXPerInchScreenDC()*DEFSCROLLHAMOUNT)/100;
  2491. _cxBorder = GetSystemMetrics(SM_CXBORDER); // Unsizable window border
  2492. _cyBorder = GetSystemMetrics(SM_CYBORDER); // widths
  2493. _cxVScroll = GetSystemMetrics(SM_CXVSCROLL); // dimensions
  2494. _cyHScroll = GetSystemMetrics(SM_CYHSCROLL); //
  2495. _cxDoubleClk = GetSystemMetrics(SM_CXDOUBLECLK);
  2496. _cyDoubleClk = GetSystemMetrics(SM_CYDOUBLECLK);
  2497. _DCT = GetDoubleClickTime();
  2498. _sysiniflags = ::GetProfileIntA("richedit30", "flags", 0);
  2499. #ifdef DEBUG
  2500. if(OnWinNT5() && (_sysiniflags & SYSINI_DEBUGGCF125X))
  2501. {
  2502. TestGetCharFlags125x(0xA0, 0x6FF);
  2503. TestGetCharFlags125x(0x2000, 0x2122);
  2504. }
  2505. #endif
  2506. _bDigitSubstMode = ReadRegDigitSubstitutionMode();
  2507. if (g_pusp)
  2508. g_pusp->ApplyDigitSubstitution(_bDigitSubstMode);
  2509. }
  2510. }
  2511. /*
  2512. * CW32System::GetSizeCursor(void)
  2513. *
  2514. * @mfunc
  2515. * Get the sizing cursor (double arrow) specified by
  2516. * the resource id. If the cursors are not loaded
  2517. * load them and cache them.
  2518. * parameters:
  2519. * idcur - cursor resource id.
  2520. *
  2521. * @rdesc
  2522. * Handle to cursor or null if failure. Returns NULL if
  2523. * idcur is null.
  2524. */
  2525. HCURSOR CW32System::GetSizeCursor(
  2526. LPTSTR idcur)
  2527. {
  2528. if(!idcur )
  2529. return NULL;
  2530. //If any cursor isn't loaded, try loading it.
  2531. if(!_hcurSizeNS)
  2532. _hcurSizeNS = LoadCursor(NULL, IDC_SIZENS);
  2533. if(!_hcurSizeWE)
  2534. _hcurSizeWE = LoadCursor(NULL, IDC_SIZEWE);
  2535. if(!_hcurSizeNWSE)
  2536. _hcurSizeNWSE = LoadCursor(NULL, IDC_SIZENWSE);
  2537. if(!_hcurSizeNESW)
  2538. _hcurSizeNESW = LoadCursor(NULL, IDC_SIZENESW);
  2539. //Return cursor corresponding to id passed in.
  2540. if(idcur == IDC_SIZENS && _hcurSizeNS)
  2541. return _hcurSizeNS;
  2542. if(idcur == IDC_SIZEWE && _hcurSizeWE)
  2543. return _hcurSizeWE;
  2544. if(idcur == IDC_SIZENWSE && _hcurSizeNWSE)
  2545. return _hcurSizeNWSE;
  2546. if(idcur == IDC_SIZENESW && _hcurSizeNESW)
  2547. return _hcurSizeNESW;
  2548. AssertSz(FALSE, "Failure loading sizing cursor.");
  2549. return NULL;
  2550. }
  2551. /*
  2552. * CW32System:GetRollerLineScrollCount()
  2553. *
  2554. * @mfunc returns the number of lines to scroll with a roller mouse wheel.
  2555. * -1 means scroll by pages
  2556. *
  2557. * @devnote We have to do different things for different platforms; NT4.0 has
  2558. * built in support for this functionality.
  2559. */
  2560. /* excerpt from new winuser.h for calls to SystemParametersInfo */
  2561. #ifndef SPI_GETWHEELSCROLLLINES
  2562. #define SPI_GETWHEELSCROLLLINES 104
  2563. #endif
  2564. LONG CW32System::GetRollerLineScrollCount()
  2565. {
  2566. if( _cLineScroll == 0 )
  2567. {
  2568. #ifndef _WIN64
  2569. HKEY hdlKey;
  2570. DWORD keyDataType;
  2571. CHAR charData[128];
  2572. DWORD dwDataBufSize;
  2573. // Fall back Value
  2574. _cLineScroll = 0;
  2575. // Read registry directly for Windows 95 & WinNT3.51, if WinNT 4.0
  2576. // and above then use SystemParametersInfo
  2577. if((OnWin95()) || (_dwPlatformId == VER_PLATFORM_WIN32_NT) && (_dwMajorVersion < 4))
  2578. {
  2579. // Read registry directly
  2580. if ( RegOpenKeyExA(HKEY_CURRENT_USER,
  2581. "Control Panel\\Desktop",
  2582. 0,
  2583. KEY_QUERY_VALUE,
  2584. &hdlKey) == ERROR_SUCCESS )
  2585. {
  2586. dwDataBufSize = sizeof(charData);
  2587. if ( RegQueryValueExA(hdlKey,
  2588. "WheelScrollLines",
  2589. NULL, // reserved
  2590. &keyDataType,
  2591. (LPBYTE) &charData,
  2592. &dwDataBufSize) == ERROR_SUCCESS )
  2593. {
  2594. _cLineScroll = W32->strtoul( charData ); //String representation
  2595. }
  2596. }
  2597. else
  2598. {
  2599. // We didn't find line scroll count in the registery. Check for a Mouse
  2600. // Wheel window and query the window how many lines to scroll
  2601. static UINT idWheelSupport = RegisterWindowMessageA(MSH_WHEELSUPPORT);
  2602. static UINT idScrollLine = RegisterWindowMessageA(MSH_SCROLL_LINES);
  2603. HWND hwndMsWheel = FindWindowA(MSH_WHEELMODULE_CLASS, MSH_WHEELMODULE_TITLE);
  2604. if (hwndMsWheel && SendMessageA(hwndMsWheel, idWheelSupport, 0, 0))
  2605. _cLineScroll = SendMessageA(hwndMsWheel, idScrollLine, 0, 0);
  2606. }
  2607. RegCloseKey(hdlKey);
  2608. }
  2609. else if ( (_dwPlatformId == VER_PLATFORM_WIN32_NT) &&
  2610. (_dwMajorVersion >= 4) || OnWin9x())
  2611. #endif //_WIN64
  2612. {
  2613. //call this function if on NT4 or Win98 (NOTE: it isn't sufficient to use
  2614. //OnWin9x() to determine if we are on a win98 system but since the
  2615. //previous if stmt checks to see if we are in a win95 system OnWin9x
  2616. //can be use)
  2617. SystemParametersInfoA(SPI_GETWHEELSCROLLLINES, 0, &_cLineScroll, 0);
  2618. }
  2619. }
  2620. return _cLineScroll;
  2621. }
  2622. //+---------------------------------------------------------------------------
  2623. //
  2624. // Member: CStrIn::CStrIn
  2625. //
  2626. // Synopsis: Inits the class.
  2627. //
  2628. // NOTE: Don't inline these functions or you'll increase code size
  2629. // by pushing -1 on the stack for each call.
  2630. //
  2631. //----------------------------------------------------------------------------
  2632. CStrIn::CStrIn(LPCWSTR pwstr, UINT CodePage)
  2633. {
  2634. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrIn::CStrIn");
  2635. Init(pwstr, -1, CodePage);
  2636. }
  2637. CStrIn::CStrIn(LPCWSTR pwstr, int cwch, UINT CodePage)
  2638. {
  2639. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrIn::CStrIn");
  2640. Init(pwstr, cwch, CodePage);
  2641. }
  2642. //+---------------------------------------------------------------------------
  2643. //
  2644. // Member: CStrIn::Init
  2645. //
  2646. // Synopsis: Converts a LPWSTR function argument to a LPSTR.
  2647. //
  2648. // Arguments: [pwstr] -- The function argument. May be NULL or an atom
  2649. // (HIWORD(pwstr) == 0).
  2650. //
  2651. // [cwch] -- The number of characters in the string to
  2652. // convert. If -1, the string is assumed to be
  2653. // NULL terminated and its length is calculated.
  2654. //
  2655. // Modifies: [this]
  2656. //
  2657. //----------------------------------------------------------------------------
  2658. void
  2659. CStrIn::Init(
  2660. LPCWSTR pwstr,
  2661. int cwch,
  2662. UINT CodePage) //@parm Code page to use (CP_ACP is default)
  2663. {
  2664. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrIn::Init");
  2665. int cchBufReq;
  2666. _cchLen = 0;
  2667. // Check if string is NULL or an atom.
  2668. if (HIWORD((DWORD_PTR)pwstr) == 0)
  2669. {
  2670. _pstr = (LPSTR) pwstr;
  2671. return;
  2672. }
  2673. Assert(cwch == -1 || cwch > 0);
  2674. //
  2675. // Convert string to preallocated buffer, and return if successful.
  2676. //
  2677. _cchLen = W32->MbcsFromUnicode(_ach, ARRAY_SIZE(_ach), pwstr, cwch, CodePage);
  2678. if (_cchLen > 0)
  2679. {
  2680. if(_ach[_cchLen-1] == 0)
  2681. _cchLen--; // account for terminator
  2682. _pstr = _ach;
  2683. return;
  2684. }
  2685. //
  2686. // Alloc space on heap for buffer.
  2687. //
  2688. TRACEINFOSZ("CStrIn: Allocating buffer for wrapped function argument.");
  2689. cchBufReq = WideCharToMultiByte(
  2690. CP_ACP, 0, pwstr, cwch, NULL, 0, NULL, NULL);
  2691. Assert(cchBufReq > 0);
  2692. _pstr = new char[cchBufReq];
  2693. if (!_pstr)
  2694. {
  2695. // On failure, the argument will point to the empty string.
  2696. TRACEINFOSZ("CStrIn: No heap space for wrapped function argument.");
  2697. _ach[0] = 0;
  2698. _pstr = _ach;
  2699. return;
  2700. }
  2701. Assert(HIWORD((DWORD_PTR)_pstr));
  2702. _cchLen = -1 + W32->MbcsFromUnicode(_pstr, cchBufReq, pwstr, cwch);
  2703. Assert(_cchLen >= 0);
  2704. }
  2705. //+---------------------------------------------------------------------------
  2706. //
  2707. // Class: CStrInMulti (CStrIn)
  2708. //
  2709. // Purpose: Converts multiple strings which are terminated by two NULLs,
  2710. // e.g. "Foo\0Bar\0\0"
  2711. //
  2712. //----------------------------------------------------------------------------
  2713. class CStrInMulti : public CStrIn
  2714. {
  2715. public:
  2716. CStrInMulti(LPCWSTR pwstr, UINT CodePage);
  2717. };
  2718. //+---------------------------------------------------------------------------
  2719. //
  2720. // Member: CStrInMulti::CStrInMulti
  2721. //
  2722. // Synopsis: Converts mulitple LPWSTRs to a multiple LPSTRs.
  2723. //
  2724. // Arguments: [pwstr] -- The strings to convert.
  2725. //
  2726. // Modifies: [this]
  2727. //
  2728. //----------------------------------------------------------------------------
  2729. CStrInMulti::CStrInMulti(
  2730. LPCWSTR pwstr,
  2731. UINT CodePage)
  2732. {
  2733. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrInMulti::CStrInMulti");
  2734. LPCWSTR pwstrT;
  2735. // We don't handle atoms because we don't need to.
  2736. Assert(HIWORD((DWORD_PTR)pwstr));
  2737. //
  2738. // Count number of characters to convert.
  2739. //
  2740. pwstrT = pwstr;
  2741. if (pwstr)
  2742. {
  2743. do {
  2744. while (*pwstrT++)
  2745. ;
  2746. } while (*pwstrT++);
  2747. }
  2748. Init(pwstr, pwstrT - pwstr, CodePage);
  2749. }
  2750. //+---------------------------------------------------------------------------
  2751. //
  2752. // Member: CStrOut::CStrOut
  2753. //
  2754. // Synopsis: Allocates enough space for an out buffer.
  2755. //
  2756. // Arguments: [pwstr] -- The Unicode buffer to convert to when destroyed.
  2757. // May be NULL.
  2758. //
  2759. // [cwchBuf] -- The size of the buffer in characters.
  2760. //
  2761. // Modifies: [this].
  2762. //
  2763. //----------------------------------------------------------------------------
  2764. CStrOut::CStrOut(LPWSTR pwstr, int cwchBuf)
  2765. {
  2766. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrOut::CStrOut");
  2767. Assert(cwchBuf >= 0);
  2768. _pwstr = pwstr;
  2769. _cwchBuf = cwchBuf;
  2770. if (!pwstr)
  2771. {
  2772. Assert(cwchBuf == 0);
  2773. _pstr = NULL;
  2774. return;
  2775. }
  2776. Assert(HIWORD((DWORD_PTR)pwstr));
  2777. // Initialize buffer in case Windows API returns an error.
  2778. _ach[0] = 0;
  2779. // Use preallocated buffer if big enough.
  2780. if (cwchBuf * 2 <= ARRAY_SIZE(_ach))
  2781. {
  2782. _pstr = _ach;
  2783. return;
  2784. }
  2785. // Allocate buffer.
  2786. TRACEINFOSZ("CStrOut: Allocating buffer for wrapped function argument.");
  2787. _pstr = new char[cwchBuf * 2];
  2788. if (!_pstr)
  2789. {
  2790. //
  2791. // On failure, the argument will point to a zero-sized buffer initialized
  2792. // to the empty string. This should cause the Windows API to fail.
  2793. //
  2794. TRACEINFOSZ("CStrOut: No heap space for wrapped function argument.");
  2795. Assert(cwchBuf > 0);
  2796. _pwstr[0] = 0;
  2797. _cwchBuf = 0;
  2798. _pstr = _ach;
  2799. return;
  2800. }
  2801. Assert(HIWORD((DWORD_PTR)_pstr));
  2802. _pstr[0] = 0;
  2803. }
  2804. //+---------------------------------------------------------------------------
  2805. //
  2806. // Member: CStrOut::Convert
  2807. //
  2808. // Synopsis: Converts the buffer from MBCS to Unicode.
  2809. //
  2810. //----------------------------------------------------------------------------
  2811. int
  2812. CStrOut::Convert()
  2813. {
  2814. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrOut::Convert");
  2815. int cch;
  2816. if (!_pstr)
  2817. return 0;
  2818. cch = MultiByteToWideChar(CP_ACP, 0, _pstr, -1, _pwstr, _cwchBuf);
  2819. Assert(cch > 0 || _cwchBuf == 0);
  2820. Free();
  2821. if (cch > 0 && cch <= _cwchBuf && _pwstr[cch-1] == L'\0')
  2822. cch--;
  2823. return cch;
  2824. }
  2825. //+---------------------------------------------------------------------------
  2826. //
  2827. // Member: CStrOut::~CStrOut
  2828. //
  2829. // Synopsis: Converts the buffer from MBCS to Unicode.
  2830. //
  2831. // Note: Don't inline this function, or you'll increase code size as
  2832. // both Convert() and CConvertStr::~CConvertStr will be called
  2833. // inline.
  2834. //
  2835. //----------------------------------------------------------------------------
  2836. CStrOut::~CStrOut()
  2837. {
  2838. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrOut::~CStrOut");
  2839. Convert();
  2840. }
  2841. //
  2842. // MultiByte --> UNICODE routins
  2843. //
  2844. //+---------------------------------------------------------------------------
  2845. //
  2846. // Member: CConvertStr::Free
  2847. //
  2848. // Synopsis: Frees string if alloc'd and initializes to NULL.
  2849. //
  2850. //----------------------------------------------------------------------------
  2851. void
  2852. CConvertStr::Free()
  2853. {
  2854. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CConvertStr::Free");
  2855. if (_pstr != _ach && HIWORD((DWORD_PTR)_pstr) != 0)
  2856. {
  2857. delete [] _pstr;
  2858. }
  2859. _pstr = NULL;
  2860. }
  2861. //+---------------------------------------------------------------------------
  2862. //
  2863. // Member: CConvertStrW::Free
  2864. //
  2865. // Synopsis: Frees string if alloc'd and initializes to NULL.
  2866. //
  2867. //----------------------------------------------------------------------------
  2868. void
  2869. CConvertStrW::Free()
  2870. {
  2871. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CConvertStrW::Free");
  2872. if (_pwstr != _awch && HIWORD((DWORD_PTR)_pwstr) != 0 )
  2873. {
  2874. delete [] _pwstr;
  2875. }
  2876. _pwstr = NULL;
  2877. }
  2878. //+---------------------------------------------------------------------------
  2879. //
  2880. // Member: CStrInW::CStrInW
  2881. //
  2882. // Synopsis: Inits the class.
  2883. //
  2884. // NOTE: Don't inline these functions or you'll increase code size
  2885. // by pushing -1 on the stack for each call.
  2886. //
  2887. //----------------------------------------------------------------------------
  2888. CStrInW::CStrInW(LPCSTR pstr)
  2889. {
  2890. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrInW::CStrInW");
  2891. Init(pstr, -1, CP_ACP);
  2892. }
  2893. CStrInW::CStrInW(LPCSTR pstr, UINT uiCodePage)
  2894. {
  2895. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrInW::CStrInW");
  2896. Init(pstr, -1, uiCodePage);
  2897. }
  2898. CStrInW::CStrInW(LPCSTR pstr, int cch, UINT uiCodePage)
  2899. {
  2900. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrInW::CStrInW");
  2901. Init(pstr, cch, uiCodePage);
  2902. }
  2903. //+---------------------------------------------------------------------------
  2904. //
  2905. // Member: CStrInW::Init
  2906. //
  2907. // Synopsis: Converts a LPSTR function argument to a LPWSTR.
  2908. //
  2909. // Arguments: [pstr] -- The function argument. May be NULL or an atom
  2910. // (HIWORD(pwstr) == 0).
  2911. //
  2912. // [cch] -- The number of characters in the string to
  2913. // convert. If -1, the string is assumed to be
  2914. // NULL terminated and its length is calculated.
  2915. //
  2916. // Modifies: [this]
  2917. //
  2918. //----------------------------------------------------------------------------
  2919. void
  2920. CStrInW::Init(LPCSTR pstr, int cch, UINT uiCodePage)
  2921. {
  2922. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrInW::Init");
  2923. int cchBufReq;
  2924. _cwchLen = 0;
  2925. // Check if string is NULL or an atom.
  2926. if (HIWORD((DWORD_PTR)pstr) == 0)
  2927. {
  2928. _pwstr = (LPWSTR) pstr;
  2929. return;
  2930. }
  2931. Assert(cch == -1 || cch > 0);
  2932. //
  2933. // Convert string to preallocated buffer, and return if successful.
  2934. //
  2935. _cwchLen = MultiByteToWideChar(
  2936. uiCodePage, 0, pstr, cch, _awch, ARRAY_SIZE(_awch));
  2937. if (_cwchLen > 0)
  2938. {
  2939. if(_awch[_cwchLen-1] == 0)
  2940. _cwchLen--; // account for terminator
  2941. _pwstr = _awch;
  2942. return;
  2943. }
  2944. //
  2945. // Alloc space on heap for buffer.
  2946. //
  2947. TRACEINFOSZ("CStrInW: Allocating buffer for wrapped function argument.");
  2948. cchBufReq = MultiByteToWideChar(
  2949. CP_ACP, 0, pstr, cch, NULL, 0);
  2950. Assert(cchBufReq > 0);
  2951. _pwstr = new WCHAR[cchBufReq];
  2952. if (!_pwstr)
  2953. {
  2954. // On failure, the argument will point to the empty string.
  2955. TRACEINFOSZ("CStrInW: No heap space for wrapped function argument.");
  2956. _awch[0] = 0;
  2957. _pwstr = _awch;
  2958. return;
  2959. }
  2960. Assert(HIWORD((DWORD_PTR)_pwstr));
  2961. _cwchLen = -1 + MultiByteToWideChar(
  2962. uiCodePage, 0, pstr, cch, _pwstr, cchBufReq);
  2963. Assert(_cwchLen >= 0);
  2964. }
  2965. //+---------------------------------------------------------------------------
  2966. //
  2967. // Member: CStrOutW::CStrOutW
  2968. //
  2969. // Synopsis: Allocates enough space for an out buffer.
  2970. //
  2971. // Arguments: [pstr] -- The ansi buffer to convert to when destroyed.
  2972. // May be NULL.
  2973. //
  2974. // [cchBuf] -- The size of the buffer in characters.
  2975. //
  2976. // Modifies: [this].
  2977. //
  2978. //----------------------------------------------------------------------------
  2979. CStrOutW::CStrOutW(LPSTR pstr, int cchBuf, UINT uiCodePage)
  2980. {
  2981. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrOutW::CStrOutW");
  2982. Assert(cchBuf >= 0);
  2983. _pstr = pstr;
  2984. _cchBuf = cchBuf;
  2985. _uiCodePage = uiCodePage;
  2986. if (!pstr)
  2987. {
  2988. Assert(cchBuf == 0);
  2989. _pwstr = NULL;
  2990. return;
  2991. }
  2992. Assert(HIWORD((DWORD_PTR)pstr));
  2993. // Initialize buffer in case Windows API returns an error.
  2994. _awch[0] = 0;
  2995. // Use preallocated buffer if big enough.
  2996. if (cchBuf <= ARRAY_SIZE(_awch))
  2997. {
  2998. _pwstr = _awch;
  2999. return;
  3000. }
  3001. // Allocate buffer.
  3002. TRACEINFOSZ("CStrOutW: Allocating buffer for wrapped function argument.");
  3003. _pwstr = new WCHAR[cchBuf * 2];
  3004. if (!_pwstr)
  3005. {
  3006. //
  3007. // On failure, the argument will point to a zero-sized buffer initialized
  3008. // to the empty string. This should cause the Windows API to fail.
  3009. //
  3010. TRACEINFOSZ("CStrOutW: No heap space for wrapped function argument.");
  3011. Assert(cchBuf > 0);
  3012. _pstr[0] = 0;
  3013. _cchBuf = 0;
  3014. _pwstr = _awch;
  3015. return;
  3016. }
  3017. Assert(HIWORD((DWORD_PTR)_pwstr));
  3018. _pwstr[0] = 0;
  3019. }
  3020. //+---------------------------------------------------------------------------
  3021. //
  3022. // Member: CStrOutW::Convert
  3023. //
  3024. // Synopsis: Converts the buffer from Unicode to MBCS
  3025. //
  3026. //----------------------------------------------------------------------------
  3027. int
  3028. CStrOutW::Convert()
  3029. {
  3030. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrOutW::Convert");
  3031. int cch;
  3032. if (!_pwstr)
  3033. return 0;
  3034. int cchBuf = _cchBuf;
  3035. cch = W32->MbcsFromUnicode(_pstr, cchBuf, _pwstr, -1, _uiCodePage);
  3036. Free();
  3037. if (cch > 0 && cch <= _cchBuf && _pstr[cch-1] == '\0')
  3038. cch--;
  3039. return cch;
  3040. }
  3041. //+---------------------------------------------------------------------------
  3042. //
  3043. // Member: CStrOutW::~CStrOutW
  3044. //
  3045. // Synopsis: Converts the buffer from Unicode to MBCS.
  3046. //
  3047. // Note: Don't inline this function, or you'll increase code size as
  3048. // both Convert() and CConvertStr::~CConvertStr will be called
  3049. // inline.
  3050. //
  3051. //----------------------------------------------------------------------------
  3052. CStrOutW::~CStrOutW()
  3053. {
  3054. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrOutW::~CStrOutW");
  3055. Convert();
  3056. }
  3057. BOOL CW32System::GetVersion(
  3058. DWORD *pdwPlatformId,
  3059. DWORD *pdwMajorVersion,
  3060. DWORD *pdwMinorVersion
  3061. )
  3062. {
  3063. OSVERSIONINFOA osv;
  3064. osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
  3065. *pdwPlatformId = 0;
  3066. *pdwMajorVersion = 0;
  3067. if (::GetVersionExA(&osv))
  3068. {
  3069. *pdwPlatformId = osv.dwPlatformId;
  3070. *pdwMajorVersion = osv.dwMajorVersion;
  3071. *pdwMinorVersion = osv.dwMinorVersion;
  3072. return TRUE;
  3073. }
  3074. return FALSE;
  3075. }
  3076. BOOL CW32System::GetStringTypes(
  3077. LCID lcid,
  3078. LPCTSTR lpSrcStr,
  3079. int cchSrc,
  3080. LPWORD lpCharType1,
  3081. LPWORD lpCharType3)
  3082. {
  3083. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3084. {
  3085. if(::GetStringTypeExW(lcid, CT_CTYPE1, lpSrcStr, cchSrc, lpCharType1))
  3086. return ::GetStringTypeExW(lcid, CT_CTYPE3, lpSrcStr, cchSrc, lpCharType3);
  3087. return FALSE;
  3088. }
  3089. CStrIn str(lpSrcStr, cchSrc, ConvertLanguageIDtoCodePage(lcid));
  3090. LONG cch = str.strlen();
  3091. if(::GetStringTypeExA(lcid, CT_CTYPE1, str, cch, lpCharType1))
  3092. return ::GetStringTypeExA(lcid, CT_CTYPE3, str, cch, lpCharType3);
  3093. return FALSE;
  3094. }
  3095. BOOL WINAPI CW32System::GetStringTypeEx(
  3096. LCID lcid,
  3097. DWORD dwInfoType,
  3098. LPCTSTR lpSrcStr,
  3099. int cchSrc,
  3100. LPWORD lpCharType
  3101. )
  3102. {
  3103. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "GetStringTypeEx");
  3104. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3105. return ::GetStringTypeExW(lcid, dwInfoType, lpSrcStr, cchSrc, lpCharType);
  3106. CStrIn str(lpSrcStr, cchSrc);
  3107. return GetStringTypeExA(lcid, dwInfoType, str, str.strlen(), lpCharType);
  3108. }
  3109. typedef LPSTR (CALLBACK *FnCharChangeCase)(LPSTR);
  3110. static LPWSTR CharChangeCase(LPWSTR pwstr, FnCharChangeCase pfn)
  3111. {
  3112. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CharChangeCaseWrap");
  3113. if (HIWORD((DWORD_PTR)pwstr) == 0)
  3114. {
  3115. LPSTR pstr=0;
  3116. int retCode;
  3117. char DBChar[3];
  3118. retCode = W32->MbcsFromUnicode((LPSTR) &pstr, sizeof(pstr), (LPWSTR) &pwstr, 1);
  3119. Assert(HIWORD((DWORD_PTR)pstr) == 0);
  3120. if (retCode == 2)
  3121. {
  3122. // This is a DBC, use string
  3123. DWORD iTemp = (DWORD)((DWORD_PTR)pstr);
  3124. DBChar[0] = char(iTemp & 0x0ff);
  3125. DBChar[1] = char(iTemp >> 8);
  3126. DBChar[2] = 0;
  3127. pstr = (*pfn)(DBChar);
  3128. W32->UnicodeFromMbcs((LPWSTR) &pwstr, sizeof(pwstr) / sizeof(WCHAR), (LPSTR)DBChar, 2);
  3129. }
  3130. else
  3131. {
  3132. pstr = (*pfn)(pstr);
  3133. W32->UnicodeFromMbcs((LPWSTR) &pwstr, sizeof(pwstr) / sizeof(WCHAR), (LPSTR) &pstr);
  3134. }
  3135. Assert(HIWORD((DWORD_PTR)pwstr) == 0);
  3136. }
  3137. else
  3138. {
  3139. CStrOut strOut(pwstr, W32->wcslen(pwstr));
  3140. W32->MbcsFromUnicode(strOut, strOut.BufSize(), pwstr);
  3141. (*pfn)(strOut);
  3142. }
  3143. return pwstr;
  3144. }
  3145. LPWSTR WINAPI CW32System::CharLower(LPWSTR pwstr)
  3146. {
  3147. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CharLower");
  3148. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3149. return ::CharLowerW(pwstr);
  3150. return CharChangeCase(pwstr, CharLowerA);
  3151. }
  3152. DWORD WINAPI CW32System::CharLowerBuff(LPWSTR pwstr, DWORD cchLength)
  3153. {
  3154. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CharLowerBuff");
  3155. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3156. return ::CharLowerBuffW(pwstr, cchLength);
  3157. LPWSTR lpBuffer = pwstr;
  3158. for (DWORD pos = 0; pos < cchLength; pos++, lpBuffer++)
  3159. *lpBuffer = (WCHAR)CharChangeCase((LPWSTR)*lpBuffer, CharLowerA);
  3160. return pos;
  3161. }
  3162. DWORD WINAPI CW32System::CharUpperBuff(LPWSTR pwstr, DWORD cchLength)
  3163. {
  3164. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CharUpperBuff");
  3165. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3166. return ::CharUpperBuffW(pwstr, cchLength);
  3167. LPWSTR lpBuffer = pwstr;
  3168. for (DWORD pos = 0; pos < cchLength; pos++, lpBuffer++)
  3169. *lpBuffer = (WCHAR)CharChangeCase((LPWSTR)*lpBuffer, CharUpperA);
  3170. return pos;
  3171. }
  3172. typedef HDC (CALLBACK *FnCreateHDCA)(LPCSTR, LPCSTR, LPCSTR, CONST DEVMODEA *);
  3173. static HDC WINAPI CreateHDCAux(
  3174. LPCWSTR lpszDriver,
  3175. LPCWSTR lpszDevice,
  3176. LPCWSTR lpszOutput,
  3177. CONST DEVMODEW * lpInitData,
  3178. FnCreateHDCA pfn
  3179. )
  3180. {
  3181. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CreateHDCWrap");
  3182. DEVMODEA devmode;
  3183. CStrIn strDriver(lpszDriver);
  3184. CStrIn strDevice(lpszDevice);
  3185. CStrIn strOutput(lpszOutput);
  3186. if ( lpInitData )
  3187. {
  3188. // converting DEVMODEW to DEVMODEA
  3189. int byteCount;
  3190. // copying the data between the two strings members
  3191. byteCount = (char *)&(devmode.dmFormName)
  3192. - (char *)&(devmode.dmSpecVersion);
  3193. memcpy(&(devmode.dmSpecVersion),
  3194. &(lpInitData->dmSpecVersion),
  3195. byteCount);
  3196. // copying the data after the second string member
  3197. byteCount = (char *)((char *)&devmode + sizeof(DEVMODEA))
  3198. - (char *)&(devmode.dmLogPixels);
  3199. memcpy(&(devmode.dmLogPixels),
  3200. &(lpInitData->dmLogPixels),
  3201. byteCount);
  3202. // converting the two strings members
  3203. W32->MbcsFromUnicode((CHAR *)devmode.dmDeviceName, CCHDEVICENAME, lpInitData->dmDeviceName);
  3204. W32->MbcsFromUnicode((CHAR *)devmode.dmFormName, CCHFORMNAME, lpInitData->dmFormName);
  3205. }
  3206. return (*pfn)(strDriver, strDevice, strOutput,
  3207. lpInitData ? &devmode : NULL);
  3208. }
  3209. HDC WINAPI CW32System::CreateIC(
  3210. LPCWSTR lpszDriver,
  3211. LPCWSTR lpszDevice,
  3212. LPCWSTR lpszOutput,
  3213. CONST DEVMODEW * lpInitData)
  3214. {
  3215. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CreateIC");
  3216. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3217. return ::CreateICW( lpszDriver, lpszDevice, lpszOutput, lpInitData );
  3218. return CreateHDCAux(lpszDriver, lpszDevice, lpszOutput, lpInitData, CreateICA);
  3219. }
  3220. HANDLE WINAPI CW32System::CreateFile(
  3221. LPCWSTR lpFileName,
  3222. DWORD dwDesiredAccess,
  3223. DWORD dwShareMode,
  3224. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  3225. DWORD dwCreationDisposition,
  3226. DWORD dwFlagsAndAttributes,
  3227. HANDLE hTemplateFile
  3228. )
  3229. {
  3230. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CreateFile");
  3231. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3232. return ::CreateFileW(lpFileName,
  3233. dwDesiredAccess,
  3234. dwShareMode,
  3235. lpSecurityAttributes,
  3236. dwCreationDisposition,
  3237. dwFlagsAndAttributes,
  3238. hTemplateFile);
  3239. CStrIn str(lpFileName);
  3240. return ::CreateFileA(
  3241. str,
  3242. dwDesiredAccess,
  3243. dwShareMode,
  3244. lpSecurityAttributes,
  3245. dwCreationDisposition,
  3246. dwFlagsAndAttributes,
  3247. hTemplateFile);
  3248. }
  3249. HFONT WINAPI CW32System::CreateFontIndirect(CONST LOGFONTW * plfw)
  3250. {
  3251. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CreateFontIndirect");
  3252. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3253. return ::CreateFontIndirectW(plfw);
  3254. LOGFONTA lfa;
  3255. HFONT hFont;
  3256. memcpy(&lfa, plfw, offsetof(LOGFONTA, lfFaceName));
  3257. MbcsFromUnicode(lfa.lfFaceName, ARRAY_SIZE(lfa.lfFaceName), plfw->lfFaceName,
  3258. -1, CP_ACP, UN_NOOBJECTS);
  3259. hFont = ::CreateFontIndirectA(&lfa);
  3260. return hFont;
  3261. }
  3262. int WINAPI CW32System::CompareString (
  3263. LCID Locale, // locale identifier
  3264. DWORD dwCmpFlags, // comparison-style options
  3265. LPCWSTR lpString1, // pointer to first string
  3266. int cch1, // size, in bytes or characters, of first string
  3267. LPCWSTR lpString2, // pointer to second string
  3268. int cch2 // size, in bytes or characters, of second string
  3269. )
  3270. {
  3271. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CompareString");
  3272. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3273. return ::CompareStringW(Locale, dwCmpFlags, lpString1, cch1, lpString2, cch2);
  3274. CStrIn str1(lpString1, cch1);
  3275. CStrIn str2(lpString2, cch2);
  3276. return CompareStringA(
  3277. Locale,
  3278. dwCmpFlags,
  3279. str1,
  3280. str1.strlen(),
  3281. str2,
  3282. str2.strlen()
  3283. );
  3284. }
  3285. LRESULT WINAPI CW32System::DefWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  3286. {
  3287. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "DefWindowProcWrap");
  3288. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3289. return ::DefWindowProcW(hWnd, msg, wParam, lParam);
  3290. return ::DefWindowProcA(hWnd, msg, wParam, lParam);
  3291. }
  3292. int WINAPI CW32System::GetObject(HGDIOBJ hgdiObj, int cbBuffer, LPVOID lpvObj)
  3293. {
  3294. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "GetObject");
  3295. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3296. return ::GetObjectW( hgdiObj, cbBuffer, lpvObj);
  3297. int nRet;
  3298. if(cbBuffer != sizeof(LOGFONTW) || !lpvObj)
  3299. {
  3300. nRet = ::GetObjectA(hgdiObj, cbBuffer, lpvObj);
  3301. if(nRet == sizeof(LOGFONTA))
  3302. {
  3303. nRet = sizeof(LOGFONTW);
  3304. }
  3305. }
  3306. else
  3307. {
  3308. LOGFONTA lfa;
  3309. nRet = ::GetObjectA(hgdiObj, sizeof(lfa), &lfa);
  3310. if(nRet > 0)
  3311. {
  3312. memcpy(lpvObj, &lfa, offsetof(LOGFONTW, lfFaceName));
  3313. UnicodeFromMbcs(((LOGFONTW*)lpvObj)->lfFaceName, ARRAY_SIZE(((LOGFONTW*)lpvObj)->lfFaceName),
  3314. lfa.lfFaceName, -1);
  3315. nRet = sizeof(LOGFONTW);
  3316. }
  3317. }
  3318. return nRet;
  3319. }
  3320. DWORD APIENTRY CW32System::GetProfileSection(
  3321. LPCWSTR lpAppName,
  3322. LPWSTR lpReturnedString,
  3323. DWORD nSize
  3324. )
  3325. {
  3326. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "GetProfileSection");
  3327. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3328. return ::GetProfileSectionW( lpAppName, lpReturnedString, nSize );
  3329. CStrIn strAppName(lpAppName);
  3330. // we can't use CStrOut here, since the returned string contains a set of
  3331. // strings delimited by single-NULL's and terminated by a double-NULL
  3332. char *pszReturnedString;
  3333. pszReturnedString = new char[nSize];
  3334. Assert(pszReturnedString);
  3335. DWORD cch = ::GetProfileSectionA(strAppName, pszReturnedString, nSize);
  3336. if(cch)
  3337. {
  3338. cch = MultiByteToWideChar(CP_ACP, 0, pszReturnedString, cch,
  3339. lpReturnedString, nSize);
  3340. }
  3341. delete pszReturnedString;
  3342. return cch;
  3343. }
  3344. BOOL APIENTRY CW32System::GetTextExtentPoint32(
  3345. HDC hdc,
  3346. LPCWSTR pwsz,
  3347. int cb,
  3348. LPSIZE pSize
  3349. )
  3350. {
  3351. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "GetTextExtentPoint32");
  3352. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3353. return ::GetTextExtentPoint32W( hdc, pwsz, cb, pSize );
  3354. CStrIn str(pwsz);
  3355. return ::GetTextExtentPoint32A(hdc, str, cb, pSize);
  3356. }
  3357. int WINAPI CW32System::GetTextFace(
  3358. HDC hdc,
  3359. int cch,
  3360. LPWSTR lpFaceName
  3361. )
  3362. {
  3363. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "GetTextFace");
  3364. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3365. return ::GetTextFaceW( hdc, cch, lpFaceName );
  3366. CStrOut str(lpFaceName, cch);
  3367. ::GetTextFaceA(hdc, str.BufSize(), str);
  3368. return str.Convert();
  3369. }
  3370. BOOL WINAPI CW32System::GetTextMetrics(HDC hdc, LPTEXTMETRICW lptm)
  3371. {
  3372. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "GetTextMetrics");
  3373. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3374. return ::GetTextMetricsW( hdc, lptm);
  3375. BOOL ret;
  3376. TEXTMETRICA tm;
  3377. ret = ::GetTextMetricsA(hdc, &tm);
  3378. if (ret)
  3379. {
  3380. lptm->tmHeight = tm.tmHeight;
  3381. lptm->tmAscent = tm.tmAscent;
  3382. lptm->tmDescent = tm.tmDescent;
  3383. lptm->tmInternalLeading = tm.tmInternalLeading;
  3384. lptm->tmExternalLeading = tm.tmExternalLeading;
  3385. lptm->tmAveCharWidth = tm.tmAveCharWidth;
  3386. lptm->tmMaxCharWidth = tm.tmMaxCharWidth;
  3387. lptm->tmWeight = tm.tmWeight;
  3388. lptm->tmOverhang = tm.tmOverhang;
  3389. lptm->tmDigitizedAspectX = tm.tmDigitizedAspectX;
  3390. lptm->tmDigitizedAspectY = tm.tmDigitizedAspectY;
  3391. lptm->tmItalic = tm.tmItalic;
  3392. lptm->tmUnderlined = tm.tmUnderlined;
  3393. lptm->tmStruckOut = tm.tmStruckOut;
  3394. lptm->tmPitchAndFamily = tm.tmPitchAndFamily;
  3395. lptm->tmCharSet = tm.tmCharSet;
  3396. UnicodeFromMbcs(&lptm->tmFirstChar, 1, (LPSTR) &tm.tmFirstChar, 1);
  3397. UnicodeFromMbcs(&lptm->tmLastChar, 1, (LPSTR) &tm.tmLastChar, 1);
  3398. UnicodeFromMbcs(&lptm->tmDefaultChar, 1, (LPSTR) &tm.tmDefaultChar, 1);
  3399. UnicodeFromMbcs(&lptm->tmBreakChar, 1, (LPSTR) &tm.tmBreakChar, 1);
  3400. }
  3401. return ret;
  3402. }
  3403. LONG WINAPI CW32System::GetWindowLong(HWND hWnd, int nIndex)
  3404. {
  3405. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "GetWindowLong");
  3406. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3407. return ::GetWindowLongW(hWnd, nIndex);
  3408. return ::GetWindowLongA(hWnd, nIndex);
  3409. }
  3410. LONG_PTR WINAPI CW32System::GetWindowLongPtr(HWND hWnd, int nIndex)
  3411. {
  3412. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "GetWindowLongPtr");
  3413. #ifdef _WIN64
  3414. return GetWindowLongPtrW(hWnd, nIndex);
  3415. #else
  3416. return GetWindowLong(hWnd, nIndex);
  3417. #endif
  3418. }
  3419. DWORD WINAPI CW32System::GetClassLong(HWND hWnd, int nIndex)
  3420. {
  3421. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "GetClassLong");
  3422. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3423. return ::GetClassLongW(hWnd, nIndex);
  3424. return ::GetClassLongA(hWnd, nIndex);
  3425. }
  3426. HBITMAP WINAPI CW32System::LoadBitmap(HINSTANCE hInstance, LPCWSTR lpBitmapName)
  3427. {
  3428. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "LoadBitmap");
  3429. Assert(HIWORD((DWORD_PTR)lpBitmapName) == 0);
  3430. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3431. return ::LoadBitmapW(hInstance, lpBitmapName);
  3432. return ::LoadBitmapA(hInstance, (LPCSTR) lpBitmapName);
  3433. }
  3434. HCURSOR WINAPI CW32System::LoadCursor(HINSTANCE hInstance, LPCWSTR lpCursorName)
  3435. {
  3436. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "LoadCursor");
  3437. Assert(HIWORD((DWORD_PTR)lpCursorName) == 0);
  3438. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3439. return ::LoadCursorW(hInstance, lpCursorName);
  3440. return ::LoadCursorA(hInstance, (LPCSTR) lpCursorName);
  3441. }
  3442. HINSTANCE WINAPI CW32System::LoadLibrary(LPCWSTR lpLibFileName)
  3443. {
  3444. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "LoadLibrary");
  3445. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3446. return ::LoadLibraryW(lpLibFileName);
  3447. CStrIn str(lpLibFileName);
  3448. return ::LoadLibraryA(str);
  3449. }
  3450. LRESULT WINAPI CW32System::SendMessage(
  3451. HWND hWnd,
  3452. UINT Msg,
  3453. WPARAM wParam,
  3454. LPARAM lParam
  3455. )
  3456. {
  3457. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "SendMessage");
  3458. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId && ::IsWindowUnicode(hWnd))
  3459. return ::SendMessageW(hWnd, Msg, wParam, lParam);
  3460. // We never need Ansi to Unicode translation in our use of SendMessage
  3461. // Our list boxes always use Unicode.
  3462. switch (Msg)
  3463. {
  3464. // We don't want to translate these!
  3465. // case LB_ADDSTRING:
  3466. // case LB_INSERTSTRING:
  3467. // case CB_ADDSTRING:
  3468. // case CB_SELECTSTRING:
  3469. // case CB_INSERTSTRING:
  3470. // case LB_GETTEXT:
  3471. // case CB_GETLBTEXT:
  3472. case WM_GETTEXT:
  3473. {
  3474. CStrOut str((LPWSTR)lParam, (int)wParam);
  3475. ::SendMessageA(hWnd, Msg, str.BufSize(), (LPARAM)(LPSTR)str);
  3476. return str.Convert();
  3477. }
  3478. break;
  3479. case WM_SETTEXT:
  3480. case EM_REPLACESEL:
  3481. Assert(FALSE); // We never send these. Dead code?
  3482. break;
  3483. case EM_SETPASSWORDCHAR:
  3484. Assert(FALSE); // We never send these. Dead code?
  3485. break;
  3486. }
  3487. return ::SendMessageA(hWnd, Msg, wParam, lParam);
  3488. }
  3489. LONG WINAPI CW32System::SetWindowLong(HWND hWnd, int nIndex, LONG dwNewLong)
  3490. {
  3491. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "SetWindowLong");
  3492. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3493. return ::SetWindowLongW(hWnd, nIndex, dwNewLong);
  3494. return ::SetWindowLongA(hWnd, nIndex, dwNewLong);
  3495. }
  3496. LONG WINAPI CW32System::SetWindowLongPtr(HWND hWnd, int nIndex, LONG_PTR dwNewLong)
  3497. {
  3498. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "SetWindowLongPtr");
  3499. #ifdef _WIN64
  3500. return ::SetWindowLongPtrW(hWnd, nIndex, dwNewLong);
  3501. #else
  3502. return SetWindowLong(hWnd, nIndex, dwNewLong);
  3503. #endif
  3504. }
  3505. BOOL WINAPI CW32System::PostMessage(
  3506. HWND hWnd,
  3507. UINT Msg,
  3508. WPARAM wParam,
  3509. LPARAM lParam
  3510. )
  3511. {
  3512. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "PostMessage");
  3513. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3514. return ::PostMessageW(hWnd, Msg, wParam, lParam);
  3515. return ::PostMessageA(hWnd, Msg, wParam, lParam);
  3516. }
  3517. BOOL WINAPI CW32System::UnregisterClass(LPCWSTR lpClassName, HINSTANCE hInstance)
  3518. {
  3519. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "UnregisterClass");
  3520. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3521. return ::UnregisterClassW( lpClassName, hInstance);
  3522. CStrIn str(lpClassName);
  3523. return ::UnregisterClassA(str, hInstance);
  3524. }
  3525. int WINAPI CW32System::lstrcmp(LPCWSTR lpString1, LPCWSTR lpString2)
  3526. {
  3527. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "lstrcmp");
  3528. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3529. return ::lstrcmpW(lpString1, lpString2);
  3530. return W32->wcscmp(lpString1, lpString2);
  3531. }
  3532. int WINAPI CW32System::lstrcmpi(LPCWSTR lpString1, LPCWSTR lpString2)
  3533. {
  3534. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "lstrcmpi");
  3535. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3536. return ::lstrcmpiW(lpString1, lpString2);
  3537. // Fall back on the simple minded CRT algortihm
  3538. // The CRT actually has two paths. This is the simple one
  3539. const wchar_t * dst = lpString1;
  3540. const wchar_t * src = lpString2;
  3541. wchar_t f,l;
  3542. do {
  3543. f = ((*dst <= L'Z') && (*dst >= L'A'))
  3544. ? *dst + L'a' - L'A'
  3545. : *dst;
  3546. l = ((*src <= L'Z') && (*src >= L'A'))
  3547. ? *src + L'a' - L'A'
  3548. : *src;
  3549. dst++;
  3550. src++;
  3551. } while ( (f) && (f == l) );
  3552. return (int)(f - l);
  3553. }
  3554. BOOL WINAPI CW32System::PeekMessage(
  3555. LPMSG lpMsg,
  3556. HWND hWnd,
  3557. UINT wMsgFilterMin,
  3558. UINT wMsgFilterMax,
  3559. UINT wRemoveMsg
  3560. )
  3561. {
  3562. TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "PeekMessage");
  3563. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3564. return ::PeekMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
  3565. return ::PeekMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
  3566. }
  3567. DWORD WINAPI CW32System::GetModuleFileName(
  3568. HMODULE hModule,
  3569. LPWSTR lpFilename,
  3570. DWORD nSize
  3571. )
  3572. {
  3573. if (VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId)
  3574. return ::GetModuleFileNameW(hModule, lpFilename, nSize);
  3575. CStrOut strout(lpFilename, nSize);
  3576. DWORD res = ::GetModuleFileNameA(hModule, strout, nSize);
  3577. strout.Convert();
  3578. return res;
  3579. }
  3580. // The high bits of _yHeightUI & _yHeightOther are being used to check if
  3581. // font is installed in the system
  3582. #define NEED_TO_CHECK_FONT 0x080
  3583. struct PreferredFontInfo
  3584. {
  3585. BYTE _bPitchAndFamilyUI;
  3586. BYTE _yHeightUI;
  3587. SHORT _iFontUI;
  3588. BYTE _bPitchAndFamilyOther;
  3589. BYTE _yHeightOther;
  3590. SHORT _iFontOther;
  3591. };
  3592. PreferredFontInfo g_pfinfo[NCHARSETS];
  3593. void CW32System::InitPreferredFontInfo()
  3594. {
  3595. // For UI case, we will use Word9 UI fonts
  3596. // For Non-UI case, we will use Word9 default email fonts
  3597. short iFont;
  3598. UINT uSysDefCodePage = GetSystemDefaultCodePage();
  3599. // Japanese Init
  3600. static const WCHAR lpUIJapanFontName[] = L"MS UI Gothic";
  3601. static const WCHAR lpOthJapanFontName[]
  3602. = {0xFF2D,0xFF33,0x0020,0xFF30,0x30B4,0x30B7,0x30C3,0x30AF, 0};
  3603. static const WCHAR lpOthJapanFontNameEUC[] = L"MS PGothic";
  3604. iFont = GetFontNameIndex( lpUIJapanFontName );
  3605. SetPreferredFontInfo( CP_JAPAN, true, iFont, 9 | NEED_TO_CHECK_FONT, 17 );
  3606. if (uSysDefCodePage == CP_JAPAN)
  3607. iFont = GetFontNameIndex( lpOthJapanFontName );
  3608. else
  3609. iFont = GetFontNameIndex( lpOthJapanFontNameEUC );
  3610. SetPreferredFontInfo( CP_JAPAN, false, iFont, 10 | NEED_TO_CHECK_FONT, 17 );
  3611. // Korean Init
  3612. static const WCHAR lpUIKoreanFontName[] = {0xAD74, 0xB9BC, 0};
  3613. static const WCHAR lpUIKoreanFontNameEUC[] = L"Gulim";
  3614. if (uSysDefCodePage == CP_KOREAN)
  3615. iFont = GetFontNameIndex( lpUIKoreanFontName );
  3616. else
  3617. iFont = GetFontNameIndex( lpUIKoreanFontNameEUC );
  3618. SetPreferredFontInfo( CP_KOREAN, true, iFont, 9 | NEED_TO_CHECK_FONT, 49 );
  3619. SetPreferredFontInfo( CP_KOREAN, false, iFont, 9 | NEED_TO_CHECK_FONT, 49 );
  3620. // Traditional Chinese Init
  3621. static const WCHAR lpUITChineseFontName[] = {0x65B0, 0x7D30, 0x660E, 0x9AD4, 0};
  3622. static const WCHAR lpUITChineseFontNameEUC[] = L"PMingLiU";
  3623. iFont = GetFontNameIndex(uSysDefCodePage == CP_CHINESE_TRAD
  3624. ? lpUITChineseFontName : lpUITChineseFontNameEUC);
  3625. SetPreferredFontInfo( CP_CHINESE_TRAD, true, iFont, 9 | NEED_TO_CHECK_FONT, 54 );
  3626. SetPreferredFontInfo( CP_CHINESE_TRAD, false, iFont, 9 | NEED_TO_CHECK_FONT, 54 );
  3627. // Simplified Chinese Init
  3628. static const WCHAR lpUISChineseFontName[] = {0x5B8B, 0x4F53, 0};
  3629. static const WCHAR lpUISChineseFontNameEUC[] = L"SimSun";
  3630. iFont = GetFontNameIndex(uSysDefCodePage == CP_CHINESE_SIM
  3631. ? lpUISChineseFontName : lpUISChineseFontNameEUC);
  3632. SetPreferredFontInfo( CP_CHINESE_SIM, true, iFont, 9 | NEED_TO_CHECK_FONT, 54 );
  3633. SetPreferredFontInfo( CP_CHINESE_SIM, false, iFont, 10 | NEED_TO_CHECK_FONT, 54 );
  3634. // English Init
  3635. iFont = GetFontNameIndex( szTahoma );
  3636. SetPreferredFontInfo(1252, true, iFont, 8, DEFAULT_PITCH | FF_SWISS );
  3637. iFont = GetFontNameIndex( szArial );
  3638. SetPreferredFontInfo(1252, false, iFont, 10, DEFAULT_PITCH | FF_SWISS );
  3639. // SYMBOL_CHARSET
  3640. iFont = GetFontNameIndex( szWingdings );
  3641. SetPreferredFontInfo(CP_SYMBOL, true, iFont, 8, DEFAULT_PITCH | FF_DONTCARE);
  3642. SetPreferredFontInfo(CP_SYMBOL, false, iFont, 10, DEFAULT_PITCH | FF_DONTCARE);
  3643. // Vietnamese Init
  3644. iFont = GetFontNameIndex( szTahoma );
  3645. SetPreferredFontInfo(1258, true, iFont, 8, DEFAULT_PITCH | FF_SWISS );
  3646. iFont = GetFontNameIndex( szArial );
  3647. SetPreferredFontInfo(1258, false, iFont, 10, DEFAULT_PITCH | FF_SWISS );
  3648. // Thai Init
  3649. if (OnWinNT5())
  3650. iFont = GetFontNameIndex( szMicrosSansSerif );
  3651. else
  3652. iFont = GetFontNameIndex( szTahoma );
  3653. SetPreferredFontInfo(874, true, iFont, 8, DEFAULT_PITCH | FF_SWISS );
  3654. iFont = GetFontNameIndex( szCordiaNew );
  3655. SetPreferredFontInfo(874, false, iFont, 14, DEFAULT_PITCH | FF_SWISS );
  3656. // Devanagari Init
  3657. iFont = GetFontNameIndex( szMangal );
  3658. SetPreferredFontInfo(CP_DEVANAGARI, true, iFont, 8, DEFAULT_PITCH | FF_SWISS );
  3659. SetPreferredFontInfo(CP_DEVANAGARI, false, iFont, 10, DEFAULT_PITCH | FF_SWISS );
  3660. // Tamil Init
  3661. iFont = GetFontNameIndex( szLatha );
  3662. SetPreferredFontInfo(CP_TAMIL, true, iFont, 8, DEFAULT_PITCH | FF_SWISS );
  3663. SetPreferredFontInfo(CP_TAMIL, false, iFont, 10, DEFAULT_PITCH | FF_SWISS );
  3664. // Georgian and Armenian Init
  3665. if(OnWinNT5())
  3666. {
  3667. iFont = GetFontNameIndex(szArialUnicode);
  3668. SetPreferredFontInfo(CP_GEORGIAN, true, iFont, 8, DEFAULT_PITCH | FF_SWISS);
  3669. SetPreferredFontInfo(CP_GEORGIAN, false, iFont, 10, DEFAULT_PITCH | FF_SWISS);
  3670. SetPreferredFontInfo(CP_ARMENIAN, true, iFont, 8, DEFAULT_PITCH | FF_SWISS);
  3671. SetPreferredFontInfo(CP_ARMENIAN, false, iFont, 10, DEFAULT_PITCH | FF_SWISS);
  3672. }
  3673. _fFEFontInfo = FEDATA_NOT_INIT;
  3674. // Check installed keyboard layouts
  3675. CheckInstalledKeyboards();
  3676. }
  3677. void CW32System::CheckInstalledKeyboards()
  3678. {
  3679. HKL rghkl[MAX_HKLS];
  3680. INT cLayouts = ::GetKeyboardLayoutList(MAX_HKLS, rghkl);
  3681. LONG cpg;
  3682. INT iScript;
  3683. for(INT i = 0; i < cLayouts; i++)
  3684. {
  3685. cpg = ConvertLanguageIDtoCodePage(PRIMARYLANGID(rghkl[i]));
  3686. GetCharSet(cpg, &iScript); // Get script index
  3687. if(iScript >= 0)
  3688. SetPreferredKbd(iScript, rghkl[i]);
  3689. }
  3690. }
  3691. bool CW32System::SetPreferredFontInfo(
  3692. int cpg,
  3693. bool fUIFont,
  3694. SHORT iFont,
  3695. BYTE yHeight,
  3696. BYTE bPitchAndFamily
  3697. )
  3698. {
  3699. int iPFI;
  3700. CLock lock;
  3701. GetCharSet( cpg, &iPFI );
  3702. if (iPFI == -1)
  3703. return false;
  3704. if (fUIFont)
  3705. {
  3706. g_pfinfo[iPFI]._bPitchAndFamilyUI = bPitchAndFamily;
  3707. g_pfinfo[iPFI]._yHeightUI = yHeight;
  3708. g_pfinfo[iPFI]._iFontUI = iFont;
  3709. }
  3710. else
  3711. {
  3712. g_pfinfo[iPFI]._bPitchAndFamilyOther = bPitchAndFamily;
  3713. g_pfinfo[iPFI]._yHeightOther = yHeight;
  3714. g_pfinfo[iPFI]._iFontOther = iFont;
  3715. }
  3716. SetFontLegitimateSize(iFont, fUIFont, yHeight & ~NEED_TO_CHECK_FONT, cpg);
  3717. return true;
  3718. }
  3719. bool CW32System::GetPreferredFontInfo(
  3720. int cpg,
  3721. bool fUIFont,
  3722. SHORT& iFont,
  3723. BYTE& yHeight,
  3724. BYTE& bPitchAndFamily
  3725. )
  3726. {
  3727. int iPFI;
  3728. if (GetCharSet( cpg, &iPFI ) && (iPFI == -1))
  3729. return false;
  3730. if (g_pfinfo[iPFI]._iFontUI == 0)
  3731. {
  3732. /* No entry. Try default */
  3733. iPFI = 0;
  3734. }
  3735. if (fUIFont)
  3736. {
  3737. bPitchAndFamily = g_pfinfo[iPFI]._bPitchAndFamilyUI;
  3738. yHeight = g_pfinfo[iPFI]._yHeightUI;
  3739. iFont = g_pfinfo[iPFI]._iFontUI;
  3740. }
  3741. else
  3742. {
  3743. bPitchAndFamily = g_pfinfo[iPFI]._bPitchAndFamilyOther;
  3744. yHeight = g_pfinfo[iPFI]._yHeightOther;
  3745. iFont = g_pfinfo[iPFI]._iFontOther;
  3746. }
  3747. if (yHeight & NEED_TO_CHECK_FONT)
  3748. {
  3749. // Check if the preferred font is installed in the system.
  3750. CLock lock;
  3751. HDC hDC = GetScreenDC();
  3752. // Turn off the checkfont bit
  3753. yHeight &= ~NEED_TO_CHECK_FONT;
  3754. if (fUIFont)
  3755. g_pfinfo[iPFI]._yHeightUI &= ~NEED_TO_CHECK_FONT;
  3756. else
  3757. g_pfinfo[iPFI]._yHeightOther &= ~NEED_TO_CHECK_FONT;
  3758. if (hDC)
  3759. {
  3760. const short *pFontIndex = fUIFont ? &g_pfinfo[iPFI]._iFontUI : &g_pfinfo[iPFI]._iFontOther;
  3761. if (IsFontAvail( hDC, cpg, fUIFont, (short *)pFontIndex))
  3762. iFont = *pFontIndex;
  3763. }
  3764. }
  3765. return true;
  3766. }
  3767. /*
  3768. * CW32System::GetPreferredFontHeight(
  3769. * bool fUIFont,
  3770. * BYTE bOrgCharSet,
  3771. * BYTE bNewCharSet,
  3772. * SHORT yOrgHeight)
  3773. *
  3774. *
  3775. * @mfunc
  3776. * called when we need the default font size when changing from one charset to another.
  3777. *
  3778. * @rdesc
  3779. * The preferred default font size in TWIP if the Original height is same as the
  3780. * original charset default font size. Otherwise, it will return the Original height.
  3781. *
  3782. */
  3783. SHORT CW32System::GetPreferredFontHeight(
  3784. bool fUIFont,
  3785. BYTE bOrgCharSet,
  3786. BYTE bNewCharSet,
  3787. SHORT yOrgHeight
  3788. )
  3789. {
  3790. BYTE yOrgPreferredHeight;
  3791. LONG idxOrgFont = ScriptIndexFromCharSet(bOrgCharSet);
  3792. LONG idxNewFont = ScriptIndexFromCharSet(bNewCharSet);
  3793. // No entry, forget it
  3794. if (idxOrgFont == -1 || idxNewFont == -1)
  3795. return yOrgHeight;
  3796. yOrgPreferredHeight = fUIFont ?
  3797. g_pfinfo[idxOrgFont]._yHeightUI : g_pfinfo[idxOrgFont]._yHeightOther;
  3798. // Get New Preferred Height
  3799. if (yOrgPreferredHeight && yOrgPreferredHeight == yOrgHeight/TWIPS_PER_POINT)
  3800. {
  3801. BYTE yNewHeight = (fUIFont ?
  3802. g_pfinfo[idxNewFont]._yHeightUI : g_pfinfo[idxNewFont]._yHeightOther);
  3803. if (yNewHeight)
  3804. return yNewHeight * TWIPS_PER_POINT;
  3805. }
  3806. return yOrgHeight;
  3807. }
  3808. /*
  3809. * CW32System::CheckInstalledFEFonts()
  3810. *
  3811. *
  3812. * @mfunc
  3813. * called when building FE fonts installed and User default LCID info
  3814. *
  3815. * @devnote
  3816. * This information is necessary when we want to classify Chinese characters
  3817. * and Full-width characters.
  3818. *
  3819. */
  3820. void CW32System::CheckInstalledFEFonts()
  3821. {
  3822. UINT uUserCodepage;
  3823. CLock cLock;
  3824. HDC hDC = GetScreenDC();
  3825. _fFEFontInfo = 0;
  3826. uUserCodepage = ConvertLanguageIDtoCodePage(::GetUserDefaultLCID());
  3827. if (!IsFECodePage(uUserCodepage))
  3828. uUserCodepage = GetACP();
  3829. switch (uUserCodepage)
  3830. {
  3831. case CP_JAPAN:
  3832. _fFEFontInfo |= (FEUSER_LCID | FEUSER_CP_JPN | JPN_FONT_AVAILABLE);
  3833. break;
  3834. case CP_KOREAN:
  3835. _fFEFontInfo |= (FEUSER_LCID | FEUSER_CP_KOR | KOR_FONT_AVAILABLE);
  3836. break;
  3837. case CP_CHINESE_TRAD:
  3838. _fFEFontInfo |= (FEUSER_LCID | FEUSER_CP_BIG5 | BIG5_FONT_AVAILABLE);
  3839. break;
  3840. case CP_CHINESE_SIM:
  3841. _fFEFontInfo |= (FEUSER_LCID | FEUSER_CP_GB | GB_FONT_AVAILABLE);
  3842. break;
  3843. }
  3844. if (hDC)
  3845. {
  3846. if (!(_fFEFontInfo & JPN_FONT_AVAILABLE) && IsFontAvail(hDC, CP_JAPAN))
  3847. _fFEFontInfo |= JPN_FONT_AVAILABLE;
  3848. if (!(_fFEFontInfo & KOR_FONT_AVAILABLE) && IsFontAvail(hDC, CP_KOREAN))
  3849. _fFEFontInfo |= KOR_FONT_AVAILABLE;
  3850. if (!(_fFEFontInfo & BIG5_FONT_AVAILABLE) && IsFontAvail(hDC, CP_CHINESE_TRAD))
  3851. _fFEFontInfo |= BIG5_FONT_AVAILABLE;
  3852. if (!(_fFEFontInfo & GB_FONT_AVAILABLE) && IsFontAvail(hDC, CP_CHINESE_SIM))
  3853. _fFEFontInfo |= GB_FONT_AVAILABLE;
  3854. }
  3855. }
  3856. /*
  3857. * CW32System::IsFEFontInSystem( cpg )
  3858. *
  3859. *
  3860. * @mfunc
  3861. * check if there is any FE font installed for the given codepage
  3862. *
  3863. * @devnote
  3864. * This information is necessary when we want to classify Chinese characters
  3865. * and Full-width characters.
  3866. *
  3867. */
  3868. bool CW32System::IsFEFontInSystem(int cpg)
  3869. {
  3870. int fFontExist = 0;
  3871. if (_fFEFontInfo == FEDATA_NOT_INIT)
  3872. {
  3873. CLock Lock;
  3874. // Look for FE fonts in the system
  3875. CheckInstalledFEFonts();
  3876. }
  3877. // Check if font for the codepage is in the system
  3878. switch (cpg)
  3879. {
  3880. case CP_JAPAN:
  3881. fFontExist = _fFEFontInfo & JPN_FONT_AVAILABLE;
  3882. break;
  3883. case CP_KOREAN:
  3884. fFontExist = _fFEFontInfo & KOR_FONT_AVAILABLE;
  3885. break;
  3886. case CP_CHINESE_TRAD:
  3887. fFontExist = _fFEFontInfo & BIG5_FONT_AVAILABLE;
  3888. break;
  3889. case CP_CHINESE_SIM:
  3890. fFontExist = _fFEFontInfo & GB_FONT_AVAILABLE;
  3891. break;
  3892. }
  3893. return (fFontExist != 0);
  3894. }
  3895. /*
  3896. * CW32System::IsFontAvail( HDC hDC, int cpg, bool fUIFont, short *piFontIndex )
  3897. *
  3898. *
  3899. * @mfunc
  3900. * called when checking if a font (UI or non-UI) is installed for a given codepage
  3901. *
  3902. * @devnote
  3903. * We will try to create the font and verify the charset of the font
  3904. * actually created. If the fontname index is supplied, we will check
  3905. * if the requested font is installed. If the name from GDI is different,
  3906. * the GDI font index will be returned in piFontIndex.
  3907. *
  3908. * @rdesc
  3909. * true if a font that supports the given codepage is available.
  3910. */
  3911. bool CW32System::IsFontAvail(
  3912. HDC hDC, //@parm Screen hDC
  3913. int cpg, //@parm cpg
  3914. bool fUIFont, //@parm UI font?
  3915. short *piFontIndex) //@parm Font Name Index (default = NULL)
  3916. {
  3917. LOGFONTW lf;
  3918. HFONT hfont;
  3919. bool retCode = false;
  3920. int iPFI;
  3921. BYTE bCharSet;
  3922. if ((bCharSet = GetCharSet(cpg, &iPFI)) && (iPFI == -1))
  3923. return false;
  3924. ZeroMemory(&lf, sizeof(lf));
  3925. // We want GDI to find a font that will support this charset
  3926. // Unspecified entries in LOGFONT will be either default or don't care.
  3927. lf.lfCharSet = bCharSet;
  3928. if (fUIFont)
  3929. {
  3930. lf.lfHeight = g_pfinfo[iPFI]._yHeightUI;
  3931. lf.lfPitchAndFamily = g_pfinfo[iPFI]._bPitchAndFamilyUI;
  3932. wcscpy(lf.lfFaceName, GetFontName((LONG)(g_pfinfo[iPFI]._iFontUI)));
  3933. }
  3934. else
  3935. {
  3936. lf.lfHeight = g_pfinfo[iPFI]._yHeightOther;
  3937. lf.lfPitchAndFamily = g_pfinfo[iPFI]._bPitchAndFamilyOther;
  3938. wcscpy(lf.lfFaceName, GetFontName((LONG)(g_pfinfo[iPFI]._iFontOther)));
  3939. }
  3940. hfont = CreateFontIndirect(&lf);
  3941. if(hfont)
  3942. {
  3943. TEXTMETRIC tm;
  3944. HFONT hfontOld = SelectFont(hDC, hfont);
  3945. if (GetTextMetrics(hDC, &tm) && tm.tmCharSet == bCharSet)
  3946. {
  3947. retCode = true;
  3948. if (piFontIndex)
  3949. {
  3950. const WCHAR *pszFontName = GetFontName(*piFontIndex);
  3951. if (pszFontName)
  3952. {
  3953. WCHAR szNewFaceName[LF_FACESIZE];
  3954. // Check if GDI gives us the same font name
  3955. szNewFaceName[0] = L'\0';
  3956. GetTextFace(hDC, LF_FACESIZE, szNewFaceName);
  3957. if (szNewFaceName[0] && wcsicmp(pszFontName, szNewFaceName))
  3958. *piFontIndex = GetFontNameIndex(szNewFaceName); // Different name
  3959. }
  3960. }
  3961. }
  3962. SelectFont(hDC, hfontOld);
  3963. DeleteObject(hfont);
  3964. }
  3965. return retCode;
  3966. }
  3967. /*
  3968. * CW32System::GetFEFontInfo( void )
  3969. *
  3970. *
  3971. * @mfunc
  3972. * called when classifying Chinese characters and Full-width characters
  3973. *
  3974. * @devnote
  3975. * Chinese characters and Full-width characters can be in any
  3976. * of the four FE codepages. We want to classfy them according to the
  3977. * User default LCID and which FE fonts are installed in the system.
  3978. *
  3979. * @rdesc
  3980. * Codepage for the character.
  3981. */
  3982. UINT CW32System::GetFEFontInfo()
  3983. {
  3984. int iDefUserCodepage = -1;
  3985. if (_fFEFontInfo == FEDATA_NOT_INIT)
  3986. {
  3987. CLock Lock;
  3988. // Check if FE fonts are available in the system
  3989. CheckInstalledFEFonts();
  3990. }
  3991. if (_fFEFontInfo & FEUSER_LCID)
  3992. iDefUserCodepage = (_fFEFontInfo & FEUSER_CODEPAGE);
  3993. if (iDefUserCodepage == FEUSER_CP_BIG5)
  3994. return CP_CHINESE_TRAD;
  3995. if (iDefUserCodepage == FEUSER_CP_GB)
  3996. return CP_CHINESE_SIM;
  3997. if (iDefUserCodepage == FEUSER_CP_JPN)
  3998. return CP_JAPAN;
  3999. if (iDefUserCodepage == FEUSER_CP_KOR)
  4000. return CP_KOREAN;
  4001. // Check which font is available and return the corresponding codepage
  4002. // We check for Simplified Chinese first since it contains more Chinese
  4003. // characters than Traditional Chinese.
  4004. if (_fFEFontInfo & GB_FONT_AVAILABLE)
  4005. return CP_CHINESE_SIM;
  4006. if (_fFEFontInfo & BIG5_FONT_AVAILABLE)
  4007. return CP_CHINESE_TRAD;
  4008. if (_fFEFontInfo & JPN_FONT_AVAILABLE)
  4009. return CP_JAPAN;
  4010. if (_fFEFontInfo & KOR_FONT_AVAILABLE)
  4011. return CP_KOREAN;
  4012. return CP_CHINESE_SIM; // Well, no FE font, tough luck.
  4013. }
  4014. /*
  4015. * CW32System::IsDiacriticOrKashida(ch, wC3Type)
  4016. *
  4017. * @mfunc
  4018. * Return TRUE if ch or wC3Type reveals that ch is a nonspacing
  4019. * diacritic or a kashida. Because Win9x GetStringTypeExW isn't
  4020. * implemented, we use range checks for Win9x.
  4021. *
  4022. * @rdesc
  4023. * True if ch or wC3Type reveals that ch is a nonspacing diacritic
  4024. */
  4025. BOOL CW32System::IsDiacriticOrKashida(
  4026. WCHAR ch, //@parm On Win9x, check ranges for ch
  4027. WORD wC3Type) //@parm On WinNT, use C3-type check
  4028. {
  4029. if(VER_PLATFORM_WIN32_WINDOWS != _dwPlatformId && wC3Type)
  4030. return wC3Type & (C3_DIACRITIC | C3_NONSPACING | C3_VOWELMARK | C3_KASHIDA);
  4031. if(!IN_RANGE(0x300, ch, 0xe50)) // Combining diacritics of interest
  4032. return FALSE; // fall in this range
  4033. return IN_RANGE(0x300, ch, 0x36F) || IsDiacritic(ch) || IsBiDiKashida(ch);
  4034. }
  4035. /*
  4036. * CW32System::IsDiacritic(ch)
  4037. *
  4038. * @mfunc
  4039. * Return TRUE if ch falls in BiDi, Thai, Devanagari or Tamil diacritic range.
  4040. */
  4041. BOOL CW32System::IsDiacritic(
  4042. WCHAR ch)
  4043. {
  4044. // BiDi
  4045. if (IsBiDiDiacritic(ch))
  4046. return TRUE;
  4047. // Thai
  4048. if (IN_RANGE(0xe31, ch, 0xe4e))
  4049. return IN_RANGE(0x0e47, ch, 0x0e4e) || IN_RANGE(0x0e34, ch, 0x0e3a) || ch == 0x0e31;
  4050. // Devanagari
  4051. if (IN_RANGE(0x0902, ch, 0x0963))
  4052. return IN_RANGE(0x0941, ch, 0x0948) || IN_RANGE(0x0951, ch, 0x0954) || ch == 0x094d ||
  4053. IN_RANGE(0x0962, ch, 0x0963) || IN_RANGE(0x0901, ch, 0x0902) || ch == 0x093c;
  4054. // Tamil
  4055. if (IN_RANGE(0x0b82, ch, 0x0bcd))
  4056. return ch == 0x0bcd || ch == 0x0bc0 || ch == 0x0b82;
  4057. return FALSE;
  4058. }