LCOV - code coverage report
Current view: top level - sw/source/core/view - viewimp.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 134 212 63.2 %
Date: 2014-04-11 Functions: 17 26 65.4 %
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 "crsrsh.hxx"
      21             : #include "rootfrm.hxx"
      22             : #include "pagefrm.hxx"
      23             : #include "viewimp.hxx"
      24             : #include "viewopt.hxx"
      25             : #include "flyfrm.hxx"
      26             : #include "frmfmt.hxx"
      27             : #include "layact.hxx"
      28             : #include "swregion.hxx"
      29             : #include "dflyobj.hxx"
      30             : #include "dview.hxx"
      31             : #include <tools/shl.hxx>
      32             : #include <swmodule.hxx>
      33             : #include <svx/svdpage.hxx>
      34             : #include <accmap.hxx>
      35             : 
      36             : // OD 12.12.2002 #103492#
      37             : #include <pagepreviewlayout.hxx>
      38             : 
      39             : #include <comcore.hrc>
      40             : #include <svx/svdundo.hxx>
      41             : #include <IDocumentLayoutAccess.hxx>
      42             : #include <IDocumentDrawModelAccess.hxx>
      43             : #include <IDocumentDeviceAccess.hxx>
      44             : #include <IDocumentSettingAccess.hxx>
      45             : 
      46        1752 : void SwViewImp::Init( const SwViewOption *pNewOpt )
      47             : {
      48             :     OSL_ENSURE( pDrawView, "SwViewImp::Init without DrawView" );
      49             :     //Create PageView if it doesn't exist
      50        1752 :     SwRootFrm *pRoot = pSh->GetLayout();
      51        1752 :     if ( !pSdrPageView )
      52             :     {
      53        1752 :         IDocumentDrawModelAccess* pIDDMA = pSh->getIDocumentDrawModelAccess();
      54        1752 :         if ( !pRoot->GetDrawPage() )
      55           0 :             pRoot->SetDrawPage( pIDDMA->GetDrawModel()->GetPage( 0 ) );
      56             : 
      57        1752 :         if ( pRoot->GetDrawPage()->GetSize() != pRoot->Frm().SSize() )
      58        1317 :             pRoot->GetDrawPage()->SetSize( pRoot->Frm().SSize() );
      59             : 
      60        1752 :         pSdrPageView = pDrawView->ShowSdrPage( pRoot->GetDrawPage());
      61             :         // OD 26.06.2003 #108784# - notify drawing page view about invisible
      62             :         // layers.
      63        1752 :         pIDDMA->NotifyInvisibleLayers( *pSdrPageView );
      64             :     }
      65        1752 :     pDrawView->SetDragStripes( pNewOpt->IsCrossHair() );
      66        1752 :     pDrawView->SetGridSnap( pNewOpt->IsSnap() );
      67        1752 :     pDrawView->SetGridVisible( pNewOpt->IsGridVisible() );
      68        1752 :     const Size &rSz = pNewOpt->GetSnapSize();
      69        1752 :     pDrawView->SetGridCoarse( rSz );
      70             :     const Size aFSize
      71        8760 :             ( rSz.Width() ? rSz.Width() /std::max(short(1),pNewOpt->GetDivisionX()):0,
      72       10512 :               rSz.Height()? rSz.Height()/std::max(short(1),pNewOpt->GetDivisionY()):0);
      73        1752 :      pDrawView->SetGridFine( aFSize );
      74        1752 :     Fraction aSnGrWdtX(rSz.Width(), pNewOpt->GetDivisionX() + 1);
      75        1752 :     Fraction aSnGrWdtY(rSz.Height(), pNewOpt->GetDivisionY() + 1);
      76        1752 :     pDrawView->SetSnapGridWidth( aSnGrWdtX, aSnGrWdtY );
      77             : 
      78        1752 :     if ( pRoot->Frm().HasArea() )
      79        1749 :         pDrawView->SetWorkArea( pRoot->Frm().SVRect() );
      80             : 
      81        1752 :     if ( GetShell()->IsPreview() )
      82           0 :         pDrawView->SetAnimationEnabled( false );
      83             : 
      84        1752 :     pDrawView->SetUseIncompatiblePathCreateInterface( false );
      85             : 
      86             :     // set handle size to 9 pixels, always
      87        1752 :     pDrawView->SetMarkHdlSizePixel(9);
      88        1752 : }
      89             : 
      90             : /// CTor for the core internals
      91        1752 : SwViewImp::SwViewImp( SwViewShell *pParent ) :
      92             :     pSh( pParent ),
      93             :     pDrawView( 0 ),
      94             :     pSdrPageView( 0 ),
      95             :     pFirstVisPage( 0 ),
      96             :     pRegion( 0 ),
      97             :     pLayAct( 0 ),
      98             :     pIdleAct( 0 ),
      99             :     pAccMap( 0 ),
     100             :     pSdrObjCached(NULL),
     101             :     bFirstPageInvalid( true ),
     102             :     bResetHdlHiddenPaint( false ),
     103             :     bSmoothUpdate( false ),
     104             :     bStopSmooth( false ),
     105             :     nRestoreActions( 0 ),
     106             :     // OD 12.12.2002 #103492#
     107        1752 :     mpPgPreviewLayout( 0 )
     108             : {
     109        1752 : }
     110             : 
     111        3502 : SwViewImp::~SwViewImp()
     112             : {
     113        1751 :     delete pAccMap;
     114             : 
     115             :     // OD 12.12.2002 #103492#
     116        1751 :     delete mpPgPreviewLayout;
     117             : 
     118             :     //JP 29.03.96: after ShowSdrPage  HideSdrPage must also be executed!!!
     119        1751 :     if( pDrawView )
     120        1751 :          pDrawView->HideSdrPage();
     121             : 
     122        1751 :     delete pDrawView;
     123             : 
     124        1751 :     DelRegion();
     125             : 
     126             :     OSL_ENSURE( !pLayAct, "Have action for the rest of your life." );
     127             :     OSL_ENSURE( !pIdleAct,"Be idle for the rest of your life." );
     128        1751 : }
     129             : 
     130        5660 : void SwViewImp::DelRegion()
     131             : {
     132        5660 :     DELETEZ(pRegion);
     133        5660 : }
     134             : 
     135       15793 : bool SwViewImp::AddPaintRect( const SwRect &rRect )
     136             : {
     137       15793 :     if ( rRect.IsOver( pSh->VisArea() ) )
     138             :     {
     139       11602 :         if ( !pRegion )
     140        3728 :             pRegion = new SwRegionRects( pSh->VisArea() );
     141       11602 :         (*pRegion) -= rRect;
     142       11602 :         return true;
     143             :     }
     144        4191 :     return false;
     145             : }
     146             : 
     147         666 : void SwViewImp::CheckWaitCrsr()
     148             : {
     149         666 :     if ( pLayAct )
     150         615 :         pLayAct->CheckWaitCrsr();
     151         666 : }
     152             : 
     153       12848 : bool SwViewImp::IsCalcLayoutProgress() const
     154             : {
     155       12848 :     return pLayAct && pLayAct->IsCalcLayout();
     156             : }
     157             : 
     158        7434 : bool SwViewImp::IsUpdateExpFlds()
     159             : {
     160        7434 :     if ( pLayAct && pLayAct->IsCalcLayout() )
     161             :     {
     162        3832 :         pLayAct->SetUpdateExpFlds();
     163        3832 :         return true;
     164             :     }
     165        3602 :     return false;
     166             : }
     167             : 
     168        7257 : void SwViewImp::SetFirstVisPage()
     169             : {
     170        7257 :     if ( pSh->mbDocSizeChgd && pSh->VisArea().Top() > pSh->GetLayout()->Frm().Height() )
     171             :     {
     172             :         //We are in an action and because of erase actions the VisArea is
     173             :         //after the first visible page.
     174             :         //To avoid excessive formatting, hand back the last page.
     175           3 :         pFirstVisPage = (SwPageFrm*)pSh->GetLayout()->Lower();
     176          11 :         while ( pFirstVisPage && pFirstVisPage->GetNext() )
     177           5 :             pFirstVisPage = (SwPageFrm*)pFirstVisPage->GetNext();
     178             :     }
     179             :     else
     180             :     {
     181        7254 :         const SwViewOption* pSwViewOption = GetShell()->GetViewOptions();
     182        7254 :         const bool bBookMode = pSwViewOption->IsViewLayoutBookMode();
     183             : 
     184        7254 :         SwPageFrm *pPage = (SwPageFrm*)pSh->GetLayout()->Lower();
     185        7254 :         SwRect aPageRect = pPage->GetBoundRect();
     186       17107 :         while ( pPage && !aPageRect.IsOver( pSh->VisArea() ) )
     187             :         {
     188        2599 :             pPage = (SwPageFrm*)pPage->GetNext();
     189        2599 :             if ( pPage )
     190             :             {
     191         838 :                 aPageRect = pPage->GetBoundRect();
     192         838 :                 if ( bBookMode && pPage->IsEmptyPage() )
     193             :                 {
     194           0 :                     const SwPageFrm& rFormatPage = pPage->GetFormatPage();
     195           0 :                     aPageRect.SSize() = rFormatPage.GetBoundRect().SSize();
     196             :                 }
     197             :             }
     198             :         }
     199        7254 :         pFirstVisPage = pPage ? pPage : (SwPageFrm*)pSh->GetLayout()->Lower();
     200             :     }
     201        7257 :     bFirstPageInvalid = false;
     202        7257 : }
     203             : 
     204        2167 : void SwViewImp::MakeDrawView()
     205             : {
     206        2167 :     IDocumentDrawModelAccess* pIDDMA = GetShell()->getIDocumentDrawModelAccess();
     207             : 
     208             :     // the else here is not an error, _MakeDrawModel() calls this method again
     209             :     // after the DrawModel is created to create DrawViews for all shells...
     210        2167 :     if( !pIDDMA->GetDrawModel() )
     211             :     {
     212         415 :         pIDDMA->_MakeDrawModel();
     213             :     }
     214             :     else
     215             :     {
     216        1752 :         if ( !pDrawView )
     217             :         {
     218             :             // #i72809#
     219             :             // Discussed with FME, he also thinks that the getPrinter is old and not correct. When i got
     220             :             // him right, it anyways returns GetOut() when it's a printer, but NULL when not. He suggested
     221             :             // to use GetOut() and check the existing cases.
     222             :             // Check worked well. Took a look at viewing, printing, PDF export and print preview with a test
     223             :             // document which has an empty 2nd page (right page, see bug)
     224        1752 :             OutputDevice* pOutDevForDrawView = GetShell()->GetWin();
     225             : 
     226        1752 :             if(!pOutDevForDrawView)
     227             :             {
     228          20 :                 pOutDevForDrawView = GetShell()->GetOut();
     229             :             }
     230             : 
     231        1752 :             pDrawView = new SwDrawView( *this, pIDDMA->GetDrawModel(), pOutDevForDrawView);
     232             :         }
     233             : 
     234        1752 :         GetDrawView()->SetActiveLayer(OUString("Heaven"));
     235        1752 :         const SwViewOption* pSwViewOption = GetShell()->GetViewOptions();
     236        1752 :         Init(pSwViewOption);
     237             : 
     238             :         // #i68597# If document is read-only, we will not profit from overlay,
     239             :         // so switch it off.
     240        1752 :         if (pDrawView->IsBufferedOverlayAllowed())
     241             :         {
     242        1752 :             if(pSwViewOption->IsReadonly())
     243             :             {
     244           1 :                 pDrawView->SetBufferedOverlayAllowed(false);
     245             :             }
     246             :         }
     247             :     }
     248        2167 : }
     249             : 
     250        6835 : Color SwViewImp::GetRetoucheColor() const
     251             : {
     252        6835 :     Color aRet( COL_TRANSPARENT );
     253        6835 :     const SwViewShell &rSh = *GetShell();
     254        6835 :     if ( rSh.GetWin() )
     255             :     {
     256        6853 :         if ( rSh.GetViewOptions()->getBrowseMode() &&
     257          38 :              COL_TRANSPARENT != rSh.GetViewOptions()->GetRetoucheColor().GetColor() )
     258           0 :             aRet = rSh.GetViewOptions()->GetRetoucheColor();
     259        6815 :         else if(rSh.GetViewOptions()->IsPagePreview()  &&
     260           0 :                     !SW_MOD()->GetAccessibilityOptions().GetIsForPagePreviews())
     261           0 :             aRet.SetColor(COL_WHITE);
     262             :         else
     263        6815 :             aRet = SwViewOption::GetDocColor();
     264             :     }
     265        6835 :     return aRet;
     266             : }
     267             : 
     268             : // create page preview layout
     269           0 : void SwViewImp::InitPagePreviewLayout()
     270             : {
     271             :     OSL_ENSURE( pSh->GetLayout(), "no layout - page preview layout can not be created.");
     272           0 :     if ( pSh->GetLayout() )
     273           0 :         mpPgPreviewLayout = new SwPagePreviewLayout( *pSh, *(pSh->GetLayout()) );
     274           0 : }
     275             : 
     276          19 : void SwViewImp::UpdateAccessible()
     277             : {
     278             :     // We require a layout and an XModel to be accessible.
     279          19 :     IDocumentLayoutAccess* pIDLA = GetShell()->getIDocumentLayoutAccess();
     280          19 :     Window *pWin = GetShell()->GetWin();
     281             :     OSL_ENSURE( GetShell()->GetLayout(), "no layout, no access" );
     282             :     OSL_ENSURE( pWin, "no window, no access" );
     283             : 
     284          19 :     if( IsAccessible() && pIDLA->GetCurrentViewShell() && pWin )
     285          19 :         GetAccessibleMap().GetDocumentView();
     286          19 : }
     287             : 
     288           0 : void SwViewImp::DisposeAccessible( const SwFrm *pFrm,
     289             :                                    const SdrObject *pObj,
     290             :                                    bool bRecursive )
     291             : {
     292             :     OSL_ENSURE( !pFrm || pFrm->IsAccessibleFrm(), "frame is not accessible" );
     293           0 :     SwViewShell *pVSh = GetShell();
     294           0 :     SwViewShell *pTmp = pVSh;
     295           0 :     do
     296             :     {
     297           0 :         if( pTmp->Imp()->IsAccessible() )
     298           0 :             pTmp->Imp()->GetAccessibleMap().Dispose( pFrm, pObj, 0, bRecursive );
     299           0 :         pTmp = (SwViewShell *)pTmp->GetNext();
     300             :     } while ( pTmp != pVSh );
     301           0 : }
     302             : 
     303          59 : void SwViewImp::MoveAccessible( const SwFrm *pFrm, const SdrObject *pObj,
     304             :                                 const SwRect& rOldFrm )
     305             : {
     306             :     OSL_ENSURE( !pFrm || pFrm->IsAccessibleFrm(), "frame is not accessible" );
     307          59 :     SwViewShell *pVSh = GetShell();
     308          59 :     SwViewShell *pTmp = pVSh;
     309          59 :     do
     310             :     {
     311          59 :         if( pTmp->Imp()->IsAccessible() )
     312          59 :             pTmp->Imp()->GetAccessibleMap().InvalidatePosOrSize( pFrm, pObj, 0,
     313          59 :                                                                  rOldFrm );
     314          59 :         pTmp = (SwViewShell *)pTmp->GetNext();
     315             :     } while ( pTmp != pVSh );
     316          59 : }
     317             : 
     318           0 : void SwViewImp::InvalidateAccessibleFrmContent( const SwFrm *pFrm )
     319             : {
     320             :     OSL_ENSURE( pFrm->IsAccessibleFrm(), "frame is not accessible" );
     321           0 :     SwViewShell *pVSh = GetShell();
     322           0 :     SwViewShell *pTmp = pVSh;
     323           0 :     do
     324             :     {
     325           0 :         if( pTmp->Imp()->IsAccessible() )
     326           0 :             pTmp->Imp()->GetAccessibleMap().InvalidateContent( pFrm );
     327           0 :         pTmp = (SwViewShell *)pTmp->GetNext();
     328             :     } while ( pTmp != pVSh );
     329           0 : }
     330             : 
     331          78 : void SwViewImp::InvalidateAccessibleCursorPosition( const SwFrm *pFrm )
     332             : {
     333          78 :     if( IsAccessible() )
     334          78 :         GetAccessibleMap().InvalidateCursorPosition( pFrm );
     335          78 : }
     336             : 
     337           0 : void SwViewImp::InvalidateAccessibleEditableState( bool bAllShells,
     338             :                                                       const SwFrm *pFrm )
     339             : {
     340           0 :     if( bAllShells )
     341             :     {
     342           0 :         SwViewShell *pVSh = GetShell();
     343           0 :         SwViewShell *pTmp = pVSh;
     344           0 :         do
     345             :         {
     346           0 :             if( pTmp->Imp()->IsAccessible() )
     347           0 :                 pTmp->Imp()->GetAccessibleMap().InvalidateStates( ACC_STATE_EDITABLE, pFrm );
     348           0 :             pTmp = (SwViewShell *)pTmp->GetNext();
     349             :         } while ( pTmp != pVSh );
     350             :     }
     351           0 :     else if( IsAccessible() )
     352             :     {
     353           0 :         GetAccessibleMap().InvalidateStates( ACC_STATE_EDITABLE, pFrm );
     354             :     }
     355           0 : }
     356             : 
     357           0 : void SwViewImp::InvalidateAccessibleRelationSet( const SwFlyFrm *pMaster,
     358             :                                                  const SwFlyFrm *pFollow )
     359             : {
     360           0 :     SwViewShell *pVSh = GetShell();
     361           0 :     SwViewShell *pTmp = pVSh;
     362           0 :     do
     363             :     {
     364           0 :         if( pTmp->Imp()->IsAccessible() )
     365           0 :             pTmp->Imp()->GetAccessibleMap().InvalidateRelationSet( pMaster,
     366           0 :                                                                    pFollow );
     367           0 :         pTmp = (SwViewShell *)pTmp->GetNext();
     368             :     } while ( pTmp != pVSh );
     369           0 : }
     370             : 
     371             : /// invalidate CONTENT_FLOWS_FROM/_TO relation for paragraphs
     372           0 : void SwViewImp::_InvalidateAccessibleParaFlowRelation( const SwTxtFrm* _pFromTxtFrm,
     373             :                                                        const SwTxtFrm* _pToTxtFrm )
     374             : {
     375           0 :     if ( !_pFromTxtFrm && !_pToTxtFrm )
     376             :     {
     377             :         // No text frame provided. Thus, nothing to do.
     378           0 :         return;
     379             :     }
     380             : 
     381           0 :     SwViewShell* pVSh = GetShell();
     382           0 :     SwViewShell* pTmp = pVSh;
     383           0 :     do
     384             :     {
     385           0 :         if ( pTmp->Imp()->IsAccessible() )
     386             :         {
     387           0 :             if ( _pFromTxtFrm )
     388             :             {
     389           0 :                 pTmp->Imp()->GetAccessibleMap().
     390           0 :                             InvalidateParaFlowRelation( *_pFromTxtFrm, true );
     391             :             }
     392           0 :             if ( _pToTxtFrm )
     393             :             {
     394           0 :                 pTmp->Imp()->GetAccessibleMap().
     395           0 :                             InvalidateParaFlowRelation( *_pToTxtFrm, false );
     396             :             }
     397             :         }
     398           0 :         pTmp = (SwViewShell *)pTmp->GetNext();
     399             :     } while ( pTmp != pVSh );
     400             : }
     401             : 
     402             : /// invalidate text selection for paragraphs
     403          78 : void SwViewImp::_InvalidateAccessibleParaTextSelection()
     404             : {
     405          78 :     SwViewShell* pVSh = GetShell();
     406          78 :     SwViewShell* pTmp = pVSh;
     407          78 :     do
     408             :     {
     409          78 :         if ( pTmp->Imp()->IsAccessible() )
     410             :         {
     411          78 :             pTmp->Imp()->GetAccessibleMap().InvalidateTextSelectionOfAllParas();
     412             :         }
     413             : 
     414          78 :         pTmp = (SwViewShell *)pTmp->GetNext();
     415             :     } while ( pTmp != pVSh );
     416          78 : }
     417             : 
     418             : /// invalidate attributes for paragraphs
     419           0 : void SwViewImp::_InvalidateAccessibleParaAttrs( const SwTxtFrm& rTxtFrm )
     420             : {
     421           0 :     SwViewShell* pVSh = GetShell();
     422           0 :     SwViewShell* pTmp = pVSh;
     423           0 :     do
     424             :     {
     425           0 :         if ( pTmp->Imp()->IsAccessible() )
     426             :         {
     427           0 :             pTmp->Imp()->GetAccessibleMap().InvalidateAttr( rTxtFrm );
     428             :         }
     429             : 
     430           0 :         pTmp = (SwViewShell *)pTmp->GetNext();
     431             :     } while ( pTmp != pVSh );
     432           0 : }
     433             : 
     434             : // OD 15.01.2003 #103492# - method signature change due to new page preview functionality
     435           0 : void SwViewImp::UpdateAccessiblePreview( const std::vector<PreviewPage*>& _rPreviewPages,
     436             :                                          const Fraction&  _rScale,
     437             :                                          const SwPageFrm* _pSelectedPageFrm,
     438             :                                          const Size&      _rPreviewWinSize )
     439             : {
     440           0 :     if( IsAccessible() )
     441           0 :         GetAccessibleMap().UpdatePreview( _rPreviewPages, _rScale,
     442           0 :                                           _pSelectedPageFrm, _rPreviewWinSize );
     443           0 : }
     444             : 
     445           0 : void SwViewImp::InvalidateAccessiblePreviewSelection( sal_uInt16 nSelPage )
     446             : {
     447           0 :     if( IsAccessible() )
     448           0 :         GetAccessibleMap().InvalidatePreviewSelection( nSelPage );
     449           0 : }
     450             : 
     451          12 : SwAccessibleMap *SwViewImp::CreateAccessibleMap()
     452             : {
     453             :     OSL_ENSURE( !pAccMap, "accessible map exists" );
     454          12 :     pAccMap = new SwAccessibleMap( GetShell() );
     455          12 :     return pAccMap;
     456             : }
     457             : 
     458          82 : void SwViewImp::FireAccessibleEvents()
     459             : {
     460          82 :     if( IsAccessible() )
     461          82 :         GetAccessibleMap().FireEvents();
     462          82 : }
     463             : 
     464             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10