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/viewobjectcontact.hxx>
21 : #include <svx/sdr/contact/viewcontact.hxx>
22 : #include <svx/sdr/contact/objectcontact.hxx>
23 : #include <svx/sdr/contact/displayinfo.hxx>
24 : #include <vcl/region.hxx>
25 : #include <svx/sdr/animation/objectanimator.hxx>
26 : #include <svx/sdr/animation/animationstate.hxx>
27 : #include <svx/sdr/contact/viewobjectcontactredirector.hxx>
28 : #include <basegfx/numeric/ftools.hxx>
29 : #include <basegfx/color/bcolor.hxx>
30 : #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
31 : #include <basegfx/tools/canvastools.hxx>
32 : #include <drawinglayer/primitive2d/animatedprimitive2d.hxx>
33 : #include <drawinglayer/processor2d/baseprocessor2d.hxx>
34 : #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
35 :
36 : //////////////////////////////////////////////////////////////////////////////
37 :
38 : using namespace com::sun::star;
39 :
40 : //////////////////////////////////////////////////////////////////////////////
41 :
42 : namespace
43 : {
44 : // animated extractor
45 :
46 : // Necessary to filter a sequence of animated primitives from
47 : // a sequence of primitives to find out if animated or not. The decision for
48 : // what to decompose is hard-coded and only done for knowingly animated primitives
49 : // to not decompose too deeply and unnecessarily. This implies that the list
50 : // which is view-specific needs to be expanded by hand when new animated objects
51 : // are added. This may eventually be changed to a dynamically configurable approach
52 : // if necessary.
53 : class AnimatedExtractingProcessor2D : public drawinglayer::processor2d::BaseProcessor2D
54 : {
55 : protected:
56 : // the found animated primitives
57 : drawinglayer::primitive2d::Primitive2DSequence maPrimitive2DSequence;
58 :
59 : // bitfield
60 : // text animation allowed?
61 : unsigned mbTextAnimationAllowed : 1;
62 :
63 : // graphic animation allowed?
64 : unsigned mbGraphicAnimationAllowed : 1;
65 :
66 : // as tooling, the process() implementation takes over API handling and calls this
67 : // virtual render method when the primitive implementation is BasePrimitive2D-based.
68 : virtual void processBasePrimitive2D(const drawinglayer::primitive2d::BasePrimitive2D& rCandidate);
69 :
70 : public:
71 : AnimatedExtractingProcessor2D(
72 : const drawinglayer::geometry::ViewInformation2D& rViewInformation,
73 : bool bTextAnimationAllowed,
74 : bool bGraphicAnimationAllowed);
75 : virtual ~AnimatedExtractingProcessor2D();
76 :
77 : // data access
78 18280 : const drawinglayer::primitive2d::Primitive2DSequence& getPrimitive2DSequence() const { return maPrimitive2DSequence; }
79 0 : bool isTextAnimationAllowed() const { return mbTextAnimationAllowed; }
80 0 : bool isGraphicAnimationAllowed() const { return mbGraphicAnimationAllowed; }
81 : };
82 :
83 18280 : AnimatedExtractingProcessor2D::AnimatedExtractingProcessor2D(
84 : const drawinglayer::geometry::ViewInformation2D& rViewInformation,
85 : bool bTextAnimationAllowed,
86 : bool bGraphicAnimationAllowed)
87 : : drawinglayer::processor2d::BaseProcessor2D(rViewInformation),
88 : maPrimitive2DSequence(),
89 : mbTextAnimationAllowed(bTextAnimationAllowed),
90 18280 : mbGraphicAnimationAllowed(bGraphicAnimationAllowed)
91 : {
92 18280 : }
93 :
94 18280 : AnimatedExtractingProcessor2D::~AnimatedExtractingProcessor2D()
95 : {
96 18280 : }
97 :
98 37966 : void AnimatedExtractingProcessor2D::processBasePrimitive2D(const drawinglayer::primitive2d::BasePrimitive2D& rCandidate)
99 : {
100 : // known implementation, access directly
101 37966 : switch(rCandidate.getPrimitive2DID())
102 : {
103 : // add and accept animated primitives directly, no need to decompose
104 : case PRIMITIVE2D_ID_ANIMATEDSWITCHPRIMITIVE2D :
105 : case PRIMITIVE2D_ID_ANIMATEDBLINKPRIMITIVE2D :
106 : case PRIMITIVE2D_ID_ANIMATEDINTERPOLATEPRIMITIVE2D :
107 : {
108 0 : const drawinglayer::primitive2d::AnimatedSwitchPrimitive2D& rSwitchPrimitive = static_cast< const drawinglayer::primitive2d::AnimatedSwitchPrimitive2D& >(rCandidate);
109 :
110 0 : if((rSwitchPrimitive.isTextAnimation() && isTextAnimationAllowed())
111 0 : || (rSwitchPrimitive.isGraphicAnimation() && isGraphicAnimationAllowed()))
112 : {
113 0 : const drawinglayer::primitive2d::Primitive2DReference xReference(const_cast< drawinglayer::primitive2d::BasePrimitive2D* >(&rCandidate));
114 0 : drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(maPrimitive2DSequence, xReference);
115 : }
116 0 : break;
117 : }
118 :
119 : // decompose animated gifs where SdrGrafPrimitive2D produces a GraphicPrimitive2D
120 : // which then produces the animation infos (all when used/needed)
121 : case PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D :
122 : case PRIMITIVE2D_ID_GRAPHICPRIMITIVE2D :
123 :
124 : // decompose SdrObjects with evtl. animated text
125 : case PRIMITIVE2D_ID_SDRCAPTIONPRIMITIVE2D :
126 : case PRIMITIVE2D_ID_SDRCONNECTORPRIMITIVE2D :
127 : case PRIMITIVE2D_ID_SDRCUSTOMSHAPEPRIMITIVE2D :
128 : case PRIMITIVE2D_ID_SDRELLIPSEPRIMITIVE2D :
129 : case PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D :
130 : case PRIMITIVE2D_ID_SDRMEASUREPRIMITIVE2D :
131 : case PRIMITIVE2D_ID_SDRPATHPRIMITIVE2D :
132 : case PRIMITIVE2D_ID_SDRRECTANGLEPRIMITIVE2D :
133 :
134 : // #121194# With Graphic as Bitmap FillStyle, also check
135 : // for primitives filled with animated graphics
136 : case PRIMITIVE2D_ID_POLYPOLYGONGRAPHICPRIMITIVE2D:
137 : case PRIMITIVE2D_ID_FILLGRAPHICPRIMITIVE2D:
138 : case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D:
139 :
140 : // decompose evtl. animated text contained in MaskPrimitive2D
141 : // or group rimitives
142 : case PRIMITIVE2D_ID_MASKPRIMITIVE2D :
143 : case PRIMITIVE2D_ID_GROUPPRIMITIVE2D :
144 : {
145 7413 : process(rCandidate.get2DDecomposition(getViewInformation2D()));
146 7413 : break;
147 : }
148 :
149 : default :
150 : {
151 : // nothing to do for the rest
152 30553 : break;
153 : }
154 : }
155 37966 : }
156 : } // end of anonymous namespace
157 :
158 : //////////////////////////////////////////////////////////////////////////////
159 :
160 : namespace sdr
161 : {
162 : namespace contact
163 : {
164 37329 : ViewObjectContact::ViewObjectContact(ObjectContact& rObjectContact, ViewContact& rViewContact)
165 : : mrObjectContact(rObjectContact),
166 : mrViewContact(rViewContact),
167 : maObjectRange(),
168 : mxPrimitive2DSequence(),
169 : mpPrimitiveAnimation(0),
170 37329 : mbLazyInvalidate(false)
171 : {
172 : // make the ViewContact remember me
173 37329 : mrViewContact.AddViewObjectContact(*this);
174 :
175 : // make the ObjectContact remember me
176 37329 : mrObjectContact.AddViewObjectContact(*this);
177 37329 : }
178 :
179 74658 : ViewObjectContact::~ViewObjectContact()
180 : {
181 : // invalidate in view
182 37329 : if(!maObjectRange.isEmpty())
183 : {
184 14266 : GetObjectContact().InvalidatePartOfView(maObjectRange);
185 : }
186 :
187 : // delete PrimitiveAnimation
188 37329 : if(mpPrimitiveAnimation)
189 : {
190 0 : delete mpPrimitiveAnimation;
191 0 : mpPrimitiveAnimation = 0;
192 : }
193 :
194 : // take care of remebered ObjectContact. Remove from
195 : // OC first. The VC removal (below) CAN trigger a StopGettingViewed()
196 : // which (depending of it's implementation) may destroy other OCs. This
197 : // can trigger the deletion of the helper OC of a page visualising object
198 : // which IS the OC of this object. Eventually StopGettingViewed() needs
199 : // to get asynchron later
200 37329 : GetObjectContact().RemoveViewObjectContact(*this);
201 :
202 : // take care of remebered ViewContact
203 37329 : GetViewContact().RemoveViewObjectContact(*this);
204 37329 : }
205 :
206 10966 : const basegfx::B2DRange& ViewObjectContact::getObjectRange() const
207 : {
208 10966 : if(maObjectRange.isEmpty())
209 : {
210 : // if range is not computed (new or LazyInvalidate objects), force it
211 6877 : const DisplayInfo aDisplayInfo;
212 13754 : const drawinglayer::primitive2d::Primitive2DSequence xSequence(getPrimitive2DSequence(aDisplayInfo));
213 :
214 6877 : if(xSequence.hasElements())
215 : {
216 5930 : const drawinglayer::geometry::ViewInformation2D& rViewInformation2D(GetObjectContact().getViewInformation2D());
217 : const_cast< ViewObjectContact* >(this)->maObjectRange =
218 5930 : drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(xSequence, rViewInformation2D);
219 6877 : }
220 : }
221 :
222 10966 : return maObjectRange;
223 : }
224 :
225 11565 : void ViewObjectContact::ActionChanged()
226 : {
227 11565 : if(!mbLazyInvalidate)
228 : {
229 : // set local flag
230 5492 : mbLazyInvalidate = true;
231 :
232 : // force ObjectRange
233 5492 : getObjectRange();
234 :
235 5492 : if(!maObjectRange.isEmpty())
236 : {
237 : // invalidate current valid range
238 4975 : GetObjectContact().InvalidatePartOfView(maObjectRange);
239 :
240 : // reset ObjectRange, it needs to be recalculated
241 4975 : maObjectRange.reset();
242 : }
243 :
244 : // register at OC for lazy invalidate
245 5492 : GetObjectContact().setLazyInvalidate(*this);
246 : }
247 11565 : }
248 :
249 90444 : void ViewObjectContact::triggerLazyInvalidate()
250 : {
251 90444 : if(mbLazyInvalidate)
252 : {
253 : // reset flag
254 5460 : mbLazyInvalidate = false;
255 :
256 : // force ObjectRange
257 5460 : getObjectRange();
258 :
259 5460 : if(!maObjectRange.isEmpty())
260 : {
261 : // invalidate current valid range
262 4938 : GetObjectContact().InvalidatePartOfView(maObjectRange);
263 : }
264 : }
265 90444 : }
266 :
267 : // Take some action when new objects are inserted
268 461 : void ViewObjectContact::ActionChildInserted(ViewContact& rChild)
269 : {
270 : // force creation of the new VOC and trigger it's refresh, so it
271 : // will take part in LazyInvalidate immediately
272 461 : rChild.GetViewObjectContact(GetObjectContact()).ActionChanged();
273 :
274 : // forward action to ObjectContact
275 : // const ViewObjectContact& rChildVOC = rChild.GetViewObjectContact(GetObjectContact());
276 : // GetObjectContact().InvalidatePartOfView(rChildVOC.getObjectRange());
277 461 : }
278 :
279 18293 : void ViewObjectContact::checkForPrimitive2DAnimations()
280 : {
281 : // remove old one
282 18293 : if(mpPrimitiveAnimation)
283 : {
284 0 : delete mpPrimitiveAnimation;
285 0 : mpPrimitiveAnimation = 0;
286 : }
287 :
288 : // check for animated primitives
289 18293 : if(mxPrimitive2DSequence.hasElements())
290 : {
291 18280 : const bool bTextAnimationAllowed(GetObjectContact().IsTextAnimationAllowed());
292 18280 : const bool bGraphicAnimationAllowed(GetObjectContact().IsGraphicAnimationAllowed());
293 :
294 18280 : if(bTextAnimationAllowed || bGraphicAnimationAllowed)
295 : {
296 18280 : AnimatedExtractingProcessor2D aAnimatedExtractor(GetObjectContact().getViewInformation2D(),
297 36560 : bTextAnimationAllowed, bGraphicAnimationAllowed);
298 18280 : aAnimatedExtractor.process(mxPrimitive2DSequence);
299 :
300 18280 : if(aAnimatedExtractor.getPrimitive2DSequence().hasElements())
301 : {
302 : // dervied primitiveList is animated, setup new PrimitiveAnimation
303 0 : mpPrimitiveAnimation = new sdr::animation::PrimitiveAnimation(*this, aAnimatedExtractor.getPrimitive2DSequence());
304 18280 : }
305 : }
306 : }
307 18293 : }
308 :
309 18627 : drawinglayer::primitive2d::Primitive2DSequence ViewObjectContact::createPrimitive2DSequence(const DisplayInfo& rDisplayInfo) const
310 : {
311 : // get the view-independent Primitive from the viewContact
312 18627 : drawinglayer::primitive2d::Primitive2DSequence xRetval(GetViewContact().getViewIndependentPrimitive2DSequence());
313 :
314 18627 : if(xRetval.hasElements())
315 : {
316 : // handle GluePoint
317 18093 : if(!GetObjectContact().isOutputToPrinter() && GetObjectContact().AreGluePointsVisible())
318 : {
319 0 : const drawinglayer::primitive2d::Primitive2DSequence xGlue(GetViewContact().createGluePointPrimitive2DSequence());
320 :
321 0 : if(xGlue.hasElements())
322 : {
323 0 : drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, xGlue);
324 0 : }
325 : }
326 :
327 : // handle ghosted
328 18093 : if(isPrimitiveGhosted(rDisplayInfo))
329 : {
330 0 : const basegfx::BColor aRGBWhite(1.0, 1.0, 1.0);
331 0 : const basegfx::BColorModifier aBColorModifier(aRGBWhite, 0.5, basegfx::BCOLORMODIFYMODE_INTERPOLATE);
332 0 : const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::ModifiedColorPrimitive2D(xRetval, aBColorModifier));
333 0 : xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
334 : }
335 : }
336 :
337 18627 : return xRetval;
338 : }
339 :
340 28569 : drawinglayer::primitive2d::Primitive2DSequence ViewObjectContact::getPrimitive2DSequence(const DisplayInfo& rDisplayInfo) const
341 : {
342 28569 : drawinglayer::primitive2d::Primitive2DSequence xNewPrimitiveSequence;
343 :
344 : // take care of redirectors and create new list
345 28569 : ViewObjectContactRedirector* pRedirector = GetObjectContact().GetViewObjectContactRedirector();
346 :
347 28569 : if(pRedirector)
348 : {
349 3812 : xNewPrimitiveSequence = pRedirector->createRedirectedPrimitive2DSequence(*this, rDisplayInfo);
350 : }
351 : else
352 : {
353 24757 : xNewPrimitiveSequence = createPrimitive2DSequence(rDisplayInfo);
354 : }
355 :
356 : // local up-to-date checks. New list different from local one?
357 28569 : if(!drawinglayer::primitive2d::arePrimitive2DSequencesEqual(mxPrimitive2DSequence, xNewPrimitiveSequence))
358 : {
359 : // has changed, copy content
360 18293 : const_cast< ViewObjectContact* >(this)->mxPrimitive2DSequence = xNewPrimitiveSequence;
361 :
362 : // check for animated stuff
363 18293 : const_cast< ViewObjectContact* >(this)->checkForPrimitive2DAnimations();
364 :
365 : // always update object range when PrimitiveSequence changes
366 18293 : const drawinglayer::geometry::ViewInformation2D& rViewInformation2D(GetObjectContact().getViewInformation2D());
367 : const_cast< ViewObjectContact* >(this)->maObjectRange =
368 18293 : drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(mxPrimitive2DSequence, rViewInformation2D);
369 : }
370 :
371 : // return current Primitive2DSequence
372 28569 : return mxPrimitive2DSequence;
373 : }
374 :
375 0 : bool ViewObjectContact::isPrimitiveVisible(const DisplayInfo& /*rDisplayInfo*/) const
376 : {
377 : // default: always visible
378 0 : return true;
379 : }
380 :
381 15592 : bool ViewObjectContact::isPrimitiveGhosted(const DisplayInfo& rDisplayInfo) const
382 : {
383 : // default: standard check
384 15592 : return (GetObjectContact().DoVisualizeEnteredGroup() && !GetObjectContact().isOutputToPrinter() && rDisplayInfo.IsGhostedDrawModeActive());
385 : }
386 :
387 263481 : drawinglayer::primitive2d::Primitive2DSequence ViewObjectContact::getPrimitive2DSequenceHierarchy(DisplayInfo& rDisplayInfo) const
388 : {
389 263481 : drawinglayer::primitive2d::Primitive2DSequence xRetval;
390 :
391 : // check model-view visibility
392 263481 : if(isPrimitiveVisible(rDisplayInfo))
393 : {
394 21691 : xRetval = getPrimitive2DSequence(rDisplayInfo);
395 :
396 21691 : if(xRetval.hasElements())
397 : {
398 : // get ranges
399 21205 : const drawinglayer::geometry::ViewInformation2D& rViewInformation2D(GetObjectContact().getViewInformation2D());
400 21205 : const basegfx::B2DRange aObjectRange(drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(xRetval, rViewInformation2D));
401 21205 : const basegfx::B2DRange aViewRange(rViewInformation2D.getViewport());
402 :
403 : // check geometrical visibility
404 21205 : if(!aViewRange.isEmpty() && !aViewRange.overlaps(aObjectRange))
405 : {
406 : // not visible, release
407 3041 : xRetval.realloc(0);
408 : }
409 : }
410 : }
411 :
412 263481 : return xRetval;
413 : }
414 :
415 40019 : drawinglayer::primitive2d::Primitive2DSequence ViewObjectContact::getPrimitive2DSequenceSubHierarchy(DisplayInfo& rDisplayInfo) const
416 : {
417 40019 : const sal_uInt32 nSubHierarchyCount(GetViewContact().GetObjectCount());
418 40019 : drawinglayer::primitive2d::Primitive2DSequence xSeqRetval;
419 :
420 336650 : for(sal_uInt32 a(0); a < nSubHierarchyCount; a++)
421 : {
422 296631 : const ViewObjectContact& rCandidate(GetViewContact().GetViewContact(a).GetViewObjectContact(GetObjectContact()));
423 :
424 296631 : drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xSeqRetval, rCandidate.getPrimitive2DSequenceHierarchy(rDisplayInfo));
425 : }
426 :
427 40019 : return xSeqRetval;
428 : }
429 : } // end of namespace contact
430 : } // end of namespace sdr
431 :
432 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|