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.

165 lines
4.3 KiB

  1. /****************************************************************************
  2. HJMODE.CPP : HJMode class managing Hanja button on the Cicero Toolbar
  3. History:
  4. 25-FEB-2000 CSLim Created
  5. ****************************************************************************/
  6. #include "private.h"
  7. #include "globals.h"
  8. #include "common.h"
  9. #include "korimx.h"
  10. #include "hjmode.h"
  11. #include "userex.h"
  12. #include "editcb.h"
  13. #include "immxutil.h"
  14. #include "helpers.h"
  15. #include "resource.h"
  16. // {61F9F0AA-3D61-4077-B177-43E1422D8348}
  17. const GUID GUID_LBI_KORIMX_HJMODE =
  18. {
  19. 0x61f9f0aa,
  20. 0x3d61,
  21. 0x4077,
  22. { 0xb1, 0x77, 0x43, 0xe1, 0x42, 0x2d, 0x83, 0x48 }
  23. };
  24. /*---------------------------------------------------------------------------
  25. HJMode::HJMode
  26. ---------------------------------------------------------------------------*/
  27. HJMode::HJMode(CToolBar *ptb)
  28. {
  29. WCHAR szText[256];
  30. m_pTb = ptb;
  31. // Set Add/Remove text and tootip text
  32. LoadStringExW(g_hInst, IDS_TT_HANJA_CONV, szText, sizeof(szText)/sizeof(WCHAR));
  33. InitInfo(CLSID_KorIMX,
  34. GUID_LBI_KORIMX_HJMODE,
  35. TF_LBI_STYLE_BTN_BUTTON | TF_LBI_STYLE_TEXTCOLORICON,
  36. 120,
  37. szText);
  38. SetToolTip(szText);
  39. // Set button text
  40. LoadStringExW(g_hInst, IDS_BUTTON_HANJA_CONV, szText, sizeof(szText)/sizeof(WCHAR));
  41. SetText(szText);
  42. }
  43. /*---------------------------------------------------------------------------
  44. HJMode::Release
  45. ---------------------------------------------------------------------------*/
  46. STDAPI_(ULONG) HJMode::Release()
  47. {
  48. long cr;
  49. cr = --m_cRef;
  50. Assert(cr >= 0);
  51. if (cr == 0)
  52. {
  53. delete this;
  54. }
  55. return cr;
  56. }
  57. /*---------------------------------------------------------------------------
  58. HJMode::GetIcon
  59. Get Button face Icon
  60. ---------------------------------------------------------------------------*/
  61. STDAPI HJMode::GetIcon(HICON *phIcon)
  62. {
  63. UINT uiIcon;
  64. if (IsHighContrastBlack())
  65. uiIcon = IDI_CMODE_HANJAW;
  66. else
  67. uiIcon = IDI_CMODE_HANJA;
  68. *phIcon = (HICON)LoadImage(g_hInst, MAKEINTRESOURCE(uiIcon), IMAGE_ICON, 16, 16, LR_LOADMAP3DCOLORS);
  69. return S_OK;
  70. }
  71. /*---------------------------------------------------------------------------
  72. HJMode::InitMenu
  73. No need, this is just toggle button
  74. ---------------------------------------------------------------------------*/
  75. STDAPI HJMode::InitMenu(ITfMenu *pMenu)
  76. {
  77. return E_NOTIMPL;
  78. }
  79. /*---------------------------------------------------------------------------
  80. HJMode::OnMenuSelect
  81. No need, this is just toggle button
  82. ---------------------------------------------------------------------------*/
  83. STDAPI HJMode::OnMenuSelect(UINT wID)
  84. {
  85. return E_NOTIMPL;
  86. }
  87. /*---------------------------------------------------------------------------
  88. HJMode::OnLButtonUp
  89. ---------------------------------------------------------------------------*/
  90. HRESULT HJMode::OnLButtonUp(const POINT pt, const RECT* prcArea)
  91. {
  92. CEditSession2 *pes;
  93. ESSTRUCT ess;
  94. ITfDocumentMgr *pdim;
  95. ITfContext *pic;
  96. HRESULT hr;
  97. pdim = m_pTb->m_pimx->GetDIM();
  98. if (pdim == NULL)
  99. {
  100. m_pTb->m_pimx->GetFocusDIM(&pdim);
  101. }
  102. Assert(pdim != NULL);
  103. if (pdim == NULL)
  104. {
  105. return E_FAIL;
  106. }
  107. GetTopIC(pdim, &pic);
  108. Assert(pic != NULL);
  109. if (pic == NULL)
  110. {
  111. return E_FAIL;
  112. }
  113. hr = E_OUTOFMEMORY;
  114. // If CandUI windows is not open, do Hanja conversion
  115. // Otherwise, send VK_ESCAPE to close Cand UI. (Office.net #141147)
  116. if (m_pTb->m_pimx->IsDisabledIC(pic) == fFalse)
  117. {
  118. ESStructInit(&ess, ESCB_HANJA_CONV);
  119. if (pes = new CEditSession2(pic, m_pTb->m_pimx, &ess, CKorIMX::_EditSessionCallback2))
  120. {
  121. pes->Invoke(ES2_READWRITE | ES2_ASYNC, &hr);
  122. pes->Release();
  123. }
  124. }
  125. else if (m_pTb->m_pimx->IsCandidateIC(pic))
  126. {
  127. keybd_event(VK_ESCAPE, 0, 0, 0);
  128. keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
  129. }
  130. SafeRelease(pic);
  131. return S_OK;
  132. }