LCOV - code coverage report
Current view: top level - svx/source/svdraw - svdtext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 43 91 47.3 %
Date: 2012-08-25 Functions: 10 14 71.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 21 88 23.9 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #define ITEMID_FONTHEIGHT   EE_CHAR_FONTHEIGHT
      31                 :            : 
      32                 :            : #include "svx/svdotext.hxx"
      33                 :            : #include "svx/svdetc.hxx"
      34                 :            : #include "editeng/outlobj.hxx"
      35                 :            : #include "svx/svdoutl.hxx"
      36                 :            : #include "svx/svdmodel.hxx"
      37                 :            : #include "editeng/fhgtitem.hxx"
      38                 :            : #include <editeng/eeitem.hxx>
      39                 :            : #include <svl/itemset.hxx>
      40                 :            : 
      41                 :      57442 : SdrText::SdrText( SdrTextObj& rObject, OutlinerParaObject* pOutlinerParaObject /* = 0 */ )
      42                 :            : : mpOutlinerParaObject( pOutlinerParaObject )
      43                 :            : , mrObject( rObject )
      44         [ +  - ]:      57442 : , mpModel( rObject.GetModel() )
      45                 :      57442 : , mbPortionInfoChecked( false )
      46                 :            : {
      47                 :            :     OSL_ENSURE(&mrObject, "SdrText created without SdrTextObj (!)");
      48                 :      57442 : }
      49                 :            : 
      50                 :      57349 : SdrText::~SdrText()
      51                 :            : {
      52                 :      57349 :     clearWeak();
      53 [ +  - ][ +  + ]:      57349 :     delete mpOutlinerParaObject;
      54         [ -  + ]:     114650 : }
      55                 :            : 
      56                 :          0 : void SdrText::CheckPortionInfo( SdrOutliner& rOutliner )
      57                 :            : {
      58         [ #  # ]:          0 :     if(!mbPortionInfoChecked)
      59                 :            :     {
      60                 :            :         // #i102062# no action when the Outliner is the HitTestOutliner,
      61                 :            :         // this will remove WrongList info at the OPO
      62 [ #  # ][ #  # ]:          0 :         if(mpModel && &rOutliner == &mpModel->GetHitTestOutliner())
                 [ #  # ]
      63                 :          0 :             return;
      64                 :            : 
      65                 :            :         // TODO: optimization: we could create a BigTextObject
      66                 :          0 :         mbPortionInfoChecked=true;
      67 [ #  # ][ #  # ]:          0 :         if(mpOutlinerParaObject!=NULL && rOutliner.ShouldCreateBigTextObject())
                 [ #  # ]
      68                 :            :         {
      69                 :            :             // #i102062# MemoryLeak closed
      70         [ #  # ]:          0 :             delete mpOutlinerParaObject;
      71                 :          0 :             mpOutlinerParaObject = rOutliner.CreateParaObject();
      72                 :            :         }
      73                 :            :     }
      74                 :            : }
      75                 :            : 
      76                 :          0 : void SdrText::ReformatText()
      77                 :            : {
      78                 :          0 :     mbPortionInfoChecked=sal_False;
      79                 :          0 :     mpOutlinerParaObject->ClearPortionInfo();
      80                 :          0 : }
      81                 :            : 
      82                 :         31 : const SfxItemSet& SdrText::GetItemSet() const
      83                 :            : {
      84                 :         31 :     return const_cast< SdrText* >(this)->GetObjectItemSet();
      85                 :            : }
      86                 :            : 
      87                 :      54529 : void SdrText::SetOutlinerParaObject( OutlinerParaObject* pTextObject )
      88                 :            : {
      89         [ +  + ]:      54529 :     if( mpOutlinerParaObject != pTextObject )
      90                 :            :     {
      91         [ +  - ]:      54236 :         if( mpModel )
      92                 :            :         {
      93                 :            :             // Update HitTestOutliner
      94                 :      54236 :             const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
      95 [ #  # ][ -  + ]:      54236 :             if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
                 [ -  + ]
      96                 :          0 :                 mpModel->GetHitTestOutliner().SetTextObj( 0 );
      97                 :            :         }
      98                 :            : 
      99         [ +  + ]:      54236 :         if( mpOutlinerParaObject )
     100         [ +  - ]:      30191 :             delete mpOutlinerParaObject;
     101                 :            : 
     102                 :      54236 :         mpOutlinerParaObject = pTextObject;
     103                 :            : 
     104                 :      54236 :         mbPortionInfoChecked = false;
     105                 :            :     }
     106                 :      54529 : }
     107                 :            : 
     108                 :     738220 : OutlinerParaObject* SdrText::GetOutlinerParaObject() const
     109                 :            : {
     110                 :     738220 :     return mpOutlinerParaObject;
     111                 :            : }
     112                 :            : 
     113                 :            : /** returns the current OutlinerParaObject and removes it from this instance */
     114                 :          0 : OutlinerParaObject* SdrText::RemoveOutlinerParaObject()
     115                 :            : {
     116         [ #  # ]:          0 :     if( mpModel )
     117                 :            :     {
     118                 :            :         // Update HitTestOutliner
     119                 :          0 :         const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
     120 [ #  # ][ #  # ]:          0 :         if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
                 [ #  # ]
     121                 :          0 :             mpModel->GetHitTestOutliner().SetTextObj( 0 );
     122                 :            :     }
     123                 :            : 
     124                 :          0 :     OutlinerParaObject* pOPO = mpOutlinerParaObject;
     125                 :            : 
     126                 :          0 :     mpOutlinerParaObject = 0;
     127                 :          0 :     mbPortionInfoChecked = false;
     128                 :            : 
     129                 :          0 :     return pOPO;
     130                 :            : }
     131                 :            : 
     132                 :      57436 : void SdrText::SetModel( SdrModel* pNewModel )
     133                 :            : {
     134         [ +  + ]:      57436 :     if( pNewModel == mpModel )
     135                 :      57436 :         return;
     136                 :            : 
     137                 :       1407 :     SdrModel* pOldModel = mpModel;
     138                 :       1407 :     mpModel = pNewModel;
     139                 :            : 
     140 [ -  + ][ #  # ]:       1407 :     if( mpOutlinerParaObject && pOldModel!=NULL && pNewModel!=NULL)
                 [ #  # ]
     141                 :            :     {
     142                 :          0 :         bool bHgtSet = GetObjectItemSet().GetItemState(EE_CHAR_FONTHEIGHT, sal_True) == SFX_ITEM_SET;
     143                 :            : 
     144                 :          0 :         MapUnit aOldUnit(pOldModel->GetScaleUnit());
     145                 :          0 :         MapUnit aNewUnit(pNewModel->GetScaleUnit());
     146                 :          0 :         bool bScaleUnitChanged=aNewUnit!=aOldUnit;
     147                 :            :         // Now move the OutlinerParaObject into a new Pool.
     148                 :            :         // TODO: We should compare the DefTab and RefDevice of both Models to
     149                 :            :         // see whether we need to use AutoGrow!
     150                 :          0 :         sal_uIntPtr nOldFontHgt=pOldModel->GetDefaultFontHeight();
     151                 :          0 :         sal_uIntPtr nNewFontHgt=pNewModel->GetDefaultFontHeight();
     152                 :          0 :         sal_Bool bDefHgtChanged=nNewFontHgt!=nOldFontHgt;
     153 [ #  # ][ #  # ]:          0 :         sal_Bool bSetHgtItem=bDefHgtChanged && !bHgtSet;
     154         [ #  # ]:          0 :         if (bSetHgtItem)
     155                 :            :         {
     156                 :            :             // fix the value of HeightItem, so
     157                 :            :             // 1. it remains and
     158                 :            :             // 2. DoStretchChars gets the right value
     159         [ #  # ]:          0 :             SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
     160                 :            :         }
     161                 :            :         // now use the Outliner, etc. so the above SetAttr can work at all
     162                 :          0 :         SdrOutliner& rOutliner = mrObject.ImpGetDrawOutliner();
     163                 :          0 :         rOutliner.SetText(*mpOutlinerParaObject);
     164         [ #  # ]:          0 :         delete mpOutlinerParaObject;
     165                 :          0 :         mpOutlinerParaObject=0;
     166         [ #  # ]:          0 :         if (bScaleUnitChanged)
     167                 :            :         {
     168 [ #  # ][ #  # ]:          0 :             Fraction aMetricFactor=GetMapFactor(aOldUnit,aNewUnit).X();
     169                 :            : 
     170         [ #  # ]:          0 :             if (bSetHgtItem)
     171                 :            :             {
     172                 :            :                 // Now correct the frame attribute
     173         [ #  # ]:          0 :                 nOldFontHgt=BigMulDiv(nOldFontHgt,aMetricFactor.GetNumerator(),aMetricFactor.GetDenominator());
     174 [ #  # ][ #  # ]:          0 :                 SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
                 [ #  # ]
     175                 :            :             }
     176                 :            :         }
     177                 :          0 :         SetOutlinerParaObject(rOutliner.CreateParaObject());
     178                 :          0 :         mpOutlinerParaObject->ClearPortionInfo();
     179                 :          0 :         mbPortionInfoChecked=sal_False;
     180                 :          0 :         rOutliner.Clear();
     181                 :            :     }
     182                 :            : }
     183                 :            : 
     184                 :        633 : void SdrText::ForceOutlinerParaObject( sal_uInt16 nOutlMode )
     185                 :            : {
     186 [ +  - ][ +  + ]:        633 :     if( mpModel && !mpOutlinerParaObject )
     187                 :            :     {
     188                 :        201 :         Outliner* pOutliner = SdrMakeOutliner( nOutlMode, mpModel );
     189         [ +  - ]:        201 :         if( pOutliner )
     190                 :            :         {
     191                 :        201 :             Outliner& aDrawOutliner = mpModel->GetDrawOutliner();
     192                 :        201 :             pOutliner->SetCalcFieldValueHdl( aDrawOutliner.GetCalcFieldValueHdl() );
     193                 :            : 
     194                 :        201 :             pOutliner->SetStyleSheet( 0, GetStyleSheet());
     195                 :        201 :             OutlinerParaObject* pOutlinerParaObject = pOutliner->CreateParaObject();
     196                 :        201 :             SetOutlinerParaObject( pOutlinerParaObject );
     197                 :            : 
     198         [ +  - ]:        201 :             delete pOutliner;
     199                 :            :         }
     200                 :            :     }
     201                 :        633 : }
     202                 :            : 
     203                 :         31 : const SfxItemSet& SdrText::GetObjectItemSet()
     204                 :            : {
     205                 :         31 :     return mrObject.GetObjectItemSet();
     206                 :            : }
     207                 :            : 
     208                 :          0 : void SdrText::SetObjectItem(const SfxPoolItem& rItem)
     209                 :            : {
     210                 :          0 :     mrObject.SetObjectItem( rItem );
     211                 :          0 : }
     212                 :            : 
     213                 :          9 : SfxStyleSheet* SdrText::GetStyleSheet() const
     214                 :            : {
     215                 :          9 :     return mrObject.GetStyleSheet();
     216                 :            : }
     217                 :            : 
     218                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10