LCOV - code coverage report
Current view: top level - libreoffice/sw/inc - ndhints.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 32 43 74.4 %
Date: 2012-12-27 Functions: 23 30 76.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             : #ifndef _NDHINTS_HXX
      20             : #define _NDHINTS_HXX
      21             : 
      22             : 
      23             : #include <tools/mempool.hxx>
      24             : #include <o3tl/sorted_vector.hxx>
      25             : 
      26             : #include "swtypes.hxx"
      27             : 
      28             : class SwTxtNode;
      29             : class SwRegHistory;                 // Is in RolBck.hxx.
      30             : class SwTxtAttr;
      31             : class SwTxtAttrNesting;
      32             : 
      33             : class SfxPoolItem;
      34             : class SfxItemSet;
      35             : class SwDoc;
      36             : 
      37             : typedef enum {
      38             :     COPY = true,
      39             :     NEW  = false,
      40             : } CopyOrNew_t;
      41             : 
      42             : /// if COPY then pTxtNode must be given!
      43             : SW_DLLPRIVATE SwTxtAttr *
      44             : MakeTxtAttr( SwDoc & rDoc, SfxPoolItem & rNew,
      45             :         xub_StrLen const nStt, xub_StrLen const nEnd,
      46             :         CopyOrNew_t const bIsCopy = NEW, SwTxtNode *const pTxtNode = 0);
      47             : SW_DLLPRIVATE SwTxtAttr *
      48             : MakeTxtAttr( SwDoc & rDoc, const SfxItemSet & rSet,
      49             :         xub_StrLen nStt, xub_StrLen nEnd );
      50             : 
      51             : /// create redline dummy text hint that must not be inserted into hints array
      52             : SW_DLLPRIVATE SwTxtAttr*
      53             : MakeRedlineTxtAttr( SwDoc & rDoc, SfxPoolItem& rAttr );
      54             : 
      55             : 
      56             : /** Class SwpHints is derived indirectly via SwpHts, because only the
      57             :    class SwTxtNode should be allowed to insert and remove attributes.
      58             :    Other classes like the Frames are given only reading access via
      59             :    the index-operator.
      60             :    Size when created is 1 because an array is created only if
      61             :    also a hint is inserted. */
      62             : 
      63             :  /// Class SwpHtStart/End
      64             : 
      65             : struct CompareSwpHtStart
      66             : {
      67             :     bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
      68             : };
      69        4678 : class SwpHtStart : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtStart,
      70             :     o3tl::find_partialorder_ptrequals> {};
      71             : 
      72             : struct CompareSwpHtEnd
      73             : {
      74             :     bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
      75             : };
      76        4678 : class SwpHtEnd : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtEnd,
      77             :     o3tl::find_partialorder_ptrequals> {};
      78             : 
      79             : /// Class SwpHintsArr
      80             : 
      81             : 
      82             : /// the Hints array
      83        4678 : class SwpHintsArray
      84             : {
      85             : 
      86             : protected:
      87             :     SwpHtStart m_HintStarts;
      88             :     SwpHtEnd   m_HintEnds;
      89             : 
      90             :     //FIXME: why are the non-const methods public?
      91             : public:
      92             :     void Insert( const SwTxtAttr *pHt );
      93             :     void DeleteAtPos( const sal_uInt16 nPosInStart );
      94             :     bool Resort();
      95             :     SwTxtAttr * Cut( const sal_uInt16 nPosInStart );
      96             : 
      97        1222 :     inline const SwTxtAttr * GetStart( const sal_uInt16 nPos ) const
      98        1222 :         { return m_HintStarts[nPos]; }
      99           0 :     inline const SwTxtAttr * GetEnd  ( const sal_uInt16 nPos ) const
     100           0 :         { return m_HintEnds  [nPos]; }
     101      560417 :     inline       SwTxtAttr * GetStart( const sal_uInt16 nPos )
     102      560417 :         { return m_HintStarts[nPos]; }
     103        8981 :     inline       SwTxtAttr * GetEnd  ( const sal_uInt16 nPos )
     104        8981 :         { return m_HintEnds  [nPos]; }
     105             : 
     106        7459 :     inline sal_uInt16 GetEndCount()   const { return m_HintEnds  .size(); }
     107        7337 :     inline sal_uInt16 GetStartCount() const { return m_HintStarts.size(); }
     108             : 
     109             :     inline sal_uInt16 GetStartOf( const SwTxtAttr *pHt ) const;
     110             :     sal_uInt16 GetPos( const SwTxtAttr *pHt ) const;
     111             : 
     112      554696 :     inline SwTxtAttr * GetTextHint( const sal_uInt16 nIdx )
     113      554696 :         { return GetStart(nIdx); }
     114      422488 :     inline const SwTxtAttr * operator[]( const sal_uInt16 nIdx ) const
     115      422488 :         { return m_HintStarts[nIdx]; }
     116      644775 :     inline sal_uInt16 Count() const { return m_HintStarts.size(); }
     117             : 
     118             : #ifdef DBG_UTIL
     119             :     bool Check() const;
     120             : #endif
     121             : };
     122             : 
     123             : 
     124             : // Class SwpHints
     125             : 
     126             : 
     127             : /// public interface
     128        2219 : class SwpHints : public SwpHintsArray
     129             : {
     130             : private:
     131             :     SwRegHistory* m_pHistory;          ///< for Undo
     132             : 
     133             :     bool m_bFontChange          : 1;   ///< font change
     134             :     /// true: the Node is in Split and Frames are moved
     135             :     bool m_bInSplitNode         : 1;
     136             :     /// m_bHasHiddenParaField is invalid, call CalcHiddenParaField()
     137             :     bool m_bCalcHiddenParaField : 1;
     138             :     bool m_bHasHiddenParaField  : 1;   ///< HiddenParaFld
     139             :     bool m_bFootnote            : 1;   ///< footnotes
     140             :     bool m_bDDEFields           : 1;   ///< the TextNode has DDE fields
     141             : 
     142             :     /// records a new attibute in m_pHistory.
     143             :     void NoteInHistory( SwTxtAttr *pAttr, const bool bNew = false );
     144             : 
     145             :     void CalcFlags( );
     146             : 
     147             :     /** Delete methods may only be called by the TextNode!
     148             :        Because the TextNode also guarantees removal of the Character for
     149             :        attributes without an end. */
     150             :     friend class SwTxtNode;
     151             :     void DeleteAtPos( const sal_uInt16 nPos );
     152             :     /// Delete the given Hint. The Hint must actually be in the array!
     153             :     void Delete( SwTxtAttr* pTxtHt );
     154             : 
     155           0 :     inline void SetInSplitNode(bool bInSplit) { m_bInSplitNode = bInSplit; }
     156           0 :     inline void SetCalcHiddenParaField() { m_bCalcHiddenParaField = true; }
     157           0 :     inline void SetHiddenParaField( const bool bNew )
     158           0 :         { m_bHasHiddenParaField = bNew; }
     159        6100 :     inline bool HasHiddenParaField() const
     160             :     {
     161        6100 :         if ( m_bCalcHiddenParaField )
     162             :         {
     163           0 :             (const_cast<SwpHints*>(this))->CalcHiddenParaField();
     164             :         }
     165        6100 :         return m_bHasHiddenParaField;
     166             :     }
     167             : 
     168             :     void InsertNesting(SwTxtAttrNesting & rNewHint);
     169             :     bool TryInsertNesting(SwTxtNode & rNode, SwTxtAttrNesting & rNewHint);
     170             :     void BuildPortions( SwTxtNode& rNode, SwTxtAttr& rNewHint,
     171             :             const SetAttrMode nMode );
     172             :     bool MergePortions( SwTxtNode& rNode );
     173             : 
     174             : public:
     175             :     SwpHints();
     176             : 
     177       13869 :     inline bool CanBeDeleted() const    { return !Count(); }
     178             : 
     179             :     /// register a History, which receives all attribute changes (for Undo)
     180           0 :     void Register( SwRegHistory* pHist ) { m_pHistory = pHist; }
     181             :     /// deregister the currently registered History
     182           0 :     void DeRegister() { Register(0); }
     183           6 :     SwRegHistory* GetHistory() const    { return m_pHistory; }
     184             : 
     185             :     /// try to insert the hint
     186             :     /// @return true iff hint successfully inserted
     187             :     bool TryInsertHint( SwTxtAttr * const pHint, SwTxtNode & rNode,
     188             :             const SetAttrMode nMode = nsSetAttrMode::SETATTR_DEFAULT );
     189             : 
     190           0 :     inline bool HasFtn() const          { return m_bFootnote; }
     191          76 :     inline bool IsInSplitNode() const   { return m_bInSplitNode; }
     192             : 
     193             :     /// calc current value of m_bHasHiddenParaField, returns true iff changed
     194             :     bool CalcHiddenParaField();
     195             : 
     196        4678 :     DECL_FIXEDMEMPOOL_NEWDEL(SwpHints)
     197             : };
     198             : 
     199             : /// Output operator for text hints.
     200             : SvStream &operator<<(SvStream &aS, const SwpHints &rHints); //$ ostream
     201             : 
     202             : 
     203             : /// Inline Implementations
     204             : 
     205             : 
     206        8645 : inline sal_uInt16 SwpHintsArray::GetStartOf( const SwTxtAttr *pHt ) const
     207             : {
     208             :     SwpHtStart::const_iterator const it =
     209        8645 :         m_HintStarts.find(const_cast<SwTxtAttr*>(pHt));
     210        8645 :     if ( it == m_HintStarts.end() )
     211             :     {
     212           0 :         return USHRT_MAX;
     213             :     }
     214        8645 :     return it - m_HintStarts.begin();
     215             : }
     216             : 
     217          15 : inline SwTxtAttr *SwpHintsArray::Cut( const sal_uInt16 nPosInStart )
     218             : {
     219          15 :     SwTxtAttr *pHt = GetTextHint(nPosInStart);
     220          15 :     DeleteAtPos( nPosInStart );
     221          15 :     return pHt;
     222             : }
     223             : 
     224             : 
     225             : #endif
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10