LCOV - code coverage report
Current view: top level - sw/inc - redline.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 54 82 65.9 %
Date: 2015-06-13 12:38:46 Functions: 27 41 65.9 %
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 INCLUDED_SW_INC_REDLINE_HXX
      20             : #define INCLUDED_SW_INC_REDLINE_HXX
      21             : 
      22             : #include <tools/datetime.hxx>
      23             : #include <rtl/ustring.hxx>
      24             : 
      25             : #include <pam.hxx>
      26             : #include <swtable.hxx>
      27             : 
      28             : #include <IDocumentRedlineAccess.hxx>
      29             : 
      30             : #include <svl/smplhint.hxx>
      31             : #include <vector>
      32             : 
      33             : class SfxItemSet;
      34             : class SwView;
      35             : 
      36             : class SW_DLLPUBLIC SwRedlineExtraData
      37             : {
      38             :     SwRedlineExtraData( const SwRedlineExtraData& ) SAL_DELETED_FUNCTION;
      39             :     SwRedlineExtraData& operator=( const SwRedlineExtraData& ) SAL_DELETED_FUNCTION;
      40             : 
      41             : protected:
      42        1606 :     SwRedlineExtraData() {}
      43             : 
      44             : public:
      45             :     virtual ~SwRedlineExtraData();
      46             :     virtual SwRedlineExtraData* CreateNew() const = 0;
      47             : 
      48             :     virtual void Reject( SwPaM& rPam ) const;
      49             :     virtual bool operator == ( const SwRedlineExtraData& ) const;
      50             : };
      51             : 
      52             : class SwRedlineExtraData_FormatColl : public SwRedlineExtraData
      53             : {
      54             :     OUString sFormatNm;
      55             :     SfxItemSet* pSet;
      56             :     sal_uInt16 nPoolId;
      57             : public:
      58             :     SwRedlineExtraData_FormatColl( const OUString& rColl, sal_uInt16 nPoolFormatId,
      59             :                                 const SfxItemSet* pSet = 0 );
      60             :     virtual ~SwRedlineExtraData_FormatColl();
      61             :     virtual SwRedlineExtraData* CreateNew() const SAL_OVERRIDE;
      62             :     virtual void Reject( SwPaM& rPam ) const SAL_OVERRIDE;
      63             :     virtual bool operator == ( const SwRedlineExtraData& ) const SAL_OVERRIDE;
      64             : 
      65             :     void SetItemSet( const SfxItemSet& rSet );
      66             : };
      67             : 
      68             : class SwRedlineExtraData_Format : public SwRedlineExtraData
      69             : {
      70             :     std::vector<sal_uInt16> aWhichIds;
      71             : 
      72             :     SwRedlineExtraData_Format( const SwRedlineExtraData_Format& rCpy );
      73             : 
      74             : public:
      75             :     SwRedlineExtraData_Format( const SfxItemSet& rSet );
      76             :     virtual ~SwRedlineExtraData_Format();
      77             :     virtual SwRedlineExtraData* CreateNew() const SAL_OVERRIDE;
      78             :     virtual void Reject( SwPaM& rPam ) const SAL_OVERRIDE;
      79             :     virtual bool operator == ( const SwRedlineExtraData& ) const SAL_OVERRIDE;
      80             : };
      81             : 
      82             : /*
      83             :  * This class is used to store 'redline' data regarding formatting changes,
      84             :  * e.g. - a text portion *was* italic and now is not italic,
      85             :  * e.g. - a text portion got a hightlight to it
      86             :  *
      87             :  * The way the information is stored is in an 'SfxItemSet' that holds all
      88             :  * the WhichIds with their values.
      89             :  */
      90             : class SW_DLLPUBLIC SwRedlineExtraData_FormattingChanges : public SwRedlineExtraData
      91             : {
      92             :     SfxItemSet* pSet;
      93             : 
      94             :     SwRedlineExtraData_FormattingChanges( const SwRedlineExtraData_FormattingChanges& rCpy );
      95             : 
      96             : public:
      97             :     SwRedlineExtraData_FormattingChanges( const SfxItemSet* pItemSet );
      98             :     virtual ~SwRedlineExtraData_FormattingChanges();
      99             :     virtual SwRedlineExtraData* CreateNew() const SAL_OVERRIDE;
     100             :     virtual void Reject( SwPaM& rPam ) const SAL_OVERRIDE;
     101             :     virtual bool operator == ( const SwRedlineExtraData& ) const SAL_OVERRIDE;
     102           8 :     SfxItemSet* GetItemSet( ) const { return pSet; }
     103             : };
     104             : 
     105             : class SW_DLLPUBLIC SwRedlineData
     106             : {
     107             :     friend class SwRangeRedline;
     108             :     SwRedlineData* pNext;       // Points to other data.
     109             :     SwRedlineExtraData* pExtraData;
     110             : 
     111             :     OUString sComment;
     112             :     DateTime aStamp;
     113             :     RedlineType_t eType;
     114             :     sal_uInt16 nAuthor, nSeqNo;
     115             : 
     116             : public:
     117             :     SwRedlineData( RedlineType_t eT, sal_uInt16 nAut );
     118             :     SwRedlineData( const SwRedlineData& rCpy, bool bCpyNext = true );
     119             : 
     120             :     // For sw3io: pNext/pExtraData are taken over.
     121             :     SwRedlineData( RedlineType_t eT, sal_uInt16 nAut, const DateTime& rDT,
     122             :                    const OUString& rCmnt, SwRedlineData* pNxt,
     123             :                     SwRedlineExtraData* pExtraData = 0 );
     124             : 
     125             :     ~SwRedlineData();
     126             : 
     127           0 :     bool operator==( const SwRedlineData& rCmp ) const
     128             :         {
     129           0 :             return nAuthor == rCmp.nAuthor &&
     130           0 :                     eType == rCmp.eType &&
     131           0 :                     sComment == rCmp.sComment &&
     132           0 :                     (( !pNext && !rCmp.pNext ) ||
     133           0 :                         ( pNext && rCmp.pNext && *pNext == *rCmp.pNext )) &&
     134           0 :                     (( !pExtraData && !rCmp.pExtraData ) ||
     135           0 :                         ( pExtraData && rCmp.pExtraData &&
     136           0 :                             *pExtraData == *rCmp.pExtraData ));
     137             :         }
     138           0 :     bool operator!=( const SwRedlineData& rCmp ) const
     139           0 :         {   return !operator==( rCmp ); }
     140             : 
     141       34880 :     RedlineType_t GetType() const
     142       34880 :   { return ((RedlineType_t)(eType & nsRedlineType_t::REDLINE_NO_FLAG_MASK)); }
     143             :     RedlineType_t GetRealType() const { return eType; }
     144          85 :     sal_uInt16 GetAuthor() const                { return nAuthor; }
     145           3 :     const OUString& GetComment() const        { return sComment; }
     146        3631 :     const DateTime& GetTimeStamp() const    { return aStamp; }
     147           5 :     inline const SwRedlineData* Next() const{ return pNext; }
     148             : 
     149           0 :     void SetComment( const OUString& rS )     { sComment = rS; }
     150        1481 :     void SetTimeStamp( const DateTime& rDT ) { aStamp = rDT; }
     151             : 
     152           0 :     void SetAutoFormatFlag()
     153           0 :   { eType = (RedlineType_t)(eType | nsRedlineType_t::REDLINE_FORM_AUTOFMT); }
     154        3069 :     bool CanCombine( const SwRedlineData& rCmp ) const
     155             :         {
     156        5269 :             return nAuthor == rCmp.nAuthor &&
     157        3973 :                     eType == rCmp.eType &&
     158        3546 :                     sComment == rCmp.sComment &&
     159        3164 :                     GetTimeStamp() == rCmp.GetTimeStamp() &&
     160        2782 :                     (( !pNext && !rCmp.pNext ) ||
     161           0 :                         ( pNext && rCmp.pNext &&
     162        5605 :                         pNext->CanCombine( *rCmp.pNext ))) &&
     163        2103 :                     (( !pExtraData && !rCmp.pExtraData ) ||
     164        1334 :                         ( pExtraData && rCmp.pExtraData &&
     165        3736 :                             *pExtraData == *rCmp.pExtraData ));
     166             :         }
     167             : 
     168             :     // ExtraData gets copied, the pointer is therefore not taken over by
     169             :     // the RedlilneObject
     170             :     void SetExtraData( const SwRedlineExtraData* pData );
     171          17 :     const SwRedlineExtraData* GetExtraData() const { return pExtraData; }
     172             : 
     173             :     // For UI-side pooling of Redline-actions.
     174             :     // At the moment only used for Autoformat with Redline.
     175             :     // Value != 0 means there can be others!
     176          52 :     sal_uInt16 GetSeqNo() const                     { return nSeqNo; }
     177           0 :     void SetSeqNo( sal_uInt16 nNo )                 { nSeqNo = nNo; }
     178             : 
     179             :     OUString GetDescr() const;
     180             : };
     181             : 
     182             : class SW_DLLPUBLIC SwRangeRedline : public SwPaM
     183             : {
     184             :     SwRedlineData* pRedlineData;
     185             :     SwNodeIndex* pContentSect;
     186             :     bool bDelLastPara : 1;
     187             :     bool bIsLastParaDelete : 1;
     188             :     bool bIsVisible : 1;
     189             : 
     190             :     void MoveToSection();
     191             :     void CopyToSection();
     192             :     void DelCopyOfSection(size_t nMyPos);
     193             :     void MoveFromSection(size_t nMyPos);
     194             : 
     195             : public:
     196             :     SwRangeRedline( RedlineType_t eType, const SwPaM& rPam );
     197             :     SwRangeRedline( const SwRedlineData& rData, const SwPaM& rPam );
     198             :     SwRangeRedline( const SwRedlineData& rData, const SwPosition& rPos );
     199             :     // For sw3io: pData is taken over!
     200          38 :     SwRangeRedline(SwRedlineData* pData, const SwPosition& rPos, bool bVsbl,
     201             :                bool bDelLP, bool bIsPD) :
     202             :         SwPaM( rPos ), pRedlineData( pData ), pContentSect( 0 ),
     203          38 :         bDelLastPara( bDelLP ), bIsLastParaDelete( bIsPD ), bIsVisible( bVsbl )
     204          38 :     {}
     205             :     SwRangeRedline( const SwRangeRedline& );
     206             :     virtual ~SwRangeRedline();
     207             : 
     208        2147 :     SwNodeIndex* GetContentIdx() const { return pContentSect; }
     209             :     // For Undo.
     210             :     void SetContentIdx( const SwNodeIndex* );
     211             : 
     212        6185 :     bool IsVisible() const { return bIsVisible; }
     213           0 :     bool IsDelLastPara() const { return bDelLastPara; }
     214             : 
     215         356 :     void SetStart( const SwPosition& rPos, SwPosition* pSttPtr = 0 )
     216             :     {
     217         356 :         if( !pSttPtr ) pSttPtr = Start();
     218         356 :         *pSttPtr = rPos;
     219         356 :     }
     220         719 :     void SetEnd( const SwPosition& rPos, SwPosition* pEndPtr = 0 )
     221             :     {
     222         719 :         if( !pEndPtr ) pEndPtr = End();
     223         719 :         *pEndPtr = rPos;
     224         719 :     }
     225             :     /// Do we have a valid selection?
     226             :     bool HasValidRange() const;
     227             : 
     228             :     const SwRedlineData& GetRedlineData(sal_uInt16 nPos = 0) const;
     229             :     bool operator==( const SwRedlineData& rCmp ) const
     230             :         { return *pRedlineData == rCmp; }
     231           0 :     bool operator!=( const SwRedlineData& rCmp ) const
     232           0 :         { return *pRedlineData != rCmp; }
     233           0 :     void SetAutoFormatFlag()               { pRedlineData->SetAutoFormatFlag(); }
     234             : 
     235             :     sal_uInt16 GetStackCount() const;
     236             :     sal_uInt16 GetAuthor( sal_uInt16 nPos = 0) const;
     237             :     OUString GetAuthorString( sal_uInt16 nPos = 0 ) const;
     238             :     const DateTime& GetTimeStamp( sal_uInt16 nPos = 0) const;
     239             :     RedlineType_t GetRealType( sal_uInt16 nPos = 0 ) const;
     240      174096 :     RedlineType_t GetType( sal_uInt16 nPos = 0) const
     241      174096 :         { return ( (RedlineType_t)(GetRealType( nPos ) & nsRedlineType_t::REDLINE_NO_FLAG_MASK)); }
     242             :     const OUString& GetComment( sal_uInt16 nPos = 0 ) const;
     243             : 
     244           0 :     void SetComment( const OUString& rS ) { pRedlineData->SetComment( rS ); }
     245             : 
     246             :     /** ExtraData gets copied, the pointer is therefore not taken over by
     247             :      *  the RedLineObject.*/
     248        1447 :     void SetExtraData( const SwRedlineExtraData* pData )
     249        1447 :         { pRedlineData->SetExtraData( pData ); }
     250           0 :     const SwRedlineExtraData* GetExtraData() const
     251           0 :         { return pRedlineData->GetExtraData(); }
     252             : 
     253             :     // For UI-side pooling of Redline-actions.
     254             :     // At the moment only used for Autoformat with Redline.
     255             :     // Value != 0 means there can be others!
     256          10 :     sal_uInt16 GetSeqNo() const             { return pRedlineData->GetSeqNo(); }
     257           0 :     void SetSeqNo( sal_uInt16 nNo )         { pRedlineData->SetSeqNo( nNo ); }
     258             : 
     259             :     // At Hide/ShowOriginal the list is traversed two times in order to
     260             :     // hide the Del-Redlines via Copy and Delete.
     261             :     // Otherwise at Move the attribution would be handled incorrectly.
     262             :     // All other callers must always give 0.
     263             :     void CallDisplayFunc(sal_uInt16 nLoop, size_t nMyPos);
     264             :     void Show(sal_uInt16 nLoop , size_t nMyPos);
     265             :     void Hide(sal_uInt16 nLoop , size_t nMyPos);
     266             :     void ShowOriginal(sal_uInt16 nLoop, size_t nMyPos);
     267             : 
     268             :     /// Calculates the intersection with text node number nNdIdx.
     269             :     void CalcStartEnd(sal_uLong nNdIdx, sal_Int32& rStart, sal_Int32& rEnd) const;
     270             : 
     271             :     /// Initiate the layout.
     272             :     void InvalidateRange();
     273             : 
     274       10639 :     bool IsOwnRedline( const SwRangeRedline& rRedl ) const
     275       10639 :         { return GetAuthor() == rRedl.GetAuthor(); }
     276             :     bool CanCombine( const SwRangeRedline& rRedl ) const;
     277             : 
     278             :     void PushData( const SwRangeRedline& rRedl, bool bOwnAsNext = true );
     279             :     bool PopData();
     280             : 
     281             :     /**
     282             :        Returns textual description of this a redline data element of
     283             :        this redline.
     284             : 
     285             :        @param nPos index of the redline data element to describe
     286             : 
     287             :        The textual description of the selected element contains the
     288             :        kind of redline and the possibly shortened text of the redline.
     289             : 
     290             :        @return textual description of the selected redline data element
     291             :      */
     292             :     OUString GetDescr(sal_uInt16 nPos = 0);
     293             : 
     294             :     bool operator==( const SwRangeRedline& ) const;
     295             :     bool operator<( const SwRangeRedline& ) const;
     296             :     void dumpAsXml(struct _xmlTextWriter* pWriter) const;
     297             : };
     298             : 
     299             : /// Base object for 'Redlines' that are not of 'Ranged' type (like table row insert\delete)
     300          34 : class SW_DLLPUBLIC SwExtraRedline : private boost::noncopyable
     301             : {
     302             : public:
     303             :     virtual ~SwExtraRedline();
     304             : };
     305             : 
     306             : /// Redline that holds information about a table-row that had some change
     307             : class SW_DLLPUBLIC SwTableRowRedline : public SwExtraRedline
     308             : {
     309             : private:
     310             :     SwRedlineData m_aRedlineData;
     311             :     const SwTableLine& m_rTableLine;
     312             : 
     313             : public:
     314             :     SwTableRowRedline(const SwRedlineData& rData, const SwTableLine& rTableLine);
     315             :     virtual ~SwTableRowRedline();
     316             : 
     317             :     /** ExtraData gets copied, the pointer is therefore not taken over by
     318             :      *  the RedLineObject.*/
     319          28 :     void SetExtraData( const SwRedlineExtraData* pData )
     320          28 :         { m_aRedlineData.SetExtraData( pData ); }
     321             :     const SwRedlineExtraData* GetExtraData() const
     322             :         { return m_aRedlineData.GetExtraData(); }
     323           6 :     const SwTableLine& GetTableLine() const
     324           6 :         { return m_rTableLine; }
     325           2 :     const SwRedlineData& GetRedlineData() const
     326           2 :         { return m_aRedlineData; }
     327             : };
     328             : 
     329             : /// Redline that holds information about a table-cell that had some change
     330             : class SW_DLLPUBLIC SwTableCellRedline : public SwExtraRedline
     331             : {
     332             : private:
     333             :     SwRedlineData m_aRedlineData;
     334             :     const SwTableBox& m_rTableBox;
     335             : 
     336             : public:
     337             :     SwTableCellRedline(const SwRedlineData& rData, const SwTableBox& rTableBox);
     338             :     virtual ~SwTableCellRedline();
     339             : 
     340             :     /** ExtraData gets copied, the pointer is therefore not taken over by
     341             :      *  the RedLineObject.*/
     342           6 :     void SetExtraData( const SwRedlineExtraData* pData )
     343           6 :         { m_aRedlineData.SetExtraData( pData ); }
     344             :     const SwRedlineExtraData* GetExtraData() const
     345             :         { return m_aRedlineData.GetExtraData(); }
     346          18 :     const SwTableBox& GetTableBox() const
     347          18 :         { return m_rTableBox; }
     348           2 :     const SwRedlineData& GetRedlineData() const
     349           2 :         { return m_aRedlineData; }
     350             : };
     351             : 
     352           0 : class SW_DLLPUBLIC SwRedlineHint : public SfxHint
     353             : {
     354             : #define SWREDLINE_INSERTED  1
     355             : #define SWREDLINE_FOCUS     3
     356             : 
     357             :     const SwRangeRedline* pRedline;
     358             :     sal_Int16 nWhich;
     359             :     const SwView* pView;
     360             : 
     361             : public:
     362           0 :     SwRedlineHint( const SwRangeRedline* p, sal_Int16 n, const SwView* pV = 0)
     363             :         : pRedline(p)
     364             :         , nWhich(n)
     365           0 :         , pView(pV)
     366           0 :         {}
     367             : 
     368             :     const SwRangeRedline* GetRedline() const { return pRedline; }
     369             :     sal_Int16 Which() const { return nWhich; }
     370             :         const SwView* GetView() const { return pView; }
     371             : };
     372             : 
     373             : #endif
     374             : 
     375             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11