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.

377 lines
9.6 KiB

  1. //
  2. // langbar.cpp
  3. //
  4. // Language bar ui code.
  5. //
  6. #include "globals.h"
  7. #include "mark.h"
  8. #include "resource.h"
  9. #define MARK_LANGBARITEMSINK_COOKIE 0x0fab0fab
  10. const struct
  11. {
  12. const WCHAR *pchDesc;
  13. void (*pfnHandler)(CMarkTextService *_this);
  14. }
  15. c_rgMenuItems[] =
  16. {
  17. { L"Start/End Composition", CMarkTextService::_Menu_OnComposition },
  18. { L"Set Global Compartment", CMarkTextService::_Menu_OnSetGlobalCompartment },
  19. { L"Set Case Property", CMarkTextService::_Menu_OnSetCaseProperty },
  20. { L"Set Custom Property", CMarkTextService::_Menu_OnSetCustomProperty },
  21. { L"View Case Property", CMarkTextService::_Menu_OnViewCaseProperty },
  22. { L"View Custom Property", CMarkTextService::_Menu_OnViewCustomProperty },
  23. };
  24. class CLangBarItemButton : public ITfLangBarItemButton,
  25. public ITfSource
  26. {
  27. public:
  28. CLangBarItemButton(CMarkTextService *pMark);
  29. ~CLangBarItemButton();
  30. // IUnknown
  31. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  32. STDMETHODIMP_(ULONG) AddRef(void);
  33. STDMETHODIMP_(ULONG) Release(void);
  34. // ITfLangBarItem
  35. STDMETHODIMP GetInfo(TF_LANGBARITEMINFO *pInfo);
  36. STDMETHODIMP GetStatus(DWORD *pdwStatus);
  37. STDMETHODIMP Show(BOOL fShow);
  38. STDMETHODIMP GetTooltipString(BSTR *pbstrToolTip);
  39. // ITfLangBarItemButton
  40. STDMETHODIMP OnClick(TfLBIClick click, POINT pt, const RECT *prcArea);
  41. STDMETHODIMP InitMenu(ITfMenu *pMenu);
  42. STDMETHODIMP OnMenuSelect(UINT wID);
  43. STDMETHODIMP GetIcon(HICON *phIcon);
  44. STDMETHODIMP GetText(BSTR *pbstrText);
  45. // ITfSource
  46. STDMETHODIMP AdviseSink(REFIID riid, IUnknown *punk, DWORD *pdwCookie);
  47. STDMETHODIMP UnadviseSink(DWORD dwCookie);
  48. private:
  49. CMarkTextService *_pMark;
  50. ITfLangBarItemSink *_pLangBarItemSink;
  51. TF_LANGBARITEMINFO _tfLangBarItemInfo;
  52. LONG _cRef;
  53. };
  54. //+---------------------------------------------------------------------------
  55. //
  56. // ctor
  57. //
  58. //----------------------------------------------------------------------------
  59. CLangBarItemButton::CLangBarItemButton(CMarkTextService *pMark)
  60. {
  61. DllAddRef();
  62. _tfLangBarItemInfo.clsidService = c_clsidMarkTextService;
  63. _tfLangBarItemInfo.guidItem = c_guidLangBarItemButton;
  64. _tfLangBarItemInfo.dwStyle = TF_LBI_STYLE_BTN_MENU;
  65. _tfLangBarItemInfo.ulSort = 0;
  66. SafeStringCopy(_tfLangBarItemInfo.szDescription, ARRAYSIZE(_tfLangBarItemInfo.szDescription), LANGBAR_ITEM_DESC);
  67. _pMark = pMark;
  68. _pMark->AddRef();
  69. _pLangBarItemSink = NULL;
  70. _cRef = 1;
  71. }
  72. //+---------------------------------------------------------------------------
  73. //
  74. // dtor
  75. //
  76. //----------------------------------------------------------------------------
  77. CLangBarItemButton::~CLangBarItemButton()
  78. {
  79. DllRelease();
  80. _pMark->Release();
  81. }
  82. //+---------------------------------------------------------------------------
  83. //
  84. // QueryInterface
  85. //
  86. //----------------------------------------------------------------------------
  87. STDAPI CLangBarItemButton::QueryInterface(REFIID riid, void **ppvObj)
  88. {
  89. if (ppvObj == NULL)
  90. return E_INVALIDARG;
  91. *ppvObj = NULL;
  92. if (IsEqualIID(riid, IID_IUnknown) ||
  93. IsEqualIID(riid, IID_ITfLangBarItem) ||
  94. IsEqualIID(riid, IID_ITfLangBarItemButton))
  95. {
  96. *ppvObj = (ITfLangBarItemButton *)this;
  97. }
  98. else if (IsEqualIID(riid, IID_ITfSource))
  99. {
  100. *ppvObj = (ITfSource *)this;
  101. }
  102. if (*ppvObj)
  103. {
  104. AddRef();
  105. return S_OK;
  106. }
  107. return E_NOINTERFACE;
  108. }
  109. //+---------------------------------------------------------------------------
  110. //
  111. // AddRef
  112. //
  113. //----------------------------------------------------------------------------
  114. STDAPI_(ULONG) CLangBarItemButton::AddRef()
  115. {
  116. return ++_cRef;
  117. }
  118. //+---------------------------------------------------------------------------
  119. //
  120. // Release
  121. //
  122. //----------------------------------------------------------------------------
  123. STDAPI_(ULONG) CLangBarItemButton::Release()
  124. {
  125. LONG cr = --_cRef;
  126. assert(_cRef >= 0);
  127. if (_cRef == 0)
  128. {
  129. delete this;
  130. }
  131. return cr;
  132. }
  133. //+---------------------------------------------------------------------------
  134. //
  135. // GetInfo
  136. //
  137. //----------------------------------------------------------------------------
  138. STDAPI CLangBarItemButton::GetInfo(TF_LANGBARITEMINFO *pInfo)
  139. {
  140. *pInfo = _tfLangBarItemInfo;
  141. return S_OK;
  142. }
  143. //+---------------------------------------------------------------------------
  144. //
  145. // GetStatus
  146. //
  147. //----------------------------------------------------------------------------
  148. STDAPI CLangBarItemButton::GetStatus(DWORD *pdwStatus)
  149. {
  150. *pdwStatus = 0;
  151. return S_OK;
  152. }
  153. //+---------------------------------------------------------------------------
  154. //
  155. // Show
  156. //
  157. //----------------------------------------------------------------------------
  158. STDAPI CLangBarItemButton::Show(BOOL fShow)
  159. {
  160. return E_NOTIMPL;
  161. }
  162. //+---------------------------------------------------------------------------
  163. //
  164. // GetTooltipString
  165. //
  166. //----------------------------------------------------------------------------
  167. STDAPI CLangBarItemButton::GetTooltipString(BSTR *pbstrToolTip)
  168. {
  169. *pbstrToolTip = SysAllocString(LANGBAR_ITEM_DESC);
  170. return (*pbstrToolTip == NULL) ? E_OUTOFMEMORY : S_OK;
  171. }
  172. //+---------------------------------------------------------------------------
  173. //
  174. // OnClick
  175. //
  176. //----------------------------------------------------------------------------
  177. STDAPI CLangBarItemButton::OnClick(TfLBIClick click, POINT pt, const RECT *prcArea)
  178. {
  179. return S_OK;
  180. }
  181. //+---------------------------------------------------------------------------
  182. //
  183. // InitMenu
  184. //
  185. //----------------------------------------------------------------------------
  186. STDAPI CLangBarItemButton::InitMenu(ITfMenu *pMenu)
  187. {
  188. int i;
  189. for (i=0; i<ARRAYSIZE(c_rgMenuItems); i++)
  190. {
  191. pMenu->AddMenuItem(i, 0, NULL, NULL, c_rgMenuItems[i].pchDesc, wcslen(c_rgMenuItems[i].pchDesc), NULL);
  192. }
  193. return S_OK;
  194. }
  195. //+---------------------------------------------------------------------------
  196. //
  197. // OnMenuSelect
  198. //
  199. //----------------------------------------------------------------------------
  200. STDAPI CLangBarItemButton::OnMenuSelect(UINT wID)
  201. {
  202. c_rgMenuItems[wID].pfnHandler(_pMark);
  203. return S_OK;
  204. }
  205. //+---------------------------------------------------------------------------
  206. //
  207. // GetIcon
  208. //
  209. //----------------------------------------------------------------------------
  210. STDAPI CLangBarItemButton::GetIcon(HICON *phIcon)
  211. {
  212. *phIcon = (HICON)LoadImage(g_hInst, TEXT("IDI_MARK"), IMAGE_ICON, 16, 16, 0);
  213. return (*phIcon != NULL) ? S_OK : E_FAIL;
  214. }
  215. //+---------------------------------------------------------------------------
  216. //
  217. // GetText
  218. //
  219. //----------------------------------------------------------------------------
  220. STDAPI CLangBarItemButton::GetText(BSTR *pbstrText)
  221. {
  222. *pbstrText = SysAllocString(LANGBAR_ITEM_DESC);
  223. return (*pbstrText == NULL) ? E_OUTOFMEMORY : S_OK;
  224. }
  225. //+---------------------------------------------------------------------------
  226. //
  227. // AdviseSink
  228. //
  229. //----------------------------------------------------------------------------
  230. STDAPI CLangBarItemButton::AdviseSink(REFIID riid, IUnknown *punk, DWORD *pdwCookie)
  231. {
  232. if (!IsEqualIID(IID_ITfLangBarItemSink, riid))
  233. return CONNECT_E_CANNOTCONNECT;
  234. if (_pLangBarItemSink != NULL)
  235. return CONNECT_E_ADVISELIMIT;
  236. if (punk->QueryInterface(IID_ITfLangBarItemSink, (void **)&_pLangBarItemSink) != S_OK)
  237. {
  238. _pLangBarItemSink = NULL;
  239. return E_NOINTERFACE;
  240. }
  241. *pdwCookie = MARK_LANGBARITEMSINK_COOKIE;
  242. return S_OK;
  243. }
  244. //+---------------------------------------------------------------------------
  245. //
  246. // UnadviseSink
  247. //
  248. //----------------------------------------------------------------------------
  249. STDAPI CLangBarItemButton::UnadviseSink(DWORD dwCookie)
  250. {
  251. if (dwCookie != MARK_LANGBARITEMSINK_COOKIE)
  252. return CONNECT_E_NOCONNECTION;
  253. if (_pLangBarItemSink == NULL)
  254. return CONNECT_E_NOCONNECTION;
  255. _pLangBarItemSink->Release();
  256. _pLangBarItemSink = NULL;
  257. return S_OK;
  258. }
  259. //+---------------------------------------------------------------------------
  260. //
  261. // _InitLanguageBar
  262. //
  263. //----------------------------------------------------------------------------
  264. BOOL CMarkTextService::_InitLanguageBar()
  265. {
  266. ITfLangBarItemMgr *pLangBarItemMgr;
  267. BOOL fRet;
  268. if (_pThreadMgr->QueryInterface(IID_ITfLangBarItemMgr, (void **)&pLangBarItemMgr) != S_OK)
  269. return FALSE;
  270. fRet = FALSE;
  271. if ((_pLangBarItem = new CLangBarItemButton(this)) == NULL)
  272. goto Exit;
  273. if (pLangBarItemMgr->AddItem(_pLangBarItem) != S_OK)
  274. {
  275. _pLangBarItem->Release();
  276. _pLangBarItem = NULL;
  277. goto Exit;
  278. }
  279. fRet = TRUE;
  280. Exit:
  281. pLangBarItemMgr->Release();
  282. return fRet;
  283. }
  284. //+---------------------------------------------------------------------------
  285. //
  286. // _UninitLanguageBar
  287. //
  288. //----------------------------------------------------------------------------
  289. void CMarkTextService::_UninitLanguageBar()
  290. {
  291. ITfLangBarItemMgr *pLangBarItemMgr;
  292. if (_pLangBarItem == NULL)
  293. return;
  294. if (_pThreadMgr->QueryInterface(IID_ITfLangBarItemMgr, (void **)&pLangBarItemMgr) == S_OK)
  295. {
  296. pLangBarItemMgr->RemoveItem(_pLangBarItem);
  297. pLangBarItemMgr->Release();
  298. }
  299. _pLangBarItem->Release();
  300. _pLangBarItem = NULL;
  301. }