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.

152 lines
3.8 KiB

  1. //
  2. // cicbtn.h
  3. //
  4. #ifndef _CICBTN_H_
  5. #define _CICBTN_H_
  6. #include "msctf.h"
  7. #include <initguid.h>
  8. #include "..\CiceroLib\inc\slbarid.h"
  9. #define CICBTN_TOOLTIP_MAX 256
  10. #define CICBTN_TEXT_MAX 256
  11. class __declspec(novtable) CCicButton : public ITfSource, public ITfLangBarItemButton
  12. {
  13. public:
  14. CCicButton()
  15. {
  16. m_uid = (UINT)-1;
  17. m_dwStatus = 0;
  18. m_fShown = FALSE;
  19. m_fEnable = TRUE;
  20. m_szText[0] = L'\0';
  21. m_plbiSink = NULL;
  22. m_cRef = 1;
  23. }
  24. ~CCicButton();
  25. //
  26. // IUnknown methods
  27. //
  28. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  29. STDMETHODIMP_(ULONG) AddRef(void);
  30. //virtual STDMETHODIMP_(ULONG) Release(void);
  31. void InitInfo(REFCLSID clsid, REFGUID rguid, DWORD dwStyle, ULONG ulSort, LPWSTR pszDesc);
  32. virtual STDMETHODIMP GetInfo(TF_LANGBARITEMINFO *pInfo);
  33. virtual STDMETHODIMP GetStatus(DWORD *pdwStatus);
  34. virtual STDMETHODIMP Show(BOOL fShow);
  35. virtual STDMETHODIMP GetTooltipString(BSTR *pbstrToolTip);
  36. virtual STDMETHODIMP AdviseSink(REFIID riid, IUnknown *punk, DWORD *pdwCookie);
  37. virtual STDMETHODIMP UnadviseSink(DWORD dwCookie);
  38. virtual STDMETHODIMP OnClick( /* [in] */ TfLBIClick click, /* [in] */ POINT pt, /* [in] */ const RECT __RPC_FAR *prcArea);
  39. virtual STDMETHODIMP InitMenu( /* [in] */ ITfMenu __RPC_FAR *pMenu);
  40. virtual STDMETHODIMP OnMenuSelect( /* [in] */ UINT wID);
  41. virtual STDMETHODIMP GetIcon( /* [out] */ HICON __RPC_FAR *phIcon);
  42. virtual STDMETHODIMP GetText( /* [out] */ BSTR __RPC_FAR *pbstrText);
  43. virtual HRESULT OnLButtonUp(const POINT pt, const RECT *prcArea);
  44. virtual HRESULT OnRButtonUp(const POINT pt, const RECT *prcArea);
  45. DWORD GetStyle() {return m_lbiInfo.dwStyle;}
  46. void SetStyle(DWORD dwStyle) {m_lbiInfo.dwStyle = dwStyle;}
  47. GUID* GetGuidItem() {return &m_lbiInfo.guidItem;}
  48. DWORD GetStatusInternal() {return m_dwStatus;}
  49. void SetStatusInternal(DWORD dw) {m_dwStatus = dw;}
  50. HRESULT ShowInternal(BOOL fShow, BOOL fNotify = FALSE);
  51. void SetOrClearStatus(DWORD dw, BOOL fSet);
  52. ITfLangBarItemSink *GetSink() { return m_plbiSink; }
  53. void SetText(WCHAR *psz);
  54. void SetToolTip(WCHAR *psz);
  55. void SetStatus(DWORD dwStatus);
  56. void Enable(BOOL fEnable);
  57. BOOL IsEnable() { return m_fEnable; }
  58. void ShowDefault(BOOL fShowDefault);
  59. void SetID(UINT uid) { m_uid = uid; }
  60. UINT GetID() { return m_uid; }
  61. void UpdateButton();
  62. protected:
  63. //DWORD _dwStatus;
  64. TF_LANGBARITEMINFO m_lbiInfo;
  65. WCHAR m_szToolTip[CICBTN_TOOLTIP_MAX];
  66. long m_cRef;
  67. ITfLangBarItemSink *m_plbiSink;
  68. private:
  69. DWORD m_dwCookie;
  70. DWORD m_dwStatus;
  71. BOOL m_fShown;
  72. BOOL m_fEnable;
  73. UINT m_uid;
  74. WCHAR m_szText[CICBTN_TEXT_MAX];
  75. };
  76. inline
  77. void CCicButton::SetOrClearStatus(DWORD dw, BOOL fSet)
  78. {
  79. if (fSet)
  80. m_dwStatus |= dw;
  81. else
  82. m_dwStatus &= ~dw;
  83. }
  84. inline
  85. void CCicButton::SetToolTip(WCHAR *psz)
  86. {
  87. StrnCopyW(m_szToolTip, psz, CICBTN_TOOLTIP_MAX);
  88. }
  89. inline
  90. void CCicButton::SetStatus(DWORD dwStatus)
  91. {
  92. BOOL fShown = m_fShown;
  93. m_dwStatus = dwStatus;
  94. ShowInternal(fShown);
  95. }
  96. inline
  97. void CCicButton::Enable(BOOL fEnable)
  98. {
  99. m_fEnable = fEnable;
  100. if(fEnable) { // enable?
  101. m_dwStatus &= ~TF_LBI_STATUS_DISABLED;
  102. } else {
  103. m_dwStatus |= TF_LBI_STATUS_DISABLED;
  104. }
  105. }
  106. inline
  107. void CCicButton::ShowDefault(BOOL fShowDefault)
  108. {
  109. if( fShowDefault == FALSE ) {
  110. m_lbiInfo.dwStyle |= TF_LBI_STYLE_HIDDENBYDEFAULT;
  111. } else {
  112. m_lbiInfo.dwStyle &= ~TF_LBI_STYLE_HIDDENBYDEFAULT;
  113. }
  114. }
  115. inline
  116. void CCicButton::SetText(WCHAR *psz)
  117. {
  118. StrnCopyW(m_szText, psz, CICBTN_TEXT_MAX);
  119. }
  120. inline
  121. void CCicButton::UpdateButton()
  122. {
  123. if (m_plbiSink)
  124. m_plbiSink->OnUpdate(TF_LBI_BTNALL| /*TF_LBI_BITMAP |*/ TF_LBI_STATUS /*| TF_LBI_BMPALL*/);
  125. }
  126. #endif // _CICBTN_H_