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

Generated by: LCOV version 1.10