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

对话框与窗口

开发平台:

Visual C++

  1. // XTPRibbonTab.cpp: implementation of the CXTPRibbonTab 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 "XTPRibbonTab.h"
  23. #include "XTPRibbonGroup.h"
  24. #include "XTPRibbonGroups.h"
  25. #include "XTPRibbonBar.h"
  26. #include "XTPRibbonControlTab.h"
  27. #ifdef _DEBUG
  28. #undef THIS_FILE
  29. static char THIS_FILE[]=__FILE__;
  30. #define new DEBUG_NEW
  31. #endif
  32. //////////////////////////////////////////////////////////////////////////
  33. //
  34. CXTPRibbonTabContextHeader::CXTPRibbonTabContextHeader(CXTPRibbonTab* pFirstTab)
  35. {
  36. ASSERT(pFirstTab);
  37. if (!pFirstTab)
  38. return;
  39. m_pLastTab = m_pFirstTab = pFirstTab;
  40. m_color = pFirstTab->GetContextColor();
  41. m_strCaption = pFirstTab->GetContextCaption();
  42. m_rcRect.SetRectEmpty();
  43. pFirstTab->m_pContextHeader = this;
  44. }
  45. CXTPRibbonTabContextHeaders::CXTPRibbonTabContextHeaders()
  46. {
  47. }
  48. CXTPRibbonTabContextHeaders::~CXTPRibbonTabContextHeaders()
  49. {
  50. RemoveAll();
  51. }
  52. int CXTPRibbonTabContextHeaders::GetCount() const
  53. {
  54. return (int)m_arrHeaders.GetSize();
  55. }
  56. CXTPRibbonTabContextHeader* CXTPRibbonTabContextHeaders::GetHeader(int nIndex) const
  57. {
  58. return m_arrHeaders.GetAt(nIndex);
  59. }
  60. void CXTPRibbonTabContextHeaders::RemoveAll()
  61. {
  62. for (int i = 0; i < GetCount(); i++)
  63. {
  64. delete m_arrHeaders[i];
  65. }
  66. m_arrHeaders.RemoveAll();
  67. }
  68. CXTPRibbonTabContextHeader* CXTPRibbonTabContextHeaders::HitTest(CPoint pt) const
  69. {
  70. for (int i = 0; i < GetCount(); i++)
  71. {
  72. if (m_arrHeaders[i]->m_rcRect.PtInRect(pt))
  73. return m_arrHeaders[i];
  74. }
  75. return NULL;
  76. }
  77. void CXTPRibbonTabContextHeaders::Add(CXTPRibbonTabContextHeader* pHeader)
  78. {
  79. m_arrHeaders.Add(pHeader);
  80. }
  81. IMPLEMENT_SERIAL(CXTPRibbonTab, CXTPTabManagerItem, VERSIONABLE_SCHEMA | _XTP_SCHEMA_CURRENT)
  82. //////////////////////////////////////////////////////////////////////
  83. // Construction/Destruction
  84. //////////////////////////////////////////////////////////////////////
  85. CXTPRibbonTab::CXTPRibbonTab()
  86. {
  87. m_nId = 0;
  88. m_pGroups = new CXTPRibbonGroups;
  89. m_pGroups->m_pParentTab = this;
  90. m_nContextColor = xtpRibbonTabContextColorNone;
  91. m_pContextHeader = NULL;
  92. m_pRibbonBar = NULL;
  93. m_pParent = NULL;
  94. }
  95. CXTPRibbonTab::~CXTPRibbonTab()
  96. {
  97. ASSERT(m_pGroups->GetCount() == 0);
  98. CMDTARGET_RELEASE(m_pGroups);
  99. }
  100. void CXTPRibbonTab::Copy(CXTPRibbonTab* pRibbonTab)
  101. {
  102. m_strCaption = pRibbonTab->m_strCaption;
  103. m_nContextColor = pRibbonTab->m_nContextColor;
  104. m_strContextCaption= pRibbonTab->m_strContextCaption;
  105. m_nId = pRibbonTab->m_nId;
  106. m_bVisible = pRibbonTab->m_bVisible;
  107. m_strToolTip = pRibbonTab->m_strToolTip;
  108. if (m_pTabManager && pRibbonTab->IsSelected())
  109. {
  110. Select();
  111. }
  112. m_pGroups->Copy(pRibbonTab->m_pGroups);
  113. }
  114. void CXTPRibbonTab::OnRemoved()
  115. {
  116. m_pGroups->RemoveAll();
  117. }
  118. CXTPRibbonBar* CXTPRibbonTab::GetRibbonBar() const
  119. {
  120. return m_pRibbonBar;
  121. }
  122. CXTPRibbonGroup* CXTPRibbonTab::AddGroup(LPCTSTR lpszCaption)
  123. {
  124. return GetGroups()->Add(lpszCaption);
  125. }
  126. CXTPRibbonGroup* CXTPRibbonTab::AddGroup(int nID)
  127. {
  128. CString strCaption;
  129. if (!strCaption.LoadString(nID))
  130. {
  131. }
  132. if (strCaption.Find('n') != -1)
  133. {
  134. CString strPrompt = strCaption;
  135. AfxExtractSubString(strCaption, strPrompt, 1);
  136. }
  137. return GetGroups()->Add(strCaption, nID);
  138. }
  139. void CXTPRibbonTab::SetVisible(BOOL bVisible)
  140. {
  141. if (bVisible == IsVisible())
  142. return;
  143. CXTPTabManagerItem::SetVisible(bVisible);
  144. if (!bVisible && IsSelected())
  145. {
  146. CXTPTabManagerItem* pItem = GetTabManager()->FindNextFocusable(-1, +1);
  147. if (pItem)
  148. {
  149. pItem->Select();
  150. }
  151. }
  152. }
  153. CXTPRibbonGroup* CXTPRibbonTab::FindGroup(int nID) const
  154. {
  155. for (int i = 0 ; i < m_pGroups->GetCount(); i++)
  156. {
  157. if (m_pGroups->GetAt(i)->GetID() == nID)
  158. return m_pGroups->GetAt(i);
  159. }
  160. return NULL;
  161. }
  162. void CXTPRibbonTab::DoPropExchange(CXTPPropExchange* pPX)
  163. {
  164. if (pPX->IsLoading())
  165. {
  166. CXTPRibbonControlTab* pControlTab = ((CXTPRibbonControlTab*)pPX->m_pOwner);
  167. m_pRibbonBar = DYNAMIC_DOWNCAST(CXTPRibbonBar, pControlTab->GetParent());
  168. m_pTabManager = pControlTab;
  169. m_pParent = m_pRibbonBar;
  170. }
  171. PX_String(pPX, _T("Caption"), m_strCaption, _T(""));
  172. PX_String(pPX, _T("ToolTip"), m_strToolTip, _T(""));
  173. PX_Enum(pPX, _T("ContextColor"), m_nContextColor, xtpRibbonTabContextColorNone);
  174. PX_String(pPX, _T("ContextCaption"), m_strContextCaption, _T(""));
  175. PX_Int(pPX, _T("Id"), m_nId, 0);
  176. PX_Bool(pPX, _T("Visible"), m_bVisible, TRUE);
  177. if (pPX->IsStoring())
  178. {
  179. BOOL bSelected = IsSelected();
  180. PX_Bool(pPX, _T("Selected"), bSelected, FALSE);
  181. }
  182. else
  183. {
  184. BOOL bSelected = FALSE;
  185. PX_Bool(pPX, _T("Selected"), bSelected, 0);
  186. if (bSelected)
  187. {
  188. Select();
  189. }
  190. }
  191. CXTPPropExchangeSection secGroups(pPX->GetSection(_T("Groups")));
  192. m_pGroups->DoPropExchange(&secGroups);
  193. }