Update ooo320-m1
[ooovba.git] / svx / source / sdr / contact / viewobjectcontactofgraphic.cxx
blob276da4a240bf03d07f43865bc96d5aa00622dfe1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewobjectcontactofgraphic.cxx,v $
11 * $Revision: 1.2.18.1 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_svx.hxx"
35 #include <svx/sdr/contact/viewobjectcontactofgraphic.hxx>
36 #include <svx/sdr/contact/viewcontactofgraphic.hxx>
37 #include <svx/sdr/event/eventhandler.hxx>
38 #include <svx/svdograf.hxx>
39 #include <svx/sdr/contact/objectcontact.hxx>
40 #include <svx/svdmodel.hxx>
41 #include <svx/svdpage.hxx>
43 //////////////////////////////////////////////////////////////////////////////
45 namespace sdr
47 namespace event
49 class AsynchGraphicLoadingEvent : public BaseEvent
51 // the ViewContactOfGraphic to work with
52 sdr::contact::ViewObjectContactOfGraphic& mrVOCOfGraphic;
54 public:
55 // basic constructor.
56 AsynchGraphicLoadingEvent(EventHandler& rEventHandler, sdr::contact::ViewObjectContactOfGraphic& rVOCOfGraphic);
58 // destructor
59 virtual ~AsynchGraphicLoadingEvent();
61 // the called method if the event is triggered
62 virtual void ExecuteEvent();
65 AsynchGraphicLoadingEvent::AsynchGraphicLoadingEvent(
66 EventHandler& rEventHandler, sdr::contact::ViewObjectContactOfGraphic& rVOCOfGraphic)
67 : BaseEvent(rEventHandler),
68 mrVOCOfGraphic(rVOCOfGraphic)
72 AsynchGraphicLoadingEvent::~AsynchGraphicLoadingEvent()
74 mrVOCOfGraphic.forgetAsynchGraphicLoadingEvent(this);
77 void AsynchGraphicLoadingEvent::ExecuteEvent()
79 mrVOCOfGraphic.doAsynchGraphicLoading();
81 } // end of namespace event
82 } // end of namespace sdr
84 //////////////////////////////////////////////////////////////////////////////
86 namespace sdr
88 namespace contact
90 // Test graphics state and eventually trigger a SwapIn event or an Asynchronous
91 // load event. Return value gives info if SwapIn was triggered or not
92 bool ViewObjectContactOfGraphic::impPrepareGraphicWithAsynchroniousLoading()
94 bool bRetval(false);
95 SdrGrafObj& rGrafObj = getSdrGrafObj();
97 if(rGrafObj.IsSwappedOut())
99 if(rGrafObj.IsLinkedGraphic())
101 // update graphic link
102 rGrafObj.ImpUpdateGraphicLink();
104 else
106 // SwapIn needs to be done. Decide if it can be done asynchronious.
107 bool bSwapInAsynchronious(false);
108 ObjectContact& rObjectContact = GetObjectContact();
110 // only when allowed from configuration
111 if(rObjectContact.IsAsynchronGraphicsLoadingAllowed())
113 // direct output or vdev output (PageView buffering)
114 if(rObjectContact.isOutputToWindow() || rObjectContact.isOutputToVirtualDevice())
116 // only when no metafile recording
117 if(!rObjectContact.isOutputToRecordingMetaFile())
119 // allow asynchronious loading
120 bSwapInAsynchronious = true;
125 if(bSwapInAsynchronious)
127 // maybe it's on the way, then do nothing
128 if(!mpAsynchLoadEvent)
130 // Trigger asynchronious SwapIn.
131 sdr::event::TimerEventHandler& rEventHandler = rObjectContact.GetEventHandler();
133 mpAsynchLoadEvent = new sdr::event::AsynchGraphicLoadingEvent(rEventHandler, *this);
136 else
138 if(rObjectContact.isOutputToPrinter())
140 // #i76395# preview mechanism is only active if
141 // swapin is called from inside paint preparation, so mbInsidePaint
142 // has to be false to be able to print with high resolution
143 rGrafObj.ForceSwapIn();
145 else
147 // SwapIn direct
148 rGrafObj.mbInsidePaint = sal_True;
149 rGrafObj.ForceSwapIn();
150 rGrafObj.mbInsidePaint = sal_False;
153 bRetval = true;
157 else
159 // it is not swapped out, somehow it was loaded. In that case, forget
160 // about an existing triggered event
161 if(mpAsynchLoadEvent)
163 // just delete it, this will remove it from the EventHandler and
164 // will trigger forgetAsynchGraphicLoadingEvent from the destructor
165 delete mpAsynchLoadEvent;
169 return bRetval;
172 // Test graphics state and eventually trigger a SwapIn event. Return value
173 // gives info if SwapIn was triggered or not
174 bool ViewObjectContactOfGraphic::impPrepareGraphicWithSynchroniousLoading()
176 bool bRetval(false);
177 SdrGrafObj& rGrafObj = getSdrGrafObj();
179 if(rGrafObj.IsSwappedOut())
181 if(rGrafObj.IsLinkedGraphic())
183 // update graphic link
184 rGrafObj.ImpUpdateGraphicLink();
186 else
188 ObjectContact& rObjectContact = GetObjectContact();
190 if(rObjectContact.isOutputToPrinter())
192 // #i76395# preview mechanism is only active if
193 // swapin is called from inside paint preparation, so mbInsidePaint
194 // has to be false to be able to print with high resolution
195 rGrafObj.ForceSwapIn();
197 else
199 // SwapIn direct
200 rGrafObj.mbInsidePaint = sal_True;
201 rGrafObj.ForceSwapIn();
202 rGrafObj.mbInsidePaint = sal_False;
205 bRetval = true;
209 return bRetval;
212 // This is the call from the asynch graphic loading. This may only be called from
213 // AsynchGraphicLoadingEvent::ExecuteEvent(). Do load the graphics. The event will
214 // be deleted (consumed) and forgetAsynchGraphicLoadingEvent will be called.
215 void ViewObjectContactOfGraphic::doAsynchGraphicLoading()
217 DBG_ASSERT(mpAsynchLoadEvent, "ViewObjectContactOfGraphic::doAsynchGraphicLoading: I did not trigger a event, why am i called (?)");
219 // swap it in
220 SdrGrafObj& rGrafObj = getSdrGrafObj();
221 rGrafObj.ForceSwapIn();
223 // #i103720# forget event to avoid possible deletion by the following ActionChanged call
224 // which may use createPrimitive2DSequence/impPrepareGraphicWithAsynchroniousLoading again.
225 // Deletion is actally done by the scheduler who leaded to coming here
226 mpAsynchLoadEvent = 0;
228 // Invalidate all paint areas and check existing animation (which may have changed).
229 GetViewContact().ActionChanged();
232 // This is the call from the destructor of the asynch graphic loading event.
233 // No one else has to call this. It is needed to let this object forget about
234 // the event. The parameter allows checking for the correct event.
235 void ViewObjectContactOfGraphic::forgetAsynchGraphicLoadingEvent(sdr::event::AsynchGraphicLoadingEvent* pEvent)
237 (void) pEvent; // suppress warning
239 if(mpAsynchLoadEvent)
241 OSL_ENSURE(!pEvent || mpAsynchLoadEvent == pEvent,
242 "ViewObjectContactOfGraphic::forgetAsynchGraphicLoadingEvent: Forced to forget another event then i have scheduled (?)");
244 // forget event
245 mpAsynchLoadEvent = 0;
249 SdrGrafObj& ViewObjectContactOfGraphic::getSdrGrafObj()
251 return static_cast< ViewContactOfGraphic& >(GetViewContact()).GetGrafObject();
254 drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfGraphic::createPrimitive2DSequence(const DisplayInfo& rDisplayInfo) const
256 // prepare primitive generation with evtl. loading the graphic when it's swapped out
257 SdrGrafObj& rGrafObj = const_cast< ViewObjectContactOfGraphic* >(this)->getSdrGrafObj();
258 bool bDoAsynchronGraphicLoading(rGrafObj.GetModel() && rGrafObj.GetModel()->IsSwapGraphics());
259 static bool bSuppressAsynchLoading(false);
260 bool bSwapInDone(false);
262 if(bDoAsynchronGraphicLoading
263 && rGrafObj.IsSwappedOut()
264 && rGrafObj.GetPage()
265 && rGrafObj.GetPage()->IsMasterPage())
267 // #i102380# force Swap-In for GraphicObjects on MasterPage to have a nicer visualisation
268 bDoAsynchronGraphicLoading = false;
271 if(bDoAsynchronGraphicLoading && !bSuppressAsynchLoading)
273 bSwapInDone = const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithAsynchroniousLoading();
275 else
277 bSwapInDone = const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithSynchroniousLoading();
280 // get return value by calling parent
281 drawinglayer::primitive2d::Primitive2DSequence xRetval = ViewObjectContactOfSdrObj::createPrimitive2DSequence(rDisplayInfo);
283 if(xRetval.hasElements())
285 // #i103255# suppress when graphic needs draft visualisation and output
286 // is for PDF export/Printer
287 const ViewContactOfGraphic& rVCOfGraphic = static_cast< const ViewContactOfGraphic& >(GetViewContact());
289 if(rVCOfGraphic.visualisationUsesDraft())
291 const ObjectContact& rObjectContact = GetObjectContact();
293 if(rObjectContact.isOutputToPDFFile() || rObjectContact.isOutputToPrinter())
295 xRetval = drawinglayer::primitive2d::Primitive2DSequence();
300 // if swap in was forced only for printing, swap out again
301 const bool bSwapInExclusiveForPrinting(bSwapInDone && GetObjectContact().isOutputToPrinter());
303 if(bSwapInExclusiveForPrinting)
305 rGrafObj.ForceSwapOut();
308 return xRetval;
311 ViewObjectContactOfGraphic::ViewObjectContactOfGraphic(ObjectContact& rObjectContact, ViewContact& rViewContact)
312 : ViewObjectContactOfSdrObj(rObjectContact, rViewContact),
313 mpAsynchLoadEvent(0)
317 ViewObjectContactOfGraphic::~ViewObjectContactOfGraphic()
319 // evtl. delete the asynch loading event
320 if(mpAsynchLoadEvent)
322 // just delete it, this will remove it from the EventHandler and
323 // will trigger forgetAsynchGraphicLoadingEvent from the destructor
324 delete mpAsynchLoadEvent;
327 } // end of namespace contact
328 } // end of namespace sdr
330 //////////////////////////////////////////////////////////////////////////////
331 // eof