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.

1684 lines
43 KiB

  1. //
  2. // cuimenu.cpp
  3. //
  4. #include "private.h"
  5. #include "cuimenu.h"
  6. #include "fontlink.h"
  7. #if (_WIN32_WINNT < 0x0500)
  8. #define SPI_GETMENUANIMATION 0x1002
  9. #define SPI_GETMENUFADE 0x1012
  10. /*
  11. * AnimateWindow() Commands
  12. */
  13. #define AW_HOR_POSITIVE 0x00000001
  14. #define AW_HOR_NEGATIVE 0x00000002
  15. #define AW_VER_POSITIVE 0x00000004
  16. #define AW_VER_NEGATIVE 0x00000008
  17. #define AW_CENTER 0x00000010
  18. #define AW_HIDE 0x00010000
  19. #define AW_ACTIVATE 0x00020000
  20. #define AW_SLIDE 0x00040000
  21. #define AW_BLEND 0x00080000
  22. #endif /* _WIN32_WINNT < 0x0500 */
  23. #define MENU_ARROW_MARGIN 2
  24. #define MENU_TEXT_MARGIN 8
  25. /*============================================================================*/
  26. //
  27. // CUIFMenuItem
  28. //
  29. /*============================================================================*/
  30. /*------------------------------------------------------------------------------
  31. ctor
  32. ------------------------------------------------------------------------------*/
  33. CUIFMenuItem::CUIFMenuItem(CUIFMenu *pMenu, DWORD dwFlags) : CUIFObject(pMenu, 0, NULL, 0)
  34. {
  35. _uId = 0;
  36. _psz = NULL;
  37. _cch = 0;
  38. _pszTab = NULL;
  39. _cchTab = 0;
  40. _uShortcutkey = 0;
  41. _hbmp = NULL;
  42. _hbmpMask = NULL;
  43. _bChecked = FALSE;
  44. _bGrayed = FALSE;
  45. _pMenu = pMenu;
  46. _uUnderLine = -1;
  47. _bNonSelectedItem = (dwFlags & UIMENUITEM_NONSELECTEDITEM) ? TRUE : FALSE;
  48. }
  49. /*------------------------------------------------------------------------------
  50. dtor
  51. ------------------------------------------------------------------------------*/
  52. CUIFMenuItem::~CUIFMenuItem(void)
  53. {
  54. if (_psz)
  55. delete _psz;
  56. if (_pszTab)
  57. delete _pszTab;
  58. if (_pSubMenu)
  59. delete _pSubMenu;
  60. }
  61. /*------------------------------------------------------------------------------
  62. Init
  63. ------------------------------------------------------------------------------*/
  64. BOOL CUIFMenuItem::Init(UINT uId, WCHAR *psz)
  65. {
  66. _uId = uId;
  67. if (!psz)
  68. {
  69. _psz = NULL;
  70. _cch = 0;
  71. return TRUE;
  72. }
  73. UINT cch = StrLenW(psz);
  74. _psz = new WCHAR[cch + 1];
  75. if (!_psz)
  76. return FALSE;
  77. int i = 0;
  78. while (*psz && (*psz != L'\t'))
  79. {
  80. if (*psz == L'&')
  81. {
  82. psz++;
  83. if (*psz != L'&')
  84. {
  85. _uShortcutkey = LOBYTE(VkKeyScanW(*psz));
  86. if (!_uShortcutkey)
  87. {
  88. Assert(!HIBYTE(*psz));
  89. _uShortcutkey = LOBYTE(VkKeyScanA(LOBYTE(*psz)));
  90. }
  91. _uUnderLine = i;
  92. }
  93. }
  94. _psz[i] = *psz;
  95. i++;
  96. psz++;
  97. }
  98. _cch = StrLenW(_psz);
  99. if (*psz == L'\t')
  100. {
  101. _pszTab = new WCHAR[cch + 1];
  102. if (_pszTab)
  103. {
  104. i = 0;
  105. psz++;
  106. while (*psz)
  107. {
  108. _pszTab[i] = *psz;
  109. psz++;
  110. i++;
  111. }
  112. _cchTab = StrLenW(_pszTab);
  113. }
  114. }
  115. return TRUE;
  116. }
  117. /*------------------------------------------------------------------------------
  118. SetBitmap
  119. ------------------------------------------------------------------------------*/
  120. void CUIFMenuItem::SetBitmap(HBITMAP hbmp)
  121. {
  122. _hbmp = hbmp;
  123. }
  124. /*------------------------------------------------------------------------------
  125. Set bitmap of button face
  126. ------------------------------------------------------------------------------*/
  127. void CUIFMenuItem::SetBitmapMask( HBITMAP hBmp )
  128. {
  129. _hbmpMask = hBmp;
  130. #if 0
  131. BITMAP bmp;
  132. GetObject(_hbmp, sizeof(bmp), &bmp);
  133. RECT rc;
  134. ::SetRect(&rc, 0, 0, bmp.bmWidth, bmp.bmHeight);
  135. _hbmpMask = CreateMaskBmp(&rc, _hbmp, hBmp,
  136. (HBRUSH)(COLOR_3DFACE + 1) );
  137. #endif
  138. CallOnPaint();
  139. }
  140. /*------------------------------------------------------------------------------
  141. Check
  142. ------------------------------------------------------------------------------*/
  143. void CUIFMenuItem::Check(BOOL bChecked)
  144. {
  145. _bChecked = bChecked;
  146. }
  147. /*------------------------------------------------------------------------------
  148. RadioCheck
  149. ------------------------------------------------------------------------------*/
  150. void CUIFMenuItem::RadioCheck(BOOL bRadioChecked)
  151. {
  152. _bRadioChecked = bRadioChecked;
  153. }
  154. /*------------------------------------------------------------------------------
  155. Gray
  156. ------------------------------------------------------------------------------*/
  157. void CUIFMenuItem::Gray(BOOL bGrayed)
  158. {
  159. _bGrayed = bGrayed;
  160. }
  161. /*------------------------------------------------------------------------------
  162. SetSub
  163. ------------------------------------------------------------------------------*/
  164. void CUIFMenuItem::SetSub(CUIFMenu *pSubMenu)
  165. {
  166. _pSubMenu = pSubMenu;
  167. }
  168. /*------------------------------------------------------------------------------
  169. InitMenuExtent
  170. ------------------------------------------------------------------------------*/
  171. void CUIFMenuItem::InitMenuExtent()
  172. {
  173. HDC hdc = GetDC(m_pUIWnd->GetWnd());
  174. if (_psz)
  175. {
  176. HFONT hFontOld= (HFONT)SelectObject( hdc, GetFont() );
  177. CUIGetTextExtentPoint32( hdc, _psz, _cch, &_size);
  178. _size.cx += MENU_TEXT_MARGIN * 2;
  179. _size.cy += MENU_TEXT_MARGIN;
  180. if (_pszTab)
  181. {
  182. CUIGetTextExtentPoint32( hdc, _pszTab, _cchTab, &_sizeTab);
  183. _sizeTab.cy += MENU_TEXT_MARGIN;
  184. }
  185. SelectObject( hdc, hFontOld);
  186. if (GetSub())
  187. {
  188. _size.cx += (_size.cy + MENU_ARROW_MARGIN);
  189. }
  190. if (_pMenu->IsO10Menu())
  191. _size.cx += 24;
  192. }
  193. else if (_hbmp)
  194. {
  195. BITMAP bmp;
  196. GetObject(_hbmp, sizeof(bmp), &bmp);
  197. _size.cx = bmp.bmWidth + 2;
  198. _size.cy = bmp.bmHeight + 4;
  199. }
  200. else
  201. {
  202. _size.cy = 0;
  203. _size.cx = 0;
  204. }
  205. ReleaseDC(m_pUIWnd->GetWnd(), hdc);
  206. }
  207. /*------------------------------------------------------------------------------
  208. OnLButtonUp
  209. ------------------------------------------------------------------------------*/
  210. void CUIFMenuItem::OnLButtonUp(POINT pt)
  211. {
  212. if (IsGrayed())
  213. return;
  214. if (IsNonSelectedItem())
  215. return;
  216. if (_pSubMenu)
  217. return;
  218. _pMenu->SetSelectedId(_uId);
  219. PostMessage(m_pUIWnd->GetWnd(), WM_NULL, 0, 0);
  220. }
  221. /*------------------------------------------------------------------------------
  222. OnMouseIn
  223. ------------------------------------------------------------------------------*/
  224. void CUIFMenuItem::OnMouseIn(POINT pt)
  225. {
  226. _pMenu->CancelSubMenu();
  227. //
  228. // start timer to open submenu.
  229. //
  230. if (_pSubMenu)
  231. {
  232. UINT uElipse;
  233. if (!SystemParametersInfo(SPI_GETMENUSHOWDELAY,
  234. 0,
  235. (void *)&uElipse,
  236. FALSE))
  237. {
  238. uElipse = 300;
  239. }
  240. StartTimer(uElipse);
  241. }
  242. //
  243. // darw this.
  244. //
  245. _pMenu->SetSelectedItem(this);
  246. }
  247. /*------------------------------------------------------------------------------
  248. OnMouseOut
  249. ------------------------------------------------------------------------------*/
  250. void CUIFMenuItem::OnMouseOut(POINT pt)
  251. {
  252. }
  253. /*------------------------------------------------------------------------------
  254. OnTimer
  255. ------------------------------------------------------------------------------*/
  256. void CUIFMenuItem::OnTimer()
  257. {
  258. EndTimer();
  259. Assert(PtrToInt(_pSubMenu));
  260. if (!_pMenu->IsPointed(this))
  261. return;
  262. ShowSubPopup();
  263. }
  264. /*------------------------------------------------------------------------------
  265. ShowSubPopup
  266. ------------------------------------------------------------------------------*/
  267. void CUIFMenuItem::ShowSubPopup()
  268. {
  269. Assert(PtrToInt(_pSubMenu));
  270. RECT rc = GetRectRef();
  271. ClientToScreen(m_pUIWnd->GetWnd(), (POINT *)&rc.left);
  272. ClientToScreen(m_pUIWnd->GetWnd(), (POINT *)&rc.right);
  273. _pSubMenu->ShowSubPopup(_pMenu, &rc, FALSE);
  274. }
  275. /*------------------------------------------------------------------------------
  276. OnPaint
  277. ------------------------------------------------------------------------------*/
  278. void CUIFMenuItem::OnPaint(HDC hDC)
  279. {
  280. if (_pMenu->IsO10Menu())
  281. OnPaintO10(hDC);
  282. else
  283. OnPaintDef(hDC);
  284. }
  285. /*------------------------------------------------------------------------------
  286. OnPaintDef
  287. ------------------------------------------------------------------------------*/
  288. void CUIFMenuItem::OnPaintDef(HDC hDC)
  289. {
  290. HFONT hFontOld;
  291. int xAlign;
  292. int yAlign;
  293. int xText;
  294. int yText;
  295. int xCheck;
  296. int yCheck;
  297. int xBmp;
  298. int yBmp;
  299. int xArrow;
  300. int yArrow;
  301. SIZE size;
  302. hFontOld= (HFONT)SelectObject( hDC, GetFont() );
  303. // calc alignment
  304. CUIGetTextExtentPoint32( hDC, _psz, _cch, &size );
  305. xAlign = 0;
  306. yAlign = (GetRectRef().bottom - GetRectRef().top - size.cy) / 2;
  307. xCheck = GetRectRef().left + xAlign;
  308. yCheck = GetRectRef().top + yAlign;
  309. xBmp = xCheck + (_pMenu->IsBmpCheckItem() ? _pMenu->GetMenuCheckWidth() : 0);
  310. yBmp = GetRectRef().top;
  311. xText = xCheck + 2 + _pMenu->GetMenuCheckWidth() + (_pMenu->IsBmpCheckItem() ? _pMenu->GetMenuCheckWidth() : 0);
  312. yText = GetRectRef().top + yAlign;
  313. xArrow = GetRectRef().left + GetRectRef().right - 10,
  314. yArrow = GetRectRef().top + yAlign;
  315. // draw
  316. SetBkMode( hDC, TRANSPARENT );
  317. if (!_bGrayed)
  318. {
  319. if (!_pMenu->IsSelectedItem(this) || IsNonSelectedItem())
  320. {
  321. SetTextColor( hDC, GetSysColor(COLOR_MENUTEXT) );
  322. CUIExtTextOut( hDC,
  323. xText,
  324. yText,
  325. ETO_CLIPPED,
  326. &GetRectRef(),
  327. _psz,
  328. _cch,
  329. NULL );
  330. DrawUnderline(hDC,
  331. xText,
  332. yText,
  333. (HBRUSH)(COLOR_MENUTEXT + 1));
  334. DrawCheck(hDC, xCheck, yCheck);
  335. DrawBitmapProc(hDC, xBmp, yBmp);
  336. DrawArrow(hDC, xArrow, yArrow);
  337. }
  338. else
  339. {
  340. SetTextColor( hDC, GetSysColor(COLOR_HIGHLIGHTTEXT) );
  341. SetBkColor( hDC, GetSysColor(COLOR_HIGHLIGHT) );
  342. CUIExtTextOut( hDC,
  343. xText,
  344. yText,
  345. ETO_CLIPPED | ETO_OPAQUE,
  346. &GetRectRef(),
  347. _psz,
  348. _cch,
  349. NULL );
  350. DrawUnderline(hDC,
  351. xText,
  352. yText,
  353. (HBRUSH)(COLOR_HIGHLIGHTTEXT + 1));
  354. DrawCheck(hDC, xCheck, yCheck);
  355. DrawBitmapProc(hDC, xBmp, yBmp);
  356. DrawArrow(hDC, xArrow, yArrow);
  357. }
  358. }
  359. else
  360. {
  361. UINT ueto = ETO_CLIPPED;
  362. if (!_pMenu->IsSelectedItem(this) || IsNonSelectedItem())
  363. {
  364. SetTextColor( hDC, GetSysColor(COLOR_3DHIGHLIGHT) );
  365. CUIExtTextOut( hDC,
  366. xText + 1,
  367. yText + 1,
  368. ueto,
  369. &GetRectRef(),
  370. _psz,
  371. _cch,
  372. NULL );
  373. DrawCheck(hDC, xCheck + 1, yCheck + 1);
  374. DrawBitmapProc(hDC, xBmp + 1, yBmp + 1);
  375. DrawArrow(hDC, xArrow + 1, yArrow + 1);
  376. }
  377. else
  378. {
  379. SetBkColor( hDC, GetSysColor(COLOR_HIGHLIGHT) );
  380. ueto |= ETO_OPAQUE;
  381. }
  382. SetTextColor(hDC, GetSysColor(COLOR_3DSHADOW) );
  383. CUIExtTextOut(hDC,
  384. xText,
  385. yText,
  386. ueto,
  387. &GetRectRef(),
  388. _psz,
  389. _cch,
  390. NULL );
  391. DrawUnderline(hDC,
  392. xText,
  393. yText,
  394. (HBRUSH)(COLOR_3DSHADOW + 1));
  395. DrawCheck(hDC, xCheck, yCheck);
  396. DrawBitmapProc(hDC, xBmp, yBmp);
  397. DrawArrow(hDC, xArrow, yArrow);
  398. }
  399. // restore objects
  400. SelectObject( hDC, hFontOld);
  401. }
  402. /*------------------------------------------------------------------------------
  403. OnPaintO10
  404. ------------------------------------------------------------------------------*/
  405. void CUIFMenuItem::OnPaintO10(HDC hDC)
  406. {
  407. HFONT hFontOld;
  408. int xAlign;
  409. int yAlign;
  410. int xText;
  411. int yText;
  412. int xCheck;
  413. int yCheck;
  414. int xBmp;
  415. int yBmp;
  416. int xArrow;
  417. int yArrow;
  418. SIZE size;
  419. RECT rc;
  420. if (!m_pUIFScheme)
  421. return;
  422. hFontOld= (HFONT)SelectObject( hDC, GetFont() );
  423. // calc alignment
  424. CUIGetTextExtentPoint32( hDC, _psz, _cch, &size );
  425. xAlign = 0;
  426. yAlign = (GetRectRef().bottom - GetRectRef().top - size.cy) / 2;
  427. xCheck = GetRectRef().left + xAlign;
  428. yCheck = GetRectRef().top + yAlign;
  429. xBmp = xCheck + (_pMenu->IsBmpCheckItem() ? _pMenu->GetMenuCheckWidth() : 0);
  430. yBmp = GetRectRef().top;
  431. xText = xBmp + 8 + _pMenu->GetMenuCheckWidth();
  432. yText = GetRectRef().top + yAlign;
  433. xArrow = GetRectRef().left + GetRectRef().right - size.cy - MENU_ARROW_MARGIN; //size.cy may be enough for size of arrow...
  434. yArrow = GetRectRef().top + yAlign;
  435. // draw
  436. GetRect(&rc);
  437. if (!_pMenu->IsSelectedItem(this) || IsNonSelectedItem())
  438. {
  439. rc.right = rc.left + _pMenu->GetMenuCheckWidth() + 2;
  440. if (_pMenu->IsBmpCheckItem())
  441. rc.right += _pMenu->GetMenuCheckWidth();
  442. ::FillRect(hDC, &rc, m_pUIFScheme->GetBrush(UIFCOLOR_CTRLBKGND));
  443. }
  444. else
  445. {
  446. m_pUIFScheme->DrawCtrlBkgd(hDC, &rc, 0, UIFDCS_SELECTED);
  447. m_pUIFScheme->DrawCtrlEdge(hDC, &rc, 0, UIFDCS_SELECTED);
  448. }
  449. SetBkMode( hDC, TRANSPARENT );
  450. if (!_bGrayed)
  451. {
  452. if (!_pMenu->IsSelectedItem(this) || IsNonSelectedItem())
  453. {
  454. SetTextColor( hDC, m_pUIFScheme->GetColor(UIFCOLOR_CTRLTEXT) );
  455. CUIExtTextOut( hDC,
  456. xText,
  457. yText,
  458. ETO_CLIPPED,
  459. &GetRectRef(),
  460. _psz,
  461. _cch,
  462. NULL );
  463. DrawUnderline(hDC,
  464. xText,
  465. yText,
  466. (HBRUSH)m_pUIFScheme->GetBrush(UIFCOLOR_CTRLTEXT));
  467. if (_pszTab)
  468. CUIExtTextOut( hDC,
  469. GetRectRef().right - _pMenu->GetMaxTabTextLength() - MENU_TEXT_MARGIN,
  470. yText,
  471. ETO_CLIPPED,
  472. &GetRectRef(),
  473. _pszTab,
  474. _cchTab,
  475. NULL );
  476. DrawCheck(hDC, xCheck, yCheck);
  477. DrawBitmapProc(hDC, xBmp, yBmp);
  478. DrawArrow(hDC, xArrow, yArrow);
  479. }
  480. else
  481. {
  482. SetTextColor( hDC, m_pUIFScheme->GetColor(UIFCOLOR_MOUSEOVERTEXT) );
  483. CUIExtTextOut( hDC,
  484. xText,
  485. yText,
  486. ETO_CLIPPED,
  487. &GetRectRef(),
  488. _psz,
  489. _cch,
  490. NULL );
  491. DrawUnderline(hDC,
  492. xText,
  493. yText,
  494. (HBRUSH)m_pUIFScheme->GetBrush(UIFCOLOR_MOUSEOVERTEXT));
  495. if (_pszTab)
  496. CUIExtTextOut( hDC,
  497. GetRectRef().right - _pMenu->GetMaxTabTextLength() - MENU_TEXT_MARGIN,
  498. yText,
  499. ETO_CLIPPED,
  500. &GetRectRef(),
  501. _pszTab,
  502. _cchTab,
  503. NULL );
  504. DrawCheck(hDC, xCheck, yCheck);
  505. DrawBitmapProc(hDC, xBmp, yBmp);
  506. DrawArrow(hDC, xArrow, yArrow);
  507. }
  508. }
  509. else
  510. {
  511. #if 1
  512. SetTextColor( hDC, m_pUIFScheme->GetColor(UIFCOLOR_CTRLTEXTDISABLED) );
  513. CUIExtTextOut(hDC,
  514. xText,
  515. yText,
  516. ETO_CLIPPED,
  517. &GetRectRef(),
  518. _psz,
  519. _cch,
  520. NULL );
  521. DrawUnderline(hDC,
  522. xText,
  523. yText,
  524. (HBRUSH)m_pUIFScheme->GetBrush(UIFCOLOR_CTRLTEXTDISABLED));
  525. if (_pszTab)
  526. CUIExtTextOut( hDC,
  527. GetRectRef().right - _pMenu->GetMaxTabTextLength() - MENU_TEXT_MARGIN,
  528. yText,
  529. ETO_CLIPPED,
  530. &GetRectRef(),
  531. _pszTab,
  532. _cchTab,
  533. NULL );
  534. DrawCheck(hDC, xCheck, yCheck);
  535. DrawBitmapProc(hDC, xBmp, yBmp);
  536. DrawArrow(hDC, xArrow, yArrow);
  537. #else
  538. UINT ueto = ETO_CLIPPED;
  539. if (!_pMenu->IsSelectedItem(this) || IsNonSelectedItem())
  540. {
  541. SetTextColor( hDC, GetSysColor(COLOR_3DHIGHLIGHT) );
  542. CUIExtTextOut( hDC,
  543. xText + 1,
  544. yText + 1,
  545. ueto,
  546. &GetRectRef(),
  547. _psz,
  548. _cch,
  549. NULL );
  550. if (_pszTab)
  551. CUIExtTextOut( hDC,
  552. GetRectRef().right - _pMenu->GetMaxTabTextLength() - 3,
  553. yText + 1,
  554. ETO_CLIPPED,
  555. &GetRectRef(),
  556. _pszTab,
  557. _cchTab,
  558. NULL );
  559. DrawCheck(hDC, xCheck + 1, yCheck + 1);
  560. DrawBitmapProc(hDC, xBmp + 1, yBmp + 1);
  561. DrawArrow(hDC, xArrow + 1, yArrow + 1);
  562. }
  563. else
  564. {
  565. SetBkColor( hDC, GetSysColor(COLOR_HIGHLIGHT) );
  566. ueto |= ETO_OPAQUE;
  567. }
  568. SetTextColor(hDC, GetSysColor(COLOR_3DSHADOW) );
  569. CUIExtTextOut(hDC,
  570. xText,
  571. yText,
  572. ueto,
  573. &GetRectRef(),
  574. _psz,
  575. _cch,
  576. NULL );
  577. DrawUnderline(hDC,
  578. xText,
  579. yText,
  580. (HBRUSH)(COLOR_3DSHADOW + 1));
  581. CUIExtTextOut( hDC,
  582. GetRectRef().right - _pMenu->GetMaxTabTextLength() - MENU_TEXT_MARGIN,
  583. yText,
  584. ETO_CLIPPED,
  585. &GetRectRef(),
  586. _pszTab,
  587. _cchTab,
  588. NULL );
  589. DrawCheck(hDC, xCheck, yCheck);
  590. DrawBitmapProc(hDC, xBmp, yBmp);
  591. DrawArrow(hDC, xArrow, yArrow);
  592. #endif
  593. }
  594. // restore objects
  595. SelectObject( hDC, hFontOld);
  596. }
  597. /*------------------------------------------------------------------------------
  598. DrawUnderline
  599. ------------------------------------------------------------------------------*/
  600. void CUIFMenuItem::DrawUnderline(HDC hDC, int x, int y, HBRUSH hbr)
  601. {
  602. if (_uUnderLine > _cch)
  603. return;
  604. SIZE size0, size1;
  605. CUIGetTextExtentPoint32( hDC, _psz, _uUnderLine, &size0 );
  606. CUIGetTextExtentPoint32( hDC, _psz, _uUnderLine + 1, &size1 );
  607. RECT rc;
  608. rc.left = x + size0.cx;
  609. if (_uUnderLine)
  610. rc.left++;
  611. rc.right = x + size1.cx;
  612. rc.top = y + size1.cy - 1;
  613. rc.bottom = y + size1.cy;
  614. FillRect(hDC, &rc, hbr);
  615. }
  616. /*------------------------------------------------------------------------------
  617. DrawCheck
  618. ------------------------------------------------------------------------------*/
  619. void CUIFMenuItem::DrawCheck(HDC hDC, int x, int y)
  620. {
  621. if (!IsCheck())
  622. return;
  623. HFONT hFontOld = (HFONT)SelectObject( hDC, _pMenu->GetMarlettFont());
  624. TextOut(hDC, x, y, _bChecked ? "a" : "h", 1);
  625. SelectObject( hDC, hFontOld);
  626. }
  627. /*------------------------------------------------------------------------------
  628. DrawArrow
  629. ------------------------------------------------------------------------------*/
  630. void CUIFMenuItem::DrawArrow(HDC hDC, int x, int y)
  631. {
  632. if (!_pSubMenu)
  633. return;
  634. HFONT hFontOld = (HFONT)SelectObject( hDC, _pMenu->GetMarlettFont());
  635. TextOut( hDC, x, y, "4", 1);
  636. SelectObject( hDC, hFontOld);
  637. }
  638. /* D R A W B I T M A P P R O C */
  639. /*------------------------------------------------------------------------------
  640. Draw bitmap on button face
  641. ------------------------------------------------------------------------------*/
  642. void CUIFMenuItem::DrawBitmapProc( HDC hDC, int x, int y)
  643. {
  644. BITMAP bmp;
  645. DWORD dwState = 0;
  646. if (!m_pUIFScheme)
  647. return;
  648. if (!_hbmp)
  649. return;
  650. int cx;
  651. int cy;
  652. cx = _pMenu->GetMenuCheckWidth();
  653. cy = GetRectRef().bottom - GetRectRef().top;
  654. // we have to do this viewport trick to get around the fact that
  655. // DrawState has a GDI bug in NT4, such that it handles offsets improperly.
  656. // so we do the offset by hand.
  657. // POINT ptOldOrg;
  658. // BOOL fRetVal = SetViewportOrgEx( hDC, 0, 0, &ptOldOrg );
  659. // Assert( fRetVal );
  660. GetObject(_hbmp, sizeof(bmp), &bmp);
  661. if (cx > bmp.bmWidth)
  662. {
  663. x += (cx - bmp.bmWidth) / 2;
  664. cx = bmp.bmWidth;
  665. }
  666. if (cy > bmp.bmHeight)
  667. {
  668. y += (cy - bmp.bmHeight) / 2;
  669. cy = bmp.bmHeight;
  670. }
  671. RECT rc;
  672. // ::SetRect(&rc, x + ptOldOrg.x,
  673. // y + ptOldOrg.y,
  674. // x + ptOldOrg.x + cx,
  675. // y + ptOldOrg.y + cy);
  676. ::SetRect(&rc, x, y, x + cx, y + cy);
  677. if (IsRTL())
  678. m_pUIFScheme->SetLayout(LAYOUT_RTL);
  679. if (_pMenu->IsSelectedItem(this) && !IsNonSelectedItem())
  680. {
  681. dwState |= UIFDCS_SELECTED;
  682. m_pUIFScheme->DrawMenuBitmap(hDC, &rc, _hbmp, _hbmpMask, dwState);
  683. }
  684. #if 0
  685. else if (IsCheck())
  686. {
  687. dwState |= UIFDCS_MOUSEOVER;
  688. m_pUIFScheme->DrawMenuBitmap(hDC, &rc, _hbmp, _hbmpMask, dwState);
  689. ::OffsetRect(&rc, -1, -1);
  690. ::InflateRect(&rc, 2, 2);
  691. m_pUIFScheme->DrawCtrlEdge(hDC, &rc, 0, UIFDCS_SELECTED);
  692. }
  693. #endif
  694. else
  695. {
  696. m_pUIFScheme->DrawMenuBitmap(hDC, &rc, _hbmp, _hbmpMask, dwState);
  697. }
  698. if (IsRTL())
  699. m_pUIFScheme->SetLayout(0);
  700. // SetViewportOrgEx( hDC, ptOldOrg.x, ptOldOrg.y, NULL );
  701. }
  702. /*============================================================================*/
  703. //
  704. // CUIFMenuItemSeparator
  705. //
  706. /*============================================================================*/
  707. /*------------------------------------------------------------------------------
  708. OnPaint
  709. ------------------------------------------------------------------------------*/
  710. void CUIFMenuItemSeparator::OnPaint(HDC hDC)
  711. {
  712. if (_pMenu->IsO10Menu())
  713. OnPaintO10(hDC);
  714. else
  715. OnPaintDef(hDC);
  716. }
  717. /*------------------------------------------------------------------------------
  718. OnPaintDef
  719. ------------------------------------------------------------------------------*/
  720. void CUIFMenuItemSeparator::OnPaintDef(HDC hDC)
  721. {
  722. if (!m_pUIFScheme)
  723. return;
  724. int xAlign = 2;
  725. int yAlign = (GetRectRef().bottom - GetRectRef().top - 2) / 2;
  726. int cx = (GetRectRef().right - GetRectRef().left - 2 * xAlign);
  727. RECT rc;
  728. ::SetRect(&rc,
  729. GetRectRef().left + xAlign,
  730. GetRectRef().top + yAlign,
  731. GetRectRef().left + xAlign + cx,
  732. GetRectRef().top + yAlign + 2);
  733. m_pUIFScheme->DrawMenuSeparator( hDC, &rc);
  734. }
  735. /*------------------------------------------------------------------------------
  736. OnPaintO10
  737. ------------------------------------------------------------------------------*/
  738. void CUIFMenuItemSeparator::OnPaintO10(HDC hDC)
  739. {
  740. if (!m_pUIFScheme)
  741. return;
  742. int xAlign = 2;
  743. int yAlign = (GetRectRef().bottom - GetRectRef().top - 2) / 2;
  744. int cx = (GetRectRef().right - GetRectRef().left - 2 * xAlign);
  745. int xStart = 0;
  746. RECT rc;
  747. GetRect(&rc);
  748. rc.right = rc.left + _pMenu->GetMenuCheckWidth() + 2;
  749. if (_pMenu->IsBmpCheckItem())
  750. rc.right += _pMenu->GetMenuCheckWidth();
  751. ::FillRect(hDC, &rc, m_pUIFScheme->GetBrush(UIFCOLOR_CTRLBKGND));
  752. xStart = _pMenu->GetMenuCheckWidth() + 2;
  753. ::SetRect(&rc,
  754. GetRectRef().left + xAlign + xStart,
  755. GetRectRef().top + yAlign,
  756. GetRectRef().left + xAlign + cx,
  757. GetRectRef().top + yAlign + 1);
  758. m_pUIFScheme->DrawMenuSeparator( hDC, &rc);
  759. }
  760. /*------------------------------------------------------------------------------
  761. InitMenuExtent
  762. ------------------------------------------------------------------------------*/
  763. void CUIFMenuItemSeparator::InitMenuExtent()
  764. {
  765. _size.cx = 0;
  766. _size.cy = 6;
  767. }
  768. /*============================================================================*/
  769. //
  770. // CUIFMenu
  771. //
  772. /*============================================================================*/
  773. /*------------------------------------------------------------------------------
  774. ctor
  775. ------------------------------------------------------------------------------*/
  776. CUIFMenu::CUIFMenu(HINSTANCE hInst, DWORD dwWndStyle, DWORD dwMenuStyle) : CUIFWindow(hInst, dwWndStyle)
  777. {
  778. _uIdSelect = CUI_MENU_UNSELECTED;
  779. _dwMenuStyle = dwMenuStyle;
  780. SetMenuFont();
  781. }
  782. /*------------------------------------------------------------------------------
  783. dtor
  784. ------------------------------------------------------------------------------*/
  785. CUIFMenu::~CUIFMenu( void )
  786. {
  787. int i;
  788. for (i = 0; i < _rgItems.GetCount(); i++)
  789. {
  790. CUIFMenuItem *pItem = _rgItems.Get(i);
  791. delete pItem;
  792. }
  793. DeleteObject(_hfontMarlett);
  794. ClearMenuFont();
  795. }
  796. /*------------------------------------------------------------------------------
  797. InsertItem
  798. ------------------------------------------------------------------------------*/
  799. BOOL CUIFMenu::InsertItem(CUIFMenuItem *pItem)
  800. {
  801. if (!_rgItems.Add( pItem ))
  802. return FALSE;
  803. pItem->SetFont(GetFont());
  804. return TRUE;
  805. }
  806. /*------------------------------------------------------------------------------
  807. InsertSeparator
  808. ------------------------------------------------------------------------------*/
  809. BOOL CUIFMenu::InsertSeparator()
  810. {
  811. CUIFMenuItemSeparator *pSep;
  812. pSep = new CUIFMenuItemSeparator(this);
  813. if (!pSep)
  814. return FALSE;
  815. pSep->Initialize();
  816. if (!_rgItems.Add( pSep ))
  817. {
  818. delete pSep;
  819. return FALSE;
  820. }
  821. return TRUE;
  822. }
  823. /*------------------------------------------------------------------------------
  824. ShowModalPopup
  825. ------------------------------------------------------------------------------*/
  826. UINT CUIFMenu::ShowModalPopup(CUIFWindow *pcuiWndParent, const RECT *prc, BOOL fVertical)
  827. {
  828. UINT uId;
  829. CUIFObject *puicap;
  830. if (pcuiWndParent)
  831. {
  832. puicap = pcuiWndParent->GetCaptureObject();
  833. pcuiWndParent->SetCaptureObject(NULL);
  834. }
  835. if (InitShow(pcuiWndParent, prc, fVertical, TRUE)) {
  836. _fInModal = TRUE;
  837. pcuiWndParent->SetBehindModal(this);
  838. ModalMessageLoop();
  839. uId = _uIdSelect;
  840. pcuiWndParent->SetBehindModal(NULL);
  841. _fInModal = FALSE;
  842. }
  843. else
  844. {
  845. uId = CUI_MENU_UNSELECTED;
  846. }
  847. UninitShow();
  848. if (pcuiWndParent)
  849. {
  850. pcuiWndParent->SetCaptureObject(puicap);
  851. }
  852. return uId;
  853. }
  854. /*------------------------------------------------------------------------------
  855. ModalMessageLoop
  856. ------------------------------------------------------------------------------*/
  857. void CUIFMenu::ModalMessageLoop( void )
  858. {
  859. MSG msg;
  860. while (GetMessage(&msg, NULL, 0, 0))
  861. {
  862. if (msg.message == WM_NULL)
  863. break;
  864. if (msg.hwnd != GetWnd())
  865. {
  866. if ((msg.message > WM_MOUSEFIRST) &&
  867. (msg.message <= WM_MOUSELAST))
  868. {
  869. break;
  870. }
  871. }
  872. //
  873. // Dispatch key message to Sub menu.
  874. //
  875. if ((msg.message >= WM_KEYFIRST) &&
  876. (msg.message <= WM_KEYLAST))
  877. {
  878. if (!msg.hwnd)
  879. {
  880. CUIFMenu *pSubMenu = GetTopSubMenu();
  881. msg.hwnd = pSubMenu->GetWnd();
  882. }
  883. }
  884. TranslateMessage(&msg);
  885. DispatchMessage(&msg);
  886. }
  887. }
  888. /*------------------------------------------------------------------------------
  889. InitShow
  890. ------------------------------------------------------------------------------*/
  891. BOOL CUIFMenu::InitShow(CUIFWindow *pcuiWndParent, const RECT *prc, BOOL fVertical, BOOL fAnimate)
  892. {
  893. int i;
  894. int cxMax = 0;
  895. SIZE size = {0, 0};
  896. RECT rc = {0, 0, 0, 0};
  897. RECT rcScreen;
  898. HMONITOR hMonitor;
  899. CUIFMenuItem *pItem;
  900. BOOL fMenuAnimation = FALSE;
  901. BOOL fAnimated = FALSE;
  902. DWORD dwSlideFlag = 0;
  903. int x;
  904. int y;
  905. CreateWnd((pcuiWndParent != NULL) ? pcuiWndParent->GetWnd() : NULL);
  906. _fIsBmpCheckItem = FALSE;
  907. for (i = 0; i < _rgItems.GetCount(); i++)
  908. {
  909. pItem = _rgItems.Get(i);
  910. pItem->InitMenuExtent();
  911. }
  912. _cxMaxTab = 0;
  913. for (i = 0; i < _rgItems.GetCount(); i++)
  914. {
  915. pItem = _rgItems.Get(i);
  916. pItem->GetMenuExtent(&size);
  917. size.cx += GetMenuCheckWidth();
  918. cxMax = (size.cx > cxMax) ? size.cx : cxMax;
  919. _cxMaxTab = (pItem->GetTabTextLength() > _cxMaxTab) ?
  920. pItem->GetTabTextLength() :
  921. _cxMaxTab;
  922. _fIsBmpCheckItem |= (pItem->IsBmp() && pItem->IsCheck()) ? TRUE : FALSE;
  923. }
  924. for (i = 0; i < _rgItems.GetCount(); i++)
  925. {
  926. pItem = _rgItems.Get(i);
  927. pItem->GetMenuExtent(&size);
  928. rc.right = rc.left + cxMax + _cxMaxTab;
  929. rc.bottom = rc.top + size.cy;
  930. pItem->SetRect(&rc);
  931. rc.top += size.cy;
  932. AddUIObj(pItem);
  933. }
  934. rc.top = 0;
  935. LONG_PTR dwStyle = GetWindowLongPtr(GetWnd(), GWL_STYLE);
  936. int nWidth = rc.right;
  937. int nHeight = rc.bottom;
  938. if (dwStyle & WS_DLGFRAME)
  939. {
  940. nWidth += GetSystemMetrics(SM_CXDLGFRAME) * 2;
  941. nHeight += GetSystemMetrics(SM_CYDLGFRAME) * 2;
  942. }
  943. else if (dwStyle & WS_BORDER)
  944. {
  945. nWidth += GetSystemMetrics(SM_CXBORDER) * 2;
  946. nHeight += GetSystemMetrics(SM_CYBORDER) * 2;
  947. }
  948. ::SetRect( &rcScreen, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) );
  949. RECT rcT;
  950. rcT = *prc;
  951. hMonitor = CUIMonitorFromRect( &rcT, MONITOR_DEFAULTTONEAREST );
  952. if (hMonitor != NULL) {
  953. MONITORINFO MonitorInfo = {0};
  954. MonitorInfo.cbSize = sizeof(MONITORINFO);
  955. if (CUIGetMonitorInfo( hMonitor, &MonitorInfo )) {
  956. rcScreen = MonitorInfo.rcMonitor;
  957. }
  958. }
  959. if (FHasStyle( UIWINDOW_LAYOUTRTL ))
  960. rc.left -= nWidth;
  961. if (fVertical)
  962. {
  963. x = rc.left + prc->left;
  964. if (rc.top + prc->bottom + nHeight <= rcScreen.bottom)
  965. {
  966. y = rc.top + prc->bottom;
  967. dwSlideFlag = AW_VER_POSITIVE;
  968. }
  969. else
  970. {
  971. y = rc.top + prc->top - nHeight;
  972. dwSlideFlag = AW_VER_NEGATIVE;
  973. }
  974. if (rc.left + prc->right + nWidth > rcScreen.right)
  975. x = rcScreen.right - nWidth;
  976. }
  977. else
  978. {
  979. y = rc.top + prc->top;
  980. if (rc.left + prc->right + nWidth <= rcScreen.right)
  981. {
  982. x = rc.left + prc->right;
  983. dwSlideFlag = AW_HOR_POSITIVE;
  984. }
  985. else
  986. {
  987. x = rc.left + prc->left - nWidth;
  988. dwSlideFlag = AW_HOR_NEGATIVE;
  989. }
  990. if (rc.top + prc->bottom + nHeight > rcScreen.bottom)
  991. y = rcScreen.bottom - nHeight;
  992. }
  993. x = min( rcScreen.right - nWidth, x );
  994. x = max( rcScreen.left, x );
  995. y = min( rcScreen.bottom - nHeight, y );
  996. y = max( rcScreen.top, y );
  997. Move(x, y, nWidth, nHeight);
  998. SetRect(NULL);
  999. // animation support
  1000. fAnimated = FALSE;
  1001. if (fAnimate) {
  1002. if (SystemParametersInfo( SPI_GETMENUANIMATION, 0, &fMenuAnimation, FALSE ) && fMenuAnimation) {
  1003. BOOL fFade = FALSE;
  1004. DWORD dwFlags;
  1005. if (!SystemParametersInfo( SPI_GETMENUFADE, 0, &fFade, FALSE )) {
  1006. fFade = FALSE;
  1007. }
  1008. // determine animation flag
  1009. if (fFade) {
  1010. dwFlags = AW_BLEND;
  1011. }
  1012. else {
  1013. dwFlags = AW_SLIDE | dwSlideFlag;
  1014. }
  1015. fAnimated = AnimateWnd( 200, dwFlags );
  1016. }
  1017. }
  1018. if (!fAnimated) {
  1019. Show(TRUE);
  1020. }
  1021. if (_pcuiParentMenu)
  1022. _pcuiParentMenu->_pCurrentSubMenu = this;
  1023. return TRUE;
  1024. }
  1025. /*------------------------------------------------------------------------------
  1026. UninitShow
  1027. ------------------------------------------------------------------------------*/
  1028. BOOL CUIFMenu::UninitShow()
  1029. {
  1030. int i;
  1031. if (_pCurrentSubMenu)
  1032. _pCurrentSubMenu->UninitShow();
  1033. Show(FALSE);
  1034. if (_pcuiParentMenu)
  1035. _pcuiParentMenu->_pCurrentSubMenu = NULL;
  1036. for (i = 0; i < _rgItems.GetCount(); i++)
  1037. RemoveUIObj(_rgItems.Get(i));
  1038. DestroyWindow(GetWnd());
  1039. return TRUE;
  1040. }
  1041. /*------------------------------------------------------------------------------
  1042. ShowSubPopup
  1043. ------------------------------------------------------------------------------*/
  1044. void CUIFMenu::ShowSubPopup(CUIFMenu *pcuiParentMenu, const RECT *prc, BOOL fVertical)
  1045. {
  1046. _pcuiParentMenu = pcuiParentMenu;
  1047. InitShow(pcuiParentMenu, prc, fVertical, TRUE); // TODO: fAnimate = FALSE if submenu has already been shown, or going to be changed contibuously
  1048. }
  1049. /*------------------------------------------------------------------------------
  1050. OnLButtonUp
  1051. ------------------------------------------------------------------------------*/
  1052. void CUIFMenu::HandleMouseMsg( UINT uMsg, POINT pt )
  1053. {
  1054. if (!PtInRect(&GetRectRef(), pt))
  1055. {
  1056. if ((uMsg == WM_LBUTTONDOWN) || (uMsg == WM_RBUTTONDOWN) ||
  1057. (uMsg == WM_LBUTTONUP) || (uMsg == WM_RBUTTONUP))
  1058. {
  1059. SetSelectedId(CUI_MENU_UNSELECTED);
  1060. PostMessage(GetWnd(), WM_NULL, 0, 0);
  1061. }
  1062. }
  1063. CUIFWindow::HandleMouseMsg( uMsg, pt );
  1064. }
  1065. /*------------------------------------------------------------------------------
  1066. CancelMenu
  1067. ------------------------------------------------------------------------------*/
  1068. void CUIFMenu::CancelMenu()
  1069. {
  1070. if (_pcuiParentMenu)
  1071. {
  1072. UninitShow();
  1073. return;
  1074. }
  1075. if (!_fInModal)
  1076. return;
  1077. SetSelectedId(CUI_MENU_UNSELECTED);
  1078. PostMessage(GetWnd(), WM_NULL, 0, 0);
  1079. }
  1080. /*------------------------------------------------------------------------------
  1081. CancelMenu
  1082. ------------------------------------------------------------------------------*/
  1083. void CUIFMenu::SetSelectedId(UINT uId)
  1084. {
  1085. if (_pcuiParentMenu)
  1086. {
  1087. _pcuiParentMenu->SetSelectedId(uId);
  1088. return;
  1089. }
  1090. _uIdSelect = uId;
  1091. }
  1092. /*------------------------------------------------------------------------------
  1093. GetTopSubMenu
  1094. ------------------------------------------------------------------------------*/
  1095. CUIFMenu *CUIFMenu::GetTopSubMenu()
  1096. {
  1097. if (_pCurrentSubMenu)
  1098. return _pCurrentSubMenu->GetTopSubMenu();
  1099. return this;
  1100. }
  1101. /*------------------------------------------------------------------------------
  1102. PostKey
  1103. ------------------------------------------------------------------------------*/
  1104. void CUIFMenu::PostKey(BOOL fUp, WPARAM wParam, LPARAM lParam)
  1105. {
  1106. if (!_fInModal)
  1107. return;
  1108. if (fUp)
  1109. PostMessage(0, WM_KEYUP, wParam, lParam);
  1110. else
  1111. PostMessage(0, WM_KEYDOWN, wParam, lParam);
  1112. }
  1113. /*------------------------------------------------------------------------------
  1114. ModalMouseNotify
  1115. ------------------------------------------------------------------------------*/
  1116. void CUIFMenu::ModalMouseNotify( UINT uMsg, POINT pt)
  1117. {
  1118. if ((uMsg == WM_LBUTTONDOWN) || (uMsg == WM_RBUTTONDOWN))
  1119. CancelMenu();
  1120. }
  1121. /*------------------------------------------------------------------------------
  1122. OnKeyDown
  1123. ------------------------------------------------------------------------------*/
  1124. void CUIFMenu::OnKeyDown(HWND hwnd, WPARAM wParam, LPARAM lParam)
  1125. {
  1126. UINT uVKey = (UINT)wParam & 0xff;
  1127. CUIFMenuItem *pItem;
  1128. switch (uVKey)
  1129. {
  1130. case VK_ESCAPE:
  1131. CancelMenu();
  1132. break;
  1133. case VK_UP:
  1134. pItem = GetPrevItem(_pSelectedItem);
  1135. goto MoveToItem;
  1136. case VK_DOWN:
  1137. pItem = GetNextItem(_pSelectedItem);
  1138. MoveToItem:
  1139. SetSelectedItem(pItem);
  1140. break;
  1141. case VK_RIGHT:
  1142. if (_pSelectedItem && _pSelectedItem->GetSub())
  1143. {
  1144. _pSelectedItem->ShowSubPopup();
  1145. CUIFMenu *pSubMenu = _pSelectedItem->GetSub();
  1146. CUIFMenuItem *pSubMenuItem = pSubMenu->GetNextItem(NULL);
  1147. pSubMenu->SetSelectedItem(pSubMenuItem);
  1148. }
  1149. break;
  1150. case VK_LEFT:
  1151. if (_pcuiParentMenu)
  1152. CancelMenu();
  1153. break;
  1154. case VK_RETURN:
  1155. DoReturn:
  1156. if (_pSelectedItem)
  1157. {
  1158. if (_pSelectedItem->IsGrayed())
  1159. break;
  1160. if (_pSelectedItem->GetSub())
  1161. {
  1162. _pSelectedItem->ShowSubPopup();
  1163. CUIFMenu *pSubMenu = _pSelectedItem->GetSub();
  1164. CUIFMenuItem *pSubMenuItem = pSubMenu->GetNextItem(NULL);
  1165. pSubMenu->SetSelectedItem(pSubMenuItem);
  1166. }
  1167. else
  1168. {
  1169. SetSelectedId(_pSelectedItem->GetId());
  1170. PostMessage(GetWnd(), WM_NULL, 0, 0);
  1171. }
  1172. }
  1173. else
  1174. {
  1175. CancelMenu();
  1176. }
  1177. break;
  1178. default:
  1179. if ((uVKey >= 'A' && uVKey <= 'Z') ||
  1180. (uVKey >= '0' && uVKey <= '9'))
  1181. {
  1182. int nCnt = _rgItems.GetCount();
  1183. int i;
  1184. for (i = 0; i < nCnt; i++)
  1185. {
  1186. pItem = _rgItems.Get(i);
  1187. Assert(PtrToInt(pItem));
  1188. if (pItem->GetVKey() == uVKey)
  1189. {
  1190. SetSelectedItem(pItem);
  1191. goto DoReturn;
  1192. }
  1193. }
  1194. }
  1195. break;
  1196. }
  1197. }
  1198. /*------------------------------------------------------------------------------
  1199. OnKeyUp
  1200. ------------------------------------------------------------------------------*/
  1201. void CUIFMenu::OnKeyUp(HWND hwnd, WPARAM wParam, LPARAM lParam)
  1202. {
  1203. }
  1204. /*------------------------------------------------------------------------------
  1205. GetNextItem
  1206. ------------------------------------------------------------------------------*/
  1207. CUIFMenuItem *CUIFMenu::GetNextItem(CUIFMenuItem *pItem)
  1208. {
  1209. int nCnt = _rgItems.GetCount();
  1210. CUIFMenuItem *pItemTmp;
  1211. int i;
  1212. if (!nCnt)
  1213. return NULL;
  1214. if (!_pSelectedItem)
  1215. return _rgItems.Get(0);
  1216. for (i = 0; i < nCnt; i++)
  1217. {
  1218. pItemTmp = _rgItems.Get(i);
  1219. Assert(PtrToInt(pItemTmp));
  1220. if (pItem == pItemTmp)
  1221. {
  1222. i++;
  1223. break;
  1224. }
  1225. }
  1226. if (i == nCnt)
  1227. i = 0;
  1228. pItemTmp = _rgItems.Get(i);
  1229. while (pItemTmp && pItemTmp->IsNonSelectedItem())
  1230. {
  1231. i++;
  1232. if (i == nCnt)
  1233. i = 0;
  1234. pItemTmp = _rgItems.Get(i);
  1235. }
  1236. return pItemTmp;
  1237. }
  1238. /*------------------------------------------------------------------------------
  1239. GetPrevItem
  1240. ------------------------------------------------------------------------------*/
  1241. CUIFMenuItem *CUIFMenu::GetPrevItem(CUIFMenuItem *pItem)
  1242. {
  1243. int nCnt = _rgItems.GetCount();
  1244. CUIFMenuItem *pItemTmp = NULL;
  1245. int i;
  1246. if (!nCnt)
  1247. return NULL;
  1248. if (!_pSelectedItem)
  1249. return _rgItems.Get(nCnt - 1);
  1250. for (i = nCnt - 1; i >= 0; i--)
  1251. {
  1252. pItemTmp = _rgItems.Get(i);
  1253. Assert(PtrToInt(pItemTmp));
  1254. if (pItem == pItemTmp)
  1255. {
  1256. i--;
  1257. break;
  1258. }
  1259. }
  1260. if (i < 0)
  1261. i = nCnt - 1;
  1262. pItemTmp = _rgItems.Get(i);
  1263. while (pItemTmp && pItemTmp->IsNonSelectedItem())
  1264. {
  1265. i--;
  1266. if (i < 0)
  1267. i = nCnt - 1;
  1268. pItemTmp = _rgItems.Get(i);
  1269. }
  1270. return pItemTmp;
  1271. }
  1272. /*------------------------------------------------------------------------------
  1273. SetMenuFont
  1274. ------------------------------------------------------------------------------*/
  1275. void CUIFMenu::SetMenuFont()
  1276. {
  1277. NONCLIENTMETRICS ncm;
  1278. int nMarlettFontSize = 14;
  1279. ncm.cbSize = sizeof(ncm);
  1280. if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, FALSE))
  1281. {
  1282. HFONT hFont = CreateFontIndirect(&ncm.lfMenuFont);
  1283. SetFont(hFont);
  1284. nMarlettFontSize = (ncm.lfMenuFont.lfHeight > 0) ?
  1285. ncm.lfMenuFont.lfHeight :
  1286. -ncm.lfMenuFont.lfHeight;
  1287. nMarlettFontSize = (ncm.iMenuHeight + nMarlettFontSize) / 2;
  1288. }
  1289. _hfontMarlett = CreateFont(nMarlettFontSize, 0, 0, 0, 400, FALSE, FALSE, FALSE, SYMBOL_CHARSET, 0, 0, 0, 0, "Marlett");
  1290. _cxMenuCheck = nMarlettFontSize;
  1291. int cxSmIcon = GetSystemMetrics( SM_CXSMICON );
  1292. if (_cxMenuCheck < cxSmIcon)
  1293. _cxMenuCheck = cxSmIcon;
  1294. _cxMenuCheck += 2;
  1295. }
  1296. /*------------------------------------------------------------------------------
  1297. ClearMenuFont
  1298. ------------------------------------------------------------------------------*/
  1299. void CUIFMenu::ClearMenuFont()
  1300. {
  1301. HFONT hFont = GetFont();
  1302. SetFont(NULL);
  1303. DeleteObject(hFont);
  1304. }