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.

410 lines
11 KiB

  1. /****************************************************************************
  2. TOOLBAR.CPP : Cicero Toolbar button management class
  3. History:
  4. 24-JAN-2000 CSLim Created
  5. ****************************************************************************/
  6. #include "precomp.h"
  7. #include "common.h"
  8. #include "cicero.h"
  9. #include "cmode.h"
  10. #include "fmode.h"
  11. #include "hjmode.h"
  12. #include "pmode.h"
  13. #include "toolbar.h"
  14. #include "ui.h"
  15. #include "syshelp.h"
  16. #include "winex.h"
  17. /*---------------------------------------------------------------------------
  18. CToolBar::CToolBar
  19. Ctor
  20. ---------------------------------------------------------------------------*/
  21. CToolBar::CToolBar()
  22. {
  23. m_fToolbarInited = fFalse;
  24. m_pImeCtx = NULL;
  25. m_pCMode = NULL;
  26. m_pFMode = NULL;
  27. m_pHJMode = NULL;
  28. #if !defined(_WIN64)
  29. m_pPMode = NULL;
  30. #endif
  31. m_pSysHelp = NULL;
  32. }
  33. /*---------------------------------------------------------------------------
  34. CToolBar::~CToolBar
  35. Dtor
  36. ---------------------------------------------------------------------------*/
  37. CToolBar::~CToolBar()
  38. {
  39. m_pImeCtx = NULL;
  40. }
  41. /*---------------------------------------------------------------------------
  42. CToolBar::Initialize
  43. Initialize Toolbar buttons. Add to Cic main toolbar.
  44. ---------------------------------------------------------------------------*/
  45. BOOL CToolBar::Initialize()
  46. {
  47. ITfLangBarMgr *pLMgr = NULL;
  48. ITfLangBarItemMgr *pLItemMgr = NULL;
  49. DWORD dwThread = 0;
  50. HRESULT hr;
  51. if (IsCicero() == fFalse)
  52. return fFalse; // do nothing
  53. if (m_fToolbarInited) // already made it
  54. return fTrue; // do nothing
  55. // initialization
  56. if (FAILED(Cicero_CreateLangBarMgr(&pLMgr)))
  57. return fFalse; // error to create a object
  58. // Get Lang bar manager
  59. if (FAILED(pLMgr->GetThreadLangBarItemMgr(GetCurrentThreadId(), &pLItemMgr, &dwThread)))
  60. {
  61. pLMgr->Release();
  62. DbgAssert(0);
  63. return fFalse; // error to create a object
  64. }
  65. // no need it.
  66. pLMgr->Release();
  67. //////////////////////////////////////////////////////////////////////////
  68. // Create Han/Eng toggle button
  69. if (!(m_pCMode = new CMode(this)))
  70. {
  71. hr = E_OUTOFMEMORY;
  72. return fFalse;
  73. }
  74. pLItemMgr->AddItem(m_pCMode);
  75. //////////////////////////////////////////////////////////////////////////
  76. // Create Full/Half shape toggle button
  77. if (!(m_pFMode = new FMode(this)))
  78. {
  79. hr = E_OUTOFMEMORY;
  80. return fFalse;
  81. }
  82. pLItemMgr->AddItem(m_pFMode);
  83. //////////////////////////////////////////////////////////////////////////
  84. // Create Hanja Conv button
  85. if (!(m_pHJMode = new HJMode(this)))
  86. {
  87. hr = E_OUTOFMEMORY;
  88. return fFalse;
  89. }
  90. pLItemMgr->AddItem(m_pHJMode);
  91. #if !defined(_WIN64)
  92. //////////////////////////////////////////////////////////////////////////
  93. // Create IME Pad button
  94. if (IsWin64() == fFalse)
  95. {
  96. if (!(m_pPMode = new PMode(this)))
  97. {
  98. hr = E_OUTOFMEMORY;
  99. return fFalse;
  100. }
  101. pLItemMgr->AddItem(m_pPMode);
  102. }
  103. #endif
  104. // Update all button
  105. CheckEnable();
  106. m_pCMode->UpdateButton();
  107. m_pFMode->UpdateButton();
  108. m_pHJMode->UpdateButton();
  109. #if !defined(_WIN64)
  110. if (IsWin64() == fFalse)
  111. m_pPMode->UpdateButton();
  112. #endif
  113. // SYSHelp support
  114. m_pSysHelp = new CSysHelpSink(SysInitMenu, OnSysMenuSelect, (VOID*)this);
  115. if (m_pSysHelp && pLItemMgr)
  116. m_pSysHelp->_Advise(pLItemMgr, GUID_LBI_HELP);
  117. m_fToolbarInited = fTrue;
  118. return fTrue;
  119. }
  120. /*---------------------------------------------------------------------------
  121. CToolBar::CheckEnable
  122. ---------------------------------------------------------------------------*/
  123. void CToolBar::CheckEnable()
  124. {
  125. if (m_pCMode == NULL || m_pFMode == NULL || m_pHJMode == NULL)
  126. return;
  127. #if !defined(_WIN64)
  128. if ((IsWin64() == fFalse) && m_pPMode == NULL)
  129. return;
  130. #endif
  131. if (m_pImeCtx == NULL) // empty or disabled(exclude cand ui)
  132. {
  133. m_pCMode->Enable(fFalse);
  134. m_pFMode->Enable(fFalse);
  135. m_pHJMode->Enable(fFalse);
  136. #if !defined(_WIN64)
  137. if (IsWin64() == fFalse)
  138. m_pPMode->Enable(fFalse);
  139. #endif
  140. }
  141. else
  142. {
  143. m_pCMode->Enable(fTrue);
  144. m_pFMode->Enable(fTrue);
  145. m_pHJMode->Enable(fTrue);
  146. #if !defined(_WIN64)
  147. if (IsWin64() == fFalse)
  148. m_pPMode->Enable(fTrue);
  149. #endif
  150. }
  151. }
  152. /*---------------------------------------------------------------------------
  153. CToolBar::SetCurrentIC
  154. ---------------------------------------------------------------------------*/
  155. void CToolBar::SetCurrentIC(PCIMECtx pImeCtx)
  156. {
  157. m_pImeCtx = pImeCtx;
  158. CheckEnable(); // enable or disable context
  159. // changed context - update all toolbar buttons
  160. Update(UPDTTB_ALL, fTrue);
  161. }
  162. /*---------------------------------------------------------------------------
  163. CToolBar::Terminate
  164. Delete toolbar buttonsfrom Cic main toolbar.
  165. ---------------------------------------------------------------------------*/
  166. void CToolBar::Terminate()
  167. {
  168. ITfLangBarMgr *pLMgr = NULL;
  169. ITfLangBarItemMgr *pLItemMgr = NULL;
  170. DWORD dwThread = 0;
  171. if (IsCicero() && m_fToolbarInited)
  172. {
  173. // initialization
  174. if (FAILED(Cicero_CreateLangBarMgr(&pLMgr)))
  175. return; // error to create a object
  176. if (FAILED(pLMgr->GetThreadLangBarItemMgr(GetCurrentThreadId(), &pLItemMgr, &dwThread)))
  177. {
  178. pLMgr->Release();
  179. DbgAssert(0);
  180. return; // error to create a object
  181. }
  182. // no need it.
  183. pLMgr->Release();
  184. #if !defined(_WIN64)
  185. if (m_pPMode && (IsWin64() == fFalse))
  186. {
  187. pLItemMgr->RemoveItem(m_pPMode);
  188. SafeReleaseClear(m_pPMode);
  189. }
  190. #endif
  191. if (m_pHJMode)
  192. {
  193. pLItemMgr->RemoveItem(m_pHJMode);
  194. SafeReleaseClear(m_pHJMode);
  195. }
  196. if (m_pFMode)
  197. {
  198. pLItemMgr->RemoveItem(m_pFMode);
  199. SafeReleaseClear(m_pFMode);
  200. }
  201. if (m_pCMode)
  202. {
  203. pLItemMgr->RemoveItem(m_pCMode);
  204. SafeReleaseClear(m_pCMode);
  205. }
  206. // Release Syshelp
  207. if (m_pSysHelp)
  208. {
  209. m_pSysHelp->_Unadvise(pLItemMgr);
  210. SafeReleaseClear(m_pSysHelp);
  211. }
  212. pLItemMgr->Release();
  213. //Toolbar uninited.
  214. m_fToolbarInited = fFalse;
  215. }
  216. }
  217. /*---------------------------------------------------------------------------
  218. CToolBar::SetConversionMode
  219. Foward the call to CKorIMX
  220. ---------------------------------------------------------------------------*/
  221. DWORD CToolBar::SetConversionMode(DWORD dwConvMode)
  222. {
  223. if (m_pImeCtx)
  224. return m_pImeCtx->SetConversionMode(dwConvMode);
  225. return 0;
  226. }
  227. /*---------------------------------------------------------------------------
  228. CToolBar::GetConversionMode
  229. Foward the call to CKorIMX
  230. ---------------------------------------------------------------------------*/
  231. DWORD CToolBar::GetConversionMode(PCIMECtx pImeCtx)
  232. {
  233. if (pImeCtx == NULL)
  234. pImeCtx = m_pImeCtx;
  235. if (pImeCtx)
  236. return pImeCtx->GetConversionMode();
  237. return 0;
  238. }
  239. /*---------------------------------------------------------------------------
  240. CToolBar::IsOn
  241. Foward the call to CKorIMX
  242. ---------------------------------------------------------------------------*/
  243. BOOL CToolBar::IsOn(PCIMECtx pImeCtx)
  244. {
  245. if (pImeCtx == NULL)
  246. pImeCtx = m_pImeCtx;
  247. if (pImeCtx)
  248. return pImeCtx->IsOpen();
  249. return fFalse;
  250. }
  251. /*---------------------------------------------------------------------------
  252. CToolBar::SetOnOff
  253. Foward the call to CKorIMX
  254. ---------------------------------------------------------------------------*/
  255. BOOL CToolBar::SetOnOff(BOOL fOn)
  256. {
  257. if (m_pImeCtx)
  258. {
  259. m_pImeCtx->SetOpen(fOn);
  260. return fOn;
  261. }
  262. return fFalse;
  263. }
  264. /*---------------------------------------------------------------------------
  265. CToolBar::GetOwnerWnd
  266. Foward the call to CKorIMX
  267. ---------------------------------------------------------------------------*/
  268. HWND CToolBar::GetOwnerWnd(PCIMECtx pImeCtx)
  269. {
  270. #if 0
  271. if (pImeCtx == NULL)
  272. pImeCtx = m_pImeCtx;
  273. if (pImeCtx)
  274. return pImeCtx->GetUIWnd();
  275. return 0;
  276. #endif
  277. return GetActiveUIWnd();
  278. }
  279. /*---------------------------------------------------------------------------
  280. CToolBar::GetOwnerWnd
  281. Update buttons. dwUpdate has update bits corresponding each button.
  282. ---------------------------------------------------------------------------*/
  283. BOOL CToolBar::Update(DWORD dwUpdate, BOOL fRefresh)
  284. {
  285. DWORD dwFlag = TF_LBI_BTNALL;
  286. if (!IsCicero())
  287. return fTrue;
  288. if (fRefresh)
  289. dwFlag |= TF_LBI_STATUS;
  290. if ((dwUpdate & UPDTTB_CMODE) && m_pCMode && m_pCMode->GetSink())
  291. m_pCMode->GetSink()->OnUpdate(dwFlag);
  292. if ((dwUpdate & UPDTTB_FHMODE) && m_pFMode && m_pFMode->GetSink())
  293. m_pFMode->GetSink()->OnUpdate(dwFlag);
  294. if ((dwUpdate & UPDTTB_HJMODE) && m_pHJMode && m_pHJMode->GetSink())
  295. m_pHJMode->GetSink()->OnUpdate(dwFlag);
  296. #if !defined(_WIN64)
  297. if ((dwUpdate & UPDTTB_PAD) && m_pPMode && m_pPMode->GetSink())
  298. m_pPMode->GetSink()->OnUpdate(dwFlag);
  299. #endif
  300. return fTrue;
  301. }
  302. /*---------------------------------------------------------------------------
  303. CToolBar::OnSysMenuSelect
  304. Cicero Help menu callback
  305. ---------------------------------------------------------------------------*/
  306. HRESULT CToolBar::OnSysMenuSelect(void *pv, UINT uiCmd)
  307. {
  308. UNREFERENCED_PARAMETER(pv);
  309. UNREFERENCED_PARAMETER(uiCmd);
  310. CHAR szHelpFileName[MAX_PATH];
  311. CHAR szHelpCmd[MAX_PATH];
  312. szHelpFileName[0] = '\0';
  313. // Load Help display name
  314. OurLoadStringA(vpInstData->hInst, IDS_HELP_FILENAME, szHelpFileName, sizeof(szHelpFileName)/sizeof(CHAR));
  315. wsprintf(szHelpCmd, "hh.exe %s", szHelpFileName);
  316. WinExec(szHelpCmd, SW_NORMAL);
  317. return S_OK;
  318. }
  319. /*---------------------------------------------------------------------------
  320. CToolBar::SysInitMenu
  321. Cicero Help menu callback
  322. ---------------------------------------------------------------------------*/
  323. HRESULT CToolBar::SysInitMenu(void *pv, ITfMenu* pMenu)
  324. {
  325. WCHAR szText[MAX_PATH];
  326. HRESULT hr;
  327. szText[0] = L'\0';
  328. if (pv == NULL || pMenu == NULL)
  329. return S_OK;
  330. // Load Help display name
  331. OurLoadStringW(vpInstData->hInst, IDS_HELP_DISPLAYNAME, szText, sizeof(szText)/sizeof(WCHAR));
  332. hr = pMenu->AddMenuItem(UINT(-1), 0,
  333. NULL /*hbmpColor*/, NULL /*hbmpMask*/, szText, lstrlenW(szText), NULL);
  334. return hr;
  335. }