LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewobjectcontactofgraphic.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 29 96 30.2 %
Date: 2014-11-03 Functions: 8 16 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sdr/contact/viewobjectcontactofgraphic.hxx>
      21             : #include <sdr/contact/viewcontactofgraphic.hxx>
      22             : #include <svx/svdograf.hxx>
      23             : #include <svx/sdr/contact/objectcontact.hxx>
      24             : #include <svx/svdmodel.hxx>
      25             : #include <svx/svdpage.hxx>
      26             : 
      27             : #include "eventhandler.hxx"
      28             : 
      29             : namespace sdr
      30             : {
      31             :     namespace event
      32             :     {
      33             :         class AsynchGraphicLoadingEvent : public BaseEvent
      34             :         {
      35             :             // the ViewContactOfGraphic to work with
      36             :             sdr::contact::ViewObjectContactOfGraphic&       mrVOCOfGraphic;
      37             : 
      38             :         public:
      39             :             // basic constructor.
      40             :             AsynchGraphicLoadingEvent(EventHandler& rEventHandler, sdr::contact::ViewObjectContactOfGraphic& rVOCOfGraphic);
      41             : 
      42             :             // destructor
      43             :             virtual ~AsynchGraphicLoadingEvent();
      44             : 
      45             :             // the called method if the event is triggered
      46             :             virtual void ExecuteEvent() SAL_OVERRIDE;
      47             :         };
      48             : 
      49           0 :         AsynchGraphicLoadingEvent::AsynchGraphicLoadingEvent(
      50             :             EventHandler& rEventHandler, sdr::contact::ViewObjectContactOfGraphic& rVOCOfGraphic)
      51             :         :   BaseEvent(rEventHandler),
      52           0 :             mrVOCOfGraphic(rVOCOfGraphic)
      53             :         {
      54           0 :         }
      55             : 
      56           0 :         AsynchGraphicLoadingEvent::~AsynchGraphicLoadingEvent()
      57             :         {
      58           0 :             mrVOCOfGraphic.forgetAsynchGraphicLoadingEvent(this);
      59           0 :         }
      60             : 
      61           0 :         void AsynchGraphicLoadingEvent::ExecuteEvent()
      62             :         {
      63           0 :             mrVOCOfGraphic.doAsynchGraphicLoading();
      64           0 :         }
      65             :     } // end of namespace event
      66             : } // end of namespace sdr
      67             : 
      68             : 
      69             : 
      70             : namespace sdr
      71             : {
      72             :     namespace contact
      73             :     {
      74             :         // Test graphics state and eventually trigger a SwapIn event or an Asynchronous
      75             :         // load event. Return value gives info if SwapIn was triggered or not
      76         346 :         bool ViewObjectContactOfGraphic::impPrepareGraphicWithAsynchroniousLoading()
      77             :         {
      78         346 :             bool bRetval(false);
      79         346 :             SdrGrafObj& rGrafObj = getSdrGrafObj();
      80             : 
      81         346 :             if(rGrafObj.IsSwappedOut())
      82             :             {
      83           0 :                 if(rGrafObj.IsLinkedGraphic())
      84             :                 {
      85             :                     // update graphic link
      86           0 :                     rGrafObj.ImpUpdateGraphicLink();
      87             :                 }
      88             :                 else
      89             :                 {
      90             :                     // SwapIn needs to be done. Decide if it can be done asynchronious.
      91           0 :                     bool bSwapInAsynchronious(false);
      92           0 :                     ObjectContact& rObjectContact = GetObjectContact();
      93             : 
      94             :                     // only when allowed from configuration
      95           0 :                     if(rObjectContact.IsAsynchronGraphicsLoadingAllowed())
      96             :                     {
      97             :                         // direct output or vdev output (PageView buffering)
      98           0 :                         if(rObjectContact.isOutputToWindow() || rObjectContact.isOutputToVirtualDevice())
      99             :                         {
     100             :                             // only when no metafile recording
     101           0 :                             if(!rObjectContact.isOutputToRecordingMetaFile())
     102             :                             {
     103             :                                 // allow asynchronious loading
     104           0 :                                 bSwapInAsynchronious = true;
     105             :                             }
     106             :                         }
     107             :                     }
     108             : 
     109           0 :                     if(bSwapInAsynchronious)
     110             :                     {
     111             :                         // maybe it's on the way, then do nothing
     112           0 :                         if(!mpAsynchLoadEvent)
     113             :                         {
     114             :                             // Trigger asynchronious SwapIn.
     115           0 :                             sdr::event::TimerEventHandler& rEventHandler = rObjectContact.GetEventHandler();
     116             : 
     117           0 :                             mpAsynchLoadEvent = new sdr::event::AsynchGraphicLoadingEvent(rEventHandler, *this);
     118             :                         }
     119             :                     }
     120             :                     else
     121             :                     {
     122           0 :                         if(rObjectContact.isOutputToPrinter() || rObjectContact.isOutputToPDFFile())
     123             :                         {
     124             :                             // #i76395# preview mechanism is only active if
     125             :                             // swapin is called from inside paint preparation, so mbInsidePaint
     126             :                             // has to be false to be able to print with high resolution
     127           0 :                             rGrafObj.ForceSwapIn();
     128             :                         }
     129             :                         else
     130             :                         {
     131             :                             // SwapIn direct
     132           0 :                             rGrafObj.mbInsidePaint = true;
     133           0 :                             rGrafObj.ForceSwapIn();
     134           0 :                             rGrafObj.mbInsidePaint = false;
     135             :                         }
     136             : 
     137           0 :                         bRetval = true;
     138             :                     }
     139             :                 }
     140             :             }
     141             :             else
     142             :             {
     143             :                 // it is not swapped out, somehow it was loaded. In that case, forget
     144             :                 // about an existing triggered event
     145         346 :                 if(mpAsynchLoadEvent)
     146             :                 {
     147             :                     // just delete it, this will remove it from the EventHandler and
     148             :                     // will trigger forgetAsynchGraphicLoadingEvent from the destructor
     149           0 :                     delete mpAsynchLoadEvent;
     150             :                 }
     151             :             }
     152             : 
     153         346 :             return bRetval;
     154             :         }
     155             : 
     156             :         // Test graphics state and eventually trigger a SwapIn event. Return value
     157             :         // gives info if SwapIn was triggered or not
     158           0 :         bool ViewObjectContactOfGraphic::impPrepareGraphicWithSynchroniousLoading()
     159             :         {
     160           0 :             bool bRetval(false);
     161           0 :             SdrGrafObj& rGrafObj = getSdrGrafObj();
     162             : 
     163           0 :             if(rGrafObj.IsSwappedOut())
     164             :             {
     165           0 :                 if(rGrafObj.IsLinkedGraphic())
     166             :                 {
     167             :                     // update graphic link
     168           0 :                     rGrafObj.ImpUpdateGraphicLink( false );
     169             :                 }
     170             :                 else
     171             :                 {
     172           0 :                     ObjectContact& rObjectContact = GetObjectContact();
     173             : 
     174           0 :                     if(rObjectContact.isOutputToPrinter() || rObjectContact.isOutputToPDFFile())
     175             :                     {
     176             :                         // #i76395# preview mechanism is only active if
     177             :                         // swapin is called from inside paint preparation, so mbInsidePaint
     178             :                         // has to be false to be able to print with high resolution
     179           0 :                         rGrafObj.ForceSwapIn();
     180             :                     }
     181             :                     else
     182             :                     {
     183             :                         // SwapIn direct
     184           0 :                         rGrafObj.mbInsidePaint = true;
     185           0 :                         rGrafObj.ForceSwapIn();
     186           0 :                         rGrafObj.mbInsidePaint = false;
     187             :                     }
     188             : 
     189           0 :                     bRetval = true;
     190             :                 }
     191             :             }
     192             : 
     193           0 :             return bRetval;
     194             :         }
     195             : 
     196             :         // This is the call from the asynch graphic loading. This may only be called from
     197             :         // AsynchGraphicLoadingEvent::ExecuteEvent(). Do load the graphics. The event will
     198             :         // be deleted (consumed) and forgetAsynchGraphicLoadingEvent will be called.
     199           0 :         void ViewObjectContactOfGraphic::doAsynchGraphicLoading()
     200             :         {
     201             :             DBG_ASSERT(mpAsynchLoadEvent, "ViewObjectContactOfGraphic::doAsynchGraphicLoading: I did not trigger a event, why am i called (?)");
     202             : 
     203             :             // swap it in
     204           0 :             SdrGrafObj& rGrafObj = getSdrGrafObj();
     205           0 :             rGrafObj.ForceSwapIn();
     206             : 
     207             :             // #i103720# forget event to avoid possible deletion by the following ActionChanged call
     208             :             // which may use createPrimitive2DSequence/impPrepareGraphicWithAsynchroniousLoading again.
     209             :             // Deletion is actally done by the scheduler who leaded to coming here
     210           0 :             mpAsynchLoadEvent = 0;
     211             : 
     212             :             // Invalidate all paint areas and check existing animation (which may have changed).
     213           0 :             GetViewContact().ActionChanged();
     214           0 :         }
     215             : 
     216             :         // This is the call from the destructor of the asynch graphic loading event.
     217             :         // No one else has to call this. It is needed to let this object forget about
     218             :         // the event. The parameter allows checking for the correct event.
     219           0 :         void ViewObjectContactOfGraphic::forgetAsynchGraphicLoadingEvent(sdr::event::AsynchGraphicLoadingEvent* pEvent)
     220             :         {
     221             :             (void) pEvent; // suppress warning
     222             : 
     223           0 :             if(mpAsynchLoadEvent)
     224             :             {
     225             :                 OSL_ENSURE(!pEvent || mpAsynchLoadEvent == pEvent,
     226             :                     "ViewObjectContactOfGraphic::forgetAsynchGraphicLoadingEvent: Forced to forget another event then i have scheduled (?)");
     227             : 
     228             :                 // forget event
     229           0 :                 mpAsynchLoadEvent = 0;
     230             :             }
     231           0 :         }
     232             : 
     233           0 :         const SdrGrafObj& ViewObjectContactOfGraphic::getSdrGrafObj() const
     234             :         {
     235           0 :             return static_cast<const ViewContactOfGraphic& >(GetViewContact()).GetGrafObject();
     236             :         }
     237             : 
     238         692 :         SdrGrafObj& ViewObjectContactOfGraphic::getSdrGrafObj()
     239             :         {
     240         692 :             return static_cast<ViewContactOfGraphic& >(GetViewContact()).GetGrafObject();
     241             :         }
     242             : 
     243         346 :         drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfGraphic::createPrimitive2DSequence(const DisplayInfo& rDisplayInfo) const
     244             :         {
     245             :             // prepare primitive generation with evtl. loading the graphic when it's swapped out
     246         346 :             SdrGrafObj& rGrafObj = const_cast< ViewObjectContactOfGraphic* >(this)->getSdrGrafObj();
     247         346 :             bool bDoAsynchronGraphicLoading(rGrafObj.GetModel() && rGrafObj.GetModel()->IsSwapGraphics());
     248         346 :             bool bSwapInDone(false);
     249         346 :             bool bSwapInExclusive(false);
     250             : 
     251         346 :             if( bDoAsynchronGraphicLoading && rGrafObj.IsSwappedOut() )
     252             :             {
     253             :                 // sometimes it is needed that each graphic is completely available and swapped in
     254             :                 // for these cases a ForceSwapIn is called later at the graphic object
     255           0 :                 if ( rGrafObj.GetPage() && rGrafObj.GetPage()->IsMasterPage() )
     256             :                 {
     257             :                     // #i102380# force Swap-In for GraphicObjects on MasterPage to have a nicer visualisation
     258           0 :                     bDoAsynchronGraphicLoading = false;
     259             :                 }
     260           0 :                 else if ( GetObjectContact().isOutputToPrinter()
     261           0 :                     || GetObjectContact().isOutputToRecordingMetaFile()
     262           0 :                     || GetObjectContact().isOutputToPDFFile() )
     263             :                 {
     264           0 :                     bDoAsynchronGraphicLoading = false;
     265           0 :                     bSwapInExclusive = true;
     266             :                 }
     267             :             }
     268         346 :             if( bDoAsynchronGraphicLoading )
     269             :             {
     270         346 :                 bSwapInDone = const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithAsynchroniousLoading();
     271             :             }
     272             :             else
     273             :             {
     274           0 :                 bSwapInDone = const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithSynchroniousLoading();
     275             :             }
     276             : 
     277             :             // get return value by calling parent
     278         346 :             drawinglayer::primitive2d::Primitive2DSequence xRetval = ViewObjectContactOfSdrObj::createPrimitive2DSequence(rDisplayInfo);
     279             : 
     280         346 :             if(xRetval.hasElements())
     281             :             {
     282             :                 // #i103255# suppress when graphic needs draft visualisation and output
     283             :                 // is for PDF export/Printer
     284         346 :                 const ViewContactOfGraphic& rVCOfGraphic = static_cast< const ViewContactOfGraphic& >(GetViewContact());
     285             : 
     286         346 :                 if(rVCOfGraphic.visualisationUsesDraft())
     287             :                 {
     288           0 :                     const ObjectContact& rObjectContact = GetObjectContact();
     289             : 
     290           0 :                     if(rObjectContact.isOutputToPDFFile() || rObjectContact.isOutputToPrinter())
     291             :                     {
     292           0 :                         xRetval = drawinglayer::primitive2d::Primitive2DSequence();
     293             :                     }
     294             :                 }
     295             :             }
     296             : 
     297             :             // if swap in was forced only for printing metafile and pdf, swap out again
     298         346 :             if( bSwapInDone && bSwapInExclusive )
     299             :             {
     300           0 :                 rGrafObj.ForceSwapOut();
     301             :             }
     302             : 
     303         346 :             return xRetval;
     304             :         }
     305             : 
     306         318 :         ViewObjectContactOfGraphic::ViewObjectContactOfGraphic(ObjectContact& rObjectContact, ViewContact& rViewContact)
     307             :         :   ViewObjectContactOfSdrObj(rObjectContact, rViewContact),
     308         318 :             mpAsynchLoadEvent(0)
     309             :         {
     310         318 :         }
     311             : 
     312         954 :         ViewObjectContactOfGraphic::~ViewObjectContactOfGraphic()
     313             :         {
     314             :             // evtl. delete the asynch loading event
     315         318 :             if(mpAsynchLoadEvent)
     316             :             {
     317             :                 // just delete it, this will remove it from the EventHandler and
     318             :                 // will trigger forgetAsynchGraphicLoadingEvent from the destructor
     319           0 :                 delete mpAsynchLoadEvent;
     320             :             }
     321         636 :         }
     322             :     } // end of namespace contact
     323         651 : } // end of namespace sdr
     324             : 
     325             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10