LCOV - code coverage report
Current view: top level - svx/source/form - fmmodel.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 90 104 86.5 %
Date: 2014-11-03 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       33772 : TYPEINIT1(FmFormModel, SdrModel);
      38             : 
      39        6311 : struct FmFormModelImplData
      40             : {
      41             :     FmXUndoEnvironment*     pUndoEnv;
      42             :     bool                bOpenInDesignIsDefaulted;
      43             :     bool                bMovingPage;
      44             :     ::boost::optional< sal_Bool >
      45             :                             aControlsUseRefDevice;
      46             : 
      47        6320 :     FmFormModelImplData()
      48             :         :pUndoEnv( NULL )
      49             :         ,bOpenInDesignIsDefaulted( true )
      50             :         ,bMovingPage( false )
      51        6320 :         ,aControlsUseRefDevice()
      52             :     {
      53        6320 :     }
      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         442 : 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         442 :     , m_bAutoControlFocus(false)
      74             : {
      75         442 :     m_pImpl = new FmFormModelImplData;
      76         442 :     m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
      77         442 :     m_pImpl->pUndoEnv->acquire();
      78         442 : }
      79             : 
      80        5878 : 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        5878 :     , m_bAutoControlFocus(false)
      87             : {
      88        5878 :     m_pImpl = new FmFormModelImplData;
      89        5878 :     m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
      90        5878 :     m_pImpl->pUndoEnv->acquire();
      91        5878 : }
      92             : 
      93       12622 : FmFormModel::~FmFormModel()
      94             : {
      95        6311 :     if (m_pObjShell && m_pImpl->pUndoEnv->IsListening(*m_pObjShell))
      96           0 :         SetObjectShell(NULL);
      97             : 
      98        6311 :     ClearUndoBuffer();
      99             :     // minimale grenze fuer undos
     100        6311 :     SetMaxUndoActionCount(1);
     101             : 
     102        6311 :     m_pImpl->pUndoEnv->release();
     103        6311 :     delete m_pImpl;
     104             : 
     105        6311 : }
     106             : 
     107           0 : SdrPage* FmFormModel::AllocPage(bool bMasterPage)
     108             : {
     109           0 :     return new FmFormPage(*this, bMasterPage);
     110             : }
     111             : 
     112        8422 : void FmFormModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
     113             : {
     114             :     // hack solange Methode intern
     115        8422 :     if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell ))
     116           0 :         SetObjectShell(m_pObjShell);
     117             : 
     118        8422 :     SdrModel::InsertPage( pPage, nPos );
     119        8422 : }
     120             : 
     121           2 : void FmFormModel::MovePage( sal_uInt16 nPgNum, sal_uInt16 nNewPos )
     122             : {
     123           2 :     m_pImpl->bMovingPage = true;
     124             :         // see InsertPage for this
     125             : 
     126           2 :     SdrModel::MovePage( nPgNum, nNewPos );
     127             : 
     128           2 :     m_pImpl->bMovingPage = false;
     129           2 : }
     130             : 
     131        8411 : SdrPage* FmFormModel::RemovePage(sal_uInt16 nPgNum)
     132             : {
     133        8411 :     FmFormPage* pToBeRemovedPage = dynamic_cast< FmFormPage* >( GetPage( nPgNum ) );
     134             :     OSL_ENSURE( pToBeRemovedPage, "FmFormModel::RemovePage: *which page*?" );
     135             : 
     136        8411 :     if ( pToBeRemovedPage )
     137             :     {
     138        8411 :         Reference< XNameContainer > xForms( pToBeRemovedPage->GetForms( false ), css::uno::UNO_QUERY );
     139        8411 :         if ( xForms.is() )
     140         606 :             m_pImpl->pUndoEnv->RemoveForms( xForms );
     141             :     }
     142             : 
     143        8411 :     FmFormPage* pRemovedPage = static_cast<FmFormPage*>(SdrModel::RemovePage(nPgNum));
     144             :     OSL_ENSURE( pRemovedPage == pToBeRemovedPage, "FmFormModel::RemovePage: inconsistency!" );
     145        8411 :     return pRemovedPage;
     146             : }
     147             : 
     148        1146 : void FmFormModel::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos)
     149             : {
     150             :     // hack solange Methode intern
     151        1146 :     if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell ))
     152           0 :         SetObjectShell(m_pObjShell);
     153             : 
     154        1146 :     SdrModel::InsertMasterPage(pPage, nPos);
     155        1146 : }
     156             : 
     157        1146 : SdrPage* FmFormModel::RemoveMasterPage(sal_uInt16 nPgNum)
     158             : {
     159        1146 :     FmFormPage* pPage = static_cast<FmFormPage*>(SdrModel::RemoveMasterPage(nPgNum));
     160             : 
     161        1146 :     if ( pPage )
     162             :     {
     163        1146 :         Reference< XNameContainer > xForms( pPage->GetForms( false ), css::uno::UNO_QUERY );
     164        1146 :         if ( xForms.is() )
     165           0 :             m_pImpl->pUndoEnv->RemoveForms( xForms );
     166             :     }
     167             : 
     168        1146 :     return pPage;
     169             : }
     170             : 
     171             : 
     172           0 : SdrLayerID FmFormModel::GetControlExportLayerId( const SdrObject& rObj ) const
     173             : {
     174           0 :     return rObj.GetLayer();
     175             : }
     176             : 
     177             : 
     178         584 : void FmFormModel::implSetOpenInDesignMode( bool _bOpenDesignMode, bool _bForce )
     179             : {
     180         584 :     if( ( _bOpenDesignMode != m_bOpenInDesignMode ) || _bForce )
     181             :     {
     182          30 :         m_bOpenInDesignMode = _bOpenDesignMode;
     183             : 
     184          30 :         if ( m_pObjShell )
     185          30 :             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         584 :     m_pImpl->bOpenInDesignIsDefaulted = false;
     189         584 : }
     190             : 
     191             : 
     192         584 : void FmFormModel::SetOpenInDesignMode( bool bOpenDesignMode )
     193             : {
     194         584 :     implSetOpenInDesignMode( bOpenDesignMode, false );
     195         584 : }
     196             : 
     197             : 
     198        6842 : bool FmFormModel::OpenInDesignModeIsDefaulted( )
     199             : {
     200        6842 :     return m_pImpl->bOpenInDesignIsDefaulted;
     201             : }
     202             : 
     203             : 
     204         750 : bool FmFormModel::ControlsUseRefDevice() const
     205             : {
     206         750 :     if ( !m_pImpl->aControlsUseRefDevice )
     207             :     {
     208         358 :         DocumentType eDocType = eUnknownDocumentType;
     209         358 :         if ( m_pObjShell )
     210         356 :             eDocType = DocumentClassification::classifyHostDocument( m_pObjShell->GetModel() );
     211         358 :         m_pImpl->aControlsUseRefDevice.reset( ControlLayouter::useDocumentReferenceDevice( eDocType ) );
     212             :     }
     213         750 :     return *m_pImpl->aControlsUseRefDevice;
     214             : }
     215             : 
     216             : 
     217         126 : void FmFormModel::SetAutoControlFocus( bool _bAutoControlFocus )
     218             : {
     219         126 :     if( _bAutoControlFocus != m_bAutoControlFocus )
     220             :     {
     221          22 :         m_bAutoControlFocus = _bAutoControlFocus;
     222          22 :         m_pObjShell->SetModified( true );
     223             :     }
     224         126 : }
     225             : 
     226             : 
     227       12981 : void FmFormModel::SetObjectShell( SfxObjectShell* pShell )
     228             : {
     229       12981 :     if (pShell == m_pObjShell)
     230       12985 :         return;
     231             : 
     232       12977 :     if (m_pObjShell)
     233             :     {
     234        6487 :         m_pImpl->pUndoEnv->EndListening( *this );
     235        6487 :         m_pImpl->pUndoEnv->EndListening( *m_pObjShell );
     236             :     }
     237             : 
     238       12977 :     m_pObjShell = pShell;
     239             : 
     240       12977 :     if (m_pObjShell)
     241             :     {
     242        6490 :         m_pImpl->pUndoEnv->SetReadOnly( m_pObjShell->IsReadOnly() || m_pObjShell->IsReadOnlyUI(), FmXUndoEnvironment::Accessor() );
     243             : 
     244        6490 :         if (!m_pImpl->pUndoEnv->IsReadOnly())
     245        6032 :              m_pImpl->pUndoEnv->StartListening(*this);
     246             : 
     247        6490 :         m_pImpl->pUndoEnv->StartListening( *m_pObjShell );
     248             :     }
     249             : }
     250             : 
     251             : 
     252       35312 : FmXUndoEnvironment& FmFormModel::GetUndoEnv()
     253             : {
     254       35312 :     return *m_pImpl->pUndoEnv;
     255         651 : }
     256             : 
     257             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10