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 122470 : SdrPage* ObjectContactOfPageView::GetSdrPage() const
50 : {
51 122470 : return GetPageWindow().GetPageView().GetPage();
52 : }
53 :
54 2639 : ObjectContactOfPageView::ObjectContactOfPageView(SdrPageWindow& rPageWindow)
55 : : ObjectContact(),
56 2639 : mrPageWindow(rPageWindow)
57 : {
58 : // init PreviewRenderer flag
59 2639 : setPreviewRenderer(((SdrPaintView&)rPageWindow.GetPageView().GetView()).IsPreviewRenderer());
60 :
61 : // init timer
62 2639 : SetPriority(SchedulerPriority::HIGH);
63 2639 : Stop();
64 2639 : }
65 :
66 7863 : ObjectContactOfPageView::~ObjectContactOfPageView()
67 : {
68 : // execute missing LazyInvalidates and stop timer
69 2621 : Invoke();
70 5242 : }
71 :
72 : // LazyInvalidate request. Take action.
73 8698 : void ObjectContactOfPageView::setLazyInvalidate(ViewObjectContact& /*rVOC*/)
74 : {
75 : // do NOT call parent, but remember that something is to do by
76 : // starting the LazyInvalidateTimer
77 8698 : Start();
78 8698 : }
79 :
80 : // call this to support evtl. preparations for repaint
81 25826 : void ObjectContactOfPageView::PrepareProcessDisplay()
82 : {
83 25826 : if(IsActive())
84 : {
85 : static bool bInvalidateDuringPaint(true);
86 :
87 356 : if(bInvalidateDuringPaint)
88 : {
89 : // there are still non-triggered LazyInvalidate events, trigger these
90 356 : Invoke();
91 : }
92 : }
93 25826 : }
94 :
95 : // From baseclass Timer, the timeout call triggered by the LazyInvalidate mechanism
96 7601 : void ObjectContactOfPageView::Invoke()
97 : {
98 : // stop the timer
99 7601 : Stop();
100 :
101 : // invalidate all LazyInvalidate VOCs new situations
102 7601 : const sal_uInt32 nVOCCount(getViewObjectContactCount());
103 :
104 168610 : for(sal_uInt32 a(0); a < nVOCCount; a++)
105 : {
106 161009 : ViewObjectContact* pCandidate = getViewObjectContact(a);
107 161009 : pCandidate->triggerLazyInvalidate();
108 : }
109 7601 : }
110 :
111 : // Process the whole displaying
112 40824 : void ObjectContactOfPageView::ProcessDisplay(DisplayInfo& rDisplayInfo)
113 : {
114 40824 : const SdrPage* pStartPage = GetSdrPage();
115 :
116 40824 : if(pStartPage && !rDisplayInfo.GetProcessLayers().IsEmpty())
117 : {
118 40824 : const ViewContact& rDrawPageVC = pStartPage->GetViewContact();
119 :
120 40824 : if(rDrawPageVC.GetObjectCount())
121 : {
122 40824 : 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 40824 : if(HasEventHandler())
130 : {
131 5 : sdr::event::TimerEventHandler& rEventHandler = GetEventHandler();
132 :
133 5 : if(!rEventHandler.IsEmpty())
134 : {
135 3 : rEventHandler.Restart();
136 : }
137 : }
138 40824 : }
139 :
140 : // Process the whole displaying. Only use given DsiplayInfo, do not access other
141 : // OutputDevices then the given ones.
142 40824 : void ObjectContactOfPageView::DoProcessDisplay(DisplayInfo& rDisplayInfo)
143 : {
144 40824 : OutputDevice& rTargetOutDev = GetPageWindow().GetPaintWindow().GetTargetOutputDevice();
145 40824 : const Size aOutputSizePixel(rTargetOutDev.GetOutputSizePixel());
146 81648 : if (!isOutputToRecordingMetaFile() // do those have outdev too?
147 80439 : && (0 == aOutputSizePixel.getWidth() ||
148 39615 : 0 == aOutputSizePixel.getHeight()))
149 : {
150 40825 : 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 40823 : 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 40823 : if(bVisualizeEnteredGroup)
160 : {
161 40823 : rDisplayInfo.SetGhostedDrawMode();
162 : }
163 :
164 : // #114359# save old and set clip region
165 40823 : OutputDevice* pOutDev = TryToGetOutputDevice();
166 : OSL_ENSURE(0 != pOutDev, "ObjectContactOfPageView without OutDev, someone has overridden TryToGetOutputDevice wrong (!)");
167 40823 : bool bClipRegionPushed(false);
168 40823 : const vcl::Region& rRedrawArea(rDisplayInfo.GetRedrawArea());
169 :
170 40823 : if(!rRedrawArea.IsEmpty())
171 : {
172 40823 : bClipRegionPushed = true;
173 40823 : pOutDev->Push(PushFlags::CLIPREGION);
174 40823 : pOutDev->IntersectClipRegion(rRedrawArea);
175 : }
176 :
177 : // Get start node and process DrawPage contents
178 40823 : const ViewObjectContact& rDrawPageVOContact = GetSdrPage()->GetViewContact().GetViewObjectContact(*this);
179 :
180 : // update current ViewInformation2D at the ObjectContact
181 40823 : const double fCurrentTime(getPrimitiveAnimator().GetTime());
182 40823 : basegfx::B2DRange aViewRange;
183 :
184 : // create ViewRange
185 40823 : if(isOutputToRecordingMetaFile())
186 : {
187 1208 : 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 1208 : const Rectangle aLogicClipRectangle(rDisplayInfo.GetRedrawArea().GetBoundRect());
196 :
197 : aViewRange = basegfx::B2DRange(
198 2416 : aLogicClipRectangle.Left(), aLogicClipRectangle.Top(),
199 3624 : aLogicClipRectangle.Right(), aLogicClipRectangle.Bottom());
200 : }
201 : }
202 : else
203 : {
204 : // use visible pixels, but transform to world coordinates
205 39615 : aViewRange = basegfx::B2DRange(0.0, 0.0, aOutputSizePixel.getWidth(), aOutputSizePixel.getHeight());
206 :
207 : // if a clip region is set, use it
208 39615 : if(!rDisplayInfo.GetRedrawArea().IsEmpty())
209 : {
210 : // get logic clip range and create discrete one
211 39615 : const Rectangle aLogicClipRectangle(rDisplayInfo.GetRedrawArea().GetBoundRect());
212 : basegfx::B2DRange aLogicClipRange(
213 79230 : aLogicClipRectangle.Left(), aLogicClipRectangle.Top(),
214 118845 : aLogicClipRectangle.Right(), aLogicClipRectangle.Bottom());
215 39615 : basegfx::B2DRange aDiscreteClipRange(aLogicClipRange);
216 39615 : 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 39615 : floor(aDiscreteClipRange.getMinY())));
223 : aDiscreteClipRange.expand(basegfx::B2DTuple(
224 39615 : 1.0 + ceil(aDiscreteClipRange.getMaxX()),
225 79230 : 1.0 + ceil(aDiscreteClipRange.getMaxY())));
226 :
227 : // intersect current ViewRange with ClipRange
228 39615 : aViewRange.intersect(aDiscreteClipRange);
229 : }
230 :
231 : // transform to world coordinates
232 39615 : 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 40823 : uno::Sequence<beans::PropertyValue>());
243 40823 : updateViewInformation2D(aNewViewInformation2D);
244 :
245 81646 : drawinglayer::primitive2d::Primitive2DSequence xPrimitiveSequence;
246 : #if HAVE_FEATURE_DESKTOP || defined( ANDROID )
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 40823 : 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 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 40823 : if(xPrimitiveSequence.hasElements())
289 : {
290 : // prepare OutputDevice (historical stuff, maybe soon removed)
291 6124 : rDisplayInfo.ClearGhostedDrawMode(); // reset, else the VCL-paint with the processor will not do the right thing
292 6124 : 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 6124 : rTargetOutDev, getViewInformation2D()));
298 :
299 6124 : if(pProcessor2D)
300 : {
301 6124 : pProcessor2D->process(xPrimitiveSequence);
302 6124 : }
303 : }
304 :
305 : // #114359# restore old ClipReghion
306 40823 : if(bClipRegionPushed)
307 : {
308 40823 : pOutDev->Pop();
309 : }
310 :
311 : // Visualize entered groups: Reset to original DrawMode
312 40823 : if(bVisualizeEnteredGroup)
313 : {
314 40823 : rDisplayInfo.ClearGhostedDrawMode();
315 40823 : }
316 : }
317 :
318 : // test if visualizing of entered groups is switched on at all
319 139520 : bool ObjectContactOfPageView::DoVisualizeEnteredGroup() const
320 : {
321 139520 : SdrView& rView = GetPageWindow().GetPageView().GetView();
322 139520 : return rView.DoVisualizeEnteredGroup();
323 : }
324 :
325 : // get active group's (the entered group) ViewContact
326 60796 : const ViewContact* ObjectContactOfPageView::getActiveViewContact() const
327 : {
328 60796 : SdrObjList* pActiveGroupList = GetPageWindow().GetPageView().GetObjList();
329 :
330 60796 : if(pActiveGroupList)
331 : {
332 60796 : if(pActiveGroupList->ISA(SdrPage))
333 : {
334 : // It's a Page itself
335 60796 : 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 15983 : void ObjectContactOfPageView::InvalidatePartOfView(const basegfx::B2DRange& rRange) const
355 : {
356 : // invalidate at associated PageWindow
357 15983 : GetPageWindow().InvalidatePageWindow(rRange);
358 15983 : }
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 42433 : bool ObjectContactOfPageView::AreGluePointsVisible() const
389 : {
390 42433 : return GetPageWindow().GetPageView().GetView().ImpIsGlueVisible();
391 : }
392 :
393 : // check if text animation is allowed.
394 41203 : bool ObjectContactOfPageView::IsTextAnimationAllowed() const
395 : {
396 41203 : SdrView& rView = GetPageWindow().GetPageView().GetView();
397 41203 : const SvtAccessibilityOptions& rOpt = rView.getAccessibilityOptions();
398 41203 : return rOpt.GetIsAllowAnimatedText();
399 : }
400 :
401 : // check if graphic animation is allowed.
402 41203 : bool ObjectContactOfPageView::IsGraphicAnimationAllowed() const
403 : {
404 41203 : SdrView& rView = GetPageWindow().GetPageView().GetView();
405 41203 : const SvtAccessibilityOptions& rOpt = rView.getAccessibilityOptions();
406 41203 : return rOpt.GetIsAllowAnimatedGraphics();
407 : }
408 :
409 : // check if asynchronious graphis loading is allowed. Default is sal_False.
410 6 : bool ObjectContactOfPageView::IsAsynchronGraphicsLoadingAllowed() const
411 : {
412 6 : SdrView& rView = GetPageWindow().GetPageView().GetView();
413 6 : 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 268624 : bool ObjectContactOfPageView::isOutputToPrinter() const
425 : {
426 268624 : return (OUTDEV_PRINTER == mrPageWindow.GetPaintWindow().GetOutputDevice().GetOutDevType());
427 : }
428 :
429 : // window?
430 6 : bool ObjectContactOfPageView::isOutputToWindow() const
431 : {
432 6 : return (OUTDEV_WINDOW == mrPageWindow.GetPaintWindow().GetOutputDevice().GetOutDevType());
433 : }
434 :
435 : // VirtualDevice?
436 6 : bool ObjectContactOfPageView::isOutputToVirtualDevice() const
437 : {
438 6 : return (OUTDEV_VIRDEV == mrPageWindow.GetPaintWindow().GetOutputDevice().GetOutDevType());
439 : }
440 :
441 : // recording MetaFile?
442 81662 : bool ObjectContactOfPageView::isOutputToRecordingMetaFile() const
443 : {
444 81662 : GDIMetaFile* pMetaFile = mrPageWindow.GetPaintWindow().GetOutputDevice().GetConnectMetaFile();
445 81662 : return (pMetaFile && pMetaFile->IsRecord() && !pMetaFile->IsPause());
446 : }
447 :
448 : // pdf export?
449 2345 : bool ObjectContactOfPageView::isOutputToPDFFile() const
450 : {
451 2345 : return (0 != mrPageWindow.GetPaintWindow().GetOutputDevice().GetPDFWriter());
452 : }
453 :
454 : // gray display mode
455 1042 : bool ObjectContactOfPageView::isDrawModeGray() const
456 : {
457 1042 : const DrawModeFlags nDrawMode(mrPageWindow.GetPaintWindow().GetOutputDevice().GetDrawMode());
458 1042 : return (nDrawMode == (DrawModeFlags::GrayLine|DrawModeFlags::GrayFill|DrawModeFlags::BlackText|DrawModeFlags::GrayBitmap|DrawModeFlags::GrayGradient));
459 : }
460 :
461 : // gray display mode
462 0 : bool ObjectContactOfPageView::isDrawModeBlackWhite() const
463 : {
464 0 : const DrawModeFlags nDrawMode(mrPageWindow.GetPaintWindow().GetOutputDevice().GetDrawMode());
465 0 : return (nDrawMode == (DrawModeFlags::BlackLine|DrawModeFlags::BlackText|DrawModeFlags::WhiteFill|DrawModeFlags::GrayBitmap|DrawModeFlags::WhiteGradient));
466 : }
467 :
468 : // high contrast display mode
469 1880 : bool ObjectContactOfPageView::isDrawModeHighContrast() const
470 : {
471 1880 : const DrawModeFlags nDrawMode(mrPageWindow.GetPaintWindow().GetOutputDevice().GetDrawMode());
472 1880 : return (nDrawMode == (DrawModeFlags::SettingsLine|DrawModeFlags::SettingsFill|DrawModeFlags::SettingsText|DrawModeFlags::SettingsGradient));
473 : }
474 :
475 : // access to SdrPageView
476 107197 : SdrPageView* ObjectContactOfPageView::TryToGetSdrPageView() const
477 : {
478 107197 : return &(mrPageWindow.GetPageView());
479 : }
480 :
481 :
482 : // access to OutputDevice
483 41121 : OutputDevice* ObjectContactOfPageView::TryToGetOutputDevice() const
484 : {
485 41121 : SdrPreRenderDevice* pPreRenderDevice = mrPageWindow.GetPaintWindow().GetPreRenderDevice();
486 :
487 41121 : if(pPreRenderDevice)
488 : {
489 1907 : return &(pPreRenderDevice->GetPreRenderDevice());
490 : }
491 : else
492 : {
493 39214 : return &(mrPageWindow.GetPaintWindow().GetOutputDevice());
494 : }
495 : }
496 :
497 : // set all UNO controls displayed in the view to design/alive mode
498 23 : void ObjectContactOfPageView::SetUNOControlsDesignMode( bool _bDesignMode ) const
499 : {
500 23 : const sal_uInt32 nCount(getViewObjectContactCount());
501 :
502 50 : for(sal_uInt32 a(0); a < nCount; a++)
503 : {
504 27 : const ViewObjectContact* pVOC = getViewObjectContact(a);
505 27 : const ViewObjectContactOfUnoControl* pUnoObjectVOC = dynamic_cast< const ViewObjectContactOfUnoControl* >(pVOC);
506 :
507 27 : if(pUnoObjectVOC)
508 : {
509 3 : pUnoObjectVOC->setControlDesignMode(_bDesignMode);
510 : }
511 : }
512 23 : }
513 : } // end of namespace contact
514 435 : } // end of namespace sdr
515 :
516 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|