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.

380 lines
9.0 KiB

  1. /****************************************************************************
  2. TOOLBAR.CPP : Cicero Toolbar button management class
  3. History:
  4. 24-JAN-2000 CSLim Created
  5. ****************************************************************************/
  6. #include "private.h"
  7. #include "globals.h"
  8. #include "korimx.h"
  9. #include "cmode.h"
  10. #include "fmode.h"
  11. #include "hjmode.h"
  12. #include "skbdmode.h"
  13. #include "pad.h"
  14. #include "immxutil.h"
  15. #include "helpers.h"
  16. #include "toolbar.h"
  17. #include "userex.h"
  18. /*---------------------------------------------------------------------------
  19. CToolBar::CToolBar
  20. Ctor
  21. ---------------------------------------------------------------------------*/
  22. CToolBar::CToolBar(CKorIMX* pImx)
  23. {
  24. m_pimx = pImx;
  25. m_pic = NULL;
  26. m_pCMode = NULL;
  27. m_pFMode = NULL;
  28. m_pHJMode = NULL;
  29. m_pSkbdMode = NULL;
  30. #if !defined(_WIN64)
  31. m_pPad = NULL;
  32. #endif
  33. m_fFocus = fFalse;
  34. }
  35. /*---------------------------------------------------------------------------
  36. CToolBar::~CToolBar
  37. Dtor
  38. ---------------------------------------------------------------------------*/
  39. CToolBar::~CToolBar()
  40. {
  41. m_pimx = NULL;
  42. SafeReleaseClear(m_pic);
  43. }
  44. /*---------------------------------------------------------------------------
  45. CToolBar::Initialize
  46. Initialize Toolbar buttons. Add to Cic main toolbar.
  47. ---------------------------------------------------------------------------*/
  48. BOOL CToolBar::Initialize()
  49. {
  50. ITfThreadMgr *ptim;
  51. ITfLangBarItemMgr *plbim;
  52. HRESULT hr;
  53. if (m_pimx == NULL)
  54. return fFalse;
  55. ptim = m_pimx->GetTIM();
  56. plbim = NULL;
  57. //////////////////////////////////////////////////////////////////////////
  58. // Get Notify UI mananger(IID_ITfLangBarItemMgr) in current TIM
  59. if (FAILED(hr = GetService(ptim, IID_ITfLangBarItemMgr, (IUnknown **)&plbim)))
  60. return fFalse;
  61. //////////////////////////////////////////////////////////////////////////
  62. // Create Han/Eng toggle button
  63. if (!(m_pCMode = new CMode(this)))
  64. {
  65. hr = E_OUTOFMEMORY;
  66. return fFalse;
  67. }
  68. plbim->AddItem(m_pCMode);
  69. //////////////////////////////////////////////////////////////////////////
  70. // Create Full/Half shape toggle button
  71. if (!(m_pFMode = new FMode(this)))
  72. {
  73. hr = E_OUTOFMEMORY;
  74. return fFalse;
  75. }
  76. plbim->AddItem(m_pFMode);
  77. //////////////////////////////////////////////////////////////////////////
  78. // Create Hanja Conv button
  79. if (!(m_pHJMode = new HJMode(this)))
  80. {
  81. hr = E_OUTOFMEMORY;
  82. return fFalse;
  83. }
  84. plbim->AddItem(m_pHJMode);
  85. //////////////////////////////////////////////////////////////////////////
  86. // Create Soft Keyboard button
  87. if (!(m_pSkbdMode = new CSoftKbdMode(this)))
  88. {
  89. hr = E_OUTOFMEMORY;
  90. return fFalse;
  91. }
  92. plbim->AddItem(m_pSkbdMode);
  93. #if !defined(_WIN64)
  94. //////////////////////////////////////////////////////////////////////////
  95. // Create Soft Keyboard button
  96. if (IsWin64() == fFalse)
  97. {
  98. if ((m_pPad = new CPad(this, m_pimx->GetPadCore())) == NULL)
  99. {
  100. hr = E_OUTOFMEMORY;
  101. return fFalse;
  102. }
  103. plbim->AddItem(m_pPad);
  104. }
  105. #endif
  106. SafeRelease(plbim);
  107. return fTrue;
  108. }
  109. /*---------------------------------------------------------------------------
  110. CToolBar::Terminate
  111. Delete toolbar buttonsfrom Cic main toolbar.
  112. ---------------------------------------------------------------------------*/
  113. void CToolBar::Terminate()
  114. {
  115. ITfThreadMgr *ptim;
  116. ITfLangBarItemMgr *plbim;
  117. HRESULT hr;
  118. if (m_pimx == NULL)
  119. return;
  120. ptim = m_pimx->GetTIM();
  121. plbim = NULL;
  122. if (FAILED(hr = GetService(ptim, IID_ITfLangBarItemMgr, (IUnknown **)&plbim)))
  123. return;
  124. if (m_pCMode)
  125. {
  126. plbim->RemoveItem(m_pCMode);
  127. SafeReleaseClear(m_pCMode);
  128. }
  129. if (m_pFMode)
  130. {
  131. plbim->RemoveItem(m_pFMode);
  132. SafeReleaseClear(m_pFMode);
  133. }
  134. if (m_pHJMode)
  135. {
  136. plbim->RemoveItem(m_pHJMode);
  137. SafeReleaseClear(m_pHJMode);
  138. }
  139. if (m_pSkbdMode)
  140. {
  141. plbim->RemoveItem(m_pSkbdMode);
  142. SafeReleaseClear(m_pSkbdMode);
  143. }
  144. #if !defined(_WIN64)
  145. if (m_pPad)
  146. {
  147. plbim->RemoveItem(m_pPad);
  148. SafeReleaseClear(m_pPad);
  149. }
  150. #endif
  151. SafeRelease(plbim);
  152. }
  153. /*---------------------------------------------------------------------------
  154. CToolBar::SetConversionMode
  155. Foward the call to CKorIMX
  156. ---------------------------------------------------------------------------*/
  157. DWORD CToolBar::SetConversionMode(DWORD dwConvMode)
  158. {
  159. if (m_pimx && m_pic)
  160. return m_pimx->SetConvMode(m_pic, dwConvMode);
  161. return 0;
  162. }
  163. /*---------------------------------------------------------------------------
  164. CToolBar::GetConversionMode
  165. Foward the call to CKorIMX
  166. ---------------------------------------------------------------------------*/
  167. UINT CToolBar::GetConversionMode(ITfContext *pic)
  168. {
  169. if (pic == NULL)
  170. pic = m_pic;
  171. if (m_pimx && pic)
  172. return m_pimx->GetConvMode(pic);
  173. return 0;
  174. }
  175. /*---------------------------------------------------------------------------
  176. CToolBar::IsOn
  177. Foward the call to CKorIMX
  178. ---------------------------------------------------------------------------*/
  179. BOOL CToolBar::IsOn(ITfContext *pic)
  180. {
  181. if (pic == NULL)
  182. pic = m_pic;
  183. if (m_pimx && pic)
  184. return m_pimx->IsOn(pic);
  185. return fFalse;
  186. }
  187. /*---------------------------------------------------------------------------
  188. CToolBar::CheckEnable
  189. ---------------------------------------------------------------------------*/
  190. void CToolBar::CheckEnable()
  191. {
  192. if (m_pic == NULL) // empty or disabled(exclude cand ui)
  193. {
  194. m_pCMode->Enable(fFalse);
  195. m_pFMode->Enable(fFalse);
  196. m_pHJMode->Enable(fFalse);
  197. m_pSkbdMode->Enable(fFalse);
  198. #if !defined(_WIN64)
  199. if (IsWin64() == fFalse)
  200. m_pPad->Enable(fFalse);
  201. #endif
  202. }
  203. else
  204. {
  205. m_pCMode->Enable(fTrue);
  206. m_pFMode->Enable(fTrue);
  207. m_pHJMode->Enable(fTrue);
  208. m_pSkbdMode->Enable(fTrue);
  209. #if !defined(_WIN64)
  210. if (IsWin64() == fFalse)
  211. m_pPad->Enable(fTrue);
  212. #endif
  213. }
  214. }
  215. /*---------------------------------------------------------------------------
  216. CToolBar::SetUIFocus
  217. ---------------------------------------------------------------------------*/
  218. void CToolBar::SetUIFocus(BOOL fFocus)
  219. {
  220. if (m_fFocus == fFocus) // same as previous state
  221. return;
  222. m_fFocus = fFocus;
  223. // notify the latest focus to IMEPad
  224. if (m_pimx && m_pimx->GetPadCore())
  225. {
  226. m_pimx->GetPadCore()->SetFocus(fFocus);
  227. }
  228. if (fFocus)
  229. Update(UPDTTB_ALL, fTrue);
  230. }
  231. /*---------------------------------------------------------------------------
  232. CToolBar::SetCurrentIC
  233. ---------------------------------------------------------------------------*/
  234. void CToolBar::SetCurrentIC(ITfContext* pic)
  235. {
  236. SafeReleaseClear(m_pic);
  237. m_pic = pic;
  238. if (m_pic)
  239. {
  240. m_pic->AddRef();
  241. }
  242. if (m_pimx == NULL)
  243. return;
  244. CheckEnable(); // enable or disable context
  245. // changed context - update all toolbar buttons
  246. Update(UPDTTB_ALL, fTrue);
  247. }
  248. /*---------------------------------------------------------------------------
  249. CToolBar::SetOnOff
  250. Foward the call to CKorIMX
  251. ---------------------------------------------------------------------------*/
  252. BOOL CToolBar::SetOnOff(BOOL fOn)
  253. {
  254. if (m_pimx && m_pic)
  255. {
  256. m_pimx->SetOnOff(m_pic, fOn);
  257. return fOn;
  258. }
  259. return fFalse;
  260. }
  261. /*---------------------------------------------------------------------------
  262. CToolBar::GetOwnerWnd
  263. Foward the call to CKorIMX
  264. ---------------------------------------------------------------------------*/
  265. HWND CToolBar::GetOwnerWnd(ITfContext *pic)
  266. {
  267. if (pic == NULL)
  268. {
  269. pic = m_pic;
  270. }
  271. if (m_pimx && pic)
  272. return m_pimx->GetOwnerWnd();
  273. return 0;
  274. }
  275. /*---------------------------------------------------------------------------
  276. CToolBar::GetIPoint
  277. ---------------------------------------------------------------------------*/
  278. IImeIPoint1* CToolBar::GetIPoint(ITfContext *pic)
  279. {
  280. if (pic == NULL )
  281. {
  282. pic = m_pic;
  283. }
  284. if (m_pimx && pic)
  285. {
  286. return m_pimx->GetIPoint(pic);
  287. }
  288. return NULL;
  289. }
  290. /*---------------------------------------------------------------------------
  291. CToolBar::GetOwnerWnd
  292. Update buttons. dwUpdate has update bits corresponding each button.
  293. ---------------------------------------------------------------------------*/
  294. BOOL CToolBar::Update(DWORD dwUpdate, BOOL fRefresh)
  295. {
  296. DWORD dwFlag = TF_LBI_BTNALL;
  297. if (fRefresh)
  298. dwFlag |= TF_LBI_STATUS;
  299. if ((dwUpdate & UPDTTB_CMODE) && m_pCMode && m_pCMode->GetSink())
  300. m_pCMode->GetSink()->OnUpdate(dwFlag);
  301. if ((dwUpdate & UPDTTB_FHMODE) && m_pFMode && m_pFMode->GetSink())
  302. m_pFMode->GetSink()->OnUpdate(dwFlag);
  303. if ((dwUpdate & UPDTTB_HJMODE) && m_pHJMode && m_pHJMode->GetSink())
  304. m_pHJMode->GetSink()->OnUpdate(dwFlag);
  305. if ((dwUpdate & UPDTTB_SKDMODE) && m_pSkbdMode && m_pSkbdMode->GetSink())
  306. m_pSkbdMode->GetSink()->OnUpdate(dwFlag);
  307. #if !defined(_WIN64)
  308. if ((IsWin64() == fFalse) && (dwUpdate & UPDTTB_SKDMODE) && m_pPad && m_pPad->GetSink())
  309. m_pPad->GetSink()->OnUpdate(dwFlag);
  310. #endif
  311. return fTrue;
  312. }