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