LCOV - code coverage report
Current view: top level - sw/source/core/doc - DocumentDrawModelManager.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 127 169 75.1 %
Date: 2015-06-13 12:38:46 Functions: 20 21 95.2 %
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 <wrtsh.hxx>
      30             : #include <swtypes.hxx>
      31             : #include <ndtxt.hxx>
      32             : #include <swhints.hxx>
      33             : #include <viewsh.hxx>
      34             : #include <view.hxx>
      35             : #include <drawdoc.hxx>
      36             : #include <rootfrm.hxx>
      37             : #include <fmtanchr.hxx>
      38             : #include <editeng/eeitem.hxx>
      39             : #include <editeng/fhgtitem.hxx>
      40             : #include <svx/svdmodel.hxx>
      41             : #include <svx/svdlayer.hxx>
      42             : #include <svx/svdoutl.hxx>
      43             : #include <svx/svdpage.hxx>
      44             : #include <svx/svdpagv.hxx>
      45             : #include <svx/svdotext.hxx>
      46             : #include <svl/smplhint.hxx>
      47             : #include <svl/srchitem.hxx>
      48             : #include <tools/link.hxx>
      49             : 
      50             : class SdrOutliner;
      51             : class XSpellChecker1;
      52             : 
      53             : namespace sw
      54             : {
      55             : 
      56        2958 : DocumentDrawModelManager::DocumentDrawModelManager(SwDoc& i_rSwdoc)
      57             :     : m_rDoc(i_rSwdoc)
      58             :     , mpDrawModel(0)
      59             :     , mnHeaven(0)
      60             :     , mnHell(0)
      61             :     , mnControls(0)
      62             :     , mnInvisibleHeaven(0)
      63             :     , mnInvisibleHell(0)
      64        2958 :     , mnInvisibleControls(0)
      65             : {
      66        2958 : }
      67             : 
      68             : // Is also called by the Sw3 Reader, if there was an error when reading the
      69             : // drawing layer. If it is called by the Sw3 Reader the layer is rebuilt
      70             : // from scratch.
      71        2958 : void DocumentDrawModelManager::InitDrawModel()
      72             : {
      73             :     // !! Attention: there is similar code in the Sw3 Reader (sw3imp.cxx) that
      74             :     // also has to be maintained!!
      75        2958 :     if ( mpDrawModel )
      76           0 :         ReleaseDrawModel();
      77             : 
      78             : //UUUU
      79             : //  // Setup DrawPool and EditEnginePool. Ownership is ours and only gets passed
      80             : //  // to the Drawing.
      81             : //  // The pools are destroyed in the ReleaseDrawModel.
      82             : //  // for loading the drawing items. This must be loaded without RefCounts!
      83             : //  SfxItemPool *pSdrPool = new SdrItemPool( &GetAttrPool() );
      84             : //  // change DefaultItems for the SdrEdgeObj distance items to TWIPS.
      85             : //  if(pSdrPool)
      86             : //  {
      87             : //      const long nDefEdgeDist = ((500 * 72) / 127); // 1/100th mm in twips
      88             : //      pSdrPool->SetPoolDefaultItem(SdrEdgeNode1HorzDistItem(nDefEdgeDist));
      89             : //      pSdrPool->SetPoolDefaultItem(SdrEdgeNode1VertDistItem(nDefEdgeDist));
      90             : //      pSdrPool->SetPoolDefaultItem(SdrEdgeNode2HorzDistItem(nDefEdgeDist));
      91             : //      pSdrPool->SetPoolDefaultItem(SdrEdgeNode2VertDistItem(nDefEdgeDist));
      92             : //
      93             : //      // #i33700#
      94             : //      // Set shadow distance defaults as PoolDefaultItems. Details see bug.
      95             : //      pSdrPool->SetPoolDefaultItem(makeSdrShadowXDistItem((300 * 72) / 127));
      96             : //      pSdrPool->SetPoolDefaultItem(makeSdrShadowYDistItem((300 * 72) / 127));
      97             : //  }
      98             : //  SfxItemPool *pEEgPool = EditEngine::CreatePool( false );
      99             : //  pSdrPool->SetSecondaryPool( pEEgPool );
     100             : //   if ( !GetAttrPool().GetFrozenIdRanges () )
     101             : //      GetAttrPool().FreezeIdRanges();
     102             : //  else
     103             : //      pSdrPool->FreezeIdRanges();
     104             : 
     105             :     // set FontHeight pool defaults without changing static SdrEngineDefaults
     106        2958 :     m_rDoc.GetAttrPool().SetPoolDefaultItem(SvxFontHeightItem( 240, 100, EE_CHAR_FONTHEIGHT ));
     107             : 
     108             :     SAL_INFO( "sw.doc", "before create DrawDocument" );
     109             :     // The document owns the SwDrawModel. We always have two layers and one page.
     110        2958 :     mpDrawModel = new SwDrawModel( &m_rDoc );
     111             : 
     112        2958 :     mpDrawModel->EnableUndo( m_rDoc.GetIDocumentUndoRedo().DoesUndo() );
     113             : 
     114        2958 :     OUString sLayerNm;
     115        2958 :     sLayerNm = "Hell";
     116        2958 :     mnHell   = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
     117             : 
     118        2958 :     sLayerNm = "Heaven";
     119        2958 :     mnHeaven = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
     120             : 
     121        2958 :     sLayerNm = "Controls";
     122        2958 :     mnControls = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
     123             : 
     124             :     // add invisible layers corresponding to the visible ones.
     125             :     {
     126        2958 :         sLayerNm = "InvisibleHell";
     127        2958 :         mnInvisibleHell   = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
     128             : 
     129        2958 :         sLayerNm = "InvisibleHeaven";
     130        2958 :         mnInvisibleHeaven = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
     131             : 
     132        2958 :         sLayerNm = "InvisibleControls";
     133        2958 :         mnInvisibleControls = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
     134             :     }
     135             : 
     136        2958 :     SdrPage* pMasterPage = mpDrawModel->AllocPage( false );
     137        2958 :     mpDrawModel->InsertPage( pMasterPage );
     138             :     SAL_INFO( "sw.doc", "after create DrawDocument" );
     139             :     SAL_INFO( "sw.doc", "before create Spellchecker/Hyphenator" );
     140        2958 :     SdrOutliner& rOutliner = mpDrawModel->GetDrawOutliner();
     141        5916 :     ::com::sun::star::uno::Reference< com::sun::star::linguistic2::XSpellChecker1 > xSpell = ::GetSpellChecker();
     142        2958 :     rOutliner.SetSpeller( xSpell );
     143        5916 :     ::com::sun::star::uno::Reference< com::sun::star::linguistic2::XHyphenator > xHyphenator( ::GetHyphenator() );
     144        2958 :     rOutliner.SetHyphenator( xHyphenator );
     145             :     SAL_INFO( "sw.doc", "after create Spellchecker/Hyphenator" );
     146        2958 :     m_rDoc.SetCalcFieldValueHdl(&rOutliner);
     147        2958 :     m_rDoc.SetCalcFieldValueHdl(&mpDrawModel->GetHitTestOutliner());
     148             : 
     149             :     // Set the LinkManager in the model so that linked graphics can be inserted.
     150             :     // The WinWord import needs it too.
     151        2958 :     mpDrawModel->SetLinkManager( & m_rDoc.getIDocumentLinksAdministration().GetLinkManager() );
     152        2958 :     mpDrawModel->SetAddExtLeading( m_rDoc.getIDocumentSettingAccess().get(DocumentSettingId::ADD_EXT_LEADING) );
     153             : 
     154        2958 :     OutputDevice* pRefDev = m_rDoc.getIDocumentDeviceAccess().getReferenceDevice( false );
     155        2958 :     if ( pRefDev )
     156           0 :         mpDrawModel->SetRefDevice( pRefDev );
     157             : 
     158        2958 :     mpDrawModel->SetNotifyUndoActionHdl( LINK( &m_rDoc, SwDoc, AddDrawUndo ));
     159        2958 :     SwViewShell* const pSh = m_rDoc.getIDocumentLayoutAccess().GetCurrentViewShell();
     160        2958 :     if ( pSh )
     161             :     {
     162           0 :         for(SwViewShell& rViewSh : pSh->GetRingContainer())
     163             :         {
     164           0 :             SwRootFrm* pRoot =  rViewSh.GetLayout();
     165           0 :             if( pRoot && !pRoot->GetDrawPage() )
     166             :             {
     167             :                 // Disable "multiple layout" for the moment:
     168             :                 // use pMasterPage instead of a new created SdrPage
     169             :                 // mpDrawModel->AllocPage( FALSE );
     170             :                 // mpDrawModel->InsertPage( pDrawPage );
     171           0 :                 SdrPage* pDrawPage = pMasterPage;
     172           0 :                 pRoot->SetDrawPage( pDrawPage );
     173           0 :                 pDrawPage->SetSize( pRoot->Frm().SSize() );
     174             :             }
     175             :         }
     176        2958 :     }
     177        2958 : }
     178             : 
     179             : 
     180        2949 : void DocumentDrawModelManager::ReleaseDrawModel()
     181             : {
     182        2949 :     if ( mpDrawModel )
     183             :     {
     184             :         // !! Also maintain the code in the sw3io for inserting documents!!
     185             : 
     186        2949 :         delete mpDrawModel; mpDrawModel = 0;
     187             : //UUUU
     188             : //      SfxItemPool *pSdrPool = GetAttrPool().GetSecondaryPool();
     189             : //
     190             : //      OSL_ENSURE( pSdrPool, "missing pool" );
     191             : //      SfxItemPool *pEEgPool = pSdrPool->GetSecondaryPool();
     192             : //      OSL_ENSURE( !pEEgPool->GetSecondaryPool(), "I don't accept additional pools");
     193             : //      pSdrPool->Delete();                 // First have the items destroyed,
     194             : //                                          // then destroy the chain!
     195             : //      GetAttrPool().SetSecondaryPool( 0 );    // This one's a must!
     196             : //      pSdrPool->SetSecondaryPool( 0 );    // That one's safer
     197             : //      SfxItemPool::Free(pSdrPool);
     198             : //      SfxItemPool::Free(pEEgPool);
     199             :     }
     200        2949 : }
     201             : 
     202             : 
     203             : 
     204             : 
     205             : 
     206      307993 : const SwDrawModel* DocumentDrawModelManager::GetDrawModel() const
     207             : {
     208      307993 :     return mpDrawModel;
     209             : }
     210             : 
     211     1002314 : SwDrawModel* DocumentDrawModelManager::GetDrawModel()
     212             : {
     213     1002314 :     return mpDrawModel;
     214             : }
     215             : 
     216        2958 : SwDrawModel* DocumentDrawModelManager::_MakeDrawModel()
     217             : {
     218             :     OSL_ENSURE( !mpDrawModel, "_MakeDrawModel: Why?" );
     219        2958 :     InitDrawModel();
     220        2958 :     SwViewShell* const pSh = m_rDoc.getIDocumentLayoutAccess().GetCurrentViewShell();
     221        2958 :     if ( pSh )
     222             :     {
     223           0 :         for(SwViewShell& rViewSh : pSh->GetRingContainer())
     224           0 :             rViewSh.MakeDrawView();
     225             : 
     226             :         // Broadcast, so that the FormShell can be connected to the DrawView
     227           0 :         if( m_rDoc.GetDocShell() )
     228             :         {
     229           0 :             SfxSimpleHint aHint( SW_BROADCAST_DRAWVIEWS_CREATED );
     230           0 :             m_rDoc.GetDocShell()->Broadcast( aHint );
     231             :         }
     232             :     }
     233        2958 :     return mpDrawModel;
     234             : }
     235             : 
     236      415829 : SwDrawModel* DocumentDrawModelManager::GetOrCreateDrawModel()
     237             : {
     238      415829 :     return GetDrawModel() ? GetDrawModel() : _MakeDrawModel();
     239             : }
     240             : 
     241      625056 : SdrLayerID DocumentDrawModelManager::GetHeavenId() const
     242             : {
     243      625056 :     return mnHeaven;
     244             : }
     245             : 
     246      239378 : SdrLayerID DocumentDrawModelManager::GetHellId() const
     247             : {
     248      239378 :     return mnHell;
     249             : }
     250             : 
     251      119187 : SdrLayerID DocumentDrawModelManager::GetControlsId() const
     252             : {
     253      119187 :     return mnControls;
     254             : }
     255             : 
     256      108656 : SdrLayerID DocumentDrawModelManager::GetInvisibleHeavenId() const
     257             : {
     258      108656 :     return mnInvisibleHeaven;
     259             : }
     260             : 
     261      107576 : SdrLayerID DocumentDrawModelManager::GetInvisibleHellId() const
     262             : {
     263      107576 :     return mnInvisibleHell;
     264             : }
     265             : 
     266       91549 : SdrLayerID DocumentDrawModelManager::GetInvisibleControlsId() const
     267             : {
     268       91549 :     return mnInvisibleControls;
     269             : }
     270             : 
     271        3109 : void DocumentDrawModelManager::NotifyInvisibleLayers( SdrPageView& _rSdrPageView )
     272             : {
     273        3109 :     OUString sLayerNm;
     274        3109 :     sLayerNm = "InvisibleHell";
     275        3109 :     _rSdrPageView.SetLayerVisible( sLayerNm, false );
     276             : 
     277        3109 :     sLayerNm = "InvisibleHeaven";
     278        3109 :     _rSdrPageView.SetLayerVisible( sLayerNm, false );
     279             : 
     280        3109 :     sLayerNm = "InvisibleControls";
     281        3109 :     _rSdrPageView.SetLayerVisible( sLayerNm, false );
     282        3109 : }
     283             : 
     284      501671 : bool DocumentDrawModelManager::IsVisibleLayerId( const SdrLayerID& _nLayerId ) const
     285             : {
     286             :     bool bRetVal;
     287             : 
     288     1095496 :     if ( _nLayerId == GetHeavenId() ||
     289      530809 :          _nLayerId == GetHellId() ||
     290       29138 :          _nLayerId == GetControlsId() )
     291             :     {
     292      487366 :         bRetVal = true;
     293             :     }
     294       34539 :     else if ( _nLayerId == GetInvisibleHeavenId() ||
     295       15128 :               _nLayerId == GetInvisibleHellId() ||
     296         823 :               _nLayerId == GetInvisibleControlsId() )
     297             :     {
     298       14305 :         bRetVal = false;
     299             :     }
     300             :     else
     301             :     {
     302             :         OSL_FAIL( "<SwDoc::IsVisibleLayerId(..)> - unknown layer ID." );
     303           0 :         bRetVal = false;
     304             :     }
     305             : 
     306      501671 :     return bRetVal;
     307             : }
     308             : 
     309           0 : SdrLayerID DocumentDrawModelManager::GetVisibleLayerIdByInvisibleOne( const SdrLayerID& _nInvisibleLayerId )
     310             : {
     311             :     SdrLayerID nVisibleLayerId;
     312             : 
     313           0 :     if ( _nInvisibleLayerId == GetInvisibleHeavenId() )
     314             :     {
     315           0 :         nVisibleLayerId = GetHeavenId();
     316             :     }
     317           0 :     else if ( _nInvisibleLayerId == GetInvisibleHellId() )
     318             :     {
     319           0 :         nVisibleLayerId = GetHellId();
     320             :     }
     321           0 :     else if ( _nInvisibleLayerId == GetInvisibleControlsId() )
     322             :     {
     323           0 :         nVisibleLayerId = GetControlsId();
     324             :     }
     325           0 :     else if ( _nInvisibleLayerId == GetHeavenId() ||
     326           0 :               _nInvisibleLayerId == GetHellId() ||
     327           0 :               _nInvisibleLayerId == GetControlsId() )
     328             :     {
     329             :         OSL_FAIL( "<SwDoc::GetVisibleLayerIdByInvisibleOne(..)> - given layer ID already an invisible one." );
     330           0 :         nVisibleLayerId = _nInvisibleLayerId;
     331             :     }
     332             :     else
     333             :     {
     334             :         OSL_FAIL( "<SwDoc::GetVisibleLayerIdByInvisibleOne(..)> - given layer ID is unknown." );
     335           0 :         nVisibleLayerId = _nInvisibleLayerId;
     336             :     }
     337             : 
     338           0 :     return nVisibleLayerId;
     339             : }
     340             : 
     341          20 : SdrLayerID DocumentDrawModelManager::GetInvisibleLayerIdByVisibleOne( const SdrLayerID& _nVisibleLayerId )
     342             : {
     343             :     SdrLayerID nInvisibleLayerId;
     344             : 
     345          20 :     if ( _nVisibleLayerId == GetHeavenId() )
     346             :     {
     347          20 :         nInvisibleLayerId = GetInvisibleHeavenId();
     348             :     }
     349           0 :     else if ( _nVisibleLayerId == GetHellId() )
     350             :     {
     351           0 :         nInvisibleLayerId = GetInvisibleHellId();
     352             :     }
     353           0 :     else if ( _nVisibleLayerId == GetControlsId() )
     354             :     {
     355           0 :         nInvisibleLayerId = GetInvisibleControlsId();
     356             :     }
     357           0 :     else if ( _nVisibleLayerId == GetInvisibleHeavenId() ||
     358           0 :               _nVisibleLayerId == GetInvisibleHellId() ||
     359           0 :               _nVisibleLayerId == GetInvisibleControlsId() )
     360             :     {
     361             :         OSL_FAIL( "<SwDoc::GetInvisibleLayerIdByVisibleOne(..)> - given layer ID already an invisible one." );
     362           0 :         nInvisibleLayerId = _nVisibleLayerId;
     363             :     }
     364             :     else
     365             :     {
     366             :         OSL_FAIL( "<SwDoc::GetInvisibleLayerIdByVisibleOne(..)> - given layer ID is unknown." );
     367           0 :         nInvisibleLayerId = _nVisibleLayerId;
     368             :     }
     369             : 
     370          20 :     return nInvisibleLayerId;
     371             : }
     372             : 
     373          43 : bool DocumentDrawModelManager::Search(const SwPaM& rPaM, const SvxSearchItem& rSearchItem)
     374             : {
     375          43 :     SwPosFlyFrms aFrames = m_rDoc.GetAllFlyFormats(&rPaM, /*bDrawAlso=*/true);
     376             : 
     377          48 :     for (const SwPosFlyFrmPtr& pPosFlyFrm : aFrames)
     378             :     {
     379             :         // Filter for at-paragraph anchored draw frames.
     380           7 :         const SwFrameFormat& rFrameFormat = pPosFlyFrm->GetFormat();
     381           7 :         const SwFormatAnchor& rAnchor = rFrameFormat.GetAnchor();
     382           7 :         if (rAnchor.GetAnchorId() != FLY_AT_PARA || rFrameFormat.Which() != RES_DRAWFRMFMT)
     383           3 :             continue;
     384             : 
     385             :         // Does the shape have matching text?
     386           4 :         SdrOutliner& rOutliner = GetDrawModel()->GetDrawOutliner();
     387           4 :         SdrObject* pObject = const_cast<SdrObject*>(rFrameFormat.FindSdrObject());
     388           4 :         SdrTextObj* pTextObj = dynamic_cast<SdrTextObj*>(pObject);
     389           4 :         if (!pTextObj)
     390           0 :             continue;
     391           4 :         const OutlinerParaObject* pParaObj = pTextObj->GetOutlinerParaObject();
     392           4 :         if (!pParaObj)
     393           0 :             continue;
     394           4 :         rOutliner.SetText(*pParaObj);
     395           4 :         SwDocShell* pDocShell = m_rDoc.GetDocShell();
     396           4 :         if (!pDocShell)
     397           2 :             return false;
     398           4 :         SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
     399           4 :         if (!pWrtShell)
     400           0 :             return false;
     401           4 :         if (!rOutliner.HasText(rSearchItem))
     402           2 :             continue;
     403             : 
     404             :         // If so, then select highlight the search result.
     405           2 :         pWrtShell->SelectObj(Point(), 0, pObject);
     406           2 :         SwView* pView = pDocShell->GetView();
     407           2 :         if (!pView)
     408           0 :             return false;
     409           2 :         if (!pView->EnterShapeDrawTextMode(pObject))
     410           0 :             continue;
     411           2 :         SdrView* pSdrView = pWrtShell->GetDrawView();
     412           2 :         if (!pSdrView)
     413           0 :             return false;
     414           2 :         OutlinerView* pOutlinerView = pSdrView->GetTextEditOutlinerView();
     415           2 :         if (!rSearchItem.GetBackward())
     416           1 :             pOutlinerView->SetSelection(ESelection(0, 0, 0, 0));
     417             :         else
     418           1 :             pOutlinerView->SetSelection(ESelection(EE_PARA_MAX_COUNT, EE_TEXTPOS_MAX_COUNT, EE_PARA_MAX_COUNT, EE_TEXTPOS_MAX_COUNT));
     419           2 :         pOutlinerView->StartSearchAndReplace(rSearchItem);
     420           2 :         return true;
     421             :     }
     422             : 
     423          84 :     return false;
     424             : }
     425             : 
     426        2970 : void DocumentDrawModelManager::DrawNotifyUndoHdl()
     427             : {
     428        2970 :     mpDrawModel->SetNotifyUndoActionHdl( Link<>() );
     429        2970 : }
     430             : 
     431         177 : }
     432             : 
     433             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11