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.

216 lines
6.4 KiB

  1. //
  2. // favband.cpp
  3. //
  4. // favorites band implementation
  5. //
  6. #include "priv.h"
  7. #include "sccls.h"
  8. #include "nscband.h"
  9. #include "resource.h"
  10. #include "favorite.h"
  11. #include "uemapp.h" // KMTF: Included for instrumentation
  12. #include <mluisupp.h>
  13. #define SUPERCLASS CNSCBand
  14. #define TF_FAVBAND 0
  15. class CFavBand : public CNSCBand
  16. {
  17. public:
  18. // *** IOleCommandTarget methods ***
  19. virtual STDMETHODIMP Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANTARG *pvarargIn, VARIANTARG *pvarargOut);
  20. // *** IDockingWindow methods ***
  21. virtual STDMETHODIMP ShowDW(BOOL fShow);
  22. protected:
  23. virtual void _AddButtons(BOOL fAdd);
  24. HRESULT _BrowserExec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANTARG *pvarargIn, VARIANTARG *pvarargOut);
  25. void _OrganizeFavorites();
  26. virtual BOOL _ShouldNavigateToPidl(LPCITEMIDLIST pidl, ULONG ulAttrib);
  27. virtual HRESULT _NavigateRightPane(IShellBrowser *psb, LPCITEMIDLIST pidl);
  28. virtual HRESULT _TranslatePidl(LPCITEMIDLIST pidl, LPITEMIDLIST *ppidlTarget, ULONG *pulAttrib);
  29. friend HRESULT CFavBand_CreateInstance(IUnknown *punkOuter, IUnknown **ppunk, LPCOBJECTINFO poi);
  30. BOOL _fStrsAdded;
  31. LONG_PTR _lStrOffset;
  32. };
  33. HRESULT CFavBand::_BrowserExec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANTARG *pvarargIn, VARIANTARG *pvarargOut)
  34. {
  35. return IUnknown_QueryServiceExec(_punkSite, SID_STopLevelBrowser, pguidCmdGroup, nCmdID, nCmdexecopt, pvarargIn, pvarargOut);
  36. }
  37. void CFavBand::_OrganizeFavorites()
  38. {
  39. DoOrganizeFavDlgW(_hwnd, NULL);
  40. }
  41. // *** IOleCommandTarget methods ***
  42. HRESULT CFavBand::Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANTARG *pvarargIn, VARIANTARG *pvarargOut)
  43. {
  44. if (pguidCmdGroup && IsEqualGUID(CLSID_FavBand, *pguidCmdGroup))
  45. {
  46. TraceMsg(TF_FAVBAND, "CFavBand::Exec CLSID_FavBand -- nCmdID == %x", nCmdID);
  47. switch(nCmdID)
  48. {
  49. case FCIDM_ADDTOFAVORITES:
  50. {
  51. _BrowserExec(&CGID_Explorer, SBCMDID_ADDTOFAVORITES, OLECMDEXECOPT_PROMPTUSER, NULL, NULL);
  52. // Instrument addition to favorites by pane
  53. UEMFireEvent(&UEMIID_BROWSER, UEME_INSTRBROWSER, UEMF_INSTRUMENT, UIBW_ADDTOFAV, UIBL_PANE);
  54. return S_OK;
  55. }
  56. case FCIDM_ORGANIZEFAVORITES:
  57. {
  58. _OrganizeFavorites();
  59. return S_OK;
  60. }
  61. }
  62. }
  63. return SUPERCLASS::Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvarargIn, pvarargOut);
  64. }
  65. static const TBBUTTON c_tbFavorites[] =
  66. {
  67. { 0, FCIDM_ADDTOFAVORITES, TBSTATE_ENABLED, BTNS_AUTOSIZE | BTNS_SHOWTEXT, {0,0}, 0, 0 },
  68. { 1, FCIDM_ORGANIZEFAVORITES, TBSTATE_ENABLED, BTNS_AUTOSIZE | BTNS_SHOWTEXT, {0,0}, 0, 1 },
  69. };
  70. void CFavBand::_AddButtons(BOOL fAdd)
  71. {
  72. IExplorerToolbar* piet;
  73. if (SUCCEEDED(_punkSite->QueryInterface(IID_IExplorerToolbar, (void**)&piet)))
  74. {
  75. if (fAdd)
  76. {
  77. piet->SetCommandTarget((IUnknown*)SAFECAST(this, IOleCommandTarget*), &CLSID_FavBand, 0);
  78. if (!_fStrsAdded)
  79. {
  80. piet->AddString(&CLSID_FavBand, MLGetHinst(), IDS_FAVS_BAR_LABELS, &_lStrOffset);
  81. _fStrsAdded = TRUE;
  82. }
  83. _EnsureImageListsLoaded();
  84. piet->SetImageList(&CLSID_FavBand, _himlNormal, _himlHot, NULL);
  85. TBBUTTON tbFavorites[ARRAYSIZE(c_tbFavorites)];
  86. memcpy(tbFavorites, c_tbFavorites, SIZEOF(TBBUTTON) * ARRAYSIZE(c_tbFavorites));
  87. for (int i = 0; i < ARRAYSIZE(c_tbFavorites); i++)
  88. tbFavorites[i].iString += (long) _lStrOffset;
  89. piet->AddButtons(&CLSID_FavBand, ARRAYSIZE(tbFavorites), tbFavorites);
  90. }
  91. else
  92. piet->SetCommandTarget(NULL, NULL, 0);
  93. piet->Release();
  94. }
  95. }
  96. // *** IDockingWindow methods ***
  97. HRESULT CFavBand::ShowDW(BOOL fShow)
  98. {
  99. HRESULT hres = SUPERCLASS::ShowDW(fShow);
  100. _AddButtons(fShow);
  101. return hres;
  102. }
  103. HRESULT CFavBand_CreateInstance(IUnknown *punkOuter, IUnknown **ppunk, LPCOBJECTINFO poi)
  104. {
  105. // aggregation checking is handled in class factory
  106. CFavBand * pfb = new CFavBand();
  107. if (!pfb)
  108. return E_OUTOFMEMORY;
  109. if (SUCCEEDED(pfb->_Init((LPCITEMIDLIST)CSIDL_FAVORITES)))
  110. {
  111. pfb->_pns = CNscTree_CreateInstance();
  112. if (pfb->_pns)
  113. {
  114. ASSERT(poi);
  115. pfb->_poi = poi;
  116. // if you change this cast, fix up CChannelBand_CreateInstance
  117. *ppunk = SAFECAST(pfb, IDeskBand *);
  118. IUnknown_SetSite(pfb->_pns, *ppunk);
  119. pfb->_SetNscMode(MODE_FAVORITES);
  120. return S_OK;
  121. }
  122. }
  123. pfb->Release();
  124. return E_FAIL;
  125. }
  126. HRESULT CFavBand::_TranslatePidl(LPCITEMIDLIST pidl, LPITEMIDLIST *ppidlTarget, ULONG *pulAttrib)
  127. {
  128. HRESULT hr = E_INVALIDARG;
  129. if (pidl && ppidlTarget && pulAttrib)
  130. {
  131. hr = IEGetAttributesOf(pidl, pulAttrib);
  132. if (SUCCEEDED(hr))
  133. {
  134. hr = SHILClone(pidl, ppidlTarget);
  135. }
  136. }
  137. return hr;
  138. }
  139. BOOL CFavBand::_ShouldNavigateToPidl(LPCITEMIDLIST pidl, ULONG ulAttrib)
  140. {
  141. return !(ulAttrib & SFGAO_FOLDER);
  142. }
  143. HRESULT CFavBand::_NavigateRightPane(IShellBrowser *psb, LPCITEMIDLIST pidl)
  144. {
  145. HRESULT hr = E_INVALIDARG;
  146. if (psb && pidl)
  147. {
  148. TCHAR szPath[MAX_PATH];
  149. hr = SHGetNameAndFlags(pidl, SHGDN_FORPARSING, szPath, ARRAYSIZE(szPath), NULL);
  150. if (SUCCEEDED(hr))
  151. {
  152. hr = NavFrameWithFile(szPath, psb);
  153. if (FAILED(hr))
  154. {
  155. IShellFolder *psf;
  156. LPCITEMIDLIST pidlLast;
  157. if (SUCCEEDED(SHBindToIDListParent(pidl, IID_PPV_ARG(IShellFolder, &psf), &pidlLast)))
  158. {
  159. LPITEMIDLIST pidlTarget;
  160. if (SUCCEEDED(SHGetNavigateTarget(psf, pidlLast, &pidlTarget, NULL)))
  161. {
  162. hr = psb->BrowseObject(pidlTarget, SBSP_SAMEBROWSER);
  163. ILFree(pidlTarget);
  164. }
  165. psf->Release();
  166. }
  167. }
  168. if (SUCCEEDED(hr))
  169. {
  170. UEMFireEvent(&UEMIID_BROWSER, UEME_INSTRBROWSER, UEMF_INSTRUMENT, UIBW_NAVIGATE, UIBL_NAVFAVS);
  171. UEMFireEvent(&UEMIID_BROWSER, UEME_RUNPIDL, UEMF_XEVENT, (WPARAM)NULL, (LPARAM)pidl);
  172. SHSendChangeMenuNotify(NULL, SHCNEE_PROMOTEDITEM, 0, pidl);
  173. }
  174. }
  175. }
  176. return hr;
  177. }