LCOV - code coverage report
Current view: top level - editeng/source/outliner - outlobj.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 92 115 80.0 %
Date: 2015-06-13 12:38:46 Functions: 30 33 90.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             : 
      20             : #include <svl/intitem.hxx>
      21             : #include <editeng/editeng.hxx>
      22             : #include <editeng/editview.hxx>
      23             : #include <editeng/editdata.hxx>
      24             : #include <editeng/eerdll.hxx>
      25             : #include <editeng/lrspitem.hxx>
      26             : #include <editeng/fhgtitem.hxx>
      27             : 
      28             : #include <editeng/outliner.hxx>
      29             : #include <editeng/outlobj.hxx>
      30             : #include <outleeng.hxx>
      31             : #include <editeng/editobj.hxx>
      32             : #include <vcl/bitmap.hxx>
      33             : #include <tools/stream.hxx>
      34             : 
      35             : #include <boost/intrusive_ptr.hpp>
      36             : #include <libxml/xmlwriter.h>
      37             : 
      38             : /**
      39             :  * This is the guts of OutlinerParaObject, refcounted and shared among
      40             :  * multiple instances of OutlinerParaObject.
      41             :  */
      42             : struct OutlinerParaObjData
      43             : {
      44             :     // data members
      45             :     EditTextObject*                 mpEditTextObject;
      46             :     ParagraphDataVector             maParagraphDataVector;
      47             :     bool                            mbIsEditDoc;
      48             : 
      49             :     // refcounter
      50             :     mutable size_t mnRefCount;
      51             : 
      52             :     // constuctor
      53      111196 :     OutlinerParaObjData( EditTextObject* pEditTextObject, const ParagraphDataVector& rParagraphDataVector, bool bIsEditDoc ) :
      54             :         mpEditTextObject(pEditTextObject),
      55             :         maParagraphDataVector(rParagraphDataVector),
      56             :         mbIsEditDoc(bIsEditDoc),
      57      111196 :         mnRefCount(0)
      58             :     {
      59      111196 :         if( maParagraphDataVector.empty() && (pEditTextObject->GetParagraphCount() != 0) )
      60         109 :             maParagraphDataVector.resize(pEditTextObject->GetParagraphCount());
      61      111196 :     }
      62             : 
      63      130651 :     OutlinerParaObjData( const OutlinerParaObjData& r ) :
      64      130651 :         mpEditTextObject(r.mpEditTextObject->Clone()),
      65             :         maParagraphDataVector(r.maParagraphDataVector),
      66             :         mbIsEditDoc(r.mbIsEditDoc),
      67      130651 :         mnRefCount(0)
      68      130651 :     {}
      69             : 
      70             :     // destructor
      71      241542 :     ~OutlinerParaObjData()
      72      241542 :     {
      73      241542 :         delete mpEditTextObject;
      74      241542 :     }
      75             : 
      76        3121 :     bool operator==(const OutlinerParaObjData& rCandidate) const
      77             :     {
      78        3121 :         return (*mpEditTextObject == *rCandidate.mpEditTextObject
      79        1356 :             && maParagraphDataVector == rCandidate.maParagraphDataVector
      80        4473 :             && mbIsEditDoc == rCandidate.mbIsEditDoc);
      81             :     }
      82             : 
      83             :     // #i102062#
      84        1352 :     bool isWrongListEqual(const OutlinerParaObjData& rCompare) const
      85             :     {
      86        1352 :         return mpEditTextObject->isWrongListEqual(*rCompare.mpEditTextObject);
      87             :     }
      88             : };
      89             : 
      90      318443 : inline void intrusive_ptr_add_ref(const OutlinerParaObjData* p)
      91             : {
      92      318443 :     ++p->mnRefCount;
      93      318443 : }
      94             : 
      95      317750 : inline void intrusive_ptr_release(const OutlinerParaObjData* p)
      96             : {
      97      317750 :     --p->mnRefCount;
      98      317750 :     if (!p->mnRefCount)
      99      241542 :         delete p;
     100      317750 : }
     101             : 
     102             : struct OutlinerParaObject::Impl
     103             : {
     104             :     typedef boost::intrusive_ptr<OutlinerParaObjData> DataRef;
     105             :     DataRef mxData;
     106             : 
     107      111087 :     Impl( const EditTextObject& rTextObj, const ParagraphDataVector& rParaData, bool bIsEditDoc ) :
     108      111087 :         mxData(new OutlinerParaObjData(rTextObj.Clone(), rParaData, bIsEditDoc)) {}
     109             : 
     110         109 :     Impl( const EditTextObject& rTextObj ) :
     111         109 :         mxData(new OutlinerParaObjData(rTextObj.Clone(), ParagraphDataVector(), true)) {}
     112             : 
     113       76552 :     Impl( const Impl& r ) : mxData(r.mxData) {}
     114             : 
     115      187055 :     ~Impl() {}
     116             : };
     117             : 
     118      130651 : void OutlinerParaObject::ImplMakeUnique()
     119             : {
     120      130651 :     mpImpl->mxData.reset(new OutlinerParaObjData(*mpImpl->mxData));
     121      130651 : }
     122             : 
     123      111087 : OutlinerParaObject::OutlinerParaObject(
     124             :     const EditTextObject& rTextObj, const ParagraphDataVector& rParagraphDataVector, bool bIsEditDoc ) :
     125      111087 :     mpImpl(new Impl(rTextObj, rParagraphDataVector, bIsEditDoc)) {}
     126             : 
     127         109 : OutlinerParaObject::OutlinerParaObject( const EditTextObject& rTextObj ) :
     128         109 :     mpImpl(new Impl(rTextObj))
     129             : {
     130         109 : }
     131             : 
     132       76552 : OutlinerParaObject::OutlinerParaObject( const OutlinerParaObject& r ) :
     133       76552 :     mpImpl(new Impl(*r.mpImpl)) {}
     134             : 
     135      187055 : OutlinerParaObject::~OutlinerParaObject()
     136             : {
     137      187055 :     delete mpImpl;
     138      187055 : }
     139             : 
     140          44 : OutlinerParaObject& OutlinerParaObject::operator=( const OutlinerParaObject& r )
     141             : {
     142          44 :     mpImpl->mxData = r.mpImpl->mxData;
     143          44 :     return *this;
     144             : }
     145             : 
     146       14861 : bool OutlinerParaObject::operator==( const OutlinerParaObject& r ) const
     147             : {
     148       14861 :     if (r.mpImpl->mxData.get() == mpImpl->mxData.get())
     149             :     {
     150       11740 :         return true;
     151             :     }
     152             : 
     153        3121 :     return (*r.mpImpl->mxData == *mpImpl->mxData);
     154             : }
     155             : 
     156             : // #i102062#
     157       13092 : bool OutlinerParaObject::isWrongListEqual( const OutlinerParaObject& r ) const
     158             : {
     159       13092 :     if (r.mpImpl->mxData.get() == mpImpl->mxData.get())
     160             :     {
     161       11740 :         return true;
     162             :     }
     163             : 
     164        1352 :     return mpImpl->mxData->isWrongListEqual(*r.mpImpl->mxData);
     165             : }
     166             : 
     167      203138 : sal_uInt16 OutlinerParaObject::GetOutlinerMode() const
     168             : {
     169      203138 :     return mpImpl->mxData->mpEditTextObject->GetUserType();
     170             : }
     171             : 
     172      111196 : void OutlinerParaObject::SetOutlinerMode(sal_uInt16 nNew)
     173             : {
     174      111196 :     if (mpImpl->mxData->mpEditTextObject->GetUserType() != nNew)
     175             :     {
     176      111196 :         ImplMakeUnique();
     177      111196 :         mpImpl->mxData->mpEditTextObject->SetUserType(nNew);
     178             :     }
     179      111196 : }
     180             : 
     181      315974 : bool OutlinerParaObject::IsVertical() const
     182             : {
     183      315974 :     return mpImpl->mxData->mpEditTextObject->IsVertical();
     184             : }
     185             : 
     186          72 : void OutlinerParaObject::SetVertical(bool bNew)
     187             : {
     188          72 :     if (mpImpl->mxData->mpEditTextObject->IsVertical() != bNew)
     189             :     {
     190           2 :         ImplMakeUnique();
     191           2 :         mpImpl->mxData->mpEditTextObject->SetVertical(bNew);
     192             :     }
     193          72 : }
     194             : 
     195      418562 : sal_Int32 OutlinerParaObject::Count() const
     196             : {
     197      418562 :     size_t nSize = mpImpl->mxData->maParagraphDataVector.size();
     198      418562 :     if (nSize > EE_PARA_MAX_COUNT)
     199             :     {
     200             :         SAL_WARN( "editeng", "OutlinerParaObject::Count - overflow " << nSize);
     201           0 :         return EE_PARA_MAX_COUNT;
     202             :     }
     203      418562 :     return static_cast<sal_Int32>(nSize);
     204             : }
     205             : 
     206           1 : sal_Int16 OutlinerParaObject::GetDepth(sal_Int32 nPara) const
     207             : {
     208           1 :     if(0 <= nPara && static_cast<size_t>(nPara) < mpImpl->mxData->maParagraphDataVector.size())
     209             :     {
     210           1 :         return mpImpl->mxData->maParagraphDataVector[nPara].getDepth();
     211             :     }
     212             :     else
     213             :     {
     214           0 :         return -1;
     215             :     }
     216             : }
     217             : 
     218      461171 : const EditTextObject& OutlinerParaObject::GetTextObject() const
     219             : {
     220      461171 :     return *mpImpl->mxData->mpEditTextObject;
     221             : }
     222             : 
     223      100861 : bool OutlinerParaObject::IsEditDoc() const
     224             : {
     225      100861 :     return mpImpl->mxData->mbIsEditDoc;
     226             : }
     227             : 
     228      215380 : const ParagraphData& OutlinerParaObject::GetParagraphData(sal_Int32 nIndex) const
     229             : {
     230      215380 :     if(0 <= nIndex && static_cast<size_t>(nIndex) < mpImpl->mxData->maParagraphDataVector.size())
     231             :     {
     232      215380 :         return mpImpl->mxData->maParagraphDataVector[nIndex];
     233             :     }
     234             :     else
     235             :     {
     236             :         OSL_FAIL("OutlinerParaObject::GetParagraphData: Access out of range (!)");
     237           0 :         static ParagraphData aEmptyParagraphData;
     238           0 :         return aEmptyParagraphData;
     239             :     }
     240             : }
     241             : 
     242          21 : void OutlinerParaObject::ClearPortionInfo()
     243             : {
     244          21 :     ImplMakeUnique();
     245          21 :     mpImpl->mxData->mpEditTextObject->ClearPortionInfo();
     246          21 : }
     247             : 
     248       19432 : bool OutlinerParaObject::ChangeStyleSheets(const OUString& rOldName,
     249             :     SfxStyleFamily eOldFamily, const OUString& rNewName, SfxStyleFamily eNewFamily)
     250             : {
     251       19432 :     ImplMakeUnique();
     252       19432 :     return mpImpl->mxData->mpEditTextObject->ChangeStyleSheets(rOldName, eOldFamily, rNewName, eNewFamily);
     253             : }
     254             : 
     255           0 : void OutlinerParaObject::ChangeStyleSheetName(SfxStyleFamily eFamily,
     256             :     const OUString& rOldName, const OUString& rNewName)
     257             : {
     258           0 :     ImplMakeUnique();
     259           0 :     mpImpl->mxData->mpEditTextObject->ChangeStyleSheetName(eFamily, rOldName, rNewName);
     260           0 : }
     261             : 
     262           0 : void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel, const OUString& rNewName,
     263             :     const SfxStyleFamily& rNewFamily)
     264             : {
     265           0 :     const sal_Int32 nCount(Count());
     266             : 
     267           0 :     if(nCount)
     268             :     {
     269           0 :         ImplMakeUnique();
     270           0 :         sal_Int32 nDecrementer(nCount);
     271             : 
     272           0 :         for(;nDecrementer;)
     273             :         {
     274           0 :             if(GetDepth(--nDecrementer) == nLevel)
     275             :             {
     276           0 :                 mpImpl->mxData->mpEditTextObject->SetStyleSheet(nDecrementer, rNewName, rNewFamily);
     277             :             }
     278             :         }
     279             :     }
     280           0 : }
     281             : 
     282           0 : void OutlinerParaObject::dumpAsXml(xmlTextWriterPtr pWriter) const
     283             : {
     284           0 :     xmlTextWriterStartElement(pWriter, BAD_CAST("outlinerParaObject"));
     285           0 :     xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
     286           0 :     GetTextObject().dumpAsXml(pWriter);
     287           0 :     xmlTextWriterEndElement(pWriter);
     288           0 : }
     289             : 
     290             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11