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.

345 lines
12 KiB

  1. #ifndef _TRAYNOT_H
  2. #define _TRAYNOT_H
  3. #include "cwndproc.h"
  4. #include <atlstuff.h>
  5. #include "dpa.h"
  6. #include "traycmn.h"
  7. #include "trayitem.h"
  8. #include "trayreg.h"
  9. #define TNM_GETCLOCK (WM_USER + 1)
  10. #define TNM_HIDECLOCK (WM_USER + 2)
  11. #define TNM_TRAYHIDE (WM_USER + 3)
  12. #define TNM_TRAYPOSCHANGED (WM_USER + 4)
  13. #define TNM_ASYNCINFOTIP (WM_USER + 5)
  14. #define TNM_ASYNCINFOTIPPOS (WM_USER + 6)
  15. #define TNM_RUDEAPP (WM_USER + 7)
  16. #define TNM_SAVESTATE (WM_USER + 8)
  17. #define TNM_NOTIFY (WM_USER + 9)
  18. #define TNM_STARTUPAPPSLAUNCHED (WM_USER + 10)
  19. #define TNM_ENABLEUSERTRACKINGINFOTIPS (WM_USER + 11)
  20. #define TNM_BANGICONMESSAGE (WM_USER + 50)
  21. #define TNM_ICONDEMOTETIMER (WM_USER + 61)
  22. #define TNM_INFOTIPTIMER (WM_USER + 62)
  23. #define TNM_UPDATEVERTICAL (WM_USER + 63)
  24. #define TNM_WORKSTATIONLOCKED (WM_USER + 64)
  25. #define TNM_SHOWTRAYBALLOON (WM_USER + 90)
  26. #define UID_CHEVRONBUTTON (-1)
  27. typedef struct
  28. {
  29. HWND hWnd;
  30. UINT uID;
  31. TCHAR szTitle[64];
  32. TCHAR szInfo[256];
  33. UINT uTimeout;
  34. DWORD dwInfoFlags;
  35. } TNINFOITEM;
  36. //
  37. // For Win64 compat, the icon and hwnd are handed around as DWORDs
  38. // (so they won't change size as they travel between 32-bit and
  39. // 64-bit processes).
  40. //
  41. #define GetHIcon(pnid) ((HICON)ULongToPtr(pnid->dwIcon))
  42. #define GetHWnd(pnid) ((HWND)ULongToPtr(pnid->dwWnd))
  43. // Everybody has a copy of this function, so we will too!
  44. STDAPI_(void) ExplorerPlaySound(LPCTSTR pszSound);
  45. // defined in tray.cpp
  46. extern BOOL IsPosInHwnd(LPARAM lParam, HWND hwnd);
  47. // defined in taskband.cpp
  48. extern BOOL ToolBar_IsVisible(HWND hwndToolBar, int iIndex);
  49. typedef enum TRAYEVENT {
  50. TRAYEVENT_ONICONHIDE,
  51. TRAYEVENT_ONICONUNHIDE,
  52. TRAYEVENT_ONICONMODIFY,
  53. TRAYEVENT_ONITEMCLICK,
  54. TRAYEVENT_ONINFOTIP,
  55. TRAYEVENT_ONNEWITEMINSERT,
  56. TRAYEVENT_ONAPPLYUSERPREF,
  57. TRAYEVENT_ONDISABLEAUTOTRAY,
  58. TRAYEVENT_ONICONDEMOTETIMER,
  59. } TRAYEVENT;
  60. typedef enum TRAYITEMPOS {
  61. TIPOS_DEMOTED,
  62. TIPOS_PROMOTED,
  63. TIPOS_ALWAYS_DEMOTED,
  64. TIPOS_ALWAYS_PROMOTED,
  65. TIPOS_HIDDEN,
  66. TIPOS_STATUSQUO,
  67. } TRAYITEMPOS;
  68. typedef enum LASTINFOTIPSTATUS {
  69. LITS_BALLOONNONE,
  70. LITS_BALLOONDESTROYED,
  71. LITS_BALLOONXCLICKED
  72. } LASTINFOTIPSTATUS;
  73. typedef enum BALLOONEVENT {
  74. BALLOONEVENT_USERLEFTCLICK,
  75. BALLOONEVENT_USERRIGHTCLICK,
  76. BALLOONEVENT_USERXCLICK,
  77. BALLOONEVENT_TIMEOUT,
  78. BALLOONEVENT_NONE,
  79. BALLOONEVENT_APPDEMOTE,
  80. BALLOONEVENT_BALLOONHIDE
  81. } BALLOONEVENT;
  82. class CTrayNotify; // forward declaration...
  83. //
  84. // CTrayNotify class members
  85. //
  86. class CTrayNotify : public CImpWndProc
  87. {
  88. public:
  89. CTrayNotify() {};
  90. virtual ~CTrayNotify() {};
  91. // *** IUnknown methods ***
  92. STDMETHODIMP_(ULONG) AddRef();
  93. STDMETHODIMP_(ULONG) Release();
  94. // *** ITrayNotify methods, which are called from the CTrayNotifyStub ***
  95. STDMETHODIMP SetPreference(LPNOTIFYITEM pNotifyItem);
  96. STDMETHODIMP RegisterCallback(INotificationCB* pNotifyCB);
  97. STDMETHODIMP EnableAutoTray(BOOL bTraySetting);
  98. // *** Properties Sheet methods ***
  99. BOOL GetIsNoTrayItemsDisplayPolicyEnabled() const
  100. {
  101. return _fNoTrayItemsDisplayPolicyEnabled;
  102. }
  103. BOOL GetIsNoAutoTrayPolicyEnabled() const
  104. {
  105. return m_TrayItemRegistry.IsNoAutoTrayPolicyEnabled();
  106. }
  107. BOOL GetIsAutoTrayEnabledByUser() const
  108. {
  109. return m_TrayItemRegistry.IsAutoTrayEnabledByUser();
  110. }
  111. // *** Other ***
  112. HWND TrayNotifyCreate(HWND hwndParent, UINT uID, HINSTANCE hInst);
  113. LRESULT TrayNotify(HWND hwndTray, HWND hwndFrom, PCOPYDATASTRUCT pcds, BOOL *pbRefresh);
  114. protected:
  115. static BOOL GetTrayItemCB(INT_PTR nIndex, void *pCallbackData, TRAYCBARG trayCallbackArg,
  116. TRAYCBRET * pOutData);
  117. void _TickleForTooltip(CNotificationItem *pni);
  118. void _UpdateChevronSize();
  119. void _UpdateChevronState(BOOL fBangMenuOpen, BOOL fTrayOrientationChanged, BOOL fUpdateDemotedItems);
  120. void _UpdateVertical(BOOL fVertical);
  121. void _OpenTheme();
  122. void _OnSizeChanged(BOOL fForceRepaint);
  123. // Tray Animation functions
  124. DWORD _GetStepTime(int iStep, int cSteps);
  125. void _ToggleDemotedMenu();
  126. void _BlankButtons(int iPos, int iNumberOfButtons, BOOL fAddButtons);
  127. void _AnimateButtons(int iIndex, DWORD dwSleep, int iNumberItems, BOOL fGrow);
  128. BOOL _SetRedraw(BOOL fRedraw);
  129. // Tray Icon Activation functions
  130. void _HideAllDemotedItems(BOOL bHide);
  131. BOOL _UpdateTrayItems(BOOL bUpdateDemotedItems);
  132. BOOL _PlaceItem(INT_PTR nIcon, CTrayItem * pti, TRAYEVENT tTrayEvent);
  133. TRAYITEMPOS _TrayItemPos(CTrayItem * pti, TRAYEVENT tTrayEvent, BOOL *bDemoteStatusChange);
  134. void _SetOrKillIconDemoteTimer(CTrayItem * pti, TRAYITEMPOS tiPos);
  135. // WndProc callback functions
  136. LRESULT v_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  137. // Callback for the chevron button
  138. static LRESULT CALLBACK ChevronSubClassWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
  139. LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
  140. // Callback for the toolbar
  141. static LRESULT CALLBACK s_ToolbarWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
  142. LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
  143. // Icon Image-related functions
  144. void _RemoveImage(UINT uIMLIndex);
  145. BOOL _CheckAndResizeImages();
  146. // InfoTip/Balloon tip functions
  147. void _ActivateTips(BOOL bActivate);
  148. void _InfoTipMouseClick(int x, int y, BOOL bRightMouseButtonClick);
  149. void _PositionInfoTip();
  150. DWORD _ShowBalloonTip(LPTSTR szTitle, DWORD dwInfoFlags, UINT uTimeout, DWORD dwLastSoundTime);
  151. void _SetInfoTip(HWND hWnd, UINT uID, LPTSTR pszInfo, LPTSTR pszInfoTitle,
  152. DWORD dwInfoFlags, UINT uTimeout, BOOL bAsync);
  153. void _ShowInfoTip(HWND hwnd, UINT uID, BOOL bShow, BOOL bAsync, UINT uReason);
  154. void _ShowChevronInfoTip();
  155. void _EmptyInfoTipQueue();
  156. void _HideBalloonTip();
  157. DWORD _GetBalloonWaitInterval(BALLOONEVENT be);
  158. void _DisableCurrentInfoTip(CTrayItem * ptiTemp, UINT uReason, BOOL bBalloonShowing);
  159. void _RemoveInfoTipFromQueue(HWND hWnd, UINT uID, BOOL bRemoveFirstOnly = FALSE);
  160. BOOL _CanShowBalloon();
  161. BOOL _CanActivateTips()
  162. {
  163. return (!_fInfoTipShowing && !_fItemClicked);
  164. }
  165. BOOL _IsChevronInfoTip(HWND hwnd, UINT uID)
  166. {
  167. return (hwnd == _hwndNotify && uID == UID_CHEVRONBUTTON);
  168. }
  169. void _OnWorkStationLocked(BOOL bLocked);
  170. void _OnRudeApp(BOOL bRudeApp);
  171. // Toolbar Notification helper functions - respond to different user messages
  172. BOOL _InsertNotify(PNOTIFYICONDATA32 pnid);
  173. BOOL _DeleteNotify(INT_PTR nIcon, BOOL bShutdown, BOOL bShouldSaveIcon);
  174. BOOL _ModifyNotify(PNOTIFYICONDATA32 pnid, INT_PTR nIcon, BOOL *pbRefresh, BOOL bFirstTime);
  175. BOOL _SetVersionNotify(PNOTIFYICONDATA32 pnid, INT_PTR nIcon);
  176. LRESULT _SendNotify(CTrayItem *pti, UINT uMsg);
  177. void _SetToolbarHotItem(HWND hWndToolbar, UINT nToolbarIcon);
  178. INT_PTR _GetToolbarFirstVisibleItem(HWND hWndToolbar, BOOL bFromLast);
  179. void _NotifyCallback(DWORD dwMessage, INT_PTR nCurrentItem, INT_PTR nPastItem);
  180. void _SetCursorPos(INT_PTR i);
  181. // Tray registry setting-related functions
  182. void _ToggleTrayItems(BOOL bEnable);
  183. // Initialization/Destroy functions
  184. LRESULT _Create(HWND hWnd);
  185. LRESULT _Destroy();
  186. // Tray repainting helpers
  187. LRESULT _Paint(HDC hdc);
  188. LRESULT _HandleCustomDraw(LPNMCUSTOMDRAW pcd);
  189. void _SizeWindows(int nMaxHorz, int nMaxVert, LPRECT prcTotal, BOOL fSizeWindows);
  190. LRESULT _CalcMinSize(int nMaxHorz, int nMaxVert);
  191. LRESULT _Size();
  192. // Timer/Timer message handling functions
  193. void _OnInfoTipTimer();
  194. LRESULT _OnTimer(UINT_PTR uTimerID);
  195. void _OnIconDemoteTimer(WPARAM wParam, LPARAM lParam);
  196. // Various Message handles
  197. LRESULT _OnMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam);
  198. LRESULT _OnCDNotify(LPNMTBCUSTOMDRAW pnm);
  199. LRESULT _Notify(LPNMHDR pNmhdr);
  200. void _OnSysChange(UINT uMsg, WPARAM wParam, LPARAM lParam);
  201. void _OnCommand(UINT id, UINT uCmd);
  202. BOOL _TrayNotifyIcon(PTRAYNOTIFYDATA pnid, BOOL *pbRefresh);
  203. // User Event Timer functions
  204. HRESULT _SetItemTimer(CTrayItem *pti);
  205. HRESULT _KillItemTimer(CTrayItem *pti);
  206. IUserEventTimer * _CreateTimer(int nTimerFlag);
  207. HRESULT _SetTimer(int nTimerFlag, UINT uCallbackMessage, UINT uTimerInterval, ULONG * puTimerID);
  208. HRESULT _KillTimer(int nTimerFlag, ULONG uTimerID);
  209. BOOL _ShouldDestroyTimer(int nTimerFlag);
  210. UINT _GetAccumulatedTime(CTrayItem * pti);
  211. void _NullifyTimer(int nTimerFlag);
  212. LRESULT _OnKeyDown(WPARAM wChar, LPARAM lFlags);
  213. void _SetUsedTime();
  214. #ifdef DEBUG
  215. void _TestNotify();
  216. #endif
  217. static const TCHAR c_szTrayNotify[] ;
  218. static const WCHAR c_wzTrayNotifyTheme[];
  219. static const WCHAR c_wzTrayNotifyHorizTheme[];
  220. static const WCHAR c_wzTrayNotifyVertTheme[];
  221. static const WCHAR c_wzTrayNotifyHorizOpenTheme[];
  222. static const WCHAR c_wzTrayNotifyVertOpenTheme[];
  223. private:
  224. // Helper/Utility functions
  225. BOOL _IsScreenSaverRunning();
  226. UINT _GetQueueCount();
  227. LONG m_cRef;
  228. HWND _hwndNotify;
  229. HWND _hwndChevron;
  230. HWND _hwndToolbar;
  231. HWND _hwndClock;
  232. HWND _hwndPager;
  233. HWND _hwndInfoTip;
  234. HWND _hwndChevronToolTip;
  235. HWND _hwndToolbarInfoTip;
  236. TCHAR _szExplorerExeName[MAX_PATH];
  237. TCHAR * _pszCurrentThreadDesktopName;
  238. HIMAGELIST _himlIcons;
  239. CTrayItemManager m_TrayItemManager;
  240. CTrayItemRegistry m_TrayItemRegistry;
  241. BOOL _fKey;
  242. BOOL _fReturn;
  243. BOOL _fBangMenuOpen;
  244. BOOL _fHaveDemoted;
  245. BOOL _fAnimating;
  246. BOOL _fAnimateMenuOpen;
  247. BOOL _fRedraw;
  248. BOOL _fRepaint;
  249. BOOL _fChevronSelected;
  250. BOOL _fNoTrayItemsDisplayPolicyEnabled;
  251. BOOL _fHasFocus;
  252. RECT _rcAnimateTotal;
  253. RECT _rcAnimateCurrent;
  254. //
  255. // Timer for icon info tips..
  256. //
  257. ULONG _uInfoTipTimer;
  258. TNINFOITEM *_pinfo; // current balloon being shown
  259. CDPA<TNINFOITEM> _dpaInfo;
  260. BOOL _fInfoTipShowing;
  261. BOOL _fItemClicked;
  262. BOOL _fEnableUserTrackedInfoTips;
  263. HTHEME _hTheme;
  264. int _nMaxHorz;
  265. int _nMaxVert;
  266. // command id of the icon which last received a single down-click
  267. int _idMouseActiveIcon;
  268. INotificationCB * _pNotifyCB;
  269. IUserEventTimer * m_pIconDemoteTimer;
  270. IUserEventTimer * m_pInfoTipTimer;
  271. BOOL _fVertical;
  272. SIZE _szChevron;
  273. BOOL _bStartupIcon;
  274. BOOL _bWorkStationLocked;
  275. BOOL _bRudeAppLaunched; // Includes screensaver...
  276. BOOL _bWaitAfterRudeAppHide;
  277. LASTINFOTIPSTATUS _litsLastInfoTip;
  278. BOOL _bWaitingBetweenBalloons;
  279. BOOL _bStartMenuAllowsTrayBalloon;
  280. BALLOONEVENT _beLastBalloonEvent;
  281. };
  282. #endif // _TRAYNOT_H