LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewobjectcontactofgraphic.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 70 93 75.3 %
Date: 2015-06-13 12:38:46 Functions: 13 16 81.2 %
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           6 :         AsynchGraphicLoadingEvent::AsynchGraphicLoadingEvent(
      50             :             EventHandler& rEventHandler, sdr::contact::ViewObjectContactOfGraphic& rVOCOfGraphic)
      51             :         :   BaseEvent(rEventHandler),
      52           6 :             mrVOCOfGraphic(rVOCOfGraphic)
      53             :         {
      54           6 :         }
      55             : 
      56          18 :         AsynchGraphicLoadingEvent::~AsynchGraphicLoadingEvent()
      57             :         {
      58           6 :             mrVOCOfGraphic.forgetAsynchGraphicLoadingEvent(this);
      59          12 :         }
      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         197 :         bool ViewObjectContactOfGraphic::impPrepareGraphicWithAsynchroniousLoading()
      77             :         {
      78         197 :             bool bRetval(false);
      79         197 :             SdrGrafObj& rGrafObj = getSdrGrafObj();
      80             : 
      81         197 :             if(rGrafObj.IsSwappedOut())
      82             :             {
      83           6 :                 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           6 :                     bool bSwapInAsynchronious(false);
      92           6 :                     ObjectContact& rObjectContact = GetObjectContact();
      93             : 
      94             :                     // only when allowed from configuration
      95           6 :                     if(rObjectContact.IsAsynchronGraphicsLoadingAllowed())
      96             :                     {
      97             :                         // direct output or vdev output (PageView buffering)
      98           6 :                         if(rObjectContact.isOutputToWindow() || rObjectContact.isOutputToVirtualDevice())
      99             :                         {
     100             :                             // only when no metafile recording
     101           6 :                             if(!rObjectContact.isOutputToRecordingMetaFile())
     102             :                             {
     103             :                                 // allow asynchronious loading
     104           6 :                                 bSwapInAsynchronious = true;
     105             :                             }
     106             :                         }
     107             :                     }
     108             : 
     109           6 :                     if(bSwapInAsynchronious)
     110             :                     {
     111             :                         // maybe it's on the way, then do nothing
     112           6 :                         if(!mpAsynchLoadEvent)
     113             :                         {
     114             :                             // Trigger asynchronious SwapIn.
     115           6 :                             sdr::event::TimerEventHandler& rEventHandler = rObjectContact.GetEventHandler();
     116             : 
     117           6 :                             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             :                         // Invalidate paint areas.
     138           0 :                         GetViewContact().ActionChanged();
     139             : 
     140           0 :                         bRetval = true;
     141             :                     }
     142             :                 }
     143             :             }
     144             :             else
     145             :             {
     146             :                 // it is not swapped out, somehow it was loaded. In that case, forget
     147             :                 // about an existing triggered event
     148         191 :                 if(mpAsynchLoadEvent)
     149             :                 {
     150             :                     // just delete it, this will remove it from the EventHandler and
     151             :                     // will trigger forgetAsynchGraphicLoadingEvent from the destructor
     152           6 :                     delete mpAsynchLoadEvent;
     153             :                 }
     154             :             }
     155             : 
     156         197 :             return bRetval;
     157             :         }
     158             : 
     159             :         // Test graphics state and eventually trigger a SwapIn event. Return value
     160             :         // gives info if SwapIn was triggered or not
     161           3 :         bool ViewObjectContactOfGraphic::impPrepareGraphicWithSynchroniousLoading()
     162             :         {
     163           3 :             bool bRetval(false);
     164           3 :             SdrGrafObj& rGrafObj = getSdrGrafObj();
     165             : 
     166           3 :             if(rGrafObj.IsSwappedOut())
     167             :             {
     168           3 :                 if(rGrafObj.IsLinkedGraphic())
     169             :                 {
     170             :                     // update graphic link
     171           1 :                     rGrafObj.ImpUpdateGraphicLink( false );
     172             :                 }
     173             :                 else
     174             :                 {
     175           2 :                     ObjectContact& rObjectContact = GetObjectContact();
     176             : 
     177           2 :                     if(rObjectContact.isOutputToPrinter() || rObjectContact.isOutputToPDFFile())
     178             :                     {
     179             :                         // #i76395# preview mechanism is only active if
     180             :                         // swapin is called from inside paint preparation, so mbInsidePaint
     181             :                         // has to be false to be able to print with high resolution
     182           0 :                         rGrafObj.ForceSwapIn();
     183             :                     }
     184             :                     else
     185             :                     {
     186             :                         // SwapIn direct
     187           2 :                         rGrafObj.mbInsidePaint = true;
     188           2 :                         rGrafObj.ForceSwapIn();
     189           2 :                         rGrafObj.mbInsidePaint = false;
     190             :                     }
     191             : 
     192             :                     // Invalidate paint areas.
     193           2 :                     GetViewContact().ActionChanged();
     194             : 
     195           2 :                     bRetval = true;
     196             :                 }
     197             :             }
     198             : 
     199           3 :             return bRetval;
     200             :         }
     201             : 
     202             :         // This is the call from the asynch graphic loading. This may only be called from
     203             :         // AsynchGraphicLoadingEvent::ExecuteEvent(). Do load the graphics. The event will
     204             :         // be deleted (consumed) and forgetAsynchGraphicLoadingEvent will be called.
     205           0 :         void ViewObjectContactOfGraphic::doAsynchGraphicLoading()
     206             :         {
     207             :             DBG_ASSERT(mpAsynchLoadEvent, "ViewObjectContactOfGraphic::doAsynchGraphicLoading: I did not trigger a event, why am i called (?)");
     208             : 
     209             :             // swap it in
     210           0 :             SdrGrafObj& rGrafObj = getSdrGrafObj();
     211           0 :             rGrafObj.ForceSwapIn();
     212             : 
     213             :             // #i103720# forget event to avoid possible deletion by the following ActionChanged call
     214             :             // which may use createPrimitive2DSequence/impPrepareGraphicWithAsynchroniousLoading again.
     215             :             // Deletion is actally done by the scheduler who leaded to coming here
     216           0 :             mpAsynchLoadEvent = 0;
     217             : 
     218             :             // Invalidate all paint areas and check existing animation (which may have changed).
     219           0 :             GetViewContact().ActionChanged();
     220           0 :         }
     221             : 
     222             :         // This is the call from the destructor of the asynch graphic loading event.
     223             :         // No one else has to call this. It is needed to let this object forget about
     224             :         // the event. The parameter allows checking for the correct event.
     225           6 :         void ViewObjectContactOfGraphic::forgetAsynchGraphicLoadingEvent(sdr::event::AsynchGraphicLoadingEvent* pEvent)
     226             :         {
     227             :             (void) pEvent; // suppress warning
     228             : 
     229           6 :             if(mpAsynchLoadEvent)
     230             :             {
     231             :                 OSL_ENSURE(!pEvent || mpAsynchLoadEvent == pEvent,
     232             :                     "ViewObjectContactOfGraphic::forgetAsynchGraphicLoadingEvent: Forced to forget another event then i have scheduled (?)");
     233             : 
     234             :                 // forget event
     235           6 :                 mpAsynchLoadEvent = 0;
     236             :             }
     237           6 :         }
     238             : 
     239           0 :         const SdrGrafObj& ViewObjectContactOfGraphic::getSdrGrafObj() const
     240             :         {
     241           0 :             return static_cast<const ViewContactOfGraphic& >(GetViewContact()).GetGrafObject();
     242             :         }
     243             : 
     244         400 :         SdrGrafObj& ViewObjectContactOfGraphic::getSdrGrafObj()
     245             :         {
     246         400 :             return static_cast<ViewContactOfGraphic& >(GetViewContact()).GetGrafObject();
     247             :         }
     248             : 
     249         200 :         drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfGraphic::createPrimitive2DSequence(const DisplayInfo& rDisplayInfo) const
     250             :         {
     251             :             // prepare primitive generation with evtl. loading the graphic when it's swapped out
     252         200 :             SdrGrafObj& rGrafObj = const_cast< ViewObjectContactOfGraphic* >(this)->getSdrGrafObj();
     253         200 :             bool bDoAsynchronGraphicLoading(rGrafObj.GetModel() && rGrafObj.GetModel()->IsSwapGraphics());
     254             : 
     255         200 :             if( bDoAsynchronGraphicLoading && rGrafObj.IsSwappedOut() )
     256             :             {
     257             :                 // sometimes it is needed that each graphic is completely available and swapped in
     258             :                 // for these cases a ForceSwapIn is called later at the graphic object
     259           9 :                 if ( rGrafObj.GetPage() && rGrafObj.GetPage()->IsMasterPage() )
     260             :                 {
     261             :                     // #i102380# force Swap-In for GraphicObjects on MasterPage to have a nicer visualisation
     262           0 :                     bDoAsynchronGraphicLoading = false;
     263             :                 }
     264          18 :                 else if ( GetObjectContact().isOutputToPrinter()
     265           9 :                     || GetObjectContact().isOutputToRecordingMetaFile()
     266          15 :                     || GetObjectContact().isOutputToPDFFile() )
     267             :                 {
     268           3 :                     bDoAsynchronGraphicLoading = false;
     269             :                 }
     270             :             }
     271         200 :             if( bDoAsynchronGraphicLoading )
     272             :             {
     273         197 :                 const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithAsynchroniousLoading();
     274             :             }
     275             :             else
     276             :             {
     277           3 :                 const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithSynchroniousLoading();
     278             :             }
     279             : 
     280             :             // get return value by calling parent
     281         200 :             drawinglayer::primitive2d::Primitive2DSequence xRetval = ViewObjectContactOfSdrObj::createPrimitive2DSequence(rDisplayInfo);
     282             : 
     283         200 :             if(xRetval.hasElements())
     284             :             {
     285             :                 // #i103255# suppress when graphic needs draft visualisation and output
     286             :                 // is for PDF export/Printer
     287         200 :                 const ViewContactOfGraphic& rVCOfGraphic = static_cast< const ViewContactOfGraphic& >(GetViewContact());
     288             : 
     289         200 :                 if(rVCOfGraphic.visualisationUsesDraft())
     290             :                 {
     291           6 :                     const ObjectContact& rObjectContact = GetObjectContact();
     292             : 
     293           6 :                     if(rObjectContact.isOutputToPDFFile() || rObjectContact.isOutputToPrinter())
     294             :                     {
     295           0 :                         xRetval = drawinglayer::primitive2d::Primitive2DSequence();
     296             :                     }
     297             :                 }
     298             :             }
     299             : 
     300         200 :             return xRetval;
     301             :         }
     302             : 
     303         181 :         ViewObjectContactOfGraphic::ViewObjectContactOfGraphic(ObjectContact& rObjectContact, ViewContact& rViewContact)
     304             :         :   ViewObjectContactOfSdrObj(rObjectContact, rViewContact),
     305         181 :             mpAsynchLoadEvent(0)
     306             :         {
     307         181 :         }
     308             : 
     309         540 :         ViewObjectContactOfGraphic::~ViewObjectContactOfGraphic()
     310             :         {
     311             :             // evtl. delete the asynch loading event
     312         180 :             if(mpAsynchLoadEvent)
     313             :             {
     314             :                 // just delete it, this will remove it from the EventHandler and
     315             :                 // will trigger forgetAsynchGraphicLoadingEvent from the destructor
     316           0 :                 delete mpAsynchLoadEvent;
     317             :             }
     318         360 :         }
     319             :     } // end of namespace contact
     320         435 : } // end of namespace sdr
     321             : 
     322             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11