Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / svdraw / svdtext.cxx
blob33729927360fb9dd81023262b78c2d934a559a0e
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>
29 SdrText::SdrText( SdrTextObj& rObject, OutlinerParaObject* pOutlinerParaObject /* = 0 */ )
30 : mpOutlinerParaObject( pOutlinerParaObject )
31 , mrObject( rObject )
32 , mpModel( rObject.GetModel() )
33 , mbPortionInfoChecked( false )
35 OSL_ENSURE(&mrObject, "SdrText created without SdrTextObj (!)");
38 SdrText::~SdrText()
40 clearWeak();
41 delete mpOutlinerParaObject;
44 void SdrText::CheckPortionInfo( SdrOutliner& rOutliner )
46 if(!mbPortionInfoChecked)
48 // #i102062# no action when the Outliner is the HitTestOutliner,
49 // this will remove WrongList info at the OPO
50 if(mpModel && &rOutliner == &mpModel->GetHitTestOutliner())
51 return;
53 // TODO: optimization: we could create a BigTextObject
54 mbPortionInfoChecked=true;
55 if(mpOutlinerParaObject!=NULL && rOutliner.ShouldCreateBigTextObject())
57 // #i102062# MemoryLeak closed
58 delete mpOutlinerParaObject;
59 mpOutlinerParaObject = rOutliner.CreateParaObject();
64 void SdrText::ReformatText()
66 mbPortionInfoChecked=false;
67 mpOutlinerParaObject->ClearPortionInfo();
70 const SfxItemSet& SdrText::GetItemSet() const
72 return const_cast< SdrText* >(this)->GetObjectItemSet();
75 void SdrText::SetOutlinerParaObject( OutlinerParaObject* pTextObject )
77 if( mpOutlinerParaObject != pTextObject )
79 if( mpModel )
81 // Update HitTestOutliner
82 const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
83 if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
84 mpModel->GetHitTestOutliner().SetTextObj( 0 );
87 delete mpOutlinerParaObject;
89 mpOutlinerParaObject = pTextObject;
91 mbPortionInfoChecked = false;
95 OutlinerParaObject* SdrText::GetOutlinerParaObject() const
97 return mpOutlinerParaObject;
100 /** returns the current OutlinerParaObject and removes it from this instance */
101 OutlinerParaObject* SdrText::RemoveOutlinerParaObject()
103 if( mpModel )
105 // Update HitTestOutliner
106 const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
107 if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
108 mpModel->GetHitTestOutliner().SetTextObj( 0 );
111 OutlinerParaObject* pOPO = mpOutlinerParaObject;
113 mpOutlinerParaObject = 0;
114 mbPortionInfoChecked = false;
116 return pOPO;
119 void SdrText::SetModel( SdrModel* pNewModel )
121 if( pNewModel == mpModel )
122 return;
124 SdrModel* pOldModel = mpModel;
125 mpModel = pNewModel;
127 if( mpOutlinerParaObject && pOldModel!=NULL && pNewModel!=NULL)
129 bool bHgtSet = GetObjectItemSet().GetItemState(EE_CHAR_FONTHEIGHT, true) == SFX_ITEM_SET;
131 MapUnit aOldUnit(pOldModel->GetScaleUnit());
132 MapUnit aNewUnit(pNewModel->GetScaleUnit());
133 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 sal_uIntPtr nOldFontHgt=pOldModel->GetDefaultFontHeight();
138 sal_uIntPtr nNewFontHgt=pNewModel->GetDefaultFontHeight();
139 bool bDefHgtChanged=nNewFontHgt!=nOldFontHgt;
140 bool bSetHgtItem=bDefHgtChanged && !bHgtSet;
141 if (bSetHgtItem)
143 // fix the value of HeightItem, so
144 // 1. it remains and
145 // 2. DoStretchChars gets the right value
146 SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
148 // now use the Outliner, etc. so the above SetAttr can work at all
149 SdrOutliner& rOutliner = mrObject.ImpGetDrawOutliner();
150 rOutliner.SetText(*mpOutlinerParaObject);
151 delete mpOutlinerParaObject;
152 mpOutlinerParaObject=0;
153 if (bScaleUnitChanged)
155 Fraction aMetricFactor=GetMapFactor(aOldUnit,aNewUnit).X();
157 if (bSetHgtItem)
159 // Now correct the frame attribute
160 nOldFontHgt=BigMulDiv(nOldFontHgt,aMetricFactor.GetNumerator(),aMetricFactor.GetDenominator());
161 SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
164 SetOutlinerParaObject(rOutliner.CreateParaObject());
165 mpOutlinerParaObject->ClearPortionInfo();
166 mbPortionInfoChecked=false;
167 rOutliner.Clear();
171 void SdrText::ForceOutlinerParaObject( sal_uInt16 nOutlMode )
173 if( mpModel && !mpOutlinerParaObject )
175 Outliner* pOutliner = SdrMakeOutliner( nOutlMode, mpModel );
176 if( pOutliner )
178 Outliner& aDrawOutliner = mpModel->GetDrawOutliner();
179 pOutliner->SetCalcFieldValueHdl( aDrawOutliner.GetCalcFieldValueHdl() );
181 pOutliner->SetStyleSheet( 0, GetStyleSheet());
182 OutlinerParaObject* pOutlinerParaObject = pOutliner->CreateParaObject();
183 SetOutlinerParaObject( pOutlinerParaObject );
185 delete pOutliner;
190 const SfxItemSet& SdrText::GetObjectItemSet()
192 return mrObject.GetObjectItemSet();
195 void SdrText::SetObjectItem(const SfxPoolItem& rItem)
197 mrObject.SetObjectItem( rItem );
200 SfxStyleSheet* SdrText::GetStyleSheet() const
202 return mrObject.GetStyleSheet();
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */