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

Generated by: LCOV version 1.10