LCOV - code coverage report
Current view: top level - svx/source/svdraw - svdtext.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 46 90 51.1 %
Date: 2014-04-11 Functions: 11 14 78.6 %
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 "svx/svdotext.hxx"
      21             : #include "svx/svdetc.hxx"
      22             : #include "editeng/outlobj.hxx"
      23             : #include "svx/svdoutl.hxx"
      24             : #include "svx/svdmodel.hxx"
      25             : #include "editeng/fhgtitem.hxx"
      26             : #include <editeng/eeitem.hxx>
      27             : #include <svl/itemset.hxx>
      28             : 
      29       41139 : SdrText::SdrText( SdrTextObj& rObject, OutlinerParaObject* pOutlinerParaObject /* = 0 */ )
      30             : : mpOutlinerParaObject( pOutlinerParaObject )
      31             : , mrObject( rObject )
      32       41139 : , mpModel( rObject.GetModel() )
      33       82278 : , mbPortionInfoChecked( false )
      34             : {
      35             :     OSL_ENSURE(&mrObject, "SdrText created without SdrTextObj (!)");
      36       41139 : }
      37             : 
      38      107764 : SdrText::~SdrText()
      39             : {
      40       36057 :     clearWeak();
      41       36057 :     delete mpOutlinerParaObject;
      42       71707 : }
      43             : 
      44           0 : void SdrText::CheckPortionInfo( SdrOutliner& rOutliner )
      45             : {
      46           0 :     if(!mbPortionInfoChecked)
      47             :     {
      48             :         // #i102062# no action when the Outliner is the HitTestOutliner,
      49             :         // this will remove WrongList info at the OPO
      50           0 :         if(mpModel && &rOutliner == &mpModel->GetHitTestOutliner())
      51           0 :             return;
      52             : 
      53             :         // TODO: optimization: we could create a BigTextObject
      54           0 :         mbPortionInfoChecked=true;
      55           0 :         if(mpOutlinerParaObject!=NULL && rOutliner.ShouldCreateBigTextObject())
      56             :         {
      57             :             // #i102062# MemoryLeak closed
      58           0 :             delete mpOutlinerParaObject;
      59           0 :             mpOutlinerParaObject = rOutliner.CreateParaObject();
      60             :         }
      61             :     }
      62             : }
      63             : 
      64           3 : void SdrText::ReformatText()
      65             : {
      66           3 :     mbPortionInfoChecked=false;
      67           3 :     mpOutlinerParaObject->ClearPortionInfo();
      68           3 : }
      69             : 
      70          30 : const SfxItemSet& SdrText::GetItemSet() const
      71             : {
      72          30 :     return const_cast< SdrText* >(this)->GetObjectItemSet();
      73             : }
      74             : 
      75       67408 : void SdrText::SetOutlinerParaObject( OutlinerParaObject* pTextObject )
      76             : {
      77       67408 :     if( mpOutlinerParaObject != pTextObject )
      78             :     {
      79       67195 :         if( mpModel )
      80             :         {
      81             :             // Update HitTestOutliner
      82       67195 :             const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
      83       67195 :             if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
      84           0 :                 mpModel->GetHitTestOutliner().SetTextObj( 0 );
      85             :         }
      86             : 
      87       67195 :         delete mpOutlinerParaObject;
      88             : 
      89       67195 :         mpOutlinerParaObject = pTextObject;
      90             : 
      91       67195 :         mbPortionInfoChecked = false;
      92             :     }
      93       67408 : }
      94             : 
      95      826186 : OutlinerParaObject* SdrText::GetOutlinerParaObject() const
      96             : {
      97      826186 :     return mpOutlinerParaObject;
      98             : }
      99             : 
     100             : /** returns the current OutlinerParaObject and removes it from this instance */
     101           0 : OutlinerParaObject* SdrText::RemoveOutlinerParaObject()
     102             : {
     103           0 :     if( mpModel )
     104             :     {
     105             :         // Update HitTestOutliner
     106           0 :         const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
     107           0 :         if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
     108           0 :             mpModel->GetHitTestOutliner().SetTextObj( 0 );
     109             :     }
     110             : 
     111           0 :     OutlinerParaObject* pOPO = mpOutlinerParaObject;
     112             : 
     113           0 :     mpOutlinerParaObject = 0;
     114           0 :     mbPortionInfoChecked = false;
     115             : 
     116           0 :     return pOPO;
     117             : }
     118             : 
     119       38748 : void SdrText::SetModel( SdrModel* pNewModel )
     120             : {
     121       38748 :     if( pNewModel == mpModel )
     122       75247 :         return;
     123             : 
     124        2249 :     SdrModel* pOldModel = mpModel;
     125        2249 :     mpModel = pNewModel;
     126             : 
     127        2249 :     if( mpOutlinerParaObject && pOldModel!=NULL && pNewModel!=NULL)
     128             :     {
     129           0 :         bool bHgtSet = GetObjectItemSet().GetItemState(EE_CHAR_FONTHEIGHT, true) == SFX_ITEM_SET;
     130             : 
     131           0 :         MapUnit aOldUnit(pOldModel->GetScaleUnit());
     132           0 :         MapUnit aNewUnit(pNewModel->GetScaleUnit());
     133           0 :         bool bScaleUnitChanged=aNewUnit!=aOldUnit;
     134             :         // Now move the OutlinerParaObject into a new Pool.
     135             :         // TODO: We should compare the DefTab and RefDevice of both Models to
     136             :         // see whether we need to use AutoGrow!
     137           0 :         sal_uIntPtr nOldFontHgt=pOldModel->GetDefaultFontHeight();
     138           0 :         sal_uIntPtr nNewFontHgt=pNewModel->GetDefaultFontHeight();
     139           0 :         bool bDefHgtChanged=nNewFontHgt!=nOldFontHgt;
     140           0 :         bool bSetHgtItem=bDefHgtChanged && !bHgtSet;
     141           0 :         if (bSetHgtItem)
     142             :         {
     143             :             // fix the value of HeightItem, so
     144             :             // 1. it remains and
     145             :             // 2. DoStretchChars gets the right value
     146           0 :             SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
     147             :         }
     148             :         // now use the Outliner, etc. so the above SetAttr can work at all
     149           0 :         SdrOutliner& rOutliner = mrObject.ImpGetDrawOutliner();
     150           0 :         rOutliner.SetText(*mpOutlinerParaObject);
     151           0 :         delete mpOutlinerParaObject;
     152           0 :         mpOutlinerParaObject=0;
     153           0 :         if (bScaleUnitChanged)
     154             :         {
     155           0 :             Fraction aMetricFactor=GetMapFactor(aOldUnit,aNewUnit).X();
     156             : 
     157           0 :             if (bSetHgtItem)
     158             :             {
     159             :                 // Now correct the frame attribute
     160           0 :                 nOldFontHgt=BigMulDiv(nOldFontHgt,aMetricFactor.GetNumerator(),aMetricFactor.GetDenominator());
     161           0 :                 SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
     162             :             }
     163             :         }
     164           0 :         SetOutlinerParaObject(rOutliner.CreateParaObject());
     165           0 :         mpOutlinerParaObject->ClearPortionInfo();
     166           0 :         mbPortionInfoChecked=false;
     167           0 :         rOutliner.Clear();
     168             :     }
     169             : }
     170             : 
     171        6551 : void SdrText::ForceOutlinerParaObject( sal_uInt16 nOutlMode )
     172             : {
     173        6551 :     if( mpModel && !mpOutlinerParaObject )
     174             :     {
     175        1873 :         Outliner* pOutliner = SdrMakeOutliner( nOutlMode, mpModel );
     176        1873 :         if( pOutliner )
     177             :         {
     178        1873 :             Outliner& aDrawOutliner = mpModel->GetDrawOutliner();
     179        1873 :             pOutliner->SetCalcFieldValueHdl( aDrawOutliner.GetCalcFieldValueHdl() );
     180             : 
     181        1873 :             pOutliner->SetStyleSheet( 0, GetStyleSheet());
     182        1873 :             OutlinerParaObject* pOutlinerParaObject = pOutliner->CreateParaObject();
     183        1873 :             SetOutlinerParaObject( pOutlinerParaObject );
     184             : 
     185        1873 :             delete pOutliner;
     186             :         }
     187             :     }
     188        6551 : }
     189             : 
     190          30 : const SfxItemSet& SdrText::GetObjectItemSet()
     191             : {
     192          30 :     return mrObject.GetObjectItemSet();
     193             : }
     194             : 
     195           0 : void SdrText::SetObjectItem(const SfxPoolItem& rItem)
     196             : {
     197           0 :     mrObject.SetObjectItem( rItem );
     198           0 : }
     199             : 
     200         245 : SfxStyleSheet* SdrText::GetStyleSheet() const
     201             : {
     202         245 :     return mrObject.GetStyleSheet();
     203             : }
     204             : 
     205             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10