LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewobjectcontact.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 105 129 81.4 %
Date: 2014-11-03 Functions: 18 23 78.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10