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.

724 lines
19 KiB

  1. /****************************************************************************
  2. PAD.CPP
  3. Owner: cslim
  4. Copyright (c) 1997-2001 Microsoft Corporation
  5. IME PAD button and helper functions
  6. History:
  7. 24-OCT-2001 CSLim Ported for Korean TIP
  8. 05-OCT-1999 TakeshiF Created
  9. *****************************************************************************///
  10. #include "private.h"
  11. #include "pad.h"
  12. #include "padcb.h"
  13. #include "globals.h"
  14. #include "nuibase.h"
  15. #include "userex.h"
  16. #include "resource.h"
  17. #define MemAlloc(a) GlobalAllocPtr(GMEM_FIXED, a)
  18. #define MemFree(a) GlobalFreePtr(a)
  19. //
  20. // menu id range
  21. //
  22. #define PADMENUSTART IDR_PAD_FIRST
  23. #define PADMENUEND IDR_PAD_END
  24. // {02D7474B-2EEA-4ebb-927A-779D9A201D02}
  25. static const GUID GUID_LBI_KORIMX_CPAD =
  26. {
  27. 0x2d7474b,
  28. 0x2eea,
  29. 0x4ebb,
  30. { 0x92, 0x7a, 0x77, 0x9d, 0x9a, 0x20, 0x1d, 0x2 }
  31. };
  32. /*---------------------------------------------------------------------------
  33. CPad::CPad
  34. ---------------------------------------------------------------------------*/
  35. CPad::CPad(CToolBar *ptb, CPadCore* pPadCore)
  36. {
  37. WCHAR szText[256];
  38. m_pTb = ptb;
  39. // Set button tooltip
  40. LoadStringExW(g_hInst, IDS_TT_IME_PAD, szText, sizeof(szText)/sizeof(WCHAR));
  41. InitInfo(CLSID_KorIMX,
  42. GUID_LBI_KORIMX_CPAD,
  43. TF_LBI_STYLE_BTN_MENU | TF_LBI_STYLE_SHOWNINTRAY,
  44. 140,
  45. szText);
  46. SetToolTip(szText);
  47. // Set button text
  48. LoadStringExW(g_hInst, IDS_BUTTON_IME_PAD, szText, sizeof(szText)/sizeof(WCHAR));
  49. SetText(szText);
  50. m_pPadCore = pPadCore;
  51. m_ciApplets = 0;
  52. m_pCfg = NULL; // applet list
  53. }
  54. /*---------------------------------------------------------------------------
  55. CPad::~CPad
  56. ---------------------------------------------------------------------------*/
  57. CPad::~CPad()
  58. {
  59. CleanAppletCfg();
  60. }
  61. /*---------------------------------------------------------------------------
  62. CPad::Release
  63. ---------------------------------------------------------------------------*/
  64. STDAPI_(ULONG) CPad::Release()
  65. {
  66. long cr;
  67. cr = --m_cRef;
  68. Assert(cr >= 0);
  69. if (cr == 0)
  70. {
  71. delete this;
  72. }
  73. return cr;
  74. }
  75. /*---------------------------------------------------------------------------
  76. CPad::GetIcon
  77. Get Button face Icon
  78. ---------------------------------------------------------------------------*/
  79. STDAPI CPad::GetIcon(HICON *phIcon)
  80. {
  81. UINT uiIcon = IDI_PAD;
  82. *phIcon = (HICON)LoadImage(g_hInst, MAKEINTRESOURCE(uiIcon), IMAGE_ICON, 16, 16, LR_LOADMAP3DCOLORS);
  83. return S_OK;
  84. }
  85. /*---------------------------------------------------------------------------
  86. CPad::InitMenu
  87. ---------------------------------------------------------------------------*/
  88. STDAPI CPad::InitMenu(ITfMenu *pMenu)
  89. {
  90. CleanAppletCfg();
  91. if (m_pPadCore == NULL)
  92. {
  93. return E_FAIL;
  94. }
  95. m_ciApplets = m_pPadCore->MakeAppletMenu(PADMENUSTART, PADMENUEND, pMenu, &m_pCfg);
  96. if (m_pCfg == NULL || m_ciApplets == 0)
  97. {
  98. return E_FAIL;
  99. }
  100. return S_OK;
  101. }
  102. /*---------------------------------------------------------------------------
  103. CPad::OnMenuSelect
  104. ---------------------------------------------------------------------------*/
  105. STDAPI CPad::OnMenuSelect(UINT uiCmd)
  106. {
  107. ITfContext *pic;
  108. IImeIPoint1 *pIP;
  109. IID iidApplet;
  110. BOOL fLaunch;
  111. if (m_pTb == NULL)
  112. {
  113. return E_FAIL;
  114. }
  115. pic = m_pTb->GetIC();
  116. if (pic == NULL)
  117. {
  118. return S_OK;
  119. }
  120. pIP = m_pTb->GetIPoint(pic);
  121. fLaunch = FALSE;
  122. if (uiCmd >= PADMENUSTART && uiCmd <= PADMENUEND)
  123. {
  124. fLaunch = TRUE;
  125. INT iidIndex = uiCmd - PADMENUSTART;
  126. Assert(m_pCfg != NULL);
  127. CopyMemory(&iidApplet, &(m_pCfg+iidIndex)->iid, sizeof(IID)); // make a copy
  128. }
  129. //
  130. // launch IMEPad with GUID
  131. //
  132. if (fLaunch)
  133. {
  134. m_pPadCore->PadBoot(pIP, &iidApplet);
  135. ShowItem(TRUE);
  136. }
  137. CleanAppletCfg();
  138. #if 0
  139. //
  140. // HW TIP navigation
  141. //
  142. if (uiCmd == IDC_PAD_HW)
  143. {
  144. //
  145. // Invoke HW TIP
  146. //
  147. m_pPadCore->InvokeHWTIP();
  148. //
  149. // show HW TIP
  150. //
  151. SetCompartmentDWORD(m_pTb->GetTIP()->GetTID(), m_pTb->GetTIP()->GetTIM(), GUID_COMPARTMENT_HANDWRITING_OPENCLOSE, 0x01, FALSE);
  152. }
  153. #endif
  154. return S_OK;
  155. }
  156. /*---------------------------------------------------------------------------
  157. CPad::ShowItem
  158. ---------------------------------------------------------------------------*/
  159. void CPad::ShowItem(BOOL fShow)
  160. {
  161. m_pPadCore->ShowPad(fShow);
  162. if (GetSink())
  163. {
  164. GetSink()->OnUpdate(TF_LBI_BTNALL);
  165. }
  166. }
  167. /*---------------------------------------------------------------------------
  168. CPad::Reset
  169. ---------------------------------------------------------------------------*/
  170. void CPad::Reset()
  171. {
  172. CleanAppletCfg();
  173. m_pTb = NULL;
  174. m_pPadCore = NULL;
  175. }
  176. /*---------------------------------------------------------------------------
  177. CPad::CleanAppletCfg
  178. ---------------------------------------------------------------------------*/
  179. void CPad::CleanAppletCfg()
  180. {
  181. if (m_pCfg)
  182. {
  183. //
  184. // release resouced that created by Pad server
  185. //
  186. UINT i;
  187. for (i = 0; i < m_ciApplets; i++)
  188. {
  189. if((m_pCfg+i)->hIcon)
  190. {
  191. ::DestroyIcon((HICON)(m_pCfg+i)->hIcon);
  192. }
  193. }
  194. MemFree(m_pCfg);
  195. m_pCfg = NULL;
  196. }
  197. m_ciApplets = 0; // reset
  198. }
  199. #if 0
  200. //
  201. // HW TIP navigation dialog
  202. //
  203. BOOL __declspec(dllexport) CPad::HWDlgProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  204. {
  205. UNREFERENCED_PARAMETER(lParam);
  206. switch (message){
  207. case WM_INITDIALOG: {
  208. SetMyClass( hDlg, 0, lParam ); // register this
  209. CPad* pPad = (CPad*)lParam;
  210. //
  211. // special menu item for HW TIP
  212. //
  213. HICON hIcon;
  214. BSTR bsz;
  215. if( pPad->m_pPadCore->GetHWInfo( &bsz, &hIcon ) ) {
  216. SysFreeString( bsz );
  217. OurSendMessage( GetDlgItem(hDlg, IDC_PAD_HW), STM_SETICON, (WPARAM)hIcon, (LPARAM)0 );
  218. DestroyIcon( hIcon );
  219. }
  220. return(TRUE);
  221. }
  222. case WM_COMMAND: {
  223. WORD wID = LOWORD(wParam);
  224. if (wID == IDOK || wID == IDCANCEL) {
  225. EndDialog(hDlg,0);
  226. }
  227. return(TRUE);
  228. }
  229. }
  230. return(FALSE);
  231. }
  232. #endif
  233. /*---------------------------------------------------------------------------
  234. CPadCore::CPadCore
  235. ---------------------------------------------------------------------------*/
  236. CPadCore::CPadCore(CKorIMX* pTip)
  237. {
  238. m_pImx = pTip;
  239. //
  240. // Pad callback
  241. //
  242. m_pPadCB = new CPadCB;
  243. if (m_pPadCB)
  244. {
  245. m_pPadCB->Initialize((void *)this);
  246. }
  247. Assert(m_pPadCB != 0);
  248. //
  249. // Pad server
  250. //
  251. HRESULT hr;
  252. hr = CImePadSvrUIM::CreateInstance(g_hInst, //Your IME module's instance handle.
  253. &m_pPadSvr, //CImePadSvrUIM's pointer's pointer
  254. 0, //Reserved. must be zero.
  255. 0); //Reserved. must be zero.
  256. Assert(SUCCEEDED(hr));
  257. m_fShown = FALSE;
  258. }
  259. /*---------------------------------------------------------------------------
  260. CPadCore::~CPadCore
  261. ---------------------------------------------------------------------------*/
  262. CPadCore::~CPadCore()
  263. {
  264. if (m_pPadSvr)
  265. {
  266. m_pPadSvr->Terminate(NULL);
  267. CImePadSvrUIM::DeleteInstance(m_pPadSvr, 0);
  268. m_pPadSvr = NULL;
  269. }
  270. if (m_pPadCB)
  271. {
  272. delete m_pPadCB;
  273. m_pPadCB = NULL;
  274. }
  275. }
  276. /*---------------------------------------------------------------------------
  277. CPadCore::SetIPoint
  278. ---------------------------------------------------------------------------*/
  279. void CPadCore::SetIPoint(IImeIPoint1* pIP)
  280. {
  281. if (m_pPadSvr == NULL)
  282. {
  283. return; // error
  284. }
  285. if (m_pPadSvr)
  286. {
  287. m_pPadSvr->SetIUnkIImeIPoint((IUnknown *)pIP);
  288. }
  289. }
  290. /*---------------------------------------------------------------------------
  291. CPadCore::InitializePad
  292. ---------------------------------------------------------------------------*/
  293. BOOL CPadCore::InitializePad()
  294. {
  295. INT iRet;
  296. if (m_pPadSvr == NULL)
  297. {
  298. return FALSE; // do nothing
  299. }
  300. iRet = m_pPadSvr->Initialize(MAKELANGID(LANG_KOREAN, SUBLANG_DEFAULT), 0, NULL);
  301. if (iRet != 0)
  302. {
  303. return FALSE;
  304. }
  305. //990525:ToshiaK. callback interface pointer is temporary
  306. m_pPadSvr->SetIUnkIImeCallback((IUnknown *)m_pPadCB);
  307. return TRUE;
  308. }
  309. /*---------------------------------------------------------------------------
  310. CPadCore::PadBoot
  311. ---------------------------------------------------------------------------*/
  312. void CPadCore::PadBoot(IImeIPoint1* pIP, IID* piid)
  313. {
  314. if (m_pPadSvr)
  315. {
  316. if (InitializePad())
  317. {
  318. SetIPoint(pIP);
  319. UINT_PTR uiParam = (UINT_PTR)piid;
  320. m_pPadSvr->ActivateApplet(IMEPADACTID_ACTIVATEBYIID, uiParam, NULL, NULL);
  321. }
  322. }
  323. }
  324. #if 0
  325. void CPadCore::PadBoot(IImeIPoint* pIP, UINT uiType)
  326. {
  327. HRESULT hr;
  328. if (pIP == NULL)
  329. {
  330. return;
  331. }
  332. if (m_pPadSvr == NULL)
  333. {
  334. return;
  335. }
  336. InitializePad(); // initialize PAD engine
  337. SetIPoint(pIP);
  338. switch( uiType ) {
  339. case JCONV_C_SKF: {
  340. m_pPadSvr->ShowUI(TRUE);
  341. }
  342. break;
  343. case JCONV_C_SYMBOLPAD: {
  344. m_pPadSvr->ActivateApplet(IMEPADACTID_ACTIVATEBYIID,
  345. (UINT_PTR)&IID_SymbolList, //IPACID_SYMBOLSEARCH,
  346. NULL,
  347. NULL);
  348. }
  349. break;
  350. case JCONV_C_CONVPART: {
  351. IImePhrase* pPhrase;
  352. WCHAR wszCompStr[128];
  353. WCHAR wszTypeStr[128];
  354. INT cwchComp = 127;
  355. INT cwchType = 127;
  356. //
  357. // type str
  358. //
  359. hr = pIP->GetPhrase( IPCURRENTPHRASE, &pPhrase, wszTypeStr, &cwchType );
  360. if( hr!= S_OK ) {
  361. cwchType = 0;
  362. }
  363. if( hr != S_OK ) {
  364. cwchType = 0;
  365. }
  366. wszTypeStr[cwchType] = L'\0';
  367. //
  368. // reading
  369. //
  370. if( pPhrase && cwchType != 0) {
  371. INT iIdx = IMEPCA_CURRENT;
  372. pPhrase->GetPhraseReadingString( &iIdx, wszCompStr, &cwchComp ); // get size
  373. wszCompStr[cwchComp] = L'\0'; // terminator
  374. }
  375. if(IsHiraString(wszCompStr)) {
  376. //for #2808
  377. //for #4824
  378. if(IsKigo(wszCompStr) || IsGaiji(wszCompStr)) {
  379. m_pPadSvr->ActivateApplet(IMEPADACTID_ACTIVATEBYIID,
  380. (UINT_PTR)&IID_SymbolList, //IPACID_SYMBOLSEARCH,
  381. wszTypeStr,
  382. wszCompStr);
  383. }
  384. else {
  385. m_pPadSvr->ActivateApplet(IMEPADACTID_ACTIVATEBYIID,
  386. (UINT_PTR)&IID_RadicalStrokeList, //IPACID_RADICALSEARCH,
  387. wszTypeStr,
  388. wszCompStr);
  389. }
  390. }
  391. else {
  392. m_pPadSvr->ActivateApplet(IMEPADACTID_ACTIVATEBYIID,
  393. (UINT_PTR)&IID_SymbolList, //IPACID_SYMBOLSEARCH,
  394. wszTypeStr,
  395. wszCompStr);
  396. }
  397. }
  398. break;
  399. default:
  400. break;
  401. }
  402. }
  403. #endif
  404. /*---------------------------------------------------------------------------
  405. CPadCore::ShowPad
  406. ---------------------------------------------------------------------------*/
  407. void CPadCore::ShowPad(BOOL fShow)
  408. {
  409. if (m_pPadSvr)
  410. {
  411. m_pPadSvr->ShowUI( fShow );
  412. }
  413. m_fShown = fShow;
  414. }
  415. /*---------------------------------------------------------------------------
  416. CPadCore::IMEPadNotify
  417. Notification callback from IMEPad
  418. ---------------------------------------------------------------------------*/
  419. void CPadCore::IMEPadNotify(BOOL fShown)
  420. {
  421. m_fShown = fShown;
  422. }
  423. /*---------------------------------------------------------------------------
  424. CPadCore::SetFocus
  425. ---------------------------------------------------------------------------*/
  426. void CPadCore::SetFocus(BOOL fFocus)
  427. {
  428. if (m_pPadSvr)
  429. {
  430. m_pPadSvr->Notify(IMEPADNOTIFY_ACTIVATECONTEXT, fFocus, 0);
  431. }
  432. }
  433. #if 0
  434. /*---------------------------------------------------------------------------
  435. CPadCore::GetHWInfo
  436. Get HW category icon stuff
  437. ---------------------------------------------------------------------------*/
  438. BOOL CPadCore::GetHWInfo( BSTR* pbsz, HICON* phIcon )
  439. {
  440. ITfThreadMgr *ptim = m_pImx->GetTIM();
  441. ITfLangBarItemMgr *plbim = NULL;
  442. ITfLangBarItem *pCat;
  443. ITfLangBarItemButton *pCatBtn;
  444. HRESULT hr;
  445. if (IsHWTIP() == FALSE)
  446. {
  447. return FALSE;
  448. }
  449. if (FAILED(hr = GetService(ptim, IID_ITfLangBarItemMgr, (IUnknown **)&plbim)))
  450. {
  451. return FALSE;
  452. }
  453. hr = plbim->GetItem(GUID_TFCAT_TIP_HANDWRITING, &pCat);
  454. if (SUCCEEDED(hr))
  455. {
  456. hr = pCat->QueryInterface(IID_ITfLangBarItemButton, (void **)&pCatBtn);
  457. if (SUCCEEDED(hr))
  458. {
  459. pCatBtn->GetIcon(phIcon);
  460. pCatBtn->GetTooltipString(pbsz);
  461. pCatBtn->Release();
  462. }
  463. pCat->Release();
  464. }
  465. plbim->Release();
  466. return TRUE;
  467. }
  468. #endif
  469. /*---------------------------------------------------------------------------
  470. CPadCore::MakeAppletMenu
  471. ---------------------------------------------------------------------------*/
  472. UINT CPadCore::MakeAppletMenu(UINT uidStart, UINT uidEnd, ITfMenu *pMenu, LPIMEPADAPPLETCONFIG *ppCfg)
  473. {
  474. LPIMEPADAPPLETCONFIG pCfgOrg, pCfgNew = NULL;
  475. int ci, ciApplets;
  476. WCHAR szText[256];
  477. HRESULT hr;
  478. if (m_pImx == NULL)
  479. {
  480. return 0;
  481. }
  482. if (!InitializePad())
  483. {
  484. return 0;
  485. }
  486. pCfgOrg = NULL;
  487. hr = m_pPadSvr->GetAppletConfigList(IMEPADAPPLETCFGMASK_ALL, &ci, &pCfgOrg);
  488. if ((S_OK != hr) || pCfgOrg == NULL)
  489. {
  490. return 0;
  491. }
  492. //
  493. // Copy CoTaskMemAlloced to MemAlloc version
  494. //
  495. pCfgNew = (LPIMEPADAPPLETCONFIG)MemAlloc(ci * sizeof(IMEPADAPPLETCONFIG));
  496. if (pCfgNew == NULL)
  497. {
  498. return 0;
  499. }
  500. CopyMemory(pCfgNew, pCfgOrg, ci*sizeof(IMEPADAPPLETCONFIG));
  501. //
  502. // release if previous data is existing
  503. // pCfgOrg->hIcon should be deleted by client (CPad class)
  504. //
  505. CoTaskMemFree(pCfgOrg);
  506. *ppCfg = pCfgNew;
  507. #if 0
  508. CMenuHelperCic* pcmh = new CMenuHelperCic(g_hInst, m_pImx);
  509. //
  510. // special menu item for HW TIP
  511. //
  512. HICON hIcon;
  513. BSTR bsz;
  514. if (GetHWInfo(&bsz, &hIcon))
  515. {
  516. pcmh->AppendItem(IDC_PAD_HW, MDS_TYPE_ICONDATA|MDS_TYPE_TEXTDATA, (ULONG_PTR)bsz, (ULONG_PTR)hIcon);
  517. SysFreeString(bsz);
  518. DestroyIcon(hIcon);
  519. //
  520. // separator
  521. //
  522. pcmh->AppendItem(MDS_VID_SEPARATOR, 0, (ULONG_PTR)0, (ULONG_PTR)0);
  523. }
  524. #endif
  525. // Add Applet menu
  526. ciApplets = min(ci, (INT)(uidEnd-uidStart));
  527. for (int i = 0; i < ciApplets; i++)
  528. {
  529. LangBarInsertMenu(pMenu, uidStart + i, (pCfgNew+i)->wchTitle, FALSE, (HICON)(pCfgNew+i)->hIcon);
  530. }
  531. // Insert separator
  532. LangBarInsertSeparator(pMenu);
  533. // Insert Cancel
  534. LoadStringExW(g_hInst, IDS_CANCEL, szText, sizeof(szText)/sizeof(WCHAR));
  535. LangBarInsertMenu(pMenu, IDCANCEL, szText);
  536. return ciApplets;
  537. }
  538. #if 0
  539. BOOL CPadCore::IsHWTIP(void)
  540. {
  541. return FALSE;
  542. #ifdef SPEC_CHANGE
  543. HRESULT hr;
  544. CLSID clsidHWTip;
  545. hr = CLSIDFromProgID( TEXT(L"MS.Handwriting.TIP"), &clsidHWTip );
  546. if( FAILED(hr) ) {
  547. return FALSE;
  548. }
  549. GUID guidWritingPad;
  550. hr = CLSIDFromProgID( TEXT(L"MS.Handwriting.WritingPad"), &guidWritingPad );
  551. if( FAILED(hr) ) {
  552. return FALSE;
  553. }
  554. ITfInputProcessorProfiles *pProfile;
  555. hr = CoCreateInstance(CLSID_TF_InputProcessorProfiles, NULL, CLSCTX_INPROC_SERVER, IID_ITfInputProcessorProfiles, (void **) &pProfile);
  556. if (FAILED(hr)) {
  557. return FALSE;
  558. }
  559. //
  560. // enum tips
  561. //
  562. IEnumTfLanguageProfiles* pEnum;
  563. hr = pProfile->EnumLanguageProfiles( CKBDTip::GetLanguage(), &pEnum );
  564. if (FAILED(hr)) {
  565. pProfile->Release();
  566. return S_FALSE;
  567. }
  568. TF_LANGUAGEPROFILE lp;
  569. ULONG ulFetched;
  570. BOOL fExist = FALSE;
  571. while (pEnum->Next(1, &lp, &ulFetched) == S_OK) {
  572. if( IsEqualCLSID( lp.clsid, clsidHWTip ) && IsEqualCLSID( lp.guidProfile, guidWritingPad) ) {
  573. fExist = TRUE;
  574. break;
  575. }
  576. }
  577. pEnum->Release();
  578. pProfile->Release();
  579. return fExist;
  580. #endif // SPEC_CHANGE
  581. }
  582. BOOL CPadCore::InvokeHWTIP(void)
  583. {
  584. if (IsHWTIP() == FALSE)
  585. {
  586. return FALSE;
  587. }
  588. HRESULT hr;
  589. CLSID clsidHWTip;
  590. hr = CLSIDFromProgID( TEXT(L"MS.Handwriting.TIP"), &clsidHWTip);
  591. if( FAILED(hr) ) {
  592. return FALSE;
  593. }
  594. GUID guidWritingPad;
  595. hr = CLSIDFromProgID( TEXT(L"MS.Handwriting.WritingPad"), &guidWritingPad );
  596. if( FAILED(hr) ) {
  597. return FALSE;
  598. }
  599. ITfInputProcessorProfiles *pProfile;
  600. hr = CoCreateInstance(CLSID_TF_InputProcessorProfiles, NULL, CLSCTX_INPROC_SERVER, IID_ITfInputProcessorProfiles, (void **) &pProfile);
  601. if (FAILED(hr)) {
  602. return FALSE;
  603. }
  604. hr = pProfile->ActivateLanguageProfile(clsidHWTip, CKBDTip::GetLanguage(), guidWritingPad);
  605. pProfile->Release();
  606. return (SUCCEEDED(hr) ? TRUE : FALSE);
  607. }
  608. #endif