/** * @file XTPMarkupEventHandlerMap.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/XTPCasting.h" #include "Common/XTPTypeId.h" #include "Common/XTPFramework.h" #include "Common/XTPSystemHelpers.h" #include "Markup/XTPMarkupObject.h" #include "Markup/XTPMarkupDelegate.h" #include "Markup/XTPMarkupEventHandlerMap.h" #include "Markup/XTPMarkupRoutedEventArgs.h" #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ////////////////////////////////////////////////////////////////////////// // CXTPMarkupEventHandlerMap CXTPMarkupEventHandlerMap::CXTPMarkupEventHandlerMap() { } CXTPMarkupEventHandlerMap::~CXTPMarkupEventHandlerMap() { RemoveAll(); } void CXTPMarkupEventHandlerMap::RemoveAll() { POSITION pos = m_mapHandlers.GetStartPosition(); while (pos) { CPtrList* pHandlers; CXTPMarkupRoutedEvent* pEvent; m_mapHandlers.GetNextAssoc(pos, pEvent, pHandlers); while (!pHandlers->IsEmpty()) { CXTPMarkupDelegate* pDelegate = (CXTPMarkupDelegate*)pHandlers->RemoveTail(); MARKUP_RELEASE(pDelegate); } delete pHandlers; } m_mapHandlers.RemoveAll(); } void CXTPMarkupEventHandlerMap::Add(CXTPMarkupRoutedEvent* pEvent, CXTPMarkupDelegate* pDelegate) { _ASSERTE(NULL != pEvent); _ASSERTE(NULL != pDelegate); CPtrList* pHandlers; if (!m_mapHandlers.Lookup(pEvent, pHandlers)) { pHandlers = new CPtrList(); m_mapHandlers.SetAt(pEvent, pHandlers); } pHandlers->AddTail(pDelegate); } BOOL CXTPMarkupEventHandlerMap::Remove(CXTPMarkupRoutedEvent* pEvent, CXTPMarkupDelegate* pDelegate) { _ASSERTE(NULL != pEvent); _ASSERTE(NULL != pDelegate); CPtrList* pHandlers = NULL; if (!m_mapHandlers.Lookup(pEvent, pHandlers)) return FALSE; POSITION pos = pHandlers->GetHeadPosition(); POSITION prev; while (NULL != pos) { prev = pos; CXTPMarkupDelegate* pOtherDelegate = (CXTPMarkupDelegate*)pHandlers->GetNext(pos); if (pOtherDelegate == pDelegate) { pHandlers->RemoveAt(prev); MARKUP_RELEASE(pDelegate); return TRUE; } } return FALSE; } void CXTPMarkupEventHandlerMap::Raise(CXTPMarkupObject* pSender, CXTPMarkupRoutedEventArgs* pEventArgs) { CPtrList* pHandlers; if (!m_mapHandlers.Lookup(pEventArgs->GetEvent(), pHandlers)) return; POSITION pos = pHandlers->GetHeadPosition(); while (pos) { CXTPMarkupDelegate* pDelegate = (CXTPMarkupDelegate*)pHandlers->GetNext(pos); pDelegate->Execute(pSender, pEventArgs); } }