/** * @file XTPRibbonQuickAccessControls.cpp * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ #include "stdafx.h" #include "Common/XTPTypeId.h" #include "Common/XTPFramework.h" #include "Common/XTPSystemHelpers.h" #include "Common/XTPSynchro.h" #include "Common/XTPApplication.h" #include "Common/XTPSingleton.h" #include "Common/XTPGdiObjects.h" #include "Common/XTPHookManager.h" #include "Common/XTPColorManager.h" #include "Common/ScrollBar/XTPScrollInfo.h" #include "CommandBars/XTPCommandBarsDefines.h" #include "CommandBars/XTPPaintManager.h" #include "CommandBars/XTPCommandBar.h" #include "CommandBars/XTPToolBar.h" #include "CommandBars/XTPMenuBar.h" #include "CommandBars/XTPMenuTitleBar.h" #include "CommandBars/XTPPopupBar.h" #include "CommandBars/XTPControls.h" #include "CommandBars/XTPControl.h" #include "CommandBars/XTPControlButton.h" #include "CommandBars/XTPControlPopup.h" #include "Ribbon/XTPRibbonPopups.h" #include "Ribbon/XTPRibbonBar.h" #include "Ribbon/XTPRibbonGroup.h" #include "Ribbon/XTPRibbonQuickAccessControls.h" #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG # undef THIS_FILE static char THIS_FILE[] = __FILE__; # define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////////// // CXTPRibbonControls IMPLEMENT_DYNCREATE(CXTPRibbonControls, CXTPControls) CXTPRibbonControls::CXTPRibbonControls() { } BOOL CXTPRibbonControls::OnControlRemoving(CXTPControl* pControl) { if (pControl->GetRibbonGroup()) { if (pControl->GetRibbonGroup()->GetControlGroupOption() == pControl) return TRUE; if ((CXTPControl*)pControl->GetRibbonGroup()->GetControlGroupPopup() == pControl) return TRUE; } CXTPRibbonBar* pRibbonBar = (CXTPRibbonBar*)m_pParent; if (pControl == (CXTPControl*)pRibbonBar->GetControlTab()) return TRUE; if (pControl == pRibbonBar->m_pControlQuickAccess) return TRUE; if (pControl == pRibbonBar->m_pControlQuickAccessMore) return TRUE; if (pControl == pRibbonBar->m_pControlScrollGroupsLeft) return TRUE; if (pControl == pRibbonBar->m_pControlScrollGroupsRight) return TRUE; return FALSE; } void CXTPRibbonControls::OnControlRemoved(CXTPControl* pControl) { pControl->m_pControls = NULL; if (pControl->GetRibbonGroup()) { pControl->GetRibbonGroup()->Remove(pControl); } CXTPRibbonBar* pRibbonBar = (CXTPRibbonBar*)m_pParent; if (pControl == (CXTPControl*)pRibbonBar->m_pControlSystemButton) { pRibbonBar->m_pControlSystemButton = NULL; } if (pRibbonBar->IsQuickAccessControl(pControl)) { pRibbonBar->GetQuickAccessControls()->Remove(pControl); } CXTPControls::OnControlRemoved(pControl); } BOOL CXTPRibbonControls::ShouldSerializeControl(CXTPControl* pControl) { if (pControl->m_bTemporary) return FALSE; if (pControl->GetRibbonGroup() != NULL) return FALSE; CXTPRibbonBar* pRibbonBar = (CXTPRibbonBar*)pControl->GetParent(); if (pControl == (CXTPControl*)pRibbonBar->m_pControlSystemButton) return FALSE; if (pRibbonBar->IsQuickAccessControl(pControl)) return FALSE; if (pControl == (CXTPControl*)pRibbonBar->GetControlTab()) return FALSE; if (pControl == pRibbonBar->m_pControlScrollGroupsLeft) return FALSE; if (pControl == pRibbonBar->m_pControlScrollGroupsRight) return FALSE; return TRUE; } void CXTPRibbonControls::Copy(CXTPControls* pControls, BOOL bRecursive) { if (this != pControls) { RemoveAll(); for (int i = 0; i < pControls->GetCount(); i++) { CXTPControl* pControl = pControls->GetAt(i); if (ShouldSerializeControl(pControl)) { AddClone(pControl, -1, bRecursive); } } } } ////////////////////////////////////////////////////////////////////////// // CXTPRibbonQuickAccessControls CXTPRibbonQuickAccessControls::CXTPRibbonQuickAccessControls() { } CXTPRibbonQuickAccessControls::~CXTPRibbonQuickAccessControls() { } int CXTPRibbonQuickAccessControls::IndexOf(CXTPControl* pControl) const { for (int nIndex = GetCount() - 1; nIndex >= 0; nIndex--) { if (GetAt(nIndex) == pControl) { return nIndex; } } return -1; } void CXTPRibbonQuickAccessControls::OnControlAdded(CXTPControl* pControl) { int nIndex = IndexOf(pControl) + (((CXTPRibbonBar*)m_pParent)->GetSystemButton() ? 1 : 0); m_pParent->GetControls()->InsertAt(pControl, nIndex); pControl->SetOnQuickAccess(TRUE); pControl->InternalAddRef(); } void CXTPRibbonQuickAccessControls::OnControlRemoved(CXTPControl* pControl) { pControl->SetOnQuickAccess(FALSE); m_pParent->GetControls()->Remove(pControl); } void CXTPRibbonQuickAccessControls::Remove(CXTPControl* pControl) { for (int nIndex = 0; nIndex < GetCount(); nIndex++) { if (GetAt(nIndex) == pControl) { m_arrControls.RemoveAt(nIndex); OnControlRemoved(pControl); pControl->InternalRelease(); return; } } } CXTPControl* CXTPRibbonQuickAccessControls::FindDuplicate(CXTPControl* pControl) { for (int i = 0; i < GetCount(); i++) { CXTPControl* pQuickAccessControl = GetAt(i); if (pQuickAccessControl->GetID() == pControl->GetID() && pQuickAccessControl->IsVisible(xtpHideWrap) && pQuickAccessControl->GetType() == pControl->GetType() && pQuickAccessControl->GetRuntimeClass() == pControl->GetRuntimeClass()) { return pQuickAccessControl; } } return NULL; } void CXTPRibbonQuickAccessControls::RefreshIndexes() { for (int nIndex = 0; nIndex < GetCount(); nIndex++) { CXTPControl* pControl = GetAt(nIndex); pControl->SetParent(m_pParent); } } void CXTPRibbonQuickAccessControls::Reset() { RemoveAll(); if (m_pOriginalControls) { CXTPControls* pControls = m_pOriginalControls; for (int i = 0; i < pControls->GetCount(); i++) { CXTPControl* pControl = pControls->GetAt(i); if (!pControl->IsTemporary()) AddClone(pControl, -1, TRUE); } } if (m_pParent) { m_pParent->OnRecalcLayout(); } }