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.

143 lines
5.1 KiB

  1. #ifndef _TRAYITEM_H
  2. #define _TRAYITEM_H
  3. #include "traycmn.h"
  4. #define TNUP_AUTOMATIC 0
  5. #define TNUP_DEMOTED 1
  6. #define TNUP_PROMOTED 2
  7. // IMPORTANT : Should be kept in sync with any flags defined in shellapi.w
  8. typedef enum ICONSTATEFLAG
  9. {
  10. TIF_HIDDEN = 0,
  11. TIF_DEMOTED,
  12. TIF_STARTUPICON,
  13. TIF_SHARED,
  14. TIF_SHAREDICONSOURCE,
  15. TIF_ONCEVISIBLE,
  16. TIF_ITEMCLICKED,
  17. TIF_ITEMSAMEICONMODIFY,
  18. } ICONSTATEFLAG;
  19. class CTrayItem
  20. {
  21. public:
  22. CTrayItem() : dwUserPref(TNUP_AUTOMATIC), guidItem(GUID_NULL) { }
  23. ~CTrayItem() { }
  24. // The icon should have an associated exe name, and it should either be
  25. // demoted or its preference should be set to something other than automatic
  26. BOOL ShouldSaveIcon()
  27. {
  28. return ( (szExeName[0] != 0) && (WasOnceVisible()) && (szIconText[0] != 0) );
  29. }
  30. BOOL IsDemoted() { return (_CheckIconState(TIF_DEMOTED)); }
  31. BOOL IsHidden() { return (_CheckIconState(TIF_HIDDEN)); }
  32. BOOL IsIconShared() { return (_CheckIconState(TIF_SHARED)); }
  33. BOOL IsSharedIconSource() { return (_CheckIconState(TIF_SHAREDICONSOURCE)); }
  34. BOOL IsStartupIcon() { return (_CheckIconState(TIF_STARTUPICON)); }
  35. BOOL WasOnceVisible() { return (_CheckIconState(TIF_ONCEVISIBLE)); }
  36. BOOL IsItemClicked() { return (_CheckIconState(TIF_ITEMCLICKED)); }
  37. BOOL IsItemSameIconModify() { return (_CheckIconState(TIF_ITEMSAMEICONMODIFY)); }
  38. BOOL IsGuidItemValid() { return (guidItem != GUID_NULL); }
  39. BOOL IsIconTimerCurrent() { return (uIconDemoteTimerID != 0); }
  40. void SetDemoted(BOOL bDemoted) { _SetIconState(TIF_DEMOTED, bDemoted); }
  41. void SetStartupIcon(BOOL bIsStartupIcon) { _SetIconState(TIF_STARTUPICON, bIsStartupIcon); }
  42. void SetSharedIconSource(BOOL bSharedIconSource)
  43. {
  44. _SetIconState(TIF_SHAREDICONSOURCE, bSharedIconSource);
  45. }
  46. void SetOnceVisible(BOOL bOnceVisible) { _SetIconState(TIF_ONCEVISIBLE, bOnceVisible); }
  47. void SetItemClicked(BOOL bItemClicked) { _SetIconState(TIF_ITEMCLICKED, bItemClicked); }
  48. void SetItemSameIconModify(BOOL bItemSameIconModify)
  49. {
  50. _SetIconState(TIF_ITEMSAMEICONMODIFY, bItemSameIconModify);
  51. }
  52. public:
  53. HWND hWnd;
  54. UINT uID;
  55. UINT uCallbackMessage;
  56. DWORD dwState;
  57. UINT uVersion;
  58. HICON hIcon; // *** may be stale, not guaranteed to be a valid hicon ***
  59. ULONG uIconDemoteTimerID;
  60. DWORD dwUserPref; // user preference (hidden? visible? automatic?)
  61. DWORD dwLastSoundTime;
  62. TCHAR szExeName[MAX_PATH];
  63. TCHAR szIconText[MAX_PATH];
  64. UINT uNumSeconds;
  65. GUID guidItem;
  66. private:
  67. DWORD _GetStateFlag(ICONSTATEFLAG sf);
  68. void _SetIconState(ICONSTATEFLAG sf, BOOL bSet);
  69. BOOL _CheckIconState(ICONSTATEFLAG sf);
  70. };
  71. // Item Count helper flags..
  72. #define GIC_PROMOTED 0
  73. #define GIC_DEMOTED 1
  74. #define GIC_ALL 2
  75. class CTrayItemManager
  76. {
  77. public:
  78. CTrayItemManager() { }
  79. ~CTrayItemManager() { }
  80. INT_PTR FindItemAssociatedWithGuid(GUID guidItemToCheck);
  81. INT_PTR FindItemAssociatedWithTimer(UINT_PTR uIconDemoteTimerID);
  82. INT_PTR FindItemAssociatedWithHwndUid(HWND hwnd, UINT uID);
  83. INT_PTR GetItemCount(int nItemCountThreshold = -1)
  84. {
  85. return _GetItemCountHelper(GIC_ALL, nItemCountThreshold);
  86. }
  87. INT_PTR GetDemotedItemCount(int nItemCountThreshold = -1)
  88. {
  89. return _GetItemCountHelper(GIC_DEMOTED, nItemCountThreshold);
  90. }
  91. INT_PTR GetPromotedItemCount(int nItemCountThreshold = -1)
  92. {
  93. return _GetItemCountHelper(GIC_PROMOTED, nItemCountThreshold);
  94. }
  95. void SetTBBtnImage(INT_PTR iIndex, int iImage);
  96. int GetTBBtnImage(INT_PTR iIndex, BOOL fByIndex = TRUE);
  97. void SetTBBtnText(INT_PTR iIndex, LPTSTR pszText);
  98. BOOL SetTBBtnStateHelper(INT_PTR iIndex, BYTE fsState, BOOL_PTR bSet);
  99. BOOL GetTrayItem(INT_PTR nIndex, CNotificationItem * pni, BOOL * pbStat);
  100. int FindImageIndex(HICON hIcon, BOOL fSetAsSharedSource);
  101. BOOL DemotedItemsPresent(int nMinDemotedItemsThreshold);
  102. CTrayItem * GetItemData(INT_PTR i, BOOL byIndex, HWND hwndToolbar);
  103. CTrayItem * GetItemDataByIndex(INT_PTR i)
  104. {
  105. return GetItemData(i, TRUE, m_hwndToolbar);
  106. }
  107. void SetIconList(HIMAGELIST hImageList) { m_himlIcons = hImageList; }
  108. void SetTrayToolbar(HWND hwndToolbar) { m_hwndToolbar = hwndToolbar; }
  109. private:
  110. INT_PTR _GetItemCountHelper(int nItemFlag, int nItemCountThreshold);
  111. HIMAGELIST m_himlIcons;
  112. HWND m_hwndToolbar;
  113. };
  114. #endif // _TRAYITEM_H