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.

242 lines
6.1 KiB

  1. #include "cabinet.h"
  2. #include "taskbar.h"
  3. #include "bandsite.h"
  4. #include "rcids.h"
  5. #include "tray.h"
  6. CSimpleOleWindow::~CSimpleOleWindow()
  7. {
  8. }
  9. CSimpleOleWindow::CSimpleOleWindow(HWND hwnd) : _cRef(1), _hwnd(hwnd)
  10. {
  11. }
  12. ULONG CSimpleOleWindow::AddRef()
  13. {
  14. _cRef++;
  15. return _cRef;
  16. }
  17. ULONG CSimpleOleWindow::Release()
  18. {
  19. ASSERT(_cRef > 0);
  20. _cRef--;
  21. if (_cRef > 0)
  22. return _cRef;
  23. delete this;
  24. return 0;
  25. }
  26. HRESULT CSimpleOleWindow::QueryInterface(REFIID riid, LPVOID * ppvObj)
  27. {
  28. if (IsEqualIID(riid, IID_IUnknown) ||
  29. IsEqualIID(riid, IID_IOleWindow))
  30. {
  31. *ppvObj = SAFECAST(this, IOleWindow*);
  32. }
  33. else
  34. {
  35. *ppvObj = NULL;
  36. return E_NOINTERFACE;
  37. }
  38. AddRef();
  39. return S_OK;
  40. }
  41. HRESULT CSimpleOleWindow::GetWindow(HWND * lphwnd)
  42. {
  43. *lphwnd = _hwnd;
  44. if (_hwnd)
  45. return S_OK;
  46. return E_FAIL;
  47. }
  48. CTaskBar::CTaskBar() : CSimpleOleWindow(v_hwndTray)
  49. {
  50. _fRestrictionsInited = FALSE;
  51. }
  52. HRESULT CTaskBar::QueryInterface(REFIID riid, LPVOID * ppvObj)
  53. {
  54. static const QITAB qit[] =
  55. {
  56. QITABENT(CTaskBar, IContextMenu),
  57. QITABENT(CTaskBar, IServiceProvider),
  58. QITABENT(CTaskBar, IRestrict),
  59. QITABENT(CTaskBar, IDeskBar),
  60. { 0 },
  61. };
  62. HRESULT hres = QISearch(this, qit, riid, ppvObj);
  63. if (FAILED(hres))
  64. {
  65. return CSimpleOleWindow::QueryInterface(riid, ppvObj);
  66. }
  67. return S_OK;
  68. }
  69. HRESULT CTaskBar::InvokeCommand(LPCMINVOKECOMMANDINFO pici)
  70. {
  71. int idCmd = -1;
  72. if (IS_INTRESOURCE(pici->lpVerb))
  73. idCmd = LOWORD(pici->lpVerb);
  74. c_tray.ContextMenuInvoke(idCmd);
  75. return S_OK;
  76. }
  77. HRESULT CTaskBar::GetCommandString(UINT_PTR idCmd,
  78. UINT uType,
  79. UINT * pwReserved,
  80. LPSTR pszName,
  81. UINT cchMax)
  82. {
  83. return E_NOTIMPL;
  84. }
  85. HRESULT CTaskBar::QueryContextMenu(HMENU hmenu,
  86. UINT indexMenu,
  87. UINT idCmdFirst,
  88. UINT idCmdLast,
  89. UINT uFlags)
  90. {
  91. int i = 0;
  92. HMENU hmenuSrc = c_tray.BuildContextMenu(FALSE);
  93. if (hmenuSrc)
  94. {
  95. //
  96. // We know that the tray context menu commands start at IDM_TRAYCONTEXTFIRST, so we
  97. // can get away with passing the same idCmdFirst to each merge.
  98. //
  99. i = Shell_MergeMenus(hmenu, hmenuSrc, indexMenu, idCmdFirst, idCmdLast, MM_ADDSEPARATOR) - idCmdFirst;
  100. DestroyMenu(hmenuSrc);
  101. BandSite_AddMenus(c_tray._ptbs, hmenu, indexMenu, idCmdFirst, idCmdFirst + (IDM_TRAYCONTEXTFIRST - 1));
  102. }
  103. return i;
  104. }
  105. // *** IServiceProvider ***
  106. HRESULT CTaskBar::QueryService(REFGUID guidService, REFIID riid, void **ppvObj)
  107. {
  108. if (ppvObj)
  109. *ppvObj = NULL;
  110. if (IsEqualGUID(guidService, SID_SRestrictionHandler))
  111. {
  112. return QueryInterface(riid, ppvObj);
  113. }
  114. return E_FAIL;
  115. }
  116. // *** IRestrict ***
  117. HRESULT CTaskBar::IsRestricted(const GUID * pguidID, DWORD dwRestrictAction, VARIANT * pvarArgs, DWORD * pdwRestrictionResult)
  118. {
  119. HRESULT hr = S_OK;
  120. if (!EVAL(pguidID) || !EVAL(pdwRestrictionResult))
  121. return E_INVALIDARG;
  122. *pdwRestrictionResult = RR_NOCHANGE;
  123. if (IsEqualGUID(RID_RDeskBars, *pguidID))
  124. {
  125. if (!_fRestrictionsInited)
  126. {
  127. _fRestrictionsInited = TRUE;
  128. if (SHRestricted(REST_NOCLOSE_DRAGDROPBAND))
  129. _fRestrictDDClose = TRUE;
  130. else
  131. _fRestrictDDClose = FALSE;
  132. if (SHRestricted(REST_NOMOVINGBAND))
  133. _fRestrictMove = TRUE;
  134. else
  135. _fRestrictMove = FALSE;
  136. }
  137. switch(dwRestrictAction)
  138. {
  139. case RA_DRAG:
  140. case RA_DROP:
  141. case RA_ADD:
  142. case RA_CLOSE:
  143. if (_fRestrictDDClose)
  144. *pdwRestrictionResult = RR_DISALLOW;
  145. break;
  146. case RA_MOVE:
  147. if (_fRestrictMove)
  148. *pdwRestrictionResult = RR_DISALLOW;
  149. break;
  150. }
  151. }
  152. // TODO: If we have or get a parent, we should ask them if they want to restrict.
  153. // if (RR_NOCHANGE == *pdwRestrictionResult) // If we don't handle it, let our parents have a wack at it.
  154. // hr = IUnknown_HandleIRestrict(_punkParent, pguidID, dwRestrictAction, pvarArgs, pdwRestrictionResult);
  155. return hr;
  156. }
  157. // *** IDeskBar ***
  158. HRESULT CTaskBar::OnPosRectChangeDB(LPRECT prc)
  159. {
  160. // if we haven't fully initialized the tray, don't resize in response to (bogus) rebar sizes
  161. // OR we're in the moving code, don't do this stuff..
  162. if (!c_tray._hbmpStartBkg || c_tray._fDeferedPosRectChange)
  163. {
  164. return S_FALSE;
  165. }
  166. BOOL fHiding = (c_tray._uAutoHide & AH_HIDING);
  167. if (fHiding)
  168. {
  169. c_tray.InvisibleUnhide(FALSE);
  170. }
  171. if ((c_tray._uAutoHide & (AH_ON | AH_HIDING)) != (AH_ON | AH_HIDING))
  172. {
  173. // during 'bottom up' resizes (e.g. isfband View.Large), we don't
  174. // get WM_ENTERSIZEMOVE/WM_EXITSIZEMOVE. so we send it here.
  175. // this fixes two bugs:
  176. // - nt5:168643: btm-of-screen on-top tray mmon clipping not updated
  177. // after view.large
  178. // - nt5:175287: top-of-screen on-top tray doesn't resize workarea
  179. // (obscuring top of 'my computer' icon) after view.large
  180. if (!g_fInSizeMove)
  181. {
  182. c_tray._fSelfSizing = TRUE;
  183. RECT rc;
  184. GetWindowRect(v_hwndTray, &rc);
  185. SendMessage(v_hwndTray, WM_SIZING, WMSZ_TOP, (LPARAM)&rc);
  186. SetWindowPos(v_hwndTray, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER | SWP_NOACTIVATE);
  187. c_tray._fSelfSizing = FALSE;
  188. }
  189. }
  190. if (fHiding)
  191. {
  192. c_tray.InvisibleUnhide(TRUE);
  193. }
  194. return S_OK;
  195. }