LCOV - code coverage report
Current view: top level - svx/source/form - fmmodel.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 90 104 86.5 %
Date: 2015-06-13 12:38:46 Functions: 22 28 78.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "fmundo.hxx"
      22             : #include "fmdocumentclassification.hxx"
      23             : #include "fmcontrollayout.hxx"
      24             : 
      25             : #include <svx/fmmodel.hxx>
      26             : #include <svx/fmpage.hxx>
      27             : #include <svx/svdobj.hxx>
      28             : 
      29             : #include <sfx2/objsh.hxx>
      30             : 
      31             : #include <boost/optional.hpp>
      32             : 
      33             : using ::com::sun::star::uno::Reference;
      34             : using ::com::sun::star::container::XNameContainer;
      35             : using namespace svxform;
      36             : 
      37       20199 : TYPEINIT1(FmFormModel, SdrModel);
      38             : 
      39        3804 : struct FmFormModelImplData
      40             : {
      41             :     FmXUndoEnvironment*     pUndoEnv;
      42             :     bool                bOpenInDesignIsDefaulted;
      43             :     bool                bMovingPage;
      44             :     ::boost::optional< sal_Bool >
      45             :                             aControlsUseRefDevice;
      46             : 
      47        3827 :     FmFormModelImplData()
      48             :         :pUndoEnv( NULL )
      49             :         ,bOpenInDesignIsDefaulted( true )
      50             :         ,bMovingPage( false )
      51        3827 :         ,aControlsUseRefDevice()
      52             :     {
      53        3827 :     }
      54             : };
      55             : 
      56           0 : FmFormModel::FmFormModel(SfxItemPool* pPool, SfxObjectShell* pPers)
      57             :     : SdrModel(pPool, pPers, false, LOADREFCOUNTS)
      58             :     , m_pImpl(NULL)
      59             :     , m_pObjShell(0)
      60             :     , m_bOpenInDesignMode(false)
      61           0 :     , m_bAutoControlFocus(false)
      62             : {
      63           0 :     m_pImpl = new FmFormModelImplData;
      64           0 :     m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
      65           0 :     m_pImpl->pUndoEnv->acquire();
      66           0 : }
      67             : 
      68         320 : FmFormModel::FmFormModel(const OUString& rPath, SfxItemPool* pPool, SfxObjectShell* pPers)
      69             :     : SdrModel(rPath, pPool, pPers, false, LOADREFCOUNTS)
      70             :     , m_pImpl(NULL)
      71             :     , m_pObjShell(0)
      72             :     , m_bOpenInDesignMode(false)
      73         320 :     , m_bAutoControlFocus(false)
      74             : {
      75         320 :     m_pImpl = new FmFormModelImplData;
      76         320 :     m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
      77         320 :     m_pImpl->pUndoEnv->acquire();
      78         320 : }
      79             : 
      80        3507 : FmFormModel::FmFormModel(const OUString& rPath, SfxItemPool* pPool, SfxObjectShell* pPers,
      81             :                          bool bUseExtColorTable)
      82             :     : SdrModel(rPath, pPool, pPers, bUseExtColorTable, LOADREFCOUNTS)
      83             :     , m_pImpl(NULL)
      84             :     , m_pObjShell(0)
      85             :     , m_bOpenInDesignMode(false)
      86        3507 :     , m_bAutoControlFocus(false)
      87             : {
      88        3507 :     m_pImpl = new FmFormModelImplData;
      89        3507 :     m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
      90        3507 :     m_pImpl->pUndoEnv->acquire();
      91        3507 : }
      92             : 
      93        7608 : FmFormModel::~FmFormModel()
      94             : {
      95        3804 :     if (m_pObjShell && m_pImpl->pUndoEnv->IsListening(*m_pObjShell))
      96           0 :         SetObjectShell(NULL);
      97             : 
      98        3804 :     ClearUndoBuffer();
      99             :     // minimale grenze fuer undos
     100        3804 :     SetMaxUndoActionCount(1);
     101             : 
     102        3804 :     m_pImpl->pUndoEnv->release();
     103        3804 :     delete m_pImpl;
     104             : 
     105        3804 : }
     106             : 
     107           0 : SdrPage* FmFormModel::AllocPage(bool bMasterPage)
     108             : {
     109           0 :     return new FmFormPage(*this, bMasterPage);
     110             : }
     111             : 
     112        5496 : void FmFormModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
     113             : {
     114             :     // hack solange Methode intern
     115        5496 :     if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell ))
     116           0 :         SetObjectShell(m_pObjShell);
     117             : 
     118        5496 :     SdrModel::InsertPage( pPage, nPos );
     119        5496 : }
     120             : 
     121           1 : void FmFormModel::MovePage( sal_uInt16 nPgNum, sal_uInt16 nNewPos )
     122             : {
     123           1 :     m_pImpl->bMovingPage = true;
     124             :         // see InsertPage for this
     125             : 
     126           1 :     SdrModel::MovePage( nPgNum, nNewPos );
     127             : 
     128           1 :     m_pImpl->bMovingPage = false;
     129           1 : }
     130             : 
     131        5451 : SdrPage* FmFormModel::RemovePage(sal_uInt16 nPgNum)
     132             : {
     133        5451 :     FmFormPage* pToBeRemovedPage = dynamic_cast< FmFormPage* >( GetPage( nPgNum ) );
     134             :     OSL_ENSURE( pToBeRemovedPage, "FmFormModel::RemovePage: *which page*?" );
     135             : 
     136        5451 :     if ( pToBeRemovedPage )
     137             :     {
     138        5451 :         Reference< XNameContainer > xForms( pToBeRemovedPage->GetForms( false ), css::uno::UNO_QUERY );
     139        5451 :         if ( xForms.is() )
     140         400 :             m_pImpl->pUndoEnv->RemoveForms( xForms );
     141             :     }
     142             : 
     143        5451 :     FmFormPage* pRemovedPage = static_cast<FmFormPage*>(SdrModel::RemovePage(nPgNum));
     144             :     OSL_ENSURE( pRemovedPage == pToBeRemovedPage, "FmFormModel::RemovePage: inconsistency!" );
     145        5451 :     return pRemovedPage;
     146             : }
     147             : 
     148         786 : void FmFormModel::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos)
     149             : {
     150             :     // hack solange Methode intern
     151         786 :     if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell ))
     152           0 :         SetObjectShell(m_pObjShell);
     153             : 
     154         786 :     SdrModel::InsertMasterPage(pPage, nPos);
     155         786 : }
     156             : 
     157         771 : SdrPage* FmFormModel::RemoveMasterPage(sal_uInt16 nPgNum)
     158             : {
     159         771 :     FmFormPage* pPage = static_cast<FmFormPage*>(SdrModel::RemoveMasterPage(nPgNum));
     160             : 
     161         771 :     if ( pPage )
     162             :     {
     163         771 :         Reference< XNameContainer > xForms( pPage->GetForms( false ), css::uno::UNO_QUERY );
     164         771 :         if ( xForms.is() )
     165           0 :             m_pImpl->pUndoEnv->RemoveForms( xForms );
     166             :     }
     167             : 
     168         771 :     return pPage;
     169             : }
     170             : 
     171             : 
     172           0 : SdrLayerID FmFormModel::GetControlExportLayerId( const SdrObject& rObj ) const
     173             : {
     174           0 :     return rObj.GetLayer();
     175             : }
     176             : 
     177             : 
     178         427 : void FmFormModel::implSetOpenInDesignMode( bool _bOpenDesignMode, bool _bForce )
     179             : {
     180         427 :     if( ( _bOpenDesignMode != m_bOpenInDesignMode ) || _bForce )
     181             :     {
     182          12 :         m_bOpenInDesignMode = _bOpenDesignMode;
     183             : 
     184          12 :         if ( m_pObjShell )
     185          12 :             m_pObjShell->SetModified( true );
     186             :     }
     187             :     // no matter if we really did it or not - from now on, it does not count as defaulted anymore
     188         427 :     m_pImpl->bOpenInDesignIsDefaulted = false;
     189         427 : }
     190             : 
     191             : 
     192         427 : void FmFormModel::SetOpenInDesignMode( bool bOpenDesignMode )
     193             : {
     194         427 :     implSetOpenInDesignMode( bOpenDesignMode, false );
     195         427 : }
     196             : 
     197             : 
     198        4026 : bool FmFormModel::OpenInDesignModeIsDefaulted( )
     199             : {
     200        4026 :     return m_pImpl->bOpenInDesignIsDefaulted;
     201             : }
     202             : 
     203             : 
     204         394 : bool FmFormModel::ControlsUseRefDevice() const
     205             : {
     206         394 :     if ( !m_pImpl->aControlsUseRefDevice )
     207             :     {
     208         179 :         DocumentType eDocType = eUnknownDocumentType;
     209         179 :         if ( m_pObjShell )
     210         178 :             eDocType = DocumentClassification::classifyHostDocument( m_pObjShell->GetModel() );
     211         179 :         m_pImpl->aControlsUseRefDevice.reset( ControlLayouter::useDocumentReferenceDevice( eDocType ) );
     212             :     }
     213         394 :     return *m_pImpl->aControlsUseRefDevice;
     214             : }
     215             : 
     216             : 
     217          73 : void FmFormModel::SetAutoControlFocus( bool _bAutoControlFocus )
     218             : {
     219          73 :     if( _bAutoControlFocus != m_bAutoControlFocus )
     220             :     {
     221           8 :         m_bAutoControlFocus = _bAutoControlFocus;
     222           8 :         m_pObjShell->SetModified( true );
     223             :     }
     224          73 : }
     225             : 
     226             : 
     227        7838 : void FmFormModel::SetObjectShell( SfxObjectShell* pShell )
     228             : {
     229        7838 :     if (pShell == m_pObjShell)
     230        7840 :         return;
     231             : 
     232        7836 :     if (m_pObjShell)
     233             :     {
     234        3909 :         m_pImpl->pUndoEnv->EndListening( *this );
     235        3909 :         m_pImpl->pUndoEnv->EndListening( *m_pObjShell );
     236             :     }
     237             : 
     238        7836 :     m_pObjShell = pShell;
     239             : 
     240        7836 :     if (m_pObjShell)
     241             :     {
     242        3927 :         m_pImpl->pUndoEnv->SetReadOnly( m_pObjShell->IsReadOnly() || m_pObjShell->IsReadOnlyUI(), FmXUndoEnvironment::Accessor() );
     243             : 
     244        3927 :         if (!m_pImpl->pUndoEnv->IsReadOnly())
     245        3593 :              m_pImpl->pUndoEnv->StartListening(*this);
     246             : 
     247        3927 :         m_pImpl->pUndoEnv->StartListening( *m_pObjShell );
     248             :     }
     249             : }
     250             : 
     251             : 
     252       24138 : FmXUndoEnvironment& FmFormModel::GetUndoEnv()
     253             : {
     254       24138 :     return *m_pImpl->pUndoEnv;
     255         435 : }
     256             : 
     257             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11