merge the formfield patch from ooo-build
[ooovba.git] / svx / source / svdraw / svdtext.cxx
blob93c0024ecc61cb9a94cd4d5a091feb786dba9521
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svdtext.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #define ITEMID_FONTHEIGHT EE_CHAR_FONTHEIGHT
36 #include "svx/svdotext.hxx"
37 #include "svx/svdetc.hxx"
38 #include "svx/outlobj.hxx"
39 #include "svx/svdoutl.hxx"
40 #include "svx/svdmodel.hxx"
41 #include "svx/fhgtitem.hxx"
42 #include <svx/eeitem.hxx>
43 #include <svtools/itemset.hxx>
45 SdrText::SdrText( SdrTextObj& rObject, OutlinerParaObject* pOutlinerParaObject /* = 0 */ )
46 : mpOutlinerParaObject( pOutlinerParaObject )
47 , mrObject( rObject )
48 , mpModel( rObject.GetModel() )
49 , mbPortionInfoChecked( false )
51 OSL_ENSURE(&mrObject, "SdrText created without SdrTextObj (!)");
54 SdrText::~SdrText()
56 clearWeak();
57 delete mpOutlinerParaObject;
60 void SdrText::CheckPortionInfo( SdrOutliner& rOutliner )
62 if(!mbPortionInfoChecked)
64 // #i102062# no action when the Outliner is the HitTestOutliner,
65 // this will remove WrongList info at the OPO
66 if(mpModel && &rOutliner == &mpModel->GetHitTestOutliner())
67 return;
69 // Optimierung: ggf. BigTextObject erzeugen
70 mbPortionInfoChecked=true;
71 if(mpOutlinerParaObject!=NULL && rOutliner.ShouldCreateBigTextObject())
73 // #i102062# MemoryLeak closed
74 delete mpOutlinerParaObject;
75 mpOutlinerParaObject = rOutliner.CreateParaObject();
80 void SdrText::ReformatText()
82 mbPortionInfoChecked=FALSE;
83 mpOutlinerParaObject->ClearPortionInfo();
86 const SfxItemSet& SdrText::GetItemSet() const
88 return const_cast< SdrText* >(this)->GetObjectItemSet();
91 void SdrText::SetOutlinerParaObject( OutlinerParaObject* pTextObject )
93 if( mpOutlinerParaObject != pTextObject )
95 if( mpModel )
97 // Update HitTestOutliner
98 const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
99 if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
100 mpModel->GetHitTestOutliner().SetTextObj( 0 );
103 if( mpOutlinerParaObject )
104 delete mpOutlinerParaObject;
106 mpOutlinerParaObject = pTextObject;
108 mbPortionInfoChecked = false;
112 OutlinerParaObject* SdrText::GetOutlinerParaObject() const
114 return mpOutlinerParaObject;
117 /** returns the current OutlinerParaObject and removes it from this instance */
118 OutlinerParaObject* SdrText::RemoveOutlinerParaObject()
120 if( mpModel )
122 // Update HitTestOutliner
123 const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
124 if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
125 mpModel->GetHitTestOutliner().SetTextObj( 0 );
128 OutlinerParaObject* pOPO = mpOutlinerParaObject;
130 mpOutlinerParaObject = 0;
131 mbPortionInfoChecked = false;
133 return pOPO;
136 void SdrText::SetModel( SdrModel* pNewModel )
138 if( pNewModel == mpModel )
139 return;
141 SdrModel* pOldModel = mpModel;
142 mpModel = pNewModel;
144 if( mpOutlinerParaObject && pOldModel!=NULL && pNewModel!=NULL)
146 bool bHgtSet = GetObjectItemSet().GetItemState(EE_CHAR_FONTHEIGHT, TRUE) == SFX_ITEM_SET;
148 MapUnit aOldUnit(pOldModel->GetScaleUnit());
149 MapUnit aNewUnit(pNewModel->GetScaleUnit());
150 FASTBOOL bScaleUnitChanged=aNewUnit!=aOldUnit;
151 // und nun dem OutlinerParaObject einen neuen Pool verpassen
152 // !!! Hier muss noch DefTab und RefDevice der beiden Models
153 // !!! verglichen werden und dann ggf. AutoGrow zuschlagen !!!
154 // !!! fehlende Implementation !!!
155 ULONG nOldFontHgt=pOldModel->GetDefaultFontHeight();
156 ULONG nNewFontHgt=pNewModel->GetDefaultFontHeight();
157 BOOL bDefHgtChanged=nNewFontHgt!=nOldFontHgt;
158 BOOL bSetHgtItem=bDefHgtChanged && !bHgtSet;
159 if (bSetHgtItem)
160 { // #32665#
161 // zunaechst das HeightItem festklopfen, damit
162 // 1. Es eben bestehen bleibt und
163 // 2. DoStretchChars vom richtigen Wert ausgeht
164 SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
166 // erst jetzt den Outliner holen, etc. damit obiges SetAttr auch wirkt
167 SdrOutliner& rOutliner = mrObject.ImpGetDrawOutliner();
168 rOutliner.SetText(*mpOutlinerParaObject);
169 delete mpOutlinerParaObject;
170 mpOutlinerParaObject=0;
171 if (bScaleUnitChanged)
173 Fraction aMetricFactor=GetMapFactor(aOldUnit,aNewUnit).X();
175 // Funktioniert nicht richtig:
176 // Geht am Outliner leider nur in %
177 // double nPercFloat=double(aMetricFactor)*100+0.5;
178 // USHORT nPerc=(USHORT)nPercFloat;
179 // rOutliner.DoStretchChars(100,nPerc);
181 if (bSetHgtItem)
183 // Und nun noch das Rahmenattribut korregieren
184 nOldFontHgt=BigMulDiv(nOldFontHgt,aMetricFactor.GetNumerator(),aMetricFactor.GetDenominator());
185 SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
188 SetOutlinerParaObject(rOutliner.CreateParaObject()); // #34494#
189 mpOutlinerParaObject->ClearPortionInfo();
190 mbPortionInfoChecked=FALSE;
191 rOutliner.Clear();
195 void SdrText::ForceOutlinerParaObject( USHORT nOutlMode )
197 if( mpModel && !mpOutlinerParaObject )
199 Outliner* pOutliner = SdrMakeOutliner( nOutlMode, mpModel );
200 if( pOutliner )
202 Outliner& aDrawOutliner = mpModel->GetDrawOutliner();
203 pOutliner->SetCalcFieldValueHdl( aDrawOutliner.GetCalcFieldValueHdl() );
205 pOutliner->SetStyleSheet( 0, GetStyleSheet());
206 OutlinerParaObject* pOutlinerParaObject = pOutliner->CreateParaObject();
207 SetOutlinerParaObject( pOutlinerParaObject );
209 delete pOutliner;
214 const SfxItemSet& SdrText::GetObjectItemSet()
216 return mrObject.GetObjectItemSet();
219 void SdrText::SetObjectItem(const SfxPoolItem& rItem)
221 mrObject.SetObjectItem( rItem );
224 SfxStyleSheet* SdrText::GetStyleSheet() const
226 return mrObject.GetStyleSheet();