Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <config_features.h>
21 :
22 : #include <sdr/contact/objectcontactofpageview.hxx>
23 : #include <sdr/contact/viewobjectcontactofunocontrol.hxx>
24 : #include <svx/svdpagv.hxx>
25 : #include <svx/svdpage.hxx>
26 : #include <svx/sdr/contact/displayinfo.hxx>
27 : #include <svx/sdr/contact/viewobjectcontact.hxx>
28 : #include <svx/svdview.hxx>
29 : #include <svx/sdr/contact/viewcontact.hxx>
30 : #include <svx/sdr/animation/objectanimator.hxx>
31 : #include <svx/sdrpagewindow.hxx>
32 : #include <svx/sdrpaintwindow.hxx>
33 : #include <basegfx/matrix/b2dhommatrix.hxx>
34 : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
35 : #include <com/sun/star/rendering/XSpriteCanvas.hpp>
36 : #include <drawinglayer/processor2d/processor2dtools.hxx>
37 : #include <svx/unoapi.hxx>
38 :
39 : #include "eventhandler.hxx"
40 : #include <boost/scoped_ptr.hpp>
41 :
42 : using namespace com::sun::star;
43 :
44 : namespace sdr
45 : {
46 : namespace contact
47 : {
48 : // internal access to SdrPage of SdrPageView
49 135401 : SdrPage* ObjectContactOfPageView::GetSdrPage() const
50 : {
51 135401 : return GetPageWindow().GetPageView().GetPage();
52 : }
53 :
54 3197 : ObjectContactOfPageView::ObjectContactOfPageView(SdrPageWindow& rPageWindow)
55 : : ObjectContact(),
56 3197 : mrPageWindow(rPageWindow)
57 : {
58 : // init PreviewRenderer flag
59 3197 : setPreviewRenderer(((SdrPaintView&)rPageWindow.GetPageView().GetView()).IsPreviewRenderer());
60 :
61 : // init timer
62 3197 : SetTimeout(1);
63 3197 : Stop();
64 3197 : }
65 :
66 9522 : ObjectContactOfPageView::~ObjectContactOfPageView()
67 : {
68 : // execute missing LazyInvalidates and stop timer
69 3174 : Timeout();
70 6348 : }
71 :
72 : // LazyInvalidate request. Take action.
73 13193 : void ObjectContactOfPageView::setLazyInvalidate(ViewObjectContact& /*rVOC*/)
74 : {
75 : // do NOT call parent, but remember that something is to do by
76 : // starting the LazyInvalidateTimer
77 13193 : Start();
78 13193 : }
79 :
80 : // call this to support evtl. preparations for repaint
81 22298 : void ObjectContactOfPageView::PrepareProcessDisplay()
82 : {
83 22298 : if(IsActive())
84 : {
85 : static bool bInvalidateDuringPaint(true);
86 :
87 1169 : if(bInvalidateDuringPaint)
88 : {
89 : // there are still non-triggered LazyInvalidate events, trigger these
90 1169 : Timeout();
91 : }
92 : }
93 22298 : }
94 :
95 : // From baseclass Timer, the timeout call triggered by the LazyInvalidate mechanism
96 10293 : void ObjectContactOfPageView::Timeout()
97 : {
98 : // stop the timer
99 10293 : Stop();
100 :
101 : // invalidate all LazyInvalidate VOCs new situations
102 10293 : const sal_uInt32 nVOCCount(getViewObjectContactCount());
103 :
104 180067 : for(sal_uInt32 a(0); a < nVOCCount; a++)
105 : {
106 169774 : ViewObjectContact* pCandidate = getViewObjectContact(a);
107 169774 : pCandidate->triggerLazyInvalidate();
108 : }
109 10293 : }
110 :
111 : // Process the whole displaying
112 45135 : void ObjectContactOfPageView::ProcessDisplay(DisplayInfo& rDisplayInfo)
113 : {
114 45135 : const SdrPage* pStartPage = GetSdrPage();
115 :
116 45135 : if(pStartPage && !rDisplayInfo.GetProcessLayers().IsEmpty())
117 : {
118 45135 : const ViewContact& rDrawPageVC = pStartPage->GetViewContact();
119 :
120 45135 : if(rDrawPageVC.GetObjectCount())
121 : {
122 45135 : DoProcessDisplay(rDisplayInfo);
123 : }
124 : }
125 :
126 : // after paint take care of the evtl. scheduled asynchronious commands.
127 : // Do this by resetting the timer contained there. Thus, after the paint
128 : // that timer will be triggered and the events will be executed.
129 45135 : if(HasEventHandler())
130 : {
131 0 : sdr::event::TimerEventHandler& rEventHandler = GetEventHandler();
132 :
133 0 : if(!rEventHandler.IsEmpty())
134 : {
135 0 : rEventHandler.Restart();
136 : }
137 : }
138 45135 : }
139 :
140 : // Process the whole displaying. Only use given DsiplayInfo, do not access other
141 : // OutputDevices then the given ones.
142 45135 : void ObjectContactOfPageView::DoProcessDisplay(DisplayInfo& rDisplayInfo)
143 : {
144 45135 : OutputDevice& rTargetOutDev = GetPageWindow().GetPaintWindow().GetTargetOutputDevice();
145 45135 : const Size aOutputSizePixel(rTargetOutDev.GetOutputSizePixel());
146 90270 : if (!isOutputToRecordingMetaFile() // do those have outdev too?
147 88146 : && (0 == aOutputSizePixel.getWidth() ||
148 43011 : 0 == aOutputSizePixel.getHeight()))
149 : {
150 45137 : return;
151 : }
152 :
153 : // visualize entered group when that feature is switched on and it's not
154 : // a print output. #i29129# No ghosted display for printing.
155 45133 : bool bVisualizeEnteredGroup(DoVisualizeEnteredGroup() && !isOutputToPrinter());
156 :
157 : // Visualize entered groups: Set to ghosted as default
158 : // start. Do this only for the DrawPage, not for MasterPages
159 45133 : if(bVisualizeEnteredGroup)
160 : {
161 45133 : rDisplayInfo.SetGhostedDrawMode();
162 : }
163 :
164 : // #114359# save old and set clip region
165 45133 : OutputDevice* pOutDev = TryToGetOutputDevice();
166 : OSL_ENSURE(0 != pOutDev, "ObjectContactOfPageView without OutDev, someone has overloaded TryToGetOutputDevice wrong (!)");
167 45133 : bool bClipRegionPushed(false);
168 45133 : const vcl::Region& rRedrawArea(rDisplayInfo.GetRedrawArea());
169 :
170 45133 : if(!rRedrawArea.IsEmpty())
171 : {
172 45133 : bClipRegionPushed = true;
173 45133 : pOutDev->Push(PushFlags::CLIPREGION);
174 45133 : pOutDev->IntersectClipRegion(rRedrawArea);
175 : }
176 :
177 : // Get start node and process DrawPage contents
178 45133 : const ViewObjectContact& rDrawPageVOContact = GetSdrPage()->GetViewContact().GetViewObjectContact(*this);
179 :
180 : // update current ViewInformation2D at the ObjectContact
181 45133 : const double fCurrentTime(getPrimitiveAnimator().GetTime());
182 45133 : basegfx::B2DRange aViewRange;
183 :
184 : // create ViewRange
185 45133 : if(isOutputToRecordingMetaFile())
186 : {
187 2122 : if (!rDisplayInfo.GetRedrawArea().IsEmpty())
188 : {
189 : // #i98402# if it's a PDF export, set the ClipRegion as ViewRange. This is
190 : // mainly because SW does not use DrawingLayer Page-Oriented and if not doing this,
191 : // all existing objects will be collected as primitives and processed.
192 : // OD 2009-03-05 #i99876# perform the same also for SW on printing.
193 : // fdo#78149 same thing also needed for plain MetaFile
194 : // export, so why not do it always
195 2122 : const Rectangle aLogicClipRectangle(rDisplayInfo.GetRedrawArea().GetBoundRect());
196 :
197 : aViewRange = basegfx::B2DRange(
198 4244 : aLogicClipRectangle.Left(), aLogicClipRectangle.Top(),
199 6366 : aLogicClipRectangle.Right(), aLogicClipRectangle.Bottom());
200 : }
201 : }
202 : else
203 : {
204 : // use visible pixels, but transform to world coordinates
205 43011 : aViewRange = basegfx::B2DRange(0.0, 0.0, aOutputSizePixel.getWidth(), aOutputSizePixel.getHeight());
206 :
207 : // if a clip region is set, use it
208 43011 : if(!rDisplayInfo.GetRedrawArea().IsEmpty())
209 : {
210 : // get logic clip range and create discrete one
211 43011 : const Rectangle aLogicClipRectangle(rDisplayInfo.GetRedrawArea().GetBoundRect());
212 : basegfx::B2DRange aLogicClipRange(
213 86022 : aLogicClipRectangle.Left(), aLogicClipRectangle.Top(),
214 129033 : aLogicClipRectangle.Right(), aLogicClipRectangle.Bottom());
215 43011 : basegfx::B2DRange aDiscreteClipRange(aLogicClipRange);
216 43011 : aDiscreteClipRange.transform(rTargetOutDev.GetViewTransformation());
217 :
218 : // align the discrete one to discrete boundaries (pixel bounds). Also
219 : // expand X and Y max by one due to Rectangle definition source
220 : aDiscreteClipRange.expand(basegfx::B2DTuple(
221 : floor(aDiscreteClipRange.getMinX()),
222 43011 : floor(aDiscreteClipRange.getMinY())));
223 : aDiscreteClipRange.expand(basegfx::B2DTuple(
224 43011 : 1.0 + ceil(aDiscreteClipRange.getMaxX()),
225 86022 : 1.0 + ceil(aDiscreteClipRange.getMaxY())));
226 :
227 : // intersect current ViewRange with ClipRange
228 43011 : aViewRange.intersect(aDiscreteClipRange);
229 : }
230 :
231 : // transform to world coordinates
232 43011 : aViewRange.transform(rTargetOutDev.GetInverseViewTransformation());
233 : }
234 :
235 : // update local ViewInformation2D
236 : const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D(
237 : basegfx::B2DHomMatrix(),
238 : rTargetOutDev.GetViewTransformation(),
239 : aViewRange,
240 : GetXDrawPageForSdrPage(GetSdrPage()),
241 : fCurrentTime,
242 45133 : uno::Sequence<beans::PropertyValue>());
243 45133 : updateViewInformation2D(aNewViewInformation2D);
244 :
245 90266 : drawinglayer::primitive2d::Primitive2DSequence xPrimitiveSequence;
246 : #if HAVE_FEATURE_DESKTOP
247 : // get whole Primitive2DSequence; this will already make use of updated ViewInformation2D
248 : // and may use the MapMode from the Target OutDev in the DisplayInfo
249 45133 : xPrimitiveSequence = rDrawPageVOContact.getPrimitive2DSequenceHierarchy(rDisplayInfo);
250 : #else
251 : // HACK: this only works when we are drawing sdr shapes via
252 : // drawinglayer; but it can happen that the hierarchy contains
253 : // more than just the shapes, and then it fails.
254 : //
255 : // This is good enough for the tiled rendering for the moment, but
256 : // we need to come up with with the real solution shortly.
257 :
258 : // Only get the expensive hierarchy if we can be sure that the
259 : // returned sequence won't be empty anyway.
260 : bool bGetHierarchy = rRedrawArea.IsEmpty();
261 : if (!bGetHierarchy)
262 : {
263 : // Not empty? Then not doing a full redraw, check if
264 : // getPrimitive2DSequenceHierarchy() is still needed.
265 : sal_Int32 nObjCount = GetSdrPage()->GetObjCount();
266 : for (sal_Int32 i = 0; i < nObjCount; ++i)
267 : {
268 : SdrObject* pObject = GetSdrPage()->GetObj(i);
269 : if (rRedrawArea.IsOver(pObject->GetCurrentBoundRect()))
270 : {
271 : bGetHierarchy = true;
272 : break;
273 : }
274 : }
275 : }
276 :
277 : if (bGetHierarchy)
278 : // get whole Primitive2DSequence; this will already make use of updated ViewInformation2D
279 : // and may use the MapMode from the Target OutDev in the DisplayInfo
280 : xPrimitiveSequence = rDrawPageVOContact.getPrimitive2DSequenceHierarchy(rDisplayInfo);
281 : #endif
282 :
283 : // if there is something to show, use a primitive processor to render it. There
284 : // is a choice between VCL and Canvas processors currently. The decision is made in
285 : // createProcessor2DFromOutputDevice and takes into accout things like the
286 : // Target is a MetaFile, a VDev or something else. The Canvas renderer is triggered
287 : // currently using the shown boolean. Canvas is not yet the default.
288 45133 : if(xPrimitiveSequence.hasElements())
289 : {
290 : // prepare OutputDevice (historical stuff, maybe soon removed)
291 4095 : rDisplayInfo.ClearGhostedDrawMode(); // reset, else the VCL-paint with the processor will not do the right thing
292 4095 : pOutDev->SetLayoutMode(TEXT_LAYOUT_DEFAULT); // reset, default is no BiDi/RTL
293 :
294 : // create renderer
295 : boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(
296 : drawinglayer::processor2d::createProcessor2DFromOutputDevice(
297 4095 : rTargetOutDev, getViewInformation2D()));
298 :
299 4095 : if(pProcessor2D)
300 : {
301 4095 : pProcessor2D->process(xPrimitiveSequence);
302 4095 : }
303 : }
304 :
305 : // #114359# restore old ClipReghion
306 45133 : if(bClipRegionPushed)
307 : {
308 45133 : pOutDev->Pop();
309 : }
310 :
311 : // Visualize entered groups: Reset to original DrawMode
312 45133 : if(bVisualizeEnteredGroup)
313 : {
314 45133 : rDisplayInfo.ClearGhostedDrawMode();
315 45133 : }
316 : }
317 :
318 : // test if visualizing of entered groups is switched on at all
319 115100 : bool ObjectContactOfPageView::DoVisualizeEnteredGroup() const
320 : {
321 115100 : SdrView& rView = GetPageWindow().GetPageView().GetView();
322 115100 : return rView.DoVisualizeEnteredGroup();
323 : }
324 :
325 : // get active group's (the entered group) ViewContact
326 51488 : const ViewContact* ObjectContactOfPageView::getActiveViewContact() const
327 : {
328 51488 : SdrObjList* pActiveGroupList = GetPageWindow().GetPageView().GetObjList();
329 :
330 51488 : if(pActiveGroupList)
331 : {
332 51488 : if(pActiveGroupList->ISA(SdrPage))
333 : {
334 : // It's a Page itself
335 51488 : return &(static_cast<SdrPage*>(pActiveGroupList)->GetViewContact());
336 : }
337 0 : else if(pActiveGroupList->GetOwnerObj())
338 : {
339 : // Group object
340 0 : return &(pActiveGroupList->GetOwnerObj()->GetViewContact());
341 : }
342 : }
343 0 : else if(GetSdrPage())
344 : {
345 : // use page of associated SdrPageView
346 0 : return &(GetSdrPage()->GetViewContact());
347 : }
348 :
349 0 : return 0;
350 : }
351 :
352 : // Invalidate given rectangle at the window/output which is represented by
353 : // this ObjectContact.
354 24000 : void ObjectContactOfPageView::InvalidatePartOfView(const basegfx::B2DRange& rRange) const
355 : {
356 : // invalidate at associated PageWindow
357 24000 : GetPageWindow().InvalidatePageWindow(rRange);
358 24000 : }
359 :
360 : // Get info if given Rectangle is visible in this view
361 0 : bool ObjectContactOfPageView::IsAreaVisible(const basegfx::B2DRange& rRange) const
362 : {
363 : // compare with the visible rectangle
364 0 : if(rRange.isEmpty())
365 : {
366 : // no range -> not visible
367 0 : return false;
368 : }
369 : else
370 : {
371 0 : const OutputDevice& rTargetOutDev = GetPageWindow().GetPaintWindow().GetTargetOutputDevice();
372 0 : const Size aOutputSizePixel(rTargetOutDev.GetOutputSizePixel());
373 0 : basegfx::B2DRange aLogicViewRange(0.0, 0.0, aOutputSizePixel.getWidth(), aOutputSizePixel.getHeight());
374 :
375 0 : aLogicViewRange.transform(rTargetOutDev.GetInverseViewTransformation());
376 :
377 0 : if(!aLogicViewRange.isEmpty() && !aLogicViewRange.overlaps(rRange))
378 : {
379 0 : return false;
380 : }
381 : }
382 :
383 : // call parent
384 0 : return ObjectContact::IsAreaVisible(rRange);
385 : }
386 :
387 : // Get info about the need to visualize GluePoints
388 21908 : bool ObjectContactOfPageView::AreGluePointsVisible() const
389 : {
390 21908 : return GetPageWindow().GetPageView().GetView().ImpIsGlueVisible();
391 : }
392 :
393 : // check if text animation is allowed.
394 24509 : bool ObjectContactOfPageView::IsTextAnimationAllowed() const
395 : {
396 24509 : SdrView& rView = GetPageWindow().GetPageView().GetView();
397 24509 : const SvtAccessibilityOptions& rOpt = rView.getAccessibilityOptions();
398 24509 : return rOpt.GetIsAllowAnimatedText();
399 : }
400 :
401 : // check if graphic animation is allowed.
402 24509 : bool ObjectContactOfPageView::IsGraphicAnimationAllowed() const
403 : {
404 24509 : SdrView& rView = GetPageWindow().GetPageView().GetView();
405 24509 : const SvtAccessibilityOptions& rOpt = rView.getAccessibilityOptions();
406 24509 : return rOpt.GetIsAllowAnimatedGraphics();
407 : }
408 :
409 : // check if asynchronious graphis loading is allowed. Default is sal_False.
410 0 : bool ObjectContactOfPageView::IsAsynchronGraphicsLoadingAllowed() const
411 : {
412 0 : SdrView& rView = GetPageWindow().GetPageView().GetView();
413 0 : return rView.IsSwapAsynchron();
414 : }
415 :
416 : // check if buffering of MasterPages is allowed. Default is sal_False.
417 0 : bool ObjectContactOfPageView::IsMasterPageBufferingAllowed() const
418 : {
419 0 : SdrView& rView = GetPageWindow().GetPageView().GetView();
420 0 : return rView.IsMasterPagePaintCaching();
421 : }
422 :
423 : // print?
424 175713 : bool ObjectContactOfPageView::isOutputToPrinter() const
425 : {
426 175713 : return (OUTDEV_PRINTER == mrPageWindow.GetPaintWindow().GetOutputDevice().GetOutDevType());
427 : }
428 :
429 : // window?
430 0 : bool ObjectContactOfPageView::isOutputToWindow() const
431 : {
432 0 : return (OUTDEV_WINDOW == mrPageWindow.GetPaintWindow().GetOutputDevice().GetOutDevType());
433 : }
434 :
435 : // VirtualDevice?
436 0 : bool ObjectContactOfPageView::isOutputToVirtualDevice() const
437 : {
438 0 : return (OUTDEV_VIRDEV == mrPageWindow.GetPaintWindow().GetOutputDevice().GetOutDevType());
439 : }
440 :
441 : // recording MetaFile?
442 90268 : bool ObjectContactOfPageView::isOutputToRecordingMetaFile() const
443 : {
444 90268 : GDIMetaFile* pMetaFile = mrPageWindow.GetPaintWindow().GetOutputDevice().GetConnectMetaFile();
445 90268 : return (pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
446 : }
447 :
448 : // pdf export?
449 1201 : bool ObjectContactOfPageView::isOutputToPDFFile() const
450 : {
451 1201 : return (0 != mrPageWindow.GetPaintWindow().GetOutputDevice().GetPDFWriter());
452 : }
453 :
454 : // gray display mode
455 776 : bool ObjectContactOfPageView::isDrawModeGray() const
456 : {
457 776 : const sal_uInt32 nDrawMode(mrPageWindow.GetPaintWindow().GetOutputDevice().GetDrawMode());
458 776 : return (nDrawMode == (DRAWMODE_GRAYLINE|DRAWMODE_GRAYFILL|DRAWMODE_BLACKTEXT|DRAWMODE_GRAYBITMAP|DRAWMODE_GRAYGRADIENT));
459 : }
460 :
461 : // gray display mode
462 0 : bool ObjectContactOfPageView::isDrawModeBlackWhite() const
463 : {
464 0 : const sal_uInt32 nDrawMode(mrPageWindow.GetPaintWindow().GetOutputDevice().GetDrawMode());
465 0 : return (nDrawMode == (DRAWMODE_BLACKLINE|DRAWMODE_BLACKTEXT|DRAWMODE_WHITEFILL|DRAWMODE_GRAYBITMAP|DRAWMODE_WHITEGRADIENT));
466 : }
467 :
468 : // high contrast display mode
469 1253 : bool ObjectContactOfPageView::isDrawModeHighContrast() const
470 : {
471 1253 : const sal_uInt32 nDrawMode(mrPageWindow.GetPaintWindow().GetOutputDevice().GetDrawMode());
472 1253 : return (nDrawMode == (DRAWMODE_SETTINGSLINE|DRAWMODE_SETTINGSFILL|DRAWMODE_SETTINGSTEXT|DRAWMODE_SETTINGSGRADIENT));
473 : }
474 :
475 : // access to SdrPageView
476 52513 : SdrPageView* ObjectContactOfPageView::TryToGetSdrPageView() const
477 : {
478 52513 : return &(mrPageWindow.GetPageView());
479 : }
480 :
481 :
482 : // access to OutputDevice
483 45723 : OutputDevice* ObjectContactOfPageView::TryToGetOutputDevice() const
484 : {
485 45723 : SdrPreRenderDevice* pPreRenderDevice = mrPageWindow.GetPaintWindow().GetPreRenderDevice();
486 :
487 45723 : if(pPreRenderDevice)
488 : {
489 969 : return &(pPreRenderDevice->GetPreRenderDevice());
490 : }
491 : else
492 : {
493 44754 : return &(mrPageWindow.GetPaintWindow().GetOutputDevice());
494 : }
495 : }
496 :
497 : // set all UNO controls displayed in the view to design/alive mode
498 46 : void ObjectContactOfPageView::SetUNOControlsDesignMode( bool _bDesignMode ) const
499 : {
500 46 : const sal_uInt32 nCount(getViewObjectContactCount());
501 :
502 100 : for(sal_uInt32 a(0); a < nCount; a++)
503 : {
504 54 : const ViewObjectContact* pVOC = getViewObjectContact(a);
505 54 : const ViewObjectContactOfUnoControl* pUnoObjectVOC = dynamic_cast< const ViewObjectContactOfUnoControl* >(pVOC);
506 :
507 54 : if(pUnoObjectVOC)
508 : {
509 6 : pUnoObjectVOC->setControlDesignMode(_bDesignMode);
510 : }
511 : }
512 46 : }
513 : } // end of namespace contact
514 651 : } // end of namespace sdr
515 :
516 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|