LCOV - code coverage report
Current view: top level - svx/source/form - fmundo.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 376 539 69.8 %
Date: 2012-08-25 Functions: 43 58 74.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 489 1238 39.5 %

           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                 :            : 
      30                 :            : #include <sal/macros.h>
      31                 :            : #include "fmundo.hxx"
      32                 :            : #include "fmpgeimp.hxx"
      33                 :            : #include "svx/dbtoolsclient.hxx"
      34                 :            : #include "svx/svditer.hxx"
      35                 :            : #include "fmobj.hxx"
      36                 :            : #include "fmprop.hrc"
      37                 :            : #include "svx/fmresids.hrc"
      38                 :            : #include "svx/fmglob.hxx"
      39                 :            : #include "svx/dialmgr.hxx"
      40                 :            : #include "svx/fmmodel.hxx"
      41                 :            : #include "svx/fmpage.hxx"
      42                 :            : 
      43                 :            : #include <com/sun/star/util/XModifyBroadcaster.hpp>
      44                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      45                 :            : #include <com/sun/star/container/XContainer.hpp>
      46                 :            : #include <com/sun/star/container/XContainerListener.hpp>
      47                 :            : #include <com/sun/star/script/XEventAttacherManager.hpp>
      48                 :            : #include <com/sun/star/form/binding/XBindableValue.hpp>
      49                 :            : #include <com/sun/star/form/binding/XListEntrySink.hpp>
      50                 :            : #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
      51                 :            : 
      52                 :            : #include "svx/fmtools.hxx"
      53                 :            : #include <rtl/logfile.hxx>
      54                 :            : #include <svl/macitem.hxx>
      55                 :            : #include <tools/shl.hxx>
      56                 :            : #include <tools/diagnose_ex.h>
      57                 :            : #include <sfx2/objsh.hxx>
      58                 :            : #include <sfx2/docfile.hxx>
      59                 :            : #include <sfx2/app.hxx>
      60                 :            : #include <sfx2/sfx.hrc>
      61                 :            : #include <sfx2/event.hxx>
      62                 :            : #include <osl/mutex.hxx>
      63                 :            : #include <comphelper/property.hxx>
      64                 :            : #include <comphelper/uno3.hxx>
      65                 :            : #include <comphelper/stl_types.hxx>
      66                 :            : #include <comphelper/componentcontext.hxx>
      67                 :            : 
      68                 :            : using namespace ::com::sun::star::uno;
      69                 :            : using namespace ::com::sun::star::awt;
      70                 :            : using namespace ::com::sun::star::beans;
      71                 :            : using namespace ::com::sun::star::container;
      72                 :            : using namespace ::com::sun::star::script;
      73                 :            : using namespace ::com::sun::star::lang;
      74                 :            : using namespace ::com::sun::star::form;
      75                 :            : using namespace ::com::sun::star::util;
      76                 :            : using namespace ::com::sun::star::reflection;
      77                 :            : using namespace ::com::sun::star::form::binding;
      78                 :            : using namespace ::svxform;
      79                 :            : 
      80                 :            : 
      81                 :            : #include <com/sun/star/script/XScriptListener.hpp>
      82                 :            : #include <comphelper/processfactory.hxx>
      83                 :            : #include <cppuhelper/implbase1.hxx>
      84                 :            : 
      85                 :            : typedef cppu::WeakImplHelper1< XScriptListener > ScriptEventListener_BASE;
      86         [ -  + ]:       3562 : class ScriptEventListenerWrapper : public ScriptEventListener_BASE
      87                 :            : {
      88                 :            : public:
      89                 :       1886 :     ScriptEventListenerWrapper( FmFormModel& _rModel) throw ( RuntimeException )
      90                 :            :         :m_rModel( _rModel )
      91                 :       1886 :         ,m_attemptedListenerCreation( false )
      92                 :            :     {
      93                 :            : 
      94                 :       1886 :     }
      95                 :            :     // XEventListener
      96                 :          0 :     virtual void SAL_CALL disposing(const EventObject& ) throw( RuntimeException ){}
      97                 :            : 
      98                 :            :     // XScriptListener
      99                 :          2 :     virtual void SAL_CALL firing(const  ScriptEvent& evt) throw(RuntimeException)
     100                 :            :     {
     101                 :          2 :         attemptListenerCreation();
     102         [ +  - ]:          2 :         if ( m_vbaListener.is() )
     103                 :            :         {
     104                 :          2 :             m_vbaListener->firing( evt );
     105                 :            :         }
     106                 :          2 :     }
     107                 :            : 
     108                 :          0 :     virtual Any SAL_CALL approveFiring(const ScriptEvent& evt) throw( com::sun::star::reflection::InvocationTargetException, RuntimeException)
     109                 :            :     {
     110                 :          0 :         attemptListenerCreation();
     111         [ #  # ]:          0 :         if ( m_vbaListener.is() )
     112                 :            :         {
     113                 :          0 :             return m_vbaListener->approveFiring( evt );
     114                 :            :         }
     115                 :          0 :         return Any();
     116                 :            :     }
     117                 :            : 
     118                 :            : private:
     119                 :          2 :     void attemptListenerCreation()
     120                 :            :     {
     121         [ -  + ]:          2 :         if ( m_attemptedListenerCreation )
     122                 :          2 :             return;
     123                 :          2 :         m_attemptedListenerCreation = true;
     124                 :            : 
     125                 :            :         try
     126                 :            :         {
     127 [ +  - ][ +  - ]:          2 :             ::comphelper::ComponentContext const aContext( ::comphelper::getProcessServiceFactory() );
     128 [ +  - ][ +  - ]:          2 :             Reference< XScriptListener > const xScriptListener( aContext.createComponent( "ooo.vba.EventListener" ), UNO_QUERY_THROW );
     129         [ +  - ]:          2 :             Reference< XPropertySet > const xListenerProps( xScriptListener, UNO_QUERY_THROW );
     130                 :            :             // SfxObjectShellRef is good here since the model controls the lifetime of the shell
     131                 :          2 :             SfxObjectShellRef const xObjectShell = m_rModel.GetObjectShell();
     132 [ #  # ][ #  # ]:          2 :             ENSURE_OR_THROW( xObjectShell.Is(), "no object shell!" );
         [ #  # ][ -  + ]
     133 [ +  - ][ +  - ]:          2 :             xListenerProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Model" ) ), makeAny( xObjectShell->GetModel() ) );
         [ +  - ][ +  - ]
                 [ +  - ]
     134                 :            : 
     135 [ +  - ][ +  - ]:          2 :             m_vbaListener = xScriptListener;
         [ #  # ][ +  - ]
     136                 :            :         }
     137                 :          0 :         catch( Exception const & )
     138                 :            :         {
     139                 :            :             DBG_UNHANDLED_EXCEPTION();
     140                 :            :         }
     141                 :            :     }
     142                 :            :     FmFormModel&                    m_rModel;
     143                 :            :     Reference< XScriptListener >    m_vbaListener;
     144                 :            :     bool                            m_attemptedListenerCreation;
     145                 :            : 
     146                 :            : 
     147                 :            : };
     148                 :            : 
     149                 :            : //------------------------------------------------------------------------------
     150                 :            : // some helper structs for caching property infos
     151                 :            : //------------------------------------------------------------------------------
     152                 :            : struct PropertyInfo
     153                 :            : {
     154                 :            :     sal_Bool    bIsTransientOrReadOnly  : 1;    // the property is transient or read-only, thus we need no undo action for it
     155                 :            :     sal_Bool    bIsValueProperty        : 1;    // the property is the special value property, thus it may be handled
     156                 :            :                                             // as if it's transient or persistent
     157                 :            : };
     158                 :            : 
     159                 :       3783 : struct PropertySetInfo
     160                 :            : {
     161                 :            :     DECLARE_STL_USTRINGACCESS_MAP(PropertyInfo, AllProperties);
     162                 :            : 
     163                 :            :     AllProperties   aProps;                 // all properties of this set which we know so far
     164                 :            :     sal_Bool            bHasEmptyControlSource; // sal_True -> the set has a DataField property, and the current value is an empty string
     165                 :            :                                             // sal_False -> the set has _no_ such property or it's value isn't empty
     166                 :            : };
     167                 :            : 
     168                 :          0 : sal_Bool operator < (const Reference< XPropertySet >& lhs,
     169                 :            :                  const Reference< XPropertySet >& rhs)
     170                 :            : {
     171                 :          0 :     return lhs.get() < rhs.get();
     172                 :            : }
     173                 :            : 
     174                 :            : DECLARE_STL_STDKEY_MAP(Reference< XPropertySet >, PropertySetInfo, PropertySetInfoCache);
     175                 :            : 
     176                 :            : //------------------------------------------------------------------------------
     177                 :            : 
     178                 :        150 : String static_STR_UNDO_PROPERTY;
     179                 :            : //------------------------------------------------------------------------------
     180                 :            : DBG_NAME(FmXUndoEnvironment)
     181                 :            : //------------------------------------------------------------------------------
     182                 :       1886 : FmXUndoEnvironment::FmXUndoEnvironment(FmFormModel& _rModel)
     183                 :            :                    :rModel( _rModel )
     184                 :            :                    ,m_pPropertySetCache( NULL )
     185                 :            :                    ,m_pScriptingEnv( ::svxform::createDefaultFormScriptingEnvironment( _rModel ) )
     186                 :            :                    ,m_Locks( 0 )
     187                 :            :                    ,bReadOnly( sal_False )
     188 [ +  - ][ +  - ]:       1886 :                    ,m_bDisposed( false )
                 [ +  - ]
     189                 :            : {
     190                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::FmXUndoEnvironment" );
     191                 :            :     DBG_CTOR(FmXUndoEnvironment,NULL);
     192                 :            :     try
     193                 :            :     {
     194         [ +  - ]:       1886 :         m_vbaListener =  new ScriptEventListenerWrapper( _rModel );
           [ +  -  #  # ]
                 [ +  - ]
     195                 :            :     }
     196         [ #  # ]:          0 :     catch( Exception& )
     197                 :            :     {
     198                 :            :     }
     199                 :       1886 : }
     200                 :            : 
     201                 :            : //------------------------------------------------------------------------------
     202 [ +  - ][ +  - ]:       1781 : FmXUndoEnvironment::~FmXUndoEnvironment()
                 [ +  - ]
     203                 :            : {
     204                 :            :     DBG_DTOR(FmXUndoEnvironment,NULL);
     205         [ +  + ]:       1781 :     if (m_pPropertySetCache)
     206         [ +  - ]:        254 :         delete static_cast<PropertySetInfoCache*>(m_pPropertySetCache);
     207         [ -  + ]:       3562 : }
     208                 :            : 
     209                 :            : //------------------------------------------------------------------------------
     210                 :        169 : void FmXUndoEnvironment::dispose()
     211                 :            : {
     212                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::dispose" );
     213                 :            :     OSL_ENSURE( !m_bDisposed, "FmXUndoEnvironment::dispose: disposed twice?" );
     214         [ +  - ]:        169 :     if ( !m_bDisposed )
     215                 :        169 :         return;
     216                 :            : 
     217                 :          0 :     Lock();
     218                 :            : 
     219                 :          0 :     sal_uInt16 nCount = rModel.GetPageCount();
     220                 :            :     sal_uInt16 i;
     221         [ #  # ]:          0 :     for (i = 0; i < nCount; i++)
     222                 :            :     {
     223 [ #  # ][ #  # ]:          0 :         FmFormPage* pPage = PTR_CAST( FmFormPage, rModel.GetPage(i) );
     224         [ #  # ]:          0 :         if ( pPage )
     225                 :            :         {
     226 [ #  # ][ #  # ]:          0 :             Reference< XInterface > xForms = pPage->GetForms( false ).get();
                 [ #  # ]
     227         [ #  # ]:          0 :             if ( xForms.is() )
     228         [ #  # ]:          0 :                 RemoveElement( xForms );
     229                 :            :         }
     230                 :            :     }
     231                 :            : 
     232                 :          0 :     nCount = rModel.GetMasterPageCount();
     233         [ #  # ]:          0 :     for (i = 0; i < nCount; i++)
     234                 :            :     {
     235 [ #  # ][ #  # ]:          0 :         FmFormPage* pPage = PTR_CAST( FmFormPage, rModel.GetMasterPage(i) );
     236         [ #  # ]:          0 :         if ( pPage )
     237                 :            :         {
     238 [ #  # ][ #  # ]:          0 :             Reference< XInterface > xForms = pPage->GetForms( false ).get();
                 [ #  # ]
     239         [ #  # ]:          0 :             if ( xForms.is() )
     240         [ #  # ]:          0 :                 RemoveElement( xForms );
     241                 :            :         }
     242                 :            :     }
     243                 :            : 
     244                 :          0 :     UnLock();
     245                 :            : 
     246                 :            :     OSL_PRECOND( rModel.GetObjectShell(), "FmXUndoEnvironment::dispose: no object shell anymore!" );
     247         [ #  # ]:          0 :     if ( rModel.GetObjectShell() )
     248                 :          0 :         EndListening( *rModel.GetObjectShell() );
     249                 :            : 
     250         [ #  # ]:          0 :     if ( IsListening( rModel ) )
     251                 :          0 :         EndListening( rModel );
     252                 :            : 
     253                 :          0 :     m_pScriptingEnv->dispose();
     254                 :            : 
     255                 :          0 :     m_bDisposed = true;
     256                 :            : }
     257                 :            : 
     258                 :            : //------------------------------------------------------------------------------
     259                 :       1392 : void FmXUndoEnvironment::ModeChanged()
     260                 :            : {
     261                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::ModeChanged" );
     262                 :            :     OSL_PRECOND( rModel.GetObjectShell(), "FmXUndoEnvironment::ModeChanged: no object shell anymore!" );
     263         [ -  + ]:       1392 :     if ( !rModel.GetObjectShell() )
     264                 :       1392 :         return;
     265                 :            : 
     266 [ +  + ][ -  + ]:       1392 :     if (bReadOnly != (rModel.GetObjectShell()->IsReadOnly() || rModel.GetObjectShell()->IsReadOnlyUI()))
                 [ +  + ]
     267                 :            :     {
     268                 :        284 :         bReadOnly = !bReadOnly;
     269                 :            : 
     270                 :        284 :         sal_uInt16 nCount = rModel.GetPageCount();
     271                 :            :         sal_uInt16 i;
     272         [ +  + ]:        985 :         for (i = 0; i < nCount; i++)
     273                 :            :         {
     274 [ +  - ][ +  - ]:        701 :             FmFormPage* pPage = PTR_CAST( FmFormPage, rModel.GetPage(i) );
     275         [ +  - ]:        701 :             if ( pPage )
     276                 :            :             {
     277 [ +  - ][ +  - ]:        701 :                 Reference< XInterface > xForms = pPage->GetForms( false ).get();
                 [ +  - ]
     278         [ +  + ]:        701 :                 if ( xForms.is() )
     279         [ +  - ]:        701 :                     TogglePropertyListening( xForms );
     280                 :            :             }
     281                 :            :         }
     282                 :            : 
     283                 :        284 :         nCount = rModel.GetMasterPageCount();
     284         [ +  + ]:        674 :         for (i = 0; i < nCount; i++)
     285                 :            :         {
     286 [ +  - ][ +  - ]:        390 :             FmFormPage* pPage = PTR_CAST( FmFormPage, rModel.GetMasterPage(i) );
     287         [ +  - ]:        390 :             if ( pPage )
     288                 :            :             {
     289 [ +  - ][ +  - ]:        390 :                 Reference< XInterface > xForms = pPage->GetForms( false ).get();
                 [ +  - ]
     290         [ -  + ]:        390 :                 if ( xForms.is() )
     291         [ #  # ]:        390 :                     TogglePropertyListening( xForms );
     292                 :            :             }
     293                 :            :         }
     294                 :            : 
     295         [ +  + ]:        284 :         if (!bReadOnly)
     296                 :        130 :             StartListening(rModel);
     297                 :            :         else
     298                 :        154 :             EndListening(rModel);
     299                 :            :     }
     300                 :            : }
     301                 :            : 
     302                 :            : //------------------------------------------------------------------------------
     303                 :     181996 : void FmXUndoEnvironment::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
     304                 :            : {
     305                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::Notify" );
     306         [ +  + ]:     181996 :     if (rHint.ISA(SdrHint))
     307                 :            :     {
     308                 :      25387 :         SdrHint* pSdrHint = (SdrHint*)&rHint;
     309      [ +  +  + ]:      25387 :         switch( pSdrHint->GetKind() )
     310                 :            :         {
     311                 :            :             case HINT_OBJINSERTED:
     312                 :            :             {
     313                 :       1947 :                 SdrObject* pSdrObj = (SdrObject*)pSdrHint->GetObject();
     314                 :       1947 :                 Inserted( pSdrObj );
     315                 :       1947 :             }   break;
     316                 :            :             case HINT_OBJREMOVED:
     317                 :            :             {
     318                 :        823 :                 SdrObject* pSdrObj = (SdrObject*)pSdrHint->GetObject();
     319                 :        823 :                 Removed( pSdrObj );
     320                 :            :             }
     321                 :        823 :             break;
     322                 :            :             default:
     323                 :      25387 :                 break;
     324                 :            :         }
     325                 :            :     }
     326         [ +  + ]:     156609 :     else if (rHint.ISA(SfxSimpleHint))
     327                 :            :     {
     328      [ +  +  + ]:      59751 :         switch ( ((SfxSimpleHint&)rHint).GetId() )
     329                 :            :         {
     330                 :            :             case SFX_HINT_DYING:
     331                 :        169 :                 dispose();
     332                 :        169 :                 rModel.SetObjectShell( NULL );
     333                 :        169 :                 break;
     334                 :            :             case SFX_HINT_MODECHANGED:
     335                 :        206 :                 ModeChanged();
     336                 :      59751 :                 break;
     337                 :            :         }
     338                 :            :     }
     339         [ +  + ]:      96858 :     else if (rHint.ISA(SfxEventHint))
     340                 :            :     {
     341         [ +  + ]:      15908 :         switch (((SfxEventHint&)rHint).GetEventId())
     342                 :            :         {
     343                 :            :         case SFX_EVENT_CREATEDOC:
     344                 :            :             case SFX_EVENT_OPENDOC:
     345                 :       1186 :                 ModeChanged();
     346                 :      15908 :                 break;
     347                 :            :         }
     348                 :            :     }
     349                 :            : 
     350                 :     181996 : }
     351                 :            : 
     352                 :            : //------------------------------------------------------------------
     353                 :       6491 : void FmXUndoEnvironment::Inserted(SdrObject* pObj)
     354                 :            : {
     355                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::Inserted" );
     356         [ +  + ]:       6491 :     if (pObj->GetObjInventor() == FmFormInventor)
     357                 :            :     {
     358 [ +  - ][ +  - ]:       1022 :         FmFormObj* pFormObj = PTR_CAST(FmFormObj, pObj);
     359                 :       1022 :         Inserted( pFormObj );
     360                 :            :     }
     361         [ +  + ]:       5469 :     else if (pObj->IsGroupObject())
     362                 :            :     {
     363 [ +  - ][ +  - ]:        120 :         SdrObjListIter aIter(*pObj->GetSubList());
     364         [ +  + ]:        896 :         while ( aIter.IsMore() )
     365 [ +  - ][ +  - ]:        896 :             Inserted( aIter.Next() );
     366                 :            :     }
     367                 :       6491 : }
     368                 :            : 
     369                 :            : //------------------------------------------------------------------------------
     370                 :            : namespace
     371                 :            : {
     372                 :        468 :     sal_Bool lcl_searchElement(const Reference< XIndexAccess>& xCont, const Reference< XInterface >& xElement)
     373                 :            :     {
     374 [ +  - ][ +  + ]:        468 :         if (!xCont.is() || !xElement.is())
                 [ +  + ]
     375                 :        460 :             return sal_False;
     376                 :            : 
     377 [ +  - ][ +  - ]:          8 :         sal_Int32 nCount = xCont->getCount();
     378                 :          8 :         Reference< XInterface > xComp;
     379         [ +  - ]:          8 :         for (sal_Int32 i = 0; i < nCount; i++)
     380                 :            :         {
     381                 :            :             try
     382                 :            :             {
     383 [ +  - ][ +  - ]:          8 :                 xCont->getByIndex(i) >>= xComp;
                 [ +  - ]
     384         [ +  - ]:          8 :                 if (xComp.is())
     385                 :            :                 {
     386 [ +  - ][ +  - ]:          8 :                     if ( xElement == xComp )
     387                 :          8 :                         return sal_True;
     388                 :            :                     else
     389                 :            :                     {
     390         [ #  # ]:          0 :                         Reference< XIndexAccess> xCont2(xComp, UNO_QUERY);
     391 [ #  # ][ #  # ]:          0 :                         if (xCont2.is() && lcl_searchElement(xCont2, xElement))
         [ #  # ][ #  # ]
     392 [ #  # ][ #  # ]:          0 :                             return sal_True;
     393                 :            :                     }
     394                 :            :                 }
     395                 :            :             }
     396         [ #  # ]:          0 :             catch(const Exception&)
     397                 :            :             {
     398                 :            :                 DBG_UNHANDLED_EXCEPTION();
     399                 :            :             }
     400                 :            :         }
     401                 :        468 :         return sal_False;
     402                 :            :     }
     403                 :            : }
     404                 :            : 
     405                 :            : //------------------------------------------------------------------------------
     406                 :       1022 : void FmXUndoEnvironment::Inserted(FmFormObj* pObj)
     407                 :            : {
     408                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::Inserted" );
     409                 :            :     DBG_ASSERT( pObj, "FmXUndoEnvironment::Inserted: invalid object!" );
     410         [ +  - ]:       1022 :     if ( !pObj )
     411                 :       1022 :         return;
     412                 :            : 
     413                 :            :     // ist das Control noch einer Form zugeordnet
     414 [ +  - ][ +  - ]:       1022 :     Reference< XInterface >  xModel(pObj->GetUnoControlModel(), UNO_QUERY);
     415         [ +  - ]:       1022 :     Reference< XFormComponent >  xContent(xModel, UNO_QUERY);
     416 [ +  + ][ +  - ]:       1022 :     if (xContent.is() && pObj->GetPage())
         [ +  - ][ +  + ]
     417                 :            :     {
     418                 :            :         // if the component doesn't belong to a form, yet, find one to insert into
     419 [ +  - ][ +  - ]:        942 :         if (!xContent->getParent().is())
                 [ +  + ]
     420                 :            :         {
     421                 :            :             try
     422                 :            :             {
     423                 :        468 :                 Reference< XIndexContainer > xObjectParent = pObj->GetOriginalParent();
     424                 :            : 
     425 [ +  - ][ +  - ]:        468 :                 FmFormPage& rPage = dynamic_cast< FmFormPage& >( *pObj->GetPage() );
     426 [ +  - ][ +  - ]:        468 :                 Reference< XIndexAccess >  xForms( rPage.GetForms(), UNO_QUERY_THROW );
     427                 :            : 
     428                 :        468 :                 Reference< XIndexContainer > xNewParent;
     429                 :        468 :                 Reference< XForm >           xForm;
     430                 :        468 :                 sal_Int32 nPos = -1;
     431 [ +  + ][ +  - ]:        468 :                 if ( lcl_searchElement( xForms, xObjectParent ) )
     432                 :            :                 {
     433                 :            :                     // the form which was the parent of the object when it was removed is still
     434                 :            :                     // part of the form component hierachy of the current page
     435         [ +  - ]:          8 :                     xNewParent = xObjectParent;
     436         [ +  - ]:          8 :                     xForm.set( xNewParent, UNO_QUERY_THROW );
     437 [ +  - ][ +  - ]:          8 :                     nPos = ::std::min( pObj->GetOriginalIndex(), xNewParent->getCount() );
                 [ +  - ]
     438                 :            :                 }
     439                 :            :                 else
     440                 :            :                 {
     441 [ +  - ][ +  - ]:        460 :                     xForm.set( rPage.GetImpl().findPlaceInFormComponentHierarchy( xContent ), UNO_SET_THROW );
     442         [ +  - ]:        460 :                     xNewParent.set( xForm, UNO_QUERY_THROW );
     443 [ +  - ][ +  - ]:        460 :                     nPos = xNewParent->getCount();
     444                 :            :                 }
     445                 :            : 
     446         [ +  - ]:        468 :                 rPage.GetImpl().setUniqueName( xContent, xForm );
     447 [ +  - ][ +  - ]:        468 :                 xNewParent->insertByIndex( nPos, makeAny( xContent ) );
                 [ +  - ]
     448                 :            : 
     449         [ +  - ]:        468 :                 Reference< XEventAttacherManager >  xManager( xNewParent, UNO_QUERY_THROW );
     450 [ +  - ][ +  - ]:        468 :                 xManager->registerScriptEvents( nPos, pObj->GetOriginalEvents() );
                 [ #  # ]
     451                 :            :             }
     452         [ #  # ]:          0 :             catch( const Exception& )
     453                 :            :             {
     454                 :            :                 DBG_UNHANDLED_EXCEPTION();
     455                 :            :             }
     456                 :            :         }
     457                 :            : 
     458                 :            :         // FormObject zuruecksetzen
     459         [ +  - ]:        942 :         pObj->ClearObjEnv();
     460                 :       1022 :     }
     461                 :            : }
     462                 :            : 
     463                 :            : //------------------------------------------------------------------
     464                 :       3015 : void FmXUndoEnvironment::Removed(SdrObject* pObj)
     465                 :            : {
     466                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::Removed" );
     467         [ +  + ]:       3015 :     if ( pObj->IsVirtualObj() )
     468                 :            :         // for virtual objects, we've already been notified of the removal of the master
     469                 :            :         // object, which is sufficient here
     470                 :       3015 :         return;
     471                 :            : 
     472         [ +  + ]:       1973 :     if (pObj->GetObjInventor() == FmFormInventor)
     473                 :            :     {
     474 [ +  - ][ +  - ]:        481 :         FmFormObj* pFormObj = PTR_CAST(FmFormObj, pObj);
     475                 :        481 :         Removed(pFormObj);
     476                 :            :     }
     477         [ +  + ]:       1492 :     else if (pObj->IsGroupObject())
     478                 :            :     {
     479 [ +  - ][ +  - ]:         69 :         SdrObjListIter aIter(*pObj->GetSubList());
     480         [ +  + ]:        441 :         while ( aIter.IsMore() )
     481 [ +  - ][ +  - ]:        441 :             Removed( aIter.Next() );
     482                 :            :     }
     483                 :            : }
     484                 :            : 
     485                 :            : //------------------------------------------------------------------------------
     486                 :        481 : void FmXUndoEnvironment::Removed(FmFormObj* pObj)
     487                 :            : {
     488                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::Removed" );
     489                 :            :     DBG_ASSERT( pObj, "FmXUndoEnvironment::Removed: invalid object!" );
     490         [ +  - ]:        481 :     if ( !pObj )
     491                 :        481 :         return;
     492                 :            : 
     493                 :            :     // ist das Control noch einer Form zugeordnet
     494 [ +  - ][ +  - ]:        481 :     Reference< XFormComponent >  xContent(pObj->GetUnoControlModel(), UNO_QUERY);
     495         [ +  + ]:        481 :     if (xContent.is())
     496                 :            :     {
     497                 :            :         // das Object wird aus einer Liste herausgenommen
     498                 :            :         // existiert ein Vater wird das Object beim beim Vater entfernt und
     499                 :            :         // am FormObject gemerkt!
     500                 :            : 
     501                 :            :         // wird das Object wieder eingefuegt und ein Parent existiert, so wird dieser
     502                 :            :         // Parent wiederum gesetzt
     503 [ +  - ][ +  - ]:        447 :         Reference< XIndexContainer >  xForm(xContent->getParent(), UNO_QUERY);
                 [ +  - ]
     504         [ +  + ]:        447 :         if (xForm.is())
     505                 :            :         {
     506 [ +  - ][ +  - ]:         10 :             Reference< XIndexAccess >  xIndexAccess((XIndexContainer*)xForm.get());
     507                 :            :             // Feststellen an welcher Position sich das Kind befunden hat
     508         [ +  - ]:         10 :             const sal_Int32 nPos = getElementPos(xIndexAccess, xContent);
     509         [ +  - ]:         10 :             if (nPos >= 0)
     510                 :            :             {
     511         [ +  - ]:         10 :                 Sequence< ScriptEventDescriptor > aEvts;
     512         [ +  - ]:         10 :                 Reference< XEventAttacherManager >  xManager(xForm, UNO_QUERY);
     513         [ +  - ]:         10 :                 if (xManager.is())
     514 [ +  - ][ +  - ]:         10 :                     aEvts = xManager->getScriptEvents(nPos);
         [ +  - ][ +  - ]
                 [ #  # ]
     515                 :            : 
     516                 :            :                 try
     517                 :            :                 {
     518         [ +  - ]:         10 :                     pObj->SetObjEnv(xForm, nPos, aEvts);
     519 [ +  - ][ +  - ]:         10 :                     xForm->removeByIndex(nPos);
     520                 :            :                 }
     521         [ #  # ]:          0 :                 catch(Exception&)
     522                 :            :                 {
     523                 :            :                     DBG_UNHANDLED_EXCEPTION();
     524         [ +  - ]:         10 :                 }
     525                 :            : 
     526                 :         10 :             }
     527                 :        447 :         }
     528                 :        481 :     }
     529                 :            : }
     530                 :            : 
     531                 :            : //  XEventListener
     532                 :            : //------------------------------------------------------------------------------
     533                 :         46 : void SAL_CALL FmXUndoEnvironment::disposing(const EventObject& e) throw( RuntimeException )
     534                 :            : {
     535                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::disposing" );
     536                 :            :     // check if it's an object we have cached informations about
     537         [ +  + ]:         46 :     if (m_pPropertySetCache)
     538                 :            :     {
     539         [ +  - ]:         44 :         Reference< XPropertySet > xSourceSet(e.Source, UNO_QUERY);
     540         [ +  - ]:         44 :         if (xSourceSet.is())
     541                 :            :         {
     542                 :         44 :             PropertySetInfoCache* pCache = static_cast<PropertySetInfoCache*>(m_pPropertySetCache);
     543         [ +  - ]:         44 :             PropertySetInfoCacheIterator aSetPos = pCache->find(xSourceSet);
     544         [ +  + ]:         44 :             if (aSetPos != pCache->end())
     545         [ +  - ]:         44 :                 pCache->erase(aSetPos);
     546                 :         44 :         }
     547                 :            :     }
     548                 :         46 : }
     549                 :            : 
     550                 :            : // XPropertyChangeListener
     551                 :            : //------------------------------------------------------------------------------
     552                 :      12621 : void SAL_CALL FmXUndoEnvironment::propertyChange(const PropertyChangeEvent& evt) throw(::com::sun::star::uno::RuntimeException)
     553                 :            : {
     554                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::propertyChange" );
     555         [ +  - ]:      12621 :     ::osl::ClearableMutexGuard aGuard( m_aMutex );
     556                 :            : 
     557         [ +  - ]:      12621 :     if (!IsLocked())
     558                 :            :     {
     559         [ +  - ]:      12621 :         Reference< XPropertySet >  xSet(evt.Source, UNO_QUERY);
     560         [ -  + ]:      12621 :         if (!xSet.is())
     561                 :      12621 :             return;
     562                 :            : 
     563                 :            :         // if it's a "default value" property of a control model, set the according "value" property
     564                 :            :         static ::rtl::OUString pDefaultValueProperties[] = {
     565                 :            :             FM_PROP_DEFAULT_TEXT, FM_PROP_DEFAULTCHECKED, FM_PROP_DEFAULT_DATE, FM_PROP_DEFAULT_TIME,
     566                 :            :             FM_PROP_DEFAULT_VALUE, FM_PROP_DEFAULT_SELECT_SEQ, FM_PROP_EFFECTIVE_DEFAULT
     567 [ +  + ][ +  - ]:      12765 :         };
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ #  #  
             #  #  #  # ]
                 [ +  + ]
     568                 :            :         const ::rtl::OUString aValueProperties[] = {
     569                 :            :             FM_PROP_TEXT, FM_PROP_STATE, FM_PROP_DATE, FM_PROP_TIME,
     570                 :            :             FM_PROP_VALUE, FM_PROP_SELECT_SEQ, FM_PROP_EFFECTIVE_VALUE
     571 [ +  - ][ +  - ]:     100968 :         };
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ #  #  
             #  #  #  # ]
     572                 :      12621 :         sal_Int32 nDefaultValueProps = sizeof(pDefaultValueProperties)/sizeof(pDefaultValueProperties[0]);
     573                 :            :         OSL_ENSURE(sizeof(aValueProperties)/sizeof(aValueProperties[0]) == nDefaultValueProps,
     574                 :            :             "FmXUndoEnvironment::propertyChange: inconsistence!");
     575         [ +  + ]:     100968 :         for (sal_Int32 i=0; i<nDefaultValueProps; ++i)
     576                 :            :         {
     577         [ +  + ]:      88347 :             if (0 == evt.PropertyName.compareTo(pDefaultValueProperties[i]))
     578                 :            :             {
     579                 :            :                 try
     580                 :            :                 {
     581 [ +  - ][ +  - ]:        127 :                     xSet->setPropertyValue(aValueProperties[i], evt.NewValue);
     582                 :            :                 }
     583         [ #  # ]:          0 :                 catch(const Exception&)
     584                 :            :                 {
     585                 :            :                     OSL_FAIL("FmXUndoEnvironment::propertyChange: could not adjust the value property!");
     586                 :            :                 }
     587                 :            :             }
     588                 :            :         }
     589                 :            : 
     590                 :            :         // no Undo for transient and readonly props. But unfortunately "transient" is not only that the
     591                 :            :         // "transient" flag is set for the property in question, instead is is somewhat more complex
     592                 :            :         // Transience criterions are:
     593                 :            :         // - the "transient" flag is set for the property
     594                 :            :         // - OR the control has a non-empty COntrolSource property, i.e. is intended to be bound
     595                 :            :         //   to a database column. Note that it doesn't matter here whether the control actually
     596                 :            :         //   *is* bound to a column
     597                 :            :         // - OR the control is bound to an external value via XBindableValue/XValueBinding
     598                 :            :         //   which does not have a "ExternalData" property being <TRUE/>
     599                 :            : 
     600         [ +  + ]:      12621 :         if (!m_pPropertySetCache)
     601 [ +  - ][ +  - ]:        257 :             m_pPropertySetCache = new PropertySetInfoCache;
     602                 :      12621 :         PropertySetInfoCache* pCache = static_cast<PropertySetInfoCache*>(m_pPropertySetCache);
     603                 :            : 
     604                 :            :         // let's see if we know something about the set
     605         [ +  - ]:      12621 :         PropertySetInfoCacheIterator aSetPos = pCache->find(xSet);
     606         [ +  + ]:      12621 :         if (aSetPos == pCache->end())
     607                 :            :         {
     608         [ +  - ]:        631 :             PropertySetInfo aNewEntry;
     609 [ +  - ][ +  - ]:        631 :             if (!::comphelper::hasProperty(FM_PROP_CONTROLSOURCE, xSet))
                 [ +  + ]
     610                 :            :             {
     611                 :        406 :                 aNewEntry.bHasEmptyControlSource = sal_False;
     612                 :            :             }
     613                 :            :             else
     614                 :            :             {
     615                 :            :                 try
     616                 :            :                 {
     617 [ +  - ][ +  - ]:        225 :                     Any aCurrentControlSource = xSet->getPropertyValue(FM_PROP_CONTROLSOURCE);
                 [ +  - ]
     618 [ +  - ][ +  - ]:        225 :                     aNewEntry.bHasEmptyControlSource = !aCurrentControlSource.hasValue() || ::comphelper::getString(aCurrentControlSource).isEmpty();
                 [ +  - ]
           [ #  #  #  # ]
                 [ +  - ]
     619                 :            :                 }
     620         [ #  # ]:          0 :                 catch(const Exception&)
     621                 :            :                 {
     622                 :            :                     DBG_UNHANDLED_EXCEPTION();
     623                 :            :                 }
     624                 :            :             }
     625 [ +  - ][ +  - ]:        631 :             aSetPos = pCache->insert(PropertySetInfoCache::value_type(xSet,aNewEntry)).first;
                 [ +  - ]
     626                 :        631 :             DBG_ASSERT(aSetPos != pCache->end(), "FmXUndoEnvironment::propertyChange : just inserted it ... why it's not there ?");
     627                 :            :         }
     628                 :            :         else
     629                 :            :         {   // is it the DataField property ?
     630 [ +  - ][ +  + ]:      11990 :             if (evt.PropertyName.equals(FM_PROP_CONTROLSOURCE))
     631                 :            :             {
     632 [ +  - ][ +  - ]:        314 :                 aSetPos->second.bHasEmptyControlSource = !evt.NewValue.hasValue() || ::comphelper::getString(evt.NewValue).isEmpty();
         [ -  + ][ +  - ]
                 [ #  # ]
     633                 :            :             }
     634                 :            :         }
     635                 :            : 
     636                 :            :         // now we have access to the cached info about the set
     637                 :            :         // let's see what we know about the property
     638                 :      12621 :         PropertySetInfo::AllProperties& rPropInfos = aSetPos->second.aProps;
     639         [ +  - ]:      12621 :         PropertySetInfo::AllPropertiesIterator aPropertyPos = rPropInfos.find(evt.PropertyName);
     640         [ +  + ]:      12621 :         if (aPropertyPos == rPropInfos.end())
     641                 :            :         {   // nothing 'til now ... have to change this ....
     642                 :            :             PropertyInfo aNewEntry;
     643                 :            : 
     644                 :            :             // the attributes
     645 [ +  - ][ +  - ]:       3983 :             sal_Int32 nAttributes = xSet->getPropertySetInfo()->getPropertyByName(evt.PropertyName).Attributes;
         [ +  - ][ +  - ]
     646 [ +  + ][ +  - ]:       3983 :             aNewEntry.bIsTransientOrReadOnly = ((nAttributes & PropertyAttribute::READONLY) != 0) || ((nAttributes & PropertyAttribute::TRANSIENT) != 0);
     647                 :            : 
     648                 :            :             // check if it is the special "DataFieldProperty"
     649                 :       3983 :             aNewEntry.bIsValueProperty = sal_False;
     650                 :            :             try
     651                 :            :             {
     652 [ +  - ][ +  - ]:       3983 :                 if (::comphelper::hasProperty(FM_PROP_CONTROLSOURCEPROPERTY, xSet))
                 [ +  + ]
     653                 :            :                 {
     654 [ +  - ][ +  - ]:       2889 :                     Any aControlSourceProperty = xSet->getPropertyValue(FM_PROP_CONTROLSOURCEPROPERTY);
         [ +  - ][ #  # ]
     655                 :       2889 :                     ::rtl::OUString sControlSourceProperty;
     656                 :       2889 :                     aControlSourceProperty >>= sControlSourceProperty;
     657                 :            : 
     658                 :       2889 :                     aNewEntry.bIsValueProperty = (sControlSourceProperty.equals(evt.PropertyName));
     659                 :            :                 }
     660                 :            :             }
     661         [ #  # ]:          0 :             catch(const Exception&)
     662                 :            :             {
     663                 :            :                 DBG_UNHANDLED_EXCEPTION();
     664                 :            :             }
     665                 :            : 
     666                 :            :             // insert the new entry
     667         [ +  - ]:       3983 :             aPropertyPos = rPropInfos.insert(PropertySetInfo::AllProperties::value_type(evt.PropertyName,aNewEntry)).first;
     668                 :            :             DBG_ASSERT(aPropertyPos != rPropInfos.end(), "FmXUndoEnvironment::propertyChange : just inserted it ... why it's not there ?");
     669                 :            :         }
     670                 :            : 
     671                 :            :         // now we have access to the cached info about the property affected
     672                 :            :         // and are able to decide whether or not we need an undo action
     673                 :            : 
     674         [ +  - ]:      12621 :         bool bAddUndoAction = rModel.IsUndoEnabled();
     675                 :            :         // no UNDO for transient/readonly properties
     676 [ +  + ][ +  + ]:      12621 :         if ( bAddUndoAction && aPropertyPos->second.bIsTransientOrReadOnly )
                 [ +  + ]
     677                 :       1153 :             bAddUndoAction = false;
     678                 :            : 
     679 [ +  + ][ +  + ]:      12621 :         if ( bAddUndoAction && aPropertyPos->second.bIsValueProperty )
                 [ +  + ]
     680                 :            :         {
     681                 :            :             // no UNDO when the "value" property changes, but the ControlSource is non-empty
     682                 :            :             // (in this case the control is intended to be bound to a database column)
     683         [ +  + ]:        603 :             if ( !aSetPos->second.bHasEmptyControlSource )
     684                 :        324 :                 bAddUndoAction = false;
     685                 :            : 
     686                 :            :             // no UNDO if the control is currently bound to an external value
     687         [ +  + ]:        603 :             if ( bAddUndoAction )
     688                 :            :             {
     689         [ +  - ]:        279 :                 Reference< XBindableValue > xBindable( evt.Source, UNO_QUERY );
     690                 :        279 :                 Reference< XValueBinding > xBinding;
     691         [ +  + ]:        279 :                 if ( xBindable.is() )
     692 [ +  - ][ +  - ]:        197 :                     xBinding = xBindable->getValueBinding();
                 [ +  - ]
     693                 :            : 
     694                 :        279 :                 Reference< XPropertySet > xBindingProps;
     695                 :        279 :                 Reference< XPropertySetInfo > xBindingPropsPSI;
     696         [ +  + ]:        279 :                 if ( xBindable.is() )
     697         [ +  - ]:        197 :                     xBindingProps.set( xBinding, UNO_QUERY );
     698         [ -  + ]:        279 :                 if ( xBindingProps.is() )
     699 [ #  # ][ #  # ]:          0 :                     xBindingPropsPSI = xBindingProps->getPropertySetInfo();
                 [ #  # ]
     700                 :            :                 // TODO: we should cache all those things, else this might be too expensive.
     701                 :            :                 // However, this requires we're notified of changes in the value binding
     702                 :            : 
     703 [ +  + ][ +  - ]:        279 :                 static const ::rtl::OUString s_sExternalData( RTL_CONSTASCII_USTRINGPARAM( "ExternalData" ) );
         [ +  - ][ #  # ]
     704 [ -  + ][ #  # ]:        279 :                 if ( xBindingPropsPSI.is() && xBindingPropsPSI->hasPropertyByName( s_sExternalData ) )
         [ #  # ][ #  # ]
                 [ -  + ]
     705                 :            :                 {
     706                 :          0 :                     sal_Bool bExternalData = sal_True;
     707 [ #  # ][ #  # ]:          0 :                     OSL_VERIFY( xBindingProps->getPropertyValue( s_sExternalData ) >>= bExternalData );
     708                 :          0 :                     bAddUndoAction = !bExternalData;
     709                 :            :                 }
     710                 :            :                 else
     711                 :        279 :                     bAddUndoAction = !xBinding.is();
     712                 :            :             }
     713                 :            :         }
     714                 :            : 
     715 [ +  + ][ +  - ]:      12621 :         if ( bAddUndoAction && ( evt.PropertyName == FM_PROP_STRINGITEMLIST ) )
         [ +  + ][ +  + ]
           [ +  +  #  # ]
     716                 :            :         {
     717         [ +  - ]:        132 :             Reference< XListEntrySink > xSink( evt.Source, UNO_QUERY );
     718 [ +  - ][ +  - ]:        132 :             if ( xSink.is() && xSink->getListEntrySource().is() )
         [ +  - ][ -  + ]
                 [ +  - ]
           [ -  +  #  # ]
     719                 :            :                 // #i41029# / 2005-01-31 / frank.schoenheit@sun.com
     720                 :        132 :                 bAddUndoAction = false;
     721                 :            :         }
     722                 :            : 
     723         [ +  + ]:      12621 :         if ( bAddUndoAction )
     724                 :            :         {
     725         [ +  - ]:      11090 :             aGuard.clear();
     726                 :            :             // TODO: this is a potential race condition: two threads here could in theory
     727                 :            :             // add their undo actions out-of-order
     728                 :            : 
     729         [ +  - ]:      11090 :             SolarMutexGuard aSolarGuard;
     730 [ +  - ][ +  - ]:      11090 :             rModel.AddUndo(new FmUndoPropertyAction(rModel, evt));
         [ +  - ][ +  - ]
     731 [ +  + ][ +  - ]:     100968 :         }
                 [ #  # ]
     732                 :            :     }
     733                 :            :     else
     734                 :            :     {
     735                 :            :         // if it's the DataField property we may have to adjust our cache
     736 [ #  # ][ #  # ]:          0 :         if (m_pPropertySetCache && evt.PropertyName.equals(FM_PROP_CONTROLSOURCE))
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     737                 :            :         {
     738         [ #  # ]:          0 :             Reference< XPropertySet >  xSet(evt.Source, UNO_QUERY);
     739                 :          0 :             PropertySetInfoCache* pCache = static_cast<PropertySetInfoCache*>(m_pPropertySetCache);
     740         [ #  # ]:          0 :             PropertySetInfo& rSetInfo = (*pCache)[xSet];
     741 [ #  # ][ #  # ]:      12621 :             rSetInfo.bHasEmptyControlSource = !evt.NewValue.hasValue() || ::comphelper::getString(evt.NewValue).isEmpty();
         [ #  # ][ #  # ]
                 [ #  # ]
     742                 :            :         }
     743 [ +  - ][ +  - ]:      12621 :     }
     744                 :            : }
     745                 :            : 
     746                 :            : // XContainerListener
     747                 :            : //------------------------------------------------------------------------------
     748                 :        807 : void SAL_CALL FmXUndoEnvironment::elementInserted(const ContainerEvent& evt) throw(::com::sun::star::uno::RuntimeException)
     749                 :            : {
     750                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::elementInserted" );
     751         [ +  - ]:        807 :     SolarMutexGuard aSolarGuard;
     752         [ +  - ]:        807 :     ::osl::MutexGuard aGuard( m_aMutex );
     753                 :            : 
     754                 :            :     // neues Object zum lauschen
     755                 :        807 :     Reference< XInterface >  xIface;
     756         [ +  - ]:        807 :     evt.Element >>= xIface;
     757                 :            :     OSL_ENSURE(xIface.is(), "FmXUndoEnvironment::elementInserted: invalid container notification!");
     758         [ +  - ]:        807 :     AddElement(xIface);
     759                 :            : 
     760 [ +  - ][ +  - ]:        807 :     implSetModified();
                 [ +  - ]
     761                 :        807 : }
     762                 :            : 
     763                 :            : //------------------------------------------------------------------------------
     764                 :       2371 : void FmXUndoEnvironment::implSetModified()
     765                 :            : {
     766                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::implSetModified" );
     767 [ +  - ][ +  + ]:       2371 :     if ( !IsLocked() && rModel.GetObjectShell() )
                 [ +  + ]
     768                 :            :     {
     769                 :       1932 :         rModel.GetObjectShell()->SetModified( sal_True );
     770                 :            :     }
     771                 :       2371 : }
     772                 :            : 
     773                 :            : //------------------------------------------------------------------------------
     774                 :         12 : void SAL_CALL FmXUndoEnvironment::elementReplaced(const ContainerEvent& evt) throw(::com::sun::star::uno::RuntimeException)
     775                 :            : {
     776                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::elementReplaced" );
     777         [ +  - ]:         12 :     SolarMutexGuard aSolarGuard;
     778         [ +  - ]:         12 :     ::osl::MutexGuard aGuard( m_aMutex );
     779                 :            : 
     780                 :         12 :     Reference< XInterface >  xIface;
     781         [ +  - ]:         12 :     evt.ReplacedElement >>= xIface;
     782                 :            :     OSL_ENSURE(xIface.is(), "FmXUndoEnvironment::elementReplaced: invalid container notification!");
     783         [ +  - ]:         12 :     RemoveElement(xIface);
     784                 :            : 
     785         [ +  - ]:         12 :     evt.Element >>= xIface;
     786         [ +  - ]:         12 :     AddElement(xIface);
     787                 :            : 
     788 [ +  - ][ +  - ]:         12 :     implSetModified();
                 [ +  - ]
     789                 :         12 : }
     790                 :            : 
     791                 :            : //------------------------------------------------------------------------------
     792                 :        451 : void SAL_CALL FmXUndoEnvironment::elementRemoved(const ContainerEvent& evt) throw(::com::sun::star::uno::RuntimeException)
     793                 :            : {
     794                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::elementRemoved" );
     795         [ +  - ]:        451 :     SolarMutexGuard aSolarGuard;
     796         [ +  - ]:        451 :     ::osl::MutexGuard aGuard( m_aMutex );
     797                 :            : 
     798         [ +  - ]:        451 :     Reference< XInterface >  xIface( evt.Element, UNO_QUERY );
     799                 :            :     OSL_ENSURE(xIface.is(), "FmXUndoEnvironment::elementRemoved: invalid container notification!");
     800         [ +  - ]:        451 :     RemoveElement(xIface);
     801                 :            : 
     802 [ +  - ][ +  - ]:        451 :     implSetModified();
                 [ +  - ]
     803                 :        451 : }
     804                 :            : 
     805                 :            : //------------------------------------------------------------------------------
     806                 :       1101 : void SAL_CALL FmXUndoEnvironment::modified( const EventObject& /*aEvent*/ ) throw (RuntimeException)
     807                 :            : {
     808                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::modified" );
     809                 :       1101 :     implSetModified();
     810                 :       1101 : }
     811                 :            : 
     812                 :            : //------------------------------------------------------------------------------
     813                 :        336 : void FmXUndoEnvironment::AddForms(const Reference< XNameContainer > & rForms)
     814                 :            : {
     815                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::AddForms" );
     816         [ +  - ]:        336 :     Lock();
     817         [ +  - ]:        336 :     Reference< XInterface >  xInt(rForms, UNO_QUERY);
     818         [ +  - ]:        336 :     AddElement(xInt);
     819         [ +  - ]:        336 :     UnLock();
     820                 :        336 : }
     821                 :            : 
     822                 :            : //------------------------------------------------------------------------------
     823                 :        322 : void FmXUndoEnvironment::RemoveForms(const Reference< XNameContainer > & rForms)
     824                 :            : {
     825                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::RemoveForms" );
     826         [ +  - ]:        322 :     Lock();
     827         [ +  - ]:        322 :     Reference< XInterface >  xInt(rForms, UNO_QUERY);
     828         [ +  - ]:        322 :     RemoveElement(xInt);
     829         [ +  - ]:        322 :     UnLock();
     830                 :        322 : }
     831                 :            : 
     832                 :            : //------------------------------------------------------------------------------
     833                 :         79 : void FmXUndoEnvironment::TogglePropertyListening(const Reference< XInterface > & Element)
     834                 :            : {
     835                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::TogglePropertyListening" );
     836                 :            :     // am Container horchen
     837         [ +  - ]:         79 :     Reference< XIndexContainer >  xContainer(Element, UNO_QUERY);
     838         [ +  + ]:         79 :     if (xContainer.is())
     839                 :            :     {
     840 [ +  - ][ +  - ]:         26 :         sal_uInt32 nCount = xContainer->getCount();
     841                 :         26 :         Reference< XInterface >  xIface;
     842         [ +  + ]:         92 :         for (sal_uInt32 i = 0; i < nCount; i++)
     843                 :            :         {
     844 [ +  - ][ +  - ]:         66 :             xContainer->getByIndex(i) >>= xIface;
                 [ +  - ]
     845         [ +  - ]:         66 :             TogglePropertyListening(xIface);
     846                 :         26 :         }
     847                 :            :     }
     848                 :            : 
     849         [ +  - ]:         79 :     Reference< XPropertySet >  xSet(Element, UNO_QUERY);
     850         [ +  + ]:         79 :     if (xSet.is())
     851                 :            :     {
     852         [ -  + ]:         66 :         if (!bReadOnly)
     853 [ #  # ][ #  # ]:          0 :             xSet->addPropertyChangeListener( ::rtl::OUString(), this );
                 [ #  # ]
     854                 :            :         else
     855 [ +  - ][ +  - ]:         66 :             xSet->removePropertyChangeListener( ::rtl::OUString(), this );
                 [ +  - ]
     856                 :         79 :     }
     857                 :         79 : }
     858                 :            : 
     859                 :            : 
     860                 :            : //------------------------------------------------------------------------------
     861                 :       1240 : void FmXUndoEnvironment::switchListening( const Reference< XIndexContainer >& _rxContainer, bool _bStartListening ) SAL_THROW(())
     862                 :            : {
     863                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::switchListening" );
     864                 :            :     OSL_PRECOND( _rxContainer.is(), "FmXUndoEnvironment::switchListening: invalid container!" );
     865         [ -  + ]:       1240 :     if ( !_rxContainer.is() )
     866                 :       1240 :         return;
     867                 :            : 
     868                 :            :     try
     869                 :            :     {
     870                 :            :         // if it's an EventAttacherManager, then we need to listen for
     871                 :            :         // script events
     872         [ +  - ]:       1240 :         Reference< XEventAttacherManager > xManager( _rxContainer, UNO_QUERY );
     873         [ +  - ]:       1240 :         if ( xManager.is() )
     874                 :            :         {
     875         [ +  + ]:       1240 :             if ( _bStartListening )
     876                 :            :             {
     877         [ +  - ]:        628 :                 m_pScriptingEnv->registerEventAttacherManager( xManager );
     878         [ +  - ]:        628 :                 if ( m_vbaListener.is() )
     879 [ +  - ][ +  - ]:        628 :                     xManager->addScriptListener( m_vbaListener );
     880                 :            :             }
     881                 :            :             else
     882                 :            :             {
     883         [ +  - ]:        612 :                 m_pScriptingEnv->revokeEventAttacherManager( xManager );
     884         [ +  - ]:        612 :                 if ( m_vbaListener.is() )
     885 [ +  - ][ +  - ]:        612 :                     xManager->removeScriptListener( m_vbaListener );
     886                 :            :             }
     887                 :            :         }
     888                 :            : 
     889                 :            :         // also handle all children of this element
     890 [ +  - ][ +  - ]:       1240 :         sal_uInt32 nCount = _rxContainer->getCount();
     891                 :       1240 :         Reference< XInterface > xInterface;
     892         [ +  + ]:       1624 :         for ( sal_uInt32 i = 0; i < nCount; ++i )
     893                 :            :         {
     894 [ +  - ][ +  - ]:        384 :             _rxContainer->getByIndex( i ) >>= xInterface;
                 [ +  - ]
     895         [ +  + ]:        384 :             if ( _bStartListening )
     896         [ +  - ]:         37 :                 AddElement( xInterface );
     897                 :            :             else
     898         [ +  - ]:        347 :                 RemoveElement( xInterface );
     899                 :            :         }
     900                 :            : 
     901                 :            :         // be notified of any changes in the container elements
     902         [ +  - ]:       1240 :         Reference< XContainer > xSimpleContainer( _rxContainer, UNO_QUERY );
     903                 :            :         OSL_ENSURE( xSimpleContainer.is(), "FmXUndoEnvironment::switchListening: how are we expected to be notified of changes in the container?" );
     904         [ +  - ]:       1240 :         if ( xSimpleContainer.is() )
     905                 :            :         {
     906         [ +  + ]:       1240 :             if ( _bStartListening )
     907 [ +  - ][ +  - ]:        628 :                 xSimpleContainer->addContainerListener( this );
                 [ +  - ]
     908                 :            :             else
     909 [ +  - ][ +  - ]:        612 :                 xSimpleContainer->removeContainerListener( this );
                 [ +  - ]
     910         [ #  # ]:       1240 :         }
     911                 :            :     }
     912                 :          0 :     catch( const Exception& )
     913                 :            :     {
     914                 :            :         OSL_FAIL( "FmXUndoEnvironment::switchListening: caught an exception!" );
     915                 :            :     }
     916                 :            : }
     917                 :            : 
     918                 :            : //------------------------------------------------------------------------------
     919                 :       2324 : void FmXUndoEnvironment::switchListening( const Reference< XInterface >& _rxObject, bool _bStartListening ) SAL_THROW(())
     920                 :            : {
     921                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::switchListening" );
     922                 :            :     OSL_PRECOND( _rxObject.is(), "FmXUndoEnvironment::switchListening: how should I listen at a NULL object?" );
     923                 :            : 
     924                 :            :     try
     925                 :            :     {
     926         [ +  + ]:       2324 :         if ( !bReadOnly )
     927                 :            :         {
     928         [ +  - ]:       2245 :             Reference< XPropertySet > xProps( _rxObject, UNO_QUERY );
     929         [ +  + ]:       2245 :             if ( xProps.is() )
     930                 :            :             {
     931         [ +  + ]:       1600 :                 if ( _bStartListening )
     932 [ +  - ][ +  - ]:        856 :                     xProps->addPropertyChangeListener( ::rtl::OUString(), this );
                 [ +  - ]
     933                 :            :                 else
     934 [ +  - ][ +  - ]:        744 :                     xProps->removePropertyChangeListener( ::rtl::OUString(), this );
                 [ +  - ]
     935                 :       2245 :             }
     936                 :            :         }
     937                 :            : 
     938         [ +  - ]:       2324 :         Reference< XModifyBroadcaster > xBroadcaster( _rxObject, UNO_QUERY );
     939         [ +  + ]:       2324 :         if ( xBroadcaster.is() )
     940                 :            :         {
     941         [ +  + ]:        223 :             if ( _bStartListening )
     942 [ +  - ][ +  - ]:        115 :                 xBroadcaster->addModifyListener( this );
                 [ +  - ]
     943                 :            :             else
     944 [ +  - ][ +  - ]:        108 :                 xBroadcaster->removeModifyListener( this );
                 [ +  - ]
     945         [ #  # ]:       2324 :         }
     946                 :            :     }
     947                 :          0 :     catch( const Exception& )
     948                 :            :     {
     949                 :            :         OSL_FAIL( "FmXUndoEnvironment::switchListening: caught an exception!" );
     950                 :            :     }
     951                 :       2324 : }
     952                 :            : 
     953                 :            : //------------------------------------------------------------------------------
     954                 :       1192 : void FmXUndoEnvironment::AddElement(const Reference< XInterface >& _rxElement )
     955                 :            : {
     956                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::AddElement" );
     957                 :            :     OSL_ENSURE( !m_bDisposed, "FmXUndoEnvironment::AddElement: not when I'm already disposed!" );
     958                 :            : 
     959                 :            :     // am Container horchen
     960         [ +  - ]:       1192 :     Reference< XIndexContainer > xContainer( _rxElement, UNO_QUERY );
     961         [ +  + ]:       1192 :     if ( xContainer.is() )
     962         [ +  - ]:        628 :         switchListening( xContainer, true );
     963                 :            : 
     964         [ +  - ]:       1192 :     switchListening( _rxElement, true );
     965                 :       1192 : }
     966                 :            : 
     967                 :            : //------------------------------------------------------------------------------
     968                 :       1132 : void FmXUndoEnvironment::RemoveElement(const Reference< XInterface >& _rxElement)
     969                 :            : {
     970                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmXUndoEnvironment::RemoveElement" );
     971         [ +  - ]:       1132 :     if ( m_bDisposed )
     972                 :       1132 :         return;
     973                 :            : 
     974         [ +  - ]:       1132 :     switchListening( _rxElement, false );
     975                 :            : 
     976         [ +  + ]:       1132 :     if (!bReadOnly)
     977                 :            :     {
     978                 :            :         // reset the ActiveConnection if the form is to be removed. This will (should) free the resources
     979                 :            :         // associated with this connection
     980                 :            :         // 86299 - 05/02/2001 - frank.schoenheit@germany.sun.com
     981         [ +  - ]:       1053 :         Reference< XForm > xForm( _rxElement, UNO_QUERY );
     982         [ +  - ]:       1053 :         Reference< XPropertySet > xFormProperties( xForm, UNO_QUERY );
     983         [ +  + ]:       1053 :         if ( xFormProperties.is() )
     984 [ +  - ][ +  - ]:        259 :             if ( !::svxform::OStaticDataAccessTools().isEmbeddedInDatabase( _rxElement ) )
         [ +  - ][ +  - ]
     985                 :            :                 // (if there is a connection in the context of the component, setting
     986                 :            :                 // a new connection would be vetoed, anyway)
     987                 :            :                 // #i34196#
     988 [ +  - ][ +  - ]:       1053 :                 xFormProperties->setPropertyValue( FM_PROP_ACTIVE_CONNECTION, Any() );
                 [ +  - ]
     989                 :            :     }
     990                 :            : 
     991         [ +  - ]:       1132 :     Reference< XIndexContainer > xContainer( _rxElement, UNO_QUERY );
     992         [ +  + ]:       1132 :     if ( xContainer.is() )
     993         [ +  - ]:       1132 :         switchListening( xContainer, false );
     994                 :            : }
     995                 :            : 
     996                 :            : 
     997                 :            : //------------------------------------------------------------------------------
     998                 :      11090 : FmUndoPropertyAction::FmUndoPropertyAction(FmFormModel& rNewMod, const PropertyChangeEvent& evt)
     999                 :            :                      :SdrUndoAction(rNewMod)
    1000                 :            :                      ,xObj(evt.Source, UNO_QUERY)
    1001                 :            :                      ,aPropertyName(evt.PropertyName)
    1002                 :            :                      ,aNewValue(evt.NewValue)
    1003         [ +  - ]:      11090 :                      ,aOldValue(evt.OldValue)
    1004                 :            : {
    1005                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmUndoPropertyAction::FmUndoPropertyAction" );
    1006         [ +  - ]:      11090 :     if (rNewMod.GetObjectShell())
    1007         [ +  - ]:      11090 :         rNewMod.GetObjectShell()->SetModified(sal_True);
    1008         [ +  + ]:      11090 :     if(static_STR_UNDO_PROPERTY.Len() == 0)
    1009 [ +  - ][ +  - ]:         11 :         static_STR_UNDO_PROPERTY = SVX_RESSTR(RID_STR_UNDO_PROPERTY);
                 [ +  - ]
    1010                 :      11090 : }
    1011                 :            : 
    1012                 :            : 
    1013                 :            : //------------------------------------------------------------------------------
    1014                 :          0 : void FmUndoPropertyAction::Undo()
    1015                 :            : {
    1016                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmUndoPropertyAction::Undo" );
    1017                 :          0 :     FmXUndoEnvironment& rEnv = ((FmFormModel&)rMod).GetUndoEnv();
    1018                 :            : 
    1019 [ #  # ][ #  # ]:          0 :     if (xObj.is() && !rEnv.IsLocked())
                 [ #  # ]
    1020                 :            :     {
    1021                 :          0 :         rEnv.Lock();
    1022                 :            :         try
    1023                 :            :         {
    1024 [ #  # ][ #  # ]:          0 :             xObj->setPropertyValue( aPropertyName, aOldValue );
    1025                 :            :         }
    1026                 :          0 :         catch( const Exception& )
    1027                 :            :         {
    1028                 :            :             OSL_FAIL( "FmUndoPropertyAction::Undo: caught an exception!" );
    1029                 :            :         }
    1030                 :          0 :         rEnv.UnLock();
    1031                 :            :     }
    1032         [ #  # ]:          0 : }
    1033                 :            : 
    1034                 :            : //------------------------------------------------------------------------------
    1035                 :          0 : void FmUndoPropertyAction::Redo()
    1036                 :            : {
    1037                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmUndoPropertyAction::Redo" );
    1038                 :          0 :     FmXUndoEnvironment& rEnv = ((FmFormModel&)rMod).GetUndoEnv();
    1039                 :            : 
    1040 [ #  # ][ #  # ]:          0 :     if (xObj.is() && !rEnv.IsLocked())
                 [ #  # ]
    1041                 :            :     {
    1042                 :          0 :         rEnv.Lock();
    1043                 :            :         try
    1044                 :            :         {
    1045 [ #  # ][ #  # ]:          0 :             xObj->setPropertyValue( aPropertyName, aNewValue );
    1046                 :            :         }
    1047                 :          0 :         catch( const Exception& )
    1048                 :            :         {
    1049                 :            :             OSL_FAIL( "FmUndoPropertyAction::Redo: caught an exception!" );
    1050                 :            :         }
    1051                 :          0 :         rEnv.UnLock();
    1052                 :            :     }
    1053         [ #  # ]:          0 : }
    1054                 :            : 
    1055                 :            : //------------------------------------------------------------------------------
    1056                 :      11181 : rtl::OUString FmUndoPropertyAction::GetComment() const
    1057                 :            : {
    1058                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmUndoPropertyAction::GetComment" );
    1059         [ +  - ]:      11181 :     String aStr(static_STR_UNDO_PROPERTY);
    1060                 :            : 
    1061 [ +  - ][ +  - ]:      11181 :     aStr.SearchAndReplace( rtl::OUString('#'), aPropertyName );
         [ +  - ][ +  - ]
                 [ +  - ]
    1062 [ +  - ][ +  - ]:      11181 :     return aStr;
    1063                 :            : }
    1064                 :            : 
    1065                 :            : 
    1066                 :            : DBG_NAME(FmUndoContainerAction);
    1067                 :            : //------------------------------------------------------------------------------
    1068                 :        246 : FmUndoContainerAction::FmUndoContainerAction(FmFormModel& _rMod,
    1069                 :            :                                              Action _eAction,
    1070                 :            :                                              const Reference< XIndexContainer > & xCont,
    1071                 :            :                                              const Reference< XInterface > & xElem,
    1072                 :            :                                              sal_Int32 nIdx)
    1073                 :            :                       :SdrUndoAction( _rMod )
    1074                 :            :                       ,m_xContainer( xCont )
    1075                 :            :                       ,m_nIndex( nIdx )
    1076         [ +  - ]:        246 :                       ,m_eAction( _eAction )
    1077                 :            : {
    1078                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmUndoContainerAction::FmUndoContainerAction" );
    1079                 :            :     OSL_ENSURE( nIdx >= 0, "FmUndoContainerAction::FmUndoContainerAction: invalid index!" );
    1080                 :            :         // some old code suggested this could be a valid argument. However, this code was
    1081                 :            :         // buggy, and it *seemed* that nobody used it - so it was removed.
    1082                 :            : 
    1083                 :            :     DBG_CTOR(FmUndoContainerAction,NULL);
    1084 [ +  - ][ +  - ]:        246 :     if ( xCont.is() && xElem.is() )
                 [ +  - ]
    1085                 :            :     {
    1086                 :            :         // normalize
    1087 [ +  - ][ +  - ]:        246 :         m_xElement = m_xElement.query( xElem );
    1088         [ -  + ]:        246 :         if ( m_eAction == Removed )
    1089                 :            :         {
    1090         [ #  # ]:          0 :             if (m_nIndex >= 0)
    1091                 :            :             {
    1092         [ #  # ]:          0 :                 Reference< XEventAttacherManager >  xManager( xCont, UNO_QUERY );
    1093         [ #  # ]:          0 :                 if ( xManager.is() )
    1094 [ #  # ][ #  # ]:          0 :                     m_aEvents = xManager->getScriptEvents(m_nIndex);
         [ #  # ][ #  # ]
    1095                 :            :             }
    1096                 :            :             else
    1097         [ #  # ]:          0 :                 m_xElement = NULL;
    1098                 :            : 
    1099                 :            :             // we now own the element
    1100         [ #  # ]:          0 :             m_xOwnElement = m_xElement;
    1101                 :            :         }
    1102                 :            :     }
    1103                 :        246 : }
    1104                 :            : 
    1105                 :            : //------------------------------------------------------------------------------
    1106         [ +  - ]:        246 : FmUndoContainerAction::~FmUndoContainerAction()
    1107                 :            : {
    1108                 :            :     // if we own the object ....
    1109         [ +  - ]:        246 :     DisposeElement( m_xOwnElement );
    1110                 :            :     DBG_DTOR(FmUndoContainerAction,NULL);
    1111         [ -  + ]:        492 : }
    1112                 :            : 
    1113                 :            : //------------------------------------------------------------------------------
    1114                 :            : 
    1115                 :        246 : void FmUndoContainerAction::DisposeElement( const Reference< XInterface > & xElem )
    1116                 :            : {
    1117         [ +  - ]:        246 :     Reference< XComponent > xComp( xElem, UNO_QUERY );
    1118         [ -  + ]:        246 :     if ( xComp.is() )
    1119                 :            :     {
    1120                 :            :         // and the object does not have a parent
    1121         [ #  # ]:          0 :         Reference< XChild >  xChild( xElem, UNO_QUERY );
    1122 [ #  # ][ #  # ]:          0 :         if ( xChild.is() && !xChild->getParent().is() )
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
    1123                 :            :             // -> dispose it
    1124 [ #  # ][ #  # ]:          0 :             xComp->dispose();
    1125                 :        246 :     }
    1126                 :        246 : }
    1127                 :            : 
    1128                 :            : //------------------------------------------------------------------------------
    1129                 :          0 : void FmUndoContainerAction::implReInsert( ) SAL_THROW( ( Exception ) )
    1130                 :            : {
    1131                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmUndoContainerAction::implReInsert" );
    1132         [ #  # ]:          0 :     if ( m_xContainer->getCount() >= m_nIndex )
    1133                 :            :     {
    1134                 :            :         // insert the element
    1135                 :          0 :         Any aVal;
    1136 [ #  # ][ #  # ]:          0 :         if ( m_xContainer->getElementType() == ::getCppuType( static_cast< const Reference< XFormComponent >* >( NULL ) ) )
         [ #  # ][ #  # ]
    1137                 :            :         {
    1138 [ #  # ][ #  # ]:          0 :             aVal <<= Reference< XFormComponent >( m_xElement, UNO_QUERY );
    1139                 :            :         }
    1140                 :            :         else
    1141                 :            :         {
    1142 [ #  # ][ #  # ]:          0 :             aVal <<= Reference< XForm >( m_xElement, UNO_QUERY );
    1143                 :            :         }
    1144 [ #  # ][ #  # ]:          0 :         m_xContainer->insertByIndex( m_nIndex, aVal );
    1145                 :            : 
    1146                 :            :         OSL_ENSURE( getElementPos( m_xContainer.get(), m_xElement ) == m_nIndex, "FmUndoContainerAction::implReInsert: insertion did not work!" );
    1147                 :            : 
    1148                 :            :         // register the events
    1149         [ #  # ]:          0 :         Reference< XEventAttacherManager >  xManager( m_xContainer, UNO_QUERY );
    1150         [ #  # ]:          0 :         if ( xManager.is() )
    1151 [ #  # ][ #  # ]:          0 :             xManager->registerScriptEvents( m_nIndex, m_aEvents );
    1152                 :            : 
    1153                 :            :         // we don't own the object anymore
    1154         [ #  # ]:          0 :         m_xOwnElement = NULL;
    1155                 :            :     }
    1156                 :          0 : }
    1157                 :            : 
    1158                 :            : //------------------------------------------------------------------------------
    1159                 :          0 : void FmUndoContainerAction::implReRemove( ) SAL_THROW( ( Exception ) )
    1160                 :            : {
    1161                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmUndoContainerAction::implReRemove" );
    1162                 :          0 :     Reference< XInterface > xElement;
    1163 [ #  # ][ #  # ]:          0 :     if ( ( m_nIndex >= 0 ) && ( m_nIndex < m_xContainer->getCount() ) )
         [ #  # ][ #  # ]
                 [ #  # ]
    1164 [ #  # ][ #  # ]:          0 :         m_xContainer->getByIndex( m_nIndex ) >>= xElement;
                 [ #  # ]
    1165                 :            : 
    1166 [ #  # ][ #  # ]:          0 :     if ( xElement != m_xElement )
    1167                 :            :     {
    1168                 :            :         // the indexes in the container changed. Okay, so go the long way and
    1169                 :            :         // manually determine the index
    1170 [ #  # ][ #  # ]:          0 :         m_nIndex = getElementPos( m_xContainer.get(), m_xElement );
                 [ #  # ]
    1171         [ #  # ]:          0 :         if ( m_nIndex != -1 )
    1172         [ #  # ]:          0 :             xElement = m_xElement;
    1173                 :            :     }
    1174                 :            : 
    1175                 :            :     OSL_ENSURE( xElement == m_xElement, "FmUndoContainerAction::implReRemove: cannot find the element which I'm responsible for!" );
    1176 [ #  # ][ #  # ]:          0 :     if ( xElement == m_xElement )
    1177                 :            :     {
    1178         [ #  # ]:          0 :         Reference< XEventAttacherManager >  xManager( m_xContainer, UNO_QUERY );
    1179         [ #  # ]:          0 :         if ( xManager.is() )
    1180 [ #  # ][ #  # ]:          0 :             m_aEvents = xManager->getScriptEvents( m_nIndex );
         [ #  # ][ #  # ]
    1181 [ #  # ][ #  # ]:          0 :         m_xContainer->removeByIndex( m_nIndex );
    1182                 :            :         // from now on, we own this object
    1183         [ #  # ]:          0 :         m_xOwnElement = m_xElement;
    1184                 :          0 :     }
    1185                 :          0 : }
    1186                 :            : 
    1187                 :            : //------------------------------------------------------------------------------
    1188                 :          0 : void FmUndoContainerAction::Undo()
    1189                 :            : {
    1190                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmUndoContainerAction::Undo" );
    1191                 :          0 :     FmXUndoEnvironment& rEnv = static_cast< FmFormModel& >( rMod ).GetUndoEnv();
    1192                 :            : 
    1193 [ #  # ][ #  # ]:          0 :     if ( m_xContainer.is() && !rEnv.IsLocked() && m_xElement.is() )
         [ #  # ][ #  # ]
    1194                 :            :     {
    1195                 :          0 :         rEnv.Lock();
    1196                 :            :         try
    1197                 :            :         {
    1198      [ #  #  # ]:          0 :             switch ( m_eAction )
    1199                 :            :             {
    1200                 :            :             case Inserted:
    1201         [ #  # ]:          0 :                 implReRemove();
    1202                 :          0 :                 break;
    1203                 :            : 
    1204                 :            :             case Removed:
    1205         [ #  # ]:          0 :                 implReInsert();
    1206                 :          0 :                 break;
    1207                 :            :             }
    1208                 :            :         }
    1209                 :          0 :         catch( const Exception& )
    1210                 :            :         {
    1211                 :            :             OSL_FAIL( "FmUndoContainerAction::Undo: caught an exception!" );
    1212                 :            :         }
    1213                 :          0 :         rEnv.UnLock();
    1214                 :            :     }
    1215         [ #  # ]:          0 : }
    1216                 :            : 
    1217                 :            : //------------------------------------------------------------------------------
    1218                 :          0 : void FmUndoContainerAction::Redo()
    1219                 :            : {
    1220                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmUndoContainerAction::Redo" );
    1221                 :          0 :     FmXUndoEnvironment& rEnv = static_cast< FmFormModel& >( rMod ).GetUndoEnv();
    1222 [ #  # ][ #  # ]:          0 :     if ( m_xContainer.is() && !rEnv.IsLocked() && m_xElement.is() )
         [ #  # ][ #  # ]
    1223                 :            :     {
    1224                 :          0 :         rEnv.Lock();
    1225                 :            :         try
    1226                 :            :         {
    1227      [ #  #  # ]:          0 :             switch ( m_eAction )
    1228                 :            :             {
    1229                 :            :             case Inserted:
    1230         [ #  # ]:          0 :                 implReInsert();
    1231                 :          0 :                 break;
    1232                 :            : 
    1233                 :            :             case Removed:
    1234         [ #  # ]:          0 :                 implReRemove();
    1235                 :          0 :                 break;
    1236                 :            :             }
    1237                 :            :         }
    1238                 :          0 :         catch( const Exception& )
    1239                 :            :         {
    1240                 :            :             OSL_FAIL( "FmUndoContainerAction::Redo: caught an exception!" );
    1241                 :            :         }
    1242                 :          0 :         rEnv.UnLock();
    1243                 :            :     }
    1244         [ #  # ]:          0 : }
    1245                 :            : 
    1246                 :            : //------------------------------------------------------------------------------
    1247                 :          0 : FmUndoModelReplaceAction::FmUndoModelReplaceAction(FmFormModel& _rMod, SdrUnoObj* _pObject, const Reference< XControlModel > & _xReplaced)
    1248                 :            :     :SdrUndoAction(_rMod)
    1249                 :            :     ,m_xReplaced(_xReplaced)
    1250                 :          0 :     ,m_pObject(_pObject)
    1251                 :            : {
    1252                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmUndoModelReplaceAction::FmUndoModelReplaceAction" );
    1253                 :          0 : }
    1254                 :            : 
    1255                 :            : //------------------------------------------------------------------------------
    1256                 :          0 : FmUndoModelReplaceAction::~FmUndoModelReplaceAction()
    1257                 :            : {
    1258                 :            :     // dispose our element if nobody else is responsible for
    1259         [ #  # ]:          0 :     DisposeElement(m_xReplaced);
    1260         [ #  # ]:          0 : }
    1261                 :            : 
    1262                 :            : //------------------------------------------------------------------------------
    1263                 :            : 
    1264                 :          0 : void FmUndoModelReplaceAction::DisposeElement( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>& xReplaced )
    1265                 :            : {
    1266         [ #  # ]:          0 :     Reference< XComponent >  xComp(xReplaced, UNO_QUERY);
    1267         [ #  # ]:          0 :     if (xComp.is())
    1268                 :            :     {
    1269         [ #  # ]:          0 :         Reference< XChild >  xChild(xReplaced, UNO_QUERY);
    1270 [ #  # ][ #  # ]:          0 :         if (!xChild.is() || !xChild->getParent().is())
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
    1271 [ #  # ][ #  # ]:          0 :             xComp->dispose();
    1272                 :          0 :     }
    1273                 :          0 : }
    1274                 :            : 
    1275                 :            : //------------------------------------------------------------------------------
    1276                 :          0 : void FmUndoModelReplaceAction::Undo()
    1277                 :            : {
    1278                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmUndoModelReplaceAction::Undo" );
    1279                 :            :     try
    1280                 :            :     {
    1281         [ #  # ]:          0 :         Reference< XControlModel > xCurrentModel( m_pObject->GetUnoControlModel() );
    1282                 :            : 
    1283                 :            :         // replace the model within the parent
    1284         [ #  # ]:          0 :         Reference< XChild > xCurrentAsChild( xCurrentModel, UNO_QUERY );
    1285                 :          0 :         Reference< XNameContainer > xCurrentsParent;
    1286         [ #  # ]:          0 :         if ( xCurrentAsChild.is() )
    1287 [ #  # ][ #  # ]:          0 :             xCurrentsParent = xCurrentsParent.query( xCurrentAsChild->getParent() );
         [ #  # ][ #  # ]
    1288                 :            :         DBG_ASSERT( xCurrentsParent.is(), "FmUndoModelReplaceAction::Undo: invalid current model!" );
    1289                 :            : 
    1290         [ #  # ]:          0 :         if ( xCurrentsParent.is() )
    1291                 :            :         {
    1292                 :            :             // the form container works with FormComponents
    1293         [ #  # ]:          0 :             Reference< XFormComponent > xComponent( m_xReplaced, UNO_QUERY );
    1294                 :            :             DBG_ASSERT( xComponent.is(), "FmUndoModelReplaceAction::Undo: the new model is no form component !" );
    1295                 :            : 
    1296         [ #  # ]:          0 :             Reference< XPropertySet > xCurrentAsSet( xCurrentModel, UNO_QUERY );
    1297                 :            :             DBG_ASSERT( ::comphelper::hasProperty(FM_PROP_NAME, xCurrentAsSet ), "FmUndoModelReplaceAction::Undo : one of the models is invalid !");
    1298                 :            : 
    1299                 :          0 :             ::rtl::OUString sName;
    1300 [ #  # ][ #  # ]:          0 :             xCurrentAsSet->getPropertyValue( FM_PROP_NAME ) >>= sName;
                 [ #  # ]
    1301 [ #  # ][ #  # ]:          0 :             xCurrentsParent->replaceByName( sName, makeAny( xComponent ) );
                 [ #  # ]
    1302                 :            : 
    1303         [ #  # ]:          0 :             m_pObject->SetUnoControlModel(m_xReplaced);
    1304         [ #  # ]:          0 :             m_pObject->SetChanged();
    1305                 :            : 
    1306         [ #  # ]:          0 :             m_xReplaced = xCurrentModel;
    1307         [ #  # ]:          0 :         }
    1308                 :            :     }
    1309                 :          0 :     catch(Exception&)
    1310                 :            :     {
    1311                 :            :         OSL_FAIL("FmUndoModelReplaceAction::Undo : could not replace the model !");
    1312                 :            :     }
    1313                 :          0 : }
    1314                 :            : 
    1315                 :            : //------------------------------------------------------------------------------
    1316                 :          0 : rtl::OUString FmUndoModelReplaceAction::GetComment() const
    1317                 :            : {
    1318                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "svx", "Ocke.Janssen@sun.com", "FmUndoModelReplaceAction::GetComment" );
    1319         [ #  # ]:          0 :     return SVX_RESSTR(RID_STR_UNDO_MODEL_REPLACE);
    1320 [ +  - ][ +  - ]:        450 : }
    1321                 :            : 
    1322                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10