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

Generated by: LCOV version 1.10