Source code of Windows XP (NT5)
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.

335 lines
12 KiB

  1. #ifndef TASKBAND_H_
  2. #define TASKBAND_H_
  3. #ifdef __cplusplus
  4. #include "atlstuff.h"
  5. #include "cwndproc.h"
  6. #include <dpa.h>
  7. #include "commoncontrols.h"
  8. class CTray;
  9. class CGroupItemContextMenu;
  10. class TASKITEM
  11. {
  12. public:
  13. TASKITEM() {};
  14. TASKITEM(TASKITEM* pti);
  15. ~TASKITEM();
  16. HWND hwnd; // NULL if this item is a group of application entries
  17. DWORD dwFlags;
  18. class TaskShortcut *ptsh;
  19. DWORD dwTimeLastClicked;
  20. DWORD dwTimeFirstOpened;
  21. WCHAR* pszExeName;
  22. int iIconPref;
  23. BOOL fMarkedFullscreen;
  24. BOOL fHungApp;
  25. };
  26. typedef TASKITEM *PTASKITEM;
  27. typedef struct
  28. {
  29. PTASKITEM pti;
  30. UINT fState;
  31. int iIndex; // used to cache toolbar index
  32. }
  33. ANIMATIONITEMINFO, *PANIMATIONITEMINFO;
  34. class CTaskBandSMC;
  35. class CTaskBand : public IDeskBand
  36. , public IObjectWithSite
  37. , public IDropTarget
  38. , public IInputObject
  39. , public IPersistStream
  40. , public IWinEventHandler
  41. , public IOleCommandTarget
  42. , public CImpWndProc
  43. {
  44. public:
  45. // *** IUnknown methods ***
  46. STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  47. STDMETHODIMP_(ULONG) AddRef();
  48. STDMETHODIMP_(ULONG) Release();
  49. // *** IOleWindow methods ***
  50. STDMETHODIMP GetWindow(HWND * lphwnd);
  51. STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode) { return E_NOTIMPL; }
  52. // *** IDockingWindow methods ***
  53. STDMETHODIMP ShowDW(BOOL fShow) { return S_OK; }
  54. STDMETHODIMP CloseDW(DWORD dwReserved) { return S_OK; }
  55. STDMETHODIMP ResizeBorderDW(LPCRECT prcBorder, IUnknown* punkToolbarSite, BOOL fReserved) { return E_NOTIMPL; }
  56. // *** IObjectWithSite methods ***
  57. STDMETHODIMP SetSite(IUnknown* punkSite);
  58. STDMETHODIMP GetSite(REFIID riid, void** ppvSite) { return E_NOTIMPL; };
  59. // *** IDeskBand methods ***
  60. STDMETHODIMP GetBandInfo(DWORD dwBandID, DWORD fViewMode, DESKBANDINFO* pdbi);
  61. // *** IDropTarget methods ***
  62. STDMETHODIMP DragEnter(IDataObject *pdtobj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
  63. STDMETHODIMP DragOver(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
  64. STDMETHODIMP DragLeave(void);
  65. STDMETHODIMP Drop(IDataObject *pdtobj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
  66. // *** IInputObject methods ***
  67. STDMETHODIMP TranslateAcceleratorIO(LPMSG lpMsg) { return E_NOTIMPL; }
  68. STDMETHODIMP HasFocusIO();
  69. STDMETHODIMP UIActivateIO(BOOL fActivate, LPMSG lpMsg);
  70. // *** IWinEventHandler methods ***
  71. STDMETHODIMP OnWinEvent(HWND hwnd, UINT dwMsg, WPARAM wParam, LPARAM lParam, LRESULT* plres);
  72. STDMETHODIMP IsWindowOwner(HWND hwnd);
  73. // *** IPersistStream methods ***
  74. STDMETHODIMP GetClassID(LPCLSID pClassID);
  75. STDMETHODIMP IsDirty(void) { return S_FALSE; }
  76. STDMETHODIMP Load(IStream *ps);
  77. STDMETHODIMP Save(LPSTREAM, BOOL) { return S_OK; }
  78. STDMETHODIMP GetSizeMax(ULARGE_INTEGER*) { return E_NOTIMPL; }
  79. // *** IOleCommandTarget methods ***
  80. STDMETHODIMP QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD rgCmds[], OLECMDTEXT *pcmdtext);
  81. STDMETHODIMP Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANTARG *pvarargIn, VARIANTARG *pvarargOut);
  82. protected:
  83. static void IconAsyncProc(HWND hwnd, UINT uMsg, ULONG_PTR dwData, LRESULT lResult);
  84. typedef struct
  85. {
  86. HWND hwnd;
  87. LPTSTR pszExeName;
  88. int iImage;
  89. }
  90. ICONCBPARAM, *PICONCBPARAM;
  91. typedef int (*PICONCALLBACK)(CTaskBand* ptb, PICONCBPARAM pip, LPARAM lParam, int iPref);
  92. static int GetIconCB(CTaskBand* ptb, PICONCBPARAM pip, LPARAM lParam, int iPref);
  93. static int GetSHILIconCB(CTaskBand* ptb, PICONCBPARAM pip, LPARAM lParam, int);
  94. static int GetDefaultIconCB(CTaskBand* ptb, PICONCBPARAM pip, LPARAM, int);
  95. static int GetClassIconCB(CTaskBand* ptb, PICONCBPARAM pip, LPARAM lParam, int);
  96. void _MoveGroup(HWND hwnd, WCHAR* szNewExeName);
  97. void _SetWindowIcon(HWND hwnd, HICON hicon, int iPref);
  98. static BOOL _ShouldMinimize(HWND hwnd);
  99. BOOL _CanMinimizeAll();
  100. BOOL _MinimizeAll(HWND hwndTray, BOOL fPostRaiseDesktop);
  101. int _HitTest(POINTL ptl);
  102. void _FreePopupMenu();
  103. void _RealityCheck();
  104. int _FindIndexByHwnd(HWND hwnd);
  105. void _CheckNeedScrollbars(int cyRow, int cItems, int iCols, int iRows,
  106. int iItemWidth, LPRECT lprcView);
  107. void _NukeScrollbar(int fnBar);
  108. void _SetItemWidth(int iItem, int iWidth);
  109. int _GetItemWidth(int iItem);
  110. int _GetLastVisibleItem();
  111. int _GetVisibleItemCount();
  112. int _GetGroupWidth(int iIndexGroup);
  113. int _GetIdealWidth(int *iRemainder);
  114. void _GetNumberOfRowsCols(int* piRows, int* piCols, BOOL fCurrentSize);
  115. int _GetTextSpace();
  116. void _GetToolbarMetrics(LPTBMETRICS ptbm);
  117. void _CheckSize(void);
  118. void _SizeItems(int iButtonWidth, int iRemainder = 0);
  119. BOOL _AddWindow(HWND hwnd);
  120. BOOL _CheckButton(int iIndex, BOOL fCheck);
  121. BOOL _IsButtonChecked(int iIndex);
  122. int _GetCurSel();
  123. void _SetCurSel(int iIndex, BOOL fIgnoreCtrlKey);
  124. int _SelectWindow(HWND hwnd);
  125. void _SwitchToWindow(HWND hwnd);
  126. int _GetSelectedItems(CDSA<PTASKITEM>* pdsa);
  127. int _GetGroupItems(int iIndexGroup, CDSA<PTASKITEM>* pdsa);
  128. void _OnGroupCommand(int iRet, CDSA<PTASKITEM>* pdsa);
  129. void _SysMenuForItem(int i, int x, int y);
  130. static void CALLBACK FakeSystemMenuCB(HWND hwnd, UINT uMsg, ULONG_PTR dwData, LRESULT lres);
  131. HWND _CreateFakeWindow(HWND hwndOwner);
  132. void _HandleSysMenuTimeout();
  133. void _HandleSysMenu(HWND hwnd);
  134. void _FakeSystemMenu(HWND hwndTask, DWORD dwPos);
  135. BOOL _ContextMenu(DWORD dwPos);
  136. void _HandleCommand(WORD wCmd, WORD wID, HWND hwnd);
  137. void _DrawNumber(HDC hdc, int iValue, BOOL fCalcRect, LPRECT prc);
  138. LRESULT _HandleCustomDraw(LPNMTBCUSTOMDRAW ptbcd, PTASKITEM pti = NULL);
  139. void _RemoveImage(int iImage);
  140. void _OnButtonPressed(int iIndex, PTASKITEM pti, BOOL fForceRestore);
  141. LRESULT _HandleNotify(LPNMHDR lpnm);
  142. void _SwitchToItem(int iItem, HWND hwnd, BOOL fIgnoreCtrlKey);
  143. LRESULT _HandleCreate();
  144. LRESULT _HandleDestroy();
  145. LRESULT _HandleScroll(BOOL fHoriz, UINT code, int nPos);
  146. void _ScrollIntoView(int iItem);
  147. LRESULT _HandleSize(WPARAM fwSizeType);
  148. LRESULT _HandleActivate(HWND hwndActive);
  149. void _UpdateItemUsage(PTASKITEM pti);
  150. void _HandleOtherWindowDestroyed(HWND hwndDestroyed);
  151. void _HandleGetMinRect(HWND hwndShell, LPPOINTS lprc);
  152. void _HandleChangeNotify(WPARAM wParam, LPARAM lParam);
  153. LRESULT _HandleHardError(HARDERRORDATA *phed, DWORD cbData);
  154. BOOL _IsItemActive(HWND hwndActive);
  155. void _CreateTBImageLists();
  156. int _AddIconToNormalImageList(HICON hicon, int iImage);
  157. void _UpdateItemText(int iItem);
  158. void _UpdateItemIcon(int iItem);
  159. void _GetDispInfo(LPNMTBDISPINFO lptbdi);
  160. void _DoRedrawWhereNeeded();
  161. void _RedrawItem(HWND hwndShell, WPARAM code, int i = -1);
  162. void _SetActiveAlt(HWND hwndAlt);
  163. HWND _EnumForRudeWindow(HWND hwndSelected);
  164. HWND _FindRudeApp(HWND hwndPossible);
  165. LRESULT _OnAppCommand(int cmd);
  166. PTASKITEM _FindItemByHwnd(HWND hwnd);
  167. void _OnWindowActivated(HWND hwnd, BOOL fSuspectFullscreen);
  168. LRESULT _HandleShellHook(int iCode, LPARAM lParam);
  169. void _VerifyButtonHeight();
  170. void _InitFonts();
  171. void _SetItemImage(int iItem, int iImage, int iPref);
  172. void _UpdateAllIcons();
  173. LRESULT _HandleWinIniChange(WPARAM wParam, LPARAM lParam, BOOL fOnCreate);
  174. void _OnSetFocus();
  175. BOOL _RegisterWindowClass();
  176. void _UpdateFlashingFlag();
  177. void _ExecuteMenuOption(HWND hwnd, int iCmd);
  178. TASKITEM* _GetItem(int i, TBBUTTONINFO* ptbb = NULL, BOOL fByIndex = TRUE);
  179. static BOOL WINAPI BuildEnumProc(HWND hwnd, LPARAM lParam);
  180. static BOOL WINAPI IsRudeEnumProc(HWND hwnd, LPARAM lParam);
  181. static DWORD WINAPI MinimizeAllThreadProc(LPVOID lpv);
  182. void _OpenTheme();
  183. virtual LRESULT v_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  184. int _GetGroupSize(int iIndexGroup);
  185. int _GetGroupIndex(int iIndexApp);
  186. DWORD _GetGroupAge(int iIndexGroup);
  187. int _GetGroupIndexFromExeName(WCHAR* szExeName);
  188. BOOL _IsHidden(int i);
  189. void _GetItemTitle(int iIndex, WCHAR* pszTitle, int cbTitle, BOOL fCustom);
  190. void _RefreshSettings();
  191. void _LoadSettings();
  192. void _Glom(int iIndexGroup, BOOL fGlom);
  193. void _HideGroup(int iIndexGroup, BOOL fHide);
  194. BOOL _AutoGlomGroup(BOOL fGlom, int iOpenSlots);
  195. void _DeleteTaskItem(int index, BOOL fDeletePTI);
  196. void _RealityCheckGroup(PTASKITEM pti);
  197. HRESULT _CreatePopupMenu(POINTL* ppt, RECTL* prcl);
  198. void _AddItemToDropDown(int iIndex);
  199. void _RemoveItemFromDropDown(int iIndex);
  200. void _RefreshItemFromDropDown(int iIndex, int iNewIndex, BOOL fRefresh);
  201. void _ClosePopupMenus();
  202. void _HandleDropDown(int index);
  203. void _UpdateProgramCount();
  204. BOOL _AddToTaskbar(PTASKITEM pti, int indexTaskbar, BOOL fVisible, BOOL fForceGetIcon);
  205. BOOL _InsertItem(HWND hwndTask, PTASKITEM ptiOveride = NULL, BOOL fForceGetIcon = FALSE);
  206. void _DeleteItem(HWND hWnd, int index = -1);
  207. void _AttachTaskShortcut(PTASKITEM pti, LPCTSTR pszExeName);
  208. void _ReattachTaskShortcut();
  209. void _BuildTaskList(CDPA<TASKITEM>* pDPA);
  210. // *** Async-Animation
  211. BOOL _fAnimate;
  212. CDSA<ANIMATIONITEMINFO> _dsaAII;
  213. // animation methods
  214. BOOL _AnimateItems(int iIndex, BOOL fExpand, BOOL fGlomAnimation);
  215. void _AsyncAnimateItems();
  216. void _ResizeAnimationItems();
  217. int _CheckAnimationSize();
  218. void _SizeNonAnimatingItems();
  219. // animation helpers
  220. void _UpdateAnimationIndices();
  221. void _UpdateAnimationIndicesSlow();
  222. int _FindItem(PTASKITEM pti);
  223. void _RemoveItemFromAnimationList(PTASKITEM ptiRemove);
  224. void _SetAnimationState(PANIMATIONITEMINFO paii, BOOL fExpand, BOOL fGlomAnimation);
  225. int _GetAnimationInsertPos(int iIndex);
  226. void _SetAnimationItemWidth(PANIMATIONITEMINFO paii, int cxStep);
  227. int _GetAnimationDistLeft(PANIMATIONITEMINFO paii, int iNormalWidth);
  228. void _FinishAnimation(PANIMATIONITEMINFO paii);
  229. int _GetAnimationWidth();
  230. int _GetAnimationStep();
  231. DWORD _GetStepTime(int iStep);
  232. int _GetCurButtonHeight();
  233. void _SetThreadPriority(int iPriority, DWORD dwWakeupTime);
  234. void _RestoreThreadPriority();
  235. BOOL _IsHorizontal() { return !(_dwViewMode & DBIF_VIEWMODE_VERTICAL); }
  236. BOOL _fGlom;
  237. int _iGroupSize;
  238. CToolBarCtrl _tb;
  239. UINT WM_ShellHook;
  240. int _iSysMenuCount;
  241. int _iIndexActiveAtLDown;
  242. HWND _hwndSysMenu;
  243. HWND _hwndLastRude;
  244. HWND _hwndPrevFocus;
  245. HWND _hwndReplacing;
  246. BOOL _fIgnoreTaskbarActivate;
  247. BOOL _fFlashing;
  248. BOOL _fDenyHotItemChange;
  249. CTray* _ptray;
  250. HFONT _hfontSave;
  251. int _iTextSpace;
  252. DWORD _dwPos;
  253. DWORD _dwViewMode;
  254. HFONT _hfontCapNormal;
  255. HFONT _hfontCapBold;
  256. HTHEME _hTheme;
  257. int _iOldPriority;
  258. int _iNewPriority;
  259. ULONG _cRef;
  260. // Drag & drop stuff
  261. int _iDropItem;
  262. DWORD _dwTriggerStart;
  263. DWORD _dwTriggerDelay;
  264. // Variables for the ASYNC popup menu
  265. IShellMenu2* _psmPopup;
  266. IMenuPopup* _pmpPopup;
  267. IMenuBand* _pmbPopup;
  268. int _iIndexPopup;
  269. int _iIndexLastPopup;
  270. CMenu _menuPopup;
  271. IImageList* _pimlSHIL;
  272. // Rarely-used stuff
  273. ULONG _uShortcutInvokeNotify;
  274. UINT _uCDHardError;
  275. CTaskBand();
  276. ~CTaskBand();
  277. HRESULT Init(CTray* ptray);
  278. HRESULT _BandInfoChanged();
  279. DWORD _dwBandID;
  280. IUnknown * _punkSite;
  281. friend HRESULT CTaskBand_CreateInstance(IUnknown* punkOuter, IUnknown** ppunk);
  282. friend class CTaskBandSMC;
  283. };
  284. #endif // __cplusplus
  285. #endif //TASKBAND_H_