bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / sdr / contact / objectcontactofpageview.cxx
blobd53539ffceb8da203b6455a0fddad8409b323e45
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/sdr/contact/objectcontactofpageview.hxx>
21 #include <svx/sdr/contact/viewobjectcontactofunocontrol.hxx>
22 #include <svx/svdpagv.hxx>
23 #include <svx/svdpage.hxx>
24 #include <svx/sdr/contact/displayinfo.hxx>
25 #include <svx/sdr/contact/viewobjectcontact.hxx>
26 #include <svx/svdview.hxx>
27 #include <svx/sdr/contact/viewcontact.hxx>
28 #include <svx/sdr/animation/objectanimator.hxx>
29 #include <svx/sdr/event/eventhandler.hxx>
30 #include <svx/sdrpagewindow.hxx>
31 #include <svx/sdrpaintwindow.hxx>
32 #include <drawinglayer/processor2d/vclprocessor2d.hxx>
33 #include <basegfx/matrix/b2dhommatrix.hxx>
34 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
35 #include <drawinglayer/processor2d/processorfromoutputdevice.hxx>
36 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
37 #include <svx/unoapi.hxx>
39 //////////////////////////////////////////////////////////////////////////////
41 using namespace com::sun::star;
43 //////////////////////////////////////////////////////////////////////////////
45 namespace sdr
47 namespace contact
49 // internal access to SdrPage of SdrPageView
50 SdrPage* ObjectContactOfPageView::GetSdrPage() const
52 return GetPageWindow().GetPageView().GetPage();
55 ObjectContactOfPageView::ObjectContactOfPageView(SdrPageWindow& rPageWindow)
56 : ObjectContact(),
57 mrPageWindow(rPageWindow)
59 // init PreviewRenderer flag
60 setPreviewRenderer(((SdrPaintView&)rPageWindow.GetPageView().GetView()).IsPreviewRenderer());
62 // init timer
63 SetTimeout(1);
64 Stop();
67 ObjectContactOfPageView::~ObjectContactOfPageView()
69 // execute missing LazyInvalidates and stop timer
70 Timeout();
73 // LazyInvalidate request. Take action.
74 void ObjectContactOfPageView::setLazyInvalidate(ViewObjectContact& /*rVOC*/)
76 // do NOT call parent, but remember that something is to do by
77 // starting the LazyInvalidateTimer
78 Start();
81 // call this to support evtl. preparations for repaint
82 void ObjectContactOfPageView::PrepareProcessDisplay()
84 if(IsActive())
86 static bool bInvalidateDuringPaint(true);
88 if(bInvalidateDuringPaint)
90 // there are still non-triggered LazyInvalidate events, trigger these
91 Timeout();
96 // From baseclass Timer, the timeout call triggered by te LazyInvalidate mechanism
97 void ObjectContactOfPageView::Timeout()
99 // stop the timer
100 Stop();
102 // invalidate all LazyInvalidate VOCs new situations
103 const sal_uInt32 nVOCCount(getViewObjectContactCount());
105 for(sal_uInt32 a(0); a < nVOCCount; a++)
107 ViewObjectContact* pCandidate = getViewObjectContact(a);
108 pCandidate->triggerLazyInvalidate();
112 // Process the whole displaying
113 void ObjectContactOfPageView::ProcessDisplay(DisplayInfo& rDisplayInfo)
115 const SdrPage* pStartPage = GetSdrPage();
117 if(pStartPage && !rDisplayInfo.GetProcessLayers().IsEmpty())
119 const ViewContact& rDrawPageVC = pStartPage->GetViewContact();
121 if(rDrawPageVC.GetObjectCount())
123 DoProcessDisplay(rDisplayInfo);
127 // after paint take care of the evtl. scheduled asynchronious commands.
128 // Do this by resetting the timer contained there. Thus, after the paint
129 // that timer will be triggered and the events will be executed.
130 if(HasEventHandler())
132 sdr::event::TimerEventHandler& rEventHandler = GetEventHandler();
134 if(!rEventHandler.IsEmpty())
136 rEventHandler.Restart();
141 // Process the whole displaying. Only use given DsiplayInfo, do not access other
142 // OutputDevices then the given ones.
143 void ObjectContactOfPageView::DoProcessDisplay(DisplayInfo& rDisplayInfo)
145 // visualize entered group when that feature is switched on and it's not
146 // a print output. #i29129# No ghosted display for printing.
147 bool bVisualizeEnteredGroup(DoVisualizeEnteredGroup() && !isOutputToPrinter());
149 // Visualize entered groups: Set to ghosted as default
150 // start. Do this only for the DrawPage, not for MasterPages
151 if(bVisualizeEnteredGroup)
153 rDisplayInfo.SetGhostedDrawMode();
156 // #114359# save old and set clip region
157 OutputDevice* pOutDev = TryToGetOutputDevice();
158 OSL_ENSURE(0 != pOutDev, "ObjectContactOfPageView without OutDev, someone has overloaded TryToGetOutputDevice wrong (!)");
159 bool bClipRegionPushed(false);
160 const Region& rRedrawArea(rDisplayInfo.GetRedrawArea());
162 if(!rRedrawArea.IsEmpty())
164 bClipRegionPushed = true;
165 pOutDev->Push(PUSH_CLIPREGION);
166 pOutDev->IntersectClipRegion(rRedrawArea);
169 // Get start node and process DrawPage contents
170 const ViewObjectContact& rDrawPageVOContact = GetSdrPage()->GetViewContact().GetViewObjectContact(*this);
172 // update current ViewInformation2D at the ObjectContact
173 const double fCurrentTime(getPrimitiveAnimator().GetTime());
174 OutputDevice& rTargetOutDev = GetPageWindow().GetPaintWindow().GetTargetOutputDevice();
175 basegfx::B2DRange aViewRange;
177 // create ViewRange
178 if(isOutputToRecordingMetaFile())
180 if(isOutputToPDFFile() || isOutputToPrinter())
182 // #i98402# if it's a PDF export, set the ClipRegion as ViewRange. This is
183 // mainly because SW does not use DrawingLayer Page-Oriented and if not doing this,
184 // all existing objects will be collected as primitives and processed.
185 // OD 2009-03-05 #i99876# perform the same also for SW on printing.
186 const Rectangle aLogicClipRectangle(rDisplayInfo.GetRedrawArea().GetBoundRect());
188 aViewRange = basegfx::B2DRange(
189 aLogicClipRectangle.Left(), aLogicClipRectangle.Top(),
190 aLogicClipRectangle.Right(), aLogicClipRectangle.Bottom());
193 else
195 // use visible pixels, but transform to world coordinates
196 const Size aOutputSizePixel(rTargetOutDev.GetOutputSizePixel());
197 aViewRange = basegfx::B2DRange(0.0, 0.0, aOutputSizePixel.getWidth(), aOutputSizePixel.getHeight());
199 // if a clip region is set, use it
200 if(!rDisplayInfo.GetRedrawArea().IsEmpty())
202 // get logic clip range and create discrete one
203 const Rectangle aLogicClipRectangle(rDisplayInfo.GetRedrawArea().GetBoundRect());
204 basegfx::B2DRange aLogicClipRange(
205 aLogicClipRectangle.Left(), aLogicClipRectangle.Top(),
206 aLogicClipRectangle.Right(), aLogicClipRectangle.Bottom());
207 basegfx::B2DRange aDiscreteClipRange(aLogicClipRange);
208 aDiscreteClipRange.transform(rTargetOutDev.GetViewTransformation());
210 // align the discrete one to discrete boundaries (pixel bounds). Also
211 // expand X and Y max by one due to Rectangle definition source
212 aDiscreteClipRange.expand(basegfx::B2DTuple(
213 floor(aDiscreteClipRange.getMinX()),
214 floor(aDiscreteClipRange.getMinY())));
215 aDiscreteClipRange.expand(basegfx::B2DTuple(
216 1.0 + ceil(aDiscreteClipRange.getMaxX()),
217 1.0 + ceil(aDiscreteClipRange.getMaxY())));
219 // intersect current ViewRange with ClipRange
220 aViewRange.intersect(aDiscreteClipRange);
223 // transform to world coordinates
224 aViewRange.transform(rTargetOutDev.GetInverseViewTransformation());
227 // update local ViewInformation2D
228 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D(
229 basegfx::B2DHomMatrix(),
230 rTargetOutDev.GetViewTransformation(),
231 aViewRange,
232 GetXDrawPageForSdrPage(GetSdrPage()),
233 fCurrentTime,
234 uno::Sequence<beans::PropertyValue>());
235 updateViewInformation2D(aNewViewInformation2D);
237 // get whole Primitive2DSequence; this will already make use of updated ViewInformation2D
238 // and may use the MapMode from the Target OutDev in the DisplayInfo
239 drawinglayer::primitive2d::Primitive2DSequence xPrimitiveSequence(rDrawPageVOContact.getPrimitive2DSequenceHierarchy(rDisplayInfo));
241 // if there is something to show, use a primitive processor to render it. There
242 // is a choice between VCL and Canvas processors currently. The decision is made in
243 // createBaseProcessor2DFromOutputDevice and takes into accout things like the
244 // Target is a MetaFile, a VDev or something else. The Canvas renderer is triggered
245 // currently using the shown boolean. Canvas is not yet the default.
246 if(xPrimitiveSequence.hasElements())
248 // prepare OutputDevice (historical stuff, maybe soon removed)
249 rDisplayInfo.ClearGhostedDrawMode(); // reset, else the VCL-paint with the processor will not do the right thing
250 pOutDev->SetLayoutMode(0); // reset, default is no BiDi/RTL
252 // create renderer
253 drawinglayer::processor2d::BaseProcessor2D* pProcessor2D =
254 drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(
255 rTargetOutDev, getViewInformation2D());
257 if(pProcessor2D)
259 pProcessor2D->process(xPrimitiveSequence);
260 delete pProcessor2D;
264 // #114359# restore old ClipReghion
265 if(bClipRegionPushed)
267 pOutDev->Pop();
270 // Visualize entered groups: Reset to original DrawMode
271 if(bVisualizeEnteredGroup)
273 rDisplayInfo.ClearGhostedDrawMode();
277 // test if visualizing of entered groups is switched on at all
278 bool ObjectContactOfPageView::DoVisualizeEnteredGroup() const
280 SdrView& rView = GetPageWindow().GetPageView().GetView();
281 return rView.DoVisualizeEnteredGroup();
284 // get active group's (the entered group) ViewContact
285 const ViewContact* ObjectContactOfPageView::getActiveViewContact() const
287 SdrObjList* pActiveGroupList = GetPageWindow().GetPageView().GetObjList();
289 if(pActiveGroupList)
291 if(pActiveGroupList->ISA(SdrPage))
293 // It's a Page itself
294 return &(((SdrPage*)pActiveGroupList)->GetViewContact());
296 else if(pActiveGroupList->GetOwnerObj())
298 // Group object
299 return &(pActiveGroupList->GetOwnerObj()->GetViewContact());
302 else if(GetSdrPage())
304 // use page of associated SdrPageView
305 return &(GetSdrPage()->GetViewContact());
308 return 0;
311 // Invalidate given rectangle at the window/output which is represented by
312 // this ObjectContact.
313 void ObjectContactOfPageView::InvalidatePartOfView(const basegfx::B2DRange& rRange) const
315 // invalidate at associated PageWindow
316 GetPageWindow().InvalidatePageWindow(rRange);
319 // Get info if given Rectangle is visible in this view
320 bool ObjectContactOfPageView::IsAreaVisible(const basegfx::B2DRange& rRange) const
322 // compare with the visible rectangle
323 if(rRange.isEmpty())
325 // no range -> not visible
326 return false;
328 else
330 const OutputDevice& rTargetOutDev = GetPageWindow().GetPaintWindow().GetTargetOutputDevice();
331 const Size aOutputSizePixel(rTargetOutDev.GetOutputSizePixel());
332 basegfx::B2DRange aLogicViewRange(0.0, 0.0, aOutputSizePixel.getWidth(), aOutputSizePixel.getHeight());
334 aLogicViewRange.transform(rTargetOutDev.GetInverseViewTransformation());
336 if(!aLogicViewRange.isEmpty() && !aLogicViewRange.overlaps(rRange))
338 return false;
342 // call parent
343 return ObjectContact::IsAreaVisible(rRange);
346 // Get info about the need to visualize GluePoints
347 bool ObjectContactOfPageView::AreGluePointsVisible() const
349 return GetPageWindow().GetPageView().GetView().ImpIsGlueVisible();
352 // check if text animation is allowed.
353 bool ObjectContactOfPageView::IsTextAnimationAllowed() const
355 SdrView& rView = GetPageWindow().GetPageView().GetView();
356 const SvtAccessibilityOptions& rOpt = rView.getAccessibilityOptions();
357 return rOpt.GetIsAllowAnimatedText();
360 // check if graphic animation is allowed.
361 bool ObjectContactOfPageView::IsGraphicAnimationAllowed() const
363 SdrView& rView = GetPageWindow().GetPageView().GetView();
364 const SvtAccessibilityOptions& rOpt = rView.getAccessibilityOptions();
365 return rOpt.GetIsAllowAnimatedGraphics();
368 // check if asynchronious graphis loading is allowed. Default is sal_False.
369 bool ObjectContactOfPageView::IsAsynchronGraphicsLoadingAllowed() const
371 SdrView& rView = GetPageWindow().GetPageView().GetView();
372 return rView.IsSwapAsynchron();
375 // check if buffering of MasterPages is allowed. Default is sal_False.
376 bool ObjectContactOfPageView::IsMasterPageBufferingAllowed() const
378 SdrView& rView = GetPageWindow().GetPageView().GetView();
379 return rView.IsMasterPagePaintCaching();
382 // print?
383 bool ObjectContactOfPageView::isOutputToPrinter() const
385 return (OUTDEV_PRINTER == mrPageWindow.GetPaintWindow().GetOutputDevice().GetOutDevType());
388 // window?
389 bool ObjectContactOfPageView::isOutputToWindow() const
391 return (OUTDEV_WINDOW == mrPageWindow.GetPaintWindow().GetOutputDevice().GetOutDevType());
394 // VirtualDevice?
395 bool ObjectContactOfPageView::isOutputToVirtualDevice() const
397 return (OUTDEV_VIRDEV == mrPageWindow.GetPaintWindow().GetOutputDevice().GetOutDevType());
400 // recording MetaFile?
401 bool ObjectContactOfPageView::isOutputToRecordingMetaFile() const
403 GDIMetaFile* pMetaFile = mrPageWindow.GetPaintWindow().GetOutputDevice().GetConnectMetaFile();
404 return (pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
407 // pdf export?
408 bool ObjectContactOfPageView::isOutputToPDFFile() const
410 return (0 != mrPageWindow.GetPaintWindow().GetOutputDevice().GetPDFWriter());
413 // gray display mode
414 bool ObjectContactOfPageView::isDrawModeGray() const
416 const sal_uInt32 nDrawMode(mrPageWindow.GetPaintWindow().GetOutputDevice().GetDrawMode());
417 return (nDrawMode == (DRAWMODE_GRAYLINE|DRAWMODE_GRAYFILL|DRAWMODE_BLACKTEXT|DRAWMODE_GRAYBITMAP|DRAWMODE_GRAYGRADIENT));
420 // gray display mode
421 bool ObjectContactOfPageView::isDrawModeBlackWhite() const
423 const sal_uInt32 nDrawMode(mrPageWindow.GetPaintWindow().GetOutputDevice().GetDrawMode());
424 return (nDrawMode == (DRAWMODE_BLACKLINE|DRAWMODE_BLACKTEXT|DRAWMODE_WHITEFILL|DRAWMODE_GRAYBITMAP|DRAWMODE_WHITEGRADIENT));
427 // high contrast display mode
428 bool ObjectContactOfPageView::isDrawModeHighContrast() const
430 const sal_uInt32 nDrawMode(mrPageWindow.GetPaintWindow().GetOutputDevice().GetDrawMode());
431 return (nDrawMode == (DRAWMODE_SETTINGSLINE|DRAWMODE_SETTINGSFILL|DRAWMODE_SETTINGSTEXT|DRAWMODE_SETTINGSGRADIENT));
434 // access to SdrPageView
435 SdrPageView* ObjectContactOfPageView::TryToGetSdrPageView() const
437 return &(mrPageWindow.GetPageView());
441 // access to OutputDevice
442 OutputDevice* ObjectContactOfPageView::TryToGetOutputDevice() const
444 SdrPreRenderDevice* pPreRenderDevice = mrPageWindow.GetPaintWindow().GetPreRenderDevice();
446 if(pPreRenderDevice)
448 return &(pPreRenderDevice->GetPreRenderDevice());
450 else
452 return &(mrPageWindow.GetPaintWindow().GetOutputDevice());
456 // set all UNO controls displayed in the view to design/alive mode
457 void ObjectContactOfPageView::SetUNOControlsDesignMode( bool _bDesignMode ) const
459 const sal_uInt32 nCount(getViewObjectContactCount());
461 for(sal_uInt32 a(0); a < nCount; a++)
463 const ViewObjectContact* pVOC = getViewObjectContact(a);
464 const ViewObjectContactOfUnoControl* pUnoObjectVOC = dynamic_cast< const ViewObjectContactOfUnoControl* >(pVOC);
466 if(pUnoObjectVOC)
468 pUnoObjectVOC->setControlDesignMode(_bDesignMode);
472 } // end of namespace contact
473 } // end of namespace sdr
475 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */