xref: /aoo42x/main/sw/source/core/text/txtfld.cxx (revision dc0f91dc)
1efeef26fSAndrew Rist /**************************************************************
2*dc0f91dcSmseidel  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*dc0f91dcSmseidel  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*dc0f91dcSmseidel  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19*dc0f91dcSmseidel  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "hintids.hxx"
29cdf0e10cSrcweir #include <fmtfld.hxx>
30cdf0e10cSrcweir #include <txtfld.hxx>
31cdf0e10cSrcweir #include <charfmt.hxx>
32cdf0e10cSrcweir 
33*dc0f91dcSmseidel #include "viewsh.hxx"	// NewFldPortion, GetDoc()
34*dc0f91dcSmseidel #include "doc.hxx"		// NewFldPortion, GetSysFldType()
35*dc0f91dcSmseidel #include "rootfrm.hxx"	// Info about virt. PageNumber
36*dc0f91dcSmseidel #include "pagefrm.hxx"	// NewFldPortion, GetVirtPageNum()
37*dc0f91dcSmseidel #include "ndtxt.hxx"	// NewNumberPortion, pHints->GetNum()
38*dc0f91dcSmseidel #include "fldbas.hxx"	// SwField
39cdf0e10cSrcweir #include "viewopt.hxx"	// SwViewOptions
40*dc0f91dcSmseidel #include "flyfrm.hxx"	// IsInBody()
41cdf0e10cSrcweir #include "viewimp.hxx"
42*dc0f91dcSmseidel #include "txtatr.hxx"	// SwTxtFld
43cdf0e10cSrcweir #include "txtcfg.hxx"
44*dc0f91dcSmseidel #include "swfont.hxx"	// NewFldPortion, new SwFont
45*dc0f91dcSmseidel #include "fntcache.hxx"	// NewFldPortion, SwFntAccess
46cdf0e10cSrcweir #include "porfld.hxx"
47*dc0f91dcSmseidel #include "porftn.hxx"	// NewExtraPortion
48*dc0f91dcSmseidel #include "porref.hxx"	// NewExtraPortion
49*dc0f91dcSmseidel #include "portox.hxx"	// NewExtraPortion
50*dc0f91dcSmseidel #include "porhyph.hxx"	// NewExtraPortion
51*dc0f91dcSmseidel #include "porfly.hxx"	// NewExtraPortion
52*dc0f91dcSmseidel #include "itrform2.hxx"	// SwTxtFormatter
53cdf0e10cSrcweir #include "chpfld.hxx"
54cdf0e10cSrcweir #include "dbfld.hxx"
55cdf0e10cSrcweir #include "expfld.hxx"
56cdf0e10cSrcweir #include "docufld.hxx"
57*dc0f91dcSmseidel #include "pagedesc.hxx"	// NewFldPortion, GetNum()
58*dc0f91dcSmseidel #include <pormulti.hxx>	// SwMultiPortion
59*dc0f91dcSmseidel #include "fmtmeta.hxx"	// lcl_NewMetaPortion
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
62ca62e2c2SSteve Yin #ifndef _REFFLD_HXX
63ca62e2c2SSteve Yin #include "reffld.hxx"
64ca62e2c2SSteve Yin #endif
65ca62e2c2SSteve Yin #ifndef _FLDDAT_HXX
66ca62e2c2SSteve Yin #include "flddat.hxx"
67ca62e2c2SSteve Yin #endif
68*dc0f91dcSmseidel 
69*dc0f91dcSmseidel 
70cdf0e10cSrcweir /*************************************************************************
71*dc0f91dcSmseidel  * SwTxtFormatter::NewFldPortion()
72cdf0e10cSrcweir  *************************************************************************/
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 
lcl_IsInBody(SwFrm * pFrm)75cdf0e10cSrcweir sal_Bool lcl_IsInBody( SwFrm *pFrm )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	if ( pFrm->IsInDocBody() )
78cdf0e10cSrcweir 		return sal_True;
79cdf0e10cSrcweir 	else
80cdf0e10cSrcweir 	{
81*dc0f91dcSmseidel 		const SwFrm *pTmp = pFrm;
82*dc0f91dcSmseidel 		const SwFlyFrm *pFly;
83cdf0e10cSrcweir 		while ( 0 != (pFly = pTmp->FindFlyFrm()) )
84*dc0f91dcSmseidel 			pTmp = pFly->GetAnchorFrm();
85cdf0e10cSrcweir 		return pTmp->IsInDocBody();
86cdf0e10cSrcweir 	}
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 
NewFldPortion(SwTxtFormatInfo & rInf,const SwTxtAttr * pHint) const90cdf0e10cSrcweir SwExpandPortion *SwTxtFormatter::NewFldPortion( SwTxtFormatInfo &rInf,
91cdf0e10cSrcweir 												const SwTxtAttr *pHint ) const
92cdf0e10cSrcweir {
93cdf0e10cSrcweir 	SwExpandPortion *pRet = 0;
94cdf0e10cSrcweir 	SwFrm *pFrame = (SwFrm*)pFrm;
95c0286415SOliver-Rainer Wittmann 	SwField *pFld = (SwField*)pHint->GetFmtFld().GetField();
96cdf0e10cSrcweir 	const sal_Bool bName = rInf.GetOpt().IsFldName();
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	SwCharFmt* pChFmt = 0;
99cdf0e10cSrcweir 	sal_Bool bNewFlyPor = sal_False,
100cdf0e10cSrcweir 		 bINet = sal_False;
101ca62e2c2SSteve Yin 	sal_uInt16 subType;
102cdf0e10cSrcweir 	// set language
103cdf0e10cSrcweir 	((SwTxtFormatter*)this)->SeekAndChg( rInf );
104cdf0e10cSrcweir 	if (pFld->GetLanguage() != GetFnt()->GetLanguage())
105cdf0e10cSrcweir 	{
106cdf0e10cSrcweir 		pFld->SetLanguage( GetFnt()->GetLanguage() );
107cdf0e10cSrcweir 		// let the visual note know about its new language
108cdf0e10cSrcweir 		if (pFld->GetTyp()->Which()==RES_POSTITFLD)
109*dc0f91dcSmseidel 			const_cast<SwFmtFld*> (&pHint->GetFmtFld())->Broadcast( SwFmtFldHint( &pHint->GetFmtFld(), SWFMTFLD_LANGUAGE ) );
110cdf0e10cSrcweir 	}
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	ViewShell *pSh = rInf.GetVsh();
113*dc0f91dcSmseidel 	SwDoc *const pDoc( (pSh) ? pSh->GetDoc() : 0 );
114*dc0f91dcSmseidel 	bool const bInClipboard( (pDoc) ? pDoc->IsClipBoard() : true );
115*dc0f91dcSmseidel 	sal_Bool bPlaceHolder = sal_False;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	switch( pFld->GetTyp()->Which() )
118cdf0e10cSrcweir 	{
119cdf0e10cSrcweir 		case RES_SCRIPTFLD:
120cdf0e10cSrcweir 		case RES_POSTITFLD:
121cdf0e10cSrcweir 			pRet = new SwPostItsPortion( RES_SCRIPTFLD == pFld->GetTyp()->Which() );
122cdf0e10cSrcweir 			break;
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 		case RES_COMBINED_CHARS:
125cdf0e10cSrcweir 			{
126cdf0e10cSrcweir 				if( bName )
127*dc0f91dcSmseidel 				{
128*dc0f91dcSmseidel 					String const sName( pFld->GetFieldName() );
129*dc0f91dcSmseidel 					pRet = new SwFldPortion(sName);
130*dc0f91dcSmseidel 				}
131cdf0e10cSrcweir 				else
132*dc0f91dcSmseidel 				{
133*dc0f91dcSmseidel 					String const sContent( pFld->ExpandField(bInClipboard) );
134*dc0f91dcSmseidel 					pRet = new SwCombinedPortion(sContent);
135*dc0f91dcSmseidel 				}
136cdf0e10cSrcweir 			}
137cdf0e10cSrcweir 			break;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 		case RES_HIDDENTXTFLD:
140*dc0f91dcSmseidel 			{
141*dc0f91dcSmseidel 				String const str( (bName)
142*dc0f91dcSmseidel 						? pFld->GetFieldName()
143*dc0f91dcSmseidel 						: pFld->ExpandField(bInClipboard) );
144*dc0f91dcSmseidel 				pRet = new SwHiddenPortion(str);
145*dc0f91dcSmseidel 			}
146cdf0e10cSrcweir 			break;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 		case RES_CHAPTERFLD:
149cdf0e10cSrcweir 			if( !bName && pSh && !pSh->Imp()->IsUpdateExpFlds() )
150cdf0e10cSrcweir 			{
151cdf0e10cSrcweir 				((SwChapterField*)pFld)->ChangeExpansion( pFrame,
152cdf0e10cSrcweir 										&((SwTxtFld*)pHint)->GetTxtNode() );
153cdf0e10cSrcweir 			}
154*dc0f91dcSmseidel 			{
155*dc0f91dcSmseidel 				String const str( (bName)
156*dc0f91dcSmseidel 						? pFld->GetFieldName()
157*dc0f91dcSmseidel 						: pFld->ExpandField(bInClipboard) );
158*dc0f91dcSmseidel 				pRet = new SwFldPortion( str );
159*dc0f91dcSmseidel 			}
160cdf0e10cSrcweir 			break;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 		case RES_DOCSTATFLD:
163cdf0e10cSrcweir 			if( !bName && pSh && !pSh->Imp()->IsUpdateExpFlds() )
164*dc0f91dcSmseidel 			{
165cdf0e10cSrcweir 				((SwDocStatField*)pFld)->ChangeExpansion( pFrame );
166*dc0f91dcSmseidel 			}
167*dc0f91dcSmseidel 			{
168*dc0f91dcSmseidel 				String const str( (bName)
169*dc0f91dcSmseidel 						? pFld->GetFieldName()
170*dc0f91dcSmseidel 						: pFld->ExpandField(bInClipboard) );
171*dc0f91dcSmseidel 				pRet = new SwFldPortion( str );
172*dc0f91dcSmseidel 			}
173*dc0f91dcSmseidel 			if(pRet)
174*dc0f91dcSmseidel 				((SwFldPortion*)pRet)->m_nAttrFldType= ATTR_PAGECOOUNTFLD;
175*dc0f91dcSmseidel 			break;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 		case RES_PAGENUMBERFLD:
178cdf0e10cSrcweir 		{
179*dc0f91dcSmseidel 			if( !bName && pSh && pSh->GetLayout() && !pSh->Imp()->IsUpdateExpFlds() ) // swmod 080122
180cdf0e10cSrcweir 			{
181*dc0f91dcSmseidel 				SwPageNumberFieldType *pPageNr = (SwPageNumberFieldType *)pFld->GetTyp();
182cdf0e10cSrcweir 
183*dc0f91dcSmseidel 				const SwRootFrm* pTmpRootFrm = pSh->GetLayout();
184*dc0f91dcSmseidel 				const sal_Bool bVirt = pTmpRootFrm->IsVirtPageNum();
185cdf0e10cSrcweir 
186*dc0f91dcSmseidel 				MSHORT nVirtNum = pFrame->GetVirtPageNum();
187*dc0f91dcSmseidel 				MSHORT nNumPages = pTmpRootFrm->GetPageNum();
188cdf0e10cSrcweir 				sal_Int16 nNumFmt = -1;
189cdf0e10cSrcweir 				if(SVX_NUM_PAGEDESC == pFld->GetFormat())
190cdf0e10cSrcweir 					nNumFmt = pFrame->FindPageFrm()->GetPageDesc()->GetNumType().GetNumberingType();
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 				pPageNr->ChangeExpansion( pDoc, nVirtNum, nNumPages,
193cdf0e10cSrcweir 											bVirt, nNumFmt > -1 ? &nNumFmt : 0);
194cdf0e10cSrcweir 			}
195*dc0f91dcSmseidel 			{
196*dc0f91dcSmseidel 				String const str( (bName)
197*dc0f91dcSmseidel 						? pFld->GetFieldName()
198*dc0f91dcSmseidel 						: pFld->ExpandField(bInClipboard) );
199*dc0f91dcSmseidel 				pRet = new SwFldPortion( str );
200*dc0f91dcSmseidel 			}
201*dc0f91dcSmseidel 			if(pRet)
202*dc0f91dcSmseidel 				((SwFldPortion*)pRet)->m_nAttrFldType= ATTR_PAGENUMBERFLD;
203*dc0f91dcSmseidel 			break;
204cdf0e10cSrcweir 		}
205cdf0e10cSrcweir 		case RES_GETEXPFLD:
206cdf0e10cSrcweir 		{
207cdf0e10cSrcweir 			if( !bName && pSh && !pSh->Imp()->IsUpdateExpFlds() )
208cdf0e10cSrcweir 			{
209cdf0e10cSrcweir 				SwGetExpField* pExpFld = (SwGetExpField*)pFld;
210cdf0e10cSrcweir 				if( !::lcl_IsInBody( pFrame ) )
211cdf0e10cSrcweir 				{
212cdf0e10cSrcweir 					pExpFld->ChgBodyTxtFlag( sal_False );
213cdf0e10cSrcweir 					pExpFld->ChangeExpansion( *pFrame, *((SwTxtFld*)pHint) );
214cdf0e10cSrcweir 				}
215cdf0e10cSrcweir 				else if( !pExpFld->IsInBodyTxt() )
216cdf0e10cSrcweir 				{
217*dc0f91dcSmseidel 					// war vorher anders, also erst expandieren, dann umsetzen!
218cdf0e10cSrcweir 					pExpFld->ChangeExpansion( *pFrame, *((SwTxtFld*)pHint) );
219cdf0e10cSrcweir 					pExpFld->ChgBodyTxtFlag( sal_True );
220cdf0e10cSrcweir 				}
221cdf0e10cSrcweir 			}
222*dc0f91dcSmseidel 			{
223*dc0f91dcSmseidel 				String const str( (bName)
224*dc0f91dcSmseidel 						? pFld->GetFieldName()
225*dc0f91dcSmseidel 						: pFld->ExpandField(bInClipboard) );
226*dc0f91dcSmseidel 				pRet = new SwFldPortion( str );
227*dc0f91dcSmseidel 			}
228cdf0e10cSrcweir 			break;
229cdf0e10cSrcweir 		}
230cdf0e10cSrcweir 		case RES_DBFLD:
231cdf0e10cSrcweir 		{
232cdf0e10cSrcweir 			if( !bName )
233cdf0e10cSrcweir 			{
234cdf0e10cSrcweir 				SwDBField* pDBFld = (SwDBField*)pFld;
235cdf0e10cSrcweir 				pDBFld->ChgBodyTxtFlag( ::lcl_IsInBody( pFrame ) );
236cdf0e10cSrcweir /* Solange das ChangeExpansion auskommentiert ist.
237cdf0e10cSrcweir  * Aktualisieren in Kopf/Fuszeilen geht aktuell nicht.
238cdf0e10cSrcweir 				if( !::lcl_IsInBody( pFrame ) )
239cdf0e10cSrcweir 				{
240cdf0e10cSrcweir 					pDBFld->ChgBodyTxtFlag( sal_False );
241cdf0e10cSrcweir 					pDBFld->ChangeExpansion( pFrame, (SwTxtFld*)pHint );
242cdf0e10cSrcweir 				}
243cdf0e10cSrcweir 				else if( !pDBFld->IsInBodyTxt() )
244cdf0e10cSrcweir 				{
245cdf0e10cSrcweir 					// war vorher anders, also erst expandieren, dann umsetzen!!
246cdf0e10cSrcweir 					pDBFld->ChangeExpansion( pFrame, (SwTxtFld*)pHint );
247cdf0e10cSrcweir 					pDBFld->ChgBodyTxtFlag( sal_True );
248cdf0e10cSrcweir 				}
249cdf0e10cSrcweir */
250cdf0e10cSrcweir 			}
251*dc0f91dcSmseidel 			{
252*dc0f91dcSmseidel 				String const str( (bName)
253*dc0f91dcSmseidel 						? pFld->GetFieldName()
254*dc0f91dcSmseidel 						: pFld->ExpandField(bInClipboard) );
255*dc0f91dcSmseidel 				pRet = new SwFldPortion(str);
256*dc0f91dcSmseidel 			}
257cdf0e10cSrcweir 			break;
258cdf0e10cSrcweir 		}
259cdf0e10cSrcweir 		case RES_REFPAGEGETFLD:
260cdf0e10cSrcweir 			if( !bName && pSh && !pSh->Imp()->IsUpdateExpFlds() )
261*dc0f91dcSmseidel 			{
262cdf0e10cSrcweir 				((SwRefPageGetField*)pFld)->ChangeExpansion( pFrame, (SwTxtFld*)pHint );
263*dc0f91dcSmseidel 			}
264*dc0f91dcSmseidel 			{
265*dc0f91dcSmseidel 				String const str( (bName)
266*dc0f91dcSmseidel 						? pFld->GetFieldName()
267*dc0f91dcSmseidel 						: pFld->ExpandField(bInClipboard) );
268*dc0f91dcSmseidel 				pRet = new SwFldPortion(str);
269*dc0f91dcSmseidel 			}
270cdf0e10cSrcweir 			break;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 		case RES_JUMPEDITFLD:
273cdf0e10cSrcweir 			if( !bName )
274*dc0f91dcSmseidel 				pChFmt = ((SwJumpEditField*)pFld)->GetCharFmt();
275cdf0e10cSrcweir 			bNewFlyPor = sal_True;
276*dc0f91dcSmseidel 			bPlaceHolder = sal_True;
277cdf0e10cSrcweir 			break;
278ca62e2c2SSteve Yin 		case RES_GETREFFLD:
279*dc0f91dcSmseidel 			subType = ((SwGetRefField*)pFld)->GetSubType();
280ca62e2c2SSteve Yin 			{
281*dc0f91dcSmseidel 				String const str( (bName)
282*dc0f91dcSmseidel 						? pFld->GetFieldName()
283*dc0f91dcSmseidel 						: pFld->ExpandField(bInClipboard) );
284*dc0f91dcSmseidel 				pRet = new SwFldPortion(str);
285*dc0f91dcSmseidel 			}
286*dc0f91dcSmseidel 			if(pRet)
287*dc0f91dcSmseidel 			{
288*dc0f91dcSmseidel 				if( subType == REF_BOOKMARK )
289*dc0f91dcSmseidel 					((SwFldPortion*)pRet)->m_nAttrFldType = ATTR_BOOKMARKFLD;
290ca62e2c2SSteve Yin 				else if( subType == REF_SETREFATTR )
291ca62e2c2SSteve Yin 					((SwFldPortion*)pRet)->m_nAttrFldType = ATTR_SETREFATTRFLD;
292ca62e2c2SSteve Yin 				break;
293ca62e2c2SSteve Yin 			}
294ca62e2c2SSteve Yin 		case RES_DATETIMEFLD:
295ca62e2c2SSteve Yin 			subType = ((SwDateTimeField*)pFld)->GetSubType();
296ca62e2c2SSteve Yin 			{
297*dc0f91dcSmseidel 				String const str( (bName)
298*dc0f91dcSmseidel 						? pFld->GetFieldName()
299*dc0f91dcSmseidel 						: pFld->ExpandField(bInClipboard) );
300*dc0f91dcSmseidel 				pRet = new SwFldPortion(str);
301*dc0f91dcSmseidel 			}
302*dc0f91dcSmseidel 			if(pRet)
303*dc0f91dcSmseidel 			{
304*dc0f91dcSmseidel 				if( subType & DATEFLD )
305ca62e2c2SSteve Yin 					((SwFldPortion*)pRet)->m_nAttrFldType= ATTR_DATEFLD;
306ca62e2c2SSteve Yin 				else if( subType & TIMEFLD )
307ca62e2c2SSteve Yin 					((SwFldPortion*)pRet)->m_nAttrFldType = ATTR_TIMEFLD;
308ca62e2c2SSteve Yin 				break;
309ca62e2c2SSteve Yin 			}
310cdf0e10cSrcweir 		default:
311*dc0f91dcSmseidel 			{
312*dc0f91dcSmseidel 				String const str( (bName)
313*dc0f91dcSmseidel 						? pFld->GetFieldName()
314*dc0f91dcSmseidel 						: pFld->ExpandField(bInClipboard) );
315*dc0f91dcSmseidel 				pRet = new SwFldPortion(str);
316*dc0f91dcSmseidel 			}
317cdf0e10cSrcweir 	}
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 	if( bNewFlyPor )
320cdf0e10cSrcweir 	{
321cdf0e10cSrcweir 		SwFont *pTmpFnt = 0;
322cdf0e10cSrcweir 		if( !bName )
323cdf0e10cSrcweir 		{
324cdf0e10cSrcweir 			pTmpFnt = new SwFont( *pFnt );
325cdf0e10cSrcweir 			if( bINet )
326cdf0e10cSrcweir 			{
327cdf0e10cSrcweir 				SwAttrPool* pPool = pChFmt->GetAttrSet().GetPool();
328cdf0e10cSrcweir 				SfxItemSet aSet( *pPool, RES_CHRATR_BEGIN, RES_CHRATR_END );
329cdf0e10cSrcweir 				SfxItemSet aTmpSet( aSet );
330*dc0f91dcSmseidel 				pFrm->GetTxtNode()->GetAttr(aSet,rInf.GetIdx(),rInf.GetIdx()+1);
331cdf0e10cSrcweir 				aTmpSet.Set( pChFmt->GetAttrSet() );
332cdf0e10cSrcweir 				aTmpSet.Differentiate( aSet );
333cdf0e10cSrcweir 				if( aTmpSet.Count() )
334*dc0f91dcSmseidel 					pTmpFnt->SetDiffFnt( &aTmpSet, pFrm->GetTxtNode()->getIDocumentSettingAccess() );
335cdf0e10cSrcweir 			}
336cdf0e10cSrcweir 			else
337*dc0f91dcSmseidel 				pTmpFnt->SetDiffFnt( &pChFmt->GetAttrSet(), pFrm->GetTxtNode()->getIDocumentSettingAccess() );
338*dc0f91dcSmseidel 		}
339*dc0f91dcSmseidel 		{
340*dc0f91dcSmseidel 			String const str( (bName)
341*dc0f91dcSmseidel 					? pFld->GetFieldName()
342*dc0f91dcSmseidel 					: pFld->ExpandField(bInClipboard) );
343*dc0f91dcSmseidel 			pRet = new SwFldPortion(str, pTmpFnt, bPlaceHolder);
344cdf0e10cSrcweir 		}
345cdf0e10cSrcweir 	}
346cdf0e10cSrcweir 
347cdf0e10cSrcweir 	return pRet;
348cdf0e10cSrcweir }
349cdf0e10cSrcweir 
350cdf0e10cSrcweir /*************************************************************************
351*dc0f91dcSmseidel  * SwTxtFormatter::TryNewNoLengthPortion()
352cdf0e10cSrcweir  *************************************************************************/
353cdf0e10cSrcweir 
lcl_NewMetaPortion(SwTxtAttr & rHint,const bool bPrefix)354cdf0e10cSrcweir SwFldPortion * lcl_NewMetaPortion(SwTxtAttr & rHint, const bool bPrefix)
355cdf0e10cSrcweir {
356*dc0f91dcSmseidel 	::sw::Meta *const pMeta(
357*dc0f91dcSmseidel 		static_cast<SwFmtMeta &>(rHint.GetAttr()).GetMeta() );
358*dc0f91dcSmseidel 	::rtl::OUString fix;
359*dc0f91dcSmseidel 	::sw::MetaField *const pField( dynamic_cast< ::sw::MetaField * >(pMeta) );
360*dc0f91dcSmseidel 	OSL_ENSURE(pField, "lcl_NewMetaPortion: no meta field?");
361*dc0f91dcSmseidel 	if (pField)
362*dc0f91dcSmseidel 	{
363*dc0f91dcSmseidel 		pField->GetPrefixAndSuffix((bPrefix) ? &fix : 0, (bPrefix) ? 0 : &fix);
364*dc0f91dcSmseidel 	}
365*dc0f91dcSmseidel 	return new SwFldPortion( fix );
366cdf0e10cSrcweir }
367cdf0e10cSrcweir 
368cdf0e10cSrcweir /** Try to create a new portion with zero length, for an end of a hint
369*dc0f91dcSmseidel 	(where there is no CH_TXTATR). Because there may be multiple hint ends at a
370*dc0f91dcSmseidel 	given index, m_nHintEndIndex is used to keep track of the already created
371*dc0f91dcSmseidel 	portions. But the portions created here may actually be deleted again,
372*dc0f91dcSmseidel 	due to UnderFlow. In that case, m_nHintEndIndex must be decremented,
373*dc0f91dcSmseidel 	so the portion will be created again on the next line.
374cdf0e10cSrcweir  */
375cdf0e10cSrcweir SwExpandPortion *
TryNewNoLengthPortion(SwTxtFormatInfo & rInfo)376cdf0e10cSrcweir SwTxtFormatter::TryNewNoLengthPortion(SwTxtFormatInfo & rInfo)
377cdf0e10cSrcweir {
378*dc0f91dcSmseidel 	if (pHints)
379*dc0f91dcSmseidel 	{
380*dc0f91dcSmseidel 		const xub_StrLen nIdx(rInfo.GetIdx());
381*dc0f91dcSmseidel 		while (m_nHintEndIndex < pHints->GetEndCount())
382*dc0f91dcSmseidel 		{
383*dc0f91dcSmseidel 			SwTxtAttr & rHint( *pHints->GetEnd(m_nHintEndIndex) );
384*dc0f91dcSmseidel 			xub_StrLen const nEnd( *rHint.GetAnyEnd() );
385*dc0f91dcSmseidel 			if (nEnd > nIdx)
386*dc0f91dcSmseidel 			{
387*dc0f91dcSmseidel 				break;
388*dc0f91dcSmseidel 			}
389*dc0f91dcSmseidel 			++m_nHintEndIndex;
390*dc0f91dcSmseidel 			if (nEnd == nIdx)
391*dc0f91dcSmseidel 			{
392*dc0f91dcSmseidel 				if (RES_TXTATR_METAFIELD == rHint.Which())
393*dc0f91dcSmseidel 				{
394*dc0f91dcSmseidel 					SwFldPortion *const pPortion(
395*dc0f91dcSmseidel 							lcl_NewMetaPortion(rHint, false));
396*dc0f91dcSmseidel 					pPortion->SetNoLength(); // no CH_TXTATR at hint end!
397*dc0f91dcSmseidel 					return pPortion;
398*dc0f91dcSmseidel 				}
399*dc0f91dcSmseidel 			}
400*dc0f91dcSmseidel 		}
401*dc0f91dcSmseidel 	}
402*dc0f91dcSmseidel 	return 0;
403cdf0e10cSrcweir }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir /*************************************************************************
406*dc0f91dcSmseidel  * SwTxtFormatter::NewExtraPortion()
407cdf0e10cSrcweir  *************************************************************************/
408cdf0e10cSrcweir 
NewExtraPortion(SwTxtFormatInfo & rInf)409cdf0e10cSrcweir SwLinePortion *SwTxtFormatter::NewExtraPortion( SwTxtFormatInfo &rInf )
410cdf0e10cSrcweir {
411*dc0f91dcSmseidel 	SwTxtAttr *pHint = GetAttr( rInf.GetIdx() );
412*dc0f91dcSmseidel 	SwLinePortion *pRet = 0;
413*dc0f91dcSmseidel 	if( !pHint )
414*dc0f91dcSmseidel 	{
415*dc0f91dcSmseidel 		pRet = new SwTxtPortion;
416*dc0f91dcSmseidel 		pRet->SetLen( 1 );
417*dc0f91dcSmseidel 		rInf.SetLen( 1 );
418*dc0f91dcSmseidel 		return pRet;
419*dc0f91dcSmseidel 	}
420*dc0f91dcSmseidel 
421*dc0f91dcSmseidel 	switch( pHint->Which() )
422*dc0f91dcSmseidel 	{
423*dc0f91dcSmseidel 	case RES_TXTATR_FLYCNT :
424*dc0f91dcSmseidel 		{
425*dc0f91dcSmseidel 			pRet = NewFlyCntPortion( rInf, pHint );
426*dc0f91dcSmseidel 			break;
427*dc0f91dcSmseidel 		}
428*dc0f91dcSmseidel 	case RES_TXTATR_FTN :
429*dc0f91dcSmseidel 		{
430*dc0f91dcSmseidel 			pRet = NewFtnPortion( rInf, pHint );
431*dc0f91dcSmseidel 			break;
432*dc0f91dcSmseidel 		}
433*dc0f91dcSmseidel 	case RES_TXTATR_FIELD :
434*dc0f91dcSmseidel 	case RES_TXTATR_ANNOTATION :
435*dc0f91dcSmseidel 		{
436*dc0f91dcSmseidel 			pRet = NewFldPortion( rInf, pHint );
437*dc0f91dcSmseidel 			break;
438*dc0f91dcSmseidel 		}
439*dc0f91dcSmseidel 	case RES_TXTATR_REFMARK :
440*dc0f91dcSmseidel 		{
441*dc0f91dcSmseidel 			pRet = new SwIsoRefPortion;
442*dc0f91dcSmseidel 			break;
443*dc0f91dcSmseidel 		}
444*dc0f91dcSmseidel 	case RES_TXTATR_TOXMARK :
445*dc0f91dcSmseidel 		{
446*dc0f91dcSmseidel 			pRet = new SwIsoToxPortion;
447*dc0f91dcSmseidel 			break;
448*dc0f91dcSmseidel 		}
449*dc0f91dcSmseidel 	case RES_TXTATR_METAFIELD:
450*dc0f91dcSmseidel 		{
451*dc0f91dcSmseidel 			pRet = lcl_NewMetaPortion( *pHint, true );
452*dc0f91dcSmseidel 			break;
453*dc0f91dcSmseidel 		}
454*dc0f91dcSmseidel 	default: ;
455*dc0f91dcSmseidel 	}
456*dc0f91dcSmseidel 	if( !pRet )
457*dc0f91dcSmseidel 	{
458*dc0f91dcSmseidel 		const XubString aNothing;
459*dc0f91dcSmseidel 		pRet = new SwFldPortion( aNothing );
460*dc0f91dcSmseidel 		rInf.SetLen( 1 );
461*dc0f91dcSmseidel 	}
462*dc0f91dcSmseidel 	return pRet;
463cdf0e10cSrcweir }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir /*************************************************************************
466*dc0f91dcSmseidel  * SwTxtFormatter::NewNumberPortion()
467cdf0e10cSrcweir  *************************************************************************/
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 
NewNumberPortion(SwTxtFormatInfo & rInf) const470cdf0e10cSrcweir SwNumberPortion *SwTxtFormatter::NewNumberPortion( SwTxtFormatInfo &rInf ) const
471cdf0e10cSrcweir {
472cdf0e10cSrcweir 	if( rInf.IsNumDone() || rInf.GetTxtStart() != nStart
473cdf0e10cSrcweir 				|| rInf.GetTxtStart() != rInf.GetIdx() )
474cdf0e10cSrcweir 		return 0;
475cdf0e10cSrcweir 
476cdf0e10cSrcweir 	SwNumberPortion *pRet = 0;
477cdf0e10cSrcweir 	const SwTxtNode* pTxtNd = GetTxtFrm()->GetTxtNode();
478cdf0e10cSrcweir 	const SwNumRule* pNumRule = pTxtNd->GetNumRule();
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 	// hat ein "gueltige" Nummer ?
481*dc0f91dcSmseidel 	if( pTxtNd->IsNumbered() && pTxtNd->IsCountedInList())
482cdf0e10cSrcweir 	{
483*dc0f91dcSmseidel 		const SwNumFmt &rNumFmt = pNumRule->Get( static_cast<sal_uInt16>(pTxtNd->GetActualListLevel()) );
484cdf0e10cSrcweir 		const sal_Bool bLeft = SVX_ADJUST_LEFT == rNumFmt.GetNumAdjust();
485cdf0e10cSrcweir 		const sal_Bool bCenter = SVX_ADJUST_CENTER == rNumFmt.GetNumAdjust();
486*dc0f91dcSmseidel 		// --> OD 2008-01-23 #newlistlevelattrs#
487*dc0f91dcSmseidel 		const bool bLabelAlignmentPosAndSpaceModeActive(
488*dc0f91dcSmseidel 				rNumFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT );
489*dc0f91dcSmseidel 		const KSHORT nMinDist = bLabelAlignmentPosAndSpaceModeActive
490*dc0f91dcSmseidel 								? 0 : rNumFmt.GetCharTextDistance();
491*dc0f91dcSmseidel 		// <--
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 		if( SVX_NUM_BITMAP == rNumFmt.GetNumberingType() )
494cdf0e10cSrcweir 		{
495*dc0f91dcSmseidel 			// --> OD 2008-01-23 #newlistlevelattrs#
496*dc0f91dcSmseidel 			pRet = new SwGrfNumPortion( (SwFrm*)GetTxtFrm(),
497*dc0f91dcSmseidel 										pTxtNd->GetLabelFollowedBy(),
498*dc0f91dcSmseidel 										rNumFmt.GetBrush(),
499*dc0f91dcSmseidel 										rNumFmt.GetGraphicOrientation(),
500*dc0f91dcSmseidel 										rNumFmt.GetGraphicSize(),
501*dc0f91dcSmseidel 										bLeft, bCenter, nMinDist,
502*dc0f91dcSmseidel 										bLabelAlignmentPosAndSpaceModeActive );
503*dc0f91dcSmseidel 			// <--
504cdf0e10cSrcweir 			long nTmpA = rInf.GetLast()->GetAscent();
505cdf0e10cSrcweir 			long nTmpD = rInf.GetLast()->Height() - nTmpA;
506cdf0e10cSrcweir 			if( !rInf.IsTest() )
507cdf0e10cSrcweir 				((SwGrfNumPortion*)pRet)->SetBase( nTmpA, nTmpD, nTmpA, nTmpD );
508cdf0e10cSrcweir 		}
509cdf0e10cSrcweir 		else
510cdf0e10cSrcweir 		{
511cdf0e10cSrcweir 			// Der SwFont wird dynamisch angelegt und im CTOR uebergeben,
512cdf0e10cSrcweir 			// weil das CharFmt nur einen SV-Font zurueckliefert.
513cdf0e10cSrcweir 			// Im Dtor vom SwNumberPortion wird der SwFont deletet.
514cdf0e10cSrcweir 			SwFont *pNumFnt = 0;
515cdf0e10cSrcweir 			const SwAttrSet* pFmt = rNumFmt.GetCharFmt() ?
516*dc0f91dcSmseidel 									&rNumFmt.GetCharFmt()->GetAttrSet() :
517*dc0f91dcSmseidel 									NULL;
518*dc0f91dcSmseidel 			const IDocumentSettingAccess* pIDSA = pTxtNd->getIDocumentSettingAccess();
519cdf0e10cSrcweir 
520*dc0f91dcSmseidel 			if( SVX_NUM_CHAR_SPECIAL == rNumFmt.GetNumberingType() )
521cdf0e10cSrcweir 			{
522cdf0e10cSrcweir 				const Font *pFmtFnt = rNumFmt.GetBulletFont();
523cdf0e10cSrcweir 
524*dc0f91dcSmseidel 				// Build a new bullet font basing on the current paragraph font:
525*dc0f91dcSmseidel 				pNumFnt = new SwFont( &rInf.GetCharAttr(), pIDSA );
526*dc0f91dcSmseidel 
527*dc0f91dcSmseidel 				// --> FME 2005-08-11 #i53199#
528*dc0f91dcSmseidel 				if ( !pIDSA->get(IDocumentSettingAccess::DO_NOT_RESET_PARA_ATTRS_FOR_NUM_FONT) )
529*dc0f91dcSmseidel 				{
530*dc0f91dcSmseidel 					// i18463:
531*dc0f91dcSmseidel 					// Underline style of paragraph font should not be considered
532*dc0f91dcSmseidel 					// Overline style of paragraph font should not be considered
533*dc0f91dcSmseidel 					// Weight style of paragraph font should not be considered
534*dc0f91dcSmseidel 					// Posture style of paragraph font should not be considered
535*dc0f91dcSmseidel 					pNumFnt->SetUnderline( UNDERLINE_NONE );
536*dc0f91dcSmseidel 					pNumFnt->SetOverline( UNDERLINE_NONE );
537*dc0f91dcSmseidel 					pNumFnt->SetItalic( ITALIC_NONE, SW_LATIN );
538*dc0f91dcSmseidel 					pNumFnt->SetItalic( ITALIC_NONE, SW_CJK );
539*dc0f91dcSmseidel 					pNumFnt->SetItalic( ITALIC_NONE, SW_CTL );
540*dc0f91dcSmseidel 					pNumFnt->SetWeight( WEIGHT_NORMAL, SW_LATIN );
541*dc0f91dcSmseidel 					pNumFnt->SetWeight( WEIGHT_NORMAL, SW_CJK );
542*dc0f91dcSmseidel 					pNumFnt->SetWeight( WEIGHT_NORMAL, SW_CTL );
543*dc0f91dcSmseidel 				}
544*dc0f91dcSmseidel 
545*dc0f91dcSmseidel 				// Apply the explicit attributes from the character style
546*dc0f91dcSmseidel 				// associated with the numbering to the new bullet font.
547cdf0e10cSrcweir 				if( pFmt )
548*dc0f91dcSmseidel 					pNumFnt->SetDiffFnt( pFmt, pIDSA );
549cdf0e10cSrcweir 
550*dc0f91dcSmseidel 				if ( pFmtFnt )
551cdf0e10cSrcweir 				{
552cdf0e10cSrcweir 					const sal_uInt8 nAct = pNumFnt->GetActual();
553cdf0e10cSrcweir 					pNumFnt->SetFamily( pFmtFnt->GetFamily(), nAct );
554cdf0e10cSrcweir 					pNumFnt->SetName( pFmtFnt->GetName(), nAct );
555cdf0e10cSrcweir 					pNumFnt->SetStyleName( pFmtFnt->GetStyleName(), nAct );
556cdf0e10cSrcweir 					pNumFnt->SetCharSet( pFmtFnt->GetCharSet(), nAct );
557cdf0e10cSrcweir 					pNumFnt->SetPitch( pFmtFnt->GetPitch(), nAct );
558cdf0e10cSrcweir 				}
559cdf0e10cSrcweir 
560*dc0f91dcSmseidel 				// we do not allow a vertical font
561*dc0f91dcSmseidel 				pNumFnt->SetVertical( pNumFnt->GetOrientation(),
562*dc0f91dcSmseidel 									  pFrm->IsVertical() );
563*dc0f91dcSmseidel 
564*dc0f91dcSmseidel 				// --> OD 2008-01-23 #newlistelevelattrs#
565*dc0f91dcSmseidel 				pRet = new SwBulletPortion( rNumFmt.GetBulletChar(),
566*dc0f91dcSmseidel 											pTxtNd->GetLabelFollowedBy(),
567*dc0f91dcSmseidel 											pNumFnt,
568*dc0f91dcSmseidel 											bLeft, bCenter, nMinDist,
569*dc0f91dcSmseidel 											bLabelAlignmentPosAndSpaceModeActive );
570*dc0f91dcSmseidel 				// <--
571cdf0e10cSrcweir 			}
572cdf0e10cSrcweir 			else
573cdf0e10cSrcweir 			{
574*dc0f91dcSmseidel 				XubString aTxt( pTxtNd->GetNumString() );
575*dc0f91dcSmseidel 				// --> OD 2008-01-23 #newlistlevelattrs#
576*dc0f91dcSmseidel 				if ( aTxt.Len() > 0 )
577*dc0f91dcSmseidel 				{
578*dc0f91dcSmseidel 					aTxt.Insert( pTxtNd->GetLabelFollowedBy() );
579*dc0f91dcSmseidel 				}
580*dc0f91dcSmseidel 				// <--
581cdf0e10cSrcweir 
582cdf0e10cSrcweir 				// 7974: Nicht nur eine Optimierung...
583cdf0e10cSrcweir 				// Eine Numberportion ohne Text wird die Breite von 0
584cdf0e10cSrcweir 				// erhalten. Die nachfolgende Textportion wird im BreakLine
585cdf0e10cSrcweir 				// in das BreakCut laufen, obwohl rInf.GetLast()->GetFlyPortion()
586cdf0e10cSrcweir 				// vorliegt!
587cdf0e10cSrcweir 				if( aTxt.Len() )
588cdf0e10cSrcweir 				{
589*dc0f91dcSmseidel 					// Build a new numbering font basing on the current paragraph font:
590*dc0f91dcSmseidel 					pNumFnt = new SwFont( &rInf.GetCharAttr(), pIDSA );
591*dc0f91dcSmseidel 
592*dc0f91dcSmseidel 					// --> FME 2005-08-11 #i53199#
593*dc0f91dcSmseidel 					if ( !pIDSA->get(IDocumentSettingAccess::DO_NOT_RESET_PARA_ATTRS_FOR_NUM_FONT) )
594*dc0f91dcSmseidel 					{
595*dc0f91dcSmseidel 						// i18463:
596*dc0f91dcSmseidel 						// Underline style of paragraph font should not be considered
597*dc0f91dcSmseidel 						pNumFnt->SetUnderline( UNDERLINE_NONE );
598*dc0f91dcSmseidel 						// Overline style of paragraph font should not be considered
599*dc0f91dcSmseidel 						pNumFnt->SetOverline( UNDERLINE_NONE );
600*dc0f91dcSmseidel 					}
601*dc0f91dcSmseidel 
602*dc0f91dcSmseidel 
603*dc0f91dcSmseidel 					// Apply the explicit attributes from the character style
604*dc0f91dcSmseidel 					// associated with the numbering to the new bullet font.
605cdf0e10cSrcweir 					if( pFmt )
606*dc0f91dcSmseidel 						pNumFnt->SetDiffFnt( pFmt, pIDSA );
607cdf0e10cSrcweir 
608*dc0f91dcSmseidel 					// we do not allow a vertical font
609*dc0f91dcSmseidel 					pNumFnt->SetVertical( pNumFnt->GetOrientation(), pFrm->IsVertical() );
610cdf0e10cSrcweir 
611*dc0f91dcSmseidel 					// --> OD 2008-01-23 #newlistlevelattrs#
612*dc0f91dcSmseidel 					pRet = new SwNumberPortion( aTxt, pNumFnt,
613*dc0f91dcSmseidel 												bLeft, bCenter, nMinDist,
614*dc0f91dcSmseidel 												bLabelAlignmentPosAndSpaceModeActive );
615*dc0f91dcSmseidel 					// <--
616cdf0e10cSrcweir 				}
617cdf0e10cSrcweir 			}
618cdf0e10cSrcweir 		}
619cdf0e10cSrcweir 	}
620cdf0e10cSrcweir 	return pRet;
621cdf0e10cSrcweir }
622cdf0e10cSrcweir 
623*dc0f91dcSmseidel /* vim: set noet sw=4 ts=4: */
624