LCOV - code coverage report
Current view: top level - libreoffice/reportdesign/source/ui/misc - RptUndo.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 163 0.0 %
Date: 2012-12-27 Functions: 0 43 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 "RptUndo.hxx"
      21             : #include "uistrings.hrc"
      22             : #include "rptui_slotid.hrc"
      23             : #include "UITools.hxx"
      24             : #include "UndoEnv.hxx"
      25             : 
      26             : #include <dbaccess/IController.hxx>
      27             : #include <com/sun/star/report/XSection.hpp>
      28             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      29             : 
      30             : #include <com/sun/star/awt/Point.hpp>
      31             : #include <com/sun/star/awt/Size.hpp>
      32             : #include <svx/unoshape.hxx>
      33             : #include <functional>
      34             : 
      35             : namespace rptui
      36             : {
      37             :     using namespace ::com::sun::star;
      38             :     using namespace uno;
      39             :     using namespace lang;
      40             :     using namespace script;
      41             :     using namespace beans;
      42             :     using namespace awt;
      43             :     using namespace util;
      44             :     using namespace container;
      45             :     using namespace report;
      46             : 
      47             : //----------------------------------------------------------------------------
      48             : namespace
      49             : {
      50           0 :     void lcl_collectElements(const uno::Reference< report::XSection >& _xSection,::std::vector< uno::Reference< drawing::XShape> >& _rControls)
      51             :     {
      52           0 :         if ( _xSection.is() )
      53             :         {
      54           0 :             sal_Int32 nCount = _xSection->getCount();
      55           0 :             _rControls.reserve(nCount);
      56           0 :             while ( nCount )
      57             :             {
      58           0 :                 uno::Reference< drawing::XShape> xShape(_xSection->getByIndex(nCount-1),uno::UNO_QUERY);
      59           0 :                 _rControls.push_back(xShape);
      60           0 :                 _xSection->remove(xShape);
      61           0 :                 --nCount;
      62           0 :             }
      63             :         }
      64           0 :     }
      65             :     //----------------------------------------------------------------------------
      66           0 :     void lcl_insertElements(const uno::Reference< report::XSection >& _xSection,const ::std::vector< uno::Reference< drawing::XShape> >& _aControls)
      67             :     {
      68           0 :         if ( _xSection.is() )
      69             :         {
      70           0 :             ::std::vector< uno::Reference< drawing::XShape> >::const_reverse_iterator aIter = _aControls.rbegin();
      71           0 :             ::std::vector< uno::Reference< drawing::XShape> >::const_reverse_iterator aEnd = _aControls.rend();
      72           0 :             for (; aIter != aEnd; ++aIter)
      73             :             {
      74             :                 try
      75             :                 {
      76           0 :                     const awt::Point aPos = (*aIter)->getPosition();
      77           0 :                     const awt::Size aSize = (*aIter)->getSize();
      78           0 :                     _xSection->add(*aIter);
      79           0 :                     (*aIter)->setPosition( aPos );
      80           0 :                     (*aIter)->setSize( aSize );
      81             :                 }
      82           0 :                 catch(const uno::Exception&)
      83             :                 {
      84             :                     OSL_FAIL("lcl_insertElements:Exception caught!");
      85             :                 }
      86             :             }
      87             :         }
      88           0 :     }
      89             :     //----------------------------------------------------------------------------
      90           0 :     void lcl_setValues(const uno::Reference< report::XSection >& _xSection,const ::std::vector< ::std::pair< ::rtl::OUString ,uno::Any> >& _aValues)
      91             :     {
      92           0 :         if ( _xSection.is() )
      93             :         {
      94           0 :             ::std::vector< ::std::pair< ::rtl::OUString ,uno::Any> >::const_iterator aIter = _aValues.begin();
      95           0 :             ::std::vector< ::std::pair< ::rtl::OUString ,uno::Any> >::const_iterator aEnd = _aValues.end();
      96           0 :             for (; aIter != aEnd; ++aIter)
      97             :             {
      98             :                 try
      99             :                 {
     100           0 :                     _xSection->setPropertyValue(aIter->first,aIter->second);
     101             :                 }
     102           0 :                 catch(const uno::Exception&)
     103             :                 {
     104             :                     OSL_FAIL("lcl_setValues:Exception caught!");
     105             :                 }
     106             :             }
     107             :         }
     108           0 :     }
     109             : }
     110             : //----------------------------------------------------------------------------
     111           0 : TYPEINIT1( OSectionUndo,         OCommentUndoAction );
     112             : DBG_NAME(rpt_OSectionUndo)
     113             : //----------------------------------------------------------------------------
     114           0 : OSectionUndo::OSectionUndo(OReportModel& _rMod
     115             :                            ,sal_uInt16 _nSlot
     116             :                            ,Action _eAction
     117             :                            ,sal_uInt16 nCommentID)
     118             : : OCommentUndoAction(_rMod,nCommentID)
     119             : ,m_eAction(_eAction)
     120             : ,m_nSlot(_nSlot)
     121           0 : ,m_bInserted(false)
     122             : {
     123             :     DBG_CTOR(rpt_OSectionUndo,NULL);
     124           0 : }
     125             : // -----------------------------------------------------------------------------
     126           0 : OSectionUndo::~OSectionUndo()
     127             : {
     128           0 :     if ( !m_bInserted )
     129             :     {
     130           0 :         OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
     131           0 :         ::std::vector< uno::Reference< drawing::XShape> >::iterator aEnd = m_aControls.end();
     132           0 :         for (::std::vector< uno::Reference< drawing::XShape> >::iterator aIter = m_aControls.begin(); aIter != aEnd; ++aIter)
     133             :         {
     134           0 :             uno::Reference< drawing::XShape> xShape = *aIter;
     135           0 :             rEnv.RemoveElement(xShape);
     136             : 
     137             : #if OSL_DEBUG_LEVEL > 0
     138             :             SvxShape* pShape = SvxShape::getImplementation( xShape );
     139             :             SdrObject* pObject = pShape ? pShape->GetSdrObject() : NULL;
     140             :             OSL_ENSURE( pShape && pShape->HasSdrObjectOwnership() && pObject && !pObject->IsInserted(),
     141             :                 "OSectionUndo::~OSectionUndo: inconsistency in the shape/object ownership!" );
     142             : #endif
     143             :             try
     144             :             {
     145           0 :                 comphelper::disposeComponent(xShape);
     146             :             }
     147           0 :             catch(const uno::Exception &)
     148             :             {
     149             :                 OSL_FAIL("Exception caught!");
     150             :             }
     151           0 :         }
     152             :     }
     153             :     DBG_DTOR(rpt_OSectionUndo,NULL);
     154           0 : }
     155             : // -----------------------------------------------------------------------------
     156           0 : void OSectionUndo::collectControls(const uno::Reference< report::XSection >& _xSection)
     157             : {
     158           0 :     m_aControls.clear();
     159             :     try
     160             :     {
     161             :         // copy all properties for restoring
     162           0 :         uno::Reference< beans::XPropertySetInfo> xInfo = _xSection->getPropertySetInfo();
     163           0 :         uno::Sequence< beans::Property> aSeq = xInfo->getProperties();
     164           0 :         const beans::Property* pIter = aSeq.getConstArray();
     165           0 :         const beans::Property* pEnd  = pIter + aSeq.getLength();
     166           0 :         for(;pIter != pEnd;++pIter)
     167             :         {
     168           0 :             if ( 0 == (pIter->Attributes & beans::PropertyAttribute::READONLY) )
     169           0 :                 m_aValues.push_back(::std::pair< ::rtl::OUString ,uno::Any>(pIter->Name,_xSection->getPropertyValue(pIter->Name)));
     170             :         }
     171           0 :         lcl_collectElements(_xSection,m_aControls);
     172             :     }
     173           0 :     catch(uno::Exception&)
     174             :     {
     175             :     }
     176           0 : }
     177             : //----------------------------------------------------------------------------
     178           0 : void OSectionUndo::Undo()
     179             : {
     180             :     try
     181             :     {
     182           0 :         switch ( m_eAction )
     183             :         {
     184             :         case Inserted:
     185           0 :             implReRemove();
     186           0 :             break;
     187             : 
     188             :         case Removed:
     189           0 :             implReInsert();
     190           0 :             break;
     191             :         }
     192             :     }
     193           0 :     catch( const Exception& )
     194             :     {
     195             :         OSL_FAIL( "OSectionUndo::Undo: caught an exception!" );
     196             :     }
     197           0 : }
     198             : //----------------------------------------------------------------------------
     199           0 : void OSectionUndo::Redo()
     200             : {
     201             :     try
     202             :     {
     203           0 :         switch ( m_eAction )
     204             :         {
     205             :         case Inserted:
     206           0 :             implReInsert();
     207           0 :             break;
     208             : 
     209             :         case Removed:
     210           0 :             implReRemove();
     211           0 :             break;
     212             :         }
     213             :     }
     214           0 :     catch( const Exception& )
     215             :     {
     216             :         OSL_FAIL( "OSectionUndo::Redo: caught an exception!" );
     217             :     }
     218           0 : }
     219             : //----------------------------------------------------------------------------
     220           0 : TYPEINIT1( OReportSectionUndo,         OSectionUndo );
     221             : //----------------------------------------------------------------------------
     222           0 : OReportSectionUndo::OReportSectionUndo(OReportModel& _rMod,sal_uInt16 _nSlot
     223             :                                        ,::std::mem_fun_t< uno::Reference< report::XSection >
     224             :                                             ,OReportHelper> _pMemberFunction
     225             :                                        ,const uno::Reference< report::XReportDefinition >& _xReport
     226             :                                        ,Action _eAction
     227             :                                        ,sal_uInt16 nCommentID)
     228             : : OSectionUndo(_rMod,_nSlot,_eAction,nCommentID)
     229             : ,m_aReportHelper(_xReport)
     230           0 : ,m_pMemberFunction(_pMemberFunction)
     231             : {
     232           0 :     if( m_eAction == Removed )
     233           0 :         collectControls(m_pMemberFunction(&m_aReportHelper));
     234           0 : }
     235             : // -----------------------------------------------------------------------------
     236           0 : OReportSectionUndo::~OReportSectionUndo()
     237             : {
     238           0 : }
     239             : //----------------------------------------------------------------------------
     240           0 : void OReportSectionUndo::implReInsert( )
     241             : {
     242           0 :     const uno::Sequence< beans::PropertyValue > aArgs;
     243           0 :     m_pController->executeChecked(m_nSlot,aArgs);
     244           0 :     uno::Reference< report::XSection > xSection = m_pMemberFunction(&m_aReportHelper);
     245           0 :     lcl_insertElements(xSection,m_aControls);
     246           0 :     lcl_setValues(xSection,m_aValues);
     247           0 :     m_bInserted = true;
     248           0 : }
     249             : //----------------------------------------------------------------------------
     250           0 : void OReportSectionUndo::implReRemove( )
     251             : {
     252           0 :     if( m_eAction == Removed )
     253           0 :         collectControls(m_pMemberFunction(&m_aReportHelper));
     254           0 :     const uno::Sequence< beans::PropertyValue > aArgs;
     255           0 :     m_pController->executeChecked(m_nSlot,aArgs);
     256           0 :     m_bInserted = false;
     257           0 : }
     258             : //----------------------------------------------------------------------------
     259           0 : TYPEINIT1( OGroupSectionUndo,         OSectionUndo );
     260             : //----------------------------------------------------------------------------
     261           0 : OGroupSectionUndo::OGroupSectionUndo(OReportModel& _rMod,sal_uInt16 _nSlot
     262             :                                        ,::std::mem_fun_t< uno::Reference< report::XSection >
     263             :                                             ,OGroupHelper> _pMemberFunction
     264             :                                        ,const uno::Reference< report::XGroup >& _xGroup
     265             :                                        ,Action _eAction
     266             :                                        ,sal_uInt16 nCommentID)
     267             : : OSectionUndo(_rMod,_nSlot,_eAction,nCommentID)
     268             : ,m_aGroupHelper(_xGroup)
     269           0 : ,m_pMemberFunction(_pMemberFunction)
     270             : {
     271           0 :     if( m_eAction == Removed )
     272             :     {
     273           0 :         uno::Reference< report::XSection > xSection = m_pMemberFunction(&m_aGroupHelper);
     274           0 :         if ( xSection.is() )
     275           0 :             m_sName = xSection->getName();
     276           0 :         collectControls(xSection);
     277             :     }
     278           0 : }
     279             : //----------------------------------------------------------------------------
     280           0 : rtl::OUString OGroupSectionUndo::GetComment() const
     281             : {
     282           0 :     if ( m_sName.isEmpty() )
     283             :     {
     284             :         try
     285             :         {
     286           0 :             uno::Reference< report::XSection > xSection = const_cast<OGroupSectionUndo*>(this)->m_pMemberFunction(&const_cast<OGroupSectionUndo*>(this)->m_aGroupHelper);
     287             : 
     288           0 :             if ( xSection.is() )
     289           0 :                 m_sName = xSection->getName();
     290             :         }
     291           0 :         catch (const uno::Exception&)
     292             :         {
     293             :         }
     294             :     }
     295           0 :     return m_strComment + m_sName;
     296             : }
     297             : //----------------------------------------------------------------------------
     298           0 : void OGroupSectionUndo::implReInsert( )
     299             : {
     300           0 :     uno::Sequence< beans::PropertyValue > aArgs(2);
     301             : 
     302           0 :     aArgs[0].Name = SID_GROUPHEADER_WITHOUT_UNDO == m_nSlot? PROPERTY_HEADERON : PROPERTY_FOOTERON;
     303           0 :     aArgs[0].Value <<= sal_True;
     304           0 :     aArgs[1].Name = PROPERTY_GROUP;
     305           0 :     aArgs[1].Value <<= m_aGroupHelper.getGroup();
     306           0 :     m_pController->executeChecked(m_nSlot,aArgs);
     307             : 
     308           0 :     uno::Reference< report::XSection > xSection = m_pMemberFunction(&m_aGroupHelper);
     309           0 :     lcl_insertElements(xSection,m_aControls);
     310           0 :     lcl_setValues(xSection,m_aValues);
     311           0 :     m_bInserted = true;
     312           0 : }
     313             : //----------------------------------------------------------------------------
     314           0 : void OGroupSectionUndo::implReRemove( )
     315             : {
     316           0 :     if( m_eAction == Removed )
     317           0 :         collectControls(m_pMemberFunction(&m_aGroupHelper));
     318             : 
     319           0 :     uno::Sequence< beans::PropertyValue > aArgs(2);
     320             : 
     321           0 :     aArgs[0].Name = SID_GROUPHEADER_WITHOUT_UNDO == m_nSlot? PROPERTY_HEADERON : PROPERTY_FOOTERON;
     322           0 :     aArgs[0].Value <<= sal_False;
     323           0 :     aArgs[1].Name = PROPERTY_GROUP;
     324           0 :     aArgs[1].Value <<= m_aGroupHelper.getGroup();
     325             : 
     326           0 :     m_pController->executeChecked(m_nSlot,aArgs);
     327           0 :     m_bInserted = false;
     328           0 : }
     329             : //----------------------------------------------------------------------------
     330           0 : TYPEINIT1( OGroupUndo,         OCommentUndoAction );
     331             : //----------------------------------------------------------------------------
     332           0 : OGroupUndo::OGroupUndo(OReportModel& _rMod
     333             :                        ,sal_uInt16 nCommentID
     334             :                        ,Action  _eAction
     335             :                        ,const uno::Reference< report::XGroup>& _xGroup
     336             :                        ,const uno::Reference< report::XReportDefinition >& _xReportDefinition)
     337             : : OCommentUndoAction(_rMod,nCommentID)
     338             : ,m_xGroup(_xGroup)
     339             : ,m_xReportDefinition(_xReportDefinition)
     340           0 : ,m_eAction(_eAction)
     341             : {
     342           0 :     m_nLastPosition = getPositionInIndexAccess(m_xReportDefinition->getGroups().get(),m_xGroup);
     343           0 : }
     344             : //----------------------------------------------------------------------------
     345           0 : void OGroupUndo::implReInsert( )
     346             : {
     347             :     try
     348             :     {
     349           0 :         m_xReportDefinition->getGroups()->insertByIndex(m_nLastPosition,uno::makeAny(m_xGroup));
     350             :     }
     351           0 :     catch(uno::Exception&)
     352             :     {
     353             :         OSL_FAIL("Exception catched while undoing remove group");
     354             :     }
     355           0 : }
     356             : //----------------------------------------------------------------------------
     357           0 : void OGroupUndo::implReRemove( )
     358             : {
     359             :     try
     360             :     {
     361           0 :         m_xReportDefinition->getGroups()->removeByIndex(m_nLastPosition);
     362             :     }
     363           0 :     catch(uno::Exception&)
     364             :     {
     365             :         OSL_FAIL("Exception catched while redoing remove group");
     366             :     }
     367           0 : }
     368             : //----------------------------------------------------------------------------
     369           0 : void OGroupUndo::Undo()
     370             : {
     371           0 :     switch ( m_eAction )
     372             :     {
     373             :     case Inserted:
     374           0 :         implReRemove();
     375           0 :         break;
     376             : 
     377             :     case Removed:
     378           0 :         implReInsert();
     379           0 :         break;
     380             :     }
     381             : 
     382           0 : }
     383             : //----------------------------------------------------------------------------
     384           0 : void OGroupUndo::Redo()
     385             : {
     386           0 :     switch ( m_eAction )
     387             :     {
     388             :     case Inserted:
     389           0 :         implReInsert();
     390           0 :         break;
     391             : 
     392             :     case Removed:
     393           0 :         implReRemove();
     394           0 :         break;
     395             :     }
     396           0 : }
     397             : //----------------------------------------------------------------------------
     398             : //============================================================================
     399             : } // rptui
     400             : //============================================================================
     401             : 
     402             : 
     403             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10