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.

416 lines
12 KiB

  1. //
  2. // nuibase.h
  3. //
  4. // Generic ITfTextEventSink object
  5. //
  6. #ifndef NUIBASE_H
  7. #define NUIBASE_H
  8. #include "ctfutb.h"
  9. #include "iconlib.h"
  10. inline HRESULT LangBarInsertMenu(ITfMenu *pMenu, UINT uId, WCHAR *psz, BOOL bChecked = FALSE, BOOL bRadioChecked = FALSE)
  11. {
  12. DWORD dwFlags = 0;
  13. if (bChecked)
  14. dwFlags |= TF_LBMENUF_CHECKED;
  15. if (bRadioChecked)
  16. dwFlags |= TF_LBMENUF_RADIOCHECKED;
  17. return pMenu->AddMenuItem(uId,
  18. dwFlags,
  19. NULL,
  20. NULL,
  21. psz,
  22. wcslen(psz),
  23. NULL);
  24. }
  25. inline HRESULT LangBarInsertGrayedMenu(ITfMenu *pMenu, WCHAR *psz)
  26. {
  27. return pMenu->AddMenuItem((UINT)-1,
  28. TF_LBMENUF_GRAYED,
  29. NULL,
  30. NULL,
  31. psz,
  32. wcslen(psz),
  33. NULL);
  34. }
  35. inline HRESULT LangBarInsertMenu(ITfMenu *pMenu, UINT uId, WCHAR *psz, HBITMAP hbmp, HBITMAP hbmpMask)
  36. {
  37. return pMenu->AddMenuItem(uId,
  38. 0,
  39. hbmp,
  40. hbmpMask,
  41. psz,
  42. wcslen(psz),
  43. NULL);
  44. }
  45. inline HRESULT LangBarInsertMenu(ITfMenu *pMenu, UINT uId, WCHAR *psz, BOOL bChecked, HICON hIcon)
  46. {
  47. HBITMAP hbmp = NULL;
  48. HBITMAP hbmpMask = NULL;
  49. if (hIcon)
  50. {
  51. HICON hSmIcon = (HICON)CopyImage(hIcon,
  52. IMAGE_ICON,
  53. 16,
  54. 16,
  55. LR_COPYFROMRESOURCE);
  56. SIZE size = {16, 16};
  57. if (!GetIconBitmaps(hSmIcon ? hSmIcon : hIcon, &hbmp, &hbmpMask, &size))
  58. return E_FAIL;
  59. if (hSmIcon)
  60. DestroyIcon(hSmIcon);
  61. if (hIcon)
  62. DestroyIcon(hIcon);
  63. }
  64. return pMenu->AddMenuItem(uId,
  65. bChecked ? TF_LBMENUF_CHECKED : 0,
  66. hbmp,
  67. hbmpMask,
  68. psz,
  69. wcslen(psz),
  70. NULL);
  71. }
  72. inline HRESULT LangBarInsertGrayedMenu(ITfMenu *pMenu, WCHAR *psz, HICON hIcon)
  73. {
  74. HBITMAP hbmp = NULL;
  75. HBITMAP hbmpMask = NULL;
  76. if (hIcon)
  77. {
  78. HICON hSmIcon = (HICON)CopyImage(hIcon,
  79. IMAGE_ICON,
  80. 16,
  81. 16,
  82. LR_COPYFROMRESOURCE);
  83. SIZE size = {16, 16};
  84. if (!GetIconBitmaps(hSmIcon ? hSmIcon : hIcon, &hbmp, &hbmpMask, &size))
  85. return E_FAIL;
  86. if (hSmIcon)
  87. DestroyIcon(hSmIcon);
  88. if (hIcon)
  89. DestroyIcon(hIcon);
  90. }
  91. return pMenu->AddMenuItem((UINT)-1,
  92. TF_LBMENUF_GRAYED,
  93. hbmp,
  94. hbmpMask,
  95. psz,
  96. wcslen(psz),
  97. NULL);
  98. }
  99. inline HRESULT LangBarInsertSubMenu(ITfMenu *pMenu, WCHAR *psz, ITfMenu **ppSubMenu)
  100. {
  101. return pMenu->AddMenuItem(UINT(-1),
  102. TF_LBMENUF_SUBMENU,
  103. NULL,
  104. NULL,
  105. psz,
  106. wcslen(psz),
  107. ppSubMenu);
  108. }
  109. inline HRESULT LangBarInsertSeparator(ITfMenu *pMenu)
  110. {
  111. return pMenu->AddMenuItem((UINT)(-1),
  112. TF_LBMENUF_SEPARATOR,
  113. NULL,
  114. NULL,
  115. NULL,
  116. 0,
  117. NULL);
  118. }
  119. #define NUIBASE_TOOLTIP_MAX 256
  120. #define NUIBASE_TEXT_MAX 256
  121. //////////////////////////////////////////////////////////////////////////////
  122. //
  123. // CLBarItemBase
  124. //
  125. //////////////////////////////////////////////////////////////////////////////
  126. class __declspec(novtable) CLBarItemBase
  127. {
  128. public:
  129. CLBarItemBase();
  130. virtual ~CLBarItemBase();
  131. void InitNuiInfo(REFCLSID clsid, REFGUID rguid, DWORD dwStyle, ULONG ulSort, WCHAR *pszDesc);
  132. virtual STDMETHODIMP GetInfo(TF_LANGBARITEMINFO *pInfo);
  133. virtual STDMETHODIMP GetStatus(DWORD *pdwStatus);
  134. virtual STDMETHODIMP Show(BOOL fShow);
  135. virtual STDMETHODIMP GetTooltipString(BSTR *pbstrToolTip);
  136. virtual STDMETHODIMP AdviseSink(REFIID riid, IUnknown *punk, DWORD *pdwCookie);
  137. virtual STDMETHODIMP UnadviseSink(DWORD dwCookie);
  138. DWORD GetStyle() {return _lbiInfo.dwStyle;}
  139. void SetStyle(DWORD dwStyle) {_lbiInfo.dwStyle = dwStyle;}
  140. GUID* GetGuidItem() {return &_lbiInfo.guidItem;}
  141. DWORD GetStatusInternal() {return _dwStatus;}
  142. void SetStatusInternal(DWORD dw) {_dwStatus = dw;}
  143. HRESULT ShowInternal(BOOL fShow, BOOL fNotify);
  144. void SetOrClearStatus(DWORD dw, BOOL fSet)
  145. {
  146. if (fSet)
  147. _dwStatus |= dw;
  148. else
  149. _dwStatus &= ~dw;
  150. }
  151. void SetToolTip(WCHAR *psz, UINT cch = (UINT)(-1))
  152. {
  153. if (cch == (UINT)(-1))
  154. StringCchCopyW(_szToolTip, ARRAYSIZE(_szToolTip), psz);
  155. else
  156. {
  157. UINT cchTemp = (UINT)min(ARRAYSIZE(_szToolTip) - 1, cch);
  158. memcpy(_szToolTip, psz, cchTemp * sizeof(WCHAR));
  159. _szToolTip[cchTemp] = L'\0';
  160. }
  161. }
  162. virtual HRESULT OnLButtonUp(const POINT pt, const RECT *prcArea);
  163. virtual HRESULT OnRButtonUp(const POINT pt, const RECT *prcArea);
  164. ITfLangBarItemSink *GetSink() {return _plbiSink;}
  165. protected:
  166. DWORD _dwStatus;
  167. TF_LANGBARITEMINFO _lbiInfo;
  168. WCHAR _szToolTip[NUIBASE_TOOLTIP_MAX];
  169. long _cRef;
  170. ITfLangBarItemSink *_plbiSink;
  171. private:
  172. DWORD _dwCookie;
  173. };
  174. //////////////////////////////////////////////////////////////////////////////
  175. //
  176. // CLBarItemButtonBase
  177. //
  178. //////////////////////////////////////////////////////////////////////////////
  179. class __declspec(novtable) CLBarItemButtonBase : public CLBarItemBase,
  180. public ITfSource,
  181. public ITfLangBarItemButton
  182. {
  183. public:
  184. CLBarItemButtonBase();
  185. virtual ~CLBarItemButtonBase();
  186. //
  187. // IUnknown methods
  188. //
  189. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  190. STDMETHODIMP_(ULONG) AddRef(void);
  191. STDMETHODIMP_(ULONG) Release(void);
  192. //
  193. // ITfSource
  194. //
  195. STDMETHODIMP AdviseSink(REFIID riid, IUnknown *punk, DWORD *pdwCookie);
  196. STDMETHODIMP UnadviseSink(DWORD dwCookie);
  197. //
  198. // ITfLangBarItem
  199. //
  200. STDMETHODIMP GetInfo(TF_LANGBARITEMINFO *pInfo);
  201. STDMETHODIMP GetStatus(DWORD *pdwStatus);
  202. STDMETHODIMP Show(BOOL fShow);
  203. STDMETHODIMP GetTooltipString(BSTR *pbstrToolTip);
  204. //
  205. // ITfLangBarItemButton
  206. //
  207. STDMETHODIMP OnClick(TfLBIClick click, POINT pt, const RECT *prcArea);
  208. STDMETHODIMP InitMenu(ITfMenu *pMenu);
  209. STDMETHODIMP OnMenuSelect(UINT wID);
  210. STDMETHODIMP GetIcon(HICON *phIcon);
  211. STDMETHODIMP GetText(BSTR *pbstrText);
  212. void SetIcon(HICON hIcon) {_hIcon = hIcon;}
  213. HICON GetIcon() {return _hIcon;}
  214. void SetText(WCHAR *psz)
  215. {
  216. StringCchCopyW(_szText, ARRAYSIZE(_szText), psz);
  217. }
  218. private:
  219. HICON _hIcon;
  220. WCHAR _szText[NUIBASE_TEXT_MAX];
  221. };
  222. //////////////////////////////////////////////////////////////////////////////
  223. //
  224. // CLBarItemBitmapButtonBase
  225. //
  226. //////////////////////////////////////////////////////////////////////////////
  227. class __declspec(novtable) CLBarItemBitmapButtonBase : public CLBarItemBase,
  228. public ITfSource,
  229. public ITfLangBarItemBitmapButton
  230. {
  231. public:
  232. CLBarItemBitmapButtonBase();
  233. virtual ~CLBarItemBitmapButtonBase();
  234. //
  235. // IUnknown methods
  236. //
  237. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  238. STDMETHODIMP_(ULONG) AddRef(void);
  239. STDMETHODIMP_(ULONG) Release(void);
  240. //
  241. // ITfSource
  242. //
  243. STDMETHODIMP AdviseSink(REFIID riid, IUnknown *punk, DWORD *pdwCookie);
  244. STDMETHODIMP UnadviseSink(DWORD dwCookie);
  245. //
  246. // ITfLangBarItem
  247. //
  248. STDMETHODIMP GetInfo(TF_LANGBARITEMINFO *pInfo);
  249. STDMETHODIMP GetStatus(DWORD *pdwStatus);
  250. STDMETHODIMP Show(BOOL fShow);
  251. STDMETHODIMP GetTooltipString(BSTR *pbstrToolTip);
  252. //
  253. // ITfLangBarItemBitmapButton
  254. //
  255. STDMETHODIMP OnClick(TfLBIClick click, POINT pt, const RECT *prcArea);
  256. STDMETHODIMP InitMenu(ITfMenu *pMenu);
  257. STDMETHODIMP OnMenuSelect(UINT wID);
  258. STDMETHODIMP GetPreferredSize(const SIZE *pszDefault, SIZE *psize);
  259. STDMETHODIMP DrawBitmap(LONG x, LONG y, DWORD dwFlags, HBITMAP *phbmp, HBITMAP *phbmpMask) = 0;
  260. STDMETHODIMP GetText(BSTR *pbstrText);
  261. void SetText(WCHAR *psz)
  262. {
  263. StringCchCopyW(_szText, ARRAYSIZE(_szText), psz);
  264. }
  265. void SetPreferedSize(SIZE *psize) {_sizePrefered = *psize;}
  266. private:
  267. SIZE _sizePrefered;
  268. WCHAR _szText[NUIBASE_TEXT_MAX];
  269. };
  270. //////////////////////////////////////////////////////////////////////////////
  271. //
  272. // CLBarItemBitmapBase
  273. //
  274. //////////////////////////////////////////////////////////////////////////////
  275. class __declspec(novtable) CLBarItemBitmapBase : public CLBarItemBase,
  276. public ITfSource,
  277. public ITfLangBarItemBitmap
  278. {
  279. public:
  280. CLBarItemBitmapBase();
  281. virtual ~CLBarItemBitmapBase();
  282. //
  283. // IUnknown methods
  284. //
  285. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  286. STDMETHODIMP_(ULONG) AddRef(void);
  287. STDMETHODIMP_(ULONG) Release(void);
  288. //
  289. // ITfSource
  290. //
  291. STDMETHODIMP AdviseSink(REFIID riid, IUnknown *punk, DWORD *pdwCookie);
  292. STDMETHODIMP UnadviseSink(DWORD dwCookie);
  293. //
  294. // ITfLangBarItem
  295. //
  296. STDMETHODIMP GetInfo(TF_LANGBARITEMINFO *pInfo);
  297. STDMETHODIMP GetStatus(DWORD *pdwStatus);
  298. STDMETHODIMP Show(BOOL fShow);
  299. STDMETHODIMP GetTooltipString(BSTR *pbstrToolTip);
  300. //
  301. // ITfLangBarItemBitmap
  302. //
  303. STDMETHODIMP OnClick(TfLBIClick click, POINT pt, const RECT *prcArea);
  304. STDMETHODIMP GetPreferredSize(const SIZE *pszDefault, SIZE *psize);
  305. STDMETHODIMP DrawBitmap(LONG x, LONG y, DWORD dwFlags, HBITMAP *phbmp, HBITMAP *phbmpMask) = 0;
  306. void SetPreferedSize(SIZE *psize) {_sizePrefered = *psize;}
  307. private:
  308. SIZE _sizePrefered;
  309. };
  310. //////////////////////////////////////////////////////////////////////////////
  311. //
  312. // CLBarItemBalloonBase
  313. //
  314. //////////////////////////////////////////////////////////////////////////////
  315. class __declspec(novtable) CLBarItemBalloonBase : public CLBarItemBase,
  316. public ITfSource,
  317. public ITfLangBarItemBalloon
  318. {
  319. public:
  320. CLBarItemBalloonBase();
  321. virtual ~CLBarItemBalloonBase();
  322. //
  323. // IUnknown methods
  324. //
  325. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  326. STDMETHODIMP_(ULONG) AddRef(void);
  327. STDMETHODIMP_(ULONG) Release(void);
  328. //
  329. // ITfSource
  330. //
  331. STDMETHODIMP AdviseSink(REFIID riid, IUnknown *punk, DWORD *pdwCookie);
  332. STDMETHODIMP UnadviseSink(DWORD dwCookie);
  333. //
  334. // ITfLangBarItem
  335. //
  336. STDMETHODIMP GetInfo(TF_LANGBARITEMINFO *pInfo);
  337. STDMETHODIMP GetStatus(DWORD *pdwStatus);
  338. STDMETHODIMP Show(BOOL fShow);
  339. STDMETHODIMP GetTooltipString(BSTR *pbstrToolTip);
  340. //
  341. // ITfLangBarItemBalloon
  342. //
  343. STDMETHODIMP OnClick(TfLBIClick click, POINT pt, const RECT *prcArea);
  344. STDMETHODIMP GetPreferredSize(const SIZE *pszDefault, SIZE *psize);
  345. STDMETHODIMP GetBalloonInfo(TF_LBBALLOONINFO *pInfo) = 0;
  346. void SetPreferedSize(SIZE *psize) {_sizePrefered = *psize;}
  347. private:
  348. SIZE _sizePrefered;
  349. };
  350. #endif // NUIBASE_H