LCOV - code coverage report
Current view: top level - reportdesign/source/core/sdr - UndoEnv.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 288 0.3 %
Date: 2015-06-13 12:38:46 Functions: 2 35 5.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #include "UndoActions.hxx"
      20             : #include "UndoEnv.hxx"
      21             : #include "formatnormalizer.hxx"
      22             : #include "conditionupdater.hxx"
      23             : #include "corestrings.hrc"
      24             : #include "rptui_slotid.hrc"
      25             : #include "RptDef.hxx"
      26             : #include "ModuleHelper.hxx"
      27             : #include "RptObject.hxx"
      28             : #include "RptPage.hxx"
      29             : #include "RptResId.hrc"
      30             : #include "RptModel.hxx"
      31             : 
      32             : #include <boost/noncopyable.hpp>
      33             : #include <com/sun/star/script/XEventAttacherManager.hpp>
      34             : #include <com/sun/star/container/XChild.hpp>
      35             : #include <com/sun/star/container/XNameContainer.hpp>
      36             : #include <com/sun/star/beans/theIntrospection.hpp>
      37             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      38             : #include <com/sun/star/util/XModifyBroadcaster.hpp>
      39             : #include <com/sun/star/beans/XIntrospectionAccess.hpp>
      40             : #include <com/sun/star/beans/XIntrospection.hpp>
      41             : 
      42             : #include <connectivity/dbtools.hxx>
      43             : #include <svl/smplhint.hxx>
      44             : #include <tools/diagnose_ex.h>
      45             : #include <comphelper/stl_types.hxx>
      46             : #include <vcl/svapp.hxx>
      47             : #include <dbaccess/dbsubcomponentcontroller.hxx>
      48             : #include <svx/unoshape.hxx>
      49             : #include <osl/mutex.hxx>
      50             : 
      51             : namespace rptui
      52             : {
      53             :     using namespace ::com::sun::star;
      54             :     using namespace uno;
      55             :     using namespace lang;
      56             :     using namespace script;
      57             :     using namespace beans;
      58             :     using namespace awt;
      59             :     using namespace util;
      60             :     using namespace container;
      61             :     using namespace report;
      62             : 
      63             : 
      64             : 
      65             : struct PropertyInfo
      66             : {
      67             :     bool    bIsReadonlyOrTransient;
      68             : 
      69           0 :     PropertyInfo( const bool i_bIsTransientOrReadOnly )
      70           0 :         :bIsReadonlyOrTransient( i_bIsTransientOrReadOnly )
      71             :     {
      72           0 :     }
      73             : };
      74             : 
      75             : typedef std::unordered_map< OUString, PropertyInfo, OUStringHash >    PropertiesInfo;
      76             : 
      77           0 : struct ObjectInfo
      78             : {
      79             :     PropertiesInfo              aProperties;
      80             :     Reference< XPropertySet >   xPropertyIntrospection;
      81             : 
      82           0 :     ObjectInfo()
      83             :         :aProperties()
      84           0 :         ,xPropertyIntrospection()
      85             :     {
      86           0 :     }
      87             : };
      88             : 
      89             : typedef ::std::map< Reference< XPropertySet >, ObjectInfo, ::comphelper::OInterfaceCompare< XPropertySet > >    PropertySetInfoCache;
      90             : 
      91             : 
      92             : 
      93           0 : class OXUndoEnvironmentImpl: private boost::noncopyable
      94             : {
      95             : public:
      96             :     OReportModel&                                       m_rModel;
      97             :     PropertySetInfoCache                                m_aPropertySetCache;
      98             :     FormatNormalizer                                    m_aFormatNormalizer;
      99             :     ConditionUpdater                                    m_aConditionUpdater;
     100             :     ::osl::Mutex                                        m_aMutex;
     101             :     ::std::vector< uno::Reference< container::XChild> > m_aSections;
     102             :     Reference< XIntrospection >                         m_xIntrospection;
     103             :     oslInterlockedCount                                 m_nLocks;
     104             :     bool                                            m_bReadOnly;
     105             :     bool                                            m_bIsUndo;
     106             : 
     107             :     OXUndoEnvironmentImpl(OReportModel& _rModel);
     108             : };
     109             : 
     110           0 : OXUndoEnvironmentImpl::OXUndoEnvironmentImpl(OReportModel& _rModel) : m_rModel(_rModel)
     111             :         ,m_aFormatNormalizer( _rModel )
     112             :         ,m_aConditionUpdater()
     113             :         ,m_nLocks(0)
     114             :         ,m_bReadOnly(false)
     115           0 :         ,m_bIsUndo(false)
     116             : {
     117           0 : }
     118             : 
     119             : 
     120             : 
     121           0 : OXUndoEnvironment::OXUndoEnvironment(OReportModel& _rModel)
     122           0 :                    :m_pImpl(new OXUndoEnvironmentImpl(_rModel) )
     123             : {
     124           0 :     StartListening(m_pImpl->m_rModel);
     125           0 : }
     126             : 
     127             : 
     128           0 : OXUndoEnvironment::~OXUndoEnvironment()
     129             : {
     130           0 : }
     131             : 
     132           0 : void OXUndoEnvironment::Lock()
     133             : {
     134             :     OSL_ENSURE(m_refCount,"Illegal call to dead object!");
     135           0 :     osl_atomic_increment( &m_pImpl->m_nLocks );
     136           0 : }
     137           0 : void OXUndoEnvironment::UnLock()
     138             : {
     139             :     OSL_ENSURE(m_refCount,"Illegal call to dead object!");
     140             : 
     141           0 :     osl_atomic_decrement( &m_pImpl->m_nLocks );
     142           0 : }
     143           0 : bool OXUndoEnvironment::IsLocked() const { return m_pImpl->m_nLocks != 0; }
     144             : 
     145           0 : void OXUndoEnvironment::RemoveSection(OReportPage* _pPage)
     146             : {
     147           0 :     if ( _pPage )
     148             :     {
     149           0 :         Reference< XInterface > xSection(_pPage->getSection());
     150           0 :         if ( xSection.is() )
     151           0 :             RemoveElement( xSection );
     152             :     }
     153           0 : }
     154             : 
     155           0 : void OXUndoEnvironment::Clear(const Accessor& /*_r*/)
     156             : {
     157           0 :     OUndoEnvLock aLock(*this);
     158             : 
     159           0 :     m_pImpl->m_aPropertySetCache.clear();
     160             : 
     161           0 :     sal_uInt16 nCount = m_pImpl->m_rModel.GetPageCount();
     162             :     sal_uInt16 i;
     163           0 :     for (i = 0; i < nCount; i++)
     164             :     {
     165           0 :         OReportPage* pPage = PTR_CAST( OReportPage, m_pImpl->m_rModel.GetPage(i) );
     166           0 :         RemoveSection(pPage);
     167             :     }
     168             : 
     169           0 :     nCount = m_pImpl->m_rModel.GetMasterPageCount();
     170           0 :     for (i = 0; i < nCount; i++)
     171             :     {
     172           0 :         OReportPage* pPage = PTR_CAST( OReportPage, m_pImpl->m_rModel.GetMasterPage(i) );
     173           0 :         RemoveSection(pPage);
     174             :     }
     175             : 
     176           0 :     m_pImpl->m_aSections.clear();
     177             : 
     178           0 :     if (IsListening(m_pImpl->m_rModel))
     179           0 :         EndListening(m_pImpl->m_rModel);
     180           0 : }
     181             : 
     182             : 
     183           0 : void OXUndoEnvironment::ModeChanged()
     184             : {
     185           0 :     m_pImpl->m_bReadOnly = !m_pImpl->m_bReadOnly;
     186             : 
     187           0 :     if (!m_pImpl->m_bReadOnly)
     188           0 :         StartListening(m_pImpl->m_rModel);
     189             :     else
     190           0 :         EndListening(m_pImpl->m_rModel);
     191           0 : }
     192             : 
     193             : 
     194           0 : void OXUndoEnvironment::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
     195             : {
     196           0 :     const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
     197           0 :     if (pSimpleHint && pSimpleHint->GetId() == SFX_HINT_MODECHANGED )
     198           0 :         ModeChanged();
     199           0 : }
     200             : 
     201             : //  XEventListener
     202             : 
     203           0 : void SAL_CALL OXUndoEnvironment::disposing(const EventObject& e) throw( RuntimeException, std::exception )
     204             : {
     205             :     // check if it's an object we have cached information about
     206           0 :     Reference< XPropertySet > xSourceSet(e.Source, UNO_QUERY);
     207           0 :     if ( xSourceSet.is() )
     208             :     {
     209           0 :         uno::Reference< report::XSection> xSection(xSourceSet,uno::UNO_QUERY);
     210           0 :         if ( xSection.is() )
     211           0 :             RemoveSection(xSection);
     212             :         else
     213           0 :             RemoveElement(xSourceSet);
     214           0 :     }
     215           0 : }
     216             : 
     217             : // XPropertyChangeListener
     218             : 
     219           0 : void SAL_CALL OXUndoEnvironment::propertyChange( const PropertyChangeEvent& _rEvent ) throw(uno::RuntimeException, std::exception)
     220             : {
     221             : 
     222           0 :     ::osl::ClearableMutexGuard aGuard( m_pImpl->m_aMutex );
     223             : 
     224           0 :     if ( IsLocked() )
     225           0 :         return;
     226             : 
     227           0 :     Reference< XPropertySet >  xSet( _rEvent.Source, UNO_QUERY );
     228           0 :     if (!xSet.is())
     229           0 :         return;
     230             : 
     231           0 :     dbaui::DBSubComponentController* pController = m_pImpl->m_rModel.getController();
     232           0 :     if ( !pController )
     233           0 :         return;
     234             : 
     235             :     // no Undo for transient and readonly props.
     236             :     // let's see if we know something about the set
     237           0 :     PropertySetInfoCache::iterator objectPos = m_pImpl->m_aPropertySetCache.find(xSet);
     238           0 :     if (objectPos == m_pImpl->m_aPropertySetCache.end())
     239             :     {
     240           0 :         objectPos = m_pImpl->m_aPropertySetCache.insert( PropertySetInfoCache::value_type(
     241             :             xSet, ObjectInfo()
     242           0 :         ) ).first;
     243             :         DBG_ASSERT(objectPos != m_pImpl->m_aPropertySetCache.end(), "OXUndoEnvironment::propertyChange : just inserted it ... why it's not there ?");
     244             :     }
     245           0 :     if ( objectPos == m_pImpl->m_aPropertySetCache.end() )
     246           0 :         return;
     247             : 
     248             :     // now we have access to the cached info about the set
     249             :     // let's see what we know about the property
     250           0 :     ObjectInfo& rObjectInfo = objectPos->second;
     251           0 :     PropertiesInfo::iterator aPropertyPos = rObjectInfo.aProperties.find( _rEvent.PropertyName );
     252           0 :     if ( aPropertyPos == rObjectInfo.aProperties.end() )
     253             :     {   // nothing 'til now ... have to change this ....
     254             :         // the attributes
     255           0 :         Reference< XPropertySetInfo > xPSI( xSet->getPropertySetInfo(), UNO_SET_THROW );
     256           0 :         sal_Int32 nPropertyAttributes = 0;
     257             :         try
     258             :         {
     259           0 :             if ( xPSI->hasPropertyByName( _rEvent.PropertyName ) )
     260             :             {
     261           0 :                 nPropertyAttributes = xPSI->getPropertyByName( _rEvent.PropertyName ).Attributes;
     262             :             }
     263             :             else
     264             :             {
     265             :                 // it's perfectly valid for a component to notify a change in a property which it doesn't have - as long
     266             :                 // as it has an attribute with this name
     267           0 :                 if ( !rObjectInfo.xPropertyIntrospection.is() )
     268             :                 {
     269           0 :                     if ( !m_pImpl->m_xIntrospection.is() )
     270             :                     {
     271           0 :                         m_pImpl->m_xIntrospection = theIntrospection::get( m_pImpl->m_rModel.getController()->getORB() );
     272             :                     }
     273             :                     Reference< XIntrospectionAccess > xIntrospection(
     274           0 :                         m_pImpl->m_xIntrospection->inspect( makeAny( _rEvent.Source ) ),
     275             :                         UNO_SET_THROW
     276           0 :                     );
     277           0 :                     rObjectInfo.xPropertyIntrospection.set( xIntrospection->queryAdapter( cppu::UnoType<XPropertySet>::get() ), UNO_QUERY_THROW );
     278             :                 }
     279           0 :                 if ( rObjectInfo.xPropertyIntrospection.is() )
     280             :                 {
     281           0 :                     xPSI.set( rObjectInfo.xPropertyIntrospection->getPropertySetInfo(), UNO_SET_THROW );
     282           0 :                     nPropertyAttributes = xPSI->getPropertyByName( _rEvent.PropertyName ).Attributes;
     283             :                 }
     284             :             }
     285             :         }
     286           0 :         catch( const Exception& )
     287             :         {
     288             :             DBG_UNHANDLED_EXCEPTION();
     289             :         }
     290             :         const bool bTransReadOnly =
     291           0 :                     ( ( nPropertyAttributes & PropertyAttribute::READONLY ) != 0 )
     292           0 :                 ||  ( ( nPropertyAttributes & PropertyAttribute::TRANSIENT ) != 0 );
     293             : 
     294             :         // insert the new entry
     295             :         aPropertyPos = rObjectInfo.aProperties.insert( PropertiesInfo::value_type(
     296             :             _rEvent.PropertyName,
     297             :             PropertyInfo( bTransReadOnly )
     298           0 :         ) ).first;
     299           0 :         DBG_ASSERT(aPropertyPos != rObjectInfo.aProperties.end(), "OXUndoEnvironment::propertyChange : just inserted it ... why it's not there ?");
     300             :     }
     301             : 
     302           0 :     implSetModified();
     303             : 
     304             :     // now we have access to the cached info about the property affected
     305             :     // and are able to decide whether or not we need an undo action
     306             : 
     307             :     // no UNDO for transient/readonly properties
     308           0 :     if ( aPropertyPos->second.bIsReadonlyOrTransient )
     309           0 :         return;
     310             : 
     311             :     // give components with sub responsibilities a chance
     312           0 :     m_pImpl->m_aFormatNormalizer.notifyPropertyChange( _rEvent );
     313           0 :     m_pImpl->m_aConditionUpdater.notifyPropertyChange( _rEvent );
     314             : 
     315           0 :     aGuard.clear();
     316             :     // TODO: this is a potential race condition: two threads here could in theory
     317             :     // add their undo actions out-of-order
     318             : 
     319           0 :     SolarMutexGuard aSolarGuard;
     320           0 :     ORptUndoPropertyAction* pUndo = NULL;
     321             :     try
     322             :     {
     323           0 :         uno::Reference< report::XSection> xSection( xSet, uno::UNO_QUERY );
     324           0 :         if ( xSection.is() )
     325             :         {
     326           0 :             uno::Reference< report::XGroup> xGroup = xSection->getGroup();
     327           0 :             if ( xGroup.is() )
     328           0 :                 pUndo = new OUndoPropertyGroupSectionAction( m_pImpl->m_rModel, _rEvent, OGroupHelper::getMemberFunction( xSection ), xGroup );
     329             :             else
     330           0 :                 pUndo = new OUndoPropertyReportSectionAction( m_pImpl->m_rModel, _rEvent, OReportHelper::getMemberFunction( xSection ), xSection->getReportDefinition() );
     331           0 :         }
     332             :     }
     333           0 :     catch(const Exception&)
     334             :     {
     335             :         DBG_UNHANDLED_EXCEPTION();
     336             :     }
     337             : 
     338           0 :     if ( pUndo == NULL )
     339           0 :         pUndo = new ORptUndoPropertyAction( m_pImpl->m_rModel, _rEvent );
     340             : 
     341           0 :     m_pImpl->m_rModel.GetSdrUndoManager()->AddUndoAction( pUndo );
     342           0 :     pController->InvalidateAll();
     343             : }
     344             : 
     345           0 : ::std::vector< uno::Reference< container::XChild> >::const_iterator OXUndoEnvironment::getSection(const Reference<container::XChild>& _xContainer) const
     346             : {
     347           0 :     ::std::vector< uno::Reference< container::XChild> >::const_iterator aFind = m_pImpl->m_aSections.end();
     348           0 :     if ( _xContainer.is() )
     349             :     {
     350           0 :         aFind = ::std::find(m_pImpl->m_aSections.begin(),m_pImpl->m_aSections.end(),_xContainer);
     351             : 
     352           0 :         if ( aFind == m_pImpl->m_aSections.end() )
     353             :         {
     354           0 :             Reference<container::XChild> xParent(_xContainer->getParent(),uno::UNO_QUERY);
     355           0 :             aFind = getSection(xParent);
     356             :         }
     357             :     }
     358           0 :     return aFind;
     359             : }
     360             : // XContainerListener
     361             : 
     362           0 : void SAL_CALL OXUndoEnvironment::elementInserted(const ContainerEvent& evt) throw(uno::RuntimeException, std::exception)
     363             : {
     364           0 :     SolarMutexGuard aSolarGuard;
     365           0 :     ::osl::MutexGuard aGuard( m_pImpl->m_aMutex );
     366             : 
     367             :     // neues Object zum lauschen
     368           0 :     Reference< uno::XInterface >  xIface( evt.Element, UNO_QUERY );
     369           0 :     if ( !IsLocked() )
     370             :     {
     371           0 :         Reference< report::XReportComponent >  xReportComponent( xIface, UNO_QUERY );
     372           0 :         if ( xReportComponent.is() )
     373             :         {
     374           0 :             Reference< report::XSection > xContainer(evt.Source,uno::UNO_QUERY);
     375             : 
     376           0 :             ::std::vector< uno::Reference< container::XChild> >::const_iterator aFind = getSection(xContainer.get());
     377             : 
     378           0 :             if ( aFind != m_pImpl->m_aSections.end() )
     379             :             {
     380           0 :                 OUndoEnvLock aLock(*this);
     381             :                 try
     382             :                 {
     383           0 :                     OReportPage* pPage = m_pImpl->m_rModel.getPage(uno::Reference< report::XSection>(*aFind,uno::UNO_QUERY));
     384             :                     OSL_ENSURE(pPage,"No page could be found for section!");
     385           0 :                     if ( pPage )
     386           0 :                         pPage->insertObject(xReportComponent);
     387             :                 }
     388           0 :                 catch(uno::Exception&)
     389             :                 {
     390             :                     DBG_UNHANDLED_EXCEPTION();
     391           0 :                 }
     392             : 
     393           0 :             }
     394             :         }
     395             :         else
     396             :         {
     397           0 :             uno::Reference< report::XFunctions> xContainer(evt.Source,uno::UNO_QUERY);
     398           0 :             if ( xContainer.is() )
     399             :             {
     400           0 :                 m_pImpl->m_rModel.GetSdrUndoManager()->AddUndoAction(
     401           0 :                     new OUndoContainerAction( m_pImpl->m_rModel, rptui::Inserted, xContainer.get(),
     402           0 :                         xIface, RID_STR_UNDO_ADDFUNCTION ) );
     403           0 :             }
     404           0 :         }
     405             :     }
     406             : 
     407           0 :     AddElement(xIface);
     408             : 
     409           0 :     implSetModified();
     410           0 : }
     411             : 
     412             : 
     413           0 : void OXUndoEnvironment::implSetModified()
     414             : {
     415           0 :     m_pImpl->m_rModel.SetModified( true );
     416           0 : }
     417             : 
     418             : 
     419           0 : void SAL_CALL OXUndoEnvironment::elementReplaced(const ContainerEvent& evt) throw(uno::RuntimeException, std::exception)
     420             : {
     421           0 :     SolarMutexGuard aSolarGuard;
     422           0 :     ::osl::MutexGuard aGuard( m_pImpl->m_aMutex );
     423             : 
     424           0 :     Reference< XInterface >  xIface(evt.ReplacedElement,uno::UNO_QUERY);
     425             :     OSL_ENSURE(xIface.is(), "OXUndoEnvironment::elementReplaced: invalid container notification!");
     426           0 :     RemoveElement(xIface);
     427             : 
     428           0 :     xIface.set(evt.Element,uno::UNO_QUERY);
     429           0 :     AddElement(xIface);
     430             : 
     431           0 :     implSetModified();
     432           0 : }
     433             : 
     434             : 
     435           0 : void SAL_CALL OXUndoEnvironment::elementRemoved(const ContainerEvent& evt) throw(uno::RuntimeException, std::exception)
     436             : {
     437           0 :     SolarMutexGuard aSolarGuard;
     438           0 :     ::osl::MutexGuard aGuard( m_pImpl->m_aMutex );
     439             : 
     440           0 :     Reference< uno::XInterface >  xIface( evt.Element, UNO_QUERY );
     441           0 :     if ( !IsLocked() )
     442             :     {
     443           0 :         Reference< report::XSection > xContainer(evt.Source,uno::UNO_QUERY);
     444           0 :         ::std::vector< uno::Reference< container::XChild> >::const_iterator aFind = getSection(xContainer.get());
     445             : 
     446           0 :         Reference< report::XReportComponent >  xReportComponent( xIface, UNO_QUERY );
     447           0 :         if ( aFind != m_pImpl->m_aSections.end() && xReportComponent.is() )
     448             :         {
     449           0 :             OXUndoEnvironment::OUndoEnvLock aLock(*this);
     450             :             try
     451             :             {
     452           0 :                 OReportPage* pPage = m_pImpl->m_rModel.getPage(uno::Reference< report::XSection >( *aFind, uno::UNO_QUERY_THROW ) );
     453             :                 OSL_ENSURE( pPage, "OXUndoEnvironment::elementRemoved: no page for the section!" );
     454           0 :                 if ( pPage )
     455           0 :                     pPage->removeSdrObject(xReportComponent);
     456             :             }
     457           0 :             catch(const uno::Exception&)
     458             :             {
     459             :                 DBG_UNHANDLED_EXCEPTION();
     460           0 :             }
     461             :         }
     462             :         else
     463             :         {
     464           0 :             uno::Reference< report::XFunctions> xFunctions(evt.Source,uno::UNO_QUERY);
     465           0 :             if ( xFunctions.is() )
     466             :             {
     467           0 :                 m_pImpl->m_rModel.GetSdrUndoManager()->AddUndoAction( new OUndoContainerAction(
     468           0 :                     m_pImpl->m_rModel, rptui::Removed, xFunctions.get(), xIface, RID_STR_UNDO_ADDFUNCTION ) );
     469           0 :             }
     470           0 :         }
     471             :     }
     472             : 
     473           0 :     if ( xIface.is() )
     474           0 :         RemoveElement(xIface);
     475             : 
     476           0 :     implSetModified();
     477           0 : }
     478             : 
     479             : 
     480           0 : void SAL_CALL OXUndoEnvironment::modified( const EventObject& /*aEvent*/ ) throw (RuntimeException, std::exception)
     481             : {
     482           0 :     implSetModified();
     483           0 : }
     484             : 
     485             : 
     486           0 : void OXUndoEnvironment::AddSection(const Reference< report::XSection > & _xSection)
     487             : {
     488           0 :     OUndoEnvLock aLock(*this);
     489             :     try
     490             :     {
     491           0 :         uno::Reference<container::XChild> xChild = _xSection.get();
     492           0 :         uno::Reference<report::XGroup> xGroup(xChild->getParent(),uno::UNO_QUERY);
     493           0 :         m_pImpl->m_aSections.push_back(xChild);
     494           0 :         Reference< XInterface >  xInt(_xSection);
     495           0 :         AddElement(xInt);
     496             :     }
     497           0 :     catch(const uno::Exception&)
     498             :     {
     499             :         DBG_UNHANDLED_EXCEPTION();
     500           0 :     }
     501           0 : }
     502             : 
     503             : 
     504           0 : void OXUndoEnvironment::RemoveSection(const Reference< report::XSection > & _xSection)
     505             : {
     506           0 :     OUndoEnvLock aLock(*this);
     507             :     try
     508             :     {
     509           0 :         uno::Reference<container::XChild> xChild(_xSection.get());
     510           0 :         m_pImpl->m_aSections.erase(::std::remove(m_pImpl->m_aSections.begin(),m_pImpl->m_aSections.end(),
     511           0 :             xChild), m_pImpl->m_aSections.end());
     512           0 :         Reference< XInterface >  xInt(_xSection);
     513           0 :         RemoveElement(xInt);
     514             :     }
     515           0 :     catch(uno::Exception&){}
     516           0 : }
     517             : 
     518             : 
     519           0 : void OXUndoEnvironment::TogglePropertyListening(const Reference< XInterface > & Element)
     520             : {
     521             :     // am Container horchen
     522           0 :     Reference< XIndexAccess >  xContainer(Element, UNO_QUERY);
     523           0 :     if (xContainer.is())
     524             :     {
     525           0 :         Reference< XInterface > xInterface;
     526           0 :         sal_Int32 nCount = xContainer->getCount();
     527           0 :         for(sal_Int32 i = 0;i != nCount;++i)
     528             :         {
     529           0 :             xInterface.set(xContainer->getByIndex( i ),uno::UNO_QUERY);
     530           0 :             TogglePropertyListening(xInterface);
     531           0 :         }
     532             :     }
     533             : 
     534           0 :     Reference< XPropertySet >  xSet(Element, UNO_QUERY);
     535           0 :     if (xSet.is())
     536             :     {
     537           0 :         if (!m_pImpl->m_bReadOnly)
     538           0 :             xSet->addPropertyChangeListener( OUString(), this );
     539             :         else
     540           0 :             xSet->removePropertyChangeListener( OUString(), this );
     541           0 :     }
     542           0 : }
     543             : 
     544             : 
     545             : 
     546           0 : void OXUndoEnvironment::switchListening( const Reference< XIndexAccess >& _rxContainer, bool _bStartListening )
     547             : {
     548             :     OSL_PRECOND( _rxContainer.is(), "OXUndoEnvironment::switchListening: invalid container!" );
     549           0 :     if ( !_rxContainer.is() )
     550           0 :         return;
     551             : 
     552             :     try
     553             :     {
     554             :         // also handle all children of this element
     555           0 :         Reference< XInterface > xInterface;
     556           0 :         sal_Int32 nCount = _rxContainer->getCount();
     557           0 :         for(sal_Int32 i = 0;i != nCount;++i)
     558             :         {
     559           0 :             xInterface.set(_rxContainer->getByIndex( i ),uno::UNO_QUERY);
     560           0 :             if ( _bStartListening )
     561           0 :                 AddElement( xInterface );
     562             :             else
     563           0 :                 RemoveElement( xInterface );
     564             :         }
     565             : 
     566             :         // be notified of any changes in the container elements
     567           0 :         Reference< XContainer > xSimpleContainer( _rxContainer, UNO_QUERY );
     568           0 :         if ( xSimpleContainer.is() )
     569             :         {
     570           0 :             if ( _bStartListening )
     571           0 :                 xSimpleContainer->addContainerListener( this );
     572             :             else
     573           0 :                 xSimpleContainer->removeContainerListener( this );
     574           0 :         }
     575             :     }
     576           0 :     catch( const Exception& )
     577             :     {
     578             :         DBG_UNHANDLED_EXCEPTION();
     579             :     }
     580             : }
     581             : 
     582             : 
     583           0 : void OXUndoEnvironment::switchListening( const Reference< XInterface >& _rxObject, bool _bStartListening )
     584             : {
     585             :     OSL_PRECOND( _rxObject.is(), "OXUndoEnvironment::switchListening: how should I listen at a NULL object?" );
     586             : 
     587             :     try
     588             :     {
     589           0 :         if ( !m_pImpl->m_bReadOnly )
     590             :         {
     591           0 :             Reference< XPropertySet > xProps( _rxObject, UNO_QUERY );
     592           0 :             if ( xProps.is() )
     593             :             {
     594           0 :                 if ( _bStartListening )
     595           0 :                     xProps->addPropertyChangeListener( OUString(), this );
     596             :                 else
     597           0 :                     xProps->removePropertyChangeListener( OUString(), this );
     598           0 :             }
     599             :         }
     600             : 
     601           0 :         Reference< XModifyBroadcaster > xBroadcaster( _rxObject, UNO_QUERY );
     602           0 :         if ( xBroadcaster.is() )
     603             :         {
     604           0 :             if ( _bStartListening )
     605           0 :                 xBroadcaster->addModifyListener( this );
     606             :             else
     607           0 :                 xBroadcaster->removeModifyListener( this );
     608           0 :         }
     609             :     }
     610           0 :     catch( const Exception& )
     611             :     {
     612             :     }
     613           0 : }
     614             : 
     615             : 
     616           0 : void OXUndoEnvironment::AddElement(const Reference< XInterface >& _rxElement )
     617             : {
     618           0 :     if ( !IsLocked() )
     619           0 :         m_pImpl->m_aFormatNormalizer.notifyElementInserted( _rxElement );
     620             : 
     621             :     // if it's a container, start listening at all elements
     622           0 :     Reference< XIndexAccess > xContainer( _rxElement, UNO_QUERY );
     623           0 :     if ( xContainer.is() )
     624           0 :         switchListening( xContainer, true );
     625             : 
     626           0 :     switchListening( _rxElement, true );
     627           0 : }
     628             : 
     629             : 
     630           0 : void OXUndoEnvironment::RemoveElement(const Reference< XInterface >& _rxElement)
     631             : {
     632           0 :     uno::Reference<beans::XPropertySet> xProp(_rxElement,uno::UNO_QUERY);
     633           0 :     if (!m_pImpl->m_aPropertySetCache.empty())
     634           0 :         m_pImpl->m_aPropertySetCache.erase(xProp);
     635           0 :     switchListening( _rxElement, false );
     636             : 
     637           0 :     Reference< XIndexAccess > xContainer( _rxElement, UNO_QUERY );
     638           0 :     if ( xContainer.is() )
     639           0 :         switchListening( xContainer, false );
     640           0 : }
     641             : 
     642           0 : void OXUndoEnvironment::SetUndoMode(bool _bUndo)
     643             : {
     644           0 :     m_pImpl->m_bIsUndo = _bUndo;
     645           0 : }
     646             : 
     647           0 : bool OXUndoEnvironment::IsUndoMode() const
     648             : {
     649           0 :     return m_pImpl->m_bIsUndo;
     650             : }
     651             : 
     652           3 : } // rptui
     653             : 
     654             : 
     655             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11