/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
OUndoContainerAction::OUndoContainerAction(SdrModel& _rMod
,Action _eAction
,uno::Reference< container::XIndexContainer > xContainer
,const Reference< XInterface > & xElem
,TranslateId pCommentId)
:OCommentUndoAction(_rMod, pCommentId)
,m_xElement(xElem)
,m_xContainer(std::move(xContainer))
,m_eAction( _eAction )
{ // normalize if ( m_eAction == Removed ) // we now own the element
m_xOwnElement = m_xElement;
}
OUndoContainerAction::~OUndoContainerAction()
{ // if we own the object...
Reference< XComponent > xComp( m_xOwnElement, UNO_QUERY ); if ( !xComp.is() ) return;
// and the object does not have a parent
Reference< XChild > xChild( m_xOwnElement, UNO_QUERY ); if ( !xChild.is() || xChild->getParent().is() ) return;
void OUndoContainerAction::implReInsert( )
{ if ( m_xContainer.is() )
{ // insert the element
m_xContainer->insertByIndex( m_xContainer->getCount(),uno::Any(m_xElement) );
} // we don't own the object anymore
m_xOwnElement = nullptr;
}
void OUndoContainerAction::implReRemove( )
{
OXUndoEnvironment& rEnv = static_cast< OReportModel& >( m_rMod ).GetUndoEnv(); try
{
OXUndoEnvironment::OUndoEnvLock aLock(rEnv); if ( m_xContainer.is() )
{ const sal_Int32 nCount = m_xContainer->getCount(); for (sal_Int32 i = 0; i < nCount; ++i)
{
uno::Reference< uno::XInterface> xObj(m_xContainer->getByIndex(i),uno::UNO_QUERY); if ( xObj == m_xElement )
{
m_xContainer->removeByIndex( i ); break;
}
}
}
} catch(uno::Exception&){} // from now on, we own this object
m_xOwnElement = m_xElement;
}
void OUndoContainerAction::Undo()
{ if ( !m_xElement.is() ) return;
// prevents that an undo action will be created for elementInserted try
{ switch ( m_eAction )
{ case Inserted:
implReRemove(); break;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.