1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: chpfld.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <com/sun/star/text/ChapterFormat.hpp>
37 #include <frame.hxx> // SwChapterFieldType::ChangeExpansion()
38 #include <pam.hxx> // fuer GetBodyTxtNode
41 #include <expfld.hxx> // fuer GetBodyTxtNode
43 #include <unofldmid.h>
45 #include <numrule.hxx>
47 using namespace ::com::sun::star
;
49 /*--------------------------------------------------------------------
50 Beschreibung: SwChapterFieldType
51 --------------------------------------------------------------------*/
54 SwChapterFieldType::SwChapterFieldType()
55 : SwFieldType( RES_CHAPTERFLD
)
60 SwFieldType
* SwChapterFieldType::Copy() const
62 return new SwChapterFieldType();
66 /*--------------------------------------------------------------------
67 Beschreibung: Kapittelfeld
68 --------------------------------------------------------------------*/
71 SwChapterField::SwChapterField(SwChapterFieldType
* pTyp
, sal_uInt32 nFmt
)
72 : SwField(pTyp
, nFmt
), nLevel( 0 )
76 String
SwChapterField::Expand() const
78 String
sStr( sNumber
);
81 case CF_TITLE
: sStr
= sTitle
; break;
84 case CF_NUM_TITLE
: sStr
.Insert( sPre
, 0 );
86 if( CF_NUM_TITLE
== GetFormat() )
90 case CF_NUM_NOPREPST_TITLE
: sStr
+= sTitle
; break;
96 SwField
* SwChapterField::Copy() const
98 SwChapterField
*pTmp
=
99 new SwChapterField((SwChapterFieldType
*)GetTyp(), GetFormat());
100 pTmp
->nLevel
= nLevel
;
101 pTmp
->sTitle
= sTitle
;
102 pTmp
->sNumber
= sNumber
;
109 // --> OD 2008-02-14 #i53420#
110 //void SwChapterField::ChangeExpansion( const SwFrm* pFrm,
111 // const SwTxtNode* pTxtNd,
112 // sal_Bool bSrchNum )
114 // ASSERT( pFrm, "in welchem Frame stehe ich denn?" )
115 // SwDoc* pDoc = (SwDoc*)pTxtNd->GetDoc();
116 // SwPosition aPos( pDoc->GetNodes().GetEndOfContent() );
118 // if( pFrm->IsInDocBody() )
119 // aPos.nNode = *pTxtNd;
120 // else if( 0 == (pTxtNd = GetBodyTxtNode( *pDoc, aPos, *pFrm )) )
121 // // kein TxtNode (Formatierung Kopf/Fusszeile)
123 // ChangeExpansion(*pTxtNd, bSrchNum);
125 void SwChapterField::ChangeExpansion(const SwFrm
* pFrm
,
126 const SwCntntNode
* pCntntNode
,
129 ASSERT( pFrm
, "in welchem Frame stehe ich denn?" )
130 SwDoc
* pDoc
= (SwDoc
*)pCntntNode
->GetDoc();
132 const SwTxtNode
* pTxtNode
= dynamic_cast<const SwTxtNode
*>(pCntntNode
);
133 if ( !pTxtNode
|| !pFrm
->IsInDocBody() )
135 SwPosition
aDummyPos( pDoc
->GetNodes().GetEndOfContent() );
136 pTxtNode
= GetBodyTxtNode( *pDoc
, aDummyPos
, *pFrm
);
141 ChangeExpansion( *pTxtNode
, bSrchNum
);
146 void SwChapterField::ChangeExpansion(const SwTxtNode
&rTxtNd
, sal_Bool bSrchNum
)
148 SwDoc
* pDoc
= (SwDoc
*)rTxtNd
.GetDoc();
149 const SwTxtNode
*pTxtNd
= rTxtNd
.FindOutlineNodeOfLevel( nLevel
);
154 const SwTxtNode
* pONd
= pTxtNd
;
156 if( pONd
&& pONd
->GetTxtColl() )
158 BYTE nPrevLvl
= nLevel
;
160 // --> OD 2008-04-02 #refactorlists#
161 // nLevel = GetRealLevel( pONd->GetTxtColl()->
162 // GetOutlineLevel() );
163 //ASSERT( pONd->GetOutlineLevel() >= 0 && pONd->GetOutlineLevel() < MAXLEVEL, //#outline level,zhaojianwei
164 // "<SwChapterField::ChangeExpansion(..)> - outline node with inconsistent outline level. Serious defect -> please inform OD." );
165 //nLevel = static_cast<BYTE>(pONd->GetOutlineLevel());
166 ASSERT( pONd
->GetAttrOutlineLevel() >= 0 && pONd
->GetAttrOutlineLevel() <= MAXLEVEL
,
167 "<SwChapterField::ChangeExpansion(..)> - outline node with inconsistent outline level. Serious defect -> please inform OD." );
168 nLevel
= static_cast<BYTE
>(pONd
->GetAttrOutlineLevel()); //<-end,zhaojianwei
171 if( nPrevLvl
< nLevel
)
173 else if( SVX_NUM_NUMBER_NONE
!= pDoc
->GetOutlineNumRule()
174 ->Get( nLevel
).GetNumberingType() )
182 pONd
= pTxtNd
->FindOutlineNodeOfLevel( nLevel
);
189 // nur die Nummer besorgen, ohne Pre-/Post-fixstrings
191 if ( pTxtNd
->IsOutline() )
193 // --> OD 2005-11-17 #128041#
194 // correction of refactoring done by cws swnumtree:
195 // retrieve numbering string without prefix and suffix strings
196 // as stated in the above german comment.
197 sNumber
= pTxtNd
->GetNumString( false );
200 SwNumRule
* pRule( pTxtNd
->GetNumRule() );
201 if ( pTxtNd
->IsCountedInList() && pRule
)
203 const SwNumFmt
& rNFmt
= pRule
->Get( static_cast<USHORT
>(pTxtNd
->GetActualListLevel()) );
204 sPost
= rNFmt
.GetSuffix();
205 sPre
= rNFmt
.GetPrefix();
208 sPost
= aEmptyStr
, sPre
= aEmptyStr
;
214 sNumber
= String("??", RTL_TEXTENCODING_ASCII_US
);
217 sTitle
= pTxtNd
->GetExpandTxt();
219 for( xub_StrLen i
= 0; i
< sTitle
.Len(); ++i
)
220 if( ' ' > sTitle
.GetChar( i
) )
221 sTitle
.Erase( i
--, 1 );
232 /*-----------------05.03.98 16:19-------------------
234 --------------------------------------------------*/
235 BOOL
SwChapterField::QueryValue( uno::Any
& rAny
, USHORT nWhichId
) const
239 case FIELD_PROP_BYTE1
:
240 rAny
<<= (sal_Int8
)nLevel
;
243 case FIELD_PROP_USHORT1
:
246 switch( GetFormat() )
248 case CF_NUMBER
: nRet
= text::ChapterFormat::NUMBER
; break;
249 case CF_TITLE
: nRet
= text::ChapterFormat::NAME
; break;
250 case CF_NUMBER_NOPREPST
:
251 nRet
= text::ChapterFormat::DIGIT
;
253 case CF_NUM_NOPREPST_TITLE
:
254 nRet
= text::ChapterFormat::NO_PREFIX_SUFFIX
;
257 default: nRet
= text::ChapterFormat::NAME_NUMBER
;
264 DBG_ERROR("illegal property");
268 /*-----------------05.03.98 16:19-------------------
270 --------------------------------------------------*/
271 BOOL
SwChapterField::PutValue( const uno::Any
& rAny
, USHORT nWhichId
)
276 case FIELD_PROP_BYTE1
:
280 if(nTmp
>= 0 && nTmp
< MAXLEVEL
)
287 case FIELD_PROP_USHORT1
:
293 case text::ChapterFormat::NAME
: SetFormat(CF_TITLE
); break;
294 case text::ChapterFormat::NUMBER
: SetFormat(CF_NUMBER
); break;
295 case text::ChapterFormat::NO_PREFIX_SUFFIX
:
296 SetFormat(CF_NUM_NOPREPST_TITLE
);
298 case text::ChapterFormat::DIGIT
:
299 SetFormat(CF_NUMBER_NOPREPST
);
301 //case text::ChapterFormat::NAME_NUMBER:
302 default: SetFormat(CF_NUM_TITLE
);
308 DBG_ERROR("illegal property");