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

Generated by: LCOV version 1.10