LCOV - code coverage report
Current view: top level - sw/source/core/view - vdraw.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 93 120 77.5 %
Date: 2015-06-13 12:38:46 Functions: 8 9 88.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 <svx/svdmodel.hxx>
      21             : #include <svx/svdpage.hxx>
      22             : #include <swmodule.hxx>
      23             : #include <svtools/accessibilityoptions.hxx>
      24             : #include <svx/svdpagv.hxx>
      25             : #include <fmtanchr.hxx>
      26             : #include <frmfmt.hxx>
      27             : 
      28             : #include <svx/svdoutl.hxx>
      29             : 
      30             : #include "drawdoc.hxx"
      31             : #include "fesh.hxx"
      32             : #include "pagefrm.hxx"
      33             : #include "rootfrm.hxx"
      34             : #include "viewimp.hxx"
      35             : #include "dflyobj.hxx"
      36             : #include "viewopt.hxx"
      37             : #include "printdata.hxx"
      38             : #include "dcontact.hxx"
      39             : #include "dview.hxx"
      40             : #include "flyfrm.hxx"
      41             : #include <vcl/svapp.hxx>
      42             : #include <vcl/settings.hxx>
      43             : 
      44             : #include <IDocumentDrawModelAccess.hxx>
      45             : 
      46       68568 : void SwViewShellImp::StartAction()
      47             : {
      48       68568 :     if ( HasDrawView() )
      49             :     {
      50       68567 :         SET_CURR_SHELL( GetShell() );
      51       68567 :         if ( pSh->ISA(SwFEShell) )
      52       68567 :             static_cast<SwFEShell*>(pSh)->HideChainMarker(); // might have changed
      53             :     }
      54       68568 : }
      55             : 
      56       41254 : void SwViewShellImp::EndAction()
      57             : {
      58       41254 :     if ( HasDrawView() )
      59             :     {
      60       41253 :         SET_CURR_SHELL( GetShell() );
      61       41253 :         if ( pSh->ISA(SwFEShell) )
      62       41253 :             static_cast<SwFEShell*>(pSh)->SetChainMarker(); // might have changed
      63             :     }
      64       41254 : }
      65             : 
      66       14996 : void SwViewShellImp::LockPaint()
      67             : {
      68       14996 :     if ( HasDrawView() )
      69             :     {
      70       14996 :         bResetHdlHiddenPaint = !GetDrawView()->areMarkHandlesHidden();
      71       14996 :         GetDrawView()->hideMarkHandles();
      72             :     }
      73             :     else
      74             :     {
      75           0 :         bResetHdlHiddenPaint = false;
      76             :     }
      77       14996 : }
      78             : 
      79       14996 : void SwViewShellImp::UnlockPaint()
      80             : {
      81       14996 :     if ( bResetHdlHiddenPaint )
      82       14996 :         GetDrawView()->showMarkHandles();
      83       14996 : }
      84             : 
      85       18572 : void SwViewShellImp::PaintLayer( const SdrLayerID _nLayerID,
      86             :                             SwPrintData const*const pPrintData,
      87             :                             const SwRect& aPaintRect,
      88             :                             const Color* _pPageBackgrdColor,
      89             :                             const bool _bIsPageRightToLeft,
      90             :                             sdr::contact::ViewObjectContactRedirector* pRedirector )
      91             : {
      92       18572 :     if ( HasDrawView() )
      93             :     {
      94             :         //change the draw mode in high contrast mode
      95       18572 :         OutputDevice* pOutDev = GetShell()->GetOut();
      96       18572 :         DrawModeFlags nOldDrawMode = pOutDev->GetDrawMode();
      97       55020 :         if( GetShell()->GetWin() &&
      98       18572 :             Application::GetSettings().GetStyleSettings().GetHighContrastMode() &&
      99           0 :             (!GetShell()->IsPreview()||SW_MOD()->GetAccessibilityOptions().GetIsForPagePreviews()))
     100             :         {
     101             :             pOutDev->SetDrawMode( nOldDrawMode | DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill |
     102           0 :                                 DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient );
     103             :         }
     104             : 
     105             :         // For correct handling of accessibility, high contrast, the
     106             :         // page background color is set as the background color at the
     107             :         // outliner of the draw view.  Only necessary for the layers
     108             :         // hell and heaven
     109       18572 :         Color aOldOutlinerBackgrdColor;
     110             :         // set default horizontal text direction on painting <hell> or
     111             :         // <heaven>.
     112       18572 :         EEHorizontalTextDirection aOldEEHoriTextDir = EE_HTEXTDIR_L2R;
     113       18572 :         const IDocumentDrawModelAccess* pIDDMA = GetShell()->getIDocumentDrawModelAccess();
     114       27858 :         if ( (_nLayerID == pIDDMA->GetHellId()) ||
     115        9286 :              (_nLayerID == pIDDMA->GetHeavenId()) )
     116             :         {
     117             :             OSL_ENSURE( _pPageBackgrdColor,
     118             :                     "incorrect usage of SwViewShellImp::PaintLayer: pPageBackgrdColor have to be set for painting layer <hell> or <heaven>");
     119       18572 :             if ( _pPageBackgrdColor )
     120             :             {
     121             :                 aOldOutlinerBackgrdColor =
     122       18572 :                         GetDrawView()->GetModel()->GetDrawOutliner().GetBackgroundColor();
     123       18572 :                 GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( *_pPageBackgrdColor );
     124             :             }
     125             : 
     126             :             aOldEEHoriTextDir =
     127       18572 :                 GetDrawView()->GetModel()->GetDrawOutliner().GetDefaultHorizontalTextDirection();
     128             :             EEHorizontalTextDirection aEEHoriTextDirOfPage =
     129       18572 :                 _bIsPageRightToLeft ? EE_HTEXTDIR_R2L : EE_HTEXTDIR_L2R;
     130       18572 :             GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aEEHoriTextDirOfPage );
     131             :         }
     132             : 
     133       18572 :         pOutDev->Push( PushFlags::LINECOLOR ); // #114231#
     134       18572 :         if (pPrintData)
     135             :         {
     136             :             // hide drawings but not form controls (form controls are handled elsewhere)
     137           2 :             SdrView &rSdrView = const_cast< SdrView & >(GetPageView()->GetView());
     138           2 :             rSdrView.setHideDraw( !pPrintData->IsPrintDraw() );
     139             :         }
     140       18572 :         GetPageView()->DrawLayer( _nLayerID, pOutDev, pRedirector, aPaintRect.SVRect() );
     141       18572 :         pOutDev->Pop();
     142             : 
     143             :         // reset background color of the outliner & default horiz. text dir.
     144       27858 :         if ( (_nLayerID == pIDDMA->GetHellId()) ||
     145        9286 :              (_nLayerID == pIDDMA->GetHeavenId()) )
     146             :         {
     147       18572 :             GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( aOldOutlinerBackgrdColor );
     148       18572 :             GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aOldEEHoriTextDir );
     149             :         }
     150             : 
     151       18572 :         pOutDev->SetDrawMode( nOldDrawMode );
     152             :     }
     153       18572 : }
     154             : 
     155             : #define FUZZY_EDGE 400
     156             : 
     157           0 : bool SwViewShellImp::IsDragPossible( const Point &rPoint )
     158             : {
     159           0 :     if ( !HasDrawView() )
     160           0 :         return false;
     161             : 
     162           0 :     const SdrMarkList &rMrkList = GetDrawView()->GetMarkedObjectList();
     163             : 
     164           0 :     if( !rMrkList.GetMarkCount() )
     165           0 :         return false;
     166             : 
     167           0 :     SdrObject *pO = rMrkList.GetMark(rMrkList.GetMarkCount()-1)->GetMarkedSdrObj();
     168             : 
     169           0 :     SwRect aRect;
     170           0 :     if( pO && ::CalcClipRect( pO, aRect, false ) )
     171             :     {
     172           0 :         SwRect aTmp;
     173           0 :         ::CalcClipRect( pO, aTmp, true );
     174           0 :         aRect.Union( aTmp );
     175             :     }
     176             :     else
     177           0 :         aRect = GetShell()->GetLayout()->Frm();
     178             : 
     179           0 :     aRect.Top(    aRect.Top()    - FUZZY_EDGE );
     180           0 :     aRect.Bottom( aRect.Bottom() + FUZZY_EDGE );
     181           0 :     aRect.Left(   aRect.Left()   - FUZZY_EDGE );
     182           0 :     aRect.Right(  aRect.Right()  + FUZZY_EDGE );
     183           0 :     return aRect.IsInside( rPoint );
     184             : }
     185             : 
     186        5313 : void SwViewShellImp::NotifySizeChg( const Size &rNewSz )
     187             : {
     188        5313 :     if ( !HasDrawView() )
     189        9337 :         return;
     190             : 
     191        1024 :     if ( GetPageView() )
     192        1024 :         GetPageView()->GetPage()->SetSize( rNewSz );
     193             : 
     194             :     // Limitation of the work area
     195        1024 :     const Rectangle aDocRect( Point( DOCUMENTBORDER, DOCUMENTBORDER ), rNewSz );
     196        1024 :     const Rectangle &rOldWork = GetDrawView()->GetWorkArea();
     197        1024 :     bool bCheckDrawObjs = false;
     198        1024 :     if ( aDocRect != rOldWork )
     199             :     {
     200         908 :         if ( rOldWork.Bottom() > aDocRect.Bottom() || rOldWork.Right() > aDocRect.Right())
     201         265 :             bCheckDrawObjs = true;
     202         908 :         GetDrawView()->SetWorkArea( aDocRect );
     203             :     }
     204        1024 :     if ( !bCheckDrawObjs )
     205         759 :         return;
     206             : 
     207             :     OSL_ENSURE( pSh->getIDocumentDrawModelAccess()->GetDrawModel(), "NotifySizeChg without DrawModel" );
     208         265 :     SdrPage* pPage = pSh->getIDocumentDrawModelAccess()->GetDrawModel()->GetPage( 0 );
     209         265 :     const size_t nObjs = pPage->GetObjCount();
     210        2783 :     for( size_t nObj = 0; nObj < nObjs; ++nObj )
     211             :     {
     212        2518 :         SdrObject *pObj = pPage->GetObj( nObj );
     213        2518 :         if( !pObj->ISA(SwVirtFlyDrawObj) )
     214             :         {
     215             :             // Objects not anchored to the frame, do not need to be adjusted
     216         828 :             const SwContact *pCont = GetUserCall(pObj);
     217             :             // this function might be called by the InsertDocument, when
     218             :             // a PageDesc-Attribute is set on a node. Then the SdrObject
     219             :             // must not have an UserCall.
     220         828 :             if( !pCont || !pCont->ISA(SwDrawContact) )
     221         827 :                 continue;
     222             : 
     223         760 :             const SwFrm *pAnchor = static_cast<const SwDrawContact*>(pCont)->GetAnchorFrm();
     224        2223 :             if ( !pAnchor || pAnchor->IsInFly() || !pAnchor->IsValid() ||
     225        2915 :                  !pAnchor->GetUpper() || !pAnchor->FindPageFrm() ||
     226         718 :                  (FLY_AS_CHAR == pCont->GetFormat()->GetAnchor().GetAnchorId()) )
     227             :             {
     228          87 :                 continue;
     229             :             }
     230             :             else
     231             :             {
     232             :                 // Actually this should never happen but currently layouting
     233             :                 // is broken. So don't move anchors, if the page is invalid.
     234             :                 // This should be turned into an DBG_ASSERT, once layouting is fixed!
     235         673 :                 const SwPageFrm *pPageFrm = pAnchor->FindPageFrm();
     236         673 :                 if (!pPageFrm || pPageFrm->IsInvalid() ) {
     237             :                     SAL_WARN( "sw.resizeview", "Trying to move anchor from invalid page - fix layouting!" );
     238          20 :                     continue;
     239             :                 }
     240             :             }
     241             : 
     242             :             // no move for drawing objects in header/footer
     243         653 :             if ( pAnchor->FindFooterOrHeader() )
     244             :             {
     245         584 :                 continue;
     246             :             }
     247             : 
     248          69 :             const Rectangle aObjBound( pObj->GetCurrentBoundRect() );
     249          69 :             if ( !aDocRect.IsInside( aObjBound ) )
     250             :             {
     251           9 :                 Size aSz;
     252           9 :                 if ( aObjBound.Left() > aDocRect.Right() )
     253           0 :                     aSz.Width() = (aDocRect.Right() - aObjBound.Left()) - MINFLY;
     254           9 :                 if ( aObjBound.Top() > aDocRect.Bottom() )
     255           0 :                     aSz.Height() = (aDocRect.Bottom() - aObjBound.Top()) - MINFLY;
     256           9 :                 if ( aSz.Width() || aSz.Height() )
     257           0 :                     pObj->Move( aSz );
     258             : 
     259             :                 // Don't let large objects disappear to the top
     260           9 :                 aSz.Width() = aSz.Height() = 0;
     261           9 :                 if ( aObjBound.Right() < aDocRect.Left() )
     262           0 :                     aSz.Width() = (aDocRect.Left() - aObjBound.Right()) + MINFLY;
     263           9 :                 if ( aObjBound.Bottom() < aDocRect.Top() )
     264           0 :                     aSz.Height() = (aDocRect.Top() - aObjBound.Bottom()) + MINFLY;
     265           9 :                 if ( aSz.Width() || aSz.Height() )
     266           0 :                     pObj->Move( aSz );
     267             :             }
     268             :         }
     269             :     }
     270         177 : }
     271             : 
     272             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11