bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / svdraw / svdtext.cxx
blob5563bf333134885c1283ff337b87d0fbaf6dff78
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
30 SdrText::SdrText( SdrTextObj& rObject, OutlinerParaObject* pOutlinerParaObject /* = 0 */ )
31 : mpOutlinerParaObject( pOutlinerParaObject )
32 , mrObject( rObject )
33 , mpModel( rObject.GetModel() )
34 , mbPortionInfoChecked( false )
36 OSL_ENSURE(&mrObject, "SdrText created without SdrTextObj (!)");
39 SdrText::~SdrText()
41 clearWeak();
42 delete mpOutlinerParaObject;
45 void SdrText::CheckPortionInfo( SdrOutliner& rOutliner )
47 if(!mbPortionInfoChecked)
49 // #i102062# no action when the Outliner is the HitTestOutliner,
50 // this will remove WrongList info at the OPO
51 if(mpModel && &rOutliner == &mpModel->GetHitTestOutliner())
52 return;
54 // TODO: optimization: we could create a BigTextObject
55 mbPortionInfoChecked=true;
56 if(mpOutlinerParaObject!=NULL && rOutliner.ShouldCreateBigTextObject())
58 // #i102062# MemoryLeak closed
59 delete mpOutlinerParaObject;
60 mpOutlinerParaObject = rOutliner.CreateParaObject();
65 void SdrText::ReformatText()
67 mbPortionInfoChecked=false;
68 mpOutlinerParaObject->ClearPortionInfo();
71 const SfxItemSet& SdrText::GetItemSet() const
73 return const_cast< SdrText* >(this)->GetObjectItemSet();
76 void SdrText::SetOutlinerParaObject( OutlinerParaObject* pTextObject )
78 if( mpOutlinerParaObject != pTextObject )
80 if( mpModel )
82 // Update HitTestOutliner
83 const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
84 if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
85 mpModel->GetHitTestOutliner().SetTextObj( 0 );
88 delete mpOutlinerParaObject;
90 mpOutlinerParaObject = pTextObject;
92 mbPortionInfoChecked = false;
96 OutlinerParaObject* SdrText::GetOutlinerParaObject() const
98 return mpOutlinerParaObject;
101 /** returns the current OutlinerParaObject and removes it from this instance */
102 OutlinerParaObject* SdrText::RemoveOutlinerParaObject()
104 if( mpModel )
106 // Update HitTestOutliner
107 const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
108 if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
109 mpModel->GetHitTestOutliner().SetTextObj( 0 );
112 OutlinerParaObject* pOPO = mpOutlinerParaObject;
114 mpOutlinerParaObject = 0;
115 mbPortionInfoChecked = false;
117 return pOPO;
120 void SdrText::SetModel( SdrModel* pNewModel )
122 if( pNewModel == mpModel )
123 return;
125 SdrModel* pOldModel = mpModel;
126 mpModel = pNewModel;
128 if( mpOutlinerParaObject && pOldModel!=NULL && pNewModel!=NULL)
130 bool bHgtSet = GetObjectItemSet().GetItemState(EE_CHAR_FONTHEIGHT, true) == SfxItemState::SET;
132 MapUnit aOldUnit(pOldModel->GetScaleUnit());
133 MapUnit aNewUnit(pNewModel->GetScaleUnit());
134 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 sal_uIntPtr nOldFontHgt=pOldModel->GetDefaultFontHeight();
139 sal_uIntPtr nNewFontHgt=pNewModel->GetDefaultFontHeight();
140 bool bDefHgtChanged=nNewFontHgt!=nOldFontHgt;
141 bool bSetHgtItem=bDefHgtChanged && !bHgtSet;
142 if (bSetHgtItem)
144 // fix the value of HeightItem, so
145 // 1. it remains and
146 // 2. DoStretchChars gets the right value
147 SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
149 // now use the Outliner, etc. so the above SetAttr can work at all
150 SdrOutliner& rOutliner = mrObject.ImpGetDrawOutliner();
151 rOutliner.SetText(*mpOutlinerParaObject);
152 delete mpOutlinerParaObject;
153 mpOutlinerParaObject=0;
154 if (bScaleUnitChanged)
156 Fraction aMetricFactor=GetMapFactor(aOldUnit,aNewUnit).X();
158 if (bSetHgtItem)
160 // Now correct the frame attribute
161 nOldFontHgt=BigMulDiv(nOldFontHgt,aMetricFactor.GetNumerator(),aMetricFactor.GetDenominator());
162 SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
165 SetOutlinerParaObject(rOutliner.CreateParaObject());
166 mpOutlinerParaObject->ClearPortionInfo();
167 mbPortionInfoChecked=false;
168 rOutliner.Clear();
172 void SdrText::ForceOutlinerParaObject( sal_uInt16 nOutlMode )
174 if( mpModel && !mpOutlinerParaObject )
176 boost::scoped_ptr<Outliner> pOutliner(SdrMakeOutliner(nOutlMode, *mpModel));
177 if( pOutliner )
179 Outliner& aDrawOutliner = mpModel->GetDrawOutliner();
180 pOutliner->SetCalcFieldValueHdl( aDrawOutliner.GetCalcFieldValueHdl() );
182 pOutliner->SetStyleSheet( 0, GetStyleSheet());
183 OutlinerParaObject* pOutlinerParaObject = pOutliner->CreateParaObject();
184 SetOutlinerParaObject( pOutlinerParaObject );
189 const SfxItemSet& SdrText::GetObjectItemSet()
191 return mrObject.GetObjectItemSet();
194 void SdrText::SetObjectItem(const SfxPoolItem& rItem)
196 mrObject.SetObjectItem( rItem );
199 SfxStyleSheet* SdrText::GetStyleSheet() const
201 return mrObject.GetStyleSheet();
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */