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