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.

1567 lines
44 KiB

  1. #include "priv.h"
  2. #include "sccls.h"
  3. #include "basebar.h"
  4. #include "bands.h"
  5. #include "menubar.h"
  6. #include "menuband.h"
  7. #include "isfband.h"
  8. #include "apithk.h"
  9. // APPCOMPAT (lamadio): Conflicts with one defined in winuserp.h
  10. #undef WINEVENT_VALID //It's tripping on this...
  11. #include "winable.h"
  12. #include "oleacc.h"
  13. #ifdef UNIX
  14. #include "unixstuff.h"
  15. #endif
  16. #define THISCLASS CMenuDeskBar
  17. #define SUPERCLASS CBaseBar
  18. // Don't fade the menu if it's larger than this magical number. Based on experiments
  19. // on a Pentium II - 233
  20. #define MAGICAL_NO_FADE_HEIGHT 600
  21. // For TraceMsg
  22. #define DM_POPUP DM_TRACE
  23. #define UP 0
  24. #define DOWN 1
  25. #define LEFT 2
  26. #define RIGHT 3
  27. #ifdef ENABLE_CHANNELS
  28. IDeskBand * ChannelBand_Create(LPCITEMIDLIST pidl);
  29. #endif // ENABLE_CHANNELS
  30. // Used by performance timing mode
  31. extern DWORD g_dwStopWatchMode; // Shell performance mode
  32. extern HMENU g_hmenuStopWatch;
  33. extern UINT g_idCmdStopWatch;
  34. HRESULT CMenuDeskBar_CreateInstance(IUnknown* pUnkOuter, IUnknown** ppunk, LPCOBJECTINFO poi)
  35. {
  36. // aggregation checking is handled in class factory
  37. CMenuDeskBar *pwbar = new CMenuDeskBar();
  38. if (pwbar)
  39. {
  40. *ppunk = SAFECAST(pwbar, IMenuPopup*);
  41. return S_OK;
  42. }
  43. return E_OUTOFMEMORY;
  44. }
  45. CMenuDeskBar::CMenuDeskBar() : SUPERCLASS()
  46. {
  47. _dwMode = DBIF_VIEWMODE_VERTICAL;
  48. _iIconSize = BMICON_SMALL;
  49. }
  50. CMenuDeskBar::~CMenuDeskBar()
  51. {
  52. SetSite(NULL);
  53. }
  54. STDMETHODIMP CMenuDeskBar::QueryInterface(REFIID riid, void **ppvObj)
  55. {
  56. HRESULT hres;
  57. static const QITAB qit[] = {
  58. QITABENT(THISCLASS, IMenuPopup),
  59. QITABENT(THISCLASS, IObjectWithSite),
  60. QITABENT(THISCLASS, IBanneredBar),
  61. QITABENT(THISCLASS, IInitializeObject),
  62. { 0 },
  63. };
  64. hres = QISearch(this, (LPCQITAB)qit, riid, ppvObj);
  65. if (FAILED(hres))
  66. hres = SUPERCLASS::QueryInterface(riid, ppvObj);
  67. return hres;
  68. }
  69. /*----------------------------------------------------------
  70. Purpose: IMenuPopup::SetSubmenu method
  71. */
  72. STDMETHODIMP CMenuDeskBar::SetSubMenu(IMenuPopup* pmp, BOOL fSet)
  73. {
  74. if (fSet)
  75. {
  76. if (_pmpChild)
  77. _pmpChild->Release();
  78. _pmpChild = pmp;
  79. _pmpChild->AddRef();
  80. }
  81. else
  82. {
  83. if (_pmpChild && SHIsSameObject(pmp, _pmpChild))
  84. {
  85. _pmpChild->Release();
  86. _pmpChild = NULL;
  87. }
  88. }
  89. return S_OK;
  90. }
  91. void CMenuDeskBar::_PopDown()
  92. {
  93. DAD_ShowDragImage(FALSE);
  94. if (_pmpChild)
  95. _pmpChild->OnSelect(MPOS_CANCELLEVEL);
  96. // ShowWindow(_hwnd, SW_HIDE);
  97. SetWindowPos(_hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
  98. ShowDW(FALSE);
  99. if (_pmpParent)
  100. {
  101. _pmpParent->SetSubMenu(this, FALSE);
  102. }
  103. UIActivateIO(FALSE, NULL);
  104. _fActive = FALSE;
  105. DAD_ShowDragImage(TRUE);
  106. }
  107. /*----------------------------------------------------------
  108. Purpose: IMenuPopup::OnSelect method
  109. */
  110. STDMETHODIMP CMenuDeskBar::OnSelect(DWORD dwSelectType)
  111. {
  112. switch (dwSelectType)
  113. {
  114. case MPOS_CHILDTRACKING:
  115. if (_pmpParent)
  116. _pmpParent->OnSelect(dwSelectType);
  117. break;
  118. case MPOS_SELECTRIGHT:
  119. case MPOS_SELECTLEFT:
  120. if (_pmpParent)
  121. _pmpParent->OnSelect(dwSelectType);
  122. break;
  123. case MPOS_EXECUTE:
  124. case MPOS_FULLCANCEL:
  125. _PopDown();
  126. if (_pmpParent)
  127. _pmpParent->OnSelect(dwSelectType);
  128. break;
  129. case MPOS_CANCELLEVEL:
  130. _PopDown();
  131. break;
  132. }
  133. return S_OK;
  134. }
  135. void SetExpandedBorder(HWND hwnd, BOOL fExpanded)
  136. {
  137. #ifdef MAINWIN
  138. // IEUNIX : WS_DLGFRAME implementaion looks ugly on UNIX.
  139. fExpanded = TRUE;
  140. #endif
  141. DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE);
  142. DWORD dwExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
  143. if (fExpanded)
  144. {
  145. dwStyle |= WS_BORDER;
  146. dwStyle &= ~WS_DLGFRAME;
  147. }
  148. else
  149. {
  150. dwStyle &= ~WS_BORDER;
  151. dwStyle |= WS_DLGFRAME;
  152. }
  153. SetWindowLong(hwnd, GWL_STYLE, dwStyle);
  154. SetWindowLong(hwnd, GWL_EXSTYLE, dwExStyle);
  155. SetWindowPos(hwnd, NULL, 0, 0, 0, 0,
  156. SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
  157. UpdateWindow(hwnd);
  158. }
  159. void CMenuDeskBar::_OnCreate()
  160. {
  161. if (!_fFlatMenuMode)
  162. SetExpandedBorder(_hwnd, _fExpanded);
  163. }
  164. DWORD CMenuDeskBar::_GetClassStyle()
  165. {
  166. DWORD dwStyle = CS_SAVEBITS; // Faster repaint for menus when they go away
  167. if (IsOS(OS_WHISTLERORGREATER))
  168. {
  169. dwStyle |= CS_DROPSHADOW; // Cool dropshadow effect on whistler....
  170. }
  171. return dwStyle;
  172. }
  173. DWORD CMenuDeskBar::_GetExStyle()
  174. {
  175. #ifndef MAINWIN
  176. return WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
  177. #else
  178. return WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_MW_UNMANAGED_WINDOW;
  179. #endif
  180. }
  181. // We use the following structure to pass a whole bunch of information from
  182. // the GetPopupWindowPosition to WillFit function. We have WillFit function
  183. // to cut the amount of duplicate code in getpopup window position. The order
  184. // in which different the sides are checked is the only difference for popping
  185. // up a window on a particular side.
  186. //
  187. // Having this function helps us to do that check by means of a parameter instead
  188. // of repeating portions of code again and again.
  189. typedef struct {
  190. RECT rcAvail; // Available dimensions b/t monitor edge and exclude edge
  191. SIZE sizeAdjust; // Size of menu edge
  192. int cyMonitor; // Size of monitor
  193. int cxMonitor;
  194. int cx; // Size of menu
  195. int cy;
  196. int cyExtendDiff; // Difference b/t calc'd size and available size
  197. RECT *prcResult;
  198. RECT *prcExclude; // Exclude rect
  199. RECT *prcMonitor;
  200. } PopupInfo;
  201. #define TOP 0
  202. #define BOTTOM 1
  203. #define LEFT 2
  204. #define RIGHT 3
  205. /*----------------------------------------------------------
  206. Purpose: Attempt to fit and position a menu in the given direction
  207. relative to an exclude rect.
  208. Setting fForce to TRUE will cause the menu size to be adjusted
  209. to fit, if necessary.
  210. This function only sets the top and left coords, not the bottom
  211. and right coords.
  212. Returns TRUE if the desired direction can be accomplished.
  213. */
  214. BOOL WillFit(PopupInfo * pinfo, int side, BOOL fForce)
  215. {
  216. BOOL bRet = FALSE;
  217. LPRECT prcResult = pinfo->prcResult;
  218. pinfo->cyExtendDiff = 0;
  219. switch(side)
  220. {
  221. case TOP:
  222. pinfo->cyExtendDiff = pinfo->cy - pinfo->rcAvail.top;
  223. if (fForce)
  224. {
  225. // Doesn't make sense to subtract a negative value
  226. ASSERT(pinfo->cyExtendDiff >= 0);
  227. // +2 for some breathing room at the edge of the screen
  228. pinfo->cy -= pinfo->cyExtendDiff + 2;
  229. }
  230. // Can the menu be positioned above?
  231. if (pinfo->cy <= pinfo->rcAvail.top)
  232. {
  233. // Yes
  234. prcResult->top = pinfo->prcExclude->top - pinfo->cy;
  235. goto AdjustHorzPos;
  236. }
  237. break;
  238. case BOTTOM:
  239. pinfo->cyExtendDiff = pinfo->cy - pinfo->rcAvail.bottom;
  240. if (fForce)
  241. {
  242. // Doesn't make sense to subtract a negative value
  243. ASSERT(pinfo->cyExtendDiff >= 0);
  244. // +2 for some breathing room at the edge of the screen
  245. pinfo->cy -= pinfo->cyExtendDiff + 2;
  246. }
  247. // Can the menu be positioned below?
  248. if (pinfo->cy <= pinfo->rcAvail.bottom)
  249. {
  250. // Yes
  251. prcResult->top = pinfo->prcExclude->bottom;
  252. AdjustHorzPos:
  253. prcResult->left = max(pinfo->prcExclude->left, pinfo->prcMonitor->left);
  254. // Can the menu be positioned relative to its left edge (hanging right)?
  255. if (prcResult->left + pinfo->cx >= pinfo->prcMonitor->right)
  256. {
  257. // No; move it in so it is on the screen
  258. // (cx has already been adjusted to fit inside the monitor dimensions)
  259. prcResult->left = pinfo->prcMonitor->right - pinfo->cx - 1;
  260. }
  261. bRet = TRUE;
  262. }
  263. break;
  264. case LEFT:
  265. // Can the menu be positioned to the left?
  266. if (pinfo->cx <= pinfo->rcAvail.left || fForce)
  267. {
  268. // Yes
  269. // When cascading left, the menu does not overlap. Also align
  270. // so the client rect is vertically aligned with the exclude top.
  271. prcResult->left = pinfo->prcExclude->left - pinfo->cx - 1;
  272. goto AdjustVerticalPos;
  273. }
  274. break;
  275. case RIGHT:
  276. // Can the menu be positioned to the right?
  277. if (pinfo->cx <= pinfo->rcAvail.right || fForce)
  278. {
  279. // Yes
  280. // Adjust the menu to slightly overlap the parent menu. Also align
  281. // so the client rect is vertically aligned with the exclude top.
  282. prcResult->left = pinfo->prcExclude->right - pinfo->sizeAdjust.cx;
  283. AdjustVerticalPos:
  284. prcResult->top = pinfo->prcExclude->top - pinfo->sizeAdjust.cy;
  285. // Can the menu be positioned relative to its top edge (hanging down)?
  286. if (prcResult->top + pinfo->cy >= pinfo->prcMonitor->bottom)
  287. {
  288. // No; can it be positioned relative to its bottom edge (hanging up)?
  289. prcResult->top = pinfo->prcExclude->bottom + pinfo->sizeAdjust.cy - pinfo->cy;
  290. if (prcResult->top < pinfo->prcMonitor->top)
  291. {
  292. // No; move the menu so it fits, but isn't vertically snapped.
  293. // (cy has already been adjusted to fit inside the monitor
  294. // dimensions)
  295. prcResult->top = pinfo->prcMonitor->bottom - pinfo->cy - 1;
  296. }
  297. }
  298. bRet = TRUE;
  299. }
  300. break;
  301. }
  302. return bRet;
  303. }
  304. void CMenuDeskBar::_GetPopupWindowPosition(RECT* prcDesired, RECT* prcExclude,
  305. RECT *prcResult, SIZE * psizeAdjust, UINT uSide)
  306. {
  307. PopupInfo info;
  308. MONITORINFO mi;
  309. HMONITOR hMonitor;
  310. RECT rcMonitor;
  311. int cyExtendDiff = 0;
  312. // Is this going to display the banner bitmap?
  313. if (_iIconSize == BMICON_LARGE)
  314. {
  315. // Yes; add that to the dimensions
  316. prcDesired->right += _sizeBmp.cx;
  317. }
  318. // First get the monitor information
  319. hMonitor = MonitorFromRect(prcExclude, MONITOR_DEFAULTTONEAREST);
  320. mi.cbSize = sizeof(mi);
  321. if (GetMonitorInfo(hMonitor, &mi))
  322. {
  323. rcMonitor = mi.rcMonitor;
  324. // Set the result rectangle same as the desired window
  325. prcResult->left = prcDesired->left;
  326. prcResult->top = prcDesired->top;
  327. // Calculate some sizes needed for calculation
  328. info.rcAvail.left = prcExclude->left - rcMonitor.left;
  329. info.rcAvail.right = rcMonitor.right - prcExclude->right;
  330. info.rcAvail.top = prcExclude->top - rcMonitor.top;
  331. info.rcAvail.bottom = rcMonitor.bottom - prcExclude->bottom;
  332. info.sizeAdjust = *psizeAdjust;
  333. info.cyMonitor = RECTHEIGHT(rcMonitor);
  334. info.cxMonitor = RECTWIDTH(rcMonitor);
  335. info.cx = RECTWIDTH(*prcDesired);
  336. info.cy = RECTHEIGHT(*prcDesired);
  337. // If the desired rect is bigger than monitor then clip it to the monitor size
  338. if (info.cy > info.cyMonitor)
  339. info.cy = info.cyMonitor;
  340. if (info.cx > info.cxMonitor)
  341. info.cx = info.cxMonitor;
  342. info.prcResult = prcResult;
  343. info.prcExclude = prcExclude;
  344. info.prcMonitor = &rcMonitor;
  345. //Now Adjust the rectangle for the correct position
  346. switch(uSide)
  347. {
  348. int iSide;
  349. case MENUBAR_TOP:
  350. if (WillFit(&info, TOP, FALSE))
  351. {
  352. _uSide = MENUBAR_TOP;
  353. }
  354. else
  355. {
  356. // We couldn't fit it above, how badly did we fall short?
  357. cyExtendDiff = info.cyExtendDiff;
  358. if (WillFit(&info, BOTTOM, FALSE))
  359. _uSide = MENUBAR_BOTTOM;
  360. // We can't fit it below either, which dir was closest?
  361. // If they are equal, default to requested direction
  362. else if (info.cyExtendDiff < cyExtendDiff)
  363. {
  364. _uSide = MENUBAR_BOTTOM;
  365. WillFit(&info, BOTTOM, TRUE);
  366. }
  367. else
  368. {
  369. _uSide = MENUBAR_TOP;
  370. WillFit(&info, TOP, TRUE);
  371. }
  372. }
  373. break;
  374. case MENUBAR_BOTTOM:
  375. if (WillFit(&info, BOTTOM, FALSE))
  376. {
  377. _uSide = MENUBAR_BOTTOM;
  378. }
  379. else
  380. {
  381. // We couldn't fit it below, how badly did we fall short?
  382. cyExtendDiff = info.cyExtendDiff;
  383. if (WillFit(&info, TOP, FALSE))
  384. _uSide = MENUBAR_TOP;
  385. // We can't fit it above either, which dir was closest?
  386. // If they are equal, default to requested direction
  387. else if (info.cyExtendDiff < cyExtendDiff)
  388. {
  389. _uSide = MENUBAR_TOP;
  390. WillFit(&info, TOP, TRUE);
  391. }
  392. else
  393. {
  394. _uSide = MENUBAR_BOTTOM;
  395. WillFit(&info, BOTTOM, TRUE);
  396. }
  397. }
  398. break;
  399. case MENUBAR_LEFT:
  400. if (WillFit(&info, LEFT, FALSE))
  401. {
  402. _uSide = MENUBAR_LEFT;
  403. }
  404. else if (WillFit(&info, RIGHT, FALSE))
  405. {
  406. _uSide = MENUBAR_RIGHT;
  407. }
  408. else
  409. {
  410. // fit where have most room and can show most of menu.
  411. if ((info.cx - (info.prcExclude)->right) > (info.prcExclude)->left)
  412. {
  413. _uSide = MENUBAR_RIGHT;
  414. iSide = RIGHT;
  415. }
  416. else
  417. {
  418. _uSide = MENUBAR_LEFT;
  419. iSide = LEFT;
  420. }
  421. WillFit(&info, iSide, TRUE);
  422. }
  423. break;
  424. case MENUBAR_RIGHT:
  425. if (WillFit(&info, RIGHT, FALSE))
  426. {
  427. _uSide = MENUBAR_RIGHT;
  428. }
  429. else if (WillFit(&info, LEFT, FALSE))
  430. {
  431. _uSide = MENUBAR_LEFT;
  432. }
  433. else
  434. {
  435. // fit where have most room and can show most of menu.
  436. if ((info.cx - (info.prcExclude)->right) >= (info.prcExclude)->left)
  437. {
  438. _uSide = MENUBAR_RIGHT;
  439. iSide = RIGHT;
  440. }
  441. else
  442. {
  443. _uSide = MENUBAR_LEFT;
  444. iSide = LEFT;
  445. }
  446. WillFit(&info, iSide, TRUE);
  447. }
  448. break;
  449. }
  450. // Finally set the bottom and right
  451. if (prcResult->top < rcMonitor.top)
  452. prcResult->top = rcMonitor.top;
  453. if (prcResult->left < rcMonitor.left)
  454. prcResult->left = rcMonitor.left;
  455. prcResult->bottom = prcResult->top + info.cy;
  456. prcResult->right = prcResult->left + info.cx;
  457. if (prcResult->bottom > rcMonitor.bottom)
  458. {
  459. // -2 for some breathing room at the edge of the screen
  460. prcResult->bottom = rcMonitor.bottom - 2;
  461. prcResult->top = prcResult->bottom - info.cy;
  462. }
  463. }
  464. }
  465. HRESULT CMenuDeskBar::_PositionWindow(POINTL *ppt, RECTL* prcExclude, DWORD dwFlags)
  466. {
  467. ASSERT(IS_VALID_READ_PTR(ppt, POINTL));
  468. ASSERT(NULL == prcExclude || IS_VALID_READ_PTR(prcExclude, RECTL));
  469. BOOL bSetFocus = (dwFlags & MPPF_SETFOCUS);
  470. RECT rcDesired;
  471. RECT rcExclude;
  472. RECT rc;
  473. SIZE sizeAdjust;
  474. UINT uAnimateSide;
  475. BOOL bMirroredWindow=IS_WINDOW_RTL_MIRRORED(_hwnd);
  476. static const iPosition[] = {MENUBAR_TOP, MENUBAR_LEFT, MENUBAR_RIGHT, MENUBAR_BOTTOM};
  477. if (dwFlags & MPPF_POS_MASK)
  478. {
  479. UINT uPosIndex = ((dwFlags & MPPF_POS_MASK) >> 29) - 1;
  480. ASSERT(uPosIndex < 4);
  481. _uSide = iPosition[uPosIndex];
  482. }
  483. if (bSetFocus)
  484. SetForegroundWindow(_hwnd);
  485. _pt = *(POINT*)ppt;
  486. // Get the size of the ideal client rect of the child
  487. RECT rcChild = {0};
  488. // (scotth): This only sets the bottom and the right values
  489. _pDBC->GetSize(DBC_GS_IDEAL, &rcChild);
  490. DWORD dwStyle = GetWindowLong(_hwnd, GWL_STYLE);
  491. DWORD dwExStyle = GetWindowLong(_hwnd, GWL_EXSTYLE);
  492. // Adjust for the window border style
  493. rcDesired = rcChild; // use rcDesired as a temp variable
  494. if (!_fNoBorder)
  495. {
  496. AdjustWindowRectEx(&rcChild, dwStyle, FALSE, dwExStyle);
  497. }
  498. // Calculate the edge of the menu border, and add a fudge factor so
  499. // left/right-cascaded menus overlap the parent menu a bit and are
  500. // correctly aligned vertically.
  501. sizeAdjust.cx = (RECTWIDTH(rcChild) - RECTWIDTH(rcDesired)) / 2;
  502. sizeAdjust.cy = (RECTHEIGHT(rcChild) - RECTHEIGHT(rcDesired)) / 2;
  503. if (prcExclude)
  504. {
  505. CopyRect(&rcExclude, (RECT*)prcExclude);
  506. //
  507. // If mirroring is enabled, let's mirror this guy
  508. // by simulating a different mirrored rect. This is
  509. // only for dropdown menus. [samera]
  510. //
  511. if (bMirroredWindow)
  512. {
  513. if ((_uSide != MENUBAR_LEFT) &&
  514. (_uSide != MENUBAR_RIGHT) )
  515. {
  516. int x;
  517. int iW = rcExclude.right-rcExclude.left;
  518. int icW = (rcChild.right-rcChild.left);
  519. if( icW > iW )
  520. {
  521. x = icW - iW;
  522. rcExclude.left -= x ;
  523. rcExclude.right -= x ;
  524. }
  525. else
  526. {
  527. x = iW - icW;
  528. rcExclude.left += x;
  529. rcExclude.right += x;
  530. }
  531. ppt->x = rcExclude.left;
  532. }
  533. }
  534. TraceMsg(DM_POPUP, "Parent Side is %d ", _uSide);
  535. switch(_uSide)
  536. {
  537. case MENUBAR_LEFT :
  538. rcDesired.left = rcExclude.left - rcChild.right; // right is width
  539. rcDesired.top = rcExclude.top;
  540. break;
  541. case MENUBAR_RIGHT :
  542. rcDesired.left = rcExclude.right;
  543. rcDesired.top = rcExclude.top;
  544. break;
  545. case MENUBAR_TOP:
  546. rcDesired.left = rcExclude.left;
  547. rcDesired.top = rcExclude.top - rcChild.bottom; // bottom is height
  548. break;
  549. case MENUBAR_BOTTOM:
  550. rcDesired.left = rcExclude.left;
  551. rcDesired.top = rcExclude.bottom;
  552. break;
  553. default:
  554. rcDesired.left = _pt.x;
  555. rcDesired.top = _pt.y;
  556. }
  557. }
  558. else
  559. {
  560. SetRectEmpty(&rcExclude);
  561. rcDesired.left = _pt.x;
  562. rcDesired.top = _pt.y;
  563. }
  564. rcDesired.right = rcDesired.left + RECTWIDTH(rcChild);
  565. rcDesired.bottom = rcDesired.top + RECTHEIGHT(rcChild);
  566. _GetPopupWindowPosition(&rcDesired, &rcExclude, &rc, &sizeAdjust, _uSide);
  567. UINT uFlags = SWP_NOOWNERZORDER;
  568. if (!bSetFocus)
  569. uFlags |= SWP_NOACTIVATE;
  570. //
  571. // Open the menus properly. In case of a RTL mirrored window,
  572. // flip the animation side. [samera]
  573. //
  574. if( bMirroredWindow )
  575. {
  576. switch( _uSide )
  577. {
  578. case MENUBAR_LEFT:
  579. uAnimateSide = MENUBAR_RIGHT;
  580. break;
  581. case MENUBAR_RIGHT:
  582. uAnimateSide = MENUBAR_LEFT;
  583. break;
  584. default:
  585. uAnimateSide = _uSide;
  586. }
  587. }
  588. else
  589. {
  590. uAnimateSide = _uSide;
  591. }
  592. TraceMsg(TF_MENUBAND, "CMenuBar::_PositionWindow (%d,%d,%d,%d)",
  593. rc.left, rc.top, rc.right, rc.bottom);
  594. // Last minuite tweak. Since we're in large icon, we need to add this
  595. // so that the bitmap is painted correctly.
  596. if(_iIconSize == BMICON_LARGE && _fExpanded)
  597. rc.right += 1;
  598. // We _DO_ want to do a Z-Order position when this flag is specified. This is
  599. // for full repositioning where we need to preserve the overlap state of all bands.
  600. // Otherwize we just want to size the bar without changing it's z-order.
  601. if (!(dwFlags & MPPF_FORCEZORDER) &&
  602. (S_OK == IUnknown_QueryServiceExec(_punkChild, SID_SMenuBandChild,
  603. &CGID_MenuBand, MBANDCID_ISINSUBMENU, 0, NULL, NULL)))
  604. {
  605. uFlags |= SWP_NOZORDER;
  606. }
  607. // If it's bigger than this magical number, then we don't animate. change to taste
  608. if (RECTHEIGHT(rc) > MAGICAL_NO_FADE_HEIGHT)
  609. dwFlags |= MPPF_NOANIMATE;
  610. AnimateSetMenuPos(_hwnd, &rc, uFlags, uAnimateSide, dwFlags & MPPF_NOANIMATE);
  611. // Save information so we can later resize this window
  612. // We already have: _pt, _uSide
  613. if (prcExclude)
  614. {
  615. _fExcludeRect = TRUE;
  616. CopyRect(&_rcExclude, (RECT*)prcExclude);
  617. }
  618. else
  619. _fExcludeRect = FALSE;
  620. return S_OK;
  621. }
  622. /*----------------------------------------------------------
  623. Purpose: IMenuPopup::Popup method
  624. */
  625. STDMETHODIMP CMenuDeskBar::Popup(POINTL* ppt, RECTL* prcExclude, DWORD dwFlags)
  626. {
  627. HRESULT hr;
  628. // Is the caller telling us to reposition?
  629. if (dwFlags & MPPF_REPOSITION)
  630. {
  631. if (ppt == NULL)
  632. ppt = (POINTL*)&_pt;
  633. if (prcExclude == NULL)
  634. prcExclude = (RECTL*)&_rcExclude;
  635. // Yes; Then we don't need to do any First show stuff.
  636. _PositionWindow(ppt, prcExclude, dwFlags);
  637. return S_OK;
  638. }
  639. ASSERT(IS_VALID_READ_PTR(ppt, POINTL));
  640. ASSERT(NULL == prcExclude || IS_VALID_READ_PTR(prcExclude, RECTL));
  641. if (g_dwProfileCAP & 0x00002000)
  642. StartCAP();
  643. if (g_dwStopWatchMode)
  644. StopWatch_Start(SWID_MENU, TEXT("Menu Start"), SPMODE_SHELL | SPMODE_DEBUGOUT);
  645. if (_pmpParent)
  646. {
  647. _pmpParent->SetSubMenu(this, TRUE);
  648. }
  649. IOleCommandTarget* poct;
  650. hr = IUnknown_QueryService(_punkChild, SID_SMenuBandChild, IID_PPV_ARG(IOleCommandTarget, &poct));
  651. if (SUCCEEDED(hr))
  652. {
  653. // We need to do this before the ShowDW. This saves us from doing the setting twice
  654. // Because in the ShowDW of MenuBand, we actually go an initialize the toolbar with
  655. // the current default setting which should be "No Keyboard Cues." If we set the state
  656. // here, then the state will be "Show keyboard cues." Then we will update the toolbar.
  657. if (dwFlags & MPPF_KEYBOARD)
  658. poct->Exec(&CGID_MenuBand, MBANDCID_KEYBOARD, 0, NULL, NULL);
  659. }
  660. else
  661. {
  662. ASSERT(poct == NULL);
  663. }
  664. _NotifyModeChange(_dwMode);
  665. hr = ShowDW(TRUE);
  666. if (SUCCEEDED(hr) && _pmpParent)
  667. {
  668. VARIANT varg;
  669. // If this Exec fails, don't panic; it just means we use the default side
  670. if (SUCCEEDED(IUnknown_Exec(_pmpParent, &CGID_MENUDESKBAR, MBCID_GETSIDE, 0, NULL, &varg)))
  671. {
  672. if (varg.vt == VT_I4)
  673. {
  674. _uSide = (UINT) varg.lVal;
  675. }
  676. }
  677. }
  678. if (SUCCEEDED(hr))
  679. {
  680. IEPlaySound(TEXT("MenuPopup"), TRUE);
  681. _PositionWindow(ppt, prcExclude, dwFlags);
  682. // Set focus
  683. UIActivateIO(TRUE, NULL);
  684. _fActive = TRUE;
  685. // Select the first/last item?
  686. if ((dwFlags & (MPPF_INITIALSELECT | MPPF_FINALSELECT)) && poct)
  687. {
  688. DWORD nCmd = (dwFlags & MPPF_INITIALSELECT) ? MBSI_FIRSTITEM : MBSI_LASTITEM;
  689. poct->Exec(&CGID_MenuBand, MBANDCID_SELECTITEM, nCmd, NULL, NULL);
  690. }
  691. }
  692. ATOMICRELEASE(poct);
  693. if (g_dwStopWatchMode)
  694. {
  695. TCHAR szMenu[32];
  696. TCHAR szText[256];
  697. *szMenu = '\0';
  698. if(g_hmenuStopWatch != NULL)
  699. GetMenuString(g_hmenuStopWatch, 0, szMenu, ARRAYSIZE(szMenu)-1, MF_BYPOSITION);
  700. StringCchPrintf(szText, ARRAYSIZE(szText), TEXT("Menu %d %s%sStop"), g_idCmdStopWatch, szMenu, *szMenu ?TEXT(" ") :TEXT(""));
  701. StopWatch_Stop(SWID_MENU, (LPCTSTR)szText, SPMODE_SHELL | SPMODE_DEBUGOUT);
  702. }
  703. if (g_dwProfileCAP & 0x00002000)
  704. StopCAP();
  705. return hr;
  706. }
  707. /*----------------------------------------------------------
  708. Purpose: IInputObjectSite::OnFocusChangeIS
  709. Returns:
  710. Cond: --
  711. */
  712. HRESULT CMenuDeskBar::OnFocusChangeIS(IUnknown *punk, BOOL fSetFocus)
  713. {
  714. return NOERROR;
  715. }
  716. /*----------------------------------------------------------
  717. Purpose: IObjectWithSite::SetSite method
  718. */
  719. STDMETHODIMP CMenuDeskBar::SetSite(IUnknown* punkSite)
  720. {
  721. ASSERT(NULL == punkSite || IS_VALID_CODE_PTR(punkSite, IUnknown));
  722. if (_fShow)
  723. _PopDown();
  724. ATOMICRELEASE(_punkSite);
  725. ATOMICRELEASE(_pmpParent);
  726. _punkSite = punkSite;
  727. if (_punkSite)
  728. {
  729. _punkSite->AddRef();
  730. IUnknown_QueryService(_punkSite, SID_SMenuPopup, IID_PPV_ARG(IMenuPopup, &_pmpParent));
  731. }
  732. else
  733. {
  734. CloseDW(0);
  735. }
  736. return S_OK;
  737. }
  738. /*----------------------------------------------------------
  739. Purpose: IObjectWithSite::GetSite method
  740. */
  741. STDMETHODIMP CMenuDeskBar::GetSite(REFIID riid, LPVOID* ppvSite)
  742. {
  743. if (_punkSite)
  744. {
  745. return _punkSite->QueryInterface(riid, ppvSite);
  746. }
  747. *ppvSite = NULL;
  748. return E_FAIL;
  749. }
  750. void CMenuDeskBar::AdjustForTheme()
  751. {
  752. if (_fFlatMenuMode)
  753. {
  754. SHSetWindowBits(_hwnd, GWL_STYLE, WS_CLIPCHILDREN | WS_DLGFRAME | WS_BORDER, WS_BORDER);
  755. }
  756. else if (!_fExpanded)
  757. {
  758. SHSetWindowBits(_hwnd, GWL_STYLE, WS_CLIPCHILDREN | WS_DLGFRAME | WS_BORDER, WS_CLIPCHILDREN | WS_DLGFRAME);
  759. }
  760. }
  761. /*----------------------------------------------------------
  762. Purpose: IOleCommandTarget::Exec method
  763. */
  764. STDMETHODIMP CMenuDeskBar::Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt,
  765. VARIANTARG *pvarargIn, VARIANTARG *pvarargOut)
  766. {
  767. if (pguidCmdGroup == NULL)
  768. {
  769. }
  770. else if (IsEqualGUID(CGID_DeskBarClient, *pguidCmdGroup))
  771. {
  772. switch (nCmdID)
  773. {
  774. case DBCID_EMPTY:
  775. // if we have no bands left, close
  776. OnSelect(MPOS_FULLCANCEL);
  777. return S_OK;
  778. default:
  779. return OLECMDERR_E_NOTSUPPORTED;
  780. }
  781. }
  782. else if (IsEqualGUID(CGID_MENUDESKBAR, *pguidCmdGroup))
  783. {
  784. switch(nCmdID)
  785. {
  786. case MBCID_GETSIDE :
  787. pvarargOut->vt = VT_I4;
  788. pvarargOut->lVal = _GetSide();
  789. return S_OK;
  790. case MBCID_RESIZE:
  791. if (_fActive)
  792. {
  793. if (_fExcludeRect)
  794. _PositionWindow((POINTL *)&_pt, (RECTL *)&_rcExclude, 0);
  795. else
  796. _PositionWindow((POINTL *)&_pt, NULL, 0);
  797. }
  798. return S_OK;
  799. case MBCID_SETEXPAND:
  800. if ((BOOL)_fExpanded != (BOOL)nCmdexecopt && !_fFlatMenuMode)
  801. {
  802. _fExpanded = nCmdexecopt;
  803. SetExpandedBorder(_hwnd, _fExpanded);
  804. }
  805. return S_OK;
  806. case MBCID_SETFLAT:
  807. {
  808. _fFlatMenuMode = BOOLIFY(nCmdexecopt);
  809. AdjustForTheme();
  810. }
  811. break;
  812. case MBCID_NOBORDER:
  813. {
  814. _fNoBorder = BOOLIFY(nCmdexecopt);
  815. SetWindowPos(_hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
  816. }
  817. break;
  818. default :
  819. return OLECMDERR_E_NOTSUPPORTED;
  820. }
  821. }
  822. return SUPERCLASS::Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvarargIn, pvarargOut);
  823. }
  824. /*----------------------------------------------------------
  825. Purpose: IServiceProvider::QueryService method
  826. */
  827. STDMETHODIMP CMenuDeskBar::QueryService(REFGUID guidService, REFIID riid, void **ppvObj)
  828. {
  829. if (IsEqualGUID(guidService, SID_SMenuPopup))
  830. {
  831. return QueryInterface(riid, ppvObj);
  832. }
  833. else if (IsEqualIID(guidService, SID_SMenuBandBottom) ||
  834. IsEqualIID(guidService, SID_SMenuBandBottomSelected)||
  835. IsEqualIID(guidService, SID_SMenuBandChild))
  836. {
  837. // SID_SMenuBandBottom queries down
  838. return IUnknown_QueryService(_punkChild, guidService, riid, ppvObj);
  839. }
  840. else
  841. {
  842. HRESULT hres = SUPERCLASS::QueryService(guidService, riid, ppvObj);
  843. if (FAILED(hres))
  844. {
  845. hres = IUnknown_QueryService(_punkSite, guidService, riid, ppvObj);
  846. }
  847. return hres;
  848. }
  849. }
  850. /*----------------------------------------------------------
  851. Purpose: IServiceProvider::QueryService method
  852. */
  853. STDMETHODIMP CMenuDeskBar::SetIconSize(DWORD iIcon)
  854. {
  855. HRESULT hres;
  856. _iIconSize = iIcon;
  857. hres = IUnknown_QueryServiceExec(_punkChild, SID_SMenuBandChild, &CGID_MenuBand,
  858. MBANDCID_SETICONSIZE, iIcon == BMICON_SMALL? ISFBVIEWMODE_SMALLICONS: ISFBVIEWMODE_LARGEICONS, NULL, NULL);
  859. return hres;
  860. }
  861. /*----------------------------------------------------------
  862. Purpose: IServiceProvider::QueryService method
  863. */
  864. STDMETHODIMP CMenuDeskBar::SetBitmap(HBITMAP hBitmap)
  865. {
  866. ASSERT(hBitmap);
  867. BITMAP bm;
  868. _hbmp = hBitmap;
  869. if (_hbmp)
  870. {
  871. if(!GetObject(_hbmp, sizeof(bm), &bm))
  872. return E_FAIL;
  873. _sizeBmp.cx = bm.bmWidth;
  874. _sizeBmp.cy = bm.bmHeight;
  875. // Hack to get color
  876. HDC hdc = GetDC(_hwnd);
  877. if (hdc)
  878. {
  879. HDC hdcMem = CreateCompatibleDC(hdc);
  880. if (hdcMem)
  881. {
  882. HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcMem, _hbmp);
  883. _rgb = GetPixel(hdcMem, 0, 0);
  884. SelectObject(hdcMem, hbmpOld);
  885. DeleteDC(hdcMem);
  886. }
  887. ReleaseDC(_hwnd, hdc);
  888. }
  889. }
  890. return NOERROR;
  891. }
  892. void CMenuDeskBar::_OnSize()
  893. {
  894. RECT rc;
  895. if (!_hwndChild)
  896. return;
  897. GetClientRect(_hwnd, &rc);
  898. if(_iIconSize == BMICON_LARGE)
  899. {
  900. rc.left += _sizeBmp.cx;
  901. if (_fExpanded)
  902. rc.left++;
  903. }
  904. SetWindowPos(_hwndChild, 0,
  905. rc.left, rc.top, RECTWIDTH(rc), RECTHEIGHT(rc),
  906. SWP_NOACTIVATE|SWP_NOZORDER|SWP_FRAMECHANGED);
  907. rc.right = rc.left;
  908. rc.left -= _sizeBmp.cx;
  909. if (_fShow)
  910. InvalidateRect(_hwnd, &rc, TRUE);
  911. }
  912. LRESULT CMenuDeskBar::_DoPaint(HWND hwnd, HDC hdc, DWORD dwFlags)
  913. {
  914. HDC hdcmem;
  915. HBITMAP hbmpOld;
  916. RECT rc;
  917. HBRUSH hbrush;
  918. int iDC = SaveDC(hdc);
  919. GetClientRect(hwnd, &rc);
  920. //Create a compatable DC
  921. hdcmem = CreateCompatibleDC(hdc);
  922. if(hdcmem)
  923. {
  924. // Offset the stuff we're paining if we're expanded
  925. BYTE bOffset = 0;
  926. // Store this for the Bar fill cycle
  927. int cyBitmap = 0;
  928. if (!_fFlatMenuMode)
  929. {
  930. bOffset = _fExpanded? 1 : 0;
  931. }
  932. if (_sizeBmp.cy <= RECTHEIGHT(rc) + 1)
  933. {
  934. //Select the bitmap into the memory DC
  935. hbmpOld = (HBITMAP)SelectObject(hdcmem, _hbmp);
  936. //Blit to the window
  937. BitBlt(hdc, bOffset, rc.bottom - _sizeBmp.cy - bOffset, _sizeBmp.cx, _sizeBmp.cy, hdcmem, 0, 0, SRCCOPY);
  938. // Ok, We need to subtract this value to see how much we need to paint for the banner.
  939. cyBitmap = _sizeBmp.cy;
  940. //Restore the DC
  941. SelectObject(hdcmem, hbmpOld);
  942. }
  943. rc.right = _sizeBmp.cx + bOffset;
  944. if (_fExpanded && !_fFlatMenuMode && !_fNoBorder)
  945. DrawEdge(hdc, &rc, BDR_RAISEDINNER, BF_LEFT | BF_TOP | BF_BOTTOM);
  946. //Paint the rest
  947. hbrush = CreateSolidBrush(_rgb);
  948. if(hbrush)
  949. {
  950. rc.bottom -= cyBitmap + bOffset;
  951. if (_fExpanded)
  952. {
  953. rc.left += bOffset;
  954. rc.top += bOffset;
  955. }
  956. FillRect(hdc, &rc, hbrush);
  957. DeleteObject(hbrush);
  958. }
  959. //Delete the DC.
  960. DeleteDC(hdcmem);
  961. }
  962. RestoreDC(hdc, iDC);
  963. return 0;
  964. }
  965. void CMenuDeskBar::_DoNCPaint(HWND hwnd, HDC hdc)
  966. {
  967. if (!_fNoBorder)
  968. {
  969. RECT rc;
  970. // Since we need to paint the border, we get the window rect
  971. GetWindowRect(hwnd, &rc);
  972. // then change the rect so that it represents values relative to
  973. // the origin.
  974. OffsetRect(&rc, -rc.left, -rc.top);
  975. if (hdc)
  976. {
  977. if (_fFlatMenuMode)
  978. {
  979. SHOutlineRect(hdc, &rc, GetSysColor(COLOR_3DSHADOW));
  980. }
  981. else
  982. DrawEdge(hdc, &rc, BDR_RAISEDOUTER, BF_RECT);
  983. }
  984. }
  985. }
  986. LRESULT CMenuDeskBar::v_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  987. {
  988. LRESULT lres;
  989. switch (uMsg)
  990. {
  991. #ifdef MAINWIN
  992. case WM_NCPAINTSPECIALFRAME:
  993. // In case of motif look the MwPaintBorder paints a Etched In
  994. // border if WM_NCPAINTSPECIALFRAME returns FALSE. We are handling
  995. // this message here and drawing the Etched Out frame explicitly.
  996. // wParam - HDC
  997. if (MwCurrentLook() == LOOK_MOTIF)
  998. {
  999. MwPaintSpecialEOBorder( hwnd, (HDC)wParam );
  1000. return TRUE;
  1001. }
  1002. break;
  1003. #endif
  1004. case WM_GETOBJECT:
  1005. if ((DWORD)lParam == OBJID_MENU)
  1006. {
  1007. IAccessible* pacc;
  1008. if (SUCCEEDED(QueryService(SID_SMenuBandChild, IID_PPV_ARG(IAccessible, &pacc))))
  1009. {
  1010. lres = LresultFromObject(IID_IAccessible, wParam, SAFECAST(pacc, IAccessible*));
  1011. pacc->Release();
  1012. return lres;
  1013. }
  1014. }
  1015. break;
  1016. case WM_NCCREATE:
  1017. //
  1018. // Since this is a mirrored menu, then open it
  1019. // on the left (mirrored) edge if possible. WillFit(...) will
  1020. // ensure this for us [samera]
  1021. //
  1022. // Mirror the menu initially if its window is mirrored
  1023. //
  1024. ASSERT(_uSide == 0);
  1025. if (IS_WINDOW_RTL_MIRRORED(_hwnd))
  1026. _uSide = MENUBAR_LEFT;
  1027. else
  1028. _uSide = MENUBAR_RIGHT;
  1029. break;
  1030. case WM_ACTIVATE:
  1031. if (LOWORD(wParam) == WA_INACTIVE)
  1032. {
  1033. if (_fActive && !_pmpChild)
  1034. {
  1035. // if we were active, and the thing going active now
  1036. // is not one of our parent menubars, then cancel everything.
  1037. // if it's a parent of ours going active, assume that
  1038. // they will tell us to die when they want us to...
  1039. if (!_IsMyParent((HWND)lParam))
  1040. OnSelect(MPOS_FULLCANCEL);
  1041. }
  1042. }
  1043. else
  1044. {
  1045. if (_pmpChild)
  1046. {
  1047. // if we're becoming active, and we have a child, that child should go away
  1048. _pmpChild->OnSelect(MPOS_CANCELLEVEL);
  1049. }
  1050. }
  1051. break;
  1052. case WM_PRINTCLIENT:
  1053. if (_iIconSize == BMICON_LARGE)
  1054. {
  1055. _DoPaint(hwnd, (HDC)wParam, (DWORD)lParam);
  1056. return 0;
  1057. }
  1058. break;
  1059. case WM_PAINT:
  1060. // Paint the banner if we're in showing large icons
  1061. if (_iIconSize == BMICON_LARGE)
  1062. {
  1063. PAINTSTRUCT ps;
  1064. BeginPaint(hwnd, &ps);
  1065. _DoPaint(hwnd, ps.hdc, 0);
  1066. EndPaint(hwnd, &ps);
  1067. return 0;
  1068. }
  1069. break;
  1070. case WM_PRINT:
  1071. if ((_fFlatMenuMode || _fExpanded) && PRF_NONCLIENT & lParam)
  1072. {
  1073. HDC hdc = (HDC)wParam;
  1074. DefWindowProcWrap(hwnd, WM_PRINT, wParam, lParam);
  1075. // Do this after so that we look right...
  1076. _DoNCPaint(hwnd, hdc);
  1077. return 1;
  1078. }
  1079. break;
  1080. case WM_NCCALCSIZE:
  1081. if (_fNoBorder)
  1082. {
  1083. return 0;
  1084. }
  1085. else
  1086. {
  1087. return SUPERCLASS::v_WndProc(hwnd, uMsg, wParam, lParam);
  1088. }
  1089. break;
  1090. case WM_NCPAINT:
  1091. if (_fNoBorder)
  1092. {
  1093. return 0;
  1094. }
  1095. else if (_fExpanded || _fFlatMenuMode)
  1096. {
  1097. HDC hdc;
  1098. hdc = GetWindowDC(hwnd);
  1099. if (hdc)
  1100. {
  1101. _DoNCPaint(hwnd, hdc);
  1102. ReleaseDC(hwnd, hdc);
  1103. }
  1104. return 1;
  1105. }
  1106. break;
  1107. case WM_NCHITTEST:
  1108. lres = SUPERCLASS::v_WndProc(hwnd, uMsg, wParam, lParam);
  1109. switch (lres)
  1110. {
  1111. case HTBOTTOM:
  1112. case HTBOTTOMLEFT:
  1113. case HTBOTTOMRIGHT:
  1114. case HTLEFT:
  1115. case HTRIGHT:
  1116. case HTTOP:
  1117. case HTTOPLEFT:
  1118. case HTTOPRIGHT:
  1119. // Don't allow the window to be resized
  1120. lres = HTBORDER;
  1121. break;
  1122. case HTTRANSPARENT:
  1123. // Don't let a click go thru to the window underneath
  1124. lres = HTCLIENT;
  1125. break;
  1126. }
  1127. return lres;
  1128. // HACKHACKHACKHACKHACKHACKHACKHACKHACKHACKHACKHACKHACKHACKHACKHACKHACKHACK
  1129. // (lamadio) 1.25.99
  1130. // This hack is here to fix a problem on down level Windows with Integrated
  1131. // IE4.01, IE5 and Office 2000.
  1132. // The bug revolves around Start Menu not being destroyed when Explorer.exe shuts
  1133. // down. Start Menu unregisters itself at CloseDW, but since the menubar never gets
  1134. // destroyed, Start Menu never deregisters itself.
  1135. // When an System service, such as MSTASK.dll keeps shell32 alive in the background,
  1136. // it leaves an outstanding reference to a change notify. When a new user logs in,
  1137. // O2k and IE5 fire up group conv, generating more than 10 change notify events in the
  1138. // start menu. This causes the batching code to be fired up: Which does not really
  1139. // work without the shell started. GroupConv also adds these events using memory
  1140. // alloced from it's process heap. Since there is an outstanding change notify handler
  1141. // these pidls get forced to be handled. Shell32 then faults derefing a bad pidl.
  1142. // By detecting an Endsession, we can eliminate this problem. Doing a SetClient(NULL)
  1143. // cause Menubar to free it's references to MenuSite. Menusite, calls CloseDW on menuband
  1144. // menuband then causes MNFolder to unregister itself. Since no one is listening any more
  1145. // the crash is avoided.
  1146. case WM_ENDSESSION:
  1147. if (wParam != 0)
  1148. {
  1149. SetClient(NULL);
  1150. }
  1151. break;
  1152. }
  1153. return SUPERCLASS::v_WndProc(hwnd, uMsg, wParam, lParam);
  1154. }
  1155. IMenuPopup* CMenuDeskBar::_GetMenuBarParent(IUnknown* punk)
  1156. {
  1157. IMenuPopup *pmp = NULL;
  1158. IObjectWithSite* pows;
  1159. punk->QueryInterface(IID_PPV_ARG(IObjectWithSite, &pows));
  1160. if (pows)
  1161. {
  1162. IServiceProvider* psp;
  1163. pows->GetSite(IID_PPV_ARG(IServiceProvider, &psp));
  1164. if (psp)
  1165. {
  1166. psp->QueryService(SID_SMenuPopup, IID_PPV_ARG(IMenuPopup, &pmp));
  1167. psp->Release();
  1168. }
  1169. pows->Release();
  1170. }
  1171. return pmp;
  1172. }
  1173. // this assumes that hwnd is a toplevel window and that the menudeskbars are also
  1174. // the only hosts and are themselves toplevel
  1175. BOOL CMenuDeskBar::_IsMyParent(HWND hwnd)
  1176. {
  1177. BOOL fRet = FALSE;
  1178. if (hwnd)
  1179. {
  1180. HWND hwndMenu;
  1181. IMenuPopup *pmpParent = _pmpParent;
  1182. if (pmpParent)
  1183. pmpParent->AddRef();
  1184. while (pmpParent && !fRet &&
  1185. SUCCEEDED(IUnknown_GetWindow(pmpParent, &hwndMenu)))
  1186. {
  1187. if (hwndMenu == hwnd)
  1188. {
  1189. fRet = TRUE;
  1190. }
  1191. IMenuPopup* pmpNext = _GetMenuBarParent(pmpParent);
  1192. pmpParent->Release();
  1193. pmpParent = pmpNext;
  1194. }
  1195. }
  1196. return fRet;
  1197. }
  1198. IMenuPopup* CreateMenuPopup(IMenuPopup* pmpParent, IShellFolder* psf, LPCITEMIDLIST pidl,
  1199. BANDINFOSFB * pbi, BOOL bMenuBand)
  1200. {
  1201. return CreateMenuPopup2(pmpParent, NULL, psf, pidl, pbi, bMenuBand);
  1202. }
  1203. IMenuPopup* CreateMenuPopup2(IMenuPopup* pmpParent, IMenuBand* pmb, IShellFolder* psf, LPCITEMIDLIST pidl,
  1204. BANDINFOSFB * pbi, BOOL bMenuBand)
  1205. {
  1206. ASSERT(pmb == NULL || IS_VALID_CODE_PTR(pmb, IMenuBand));
  1207. ASSERT(psf == NULL || IS_VALID_CODE_PTR(psf, IShellFolder));
  1208. ASSERT(pmpParent == NULL || IS_VALID_CODE_PTR(pmpParent, IMenuPopup));
  1209. ASSERT(pidl && IS_VALID_PIDL(pidl));
  1210. ASSERT(pbi == NULL || IS_VALID_READ_PTR(pbi, BANDINFOSFB));
  1211. IMenuPopup* pmp = NULL;
  1212. IDeskBand *pdb = NULL;
  1213. IBandSite *pbs = NULL;
  1214. HRESULT hres = E_FAIL;
  1215. if (!pdb)
  1216. {
  1217. TraceMsg(TF_MENUBAND, "CreateMenuPopup2 : Did not find a this (0x%x) band.", pidl);
  1218. if (bMenuBand)
  1219. {
  1220. pdb = CMenuBand_Create(psf, pidl, FALSE);
  1221. }
  1222. else
  1223. pdb = CISFBand_CreateEx(psf, pidl);
  1224. if (pdb)
  1225. {
  1226. if (pbi)
  1227. {
  1228. IShellFolderBand *pisfBand;
  1229. if (SUCCEEDED(pdb->QueryInterface(IID_IShellFolderBand, (LPVOID*)&pisfBand)))
  1230. {
  1231. pisfBand->SetBandInfoSFB(pbi);
  1232. pisfBand->Release();
  1233. }
  1234. }
  1235. if (!pmpParent)
  1236. {
  1237. const CLSID * pclsid;
  1238. if (bMenuBand)
  1239. pclsid = &CLSID_MenuBandSite;
  1240. else
  1241. pclsid = &CLSID_RebarBandSite;
  1242. CoCreateInstance(*pclsid, NULL, CLSCTX_INPROC_SERVER, IID_IBandSite, (LPVOID*)&pbs);
  1243. if (pbs)
  1244. {
  1245. if (bMenuBand)
  1246. {
  1247. BANDSITEINFO bsinfo;
  1248. // Don't show the gripper for vertical menubands
  1249. bsinfo.dwMask = BSIM_STYLE;
  1250. bsinfo.dwStyle = BSIS_NOGRIPPER | BSIS_NODROPTARGET;
  1251. pbs->SetBandSiteInfo(&bsinfo);
  1252. }
  1253. CMenuDeskBar *pcmdb = new CMenuDeskBar();
  1254. if (pcmdb)
  1255. {
  1256. if (SUCCEEDED(pcmdb->SetClient(pbs)))
  1257. pcmdb->QueryInterface(IID_IMenuPopup, (LPVOID *)&pmp);
  1258. pcmdb->Release();
  1259. }
  1260. }
  1261. }
  1262. if (pbs)
  1263. {
  1264. pbs->AddBand(pdb);
  1265. }
  1266. }
  1267. }
  1268. ATOMICRELEASE(pdb);
  1269. ATOMICRELEASE(pbs);
  1270. if (!pmp)
  1271. IUnknown_Set((IUnknown**) &pmp, pmpParent);
  1272. return pmp;
  1273. }