LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewobjectcontactofgraphic.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 93 0.0 %
Date: 2014-04-14 Functions: 0 13 0.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 <svx/sdr/contact/viewobjectcontactofgraphic.hxx>
      21             : #include <svx/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           0 :         bool ViewObjectContactOfGraphic::impPrepareGraphicWithAsynchroniousLoading()
      77             :         {
      78           0 :             bool bRetval(false);
      79           0 :             SdrGrafObj& rGrafObj = getSdrGrafObj();
      80             : 
      81           0 :             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           0 :                 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           0 :             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 :         SdrGrafObj& ViewObjectContactOfGraphic::getSdrGrafObj()
     234             :         {
     235           0 :             return static_cast< ViewContactOfGraphic& >(GetViewContact()).GetGrafObject();
     236             :         }
     237             : 
     238           0 :         drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfGraphic::createPrimitive2DSequence(const DisplayInfo& rDisplayInfo) const
     239             :         {
     240             :             // prepare primitive generation with evtl. loading the graphic when it's swapped out
     241           0 :             SdrGrafObj& rGrafObj = const_cast< ViewObjectContactOfGraphic* >(this)->getSdrGrafObj();
     242           0 :             bool bDoAsynchronGraphicLoading(rGrafObj.GetModel() && rGrafObj.GetModel()->IsSwapGraphics());
     243           0 :             bool bSwapInDone(false);
     244           0 :             bool bSwapInExclusive(false);
     245             : 
     246           0 :             if( bDoAsynchronGraphicLoading && rGrafObj.IsSwappedOut() )
     247             :             {
     248             :                 // sometimes it is needed that each graphic is completely available and swapped in
     249             :                 // for these cases a ForceSwapIn is called later at the graphic object
     250           0 :                 if ( rGrafObj.GetPage() && rGrafObj.GetPage()->IsMasterPage() )
     251             :                 {
     252             :                     // #i102380# force Swap-In for GraphicObjects on MasterPage to have a nicer visualisation
     253           0 :                     bDoAsynchronGraphicLoading = false;
     254             :                 }
     255           0 :                 else if ( GetObjectContact().isOutputToPrinter()
     256           0 :                     || GetObjectContact().isOutputToRecordingMetaFile()
     257           0 :                     || GetObjectContact().isOutputToPDFFile() )
     258             :                 {
     259           0 :                     bDoAsynchronGraphicLoading = false;
     260           0 :                     bSwapInExclusive = true;
     261             :                 }
     262             :             }
     263           0 :             if( bDoAsynchronGraphicLoading )
     264             :             {
     265           0 :                 bSwapInDone = const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithAsynchroniousLoading();
     266             :             }
     267             :             else
     268             :             {
     269           0 :                 bSwapInDone = const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithSynchroniousLoading();
     270             :             }
     271             : 
     272             :             // get return value by calling parent
     273           0 :             drawinglayer::primitive2d::Primitive2DSequence xRetval = ViewObjectContactOfSdrObj::createPrimitive2DSequence(rDisplayInfo);
     274             : 
     275           0 :             if(xRetval.hasElements())
     276             :             {
     277             :                 // #i103255# suppress when graphic needs draft visualisation and output
     278             :                 // is for PDF export/Printer
     279           0 :                 const ViewContactOfGraphic& rVCOfGraphic = static_cast< const ViewContactOfGraphic& >(GetViewContact());
     280             : 
     281           0 :                 if(rVCOfGraphic.visualisationUsesDraft())
     282             :                 {
     283           0 :                     const ObjectContact& rObjectContact = GetObjectContact();
     284             : 
     285           0 :                     if(rObjectContact.isOutputToPDFFile() || rObjectContact.isOutputToPrinter())
     286             :                     {
     287           0 :                         xRetval = drawinglayer::primitive2d::Primitive2DSequence();
     288             :                     }
     289             :                 }
     290             :             }
     291             : 
     292             :             // if swap in was forced only for printing metafile and pdf, swap out again
     293           0 :             if( bSwapInDone && bSwapInExclusive )
     294             :             {
     295           0 :                 rGrafObj.ForceSwapOut();
     296             :             }
     297             : 
     298           0 :             return xRetval;
     299             :         }
     300             : 
     301           0 :         ViewObjectContactOfGraphic::ViewObjectContactOfGraphic(ObjectContact& rObjectContact, ViewContact& rViewContact)
     302             :         :   ViewObjectContactOfSdrObj(rObjectContact, rViewContact),
     303           0 :             mpAsynchLoadEvent(0)
     304             :         {
     305           0 :         }
     306             : 
     307           0 :         ViewObjectContactOfGraphic::~ViewObjectContactOfGraphic()
     308             :         {
     309             :             // evtl. delete the asynch loading event
     310           0 :             if(mpAsynchLoadEvent)
     311             :             {
     312             :                 // just delete it, this will remove it from the EventHandler and
     313             :                 // will trigger forgetAsynchGraphicLoadingEvent from the destructor
     314           0 :                 delete mpAsynchLoadEvent;
     315             :             }
     316           0 :         }
     317             :     } // end of namespace contact
     318             : } // end of namespace sdr
     319             : 
     320             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10