LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewobjectcontactofgraphic.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 28 93 30.1 %
Date: 2012-08-25 Functions: 6 13 46.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 106 13.2 %

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

Generated by: LCOV version 1.10