LCOV - code coverage report
Current view: top level - svx/source/form - fmmodel.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 90 103 87.4 %
Date: 2012-08-25 Functions: 20 26 76.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 59 112 52.7 %

           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 "fmundo.hxx"
      31                 :            : #include "fmdocumentclassification.hxx"
      32                 :            : #include "fmcontrollayout.hxx"
      33                 :            : 
      34                 :            : #include <svx/fmmodel.hxx>
      35                 :            : #include <svx/fmpage.hxx>
      36                 :            : #include <svx/svdobj.hxx>
      37                 :            : 
      38                 :            : #include <sfx2/objsh.hxx>
      39                 :            : 
      40                 :            : #include <boost/optional.hpp>
      41                 :            : 
      42                 :            : using ::com::sun::star::uno::Reference;
      43                 :            : using ::com::sun::star::container::XNameContainer;
      44                 :            : using namespace svxform;
      45                 :            : 
      46 [ +  - ][ #  # ]:      11754 : TYPEINIT1(FmFormModel, SdrModel);
      47                 :            : 
      48                 :       1781 : struct FmFormModelImplData
      49                 :            : {
      50                 :            :     FmXUndoEnvironment*     pUndoEnv;
      51                 :            :     sal_Bool                bOpenInDesignIsDefaulted;
      52                 :            :     sal_Bool                bMovingPage;
      53                 :            :     ::boost::optional< sal_Bool >
      54                 :            :                             aControlsUseRefDevice;
      55                 :            : 
      56                 :       1886 :     FmFormModelImplData()
      57                 :            :         :pUndoEnv( NULL )
      58                 :            :         ,bOpenInDesignIsDefaulted( sal_True )
      59                 :            :         ,bMovingPage( sal_False )
      60                 :       1886 :         ,aControlsUseRefDevice()
      61                 :            :     {
      62                 :       1886 :     }
      63                 :            : };
      64                 :            : 
      65                 :            : /*************************************************************************
      66                 :            : |*
      67                 :            : |* Ctor
      68                 :            : |*
      69                 :            : \************************************************************************/
      70                 :          0 : FmFormModel::FmFormModel(SfxItemPool* pPool, SfxObjectShell* pPers)
      71                 :            :             :SdrModel(pPool, pPers, LOADREFCOUNTS)
      72                 :            :             ,m_pImpl(NULL)
      73                 :            :             ,m_pObjShell(0)
      74                 :            :             ,m_bOpenInDesignMode(sal_False)
      75         [ #  # ]:          0 :             ,m_bAutoControlFocus(sal_False)
      76                 :            : {
      77 [ #  # ][ #  # ]:          0 :     m_pImpl = new FmFormModelImplData;
      78         [ #  # ]:          0 :     m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
      79                 :          0 :     m_pImpl->pUndoEnv->acquire();
      80                 :          0 : }
      81                 :            : 
      82                 :            : /*************************************************************************
      83                 :            : |*
      84                 :            : |* Ctor
      85                 :            : |*
      86                 :            : \************************************************************************/
      87                 :        178 : FmFormModel::FmFormModel(const XubString& rPath, SfxItemPool* pPool, SfxObjectShell* pPers)
      88                 :            :             :SdrModel(rPath, pPool, pPers)
      89                 :            :             ,m_pImpl(NULL)
      90                 :            :             ,m_pObjShell(0)
      91                 :            :             ,m_bOpenInDesignMode(sal_False)
      92         [ +  + ]:        178 :             ,m_bAutoControlFocus(sal_False)
      93                 :            : {
      94 [ +  - ][ +  - ]:        178 :     m_pImpl = new FmFormModelImplData;
      95         [ +  - ]:        178 :     m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
      96                 :        178 :     m_pImpl->pUndoEnv->acquire();
      97                 :        178 : }
      98                 :            : 
      99                 :            : /*************************************************************************
     100                 :            : |*
     101                 :            : |* Ctor
     102                 :            : |*
     103                 :            : \************************************************************************/
     104                 :       1708 : FmFormModel::FmFormModel(const XubString& rPath, SfxItemPool* pPool, SfxObjectShell* pPers,
     105                 :            :                          bool bUseExtColorTable)
     106                 :            :             :SdrModel(rPath, pPool, pPers, bUseExtColorTable, LOADREFCOUNTS)
     107                 :            :             ,m_pImpl( NULL )
     108                 :            :             ,m_pObjShell(0)
     109                 :            :             ,m_bOpenInDesignMode(sal_False)
     110         [ +  - ]:       1708 :             ,m_bAutoControlFocus(sal_False)
     111                 :            : {
     112 [ +  - ][ +  - ]:       1708 :     m_pImpl = new FmFormModelImplData;
     113         [ +  - ]:       1708 :     m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
     114                 :       1708 :     m_pImpl->pUndoEnv->acquire();
     115                 :       1708 : }
     116                 :            : 
     117                 :            : /*************************************************************************
     118                 :            : |*
     119                 :            : |* Dtor
     120                 :            : |*
     121                 :            : \************************************************************************/
     122                 :       1781 : FmFormModel::~FmFormModel()
     123                 :            : {
     124 [ -  + ][ #  # ]:       1781 :     if (m_pObjShell && m_pImpl->pUndoEnv->IsListening(*m_pObjShell))
         [ #  # ][ -  + ]
     125         [ #  # ]:          0 :         SetObjectShell(NULL);
     126                 :            : 
     127         [ +  - ]:       1781 :     ClearUndoBuffer();
     128                 :            :     // minimale grenze fuer undos
     129         [ +  - ]:       1781 :     SetMaxUndoActionCount(1);
     130                 :            : 
     131                 :       1781 :     m_pImpl->pUndoEnv->release();
     132 [ +  - ][ +  - ]:       1781 :     delete m_pImpl;
     133                 :            : 
     134         [ -  + ]:       1781 : }
     135                 :            : 
     136                 :            : /*************************************************************************
     137                 :            : |*
     138                 :            : |* Erzeugt eine neue Seite
     139                 :            : |*
     140                 :            : \************************************************************************/
     141                 :          0 : SdrPage* FmFormModel::AllocPage(bool bMasterPage)
     142                 :            : {
     143         [ #  # ]:          0 :     return new FmFormPage(*this, NULL, bMasterPage);
     144                 :            : }
     145                 :            : 
     146                 :            : /*************************************************************************
     147                 :            : |*
     148                 :            : |* InsertPage
     149                 :            : |*
     150                 :            : \************************************************************************/
     151                 :       2516 : void FmFormModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
     152                 :            : {
     153                 :            :     // hack solange Methode intern
     154 [ +  + ][ -  + ]:       2516 :     if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell ))
                 [ -  + ]
     155                 :          0 :         SetObjectShell(m_pObjShell);
     156                 :            : 
     157                 :       2516 :     SdrModel::InsertPage( pPage, nPos );
     158                 :       2516 : }
     159                 :            : 
     160                 :            : /*************************************************************************
     161                 :            : |*
     162                 :            : |* MovePage
     163                 :            : |*
     164                 :            : \************************************************************************/
     165                 :          3 : void FmFormModel::MovePage( sal_uInt16 nPgNum, sal_uInt16 nNewPos )
     166                 :            : {
     167                 :          3 :     m_pImpl->bMovingPage = sal_True;
     168                 :            :         // see InsertPage for this
     169                 :            : 
     170                 :          3 :     SdrModel::MovePage( nPgNum, nNewPos );
     171                 :            : 
     172                 :          3 :     m_pImpl->bMovingPage = sal_False;
     173                 :          3 : }
     174                 :            : 
     175                 :            : /*************************************************************************
     176                 :            : |*
     177                 :            : |* RemovePage
     178                 :            : |*
     179                 :            : \************************************************************************/
     180                 :       2388 : SdrPage* FmFormModel::RemovePage(sal_uInt16 nPgNum)
     181                 :            : {
     182         [ -  + ]:       2388 :     FmFormPage* pToBeRemovedPage = dynamic_cast< FmFormPage* >( GetPage( nPgNum ) );
     183                 :            :     OSL_ENSURE( pToBeRemovedPage, "FmFormModel::RemovePage: *which page*?" );
     184                 :            : 
     185         [ +  - ]:       2388 :     if ( pToBeRemovedPage )
     186                 :            :     {
     187         [ +  - ]:       2388 :         Reference< XNameContainer > xForms( pToBeRemovedPage->GetForms( false ) );
     188         [ +  + ]:       2388 :         if ( xForms.is() )
     189         [ +  - ]:       2388 :             m_pImpl->pUndoEnv->RemoveForms( xForms );
     190                 :            :     }
     191                 :            : 
     192                 :       2388 :     FmFormPage* pRemovedPage = (FmFormPage*)SdrModel::RemovePage(nPgNum);
     193                 :            :     OSL_ENSURE( pRemovedPage == pToBeRemovedPage, "FmFormModel::RemovePage: inconsistency!" );
     194                 :       2388 :     return pRemovedPage;
     195                 :            : }
     196                 :            : 
     197                 :            : /*************************************************************************
     198                 :            : |*
     199                 :            : |* InsertMasterPage
     200                 :            : |*
     201                 :            : \************************************************************************/
     202                 :        481 : void FmFormModel::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos)
     203                 :            : {
     204                 :            :     // hack solange Methode intern
     205 [ +  + ][ -  + ]:        481 :     if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell ))
                 [ -  + ]
     206                 :          0 :         SetObjectShell(m_pObjShell);
     207                 :            : 
     208                 :        481 :     SdrModel::InsertMasterPage(pPage, nPos);
     209                 :        481 : }
     210                 :            : 
     211                 :            : /*************************************************************************
     212                 :            : |*
     213                 :            : |* RemoveMasterPage
     214                 :            : |*
     215                 :            : \************************************************************************/
     216                 :        472 : SdrPage* FmFormModel::RemoveMasterPage(sal_uInt16 nPgNum)
     217                 :            : {
     218                 :        472 :     FmFormPage* pPage = (FmFormPage*)SdrModel::RemoveMasterPage(nPgNum);
     219                 :            : 
     220         [ +  - ]:        472 :     if ( pPage )
     221                 :            :     {
     222         [ +  - ]:        472 :         Reference< XNameContainer > xForms( pPage->GetForms( false ) );
     223         [ -  + ]:        472 :         if ( xForms.is() )
     224         [ #  # ]:        472 :             m_pImpl->pUndoEnv->RemoveForms( xForms );
     225                 :            :     }
     226                 :            : 
     227                 :        472 :     return pPage;
     228                 :            : }
     229                 :            : 
     230                 :            : //------------------------------------------------------------------------
     231                 :          0 : SdrLayerID FmFormModel::GetControlExportLayerId( const SdrObject& rObj ) const
     232                 :            : {
     233                 :          0 :     return rObj.GetLayer();
     234                 :            : }
     235                 :            : 
     236                 :            : //------------------------------------------------------------------------
     237                 :        236 : void FmFormModel::implSetOpenInDesignMode( sal_Bool _bOpenDesignMode, sal_Bool _bForce )
     238                 :            : {
     239 [ +  + ][ -  + ]:        236 :     if( ( _bOpenDesignMode != m_bOpenInDesignMode ) || _bForce )
     240                 :            :     {
     241                 :         20 :         m_bOpenInDesignMode = _bOpenDesignMode;
     242                 :            : 
     243         [ +  - ]:         20 :         if ( m_pObjShell )
     244                 :         20 :             m_pObjShell->SetModified( sal_True );
     245                 :            :     }
     246                 :            :     // no matter if we really did it or not - from now on, it does not count as defaulted anymore
     247                 :        236 :     m_pImpl->bOpenInDesignIsDefaulted = sal_False;
     248                 :        236 : }
     249                 :            : 
     250                 :            : //------------------------------------------------------------------------
     251                 :        236 : void FmFormModel::SetOpenInDesignMode( sal_Bool bOpenDesignMode )
     252                 :            : {
     253                 :        236 :     implSetOpenInDesignMode( bOpenDesignMode, sal_False );
     254                 :        236 : }
     255                 :            : 
     256                 :            : //------------------------------------------------------------------------
     257                 :       2277 : sal_Bool FmFormModel::OpenInDesignModeIsDefaulted( )
     258                 :            : {
     259                 :       2277 :     return m_pImpl->bOpenInDesignIsDefaulted;
     260                 :            : }
     261                 :            : 
     262                 :            : //------------------------------------------------------------------------
     263                 :        584 : sal_Bool FmFormModel::ControlsUseRefDevice() const
     264                 :            : {
     265         [ +  + ]:        584 :     if ( !m_pImpl->aControlsUseRefDevice )
     266                 :            :     {
     267                 :        271 :         DocumentType eDocType = eUnknownDocumentType;
     268         [ +  + ]:        271 :         if ( m_pObjShell )
     269         [ +  - ]:        268 :             eDocType = DocumentClassification::classifyHostDocument( m_pObjShell->GetModel() );
     270         [ +  - ]:        271 :         m_pImpl->aControlsUseRefDevice.reset( ControlLayouter::useDocumentReferenceDevice( eDocType ) );
     271                 :            :     }
     272                 :        584 :     return *m_pImpl->aControlsUseRefDevice;
     273                 :            : }
     274                 :            : 
     275                 :            : //------------------------------------------------------------------------
     276                 :         55 : void FmFormModel::SetAutoControlFocus( sal_Bool _bAutoControlFocus )
     277                 :            : {
     278         [ +  + ]:         55 :     if( _bAutoControlFocus != m_bAutoControlFocus )
     279                 :            :     {
     280                 :         17 :         m_bAutoControlFocus = _bAutoControlFocus;
     281                 :         17 :         m_pObjShell->SetModified( sal_True );
     282                 :            :     }
     283                 :         55 : }
     284                 :            : 
     285                 :            : //------------------------------------------------------------------------
     286                 :       5335 : void FmFormModel::SetObjectShell( SfxObjectShell* pShell )
     287                 :            : {
     288         [ +  + ]:       5335 :     if (pShell == m_pObjShell)
     289                 :       5335 :         return;
     290                 :            : 
     291         [ +  + ]:       3943 :     if (m_pObjShell)
     292                 :            :     {
     293                 :       1919 :         m_pImpl->pUndoEnv->EndListening( *this );
     294                 :       1919 :         m_pImpl->pUndoEnv->EndListening( *m_pObjShell );
     295                 :            :     }
     296                 :            : 
     297                 :       3943 :     m_pObjShell = pShell;
     298                 :            : 
     299         [ +  + ]:       3943 :     if (m_pObjShell)
     300                 :            :     {
     301 [ +  - ][ +  + ]:       2024 :         m_pImpl->pUndoEnv->SetReadOnly( m_pObjShell->IsReadOnly() || m_pObjShell->IsReadOnlyUI(), FmXUndoEnvironment::Accessor() );
         [ +  - ][ -  + ]
     302                 :            : 
     303         [ +  + ]:       2024 :         if (!m_pImpl->pUndoEnv->IsReadOnly())
     304                 :       1846 :              m_pImpl->pUndoEnv->StartListening(*this);
     305                 :            : 
     306                 :       2024 :         m_pImpl->pUndoEnv->StartListening( *m_pObjShell );
     307                 :            :     }
     308                 :            : }
     309                 :            : 
     310                 :            : //------------------------------------------------------------------------
     311                 :       6010 : FmXUndoEnvironment& FmFormModel::GetUndoEnv()
     312                 :            : {
     313                 :       6010 :     return *m_pImpl->pUndoEnv;
     314                 :            : }
     315                 :            : 
     316                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10