LCOV - code coverage report
Current view: top level - libreoffice/sc/inc - chartlis.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 4 6 66.7 %
Date: 2012-12-27 Functions: 4 6 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             : #ifndef SC_CHARTLIS_HXX
      21             : #define SC_CHARTLIS_HXX
      22             : 
      23             : 
      24             : #include <vcl/timer.hxx>
      25             : #include <svl/listener.hxx>
      26             : #include "rangelst.hxx"
      27             : #include "token.hxx"
      28             : #include "externalrefmgr.hxx"
      29             : 
      30             : #include <memory>
      31             : #include <vector>
      32             : #include <list>
      33             : 
      34             : #include <boost/unordered_set.hpp>
      35             : #include <boost/scoped_ptr.hpp>
      36             : #include <boost/ptr_container/ptr_map.hpp>
      37             : 
      38             : class ScDocument;
      39             : class ScChartUnoData;
      40             : #include <com/sun/star/chart/XChartData.hpp>
      41             : #include <com/sun/star/chart/XChartDataChangeEventListener.hpp>
      42             : 
      43             : class SC_DLLPUBLIC ScChartListener : public SvtListener
      44             : {
      45             : public:
      46             :     class ExternalRefListener : public ScExternalRefManager::LinkListener
      47             :     {
      48             :     public:
      49             :         ExternalRefListener(ScChartListener& rParent, ScDocument* pDoc);
      50             :         virtual ~ExternalRefListener();
      51             :         virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType);
      52             :         void addFileId(sal_uInt16 nFileId);
      53             :         void removeFileId(sal_uInt16 nFileId);
      54             :         ::boost::unordered_set<sal_uInt16>& getAllFileIds();
      55             : 
      56             :     private:
      57             :         ExternalRefListener();
      58             :         ExternalRefListener(const ExternalRefListener& r);
      59             : 
      60             :         ScChartListener& mrParent;
      61             :         ::boost::unordered_set<sal_uInt16> maFileIds;
      62             :         ScDocument*                 mpDoc;
      63             :     };
      64             : 
      65             : private:
      66             : 
      67             :     boost::scoped_ptr<ExternalRefListener> mpExtRefListener;
      68             :     boost::scoped_ptr<std::vector<ScTokenRef> > mpTokens;
      69             : 
      70             :     rtl::OUString maName;
      71             :     ScChartUnoData* pUnoData;
      72             :     ScDocument*     mpDoc;
      73             :     bool            bUsed:1;  // for ScChartListenerCollection::FreeUnused
      74             :     bool            bDirty:1;
      75             :     bool            bSeriesRangesScheduled:1;
      76             : 
      77             :                     // not implemented
      78             :     ScChartListener& operator=( const ScChartListener& );
      79             : 
      80             : public:
      81             :     ScChartListener( const rtl::OUString& rName, ScDocument* pDoc,
      82             :                      const ScRangeListRef& rRangeListRef );
      83             :     ScChartListener( const rtl::OUString& rName, ScDocument* pDoc,
      84             :                      ::std::vector<ScTokenRef>* pTokens );
      85             :     ScChartListener( const ScChartListener& );
      86             :     ~ScChartListener();
      87             : 
      88             :     const rtl::OUString& GetName() const;
      89             : 
      90             :     void            SetUno( const com::sun::star::uno::Reference< com::sun::star::chart::XChartDataChangeEventListener >& rListener,
      91             :                             const com::sun::star::uno::Reference< com::sun::star::chart::XChartData >& rSource );
      92             :     com::sun::star::uno::Reference< com::sun::star::chart::XChartDataChangeEventListener >  GetUnoListener() const;
      93             :     com::sun::star::uno::Reference< com::sun::star::chart::XChartData >                     GetUnoSource() const;
      94             : 
      95          40 :     bool            IsUno() const   { return (pUnoData != NULL); }
      96             : 
      97             :     virtual void    Notify( SvtBroadcaster& rBC, const SfxHint& rHint );
      98             :     void            StartListeningTo();
      99             :     void            EndListeningTo();
     100             :     void            ChangeListening( const ScRangeListRef& rRangeListRef,
     101             :                                     bool bDirty = false );
     102             :     void            Update();
     103             :     ScRangeListRef  GetRangeList() const;
     104             :     void            SetRangeList( const ScRangeListRef& rNew );
     105          40 :     bool            IsUsed() const { return bUsed; }
     106         120 :     void            SetUsed( bool bFlg ) { bUsed = bFlg; }
     107           0 :     bool            IsDirty() const { return bDirty; }
     108           0 :     void            SetDirty( bool bFlg ) { bDirty = bFlg; }
     109             : 
     110             :     void            UpdateChartIntersecting( const ScRange& rRange );
     111             : 
     112             :     // if chart series ranges are to be updated later on (e.g. DeleteTab, InsertTab)
     113             :     void            ScheduleSeriesRanges()      { bSeriesRangesScheduled = true; }
     114             :     void            UpdateScheduledSeriesRanges();
     115             :     void            UpdateSeriesRanges();
     116             : 
     117             :     ExternalRefListener* GetExtRefListener();
     118             :     void            SetUpdateQueue();
     119             : 
     120             :     bool operator==( const ScChartListener& ) const;
     121             :     bool operator!=( const ScChartListener& r ) const;
     122             : };
     123             : 
     124             : // ============================================================================
     125             : 
     126             : class ScChartHiddenRangeListener
     127             : {
     128             : public:
     129             :     ScChartHiddenRangeListener();
     130             :     virtual ~ScChartHiddenRangeListener();
     131             :     virtual void notify() = 0;
     132             : };
     133             : 
     134             : // ============================================================================
     135             : 
     136             : class ScChartListenerCollection
     137             : {
     138             : public:
     139          82 :     struct RangeListenerItem
     140             :     {
     141             :         ScRange                     maRange;
     142             :         ScChartHiddenRangeListener* mpListener;
     143             :         explicit RangeListenerItem(const ScRange& rRange, ScChartHiddenRangeListener* p);
     144             :     };
     145             : 
     146             :     typedef boost::ptr_map<rtl::OUString, ScChartListener> ListenersType;
     147             :     typedef boost::unordered_set<rtl::OUString, rtl::OUStringHash> StringSetType;
     148             : private:
     149             :     ListenersType maListeners;
     150             :     ::std::list<RangeListenerItem> maHiddenListeners;
     151             :     StringSetType maNonOleObjectNames;
     152             : 
     153             :     Timer           aTimer;
     154             :     ScDocument*     pDoc;
     155             : 
     156             :                     DECL_LINK(TimerHdl, void *);
     157             : 
     158             :                     // not implemented
     159             :     ScChartListenerCollection& operator=( const ScChartListenerCollection& );
     160             : 
     161             : public:
     162             :     ScChartListenerCollection( ScDocument* pDoc );
     163             :     ScChartListenerCollection( const ScChartListenerCollection& );
     164             :     ~ScChartListenerCollection();
     165             : 
     166             :                     // only needed after copy-ctor, if newly added to doc
     167             :     void            StartAllListeners();
     168             : 
     169             :     SC_DLLPUBLIC void insert(ScChartListener* pListener);
     170             :     ScChartListener* findByName(const rtl::OUString& rName);
     171             :     const ScChartListener* findByName(const rtl::OUString& rName) const;
     172             :     bool hasListeners() const;
     173             : 
     174             :     const ListenersType& getListeners() const;
     175             :     ListenersType& getListeners();
     176             :     StringSetType& getNonOleObjectNames();
     177             : 
     178             :     /**
     179             :      * Create a unique name that's not taken by any existing chart listener
     180             :      * objects.  The name consists of a prefix given followed by a number.
     181             :      */
     182             :     rtl::OUString getUniqueName(const rtl::OUString& rPrefix) const;
     183             : 
     184             :     void            ChangeListening( const String& rName,
     185             :                                     const ScRangeListRef& rRangeListRef,
     186             :                                     bool bDirty = false );
     187             :     // use FreeUnused only the way it's used in ScDocument::UpdateChartListenerCollection
     188             :     void            FreeUnused();
     189             :     void            FreeUno( const com::sun::star::uno::Reference< com::sun::star::chart::XChartDataChangeEventListener >& rListener,
     190             :                              const com::sun::star::uno::Reference< com::sun::star::chart::XChartData >& rSource );
     191             :     void            StartTimer();
     192             :     void            UpdateDirtyCharts();
     193             :     SC_DLLPUBLIC void SetDirty();
     194             :     void            SetDiffDirty( const ScChartListenerCollection&,
     195             :                         bool bSetChartRangeLists = false );
     196             : 
     197             :     void            SetRangeDirty( const ScRange& rRange );     // for example rows/columns
     198             : 
     199             :     void            UpdateScheduledSeriesRanges();
     200             :     void            UpdateChartsContainingTab( SCTAB nTab );
     201             : 
     202             :     bool operator==( const ScChartListenerCollection& r ) const;
     203             :     bool operator!=( const ScChartListenerCollection& r ) const;
     204             : 
     205             :     /**
     206             :      * Start listening on hide/show change within specified cell range.  A
     207             :      * single listener may listen on multiple ranges when the caller passes
     208             :      * the same pointer multiple times with different ranges.
     209             :      *
     210             :      * Note that the caller is responsible for managing the life-cycle of the
     211             :      * listener instance.
     212             :      */
     213             :     void            StartListeningHiddenRange( const ScRange& rRange,
     214             :                                                ScChartHiddenRangeListener* pListener );
     215             : 
     216             :     /**
     217             :      * Remove all ranges associated with passed listener instance from the
     218             :      * list of hidden range listeners.  This does not delete the passed
     219             :      * listener instance.
     220             :      */
     221             :     void            EndListeningHiddenRange( ScChartHiddenRangeListener* pListener );
     222             : };
     223             : 
     224             : 
     225             : #endif
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10