1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26
27 #define ITEMID_FONTHEIGHT EE_CHAR_FONTHEIGHT
28
29 #include "svx/svdotext.hxx"
30 #include "svx/svdetc.hxx"
31 #include "editeng/outlobj.hxx"
32 #include "svx/svdoutl.hxx"
33 #include "svx/svdmodel.hxx"
34 #include "editeng/fhgtitem.hxx"
35 #include <editeng/eeitem.hxx>
36 #include <svl/itemset.hxx>
37
SdrText(SdrTextObj & rObject,OutlinerParaObject * pOutlinerParaObject)38 SdrText::SdrText( SdrTextObj& rObject, OutlinerParaObject* pOutlinerParaObject /* = 0 */ )
39 : mpOutlinerParaObject( pOutlinerParaObject )
40 , mrObject( rObject )
41 , mpModel( rObject.GetModel() )
42 , mbPortionInfoChecked( false )
43 {
44 OSL_ENSURE(&mrObject, "SdrText created without SdrTextObj (!)");
45 }
46
~SdrText()47 SdrText::~SdrText()
48 {
49 clearWeak();
50 delete mpOutlinerParaObject;
51 }
52
CheckPortionInfo(SdrOutliner & rOutliner)53 void SdrText::CheckPortionInfo( SdrOutliner& rOutliner )
54 {
55 if(!mbPortionInfoChecked)
56 {
57 // #i102062# no action when the Outliner is the HitTestOutliner,
58 // this will remove WrongList info at the OPO
59 if(mpModel && &rOutliner == &mpModel->GetHitTestOutliner())
60 return;
61
62 // Optimierung: ggf. BigTextObject erzeugen
63 mbPortionInfoChecked=true;
64 if(mpOutlinerParaObject!=NULL && rOutliner.ShouldCreateBigTextObject())
65 {
66 // #i102062# MemoryLeak closed
67 delete mpOutlinerParaObject;
68 mpOutlinerParaObject = rOutliner.CreateParaObject();
69 }
70 }
71 }
72
ReformatText()73 void SdrText::ReformatText()
74 {
75 mbPortionInfoChecked=sal_False;
76 mpOutlinerParaObject->ClearPortionInfo();
77 }
78
GetItemSet() const79 const SfxItemSet& SdrText::GetItemSet() const
80 {
81 return const_cast< SdrText* >(this)->GetObjectItemSet();
82 }
83
SetOutlinerParaObject(OutlinerParaObject * pTextObject)84 void SdrText::SetOutlinerParaObject( OutlinerParaObject* pTextObject )
85 {
86 if( mpOutlinerParaObject != pTextObject )
87 {
88 if( mpModel )
89 {
90 // Update HitTestOutliner
91 const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
92 if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
93 mpModel->GetHitTestOutliner().SetTextObj( 0 );
94 }
95
96 if( mpOutlinerParaObject )
97 delete mpOutlinerParaObject;
98
99 mpOutlinerParaObject = pTextObject;
100
101 mbPortionInfoChecked = false;
102 }
103 }
104
GetOutlinerParaObject() const105 OutlinerParaObject* SdrText::GetOutlinerParaObject() const
106 {
107 return mpOutlinerParaObject;
108 }
109
110 /** returns the current OutlinerParaObject and removes it from this instance */
RemoveOutlinerParaObject()111 OutlinerParaObject* SdrText::RemoveOutlinerParaObject()
112 {
113 if( mpModel )
114 {
115 // Update HitTestOutliner
116 const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
117 if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
118 mpModel->GetHitTestOutliner().SetTextObj( 0 );
119 }
120
121 OutlinerParaObject* pOPO = mpOutlinerParaObject;
122
123 mpOutlinerParaObject = 0;
124 mbPortionInfoChecked = false;
125
126 return pOPO;
127 }
128
SetModel(SdrModel * pNewModel)129 void SdrText::SetModel( SdrModel* pNewModel )
130 {
131 if( pNewModel == mpModel )
132 return;
133
134 SdrModel* pOldModel = mpModel;
135 mpModel = pNewModel;
136
137 if( mpOutlinerParaObject && pOldModel!=NULL && pNewModel!=NULL)
138 {
139 bool bHgtSet = GetObjectItemSet().GetItemState(EE_CHAR_FONTHEIGHT, sal_True) == SFX_ITEM_SET;
140
141 MapUnit aOldUnit(pOldModel->GetScaleUnit());
142 MapUnit aNewUnit(pNewModel->GetScaleUnit());
143 FASTBOOL bScaleUnitChanged=aNewUnit!=aOldUnit;
144 // und nun dem OutlinerParaObject einen neuen Pool verpassen
145 // !!! Hier muss noch DefTab und RefDevice der beiden Models
146 // !!! verglichen werden und dann ggf. AutoGrow zuschlagen !!!
147 // !!! fehlende Implementation !!!
148 sal_uIntPtr nOldFontHgt=pOldModel->GetDefaultFontHeight();
149 sal_uIntPtr nNewFontHgt=pNewModel->GetDefaultFontHeight();
150 sal_Bool bDefHgtChanged=nNewFontHgt!=nOldFontHgt;
151 sal_Bool bSetHgtItem=bDefHgtChanged && !bHgtSet;
152 if (bSetHgtItem)
153 { // #32665#
154 // zunaechst das HeightItem festklopfen, damit
155 // 1. Es eben bestehen bleibt und
156 // 2. DoStretchChars vom richtigen Wert ausgeht
157 SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
158 }
159 // erst jetzt den Outliner holen, etc. damit obiges SetAttr auch wirkt
160 SdrOutliner& rOutliner = mrObject.ImpGetDrawOutliner();
161 rOutliner.SetText(*mpOutlinerParaObject);
162 delete mpOutlinerParaObject;
163 mpOutlinerParaObject=0;
164 if (bScaleUnitChanged)
165 {
166 Fraction aMetricFactor=GetMapFactor(aOldUnit,aNewUnit).X();
167
168 // Funktioniert nicht richtig:
169 // Geht am Outliner leider nur in %
170 // double nPercFloat=double(aMetricFactor)*100+0.5;
171 // sal_uInt16 nPerc=(sal_uInt16)nPercFloat;
172 // rOutliner.DoStretchChars(100,nPerc);
173
174 if (bSetHgtItem)
175 {
176 // Und nun noch das Rahmenattribut korregieren
177 nOldFontHgt=BigMulDiv(nOldFontHgt,aMetricFactor.GetNumerator(),aMetricFactor.GetDenominator());
178 SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
179 }
180 }
181 SetOutlinerParaObject(rOutliner.CreateParaObject()); // #34494#
182 mpOutlinerParaObject->ClearPortionInfo();
183 mbPortionInfoChecked=sal_False;
184 rOutliner.Clear();
185 }
186 }
187
ForceOutlinerParaObject(sal_uInt16 nOutlMode)188 void SdrText::ForceOutlinerParaObject( sal_uInt16 nOutlMode )
189 {
190 if( mpModel && !mpOutlinerParaObject )
191 {
192 Outliner* pOutliner = SdrMakeOutliner( nOutlMode, mpModel );
193 if( pOutliner )
194 {
195 Outliner& aDrawOutliner = mpModel->GetDrawOutliner();
196 pOutliner->SetCalcFieldValueHdl( aDrawOutliner.GetCalcFieldValueHdl() );
197
198 pOutliner->SetStyleSheet( 0, GetStyleSheet());
199 OutlinerParaObject* pOutlinerParaObject = pOutliner->CreateParaObject();
200 SetOutlinerParaObject( pOutlinerParaObject );
201
202 delete pOutliner;
203 }
204 }
205 }
206
GetObjectItemSet()207 const SfxItemSet& SdrText::GetObjectItemSet()
208 {
209 return mrObject.GetObjectItemSet();
210 }
211
SetObjectItem(const SfxPoolItem & rItem)212 void SdrText::SetObjectItem(const SfxPoolItem& rItem)
213 {
214 mrObject.SetObjectItem( rItem );
215 }
216
GetStyleSheet() const217 SfxStyleSheet* SdrText::GetStyleSheet() const
218 {
219 return mrObject.GetStyleSheet();
220 }
221