LCOV - code coverage report
Current view: top level - editeng/source/outliner - outlobj.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 87 109 79.8 %
Date: 2014-11-03 Functions: 30 34 88.2 %
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             : 
      37             : /**
      38             :  * This is the guts of OutlinerParaObject, refcounted and shared among
      39             :  * multiple instances of OutlinerParaObject.
      40             :  */
      41             : struct OutlinerParaObjData
      42             : {
      43             :     // data members
      44             :     EditTextObject*                 mpEditTextObject;
      45             :     ParagraphDataVector             maParagraphDataVector;
      46             :     bool                            mbIsEditDoc;
      47             : 
      48             :     // refcounter
      49             :     mutable size_t mnRefCount;
      50             : 
      51             :     // constuctor
      52       95626 :     OutlinerParaObjData( EditTextObject* pEditTextObject, const ParagraphDataVector& rParagraphDataVector, bool bIsEditDoc ) :
      53             :         mpEditTextObject(pEditTextObject),
      54             :         maParagraphDataVector(rParagraphDataVector),
      55             :         mbIsEditDoc(bIsEditDoc),
      56       95626 :         mnRefCount(0)
      57             :     {
      58       95626 :         if( maParagraphDataVector.empty() && (pEditTextObject->GetParagraphCount() != 0) )
      59         194 :             maParagraphDataVector.resize(pEditTextObject->GetParagraphCount());
      60       95626 :     }
      61             : 
      62      116216 :     OutlinerParaObjData( const OutlinerParaObjData& r ) :
      63      116216 :         mpEditTextObject(r.mpEditTextObject->Clone()),
      64             :         maParagraphDataVector(r.maParagraphDataVector),
      65             :         mbIsEditDoc(r.mbIsEditDoc),
      66      116216 :         mnRefCount(0)
      67      116216 :     {}
      68             : 
      69             :     // destructor
      70      211500 :     ~OutlinerParaObjData()
      71      211500 :     {
      72      211500 :         delete mpEditTextObject;
      73      211500 :     }
      74             : 
      75        3960 :     bool operator==(const OutlinerParaObjData& rCandidate) const
      76             :     {
      77        3960 :         return (*mpEditTextObject == *rCandidate.mpEditTextObject
      78        1826 :             && maParagraphDataVector == rCandidate.maParagraphDataVector
      79        5778 :             && mbIsEditDoc == rCandidate.mbIsEditDoc);
      80             :     }
      81             : 
      82             :     // #i102062#
      83        1818 :     bool isWrongListEqual(const OutlinerParaObjData& rCompare) const
      84             :     {
      85        1818 :         return mpEditTextObject->isWrongListEqual(*rCompare.mpEditTextObject);
      86             :     }
      87             : };
      88             : 
      89      263392 : inline void intrusive_ptr_add_ref(const OutlinerParaObjData* p)
      90             : {
      91      263392 :     ++p->mnRefCount;
      92      263392 : }
      93             : 
      94      262442 : inline void intrusive_ptr_release(const OutlinerParaObjData* p)
      95             : {
      96      262442 :     --p->mnRefCount;
      97      262442 :     if (!p->mnRefCount)
      98      211500 :         delete p;
      99      262442 : }
     100             : 
     101             : struct OutlinerParaObject::Impl
     102             : {
     103             :     typedef boost::intrusive_ptr<OutlinerParaObjData> DataRef;
     104             :     DataRef mxData;
     105             : 
     106       95432 :     Impl( const EditTextObject& rTextObj, const ParagraphDataVector& rParaData, bool bIsEditDoc ) :
     107       95432 :         mxData(new OutlinerParaObjData(rTextObj.Clone(), rParaData, bIsEditDoc)) {}
     108             : 
     109         194 :     Impl( const EditTextObject& rTextObj ) :
     110         194 :         mxData(new OutlinerParaObjData(rTextObj.Clone(), ParagraphDataVector(), true)) {}
     111             : 
     112       51550 :     Impl( const Impl& r ) : mxData(r.mxData) {}
     113             : 
     114      146226 :     ~Impl() {}
     115             : };
     116             : 
     117      116216 : void OutlinerParaObject::ImplMakeUnique()
     118             : {
     119      116216 :     mpImpl->mxData.reset(new OutlinerParaObjData(*mpImpl->mxData));
     120      116216 : }
     121             : 
     122       95432 : OutlinerParaObject::OutlinerParaObject(
     123             :     const EditTextObject& rTextObj, const ParagraphDataVector& rParagraphDataVector, bool bIsEditDoc ) :
     124       95432 :     mpImpl(new Impl(rTextObj, rParagraphDataVector, bIsEditDoc)) {}
     125             : 
     126         194 : OutlinerParaObject::OutlinerParaObject( const EditTextObject& rTextObj ) :
     127         194 :     mpImpl(new Impl(rTextObj))
     128             : {
     129         194 : }
     130             : 
     131       51550 : OutlinerParaObject::OutlinerParaObject( const OutlinerParaObject& r ) :
     132       51550 :     mpImpl(new Impl(*r.mpImpl)) {}
     133             : 
     134      146226 : OutlinerParaObject::~OutlinerParaObject()
     135             : {
     136      146226 :     delete mpImpl;
     137      146226 : }
     138             : 
     139           0 : OutlinerParaObject& OutlinerParaObject::operator=( const OutlinerParaObject& r )
     140             : {
     141           0 :     mpImpl->mxData = r.mpImpl->mxData;
     142           0 :     return *this;
     143             : }
     144             : 
     145        9291 : bool OutlinerParaObject::operator==( const OutlinerParaObject& r ) const
     146             : {
     147        9291 :     if (r.mpImpl->mxData.get() == mpImpl->mxData.get())
     148             :     {
     149        5331 :         return true;
     150             :     }
     151             : 
     152        3960 :     return (*r.mpImpl->mxData == *mpImpl->mxData);
     153             : }
     154             : 
     155             : // #i102062#
     156        7149 : bool OutlinerParaObject::isWrongListEqual( const OutlinerParaObject& r ) const
     157             : {
     158        7149 :     if (r.mpImpl->mxData.get() == mpImpl->mxData.get())
     159             :     {
     160        5331 :         return true;
     161             :     }
     162             : 
     163        1818 :     return mpImpl->mxData->isWrongListEqual(*r.mpImpl->mxData);
     164             : }
     165             : 
     166      163374 : sal_uInt16 OutlinerParaObject::GetOutlinerMode() const
     167             : {
     168      163374 :     return mpImpl->mxData->mpEditTextObject->GetUserType();
     169             : }
     170             : 
     171       95626 : void OutlinerParaObject::SetOutlinerMode(sal_uInt16 nNew)
     172             : {
     173       95626 :     if (mpImpl->mxData->mpEditTextObject->GetUserType() != nNew)
     174             :     {
     175       95626 :         ImplMakeUnique();
     176       95626 :         mpImpl->mxData->mpEditTextObject->SetUserType(nNew);
     177             :     }
     178       95626 : }
     179             : 
     180      240607 : bool OutlinerParaObject::IsVertical() const
     181             : {
     182      240607 :     return mpImpl->mxData->mpEditTextObject->IsVertical();
     183             : }
     184             : 
     185         140 : void OutlinerParaObject::SetVertical(bool bNew)
     186             : {
     187         140 :     if (mpImpl->mxData->mpEditTextObject->IsVertical() != bNew)
     188             :     {
     189           4 :         ImplMakeUnique();
     190           4 :         mpImpl->mxData->mpEditTextObject->SetVertical(bNew);
     191             :     }
     192         140 : }
     193             : 
     194      340430 : sal_Int32 OutlinerParaObject::Count() const
     195             : {
     196      340430 :     size_t nSize = mpImpl->mxData->maParagraphDataVector.size();
     197      340430 :     if (nSize > EE_PARA_MAX_COUNT)
     198             :     {
     199             :         SAL_WARN( "editeng", "OutlinerParaObject::Count - overflow " << nSize);
     200           0 :         return EE_PARA_MAX_COUNT;
     201             :     }
     202      340430 :     return static_cast<sal_Int32>(nSize);
     203             : }
     204             : 
     205           0 : sal_Int16 OutlinerParaObject::GetDepth(sal_Int32 nPara) const
     206             : {
     207           0 :     if(0 <= nPara && static_cast<size_t>(nPara) < mpImpl->mxData->maParagraphDataVector.size())
     208             :     {
     209           0 :         return mpImpl->mxData->maParagraphDataVector[nPara].getDepth();
     210             :     }
     211             :     else
     212             :     {
     213           0 :         return -1;
     214             :     }
     215             : }
     216             : 
     217      401078 : const EditTextObject& OutlinerParaObject::GetTextObject() const
     218             : {
     219      401078 :     return *mpImpl->mxData->mpEditTextObject;
     220             : }
     221             : 
     222       78420 : bool OutlinerParaObject::IsEditDoc() const
     223             : {
     224       78420 :     return mpImpl->mxData->mbIsEditDoc;
     225             : }
     226             : 
     227      177007 : const ParagraphData& OutlinerParaObject::GetParagraphData(sal_Int32 nIndex) const
     228             : {
     229      177007 :     if(0 <= nIndex && static_cast<size_t>(nIndex) < mpImpl->mxData->maParagraphDataVector.size())
     230             :     {
     231      177007 :         return mpImpl->mxData->maParagraphDataVector[nIndex];
     232             :     }
     233             :     else
     234             :     {
     235             :         OSL_FAIL("OutlinerParaObject::GetParagraphData: Access out of range (!)");
     236           0 :         static ParagraphData aEmptyParagraphData;
     237           0 :         return aEmptyParagraphData;
     238             :     }
     239             : }
     240             : 
     241           6 : void OutlinerParaObject::ClearPortionInfo()
     242             : {
     243           6 :     ImplMakeUnique();
     244           6 :     mpImpl->mxData->mpEditTextObject->ClearPortionInfo();
     245           6 : }
     246             : 
     247       20580 : bool OutlinerParaObject::ChangeStyleSheets(const OUString& rOldName,
     248             :     SfxStyleFamily eOldFamily, const OUString& rNewName, SfxStyleFamily eNewFamily)
     249             : {
     250       20580 :     ImplMakeUnique();
     251       20580 :     return mpImpl->mxData->mpEditTextObject->ChangeStyleSheets(rOldName, eOldFamily, rNewName, eNewFamily);
     252             : }
     253             : 
     254           0 : void OutlinerParaObject::ChangeStyleSheetName(SfxStyleFamily eFamily,
     255             :     const OUString& rOldName, const OUString& rNewName)
     256             : {
     257           0 :     ImplMakeUnique();
     258           0 :     mpImpl->mxData->mpEditTextObject->ChangeStyleSheetName(eFamily, rOldName, rNewName);
     259           0 : }
     260             : 
     261           0 : void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel, const OUString& rNewName,
     262             :     const SfxStyleFamily& rNewFamily)
     263             : {
     264           0 :     const sal_Int32 nCount(Count());
     265             : 
     266           0 :     if(nCount)
     267             :     {
     268           0 :         ImplMakeUnique();
     269           0 :         sal_Int32 nDecrementer(nCount);
     270             : 
     271           0 :         for(;nDecrementer;)
     272             :         {
     273           0 :             if(GetDepth(--nDecrementer) == nLevel)
     274             :             {
     275           0 :                 mpImpl->mxData->mpEditTextObject->SetStyleSheet(nDecrementer, rNewName, rNewFamily);
     276             :             }
     277             :         }
     278             :     }
     279         669 : }
     280             : 
     281             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10