LCOV - code coverage report
Current view: top level - reportdesign/source/ui/misc - RptUndo.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 163 0.0 %
Date: 2012-08-25 Functions: 0 43 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "RptUndo.hxx"
      30                 :            : #include "uistrings.hrc"
      31                 :            : #include "rptui_slotid.hrc"
      32                 :            : #include "UITools.hxx"
      33                 :            : #include "UndoEnv.hxx"
      34                 :            : 
      35                 :            : #include <dbaccess/IController.hxx>
      36                 :            : #include <com/sun/star/report/XSection.hpp>
      37                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      38                 :            : 
      39                 :            : #include <com/sun/star/awt/Point.hpp>
      40                 :            : #include <com/sun/star/awt/Size.hpp>
      41                 :            : #include <svx/unoshape.hxx>
      42                 :            : #include <functional>
      43                 :            : 
      44                 :            : namespace rptui
      45                 :            : {
      46                 :            :     using namespace ::com::sun::star;
      47                 :            :     using namespace uno;
      48                 :            :     using namespace lang;
      49                 :            :     using namespace script;
      50                 :            :     using namespace beans;
      51                 :            :     using namespace awt;
      52                 :            :     using namespace util;
      53                 :            :     using namespace container;
      54                 :            :     using namespace report;
      55                 :            : 
      56                 :            : //----------------------------------------------------------------------------
      57                 :            : namespace
      58                 :            : {
      59                 :          0 :     void lcl_collectElements(const uno::Reference< report::XSection >& _xSection,::std::vector< uno::Reference< drawing::XShape> >& _rControls)
      60                 :            :     {
      61                 :          0 :         if ( _xSection.is() )
      62                 :            :         {
      63                 :          0 :             sal_Int32 nCount = _xSection->getCount();
      64                 :          0 :             _rControls.reserve(nCount);
      65                 :          0 :             while ( nCount )
      66                 :            :             {
      67                 :          0 :                 uno::Reference< drawing::XShape> xShape(_xSection->getByIndex(nCount-1),uno::UNO_QUERY);
      68                 :          0 :                 _rControls.push_back(xShape);
      69                 :          0 :                 _xSection->remove(xShape);
      70                 :          0 :                 --nCount;
      71                 :          0 :             }
      72                 :            :         }
      73                 :          0 :     }
      74                 :            :     //----------------------------------------------------------------------------
      75                 :          0 :     void lcl_insertElements(const uno::Reference< report::XSection >& _xSection,const ::std::vector< uno::Reference< drawing::XShape> >& _aControls)
      76                 :            :     {
      77                 :          0 :         if ( _xSection.is() )
      78                 :            :         {
      79                 :          0 :             ::std::vector< uno::Reference< drawing::XShape> >::const_reverse_iterator aIter = _aControls.rbegin();
      80                 :          0 :             ::std::vector< uno::Reference< drawing::XShape> >::const_reverse_iterator aEnd = _aControls.rend();
      81                 :          0 :             for (; aIter != aEnd; ++aIter)
      82                 :            :             {
      83                 :            :                 try
      84                 :            :                 {
      85                 :          0 :                     const awt::Point aPos = (*aIter)->getPosition();
      86                 :          0 :                     const awt::Size aSize = (*aIter)->getSize();
      87                 :          0 :                     _xSection->add(*aIter);
      88                 :          0 :                     (*aIter)->setPosition( aPos );
      89                 :          0 :                     (*aIter)->setSize( aSize );
      90                 :            :                 }
      91                 :          0 :                 catch(const uno::Exception&)
      92                 :            :                 {
      93                 :            :                     OSL_FAIL("lcl_insertElements:Exception caught!");
      94                 :            :                 }
      95                 :            :             }
      96                 :            :         }
      97                 :          0 :     }
      98                 :            :     //----------------------------------------------------------------------------
      99                 :          0 :     void lcl_setValues(const uno::Reference< report::XSection >& _xSection,const ::std::vector< ::std::pair< ::rtl::OUString ,uno::Any> >& _aValues)
     100                 :            :     {
     101                 :          0 :         if ( _xSection.is() )
     102                 :            :         {
     103                 :          0 :             ::std::vector< ::std::pair< ::rtl::OUString ,uno::Any> >::const_iterator aIter = _aValues.begin();
     104                 :          0 :             ::std::vector< ::std::pair< ::rtl::OUString ,uno::Any> >::const_iterator aEnd = _aValues.end();
     105                 :          0 :             for (; aIter != aEnd; ++aIter)
     106                 :            :             {
     107                 :            :                 try
     108                 :            :                 {
     109                 :          0 :                     _xSection->setPropertyValue(aIter->first,aIter->second);
     110                 :            :                 }
     111                 :          0 :                 catch(const uno::Exception&)
     112                 :            :                 {
     113                 :            :                     OSL_FAIL("lcl_setValues:Exception caught!");
     114                 :            :                 }
     115                 :            :             }
     116                 :            :         }
     117                 :          0 :     }
     118                 :            : }
     119                 :            : //----------------------------------------------------------------------------
     120                 :          0 : TYPEINIT1( OSectionUndo,         OCommentUndoAction );
     121                 :            : DBG_NAME(rpt_OSectionUndo)
     122                 :            : //----------------------------------------------------------------------------
     123                 :          0 : OSectionUndo::OSectionUndo(OReportModel& _rMod
     124                 :            :                            ,sal_uInt16 _nSlot
     125                 :            :                            ,Action _eAction
     126                 :            :                            ,sal_uInt16 nCommentID)
     127                 :            : : OCommentUndoAction(_rMod,nCommentID)
     128                 :            : ,m_eAction(_eAction)
     129                 :            : ,m_nSlot(_nSlot)
     130                 :          0 : ,m_bInserted(false)
     131                 :            : {
     132                 :            :     DBG_CTOR(rpt_OSectionUndo,NULL);
     133                 :          0 : }
     134                 :            : // -----------------------------------------------------------------------------
     135                 :          0 : OSectionUndo::~OSectionUndo()
     136                 :            : {
     137                 :          0 :     if ( !m_bInserted )
     138                 :            :     {
     139                 :          0 :         OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
     140                 :          0 :         ::std::vector< uno::Reference< drawing::XShape> >::iterator aEnd = m_aControls.end();
     141                 :          0 :         for (::std::vector< uno::Reference< drawing::XShape> >::iterator aIter = m_aControls.begin(); aIter != aEnd; ++aIter)
     142                 :            :         {
     143                 :          0 :             uno::Reference< drawing::XShape> xShape = *aIter;
     144                 :          0 :             rEnv.RemoveElement(xShape);
     145                 :            : 
     146                 :            : #if OSL_DEBUG_LEVEL > 0
     147                 :            :             SvxShape* pShape = SvxShape::getImplementation( xShape );
     148                 :            :             SdrObject* pObject = pShape ? pShape->GetSdrObject() : NULL;
     149                 :            :             OSL_ENSURE( pShape && pShape->HasSdrObjectOwnership() && pObject && !pObject->IsInserted(),
     150                 :            :                 "OSectionUndo::~OSectionUndo: inconsistency in the shape/object ownership!" );
     151                 :            : #endif
     152                 :            :             try
     153                 :            :             {
     154                 :          0 :                 comphelper::disposeComponent(xShape);
     155                 :            :             }
     156                 :          0 :             catch(const uno::Exception &)
     157                 :            :             {
     158                 :            :                 OSL_FAIL("Exception caught!");
     159                 :            :             }
     160                 :          0 :         }
     161                 :            :     }
     162                 :            :     DBG_DTOR(rpt_OSectionUndo,NULL);
     163                 :          0 : }
     164                 :            : // -----------------------------------------------------------------------------
     165                 :          0 : void OSectionUndo::collectControls(const uno::Reference< report::XSection >& _xSection)
     166                 :            : {
     167                 :          0 :     m_aControls.clear();
     168                 :            :     try
     169                 :            :     {
     170                 :            :         // copy all properties for restoring
     171                 :          0 :         uno::Reference< beans::XPropertySetInfo> xInfo = _xSection->getPropertySetInfo();
     172                 :          0 :         uno::Sequence< beans::Property> aSeq = xInfo->getProperties();
     173                 :          0 :         const beans::Property* pIter = aSeq.getConstArray();
     174                 :          0 :         const beans::Property* pEnd  = pIter + aSeq.getLength();
     175                 :          0 :         for(;pIter != pEnd;++pIter)
     176                 :            :         {
     177                 :          0 :             if ( 0 == (pIter->Attributes & beans::PropertyAttribute::READONLY) )
     178                 :          0 :                 m_aValues.push_back(::std::pair< ::rtl::OUString ,uno::Any>(pIter->Name,_xSection->getPropertyValue(pIter->Name)));
     179                 :            :         }
     180                 :          0 :         lcl_collectElements(_xSection,m_aControls);
     181                 :            :     }
     182                 :          0 :     catch(uno::Exception&)
     183                 :            :     {
     184                 :            :     }
     185                 :          0 : }
     186                 :            : //----------------------------------------------------------------------------
     187                 :          0 : void OSectionUndo::Undo()
     188                 :            : {
     189                 :            :     try
     190                 :            :     {
     191                 :          0 :         switch ( m_eAction )
     192                 :            :         {
     193                 :            :         case Inserted:
     194                 :          0 :             implReRemove();
     195                 :          0 :             break;
     196                 :            : 
     197                 :            :         case Removed:
     198                 :          0 :             implReInsert();
     199                 :          0 :             break;
     200                 :            :         }
     201                 :            :     }
     202                 :          0 :     catch( const Exception& )
     203                 :            :     {
     204                 :            :         OSL_FAIL( "OSectionUndo::Undo: caught an exception!" );
     205                 :            :     }
     206                 :          0 : }
     207                 :            : //----------------------------------------------------------------------------
     208                 :          0 : void OSectionUndo::Redo()
     209                 :            : {
     210                 :            :     try
     211                 :            :     {
     212                 :          0 :         switch ( m_eAction )
     213                 :            :         {
     214                 :            :         case Inserted:
     215                 :          0 :             implReInsert();
     216                 :          0 :             break;
     217                 :            : 
     218                 :            :         case Removed:
     219                 :          0 :             implReRemove();
     220                 :          0 :             break;
     221                 :            :         }
     222                 :            :     }
     223                 :          0 :     catch( const Exception& )
     224                 :            :     {
     225                 :            :         OSL_FAIL( "OSectionUndo::Redo: caught an exception!" );
     226                 :            :     }
     227                 :          0 : }
     228                 :            : //----------------------------------------------------------------------------
     229                 :          0 : TYPEINIT1( OReportSectionUndo,         OSectionUndo );
     230                 :            : //----------------------------------------------------------------------------
     231                 :          0 : OReportSectionUndo::OReportSectionUndo(OReportModel& _rMod,sal_uInt16 _nSlot
     232                 :            :                                        ,::std::mem_fun_t< uno::Reference< report::XSection >
     233                 :            :                                             ,OReportHelper> _pMemberFunction
     234                 :            :                                        ,const uno::Reference< report::XReportDefinition >& _xReport
     235                 :            :                                        ,Action _eAction
     236                 :            :                                        ,sal_uInt16 nCommentID)
     237                 :            : : OSectionUndo(_rMod,_nSlot,_eAction,nCommentID)
     238                 :            : ,m_aReportHelper(_xReport)
     239                 :          0 : ,m_pMemberFunction(_pMemberFunction)
     240                 :            : {
     241                 :          0 :     if( m_eAction == Removed )
     242                 :          0 :         collectControls(m_pMemberFunction(&m_aReportHelper));
     243                 :          0 : }
     244                 :            : // -----------------------------------------------------------------------------
     245                 :          0 : OReportSectionUndo::~OReportSectionUndo()
     246                 :            : {
     247                 :          0 : }
     248                 :            : //----------------------------------------------------------------------------
     249                 :          0 : void OReportSectionUndo::implReInsert( )
     250                 :            : {
     251                 :          0 :     const uno::Sequence< beans::PropertyValue > aArgs;
     252                 :          0 :     m_pController->executeChecked(m_nSlot,aArgs);
     253                 :          0 :     uno::Reference< report::XSection > xSection = m_pMemberFunction(&m_aReportHelper);
     254                 :          0 :     lcl_insertElements(xSection,m_aControls);
     255                 :          0 :     lcl_setValues(xSection,m_aValues);
     256                 :          0 :     m_bInserted = true;
     257                 :          0 : }
     258                 :            : //----------------------------------------------------------------------------
     259                 :          0 : void OReportSectionUndo::implReRemove( )
     260                 :            : {
     261                 :          0 :     if( m_eAction == Removed )
     262                 :          0 :         collectControls(m_pMemberFunction(&m_aReportHelper));
     263                 :          0 :     const uno::Sequence< beans::PropertyValue > aArgs;
     264                 :          0 :     m_pController->executeChecked(m_nSlot,aArgs);
     265                 :          0 :     m_bInserted = false;
     266                 :          0 : }
     267                 :            : //----------------------------------------------------------------------------
     268                 :          0 : TYPEINIT1( OGroupSectionUndo,         OSectionUndo );
     269                 :            : //----------------------------------------------------------------------------
     270                 :          0 : OGroupSectionUndo::OGroupSectionUndo(OReportModel& _rMod,sal_uInt16 _nSlot
     271                 :            :                                        ,::std::mem_fun_t< uno::Reference< report::XSection >
     272                 :            :                                             ,OGroupHelper> _pMemberFunction
     273                 :            :                                        ,const uno::Reference< report::XGroup >& _xGroup
     274                 :            :                                        ,Action _eAction
     275                 :            :                                        ,sal_uInt16 nCommentID)
     276                 :            : : OSectionUndo(_rMod,_nSlot,_eAction,nCommentID)
     277                 :            : ,m_aGroupHelper(_xGroup)
     278                 :          0 : ,m_pMemberFunction(_pMemberFunction)
     279                 :            : {
     280                 :          0 :     if( m_eAction == Removed )
     281                 :            :     {
     282                 :          0 :         uno::Reference< report::XSection > xSection = m_pMemberFunction(&m_aGroupHelper);
     283                 :          0 :         if ( xSection.is() )
     284                 :          0 :             m_sName = xSection->getName();
     285                 :          0 :         collectControls(xSection);
     286                 :            :     }
     287                 :          0 : }
     288                 :            : //----------------------------------------------------------------------------
     289                 :          0 : rtl::OUString OGroupSectionUndo::GetComment() const
     290                 :            : {
     291                 :          0 :     if ( m_sName.isEmpty() )
     292                 :            :     {
     293                 :            :         try
     294                 :            :         {
     295                 :          0 :             uno::Reference< report::XSection > xSection = const_cast<OGroupSectionUndo*>(this)->m_pMemberFunction(&const_cast<OGroupSectionUndo*>(this)->m_aGroupHelper);
     296                 :            : 
     297                 :          0 :             if ( xSection.is() )
     298                 :          0 :                 m_sName = xSection->getName();
     299                 :            :         }
     300                 :          0 :         catch (const uno::Exception&)
     301                 :            :         {
     302                 :            :         }
     303                 :            :     }
     304                 :          0 :     return m_strComment + m_sName;
     305                 :            : }
     306                 :            : //----------------------------------------------------------------------------
     307                 :          0 : void OGroupSectionUndo::implReInsert( )
     308                 :            : {
     309                 :          0 :     uno::Sequence< beans::PropertyValue > aArgs(2);
     310                 :            : 
     311                 :          0 :     aArgs[0].Name = SID_GROUPHEADER_WITHOUT_UNDO == m_nSlot? PROPERTY_HEADERON : PROPERTY_FOOTERON;
     312                 :          0 :     aArgs[0].Value <<= sal_True;
     313                 :          0 :     aArgs[1].Name = PROPERTY_GROUP;
     314                 :          0 :     aArgs[1].Value <<= m_aGroupHelper.getGroup();
     315                 :          0 :     m_pController->executeChecked(m_nSlot,aArgs);
     316                 :            : 
     317                 :          0 :     uno::Reference< report::XSection > xSection = m_pMemberFunction(&m_aGroupHelper);
     318                 :          0 :     lcl_insertElements(xSection,m_aControls);
     319                 :          0 :     lcl_setValues(xSection,m_aValues);
     320                 :          0 :     m_bInserted = true;
     321                 :          0 : }
     322                 :            : //----------------------------------------------------------------------------
     323                 :          0 : void OGroupSectionUndo::implReRemove( )
     324                 :            : {
     325                 :          0 :     if( m_eAction == Removed )
     326                 :          0 :         collectControls(m_pMemberFunction(&m_aGroupHelper));
     327                 :            : 
     328                 :          0 :     uno::Sequence< beans::PropertyValue > aArgs(2);
     329                 :            : 
     330                 :          0 :     aArgs[0].Name = SID_GROUPHEADER_WITHOUT_UNDO == m_nSlot? PROPERTY_HEADERON : PROPERTY_FOOTERON;
     331                 :          0 :     aArgs[0].Value <<= sal_False;
     332                 :          0 :     aArgs[1].Name = PROPERTY_GROUP;
     333                 :          0 :     aArgs[1].Value <<= m_aGroupHelper.getGroup();
     334                 :            : 
     335                 :          0 :     m_pController->executeChecked(m_nSlot,aArgs);
     336                 :          0 :     m_bInserted = false;
     337                 :          0 : }
     338                 :            : //----------------------------------------------------------------------------
     339                 :          0 : TYPEINIT1( OGroupUndo,         OCommentUndoAction );
     340                 :            : //----------------------------------------------------------------------------
     341                 :          0 : OGroupUndo::OGroupUndo(OReportModel& _rMod
     342                 :            :                        ,sal_uInt16 nCommentID
     343                 :            :                        ,Action  _eAction
     344                 :            :                        ,const uno::Reference< report::XGroup>& _xGroup
     345                 :            :                        ,const uno::Reference< report::XReportDefinition >& _xReportDefinition)
     346                 :            : : OCommentUndoAction(_rMod,nCommentID)
     347                 :            : ,m_xGroup(_xGroup)
     348                 :            : ,m_xReportDefinition(_xReportDefinition)
     349                 :          0 : ,m_eAction(_eAction)
     350                 :            : {
     351                 :          0 :     m_nLastPosition = getPositionInIndexAccess(m_xReportDefinition->getGroups().get(),m_xGroup);
     352                 :          0 : }
     353                 :            : //----------------------------------------------------------------------------
     354                 :          0 : void OGroupUndo::implReInsert( )
     355                 :            : {
     356                 :            :     try
     357                 :            :     {
     358                 :          0 :         m_xReportDefinition->getGroups()->insertByIndex(m_nLastPosition,uno::makeAny(m_xGroup));
     359                 :            :     }
     360                 :          0 :     catch(uno::Exception&)
     361                 :            :     {
     362                 :            :         OSL_FAIL("Exception catched while undoing remove group");
     363                 :            :     }
     364                 :          0 : }
     365                 :            : //----------------------------------------------------------------------------
     366                 :          0 : void OGroupUndo::implReRemove( )
     367                 :            : {
     368                 :            :     try
     369                 :            :     {
     370                 :          0 :         m_xReportDefinition->getGroups()->removeByIndex(m_nLastPosition);
     371                 :            :     }
     372                 :          0 :     catch(uno::Exception&)
     373                 :            :     {
     374                 :            :         OSL_FAIL("Exception catched while redoing remove group");
     375                 :            :     }
     376                 :          0 : }
     377                 :            : //----------------------------------------------------------------------------
     378                 :          0 : void OGroupUndo::Undo()
     379                 :            : {
     380                 :          0 :     switch ( m_eAction )
     381                 :            :     {
     382                 :            :     case Inserted:
     383                 :          0 :         implReRemove();
     384                 :          0 :         break;
     385                 :            : 
     386                 :            :     case Removed:
     387                 :          0 :         implReInsert();
     388                 :          0 :         break;
     389                 :            :     }
     390                 :            : 
     391                 :          0 : }
     392                 :            : //----------------------------------------------------------------------------
     393                 :          0 : void OGroupUndo::Redo()
     394                 :            : {
     395                 :          0 :     switch ( m_eAction )
     396                 :            :     {
     397                 :            :     case Inserted:
     398                 :          0 :         implReInsert();
     399                 :          0 :         break;
     400                 :            : 
     401                 :            :     case Removed:
     402                 :          0 :         implReRemove();
     403                 :          0 :         break;
     404                 :            :     }
     405                 :          0 : }
     406                 :            : //----------------------------------------------------------------------------
     407                 :            : //============================================================================
     408                 :            : } // rptui
     409                 :            : //============================================================================
     410                 :            : 
     411                 :            : 
     412                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10