LCOV - code coverage report
Current view: top level - sw/source/core/doc - DocumentDrawModelManager.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 89 133 66.9 %
Date: 2014-11-03 Functions: 18 20 90.0 %
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             : #include <DocumentDrawModelManager.hxx>
      21             : 
      22             : #include <doc.hxx>
      23             : #include <IDocumentUndoRedo.hxx>
      24             : #include <IDocumentSettingAccess.hxx>
      25             : #include <IDocumentDeviceAccess.hxx>
      26             : #include <IDocumentLinksAdministration.hxx>
      27             : #include <IDocumentLayoutAccess.hxx>
      28             : #include <docsh.hxx>
      29             : #include <swtypes.hxx>
      30             : #include <swhints.hxx>
      31             : #include <viewsh.hxx>
      32             : #include <drawdoc.hxx>
      33             : #include <rootfrm.hxx>
      34             : #include <editeng/eeitem.hxx>
      35             : #include <editeng/fhgtitem.hxx>
      36             : #include <svx/svdmodel.hxx>
      37             : #include <svx/svdlayer.hxx>
      38             : #include <svx/svdoutl.hxx>
      39             : #include <svx/svdpage.hxx>
      40             : #include <svx/svdpagv.hxx>
      41             : #include <svl/smplhint.hxx>
      42             : #include <tools/link.hxx>
      43             : 
      44             : class SdrOutliner;
      45             : class XSpellChecker1;
      46             : 
      47             : namespace sw
      48             : {
      49             : 
      50        5052 : DocumentDrawModelManager::DocumentDrawModelManager(SwDoc& i_rSwdoc)
      51             :     : m_rSwdoc(i_rSwdoc)
      52             :     , mpDrawModel(0)
      53             :     , mnHeaven(0)
      54             :     , mnHell(0)
      55             :     , mnControls(0)
      56             :     , mnInvisibleHeaven(0)
      57             :     , mnInvisibleHell(0)
      58        5052 :     , mnInvisibleControls(0)
      59             : {
      60        5052 : }
      61             : 
      62             : // Is also called by the Sw3 Reader, if there was an error when reading the
      63             : // drawing layer. If it is called by the Sw3 Reader the layer is rebuilt
      64             : // from scratch.
      65        5052 : void DocumentDrawModelManager::InitDrawModel()
      66             : {
      67             :     // !! Attention: there is similar code in the Sw3 Reader (sw3imp.cxx) that
      68             :     // also has to be maintained!!
      69        5052 :     if ( mpDrawModel )
      70           0 :         ReleaseDrawModel();
      71             : 
      72             : //UUUU
      73             : //  // Setup DrawPool and EditEnginePool. Ownership is ours and only gets passed
      74             : //  // to the Drawing.
      75             : //  // The pools are destroyed in the ReleaseDrawModel.
      76             : //  // for loading the drawing items. This must be loaded without RefCounts!
      77             : //  SfxItemPool *pSdrPool = new SdrItemPool( &GetAttrPool() );
      78             : //  // change DefaultItems for the SdrEdgeObj distance items to TWIPS.
      79             : //  if(pSdrPool)
      80             : //  {
      81             : //      const long nDefEdgeDist = ((500 * 72) / 127); // 1/100th mm in twips
      82             : //      pSdrPool->SetPoolDefaultItem(SdrEdgeNode1HorzDistItem(nDefEdgeDist));
      83             : //      pSdrPool->SetPoolDefaultItem(SdrEdgeNode1VertDistItem(nDefEdgeDist));
      84             : //      pSdrPool->SetPoolDefaultItem(SdrEdgeNode2HorzDistItem(nDefEdgeDist));
      85             : //      pSdrPool->SetPoolDefaultItem(SdrEdgeNode2VertDistItem(nDefEdgeDist));
      86             : //
      87             : //      // #i33700#
      88             : //      // Set shadow distance defaults as PoolDefaultItems. Details see bug.
      89             : //      pSdrPool->SetPoolDefaultItem(makeSdrShadowXDistItem((300 * 72) / 127));
      90             : //      pSdrPool->SetPoolDefaultItem(makeSdrShadowYDistItem((300 * 72) / 127));
      91             : //  }
      92             : //  SfxItemPool *pEEgPool = EditEngine::CreatePool( false );
      93             : //  pSdrPool->SetSecondaryPool( pEEgPool );
      94             : //   if ( !GetAttrPool().GetFrozenIdRanges () )
      95             : //      GetAttrPool().FreezeIdRanges();
      96             : //  else
      97             : //      pSdrPool->FreezeIdRanges();
      98             : 
      99             :     // set FontHeight pool defaults without changing static SdrEngineDefaults
     100        5052 :     m_rSwdoc.GetAttrPool().SetPoolDefaultItem(SvxFontHeightItem( 240, 100, EE_CHAR_FONTHEIGHT ));
     101             : 
     102             :     SAL_INFO( "sw.doc", "before create DrawDocument" );
     103             :     // The document owns the SwDrawModel. We always have two layers and one page.
     104        5052 :     mpDrawModel = new SwDrawModel( &m_rSwdoc );
     105             : 
     106        5052 :     mpDrawModel->EnableUndo( m_rSwdoc.GetIDocumentUndoRedo().DoesUndo() );
     107             : 
     108        5052 :     OUString sLayerNm;
     109        5052 :     sLayerNm = "Hell";
     110        5052 :     mnHell   = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
     111             : 
     112        5052 :     sLayerNm = "Heaven";
     113        5052 :     mnHeaven = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
     114             : 
     115        5052 :     sLayerNm = "Controls";
     116        5052 :     mnControls = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
     117             : 
     118             :     // add invisible layers corresponding to the visible ones.
     119             :     {
     120        5052 :         sLayerNm = "InvisibleHell";
     121        5052 :         mnInvisibleHell   = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
     122             : 
     123        5052 :         sLayerNm = "InvisibleHeaven";
     124        5052 :         mnInvisibleHeaven = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
     125             : 
     126        5052 :         sLayerNm = "InvisibleControls";
     127        5052 :         mnInvisibleControls = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
     128             :     }
     129             : 
     130        5052 :     SdrPage* pMasterPage = mpDrawModel->AllocPage( false );
     131        5052 :     mpDrawModel->InsertPage( pMasterPage );
     132             :     SAL_INFO( "sw.doc", "after create DrawDocument" );
     133             :     SAL_INFO( "sw.doc", "before create Spellchecker/Hyphenator" );
     134        5052 :     SdrOutliner& rOutliner = mpDrawModel->GetDrawOutliner();
     135       10104 :     ::com::sun::star::uno::Reference< com::sun::star::linguistic2::XSpellChecker1 > xSpell = ::GetSpellChecker();
     136        5052 :     rOutliner.SetSpeller( xSpell );
     137       10104 :     ::com::sun::star::uno::Reference< com::sun::star::linguistic2::XHyphenator > xHyphenator( ::GetHyphenator() );
     138        5052 :     rOutliner.SetHyphenator( xHyphenator );
     139             :     SAL_INFO( "sw.doc", "after create Spellchecker/Hyphenator" );
     140        5052 :     m_rSwdoc.SetCalcFieldValueHdl(&rOutliner);
     141        5052 :     m_rSwdoc.SetCalcFieldValueHdl(&mpDrawModel->GetHitTestOutliner());
     142             : 
     143             :     // Set the LinkManager in the model so that linked graphics can be inserted.
     144             :     // The WinWord import needs it too.
     145        5052 :     mpDrawModel->SetLinkManager( & m_rSwdoc.getIDocumentLinksAdministration().GetLinkManager() );
     146        5052 :     mpDrawModel->SetAddExtLeading( m_rSwdoc.getIDocumentSettingAccess().get(IDocumentSettingAccess::ADD_EXT_LEADING) );
     147             : 
     148        5052 :     OutputDevice* pRefDev = m_rSwdoc.getIDocumentDeviceAccess().getReferenceDevice( false );
     149        5052 :     if ( pRefDev )
     150           0 :         mpDrawModel->SetRefDevice( pRefDev );
     151             : 
     152        5052 :     mpDrawModel->SetNotifyUndoActionHdl( LINK( &m_rSwdoc, SwDoc, AddDrawUndo ));
     153        5052 :     if ( m_rSwdoc.getIDocumentLayoutAccess().GetCurrentViewShell() )
     154             :     {
     155           0 :         SwViewShell* pViewSh = m_rSwdoc.getIDocumentLayoutAccess().GetCurrentViewShell();
     156           0 :         do
     157             :         {
     158           0 :             SwRootFrm* pRoot =  pViewSh->GetLayout();
     159           0 :             if( pRoot && !pRoot->GetDrawPage() )
     160             :             {
     161             :                 // Disable "multiple layout" for the moment:
     162             :                 // use pMasterPage instead of a new created SdrPage
     163             :                 // mpDrawModel->AllocPage( FALSE );
     164             :                 // mpDrawModel->InsertPage( pDrawPage );
     165           0 :                 SdrPage* pDrawPage = pMasterPage;
     166           0 :                 pRoot->SetDrawPage( pDrawPage );
     167           0 :                 pDrawPage->SetSize( pRoot->Frm().SSize() );
     168             :             }
     169           0 :             pViewSh = (SwViewShell*)pViewSh->GetNext();
     170           0 :         }while( pViewSh != m_rSwdoc.getIDocumentLayoutAccess().GetCurrentViewShell() );
     171        5052 :     }
     172        5052 : }
     173             : 
     174             : 
     175        5045 : void DocumentDrawModelManager::ReleaseDrawModel()
     176             : {
     177        5045 :     if ( mpDrawModel )
     178             :     {
     179             :         // !! Also maintain the code in the sw3io for inserting documents!!
     180             : 
     181        5045 :         delete mpDrawModel; mpDrawModel = 0;
     182             : //UUUU
     183             : //      SfxItemPool *pSdrPool = GetAttrPool().GetSecondaryPool();
     184             : //
     185             : //      OSL_ENSURE( pSdrPool, "missing pool" );
     186             : //      SfxItemPool *pEEgPool = pSdrPool->GetSecondaryPool();
     187             : //      OSL_ENSURE( !pEEgPool->GetSecondaryPool(), "I don't accept additional pools");
     188             : //      pSdrPool->Delete();                 // First have the items destroyed,
     189             : //                                          // then destroy the chain!
     190             : //      GetAttrPool().SetSecondaryPool( 0 );    // This one's a must!
     191             : //      pSdrPool->SetSecondaryPool( 0 );    // That one's safer
     192             : //      SfxItemPool::Free(pSdrPool);
     193             : //      SfxItemPool::Free(pEEgPool);
     194             :     }
     195        5045 : }
     196             : 
     197             : 
     198             : 
     199             : 
     200             : 
     201           0 : const SwDrawModel* DocumentDrawModelManager::GetDrawModel() const
     202             : {
     203           0 :     return mpDrawModel;
     204             : }
     205             : 
     206     1622405 : SwDrawModel* DocumentDrawModelManager::GetDrawModel()
     207             : {
     208     1622405 :     return mpDrawModel;
     209             : }
     210             : 
     211        5052 : SwDrawModel* DocumentDrawModelManager::_MakeDrawModel()
     212             : {
     213             :     OSL_ENSURE( !mpDrawModel, "_MakeDrawModel: Why?" );
     214        5052 :     InitDrawModel();
     215        5052 :     if ( m_rSwdoc.getIDocumentLayoutAccess().GetCurrentViewShell() )
     216             :     {
     217           0 :         SwViewShell* pTmp = m_rSwdoc.getIDocumentLayoutAccess().GetCurrentViewShell();
     218           0 :         do
     219             :         {
     220           0 :             pTmp->MakeDrawView();
     221           0 :             pTmp = (SwViewShell*) pTmp->GetNext();
     222           0 :         } while ( pTmp != m_rSwdoc.getIDocumentLayoutAccess().GetCurrentViewShell() );
     223             : 
     224             :         // Broadcast, so that the FormShell can be connected to the DrawView
     225           0 :         if( m_rSwdoc.GetDocShell() )
     226             :         {
     227           0 :             SfxSimpleHint aHnt( SW_BROADCAST_DRAWVIEWS_CREATED );
     228           0 :             m_rSwdoc.GetDocShell()->Broadcast( aHnt );
     229             :         }
     230             :     }
     231        5052 :     return mpDrawModel;
     232             : }
     233             : 
     234      707431 : SwDrawModel* DocumentDrawModelManager::GetOrCreateDrawModel()
     235             : {
     236      707431 :     return GetDrawModel() ? GetDrawModel() : _MakeDrawModel();
     237             : }
     238             : 
     239     1226445 : SdrLayerID DocumentDrawModelManager::GetHeavenId() const
     240             : {
     241     1226445 :     return mnHeaven;
     242             : }
     243             : 
     244      418245 : SdrLayerID DocumentDrawModelManager::GetHellId() const
     245             : {
     246      418245 :     return mnHell;
     247             : }
     248             : 
     249      214831 : SdrLayerID DocumentDrawModelManager::GetControlsId() const
     250             : {
     251      214831 :     return mnControls;
     252             : }
     253             : 
     254      210496 : SdrLayerID DocumentDrawModelManager::GetInvisibleHeavenId() const
     255             : {
     256      210496 :     return mnInvisibleHeaven;
     257             : }
     258             : 
     259      208636 : SdrLayerID DocumentDrawModelManager::GetInvisibleHellId() const
     260             : {
     261      208636 :     return mnInvisibleHell;
     262             : }
     263             : 
     264      178976 : SdrLayerID DocumentDrawModelManager::GetInvisibleControlsId() const
     265             : {
     266      178976 :     return mnInvisibleControls;
     267             : }
     268             : 
     269        5318 : void DocumentDrawModelManager::NotifyInvisibleLayers( SdrPageView& _rSdrPageView )
     270             : {
     271        5318 :     OUString sLayerNm;
     272        5318 :     sLayerNm = "InvisibleHell";
     273        5318 :     _rSdrPageView.SetLayerVisible( sLayerNm, false );
     274             : 
     275        5318 :     sLayerNm = "InvisibleHeaven";
     276        5318 :     _rSdrPageView.SetLayerVisible( sLayerNm, false );
     277             : 
     278        5318 :     sLayerNm = "InvisibleControls";
     279        5318 :     _rSdrPageView.SetLayerVisible( sLayerNm, false );
     280        5318 : }
     281             : 
     282     1002619 : bool DocumentDrawModelManager::IsVisibleLayerId( const SdrLayerID& _nLayerId ) const
     283             : {
     284             :     bool bRetVal;
     285             : 
     286     2163070 :     if ( _nLayerId == GetHeavenId() ||
     287     1041434 :          _nLayerId == GetHellId() ||
     288       38815 :          _nLayerId == GetControlsId() )
     289             :     {
     290      976119 :         bRetVal = true;
     291             :     }
     292       64020 :     else if ( _nLayerId == GetInvisibleHeavenId() ||
     293       28152 :               _nLayerId == GetInvisibleHellId() ||
     294        1652 :               _nLayerId == GetInvisibleControlsId() )
     295             :     {
     296       26500 :         bRetVal = false;
     297             :     }
     298             :     else
     299             :     {
     300             :         OSL_FAIL( "<SwDoc::IsVisibleLayerId(..)> - unknown layer ID." );
     301           0 :         bRetVal = false;
     302             :     }
     303             : 
     304     1002619 :     return bRetVal;
     305             : }
     306             : 
     307           0 : SdrLayerID DocumentDrawModelManager::GetVisibleLayerIdByInvisibleOne( const SdrLayerID& _nInvisibleLayerId )
     308             : {
     309             :     SdrLayerID nVisibleLayerId;
     310             : 
     311           0 :     if ( _nInvisibleLayerId == GetInvisibleHeavenId() )
     312             :     {
     313           0 :         nVisibleLayerId = GetHeavenId();
     314             :     }
     315           0 :     else if ( _nInvisibleLayerId == GetInvisibleHellId() )
     316             :     {
     317           0 :         nVisibleLayerId = GetHellId();
     318             :     }
     319           0 :     else if ( _nInvisibleLayerId == GetInvisibleControlsId() )
     320             :     {
     321           0 :         nVisibleLayerId = GetControlsId();
     322             :     }
     323           0 :     else if ( _nInvisibleLayerId == GetHeavenId() ||
     324           0 :               _nInvisibleLayerId == GetHellId() ||
     325           0 :               _nInvisibleLayerId == GetControlsId() )
     326             :     {
     327             :         OSL_FAIL( "<SwDoc::GetVisibleLayerIdByInvisibleOne(..)> - given layer ID already an invisible one." );
     328           0 :         nVisibleLayerId = _nInvisibleLayerId;
     329             :     }
     330             :     else
     331             :     {
     332             :         OSL_FAIL( "<SwDoc::GetVisibleLayerIdByInvisibleOne(..)> - given layer ID is unknown." );
     333           0 :         nVisibleLayerId = _nInvisibleLayerId;
     334             :     }
     335             : 
     336           0 :     return nVisibleLayerId;
     337             : }
     338             : 
     339          46 : SdrLayerID DocumentDrawModelManager::GetInvisibleLayerIdByVisibleOne( const SdrLayerID& _nVisibleLayerId )
     340             : {
     341             :     SdrLayerID nInvisibleLayerId;
     342             : 
     343          46 :     if ( _nVisibleLayerId == GetHeavenId() )
     344             :     {
     345          46 :         nInvisibleLayerId = GetInvisibleHeavenId();
     346             :     }
     347           0 :     else if ( _nVisibleLayerId == GetHellId() )
     348             :     {
     349           0 :         nInvisibleLayerId = GetInvisibleHellId();
     350             :     }
     351           0 :     else if ( _nVisibleLayerId == GetControlsId() )
     352             :     {
     353           0 :         nInvisibleLayerId = GetInvisibleControlsId();
     354             :     }
     355           0 :     else if ( _nVisibleLayerId == GetInvisibleHeavenId() ||
     356           0 :               _nVisibleLayerId == GetInvisibleHellId() ||
     357           0 :               _nVisibleLayerId == GetInvisibleControlsId() )
     358             :     {
     359             :         OSL_FAIL( "<SwDoc::GetInvisibleLayerIdByVisibleOne(..)> - given layer ID already an invisible one." );
     360           0 :         nInvisibleLayerId = _nVisibleLayerId;
     361             :     }
     362             :     else
     363             :     {
     364             :         OSL_FAIL( "<SwDoc::GetInvisibleLayerIdByVisibleOne(..)> - given layer ID is unknown." );
     365           0 :         nInvisibleLayerId = _nVisibleLayerId;
     366             :     }
     367             : 
     368          46 :     return nInvisibleLayerId;
     369             : }
     370             : 
     371        5083 : void DocumentDrawModelManager::DrawNotifyUndoHdl()
     372             : {
     373        5083 :     mpDrawModel->SetNotifyUndoActionHdl( Link() );
     374        5083 : }
     375             : 
     376         270 : }
     377             : 
     378             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10