LCOV - code coverage report
Current view: top level - reportdesign/source/core/sdr - UndoActions.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 167 0.0 %
Date: 2014-04-11 Functions: 0 35 0.0 %
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             : 
      20             : #include "UndoActions.hxx"
      21             : #include "UndoEnv.hxx"
      22             : #include "formatnormalizer.hxx"
      23             : #include "conditionupdater.hxx"
      24             : #include "corestrings.hrc"
      25             : #include "rptui_slotid.hrc"
      26             : #include "RptDef.hxx"
      27             : #include "ModuleHelper.hxx"
      28             : #include "RptObject.hxx"
      29             : #include "RptPage.hxx"
      30             : #include "RptResId.hrc"
      31             : #include "RptModel.hxx"
      32             : 
      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/PropertyAttribute.hpp>
      37             : #include <com/sun/star/util/XModifyBroadcaster.hpp>
      38             : 
      39             : #include <connectivity/dbtools.hxx>
      40             : #include <svl/smplhint.hxx>
      41             : #include <tools/diagnose_ex.h>
      42             : #include <comphelper/stl_types.hxx>
      43             : #include <vcl/svapp.hxx>
      44             : #include <dbaccess/dbsubcomponentcontroller.hxx>
      45             : #include <svx/unoshape.hxx>
      46             : #include <osl/mutex.hxx>
      47             : 
      48             : namespace rptui
      49             : {
      50             :     using namespace ::com::sun::star;
      51             :     using namespace uno;
      52             :     using namespace lang;
      53             :     using namespace script;
      54             :     using namespace beans;
      55             :     using namespace awt;
      56             :     using namespace util;
      57             :     using namespace container;
      58             :     using namespace report;
      59             : 
      60           0 : ::std::mem_fun_t<uno::Reference<report::XSection> , OGroupHelper> OGroupHelper::getMemberFunction(const Reference< XSection >& _xSection)
      61             : {
      62           0 :     ::std::mem_fun_t<uno::Reference<report::XSection> , OGroupHelper> pMemFunSection = ::std::mem_fun(&OGroupHelper::getFooter);
      63           0 :     uno::Reference< report::XGroup> xGroup = _xSection->getGroup();
      64           0 :     if ( xGroup->getHeaderOn() && xGroup->getHeader() == _xSection )
      65           0 :         pMemFunSection = ::std::mem_fun(&OGroupHelper::getHeader);
      66           0 :     return pMemFunSection;
      67             : }
      68             : 
      69           0 : ::std::mem_fun_t<uno::Reference<report::XSection> , OReportHelper> OReportHelper::getMemberFunction(const Reference< XSection >& _xSection)
      70             : {
      71           0 :     uno::Reference< report::XReportDefinition> xReportDefinition(_xSection->getReportDefinition());
      72           0 :     ::std::mem_fun_t<uno::Reference<report::XSection> , OReportHelper> pMemFunSection = ::std::mem_fun(&OReportHelper::getReportFooter);
      73           0 :     if ( xReportDefinition->getReportHeaderOn() && xReportDefinition->getReportHeader() == _xSection )
      74           0 :         pMemFunSection = ::std::mem_fun(&OReportHelper::getReportHeader);
      75           0 :     else if ( xReportDefinition->getPageHeaderOn() && xReportDefinition->getPageHeader() == _xSection )
      76           0 :         pMemFunSection = ::std::mem_fun(&OReportHelper::getPageHeader);
      77           0 :     else if ( xReportDefinition->getPageFooterOn() && xReportDefinition->getPageFooter() == _xSection )
      78           0 :         pMemFunSection = ::std::mem_fun(&OReportHelper::getPageFooter);
      79           0 :     else if ( xReportDefinition->getDetail() == _xSection )
      80           0 :         pMemFunSection = ::std::mem_fun(&OReportHelper::getDetail);
      81           0 :     return pMemFunSection;
      82             : }
      83             : 
      84             : 
      85           0 : TYPEINIT1( OCommentUndoAction,          SdrUndoAction );
      86             : 
      87           0 : OCommentUndoAction::OCommentUndoAction(SdrModel& _rMod,sal_uInt16 nCommentID)
      88           0 :     :SdrUndoAction(_rMod)
      89             : {
      90           0 :     m_pController = static_cast< OReportModel& >( _rMod ).getController();
      91           0 :     if ( nCommentID )
      92           0 :         m_strComment = ModuleRes(nCommentID);
      93           0 : }
      94           0 : OCommentUndoAction::~OCommentUndoAction()
      95             : {
      96           0 : }
      97             : 
      98           0 : void OCommentUndoAction::Undo()
      99             : {
     100           0 : }
     101             : 
     102           0 : void OCommentUndoAction::Redo()
     103             : {
     104           0 : }
     105             : 
     106           0 : OUndoContainerAction::OUndoContainerAction(SdrModel& _rMod
     107             :                                              ,Action _eAction
     108             :                                              ,const uno::Reference< container::XIndexContainer > _xContainer
     109             :                                              ,const Reference< XInterface > & xElem
     110             :                                              ,sal_uInt16 _nCommentId)
     111             :                       :OCommentUndoAction(_rMod,_nCommentId)
     112             :                       ,m_xElement(xElem)
     113             :                       ,m_xContainer(_xContainer)
     114           0 :                          ,m_eAction( _eAction )
     115             : {
     116             :     // normalize
     117           0 :     if ( m_eAction == Removed )
     118             :         // we now own the element
     119           0 :         m_xOwnElement = m_xElement;
     120           0 : }
     121             : 
     122           0 : OUndoContainerAction::~OUndoContainerAction()
     123             : {
     124             :     // if we own the object ....
     125           0 :     Reference< XComponent > xComp( m_xOwnElement, UNO_QUERY );
     126           0 :     if ( xComp.is() )
     127             :     {
     128             :         // and the object does not have a parent
     129           0 :         Reference< XChild >  xChild( m_xOwnElement, UNO_QUERY );
     130           0 :         if ( xChild.is() && !xChild->getParent().is() )
     131             :         {
     132           0 :             OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
     133           0 :             rEnv.RemoveElement( m_xOwnElement );
     134             : 
     135             : #if OSL_DEBUG_LEVEL > 0
     136             :             SvxShape* pShape = SvxShape::getImplementation( xChild );
     137             :             SdrObject* pObject = pShape ? pShape->GetSdrObject() : NULL;
     138             :             OSL_ENSURE( pObject ? pShape->HasSdrObjectOwnership() && !pObject->IsInserted() : true ,
     139             :                 "OUndoContainerAction::~OUndoContainerAction: inconsistency in the shape/object ownership!" );
     140             : #endif
     141             :             // -> dispose it
     142             :             try
     143             :             {
     144           0 :                 comphelper::disposeComponent( xComp );
     145             :             }
     146           0 :             catch ( const uno::Exception& )
     147             :             {
     148             :                 DBG_UNHANDLED_EXCEPTION();
     149             :             }
     150           0 :         }
     151           0 :     }
     152           0 : }
     153             : 
     154           0 : void OUndoContainerAction::implReInsert( ) SAL_THROW( ( Exception ) )
     155             : {
     156           0 :     if ( m_xContainer.is() )
     157             :     {
     158             :         // insert the element
     159           0 :         m_xContainer->insertByIndex( m_xContainer->getCount(),uno::makeAny(m_xElement) );
     160             :     }
     161             :     // we don't own the object anymore
     162           0 :     m_xOwnElement = NULL;
     163           0 : }
     164             : 
     165             : 
     166           0 : void OUndoContainerAction::implReRemove( ) SAL_THROW( ( Exception ) )
     167             : {
     168           0 :     OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
     169             :     try
     170             :     {
     171           0 :         OXUndoEnvironment::OUndoEnvLock aLock(rEnv);
     172           0 :         if ( m_xContainer.is() )
     173             :         {
     174           0 :             const sal_Int32 nCount = m_xContainer->getCount();
     175           0 :             for (sal_Int32 i = 0; i < nCount; ++i)
     176             :             {
     177           0 :                 uno::Reference< uno::XInterface> xObj(m_xContainer->getByIndex(i),uno::UNO_QUERY);
     178           0 :                 if ( xObj == m_xElement )
     179             :                 {
     180           0 :                     m_xContainer->removeByIndex( i );
     181           0 :                     break;
     182             :                 }
     183           0 :             }
     184           0 :         }
     185             :     }
     186           0 :     catch(uno::Exception&){}
     187             :     // from now on, we own this object
     188           0 :     m_xOwnElement = m_xElement;
     189           0 : }
     190             : 
     191             : 
     192           0 : void OUndoContainerAction::Undo()
     193             : {
     194           0 :     if ( m_xElement.is() )
     195             :     {
     196             :         // prevents that an undo action will be created for elementInserted
     197             :         try
     198             :         {
     199           0 :             switch ( m_eAction )
     200             :             {
     201             :             case Inserted:
     202           0 :                 implReRemove();
     203           0 :                 break;
     204             : 
     205             :             case Removed:
     206           0 :                 implReInsert();
     207           0 :                 break;
     208             :             default:
     209             :                 OSL_FAIL("Illegal case value");
     210           0 :                 break;
     211             :             }
     212             :         }
     213           0 :         catch( const Exception& )
     214             :         {
     215             :             OSL_FAIL( "OUndoContainerAction::Undo: caught an exception!" );
     216             :         }
     217             :     }
     218           0 : }
     219             : 
     220             : 
     221           0 : void OUndoContainerAction::Redo()
     222             : {
     223           0 :     if ( m_xElement.is() )
     224             :     {
     225             :         try
     226             :         {
     227           0 :             switch ( m_eAction )
     228             :             {
     229             :             case Inserted:
     230           0 :                 implReInsert();
     231           0 :                 break;
     232             : 
     233             :             case Removed:
     234           0 :                 implReRemove();
     235           0 :                 break;
     236             :             default:
     237             :                 OSL_FAIL("Illegal case value");
     238           0 :                 break;
     239             :             }
     240             :         }
     241           0 :         catch( const Exception& )
     242             :         {
     243             :             OSL_FAIL( "OUndoContainerAction::Redo: caught an exception!" );
     244             :         }
     245             :     }
     246           0 : }
     247             : 
     248           0 : OUndoGroupSectionAction::OUndoGroupSectionAction(SdrModel& _rMod
     249             :                                              ,Action _eAction
     250             :                                              ,::std::mem_fun_t< uno::Reference< report::XSection >
     251             :                                                     ,OGroupHelper> _pMemberFunction
     252             :                                              ,const uno::Reference< report::XGroup >& _xGroup
     253             :                                              ,const Reference< XInterface > & xElem
     254             :                                              ,sal_uInt16 _nCommentId)
     255             : :OUndoContainerAction(_rMod,_eAction,NULL,xElem,_nCommentId)
     256             : ,m_aGroupHelper(_xGroup)
     257           0 : ,m_pMemberFunction(_pMemberFunction)
     258             : {
     259           0 : }
     260             : 
     261           0 : void OUndoGroupSectionAction::implReInsert( ) SAL_THROW( ( Exception ) )
     262             : {
     263           0 :     OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
     264             :     try
     265             :     {
     266           0 :         OXUndoEnvironment::OUndoEnvLock aLock(rEnv);
     267           0 :         uno::Reference< report::XSection> xSection = m_pMemberFunction(&m_aGroupHelper);
     268           0 :         if ( xSection.is() )
     269           0 :             xSection->add(uno::Reference< drawing::XShape>(m_xElement,uno::UNO_QUERY));
     270             :     }
     271           0 :     catch(uno::Exception&){}
     272             : 
     273             :     // we don't own the object anymore
     274           0 :     m_xOwnElement = NULL;
     275           0 : }
     276             : 
     277             : 
     278           0 : void OUndoGroupSectionAction::implReRemove( ) SAL_THROW( ( Exception ) )
     279             : {
     280           0 :         OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
     281             :     try
     282             :     {
     283           0 :         OXUndoEnvironment::OUndoEnvLock aLock(rEnv);
     284           0 :         uno::Reference< report::XSection> xSection = m_pMemberFunction(&m_aGroupHelper);
     285           0 :         if ( xSection.is() )
     286           0 :             xSection->remove(uno::Reference< drawing::XShape>(m_xElement,uno::UNO_QUERY));
     287             :     }
     288           0 :     catch(uno::Exception&){}
     289             : 
     290             :     // from now on, we own this object
     291           0 :     m_xOwnElement = m_xElement;
     292           0 : }
     293             : 
     294           0 : OUndoReportSectionAction::OUndoReportSectionAction(SdrModel& _rMod
     295             :                                              ,Action _eAction
     296             :                                              ,::std::mem_fun_t< uno::Reference< report::XSection >
     297             :                                                 ,OReportHelper> _pMemberFunction
     298             :                                              ,const uno::Reference< report::XReportDefinition >& _xReport
     299             :                                              ,const Reference< XInterface > & xElem
     300             :                                              ,sal_uInt16 _nCommentId)
     301             : :OUndoContainerAction(_rMod,_eAction,NULL,xElem,_nCommentId)
     302             : ,m_aReportHelper(_xReport)
     303           0 : ,m_pMemberFunction(_pMemberFunction)
     304             : {
     305           0 : }
     306             : 
     307           0 : void OUndoReportSectionAction::implReInsert( ) SAL_THROW( ( Exception ) )
     308             : {
     309           0 :     OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
     310             :     try
     311             :     {
     312           0 :         OXUndoEnvironment::OUndoEnvLock aLock(rEnv);
     313           0 :         uno::Reference< report::XSection> xSection = m_pMemberFunction(&m_aReportHelper);
     314           0 :         if ( xSection.is() )
     315             :         {
     316           0 :             uno::Reference< drawing::XShape> xShape(m_xElement,uno::UNO_QUERY_THROW);
     317           0 :             awt::Point aPos = xShape->getPosition();
     318           0 :             awt::Size aSize = xShape->getSize();
     319           0 :             xSection->add(xShape);
     320           0 :             xShape->setPosition( aPos );
     321           0 :             xShape->setSize( aSize );
     322           0 :         }
     323             :     }
     324           0 :     catch(uno::Exception&){}
     325             :     // we don't own the object anymore
     326           0 :     m_xOwnElement = NULL;
     327           0 : }
     328             : 
     329             : 
     330           0 : void OUndoReportSectionAction::implReRemove( ) SAL_THROW( ( Exception ) )
     331             : {
     332           0 :     OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
     333             :     try
     334             :     {
     335           0 :         OXUndoEnvironment::OUndoEnvLock aLock(rEnv);
     336           0 :         uno::Reference< report::XSection> xSection = m_pMemberFunction(&m_aReportHelper);
     337           0 :         if ( xSection.is() )
     338           0 :             xSection->remove(uno::Reference< drawing::XShape>(m_xElement,uno::UNO_QUERY));
     339             :     }
     340           0 :     catch(uno::Exception&){}
     341             :     // from now on, we own this object
     342           0 :     m_xOwnElement = m_xElement;
     343           0 : }
     344             : 
     345           0 : ORptUndoPropertyAction::ORptUndoPropertyAction(SdrModel& rNewMod, const PropertyChangeEvent& evt)
     346             :                      :OCommentUndoAction(rNewMod,0)
     347             :                      ,m_xObj(evt.Source, UNO_QUERY)
     348             :                      ,m_aPropertyName(evt.PropertyName)
     349             :                      ,m_aNewValue(evt.NewValue)
     350           0 :                      ,m_aOldValue(evt.OldValue)
     351             : {
     352           0 : }
     353             : 
     354           0 : void ORptUndoPropertyAction::Undo()
     355             : {
     356           0 :     setProperty(sal_True);
     357           0 : }
     358             : 
     359             : 
     360           0 : void ORptUndoPropertyAction::Redo()
     361             : {
     362           0 :     setProperty(sal_False);
     363           0 : }
     364             : 
     365           0 : Reference< XPropertySet> ORptUndoPropertyAction::getObject()
     366             : {
     367           0 :     return m_xObj;
     368             : }
     369             : 
     370           0 : void ORptUndoPropertyAction::setProperty(sal_Bool _bOld)
     371             : {
     372           0 :     Reference< XPropertySet> xObj = getObject();
     373             : 
     374           0 :     if (xObj.is() )
     375             :     {
     376             :         try
     377             :         {
     378           0 :             xObj->setPropertyValue( m_aPropertyName, _bOld ? m_aOldValue : m_aNewValue );
     379             :         }
     380           0 :         catch( const Exception& )
     381             :         {
     382             :             OSL_FAIL( "ORptUndoPropertyAction::Redo: caught an exception!" );
     383             :         }
     384           0 :     }
     385           0 : }
     386             : 
     387           0 : OUString ORptUndoPropertyAction::GetComment() const
     388             : {
     389           0 :     OUString aStr( ModuleRes(RID_STR_UNDO_PROPERTY).toString() );
     390             : 
     391           0 :     return aStr.replaceFirst("#", m_aPropertyName);
     392             : }
     393             : 
     394           0 : OUndoPropertyGroupSectionAction::OUndoPropertyGroupSectionAction(SdrModel& _rMod
     395             :                                              ,const PropertyChangeEvent& evt
     396             :                                              ,::std::mem_fun_t< uno::Reference< report::XSection >
     397             :                                                     ,OGroupHelper> _pMemberFunction
     398             :                                              ,const uno::Reference< report::XGroup >& _xGroup
     399             :                                              )
     400             : :ORptUndoPropertyAction(_rMod,evt)
     401             : ,m_aGroupHelper(_xGroup)
     402           0 : ,m_pMemberFunction(_pMemberFunction)
     403             : {
     404           0 : }
     405             : 
     406           0 : Reference< XPropertySet> OUndoPropertyGroupSectionAction::getObject()
     407             : {
     408           0 :     return m_pMemberFunction(&m_aGroupHelper).get();
     409             : }
     410             : 
     411           0 : OUndoPropertyReportSectionAction::OUndoPropertyReportSectionAction(SdrModel& _rMod
     412             :                                              ,const PropertyChangeEvent& evt
     413             :                                              ,::std::mem_fun_t< uno::Reference< report::XSection >
     414             :                                                 ,OReportHelper> _pMemberFunction
     415             :                                              ,const uno::Reference< report::XReportDefinition >& _xReport
     416             :                                              )
     417             : :ORptUndoPropertyAction(_rMod,evt)
     418             : ,m_aReportHelper(_xReport)
     419           0 : ,m_pMemberFunction(_pMemberFunction)
     420             : {
     421           0 : }
     422             : 
     423           0 : Reference< XPropertySet> OUndoPropertyReportSectionAction::getObject()
     424             : {
     425           0 :     return m_pMemberFunction(&m_aReportHelper).get();
     426             : }
     427             : 
     428             : } // rptui
     429             : 
     430             : 
     431             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10