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.

3374 lines
105 KiB

  1. #include "shellprv.h"
  2. #include "common.h"
  3. #include "menuband.h"
  4. #include "dpastuff.h" // COrderList_*
  5. #include "resource.h"
  6. #include "mnbase.h"
  7. #include "oleacc.h"
  8. #include "mnfolder.h"
  9. #include "icotask.h"
  10. #include "util.h"
  11. #include <uxtheme.h>
  12. #define PGMP_RECALCSIZE 200
  13. HRESULT IUnknown_RefreshParent(IUnknown* punk, LPCITEMIDLIST pidl, DWORD dwFlags)
  14. {
  15. IShellMenu* psm;
  16. HRESULT hr = IUnknown_QueryService(punk, SID_SMenuBandParent, IID_PPV_ARG(IShellMenu, &psm));
  17. if (SUCCEEDED(hr))
  18. {
  19. LPITEMIDLIST pidlParent = ILClone(pidl);
  20. if (pidlParent)
  21. {
  22. SMDATA smd;
  23. ILRemoveLastID(pidlParent);
  24. smd.dwMask = SMDM_SHELLFOLDER;
  25. smd.pidlFolder = pidlParent;
  26. smd.pidlItem = ILFindLastID(pidl);
  27. hr = psm->InvalidateItem(&smd, dwFlags);
  28. ILFree(pidlParent);
  29. }
  30. psm->Release();
  31. }
  32. return hr;
  33. }
  34. void CMenuData::SetSubMenu(IUnknown* punk)
  35. {
  36. ATOMICRELEASE(_punkSubmenu);
  37. _punkSubmenu = punk;
  38. if (_punkSubmenu)
  39. _punkSubmenu->AddRef();
  40. }
  41. HRESULT CMenuData::GetSubMenu(const GUID* pguidService, REFIID riid, void** ppv)
  42. {
  43. // pguidService is for asking specifically for the Shell Folder portion or the Static portion
  44. if (_punkSubmenu)
  45. {
  46. if (pguidService)
  47. {
  48. return IUnknown_QueryService(_punkSubmenu, *pguidService, riid, ppv);
  49. }
  50. else
  51. return _punkSubmenu->QueryInterface(riid, ppv);
  52. }
  53. else
  54. return E_NOINTERFACE;
  55. }
  56. CMenuData::~CMenuData()
  57. {
  58. ATOMICRELEASE(_punkSubmenu);
  59. }
  60. STDMETHODIMP CMenuSFToolbar::QueryInterface(REFIID riid, void** ppvObj)
  61. {
  62. HRESULT hr = CMenuToolbarBase::QueryInterface(riid, ppvObj);
  63. if (FAILED(hr))
  64. hr = CSFToolbar::QueryInterface(riid, ppvObj);
  65. return hr;
  66. }
  67. //-------------------------------------------------------------------------
  68. //
  69. // CMenuSFToolbar class
  70. //
  71. //-------------------------------------------------------------------------
  72. #define SENTINEL_EMPTY 0
  73. #define SENTINEL_CHEVRON 1
  74. #define SENTINEL_SEP 2
  75. #define PIDLSENTINEL(i) ((LPCITEMIDLIST)MAKEINTRESOURCE(i))
  76. #define POISENTINEL(i) ((PORDERITEM) MAKEINTRESOURCE(i))
  77. STDMETHODIMP CMenuSFToolbar::SetSite(IUnknown* punkSite)
  78. {
  79. HRESULT hr = CMenuToolbarBase::SetSite(punkSite);
  80. if (SUCCEEDED(hr))
  81. {
  82. _fMulticolumnMB = BOOLIFY(_pcmb->_dwFlags & SMINIT_MULTICOLUMN);
  83. _fMulticolumn = _fMulticolumnMB;
  84. _fVertical = _fVerticalMB;
  85. if (_fVerticalMB)
  86. _dwStyle |= CCS_VERT;
  87. }
  88. return hr;
  89. }
  90. CMenuSFToolbar::CMenuSFToolbar(CMenuBand* pmb, IShellFolder* psf, LPCITEMIDLIST pidl, HKEY hKey, DWORD dwFlags)
  91. : CMenuToolbarBase(pmb, dwFlags)
  92. , _idCmdSep(-1)
  93. {
  94. // Change this to IStream
  95. _hKey = hKey;
  96. // Do we have a place to persist our reorder?
  97. if (_hKey == NULL)
  98. {
  99. // No, then don't allow it.
  100. _fAllowReorder = FALSE;
  101. }
  102. _dwStyle |= TBSTYLE_REGISTERDROP;
  103. _dwStyle &= ~TBSTYLE_TOOLTIPS; // We handle our own tooltips.
  104. _iDefaultIconIndex = -1;
  105. SetShellFolder(psf, pidl);
  106. _AfterLoad();
  107. }
  108. HRESULT CMenuSFToolbar::SetShellFolder(IShellFolder* psf, LPCITEMIDLIST pidl)
  109. {
  110. HRESULT hr = CSFToolbar::SetShellFolder(psf, pidl);
  111. ATOMICRELEASE(_pasf2);
  112. if (psf)
  113. psf->QueryInterface(IID_PPV_ARG(IAugmentedShellFolder2, &_pasf2));
  114. if (!_pasf2)
  115. {
  116. // SMSET_SEPARATEMERGEFOLDER requires IAugmentedShellFolder2 support
  117. _dwFlags &= ~SMSET_SEPARATEMERGEFOLDER;
  118. }
  119. if (_dwFlags & SMSET_SEPARATEMERGEFOLDER)
  120. {
  121. // Remember the namespace GUID of the one to highlight
  122. DWORD dwNSId;
  123. if (SUCCEEDED(_pasf2->EnumNameSpace(0, &dwNSId)))
  124. {
  125. _pasf2->QueryNameSpace(dwNSId, &_guidAboveSep, NULL);
  126. }
  127. }
  128. return hr;
  129. }
  130. CMenuSFToolbar::~CMenuSFToolbar()
  131. {
  132. ASSERT(_pcmb->_cRef == 0 || _pcmb->_pmtbShellFolder == NULL);
  133. _hwndWorkerWindow = NULL; // This is destroyed by the _pmbState destructor.
  134. // Prevent a double delete which happens in the base class.
  135. ATOMICRELEASE(_pasf2);
  136. if (_hKey)
  137. RegCloseKey(_hKey);
  138. }
  139. void CMenuSFToolbar::v_Close()
  140. {
  141. CMenuToolbarBase::EmptyToolbar();
  142. _UnregisterToolbar();
  143. if (_hwndPager)
  144. {
  145. DestroyWindow(_hwndPager); // Should Destroy Toolbar.
  146. }
  147. else if (_hwndMB)
  148. {
  149. // In the MultiColumn case, there is no pager so we have to
  150. // manually destroy the Toolbar
  151. DestroyWindow(_hwndMB);
  152. }
  153. _hwndPager = NULL;
  154. _hwndMB = NULL;
  155. _hwndTB = NULL;
  156. }
  157. PIBDATA CMenuSFToolbar::_CreateItemData(PORDERITEM poi)
  158. {
  159. return (PIBDATA)new CMenuData(poi);
  160. }
  161. HRESULT CMenuSFToolbar::_AfterLoad()
  162. {
  163. HRESULT hr = CSFToolbar::_AfterLoad();
  164. if (SUCCEEDED(hr))
  165. _LoadOrderStream();
  166. return hr;
  167. }
  168. HRESULT CMenuSFToolbar::_LoadOrderStream()
  169. {
  170. OrderList_Destroy(&_hdpaOrder);
  171. IStream* pstm;
  172. HRESULT hr = E_FAIL;
  173. if (_hKey)
  174. {
  175. // We use "Menu" for Backwards compatibility with shdoc401 start menu, but having no
  176. // sub key is more correct (Other places use it) so on NT5 we use the new method.
  177. pstm = SHOpenRegStream(_hKey, (_pcmb->_dwFlags & SMINIT_LEGACYMENU) ? TEXT("Menu") : TEXT(""),
  178. TEXT("Order"), STGM_READ);
  179. }
  180. else
  181. {
  182. if (S_FALSE == CallCB(NULL, SMC_GETSFOBJECT, (WPARAM)(GUID*)&IID_IStream, (LPARAM)(void**)&pstm))
  183. pstm = NULL;
  184. }
  185. if (pstm)
  186. {
  187. hr = OrderList_LoadFromStream(pstm, &_hdpaOrder, _psf);
  188. _fHasOrder = FALSE;
  189. _fAllowReorder = TRUE;
  190. // Check to see if we have a persisted order. If we don't have a persisted order,
  191. // then all of the items are -1. If just one of those has a number other than
  192. // -1, then we do have "Order" and should use that instead of alphabetizing.
  193. if (_hdpaOrder)
  194. {
  195. for (int i = 0; !_fHasOrder && i < DPA_GetPtrCount(_hdpaOrder); i++)
  196. {
  197. PORDERITEM poi = (PORDERITEM)DPA_FastGetPtr(_hdpaOrder, i);
  198. if (poi->nOrder != MNFOLDER_NORODER)
  199. _fHasOrder = TRUE;
  200. }
  201. }
  202. pstm->Release();
  203. }
  204. return hr;
  205. }
  206. HRESULT CMenuSFToolbar::_SaveOrderStream()
  207. {
  208. IStream* pstm;
  209. HRESULT hr = E_FAIL;
  210. // Persist the new order out to the registry
  211. // It is reasonable to assume that if we don't have an _hdpa we have
  212. // not filled the toolbar yet. Since we have not filled it, we haven't changed
  213. // the order, so we don't need to persist out that order information.
  214. if (_hdpa)
  215. {
  216. // Always save this information
  217. _FindMinPromotedItems(TRUE);
  218. // Did we load an order stream when we initialized this pane?
  219. if (!_fHasOrder)
  220. {
  221. // No; Then we do not want to persist the order. We will initialize
  222. // all of the order items to -1. This is backward compatible because
  223. // IE 4 will merge alphabetically, but revert to a persited order when saving.
  224. for (int i = 0; i < DPA_GetPtrCount(_hdpa); i++)
  225. {
  226. PORDERITEM poi = (PORDERITEM)DPA_FastGetPtr(_hdpa, i);
  227. poi->nOrder = MNFOLDER_NORODER;
  228. }
  229. }
  230. if (_hKey)
  231. {
  232. pstm = SHOpenRegStream(_hKey, (_pcmb->_dwFlags & SMINIT_LEGACYMENU) ? TEXT("Menu") : TEXT(""),
  233. TEXT("Order"), STGM_CREATE | STGM_WRITE);
  234. }
  235. else
  236. {
  237. if (S_OK != CallCB(NULL, SMC_GETSFOBJECT, (WPARAM)(GUID*)&IID_IStream, (LPARAM)(void**)&pstm))
  238. pstm = NULL;
  239. }
  240. if (pstm)
  241. {
  242. hr = OrderList_SaveToStream(pstm, _hdpaOrder ? _hdpaOrder : _hdpa, _psf);
  243. if (SUCCEEDED(hr))
  244. {
  245. CallCB(NULL, SMC_SETSFOBJECT, (WPARAM)(GUID*)&IID_IStream, (LPARAM)(void**)&pstm);
  246. }
  247. pstm->Release();
  248. }
  249. }
  250. if (SUCCEEDED(hr))
  251. hr = CSFToolbar::_SaveOrderStream();
  252. return hr;
  253. }
  254. void CMenuSFToolbar::_Dropped(int nIndex, BOOL fDroppedOnSource)
  255. {
  256. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  257. ASSERT(_fDropping);
  258. CSFToolbar::_Dropped(nIndex, fDroppedOnSource);
  259. SHPlaySound(TEXT("MoveMenuItem"));
  260. // Set this to false here because it is ugly that we don't behave like a menu right after a drop.
  261. _fEditMode = FALSE;
  262. // Notify the toplevel menuband of the drop in case it was popped open
  263. // because of the drag/drop event.
  264. //
  265. // (There are some functionality/activation problems if we keep the
  266. // menu up after this case. So to avoid those things at this late date,
  267. // we're going to cancel the menu after a timeout.)
  268. IOleCommandTarget * poct;
  269. _pcmb->QueryService(SID_SMenuBandTop, IID_PPV_ARG(IOleCommandTarget, &poct));
  270. if (poct)
  271. {
  272. poct->Exec(&CGID_MenuBand, MBANDCID_ITEMDROPPED, 0, NULL, NULL);
  273. poct->Release();
  274. }
  275. _pcmb->_fDragEntered = FALSE;
  276. }
  277. HMENU CMenuSFToolbar::_GetContextMenu(IContextMenu* pcm, int* pid)
  278. {
  279. *pid += MNIDM_LAST;
  280. HMENU hmenu = CSFToolbar::_GetContextMenu(pcm, pid);
  281. HMENU hmenu2 = SHLoadMenuPopup(HINST_THISDLL, MENU_MNFOLDERCONTEXT);
  282. // now find the properties insertion point and
  283. int iCount = GetMenuItemCount(hmenu);
  284. for (int i = 0; i < iCount; i++)
  285. {
  286. TCHAR szCommand[40];
  287. UINT id = GetMenuItemID(hmenu, i);
  288. if (IsInRange(id, *pid, 0x7fff))
  289. {
  290. id -= *pid;
  291. ContextMenu_GetCommandStringVerb(pcm, id, szCommand, ARRAYSIZE(szCommand));
  292. if (!lstrcmpi(szCommand, TEXT("properties")))
  293. {
  294. break;
  295. }
  296. }
  297. }
  298. Shell_MergeMenus(hmenu, hmenu2, i, 0, 0x7FFF, 0);
  299. DestroyMenu(hmenu2);
  300. return hmenu;
  301. }
  302. void CMenuSFToolbar::_OnDefaultContextCommand(int idCmd)
  303. {
  304. switch (idCmd)
  305. {
  306. case MNIDM_RESORT:
  307. {
  308. // We used to blow away the order stream and refill, but since we use the order stream
  309. // for calculating the presence of new items, this promoted all of the items were were
  310. // sorting.
  311. HDPA hdpa = _hdpa;
  312. // if we have a _hdpaOrder it may be out of sync and we just want to resort the
  313. // ones in _hdpa anyway so ditch the orderlist.
  314. OrderList_Destroy(&_hdpaOrder);
  315. _SortDPA(hdpa);
  316. OrderList_Reorder(hdpa);
  317. _fChangedOrder = TRUE;
  318. // This call knows about _hdpa and _hdpaOrder
  319. _SaveOrderStream();
  320. // MIKESH: this is needed because otherwise FillToolbar will use the current _hdpa
  321. // and nothing gets changed... I think it's because OrderItem_Compare returns failure on some of the pidls
  322. CMenuToolbarBase::EmptyToolbar();
  323. _SetDirty(TRUE);
  324. _LoadOrderStream();
  325. if (_fShow)
  326. {
  327. _FillToolbar();
  328. }
  329. break;
  330. }
  331. }
  332. }
  333. LRESULT CMenuSFToolbar::_OnContextMenu(WPARAM wParam, LPARAM lParam)
  334. {
  335. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  336. //
  337. // When the NoSetTaskbar restriction is set, this code will disallow
  338. // Context menus. It querys up to the Start menu to ask for permission
  339. // to set.
  340. LRESULT lres = 0;
  341. // No UEM on Context Menus. This avoids the problem where we expand the menubands
  342. // with a context menu present.
  343. _fSuppressUserMonitor = TRUE;
  344. // Allow the selected item to blow away the menus. This is explicitly for the Verbs "Open"
  345. // "Print" and such that launch another process. Inprocess commands are unaffected by this.
  346. LockSetForegroundWindow(LSFW_UNLOCK);
  347. BOOL fOwnerIsTopmost = (WS_EX_TOPMOST & GetWindowLong(_pcmb->_pmbState->GetSubclassedHWND(), GWL_EXSTYLE));
  348. if (fOwnerIsTopmost)
  349. {
  350. ::SetWindowPos(_pcmb->_pmbState->GetSubclassedHWND(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
  351. }
  352. KillTimer(_hwndMB, MBTIMER_INFOTIP);
  353. _pcmb->_pmbState->HideTooltip(FALSE);
  354. if (!(_pcmb->_dwFlags & SMINIT_RESTRICT_CONTEXTMENU))
  355. lres = CSFToolbar::_OnContextMenu(wParam, lParam);
  356. if (fOwnerIsTopmost)
  357. {
  358. ::SetWindowPos(_pcmb->_pmbState->GetSubclassedHWND(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
  359. IUnknown_QueryServiceExec(SAFECAST(_pcmb, IOleCommandTarget*), SID_SMenuBandTop,
  360. &CGID_MenuBand, MBANDCID_REPOSITION, TRUE, NULL, NULL);
  361. }
  362. // Take the capture back after the context menu
  363. GetMessageFilter()->RetakeCapture();
  364. return lres;
  365. }
  366. HRESULT CMenuSFToolbar::_GetInfo(LPCITEMIDLIST pidl, SMINFO* psminfo)
  367. {
  368. if (psminfo->dwMask & SMIM_TYPE)
  369. {
  370. psminfo->dwType = SMIT_STRING;
  371. }
  372. if (psminfo->dwMask & SMIM_FLAGS)
  373. {
  374. psminfo->dwFlags = SMIF_ICON | SMIF_DROPTARGET;
  375. }
  376. if (psminfo->dwMask & SMIM_ICON)
  377. {
  378. psminfo->dwMask &= ~SMIM_ICON;
  379. psminfo->iIcon = -1;
  380. }
  381. DWORD dwAttr = SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_BROWSABLE;
  382. // Folders that behave like shortcuts should not be considered
  383. // as cascading menu items. Channels are an example.
  384. // HACKHACK: to detect channels, we originally planned to GetUIObject
  385. // IShellLink. But this doesn't work on browser-only b/c it doesn't
  386. // pipe down to the shell extension. So as a hack, we'll key off
  387. // the absence of SFGAO_FILESYSTEM.
  388. // Is this a folder?
  389. // And is it NOT a browseable folder? If it's a Browseable folder, this means that it's a namespace
  390. // such as the Internet Namespace. The Internet name space's shell folder does not return real items, so it
  391. // makes it useless in menus. So, filter it out, and treat it like an item.
  392. HRESULT hr = _psf->GetAttributesOf(1, &pidl, &dwAttr);
  393. if (SUCCEEDED(hr) && ((dwAttr & (SFGAO_FOLDER | SFGAO_BROWSABLE)) == SFGAO_FOLDER))
  394. {
  395. // Since SHIsExpandableFolder is such an expensive call, and we only need
  396. // it for legacy Channels support, only do this call where channels are:
  397. // Favorites menu and Start Menu | Favorites.
  398. if (_dwFlags & SMSET_HASEXPANDABLEFOLDERS)
  399. {
  400. // Yes; but does it also behave like a shortcut?
  401. if (SHIsExpandableFolder(_psf, pidl))
  402. psminfo->dwFlags |= SMIF_SUBMENU;
  403. }
  404. else
  405. {
  406. // We're going to assume that if it's a folder, it really is a folder.
  407. psminfo->dwFlags |= SMIF_SUBMENU;
  408. }
  409. }
  410. CallCB(pidl, SMC_GETSFINFO, 0, (LPARAM)psminfo);
  411. return hr;
  412. }
  413. /*----------------------------------------------------------
  414. Purpose: This function determines the toolbar button style for the
  415. given pidl.
  416. Returns S_OK if pdwMIFFlags is also set (i.e., the object
  417. supported IMenuBandItem to provide more info). S_FALSE if only
  418. *pdwStyle is set.
  419. */
  420. HRESULT CMenuSFToolbar::_TBStyleForPidl(LPCITEMIDLIST pidl,
  421. DWORD * pdwStyle, DWORD* pdwState, DWORD * pdwMIFFlags, int * piIcon)
  422. {
  423. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  424. HRESULT hr = S_FALSE;
  425. DWORD dwStyle = TBSTYLE_BUTTON | TBSTYLE_DROPDOWN | TBSTYLE_NOPREFIX;
  426. *pdwState = TBSTATE_ENABLED;
  427. *pdwMIFFlags = 0;
  428. *piIcon = -1;
  429. if (!IS_INTRESOURCE(pidl))
  430. {
  431. SMINFO sminfo;
  432. sminfo.dwMask = SMIM_TYPE | SMIM_FLAGS | SMIM_ICON;
  433. if (SUCCEEDED(_GetInfo(pidl, &sminfo)))
  434. {
  435. *pdwMIFFlags = sminfo.dwFlags;
  436. if (sminfo.dwFlags & SMIF_ACCELERATOR)
  437. dwStyle &= ~TBSTYLE_NOPREFIX;
  438. if (sminfo.dwType & SMIT_SEPARATOR)
  439. {
  440. dwStyle &= ~TBSTYLE_BUTTON;
  441. dwStyle |= TBSTYLE_SEP;
  442. }
  443. if (sminfo.dwFlags & SMIF_ICON)
  444. *piIcon = sminfo.iIcon;
  445. if (sminfo.dwFlags & SMIF_DEMOTED &&
  446. !_pcmb->_fExpanded)
  447. {
  448. *pdwState |= TBSTATE_HIDDEN;
  449. _fHasDemotedItems = TRUE;
  450. }
  451. if (sminfo.dwFlags & SMIF_HIDDEN)
  452. *pdwState |= TBSTATE_HIDDEN;
  453. hr = S_OK;
  454. }
  455. }
  456. else if (pidl == PIDLSENTINEL(SENTINEL_EMPTY) ||
  457. pidl == PIDLSENTINEL(SENTINEL_CHEVRON))
  458. {
  459. // For null pidls ("empty" menuitems), there is no icon.
  460. // SMIF_DROPTTARGET is set so the user can drop into an empty submenu.
  461. *pdwMIFFlags = SMIF_DROPTARGET;
  462. // Return S_OK so the pdwMIFFlags is examined.
  463. hr = S_OK;
  464. }
  465. else if (pidl == PIDLSENTINEL(SENTINEL_SEP))
  466. {
  467. dwStyle &= ~TBSTYLE_BUTTON;
  468. dwStyle |= TBSTYLE_SEP;
  469. hr = S_OK;
  470. }
  471. *pdwStyle = dwStyle;
  472. return hr;
  473. }
  474. BOOL CMenuSFToolbar::_FilterPidl(LPCITEMIDLIST pidl)
  475. {
  476. BOOL fRet = FALSE;
  477. if (pidl)
  478. {
  479. fRet = (S_OK == CallCB(pidl, SMC_FILTERPIDL, 0, 0));
  480. }
  481. return fRet;
  482. }
  483. //
  484. // Note: This must return exactly TRUE or FALSE.
  485. //
  486. BOOL CMenuSFToolbar::_IsAboveNSSeparator(LPCITEMIDLIST pidl)
  487. {
  488. GUID guidNS;
  489. return (_dwFlags & SMSET_SEPARATEMERGEFOLDER) &&
  490. SUCCEEDED(_pasf2->GetNameSpaceID(pidl, &guidNS)) &&
  491. IsEqualGUID(guidNS, _guidAboveSep);
  492. }
  493. void CMenuSFToolbar::_FillDPA(HDPA hdpa, HDPA hdpaSort, DWORD dwEnumFlags)
  494. {
  495. _fHasSubMenu = FALSE;
  496. CallCB(NULL, SMC_BEGINENUM, (WPARAM)&dwEnumFlags, 0);
  497. CSFToolbar::_FillDPA(hdpa, hdpaSort, dwEnumFlags);
  498. //
  499. // If we are doing separators, make sure all the "above" items
  500. // come before the "below" items.
  501. //
  502. // The items are almost always in the correct order already,
  503. // with maybe one or two exceptions, so optimize for that case.
  504. //
  505. if (_dwFlags & SMSET_SEPARATEMERGEFOLDER)
  506. {
  507. // Invariant: Items 0..i-1 are _guidAboveSep
  508. // Items i..j-1 are not _guidAboveSep
  509. // Items j... are unknown
  510. int i, j;
  511. for (i = j = 0; j < DPA_GetPtrCount(hdpa); j++)
  512. {
  513. PORDERITEM poi = (PORDERITEM)DPA_FastGetPtr(hdpa, j);
  514. if (_IsAboveNSSeparator(poi->pidl))
  515. {
  516. if (i != j)
  517. {
  518. DPA_InsertPtr(hdpa, i, DPA_DeletePtr(hdpa, j));
  519. }
  520. i++;
  521. }
  522. }
  523. OrderList_Reorder(hdpa); // Recompute item numbers after we shuffled them around
  524. }
  525. // End of separator enforcement
  526. CallCB(NULL, SMC_ENDENUM, 0, 0);
  527. if (0 == DPA_GetPtrCount(hdpa) && _psf)
  528. {
  529. OrderList_Append(hdpa, NULL, 0); // Add a bogus pidl
  530. _fEmpty = TRUE;
  531. _fHasDemotedItems = FALSE;
  532. if (_dwFlags & SMSET_NOEMPTY)
  533. _fDontShowEmpty = TRUE;
  534. }
  535. else
  536. {
  537. _fEmpty = FALSE;
  538. if (_dwFlags & SMSET_NOEMPTY)
  539. _fDontShowEmpty = FALSE;
  540. }
  541. }
  542. void CMenuSFToolbar::_AddChevron()
  543. {
  544. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  545. // Does this menu get a chevron button?
  546. if (_fHasDemotedItems && !_pcmb->_fExpanded && _idCmdChevron == -1)
  547. {
  548. // Yes; (we shouldn't get here if the menu is empty)
  549. ASSERT(!_fEmpty);
  550. int iIndex;
  551. // Add the chevron to the top or the bottom
  552. if (_dwFlags & SMSET_TOP && _pcmb->_pmtbTop != _pcmb->_pmtbBottom)
  553. iIndex = 0; // add to top
  554. else
  555. iIndex = ToolBar_ButtonCount(_hwndTB); // append to bottom
  556. PIBDATA pibd = _AddOrderItemTB(POISENTINEL(SENTINEL_CHEVRON), iIndex, NULL);
  557. // Remember where the Chevron ended up
  558. if (pibd)
  559. {
  560. _idCmdChevron = GetButtonCmd(_hwndTB, iIndex);
  561. }
  562. }
  563. }
  564. void CMenuSFToolbar::_RemoveChevron()
  565. {
  566. if (-1 != _idCmdChevron)
  567. {
  568. // Yes; remove the chevron
  569. int iPos = ToolBar_CommandToIndex(_hwndTB, _idCmdChevron);
  570. InlineDeleteButton(iPos);
  571. _idCmdChevron = -1;
  572. }
  573. }
  574. //
  575. // Return the index of the first item that goes below the separator.
  576. //
  577. // For large directories this can get called a lot so try to keep
  578. // the running time sublinear.
  579. //
  580. int CMenuSFToolbar::_GetNSSeparatorPlacement()
  581. {
  582. //
  583. // Invariant:
  584. //
  585. // if... then DPA_GetPtrCount(i) is...
  586. // ------------------------ -----------------------------
  587. // i < iLow above the separator
  588. // iLow <= i < iHigh unknown
  589. // iHigh <= i below the separator
  590. //
  591. // where we pretend that item -1 is above the separator and all items
  592. // past the end of the DPA are below the separator.
  593. //
  594. if (!_hdpa) return -1; // Weird low-memory condition
  595. int iLow = 0;
  596. int iHigh = DPA_GetPtrCount(_hdpa);
  597. while (iLow < iHigh)
  598. {
  599. int iMid = (iLow + iHigh) / 2;
  600. PORDERITEM poi = (PORDERITEM)DPA_FastGetPtr(_hdpa, iMid);
  601. if (_IsAboveNSSeparator(poi->pidl))
  602. {
  603. iLow = iMid + 1;
  604. }
  605. else
  606. {
  607. iHigh = iMid;
  608. }
  609. }
  610. return iLow;
  611. }
  612. void CMenuSFToolbar::_AddNSSeparator()
  613. {
  614. if (_idCmdSep == -1 && (_dwFlags & SMSET_SEPARATEMERGEFOLDER))
  615. {
  616. int iPos = _GetNSSeparatorPlacement();
  617. if (iPos > 0 && iPos < DPA_GetPtrCount(_hdpa))
  618. {
  619. PIBDATA pibd = _AddOrderItemTB(POISENTINEL(SENTINEL_SEP), iPos, NULL);
  620. if (pibd)
  621. {
  622. _idCmdSep = GetButtonCmd(_hwndTB, iPos);
  623. }
  624. }
  625. }
  626. }
  627. void CMenuSFToolbar::_RemoveNSSeparator()
  628. {
  629. if (-1 != _idCmdSep)
  630. {
  631. // Yes; remove the Sep
  632. int iPos = ToolBar_CommandToIndex(_hwndTB, _idCmdSep);
  633. InlineDeleteButton(iPos);
  634. _idCmdSep = -1;
  635. }
  636. }
  637. // Note! This must return exactly TRUE or FALSE.
  638. BOOL CMenuSFToolbar::_IsBelowNSSeparator(int iIndex)
  639. {
  640. if (_idCmdSep != -1)
  641. {
  642. int iPos = ToolBar_CommandToIndex(_hwndTB, _idCmdSep);
  643. if (iPos >= 0 && iIndex >= iPos)
  644. {
  645. return TRUE;
  646. }
  647. }
  648. return FALSE;
  649. }
  650. //
  651. // Our separator line isn't recorded in the DPA so we need to
  652. // subtract it out...
  653. //
  654. int CMenuSFToolbar::v_TBIndexToDPAIndex(int iTBIndex)
  655. {
  656. if (_IsBelowNSSeparator(iTBIndex))
  657. {
  658. iTBIndex--;
  659. }
  660. return iTBIndex;
  661. }
  662. int CMenuSFToolbar::v_DPAIndexToTBIndex(int iIndex)
  663. {
  664. if (_IsBelowNSSeparator(iIndex))
  665. {
  666. iIndex++;
  667. }
  668. return iIndex;
  669. }
  670. void CMenuSFToolbar::_ToolbarChanged()
  671. {
  672. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  673. _pcmb->_fForceButtonUpdate = TRUE;
  674. // We shouldn't change the size of the menubar while we're in the middle
  675. // of a delete. Wait until we're done...
  676. if (!_fPreventToolbarChange && _fShow && !_fEmptyingToolbar)
  677. {
  678. // Resize the MenuBar
  679. HWND hwndP = _hwndPager ? GetParent(_hwndPager): GetParent(_hwndTB);
  680. if (hwndP && (GetDesktopWindow() != hwndP))
  681. {
  682. RECT rcOld = {0};
  683. RECT rcNew = {0};
  684. GetClientRect(hwndP, &rcOld);
  685. _pcmb->ResizeMenuBar();
  686. GetClientRect(hwndP, &rcNew);
  687. // If the rect sizes haven't changed, then we need to re-layout the
  688. // band because the button widths may have changed.
  689. if (EqualRect(&rcOld, &rcNew))
  690. NegotiateSize();
  691. // This pane may have changed sizes. If there is a sub menu, then
  692. // we need to have them reposition themselves
  693. if (_pcmb->_fInSubMenu && _pcmb->_pmtbTracked)
  694. {
  695. _pcmb->_pmtbTracked->PositionSubmenu(-1);
  696. IUnknown_QueryServiceExec(_pcmb->_pmpSubMenu, SID_SMenuBandChild,
  697. &CGID_MenuBand, MBANDCID_REPOSITION, 0, NULL, NULL);
  698. }
  699. }
  700. }
  701. }
  702. void CMenuSFToolbar::_FillToolbar()
  703. {
  704. // Don't fill the toolbar if we're not dirty or we're emptying the toolbar
  705. // If we try and fill the toolbar while we're emptying we enter a race condition
  706. // where we could AV. This fixes a bug where when dragging a folder into the
  707. // start menu, and cascade a menu, we empty one toolbar, which causes the
  708. // other toolbar to get destroyed, unregister itself, flush the change notify
  709. // queue, causing the original window to empty again... (lamadio) 7.16.98
  710. if (_fDirty && !_fEmptyingToolbar)
  711. {
  712. LPITEMIDLIST pidlItem = NULL;
  713. IShellMenu* psmSubMenu = NULL;
  714. // Populating the menu will take a long time since we're hitting
  715. // the disk. Give the user some feedback if the cursor is
  716. // IDC_ARROW. (If the cursor is something else, then don't
  717. // mess with it.) Note that we have to use (HCURSOR)-1 as a
  718. // sentinel, because it's possible that the current cursor is NULL.
  719. // Prevent _ToolbarChanged from Doing things. (Perf)
  720. _fPreventToolbarChange = TRUE;
  721. _RemoveNSSeparator();
  722. _RemoveChevron(); // Remove the chevron...
  723. if (S_OK == CallCB(NULL, SMC_DUMPONUPDATE, 0, 0))
  724. {
  725. EmptyToolbar();
  726. }
  727. CSFToolbar::_FillToolbar();
  728. // If we had a Chevron before we refreshed the toolbar,
  729. // then we need to add it back.
  730. _AddChevron();
  731. _AddNSSeparator(); // See if we need a separator now
  732. if (_hwndPager)
  733. SendMessage(_hwndPager, PGMP_RECALCSIZE, (WPARAM) 0, (LPARAM) 0);
  734. _fPreventToolbarChange = FALSE;
  735. _ToolbarChanged();
  736. }
  737. }
  738. void CMenuSFToolbar::v_OnDeleteButton(void *pData)
  739. {
  740. CMenuData* pmd = (CMenuData*)pData;
  741. if (pmd)
  742. delete pmd;
  743. }
  744. void CMenuSFToolbar::v_OnEmptyToolbar()
  745. {
  746. CMenuToolbarBase::v_OnEmptyToolbar();
  747. OrderList_Destroy(&_hdpa);
  748. _fDirty = TRUE;
  749. _nNextCommandID = 0;
  750. }
  751. void CMenuSFToolbar::_ObtainPIDLName(LPCITEMIDLIST pidl, LPTSTR psz, int cchMax)
  752. {
  753. // We overload this function because we have some special sentinel pidls
  754. if (!IS_INTRESOURCE(pidl))
  755. {
  756. CSFToolbar::_ObtainPIDLName(pidl, psz, cchMax);
  757. }
  758. else if (pidl == PIDLSENTINEL(SENTINEL_EMPTY))
  759. {
  760. LoadString(HINST_THISDLL, IDS_EMPTY, psz, cchMax);
  761. }
  762. else
  763. {
  764. ASSERT(pidl == PIDLSENTINEL(SENTINEL_CHEVRON) ||
  765. pidl == PIDLSENTINEL(SENTINEL_SEP));
  766. StrCpyN(psz, TEXT(""), cchMax);
  767. }
  768. }
  769. void CMenuSFToolbar::v_NewItem(LPCITEMIDLIST pidl)
  770. {
  771. // This is called when an item is present in the filesystem
  772. // that is not in the order stream. This occurs when an item is
  773. // created when the menu is not up.
  774. // New items are going to have a weird Promotion state
  775. // if there are multiple clients. Each client is going to be the create, and try to increment this.
  776. // We have to syncronize access to this. I'm not sure how to do this.
  777. // Note, this has not been a problem.
  778. // New items get promoted.
  779. CallCB(pidl, SMC_NEWITEM, 0, 0);
  780. // Since this is a new item, we want to increment the promoted items
  781. // so that we can do chevron tracking.
  782. _cPromotedItems++;
  783. }
  784. void CMenuSFToolbar::_SetDirty(BOOL fDirty)
  785. {
  786. if (fDirty)
  787. _pcmb->_fForceButtonUpdate = TRUE;
  788. CSFToolbar::_SetDirty(fDirty);
  789. }
  790. void CMenuSFToolbar::_NotifyBulkOperation(BOOL fStart)
  791. {
  792. if (fStart)
  793. {
  794. _RemoveNSSeparator();
  795. _RemoveChevron();
  796. }
  797. else
  798. {
  799. _AddChevron();
  800. _AddNSSeparator();
  801. }
  802. }
  803. void CMenuSFToolbar::_OnFSNotifyAdd(LPCITEMIDLIST pidl, DWORD dwFlags, int nIndex)
  804. {
  805. DWORD dwEnumFlags = SHCONTF_FOLDERS | SHCONTF_NONFOLDERS;
  806. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  807. if (!(dwFlags & FSNA_BULKADD))
  808. {
  809. // Removing the separator shuffles the indices around, so compensate for it here
  810. if (_IsBelowNSSeparator(nIndex))
  811. {
  812. nIndex--;
  813. }
  814. if (_fDropping && _tbim.iButton != -1 && _IsBelowNSSeparator(_tbim.iButton))
  815. {
  816. _tbim.iButton--;
  817. }
  818. _NotifyBulkOperation(TRUE); // pretend this is a one-item bulk operation
  819. }
  820. CallCB(NULL, SMC_BEGINENUM, (WPARAM)&dwEnumFlags, 0);
  821. if ((dwFlags & FSNA_ADDDEFAULT) && (_dwFlags & SMSET_SEPARATEMERGEFOLDER) &&
  822. _IsAboveNSSeparator(pidl))
  823. {
  824. dwFlags &= ~FSNA_ADDDEFAULT;
  825. nIndex = _GetNSSeparatorPlacement(); // inserts above the separator
  826. }
  827. CSFToolbar::_OnFSNotifyAdd(pidl, dwFlags, nIndex);
  828. CallCB(NULL, SMC_ENDENUM, 0, 0);
  829. // When we add something to this, we want to promote our parent.
  830. IUnknown_RefreshParent(_pcmb->_punkSite, _pidl, SMINV_PROMOTE);
  831. if (!(dwFlags & FSNA_BULKADD))
  832. {
  833. _NotifyBulkOperation(FALSE); // pretend this is a one-item bulk operation
  834. _SaveOrderStream();
  835. }
  836. }
  837. UINT ToolBar_GetVisibleCount(HWND hwnd)
  838. {
  839. UINT cVis = 0;
  840. int cItems = ToolBar_ButtonCount(hwnd) - 1;
  841. for (; cItems >= 0; cItems--)
  842. {
  843. TBBUTTONINFO tbinfo;
  844. tbinfo.cbSize = sizeof(tbinfo);
  845. tbinfo.dwMask = TBIF_BYINDEX | TBIF_STATE;
  846. if (ToolBar_GetButtonInfo(hwnd, cItems, &tbinfo))
  847. {
  848. if (!(tbinfo.fsState & TBSTATE_HIDDEN))
  849. {
  850. cVis ++;
  851. }
  852. }
  853. }
  854. return cVis;
  855. }
  856. void CMenuSFToolbar::_OnFSNotifyRemove(LPCITEMIDLIST pidl)
  857. {
  858. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  859. int i;
  860. _RemoveNSSeparator();
  861. _RemoveChevron();
  862. // Check to see if this item is a promoted guy...
  863. LPITEMIDLIST pidlButton;
  864. if (SUCCEEDED(_GetButtonFromPidl(pidl, NULL, &i, &pidlButton)))
  865. {
  866. int idCmd = GetButtonCmd(_hwndMB, i);
  867. // Is he promoted?
  868. if (!(v_GetFlags(idCmd) & SMIF_DEMOTED))
  869. {
  870. // Yes, then we need to decrement the promoted count because
  871. // we are removing a promoted guy.
  872. _cPromotedItems--;
  873. // We should expand if we go to zero
  874. if (_cPromotedItems == 0)
  875. {
  876. // Demote the parent
  877. IUnknown_RefreshParent(_pcmb->_punkSite, _pidl, SMINV_DEMOTE | SMINV_NEXTSHOW);
  878. Expand(TRUE);
  879. }
  880. }
  881. if (_pcmb->_fInSubMenu && _pcmb->_nItemSubMenu == idCmd)
  882. _pcmb->_SubMenuOnSelect(MPOS_CANCELLEVEL);
  883. }
  884. CSFToolbar::_OnFSNotifyRemove(pidl);
  885. //Oooppsss, we removed the only string. Replace with our "(Empty)"
  886. // handler....
  887. if (0 == DPA_GetPtrCount(_hdpa) && _psf && _fVerticalMB)
  888. {
  889. ASSERT(_fEmpty == FALSE);
  890. // If we are Empty, then we cannot have any demoted items
  891. // NOTE: We can have no demoted items and not be empty, so one does
  892. // not imply the other.
  893. _fHasDemotedItems = FALSE;
  894. _AddPidl(NULL, FALSE, 0);
  895. _fEmpty = TRUE;
  896. if (_dwFlags & SMSET_NOEMPTY)
  897. _fDontShowEmpty = TRUE;
  898. }
  899. if (_dwFlags & SMSET_COLLAPSEONEMPTY &&
  900. ToolBar_GetVisibleCount(_hwndMB) == 0)
  901. {
  902. // When we don't want to be shown when empty, collapse.
  903. _pcmb->_SiteOnSelect(MPOS_FULLCANCEL);
  904. }
  905. _AddChevron();
  906. _AddNSSeparator();
  907. }
  908. void CMenuSFToolbar::_OnFSNotifyRename(LPCITEMIDLIST pidlFrom, LPCITEMIDLIST pidlTo)
  909. {
  910. if ((_dwFlags & SMSET_SEPARATEMERGEFOLDER) &&
  911. _IsAboveNSSeparator(pidlFrom) != _IsAboveNSSeparator(pidlTo))
  912. {
  913. // This is a rename of something "to itself" but which crosses
  914. // the separator line. Don't handle it as an internal rename;
  915. // just ignore it and let the upcoming updatedir do the real work.
  916. }
  917. else
  918. {
  919. CSFToolbar::_OnFSNotifyRename(pidlFrom, pidlTo);
  920. }
  921. }
  922. void CMenuSFToolbar::NegotiateSize()
  923. {
  924. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  925. HWND hwndP = _hwndPager ? GetParent(_hwndPager): GetParent(_hwndTB);
  926. if (hwndP && (GetDesktopWindow() != hwndP))
  927. {
  928. RECT rc = {0};
  929. GetClientRect(hwndP, &rc);
  930. _pcmb->OnPosRectChangeDB(&rc);
  931. }
  932. }
  933. /*----------------------------------------------------------
  934. Purpose: CDelegateDropTarget::DragEnter
  935. Informs Menuband that a drag has entered it's window.
  936. */
  937. STDMETHODIMP CMenuSFToolbar::DragEnter(IDataObject *pdtobj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
  938. {
  939. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  940. _pcmb->_fDragEntered = TRUE;
  941. IOleCommandTarget * poct;
  942. _pcmb->QueryService(SID_SMenuBandTop, IID_PPV_ARG(IOleCommandTarget, &poct));
  943. if (poct)
  944. {
  945. poct->Exec(&CGID_MenuBand, MBANDCID_DRAGENTER, 0, NULL, NULL);
  946. poct->Release();
  947. }
  948. return CSFToolbar::DragEnter(pdtobj, grfKeyState, pt, pdwEffect);
  949. }
  950. /*----------------------------------------------------------
  951. Purpose: CDelegateDropTarget::DragLeave
  952. Informs Menuband that a drag has left it's window.
  953. */
  954. STDMETHODIMP CMenuSFToolbar::DragLeave(void)
  955. {
  956. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  957. _pcmb->_fDragEntered = FALSE;
  958. IOleCommandTarget * poct;
  959. _pcmb->QueryService(SID_SMenuBandTop, IID_PPV_ARG(IOleCommandTarget, &poct));
  960. if (poct)
  961. {
  962. poct->Exec(&CGID_MenuBand, MBANDCID_DRAGLEAVE, 0, NULL, NULL);
  963. poct->Release();
  964. }
  965. return CSFToolbar::DragLeave();
  966. }
  967. /*----------------------------------------------------------
  968. Purpose: CDelegateDropTarget::HitTestDDT
  969. Returns the ID to pass to GetObject.
  970. 30
  971. */
  972. HRESULT CMenuSFToolbar::HitTestDDT(UINT nEvent, LPPOINT ppt, DWORD_PTR *pdwId, DWORD *pdwEffect)
  973. {
  974. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  975. TBINSERTMARK tbim;
  976. DWORD dwFlags = 0;
  977. BOOL fOnButton = FALSE;
  978. // If we're in drag and drop, Take UEM out of the picture
  979. _fSuppressUserMonitor = TRUE;
  980. // Unlike the CISFBand implementation, we always want to insert
  981. // b/t the menu items. So we return a negative index so the
  982. // GetObject method will treat all the drops as if we're dropping
  983. // in b/t the items, even if the cursor is over a menuitem.
  984. switch (nEvent)
  985. {
  986. case HTDDT_ENTER:
  987. // OLE is in its modal drag/drop loop, and it has the capture.
  988. // We shouldn't take the capture back during this time.
  989. if (!(_pcmb->_dwFlags & SMINIT_RESTRICT_DRAGDROP) &&
  990. (S_FALSE == CallCB(NULL, SMC_SFDDRESTRICTED, NULL, NULL)))
  991. {
  992. // Since we've been entered, set the global state as
  993. // having the drag. If at some point the whole menu
  994. // heirarchy does not have the drag inside of it, we want to
  995. // collapse the menu. This is to prevent the hanging menu syndrome.
  996. _pcmb->_pmbState->HasDrag(TRUE);
  997. KillTimer(_hwndMB, MBTIMER_DRAGPOPDOWN);
  998. GetMessageFilter()->PreventCapture(TRUE);
  999. return S_OK;
  1000. }
  1001. else
  1002. return S_FALSE;
  1003. case HTDDT_OVER:
  1004. BLOCK
  1005. {
  1006. int iButton = -1;
  1007. *pdwEffect = DROPEFFECT_NONE;
  1008. POINT pt = *ppt;
  1009. ClientToScreen(_hwndTB, &pt);
  1010. if (WindowFromPoint(pt) == _hwndPager)
  1011. {
  1012. iButton = IBHT_PAGER;
  1013. tbim.iButton = -1;
  1014. tbim.dwFlags = 0;
  1015. }
  1016. else
  1017. {
  1018. // Are we sitting BETWEEN buttons?
  1019. if (ToolBar_InsertMarkHitTest(_hwndTB, ppt, &tbim))
  1020. {
  1021. // Yes.
  1022. // Is this on the source button?
  1023. if (!(tbim.dwFlags & TBIMHT_BACKGROUND) &&
  1024. tbim.iButton == _iDragSource)
  1025. {
  1026. iButton = IBHT_SOURCE; // Yes; don't drop on the source button
  1027. }
  1028. else
  1029. {
  1030. iButton = tbim.iButton;
  1031. }
  1032. }
  1033. // No we're either sitting on a button or the background. Button?
  1034. else if (tbim.iButton != -1 && !(tbim.dwFlags & TBIMHT_BACKGROUND))
  1035. {
  1036. // On a Button. Cool.
  1037. iButton = tbim.iButton;
  1038. fOnButton = TRUE;
  1039. }
  1040. // Can this drop target even accept the drop?
  1041. int idBtn = GetButtonCmd(_hwndTB, tbim.iButton);
  1042. dwFlags = v_GetFlags(idBtn);
  1043. if (_idCmdChevron != idBtn &&
  1044. !(dwFlags & (SMIF_DROPTARGET | SMIF_DROPCASCADE)) ||
  1045. ((_pcmb->_dwFlags & SMINIT_RESTRICT_DRAGDROP) ||
  1046. (S_OK == CallCB(NULL, SMC_SFDDRESTRICTED, NULL, NULL))))
  1047. {
  1048. // No
  1049. return E_FAIL;
  1050. }
  1051. }
  1052. *pdwId = iButton;
  1053. }
  1054. break;
  1055. case HTDDT_LEAVE:
  1056. // If the dropped occured in this band, then we don't want to collapse the menu
  1057. if (!_fHasDrop)
  1058. {
  1059. // Since we've been left, set the global state. If moving between panes
  1060. // then the pane that will be entered will reset this within the timeout period
  1061. _pcmb->_pmbState->HasDrag(FALSE);
  1062. _SetTimer(MBTIMER_DRAGPOPDOWN);
  1063. }
  1064. // We can take the capture back anytime now
  1065. GetMessageFilter()->PreventCapture(FALSE);
  1066. if (!_fVerticalMB)
  1067. {
  1068. tbim = _tbim;
  1069. }
  1070. else
  1071. {
  1072. // Turn off the insertion mark
  1073. tbim.iButton = -1;
  1074. tbim.dwFlags = 0;
  1075. DAD_ShowDragImage(FALSE);
  1076. ToolBar_SetInsertMark(_hwndTB, &tbim);
  1077. UpdateWindow(_hwndTB);
  1078. DAD_ShowDragImage(TRUE);
  1079. }
  1080. break;
  1081. }
  1082. // Did the drop target change?
  1083. if (tbim.iButton != _tbim.iButton || tbim.dwFlags != _tbim.dwFlags)
  1084. {
  1085. DAD_ShowDragImage(FALSE);
  1086. // Yes
  1087. // If we're sitting on a button, highlight it. Otherwise remove the hightlight.
  1088. //ToolBar_SetHotItem(_hwndTB, fOnButton? tbim.iButton : -1);
  1089. // No.
  1090. // We pop open submenus here during drag and drop. But only
  1091. // if the button has changed (not the flags). Otherwise we'd
  1092. // get flashing submenus as the cursor moves w/in a single item.
  1093. if (tbim.iButton != _tbim.iButton)
  1094. {
  1095. _SetTimer(MBTIMER_DRAGOVER);
  1096. BOOL_PTR fOldAnchor = ToolBar_SetAnchorHighlight(_hwndTB, FALSE);
  1097. ToolBar_SetHotItem(_hwndTB, -1);
  1098. _pcmb->_SiteOnSelect(MPOS_CHILDTRACKING);
  1099. ToolBar_SetAnchorHighlight(_hwndTB, fOldAnchor);
  1100. }
  1101. // for now I don't want to rely on non-filesystem IShellFolder
  1102. // implementations to call our OnChange method when a drop occurs,
  1103. // so don't even show the insert mark.
  1104. // We do not want to display the Insert mark if we do not allow reorder.
  1105. if ((_fFSNotify || _iDragSource >= 0) && (dwFlags & SMIF_DROPTARGET) && _fAllowReorder)
  1106. {
  1107. ToolBar_SetInsertMark(_hwndTB, &tbim);
  1108. }
  1109. if (ppt)
  1110. _tbim = tbim;
  1111. UpdateWindow(_hwndTB);
  1112. DAD_ShowDragImage(TRUE);
  1113. }
  1114. if (!_fVerticalMB && HTDDT_LEAVE == nEvent)
  1115. {
  1116. // Cursor leaving menuband, reset
  1117. _tbim.iButton = -1;
  1118. _iDragSource = -1;
  1119. }
  1120. return S_OK;
  1121. }
  1122. HRESULT CMenuSFToolbar::GetObjectDDT(DWORD_PTR dwId, REFIID riid, void **ppvObj)
  1123. {
  1124. HRESULT hr = E_NOINTERFACE;
  1125. int nID = (int)dwId;
  1126. *ppvObj = NULL;
  1127. if (nID == IBHT_PAGER)
  1128. {
  1129. SendMessage(_hwndPager, PGM_GETDROPTARGET, 0, (LPARAM)ppvObj);
  1130. }
  1131. // Is the target the source?
  1132. else if (nID >= 0)
  1133. {
  1134. // No; does the shellfolder support IDropTarget?
  1135. PORDERITEM poi = (PORDERITEM)DPA_GetPtr(_hdpa, v_TBIndexToDPAIndex(nID));
  1136. if (poi)
  1137. {
  1138. IShellFolder *psfCVO;
  1139. hr = _GetFolderForCreateViewObject(_IsAboveNSSeparator(poi->pidl), &psfCVO);
  1140. if (SUCCEEDED(hr))
  1141. {
  1142. // We want to pass the subclassed HWND, because all we want the parent of the context menus to be
  1143. // the Subclassed window. This is so we don't loose focus and collapse.
  1144. hr = psfCVO->CreateViewObject(_pcmb->_pmbState->GetWorkerWindow(_hwndMB), riid, ppvObj);
  1145. psfCVO->Release();
  1146. }
  1147. }
  1148. }
  1149. if (*ppvObj)
  1150. hr = S_OK;
  1151. //TraceMsg(TF_BAND, "ISFBand::GetObject(%d) returns %x", dwId, hr);
  1152. return hr;
  1153. }
  1154. HRESULT CMenuSFToolbar::_GetFolderForCreateViewObject(BOOL fAbove, IShellFolder **ppsf)
  1155. {
  1156. HRESULT hr;
  1157. *ppsf = NULL;
  1158. if (!(_dwFlags & SMSET_SEPARATEMERGEFOLDER))
  1159. {
  1160. *ppsf = _psf;
  1161. _psf->AddRef();
  1162. return S_OK;
  1163. }
  1164. //
  1165. // Is this folder a mix of items above and below the line?
  1166. //
  1167. DWORD dwIndex;
  1168. DWORD dwNSId;
  1169. GUID guid;
  1170. int cAbove = 0;
  1171. int cBelow = 0;
  1172. for (dwIndex = 0; SUCCEEDED(_pasf2->EnumNameSpace(dwIndex, &dwNSId)) &&
  1173. SUCCEEDED(_pasf2->QueryNameSpace(dwNSId, &guid, NULL));
  1174. dwIndex++)
  1175. {
  1176. if (IsEqualGUID(guid, _guidAboveSep))
  1177. {
  1178. cAbove++;
  1179. }
  1180. else
  1181. {
  1182. cBelow++;
  1183. }
  1184. }
  1185. if (cAbove == 0 || cBelow == 0)
  1186. {
  1187. // No, it's all above or all below; we can (and indeed must) use it.
  1188. // We must use it because it might be User\Start Menu\Subfolder,
  1189. // but we want it to "realize" that it can accept drops from
  1190. // a common folder and should create All Users\Start Menu\Subfolder
  1191. // as a result.
  1192. *ppsf = _psf;
  1193. _psf->AddRef();
  1194. return S_OK;
  1195. }
  1196. //
  1197. // Create a subset of the merged shell folder to describe
  1198. // only the part above or below the line.
  1199. //
  1200. //
  1201. // Create another instance of whatever shellfolder we have.
  1202. //
  1203. CLSID clsid;
  1204. hr = IUnknown_GetClassID(_psf, &clsid);
  1205. if (FAILED(hr))
  1206. {
  1207. return hr;
  1208. }
  1209. IAugmentedShellFolder *pasfNew;
  1210. hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IAugmentedShellFolder, &pasfNew));
  1211. if (SUCCEEDED(hr))
  1212. {
  1213. // See how many namespaces there are...
  1214. hr = _pasf2->EnumNameSpace((DWORD)-1, NULL);
  1215. if (SUCCEEDED(hr))
  1216. {
  1217. // Allocate enough memory to keep track of them...
  1218. DWORD cNamespacesAlloc = HRESULT_CODE(hr);
  1219. // There had better be some namespaces because we don't even get
  1220. // here unless we find one "above" and one "below" namespace.
  1221. ASSERT(cNamespacesAlloc);
  1222. DWORD cNamespaces = 0;
  1223. QUERYNAMESPACEINFO *rgqnsi = new QUERYNAMESPACEINFO[cNamespacesAlloc];
  1224. if (rgqnsi)
  1225. {
  1226. IAugmentedShellFolder3 *pasf3;
  1227. hr = _pasf2->QueryInterface(IID_PPV_ARG(IAugmentedShellFolder3, &pasf3));
  1228. if (SUCCEEDED(hr))
  1229. {
  1230. // Collect information about them all, keep the ones we like.
  1231. //
  1232. // Note that in this loop we do not save the error failure from EnumNameSpace
  1233. // because we expect it to fail (with NO_MORE_ITEMS) and we don't want
  1234. // that to cause us to panic and bail out
  1235. DWORD dwFlagsMissing = ASFF_DEFNAMESPACE_ALL;
  1236. QUERYNAMESPACEINFO *pqnsi = rgqnsi;
  1237. for (dwIndex = 0; SUCCEEDED(pasf3->EnumNameSpace(dwIndex, &dwNSId)); dwIndex++)
  1238. {
  1239. ASSERT(cNamespaces < cNamespacesAlloc); // if this assert fires, then EnumNameSpace lied to us!
  1240. pqnsi->cbSize = sizeof(QUERYNAMESPACEINFO);
  1241. pqnsi->dwMask = ASFQNSI_FLAGS | ASFQNSI_FOLDER | ASFQNSI_GUID | ASFQNSI_PIDL;
  1242. hr = pasf3->QueryNameSpace2(dwNSId, pqnsi);
  1243. if (FAILED(hr))
  1244. {
  1245. break; // Fail!
  1246. }
  1247. if (BOOLIFY(IsEqualGUID(pqnsi->guidObject, _guidAboveSep)) == fAbove)
  1248. {
  1249. dwFlagsMissing &= ~pqnsi->dwFlags;
  1250. pqnsi++;
  1251. cNamespaces++;
  1252. }
  1253. else
  1254. {
  1255. ATOMICRELEASE(pqnsi->psf);
  1256. ILFree(pqnsi->pidl);
  1257. }
  1258. }
  1259. // Any ASFF_DEFNAMESPACE_* flags that nobody claimed,
  1260. // give them to the first namespace.
  1261. if (cNamespaces)
  1262. {
  1263. rgqnsi[0].dwFlags |= dwFlagsMissing;
  1264. }
  1265. // Add in all the namespaces
  1266. for (dwIndex = 0; SUCCEEDED(hr) && dwIndex < cNamespaces; dwIndex++)
  1267. {
  1268. hr = pasfNew->AddNameSpace(&rgqnsi[dwIndex].guidObject,
  1269. rgqnsi[dwIndex].psf,
  1270. rgqnsi[dwIndex].pidl,
  1271. rgqnsi[dwIndex].dwFlags);
  1272. }
  1273. pasf3->Release();
  1274. } // QueryInterface
  1275. //
  1276. // Now free all the memory we allocated...
  1277. //
  1278. for (dwIndex = 0; dwIndex < cNamespaces; dwIndex++)
  1279. {
  1280. ATOMICRELEASE(rgqnsi[dwIndex].psf);
  1281. ILFree(rgqnsi[dwIndex].pidl);
  1282. }
  1283. delete [] rgqnsi;
  1284. }
  1285. else
  1286. {
  1287. hr = E_OUTOFMEMORY; // "new" failed
  1288. }
  1289. }
  1290. if (SUCCEEDED(hr))
  1291. {
  1292. *ppsf = pasfNew; // transfer ownership to caller
  1293. }
  1294. else
  1295. {
  1296. pasfNew->Release();
  1297. }
  1298. }
  1299. return hr;
  1300. }
  1301. // S_OK if the drop was handled. Otherwise S_FALSE.
  1302. HRESULT CMenuSFToolbar::OnDropDDT(IDropTarget *pdt, IDataObject *pdtobj, DWORD * pgrfKeyState, POINTL pt, DWORD *pdwEffect)
  1303. {
  1304. // Since the modal drag-drop loop released the capture, take it
  1305. // back so we behave properly.
  1306. KillTimer(_hwndMB, MBTIMER_DRAGPOPDOWN);
  1307. HRESULT hr = S_FALSE;
  1308. // If this drop came from us, but it came from the other side of the
  1309. // separator, then act as if it didn't come from us after all.
  1310. if (_iDragSource >= 0 &&
  1311. (_dwFlags & SMSET_SEPARATEMERGEFOLDER) &&
  1312. _IsBelowNSSeparator(_iDragSource) != _IsBelowNSSeparator(_tbim.iButton))
  1313. {
  1314. _iDragSource = -1; // act as if the object came from somewhere else
  1315. }
  1316. // We need to say that the last drag leave is really the drop.
  1317. _fHasDrop = TRUE;
  1318. _idCmdDragging = -1;
  1319. LockSetForegroundWindow(LSFW_LOCK);
  1320. // Only send an hwnd to the callback if the drop source is external
  1321. if (!(_pcmb->_dwFlags & SMINIT_RESTRICT_DRAGDROP) &&
  1322. (S_FALSE == CallCB(NULL, SMC_SFDDRESTRICTED, (WPARAM)pdtobj,
  1323. (LPARAM)(_iDragSource < 0 ? GetHWNDForUIObject() : NULL))))
  1324. {
  1325. int iButtonOrig = _tbim.iButton;
  1326. // Removing the separator shuffles the indices around, so compensate for it here
  1327. if (_iDragSource >= 0 && _IsBelowNSSeparator(_iDragSource))
  1328. {
  1329. _iDragSource--;
  1330. }
  1331. if (_tbim.iButton != -1 && _IsBelowNSSeparator(_tbim.iButton))
  1332. {
  1333. _tbim.iButton--;
  1334. }
  1335. _RemoveNSSeparator();
  1336. _RemoveChevron();
  1337. hr = CSFToolbar::OnDropDDT(pdt, pdtobj, pgrfKeyState, pt, pdwEffect);
  1338. _AddChevron();
  1339. _AddNSSeparator();
  1340. _tbim.iButton = iButtonOrig;
  1341. }
  1342. LockSetForegroundWindow(LSFW_UNLOCK);
  1343. return hr;
  1344. }
  1345. PIBDATA CMenuSFToolbar::_AddOrderItemTB(PORDERITEM poi, int index, TBBUTTON* ptbb)
  1346. {
  1347. PIBDATA pibd = CSFToolbar::_AddOrderItemTB(poi, index, ptbb);
  1348. if (pibd)
  1349. {
  1350. if (pibd->GetFlags() & SMIF_SUBMENU)
  1351. {
  1352. _fHasSubMenu = TRUE;
  1353. }
  1354. }
  1355. return pibd;
  1356. }
  1357. BOOL CMenuSFToolbar::_AddPidl(LPITEMIDLIST pidl, DWORD dwFlags, int index)
  1358. {
  1359. BOOL bRet;
  1360. // Is this item being added to an empty menu?
  1361. // also, if the pidl is null then that means we're trying to add an "empty"
  1362. // tag. in that case we don't want to run through the code of preemptively
  1363. // removing the "empty" menu item and then adding it back on failure,
  1364. // so we go right to the else statement.
  1365. if (_fEmpty && pidl)
  1366. {
  1367. // Yes; remove the empty menu item
  1368. InlineDeleteButton(0);
  1369. DPA_DeletePtr(_hdpa, 0);
  1370. _fEmpty = FALSE;
  1371. if (_dwFlags & SMSET_NOEMPTY)
  1372. _fDontShowEmpty = FALSE;
  1373. bRet = CSFToolbar::_AddPidl(pidl, dwFlags, index);
  1374. // Failed to add new item?
  1375. if (!bRet)
  1376. {
  1377. // Yes; add the empty menu item back
  1378. OrderList_Append(_hdpa, NULL, 0); // Add a bogus pidl
  1379. _fEmpty = TRUE;
  1380. _fHasDemotedItems = FALSE;
  1381. if (_dwFlags & SMSET_NOEMPTY)
  1382. _fDontShowEmpty = TRUE;
  1383. }
  1384. }
  1385. else
  1386. bRet = CSFToolbar::_AddPidl(pidl, dwFlags, index);
  1387. return bRet;
  1388. }
  1389. BOOL CMenuSFToolbar::_ReBindToFolder(LPCITEMIDLIST pidl)
  1390. {
  1391. // We may be able to share this code with the code in _FillToolbar, but the difference is,
  1392. // in Fill Toolbar, the Toolbar Button does not have a Sub Menu. We reinitialize one we save away,
  1393. // and force it back into the child button. Here, we have the luxury of having the Sub Menu still
  1394. // in the toolbar button. I may be able to extract common code into a separate function. Left
  1395. // as an exercise to the reader.
  1396. // Need special Handling for this. We need to free the sub menu and
  1397. // rebind to it ifit's up.
  1398. BOOL fBound = FALSE;
  1399. TBBUTTONINFO tbinfo = {0};
  1400. tbinfo.dwMask = TBIF_COMMAND | TBIF_LPARAM;
  1401. LPITEMIDLIST pidlItem;
  1402. if (SUCCEEDED(_GetButtonFromPidl(ILFindLastID(pidl), &tbinfo, NULL, &pidlItem)))
  1403. {
  1404. CMenuData* pmd = (CMenuData*)tbinfo.lParam;
  1405. if (EVAL(pmd))
  1406. {
  1407. IShellFolderBand* psfb;
  1408. // We have the Toolbar button into, we should see if it has a sub menu associated with it.
  1409. if (SUCCEEDED(pmd->GetSubMenu(&SID_MenuShellFolder, IID_PPV_ARG(IShellFolderBand, &psfb))))
  1410. {
  1411. // It does. Then reuse!
  1412. LPITEMIDLIST pidlFull = NULL;
  1413. IShellFolder* psf = NULL;
  1414. if (_pasf2)
  1415. {
  1416. LPITEMIDLIST pidlFolder, pidlChild;
  1417. // Remember: Folder pidls must be unwrapped.
  1418. _pasf2->UnWrapIDList(pidlItem, 1, NULL, &pidlFolder, &pidlChild, NULL);
  1419. pidlFull = ILCombine(pidlFolder, pidlChild);
  1420. ILFree(pidlChild);
  1421. ILFree(pidlFolder);
  1422. }
  1423. else
  1424. {
  1425. // Not a wrapped guy, Sweet!
  1426. pidlFull = ILCombine(_pidl, pidlItem);
  1427. }
  1428. _psf->BindToObject(pidlItem, NULL, IID_PPV_ARG(IShellFolder, &psf));
  1429. if (psf)
  1430. {
  1431. if (pidlFull)
  1432. {
  1433. fBound = SUCCEEDED(psfb->InitializeSFB(psf, pidlFull));
  1434. if (fBound)
  1435. {
  1436. _pcmb->_nItemSubMenu = tbinfo.idCommand;
  1437. }
  1438. }
  1439. psf->Release();
  1440. }
  1441. ILFree(pidlFull);
  1442. psfb->Release();
  1443. }
  1444. }
  1445. }
  1446. return fBound;
  1447. }
  1448. HRESULT CMenuSFToolbar::OnTranslatedChange(LONG lEvent, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
  1449. {
  1450. HRESULT hr = CSFToolbar::OnTranslatedChange(lEvent, pidl1, pidl2);
  1451. if (SUCCEEDED(hr))
  1452. {
  1453. switch(lEvent)
  1454. {
  1455. case SHCNE_RENAMEFOLDER:
  1456. if (_IsChildID(pidl2, TRUE))
  1457. {
  1458. _ReBindToFolder(pidl2);
  1459. }
  1460. break;
  1461. case SHCNE_RMDIR:
  1462. if (_IsChildID(pidl1, TRUE))
  1463. {
  1464. _ReBindToFolder(pidl1);
  1465. }
  1466. break;
  1467. case SHCNE_EXTENDED_EVENT:
  1468. {
  1469. SHChangeDWORDAsIDList UNALIGNED * pdwidl = (SHChangeDWORDAsIDList UNALIGNED *)pidl1;
  1470. if (_IsChildID(pidl2, TRUE))
  1471. {
  1472. if (!SHChangeMenuWasSentByMe(this, pidl1))
  1473. {
  1474. DWORD dwFlags = SMINV_NOCALLBACK; // So that we don't doubly increment
  1475. SMDATA smd = {0};
  1476. smd.dwMask = SMDM_SHELLFOLDER;
  1477. smd.pidlFolder = _pidl;
  1478. smd.pidlItem = ILFindLastID(pidl2);
  1479. // Syncronize Promotion state.
  1480. if (pdwidl->dwItem1 == SHCNEE_PROMOTEDITEM)
  1481. {
  1482. dwFlags |= SMINV_PROMOTE;
  1483. }
  1484. else if (pdwidl->dwItem1 == SHCNEE_DEMOTEDITEM)
  1485. {
  1486. dwFlags |= SMINV_DEMOTE;
  1487. }
  1488. // Are we actually doing something?
  1489. if (SMINV_NOCALLBACK != dwFlags)
  1490. {
  1491. v_InvalidateItem(&smd, dwFlags);
  1492. }
  1493. }
  1494. }
  1495. }
  1496. break;
  1497. default:
  1498. break;
  1499. }
  1500. }
  1501. return hr;
  1502. }
  1503. // IShellChangeNotify::OnChange
  1504. HRESULT CMenuSFToolbar::OnChange(LONG lEvent, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
  1505. {
  1506. HRESULT hr = E_FAIL;
  1507. // If we're in the middle of being destroyed, don't process this.
  1508. if (!_hwndMB)
  1509. return S_OK;
  1510. AddRef();
  1511. _pcmb->_pmbState->PushChangeNotify();
  1512. SMCSHCHANGENOTIFYSTRUCT shns;
  1513. shns.lEvent = lEvent;
  1514. shns.pidl1 = pidl1;
  1515. shns.pidl2 = pidl2;
  1516. CallCB(NULL, SMC_SHCHANGENOTIFY, NULL, (LPARAM)&shns); // Ignore return value. Notify only.
  1517. // Since we may be removing the selected item, we want the selection to move to the next item
  1518. int iHot = ToolBar_GetHotItem(_hwndMB);
  1519. hr = CSFToolbar::OnChange(lEvent, pidl1, pidl2);
  1520. // Is this a child of this toolbar is some shape or form?
  1521. // 1) The changing pidl is a child of this pane.
  1522. // 2) What the pidl is changing to is in this pane (For renames)
  1523. // 3) Updatedirs. Recursive change notifies must forward update dirs all the way down the chain.
  1524. // 4) EXTENDED events with a pidl2 == NULL. This means Reorder all your items.
  1525. if (_IsChildID(pidl1, FALSE) ||
  1526. _IsChildID(pidl2, FALSE) ||
  1527. lEvent == SHCNE_UPDATEDIR ||
  1528. (lEvent == SHCNE_EXTENDED_EVENT &&
  1529. pidl2 == NULL))
  1530. {
  1531. // We need to forward this down then.
  1532. HRESULT hrInner = _pcmb->ForwardChangeNotify(lEvent, pidl1, pidl2);
  1533. // Did either of us handle this change?
  1534. if (SUCCEEDED(hrInner) || SUCCEEDED(hr))
  1535. {
  1536. hr = S_OK;
  1537. }
  1538. else if (lEvent != SHCNE_EXTENDED_EVENT) // Don't bother with extended events...
  1539. {
  1540. // Ok so neither of us handled this?
  1541. // Must be the SHChangeNotifyCollapsing code that collapses
  1542. // the Directory Create and item create into a single item create.
  1543. // We need to force an update dir on ourselves so that we get this change.
  1544. hr = CSFToolbar::OnChange(SHCNE_UPDATEDIR, pidl1, pidl2);
  1545. }
  1546. }
  1547. // Set the hot item back, wrapping if necessary.
  1548. if (ToolBar_GetHotItem(_hwndMB) != iHot)
  1549. SetHotItem(1, iHot, -1, 0);
  1550. _pcmb->_pmbState->PopChangeNotify();
  1551. Release();
  1552. return hr;
  1553. }
  1554. void CMenuSFToolbar::_OnDragBegin(int iItem, DWORD dwPreferredEffect)
  1555. {
  1556. // During drag and drop, allow dialogs to collapse menu.
  1557. LockSetForegroundWindow(LSFW_UNLOCK);
  1558. LPCITEMIDLIST pidl = _IDToPidl(iItem, NULL);
  1559. dwPreferredEffect = DROPEFFECT_MOVE;
  1560. CallCB(pidl, SMC_BEGINDRAG, (WPARAM)&dwPreferredEffect, 0);
  1561. CSFToolbar::_OnDragBegin(iItem, dwPreferredEffect);
  1562. if (_fEditMode)
  1563. SetTimer(_hwndTB, MBTIMER_ENDEDIT, MBTIMER_ENDEDITTIME, 0);
  1564. }
  1565. void CMenuSFToolbar::v_SendMenuNotification(UINT idCmd, BOOL fClear)
  1566. {
  1567. if (fClear)
  1568. {
  1569. // If we're clearing, tell the browser
  1570. PostMessage(_pcmb->_pmbState->GetSubclassedHWND(), WM_MENUSELECT,
  1571. MAKEWPARAM(0, -1), NULL);
  1572. }
  1573. else
  1574. {
  1575. PIBDATA pibdata = _IDToPibData(idCmd);
  1576. LPCITEMIDLIST pidl;
  1577. // Only send notifications for non submenu items
  1578. if (EVAL(pibdata) && (pidl = pibdata->GetPidl()))
  1579. {
  1580. CallCB(pidl, SMC_SFSELECTITEM, 0, 0);
  1581. // Don't free Pidl
  1582. }
  1583. }
  1584. }
  1585. LRESULT CMenuSFToolbar::_OnGetObject(NMOBJECTNOTIFY* pnmon)
  1586. {
  1587. pnmon->hResult = QueryInterface(*pnmon->piid, &pnmon->pObject);
  1588. return 1;
  1589. }
  1590. LRESULT CMenuSFToolbar::_OnNotify(LPNMHDR pnm)
  1591. {
  1592. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  1593. LRESULT lres = 0;
  1594. // These are notifies we handle even when disengaged from the message hook.
  1595. switch (pnm->code)
  1596. {
  1597. case TBN_DELETINGBUTTON:
  1598. if (_fEmptyingToolbar)
  1599. return 0;
  1600. else
  1601. goto DoDefault;
  1602. break;
  1603. case TBN_GETDISPINFOA:
  1604. case TBN_GETDISPINFOW:
  1605. case NM_CUSTOMDRAW:
  1606. goto DoDefault;
  1607. }
  1608. // Pager notifications MUST be forwarded even when the message hook is disengaged.
  1609. if ((pnm->code <= PGN_FIRST) && (pnm->code >= PGN_LAST))
  1610. {
  1611. goto DoNotify;
  1612. }
  1613. // Is the Global Message filter Disengaged? This will happen when the Subclassed window
  1614. // looses activation to a dialog box of some kind.
  1615. if (lres == 0 && !GetMessageFilter()->IsEngaged())
  1616. {
  1617. // Yes; We've lost activation so we don't want to track like a normal menu...
  1618. // For hot item change, return 1 so that the toolbar does not change the hot item.
  1619. if (pnm->code == TBN_HOTITEMCHANGE && _pcmb->_fMenuMode)
  1620. return 1;
  1621. // For all other items, don't do anything....
  1622. return 0;
  1623. }
  1624. DoNotify:
  1625. switch (pnm->code)
  1626. {
  1627. case PGN_SCROLL:
  1628. KillTimer(_hwndMB, MBTIMER_DRAGPOPDOWN);
  1629. if (_pcmb->_fInSubMenu)
  1630. _pcmb->_SubMenuOnSelect(MPOS_CANCELLEVEL);
  1631. _fSuppressUserMonitor = TRUE;
  1632. break;
  1633. case TBN_GETOBJECT:
  1634. lres = _OnGetObject((NMOBJECTNOTIFY*)pnm);
  1635. break;
  1636. case TBN_DRAGOUT:
  1637. {
  1638. TBNOTIFY *ptbn = (TBNOTIFY*)pnm;
  1639. if (!_fEmpty && !_IsSpecialCmd(ptbn->iItem) &&
  1640. !(_pcmb->_dwFlags & SMINIT_RESTRICT_DRAGDROP) &&
  1641. (S_FALSE == CallCB(NULL, SMC_SFDDRESTRICTED, NULL, NULL)))
  1642. {
  1643. // We're now in edit mode
  1644. _fEditMode = TRUE;
  1645. _idCmdDragging = ptbn->iItem;
  1646. _MarkItem(ptbn->iItem);
  1647. lres = 1; // Allow the drag to occur
  1648. goto DoDefault;
  1649. }
  1650. else
  1651. lres = 0; // Do not allow the drag out.
  1652. }
  1653. break;
  1654. default:
  1655. DoDefault:
  1656. lres = CMenuToolbarBase::_OnNotify(pnm);
  1657. if (lres == 0)
  1658. {
  1659. lres = CSFToolbar::_OnNotify(pnm);
  1660. }
  1661. break;
  1662. }
  1663. return lres;
  1664. }
  1665. HRESULT CMenuSFToolbar::CreateToolbar(HWND hwndParent)
  1666. {
  1667. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  1668. HRESULT hr = CSFToolbar::_CreateToolbar(hwndParent);
  1669. if (SUCCEEDED(hr))
  1670. {
  1671. if (_hwndPager)
  1672. {
  1673. SHSetWindowBits(_hwndPager, GWL_STYLE, PGS_DRAGNDROP, PGS_DRAGNDROP);
  1674. SHSetWindowBits(_hwndPager, GWL_STYLE, PGS_AUTOSCROLL, PGS_AUTOSCROLL);
  1675. SHSetWindowBits(_hwndPager, GWL_STYLE, PGS_HORZ|PGS_VERT,
  1676. _fVertical ? PGS_VERT : PGS_HORZ);
  1677. }
  1678. _hwndMB = _hwndTB;
  1679. SetWindowTheme(_hwndMB, L"", L"");
  1680. hr = CMenuToolbarBase::CreateToolbar(hwndParent);
  1681. // By "Registering optimized" means that someone else is going to pass the change to us,
  1682. // we don't need to register for it. This is for the disjoint Fast Items | Programs menu case.
  1683. // We still need top level change notify registration for Favorites, Documents, Printers and Control
  1684. // Panel (Depending on their visibility)
  1685. //
  1686. if (_pcmb->_uId == MNFOLDER_IS_PARENT ||
  1687. (_dwFlags & SMSET_DONTREGISTERCHANGENOTIFY))
  1688. _fRegisterChangeNotify = FALSE;
  1689. // This is a good as spot as any to do this:
  1690. _RegisterToolbar();
  1691. }
  1692. return hr;
  1693. }
  1694. HKEY CMenuSFToolbar::_GetKey(LPCITEMIDLIST pidl)
  1695. {
  1696. HKEY hMenuKey;
  1697. DWORD dwDisp;
  1698. TCHAR szDisplay[MAX_PATH];
  1699. if (!_hKey)
  1700. return NULL;
  1701. _ObtainPIDLName(pidl, szDisplay, ARRAYSIZE(szDisplay));
  1702. // setshellfolder calls need read and write key
  1703. RegCreateKeyEx(_hKey, szDisplay, NULL, NULL,
  1704. REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE,
  1705. NULL, &hMenuKey, &dwDisp);
  1706. TraceMsg(TF_MENUBAND, "%d is setting %s\'s Key to %d", _hKey, szDisplay, hMenuKey);
  1707. return hMenuKey;
  1708. }
  1709. //***
  1710. // NOTES
  1711. // idtCmd is currently always -1. we'll need other values when we're
  1712. // called from CallCB. however we can't do that until we move idtCmd
  1713. // 'down' into CallCB.
  1714. HRESULT CMenuSFToolbar::v_GetState(int idtCmd, LPSMDATA psmd)
  1715. {
  1716. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  1717. HRESULT hr = E_FAIL;
  1718. CMenuData* pdata;
  1719. LPITEMIDLIST pidl = NULL;
  1720. psmd->dwMask = SMDM_SHELLFOLDER;
  1721. if (idtCmd == -1)
  1722. idtCmd = GetButtonCmd(_hwndTB, ToolBar_GetHotItem(_hwndTB));
  1723. pdata = (CMenuData*)_IDToPibData(idtCmd);
  1724. if (EVAL(pdata))
  1725. {
  1726. pidl = pdata->GetPidl();
  1727. ASSERT(IS_VALID_PIDL(pidl));
  1728. }
  1729. if (pidl)
  1730. {
  1731. if (_pasf2 && S_OK == _pasf2->UnWrapIDList(pidl, 1, &psmd->psf, &psmd->pidlFolder, &psmd->pidlItem, NULL))
  1732. {
  1733. /*NOTHING*/
  1734. ;
  1735. }
  1736. else
  1737. {
  1738. // Then it must be a straight ShellFolder.
  1739. psmd->psf = _psf;
  1740. if (EVAL(psmd->psf))
  1741. psmd->psf->AddRef();
  1742. psmd->pidlFolder = ILClone(_pidl);
  1743. psmd->pidlItem = ILClone(ILFindLastID(pidl));
  1744. }
  1745. psmd->uIdParent = _pcmb->_uId;
  1746. psmd->punk = SAFECAST(_pcmb, IShellMenu*);
  1747. psmd->punk->AddRef();
  1748. hr = S_OK;
  1749. }
  1750. return hr;
  1751. }
  1752. HRESULT CMenuSFToolbar::CallCB(LPCITEMIDLIST pidl, DWORD dwMsg, WPARAM wParam, LPARAM lParam)
  1753. {
  1754. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  1755. if (!_pcmb->_psmcb)
  1756. return S_FALSE;
  1757. SMDATA smd;
  1758. HRESULT hr = S_FALSE;
  1759. BOOL fDestroy = FALSE;
  1760. // todo: call v_GetState (but need idCmd for pidl)
  1761. smd.dwMask = SMDM_SHELLFOLDER;
  1762. if (pidl)
  1763. {
  1764. // We used to unwrap the pidl here in the case of AUGMISF, but why? In the Callback, we only
  1765. // needed the Full pidl for Executing and for Darwin. The unwrap is an expensive call that in
  1766. // the majority case wasn't even used. Put it on the client to unwrap it. Start Menu is the
  1767. // only user of Augmented shell folders anyway....
  1768. smd.psf = _psf;
  1769. smd.pidlFolder = _pidl;
  1770. smd.pidlItem = (LPITEMIDLIST)pidl;
  1771. }
  1772. else
  1773. {
  1774. // Null pidl means tell the callback about me...
  1775. smd.pidlItem = ILClone(ILFindLastID(_pidl));
  1776. smd.pidlFolder = ILClone(_pidl);
  1777. ILRemoveLastID(smd.pidlFolder);
  1778. smd.psf = NULL; // Incase bind fails.
  1779. IEBindToObject(smd.pidlFolder, &smd.psf);
  1780. fDestroy = TRUE;
  1781. }
  1782. smd.uIdParent = _pcmb->_uId;
  1783. smd.uIdAncestor = _pcmb->_uIdAncestor;
  1784. smd.punk = SAFECAST(_pcmb, IShellMenu*);
  1785. smd.pvUserData = _pcmb->_pvUserData;
  1786. hr = _pcmb->_psmcb->CallbackSM(&smd, dwMsg, wParam, lParam);
  1787. if (fDestroy)
  1788. {
  1789. ATOMICRELEASE(smd.psf);
  1790. ILFree(smd.pidlFolder);
  1791. ILFree(smd.pidlItem);
  1792. }
  1793. return hr;
  1794. }
  1795. HRESULT CMenuSFToolbar::v_CallCBItem(int idtCmd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1796. {
  1797. LPCITEMIDLIST pidl = NULL;
  1798. CMenuData* pdata = NULL;
  1799. // Optimization:
  1800. if (uMsg == SMC_CUSTOMDRAW)
  1801. {
  1802. NMCUSTOMDRAW * pnmcd = (NMCUSTOMDRAW *)lParam;
  1803. if (pnmcd ->dwDrawStage & CDDS_ITEM)
  1804. {
  1805. pdata = (CMenuData*)pnmcd ->lItemlParam;
  1806. ASSERT(pdata);
  1807. }
  1808. }
  1809. else
  1810. {
  1811. pdata = (CMenuData*)_IDToPibData(idtCmd);
  1812. ASSERT(pdata);
  1813. }
  1814. if (pdata)
  1815. {
  1816. ASSERT(pdata->GetPidl() == NULL || IS_VALID_PIDL(pdata->GetPidl()));
  1817. pidl = pdata->GetPidl();
  1818. }
  1819. return CallCB(pidl, uMsg, wParam, lParam);
  1820. }
  1821. HRESULT CMenuSFToolbar::v_GetSubMenu(int idCmd, const GUID* pguidService, REFIID riid, void** ppvObj)
  1822. {
  1823. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  1824. CMenuData* pdata = (CMenuData*)_IDToPibData(idCmd);
  1825. HRESULT hr;
  1826. ASSERT(IS_VALID_WRITE_PTR(ppvObj, void*));
  1827. *ppvObj = NULL;
  1828. if (pdata && pdata->GetFlags() & SMIF_SUBMENU)
  1829. {
  1830. hr = pdata->GetSubMenu(pguidService, riid, (void**)ppvObj);
  1831. if (FAILED(hr) && IsEqualGUID(riid, IID_IShellMenu))
  1832. {
  1833. hr = CallCB(pdata->GetPidl(), SMC_GETSFOBJECT, (WPARAM)&riid, (LPARAM)ppvObj);
  1834. if (SUCCEEDED(hr))
  1835. {
  1836. BOOL fCache = TRUE;
  1837. if (S_OK != hr)
  1838. {
  1839. hr = E_FAIL;
  1840. IShellMenu* psm = (IShellMenu*) new CMenuBand();
  1841. if (psm)
  1842. {
  1843. IShellFolder* psf = NULL;
  1844. LPITEMIDLIST pidlItem = pdata->GetPidl();
  1845. LPITEMIDLIST pidlFolder = _pidl;
  1846. BOOL fDestroy = FALSE;
  1847. IShellMenuCallback* psmcb;
  1848. // Ask the callback if they want to supply a different callback
  1849. // object for this sub menu. If they do, then use what they
  1850. // pass back NOTE: If they pass back S_OK, it's perfectly Ok,
  1851. // for them to pass back a NULL psmcb. This means, I don't want
  1852. // my child to have a callback. Use the default.
  1853. // If they don't handle it, then use their pointer.
  1854. if (S_FALSE == CallCB(pdata->GetPidl(), SMC_GETSFOBJECT,
  1855. (WPARAM)&IID_IShellMenuCallback, (LPARAM)&psmcb))
  1856. {
  1857. psmcb = _pcmb->_psmcb;
  1858. if (psmcb)
  1859. psmcb->AddRef();
  1860. }
  1861. // This has to be before the unwrap because it does name resolution through
  1862. // the Augmented ISF.
  1863. HKEY hMenuKey = _GetKey(pidlItem);
  1864. if (_pasf2)
  1865. {
  1866. if (S_OK == _pasf2->UnWrapIDList(pdata->GetPidl(), 1, &psf, &pidlFolder, &pidlItem, NULL))
  1867. {
  1868. psf->Release(); // I don't need this
  1869. psf = NULL;
  1870. fDestroy = TRUE;
  1871. }
  1872. _pasf2->BindToObject(pdata->GetPidl(), NULL, IID_PPV_ARG(IShellFolder, &psf));
  1873. }
  1874. // Inherit the flags from the parent...
  1875. DWORD dwFlags = SMINIT_VERTICAL |
  1876. (_pcmb->_dwFlags & (SMINIT_RESTRICT_CONTEXTMENU |
  1877. SMINIT_RESTRICT_DRAGDROP |
  1878. SMINIT_MULTICOLUMN));
  1879. LPITEMIDLIST pidlFull = ILCombine(pidlFolder, pidlItem);
  1880. if (psf == NULL)
  1881. {
  1882. hr = _psf->BindToObject(pidlItem, NULL, IID_PPV_ARG(IShellFolder, &psf));
  1883. }
  1884. LPCITEMIDLIST pidlWrappedItem = pdata->GetPidl();
  1885. // _psf can be an augmented shell folder. Use the wrapped item....
  1886. DWORD dwAttrib = SFGAO_LINK | SFGAO_FOLDER;
  1887. if (SUCCEEDED(_psf->GetAttributesOf(1, (LPCITEMIDLIST*)&pidlWrappedItem, &dwAttrib)) &&
  1888. (dwAttrib & (SFGAO_LINK | SFGAO_FOLDER)) == (SFGAO_LINK | SFGAO_FOLDER))
  1889. {
  1890. // folder shortcuts, We're not going to persist anything
  1891. RegCloseKey(hMenuKey);
  1892. hMenuKey = NULL;
  1893. psmcb = NULL; // We're not going to pass a callback. NOTE: We don't need to release this
  1894. dwFlags &= ~SMINIT_MULTICOLUMN; // No multi on FShortcut...
  1895. fCache = FALSE;
  1896. }
  1897. UINT uIdAncestor = _pcmb->_uIdAncestor;
  1898. if (uIdAncestor == ANCESTORDEFAULT)
  1899. uIdAncestor = idCmd;
  1900. psm->Initialize(psmcb, MNFOLDER_IS_PARENT, uIdAncestor, dwFlags);
  1901. if (psf)
  1902. {
  1903. hr = psm->SetShellFolder(psf, pidlFull, hMenuKey,
  1904. _dwFlags & (SMSET_HASEXPANDABLEFOLDERS | SMSET_USEBKICONEXTRACTION));
  1905. if (SUCCEEDED(hr))
  1906. {
  1907. hr = psm->QueryInterface(riid, ppvObj);
  1908. }
  1909. psf->Release();
  1910. }
  1911. ILFree(pidlFull);
  1912. _SetMenuBand(psm);
  1913. psm->Release();
  1914. if (psmcb)
  1915. psmcb->Release();
  1916. if (fDestroy)
  1917. {
  1918. ILFree(pidlFolder);
  1919. ILFree(pidlItem);
  1920. }
  1921. }
  1922. }
  1923. if (*ppvObj)
  1924. {
  1925. if (fCache)
  1926. {
  1927. pdata->SetSubMenu((IUnknown*)*ppvObj);
  1928. }
  1929. VARIANT Var;
  1930. Var.vt = VT_UNKNOWN;
  1931. Var.byref = SAFECAST(_pcmb->_pmbm, IUnknown*);
  1932. // Set the CMenuBandMetrics into the new menuband
  1933. IUnknown_Exec((IUnknown*)*ppvObj, &CGID_MenuBand, MBANDCID_SETFONTS, 0, &Var, NULL);
  1934. // Set the CMenuBandState into the new menuband
  1935. Var.vt = VT_INT_PTR;
  1936. Var.byref = _pcmb->_pmbState;
  1937. IUnknown_Exec((IUnknown*)*ppvObj, &CGID_MenuBand, MBANDCID_SETSTATEOBJECT, 0, &Var, NULL);
  1938. }
  1939. }
  1940. }
  1941. }
  1942. else
  1943. {
  1944. hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
  1945. }
  1946. return hr;
  1947. }
  1948. DWORD CMenuSFToolbar::v_GetFlags(int idCmd)
  1949. {
  1950. CMenuData* pdata = (CMenuData*)_IDToPibData(idCmd);
  1951. // Toolbar is allowed to pass a bad command in the case of background erase
  1952. if (pdata)
  1953. return pdata->GetFlags();
  1954. else
  1955. return 0;
  1956. }
  1957. // This is to tell all other clients that we updated the promotion state of something.
  1958. void CMenuSFToolbar::BroadcastIntelliMenuState(LPCITEMIDLIST pidlItem, BOOL fPromoted)
  1959. {
  1960. LPITEMIDLIST pidlFolder;
  1961. LPITEMIDLIST pidlItemUnwrapped;
  1962. LPITEMIDLIST pidlFull;
  1963. if (_pasf2 && S_OK == _pasf2->UnWrapIDList(pidlItem, 1, NULL, &pidlFolder, &pidlItemUnwrapped, NULL))
  1964. {
  1965. pidlFull = ILCombine(pidlFolder, pidlItemUnwrapped);
  1966. ILFree(pidlFolder);
  1967. ILFree(pidlItemUnwrapped);
  1968. }
  1969. else
  1970. {
  1971. pidlFull = ILCombine(_pidl, pidlItem);
  1972. }
  1973. SHSendChangeMenuNotify(this,
  1974. fPromoted ? SHCNEE_PROMOTEDITEM : SHCNEE_DEMOTEDITEM,
  1975. 0, pidlFull);
  1976. ILFree(pidlFull);
  1977. }
  1978. STDAPI SHInvokeCommandWithFlags(HWND hwnd, IShellFolder* psf, LPCITEMIDLIST pidlItem, DWORD dwFlags, LPCSTR lpVerb)
  1979. {
  1980. HRESULT hr = E_FAIL;
  1981. if (psf)
  1982. {
  1983. IContextMenu *pcm;
  1984. if (SUCCEEDED(psf->GetUIObjectOf(hwnd, 1, &pidlItem, IID_X_PPV_ARG(IContextMenu, 0, &pcm))))
  1985. {
  1986. dwFlags |= IsOS(OS_WHISTLERORGREATER) ? CMIC_MASK_FLAG_LOG_USAGE : 0;
  1987. hr = SHInvokeCommandsOnContextMenu(hwnd, NULL, pcm, dwFlags, lpVerb ? &lpVerb : NULL, lpVerb ? 1 : 0);
  1988. pcm->Release();
  1989. }
  1990. }
  1991. return hr;
  1992. }
  1993. HRESULT CMenuSFToolbar::v_ExecItem(int idCmd)
  1994. {
  1995. CMenuData* pdata = (CMenuData*)_IDToPibData(idCmd);
  1996. HRESULT hr = E_FAIL;
  1997. if (pdata && !_fEmpty && !(_IsSpecialCmd(idCmd)))
  1998. {
  1999. // STRESS: pdata was becomming 0x8 for some reason after the InvokeDefault.
  2000. // I assume that this call was causing a flush, which frees our list of pidls.
  2001. // So, I'm cloning it. I also changed the order, so that we'll just fire the
  2002. // UEM event.
  2003. LPITEMIDLIST pidl = ILClone(pdata->GetPidl());
  2004. if (pidl)
  2005. {
  2006. ASSERT(IS_VALID_PIDL(pidl));
  2007. SMDATA smd;
  2008. smd.dwMask = SMDM_SHELLFOLDER;
  2009. smd.pidlFolder = _pidl;
  2010. smd.pidlItem = pidl;
  2011. // SMINV_FORCE here also tells the Start Menu that the invoke
  2012. // came from an Exec
  2013. v_InvalidateItem(&smd, SMINV_PROMOTE | SMINV_FORCE);
  2014. hr = CallCB(pidl, SMC_SFEXEC, 0, 0);
  2015. // Did the Callback handle this execute for us?
  2016. if (hr == S_FALSE)
  2017. {
  2018. // No, Ok, do it ourselves.
  2019. hr = SHInvokeCommandWithFlags(_hwndTB, _psf, pidl, CMIC_MASK_ASYNCOK, NULL);
  2020. }
  2021. ILFree(pidl);
  2022. }
  2023. }
  2024. return hr;
  2025. }
  2026. HRESULT CMenuSFToolbar::v_GetInfoTip(int idCmd, LPTSTR psz, UINT cch)
  2027. {
  2028. CMenuData* pdata = (CMenuData*)_IDToPibData(idCmd);
  2029. HRESULT hr = E_FAIL;
  2030. if (_fEmpty || !pdata)
  2031. return hr;
  2032. // make a copy of the pidl that we're using, since we can get reentered in the sendmessage
  2033. // and free the data from the dpa.
  2034. LPITEMIDLIST pidlCopy = ILClone(pdata->GetPidl());
  2035. // dont worry about failure -- pdata->GetPidl() can be NULL anyway,
  2036. // in which case ILClone will return NULL, and CallCB and GetInfoTip already have NULL checks.
  2037. hr = CallCB(pidlCopy, SMC_GETSFINFOTIP, (WPARAM)psz, (LPARAM)cch);
  2038. if (S_FALSE == hr)
  2039. {
  2040. hr = E_FAIL;
  2041. if (GetInfoTip(_psf, pidlCopy, psz, cch))
  2042. {
  2043. hr = S_OK;
  2044. }
  2045. }
  2046. ILFree(pidlCopy);
  2047. return hr;
  2048. }
  2049. void CMenuSFToolbar::v_ForwardMouseMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  2050. {
  2051. RECT rc;
  2052. POINT pt;
  2053. HWND hwndFwd;
  2054. // These are in screen coords
  2055. pt.x = GET_X_LPARAM(lParam);
  2056. pt.y = GET_Y_LPARAM(lParam);
  2057. hwndFwd = _hwndPager ? _hwndPager : _hwndTB;
  2058. GetWindowRect(hwndFwd, &rc);
  2059. if (PtInRect(&rc, pt))
  2060. {
  2061. MapWindowPoints(NULL, hwndFwd, &pt, 1);
  2062. HWND hwnd = ChildWindowFromPoint(hwndFwd, pt);
  2063. if (hwnd)
  2064. {
  2065. MapWindowPoints(hwndFwd, hwnd, &pt, 1);
  2066. }
  2067. else
  2068. {
  2069. hwnd = hwndFwd;
  2070. }
  2071. SendMessage(hwnd, uMsg, wParam, MAKELONG(pt.x, pt.y));
  2072. }
  2073. }
  2074. HRESULT CMenuSFToolbar::OnWinEvent(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plres)
  2075. {
  2076. switch(uMsg)
  2077. {
  2078. case WM_SYSCOLORCHANGE:
  2079. if (_hwndPager)
  2080. Pager_SetBkColor(_hwndPager, GetSysColor(COLOR_MENU));
  2081. // Change the color, so that we can see it.
  2082. ToolBar_SetInsertMarkColor(_hwndMB, GetSysColor(COLOR_MENUTEXT));
  2083. break;
  2084. }
  2085. HRESULT hr = CMenuToolbarBase::OnWinEvent(hwnd, uMsg, wParam, lParam, plres);
  2086. if (hr != S_OK)
  2087. hr = CSFToolbar::OnWinEvent(hwnd, uMsg, wParam, lParam, plres);
  2088. return hr;
  2089. }
  2090. BOOL CMenuSFToolbar::v_UpdateIconSize(UINT uIconSize, BOOL fUpdateButtons)
  2091. {
  2092. if (uIconSize == -1)
  2093. uIconSize = _uIconSize;
  2094. _uIconSizeMB = uIconSize;
  2095. return _UpdateIconSize(_uIconSizeMB, fUpdateButtons);
  2096. }
  2097. HRESULT CMenuSFToolbar::GetShellFolder(LPITEMIDLIST* ppidl, REFIID riid, void** ppvObj)
  2098. {
  2099. HRESULT hr = E_FAIL;
  2100. *ppvObj = NULL;
  2101. if (_psf)
  2102. {
  2103. hr = _psf->QueryInterface(riid, ppvObj);
  2104. }
  2105. if (SUCCEEDED(hr) && ppidl)
  2106. {
  2107. *ppidl = ILClone(_pidl);
  2108. if (! *ppidl)
  2109. {
  2110. (*(IUnknown**)ppvObj)->Release();
  2111. *ppvObj = NULL;
  2112. hr = E_FAIL;
  2113. }
  2114. }
  2115. return hr;
  2116. }
  2117. LRESULT CMenuSFToolbar::_OnTimer(WPARAM wParam)
  2118. {
  2119. switch(wParam)
  2120. {
  2121. case MBTIMER_ENDEDIT:
  2122. KillTimer(_hwndTB, wParam);
  2123. _fEditMode = FALSE;
  2124. break;
  2125. case MBTIMER_CLICKUNHANDLE:
  2126. KillTimer(_hwndTB, wParam);
  2127. _fClickHandled = FALSE;
  2128. break;
  2129. default:
  2130. return CMenuToolbarBase::_OnTimer(wParam);
  2131. }
  2132. return 1;
  2133. }
  2134. LRESULT CMenuSFToolbar::_OnDropDown(LPNMTOOLBAR pnmtb)
  2135. {
  2136. if (GetAsyncKeyState(VK_LBUTTON) < 0 && _fEditMode)
  2137. {
  2138. // Are we in edit mode?
  2139. if (_fEditMode)
  2140. {
  2141. // Yes, mark the item as the item that is subject to moving
  2142. _MarkItem(pnmtb->iItem);
  2143. }
  2144. return TBDDRET_TREATPRESSED;
  2145. }
  2146. return CMenuToolbarBase::_OnDropDown(pnmtb);
  2147. }
  2148. // In the context of a menuband, marking means putting
  2149. // a black rectangle around the item currently being dragged.
  2150. void CMenuSFToolbar::_MarkItem(int idCmd)
  2151. {
  2152. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  2153. // Un-highlight the previously moved button
  2154. if (0 <= _pcmb->_nItemMove)
  2155. {
  2156. // Should item move be a member of SFToolbar?
  2157. ToolBar_MarkButton(_hwndTB, _pcmb->_nItemMove, FALSE);
  2158. _pcmb->_nItemMove = -1;
  2159. }
  2160. if (_fEditMode)
  2161. {
  2162. _pcmb->_nItemMove = idCmd;
  2163. ToolBar_MarkButton(_hwndTB, _pcmb->_nItemMove, TRUE);
  2164. }
  2165. }
  2166. STDMETHODIMP CMenuSFToolbar::IsWindowOwner(HWND hwnd)
  2167. {
  2168. if (_hwndTB == hwnd || _hwndPager == hwnd || HWND_BROADCAST == hwnd)
  2169. {
  2170. return S_OK;
  2171. }
  2172. else
  2173. {
  2174. return S_FALSE;
  2175. }
  2176. }
  2177. void CMenuSFToolbar::SetWindowPos(LPSIZE psize, LPRECT prc, DWORD dwFlags)
  2178. {
  2179. if (!_hwndPager)
  2180. {
  2181. CMenuToolbarBase::SetWindowPos(psize, prc, dwFlags);
  2182. return;
  2183. }
  2184. DWORD rectWidth = RECTWIDTH(*prc);
  2185. TraceMsg(TF_MENUBAND, "CMSFTB::SetWindowPos %d - (%d,%d,%d,%d)", psize?psize->cx:0,
  2186. prc->left, prc->top, prc->right, prc->bottom);
  2187. ShowWindow(_hwndPager, SW_SHOW);
  2188. ::SetWindowPos(_hwndPager, NULL, prc->left, prc->top,
  2189. rectWidth, RECTHEIGHT(*prc), SWP_NOZORDER | SWP_NOACTIVATE | dwFlags);
  2190. if (psize)
  2191. {
  2192. int cx = psize->cx;
  2193. ToolBar_SetButtonWidth(_hwndTB, cx, cx);
  2194. }
  2195. SendMessage(_hwndPager, PGMP_RECALCSIZE, 0L, 0L);
  2196. }
  2197. void CMenuSFToolbar::SetParent(HWND hwndParent)
  2198. {
  2199. int nCmdShow = SW_SHOW;
  2200. if (hwndParent)
  2201. {
  2202. if (!_hwndTB)
  2203. CreateToolbar(hwndParent);
  2204. else
  2205. {
  2206. // make sure width is set correctly . . .
  2207. SendMessage(_hwndTB, TB_SETBUTTONWIDTH, 0, MAKELONG(_cxMin, _cxMax));
  2208. }
  2209. }
  2210. else
  2211. {
  2212. // As an optimization, we implement "disowning" ourselves
  2213. // as just moving ourselves offscreen. The previous parent
  2214. // still owns us. The parent is invariably the menusite.
  2215. RECT rc = {-1,-1,-1,-1};
  2216. SetWindowPos(NULL, &rc, 0);
  2217. nCmdShow = SW_HIDE;
  2218. }
  2219. HWND hwnd = _hwndPager ? _hwndPager: _hwndTB;
  2220. if (IsWindow(hwnd)) // JANK : Fix for bug #98253
  2221. {
  2222. if (nCmdShow == SW_HIDE)
  2223. {
  2224. ShowWindow(hwnd, nCmdShow);
  2225. }
  2226. ::SetParent(hwnd, hwndParent);
  2227. SendMessage(hwnd, TB_SETPARENT, (WPARAM)hwndParent, NULL);
  2228. if (nCmdShow == SW_SHOW)
  2229. {
  2230. ShowWindow(hwnd, nCmdShow);
  2231. }
  2232. }
  2233. }
  2234. void CMenuSFToolbar::Expand(BOOL fExpand)
  2235. {
  2236. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  2237. TBBUTTON tbb;
  2238. DAD_ShowDragImage(FALSE);
  2239. // Since we're not sure if the Chevron is going to be visible we should remove it here
  2240. // Later we'll add it back in if it's needed.
  2241. _RemoveNSSeparator();
  2242. _RemoveChevron();
  2243. // Loop through and apply the fExpand
  2244. int iNumButtons = ToolBar_ButtonCount(_hwndTB);
  2245. // We reset these when iterating.
  2246. _cPromotedItems = 0;
  2247. _fHasDemotedItems = FALSE;
  2248. int iHotItem = ToolBar_GetHotItem(_hwndMB);
  2249. // SendMessage(_hwndMB, WM_SETREDRAW, FALSE, 0);
  2250. for (int i = 0; i < iNumButtons; i++)
  2251. {
  2252. if (!ToolBar_GetButton(_hwndMB, i, &tbb))
  2253. continue;
  2254. CMenuData* pmd = (CMenuData*)tbb.dwData;
  2255. // Get the toolbar state. Toolbar can set things like
  2256. // TBSTATE_WRAP that we would go nuke.
  2257. DWORD dwState = tbb.fsState;
  2258. DWORD dwFlags = pmd ? pmd->GetFlags() : 0;
  2259. if (dwFlags & SMIF_DEMOTED)
  2260. {
  2261. // Are we expanding?
  2262. if (fExpand)
  2263. {
  2264. //Yes; Enable the button and remove the hidden state
  2265. dwState |= TBSTATE_ENABLED;
  2266. dwState &= ~TBSTATE_HIDDEN;
  2267. }
  2268. else
  2269. {
  2270. //No; Remove the Enabled state and hide the button
  2271. dwState |= TBSTATE_HIDDEN;
  2272. dwState &= ~TBSTATE_ENABLED;
  2273. }
  2274. _fHasDemotedItems = TRUE;
  2275. }
  2276. else if (dwFlags & SMIF_HIDDEN)
  2277. {
  2278. dwState |= TBSTATE_HIDDEN;
  2279. dwState &= ~TBSTATE_ENABLED;
  2280. }
  2281. else if (tbb.idCommand != _idCmdChevron)
  2282. {
  2283. dwState |= TBSTATE_ENABLED;
  2284. dwState &= ~TBSTATE_HIDDEN;
  2285. _cPromotedItems++;
  2286. }
  2287. // If the state has changed, then set it into the toolbar.
  2288. if (dwState != tbb.fsState)
  2289. ToolBar_SetState(_hwndTB, tbb.idCommand, dwState);
  2290. }
  2291. // _fExpand means "Draw as Expanded". We do not want to
  2292. // draw expanded when we have no demoted items.
  2293. _pcmb->_fExpanded = _fHasDemotedItems? fExpand : FALSE;
  2294. if (fExpand)
  2295. {
  2296. if (_pcmb->_pmbState)
  2297. {
  2298. _pcmb->_pmbState->SetExpand(TRUE);
  2299. _pcmb->_pmbState->HideTooltip(TRUE);
  2300. }
  2301. }
  2302. else
  2303. {
  2304. _AddChevron();
  2305. }
  2306. _AddNSSeparator();
  2307. // Have the menubar think about changing its height
  2308. IUnknown_QueryServiceExec(_pcmb->_punkSite, SID_SMenuPopup, &CGID_MENUDESKBAR,
  2309. MBCID_SETEXPAND, _fHasDemotedItems?(int)_pcmb->_pmbState->GetExpand():FALSE, NULL, NULL);
  2310. // SendMessage(_hwndMB, WM_SETREDRAW, TRUE, 0);
  2311. _ToolbarChanged();
  2312. ToolBar_SetHotItem(_hwndMB, iHotItem);
  2313. if (_hwndPager)
  2314. UpdateWindow(_hwndPager);
  2315. UpdateWindow(_hwndTB);
  2316. DAD_ShowDragImage(TRUE);
  2317. }
  2318. void CMenuSFToolbar::GetSize(SIZE* psize)
  2319. {
  2320. CMenuToolbarBase::GetSize(psize);
  2321. if (_fEmpty && _fDontShowEmpty)
  2322. {
  2323. psize->cy = 0;
  2324. TraceMsg(TF_MENUBAND, "CMSFT::GetSize (%d, %d)", psize->cx, psize->cy);
  2325. }
  2326. }
  2327. void CMenuSFToolbar::_RefreshInfo()
  2328. {
  2329. int cButton = ToolBar_ButtonCount(_hwndMB);
  2330. for (int iButton = 0; iButton < cButton; iButton++)
  2331. {
  2332. int idCmd = GetButtonCmd(_hwndTB, iButton);
  2333. if (!_IsSpecialCmd(idCmd))
  2334. {
  2335. // Get the information from that button.
  2336. CMenuData* pmd = (CMenuData*)_IDToPibData(idCmd);
  2337. if (pmd)
  2338. {
  2339. SMINFO sminfo;
  2340. sminfo.dwMask = SMIM_FLAGS;
  2341. if (SUCCEEDED(_GetInfo(pmd->GetPidl(), &sminfo)))
  2342. {
  2343. pmd->SetFlags(sminfo.dwFlags);
  2344. }
  2345. }
  2346. }
  2347. }
  2348. }
  2349. void CMenuSFToolbar::_FindMinPromotedItems(BOOL fSetOrderStream)
  2350. {
  2351. // We need to iterate through the buttons and set the Promoted flag.
  2352. int cButton = ToolBar_ButtonCount(_hwndMB);
  2353. for (int iButton = 0; iButton < cButton; iButton++)
  2354. {
  2355. int idCmd = GetButtonCmd(_hwndTB, iButton);
  2356. if (!_IsSpecialCmd(idCmd))
  2357. {
  2358. // Get the information from that button.
  2359. CMenuData* pmd = (CMenuData*)_IDToPibData(idCmd);
  2360. if (pmd)
  2361. {
  2362. PORDERITEM poi = pmd->GetOrderItem();
  2363. if (fSetOrderStream)
  2364. {
  2365. DWORD dwFlags = pmd->GetFlags();
  2366. OrderItem_SetFlags(poi, dwFlags);
  2367. }
  2368. else // Query the order stream
  2369. {
  2370. DWORD dwFlags = OrderItem_GetFlags(poi);
  2371. DWORD dwOldFlags = pmd->GetFlags();
  2372. // When reading the flags from the registry, we only care about the demote flag.
  2373. if (dwFlags & SMIF_DEMOTED)
  2374. {
  2375. dwOldFlags |= SMIF_DEMOTED;
  2376. }
  2377. else if (!(dwOldFlags & SMIF_SUBMENU)) // Don't promote sub menus.
  2378. {
  2379. // Force a promote
  2380. CallCB(pmd->GetPidl(), SMC_PROMOTE, 0, 0);
  2381. dwOldFlags &= ~SMIF_DEMOTED;
  2382. }
  2383. pmd->SetFlags(dwOldFlags);
  2384. }
  2385. }
  2386. }
  2387. }
  2388. }
  2389. void CMenuSFToolbar::v_Show(BOOL fShow, BOOL fForceUpdate)
  2390. {
  2391. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  2392. CMenuToolbarBase::v_Show(fShow, fForceUpdate);
  2393. if (fShow)
  2394. {
  2395. BOOL fDirty = _fDirty;
  2396. _fClickHandled = FALSE;
  2397. _RegisterToolbar();
  2398. // this is to flush the whole thing if we got invalidated (like the
  2399. // darwin hack makes us do). if we don't clear out, then some
  2400. // stale data is left in and _FillToolbar doesn't flush it any more.
  2401. if (fDirty)
  2402. {
  2403. EmptyToolbar();
  2404. }
  2405. _FillToolbar();
  2406. _pcmb->SetTracked(NULL); // Since hot item is NULL
  2407. ToolBar_SetHotItem(_hwndTB, -1);
  2408. if (_fEmpty && (_dwFlags & SMSET_NOEMPTY))
  2409. {
  2410. _fDontShowEmpty = TRUE;
  2411. }
  2412. else if (_fRefreshInfo && !fDirty) // Do we need to refresh our information?
  2413. {
  2414. // Yes;
  2415. _RefreshInfo();
  2416. }
  2417. // HACKHACK (lamadio) : There is a sizing issue, where the sizing between the
  2418. // toolbars gets preemted by a resize of the menubar before the size calculation completes.
  2419. // So:
  2420. // ShowDW - Asks each toolbar to calc it's width
  2421. // CMenuSFToolbar::v_Show - Does a _FillToolbar. Since (in this senario) an item
  2422. // Has been added, it calls _ToolbarChanged
  2423. // _ToolbarChanged - This says to the menubar, I've changed sizes, recalc.
  2424. // ResizeMenuBar - In the depths, it eventually calls OnPosRectChanged, which asks each
  2425. // Toolbar what it's size is. Since the menu portion has not calculated it yet,
  2426. // It has the old size which is has the old size of the sftoolbar. So everything
  2427. // Gets reset to that size.
  2428. //
  2429. // We only want to Call expand if we are dirty or the expand state has changed. We
  2430. // call for the Dirty case, because Expand does some neat stuff in calculating the
  2431. // number of promoted items. If the state has changed, we want to reflect that.
  2432. BOOL fExpand = _pcmb->_pmbState ? _pcmb->_pmbState->GetExpand() : FALSE;
  2433. if ((BOOL)_pcmb->_fExpanded != fExpand || fDirty || _fRefreshInfo)
  2434. {
  2435. fForceUpdate = TRUE;
  2436. Expand(fExpand);
  2437. }
  2438. // Only do this in the beginning.
  2439. if (_fFirstTime)
  2440. {
  2441. CallCB(NULL, SMC_GETMINPROMOTED, 0, (LPARAM)&_cMinPromotedItems);
  2442. if (_cPromotedItems < _cMinPromotedItems)
  2443. {
  2444. _FindMinPromotedItems(FALSE);
  2445. Expand(fExpand);
  2446. }
  2447. }
  2448. // Have the menubar think about changing its height
  2449. // we need to do this here because the menubar may have changed it's
  2450. // expand state independant of the pane.
  2451. IUnknown_QueryServiceExec(_pcmb->_punkSite, SID_SMenuPopup, &CGID_MENUDESKBAR,
  2452. MBCID_SETEXPAND, (int)_pcmb->_fExpanded, NULL, NULL);
  2453. // If we're dirty, have our parent consider promoting itself if there
  2454. // are promoted items in the menu, or demoting itself if there arn't.
  2455. // Don't worry, the parent won't do anything if it's already in that state.
  2456. if (fDirty)
  2457. {
  2458. IUnknown_RefreshParent(_pcmb->_punkSite, _pidl,
  2459. ((_cPromotedItems == 0)? SMINV_DEMOTE : SMINV_PROMOTE) | SMINV_NEXTSHOW);
  2460. }
  2461. // If it is empty, we want to auto expand.
  2462. // We have to do this before the update buttons, so that the size is calculate correctly.
  2463. if (_cPromotedItems == 0 && !_pcmb->_fExpanded)
  2464. Expand(TRUE);
  2465. if (fForceUpdate)
  2466. _UpdateButtons();
  2467. if (_fHasDemotedItems)
  2468. {
  2469. if (S_OK == CallCB(NULL, SMC_DISPLAYCHEVRONTIP, 0, 0))
  2470. {
  2471. _FlashChevron();
  2472. }
  2473. }
  2474. _fFirstTime = FALSE;
  2475. _fRefreshInfo = FALSE;
  2476. }
  2477. else
  2478. {
  2479. KillTimer(_hwndMB, MBTIMER_UEMTIMEOUT);
  2480. }
  2481. _fShowMB = _fShow = fShow;
  2482. // Reset these so we don't have stale information for the next drag drop cycle. NT #287914 (lamadio) 3.22.99
  2483. _tbim.iButton = -1;
  2484. _tbim.dwFlags = 0;
  2485. _idCmdDragging = -1;
  2486. // n.b. for !fShow, we don't kill the tracked site chain. we
  2487. // count on this in startmnu.cpp!CStartMenuCallback::_OnExecItem,
  2488. // where we walk up the chain to find all hit 'nodes'. if we need
  2489. // to change this we could fire a 'pre-exec' event.
  2490. }
  2491. void CMenuSFToolbar::v_UpdateButtons(BOOL fNegotiateSize)
  2492. {
  2493. CSFToolbar::_UpdateButtons();
  2494. if (_hwndTB && fNegotiateSize && _fVerticalMB)
  2495. NegotiateSize();
  2496. }
  2497. // this method invalidates a single item in the toolbar
  2498. HRESULT CMenuSFToolbar::v_InvalidateItem(LPSMDATA psmd, DWORD dwFlags)
  2499. {
  2500. ASSERT(_pcmb); // if you hit this assert, you haven't initialized yet.. call SetSite first
  2501. // Default to not not handling this event.
  2502. HRESULT hr = S_FALSE;
  2503. if (NULL == psmd)
  2504. {
  2505. if (dwFlags & SMINV_REFRESH)
  2506. {
  2507. _Refresh();
  2508. hr = S_OK;
  2509. }
  2510. }
  2511. else if (psmd->dwMask & SMDM_SHELLFOLDER)
  2512. {
  2513. // Yes;
  2514. int i;
  2515. LPITEMIDLIST pidlButton = NULL;
  2516. SMINFO sminfo;
  2517. sminfo.dwMask = SMIM_FLAGS;
  2518. // Since this pidl is comming from an outside source,
  2519. // we may need to translate it to a wrapped pidl.
  2520. // Do we have a pidl Translator?
  2521. if (_ptscn)
  2522. {
  2523. // Yes;
  2524. LPITEMIDLIST pidlTranslated;
  2525. LPITEMIDLIST pidlDummy = NULL;
  2526. LPITEMIDLIST pidlToTranslate = ILCombine(psmd->pidlFolder, psmd->pidlItem);
  2527. if (pidlToTranslate)
  2528. {
  2529. LONG lEvent = 0, lEvent2;
  2530. LPITEMIDLIST pidlDummy1, pidlDummy2;
  2531. if (SUCCEEDED(_ptscn->TranslateIDs(&lEvent, pidlToTranslate, NULL, &pidlTranslated, &pidlDummy,
  2532. &lEvent2, &pidlDummy1, &pidlDummy2)))
  2533. {
  2534. // Get the button in the toolbar that corresponds to this pidl.
  2535. _GetButtonFromPidl(ILFindLastID(pidlTranslated), NULL, &i, &pidlButton);
  2536. // if pidl does not get translated TranslateIDs returns the same pidl passed
  2537. // to the function
  2538. if (pidlTranslated != pidlToTranslate)
  2539. ILFree(pidlTranslated);
  2540. // Don't need to delete pidlDummy because it's not set.
  2541. ASSERT(pidlDummy == NULL);
  2542. ASSERT(pidlDummy1 == NULL);
  2543. ASSERT(pidlDummy2 == NULL);
  2544. }
  2545. ILFree(pidlToTranslate);
  2546. }
  2547. }
  2548. // Did we come from a non-augmented shell folder, or
  2549. // did the caller pass a wrapped pidl?
  2550. if (!pidlButton)
  2551. {
  2552. // Seems like it, we'll try to find the pidl they passed in
  2553. // Get the button in the toolbar that corresponds to this pidl.
  2554. _GetButtonFromPidl(psmd->pidlItem, NULL, &i, &pidlButton);
  2555. }
  2556. // Did we find this pidl in the toolbar?
  2557. if (pidlButton)
  2558. {
  2559. int idCmd = GetButtonCmd(_hwndTB, v_DPAIndexToTBIndex(i));
  2560. // Yes, Get the information from that button.
  2561. CMenuData* pmd = (CMenuData*)_IDToPibData(idCmd);
  2562. if (pmd)
  2563. {
  2564. BOOL fRefresh = FALSE;
  2565. DWORD dwFlagsUp = dwFlags;
  2566. DWORD dwOldItemFlags = pmd->GetFlags();
  2567. DWORD dwNewItemFlags = dwOldItemFlags;
  2568. if ((dwFlags & SMINV_DEMOTE) &&
  2569. (!(dwOldItemFlags & SMIF_DEMOTED) || dwFlags & SMINV_FORCE))
  2570. {
  2571. if (!(dwFlags & SMINV_NOCALLBACK))
  2572. {
  2573. CallCB(pidlButton, SMC_DEMOTE, 0, 0);
  2574. BroadcastIntelliMenuState(pidlButton, FALSE);
  2575. }
  2576. dwNewItemFlags |= SMIF_DEMOTED;
  2577. dwFlagsUp |= SMINV_DEMOTE;
  2578. }
  2579. else if ((dwFlags & SMINV_PROMOTE) &&
  2580. ((dwOldItemFlags & SMIF_DEMOTED) || dwFlags & SMINV_FORCE))
  2581. {
  2582. if (!(dwFlags & SMINV_NOCALLBACK))
  2583. {
  2584. CallCB(pidlButton, SMC_PROMOTE, dwFlags, 0);
  2585. BroadcastIntelliMenuState(pidlButton, TRUE);
  2586. }
  2587. dwNewItemFlags &= ~SMIF_DEMOTED;
  2588. dwFlagsUp |= SMINV_PROMOTE;
  2589. }
  2590. // Was it promoted and now Demoted or
  2591. // Was it demoted and now promoted
  2592. if ((dwNewItemFlags & SMIF_DEMOTED) ^
  2593. (dwOldItemFlags & SMIF_DEMOTED))
  2594. {
  2595. fRefresh = TRUE;
  2596. if (dwNewItemFlags & SMIF_DEMOTED)
  2597. {
  2598. // Yes; Then decrement the Promoted count
  2599. _cPromotedItems--;
  2600. // If we're decementing, then we not have a demoted item.
  2601. _fHasDemotedItems = TRUE;
  2602. // Have we dropped off the face of the earth?
  2603. if (_cPromotedItems == 0)
  2604. {
  2605. dwFlagsUp |= SMINV_DEMOTE;
  2606. Expand(TRUE);
  2607. }
  2608. else
  2609. {
  2610. fRefresh = FALSE;
  2611. }
  2612. }
  2613. else
  2614. {
  2615. int cButtons = ToolBar_ButtonCount(_hwndMB);
  2616. _cPromotedItems++;
  2617. if (cButtons == _cPromotedItems)
  2618. {
  2619. // if the button count is the number of promoted items,
  2620. // then we can't have any demoted items
  2621. // then we need to reset the _fHasDemotedItems flag so that
  2622. // we don't get a chevron and stuff...
  2623. _fHasDemotedItems = FALSE;
  2624. }
  2625. dwFlagsUp |= SMINV_PROMOTE;
  2626. fRefresh = TRUE;
  2627. }
  2628. }
  2629. if (fRefresh || dwFlags & SMINV_FORCE)
  2630. IUnknown_RefreshParent(_pcmb->_punkSite, _pidl, dwFlagsUp);
  2631. if (dwOldItemFlags != dwNewItemFlags || dwFlags & SMINV_FORCE)
  2632. {
  2633. if (dwFlags & SMINV_NEXTSHOW || !_fShow)
  2634. {
  2635. _fRefreshInfo = TRUE;
  2636. }
  2637. else
  2638. {
  2639. // Since we updated the flags, set them into the cache
  2640. pmd->SetFlags(dwNewItemFlags);
  2641. // Based on the new flags, do we enable?
  2642. DWORD dwState = ToolBar_GetState(_hwndTB, idCmd);
  2643. dwState |= TBSTATE_ENABLED;
  2644. if (dwNewItemFlags & SMIF_DEMOTED &&
  2645. !_pcmb->_fExpanded)
  2646. {
  2647. // No; We're not expanded and this is a demoted item
  2648. dwState |= TBSTATE_HIDDEN;
  2649. dwState &= ~TBSTATE_ENABLED;
  2650. _fHasDemotedItems = TRUE;
  2651. // Just in case the chevron is not there, we should
  2652. // try and add it. This call will never add more than 1
  2653. _AddChevron();
  2654. }
  2655. else if (!_fHasDemotedItems)
  2656. {
  2657. _RemoveChevron();
  2658. }
  2659. // Also recalculate the NS separator
  2660. _RemoveNSSeparator();
  2661. _AddNSSeparator();
  2662. // Adjust the state of the button in the toolbar.
  2663. ToolBar_SetState(_hwndTB, idCmd, dwState);
  2664. _ToolbarChanged();
  2665. }
  2666. }
  2667. }
  2668. }
  2669. // We handled this one.
  2670. hr = S_OK;
  2671. }
  2672. return hr;
  2673. }
  2674. LRESULT CMenuSFToolbar::_DefWindowProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  2675. {
  2676. switch (uMessage)
  2677. {
  2678. case WM_GETOBJECT:
  2679. // Yet another poor design choice on the part of the accessibility team.
  2680. // Typically, if you do not answer a WM_* you return 0. They choose 0 as their success
  2681. // code.
  2682. return _DefWindowProcMB(hwnd, uMessage, wParam, lParam);
  2683. break;
  2684. }
  2685. return CSFToolbar::_DefWindowProc(hwnd, uMessage, wParam, lParam);
  2686. }
  2687. void CMenuSFToolbar::_SetFontMetrics()
  2688. {
  2689. CMenuToolbarBase::_SetFontMetrics();
  2690. if (_hwndPager && _pcmb->_pmbm)
  2691. Pager_SetBkColor(_hwndPager, _pcmb->_pmbm->_clrBackground);
  2692. }
  2693. int CMenuSFToolbar::_GetBitmap(int iCommandID, PIBDATA pibdata, BOOL fUseCache)
  2694. {
  2695. int iIcon = -1;
  2696. // If we don't have a pibdata, or we can't get an icon return.
  2697. if (!pibdata || pibdata->GetNoIcon())
  2698. return -1;
  2699. if (_dwFlags & SMSET_USEBKICONEXTRACTION)
  2700. {
  2701. LPITEMIDLIST pidlItem = pibdata->GetPidl();
  2702. // If the caller is using background icon extraction, we need them to provide a
  2703. // default icon that we are going to display until we get the real one. This is
  2704. // specifically to make favorites fast.
  2705. if (_iDefaultIconIndex == -1)
  2706. {
  2707. TCHAR szIconPath [MAX_PATH];
  2708. if (S_OK == CallCB(NULL, SMC_DEFAULTICON, (WPARAM)szIconPath, (LPARAM)&iIcon))
  2709. {
  2710. _iDefaultIconIndex = Shell_GetCachedImageIndex(szIconPath, iIcon, 0);
  2711. }
  2712. }
  2713. iIcon = _iDefaultIconIndex;
  2714. DWORD dwAttrib = SFGAO_FOLDER;
  2715. if (pidlItem && SUCCEEDED(_psf->GetAttributesOf(1, (LPCITEMIDLIST*)&pidlItem, &dwAttrib)))
  2716. {
  2717. if (dwAttrib & SFGAO_FOLDER)
  2718. iIcon = II_FOLDER;
  2719. }
  2720. IShellTaskScheduler* pScheduler = _pcmb->_pmbState->GetScheduler();
  2721. if (pScheduler)
  2722. {
  2723. IShellFolder* psf = NULL;
  2724. LPITEMIDLIST pidlFolder = _pidl;
  2725. LPITEMIDLIST pidlItemUnwrapped;
  2726. // Since this can be an augmented shell folder, we should do the correct thing so that
  2727. // the icon extraction with the full pidl takes place correctly.
  2728. if (_pasf2 &&
  2729. S_OK == _pasf2->UnWrapIDList(pidlItem, 1, NULL, &pidlFolder, &pidlItemUnwrapped, NULL))
  2730. {
  2731. pidlItem = ILCombine(pidlFolder, pidlItemUnwrapped);
  2732. ILFree(pidlFolder);
  2733. ILFree(pidlItemUnwrapped);
  2734. }
  2735. else
  2736. {
  2737. psf = _psf;
  2738. }
  2739. // AddIconTask takes ownership of the pidl when psf is NULL and will free it.
  2740. HRESULT hr = AddIconTask(pScheduler, psf, pidlFolder, pidlItem,
  2741. s_IconCallback, (void *)_hwndTB, iCommandID, NULL);
  2742. pScheduler->Release();
  2743. if (FAILED(hr))
  2744. {
  2745. // If that call failed for some reason, default to the shell32 impl.
  2746. goto DoSyncMap;
  2747. }
  2748. }
  2749. else
  2750. goto DoSyncMap;
  2751. }
  2752. else
  2753. {
  2754. DoSyncMap:
  2755. iIcon = CSFToolbar::_GetBitmap(iCommandID, pibdata, fUseCache);
  2756. }
  2757. return iIcon;
  2758. }
  2759. void CMenuSFToolbar::s_IconCallback(void * pvData, UINT uId, UINT iIconIndex)
  2760. {
  2761. HWND hwnd = (HWND)pvData;
  2762. if (hwnd && IsWindow(hwnd))
  2763. {
  2764. DAD_ShowDragImage(FALSE);
  2765. SendMessage(hwnd, TB_CHANGEBITMAP, uId, iIconIndex);
  2766. DAD_ShowDragImage(TRUE);
  2767. }
  2768. }
  2769. HWND CMenuSFToolbar::GetHWNDForUIObject()
  2770. {
  2771. HWND hwnd = _pcmb->_pmbState->GetWorkerWindow(_hwndMB);
  2772. if (hwnd)
  2773. ::SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER);
  2774. return hwnd;
  2775. }
  2776. HWND CMenuSFToolbar::CreateWorkerWindow()
  2777. {
  2778. return GetHWNDForUIObject();
  2779. }
  2780. LRESULT CMenuSFToolbar::v_OnCustomDraw(NMCUSTOMDRAW * pnmcd)
  2781. {
  2782. LRESULT lRes = CMenuToolbarBase::v_OnCustomDraw(pnmcd);
  2783. #ifdef FLATMENU_ICONBAR
  2784. // We may have a background banner in Flat Menu Mode.
  2785. UINT cBits = GetDeviceCaps(pnmcd->hdc, BITSPIXEL);
  2786. if (pnmcd->dwDrawStage == CDDS_PREERASE &&
  2787. _pcmb->_pmbm->_fFlatMenuMode && // Only in flat mode
  2788. _uIconSizeMB != ISFBVIEWMODE_LARGEICONS && // And designers didn't like it in the large icon mode
  2789. cBits > 8) // and only if we're in 16 bit color
  2790. {
  2791. RECT rcClient;
  2792. GetClientRect(_hwndMB, &rcClient);
  2793. rcClient.right = GetTBImageListWidth(_hwndMB) + ICONBACKGROUNDFUDGE;
  2794. SHFillRectClr(pnmcd->hdc, &rcClient, _pcmb->_pmbm->_clrMenuGrad);
  2795. }
  2796. #endif
  2797. return lRes;
  2798. }