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()
35*3436fcd2Smseidel #include "rootfrm.hxx" // Info about 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
68*3436fcd2Smseidel
69*3436fcd2Smseidel
70cdf0e10cSrcweir /*************************************************************************
71cdf0e10cSrcweir * 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 {
81cdf0e10cSrcweir const SwFrm *pTmp = pFrm;
82cdf0e10cSrcweir const SwFlyFrm *pFly;
83cdf0e10cSrcweir while ( 0 != (pFly = pTmp->FindFlyFrm()) )
84cdf0e10cSrcweir 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)
109c0286415SOliver-Rainer Wittmann const_cast<SwFmtFld*> (&pHint->GetFmtFld())->Broadcast( SwFmtFldHint( &pHint->GetFmtFld(), SWFMTFLD_LANGUAGE ) );
110cdf0e10cSrcweir }
111cdf0e10cSrcweir
112cdf0e10cSrcweir ViewShell *pSh = rInf.GetVsh();
113cdf0e10cSrcweir SwDoc *const pDoc( (pSh) ? pSh->GetDoc() : 0 );
114cdf0e10cSrcweir bool const bInClipboard( (pDoc) ? pDoc->IsClipBoard() : true );
115cdf0e10cSrcweir 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 )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir String const sName( pFld->GetFieldName() );
129cdf0e10cSrcweir pRet = new SwFldPortion(sName);
130cdf0e10cSrcweir }
131cdf0e10cSrcweir else
132cdf0e10cSrcweir {
133cdf0e10cSrcweir String const sContent( pFld->ExpandField(bInClipboard) );
134cdf0e10cSrcweir pRet = new SwCombinedPortion(sContent);
135cdf0e10cSrcweir }
136cdf0e10cSrcweir }
137cdf0e10cSrcweir break;
138cdf0e10cSrcweir
139cdf0e10cSrcweir case RES_HIDDENTXTFLD:
140cdf0e10cSrcweir {
141cdf0e10cSrcweir String const str( (bName)
142cdf0e10cSrcweir ? pFld->GetFieldName()
143cdf0e10cSrcweir : pFld->ExpandField(bInClipboard) );
144cdf0e10cSrcweir pRet = new SwHiddenPortion(str);
145cdf0e10cSrcweir }
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 }
154cdf0e10cSrcweir {
155cdf0e10cSrcweir String const str( (bName)
156cdf0e10cSrcweir ? pFld->GetFieldName()
157cdf0e10cSrcweir : pFld->ExpandField(bInClipboard) );
158cdf0e10cSrcweir pRet = new SwFldPortion( str );
159cdf0e10cSrcweir }
160cdf0e10cSrcweir break;
161cdf0e10cSrcweir
162cdf0e10cSrcweir case RES_DOCSTATFLD:
163cdf0e10cSrcweir if( !bName && pSh && !pSh->Imp()->IsUpdateExpFlds() )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir ((SwDocStatField*)pFld)->ChangeExpansion( pFrame );
166cdf0e10cSrcweir }
167cdf0e10cSrcweir {
168cdf0e10cSrcweir String const str( (bName)
169cdf0e10cSrcweir ? pFld->GetFieldName()
170cdf0e10cSrcweir : pFld->ExpandField(bInClipboard) );
171cdf0e10cSrcweir pRet = new SwFldPortion( str );
172cdf0e10cSrcweir }
173ca62e2c2SSteve Yin if(pRet)
174ca62e2c2SSteve Yin ((SwFldPortion*)pRet)->m_nAttrFldType= ATTR_PAGECOOUNTFLD;
175cdf0e10cSrcweir break;
176cdf0e10cSrcweir
177cdf0e10cSrcweir case RES_PAGENUMBERFLD:
178cdf0e10cSrcweir {
179cdf0e10cSrcweir if( !bName && pSh && pSh->GetLayout() && !pSh->Imp()->IsUpdateExpFlds() ) // swmod 080122
180cdf0e10cSrcweir {
181cdf0e10cSrcweir SwPageNumberFieldType *pPageNr = (SwPageNumberFieldType *)pFld->GetTyp();
182cdf0e10cSrcweir
183cdf0e10cSrcweir const SwRootFrm* pTmpRootFrm = pSh->GetLayout();
184cdf0e10cSrcweir const sal_Bool bVirt = pTmpRootFrm->IsVirtPageNum();
185cdf0e10cSrcweir
186cdf0e10cSrcweir MSHORT nVirtNum = pFrame->GetVirtPageNum();
187cdf0e10cSrcweir 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 }
195cdf0e10cSrcweir {
196cdf0e10cSrcweir String const str( (bName)
197cdf0e10cSrcweir ? pFld->GetFieldName()
198cdf0e10cSrcweir : pFld->ExpandField(bInClipboard) );
199cdf0e10cSrcweir pRet = new SwFldPortion( str );
200cdf0e10cSrcweir }
201ca62e2c2SSteve Yin if(pRet)
202ca62e2c2SSteve Yin ((SwFldPortion*)pRet)->m_nAttrFldType= ATTR_PAGENUMBERFLD;
203cdf0e10cSrcweir 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*3436fcd2Smseidel // war vorher anders, also erst expandieren, dann umsetzen!
218cdf0e10cSrcweir pExpFld->ChangeExpansion( *pFrame, *((SwTxtFld*)pHint) );
219cdf0e10cSrcweir pExpFld->ChgBodyTxtFlag( sal_True );
220cdf0e10cSrcweir }
221cdf0e10cSrcweir }
222cdf0e10cSrcweir {
223cdf0e10cSrcweir String const str( (bName)
224cdf0e10cSrcweir ? pFld->GetFieldName()
225cdf0e10cSrcweir : pFld->ExpandField(bInClipboard) );
226cdf0e10cSrcweir pRet = new SwFldPortion( str );
227cdf0e10cSrcweir }
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 }
251cdf0e10cSrcweir {
252cdf0e10cSrcweir String const str( (bName)
253cdf0e10cSrcweir ? pFld->GetFieldName()
254cdf0e10cSrcweir : pFld->ExpandField(bInClipboard) );
255cdf0e10cSrcweir pRet = new SwFldPortion(str);
256cdf0e10cSrcweir }
257cdf0e10cSrcweir break;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir case RES_REFPAGEGETFLD:
260cdf0e10cSrcweir if( !bName && pSh && !pSh->Imp()->IsUpdateExpFlds() )
261cdf0e10cSrcweir {
262cdf0e10cSrcweir ((SwRefPageGetField*)pFld)->ChangeExpansion( pFrame, (SwTxtFld*)pHint );
263cdf0e10cSrcweir }
264cdf0e10cSrcweir {
265cdf0e10cSrcweir String const str( (bName)
266cdf0e10cSrcweir ? pFld->GetFieldName()
267cdf0e10cSrcweir : pFld->ExpandField(bInClipboard) );
268cdf0e10cSrcweir pRet = new SwFldPortion(str);
269cdf0e10cSrcweir }
270cdf0e10cSrcweir break;
271cdf0e10cSrcweir
272cdf0e10cSrcweir case RES_JUMPEDITFLD:
273cdf0e10cSrcweir if( !bName )
274cdf0e10cSrcweir pChFmt = ((SwJumpEditField*)pFld)->GetCharFmt();
275cdf0e10cSrcweir bNewFlyPor = sal_True;
276cdf0e10cSrcweir bPlaceHolder = sal_True;
277cdf0e10cSrcweir break;
278ca62e2c2SSteve Yin case RES_GETREFFLD:
279ca62e2c2SSteve Yin subType = ((SwGetRefField*)pFld)->GetSubType();
280ca62e2c2SSteve Yin {
281ca62e2c2SSteve Yin String const str( (bName)
282ca62e2c2SSteve Yin ? pFld->GetFieldName()
283ca62e2c2SSteve Yin : pFld->ExpandField(bInClipboard) );
284ca62e2c2SSteve Yin pRet = new SwFldPortion(str);
285ca62e2c2SSteve Yin }
286ca62e2c2SSteve Yin if(pRet)
287ca62e2c2SSteve Yin {
288ca62e2c2SSteve Yin if( subType == REF_BOOKMARK )
289ca62e2c2SSteve Yin ((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 {
297ca62e2c2SSteve Yin String const str( (bName)
298ca62e2c2SSteve Yin ? pFld->GetFieldName()
299ca62e2c2SSteve Yin : pFld->ExpandField(bInClipboard) );
300ca62e2c2SSteve Yin pRet = new SwFldPortion(str);
301ca62e2c2SSteve Yin }
302ca62e2c2SSteve Yin if(pRet)
303ca62e2c2SSteve Yin {
304ca62e2c2SSteve Yin 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:
311cdf0e10cSrcweir {
312cdf0e10cSrcweir String const str( (bName)
313cdf0e10cSrcweir ? pFld->GetFieldName()
314cdf0e10cSrcweir : pFld->ExpandField(bInClipboard) );
315cdf0e10cSrcweir pRet = new SwFldPortion(str);
316cdf0e10cSrcweir }
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 );
330cdf0e10cSrcweir pFrm->GetTxtNode()->GetAttr(aSet,rInf.GetIdx(),rInf.GetIdx()+1);
331cdf0e10cSrcweir aTmpSet.Set( pChFmt->GetAttrSet() );
332cdf0e10cSrcweir aTmpSet.Differentiate( aSet );
333cdf0e10cSrcweir if( aTmpSet.Count() )
334cdf0e10cSrcweir pTmpFnt->SetDiffFnt( &aTmpSet, pFrm->GetTxtNode()->getIDocumentSettingAccess() );
335cdf0e10cSrcweir }
336cdf0e10cSrcweir else
337cdf0e10cSrcweir pTmpFnt->SetDiffFnt( &pChFmt->GetAttrSet(), pFrm->GetTxtNode()->getIDocumentSettingAccess() );
338cdf0e10cSrcweir }
339cdf0e10cSrcweir {
340cdf0e10cSrcweir String const str( (bName)
341cdf0e10cSrcweir ? pFld->GetFieldName()
342cdf0e10cSrcweir : pFld->ExpandField(bInClipboard) );
343cdf0e10cSrcweir pRet = new SwFldPortion(str, pTmpFnt, bPlaceHolder);
344cdf0e10cSrcweir }
345cdf0e10cSrcweir }
346cdf0e10cSrcweir
347cdf0e10cSrcweir return pRet;
348cdf0e10cSrcweir }
349cdf0e10cSrcweir
350cdf0e10cSrcweir /*************************************************************************
351cdf0e10cSrcweir * SwTxtFormatter::TryNewNoLengthPortion()
352cdf0e10cSrcweir *************************************************************************/
353cdf0e10cSrcweir
lcl_NewMetaPortion(SwTxtAttr & rHint,const bool bPrefix)354cdf0e10cSrcweir SwFldPortion * lcl_NewMetaPortion(SwTxtAttr & rHint, const bool bPrefix)
355cdf0e10cSrcweir {
356cdf0e10cSrcweir ::sw::Meta *const pMeta(
357cdf0e10cSrcweir static_cast<SwFmtMeta &>(rHint.GetAttr()).GetMeta() );
358cdf0e10cSrcweir ::rtl::OUString fix;
359cdf0e10cSrcweir ::sw::MetaField *const pField( dynamic_cast< ::sw::MetaField * >(pMeta) );
360cdf0e10cSrcweir OSL_ENSURE(pField, "lcl_NewMetaPortion: no meta field?");
361cdf0e10cSrcweir if (pField)
362cdf0e10cSrcweir {
363cdf0e10cSrcweir pField->GetPrefixAndSuffix((bPrefix) ? &fix : 0, (bPrefix) ? 0 : &fix);
364cdf0e10cSrcweir }
365cdf0e10cSrcweir return new SwFldPortion( fix );
366cdf0e10cSrcweir }
367cdf0e10cSrcweir
368cdf0e10cSrcweir /** Try to create a new portion with zero length, for an end of a hint
369cdf0e10cSrcweir (where there is no CH_TXTATR). Because there may be multiple hint ends at a
370cdf0e10cSrcweir given index, m_nHintEndIndex is used to keep track of the already created
371cdf0e10cSrcweir portions. But the portions created here may actually be deleted again,
372cdf0e10cSrcweir due to UnderFlow. In that case, m_nHintEndIndex must be decremented,
373cdf0e10cSrcweir so the portion will be created again on the next line.
374cdf0e10cSrcweir */
375cdf0e10cSrcweir SwExpandPortion *
TryNewNoLengthPortion(SwTxtFormatInfo & rInfo)376cdf0e10cSrcweir SwTxtFormatter::TryNewNoLengthPortion(SwTxtFormatInfo & rInfo)
377cdf0e10cSrcweir {
378cdf0e10cSrcweir if (pHints)
379cdf0e10cSrcweir {
380cdf0e10cSrcweir const xub_StrLen nIdx(rInfo.GetIdx());
381cdf0e10cSrcweir while (m_nHintEndIndex < pHints->GetEndCount())
382cdf0e10cSrcweir {
383cdf0e10cSrcweir SwTxtAttr & rHint( *pHints->GetEnd(m_nHintEndIndex) );
384cdf0e10cSrcweir xub_StrLen const nEnd( *rHint.GetAnyEnd() );
385cdf0e10cSrcweir if (nEnd > nIdx)
386cdf0e10cSrcweir {
387cdf0e10cSrcweir break;
388cdf0e10cSrcweir }
389cdf0e10cSrcweir ++m_nHintEndIndex;
390cdf0e10cSrcweir if (nEnd == nIdx)
391cdf0e10cSrcweir {
392cdf0e10cSrcweir if (RES_TXTATR_METAFIELD == rHint.Which())
393cdf0e10cSrcweir {
394cdf0e10cSrcweir SwFldPortion *const pPortion(
395cdf0e10cSrcweir lcl_NewMetaPortion(rHint, false));
396cdf0e10cSrcweir pPortion->SetNoLength(); // no CH_TXTATR at hint end!
397cdf0e10cSrcweir return pPortion;
398cdf0e10cSrcweir }
399cdf0e10cSrcweir }
400cdf0e10cSrcweir }
401cdf0e10cSrcweir }
402cdf0e10cSrcweir return 0;
403cdf0e10cSrcweir }
404cdf0e10cSrcweir
405cdf0e10cSrcweir /*************************************************************************
406cdf0e10cSrcweir * SwTxtFormatter::NewExtraPortion()
407cdf0e10cSrcweir *************************************************************************/
408cdf0e10cSrcweir
NewExtraPortion(SwTxtFormatInfo & rInf)409cdf0e10cSrcweir SwLinePortion *SwTxtFormatter::NewExtraPortion( SwTxtFormatInfo &rInf )
410cdf0e10cSrcweir {
411cdf0e10cSrcweir SwTxtAttr *pHint = GetAttr( rInf.GetIdx() );
412cdf0e10cSrcweir SwLinePortion *pRet = 0;
413cdf0e10cSrcweir if( !pHint )
414cdf0e10cSrcweir {
415cdf0e10cSrcweir pRet = new SwTxtPortion;
416cdf0e10cSrcweir pRet->SetLen( 1 );
417cdf0e10cSrcweir rInf.SetLen( 1 );
418cdf0e10cSrcweir return pRet;
419cdf0e10cSrcweir }
420cdf0e10cSrcweir
421cdf0e10cSrcweir switch( pHint->Which() )
422cdf0e10cSrcweir {
423cdf0e10cSrcweir case RES_TXTATR_FLYCNT :
424cdf0e10cSrcweir {
425cdf0e10cSrcweir pRet = NewFlyCntPortion( rInf, pHint );
426cdf0e10cSrcweir break;
427cdf0e10cSrcweir }
428cdf0e10cSrcweir case RES_TXTATR_FTN :
429cdf0e10cSrcweir {
430cdf0e10cSrcweir pRet = NewFtnPortion( rInf, pHint );
431cdf0e10cSrcweir break;
432cdf0e10cSrcweir }
433cdf0e10cSrcweir case RES_TXTATR_FIELD :
434dec99bbdSOliver-Rainer Wittmann case RES_TXTATR_ANNOTATION :
435cdf0e10cSrcweir {
436cdf0e10cSrcweir pRet = NewFldPortion( rInf, pHint );
437cdf0e10cSrcweir break;
438cdf0e10cSrcweir }
439cdf0e10cSrcweir case RES_TXTATR_REFMARK :
440cdf0e10cSrcweir {
441cdf0e10cSrcweir pRet = new SwIsoRefPortion;
442cdf0e10cSrcweir break;
443cdf0e10cSrcweir }
444cdf0e10cSrcweir case RES_TXTATR_TOXMARK :
445cdf0e10cSrcweir {
446cdf0e10cSrcweir pRet = new SwIsoToxPortion;
447cdf0e10cSrcweir break;
448cdf0e10cSrcweir }
449cdf0e10cSrcweir case RES_TXTATR_METAFIELD:
450cdf0e10cSrcweir {
451cdf0e10cSrcweir pRet = lcl_NewMetaPortion( *pHint, true );
452cdf0e10cSrcweir break;
453cdf0e10cSrcweir }
454cdf0e10cSrcweir default: ;
455cdf0e10cSrcweir }
456cdf0e10cSrcweir if( !pRet )
457cdf0e10cSrcweir {
458cdf0e10cSrcweir const XubString aNothing;
459cdf0e10cSrcweir pRet = new SwFldPortion( aNothing );
460cdf0e10cSrcweir rInf.SetLen( 1 );
461cdf0e10cSrcweir }
462cdf0e10cSrcweir return pRet;
463cdf0e10cSrcweir }
464cdf0e10cSrcweir
465cdf0e10cSrcweir /*************************************************************************
466cdf0e10cSrcweir * 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 ?
481cdf0e10cSrcweir if( pTxtNd->IsNumbered() && pTxtNd->IsCountedInList())
482cdf0e10cSrcweir {
483cdf0e10cSrcweir 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();
486cdf0e10cSrcweir // --> OD 2008-01-23 #newlistlevelattrs#
487cdf0e10cSrcweir const bool bLabelAlignmentPosAndSpaceModeActive(
488cdf0e10cSrcweir rNumFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT );
489cdf0e10cSrcweir const KSHORT nMinDist = bLabelAlignmentPosAndSpaceModeActive
490cdf0e10cSrcweir ? 0 : rNumFmt.GetCharTextDistance();
491cdf0e10cSrcweir // <--
492cdf0e10cSrcweir
493cdf0e10cSrcweir if( SVX_NUM_BITMAP == rNumFmt.GetNumberingType() )
494cdf0e10cSrcweir {
495cdf0e10cSrcweir // --> OD 2008-01-23 #newlistlevelattrs#
496cdf0e10cSrcweir pRet = new SwGrfNumPortion( (SwFrm*)GetTxtFrm(),
497cdf0e10cSrcweir pTxtNd->GetLabelFollowedBy(),
498cdf0e10cSrcweir rNumFmt.GetBrush(),
499cdf0e10cSrcweir rNumFmt.GetGraphicOrientation(),
500cdf0e10cSrcweir rNumFmt.GetGraphicSize(),
501cdf0e10cSrcweir bLeft, bCenter, nMinDist,
502cdf0e10cSrcweir bLabelAlignmentPosAndSpaceModeActive );
503cdf0e10cSrcweir // <--
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() ?
516cdf0e10cSrcweir &rNumFmt.GetCharFmt()->GetAttrSet() :
517cdf0e10cSrcweir NULL;
518cdf0e10cSrcweir const IDocumentSettingAccess* pIDSA = pTxtNd->getIDocumentSettingAccess();
519cdf0e10cSrcweir
520cdf0e10cSrcweir if( SVX_NUM_CHAR_SPECIAL == rNumFmt.GetNumberingType() )
521cdf0e10cSrcweir {
522cdf0e10cSrcweir const Font *pFmtFnt = rNumFmt.GetBulletFont();
523cdf0e10cSrcweir
524cdf0e10cSrcweir // Build a new bullet font basing on the current paragraph font:
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 // Apply the explicit attributes from the character style
546*3436fcd2Smseidel // associated with the numbering to the new bullet font.
547cdf0e10cSrcweir if( pFmt )
548cdf0e10cSrcweir pNumFnt->SetDiffFnt( pFmt, pIDSA );
549cdf0e10cSrcweir
550cdf0e10cSrcweir 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
560cdf0e10cSrcweir // we do not allow a vertical font
561cdf0e10cSrcweir pNumFnt->SetVertical( pNumFnt->GetOrientation(),
562cdf0e10cSrcweir pFrm->IsVertical() );
563cdf0e10cSrcweir
564cdf0e10cSrcweir // --> OD 2008-01-23 #newlistelevelattrs#
565cdf0e10cSrcweir pRet = new SwBulletPortion( rNumFmt.GetBulletChar(),
566cdf0e10cSrcweir pTxtNd->GetLabelFollowedBy(),
567cdf0e10cSrcweir pNumFnt,
568cdf0e10cSrcweir bLeft, bCenter, nMinDist,
569cdf0e10cSrcweir bLabelAlignmentPosAndSpaceModeActive );
570cdf0e10cSrcweir // <--
571cdf0e10cSrcweir }
572cdf0e10cSrcweir else
573cdf0e10cSrcweir {
574cdf0e10cSrcweir XubString aTxt( pTxtNd->GetNumString() );
575cdf0e10cSrcweir // --> OD 2008-01-23 #newlistlevelattrs#
576cdf0e10cSrcweir if ( aTxt.Len() > 0 )
577cdf0e10cSrcweir {
578cdf0e10cSrcweir aTxt.Insert( pTxtNd->GetLabelFollowedBy() );
579cdf0e10cSrcweir }
580cdf0e10cSrcweir // <--
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 {
589cdf0e10cSrcweir // Build a new numbering font basing on the current paragraph font:
590cdf0e10cSrcweir pNumFnt = new SwFont( &rInf.GetCharAttr(), pIDSA );
591cdf0e10cSrcweir
592cdf0e10cSrcweir // --> FME 2005-08-11 #i53199#
593cdf0e10cSrcweir if ( !pIDSA->get(IDocumentSettingAccess::DO_NOT_RESET_PARA_ATTRS_FOR_NUM_FONT) )
594cdf0e10cSrcweir {
595cdf0e10cSrcweir // i18463:
596cdf0e10cSrcweir // Underline style of paragraph font should not be considered
597cdf0e10cSrcweir pNumFnt->SetUnderline( UNDERLINE_NONE );
598cdf0e10cSrcweir // Overline style of paragraph font should not be considered
599cdf0e10cSrcweir pNumFnt->SetOverline( UNDERLINE_NONE );
600cdf0e10cSrcweir }
601cdf0e10cSrcweir
602cdf0e10cSrcweir
603cdf0e10cSrcweir // Apply the explicit attributes from the character style
604*3436fcd2Smseidel // associated with the numbering to the new bullet font.
605cdf0e10cSrcweir if( pFmt )
606cdf0e10cSrcweir pNumFnt->SetDiffFnt( pFmt, pIDSA );
607cdf0e10cSrcweir
608cdf0e10cSrcweir // we do not allow a vertical font
609cdf0e10cSrcweir pNumFnt->SetVertical( pNumFnt->GetOrientation(), pFrm->IsVertical() );
610cdf0e10cSrcweir
611cdf0e10cSrcweir // --> OD 2008-01-23 #newlistlevelattrs#
612cdf0e10cSrcweir pRet = new SwNumberPortion( aTxt, pNumFnt,
613cdf0e10cSrcweir bLeft, bCenter, nMinDist,
614cdf0e10cSrcweir bLabelAlignmentPosAndSpaceModeActive );
615cdf0e10cSrcweir // <--
616cdf0e10cSrcweir }
617cdf0e10cSrcweir }
618cdf0e10cSrcweir }
619cdf0e10cSrcweir }
620cdf0e10cSrcweir return pRet;
621cdf0e10cSrcweir }
622cdf0e10cSrcweir
623*3436fcd2Smseidel /* vim: set noet sw=4 ts=4: */
624