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.

342 lines
7.9 KiB

  1. //
  2. // cicbtn.cpp
  3. //
  4. // base code: nuibase sample
  5. //
  6. #include "private.h"
  7. #include "globals.h"
  8. #include "cicbtn.h"
  9. #include "helpers.h"
  10. #define CICBTN_ITEMSINK_COOKIE 0x80000003
  11. //////////////////////////////////////////////////////////////////////////////
  12. //
  13. // CCicButton
  14. //
  15. //////////////////////////////////////////////////////////////////////////////
  16. //+---------------------------------------------------------------------------
  17. //
  18. // dtor
  19. //
  20. //----------------------------------------------------------------------------
  21. CCicButton::~CCicButton()
  22. {
  23. SafeRelease(m_plbiSink);
  24. }
  25. //+---------------------------------------------------------------------------
  26. //
  27. // InitInfo
  28. //
  29. //----------------------------------------------------------------------------
  30. void CCicButton::InitInfo(REFCLSID rclsid,
  31. REFGUID rguid,
  32. DWORD dwStyle,
  33. ULONG ulSort,
  34. LPWSTR pszDesc)
  35. {
  36. // init nuiInfo.
  37. m_lbiInfo.clsidService = rclsid;
  38. m_lbiInfo.guidItem = rguid;
  39. m_lbiInfo.dwStyle = dwStyle;
  40. m_lbiInfo.ulSort = ulSort;
  41. StringCchCopyW(m_lbiInfo.szDescription, ARRAYSIZE(m_lbiInfo.szDescription), pszDesc);
  42. }
  43. //+---------------------------------------------------------------------------
  44. //
  45. // GetType
  46. //
  47. //----------------------------------------------------------------------------
  48. STDAPI CCicButton::GetInfo(TF_LANGBARITEMINFO *pInfo)
  49. {
  50. *pInfo = m_lbiInfo;
  51. return S_OK;
  52. }
  53. //+---------------------------------------------------------------------------
  54. //
  55. // GetStatus
  56. //
  57. //----------------------------------------------------------------------------
  58. STDAPI CCicButton::GetStatus(DWORD *pdwStatus)
  59. {
  60. *pdwStatus = m_dwStatus;
  61. if (m_fEnable) // enable?
  62. {
  63. // do nothing
  64. }
  65. else
  66. *pdwStatus |= TF_LBI_STATUS_DISABLED;
  67. return S_OK;
  68. }
  69. //+---------------------------------------------------------------------------
  70. //
  71. // Show
  72. //
  73. //----------------------------------------------------------------------------
  74. STDAPI CCicButton::Show(BOOL fShow)
  75. {
  76. ITfLangBarItemSink* pSink;
  77. ShowInternal(fShow);
  78. pSink = GetSink();
  79. if (pSink)
  80. pSink->OnUpdate(TF_LBI_STATUS);
  81. return S_OK;
  82. }
  83. //+---------------------------------------------------------------------------
  84. //
  85. // AdviseSink
  86. //
  87. //----------------------------------------------------------------------------
  88. HRESULT CCicButton::AdviseSink(REFIID riid, IUnknown *punk, DWORD *pdwCookie)
  89. {
  90. HRESULT hr;
  91. if (IsEqualIID(IID_ITfLangBarItemSink, riid))
  92. {
  93. if (m_plbiSink)
  94. hr = CONNECT_E_CANNOTCONNECT;
  95. else
  96. {
  97. hr = punk->QueryInterface(IID_ITfLangBarItemSink, (void **)&m_plbiSink);
  98. if (SUCCEEDED(hr))
  99. *pdwCookie = CICBTN_ITEMSINK_COOKIE;
  100. }
  101. }
  102. else
  103. hr = CONNECT_E_CANNOTCONNECT;
  104. return hr;
  105. }
  106. //+---------------------------------------------------------------------------
  107. //
  108. // UnadviseSink
  109. //
  110. //----------------------------------------------------------------------------
  111. HRESULT CCicButton::UnadviseSink(DWORD dwCookie)
  112. {
  113. if (CICBTN_ITEMSINK_COOKIE != dwCookie)
  114. return E_FAIL;
  115. if (!m_plbiSink)
  116. return E_UNEXPECTED;
  117. m_plbiSink->Release();
  118. m_plbiSink = NULL;
  119. return S_OK;
  120. }
  121. //+---------------------------------------------------------------------------
  122. //
  123. // Show
  124. //
  125. //----------------------------------------------------------------------------
  126. HRESULT CCicButton::ShowInternal(BOOL fShow, BOOL fNotify)
  127. {
  128. m_fShown = fShow;
  129. DWORD dwOldStatus = m_dwStatus;
  130. if (fShow)
  131. m_dwStatus &= ~TF_LBI_STATUS_HIDDEN;
  132. else
  133. m_dwStatus |= TF_LBI_STATUS_HIDDEN;
  134. if (fNotify && (dwOldStatus != m_dwStatus) && m_plbiSink)
  135. m_plbiSink->OnUpdate(TF_LBI_STATUS);
  136. return S_OK;
  137. }
  138. //////////////////////////////////////////////////////////////////////////////
  139. //
  140. // CLBarItemButtonBase
  141. //
  142. //////////////////////////////////////////////////////////////////////////////
  143. //+---------------------------------------------------------------------------
  144. //
  145. // IUnknown
  146. //
  147. //----------------------------------------------------------------------------
  148. STDAPI CCicButton::QueryInterface(REFIID riid, void **ppvObj)
  149. {
  150. *ppvObj = NULL;
  151. if (IsEqualIID(riid, IID_IUnknown) ||
  152. IsEqualIID(riid, IID_ITfLangBarItem))
  153. {
  154. *ppvObj = SAFECAST(this, ITfLangBarItem *);
  155. }
  156. else if (IsEqualIID(riid, IID_ITfLangBarItemButton))
  157. {
  158. *ppvObj = SAFECAST(this, ITfLangBarItemButton *);
  159. }
  160. else if (IsEqualIID(riid, IID_ITfSource))
  161. {
  162. *ppvObj = SAFECAST(this, ITfSource *);
  163. }
  164. if (*ppvObj)
  165. {
  166. AddRef();
  167. return S_OK;
  168. }
  169. return E_NOINTERFACE;
  170. }
  171. STDAPI_(ULONG) CCicButton::AddRef()
  172. {
  173. return ++m_cRef;
  174. }
  175. #ifdef NEVER // each button object has this
  176. STDAPI_(ULONG) CCicButton::Release()
  177. {
  178. long cr;
  179. cr = --m_cRef;
  180. Assert(cr >= 0);
  181. if (cr == 0)
  182. {
  183. delete this;
  184. }
  185. return cr;
  186. }
  187. #endif // NEVER
  188. //+---------------------------------------------------------------------------
  189. //
  190. // OnClick
  191. //
  192. //----------------------------------------------------------------------------
  193. STDAPI CCicButton::OnClick(TfLBIClick click, POINT pt, const RECT *prcArea)
  194. {
  195. switch (click)
  196. {
  197. case TF_LBI_CLK_RIGHT:
  198. return OnRButtonUp(pt, prcArea);
  199. case TF_LBI_CLK_LEFT:
  200. return OnLButtonUp(pt, prcArea);
  201. }
  202. return E_NOTIMPL;
  203. }
  204. //+---------------------------------------------------------------------------
  205. //
  206. // OnLButtonUp
  207. //
  208. //----------------------------------------------------------------------------
  209. HRESULT CCicButton::OnLButtonUp(const POINT pt, const RECT *prcArea)
  210. {
  211. pt, prcArea; // no ref
  212. return E_NOTIMPL;
  213. }
  214. //+---------------------------------------------------------------------------
  215. //
  216. // OnRButtonUp
  217. //
  218. //----------------------------------------------------------------------------
  219. HRESULT CCicButton::OnRButtonUp(const POINT pt, const RECT *prcArea)
  220. {
  221. pt, prcArea; // no ref
  222. return E_NOTIMPL;
  223. }
  224. //+---------------------------------------------------------------------------
  225. //
  226. // InitMenu
  227. //
  228. //----------------------------------------------------------------------------
  229. STDAPI CCicButton::InitMenu(ITfMenu *pMenu)
  230. {
  231. pMenu; // no ref
  232. return E_NOTIMPL;
  233. }
  234. //+---------------------------------------------------------------------------
  235. //
  236. // OnMenuSelect
  237. //
  238. //----------------------------------------------------------------------------
  239. STDAPI CCicButton::OnMenuSelect(UINT uID)
  240. {
  241. uID; // no ref
  242. return E_NOTIMPL;
  243. }
  244. //+---------------------------------------------------------------------------
  245. //
  246. // GetIcon
  247. //
  248. //----------------------------------------------------------------------------
  249. STDAPI CCicButton::GetIcon(HICON *phIcon)
  250. {
  251. phIcon; // no ref
  252. return E_NOTIMPL;
  253. }
  254. //+---------------------------------------------------------------------------
  255. //
  256. // GetText
  257. //
  258. //----------------------------------------------------------------------------
  259. STDAPI CCicButton::GetText(BSTR *pbstrText)
  260. {
  261. if (!pbstrText)
  262. return E_INVALIDARG;
  263. *pbstrText = SysAllocString(m_szText);
  264. return S_OK;
  265. }
  266. //+---------------------------------------------------------------------------
  267. //
  268. // GetTooltipString
  269. //
  270. //----------------------------------------------------------------------------
  271. STDAPI CCicButton::GetTooltipString(BSTR *pbstrToolTip)
  272. {
  273. if (!pbstrToolTip)
  274. return E_INVALIDARG;
  275. *pbstrToolTip = SysAllocString(m_szToolTip);
  276. return S_OK;
  277. }