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