EGOutlookCtrl.cpp
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 32k
Category:

Graph program

Development Platform:

Visual C++

  1. // Outlook2Ctrl.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "EGButtonsBar.h"
  5. #include "EGMenu.h"
  6. // CEGButtonsBar
  7. void CEGButtonsBar::DrawGradientRect(CDC * pDC, CRect &rect, COLORREF cr1, COLORREF cr2, DWORD dwStyle)
  8. {
  9. #if(WINVER >= 0x0500)
  10. TRIVERTEX        vert[2] ;
  11. GRADIENT_RECT    gRect;
  12. vert [0] .x      = rect.left;
  13. vert [0] .y      = rect.top;
  14. vert [0] .Red    = GetRValue(cr1)*0xFF00/255;
  15. vert [0] .Green  = GetGValue(cr1)*0xFF00/255;
  16. vert [0] .Blue   = GetBValue(cr1)*0xFF00/255;
  17. vert [0] .Alpha  = 0;
  18. vert [1] .x      = rect.right;
  19. vert [1] .y      = rect.bottom; 
  20. vert [1] .Red    = GetRValue(cr2)*0xFF00/255;
  21. vert [1] .Green  = GetGValue(cr2)*0xFF00/255;
  22. vert [1] .Blue   = GetBValue(cr2)*0xFF00/255;
  23. vert [1] .Alpha  = 0x0000;
  24. gRect.UpperLeft  = 0;
  25. gRect.LowerRight = 1;
  26. GradientFill(pDC->GetSafeHdc(),vert,2,&gRect,1,dwStyle);
  27. #else
  28. pDC->FillSolidRect(rect, cr1);
  29. #endif
  30. }
  31. IMPLEMENT_DYNAMIC( CEGButtonsBar, CControlBar )
  32. CEGButtonsBar::CEGButtonsBar()
  33. {
  34. m_iSize = 200;//AfxGetApp()->GetProfileInt("Settings","OutbarSize",200);
  35. m_iDragging = 0;
  36. m_iDragoffset = 0;
  37. hDragCur = AfxGetApp()->LoadCursor(AFX_IDC_HSPLITBAR); // sometime fails .. 
  38. if (!hDragCur) hDragCur = AfxGetApp()->LoadStandardCursor(MAKEINTRESOURCE(IDC_SIZEWE)); 
  39. #if(WINVER >= 0x0500)
  40. hHandCur = LoadCursor(NULL, IDC_HAND);
  41. #else
  42. hHandCur = LoadCursor(NULL, IDC_ARROW);
  43. #endif
  44. LOGFONT lf;
  45. HFONT hf = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
  46. CFont * gf = CFont::FromHandle(hf);
  47. gf->GetLogFont(&lf);
  48. lf.lfUnderline = TRUE;
  49. ftHotItems.CreateFontIndirect(&lf);
  50. lf.lfUnderline = FALSE;
  51. ftItems.CreateFontIndirect(&lf);
  52. lf.lfWeight = FW_SEMIBOLD;
  53. ftFolders.CreateFontIndirect(&lf);
  54. lf.lfHeight = 20;
  55. ftCaption.CreateFontIndirect(&lf);
  56. m_csCaption = "";
  57.  
  58. SetupColors();
  59. m_iNumFoldersDisplayed = -1;
  60. m_iFolderHeight = 24;
  61. m_iItemHeight = 18;
  62. m_iSelectedFolder = 0;
  63. m_iSubItemHeight = 17;
  64. iHiFolder = iHiLink = -1;
  65. pLastHilink = NULL;
  66. }
  67. CEGButtonsBar::~CEGButtonsBar()
  68. {
  69. for (int t = 0; t < m_Folders.GetSize(); t++)
  70. {
  71. CEGButtonsFolder * p = (CEGButtonsFolder *) m_Folders.GetAt(t);
  72. delete p;
  73. }
  74. m_Folders.RemoveAll();
  75. //AfxGetApp()->WriteProfileInt("Settings","OutbarSize",m_iSize);
  76. }
  77. void CEGButtonsBar::SetupColors()
  78. {
  79. /*
  80. // classical 
  81. m_crBackCaption = GetSysColor(COLOR_BTNSHADOW);
  82. m_crTextCaption = GetSysColor(COLOR_WINDOW);
  83. m_crCmdOther = GetSysColor(COLOR_WINDOW);
  84. m_crDisabled = GetSysColor(COLOR_GRAYTEXT);
  85. // m_crBackground = GetSysColor(COLOR_BTNSHADOW);
  86. m_crBackground = GetSysColor(COLOR_BTNSHADOW);
  87. m_crCmdLink = GetSysColor(COLOR_CAPTIONTEXT);
  88. */
  89. // modern
  90. m_crBackCaption = GetSysColor(COLOR_BTNSHADOW);
  91. m_crTextCaption = GetSysColor(COLOR_WINDOW);
  92. m_crCmdOther = GetSysColor(COLOR_BTNTEXT);
  93. m_crDisabled = GetSysColor(COLOR_GRAYTEXT);
  94. m_crBackground = GetSysColor(COLOR_WINDOW);
  95. #if(WINVER >= 0x0500)
  96. m_crCmdLink = GetSysColor(COLOR_HOTLIGHT);
  97. #else
  98. m_crCmdLink = GetSysColor(COLOR_BTNHIGHLIGHT);
  99. #endif /* WINVER >= 0x0400 */
  100. }
  101. BEGIN_MESSAGE_MAP(CEGButtonsBar, CControlBar)
  102. ON_WM_PAINT()
  103. ON_WM_ERASEBKGND()
  104. ON_WM_CREATE()
  105. ON_WM_LBUTTONDOWN()
  106. ON_WM_LBUTTONUP()
  107. ON_WM_MOUSEMOVE()
  108. ON_WM_SETCURSOR()
  109. ON_WM_SIZE()
  110. ON_MESSAGE( WM_MOUSELEAVE, OnMouseLeave )
  111. END_MESSAGE_MAP()
  112. // CEGButtonsBar message handlers
  113. bool CEGButtonsBar::Create(CWnd * pParent, int iId)
  114. {
  115. if (CControlBar::Create(NULL, "", WS_VISIBLE|WS_CHILD, CRect(0,0,0,0), pParent, iId))
  116. {
  117. SetOwner(pParent);
  118. return true;
  119. }
  120. return false;
  121. }
  122. void CEGButtonsBar::OnPaint()
  123. {
  124. ClearRects();
  125. CPaintDC pdc(this);
  126. CRect rc;
  127. GetClientRect(rc);
  128. if (m_iSize <= 4)
  129. {
  130. pdc.FillSolidRect(rc, GetSysColor(COLOR_3DFACE));
  131. return;
  132. }
  133. COMemDC dc(&pdc);
  134. DrawCaption(&dc, rc);
  135. CRect rcBdr(rc);
  136. rc.InflateRect(-1,-1);
  137. DrawButtons(&dc, rc);
  138. rcInnerRect = rc;
  139. dc.FillSolidRect(rc, m_crBackground);
  140. if (m_iSelectedFolder >= 0 && m_iSelectedFolder < m_Folders.GetSize())
  141. {
  142. CEGButtonsFolder * o = (CEGButtonsFolder *) m_Folders.GetAt(m_iSelectedFolder);
  143. DrawItems(&dc, o, rc);
  144. }
  145. switch (CEGMenu::GetMenuDrawMode())
  146. {
  147. case CEGMenu::STYLE_XP:
  148. case CEGMenu::STYLE_XP_NOBORDER:
  149. case CEGMenu::STYLE_XP_2003_NOBORDER:
  150. case CEGMenu::STYLE_XP_2003:
  151. case CEGMenu::STYLE_COLORFUL_NOBORDER:
  152. case CEGMenu::STYLE_COLORFUL:
  153. case CEGMenu::STYLE_ICY_NOBORDER:
  154. case CEGMenu::STYLE_ICY:
  155. dc.Draw3dRect(rcBdr, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DSHADOW));
  156. break;
  157. default: // NATIVE THEME
  158. dc.DrawEdge( &rcBdr, EDGE_SUNKEN, BF_ADJUST | BF_RECT );
  159. //dc.Draw3dRect(rcBdr, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DSHADOW));
  160. break;
  161. }
  162. }
  163. void CEGButtonsBar::AnimateToFolder(int f)
  164. {
  165. m_iSelectedFolder = f;
  166.   pLastHilink = NULL;
  167. m_csCaption = GetFolder(f)->csName;
  168. if (m_iSize > 4)
  169. {
  170. CRect rc;
  171. GetClientRect(rc);
  172. CDC dc;
  173. CClientDC cdc(this);
  174. dc.CreateCompatibleDC(&cdc);
  175. CBitmap bmp;
  176. bmp.CreateCompatibleBitmap(&cdc, rc.Width(), rc.Height());
  177. CBitmap * ob = (CBitmap *) dc.SelectObject(&bmp);
  178. DrawCaption(&dc, rc);
  179. CRect rcBdr(rc);
  180. rc.InflateRect(-1,-1);
  181. DrawButtons(&dc, rc);
  182. int iBottomInner = rc.bottom;
  183. dc.Draw3dRect(rcBdr, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
  184. rcInnerRect = rc;
  185. dc.FillSolidRect(rc, m_crBackground);
  186. if (m_iSelectedFolder >= 0 && m_iSelectedFolder < m_Folders.GetSize())
  187. {
  188. CEGButtonsFolder * o = (CEGButtonsFolder *) m_Folders.GetAt(m_iSelectedFolder);
  189. DrawItems(&dc, o, rc);
  190. }
  191. for (int t = iBottomInner - 10; t > 0; t -= (iBottomInner/8))
  192. {
  193. cdc.BitBlt(0,t,rc.Width(), iBottomInner - t, &dc, 0,0, SRCCOPY);
  194. Sleep(30);
  195. }
  196. dc.SelectObject(ob);
  197. }
  198. Invalidate();
  199. }
  200. BOOL CEGButtonsBar::OnEraseBkgnd(CDC* pDC)
  201. {
  202. return CControlBar::OnEraseBkgnd(pDC);
  203. }
  204. int CEGButtonsBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
  205. {
  206. if (CControlBar::OnCreate(lpCreateStruct) == -1) 
  207. return -1;
  208. SetBarStyle (CBRS_LEFT|CBRS_HIDE_INPLACE & ~(CBRS_BORDER_ANY | CBRS_GRIPPER));
  209. m_bIsMouseInside = FALSE;
  210. return 0;
  211. }
  212. CSize CEGButtonsBar::CalcFixedLayout (BOOL /*bStretch*/, BOOL /* bHorz */)
  213. {
  214. CSize size = CSize (m_iSize, 32767);
  215. return size;
  216. }
  217. void CEGButtonsBar::SetCurFolder(int f, bool bAnimation, BOOL bNotify)
  218. {
  219. // hide all subwindows
  220. if (m_iSelectedFolder >= 0 && m_iSelectedFolder != f)
  221. {
  222. for (int f = 0; f < m_Folders.GetSize(); f++)
  223. {
  224. CEGButtonsFolder * pf = (CEGButtonsFolder *) m_Folders.GetAt(f);
  225. for (int i = 0; i < pf->m_Items.GetSize(); i++)
  226. {
  227. CEGButtonsItem * pi = (CEGButtonsItem *) pf->m_Items.GetAt(i);
  228. for (int s = 0; s < pi->m_SubItems.GetSize(); s++)
  229. {
  230. CEGButtonsSubItem * ps = (CEGButtonsSubItem *) pi->m_SubItems.GetAt(s);
  231. if (ps->hHostedWnd) ::ShowWindow(ps->hHostedWnd, SW_HIDE);
  232. ps->rcItem.SetRectEmpty();
  233. }
  234. }
  235. }
  236. }
  237. if (m_iSelectedFolder != f)
  238. {
  239. if (bAnimation) AnimateToFolder(f);
  240. else
  241. {
  242. m_iSelectedFolder = f;
  243.   pLastHilink = NULL;
  244. m_csCaption = GetFolder(f)->csName;
  245. }
  246. Invalidate();
  247. if ( bNotify ) {
  248. UINT nCmd = GetFolder(f)->nCommandID;
  249. if ( nCmd > 0 )
  250. AfxGetMainWnd()->SendMessage( WM_COMMAND, MAKEWPARAM( nCmd, 0 ), 0 );
  251. }
  252. }
  253. }
  254. void CEGButtonsBar::OnLButtonDown(UINT nFlags, CPoint point)
  255. {
  256. if (m_iSize <= 4 || m_dragRect.PtInRect(point))
  257. {
  258. m_iDragoffset = m_iSize - point.x;
  259. m_iDragging = 1;
  260. SetCursor(hDragCur);
  261. SetCapture();
  262. SetFocus();
  263. CRect rc;
  264. GetClientRect(rc);
  265. OnInvertTracker(m_dragRect);
  266. return;
  267. }
  268. int f,i,s;
  269. int r = HitTest(f,i,s,point);
  270. if (r == 1)
  271. {
  272. SetCurFolder(f, true, TRUE );
  273. }
  274. if (r == 4)
  275. {
  276. CEGButtonsSubItem * ps = GetSubItem(f,i,s);
  277. if (ps->dwStyle == 2 || ps->dwStyle == 3) // item is hotlinked or checkbox
  278. {
  279. AfxGetMainWnd()->SendMessage(WM_COMMAND, MAKELONG(ps->lParam, 0), (LPARAM) GetSafeHwnd());
  280. InvalidateRect(rcInnerRect, FALSE);
  281. }
  282. if (ps->dwStyle == 0 || ps->dwStyle == 1) // item is radio or singlelist .. check before sending
  283. {
  284. CEGButtonsCCmdUI pui;
  285. pui.pSI = ps;
  286. pui.m_nID = ps->lParam; 
  287. AfxGetMainWnd()->OnCmdMsg(pui.m_nID, CN_UPDATE_COMMAND_UI, &pui, NULL);
  288. if (!(pui.iRes & 2)) // not checked yet .. so let's do it
  289. AfxGetMainWnd()->SendMessage(WM_COMMAND, MAKELONG(ps->lParam, 0), (LPARAM) GetSafeHwnd());
  290. InvalidateRect(rcInnerRect, FALSE);
  291. }
  292. }
  293. CControlBar::OnLButtonDown(nFlags, point);
  294. }
  295. void CEGButtonsBar::OnLButtonUp(UINT nFlags, CPoint point)
  296. {
  297. if (m_iDragging)
  298. {
  299. ReleaseCapture();
  300. OnInvertTracker(m_dragRect);
  301. m_iSize = point.x + m_iDragoffset;
  302. if (m_iSize < 4) m_iSize = 4;
  303. CFrameWnd* pParentFrame = GetParentFrame ();
  304. pParentFrame->RecalcLayout ();
  305. }
  306. m_iDragging = 0;
  307. CControlBar::OnLButtonUp(nFlags, point);
  308. }
  309. void CEGButtonsBar::OnMouseMove(UINT nFlags, CPoint point)
  310. {
  311. if ( !m_bIsMouseInside ) {
  312. m_bIsMouseInside = TRUE;
  313. TRACKMOUSEEVENT tme;
  314. memset( (LPVOID)&tme, 0, sizeof( TRACKMOUSEEVENT ) );
  315. tme.cbSize = sizeof( TRACKMOUSEEVENT );
  316. tme.hwndTrack = m_hWnd;
  317. tme.dwFlags = TME_LEAVE;
  318. TrackMouseEvent( &tme ); 
  319. }
  320. if (m_iDragging == 1)
  321. {
  322. CRect rc1(m_dragRect);
  323. m_dragRect.SetRect(point.x-5 + m_iDragoffset, rc1.top, point.x + m_iDragoffset, rc1.bottom);
  324. if (rc1 != m_dragRect)
  325. {
  326. OnInvertTracker(rc1);
  327. OnInvertTracker(m_dragRect);
  328. }
  329. }
  330. else
  331. {
  332. int f,i,s;
  333. int r = HitTest(f,i,s,point);
  334. if (r == 1)
  335. {
  336. CClientDC dc(this); 
  337. if (iHiFolder >= 0 && iHiFolder != f)
  338. {
  339. DrawButton(&dc, (CEGButtonsFolder *) m_Folders.GetAt(iHiFolder), iHiFolder == m_iSelectedFolder, false);
  340. }
  341. if (iHiFolder != f)
  342. {
  343. iHiFolder = f;
  344. DrawButton(&dc, (CEGButtonsFolder *) m_Folders.GetAt(iHiFolder), iHiFolder == m_iSelectedFolder, true);
  345. }
  346. }
  347. if (r == 4)
  348. {
  349. CEGButtonsSubItem * ps = GetSubItem(f,i,s);
  350. CClientDC dc(this); 
  351. if (pLastHilink && pLastHilink != ps)
  352. {
  353. DrawSubItem(&dc, GetFolder(iHilinkFolder), GetItem(iHilinkFolder, iHilinkItem), pLastHilink, false);
  354. }
  355. if (pLastHilink != ps)
  356. {
  357. pLastHilink = ps;
  358. DrawSubItem(&dc, GetFolder(f), GetItem(f,i), ps, true);
  359. iHilinkFolder = f;
  360. iHilinkItem = i;
  361. }
  362. }
  363. if (r == 0)
  364. {
  365. if (iHiFolder >= 0)
  366. {
  367. CClientDC dc(this); 
  368. DrawButton(&dc, (CEGButtonsFolder *) m_Folders.GetAt(iHiFolder), iHiFolder == m_iSelectedFolder, false);
  369. iHiFolder = -1;
  370. }
  371. if (pLastHilink != NULL)
  372. {
  373. CClientDC dc(this); 
  374. DrawSubItem(&dc, GetFolder(iHilinkFolder), GetItem(iHilinkFolder, iHilinkItem), pLastHilink, false);
  375. pLastHilink = NULL;
  376. }
  377. }
  378. }
  379. CControlBar::OnMouseMove(nFlags, point);
  380. }
  381. BOOL CEGButtonsBar::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  382. {
  383. if (nHitTest == HTCLIENT)
  384. {
  385. CPoint point;
  386. ::GetCursorPos (&point);
  387. ScreenToClient (&point);
  388. if (m_iDragging || m_dragRect.PtInRect(point)) 
  389. {
  390. SetCursor(hDragCur);
  391. return TRUE;
  392. }
  393. int f,i,s;
  394. int r = HitTest(f,i,s,point);
  395. if (r == 4)
  396. {
  397. CEGButtonsSubItem * ps = GetSubItem(f,i,s);
  398. if (ps->dwStyle == 2) // item is hotlinked
  399. {
  400. SetCursor(hHandCur);
  401. return TRUE;
  402. }
  403. }
  404. if (r == 1)
  405. {
  406. SetCursor(hHandCur);
  407. return TRUE;
  408. }
  409. }
  410. return CControlBar::OnSetCursor(pWnd, nHitTest, message);
  411. }
  412. void CEGButtonsBar::OnInvertTracker(const CRect& rc)
  413. {
  414. CFrameWnd* pParentFrame = GetParentFrame ();
  415. CDC* pDC = pParentFrame->GetDC();
  416. CRect rect(rc);
  417.     ClientToScreen(rect);
  418. pParentFrame->ScreenToClient(rect);
  419. CBrush br;
  420. br.CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
  421. HBRUSH hOldBrush = NULL;
  422. hOldBrush = (HBRUSH)SelectObject(pDC->m_hDC, br.m_hObject);
  423. pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), DSTINVERT);
  424. if (hOldBrush != NULL) SelectObject(pDC->m_hDC, hOldBrush);
  425. ReleaseDC(pDC);
  426. }
  427. void CEGButtonsBar::DrawCaption(CDC * pDC, CRect & rect)
  428. {
  429. CRect rc(rect);
  430. rect.top += 25;
  431. rc.bottom = rc.top + 25;
  432. pDC->FillSolidRect(rc, GetSysColor(COLOR_3DFACE));
  433. // rc.InflateRect(0,-2);
  434. // rc.bottom -=2;
  435. rc.top ++;
  436. pDC->FillSolidRect(rc, m_crBackCaption);
  437. pDC->SetTextColor(m_crTextCaption);
  438. pDC->SetBkMode(TRANSPARENT);
  439. CFont * of = (CFont *) pDC->SelectObject(&ftCaption);
  440. rc.left += 4;
  441.     pDC->DrawText(m_csCaption, rc, DT_SINGLELINE|DT_END_ELLIPSIS|DT_VCENTER);
  442. pDC->SelectObject(of);
  443. CRect rcSide(rect.right-4,rc.top,rect.right,rect.bottom);
  444. pDC->FillSolidRect(rcSide, GetSysColor(COLOR_3DFACE));
  445. rect.right -= 4;
  446. }
  447. CEGButtonsFolder::CEGButtonsFolder()
  448. {
  449. hIcon = NULL;
  450. dwStyle = 0;
  451. rcItem.SetRectEmpty();
  452. nCommandID = 0;
  453. }
  454. CEGButtonsFolder::~CEGButtonsFolder()
  455. {
  456. for (int t = 0; t < m_Items.GetSize(); t++)
  457. {
  458. CEGButtonsItem * p = (CEGButtonsItem *) m_Items.GetAt(t);
  459. delete p;
  460. }
  461. m_Items.RemoveAll();
  462. }
  463. CEGButtonsItem::CEGButtonsItem()
  464. {
  465. dwStyle = 0;
  466. rcItem.SetRectEmpty();
  467. }
  468. CEGButtonsItem::~CEGButtonsItem()
  469. {
  470. for (int t = 0; t < m_SubItems.GetSize(); t++)
  471. {
  472. CEGButtonsSubItem * p = (CEGButtonsSubItem *) m_SubItems.GetAt(t);
  473. delete p;
  474. }
  475. m_SubItems.RemoveAll();
  476. }
  477. CEGButtonsSubItem::CEGButtonsSubItem()
  478. {
  479. hIcon = NULL;
  480. hHostedWnd = NULL;
  481. dwStyle = 0;
  482. rcItem.SetRectEmpty();
  483. iLastStatus = 0;
  484. }
  485. CEGButtonsSubItem::~CEGButtonsSubItem()
  486. {
  487. }
  488. int CEGButtonsBar::AddFolderRes(const char * m_strName, UINT iIcoID, DWORD lParam, UINT nCmdID)
  489. {
  490. HICON hIco = (HICON) LoadImage(AfxGetInstanceHandle(),MAKEINTRESOURCE(iIcoID),IMAGE_ICON,16,16,0);
  491. return AddFolder(m_strName, hIco, lParam, nCmdID);
  492. }
  493. int CEGButtonsBar::AddSubItem(const char * m_strName, int iIcoID, DWORD dwStyle, DWORD lParam, int iFolder, int iFolderItem)
  494. {
  495. HICON hIco = (HICON) LoadImage(AfxGetInstanceHandle(),MAKEINTRESOURCE(iIcoID),IMAGE_ICON,16,16,0);
  496. return AddSubItem(m_strName, hIco, dwStyle, lParam, iFolder, iFolderItem);
  497. }
  498. int CEGButtonsBar::AddFolder(const char * m_strName, HICON hIcon, DWORD lParam, UINT nCmdID)
  499. {
  500. if (m_csCaption == "") m_csCaption = m_strName;
  501. CEGButtonsFolder * o = new CEGButtonsFolder;
  502. o->csName = m_strName;
  503. o->hIcon = hIcon;
  504. o->lParam = lParam;
  505. o->nCommandID = nCmdID;
  506. return (int) m_Folders.Add(o);
  507. }
  508. int CEGButtonsBar::AddFolderItem(const char * m_strItemName, DWORD dwStyle, int iFolder)
  509. {
  510. if (iFolder < 0) iFolder = (int) m_Folders.GetSize() - 1;
  511. CEGButtonsFolder * o = (CEGButtonsFolder *) m_Folders.GetAt(iFolder);
  512. CEGButtonsItem * i = new CEGButtonsItem;
  513. i->csName = m_strItemName;
  514. i->dwStyle = dwStyle;
  515. return (int) o->m_Items.Add(i);
  516. }
  517. /*
  518. bool CEGButtonsBar::RemoveFolder(int iFolder)
  519. {
  520. int sz = (int) m_Folders.GetSize();
  521. if ( iFolder < 0 || iFolder >= sz )
  522. return false;
  523. CEGButtonsFolder * o = (CEGButtonsFolder *) m_Folders.GetAt( iFolder );
  524. int sub_sz = (int) (o->m_Items.GetSize());
  525. for (int i=0; i<sub_sz; i++)
  526. {
  527. CEGButtonsItem * it = (CEGButtonsItem *)(o->m_Items.GetAt(i));
  528. int sub_sub_sz = (int)(it->m_SubItems.GetSize());
  529. for (int j=0;j<sub_sub_sz;j++)
  530. delete it->m_SubItems.GetAt(j);
  531. it->m_SubItems.RemoveAll();
  532. delete it;
  533. }
  534. o->m_Items.RemoveAll();
  535. delete o;
  536. m_Folders.RemoveAt(iFolder);
  537. return true;
  538. }*/
  539. bool CEGButtonsBar::RemoveFolder(int ind)
  540. {
  541. int sz = (int) m_Folders.GetSize();
  542. if (ind<0 || ind>=sz)
  543. return false;
  544. CEGButtonsFolder * o = (CEGButtonsFolder *) m_Folders.GetAt(ind);
  545. int sub_sz = (int) (o->m_Items.GetSize());
  546. for (int i=0;i<sub_sz;i++)
  547. {
  548. CEGButtonsItem * it = (CEGButtonsItem *)(o->m_Items.GetAt(i));
  549. int sub_sub_sz = (int)(it->m_SubItems.GetSize());
  550. for (int j=0;j<sub_sub_sz;j++)
  551. {
  552. CEGButtonsSubItem * sI = (CEGButtonsSubItem*)(it->m_SubItems.GetAt(i));
  553. if (sI->dwStyle==OCL_HWND && ::IsWindow(sI->hHostedWnd))
  554. ::ShowWindow(sI->hHostedWnd,SW_HIDE);
  555. delete it->m_SubItems.GetAt(j);
  556. }
  557. it->m_SubItems.RemoveAll();
  558. delete it;
  559. }
  560. o->m_Items.RemoveAll();
  561. delete o;
  562. m_Folders.RemoveAt(ind);
  563. if (m_iSelectedFolder==ind)
  564. SetCurFolder((ind>1)?(ind-1):0, false, TRUE );
  565. else
  566. Invalidate();
  567. return true;
  568. }
  569. int CEGButtonsBar::AddSubItem(const char * m_strName, HICON hIcon, DWORD dwStyle, DWORD lParam, int iFolder, int iFolderItem)
  570. {
  571. if (iFolder < 0) iFolder = (int) m_Folders.GetSize() - 1;
  572. CEGButtonsFolder * o = (CEGButtonsFolder *) m_Folders.GetAt(iFolder);
  573. if (iFolderItem < 0) iFolderItem = (int) o->m_Items.GetSize() - 1;
  574. CEGButtonsItem  * i = (CEGButtonsItem *) o->m_Items.GetAt(iFolderItem);
  575. CEGButtonsSubItem * s = new CEGButtonsSubItem;
  576. s->csName = m_strName;
  577. s->dwStyle = dwStyle;
  578. s->hIcon = hIcon;
  579. s->lParam = lParam;
  580. return (int) i->m_SubItems.Add(s);
  581. }
  582. int CEGButtonsBar::AddSubItem(HWND hHosted, bool bStretch, int iFolder, int iFolderItem)
  583. {
  584. ASSERT(hHosted);
  585. if (iFolder < 0) iFolder = (int) m_Folders.GetSize() - 1;
  586. CEGButtonsFolder * o = (CEGButtonsFolder *) m_Folders.GetAt(iFolder);
  587. if (iFolderItem < 0) iFolderItem = (int) o->m_Items.GetSize() - 1;
  588. CEGButtonsItem  * i = (CEGButtonsItem *) o->m_Items.GetAt(iFolderItem);
  589. CEGButtonsSubItem * s = new CEGButtonsSubItem;
  590. CRect rc;
  591. ::GetWindowRect(hHosted, rc);
  592. s->dwStyle = OCL_HWND;
  593. s->lParam = rc.Height();
  594. s->hHostedWnd = hHosted;
  595. if (bStretch) s->lParam = 0xFFFFFFFF;
  596. return (int) i->m_SubItems.Add(s);
  597. }
  598. void CEGButtonsBar::DrawButtons(CDC * pDC, CRect & rect)
  599. {
  600. if (rect.bottom - m_iFolderHeight < rect.top) return;
  601. int by = rect.bottom;
  602. CPoint pt;
  603. GetCursorPos(&pt);
  604. ScreenToClient(&pt);
  605. for (int t = (int) m_Folders.GetSize() - 1; t >= 0; t--)
  606. {
  607. CEGButtonsFolder * o = (CEGButtonsFolder *) m_Folders.GetAt(t);
  608. o->rcItem.SetRect(rect.left, by - m_iFolderHeight, rect.right, by);
  609. pDC->FillSolidRect(o->rcItem.left,o->rcItem.top-1,o->rcItem.Width(), o->rcItem.Height() + 1, m_crBackCaption);
  610. DrawButton(pDC, o, t == m_iSelectedFolder ? true : false, o->rcItem.PtInRect(pt) ? true : false);
  611. by -= (m_iFolderHeight + 1);
  612. rect.bottom -= (m_iFolderHeight + 1);
  613. if (rect.top >= rect.bottom - m_iFolderHeight) break;
  614. }
  615. }
  616. void CEGButtonsBar::DrawButton(CDC * pDC, CEGButtonsFolder * o, bool bSel, bool bOver)
  617. {
  618. pDC->SetTextColor(m_crCmdOther);
  619. pDC->SetBkMode(TRANSPARENT);
  620. CFont * of = (CFont *) pDC->SelectObject(&ftFolders);
  621. CRect rect(o->rcItem);
  622. switch (CEGMenu::GetMenuDrawMode())
  623. {
  624. case CEGMenu::STYLE_XP:
  625. case CEGMenu::STYLE_XP_NOBORDER:
  626. if ( bOver ) {
  627. pDC->FillSolidRect(rect, GetXpHighlightColor());
  628. } else  if (bSel)  {
  629. pDC->FillSolidRect(rect, LightenColor( 120, GetXpHighlightColor() ) );//COLOR_ACTIVECAPTION));
  630. } else {
  631. pDC->FillSolidRect(rect, MixedColor(CEGMenu::GetMenuBarColorXP(),GetSysColor(COLOR_WINDOW)) );
  632. }
  633. break;
  634. case CEGMenu::STYLE_XP_2003_NOBORDER:
  635. case CEGMenu::STYLE_XP_2003:
  636. case CEGMenu::STYLE_COLORFUL_NOBORDER:
  637. case CEGMenu::STYLE_COLORFUL:
  638. if ( bOver ) {
  639. COLORREF cr1 = GetXpHighlightColor();
  640. COLORREF cr2 = cr1;
  641. DrawGradientRect(pDC, rect, cr1, cr2);
  642. } else  if (bSel)  {
  643. COLORREF cr1 = LightenColor( 120, GetXpHighlightColor() );
  644. COLORREF cr2 = cr1;
  645. DrawGradientRect(pDC, rect, cr1, cr2);
  646. } else {
  647. COLORREF cr1 = GetSysColor(COLOR_WINDOW);
  648. COLORREF cr2 = GetSysColor(COLOR_BTNFACE);
  649. DrawGradientRect(pDC, rect, cr1, cr2);
  650. }
  651. break;
  652. case CEGMenu::STYLE_ICY_NOBORDER:
  653. case CEGMenu::STYLE_ICY:
  654. if ( bOver ) {
  655. COLORREF cr1 =  DarkenColor(60, GetSysColor(COLOR_HIGHLIGHT) );//GetXpHighlightColor();
  656. COLORREF cr2 = LightenColor(60, GetSysColor(COLOR_HIGHLIGHT) );
  657. DrawGradientRect(pDC, rect, cr2, cr1 );
  658. } else  if ( bSel )  {
  659. COLORREF cr1 =  LightenColor(80, GetSysColor(COLOR_HIGHLIGHT) );
  660. pDC->FillSolidRect( &rect, cr1 );
  661. } else {
  662. COLORREF cr1 = LightenColor( 60, CEGMenu::GetMenuColor() );
  663. COLORREF cr2 = GetSysColor(COLOR_BTNFACE);
  664. COLORREF cr3 = DarkenColor( 60, CEGMenu::GetMenuColor() );
  665. CRect rc = rect;
  666. rc.bottom /= 2;
  667. DrawGradientRect(pDC, rect, cr1, cr2);
  668. rc.top = rc.bottom + 1;
  669. rc.bottom = rect.bottom;
  670. DrawGradientRect(pDC, rect, cr2, cr3);
  671. }
  672. break;
  673. default: // NATIVE THEME
  674. InflateRect( &rect, -1, 0 );
  675. if ( o == m_Folders.GetAt( 0 ) )
  676. rect.top--;
  677. if ( o == m_Folders.GetAt( m_Folders.GetCount()-1 ) )
  678. rect.bottom--;
  679. if ( bSel )  {
  680. //pDC->FillSolidRect(rect, GetSysColor(COLOR_BTNFACE));
  681. /* CBrush br;
  682. br.CreateSolidBrush( GetSysColor(COLOR_BTNFACE) );
  683. CPen pn;
  684. pn.CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ) );
  685. CPen * pOldPen = pDC->SelectObject( &pn );
  686. CBrush* pOldBrush = pDC->
  687. */
  688. pDC->Draw3dRect( &rect, GetSysColor( COLOR_3DSHADOW ) , GetSysColor( COLOR_WINDOW ) );
  689. InflateRect( &rect, -1, -1 );
  690. pDC->FillSolidRect( &rect, GetSysColor(COLOR_BTNFACE));
  691. } else {
  692. pDC->DrawFrameControl( &rect, DFC_BUTTON, DFCS_BUTTONPUSH );
  693. }
  694. break;
  695. }
  696. if (o->hIcon && rect.left+20 < rect.right) 
  697. DrawIconEx(pDC->GetSafeHdc(), rect.left+rect.Height()/2-8, rect.top+rect.Height()/2-8, o->hIcon,16,16,0,NULL, DI_NORMAL);
  698. if ( ( CEGMenu::GetMenuDrawMode() == CEGMenu::STYLE_ICY_NOBORDER ||
  699. CEGMenu::GetMenuDrawMode() == CEGMenu::STYLE_ICY ) && ( bSel || bOver ) ) {
  700. pDC->SetTextColor(GetSysColor(COLOR_WINDOW));
  701. } else {
  702. pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT));
  703. }
  704. CRect rc1(rect);
  705. rc1.left += 24;
  706. pDC->DrawText(o->csName, rc1, DT_SINGLELINE|DT_END_ELLIPSIS|DT_VCENTER);
  707. pDC->SelectObject(of);
  708. }
  709. void CEGButtonsBar::DrawItems(CDC * pDC, CEGButtonsFolder * oFolder, CRect & rect)
  710. {
  711. if (rect.bottom - m_iItemHeight < rect.top) return;
  712. CFont * of = (CFont *) pDC->SelectObject(&ftItems);
  713. for (int t = 0; t < oFolder->m_Items.GetSize(); t++)
  714. {
  715. if (t != 0) rect.top += 7;
  716. // if (t == 0) rect.top += 1;
  717. CEGButtonsItem * i = (CEGButtonsItem *) oFolder->m_Items.GetAt(t);
  718. if (i->csName != "") {
  719. // i->rcItem.SetRect(rect.left+1,rect.top, rect.right-1, rect.top + m_iItemHeight);
  720. i->rcItem.SetRect(rect.left,rect.top-1, rect.right, rect.top + m_iItemHeight -1 );
  721. rect.top += m_iItemHeight;
  722. } else {
  723. // i->rcItem.SetRect(rect.left+1,rect.top+1, rect.right-1, rect.top + 3);
  724. i->rcItem.SetRect(rect.left,rect.top, rect.right, rect.top + 3);
  725. rect.top += 8;
  726. }
  727. DrawItem(pDC, oFolder, i);
  728. DrawSubItems(pDC, oFolder, i, rect);
  729. if (rect.top >= rect.bottom - m_iItemHeight) break;
  730. }
  731. pDC->SelectObject(of);
  732. }
  733. void CEGButtonsBar::DrawItem(CDC * pDC, CEGButtonsFolder * o, CEGButtonsItem * i)
  734. {
  735. CRect rect(i->rcItem), rc;
  736. COLORREF cr1, cr2, cr3;
  737. switch (CEGMenu::GetMenuDrawMode())
  738. {
  739. case CEGMenu::STYLE_XP:
  740. case CEGMenu::STYLE_XP_NOBORDER:
  741. cr1 = MixedColor(CEGMenu::GetMenuBarColorXP(),GetSysColor(COLOR_WINDOW));
  742. cr2 = GetSysColor(COLOR_BTNFACE);
  743. cr3 = GetSysColor(COLOR_BTNSHADOW);
  744. if (i->csName != "") {
  745. rect.right ++;
  746. pDC->Draw3dRect( rect, cr2, cr3 );
  747. rect.right --;
  748. InflateRect( &rect, 0, -1 );
  749. }
  750. pDC->FillSolidRect( rect, cr1 );
  751. break;
  752. case CEGMenu::STYLE_XP_2003_NOBORDER:
  753. case CEGMenu::STYLE_XP_2003:
  754. case CEGMenu::STYLE_COLORFUL_NOBORDER:
  755. case CEGMenu::STYLE_COLORFUL:
  756. cr1 = GetSysColor(COLOR_WINDOW);
  757. cr2 = GetSysColor(COLOR_BTNFACE);
  758. cr3 = GetSysColor(COLOR_BTNSHADOW);
  759. if (i->csName != "") {
  760. rect.right ++;
  761. pDC->Draw3dRect( rect, cr2, cr3 );
  762. rect.right --;
  763. InflateRect( &rect, 0, -1 );
  764. }
  765. DrawGradientRect(pDC, rect, cr1, cr2);
  766. break;
  767. case CEGMenu::STYLE_ICY_NOBORDER:
  768. case CEGMenu::STYLE_ICY:
  769. cr1 = LightenColor( 60, CEGMenu::GetMenuColor() );
  770. cr2 = GetSysColor(COLOR_BTNFACE);
  771. cr3 = DarkenColor( 60, CEGMenu::GetMenuColor() );
  772. if (i->csName != "") {
  773. rect.right ++;
  774. pDC->Draw3dRect( rect, cr2, cr3 );
  775. rect.right --;
  776. InflateRect( &rect, 0, -1 );
  777. }
  778. rc = rect;
  779. rc.bottom /= 2;
  780. DrawGradientRect(pDC, rect, cr1, cr2);
  781. rc.top = rc.bottom + 1;
  782. rc.bottom = rect.bottom;
  783. DrawGradientRect(pDC, rect, cr2, cr3);
  784. break;
  785. default: // NATIVE THEME
  786. InflateRect( &rect, -1, 0 );
  787. if ( i == o->m_Items.GetAt( 0 ) )
  788. rect.top +=2;
  789. if ( i->csName != _T("") ) {
  790. pDC->DrawFrameControl( &rect, DFC_BUTTON, DFCS_BUTTONPUSH );
  791. } else {
  792. pDC->FillSolidRect(rect, GetSysColor(COLOR_BTNFACE));
  793. }
  794. break;
  795. }
  796. if (i->csName != "")
  797. {
  798. pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT));
  799. CRect rc1(rect);
  800. rc1.left += 4;
  801. pDC->DrawText(i->csName, rc1, DT_SINGLELINE|DT_END_ELLIPSIS|DT_VCENTER);
  802. }
  803. }
  804. void CEGButtonsBar::DrawSubItems(CDC * pDC, CEGButtonsFolder * oFolder, CEGButtonsItem * iItem, CRect & rect)
  805. {
  806. if (rect.bottom - m_iSubItemHeight < rect.top) return;
  807. CPoint pt;
  808. GetCursorPos(&pt);
  809. ScreenToClient(&pt);
  810. for (int t1 = 0; t1 < iItem->m_SubItems.GetSize(); t1++)
  811. {
  812. CEGButtonsSubItem * p = (CEGButtonsSubItem *) iItem->m_SubItems.GetAt(t1);
  813. if (p->hHostedWnd)
  814. {
  815. int dy;
  816. if (p->lParam == 0xFFFFFFFF) dy = rect.Height(); else dy = (int) p->lParam;
  817. p->rcItem.SetRect(rect.left,rect.top-1,rect.right,rect.top+dy);
  818. ::SetWindowPos(p->hHostedWnd, NULL,p->rcItem.left, p->rcItem.top, p->rcItem.Width(), p->rcItem.Height(), SWP_NOZORDER);
  819. if (!::IsWindowVisible(p->hHostedWnd)) ::ShowWindow(p->hHostedWnd, SW_SHOW);
  820. rect.top += dy;
  821. }
  822. else
  823. {
  824. p->rcItem.SetRect(rect.left+1,rect.top,rect.right-1,rect.top+m_iSubItemHeight);
  825. DrawSubItem(pDC, oFolder, iItem, p, p->rcItem.PtInRect(pt) ? true : false);
  826. rect.top += m_iSubItemHeight;
  827. }
  828. if (rect.top >= rect.bottom - m_iSubItemHeight) break;
  829. }
  830. }
  831. void CEGButtonsBar::DrawSubItem(CDC * pDC, CEGButtonsFolder * /* oFolder */, CEGButtonsItem * /* iItem */, CEGButtonsSubItem * pSubItem, bool bOver)
  832. {
  833. CRect rect(pSubItem->rcItem);
  834. CFont * of = (CFont *) pDC->SelectObject(&ftItems);
  835. pDC->SetBkColor(m_crBackground);
  836. //pDC->SetBkColor( GetSysColor( COLOR_WINDOW) );
  837. switch (pSubItem->dwStyle)
  838. {
  839. case 0:
  840. {
  841. pDC->SetTextColor(m_crCmdOther);
  842. if (bOver)
  843. {
  844. pDC->SelectObject(&ftHotItems);
  845. }
  846. if (pSubItem->hIcon && rect.left+25 < rect.right)
  847. {
  848. if (pSubItem->hIcon) {
  849. pDC->FillSolidRect( rect.left+8, rect.top+1, 16, 16, m_crBackground );
  850. DrawIconEx(pDC->GetSafeHdc(), rect.left+8, rect.top+1, pSubItem->hIcon,16,16,0,NULL, DI_NORMAL);
  851. }
  852. }
  853. rect.left += 28;
  854. if (pSubItem->lParam)
  855. {
  856. CEGButtonsCCmdUI pui;
  857. pui.pSI = pSubItem;
  858. pui.m_nID = pSubItem->lParam;
  859. GetOwner()->OnCmdMsg(pui.m_nID, CN_UPDATE_COMMAND_UI, &pui, NULL);
  860. if (pui.iRes&2) pDC->FillSolidRect(rect, GetSysColor(COLOR_3DFACE)); // checked
  861. pSubItem->iLastStatus = pui.iRes;
  862. }
  863. pDC->DrawText(pSubItem->csName, rect, DT_SINGLELINE|DT_END_ELLIPSIS|DT_VCENTER);
  864. }
  865. break;
  866. case 1:
  867. {
  868. pDC->SetTextColor(m_crCmdOther);
  869. DWORD dwHotStyle = 0;
  870. if (bOver) 
  871. {
  872. #if(WINVER >= 0x0500)
  873. dwHotStyle = DFCS_HOT;
  874. #endif
  875. pDC->SelectObject(&ftHotItems);
  876. }
  877. CRect rci(rect.left+8, rect.top+2, rect.left + 20, rect.top + 14);
  878. if (pSubItem->lParam)
  879. {
  880. CEGButtonsCCmdUI pui;
  881. pui.pSI = pSubItem;
  882. pui.m_nID = pSubItem->lParam; 
  883. GetOwner()->OnCmdMsg(pui.m_nID, CN_UPDATE_COMMAND_UI, &pui, NULL);
  884. if (!(pui.iRes&2)) pDC->DrawFrameControl(rci, DFC_BUTTON, DFCS_BUTTONRADIO|DFCS_FLAT|dwHotStyle);
  885. else pDC->DrawFrameControl(rci, DFC_BUTTON, DFCS_BUTTONRADIO|DFCS_FLAT|DFCS_CHECKED|dwHotStyle);
  886. pSubItem->iLastStatus = pui.iRes;
  887. }
  888. else pDC->DrawFrameControl(rci, DFC_BUTTON, DFCS_BUTTONRADIO|DFCS_FLAT|dwHotStyle);
  889. rect.left += 28;
  890. pDC->DrawText(pSubItem->csName, rect, DT_SINGLELINE|DT_END_ELLIPSIS|DT_VCENTER);
  891. }
  892. break;
  893. case 2:
  894. {
  895. pDC->SetTextColor(m_crCmdLink);
  896. if (pSubItem->hIcon && rect.left+25 < rect.right)
  897. if (pSubItem->hIcon) {
  898. pDC->FillSolidRect( rect.left+8, rect.top+1, 16, 16, m_crBackground );
  899. DrawIconEx(pDC->GetSafeHdc(), rect.left+8, rect.top+1, pSubItem->hIcon,16,16,0,NULL, DI_NORMAL);
  900. }
  901. rect.left += 28;
  902. if (bOver) 
  903. pDC->SelectObject(&ftHotItems);
  904. if (pSubItem->lParam)
  905. {
  906. CEGButtonsCCmdUI pui;
  907. pui.pSI = pSubItem;
  908. pui.m_nID = pSubItem->lParam;
  909. GetOwner()->OnCmdMsg(pui.m_nID, CN_UPDATE_COMMAND_UI, &pui, NULL);
  910. pSubItem->iLastStatus = pui.iRes;
  911. }
  912. pDC->DrawText(pSubItem->csName, rect, DT_SINGLELINE|DT_END_ELLIPSIS|DT_VCENTER);
  913. }
  914. break;
  915. case 3: // checkbox
  916. {
  917. pDC->SetTextColor(m_crCmdOther);
  918. DWORD dwHotStyle = 0;
  919. if (bOver) 
  920. {
  921. #if(WINVER >= 0x0500)
  922. dwHotStyle = DFCS_HOT;
  923. #endif
  924. pDC->SelectObject(&ftHotItems);
  925. }
  926. CRect rci(rect.left+8, rect.top+2, rect.left + 20, rect.top + 14);
  927. if (pSubItem->lParam)
  928. {
  929. CEGButtonsCCmdUI pui;
  930. pui.pSI = pSubItem;
  931. pui.m_nID = pSubItem->lParam; 
  932. GetOwner()->OnCmdMsg(pui.m_nID, CN_UPDATE_COMMAND_UI, &pui, NULL);
  933. if (!(pui.iRes&2)) pDC->DrawFrameControl(rci, DFC_BUTTON, DFCS_BUTTONCHECK|DFCS_FLAT|dwHotStyle);
  934. else pDC->DrawFrameControl(rci, DFC_BUTTON, DFCS_BUTTONCHECK|DFCS_FLAT|DFCS_CHECKED|dwHotStyle);
  935. pSubItem->iLastStatus = pui.iRes;
  936. }
  937. else pDC->DrawFrameControl(rci, DFC_BUTTON, DFCS_BUTTONCHECK|DFCS_FLAT|dwHotStyle);
  938. rect.left += 28;
  939. pDC->DrawText(pSubItem->csName, rect, DT_SINGLELINE|DT_END_ELLIPSIS|DT_VCENTER);
  940. }
  941. break;
  942. }
  943. pDC->SelectObject(of);
  944. }
  945. void CEGButtonsBar::OnSize(UINT nType, int cx, int cy)
  946. {
  947. CControlBar::OnSize(nType, cx, cy);
  948. m_dragRect.SetRect(cx-5, 0, cx, cy);
  949. }
  950. int CEGButtonsBar::HitTest(int & iFolder, int & iItem, int & iSubItem, CPoint point)
  951. {
  952. for (iFolder = 0; iFolder < m_Folders.GetSize(); iFolder++)
  953. {
  954. CEGButtonsFolder * pf = (CEGButtonsFolder *) m_Folders.GetAt(iFolder);
  955. if (pf->rcItem.PtInRect(point)) return 1;
  956. for (iItem = 0; iItem < pf->m_Items.GetSize(); iItem++)
  957. {
  958. CEGButtonsItem * pi = (CEGButtonsItem *) pf->m_Items.GetAt(iItem);
  959. if (pi->rcItem.PtInRect(point)) return 2;
  960. for (iSubItem = 0; iSubItem < pi->m_SubItems.GetSize(); iSubItem++)
  961. {
  962. CEGButtonsSubItem * ps = (CEGButtonsSubItem *) pi->m_SubItems.GetAt(iSubItem);
  963. if (ps->rcItem.PtInRect(point)) return 4;
  964. }
  965. }
  966. }
  967. return 0;
  968. }
  969. void CEGButtonsBar::ClearRects(void)
  970. {
  971. for (int f = 0; f < m_Folders.GetSize(); f++)
  972. {
  973. CEGButtonsFolder * pf = (CEGButtonsFolder *) m_Folders.GetAt(f);
  974. pf->rcItem.SetRectEmpty();
  975. for (int i = 0; i < pf->m_Items.GetSize(); i++)
  976. {
  977. CEGButtonsItem * pi = (CEGButtonsItem *) pf->m_Items.GetAt(i);
  978. pi->rcItem.SetRectEmpty();
  979. for (int s = 0; s < pi->m_SubItems.GetSize(); s++)
  980. {
  981. CEGButtonsSubItem * ps = (CEGButtonsSubItem *) pi->m_SubItems.GetAt(s);
  982. ps->rcItem.SetRectEmpty();
  983. }
  984. }
  985. }
  986. }
  987. CEGButtonsSubItem * CEGButtonsBar::GetSubItem(int f, int i, int s)
  988. {
  989. CEGButtonsItem   * pi = (CEGButtonsItem *)   GetFolder(f)->m_Items.GetAt(i);
  990.     CEGButtonsSubItem *ps = (CEGButtonsSubItem *) pi->m_SubItems.GetAt(s);
  991. return ps;
  992. }
  993. CEGButtonsFolder * CEGButtonsBar::GetFolder(int f)
  994. {
  995. return (CEGButtonsFolder *) m_Folders.GetAt(f);
  996. }
  997. CEGButtonsItem * CEGButtonsBar::GetItem(int f, int i)
  998. {
  999. return (CEGButtonsItem *) GetFolder(f)->m_Items.GetAt(i);
  1000. }
  1001. void CEGButtonsBar::OnUpdateCmdUI(CFrameWnd* /* pTarget */, BOOL /* bDisableIfNoHndler */)
  1002. {
  1003. if (m_iSelectedFolder < 0) return;
  1004. CEGButtonsFolder * oFolder = GetFolder(m_iSelectedFolder);
  1005. for (int i = 0; i < oFolder->m_Items.GetSize(); i++)
  1006. {
  1007. CEGButtonsItem * pi = (CEGButtonsItem *) oFolder->m_Items.GetAt(i);
  1008. for (int s = 0; s < pi->m_SubItems.GetSize(); s++)
  1009. {
  1010. CEGButtonsSubItem * ps = (CEGButtonsSubItem *) pi->m_SubItems.GetAt(s);
  1011. if (ps->dwStyle == OCL_SELECT || ps->dwStyle == OCL_RADIO || ps->dwStyle == OCL_CHECK)
  1012. {
  1013. CEGButtonsCCmdUI pui;
  1014. pui.pSI = ps;
  1015. pui.m_nID = ps->lParam; 
  1016. GetOwner()->OnCmdMsg(pui.m_nID, CN_UPDATE_COMMAND_UI, &pui, NULL);
  1017. if (pui.iRes != ps->iLastStatus && !ps->rcItem.IsRectEmpty())
  1018. {
  1019.                     InvalidateRect(ps->rcItem);
  1020. }
  1021. }
  1022. }
  1023. }
  1024. /* iLastStatus = pui.iRes;
  1025. TRACE1("%dn", (int) GetTickCount());
  1026. CToolBar b;
  1027. b.OnUpdateCmdUI(*/
  1028. }
  1029. LRESULT CEGButtonsBar::OnMouseLeave( WPARAM /*wParam*/, LPARAM /*lParam*/ ) {
  1030. // canceling hottrack mode
  1031. if ( m_iDragging == 0 && iHiFolder >= 0 ) {
  1032. CClientDC dc(this); 
  1033. DrawButton(&dc, (CEGButtonsFolder *) m_Folders.GetAt(iHiFolder), iHiFolder == m_iSelectedFolder, false);
  1034. iHiFolder = -1;
  1035. }
  1036. m_bIsMouseInside = FALSE;
  1037. return 0L;
  1038. }