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.

349 lines
8.0 KiB

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