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

对话框与窗口

开发平台:

Visual C++

  1. // XTPRibbonQuickAccessControls.cpp: implementation of the CXTPRibbonQuickAccessControls 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 "CommandBars/XTPCommandBar.h"
  22. #include "XTPRibbonBar.h"
  23. #include "XTPRibbonGroup.h"
  24. #include "XTPRibbonQuickAccessControls.h"
  25. #ifdef _DEBUG
  26. #undef THIS_FILE
  27. static char THIS_FILE[]=__FILE__;
  28. #define new DEBUG_NEW
  29. #endif
  30. //////////////////////////////////////////////////////////////////////////
  31. // CXTPRibbonControls
  32. IMPLEMENT_DYNCREATE(CXTPRibbonControls, CXTPControls)
  33. CXTPRibbonControls::CXTPRibbonControls()
  34. {
  35. }
  36. BOOL CXTPRibbonControls::OnControlRemoving(CXTPControl* pControl)
  37. {
  38. if (pControl->GetRibbonGroup())
  39. {
  40. if (pControl->GetRibbonGroup()->GetControlGroupOption() == pControl)
  41. return TRUE;
  42. if ((CXTPControl*)pControl->GetRibbonGroup()->GetControlGroupPopup() == pControl)
  43. return TRUE;
  44. }
  45. CXTPRibbonBar* pRibbonBar = (CXTPRibbonBar*)m_pParent;
  46. if (pControl == (CXTPControl*)pRibbonBar->GetControlTab())
  47. return TRUE;
  48. if (pControl == pRibbonBar->m_pControlQuickAccess)
  49. return TRUE;
  50. if (pControl == pRibbonBar->m_pControlQuickAccessMore)
  51. return TRUE;
  52. if (pControl == pRibbonBar->m_pControlScrollGroupsLeft)
  53. return TRUE;
  54. if (pControl == pRibbonBar->m_pControlScrollGroupsRight)
  55. return TRUE;
  56. return FALSE;
  57. }
  58. void CXTPRibbonControls::OnControlRemoved(CXTPControl* pControl)
  59. {
  60. pControl->m_pControls = NULL;
  61. if (pControl->GetRibbonGroup())
  62. {
  63. pControl->GetRibbonGroup()->Remove(pControl);
  64. }
  65. CXTPRibbonBar* pRibbonBar = (CXTPRibbonBar*)m_pParent;
  66. if (pControl == (CXTPControl*)pRibbonBar->m_pControlSystemButton)
  67. {
  68. pRibbonBar->m_pControlSystemButton = NULL;
  69. }
  70. if (pRibbonBar->IsQuickAccessControl(pControl))
  71. {
  72. pRibbonBar->GetQuickAccessControls()->Remove(pControl);
  73. }
  74. CXTPControls::OnControlRemoved(pControl);
  75. }
  76. BOOL CXTPRibbonControls::ShouldSerializeControl(CXTPControl* pControl)
  77. {
  78. if (pControl->m_bTemporary)
  79. return FALSE;
  80. if (pControl->GetRibbonGroup() != NULL)
  81. return FALSE;
  82. CXTPRibbonBar* pRibbonBar = (CXTPRibbonBar*)pControl->GetParent();
  83. if (pControl == (CXTPControl*)pRibbonBar->m_pControlSystemButton)
  84. return FALSE;
  85. if (pRibbonBar->IsQuickAccessControl(pControl))
  86. return FALSE;
  87. if (pControl == (CXTPControl*)pRibbonBar->GetControlTab())
  88. return FALSE;
  89. if (pControl == pRibbonBar->m_pControlScrollGroupsLeft)
  90. return FALSE;
  91. if (pControl == pRibbonBar->m_pControlScrollGroupsRight)
  92. return FALSE;
  93. return TRUE;
  94. }
  95. void CXTPRibbonControls::Copy(CXTPControls* pControls, BOOL bRecursive)
  96. {
  97. RemoveAll();
  98. for (int i = 0; i < pControls->GetCount(); i++)
  99. {
  100. CXTPControl* pControl = pControls->GetAt(i);
  101. if (ShouldSerializeControl(pControl))
  102. {
  103. AddClone(pControl, -1, bRecursive);
  104. }
  105. }
  106. }
  107. //////////////////////////////////////////////////////////////////////////
  108. // CXTPRibbonQuickAccessControls
  109. CXTPRibbonQuickAccessControls::CXTPRibbonQuickAccessControls()
  110. {
  111. }
  112. CXTPRibbonQuickAccessControls::~CXTPRibbonQuickAccessControls()
  113. {
  114. }
  115. int CXTPRibbonQuickAccessControls::IndexOf(CXTPControl* pControl) const
  116. {
  117. for (int nIndex = GetCount() - 1; nIndex >= 0; nIndex--)
  118. {
  119. if (GetAt(nIndex) == pControl)
  120. {
  121. return nIndex;
  122. }
  123. }
  124. return -1;
  125. }
  126. void CXTPRibbonQuickAccessControls::OnControlAdded(CXTPControl* pControl)
  127. {
  128. int nIndex = IndexOf(pControl) + (((CXTPRibbonBar*)m_pParent)->GetSystemButton() ? 1 : 0);
  129. m_pParent->GetControls()->InsertAt(pControl, nIndex);
  130. pControl->InternalAddRef();
  131. }
  132. void CXTPRibbonQuickAccessControls::OnControlRemoved(CXTPControl* pControl)
  133. {
  134. m_pParent->GetControls()->Remove(pControl);
  135. }
  136. void CXTPRibbonQuickAccessControls::Remove(CXTPControl* pControl)
  137. {
  138. for (int nIndex = 0; nIndex < GetCount(); nIndex++)
  139. {
  140. if (GetAt(nIndex) == pControl)
  141. {
  142. m_arrControls.RemoveAt(nIndex);
  143. OnControlRemoved(pControl);
  144. pControl->InternalRelease();
  145. return;
  146. }
  147. }
  148. }
  149. CXTPControl* CXTPRibbonQuickAccessControls::FindDuplicate(CXTPControl* pControl)
  150. {
  151. for (int i = 0; i < GetCount(); i++)
  152. {
  153. CXTPControl* pQuickAccessControl = GetAt(i);
  154. if (pQuickAccessControl->GetID() == pControl->GetID() && pQuickAccessControl->IsVisible() &&
  155. pQuickAccessControl->GetType() == pControl->GetType() && pQuickAccessControl->GetRuntimeClass() == pControl->GetRuntimeClass())
  156. {
  157. return pQuickAccessControl;
  158. }
  159. }
  160. return NULL;
  161. }
  162. void CXTPRibbonQuickAccessControls::RefreshIndexes()
  163. {
  164. for (int nIndex = 0; nIndex < GetCount(); nIndex++)
  165. {
  166. CXTPControl* pControl = GetAt(nIndex);
  167. pControl->SetParent(m_pParent);
  168. }
  169. }
  170. void CXTPRibbonQuickAccessControls::Reset()
  171. {
  172. RemoveAll();
  173. if (m_pOriginalControls)
  174. {
  175. CXTPControls* pControls = m_pOriginalControls;
  176. for (int i = 0; i < pControls->GetCount(); i++)
  177. {
  178. CXTPControl* pControl = pControls->GetAt(i);
  179. if (!pControl->IsTemporary())
  180. AddClone(pControl, -1, TRUE);
  181. }
  182. }
  183. if (m_pParent)
  184. {
  185. m_pParent->OnRecalcLayout();
  186. }
  187. }