XTPRibbonGroup.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:18k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // XTPRibbonGroup.cpp: implementation of the CXTPRibbonGroup class.
  2. //
  3. // This file is a part of the XTREME RIBBON MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "Common/XTPPropExchange.h"
  22. #include "Common/XTPImageManager.h"
  23. #include "CommandBars/XTPControl.h"
  24. #include "CommandBars/XTPControls.h"
  25. #include "CommandBars/XTPControlPopup.h"
  26. #include "CommandBars/XTPControlButton.h"
  27. #include "CommandBars/XTPPopupBar.h"
  28. #include "CommandBars/XTPToolBar.h"
  29. #include "CommandBars/XTPCommandBars.h"
  30. #include "XTPRibbonGroup.h"
  31. #include "XTPRibbonGroups.h"
  32. #include "XTPRibbonBar.h"
  33. #include "XTPRibbonTheme.h"
  34. #include "XTPRibbonQuickAccessControls.h"
  35. #ifdef _DEBUG
  36. #undef THIS_FILE
  37. static char THIS_FILE[]=__FILE__;
  38. #define new DEBUG_NEW
  39. #endif
  40. IMPLEMENT_SERIAL(CXTPRibbonGroup, CCmdTarget, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  41. //////////////////////////////////////////////////////////////////////////
  42. // CXTPRibbonGroupOption
  43. IMPLEMENT_XTP_CONTROL(CXTPRibbonGroupOption, CXTPControlButton)
  44. void CXTPRibbonGroupOption::Draw(CDC* pDC)
  45. {
  46. if (m_pRibbonGroup)
  47. {
  48. m_pRibbonGroup->GetRibbonBar()->GetRibbonPaintManager()->DrawControlGroupOption(pDC, this, TRUE);
  49. }
  50. else
  51. {
  52. CXTPControlButton::Draw(pDC);
  53. }
  54. }
  55. //////////////////////////////////////////////////////////////////////////
  56. // CXTPRibbonGroupControlPopup
  57. CXTPRibbonGroupControlPopup::CXTPRibbonGroupControlPopup(CXTPRibbonGroup* pGroup)
  58. {
  59. m_pRibbonGroup = pGroup;
  60. m_pPopupGroup = pGroup;
  61. SetFlags(xtpFlagManualUpdate);
  62. m_controlType = xtpControlButtonPopup;
  63. m_pCommandBar = CXTPPopupBar::CreatePopupBar(0);
  64. }
  65. CSize CXTPRibbonGroupControlPopup::GetSize (CDC* pDC)
  66. {
  67. return ((CXTPRibbonTheme*)GetParent()->GetPaintManager())->DrawControlGroupPopup(pDC, this, FALSE);
  68. }
  69. void CXTPRibbonGroupControlPopup::Draw(CDC* pDC)
  70. {
  71. ((CXTPRibbonTheme*)GetParent()->GetPaintManager())->DrawControlGroupPopup(pDC, this, TRUE);
  72. }
  73. BOOL CXTPRibbonGroupControlPopup::IsTransparent() const
  74. {
  75. return TRUE;
  76. }
  77. CXTPRibbonBar* CXTPRibbonGroupControlPopup::GetRibbonBar() const
  78. {
  79. ASSERT(m_pParent);
  80. if (!m_pParent)
  81. return NULL;
  82. if (DYNAMIC_DOWNCAST(CXTPRibbonBar, m_pParent))
  83. return (CXTPRibbonBar*)m_pParent;
  84. if (DYNAMIC_DOWNCAST(CXTPRibbonGroupPopupToolBar, m_pParent))
  85. return ((CXTPRibbonGroupPopupToolBar*)m_pParent)->m_pRibbonBar;
  86. if (DYNAMIC_DOWNCAST(CXTPRibbonTabPopupToolBar, m_pParent))
  87. return ((CXTPRibbonTabPopupToolBar*)m_pParent)->m_pRibbonBar;
  88. if (DYNAMIC_DOWNCAST(CXTPRibbonBarMorePopupToolBar, m_pParent))
  89. return ((CXTPRibbonBarMorePopupToolBar*)m_pParent)->m_pRibbonBar;
  90. ASSERT(FALSE);
  91. return NULL;
  92. }
  93. void CXTPRibbonGroupControlPopup::Copy(CXTPControl* pControl, BOOL bRecursive)
  94. {
  95. CXTPControlButton::Copy(pControl, bRecursive);
  96. if (m_pParent && pControl->GetParent() && GetRibbonBar() != ((CXTPRibbonGroupControlPopup*)pControl)->GetRibbonBar())
  97. {
  98. m_pPopupGroup = GetRibbonBar()->FindGroup(GetID());
  99. }
  100. else
  101. {
  102. m_pPopupGroup = ((CXTPRibbonGroupControlPopup*)pControl)->m_pPopupGroup;
  103. }
  104. }
  105. void CXTPRibbonGroupControlPopup::GenerateCommandBarList(DWORD& /*nID*/, CXTPCommandBarList* /*pCommandBarList*/, XTP_COMMANDBARS_PROPEXCHANGE_PARAM* /*pParam*/)
  106. {
  107. }
  108. void CXTPRibbonGroupControlPopup::OnLButtonUp(CPoint /*point*/)
  109. {
  110. }
  111. BOOL CXTPRibbonGroupControlPopup::IsVisible(DWORD dwSkipFlags /*= 0*/) const
  112. {
  113. return CXTPControlPopup::IsVisible(dwSkipFlags) &&
  114. (!m_pPopupGroup || m_pPopupGroup->m_bVisible);
  115. }
  116. IMPLEMENT_XTP_CONTROL(CXTPRibbonGroupControlPopup, CXTPControlPopup)
  117. BOOL CXTPRibbonGroupControlPopup::OnSetPopup(BOOL bPopup)
  118. {
  119. m_bPopup = bPopup;
  120. if (bPopup)
  121. {
  122. CMDTARGET_RELEASE(m_pCommandBar);
  123. CXTPCommandBars* pCommandBars = m_pParent->GetCommandBars();
  124. ASSERT(pCommandBars);
  125. if (!m_pPopupGroup)
  126. {
  127. m_pCommandBar = new CXTPPopupToolBar();
  128. m_pCommandBar->SetCommandBars(pCommandBars);
  129. m_pCommandBar->Popup(this, IsKeyboardSelected(GetSelected()));
  130. }
  131. else
  132. {
  133. m_pCommandBar = new CXTPRibbonGroupPopupToolBar(m_pPopupGroup);
  134. m_pCommandBar->SetCommandBars(pCommandBars);
  135. m_pCommandBar->EnableCustomization(FALSE);
  136. m_pCommandBar->Popup(this, IsKeyboardSelected(GetSelected()));
  137. }
  138. }
  139. else
  140. {
  141. ASSERT(m_pCommandBar);
  142. if (m_pCommandBar) m_pCommandBar->SetTrackingMode(FALSE);
  143. }
  144. RedrawParent();
  145. return TRUE;
  146. }
  147. CXTPRibbonGroup::CXTPRibbonGroup()
  148. {
  149. m_nIndex = -1;
  150. m_pGroups = NULL;
  151. m_pParent = NULL;
  152. m_pRibbonBar = NULL;
  153. m_rcGroup.SetRectEmpty();
  154. m_nId = -1;
  155. m_nIconId = -1;
  156. m_bReduced = FALSE;
  157. m_nAllowReduce = 4;
  158. m_bVisible = TRUE;
  159. m_bControlsCentering = FALSE;
  160. m_pControlGroupOption = new CXTPRibbonGroupOption();
  161. m_pControlGroupOption->m_pRibbonGroup = this;
  162. m_pControlGroupPopup = new CXTPRibbonGroupControlPopup(this);
  163. m_pControlGroupPopup->m_buttonRibbonStyle = xtpButtonIconAndCaptionBelow;
  164. m_bShowOptionButton = FALSE;
  165. m_pLayoutInfo = NULL;
  166. m_nRowCount = 2;
  167. m_bControlsGrouping = FALSE;
  168. }
  169. CXTPRibbonGroup::~CXTPRibbonGroup()
  170. {
  171. RemoveAll();
  172. CMDTARGET_RELEASE(m_pControlGroupOption);
  173. CMDTARGET_RELEASE(m_pControlGroupPopup);
  174. }
  175. void CXTPRibbonGroup::SetID(int nId)
  176. {
  177. m_nId = nId;
  178. m_pControlGroupOption->SetID(m_nId);
  179. m_pControlGroupPopup->SetID(m_nId);
  180. }
  181. void CXTPRibbonGroup::Copy(CXTPRibbonGroup* pGroup)
  182. {
  183. m_nId = pGroup->m_nId;
  184. m_nIconId = pGroup->m_nIconId;
  185. m_bShowOptionButton = pGroup->m_bShowOptionButton;
  186. m_strCaption = pGroup->m_strCaption;
  187. m_pGroups = pGroup->m_pGroups;
  188. m_bControlsGrouping = pGroup->m_bControlsGrouping;
  189. m_bControlsCentering = pGroup->m_bControlsCentering;
  190. m_bVisible = pGroup->m_bVisible;
  191. int nControlPos = m_pControlGroupOption->GetIndex();
  192. for (int i = 0; i < pGroup->GetCount(); i++)
  193. {
  194. CXTPControl* pControl = pGroup->GetAt(i);
  195. CXTPControl* pClone = m_pParent->GetControls()->AddClone(pControl, nControlPos + i);
  196. pClone->m_pRibbonGroup = this;
  197. pClone->SetHideFlag(xtpHideRibbonTab, FALSE);
  198. m_arrControls.Add(pClone);
  199. pClone->InternalAddRef();
  200. }
  201. m_pControlGroupOption->Copy(pGroup->m_pControlGroupOption, FALSE);
  202. m_pControlGroupOption->SetHideFlag(xtpHideRibbonTab, FALSE);
  203. m_pControlGroupPopup->Copy(pGroup->m_pControlGroupPopup, FALSE);
  204. m_pControlGroupPopup->SetHideFlag(xtpHideRibbonTab, FALSE);
  205. }
  206. void CXTPRibbonGroup::Remove(CXTPControl* pControl)
  207. {
  208. for (int nIndex = 0; nIndex < m_arrControls.GetSize(); nIndex++)
  209. {
  210. if (m_arrControls.GetAt(nIndex) == pControl)
  211. {
  212. RemoveAt(nIndex);
  213. return;
  214. }
  215. }
  216. }
  217. void CXTPRibbonGroup::RemoveAt(int nIndex)
  218. {
  219. if (nIndex >= 0 && nIndex < GetCount())
  220. {
  221. CXTPControl* pControl = m_arrControls.GetAt(nIndex);
  222. pControl->m_pRibbonGroup = NULL;
  223. m_arrControls.RemoveAt(nIndex);
  224. GetRibbonBar()->GetControls()->Remove(pControl);
  225. pControl->InternalRelease();
  226. }
  227. }
  228. void CXTPRibbonGroup::RemoveAll()
  229. {
  230. for (int nIndex = (int)m_arrControls.GetSize() - 1; nIndex >= 0; nIndex--)
  231. {
  232. CXTPControl* pControl = m_arrControls.GetAt(nIndex);
  233. pControl->m_pRibbonGroup = NULL;
  234. m_arrControls.RemoveAt(nIndex);
  235. m_pParent->GetControls()->Remove(pControl);
  236. pControl->InternalRelease();
  237. }
  238. }
  239. CXTPRibbonTab* CXTPRibbonGroup::GetParentTab() const
  240. {
  241. return m_pGroups->GetParentTab();
  242. }
  243. BOOL CXTPRibbonGroup::IsHighlighted() const
  244. {
  245. CXTPRibbonScrollableBar* pScrollableBar = GetScrollableBar(m_pParent);
  246. return pScrollableBar && pScrollableBar->GetHighlightedGroup() == this;
  247. }
  248. int CXTPRibbonGroup::GetMinimumWidth(CDC* pDC)
  249. {
  250. CXTPFontDC fnt(pDC, &GetRibbonBar()->GetRibbonPaintManager()->m_fontGroupCaption);
  251. CSize sz = pDC->GetTextExtent(m_strCaption);
  252. if (m_bShowOptionButton)
  253. sz.cx += GetRibbonBar()->GetRibbonPaintManager()->GetGroupCaptionHeight();
  254. return sz.cx;
  255. }
  256. BOOL CXTPRibbonGroup::IsOptionButtonVisible() const
  257. {
  258. return !m_bReduced && m_bShowOptionButton;
  259. }
  260. void CXTPRibbonGroup::SetRect(CRect rc)
  261. {
  262. m_rcGroup = rc;
  263. if (m_bReduced)
  264. {
  265. CRect rcEntry(rc.left, rc.top, rc.right, rc.bottom);
  266. m_pControlGroupPopup->SetHideFlag(xtpHideWrap, FALSE);
  267. m_pControlGroupPopup->SetRect(rcEntry);
  268. m_pControlGroupPopup->SetWrap(TRUE);
  269. }
  270. else
  271. {
  272. m_pControlGroupPopup->SetHideFlag(xtpHideWrap, TRUE);
  273. }
  274. if (!m_bShowOptionButton)
  275. {
  276. m_pControlGroupOption->SetHideFlag(xtpHideGeneric, TRUE);
  277. }
  278. else if (m_bReduced)
  279. {
  280. m_pControlGroupOption->SetHideFlag(xtpHideWrap, TRUE);
  281. }
  282. else
  283. {
  284. int nHeight = GetRibbonBar()->GetRibbonPaintManager()->GetGroupCaptionHeight();
  285. m_pControlGroupOption->SetWrap(TRUE);
  286. m_pControlGroupOption->SetHideFlag(xtpHideGeneric, FALSE);
  287. m_pControlGroupOption->SetHideFlag(xtpHideWrap, FALSE);
  288. m_pControlGroupOption->SetRect(CRect(rc.right - nHeight - 1, rc.bottom - nHeight, rc.right - 3, rc.bottom - 3));
  289. }
  290. }
  291. void CXTPRibbonGroup::RepositionControls(CDC* pDC)
  292. {
  293. CXTPRibbonTheme* pPaintManager = GetRibbonBar()->GetRibbonPaintManager();
  294. int x = m_rcGroup.left + 4;
  295. int y = m_rcGroup.top + pPaintManager->GetGroupCaptionHeight();
  296. for (int i = 0; i < GetCount(); i++)
  297. {
  298. CXTPControl* pControl = GetAt(i);
  299. if (!pControl->IsVisible())
  300. continue;
  301. CSize sz = pControl->GetSize(pDC);
  302. pControl->SetRect(CRect(x, y, x + sz.cx, y + sz.cy));
  303. x += sz.cx;
  304. }
  305. }
  306. CRect CXTPRibbonGroup::GetCaptionRect() const
  307. {
  308. CRect rcCaption(m_rcGroup);
  309. rcCaption.top = rcCaption.bottom - GetRibbonBar()->GetRibbonPaintManager()->GetGroupCaptionHeight();
  310. return rcCaption;
  311. }
  312. void CXTPRibbonGroup::Draw(CDC* pDC, CRect rcClipBox)
  313. {
  314. GetRibbonBar()->GetRibbonPaintManager()->DrawGroup(pDC, this);
  315. BOOL bFirst = TRUE;
  316. for (int i = 0; i < GetCount(); i++)
  317. {
  318. CXTPControl* pControl = GetAt(i);
  319. if (!pControl->IsVisible())
  320. continue;
  321. if (!m_bControlsGrouping && pControl->GetBeginGroup() && !bFirst)
  322. {
  323. GetRibbonBar()->GetPaintManager()->
  324. DrawCommandBarSeparator(pDC, GetRibbonBar(), pControl);
  325. }
  326. if (CRect().IntersectRect(rcClipBox, pControl->GetRect()))
  327. {
  328. pControl->Draw(pDC);
  329. }
  330. bFirst = FALSE;
  331. }
  332. if (m_pControlGroupPopup->IsVisible())
  333. {
  334. m_pControlGroupPopup->Draw(pDC);
  335. }
  336. if (m_pControlGroupOption->IsVisible())
  337. {
  338. m_pControlGroupOption->Draw(pDC);
  339. }
  340. }
  341. int CXTPRibbonGroup::IndexOf(CXTPControl* pControl) const
  342. {
  343. if (pControl->GetRibbonGroup() != this)
  344. return -1;
  345. return pControl->GetIndex() + GetCount() - m_pControlGroupOption->GetIndex();
  346. }
  347. CXTPControl* CXTPRibbonGroup::AddClone(CXTPControl* pClone, int nBefore, BOOL bRecursive)
  348. {
  349. if (nBefore < 0 || nBefore >= GetCount())
  350. nBefore = (int)GetCount();
  351. CXTPControl* pControl = (CXTPControl*)pClone->GetRuntimeClass()->CreateObject();
  352. ASSERT(pControl);
  353. if (!pControl)
  354. return NULL;
  355. int nControlPos = m_pControlGroupOption->GetIndex() - GetCount() + nBefore;
  356. GetRibbonBar()->GetControls()->InsertAt(pControl, nControlPos);
  357. m_arrControls.InsertAt(nBefore, pControl);
  358. pControl->InternalAddRef();
  359. pControl->Copy(pClone, bRecursive);
  360. pControl->m_pRibbonGroup = this;
  361. pControl->SetHideFlag(xtpHideRibbonTab, !IsVisible());
  362. return pControl;
  363. }
  364. CXTPControl* CXTPRibbonGroup::Add(XTPControlType controlType, int nId, LPCTSTR lpszParameter, int nBefore, BOOL bTemporary)
  365. {
  366. if (nBefore < 0 || nBefore >= GetCount())
  367. nBefore = (int)GetCount();
  368. int nControlPos = m_pControlGroupOption->GetIndex() - GetCount() + nBefore;
  369. CXTPControl* pControl = GetRibbonBar()->GetControls()->Add(controlType, nId, lpszParameter, nControlPos, bTemporary);
  370. ASSERT(pControl);
  371. if (!pControl)
  372. return NULL;
  373. m_arrControls.InsertAt(nBefore, pControl);
  374. pControl->InternalAddRef();
  375. pControl->m_pRibbonGroup = this;
  376. pControl->SetHideFlag(xtpHideRibbonTab, !IsVisible());
  377. return pControl;
  378. }
  379. void CXTPRibbonGroup::SetVisible(BOOL bVisible)
  380. {
  381. if (m_bVisible != bVisible)
  382. {
  383. m_bVisible = bVisible;
  384. GetRibbonBar()->RebuildControls(GetRibbonBar()->GetSelectedTab());
  385. GetRibbonBar()->OnRecalcLayout();
  386. }
  387. }
  388. BOOL CXTPRibbonGroup::IsVisible() const
  389. {
  390. if (m_pRibbonBar != m_pParent)
  391. return m_bVisible;
  392. return GetRibbonBar()->GetSelectedTab() == GetParentTab() && m_bVisible;
  393. }
  394. void CXTPRibbonGroup::OnGroupAdded()
  395. {
  396. CXTPControl* pGroupOption = GetControlGroupOption();
  397. m_pParent->GetControls()->Add(pGroupOption);
  398. pGroupOption->InternalAddRef();
  399. pGroupOption->SetHideFlag(xtpHideRibbonTab, !IsVisible());
  400. pGroupOption->SetID(GetID());
  401. CXTPControl* pGroupPopup = (CXTPControl*)GetControlGroupPopup();
  402. m_pParent->GetControls()->Add(pGroupPopup);
  403. pGroupPopup->SetCaption(GetCaption());
  404. pGroupPopup->SetDescription(NULL);
  405. pGroupPopup->InternalAddRef();
  406. pGroupPopup->SetHideFlag(xtpHideRibbonTab, !IsVisible());
  407. CXTPCommandBars* pCommandBars = m_pRibbonBar->GetCommandBars();
  408. ASSERT(pCommandBars);
  409. if (pCommandBars && pCommandBars->IsActionsEnabled())
  410. {
  411. CXTPControlAction* pAction = pCommandBars->CreateAction(GetID());
  412. if (pAction->GetCaption().IsEmpty()) pAction->SetCaption(GetCaption());
  413. pGroupPopup->SetAction(pAction);
  414. pGroupOption->SetAction(pAction);
  415. }
  416. }
  417. void CXTPRibbonGroup::OnGroupRemoved()
  418. {
  419. RemoveAll();
  420. if (m_pParent == m_pRibbonBar)
  421. {
  422. GetControlGroupPopup()->m_pRibbonGroup = NULL;
  423. m_pParent->GetControls()->Remove(GetControlGroupPopup());
  424. if (m_pRibbonBar->m_pHighlightedGroup == this)
  425. {
  426. m_pRibbonBar->m_pHighlightedGroup = NULL;
  427. }
  428. }
  429. GetControlGroupOption()->m_pRibbonGroup = NULL;
  430. m_pParent->GetControls()->Remove(GetControlGroupOption());
  431. }
  432. BOOL CXTPRibbonGroup::SetButtons(UINT* pButtons, int nCount)
  433. {
  434. BOOL bSeparator = FALSE;
  435. CXTPRibbonBar* pRibbonBar = GetRibbonBar();
  436. CWnd* pSite = pRibbonBar->GetSite();
  437. for (int i = 0; i < nCount; i++)
  438. {
  439. if (pButtons[i] == 0)
  440. bSeparator = TRUE;
  441. else
  442. {
  443. XTPControlType controlType = xtpControlButton;
  444. XTPButtonStyle buttonStyle = xtpButtonAutomatic;
  445. CXTPControl* pControl = NULL;
  446. UINT nID = pButtons[i];
  447. XTP_COMMANDBARS_CREATECONTROL cs;
  448. if (pSite)
  449. {
  450. cs.nID = nID;
  451. cs.pControl = NULL;
  452. cs.bToolBar = TRUE;
  453. cs.pMenu = NULL;
  454. cs.nIndex = i;
  455. cs.strCaption = pRibbonBar->GetTitle();
  456. cs.controlType = controlType;
  457. cs.pCommandBar = pRibbonBar;
  458. cs.buttonStyle = buttonStyle;
  459. if (pSite->SendMessage(WM_XTP_BEFORECREATECONTROL, 0, (LPARAM)&cs) != 0)
  460. {
  461. pControl = cs.pControl;
  462. controlType = cs.controlType;
  463. buttonStyle = cs.buttonStyle;
  464. nID = cs.nID;
  465. }
  466. }
  467. int nControlPos = m_pControlGroupOption->GetIndex();
  468. if (pControl == NULL)
  469. {
  470. pControl = pRibbonBar->GetControls()->Add(controlType, nID, NULL, nControlPos);
  471. if (pControl)
  472. {
  473. pControl->SetStyle(buttonStyle);
  474. if (controlType == xtpControlPopup) pControl->SetIconId(nID);
  475. }
  476. }
  477. else pRibbonBar->GetControls()->Add(pControl, nID, NULL, nControlPos);
  478. if (!pControl)
  479. continue;
  480. if (bSeparator)
  481. {
  482. pControl->SetBeginGroup(TRUE);
  483. bSeparator = FALSE;
  484. }
  485. m_arrControls.InsertAt(GetCount(), pControl);
  486. pControl->InternalAddRef();
  487. pControl->m_pRibbonGroup = this;
  488. pControl->SetHideFlag(xtpHideRibbonTab, !IsVisible());
  489. if (pSite)
  490. {
  491. cs.pControl = pControl;
  492. pSite->SendMessage(WM_XTP_AFTERCREATECONTROL, 0, (LPARAM)&cs);
  493. }
  494. }
  495. }
  496. return TRUE;
  497. }
  498. CXTPControl* CXTPRibbonGroup::Add(CXTPControl* pControl, int nId, LPCTSTR lpszParameter, int nBefore, BOOL bTemporary)
  499. {
  500. ASSERT(pControl);
  501. if (!pControl)
  502. return NULL;
  503. if (nBefore < 0 || nBefore >= GetCount())
  504. nBefore = (int)GetCount();
  505. int nControlPos = m_pControlGroupOption->GetIndex() - GetCount() + nBefore;
  506. GetRibbonBar()->GetControls()->Add(pControl, nId, lpszParameter, nControlPos, bTemporary);
  507. m_arrControls.InsertAt(nBefore, pControl);
  508. pControl->InternalAddRef();
  509. pControl->m_pRibbonGroup = this;
  510. pControl->SetHideFlag(xtpHideRibbonTab, !IsVisible());
  511. return pControl;
  512. }
  513. CXTPControl* CXTPRibbonGroup::InsertAt(CXTPControl* pControl, int nBefore)
  514. {
  515. ASSERT(pControl);
  516. if (!pControl)
  517. return NULL;
  518. if (nBefore < 0 || nBefore >= GetCount())
  519. nBefore = (int)GetCount();
  520. int nControlPos = m_pControlGroupOption->GetIndex() - GetCount() + nBefore;
  521. GetRibbonBar()->GetControls()->InsertAt(pControl, nControlPos);
  522. m_arrControls.InsertAt(nBefore, pControl);
  523. pControl->InternalAddRef();
  524. pControl->m_pRibbonGroup = this;
  525. pControl->SetHideFlag(xtpHideRibbonTab, !IsVisible());
  526. return pControl;
  527. }
  528. BOOL CXTPRibbonGroup::LoadToolBar(UINT nIDResource, BOOL bLoadIcons)
  529. {
  530. LPCTSTR lpszResourceName = MAKEINTRESOURCE(nIDResource);
  531. struct CToolBarData
  532. {
  533. WORD wVersion;
  534. WORD wWidth;
  535. WORD wHeight;
  536. WORD wItemCount;
  537. WORD* items()
  538. { return (WORD*)(this + 1); }
  539. };
  540. ASSERT_VALID(this);
  541. ASSERT(lpszResourceName != NULL);
  542. if (!lpszResourceName)
  543. return FALSE;
  544. // determine location of the bitmap in resource fork
  545. HINSTANCE hInst = AfxFindResourceHandle(lpszResourceName, RT_TOOLBAR);
  546. if (!hInst)
  547. return FALSE;
  548. HRSRC hRsrc = ::FindResource(hInst, lpszResourceName, RT_TOOLBAR);
  549. if (hRsrc == NULL)
  550. return FALSE;
  551. HGLOBAL hGlobal = LoadResource(hInst, hRsrc);
  552. if (hGlobal == NULL)
  553. return FALSE;
  554. CToolBarData* pData = (CToolBarData*)LockResource(hGlobal);
  555. if (pData == NULL)
  556. return FALSE;
  557. ASSERT(pData->wVersion == 1);
  558. int i;
  559. UINT* pItems = new UINT[pData->wItemCount];
  560. for (i = 0; i < pData->wItemCount; i++)
  561. pItems[i] = pData->items()[i];
  562. BOOL bResult = SetButtons(pItems, pData->wItemCount);
  563. if (bLoadIcons)
  564. {
  565. CXTPImageManager* pImageManager = GetRibbonBar()->GetImageManager();
  566. if (!pImageManager->SetIcons(nIDResource, pItems,
  567. pData->wItemCount, CSize(pData->wWidth, pData->wHeight)))
  568. bResult = FALSE;
  569. }
  570. delete[] pItems;
  571. UnlockResource(hGlobal);
  572. FreeResource(hGlobal);
  573. return bResult;
  574. }