1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: objectcontactofpageview.cxx,v $
10 * $Revision: 1.20.18.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <svx/sdr/contact/objectcontactofpageview.hxx>
34 #include <svx/sdr/contact/viewobjectcontactofunocontrol.hxx>
35 #include <svx/svdpagv.hxx>
36 #include <svx/svdpage.hxx>
37 #include <svx/sdr/contact/displayinfo.hxx>
38 #include <svx/sdr/contact/viewobjectcontact.hxx>
39 #include <svx/svdview.hxx>
40 #include <svx/sdr/contact/viewcontact.hxx>
41 #include <svx/sdr/animation/objectanimator.hxx>
42 #include <svx/sdr/event/eventhandler.hxx>
43 #include <svx/sdrpagewindow.hxx>
44 #include <sdrpaintwindow.hxx>
45 #include <drawinglayer/processor2d/vclprocessor2d.hxx>
46 #include <basegfx/matrix/b2dhommatrix.hxx>
47 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
48 #include <svx/sdr/contact/objectcontacttools.hxx>
49 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
52 //////////////////////////////////////////////////////////////////////////////
54 using namespace com::sun::star
;
56 //////////////////////////////////////////////////////////////////////////////
62 // internal access to SdrPage of SdrPageView
63 SdrPage
* ObjectContactOfPageView::GetSdrPage() const
65 return GetPageWindow().GetPageView().GetPage();
68 ObjectContactOfPageView::ObjectContactOfPageView(SdrPageWindow
& rPageWindow
)
70 mrPageWindow(rPageWindow
)
72 // init PreviewRenderer flag
73 setPreviewRenderer(((SdrPaintView
&)rPageWindow
.GetPageView().GetView()).IsPreviewRenderer());
80 ObjectContactOfPageView::~ObjectContactOfPageView()
82 // execute missing LazyInvalidates and stop timer
86 // LazyInvalidate request. Take action.
87 void ObjectContactOfPageView::setLazyInvalidate(ViewObjectContact
& /*rVOC*/)
89 // do NOT call parent, but remember that something is to do by
90 // starting the LazyInvalidateTimer
94 // call this to support evtl. preparations for repaint
95 void ObjectContactOfPageView::PrepareProcessDisplay()
99 static bool bInvalidateDuringPaint(true);
101 if(bInvalidateDuringPaint
)
103 // there are still non-triggered LazyInvalidate events, trigger these
109 // From baseclass Timer, the timeout call triggered by te LazyInvalidate mechanism
110 void ObjectContactOfPageView::Timeout()
115 // invalidate all LazyInvalidate VOCs new situations
116 const sal_uInt32
nVOCCount(getViewObjectContactCount());
118 for(sal_uInt32
a(0); a
< nVOCCount
; a
++)
120 ViewObjectContact
* pCandidate
= getViewObjectContact(a
);
121 pCandidate
->triggerLazyInvalidate();
125 // Process the whole displaying
126 void ObjectContactOfPageView::ProcessDisplay(DisplayInfo
& rDisplayInfo
)
128 const SdrPage
* pStartPage
= GetSdrPage();
130 if(pStartPage
&& !rDisplayInfo
.GetProcessLayers().IsEmpty())
132 const ViewContact
& rDrawPageVC
= pStartPage
->GetViewContact();
134 if(rDrawPageVC
.GetObjectCount())
136 DoProcessDisplay(rDisplayInfo
);
140 // after paint take care of the evtl. scheduled asynchronious commands.
141 // Do this by resetting the timer contained there. Thus, after the paint
142 // that timer will be triggered and the events will be executed.
143 if(HasEventHandler())
145 sdr::event::TimerEventHandler
& rEventHandler
= GetEventHandler();
147 if(!rEventHandler
.IsEmpty())
149 rEventHandler
.Restart();
154 // Process the whole displaying. Only use given DsiplayInfo, do not access other
155 // OutputDevices then the given ones.
156 void ObjectContactOfPageView::DoProcessDisplay(DisplayInfo
& rDisplayInfo
)
158 // visualize entered group when that feature is switched on and it's not
159 // a print output. #i29129# No ghosted display for printing.
160 sal_Bool
bVisualizeEnteredGroup(DoVisualizeEnteredGroup() && !isOutputToPrinter());
162 // Visualize entered groups: Set to ghosted as default
163 // start. Do this only for the DrawPage, not for MasterPages
164 if(bVisualizeEnteredGroup
)
166 rDisplayInfo
.SetGhostedDrawMode();
169 // #114359# save old and set clip region
170 OutputDevice
* pOutDev
= TryToGetOutputDevice();
171 OSL_ENSURE(0 != pOutDev
, "ObjectContactOfPageView without OutDev, someone has overloaded TryToGetOutputDevice wrong (!)");
172 sal_Bool
bClipRegionPushed(sal_False
);
173 const Region
& rRedrawArea(rDisplayInfo
.GetRedrawArea());
175 if(!rRedrawArea
.IsEmpty())
177 bClipRegionPushed
= sal_True
;
178 pOutDev
->Push(PUSH_CLIPREGION
);
179 pOutDev
->IntersectClipRegion(rRedrawArea
);
182 // Get start node and process DrawPage contents
183 const ViewObjectContact
& rDrawPageVOContact
= GetSdrPage()->GetViewContact().GetViewObjectContact(*this);
185 // update current ViewInformation2D at the ObjectContact
186 const double fCurrentTime(getPrimitiveAnimator().GetTime());
187 OutputDevice
& rTargetOutDev
= GetPageWindow().GetPaintWindow().GetTargetOutputDevice();
188 basegfx::B2DRange aViewRange
;
191 if(isOutputToRecordingMetaFile())
193 if(isOutputToPDFFile() || isOutputToPrinter())
195 // #i98402# if it's a PDF export, set the ClipRegion as ViewRange. This is
196 // mainly because SW does not use DrawingLayer Page-Oriented and if not doing this,
197 // all existing objects will be collected as primitives and processed.
198 // OD 2009-03-05 #i99876# perform the same also for SW on printing.
199 const Rectangle
aLogicClipRectangle(rDisplayInfo
.GetRedrawArea().GetBoundRect());
201 aViewRange
= basegfx::B2DRange(
202 aLogicClipRectangle
.Left(), aLogicClipRectangle
.Top(),
203 aLogicClipRectangle
.Right(), aLogicClipRectangle
.Bottom());
208 // use visible pixels, but transform to world coordinates
209 const Size
aOutputSizePixel(rTargetOutDev
.GetOutputSizePixel());
210 aViewRange
= basegfx::B2DRange(0.0, 0.0, aOutputSizePixel
.getWidth(), aOutputSizePixel
.getHeight());
212 // if a clip region is set, use it
213 if(!rDisplayInfo
.GetRedrawArea().IsEmpty())
215 // get logic clip range and create discrete one
216 const Rectangle
aLogicClipRectangle(rDisplayInfo
.GetRedrawArea().GetBoundRect());
217 basegfx::B2DRange
aLogicClipRange(
218 aLogicClipRectangle
.Left(), aLogicClipRectangle
.Top(),
219 aLogicClipRectangle
.Right(), aLogicClipRectangle
.Bottom());
220 basegfx::B2DRange
aDiscreteClipRange(aLogicClipRange
);
221 aDiscreteClipRange
.transform(rTargetOutDev
.GetViewTransformation());
223 // align the discrete one to discrete boundaries (pixel bounds). Also
224 // expand X and Y max by one due to Rectangle definition source
225 aDiscreteClipRange
.expand(basegfx::B2DTuple(
226 floor(aDiscreteClipRange
.getMinX()),
227 floor(aDiscreteClipRange
.getMinY())));
228 aDiscreteClipRange
.expand(basegfx::B2DTuple(
229 1.0 + ceil(aDiscreteClipRange
.getMaxX()),
230 1.0 + ceil(aDiscreteClipRange
.getMaxY())));
232 // intersect current ViewRange with ClipRange
233 aViewRange
.intersect(aDiscreteClipRange
);
236 // transform to world coordinates
237 aViewRange
.transform(rTargetOutDev
.GetInverseViewTransformation());
240 // update local ViewInformation2D
241 const drawinglayer::geometry::ViewInformation2D
aNewViewInformation2D(
242 basegfx::B2DHomMatrix(),
243 rTargetOutDev
.GetViewTransformation(),
245 GetXDrawPageForSdrPage(GetSdrPage()),
248 updateViewInformation2D(aNewViewInformation2D
);
250 // get whole Primitive2DSequence; this will already make use of updated ViewInformation2D
251 // and may use the MapMode from the Target OutDev in the DisplayInfo
252 drawinglayer::primitive2d::Primitive2DSequence
xPrimitiveSequence(rDrawPageVOContact
.getPrimitive2DSequenceHierarchy(rDisplayInfo
));
254 // if there is something to show, use a primitive processor to render it. There
255 // is a choice between VCL and Canvas processors currently. The decision is made in
256 // createBaseProcessor2DFromOutputDevice and takes into accout things like the
257 // Target is a MetaFile, a VDev or something else. The Canvas renderer is triggered
258 // currently using the shown boolean. Canvas is not yet the default.
259 if(xPrimitiveSequence
.hasElements())
261 // prepare OutputDevice (historical stuff, maybe soon removed)
262 rDisplayInfo
.ClearGhostedDrawMode(); // reset, else the VCL-paint with the processor will not do the right thing
263 pOutDev
->SetLayoutMode(0); // reset, default is no BiDi/RTL
266 drawinglayer::processor2d::BaseProcessor2D
* pProcessor2D
= createBaseProcessor2DFromOutputDevice(
267 rTargetOutDev
, getViewInformation2D());
271 pProcessor2D
->process(xPrimitiveSequence
);
276 // #114359# restore old ClipReghion
277 if(bClipRegionPushed
)
282 // Visualize entered groups: Reset to original DrawMode
283 if(bVisualizeEnteredGroup
)
285 rDisplayInfo
.ClearGhostedDrawMode();
289 // test if visualizing of entered groups is switched on at all
290 bool ObjectContactOfPageView::DoVisualizeEnteredGroup() const
292 SdrView
& rView
= GetPageWindow().GetPageView().GetView();
293 return rView
.DoVisualizeEnteredGroup();
296 // get active group's (the entered group) ViewContact
297 const ViewContact
* ObjectContactOfPageView::getActiveViewContact() const
299 SdrObjList
* pActiveGroupList
= GetPageWindow().GetPageView().GetObjList();
303 if(pActiveGroupList
->ISA(SdrPage
))
305 // It's a Page itself
306 return &(((SdrPage
*)pActiveGroupList
)->GetViewContact());
308 else if(pActiveGroupList
->GetOwnerObj())
311 return &(pActiveGroupList
->GetOwnerObj()->GetViewContact());
314 else if(GetSdrPage())
316 // use page of associated SdrPageView
317 return &(GetSdrPage()->GetViewContact());
323 // Invalidate given rectangle at the window/output which is represented by
324 // this ObjectContact.
325 void ObjectContactOfPageView::InvalidatePartOfView(const basegfx::B2DRange
& rRange
) const
327 // invalidate at associated PageWindow
328 GetPageWindow().InvalidatePageWindow(rRange
);
331 // Get info if given Rectangle is visible in this view
332 bool ObjectContactOfPageView::IsAreaVisible(const basegfx::B2DRange
& rRange
) const
334 // compare with the visible rectangle
337 // no range -> not visible
342 const OutputDevice
& rTargetOutDev
= GetPageWindow().GetPaintWindow().GetTargetOutputDevice();
343 const Size
aOutputSizePixel(rTargetOutDev
.GetOutputSizePixel());
344 basegfx::B2DRange
aLogicViewRange(0.0, 0.0, aOutputSizePixel
.getWidth(), aOutputSizePixel
.getHeight());
346 aLogicViewRange
.transform(rTargetOutDev
.GetInverseViewTransformation());
348 if(!aLogicViewRange
.isEmpty() && !aLogicViewRange
.overlaps(rRange
))
355 return ObjectContact::IsAreaVisible(rRange
);
358 // Get info about the need to visualize GluePoints
359 bool ObjectContactOfPageView::AreGluePointsVisible() const
361 return GetPageWindow().GetPageView().GetView().ImpIsGlueVisible();
364 // check if text animation is allowed.
365 bool ObjectContactOfPageView::IsTextAnimationAllowed() const
367 SdrView
& rView
= GetPageWindow().GetPageView().GetView();
368 const SvtAccessibilityOptions
& rOpt
= rView
.getAccessibilityOptions();
369 return rOpt
.GetIsAllowAnimatedText();
372 // check if graphic animation is allowed.
373 bool ObjectContactOfPageView::IsGraphicAnimationAllowed() const
375 SdrView
& rView
= GetPageWindow().GetPageView().GetView();
376 const SvtAccessibilityOptions
& rOpt
= rView
.getAccessibilityOptions();
377 return rOpt
.GetIsAllowAnimatedGraphics();
380 // check if asynchronious graphis loading is allowed. Default is sal_False.
381 bool ObjectContactOfPageView::IsAsynchronGraphicsLoadingAllowed() const
383 SdrView
& rView
= GetPageWindow().GetPageView().GetView();
384 return rView
.IsSwapAsynchron();
387 // check if buffering of MasterPages is allowed. Default is sal_False.
388 bool ObjectContactOfPageView::IsMasterPageBufferingAllowed() const
390 SdrView
& rView
= GetPageWindow().GetPageView().GetView();
391 return rView
.IsMasterPagePaintCaching();
395 bool ObjectContactOfPageView::isOutputToPrinter() const
397 return (OUTDEV_PRINTER
== mrPageWindow
.GetPaintWindow().GetOutputDevice().GetOutDevType());
401 bool ObjectContactOfPageView::isOutputToWindow() const
403 return (OUTDEV_WINDOW
== mrPageWindow
.GetPaintWindow().GetOutputDevice().GetOutDevType());
407 bool ObjectContactOfPageView::isOutputToVirtualDevice() const
409 return (OUTDEV_VIRDEV
== mrPageWindow
.GetPaintWindow().GetOutputDevice().GetOutDevType());
412 // recording MetaFile?
413 bool ObjectContactOfPageView::isOutputToRecordingMetaFile() const
415 GDIMetaFile
* pMetaFile
= mrPageWindow
.GetPaintWindow().GetOutputDevice().GetConnectMetaFile();
416 return (pMetaFile
&& pMetaFile
->IsRecord() && !pMetaFile
->IsPause());
420 bool ObjectContactOfPageView::isOutputToPDFFile() const
422 return (0 != mrPageWindow
.GetPaintWindow().GetOutputDevice().GetPDFWriter());
426 bool ObjectContactOfPageView::isDrawModeGray() const
428 const sal_uInt32
nDrawMode(mrPageWindow
.GetPaintWindow().GetOutputDevice().GetDrawMode());
429 return (nDrawMode
== (DRAWMODE_GRAYLINE
|DRAWMODE_GRAYFILL
|DRAWMODE_BLACKTEXT
|DRAWMODE_GRAYBITMAP
|DRAWMODE_GRAYGRADIENT
));
433 bool ObjectContactOfPageView::isDrawModeBlackWhite() const
435 const sal_uInt32
nDrawMode(mrPageWindow
.GetPaintWindow().GetOutputDevice().GetDrawMode());
436 return (nDrawMode
== (DRAWMODE_BLACKLINE
|DRAWMODE_BLACKTEXT
|DRAWMODE_WHITEFILL
|DRAWMODE_GRAYBITMAP
|DRAWMODE_WHITEGRADIENT
));
439 // high contrast display mode
440 bool ObjectContactOfPageView::isDrawModeHighContrast() const
442 const sal_uInt32
nDrawMode(mrPageWindow
.GetPaintWindow().GetOutputDevice().GetDrawMode());
443 return (nDrawMode
== (DRAWMODE_SETTINGSLINE
|DRAWMODE_SETTINGSFILL
|DRAWMODE_SETTINGSTEXT
|DRAWMODE_SETTINGSGRADIENT
));
446 // access to SdrPageView
447 SdrPageView
* ObjectContactOfPageView::TryToGetSdrPageView() const
449 return &(mrPageWindow
.GetPageView());
453 // access to OutputDevice
454 OutputDevice
* ObjectContactOfPageView::TryToGetOutputDevice() const
456 SdrPreRenderDevice
* pPreRenderDevice
= mrPageWindow
.GetPaintWindow().GetPreRenderDevice();
460 return &(pPreRenderDevice
->GetPreRenderDevice());
464 return &(mrPageWindow
.GetPaintWindow().GetOutputDevice());
468 // set all UNO controls displayed in the view to design/alive mode
469 void ObjectContactOfPageView::SetUNOControlsDesignMode( bool _bDesignMode
) const
471 const sal_uInt32
nCount(getViewObjectContactCount());
473 for(sal_uInt32
a(0); a
< nCount
; a
++)
475 const ViewObjectContact
* pVOC
= getViewObjectContact(a
);
476 const ViewObjectContactOfUnoControl
* pUnoObjectVOC
= dynamic_cast< const ViewObjectContactOfUnoControl
* >(pVOC
);
480 pUnoObjectVOC
->setControlDesignMode(_bDesignMode
);
484 } // end of namespace contact
485 } // end of namespace sdr
487 //////////////////////////////////////////////////////////////////////////////