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