xref: /aoo41x/main/svx/source/svdraw/svdtext.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #define ITEMID_FONTHEIGHT   EE_CHAR_FONTHEIGHT
32 
33 #include "svx/svdotext.hxx"
34 #include "svx/svdetc.hxx"
35 #include "editeng/outlobj.hxx"
36 #include "svx/svdoutl.hxx"
37 #include "svx/svdmodel.hxx"
38 #include "editeng/fhgtitem.hxx"
39 #include <editeng/eeitem.hxx>
40 #include <svl/itemset.hxx>
41 
42 SdrText::SdrText( SdrTextObj& rObject, OutlinerParaObject* pOutlinerParaObject /* = 0 */ )
43 : mpOutlinerParaObject( pOutlinerParaObject )
44 , mrObject( rObject )
45 , mpModel( rObject.GetModel() )
46 , mbPortionInfoChecked( false )
47 {
48 	OSL_ENSURE(&mrObject, "SdrText created without SdrTextObj (!)");
49 }
50 
51 SdrText::~SdrText()
52 {
53     clearWeak();
54     delete mpOutlinerParaObject;
55 }
56 
57 void SdrText::CheckPortionInfo( SdrOutliner& rOutliner )
58 {
59 	if(!mbPortionInfoChecked)
60 	{
61         // #i102062# no action when the Outliner is the HitTestOutliner,
62         // this will remove WrongList info at the OPO
63         if(mpModel && &rOutliner == &mpModel->GetHitTestOutliner())
64             return;
65 
66 		// Optimierung: ggf. BigTextObject erzeugen
67 		mbPortionInfoChecked=true;
68 		if(mpOutlinerParaObject!=NULL && rOutliner.ShouldCreateBigTextObject())
69         {
70             // #i102062# MemoryLeak closed
71             delete mpOutlinerParaObject;
72 			mpOutlinerParaObject = rOutliner.CreateParaObject();
73         }
74 	}
75 }
76 
77 void SdrText::ReformatText()
78 {
79 	mbPortionInfoChecked=sal_False;
80 	mpOutlinerParaObject->ClearPortionInfo();
81 }
82 
83 const SfxItemSet& SdrText::GetItemSet() const
84 {
85 	return const_cast< SdrText* >(this)->GetObjectItemSet();
86 }
87 
88 void SdrText::SetOutlinerParaObject( OutlinerParaObject* pTextObject )
89 {
90 	if( mpOutlinerParaObject != pTextObject )
91 	{
92 		if( mpModel )
93 		{
94 			// Update HitTestOutliner
95 			const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
96 			if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
97 				mpModel->GetHitTestOutliner().SetTextObj( 0 );
98 		}
99 
100 		if( mpOutlinerParaObject )
101 			delete mpOutlinerParaObject;
102 
103 		mpOutlinerParaObject = pTextObject;
104 
105 		mbPortionInfoChecked = false;
106 	}
107 }
108 
109 OutlinerParaObject* SdrText::GetOutlinerParaObject() const
110 {
111 	return mpOutlinerParaObject;
112 }
113 
114 /** returns the current OutlinerParaObject and removes it from this instance */
115 OutlinerParaObject* SdrText::RemoveOutlinerParaObject()
116 {
117 	if( mpModel )
118 	{
119 		// Update HitTestOutliner
120 		const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
121 		if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject )
122 			mpModel->GetHitTestOutliner().SetTextObj( 0 );
123 	}
124 
125 	OutlinerParaObject* pOPO = mpOutlinerParaObject;
126 
127 	mpOutlinerParaObject = 0;
128 	mbPortionInfoChecked = false;
129 
130 	return pOPO;
131 }
132 
133 void SdrText::SetModel( SdrModel* pNewModel )
134 {
135 	if( pNewModel == mpModel )
136 		return;
137 
138 	SdrModel* pOldModel = mpModel;
139 	mpModel = pNewModel;
140 
141 	if( mpOutlinerParaObject && pOldModel!=NULL && pNewModel!=NULL)
142 	{
143 		bool bHgtSet = GetObjectItemSet().GetItemState(EE_CHAR_FONTHEIGHT, sal_True) == SFX_ITEM_SET;
144 
145 		MapUnit aOldUnit(pOldModel->GetScaleUnit());
146 		MapUnit aNewUnit(pNewModel->GetScaleUnit());
147 		FASTBOOL bScaleUnitChanged=aNewUnit!=aOldUnit;
148 		// und nun dem OutlinerParaObject einen neuen Pool verpassen
149 		// !!! Hier muss noch DefTab und RefDevice der beiden Models
150 		// !!! verglichen werden und dann ggf. AutoGrow zuschlagen !!!
151 		// !!! fehlende Implementation !!!
152 		sal_uIntPtr nOldFontHgt=pOldModel->GetDefaultFontHeight();
153 		sal_uIntPtr nNewFontHgt=pNewModel->GetDefaultFontHeight();
154 		sal_Bool bDefHgtChanged=nNewFontHgt!=nOldFontHgt;
155 		sal_Bool bSetHgtItem=bDefHgtChanged && !bHgtSet;
156 		if (bSetHgtItem)
157 		{ // #32665#
158 			// zunaechst das HeightItem festklopfen, damit
159 			// 1. Es eben bestehen bleibt und
160 			// 2. DoStretchChars vom richtigen Wert ausgeht
161 			SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
162 		}
163 		// erst jetzt den Outliner holen, etc. damit obiges SetAttr auch wirkt
164 		SdrOutliner& rOutliner = mrObject.ImpGetDrawOutliner();
165 		rOutliner.SetText(*mpOutlinerParaObject);
166 		delete mpOutlinerParaObject;
167 		mpOutlinerParaObject=0;
168 		if (bScaleUnitChanged)
169 		{
170 			Fraction aMetricFactor=GetMapFactor(aOldUnit,aNewUnit).X();
171 
172 			// Funktioniert nicht richtig:
173 			// Geht am Outliner leider nur in %
174 			// double nPercFloat=double(aMetricFactor)*100+0.5;
175 			// sal_uInt16 nPerc=(sal_uInt16)nPercFloat;
176 			// rOutliner.DoStretchChars(100,nPerc);
177 
178 			if (bSetHgtItem)
179 			{
180 				// Und nun noch das Rahmenattribut korregieren
181 				nOldFontHgt=BigMulDiv(nOldFontHgt,aMetricFactor.GetNumerator(),aMetricFactor.GetDenominator());
182 				SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
183 			}
184 		}
185 		SetOutlinerParaObject(rOutliner.CreateParaObject()); // #34494#
186 		mpOutlinerParaObject->ClearPortionInfo();
187 		mbPortionInfoChecked=sal_False;
188 		rOutliner.Clear();
189 	}
190 }
191 
192 void SdrText::ForceOutlinerParaObject( sal_uInt16 nOutlMode )
193 {
194 	if( mpModel && !mpOutlinerParaObject )
195 	{
196 		Outliner* pOutliner = SdrMakeOutliner( nOutlMode, mpModel );
197 		if( pOutliner )
198 		{
199 			Outliner& aDrawOutliner = mpModel->GetDrawOutliner();
200 			pOutliner->SetCalcFieldValueHdl( aDrawOutliner.GetCalcFieldValueHdl() );
201 
202 			pOutliner->SetStyleSheet( 0, GetStyleSheet());
203 			OutlinerParaObject* pOutlinerParaObject = pOutliner->CreateParaObject();
204 			SetOutlinerParaObject( pOutlinerParaObject );
205 
206 			delete pOutliner;
207 		}
208 	}
209 }
210 
211 const SfxItemSet& SdrText::GetObjectItemSet()
212 {
213 	return mrObject.GetObjectItemSet();
214 }
215 
216 void SdrText::SetObjectItem(const SfxPoolItem& rItem)
217 {
218 	mrObject.SetObjectItem( rItem );
219 }
220 
221 SfxStyleSheet* SdrText::GetStyleSheet() const
222 {
223 	return mrObject.GetStyleSheet();
224 }
225