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

Generated by: LCOV version 1.10