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.

5506 lines
152 KiB

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