LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewcontact.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 79 103 76.7 %
Date: 2014-11-03 Functions: 16 24 66.7 %
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 <svx/sdr/contact/viewcontact.hxx>
      21             : #include <svx/sdr/contact/viewobjectcontact.hxx>
      22             : #include <svx/sdr/contact/objectcontact.hxx>
      23             : #include <basegfx/polygon/b2dpolygon.hxx>
      24             : #include <basegfx/polygon/b2dpolygontools.hxx>
      25             : #include <basegfx/color/bcolor.hxx>
      26             : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      27             : #include <basegfx/matrix/b2dhommatrix.hxx>
      28             : #include <sdr/contact/objectcontactofpageview.hxx>
      29             : #include <tools/debug.hxx>
      30             : 
      31             : 
      32             : 
      33             : namespace sdr
      34             : {
      35             :     namespace contact
      36             :     {
      37             :         // Create a Object-Specific ViewObjectContact, set ViewContact and
      38             :         // ObjectContact. Always needs to return something. Default is to create
      39             :         // a standard ViewObjectContact containing the given ObjectContact and *this
      40           0 :         ViewObjectContact& ViewContact::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
      41             :         {
      42           0 :             return *(new ViewObjectContact(rObjectContact, *this));
      43             :         }
      44             : 
      45      216410 :         ViewContact::ViewContact()
      46             :         :   maViewObjectContactVector(),
      47      216410 :             mxViewIndependentPrimitive2DSequence()
      48             :         {
      49      216410 :         }
      50             : 
      51             :         // Methods to react on start getting viewed or stop getting
      52             :         // viewed. This info is derived from the count of members of
      53             :         // registered ViewObjectContacts. Default does nothing.
      54       57992 :         void ViewContact::StartGettingViewed()
      55             :         {
      56       57992 :         }
      57             : 
      58       55754 :         void ViewContact::StopGettingViewed()
      59             :         {
      60       55754 :         }
      61             : 
      62      428464 :         ViewContact::~ViewContact()
      63             :         {
      64      214232 :             deleteAllVOCs();
      65      214232 :         }
      66             : 
      67      523966 :         void ViewContact::deleteAllVOCs()
      68             :         {
      69             :             // get rid of all VOCs
      70             :             // #i84257# To avoid that each 'delete pCandidate' again uses
      71             :             // the local RemoveViewObjectContact with a search and removal in the
      72             :             // vector, simply copy and clear local vector.
      73      523966 :             std::vector< ViewObjectContact* > aLocalVOCList(maViewObjectContactVector);
      74      523966 :             maViewObjectContactVector.clear();
      75             : 
      76     1048425 :             while(!aLocalVOCList.empty())
      77             :             {
      78         493 :                 ViewObjectContact* pCandidate = aLocalVOCList.back();
      79         493 :                 aLocalVOCList.pop_back();
      80             :                 DBG_ASSERT(pCandidate, "Corrupted ViewObjectContactList in VC (!)");
      81             : 
      82             :                 // ViewObjectContacts only make sense with View and Object contacts.
      83             :                 // When the contact to the SdrObject is deleted like in this case,
      84             :                 // all ViewObjectContacts can be deleted, too.
      85         493 :                 delete pCandidate;
      86             :             }
      87             : 
      88             :             // assert when there were new entries added during deletion
      89      523966 :             DBG_ASSERT(maViewObjectContactVector.empty(), "Corrupted ViewObjectContactList in VC (!)");
      90      523966 :         }
      91             : 
      92             :         // get a Object-specific ViewObjectContact for a specific
      93             :         // ObjectContact (->View). Always needs to return something.
      94      607541 :         ViewObjectContact& ViewContact::GetViewObjectContact(ObjectContact& rObjectContact)
      95             :         {
      96      607541 :             ViewObjectContact* pRetval = 0L;
      97      607541 :             const sal_uInt32 nCount(maViewObjectContactVector.size());
      98             : 
      99             :             // first search if there exists a VOC for the given OC
     100     1161031 :             for(sal_uInt32 a(0); !pRetval && a < nCount; a++)
     101             :             {
     102      553490 :                 ViewObjectContact* pCandidate = maViewObjectContactVector[a];
     103             :                 DBG_ASSERT(pCandidate, "Corrupted ViewObjectContactList (!)");
     104             : 
     105      553490 :                 if(&(pCandidate->GetObjectContact()) == &rObjectContact)
     106             :                 {
     107      545005 :                     pRetval = pCandidate;
     108             :                 }
     109             :             }
     110             : 
     111      607541 :             if(!pRetval)
     112             :             {
     113             :                 // create a new one. It's inserted to the local list from the
     114             :                 // ViewObjectContact constructor via AddViewObjectContact()
     115       62536 :                 pRetval = &CreateObjectSpecificViewObjectContact(rObjectContact);
     116             :             }
     117             : 
     118      607541 :             return *pRetval;
     119             :         }
     120             : 
     121             :         // A new ViewObjectContact was created and shall be remembered.
     122       62536 :         void ViewContact::AddViewObjectContact(ViewObjectContact& rVOContact)
     123             :         {
     124       62536 :             maViewObjectContactVector.push_back(&rVOContact);
     125             : 
     126       62536 :             if(1L == maViewObjectContactVector.size())
     127             :             {
     128       57992 :                 StartGettingViewed();
     129             :             }
     130       62536 :         }
     131             : 
     132             :         // A ViewObjectContact was deleted and shall be forgotten.
     133       60791 :         void ViewContact::RemoveViewObjectContact(ViewObjectContact& rVOContact)
     134             :         {
     135       60791 :             std::vector< ViewObjectContact* >::iterator aFindResult = std::find(maViewObjectContactVector.begin(), maViewObjectContactVector.end(), &rVOContact);
     136             : 
     137       60791 :             if(aFindResult != maViewObjectContactVector.end())
     138             :             {
     139       60298 :                 maViewObjectContactVector.erase(aFindResult);
     140             : 
     141       60298 :                 if(maViewObjectContactVector.empty())
     142             :                 {
     143             :                     // This may need to get asynchron later since it eventually triggers
     144             :                     // deletes of OCs where the VOC is still added.
     145       55754 :                     StopGettingViewed();
     146             :                 }
     147             :             }
     148       60791 :         }
     149             : 
     150             :         // Test if this ViewContact has ViewObjectContacts at all. This can
     151             :         // be used to test if this ViewContact is visualized ATM or not
     152          60 :         bool ViewContact::HasViewObjectContacts(bool bExcludePreviews) const
     153             :         {
     154          60 :             const sal_uInt32 nCount(maViewObjectContactVector.size());
     155             : 
     156          60 :             if(bExcludePreviews)
     157             :             {
     158          60 :                 for(sal_uInt32 a(0); a < nCount; a++)
     159             :                 {
     160           0 :                     if(!maViewObjectContactVector[a]->GetObjectContact().IsPreviewRenderer())
     161             :                     {
     162           0 :                         return true;
     163             :                     }
     164             :                 }
     165             : 
     166          60 :                 return false;
     167             :             }
     168             :             else
     169             :             {
     170           0 :                 return (0L != nCount);
     171             :             }
     172             :         }
     173             : 
     174             :         // Test if this ViewContact has ViewObjectContacts at all. This can
     175             :         // be used to test if this ViewContact is visualized ATM or not
     176           0 :         bool ViewContact::isAnimatedInAnyViewObjectContact() const
     177             :         {
     178           0 :             const sal_uInt32 nCount(maViewObjectContactVector.size());
     179             : 
     180           0 :             for(sal_uInt32 a(0); a < nCount; a++)
     181             :             {
     182           0 :                 if(maViewObjectContactVector[a]->isAnimated())
     183             :                 {
     184           0 :                     return true;
     185             :                 }
     186             :             }
     187             : 
     188           0 :             return false;
     189             :         }
     190             : 
     191             :         // Access to possible sub-hierarchy and parent. GetObjectCount() default is 0L
     192             :         // and GetViewContact default pops up an assert since it's an error if
     193             :         // GetObjectCount has a result != 0 and it's not overloaded.
     194       24060 :         sal_uInt32 ViewContact::GetObjectCount() const
     195             :         {
     196             :             // no sub-objects
     197       24060 :             return 0;
     198             :         }
     199             : 
     200           0 :         ViewContact& ViewContact::GetViewContact(sal_uInt32 /*nIndex*/) const
     201             :         {
     202             :             // This is the default implementation; call would be an error
     203             :             OSL_FAIL("ViewContact::GetViewContact: This call needs to be overloaded when GetObjectCount() can return results != 0 (!)");
     204           0 :             return (ViewContact&)(*this);
     205             :         }
     206             : 
     207           0 :         ViewContact* ViewContact::GetParentContact() const
     208             :         {
     209             :             // default has no parent
     210           0 :             return 0;
     211             :         }
     212             : 
     213       90554 :         void ViewContact::ActionChildInserted(ViewContact& rChild)
     214             :         {
     215             :             // propagate change to all exsisting visualisations which
     216             :             // will force a VOC for the new child and invalidate its range
     217       90554 :             const sal_uInt32 nCount(maViewObjectContactVector.size());
     218             : 
     219       91761 :             for(sal_uInt32 a(0); a < nCount; a++)
     220             :             {
     221        1207 :                 ViewObjectContact* pCandidate = maViewObjectContactVector[a];
     222             :                 DBG_ASSERT(pCandidate, "ViewContact::GetViewObjectContact() invalid ViewObjectContactList (!)");
     223             : 
     224             :                 // take action at all VOCs. At the VOCs ObjectContact the initial
     225             :                 // rectangle will be invalidated at the associated OutputDevice.
     226        1207 :                 pCandidate->ActionChildInserted(rChild);
     227             :             }
     228       90554 :         }
     229             : 
     230             :         // React on changes of the object of this ViewContact
     231     1599432 :         void ViewContact::ActionChanged()
     232             :         {
     233             :             // propagate change to all existing VOCs. This will invalidate
     234             :             // all drawn visualisations in all known views
     235     1599432 :             const sal_uInt32 nCount(maViewObjectContactVector.size());
     236             : 
     237     1617578 :             for(sal_uInt32 a(0); a < nCount; a++)
     238             :             {
     239       18146 :                 ViewObjectContact* pCandidate = maViewObjectContactVector[a];
     240             :                 DBG_ASSERT(pCandidate, "ViewContact::GetViewObjectContact() invalid ViewObjectContactList (!)");
     241             : 
     242       18146 :                 pCandidate->ActionChanged();
     243             :             }
     244     1599432 :         }
     245             : 
     246             :         // access to SdrObject and/or SdrPage. May return 0L like the default
     247             :         // implementations do. Needs to be overloaded as needed.
     248        2466 :         SdrObject* ViewContact::TryToGetSdrObject() const
     249             :         {
     250        2466 :             return 0L;
     251             :         }
     252             : 
     253           0 :         SdrPage* ViewContact::TryToGetSdrPage() const
     254             :         {
     255           0 :             return 0L;
     256             :         }
     257             : 
     258             : 
     259             :         // primitive stuff
     260             : 
     261           0 :         drawinglayer::primitive2d::Primitive2DSequence ViewContact::createViewIndependentPrimitive2DSequence() const
     262             :         {
     263             :             // This is the default implementation and should never be called (see header). If this is called,
     264             :             // someone implemented a ViewContact (VC) visualisation object without defining the visualisation by
     265             :             // providing a seqence of primitives -> which cannot be correct.
     266             :             // Since we have no access to any known model data here, the default implementation creates a yellow placeholder
     267             :             // hairline polygon with a default size of (1000, 1000, 5000, 3000)
     268             :             OSL_FAIL("ViewContact::createViewIndependentPrimitive2DSequence(): Never call the fallback base implementation, this is always an error (!)");
     269           0 :             const basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(basegfx::B2DRange(1000.0, 1000.0, 5000.0, 3000.0)));
     270           0 :             const basegfx::BColor aYellow(1.0, 1.0, 0.0);
     271             :             const drawinglayer::primitive2d::Primitive2DReference xReference(
     272           0 :                 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aOutline, aYellow));
     273             : 
     274           0 :             return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
     275             :         }
     276             : 
     277       98517 :         drawinglayer::primitive2d::Primitive2DSequence ViewContact::getViewIndependentPrimitive2DSequence() const
     278             :         {
     279             :             // local up-to-date checks. Create new list and compare.
     280       98517 :             drawinglayer::primitive2d::Primitive2DSequence xNew(createViewIndependentPrimitive2DSequence());
     281             : 
     282       98517 :             if(xNew.hasElements())
     283             :             {
     284             :                 // allow evtl. embedding in object-specific infos, e.g. Name, Title, Description
     285       91381 :                 xNew = embedToObjectSpecificInformation(xNew);
     286             :             }
     287             : 
     288       98517 :             if(!drawinglayer::primitive2d::arePrimitive2DSequencesEqual(mxViewIndependentPrimitive2DSequence, xNew))
     289             :             {
     290             :                 // has changed, copy content
     291       60246 :                 const_cast< ViewContact* >(this)->mxViewIndependentPrimitive2DSequence = xNew;
     292             :             }
     293             : 
     294             :             // return current Primitive2DSequence
     295       98517 :             return mxViewIndependentPrimitive2DSequence;
     296             :         }
     297             : 
     298             :         // add Gluepoints (if available)
     299           0 :         drawinglayer::primitive2d::Primitive2DSequence ViewContact::createGluePointPrimitive2DSequence() const
     300             :         {
     301             :             // default returns empty reference
     302           0 :             return drawinglayer::primitive2d::Primitive2DSequence();
     303             :         }
     304             : 
     305        7465 :         drawinglayer::primitive2d::Primitive2DSequence ViewContact::embedToObjectSpecificInformation(const drawinglayer::primitive2d::Primitive2DSequence& rSource) const
     306             :         {
     307             :             // nothing to do for default
     308        7465 :             return rSource;
     309             :         }
     310             : 
     311      309734 :         void ViewContact::flushViewObjectContacts(bool bWithHierarchy)
     312             :         {
     313      309734 :             if(bWithHierarchy)
     314             :             {
     315             :                 // flush DrawingLayer hierarchy
     316      309728 :                 const sal_uInt32 nCount(GetObjectCount());
     317             : 
     318      525304 :                 for(sal_uInt32 a(0); a < nCount; a++)
     319             :                 {
     320      215576 :                     ViewContact& rChild = GetViewContact(a);
     321      215576 :                     rChild.flushViewObjectContacts(bWithHierarchy);
     322             :                 }
     323             :             }
     324             : 
     325             :             // delete local VOCs
     326      309734 :             deleteAllVOCs();
     327      309734 :         }
     328             :     } // end of namespace contact
     329             : } // end of namespace sdr
     330             : 
     331             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10