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 <com/sun/star/text/ChapterFormat.hpp>
29cdf0e10cSrcweir #include <doc.hxx>
30cdf0e10cSrcweir #include <frame.hxx> // SwChapterFieldType::ChangeExpansion()
31cdf0e10cSrcweir #include <pam.hxx> // fuer GetBodyTxtNode
32cdf0e10cSrcweir #include <ndtxt.hxx>
33cdf0e10cSrcweir #include <chpfld.hxx>
34cdf0e10cSrcweir #include <expfld.hxx> // fuer GetBodyTxtNode
35cdf0e10cSrcweir #ifndef _UNOFLDMID_H
36cdf0e10cSrcweir #include <unofldmid.h>
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #include <numrule.hxx>
39cdf0e10cSrcweir
40cdf0e10cSrcweir using namespace ::com::sun::star;
41cdf0e10cSrcweir
42cdf0e10cSrcweir /*--------------------------------------------------------------------
43cdf0e10cSrcweir Beschreibung: SwChapterFieldType
44cdf0e10cSrcweir --------------------------------------------------------------------*/
45cdf0e10cSrcweir
46cdf0e10cSrcweir
SwChapterFieldType()47cdf0e10cSrcweir SwChapterFieldType::SwChapterFieldType()
48cdf0e10cSrcweir : SwFieldType( RES_CHAPTERFLD )
49cdf0e10cSrcweir {
50cdf0e10cSrcweir }
51cdf0e10cSrcweir
52cdf0e10cSrcweir
Copy() const53cdf0e10cSrcweir SwFieldType* SwChapterFieldType::Copy() const
54cdf0e10cSrcweir {
55cdf0e10cSrcweir return new SwChapterFieldType();
56cdf0e10cSrcweir }
57cdf0e10cSrcweir
58cdf0e10cSrcweir
59cdf0e10cSrcweir /*--------------------------------------------------------------------
60cdf0e10cSrcweir Beschreibung: Kapittelfeld
61cdf0e10cSrcweir --------------------------------------------------------------------*/
62cdf0e10cSrcweir
63cdf0e10cSrcweir
SwChapterField(SwChapterFieldType * pTyp,sal_uInt32 nFmt)64cdf0e10cSrcweir SwChapterField::SwChapterField(SwChapterFieldType* pTyp, sal_uInt32 nFmt)
65cdf0e10cSrcweir : SwField(pTyp, nFmt), nLevel( 0 )
66cdf0e10cSrcweir {}
67cdf0e10cSrcweir
68cdf0e10cSrcweir
Expand() const69cdf0e10cSrcweir String SwChapterField::Expand() const
70cdf0e10cSrcweir {
71cdf0e10cSrcweir String sStr( sNumber );
72cdf0e10cSrcweir switch( GetFormat() )
73cdf0e10cSrcweir {
74cdf0e10cSrcweir case CF_TITLE: sStr = sTitle; break;
75cdf0e10cSrcweir
76cdf0e10cSrcweir case CF_NUMBER:
77cdf0e10cSrcweir case CF_NUM_TITLE: sStr.Insert( sPre, 0 );
78cdf0e10cSrcweir sStr += sPost;
79cdf0e10cSrcweir if( CF_NUM_TITLE == GetFormat() )
80cdf0e10cSrcweir sStr += sTitle;
81cdf0e10cSrcweir break;
82cdf0e10cSrcweir
83cdf0e10cSrcweir case CF_NUM_NOPREPST_TITLE: sStr += sTitle; break;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir return sStr;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
88cdf0e10cSrcweir
Copy() const89cdf0e10cSrcweir SwField* SwChapterField::Copy() const
90cdf0e10cSrcweir {
91cdf0e10cSrcweir SwChapterField *pTmp =
92cdf0e10cSrcweir new SwChapterField((SwChapterFieldType*)GetTyp(), GetFormat());
93cdf0e10cSrcweir pTmp->nLevel = nLevel;
94cdf0e10cSrcweir pTmp->sTitle = sTitle;
95cdf0e10cSrcweir pTmp->sNumber = sNumber;
96cdf0e10cSrcweir pTmp->sPost = sPost;
97cdf0e10cSrcweir pTmp->sPre = sPre;
98cdf0e10cSrcweir
99cdf0e10cSrcweir return pTmp;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
102cdf0e10cSrcweir // --> OD 2008-02-14 #i53420#
103cdf0e10cSrcweir //void SwChapterField::ChangeExpansion( const SwFrm* pFrm,
104cdf0e10cSrcweir // const SwTxtNode* pTxtNd,
105cdf0e10cSrcweir // sal_Bool bSrchNum )
106cdf0e10cSrcweir //{
107cdf0e10cSrcweir // ASSERT( pFrm, "in welchem Frame stehe ich denn?" )
108cdf0e10cSrcweir // SwDoc* pDoc = (SwDoc*)pTxtNd->GetDoc();
109cdf0e10cSrcweir // SwPosition aPos( pDoc->GetNodes().GetEndOfContent() );
110cdf0e10cSrcweir
111cdf0e10cSrcweir // if( pFrm->IsInDocBody() )
112cdf0e10cSrcweir // aPos.nNode = *pTxtNd;
113cdf0e10cSrcweir // else if( 0 == (pTxtNd = GetBodyTxtNode( *pDoc, aPos, *pFrm )) )
114cdf0e10cSrcweir // // kein TxtNode (Formatierung Kopf/Fusszeile)
115cdf0e10cSrcweir // return;
116cdf0e10cSrcweir // ChangeExpansion(*pTxtNd, bSrchNum);
117cdf0e10cSrcweir //}
ChangeExpansion(const SwFrm * pFrm,const SwCntntNode * pCntntNode,sal_Bool bSrchNum)118cdf0e10cSrcweir void SwChapterField::ChangeExpansion(const SwFrm* pFrm,
119cdf0e10cSrcweir const SwCntntNode* pCntntNode,
120cdf0e10cSrcweir sal_Bool bSrchNum )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir ASSERT( pFrm, "in welchem Frame stehe ich denn?" )
123cdf0e10cSrcweir SwDoc* pDoc = (SwDoc*)pCntntNode->GetDoc();
124cdf0e10cSrcweir
125cdf0e10cSrcweir const SwTxtNode* pTxtNode = dynamic_cast<const SwTxtNode*>(pCntntNode);
126cdf0e10cSrcweir if ( !pTxtNode || !pFrm->IsInDocBody() )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir SwPosition aDummyPos( pDoc->GetNodes().GetEndOfContent() );
129cdf0e10cSrcweir pTxtNode = GetBodyTxtNode( *pDoc, aDummyPos, *pFrm );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir
132cdf0e10cSrcweir if ( pTxtNode )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir ChangeExpansion( *pTxtNode, bSrchNum );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir }
137cdf0e10cSrcweir // <--
138cdf0e10cSrcweir
ChangeExpansion(const SwTxtNode & rTxtNd,sal_Bool bSrchNum)139cdf0e10cSrcweir void SwChapterField::ChangeExpansion(const SwTxtNode &rTxtNd, sal_Bool bSrchNum)
140cdf0e10cSrcweir {
141*d83e2ff7SJian Hong Cheng //i120759,this function is for both the reference chapter field and normal chapter field
142*d83e2ff7SJian Hong Cheng //bSrchNum can distinguish the two types,to the latter type,the outline num rule is must...
143*d83e2ff7SJian Hong Cheng sNumber = aEmptyStr;
144*d83e2ff7SJian Hong Cheng sTitle = aEmptyStr;
145*d83e2ff7SJian Hong Cheng sPost = aEmptyStr;
146*d83e2ff7SJian Hong Cheng sPre = aEmptyStr;
147*d83e2ff7SJian Hong Cheng //The reference chapter field of normal num rule will be handled in this code segment
148*d83e2ff7SJian Hong Cheng if (bSrchNum && !rTxtNd.IsOutline())
149*d83e2ff7SJian Hong Cheng {
150*d83e2ff7SJian Hong Cheng SwNumRule* pRule(rTxtNd.GetNumRule());
151*d83e2ff7SJian Hong Cheng if (rTxtNd.IsCountedInList() && pRule)
152*d83e2ff7SJian Hong Cheng {
153*d83e2ff7SJian Hong Cheng sNumber = rTxtNd.GetNumString(false);
154*d83e2ff7SJian Hong Cheng const SwNumFmt& rNFmt = pRule->Get(static_cast<unsigned short>(rTxtNd.GetActualListLevel()));
155*d83e2ff7SJian Hong Cheng sPost = rNFmt.GetSuffix();
156*d83e2ff7SJian Hong Cheng sPre = rNFmt.GetPrefix();
157*d83e2ff7SJian Hong Cheng }
158*d83e2ff7SJian Hong Cheng else
159*d83e2ff7SJian Hong Cheng {
160*d83e2ff7SJian Hong Cheng sNumber = String("??", RTL_TEXTENCODING_ASCII_US);
161*d83e2ff7SJian Hong Cheng }
162*d83e2ff7SJian Hong Cheng sTitle = rTxtNd.GetExpandTxt();
163*d83e2ff7SJian Hong Cheng
164*d83e2ff7SJian Hong Cheng for( xub_StrLen i = 0; i < sTitle.Len(); ++i )
165*d83e2ff7SJian Hong Cheng if( ' ' > sTitle.GetChar( i ) )
166*d83e2ff7SJian Hong Cheng sTitle.Erase( i--, 1 );
167*d83e2ff7SJian Hong Cheng }else
168*d83e2ff7SJian Hong Cheng {
169*d83e2ff7SJian Hong Cheng //End
170cdf0e10cSrcweir SwDoc* pDoc = (SwDoc*)rTxtNd.GetDoc();
171cdf0e10cSrcweir const SwTxtNode *pTxtNd = rTxtNd.FindOutlineNodeOfLevel( nLevel );
172cdf0e10cSrcweir if( pTxtNd )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir if( bSrchNum )
175cdf0e10cSrcweir {
176cdf0e10cSrcweir const SwTxtNode* pONd = pTxtNd;
177cdf0e10cSrcweir do {
178cdf0e10cSrcweir if( pONd && pONd->GetTxtColl() )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir sal_uInt8 nPrevLvl = nLevel;
181cdf0e10cSrcweir
182cdf0e10cSrcweir // --> OD 2008-04-02 #refactorlists#
183cdf0e10cSrcweir // nLevel = GetRealLevel( pONd->GetTxtColl()->
184cdf0e10cSrcweir // GetOutlineLevel() );
185cdf0e10cSrcweir //ASSERT( pONd->GetOutlineLevel() >= 0 && pONd->GetOutlineLevel() < MAXLEVEL, //#outline level,zhaojianwei
186cdf0e10cSrcweir // "<SwChapterField::ChangeExpansion(..)> - outline node with inconsistent outline level. Serious defect -> please inform OD." );
187cdf0e10cSrcweir //nLevel = static_cast<sal_uInt8>(pONd->GetOutlineLevel());
188cdf0e10cSrcweir ASSERT( pONd->GetAttrOutlineLevel() >= 0 && pONd->GetAttrOutlineLevel() <= MAXLEVEL,
189cdf0e10cSrcweir "<SwChapterField::ChangeExpansion(..)> - outline node with inconsistent outline level. Serious defect -> please inform OD." );
190cdf0e10cSrcweir nLevel = static_cast<sal_uInt8>(pONd->GetAttrOutlineLevel()); //<-end,zhaojianwei
191cdf0e10cSrcweir // <--
192cdf0e10cSrcweir
193cdf0e10cSrcweir if( nPrevLvl < nLevel )
194cdf0e10cSrcweir nLevel = nPrevLvl;
195cdf0e10cSrcweir else if( SVX_NUM_NUMBER_NONE != pDoc->GetOutlineNumRule()
196cdf0e10cSrcweir ->Get( nLevel ).GetNumberingType() )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir pTxtNd = pONd;
199cdf0e10cSrcweir break;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir
202cdf0e10cSrcweir if( !nLevel-- )
203cdf0e10cSrcweir break;
204cdf0e10cSrcweir pONd = pTxtNd->FindOutlineNodeOfLevel( nLevel );
205cdf0e10cSrcweir }
206cdf0e10cSrcweir else
207cdf0e10cSrcweir break;
208cdf0e10cSrcweir } while( sal_True );
209cdf0e10cSrcweir }
210cdf0e10cSrcweir
211cdf0e10cSrcweir // nur die Nummer besorgen, ohne Pre-/Post-fixstrings
212cdf0e10cSrcweir
213cdf0e10cSrcweir if ( pTxtNd->IsOutline() )
214cdf0e10cSrcweir {
215cdf0e10cSrcweir // --> OD 2005-11-17 #128041#
216cdf0e10cSrcweir // correction of refactoring done by cws swnumtree:
217cdf0e10cSrcweir // retrieve numbering string without prefix and suffix strings
218cdf0e10cSrcweir // as stated in the above german comment.
219cdf0e10cSrcweir sNumber = pTxtNd->GetNumString( false );
220cdf0e10cSrcweir // <--
221cdf0e10cSrcweir
222cdf0e10cSrcweir SwNumRule* pRule( pTxtNd->GetNumRule() );
223cdf0e10cSrcweir if ( pTxtNd->IsCountedInList() && pRule )
224cdf0e10cSrcweir {
225cdf0e10cSrcweir const SwNumFmt& rNFmt = pRule->Get( static_cast<sal_uInt16>(pTxtNd->GetActualListLevel()) );
226cdf0e10cSrcweir sPost = rNFmt.GetSuffix();
227cdf0e10cSrcweir sPre = rNFmt.GetPrefix();
228cdf0e10cSrcweir }
229cdf0e10cSrcweir }
230cdf0e10cSrcweir else
231cdf0e10cSrcweir {
232cdf0e10cSrcweir sNumber = String("??", RTL_TEXTENCODING_ASCII_US);
233cdf0e10cSrcweir }
234cdf0e10cSrcweir
235cdf0e10cSrcweir sTitle = pTxtNd->GetExpandTxt();
236cdf0e10cSrcweir
237cdf0e10cSrcweir for( xub_StrLen i = 0; i < sTitle.Len(); ++i )
238cdf0e10cSrcweir if( ' ' > sTitle.GetChar( i ) )
239cdf0e10cSrcweir sTitle.Erase( i--, 1 );
240cdf0e10cSrcweir }
241cdf0e10cSrcweir }
242cdf0e10cSrcweir }
243cdf0e10cSrcweir
244cdf0e10cSrcweir /*-----------------05.03.98 16:19-------------------
245cdf0e10cSrcweir
246cdf0e10cSrcweir --------------------------------------------------*/
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const247cdf0e10cSrcweir sal_Bool SwChapterField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
248cdf0e10cSrcweir {
249cdf0e10cSrcweir switch( nWhichId )
250cdf0e10cSrcweir {
251cdf0e10cSrcweir case FIELD_PROP_BYTE1:
252cdf0e10cSrcweir rAny <<= (sal_Int8)nLevel;
253cdf0e10cSrcweir break;
254cdf0e10cSrcweir
255cdf0e10cSrcweir case FIELD_PROP_USHORT1:
256cdf0e10cSrcweir {
257cdf0e10cSrcweir sal_Int16 nRet;
258cdf0e10cSrcweir switch( GetFormat() )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir case CF_NUMBER: nRet = text::ChapterFormat::NUMBER; break;
261cdf0e10cSrcweir case CF_TITLE: nRet = text::ChapterFormat::NAME; break;
262cdf0e10cSrcweir case CF_NUMBER_NOPREPST:
263cdf0e10cSrcweir nRet = text::ChapterFormat::DIGIT;
264cdf0e10cSrcweir break;
265cdf0e10cSrcweir case CF_NUM_NOPREPST_TITLE:
266cdf0e10cSrcweir nRet = text::ChapterFormat::NO_PREFIX_SUFFIX;
267cdf0e10cSrcweir break;
268cdf0e10cSrcweir case CF_NUM_TITLE:
269cdf0e10cSrcweir default: nRet = text::ChapterFormat::NAME_NUMBER;
270cdf0e10cSrcweir }
271cdf0e10cSrcweir rAny <<= nRet;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir break;
274cdf0e10cSrcweir
275cdf0e10cSrcweir default:
276cdf0e10cSrcweir DBG_ERROR("illegal property");
277cdf0e10cSrcweir }
278cdf0e10cSrcweir return sal_True;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir /*-----------------05.03.98 16:19-------------------
281cdf0e10cSrcweir
282cdf0e10cSrcweir --------------------------------------------------*/
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)283cdf0e10cSrcweir sal_Bool SwChapterField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
284cdf0e10cSrcweir {
285cdf0e10cSrcweir sal_Bool bRet = sal_True;
286cdf0e10cSrcweir switch( nWhichId )
287cdf0e10cSrcweir {
288cdf0e10cSrcweir case FIELD_PROP_BYTE1:
289cdf0e10cSrcweir {
290cdf0e10cSrcweir sal_Int8 nTmp = 0;
291cdf0e10cSrcweir rAny >>= nTmp;
292cdf0e10cSrcweir if(nTmp >= 0 && nTmp < MAXLEVEL)
293cdf0e10cSrcweir nLevel = nTmp;
294cdf0e10cSrcweir else
295cdf0e10cSrcweir bRet = sal_False;
296cdf0e10cSrcweir break;
297cdf0e10cSrcweir }
298cdf0e10cSrcweir
299cdf0e10cSrcweir case FIELD_PROP_USHORT1:
300cdf0e10cSrcweir {
301cdf0e10cSrcweir sal_Int16 nVal = 0;
302cdf0e10cSrcweir rAny >>= nVal;
303cdf0e10cSrcweir switch( nVal )
304cdf0e10cSrcweir {
305cdf0e10cSrcweir case text::ChapterFormat::NAME: SetFormat(CF_TITLE); break;
306cdf0e10cSrcweir case text::ChapterFormat::NUMBER: SetFormat(CF_NUMBER); break;
307cdf0e10cSrcweir case text::ChapterFormat::NO_PREFIX_SUFFIX:
308cdf0e10cSrcweir SetFormat(CF_NUM_NOPREPST_TITLE);
309cdf0e10cSrcweir break;
310cdf0e10cSrcweir case text::ChapterFormat::DIGIT:
311cdf0e10cSrcweir SetFormat(CF_NUMBER_NOPREPST);
312cdf0e10cSrcweir break;
313cdf0e10cSrcweir //case text::ChapterFormat::NAME_NUMBER:
314cdf0e10cSrcweir default: SetFormat(CF_NUM_TITLE);
315cdf0e10cSrcweir }
316cdf0e10cSrcweir }
317cdf0e10cSrcweir break;
318cdf0e10cSrcweir
319cdf0e10cSrcweir default:
320cdf0e10cSrcweir DBG_ERROR("illegal property");
321cdf0e10cSrcweir bRet = sal_False;
322cdf0e10cSrcweir }
323cdf0e10cSrcweir return bRet;
324cdf0e10cSrcweir }
325