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.

336 lines
9.0 KiB

  1. //
  2. // sysbtn.cpp
  3. //
  4. #include "private.h"
  5. #include "globals.h"
  6. #include "immxutil.h"
  7. #include "sapilayr.h"
  8. #include "xstring.h"
  9. #include "sysbtn.h"
  10. #include "nui.h"
  11. //////////////////////////////////////////////////////////////////////////////
  12. //
  13. // CLBarItemSystemButtonBase
  14. //
  15. //////////////////////////////////////////////////////////////////////////////
  16. //+---------------------------------------------------------------------------
  17. //
  18. // IUnknown
  19. //
  20. //----------------------------------------------------------------------------
  21. STDAPI CLBarItemSystemButtonBase::QueryInterface(REFIID riid, void **ppvObj)
  22. {
  23. *ppvObj = NULL;
  24. if (IsEqualIID(riid, IID_IUnknown) ||
  25. IsEqualIID(riid, IID_ITfLangBarItem))
  26. {
  27. *ppvObj = SAFECAST(this, ITfLangBarItem *);
  28. }
  29. else if (IsEqualIID(riid, IID_ITfLangBarItemButton))
  30. {
  31. *ppvObj = SAFECAST(this, ITfLangBarItemButton *);
  32. }
  33. else if (IsEqualIID(riid, IID_ITfSource))
  34. {
  35. *ppvObj = SAFECAST(this, ITfSource *);
  36. }
  37. else if (IsEqualIID(riid, IID_ITfSystemLangBarItem))
  38. {
  39. *ppvObj = SAFECAST(this, ITfSystemLangBarItem *);
  40. }
  41. if (*ppvObj)
  42. {
  43. AddRef();
  44. return S_OK;
  45. }
  46. return E_NOINTERFACE;
  47. }
  48. STDAPI_(ULONG) CLBarItemSystemButtonBase::AddRef()
  49. {
  50. return CLBarItemButtonBase::AddRef();
  51. }
  52. STDAPI_(ULONG) CLBarItemSystemButtonBase::Release()
  53. {
  54. return CLBarItemButtonBase::Release();
  55. }
  56. //+---------------------------------------------------------------------------
  57. //
  58. // ctor
  59. //
  60. //----------------------------------------------------------------------------
  61. CLBarItemSystemButtonBase::CLBarItemSystemButtonBase()
  62. {
  63. }
  64. //----------------------------------------------------------------------------
  65. //
  66. // dtor
  67. //
  68. //----------------------------------------------------------------------------
  69. CLBarItemSystemButtonBase::~CLBarItemSystemButtonBase()
  70. {
  71. if (_pMenuMap)
  72. delete _pMenuMap;
  73. }
  74. //+---------------------------------------------------------------------------
  75. //
  76. // AdviseSink
  77. //
  78. //----------------------------------------------------------------------------
  79. STDAPI CLBarItemSystemButtonBase::AdviseSink(REFIID riid, IUnknown *punk, DWORD *pdwCookie)
  80. {
  81. HRESULT hr;
  82. hr = CLBarItemButtonBase::AdviseSink(riid, punk, pdwCookie);
  83. if( S_OK != hr)
  84. {
  85. const IID *rgiid = &IID_ITfSystemLangBarItemSink;
  86. hr = GenericAdviseSink(riid, punk, &rgiid, &_rgEventSinks, 1, pdwCookie);
  87. if (hr == S_OK)
  88. {
  89. // adjust the cookie so we don't overlap with idle detector sinks
  90. *pdwCookie = GenericChainToCookie(*pdwCookie, 1);
  91. }
  92. }
  93. return hr;
  94. }
  95. //+---------------------------------------------------------------------------
  96. //
  97. // UnadviseSink
  98. //
  99. //----------------------------------------------------------------------------
  100. STDAPI CLBarItemSystemButtonBase::UnadviseSink(DWORD dwCookie)
  101. {
  102. HRESULT hr = CLBarItemButtonBase::UnadviseSink(dwCookie);
  103. if (hr == S_OK)
  104. return hr;
  105. dwCookie = GenericUnchainToCookie(dwCookie, 1);
  106. return GenericUnadviseSink(&_rgEventSinks, 1, dwCookie);
  107. }
  108. //+---------------------------------------------------------------------------
  109. //
  110. // GetInfo
  111. //
  112. //----------------------------------------------------------------------------
  113. STDAPI CLBarItemSystemButtonBase::GetInfo(TF_LANGBARITEMINFO *pInfo)
  114. {
  115. return CLBarItemButtonBase::GetInfo(pInfo);
  116. }
  117. //+---------------------------------------------------------------------------
  118. //
  119. // Show
  120. //
  121. //----------------------------------------------------------------------------
  122. STDAPI CLBarItemSystemButtonBase::Show(BOOL fShow)
  123. {
  124. return CLBarItemButtonBase::Show(fShow);
  125. }
  126. //----------------------------------------------------------------------------
  127. //
  128. // SetIcon
  129. //
  130. //----------------------------------------------------------------------------
  131. STDAPI CLBarItemSystemButtonBase::SetIcon(HICON hIcon)
  132. {
  133. CLBarItemButtonBase::SetIcon(hIcon);
  134. return S_OK;
  135. }
  136. //----------------------------------------------------------------------------
  137. //
  138. // SetTooltipString
  139. //
  140. //----------------------------------------------------------------------------
  141. STDAPI CLBarItemSystemButtonBase::SetTooltipString(WCHAR *pchToolTip, ULONG cch)
  142. {
  143. SetToolTip(pchToolTip);
  144. return S_OK;
  145. }
  146. //+---------------------------------------------------------------------------
  147. //
  148. // _InsertCustomMenus
  149. //
  150. //----------------------------------------------------------------------------
  151. BOOL CLBarItemSystemButtonBase::_InsertCustomMenus(ITfMenu *pMenu, UINT *pnTipCurMenuID)
  152. {
  153. int nCntEventSink;
  154. int i;
  155. BOOL bRet = FALSE;
  156. //
  157. // Insert Custom item to menu
  158. //
  159. ClearMenuMap();
  160. nCntEventSink = _rgEventSinks.Count();
  161. for (i = 0; i < nCntEventSink; i++)
  162. {
  163. CCicLibMenu *pMenuTmp;
  164. GENERICSINK *pSink;
  165. ITfSystemLangBarItemSink *plbSink;
  166. if (!_pMenuMap)
  167. _pMenuMap = new CStructArray<TIPMENUITEMMAP>;
  168. if (!_pMenuMap)
  169. {
  170. Assert(0);
  171. goto Exit;
  172. }
  173. pMenuTmp = new CCicLibMenu;
  174. if (!pMenuTmp)
  175. {
  176. goto Exit;
  177. }
  178. pSink = _rgEventSinks.GetPtr(i);
  179. if (SUCCEEDED(pSink->pSink->QueryInterface(
  180. IID_ITfSystemLangBarItemSink,
  181. (void **)&plbSink)))
  182. {
  183. if (SUCCEEDED(plbSink->InitMenu(pMenuTmp)))
  184. {
  185. if (*pnTipCurMenuID > IDM_CUSTOM_MENU_START)
  186. LangBarInsertSeparator(pMenu);
  187. *pnTipCurMenuID = _MergeMenu(pMenu,
  188. pMenuTmp,
  189. plbSink,
  190. _pMenuMap,
  191. *pnTipCurMenuID);
  192. }
  193. plbSink->Release();
  194. }
  195. else
  196. {
  197. Assert(0);
  198. }
  199. pMenuTmp->Release();
  200. }
  201. bRet = TRUE;
  202. Exit:
  203. return bRet;
  204. }
  205. //+---------------------------------------------------------------------------
  206. //
  207. // _MergeMenu
  208. //
  209. //----------------------------------------------------------------------------
  210. #define MIIM_ALL ( MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_STRING | MIIM_BITMAP | MIIM_FTYPE )
  211. UINT CLBarItemSystemButtonBase::_MergeMenu(ITfMenu *pMenu,
  212. CCicLibMenu *pMenuTip,
  213. ITfSystemLangBarItemSink *plbSink,
  214. CStructArray<TIPMENUITEMMAP> *pMenuMap,
  215. UINT &nCurID)
  216. {
  217. int i;
  218. int nMenuCnt = pMenuTip->GetItemCount();
  219. if (nMenuCnt <= 0)
  220. return nCurID;
  221. for (i = 0; i < nMenuCnt; i++)
  222. {
  223. CCicLibMenuItem *pItem = pMenuTip->GetItem(i);
  224. TIPMENUITEMMAP *ptmm;
  225. int nCnt;
  226. nCnt = pMenuMap->Count();
  227. if (!pMenuMap->Insert(nCnt, 1))
  228. return nCurID;
  229. ptmm = pMenuMap->GetPtr(nCnt);
  230. ptmm->plbSink = plbSink;
  231. ptmm->nOrgID = pItem->GetId();
  232. ptmm->nTmpID = nCurID++;
  233. if (pItem->GetSubMenu())
  234. {
  235. ITfMenu *pSubMenu = NULL;
  236. if (SUCCEEDED(pMenu->AddMenuItem((UINT)-1,
  237. pItem->GetFlags(),
  238. pItem->GetBitmap(),
  239. pItem->GetBitmapMask(),
  240. pItem->GetText(),
  241. wcslen(pItem->GetText()),
  242. &pSubMenu)))
  243. {
  244. _MergeMenu(pSubMenu,
  245. pItem->GetSubMenu(),
  246. plbSink,
  247. pMenuMap,
  248. nCurID);
  249. pSubMenu->Release();
  250. }
  251. }
  252. else
  253. {
  254. pMenu->AddMenuItem(ptmm->nTmpID,
  255. pItem->GetFlags(),
  256. pItem->GetBitmap(),
  257. pItem->GetBitmapMask(),
  258. pItem->GetText(),
  259. wcslen(pItem->GetText()),
  260. NULL);
  261. }
  262. }
  263. return nCurID;
  264. }
  265. STDAPI CLBarItemSystemButtonBase::OnMenuSelect(UINT wID)
  266. {
  267. HRESULT hr = S_OK;
  268. int nMenuMapoCnt = _pMenuMap->Count();
  269. for (int i = 0; i < nMenuMapoCnt; i++)
  270. {
  271. TIPMENUITEMMAP *ptmm;
  272. ptmm = _pMenuMap->GetPtr(i);
  273. if (ptmm->nTmpID == (UINT)wID)
  274. {
  275. hr = ptmm->plbSink->OnMenuSelect(ptmm->nOrgID);
  276. break;
  277. }
  278. }
  279. return hr;
  280. }