xref: /aoo41x/main/sw/source/core/fields/docufld.cxx (revision dec99bbd)
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
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
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.
19efeef26fSAndrew Rist  *
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 #include <textapi.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <tools/pstm.hxx>
30cdf0e10cSrcweir #include <hintids.hxx>
31cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp>
32cdf0e10cSrcweir #include <com/sun/star/script/XTypeConverter.hpp>
33cdf0e10cSrcweir #include <com/sun/star/text/SetVariableType.hpp>
34cdf0e10cSrcweir #include <com/sun/star/text/XTextFieldsSupplier.hpp>
35cdf0e10cSrcweir #include <com/sun/star/text/UserDataPart.hpp>
36cdf0e10cSrcweir #include <com/sun/star/text/ChapterFormat.hpp>
37cdf0e10cSrcweir #include <com/sun/star/text/XTextField.hpp>
38cdf0e10cSrcweir #include <com/sun/star/text/PlaceholderType.hpp>
39cdf0e10cSrcweir #include <com/sun/star/text/TemplateDisplayFormat.hpp>
40cdf0e10cSrcweir #include <com/sun/star/text/UserFieldFormat.hpp>
41cdf0e10cSrcweir #include <com/sun/star/text/PageNumberType.hpp>
42cdf0e10cSrcweir #include <com/sun/star/text/ReferenceFieldPart.hpp>
43cdf0e10cSrcweir #include <com/sun/star/text/FilenameDisplayFormat.hpp>
44cdf0e10cSrcweir #include <com/sun/star/text/XDependentTextField.hpp>
45cdf0e10cSrcweir #include <com/sun/star/text/DocumentStatistic.hpp>
46cdf0e10cSrcweir #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
47cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp>
48cdf0e10cSrcweir #include <com/sun/star/util/Date.hpp>
49cdf0e10cSrcweir #include <com/sun/star/util/Duration.hpp>
50cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
51cdf0e10cSrcweir #include <editeng/unolingu.hxx>
52cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
53cdf0e10cSrcweir #include <comphelper/types.hxx>
54cdf0e10cSrcweir #include <comphelper/string.hxx>
55cdf0e10cSrcweir #include <tools/urlobj.hxx>
56cdf0e10cSrcweir #include <vcl/svapp.hxx>
57cdf0e10cSrcweir #include <svl/urihelper.hxx>
58cdf0e10cSrcweir #include <unotools/useroptions.hxx>
59cdf0e10cSrcweir #include <unotools/syslocale.hxx>
60cdf0e10cSrcweir #include <svl/zforlist.hxx>
61cdf0e10cSrcweir 
62cdf0e10cSrcweir #include <tools/time.hxx>
63cdf0e10cSrcweir #include <tools/datetime.hxx>
64cdf0e10cSrcweir 
65cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
66cdf0e10cSrcweir #include <com/sun/star/util/Date.hpp>
67cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
68cdf0e10cSrcweir #include <com/sun/star/util/Time.hpp>
69cdf0e10cSrcweir 
70cdf0e10cSrcweir #include <tools/shl.hxx>
71cdf0e10cSrcweir #include <swmodule.hxx>
72cdf0e10cSrcweir #include <sfx2/app.hxx>
73cdf0e10cSrcweir #include <sfx2/docfile.hxx>
74cdf0e10cSrcweir #include <sfx2/doctempl.hxx>
75cdf0e10cSrcweir #include <fmtfld.hxx>
76cdf0e10cSrcweir #include <txtfld.hxx>
77cdf0e10cSrcweir #include <charfmt.hxx>
78cdf0e10cSrcweir #include <docstat.hxx>
79cdf0e10cSrcweir #include <pagedesc.hxx>
80cdf0e10cSrcweir #include <fmtpdsc.hxx>
81cdf0e10cSrcweir #include <doc.hxx>
82cdf0e10cSrcweir #include <rootfrm.hxx>		// AuthorField
83cdf0e10cSrcweir #include <pagefrm.hxx>		//
84cdf0e10cSrcweir #include <cntfrm.hxx>		//
85cdf0e10cSrcweir #include <pam.hxx>
86cdf0e10cSrcweir #include <viewsh.hxx>
87cdf0e10cSrcweir #include <dbmgr.hxx>
88cdf0e10cSrcweir #include <shellres.hxx>
89cdf0e10cSrcweir #include <docufld.hxx>
90cdf0e10cSrcweir #include <flddat.hxx>
91cdf0e10cSrcweir #include <docfld.hxx>
92cdf0e10cSrcweir #include <ndtxt.hxx>
93cdf0e10cSrcweir #include <expfld.hxx>
94cdf0e10cSrcweir #include <poolfmt.hxx>
95cdf0e10cSrcweir #include <docsh.hxx>
96cdf0e10cSrcweir #include <unofldmid.h>
97cdf0e10cSrcweir #include <swunohelper.hxx>
98cdf0e10cSrcweir #include <comcore.hrc>
99cdf0e10cSrcweir 
100cdf0e10cSrcweir #include <editeng/outliner.hxx>
101cdf0e10cSrcweir #include <editeng/outlobj.hxx>
102cdf0e10cSrcweir #include <switerator.hxx>
103cdf0e10cSrcweir 
104cdf0e10cSrcweir #define URL_DECODE 	INetURLObject::DECODE_UNAMBIGUOUS
105cdf0e10cSrcweir 
106cdf0e10cSrcweir using ::rtl::OUString;
107cdf0e10cSrcweir using namespace ::com::sun::star;
108cdf0e10cSrcweir using namespace ::com::sun::star::uno;
109cdf0e10cSrcweir using namespace nsSwDocInfoSubType;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir /*--------------------------------------------------------------------
112cdf0e10cSrcweir 	Beschreibung: SwPageNumberFieldType
113cdf0e10cSrcweir  --------------------------------------------------------------------*/
114cdf0e10cSrcweir 
SwPageNumberFieldType()115cdf0e10cSrcweir SwPageNumberFieldType::SwPageNumberFieldType()
116cdf0e10cSrcweir 	: SwFieldType( RES_PAGENUMBERFLD ),
117cdf0e10cSrcweir 	nNumberingType( SVX_NUM_ARABIC ),
118cdf0e10cSrcweir 	nNum( 0 ),
119cdf0e10cSrcweir 	nMax( USHRT_MAX ),
120cdf0e10cSrcweir 	bVirtuell( sal_False )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
Expand(sal_uInt32 nFmt,short nOff,const String & rUserStr,String & rRet) const124cdf0e10cSrcweir String& SwPageNumberFieldType::Expand( sal_uInt32 nFmt, short nOff,
125cdf0e10cSrcweir 								const String& rUserStr, String& rRet ) const
126cdf0e10cSrcweir {
127cdf0e10cSrcweir 	sal_uInt32 nTmpFmt = (SVX_NUM_PAGEDESC == nFmt) ? (sal_uInt32)nNumberingType : nFmt;
128cdf0e10cSrcweir 	long nTmp = nNum + nOff;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	if( 0 >= nTmp || SVX_NUM_NUMBER_NONE == nTmpFmt || (!bVirtuell && nTmp > nMax) )
131cdf0e10cSrcweir 		rRet = aEmptyStr;
132cdf0e10cSrcweir 	else if( SVX_NUM_CHAR_SPECIAL == nTmpFmt )
133cdf0e10cSrcweir 		rRet = rUserStr;
134cdf0e10cSrcweir 	else
135cdf0e10cSrcweir 		rRet = FormatNumber( (sal_uInt16)nTmp, nTmpFmt );
136cdf0e10cSrcweir 	return rRet;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
Copy() const139cdf0e10cSrcweir SwFieldType* SwPageNumberFieldType::Copy() const
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	SwPageNumberFieldType *pTmp = new SwPageNumberFieldType();
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	pTmp->nNum 		 = nNum;
144cdf0e10cSrcweir 	pTmp->nMax 		 = nMax;
145cdf0e10cSrcweir 	pTmp->nNumberingType = nNumberingType;
146cdf0e10cSrcweir 	pTmp->bVirtuell  = bVirtuell;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	return pTmp;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir /*--------------------------------------------------------------------
152cdf0e10cSrcweir 	Beschreibung: Verschiedene Expandierung
153cdf0e10cSrcweir  --------------------------------------------------------------------*/
154cdf0e10cSrcweir 
ChangeExpansion(SwDoc * pDoc,sal_uInt16 nPage,sal_uInt16 nNumPages,sal_Bool bVirt,const sal_Int16 * pNumFmt)155cdf0e10cSrcweir void SwPageNumberFieldType::ChangeExpansion( SwDoc* pDoc, sal_uInt16 nPage,
156cdf0e10cSrcweir 											sal_uInt16 nNumPages, sal_Bool bVirt,
157cdf0e10cSrcweir 											const sal_Int16* pNumFmt )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir 	nNum = nPage;
160cdf0e10cSrcweir 	nMax = nNumPages;
161cdf0e10cSrcweir 	if( pNumFmt )
162cdf0e10cSrcweir 		nNumberingType = *pNumFmt;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 	bVirtuell = sal_False;
165cdf0e10cSrcweir 	if( bVirt )
166cdf0e10cSrcweir 	{
167cdf0e10cSrcweir 		// dann muss das Flag ueberprueft werden, denn das Layout setzt
168cdf0e10cSrcweir 		// es NIE zurueck
169cdf0e10cSrcweir 		const SfxItemPool &rPool = pDoc->GetAttrPool();
170cdf0e10cSrcweir 		const SwFmtPageDesc *pDesc;
171cdf0e10cSrcweir 		sal_uInt32 nMaxItems = rPool.GetItemCount2( RES_PAGEDESC );
172cdf0e10cSrcweir 		for( sal_uInt32 n = 0; n < nMaxItems; ++n )
173cdf0e10cSrcweir 			if( 0 != (pDesc = (SwFmtPageDesc*)rPool.GetItem2( RES_PAGEDESC, n ) )
174cdf0e10cSrcweir 				&& pDesc->GetNumOffset() && pDesc->GetDefinedIn() )
175cdf0e10cSrcweir 			{
176cdf0e10cSrcweir                 SwCntntNode* pNd = PTR_CAST( SwCntntNode, pDesc->GetDefinedIn() );
177cdf0e10cSrcweir 				if( pNd )
178cdf0e10cSrcweir 				{
179cdf0e10cSrcweir                     if ( SwIterator<SwFrm,SwCntntNode>::FirstElement(*pNd) )
180cdf0e10cSrcweir 						bVirtuell = sal_True;
181cdf0e10cSrcweir 				}
182cdf0e10cSrcweir 				else if( pDesc->GetDefinedIn()->ISA( SwFmt ))
183cdf0e10cSrcweir 				{
184cdf0e10cSrcweir 					SwAutoFmtGetDocNode aGetHt( &pDoc->GetNodes() );
185cdf0e10cSrcweir 					bVirtuell = !pDesc->GetDefinedIn()->GetInfo( aGetHt );
186cdf0e10cSrcweir 					break;
187cdf0e10cSrcweir 				}
188cdf0e10cSrcweir 			}
189cdf0e10cSrcweir 	}
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir /*--------------------------------------------------------------------
193cdf0e10cSrcweir 	Beschreibung: SwPageNumberField
194cdf0e10cSrcweir  --------------------------------------------------------------------*/
195cdf0e10cSrcweir 
SwPageNumberField(SwPageNumberFieldType * pTyp,sal_uInt16 nSub,sal_uInt32 nFmt,short nOff)196cdf0e10cSrcweir SwPageNumberField::SwPageNumberField(SwPageNumberFieldType* pTyp,
197cdf0e10cSrcweir 									 sal_uInt16 nSub, sal_uInt32 nFmt, short nOff)
198cdf0e10cSrcweir 	: SwField(pTyp, nFmt), nSubType(nSub), nOffset(nOff)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
Expand() const202cdf0e10cSrcweir String SwPageNumberField::Expand() const
203cdf0e10cSrcweir {
204cdf0e10cSrcweir 	String sRet;
205cdf0e10cSrcweir 	SwPageNumberFieldType* pFldType = (SwPageNumberFieldType*)GetTyp();
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 	if( PG_NEXT == nSubType && 1 != nOffset )
208cdf0e10cSrcweir 	{
209cdf0e10cSrcweir 		if( pFldType->Expand( GetFormat(), 1, sUserStr, sRet ).Len() )
210cdf0e10cSrcweir 			pFldType->Expand( GetFormat(), nOffset, sUserStr, sRet );
211cdf0e10cSrcweir 	}
212cdf0e10cSrcweir 	else if( PG_PREV == nSubType && -1 != nOffset )
213cdf0e10cSrcweir 	{
214cdf0e10cSrcweir 		if( pFldType->Expand( GetFormat(), -1, sUserStr, sRet ).Len() )
215cdf0e10cSrcweir 			pFldType->Expand( GetFormat(), nOffset, sUserStr, sRet );
216cdf0e10cSrcweir 	}
217cdf0e10cSrcweir 	else
218cdf0e10cSrcweir 		pFldType->Expand( GetFormat(), nOffset, sUserStr, sRet );
219cdf0e10cSrcweir 	return sRet;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
Copy() const222cdf0e10cSrcweir SwField* SwPageNumberField::Copy() const
223cdf0e10cSrcweir {
224cdf0e10cSrcweir 	SwPageNumberField *pTmp =
225cdf0e10cSrcweir 		new SwPageNumberField((SwPageNumberFieldType*)GetTyp(), nSubType, GetFormat(), nOffset);
226cdf0e10cSrcweir 	pTmp->SetLanguage( GetLanguage() );
227cdf0e10cSrcweir 	pTmp->SetUserString( sUserStr );
228cdf0e10cSrcweir 	return pTmp;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
GetPar2() const231cdf0e10cSrcweir String SwPageNumberField::GetPar2() const
232cdf0e10cSrcweir {
233cdf0e10cSrcweir 	return String::CreateFromInt32(nOffset);
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
SetPar2(const String & rStr)236cdf0e10cSrcweir void SwPageNumberField::SetPar2(const String& rStr)
237cdf0e10cSrcweir {
238cdf0e10cSrcweir 	nOffset = (short)rStr.ToInt32();
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
GetSubType() const241cdf0e10cSrcweir sal_uInt16 SwPageNumberField::GetSubType() const
242cdf0e10cSrcweir {
243cdf0e10cSrcweir 	return nSubType;
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const246cdf0e10cSrcweir sal_Bool SwPageNumberField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
247cdf0e10cSrcweir {
248cdf0e10cSrcweir     switch( nWhichId )
249cdf0e10cSrcweir 	{
250cdf0e10cSrcweir 	case FIELD_PROP_FORMAT:
251cdf0e10cSrcweir 		rAny <<= (sal_Int16)GetFormat();
252cdf0e10cSrcweir 		break;
253cdf0e10cSrcweir 	case FIELD_PROP_USHORT1:
254cdf0e10cSrcweir 		rAny <<= nOffset;
255cdf0e10cSrcweir 		break;
256cdf0e10cSrcweir 	case FIELD_PROP_SUBTYPE:
257cdf0e10cSrcweir 		{
258cdf0e10cSrcweir 	 		text::PageNumberType eType;
259cdf0e10cSrcweir 			eType = text::PageNumberType_CURRENT;
260cdf0e10cSrcweir 			if(nSubType == PG_PREV)
261cdf0e10cSrcweir 				eType = text::PageNumberType_PREV;
262cdf0e10cSrcweir 			else if(nSubType == PG_NEXT)
263cdf0e10cSrcweir 				eType = text::PageNumberType_NEXT;
264cdf0e10cSrcweir 			rAny.setValue(&eType, ::getCppuType((const text::PageNumberType*)0));
265cdf0e10cSrcweir 		}
266cdf0e10cSrcweir 		break;
267cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
268cdf0e10cSrcweir 		rAny <<= OUString(sUserStr);
269cdf0e10cSrcweir 		break;
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 	default:
272cdf0e10cSrcweir 		DBG_ERROR("illegal property");
273cdf0e10cSrcweir 	}
274cdf0e10cSrcweir 	return sal_True;
275cdf0e10cSrcweir }
276cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)277cdf0e10cSrcweir sal_Bool SwPageNumberField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
278cdf0e10cSrcweir {
279cdf0e10cSrcweir     sal_Bool bRet = sal_True;
280cdf0e10cSrcweir 	sal_Int16 nSet = 0;
281cdf0e10cSrcweir     switch( nWhichId )
282cdf0e10cSrcweir 	{
283cdf0e10cSrcweir 	case FIELD_PROP_FORMAT:
284cdf0e10cSrcweir 		rAny >>= nSet;
285cdf0e10cSrcweir 
286cdf0e10cSrcweir 		// TODO: woher kommen die defines?
287cdf0e10cSrcweir 		if(nSet <= SVX_NUM_PAGEDESC )
288cdf0e10cSrcweir 			SetFormat(nSet);
289cdf0e10cSrcweir 		else {
290cdf0e10cSrcweir 			//exception(wrong_value)
291cdf0e10cSrcweir 			;
292cdf0e10cSrcweir         }
293cdf0e10cSrcweir 		break;
294cdf0e10cSrcweir 	case FIELD_PROP_USHORT1:
295cdf0e10cSrcweir 		rAny >>= nSet;
296cdf0e10cSrcweir 		nOffset = nSet;
297cdf0e10cSrcweir 		break;
298cdf0e10cSrcweir 	case FIELD_PROP_SUBTYPE:
299cdf0e10cSrcweir         switch( SWUnoHelper::GetEnumAsInt32( rAny ) )
300cdf0e10cSrcweir 		{
301cdf0e10cSrcweir 			case text::PageNumberType_CURRENT:
302cdf0e10cSrcweir 				nSubType = PG_RANDOM;
303cdf0e10cSrcweir 			break;
304cdf0e10cSrcweir 			case text::PageNumberType_PREV:
305cdf0e10cSrcweir 				nSubType = PG_PREV;
306cdf0e10cSrcweir 			break;
307cdf0e10cSrcweir             case text::PageNumberType_NEXT:
308cdf0e10cSrcweir                 nSubType = PG_NEXT;
309cdf0e10cSrcweir 			break;
310cdf0e10cSrcweir 			default:
311cdf0e10cSrcweir                 bRet = sal_False;
312cdf0e10cSrcweir 		}
313cdf0e10cSrcweir 		break;
314cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
315cdf0e10cSrcweir 		::GetString( rAny, sUserStr );
316cdf0e10cSrcweir 		break;
317cdf0e10cSrcweir 
318cdf0e10cSrcweir 	default:
319cdf0e10cSrcweir 		DBG_ERROR("illegal property");
320cdf0e10cSrcweir 	}
321cdf0e10cSrcweir     return bRet;
322cdf0e10cSrcweir }
323cdf0e10cSrcweir /*--------------------------------------------------------------------
324cdf0e10cSrcweir 	Beschreibung: SwAuthorFieldType
325cdf0e10cSrcweir  --------------------------------------------------------------------*/
326cdf0e10cSrcweir 
SwAuthorFieldType()327cdf0e10cSrcweir SwAuthorFieldType::SwAuthorFieldType()
328cdf0e10cSrcweir 	: SwFieldType( RES_AUTHORFLD )
329cdf0e10cSrcweir {
330cdf0e10cSrcweir }
331cdf0e10cSrcweir 
Expand(sal_uLong nFmt) const332cdf0e10cSrcweir String SwAuthorFieldType::Expand(sal_uLong nFmt) const
333cdf0e10cSrcweir {
334cdf0e10cSrcweir 	String sRet;
335cdf0e10cSrcweir     SvtUserOptions&  rOpt = SW_MOD()->GetUserOptions();
336cdf0e10cSrcweir 	if((nFmt & 0xff) == AF_NAME)
337cdf0e10cSrcweir         sRet = rOpt.GetFullName();
338cdf0e10cSrcweir 	else
339cdf0e10cSrcweir         sRet = rOpt.GetID();
340cdf0e10cSrcweir 	return sRet;
341cdf0e10cSrcweir }
342cdf0e10cSrcweir 
Copy() const343cdf0e10cSrcweir SwFieldType* SwAuthorFieldType::Copy() const
344cdf0e10cSrcweir {
345cdf0e10cSrcweir 	return new SwAuthorFieldType;
346cdf0e10cSrcweir }
347cdf0e10cSrcweir 
348cdf0e10cSrcweir /*--------------------------------------------------------------------
349cdf0e10cSrcweir 	Beschreibung: SwAuthorField
350cdf0e10cSrcweir  --------------------------------------------------------------------*/
351cdf0e10cSrcweir 
SwAuthorField(SwAuthorFieldType * pTyp,sal_uInt32 nFmt)352cdf0e10cSrcweir SwAuthorField::SwAuthorField(SwAuthorFieldType* pTyp, sal_uInt32 nFmt)
353cdf0e10cSrcweir 	: SwField(pTyp, nFmt)
354cdf0e10cSrcweir {
355cdf0e10cSrcweir 	aContent = ((SwAuthorFieldType*)GetTyp())->Expand(GetFormat());
356cdf0e10cSrcweir }
357cdf0e10cSrcweir 
Expand() const358cdf0e10cSrcweir String SwAuthorField::Expand() const
359cdf0e10cSrcweir {
360cdf0e10cSrcweir 	if (!IsFixed())
361cdf0e10cSrcweir 		((SwAuthorField*)this)->aContent =
362cdf0e10cSrcweir 					((SwAuthorFieldType*)GetTyp())->Expand(GetFormat());
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 	return aContent;
365cdf0e10cSrcweir }
366cdf0e10cSrcweir 
Copy() const367cdf0e10cSrcweir SwField* SwAuthorField::Copy() const
368cdf0e10cSrcweir {
369cdf0e10cSrcweir 	SwAuthorField *pTmp = new SwAuthorField( (SwAuthorFieldType*)GetTyp(),
370cdf0e10cSrcweir 												GetFormat());
371cdf0e10cSrcweir 	pTmp->SetExpansion(aContent);
372cdf0e10cSrcweir 	return pTmp;
373cdf0e10cSrcweir }
374cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const375cdf0e10cSrcweir sal_Bool SwAuthorField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
376cdf0e10cSrcweir {
377cdf0e10cSrcweir 	sal_Bool bVal;
378cdf0e10cSrcweir     switch( nWhichId )
379cdf0e10cSrcweir 	{
380cdf0e10cSrcweir 	case FIELD_PROP_BOOL1:
381cdf0e10cSrcweir 		bVal = (GetFormat() & 0xff) == AF_NAME;
382cdf0e10cSrcweir 		rAny.setValue(&bVal, ::getBooleanCppuType());
383cdf0e10cSrcweir 		break;
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 	case FIELD_PROP_BOOL2:
386cdf0e10cSrcweir 		bVal = IsFixed();
387cdf0e10cSrcweir 		rAny.setValue(&bVal, ::getBooleanCppuType());
388cdf0e10cSrcweir 		break;
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
391cdf0e10cSrcweir 		rAny <<= rtl::OUString(GetContent());
392cdf0e10cSrcweir 		break;
393cdf0e10cSrcweir 
394cdf0e10cSrcweir 	default:
395cdf0e10cSrcweir 		DBG_ERROR("illegal property");
396cdf0e10cSrcweir 	}
397cdf0e10cSrcweir 	return sal_True;
398cdf0e10cSrcweir }
399cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)400cdf0e10cSrcweir sal_Bool SwAuthorField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
401cdf0e10cSrcweir {
402cdf0e10cSrcweir     switch( nWhichId )
403cdf0e10cSrcweir 	{
404cdf0e10cSrcweir 	case FIELD_PROP_BOOL1:
405cdf0e10cSrcweir 		SetFormat( *(sal_Bool*)rAny.getValue() ? AF_NAME : AF_SHORTCUT );
406cdf0e10cSrcweir 		break;
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 	case FIELD_PROP_BOOL2:
409cdf0e10cSrcweir 		if( *(sal_Bool*)rAny.getValue() )
410cdf0e10cSrcweir 			SetFormat( GetFormat() | AF_FIXED);
411cdf0e10cSrcweir 		else
412cdf0e10cSrcweir 			SetFormat( GetFormat() & ~AF_FIXED);
413cdf0e10cSrcweir 		break;
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
416cdf0e10cSrcweir 		::GetString( rAny, aContent );
417cdf0e10cSrcweir 		break;
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 	default:
420cdf0e10cSrcweir 		DBG_ERROR("illegal property");
421cdf0e10cSrcweir 	}
422cdf0e10cSrcweir 	return sal_True;
423cdf0e10cSrcweir }
424cdf0e10cSrcweir 
425cdf0e10cSrcweir /*--------------------------------------------------------------------
426cdf0e10cSrcweir 	Beschreibung: SwFileNameFieldType
427cdf0e10cSrcweir  --------------------------------------------------------------------*/
428cdf0e10cSrcweir 
SwFileNameFieldType(SwDoc * pDocument)429cdf0e10cSrcweir SwFileNameFieldType::SwFileNameFieldType(SwDoc *pDocument)
430cdf0e10cSrcweir 	: SwFieldType( RES_FILENAMEFLD )
431cdf0e10cSrcweir {
432cdf0e10cSrcweir 	pDoc = pDocument;
433cdf0e10cSrcweir }
434cdf0e10cSrcweir 
Expand(sal_uLong nFmt) const435cdf0e10cSrcweir String SwFileNameFieldType::Expand(sal_uLong nFmt) const
436cdf0e10cSrcweir {
437cdf0e10cSrcweir 	String aRet;
438cdf0e10cSrcweir 	const SwDocShell* pDShell = pDoc->GetDocShell();
439cdf0e10cSrcweir 	if( pDShell && pDShell->HasName() )
440cdf0e10cSrcweir 	{
441cdf0e10cSrcweir 		const INetURLObject& rURLObj = pDShell->GetMedium()->GetURLObject();
442cdf0e10cSrcweir 		switch( nFmt & ~FF_FIXED )
443cdf0e10cSrcweir 		{
444cdf0e10cSrcweir 			case FF_PATH:
445cdf0e10cSrcweir 				{
446cdf0e10cSrcweir 					if( INET_PROT_FILE == rURLObj.GetProtocol() )
447cdf0e10cSrcweir 					{
448cdf0e10cSrcweir 						INetURLObject aTemp(rURLObj);
449cdf0e10cSrcweir 						aTemp.removeSegment();
450cdf0e10cSrcweir                         // #101947# last slash should belong to the pathname
451cdf0e10cSrcweir 						aRet = aTemp.PathToFileName();//GetFull();
452cdf0e10cSrcweir 					}
453cdf0e10cSrcweir 					else
454cdf0e10cSrcweir 					{
455cdf0e10cSrcweir 						aRet = URIHelper::removePassword(
456cdf0e10cSrcweir 									rURLObj.GetMainURL( INetURLObject::NO_DECODE ),
457cdf0e10cSrcweir 									INetURLObject::WAS_ENCODED, URL_DECODE );
458cdf0e10cSrcweir 						aRet.Erase( aRet.Search( String(rURLObj.GetLastName(
459cdf0e10cSrcweir 													URL_DECODE )) ) );
460cdf0e10cSrcweir 					}
461cdf0e10cSrcweir 				}
462cdf0e10cSrcweir 				break;
463cdf0e10cSrcweir 
464cdf0e10cSrcweir 			case FF_NAME:
465cdf0e10cSrcweir 				aRet = rURLObj.GetLastName( URL_DECODE );
466cdf0e10cSrcweir 				break;
467cdf0e10cSrcweir 
468cdf0e10cSrcweir 			case FF_NAME_NOEXT:
469cdf0e10cSrcweir 				aRet = rURLObj.GetBase();
470cdf0e10cSrcweir 				break;
471cdf0e10cSrcweir 
472cdf0e10cSrcweir 			default:
473cdf0e10cSrcweir 				if( INET_PROT_FILE == rURLObj.GetProtocol() )
474cdf0e10cSrcweir 					aRet = rURLObj.GetFull();
475cdf0e10cSrcweir 				else
476cdf0e10cSrcweir 					aRet = URIHelper::removePassword(
477cdf0e10cSrcweir 									rURLObj.GetMainURL( INetURLObject::NO_DECODE ),
478cdf0e10cSrcweir 									INetURLObject::WAS_ENCODED, URL_DECODE );
479cdf0e10cSrcweir 		}
480cdf0e10cSrcweir 	}
481cdf0e10cSrcweir 	return aRet;
482cdf0e10cSrcweir }
483cdf0e10cSrcweir 
Copy() const484cdf0e10cSrcweir SwFieldType* SwFileNameFieldType::Copy() const
485cdf0e10cSrcweir {
486cdf0e10cSrcweir 	SwFieldType *pTmp = new SwFileNameFieldType(pDoc);
487cdf0e10cSrcweir 	return pTmp;
488cdf0e10cSrcweir }
489cdf0e10cSrcweir /*--------------------------------------------------------------------
490cdf0e10cSrcweir 	Beschreibung: SwFileNameField
491cdf0e10cSrcweir  --------------------------------------------------------------------*/
492cdf0e10cSrcweir 
SwFileNameField(SwFileNameFieldType * pTyp,sal_uInt32 nFmt)493cdf0e10cSrcweir SwFileNameField::SwFileNameField(SwFileNameFieldType* pTyp, sal_uInt32 nFmt)
494cdf0e10cSrcweir 	: SwField(pTyp, nFmt)
495cdf0e10cSrcweir {
496cdf0e10cSrcweir 	aContent = ((SwFileNameFieldType*)GetTyp())->Expand(GetFormat());
497cdf0e10cSrcweir }
498cdf0e10cSrcweir 
Expand() const499cdf0e10cSrcweir String SwFileNameField::Expand() const
500cdf0e10cSrcweir {
501cdf0e10cSrcweir 	if (!IsFixed())
502cdf0e10cSrcweir 		((SwFileNameField*)this)->aContent = ((SwFileNameFieldType*)GetTyp())->Expand(GetFormat());
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 	return aContent;
505cdf0e10cSrcweir }
506cdf0e10cSrcweir 
Copy() const507cdf0e10cSrcweir SwField* SwFileNameField::Copy() const
508cdf0e10cSrcweir {
509cdf0e10cSrcweir 	SwFileNameField *pTmp =
510cdf0e10cSrcweir 		new SwFileNameField((SwFileNameFieldType*)GetTyp(), GetFormat());
511cdf0e10cSrcweir 	pTmp->SetExpansion(aContent);
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 	return pTmp;
514cdf0e10cSrcweir }
515cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const516cdf0e10cSrcweir sal_Bool SwFileNameField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
517cdf0e10cSrcweir {
518cdf0e10cSrcweir     switch( nWhichId )
519cdf0e10cSrcweir 	{
520cdf0e10cSrcweir 	case FIELD_PROP_FORMAT:
521cdf0e10cSrcweir 		{
522cdf0e10cSrcweir         	sal_Int16 nRet;
523cdf0e10cSrcweir 			switch( GetFormat() &(~FF_FIXED) )
524cdf0e10cSrcweir 			{
525cdf0e10cSrcweir 				case FF_PATH:
526cdf0e10cSrcweir 					nRet = text::FilenameDisplayFormat::PATH;
527cdf0e10cSrcweir 				break;
528cdf0e10cSrcweir 				case FF_NAME_NOEXT:
529cdf0e10cSrcweir 					nRet = text::FilenameDisplayFormat::NAME;
530cdf0e10cSrcweir 				break;
531cdf0e10cSrcweir 				case FF_NAME:
532cdf0e10cSrcweir 					nRet = text::FilenameDisplayFormat::NAME_AND_EXT;
533cdf0e10cSrcweir 				break;
534cdf0e10cSrcweir 				default:	nRet = text::FilenameDisplayFormat::FULL;
535cdf0e10cSrcweir 			}
536cdf0e10cSrcweir 			rAny <<= nRet;
537cdf0e10cSrcweir 		}
538cdf0e10cSrcweir 		break;
539cdf0e10cSrcweir 
540cdf0e10cSrcweir 	case FIELD_PROP_BOOL2:
541cdf0e10cSrcweir 		{
542cdf0e10cSrcweir 			sal_Bool bVal = IsFixed();
543cdf0e10cSrcweir 			rAny.setValue(&bVal, ::getBooleanCppuType());
544cdf0e10cSrcweir 		}
545cdf0e10cSrcweir 		break;
546cdf0e10cSrcweir 
547cdf0e10cSrcweir 	case FIELD_PROP_PAR3:
548cdf0e10cSrcweir 		rAny <<= OUString(GetContent());
549cdf0e10cSrcweir 		break;
550cdf0e10cSrcweir 	default:
551cdf0e10cSrcweir 		DBG_ERROR("illegal property");
552cdf0e10cSrcweir 	}
553cdf0e10cSrcweir 	return sal_True;
554cdf0e10cSrcweir }
555cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)556cdf0e10cSrcweir sal_Bool SwFileNameField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
557cdf0e10cSrcweir {
558cdf0e10cSrcweir     switch( nWhichId )
559cdf0e10cSrcweir 	{
560cdf0e10cSrcweir 	case FIELD_PROP_FORMAT:
561cdf0e10cSrcweir 		{
562cdf0e10cSrcweir 			//JP 24.10.2001: int32 because in UnoField.cxx a putvalue is
563cdf0e10cSrcweir 			//				called with a int32 value! But normally we need
564cdf0e10cSrcweir 			//				here only a int16
565cdf0e10cSrcweir 			sal_Int32 nType = 0;
566cdf0e10cSrcweir 			rAny >>= nType;
567cdf0e10cSrcweir 			sal_Bool bFixed = IsFixed();
568cdf0e10cSrcweir 			switch( nType )
569cdf0e10cSrcweir 			{
570cdf0e10cSrcweir 				case text::FilenameDisplayFormat::PATH:
571cdf0e10cSrcweir 					nType = FF_PATH;
572cdf0e10cSrcweir 				break;
573cdf0e10cSrcweir 				case text::FilenameDisplayFormat::NAME:
574cdf0e10cSrcweir 					nType = FF_NAME_NOEXT;
575cdf0e10cSrcweir 				break;
576cdf0e10cSrcweir 				case text::FilenameDisplayFormat::NAME_AND_EXT:
577cdf0e10cSrcweir 					nType = FF_NAME;
578cdf0e10cSrcweir 				break;
579cdf0e10cSrcweir 				default:	nType = FF_PATHNAME;
580cdf0e10cSrcweir 			}
581cdf0e10cSrcweir 			if(bFixed)
582cdf0e10cSrcweir 				nType |= FF_FIXED;
583cdf0e10cSrcweir 			SetFormat(nType);
584cdf0e10cSrcweir 		}
585cdf0e10cSrcweir 		break;
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 	case FIELD_PROP_BOOL2:
588cdf0e10cSrcweir 		if( *(sal_Bool*)rAny.getValue() )
589cdf0e10cSrcweir 			SetFormat( GetFormat() | FF_FIXED);
590cdf0e10cSrcweir 		else
591cdf0e10cSrcweir 			SetFormat( GetFormat() & ~FF_FIXED);
592cdf0e10cSrcweir 		break;
593cdf0e10cSrcweir 
594cdf0e10cSrcweir 	case FIELD_PROP_PAR3:
595cdf0e10cSrcweir 		::GetString( rAny, aContent );
596cdf0e10cSrcweir 		break;
597cdf0e10cSrcweir 
598cdf0e10cSrcweir 	default:
599cdf0e10cSrcweir 		DBG_ERROR("illegal property");
600cdf0e10cSrcweir 	}
601cdf0e10cSrcweir 	return sal_True;
602cdf0e10cSrcweir }
603cdf0e10cSrcweir /*--------------------------------------------------------------------
604cdf0e10cSrcweir 	Beschreibung: SwTemplNameFieldType
605cdf0e10cSrcweir  --------------------------------------------------------------------*/
606cdf0e10cSrcweir 
SwTemplNameFieldType(SwDoc * pDocument)607cdf0e10cSrcweir SwTemplNameFieldType::SwTemplNameFieldType(SwDoc *pDocument)
608cdf0e10cSrcweir 	: SwFieldType( RES_TEMPLNAMEFLD )
609cdf0e10cSrcweir {
610cdf0e10cSrcweir 	pDoc = pDocument;
611cdf0e10cSrcweir }
612cdf0e10cSrcweir 
Expand(sal_uLong nFmt) const613cdf0e10cSrcweir String SwTemplNameFieldType::Expand(sal_uLong nFmt) const
614cdf0e10cSrcweir {
615cdf0e10cSrcweir 	ASSERT( nFmt < FF_END, "Expand: kein guelt. Fmt!" );
616cdf0e10cSrcweir 
617cdf0e10cSrcweir 	String aRet;
618cdf0e10cSrcweir     SwDocShell *pDocShell(pDoc->GetDocShell());
619cdf0e10cSrcweir     DBG_ASSERT(pDocShell, "no SwDocShell");
620cdf0e10cSrcweir     if (pDocShell) {
621cdf0e10cSrcweir         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
622cdf0e10cSrcweir             pDocShell->GetModel(), uno::UNO_QUERY_THROW);
623cdf0e10cSrcweir         uno::Reference<document::XDocumentProperties> xDocProps(
624cdf0e10cSrcweir             xDPS->getDocumentProperties());
625cdf0e10cSrcweir         DBG_ASSERT(xDocProps.is(), "Doc has no DocumentProperties");
626cdf0e10cSrcweir 
627cdf0e10cSrcweir 		if( FF_UI_NAME == nFmt )
628cdf0e10cSrcweir 			aRet = xDocProps->getTemplateName();
629cdf0e10cSrcweir 		else if( !xDocProps->getTemplateURL().equalsAscii("") )
630cdf0e10cSrcweir 		{
631cdf0e10cSrcweir 			if( FF_UI_RANGE == nFmt )
632cdf0e10cSrcweir 			{
633cdf0e10cSrcweir 				// fuers besorgen vom RegionNamen !!
634cdf0e10cSrcweir 				SfxDocumentTemplates aFac;
635cdf0e10cSrcweir 				aFac.Construct();
636cdf0e10cSrcweir 				String sTmp;
637cdf0e10cSrcweir 				aFac.GetLogicNames( xDocProps->getTemplateURL(), aRet, sTmp );
638cdf0e10cSrcweir 			}
639cdf0e10cSrcweir 			else
640cdf0e10cSrcweir 			{
641cdf0e10cSrcweir 				INetURLObject aPathName( xDocProps->getTemplateURL() );
642cdf0e10cSrcweir 				if( FF_NAME == nFmt )
643cdf0e10cSrcweir 					aRet = aPathName.GetName(URL_DECODE);
644cdf0e10cSrcweir 				else if( FF_NAME_NOEXT == nFmt )
645cdf0e10cSrcweir 					aRet = aPathName.GetBase();
646cdf0e10cSrcweir 				else
647cdf0e10cSrcweir 				{
648cdf0e10cSrcweir 					if( FF_PATH == nFmt )
649cdf0e10cSrcweir 					{
650cdf0e10cSrcweir 						aPathName.removeSegment();
651cdf0e10cSrcweir 						aRet = aPathName.GetFull();
652cdf0e10cSrcweir 					}
653cdf0e10cSrcweir 					else
654cdf0e10cSrcweir 						aRet = aPathName.GetFull();
655cdf0e10cSrcweir 				}
656cdf0e10cSrcweir 			}
657cdf0e10cSrcweir 		}
658cdf0e10cSrcweir 	}
659cdf0e10cSrcweir 	return aRet;
660cdf0e10cSrcweir }
661cdf0e10cSrcweir 
Copy() const662cdf0e10cSrcweir SwFieldType* SwTemplNameFieldType::Copy() const
663cdf0e10cSrcweir {
664cdf0e10cSrcweir 	SwFieldType *pTmp = new SwTemplNameFieldType(pDoc);
665cdf0e10cSrcweir 	return pTmp;
666cdf0e10cSrcweir }
667cdf0e10cSrcweir /*--------------------------------------------------------------------
668cdf0e10cSrcweir 	Beschreibung: SwTemplNameField
669cdf0e10cSrcweir  --------------------------------------------------------------------*/
670cdf0e10cSrcweir 
SwTemplNameField(SwTemplNameFieldType * pTyp,sal_uInt32 nFmt)671cdf0e10cSrcweir SwTemplNameField::SwTemplNameField(SwTemplNameFieldType* pTyp, sal_uInt32 nFmt)
672cdf0e10cSrcweir 	: SwField(pTyp, nFmt)
673cdf0e10cSrcweir {}
674cdf0e10cSrcweir 
Expand() const675cdf0e10cSrcweir String SwTemplNameField::Expand() const
676cdf0e10cSrcweir {
677cdf0e10cSrcweir 	return((SwTemplNameFieldType*)GetTyp())->Expand(GetFormat());
678cdf0e10cSrcweir }
679cdf0e10cSrcweir 
Copy() const680cdf0e10cSrcweir SwField* SwTemplNameField::Copy() const
681cdf0e10cSrcweir {
682cdf0e10cSrcweir 	SwTemplNameField *pTmp =
683cdf0e10cSrcweir 		new SwTemplNameField((SwTemplNameFieldType*)GetTyp(), GetFormat());
684cdf0e10cSrcweir 	return pTmp;
685cdf0e10cSrcweir }
686cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const687cdf0e10cSrcweir sal_Bool SwTemplNameField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
688cdf0e10cSrcweir {
689cdf0e10cSrcweir     switch ( nWhichId )
690cdf0e10cSrcweir 	{
691cdf0e10cSrcweir 	case FIELD_PROP_FORMAT:
692cdf0e10cSrcweir 		{
693cdf0e10cSrcweir         	sal_Int16 nRet;
694cdf0e10cSrcweir 			switch( GetFormat() )
695cdf0e10cSrcweir 			{
696cdf0e10cSrcweir 				case FF_PATH:		nRet = text::FilenameDisplayFormat::PATH; break;
697cdf0e10cSrcweir 				case FF_NAME_NOEXT: nRet = text::FilenameDisplayFormat::NAME; break;
698cdf0e10cSrcweir 				case FF_NAME: 		nRet = text::FilenameDisplayFormat::NAME_AND_EXT; break;
699cdf0e10cSrcweir 				case FF_UI_RANGE: 	nRet = text::TemplateDisplayFormat::AREA; break;
700cdf0e10cSrcweir 				case FF_UI_NAME:    nRet = text::TemplateDisplayFormat::TITLE;  break;
701cdf0e10cSrcweir 				default:	nRet = text::FilenameDisplayFormat::FULL;
702cdf0e10cSrcweir 
703cdf0e10cSrcweir 			}
704cdf0e10cSrcweir 			rAny <<= nRet;
705cdf0e10cSrcweir 		}
706cdf0e10cSrcweir 		break;
707cdf0e10cSrcweir 	default:
708cdf0e10cSrcweir 		DBG_ERROR("illegal property");
709cdf0e10cSrcweir 	}
710cdf0e10cSrcweir 	return sal_True;
711cdf0e10cSrcweir }
712cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)713cdf0e10cSrcweir sal_Bool SwTemplNameField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
714cdf0e10cSrcweir {
715cdf0e10cSrcweir     switch ( nWhichId )
716cdf0e10cSrcweir 	{
717cdf0e10cSrcweir 	case FIELD_PROP_FORMAT:
718cdf0e10cSrcweir 		{
719cdf0e10cSrcweir 			//JP 24.10.2001: int32 because in UnoField.cxx a putvalue is
720cdf0e10cSrcweir 			//				called with a int32 value! But normally we need
721cdf0e10cSrcweir 			//				here only a int16
722cdf0e10cSrcweir 			sal_Int32 nType = 0;
723cdf0e10cSrcweir 			rAny >>= nType;
724cdf0e10cSrcweir 			switch( nType )
725cdf0e10cSrcweir 			{
726cdf0e10cSrcweir 			case text::FilenameDisplayFormat::PATH:
727cdf0e10cSrcweir 				SetFormat(FF_PATH);
728cdf0e10cSrcweir 			break;
729cdf0e10cSrcweir 			case text::FilenameDisplayFormat::NAME:
730cdf0e10cSrcweir 				SetFormat(FF_NAME_NOEXT);
731cdf0e10cSrcweir 			break;
732cdf0e10cSrcweir 			case text::FilenameDisplayFormat::NAME_AND_EXT:
733cdf0e10cSrcweir 				SetFormat(FF_NAME);
734cdf0e10cSrcweir 			break;
735cdf0e10cSrcweir 			case text::TemplateDisplayFormat::AREA	:
736cdf0e10cSrcweir 				SetFormat(FF_UI_RANGE);
737cdf0e10cSrcweir 			break;
738cdf0e10cSrcweir 			case text::TemplateDisplayFormat::TITLE  :
739cdf0e10cSrcweir 				SetFormat(FF_UI_NAME);
740cdf0e10cSrcweir 			break;
741cdf0e10cSrcweir 			default:	SetFormat(FF_PATHNAME);
742cdf0e10cSrcweir 			}
743cdf0e10cSrcweir 		}
744cdf0e10cSrcweir 		break;
745cdf0e10cSrcweir 	default:
746cdf0e10cSrcweir 		DBG_ERROR("illegal property");
747cdf0e10cSrcweir 	}
748cdf0e10cSrcweir 	return sal_True;
749cdf0e10cSrcweir }
750cdf0e10cSrcweir /*--------------------------------------------------------------------
751cdf0e10cSrcweir 	Beschreibung: SwDocStatFieldType
752cdf0e10cSrcweir  --------------------------------------------------------------------*/
753cdf0e10cSrcweir 
SwDocStatFieldType(SwDoc * pDocument)754cdf0e10cSrcweir SwDocStatFieldType::SwDocStatFieldType(SwDoc* pDocument)
755cdf0e10cSrcweir 	: SwFieldType( RES_DOCSTATFLD ), nNumberingType( SVX_NUM_ARABIC )
756cdf0e10cSrcweir {
757cdf0e10cSrcweir 	pDoc = pDocument;
758cdf0e10cSrcweir }
759cdf0e10cSrcweir 
Expand(sal_uInt16 nSubType,sal_uInt32 nFmt) const760cdf0e10cSrcweir String SwDocStatFieldType::Expand(sal_uInt16 nSubType, sal_uInt32 nFmt) const
761cdf0e10cSrcweir {
762cdf0e10cSrcweir 	sal_uInt32 nVal = 0;
763cdf0e10cSrcweir 	const SwDocStat& rDStat = pDoc->GetDocStat();
764cdf0e10cSrcweir 	switch( nSubType )
765cdf0e10cSrcweir 	{
766cdf0e10cSrcweir 		case DS_TBL:  nVal = rDStat.nTbl;   break;
767cdf0e10cSrcweir 		case DS_GRF:  nVal = rDStat.nGrf;   break;
768cdf0e10cSrcweir 		case DS_OLE:  nVal = rDStat.nOLE;   break;
769cdf0e10cSrcweir 		case DS_PARA: nVal = rDStat.nPara;  break;
770cdf0e10cSrcweir 		case DS_WORD: nVal = rDStat.nWord;  break;
771cdf0e10cSrcweir 		case DS_CHAR: nVal = rDStat.nChar;  break;
772cdf0e10cSrcweir 		case DS_PAGE:
773cdf0e10cSrcweir 			if( pDoc->GetCurrentLayout() )//swmod 080218
774cdf0e10cSrcweir 				((SwDocStat	&)rDStat).nPage = pDoc->GetCurrentLayout()->GetPageNum();	//swmod 080218
775cdf0e10cSrcweir 			nVal = rDStat.nPage;
776cdf0e10cSrcweir 			if( SVX_NUM_PAGEDESC == nFmt )
777cdf0e10cSrcweir 				nFmt = (sal_uInt32)nNumberingType;
778cdf0e10cSrcweir 			break;
779cdf0e10cSrcweir 		default:
780cdf0e10cSrcweir 			ASSERT( sal_False, "SwDocStatFieldType::Expand: unbekannter SubType" );
781cdf0e10cSrcweir 	}
782cdf0e10cSrcweir 
783cdf0e10cSrcweir 	String sRet;
784cdf0e10cSrcweir 	if( nVal <= SHRT_MAX )
785cdf0e10cSrcweir 		sRet = FormatNumber( (sal_uInt16)nVal, nFmt );
786cdf0e10cSrcweir 	else
787cdf0e10cSrcweir 		sRet = String::CreateFromInt32( nVal );
788cdf0e10cSrcweir 	return sRet;
789cdf0e10cSrcweir }
790cdf0e10cSrcweir 
Copy() const791cdf0e10cSrcweir SwFieldType* SwDocStatFieldType::Copy() const
792cdf0e10cSrcweir {
793cdf0e10cSrcweir 	SwDocStatFieldType *pTmp = new SwDocStatFieldType(pDoc);
794cdf0e10cSrcweir 	return pTmp;
795cdf0e10cSrcweir }
796cdf0e10cSrcweir 
797cdf0e10cSrcweir /*--------------------------------------------------------------------
798cdf0e10cSrcweir 	Beschreibung: SwDocStatFieldType
799cdf0e10cSrcweir 				  Aus historischen Gruenden steht in nFormat der
800cdf0e10cSrcweir 				  SubType
801cdf0e10cSrcweir  --------------------------------------------------------------------*/
802cdf0e10cSrcweir 
SwDocStatField(SwDocStatFieldType * pTyp,sal_uInt16 nSub,sal_uInt32 nFmt)803cdf0e10cSrcweir SwDocStatField::SwDocStatField(SwDocStatFieldType* pTyp, sal_uInt16 nSub, sal_uInt32 nFmt)
804cdf0e10cSrcweir 	: SwField(pTyp, nFmt),
805cdf0e10cSrcweir 	nSubType(nSub)
806cdf0e10cSrcweir {}
807cdf0e10cSrcweir 
Expand() const808cdf0e10cSrcweir String SwDocStatField::Expand() const
809cdf0e10cSrcweir {
810cdf0e10cSrcweir 	return((SwDocStatFieldType*)GetTyp())->Expand(nSubType, GetFormat());
811cdf0e10cSrcweir }
812cdf0e10cSrcweir 
Copy() const813cdf0e10cSrcweir SwField* SwDocStatField::Copy() const
814cdf0e10cSrcweir {
815cdf0e10cSrcweir 	SwDocStatField *pTmp = new SwDocStatField(
816cdf0e10cSrcweir 					(SwDocStatFieldType*)GetTyp(), nSubType, GetFormat() );
817cdf0e10cSrcweir 	return pTmp;
818cdf0e10cSrcweir }
819cdf0e10cSrcweir 
GetSubType() const820cdf0e10cSrcweir sal_uInt16 SwDocStatField::GetSubType() const
821cdf0e10cSrcweir {
822cdf0e10cSrcweir 	return nSubType;
823cdf0e10cSrcweir }
824cdf0e10cSrcweir 
SetSubType(sal_uInt16 nSub)825cdf0e10cSrcweir void SwDocStatField::SetSubType(sal_uInt16 nSub)
826cdf0e10cSrcweir {
827cdf0e10cSrcweir 	nSubType = nSub;
828cdf0e10cSrcweir }
829cdf0e10cSrcweir 
ChangeExpansion(const SwFrm * pFrm)830cdf0e10cSrcweir void SwDocStatField::ChangeExpansion( const SwFrm* pFrm )
831cdf0e10cSrcweir {
832cdf0e10cSrcweir 	if( DS_PAGE == nSubType && SVX_NUM_PAGEDESC == GetFormat() )
833cdf0e10cSrcweir 		((SwDocStatFieldType*)GetTyp())->SetNumFormat(
834cdf0e10cSrcweir 				pFrm->FindPageFrm()->GetPageDesc()->GetNumType().GetNumberingType() );
835cdf0e10cSrcweir }
836cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const837cdf0e10cSrcweir sal_Bool SwDocStatField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
838cdf0e10cSrcweir {
839cdf0e10cSrcweir     switch ( nWhichId )
840cdf0e10cSrcweir 	{
841cdf0e10cSrcweir 	case FIELD_PROP_USHORT2:
842cdf0e10cSrcweir 		rAny <<= (sal_Int16)GetFormat();
843cdf0e10cSrcweir 		break;
844cdf0e10cSrcweir 	default:
845cdf0e10cSrcweir 		DBG_ERROR("illegal property");
846cdf0e10cSrcweir 	}
847cdf0e10cSrcweir 	return sal_True;
848cdf0e10cSrcweir }
849cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)850cdf0e10cSrcweir sal_Bool SwDocStatField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
851cdf0e10cSrcweir {
852cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
853cdf0e10cSrcweir     switch ( nWhichId )
854cdf0e10cSrcweir 	{
855cdf0e10cSrcweir 	case FIELD_PROP_USHORT2:
856cdf0e10cSrcweir 		{
857cdf0e10cSrcweir 			sal_Int16 nSet = 0;
858cdf0e10cSrcweir 			rAny >>= nSet;
859cdf0e10cSrcweir 			if(nSet <= SVX_NUM_CHARS_LOWER_LETTER_N &&
860cdf0e10cSrcweir 				nSet != SVX_NUM_CHAR_SPECIAL &&
861cdf0e10cSrcweir 					nSet != SVX_NUM_BITMAP)
862cdf0e10cSrcweir 			{
863cdf0e10cSrcweir 				SetFormat(nSet);
864cdf0e10cSrcweir 				bRet = sal_True;
865cdf0e10cSrcweir 			}
866cdf0e10cSrcweir 		}
867cdf0e10cSrcweir 		break;
868cdf0e10cSrcweir 
869cdf0e10cSrcweir 	default:
870cdf0e10cSrcweir 		DBG_ERROR("illegal property");
871cdf0e10cSrcweir 	}
872cdf0e10cSrcweir 	return bRet;
873cdf0e10cSrcweir }
874cdf0e10cSrcweir 
875cdf0e10cSrcweir /*--------------------------------------------------------------------
876cdf0e10cSrcweir 	Beschreibung: DokumentinfoFields
877cdf0e10cSrcweir  --------------------------------------------------------------------*/
878cdf0e10cSrcweir 
SwDocInfoFieldType(SwDoc * pDc)879cdf0e10cSrcweir SwDocInfoFieldType::SwDocInfoFieldType(SwDoc* pDc)
880cdf0e10cSrcweir 	: SwValueFieldType( pDc, RES_DOCINFOFLD )
881cdf0e10cSrcweir {
882cdf0e10cSrcweir }
883cdf0e10cSrcweir 
884cdf0e10cSrcweir // ---------------------------------------------------------------------------
Copy() const885cdf0e10cSrcweir SwFieldType* SwDocInfoFieldType::Copy() const
886cdf0e10cSrcweir {
887cdf0e10cSrcweir 	SwDocInfoFieldType* pTyp = new SwDocInfoFieldType(GetDoc());
888cdf0e10cSrcweir 	return pTyp;
889cdf0e10cSrcweir }
890cdf0e10cSrcweir 
lcl_GetLocalDataWrapper(sal_uLong nLang,const LocaleDataWrapper ** ppAppLocalData,const LocaleDataWrapper ** ppLocalData)891cdf0e10cSrcweir void lcl_GetLocalDataWrapper( sal_uLong nLang,
892cdf0e10cSrcweir 							  const LocaleDataWrapper **ppAppLocalData,
893cdf0e10cSrcweir 							  const LocaleDataWrapper **ppLocalData )
894cdf0e10cSrcweir {
895cdf0e10cSrcweir     SvtSysLocale aLocale;
896cdf0e10cSrcweir 	*ppAppLocalData = &aLocale.GetLocaleData();
897cdf0e10cSrcweir 	*ppLocalData = *ppAppLocalData;
898cdf0e10cSrcweir 	if( nLang != SvxLocaleToLanguage( (*ppLocalData)->getLocale() ) )
899cdf0e10cSrcweir 		*ppLocalData = new LocaleDataWrapper(
900cdf0e10cSrcweir 						::comphelper::getProcessServiceFactory(),
901cdf0e10cSrcweir 						SvxCreateLocale( static_cast<LanguageType>(nLang) ) );
902cdf0e10cSrcweir }
903cdf0e10cSrcweir 
904cdf0e10cSrcweir // ---------------------------------------------------------------------------
Expand(sal_uInt16 nSub,sal_uInt32 nFormat,sal_uInt16 nLang,const String & rName) const905cdf0e10cSrcweir String SwDocInfoFieldType::Expand( sal_uInt16 nSub, sal_uInt32 nFormat,
906cdf0e10cSrcweir 									sal_uInt16 nLang, const String& rName ) const
907cdf0e10cSrcweir {
908cdf0e10cSrcweir 	String aStr;
909cdf0e10cSrcweir 	const LocaleDataWrapper *pAppLocalData = 0, *pLocalData = 0;
910cdf0e10cSrcweir     SwDocShell *pDocShell(GetDoc()->GetDocShell());
911cdf0e10cSrcweir     DBG_ASSERT(pDocShell, "no SwDocShell");
912cdf0e10cSrcweir     if (!pDocShell) { return aStr; }
913cdf0e10cSrcweir 
914cdf0e10cSrcweir     uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
915cdf0e10cSrcweir         pDocShell->GetModel(), uno::UNO_QUERY_THROW);
916cdf0e10cSrcweir     uno::Reference<document::XDocumentProperties> xDocProps(
917cdf0e10cSrcweir         xDPS->getDocumentProperties());
918cdf0e10cSrcweir     DBG_ASSERT(xDocProps.is(), "Doc has no DocumentProperties");
919cdf0e10cSrcweir 
920cdf0e10cSrcweir 	sal_uInt16 nExtSub = nSub & 0xff00;
921cdf0e10cSrcweir 	nSub &= 0xff;	// ExtendedSubTypes nicht beachten
922cdf0e10cSrcweir 
923cdf0e10cSrcweir 	switch(nSub)
924cdf0e10cSrcweir 	{
925cdf0e10cSrcweir 	case DI_TITEL:	aStr = xDocProps->getTitle();	    break;
926cdf0e10cSrcweir 	case DI_THEMA:	aStr = xDocProps->getSubject();	    break;
927cdf0e10cSrcweir 	case DI_KEYS:	aStr = ::comphelper::string::convertCommaSeparated(
928cdf0e10cSrcweir                                 xDocProps->getKeywords());
929cdf0e10cSrcweir                     break;
930cdf0e10cSrcweir 	case DI_COMMENT:aStr = xDocProps->getDescription();	break;
931cdf0e10cSrcweir 	case DI_DOCNO:	aStr = String::CreateFromInt32(
932cdf0e10cSrcweir 										xDocProps->getEditingCycles() );
933cdf0e10cSrcweir 					break;
934cdf0e10cSrcweir 	case DI_EDIT:
935cdf0e10cSrcweir 		if ( !nFormat )
936cdf0e10cSrcweir 		{
937cdf0e10cSrcweir 			lcl_GetLocalDataWrapper( nLang, &pAppLocalData, &pLocalData );
938cdf0e10cSrcweir             sal_Int32 dur = xDocProps->getEditingDuration();
939cdf0e10cSrcweir 			aStr = pLocalData->getTime( Time(dur/3600, (dur%3600)/60, dur%60),
940cdf0e10cSrcweir                                         sal_False, sal_False);
941cdf0e10cSrcweir 		}
942cdf0e10cSrcweir 		else
943cdf0e10cSrcweir 		{
944cdf0e10cSrcweir             sal_Int32 dur = xDocProps->getEditingDuration();
945cdf0e10cSrcweir             double fVal = Time(dur/3600, (dur%3600)/60, dur%60).GetTimeInDays();
946cdf0e10cSrcweir 			aStr = ExpandValue(fVal, nFormat, nLang);
947cdf0e10cSrcweir 		}
948cdf0e10cSrcweir 		break;
949cdf0e10cSrcweir 	case DI_CUSTOM:
950cdf0e10cSrcweir 		{
951cdf0e10cSrcweir 			::rtl::OUString sVal;
952cdf0e10cSrcweir 			try
953cdf0e10cSrcweir 			{
954cdf0e10cSrcweir 				uno::Any aAny;
955cdf0e10cSrcweir 				uno::Reference < beans::XPropertySet > xSet(
956cdf0e10cSrcweir                     xDocProps->getUserDefinedProperties(),
957cdf0e10cSrcweir                     uno::UNO_QUERY_THROW);
958cdf0e10cSrcweir 				aAny = xSet->getPropertyValue( rName );
959cdf0e10cSrcweir 
960cdf0e10cSrcweir 				uno::Reference < script::XTypeConverter > xConverter( comphelper::getProcessServiceFactory()
961cdf0e10cSrcweir 					->createInstance(::rtl::OUString::createFromAscii("com.sun.star.script.Converter")), uno::UNO_QUERY );
962cdf0e10cSrcweir 				uno::Any aNew;
963cdf0e10cSrcweir 					aNew = xConverter->convertToSimpleType( aAny, uno::TypeClass_STRING );
964cdf0e10cSrcweir 				aNew >>= sVal;
965cdf0e10cSrcweir 			}
966cdf0e10cSrcweir 			catch (uno::Exception&) {}
967cdf0e10cSrcweir 			return sVal;
968cdf0e10cSrcweir 		}
969cdf0e10cSrcweir 
970cdf0e10cSrcweir 	default:
971cdf0e10cSrcweir 		{
972cdf0e10cSrcweir 			String aName( xDocProps->getAuthor() );
973cdf0e10cSrcweir 			util::DateTime uDT( xDocProps->getCreationDate() );
974cdf0e10cSrcweir             Date aD(uDT.Day, uDT.Month, uDT.Year);
975cdf0e10cSrcweir             Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
976cdf0e10cSrcweir             DateTime aDate(aD,aT);
977cdf0e10cSrcweir 			if( nSub == DI_CREATE )
978cdf0e10cSrcweir 				;		// das wars schon!!
979cdf0e10cSrcweir 			else if( nSub == DI_CHANGE )
980cdf0e10cSrcweir 			{
981cdf0e10cSrcweir 				aName = xDocProps->getModifiedBy();
982cdf0e10cSrcweir 				uDT = xDocProps->getModificationDate();
983cdf0e10cSrcweir                 Date bD(uDT.Day, uDT.Month, uDT.Year);
984cdf0e10cSrcweir                 Time bT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
985cdf0e10cSrcweir                 DateTime bDate(bD,bT);
986cdf0e10cSrcweir                 aDate = bDate;
987cdf0e10cSrcweir             }
988cdf0e10cSrcweir 			else if( nSub == DI_PRINT )
989cdf0e10cSrcweir 			{
990cdf0e10cSrcweir 				aName = xDocProps->getPrintedBy();
991cdf0e10cSrcweir 				uDT = xDocProps->getPrintDate();
992cdf0e10cSrcweir                 Date bD(uDT.Day, uDT.Month, uDT.Year);
993cdf0e10cSrcweir                 Time bT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
994cdf0e10cSrcweir                 DateTime bDate(bD,bT);
995cdf0e10cSrcweir                 aDate = bDate;
996cdf0e10cSrcweir 			}
997cdf0e10cSrcweir 			else
998cdf0e10cSrcweir 				break;
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir 			if (aDate.IsValid())
1001cdf0e10cSrcweir 			{
1002cdf0e10cSrcweir 				switch (nExtSub & ~DI_SUB_FIXED)
1003cdf0e10cSrcweir 				{
1004cdf0e10cSrcweir 				case DI_SUB_AUTHOR:
1005cdf0e10cSrcweir 					aStr = aName;
1006cdf0e10cSrcweir 					break;
1007cdf0e10cSrcweir 
1008cdf0e10cSrcweir 				case DI_SUB_TIME:
1009cdf0e10cSrcweir 					if (!nFormat)
1010cdf0e10cSrcweir 					{
1011cdf0e10cSrcweir 						lcl_GetLocalDataWrapper( nLang, &pAppLocalData,
1012cdf0e10cSrcweir 														&pLocalData );
1013cdf0e10cSrcweir 						aStr = pLocalData->getTime( aDate,
1014cdf0e10cSrcweir 													sal_False, sal_False);
1015cdf0e10cSrcweir 					}
1016cdf0e10cSrcweir 					else
1017cdf0e10cSrcweir 					{
1018cdf0e10cSrcweir 						// Numberformatter anwerfen!
1019cdf0e10cSrcweir 						double fVal = SwDateTimeField::GetDateTime( GetDoc(),
1020cdf0e10cSrcweir                                                     aDate);
1021cdf0e10cSrcweir 						aStr = ExpandValue(fVal, nFormat, nLang);
1022cdf0e10cSrcweir 					}
1023cdf0e10cSrcweir 					break;
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir 				case DI_SUB_DATE:
1026cdf0e10cSrcweir 					if (!nFormat)
1027cdf0e10cSrcweir 					{
1028cdf0e10cSrcweir 						lcl_GetLocalDataWrapper( nLang, &pAppLocalData,
1029cdf0e10cSrcweir 												 &pLocalData );
1030cdf0e10cSrcweir 						aStr = pLocalData->getDate( aDate );
1031cdf0e10cSrcweir 					}
1032cdf0e10cSrcweir 					else
1033cdf0e10cSrcweir 					{
1034cdf0e10cSrcweir 						// Numberformatter anwerfen!
1035cdf0e10cSrcweir 						double fVal = SwDateTimeField::GetDateTime( GetDoc(),
1036cdf0e10cSrcweir                                                     aDate);
1037cdf0e10cSrcweir 						aStr = ExpandValue(fVal, nFormat, nLang);
1038cdf0e10cSrcweir 					}
1039cdf0e10cSrcweir 					break;
1040cdf0e10cSrcweir 				}
1041cdf0e10cSrcweir 			}
1042cdf0e10cSrcweir 		}
1043cdf0e10cSrcweir 		break;
1044cdf0e10cSrcweir 	}
1045cdf0e10cSrcweir 
1046cdf0e10cSrcweir 	if( pAppLocalData != pLocalData )
1047cdf0e10cSrcweir 		delete pLocalData;
1048cdf0e10cSrcweir 
1049cdf0e10cSrcweir 	return aStr;
1050cdf0e10cSrcweir }
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir // ---------------------------------------------------------------------------
SwDocInfoField(SwDocInfoFieldType * pTyp,sal_uInt16 nSub,const String & rName,sal_uInt32 nFmt)1053cdf0e10cSrcweir SwDocInfoField::SwDocInfoField(SwDocInfoFieldType* pTyp, sal_uInt16 nSub, const String& rName, sal_uInt32 nFmt) :
1054cdf0e10cSrcweir 	SwValueField(pTyp, nFmt), nSubType(nSub)
1055cdf0e10cSrcweir {
1056cdf0e10cSrcweir 	aName = rName;
1057cdf0e10cSrcweir 	aContent = ((SwDocInfoFieldType*)GetTyp())->Expand(nSubType, nFmt, GetLanguage(), aName);
1058cdf0e10cSrcweir }
1059cdf0e10cSrcweir 
SwDocInfoField(SwDocInfoFieldType * pTyp,sal_uInt16 nSub,const String & rName,const String & rValue,sal_uInt32 nFmt)1060cdf0e10cSrcweir SwDocInfoField::SwDocInfoField(SwDocInfoFieldType* pTyp, sal_uInt16 nSub, const String& rName, const String& rValue, sal_uInt32 nFmt) :
1061cdf0e10cSrcweir     SwValueField(pTyp, nFmt), nSubType(nSub)
1062cdf0e10cSrcweir {
1063cdf0e10cSrcweir     aName = rName;
1064cdf0e10cSrcweir     aContent = rValue;
1065cdf0e10cSrcweir }
1066cdf0e10cSrcweir 
1067cdf0e10cSrcweir // ---------------------------------------------------------------------------
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir template<class T>
lcl_TimeToDouble(const T & rTime)1070cdf0e10cSrcweir double lcl_TimeToDouble( const T& rTime )
1071cdf0e10cSrcweir {
1072cdf0e10cSrcweir     const double fMilliSecondsPerDay = 86400000.0;
1073cdf0e10cSrcweir     return ((rTime.Hours*3600000)+(rTime.Minutes*60000)+(rTime.Seconds*1000)+(rTime.HundredthSeconds*10)) / fMilliSecondsPerDay;
1074cdf0e10cSrcweir }
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir template<class D>
lcl_DateToDouble(const D & rDate,const Date & rNullDate)1077cdf0e10cSrcweir double lcl_DateToDouble( const D& rDate, const Date& rNullDate )
1078cdf0e10cSrcweir {
1079cdf0e10cSrcweir     long nDate = Date::DateToDays( rDate.Day, rDate.Month, rDate.Year );
1080cdf0e10cSrcweir     long nNullDate = Date::DateToDays( rNullDate.GetDay(), rNullDate.GetMonth(), rNullDate.GetYear() );
1081cdf0e10cSrcweir     return double( nDate - nNullDate );
1082cdf0e10cSrcweir }
1083cdf0e10cSrcweir 
Expand() const1084cdf0e10cSrcweir String SwDocInfoField::Expand() const
1085cdf0e10cSrcweir {
1086cdf0e10cSrcweir     if ( ( nSubType & 0xFF ) == DI_CUSTOM )
1087cdf0e10cSrcweir     {
1088cdf0e10cSrcweir          // custom properties currently need special treatment
1089cdf0e10cSrcweir          // we don't have a secure way to detect "real" custom properties in Word  Import of text fields
1090cdf0e10cSrcweir         // so we treat *every* unknown property as a custom property, even the "built-in" section in Word's document summary information stream
1091cdf0e10cSrcweir         // as these properties have not been inserted when the document summary information was imported, we do it here
1092cdf0e10cSrcweir         // this approach is still a lot better than the old one to import such fields as "user fields" and simple text
1093cdf0e10cSrcweir         SwDocShell* pDocShell = GetDoc()->GetDocShell();
1094cdf0e10cSrcweir         if( !pDocShell )
1095cdf0e10cSrcweir             return aContent;
1096cdf0e10cSrcweir         try
1097cdf0e10cSrcweir         {
1098cdf0e10cSrcweir             uno::Reference<document::XDocumentPropertiesSupplier> xDPS( pDocShell->GetModel(), uno::UNO_QUERY_THROW);
1099cdf0e10cSrcweir             uno::Reference<document::XDocumentProperties> xDocProps( xDPS->getDocumentProperties());
1100cdf0e10cSrcweir             uno::Reference < beans::XPropertySet > xSet( xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
1101cdf0e10cSrcweir             uno::Reference < beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo();
1102cdf0e10cSrcweir 
1103cdf0e10cSrcweir             uno::Any aAny;
1104cdf0e10cSrcweir             if( xSetInfo->hasPropertyByName( aName ) )
1105cdf0e10cSrcweir                 aAny = xSet->getPropertyValue( aName );
1106cdf0e10cSrcweir             if ( aAny.getValueType() != ::getVoidCppuType() )
1107cdf0e10cSrcweir             {
1108cdf0e10cSrcweir                 // "void" type means that the property has not been inserted until now
1109cdf0e10cSrcweir                 if ( !IsFixed() )
1110cdf0e10cSrcweir                 {
1111cdf0e10cSrcweir                     // if the field is "fixed" we don't update it from the property
1112cdf0e10cSrcweir                     ::rtl::OUString sVal;
1113cdf0e10cSrcweir                     uno::Reference < script::XTypeConverter > xConverter( comphelper::getProcessServiceFactory()
1114cdf0e10cSrcweir                         ->createInstance(::rtl::OUString::createFromAscii("com.sun.star.script.Converter")), uno::UNO_QUERY );
1115cdf0e10cSrcweir                     util::Date aDate;
1116cdf0e10cSrcweir                     util::DateTime aDateTime;
1117cdf0e10cSrcweir                     util::Duration aDuration;
1118cdf0e10cSrcweir                     if( aAny >>= aDate)
1119cdf0e10cSrcweir                     {
1120cdf0e10cSrcweir                         SvNumberFormatter* pFormatter = pDocShell->GetDoc()->GetNumberFormatter();
1121cdf0e10cSrcweir                         Date* pNullDate = pFormatter->GetNullDate();
1122cdf0e10cSrcweir                         sVal = ExpandValue( lcl_DateToDouble<util::Date>( aDate, *pNullDate ), GetFormat(), GetLanguage());
1123cdf0e10cSrcweir                     }
1124cdf0e10cSrcweir                     else if( aAny >>= aDateTime )
1125cdf0e10cSrcweir                     {
1126cdf0e10cSrcweir                         double fDateTime = lcl_TimeToDouble<util::DateTime>( aDateTime );
1127cdf0e10cSrcweir                         SvNumberFormatter* pFormatter = pDocShell->GetDoc()->GetNumberFormatter();
1128cdf0e10cSrcweir                         Date* pNullDate = pFormatter->GetNullDate();
1129cdf0e10cSrcweir                         fDateTime += lcl_DateToDouble<util::DateTime>( aDateTime, *pNullDate );
1130cdf0e10cSrcweir                         sVal = ExpandValue( fDateTime, GetFormat(), GetLanguage());
1131cdf0e10cSrcweir                     }
1132cdf0e10cSrcweir                     else if( aAny >>= aDuration )
1133cdf0e10cSrcweir                     {
1134cdf0e10cSrcweir                         String sText(aDuration.Negative ? '-' : '+');
1135cdf0e10cSrcweir                         sText += ViewShell::GetShellRes()->sDurationFormat;
1136cdf0e10cSrcweir                         sText.SearchAndReplace(String::CreateFromAscii( "%1"), String::CreateFromInt32( aDuration.Years ) );
1137cdf0e10cSrcweir                         sText.SearchAndReplace(String::CreateFromAscii( "%2"), String::CreateFromInt32( aDuration.Months ) );
1138cdf0e10cSrcweir                         sText.SearchAndReplace(String::CreateFromAscii( "%3"), String::CreateFromInt32( aDuration.Days   ) );
1139cdf0e10cSrcweir                         sText.SearchAndReplace(String::CreateFromAscii( "%4"), String::CreateFromInt32( aDuration.Hours  ) );
1140cdf0e10cSrcweir                         sText.SearchAndReplace(String::CreateFromAscii( "%5"), String::CreateFromInt32( aDuration.Minutes) );
1141cdf0e10cSrcweir                         sText.SearchAndReplace(String::CreateFromAscii( "%6"), String::CreateFromInt32( aDuration.Seconds) );
1142cdf0e10cSrcweir                         sVal = sText;
1143cdf0e10cSrcweir                     }
1144cdf0e10cSrcweir                     else
1145cdf0e10cSrcweir                     {
1146cdf0e10cSrcweir                         uno::Any aNew = xConverter->convertToSimpleType( aAny, uno::TypeClass_STRING );
1147cdf0e10cSrcweir                         aNew >>= sVal;
1148cdf0e10cSrcweir                     }
1149cdf0e10cSrcweir                     ((SwDocInfoField*)this)->aContent = sVal;
1150cdf0e10cSrcweir                 }
1151cdf0e10cSrcweir             }
1152cdf0e10cSrcweir         }
1153cdf0e10cSrcweir         catch (uno::Exception&) {}
1154cdf0e10cSrcweir     }
1155cdf0e10cSrcweir     else if ( !IsFixed() )
1156cdf0e10cSrcweir 		((SwDocInfoField*)this)->aContent = ((SwDocInfoFieldType*)GetTyp())->Expand(nSubType, GetFormat(), GetLanguage(), aName);
1157cdf0e10cSrcweir 
1158cdf0e10cSrcweir 	return aContent;
1159cdf0e10cSrcweir }
1160cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
GetFieldName() const1163cdf0e10cSrcweir String SwDocInfoField::GetFieldName() const
1164cdf0e10cSrcweir {
1165cdf0e10cSrcweir     String aStr(SwFieldType::GetTypeStr(GetTypeId()));
1166cdf0e10cSrcweir     aStr += ':';
1167cdf0e10cSrcweir 
1168cdf0e10cSrcweir     sal_uInt16 const nSub = nSubType & 0xff;
1169cdf0e10cSrcweir 
1170cdf0e10cSrcweir     switch (nSub)
1171cdf0e10cSrcweir     {
1172cdf0e10cSrcweir         case DI_CUSTOM:
1173cdf0e10cSrcweir             aStr += aName;
1174cdf0e10cSrcweir             break;
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir         default:
1177cdf0e10cSrcweir             aStr += *ViewShell::GetShellRes()
1178cdf0e10cSrcweir                         ->aDocInfoLst[ nSub - DI_SUBTYPE_BEGIN ];
1179cdf0e10cSrcweir             break;
1180cdf0e10cSrcweir     }
1181cdf0e10cSrcweir     if (IsFixed())
1182cdf0e10cSrcweir     {
1183cdf0e10cSrcweir         aStr += ' ';
1184cdf0e10cSrcweir         aStr += ViewShell::GetShellRes()->aFixedStr;
1185cdf0e10cSrcweir     }
1186cdf0e10cSrcweir     return aStr;
1187cdf0e10cSrcweir }
1188cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1189cdf0e10cSrcweir 
1190cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Copy() const1191cdf0e10cSrcweir SwField* SwDocInfoField::Copy() const
1192cdf0e10cSrcweir {
1193cdf0e10cSrcweir 	SwDocInfoField* pFld = new SwDocInfoField((SwDocInfoFieldType*)GetTyp(), nSubType, aName, GetFormat());
1194cdf0e10cSrcweir     pFld->SetAutomaticLanguage(IsAutomaticLanguage());
1195cdf0e10cSrcweir 	pFld->aContent = aContent;
1196cdf0e10cSrcweir 
1197cdf0e10cSrcweir 	return pFld;
1198cdf0e10cSrcweir }
1199cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1200cdf0e10cSrcweir 
1201cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
GetSubType() const1202cdf0e10cSrcweir sal_uInt16 SwDocInfoField::GetSubType() const
1203cdf0e10cSrcweir {
1204cdf0e10cSrcweir 	return nSubType;
1205cdf0e10cSrcweir }
1206cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1207cdf0e10cSrcweir 
1208cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SetSubType(sal_uInt16 nSub)1209cdf0e10cSrcweir void SwDocInfoField::SetSubType(sal_uInt16 nSub)
1210cdf0e10cSrcweir {
1211cdf0e10cSrcweir 	nSubType = nSub;
1212cdf0e10cSrcweir }
1213cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1214cdf0e10cSrcweir 
1215cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SetLanguage(sal_uInt16 nLng)1216cdf0e10cSrcweir void SwDocInfoField::SetLanguage(sal_uInt16 nLng)
1217cdf0e10cSrcweir {
1218cdf0e10cSrcweir 	if (!GetFormat())
1219cdf0e10cSrcweir 		SwField::SetLanguage(nLng);
1220cdf0e10cSrcweir 	else
1221cdf0e10cSrcweir 		SwValueField::SetLanguage(nLng);
1222cdf0e10cSrcweir }
1223cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1224cdf0e10cSrcweir 
1225cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const1226cdf0e10cSrcweir sal_Bool SwDocInfoField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
1227cdf0e10cSrcweir {
1228cdf0e10cSrcweir     switch( nWhichId )
1229cdf0e10cSrcweir 	{
1230cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
1231cdf0e10cSrcweir 		rAny <<= OUString(aContent);
1232cdf0e10cSrcweir 		break;
1233cdf0e10cSrcweir 
1234cdf0e10cSrcweir 	case FIELD_PROP_PAR4:
1235cdf0e10cSrcweir 		rAny <<= OUString(aName);
1236cdf0e10cSrcweir 		break;
1237cdf0e10cSrcweir 
1238cdf0e10cSrcweir 	case FIELD_PROP_USHORT1:
1239cdf0e10cSrcweir 		rAny  <<= (sal_Int16)aContent.ToInt32();
1240cdf0e10cSrcweir 		break;
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir 	case FIELD_PROP_BOOL1:
1243cdf0e10cSrcweir 		{
1244cdf0e10cSrcweir 			sal_Bool bVal = 0 != (nSubType & DI_SUB_FIXED);
1245cdf0e10cSrcweir 			rAny.setValue(&bVal, ::getBooleanCppuType());
1246cdf0e10cSrcweir 		}
1247cdf0e10cSrcweir 		break;
1248cdf0e10cSrcweir 	case FIELD_PROP_FORMAT:
1249cdf0e10cSrcweir 		rAny  <<= (sal_Int32)GetFormat();
1250cdf0e10cSrcweir 		break;
1251cdf0e10cSrcweir 
1252cdf0e10cSrcweir 	case FIELD_PROP_DOUBLE:
1253cdf0e10cSrcweir 		{
1254cdf0e10cSrcweir 			double fVal = GetValue();
1255cdf0e10cSrcweir 			rAny.setValue(&fVal, ::getCppuType(&fVal));
1256cdf0e10cSrcweir 		}
1257cdf0e10cSrcweir 		break;
1258cdf0e10cSrcweir 	case FIELD_PROP_PAR3:
1259cdf0e10cSrcweir 		rAny <<= rtl::OUString(Expand());
1260cdf0e10cSrcweir 		break;
1261cdf0e10cSrcweir 	case FIELD_PROP_BOOL2:
1262cdf0e10cSrcweir 		{
1263cdf0e10cSrcweir 			sal_uInt16 nExtSub = (nSubType & 0xff00) & ~DI_SUB_FIXED;
1264cdf0e10cSrcweir 			sal_Bool bVal = (nExtSub == DI_SUB_DATE);
1265cdf0e10cSrcweir 			rAny.setValue(&bVal, ::getBooleanCppuType());
1266cdf0e10cSrcweir 		}
1267cdf0e10cSrcweir 		break;
1268cdf0e10cSrcweir 	default:
1269cdf0e10cSrcweir         return SwField::QueryValue(rAny, nWhichId);
1270cdf0e10cSrcweir     }
1271cdf0e10cSrcweir 	return sal_True;
1272cdf0e10cSrcweir }
1273cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1274cdf0e10cSrcweir 
1275cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)1276cdf0e10cSrcweir sal_Bool SwDocInfoField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
1277cdf0e10cSrcweir {
1278cdf0e10cSrcweir 	sal_Int32 nValue = 0;
1279cdf0e10cSrcweir     switch( nWhichId )
1280cdf0e10cSrcweir 	{
1281cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
1282cdf0e10cSrcweir 		if( nSubType & DI_SUB_FIXED )
1283cdf0e10cSrcweir 			::GetString( rAny, aContent );
1284cdf0e10cSrcweir 		break;
1285cdf0e10cSrcweir 
1286cdf0e10cSrcweir 	case FIELD_PROP_USHORT1:
1287cdf0e10cSrcweir 		if( nSubType & DI_SUB_FIXED )
1288cdf0e10cSrcweir 		{
1289cdf0e10cSrcweir 			rAny >>= nValue;
1290cdf0e10cSrcweir 			aContent = String::CreateFromInt32(nValue);
1291cdf0e10cSrcweir 		}
1292cdf0e10cSrcweir 		break;
1293cdf0e10cSrcweir 
1294cdf0e10cSrcweir 	case FIELD_PROP_BOOL1:
1295cdf0e10cSrcweir 		if(*(sal_Bool*)rAny.getValue())
1296cdf0e10cSrcweir 			nSubType |= DI_SUB_FIXED;
1297cdf0e10cSrcweir 		else
1298cdf0e10cSrcweir 			nSubType &= ~DI_SUB_FIXED;
1299cdf0e10cSrcweir 		break;
1300cdf0e10cSrcweir 	case FIELD_PROP_FORMAT:
1301cdf0e10cSrcweir 		{
1302cdf0e10cSrcweir 			rAny >>= nValue;
1303cdf0e10cSrcweir 			if( nValue >= 0)
1304cdf0e10cSrcweir 				SetFormat(nValue);
1305cdf0e10cSrcweir 		}
1306cdf0e10cSrcweir 		break;
1307cdf0e10cSrcweir 
1308cdf0e10cSrcweir 	case FIELD_PROP_PAR3:
1309cdf0e10cSrcweir 		::GetString( rAny, aContent );
1310cdf0e10cSrcweir 		break;
1311cdf0e10cSrcweir 	case FIELD_PROP_BOOL2:
1312cdf0e10cSrcweir 		nSubType &= 0xf0ff;
1313cdf0e10cSrcweir 		if(*(sal_Bool*)rAny.getValue())
1314cdf0e10cSrcweir 			nSubType |= DI_SUB_DATE;
1315cdf0e10cSrcweir 		else
1316cdf0e10cSrcweir 			nSubType |= DI_SUB_TIME;
1317cdf0e10cSrcweir 		break;
1318cdf0e10cSrcweir 	default:
1319cdf0e10cSrcweir         return SwField::PutValue(rAny, nWhichId);
1320cdf0e10cSrcweir     }
1321cdf0e10cSrcweir 	return sal_True;
1322cdf0e10cSrcweir }
1323cdf0e10cSrcweir 
1324cdf0e10cSrcweir /*--------------------------------------------------------------------
1325cdf0e10cSrcweir 	Beschreibung: SwHiddenTxtFieldType by JP
1326cdf0e10cSrcweir  --------------------------------------------------------------------*/
1327cdf0e10cSrcweir 
SwHiddenTxtFieldType(sal_Bool bSetHidden)1328cdf0e10cSrcweir SwHiddenTxtFieldType::SwHiddenTxtFieldType( sal_Bool bSetHidden )
1329cdf0e10cSrcweir 	: SwFieldType( RES_HIDDENTXTFLD ), bHidden( bSetHidden )
1330cdf0e10cSrcweir {
1331cdf0e10cSrcweir }
1332cdf0e10cSrcweir 
Copy() const1333cdf0e10cSrcweir SwFieldType* SwHiddenTxtFieldType::Copy() const
1334cdf0e10cSrcweir {
1335cdf0e10cSrcweir 	return new SwHiddenTxtFieldType( bHidden );
1336cdf0e10cSrcweir }
1337cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1338cdf0e10cSrcweir 
1339cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SetHiddenFlag(sal_Bool bSetHidden)1340cdf0e10cSrcweir void SwHiddenTxtFieldType::SetHiddenFlag( sal_Bool bSetHidden )
1341cdf0e10cSrcweir {
1342cdf0e10cSrcweir 	if( bHidden != bSetHidden )
1343cdf0e10cSrcweir 	{
1344cdf0e10cSrcweir 		bHidden = bSetHidden;
1345cdf0e10cSrcweir 		UpdateFlds();		// alle HiddenText benachrichtigen
1346cdf0e10cSrcweir 	}
1347cdf0e10cSrcweir }
1348cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1349cdf0e10cSrcweir 
1350cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SwHiddenTxtField(SwHiddenTxtFieldType * pFldType,sal_Bool bConditional,const String & rCond,const String & rStr,sal_Bool bHidden,sal_uInt16 nSub)1351cdf0e10cSrcweir SwHiddenTxtField::SwHiddenTxtField( SwHiddenTxtFieldType* pFldType,
1352cdf0e10cSrcweir 									sal_Bool 	bConditional,
1353cdf0e10cSrcweir 									const 	String& rCond,
1354cdf0e10cSrcweir 									const	String& rStr,
1355cdf0e10cSrcweir 									sal_Bool 	bHidden,
1356cdf0e10cSrcweir 									sal_uInt16  nSub) :
1357cdf0e10cSrcweir 	SwField( pFldType ), aCond(rCond), nSubType(nSub),
1358cdf0e10cSrcweir 	bCanToggle(bConditional), bIsHidden(bHidden), bValid(sal_False)
1359cdf0e10cSrcweir {
1360cdf0e10cSrcweir 	if(nSubType == TYP_CONDTXTFLD)
1361cdf0e10cSrcweir 	{
1362cdf0e10cSrcweir 		sal_uInt16 nPos = 0;
1363cdf0e10cSrcweir 		aTRUETxt = rStr.GetToken(0, '|', nPos);
1364cdf0e10cSrcweir 
1365cdf0e10cSrcweir 		if(nPos != STRING_NOTFOUND)
1366cdf0e10cSrcweir 		{
1367cdf0e10cSrcweir 			aFALSETxt = rStr.GetToken(0, '|', nPos);
1368cdf0e10cSrcweir 			if(nPos != STRING_NOTFOUND)
1369cdf0e10cSrcweir 			{
1370cdf0e10cSrcweir 				aContent = rStr.GetToken(0, '|', nPos);
1371cdf0e10cSrcweir 				bValid = sal_True;
1372cdf0e10cSrcweir 			}
1373cdf0e10cSrcweir 		}
1374cdf0e10cSrcweir 	}
1375cdf0e10cSrcweir 	else
1376cdf0e10cSrcweir 		aTRUETxt = rStr;
1377cdf0e10cSrcweir }
1378cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1379cdf0e10cSrcweir 
1380cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SwHiddenTxtField(SwHiddenTxtFieldType * pFldType,const String & rCond,const String & rTrue,const String & rFalse,sal_uInt16 nSub)1381cdf0e10cSrcweir SwHiddenTxtField::SwHiddenTxtField( SwHiddenTxtFieldType* pFldType,
1382cdf0e10cSrcweir 									const String& rCond,
1383cdf0e10cSrcweir 									const String& rTrue,
1384cdf0e10cSrcweir 									const String& rFalse,
1385cdf0e10cSrcweir 									sal_uInt16 nSub)
1386cdf0e10cSrcweir 	: SwField( pFldType ), aTRUETxt(rTrue), aFALSETxt(rFalse), aCond(rCond), nSubType(nSub),
1387cdf0e10cSrcweir 	  bIsHidden(sal_True), bValid(sal_False)
1388cdf0e10cSrcweir {
1389cdf0e10cSrcweir 	bCanToggle	= aCond.Len() > 0;
1390cdf0e10cSrcweir }
1391cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1392cdf0e10cSrcweir 
1393cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Expand() const1394cdf0e10cSrcweir String SwHiddenTxtField::Expand() const
1395cdf0e10cSrcweir {
1396cdf0e10cSrcweir 	// Type: !Hidden  -> immer anzeigen
1397cdf0e10cSrcweir 	// 		  Hide	  -> Werte die Bedingung aus
1398cdf0e10cSrcweir 
1399cdf0e10cSrcweir 	if( TYP_CONDTXTFLD == nSubType )
1400cdf0e10cSrcweir 	{
1401cdf0e10cSrcweir 		if( bValid )
1402cdf0e10cSrcweir 			return aContent;
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir 		if( bCanToggle && !bIsHidden )
1405cdf0e10cSrcweir 			return aTRUETxt;
1406cdf0e10cSrcweir 	}
1407cdf0e10cSrcweir 	else if( !((SwHiddenTxtFieldType*)GetTyp())->GetHiddenFlag() ||
1408cdf0e10cSrcweir 		( bCanToggle && bIsHidden ))
1409cdf0e10cSrcweir 		return aTRUETxt;
1410cdf0e10cSrcweir 
1411cdf0e10cSrcweir 	return aFALSETxt;
1412cdf0e10cSrcweir }
1413cdf0e10cSrcweir 
1414cdf0e10cSrcweir /*--------------------------------------------------------------------
1415cdf0e10cSrcweir 	Beschreibung: Aktuellen Field-Value holen und cachen
1416cdf0e10cSrcweir  --------------------------------------------------------------------*/
1417cdf0e10cSrcweir 
Evaluate(SwDoc * pDoc)1418cdf0e10cSrcweir void SwHiddenTxtField::Evaluate(SwDoc* pDoc)
1419cdf0e10cSrcweir {
1420cdf0e10cSrcweir 	ASSERT(pDoc, Wo ist das Dokument Seniore);
1421cdf0e10cSrcweir 
1422cdf0e10cSrcweir 	if( TYP_CONDTXTFLD == nSubType )
1423cdf0e10cSrcweir 	{
1424cdf0e10cSrcweir 		SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
1425cdf0e10cSrcweir 
1426cdf0e10cSrcweir 		bValid = sal_False;
1427cdf0e10cSrcweir 		String sTmpName;
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir 		if (bCanToggle && !bIsHidden)
1430cdf0e10cSrcweir 			sTmpName = aTRUETxt;
1431cdf0e10cSrcweir 		else
1432cdf0e10cSrcweir 			sTmpName = aFALSETxt;
1433cdf0e10cSrcweir 
1434cdf0e10cSrcweir // OS 21.08.97: #42943# Datenbankausdruecke muessen sich von
1435cdf0e10cSrcweir // 				einfachem Text unterscheiden. also wird der einfache Text
1436cdf0e10cSrcweir // 				bevorzugt in Anfuehrungszeichen gesetzt.
1437cdf0e10cSrcweir // 				Sind diese vorhanden werden umschliessende entfernt.
1438cdf0e10cSrcweir //				Wenn nicht, dann wird auf die Tauglichkeit als Datenbankname
1439cdf0e10cSrcweir //				geprueft. Nur wenn zwei oder mehr Punkte vorhanden sind und kein
1440cdf0e10cSrcweir //				Anfuehrungszeichen enthalten ist, gehen wir von einer DB aus.
1441cdf0e10cSrcweir 		if(sTmpName.Len() > 1 && sTmpName.GetChar(0) == '\"' &&
1442cdf0e10cSrcweir 			sTmpName.GetChar((sTmpName.Len() - 1))== '\"')
1443cdf0e10cSrcweir 		{
1444cdf0e10cSrcweir 			aContent = sTmpName.Copy(1, sTmpName.Len() - 2);
1445cdf0e10cSrcweir 			bValid = sal_True;
1446cdf0e10cSrcweir 		}
1447cdf0e10cSrcweir 		else if(sTmpName.Search('\"') == STRING_NOTFOUND &&
1448cdf0e10cSrcweir 			sTmpName.GetTokenCount('.') > 2)
1449cdf0e10cSrcweir 		{
1450cdf0e10cSrcweir 			::ReplacePoint(sTmpName);
1451cdf0e10cSrcweir 			if(sTmpName.GetChar(0) == '[' && sTmpName.GetChar(sTmpName.Len()-1) == ']')
1452cdf0e10cSrcweir 			{	// Eckige Klammern entfernen
1453cdf0e10cSrcweir 				sTmpName.Erase(0, 1);
1454cdf0e10cSrcweir 				sTmpName.Erase(sTmpName.Len()-1, 1);
1455cdf0e10cSrcweir 			}
1456cdf0e10cSrcweir 
1457cdf0e10cSrcweir 			if( pMgr)
1458cdf0e10cSrcweir 			{
1459cdf0e10cSrcweir 				String sDBName( GetDBName( sTmpName, pDoc ));
1460cdf0e10cSrcweir 				String sDataSource(sDBName.GetToken(0, DB_DELIM));
1461cdf0e10cSrcweir 				String sDataTableOrQuery(sDBName.GetToken(1, DB_DELIM));
1462cdf0e10cSrcweir 				if( pMgr->IsInMerge() && sDBName.Len() &&
1463cdf0e10cSrcweir 					pMgr->IsDataSourceOpen( sDataSource,
1464cdf0e10cSrcweir 												sDataTableOrQuery, sal_False))
1465cdf0e10cSrcweir 				{
1466cdf0e10cSrcweir 					double fNumber;
1467cdf0e10cSrcweir 					sal_uInt32 nTmpFormat;
1468cdf0e10cSrcweir 					pMgr->GetMergeColumnCnt(GetColumnName( sTmpName ),
1469cdf0e10cSrcweir                         GetLanguage(), aContent, &fNumber, &nTmpFormat );
1470cdf0e10cSrcweir 					bValid = sal_True;
1471cdf0e10cSrcweir 				}
1472cdf0e10cSrcweir 				else if( sDBName.Len() && sDataSource.Len() &&
1473cdf0e10cSrcweir 						 sDataTableOrQuery.Len() )
1474cdf0e10cSrcweir 					bValid = sal_True;
1475cdf0e10cSrcweir 			}
1476cdf0e10cSrcweir 		}
1477cdf0e10cSrcweir 	}
1478cdf0e10cSrcweir }
1479cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1480cdf0e10cSrcweir 
1481cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
GetFieldName() const1482cdf0e10cSrcweir String SwHiddenTxtField::GetFieldName() const
1483cdf0e10cSrcweir {
1484cdf0e10cSrcweir     String aStr(SwFieldType::GetTypeStr(nSubType));
1485cdf0e10cSrcweir     aStr += ' ';
1486cdf0e10cSrcweir     aStr += aCond;
1487cdf0e10cSrcweir     aStr += ' ';
1488cdf0e10cSrcweir     aStr += aTRUETxt;
1489cdf0e10cSrcweir 
1490cdf0e10cSrcweir     if (nSubType == TYP_CONDTXTFLD)
1491cdf0e10cSrcweir     {
1492cdf0e10cSrcweir         aStr.AppendAscii(" : ");
1493cdf0e10cSrcweir         aStr += aFALSETxt;
1494cdf0e10cSrcweir     }
1495cdf0e10cSrcweir     return aStr;
1496cdf0e10cSrcweir }
1497cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1498cdf0e10cSrcweir 
1499cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Copy() const1500cdf0e10cSrcweir SwField* SwHiddenTxtField::Copy() const
1501cdf0e10cSrcweir {
1502cdf0e10cSrcweir 	SwHiddenTxtField* pFld =
1503cdf0e10cSrcweir 		new SwHiddenTxtField((SwHiddenTxtFieldType*)GetTyp(), aCond,
1504cdf0e10cSrcweir 							  aTRUETxt, aFALSETxt);
1505cdf0e10cSrcweir 	pFld->bIsHidden = bIsHidden;
1506cdf0e10cSrcweir 	pFld->bValid	= bValid;
1507cdf0e10cSrcweir 	pFld->aContent	= aContent;
1508cdf0e10cSrcweir 	pFld->SetFormat(GetFormat());
1509cdf0e10cSrcweir 	pFld->nSubType 	= nSubType;
1510cdf0e10cSrcweir 	return pFld;
1511cdf0e10cSrcweir }
1512cdf0e10cSrcweir 
1513cdf0e10cSrcweir 
1514cdf0e10cSrcweir /*--------------------------------------------------------------------
1515cdf0e10cSrcweir 	Beschreibung: Bedingung setzen
1516cdf0e10cSrcweir  --------------------------------------------------------------------*/
1517cdf0e10cSrcweir 
SetPar1(const String & rStr)1518cdf0e10cSrcweir void SwHiddenTxtField::SetPar1(const String& rStr)
1519cdf0e10cSrcweir {
1520cdf0e10cSrcweir 	aCond = rStr;
1521cdf0e10cSrcweir 	bCanToggle = aCond.Len() > 0;
1522cdf0e10cSrcweir }
1523cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1524cdf0e10cSrcweir 
1525cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
GetPar1() const1526cdf0e10cSrcweir const String& SwHiddenTxtField::GetPar1() const
1527cdf0e10cSrcweir {
1528cdf0e10cSrcweir 	return aCond;
1529cdf0e10cSrcweir }
1530cdf0e10cSrcweir 
1531cdf0e10cSrcweir /*--------------------------------------------------------------------
1532cdf0e10cSrcweir 	Beschreibung: True/False Text
1533cdf0e10cSrcweir  --------------------------------------------------------------------*/
1534cdf0e10cSrcweir 
SetPar2(const String & rStr)1535cdf0e10cSrcweir void SwHiddenTxtField::SetPar2(const String& rStr)
1536cdf0e10cSrcweir {
1537cdf0e10cSrcweir 	if(nSubType == TYP_CONDTXTFLD)
1538cdf0e10cSrcweir 	{
1539cdf0e10cSrcweir 		sal_uInt16 nPos = rStr.Search('|');
1540cdf0e10cSrcweir 		aTRUETxt = rStr.Copy(0, nPos);
1541cdf0e10cSrcweir 
1542cdf0e10cSrcweir 		if(nPos != STRING_NOTFOUND)
1543cdf0e10cSrcweir 			aFALSETxt = rStr.Copy(nPos + 1);
1544cdf0e10cSrcweir 	}
1545cdf0e10cSrcweir 	else
1546cdf0e10cSrcweir 		aTRUETxt = rStr;
1547cdf0e10cSrcweir }
1548cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1549cdf0e10cSrcweir 
1550cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
GetPar2() const1551cdf0e10cSrcweir String SwHiddenTxtField::GetPar2() const
1552cdf0e10cSrcweir {
1553cdf0e10cSrcweir 	String aRet(aTRUETxt);
1554cdf0e10cSrcweir 	if(nSubType == TYP_CONDTXTFLD)
1555cdf0e10cSrcweir 	{
1556cdf0e10cSrcweir 		aRet += '|';
1557cdf0e10cSrcweir 		aRet += aFALSETxt;
1558cdf0e10cSrcweir 	}
1559cdf0e10cSrcweir 	return aRet;
1560cdf0e10cSrcweir }
1561cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1562cdf0e10cSrcweir 
1563cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
GetSubType() const1564cdf0e10cSrcweir sal_uInt16 SwHiddenTxtField::GetSubType() const
1565cdf0e10cSrcweir {
1566cdf0e10cSrcweir 	return nSubType;
1567cdf0e10cSrcweir }
1568cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1569cdf0e10cSrcweir 
1570cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const1571cdf0e10cSrcweir sal_Bool SwHiddenTxtField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
1572cdf0e10cSrcweir {
1573cdf0e10cSrcweir 	const String* pOut = 0;
1574cdf0e10cSrcweir     switch( nWhichId )
1575cdf0e10cSrcweir 	{
1576cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
1577cdf0e10cSrcweir 		pOut = &aCond;
1578cdf0e10cSrcweir 		break;
1579cdf0e10cSrcweir 	case FIELD_PROP_PAR2:
1580cdf0e10cSrcweir 		pOut = &aTRUETxt;
1581cdf0e10cSrcweir 		break;
1582cdf0e10cSrcweir 	case FIELD_PROP_PAR3:
1583cdf0e10cSrcweir 		pOut = &aFALSETxt;
1584cdf0e10cSrcweir 		break;
1585cdf0e10cSrcweir     case FIELD_PROP_PAR4 :
1586cdf0e10cSrcweir         pOut = &aContent;
1587cdf0e10cSrcweir     break;
1588cdf0e10cSrcweir     case FIELD_PROP_BOOL1:
1589cdf0e10cSrcweir 		{
1590cdf0e10cSrcweir         	sal_Bool bHidden = bIsHidden;
1591cdf0e10cSrcweir         	rAny.setValue(&bHidden, ::getBooleanCppuType());
1592cdf0e10cSrcweir 		}
1593cdf0e10cSrcweir 		break;
1594cdf0e10cSrcweir 	default:
1595cdf0e10cSrcweir 		DBG_ERROR("illegal property");
1596cdf0e10cSrcweir 	}
1597cdf0e10cSrcweir 	if( pOut )
1598cdf0e10cSrcweir 		rAny <<= OUString( *pOut );
1599cdf0e10cSrcweir 	return sal_True;
1600cdf0e10cSrcweir }
1601cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1602cdf0e10cSrcweir 
1603cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)1604cdf0e10cSrcweir sal_Bool SwHiddenTxtField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
1605cdf0e10cSrcweir {
1606cdf0e10cSrcweir     switch( nWhichId )
1607cdf0e10cSrcweir 	{
1608cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
1609cdf0e10cSrcweir 		{
1610cdf0e10cSrcweir 			String sVal;
1611cdf0e10cSrcweir 			SetPar1(::GetString( rAny, sVal ));
1612cdf0e10cSrcweir 		}
1613cdf0e10cSrcweir 		break;
1614cdf0e10cSrcweir 	case FIELD_PROP_PAR2:
1615cdf0e10cSrcweir 		::GetString( rAny, aTRUETxt );
1616cdf0e10cSrcweir 		break;
1617cdf0e10cSrcweir 	case FIELD_PROP_PAR3:
1618cdf0e10cSrcweir 		::GetString( rAny, aFALSETxt );
1619cdf0e10cSrcweir 		break;
1620cdf0e10cSrcweir 	case FIELD_PROP_BOOL1:
1621cdf0e10cSrcweir         bIsHidden = *(sal_Bool*)rAny.getValue();
1622cdf0e10cSrcweir 		break;
1623cdf0e10cSrcweir     case FIELD_PROP_PAR4:
1624cdf0e10cSrcweir         ::GetString( rAny, aContent);
1625cdf0e10cSrcweir         bValid = sal_True;
1626cdf0e10cSrcweir     break;
1627cdf0e10cSrcweir     default:
1628cdf0e10cSrcweir 		DBG_ERROR("illegal property");
1629cdf0e10cSrcweir 	}
1630cdf0e10cSrcweir 	return sal_True;
1631cdf0e10cSrcweir }
1632cdf0e10cSrcweir 
1633cdf0e10cSrcweir //------------------------------------------------------------------------------
1634cdf0e10cSrcweir 
GetColumnName(const String & rName)1635cdf0e10cSrcweir String SwHiddenTxtField::GetColumnName(const String& rName)
1636cdf0e10cSrcweir {
1637cdf0e10cSrcweir 	sal_uInt16 nPos = rName.Search(DB_DELIM);
1638cdf0e10cSrcweir 	if( STRING_NOTFOUND != nPos )
1639cdf0e10cSrcweir 	{
1640cdf0e10cSrcweir 		nPos = rName.Search(DB_DELIM, nPos + 1);
1641cdf0e10cSrcweir 
1642cdf0e10cSrcweir 		if( STRING_NOTFOUND != nPos )
1643cdf0e10cSrcweir 			return rName.Copy(nPos + 1);
1644cdf0e10cSrcweir 	}
1645cdf0e10cSrcweir 	return rName;
1646cdf0e10cSrcweir }
1647cdf0e10cSrcweir 
1648cdf0e10cSrcweir //------------------------------------------------------------------------------
1649cdf0e10cSrcweir 
GetDBName(const String & rName,SwDoc * pDoc)1650cdf0e10cSrcweir String SwHiddenTxtField::GetDBName(const String& rName, SwDoc *pDoc)
1651cdf0e10cSrcweir {
1652cdf0e10cSrcweir 	sal_uInt16 nPos = rName.Search(DB_DELIM);
1653cdf0e10cSrcweir 	if( STRING_NOTFOUND != nPos )
1654cdf0e10cSrcweir 	{
1655cdf0e10cSrcweir 		nPos = rName.Search(DB_DELIM, nPos + 1);
1656cdf0e10cSrcweir 
1657cdf0e10cSrcweir 		if( STRING_NOTFOUND != nPos )
1658cdf0e10cSrcweir 			return rName.Copy( 0, nPos );
1659cdf0e10cSrcweir 	}
1660cdf0e10cSrcweir 	SwDBData aData = pDoc->GetDBData();
1661cdf0e10cSrcweir 	String sRet = aData.sDataSource;
1662cdf0e10cSrcweir 	sRet += DB_DELIM;
1663cdf0e10cSrcweir 	sRet += String(aData.sCommand);
1664cdf0e10cSrcweir 	return sRet;
1665cdf0e10cSrcweir }
1666cdf0e10cSrcweir 
1667cdf0e10cSrcweir /*--------------------------------------------------------------------
1668cdf0e10cSrcweir 	Beschreibung: Der Feldtyp fuer Zeilenhoehe 0
1669cdf0e10cSrcweir  --------------------------------------------------------------------*/
1670cdf0e10cSrcweir 
SwHiddenParaFieldType()1671cdf0e10cSrcweir SwHiddenParaFieldType::SwHiddenParaFieldType()
1672cdf0e10cSrcweir 	: SwFieldType( RES_HIDDENPARAFLD )
1673cdf0e10cSrcweir {
1674cdf0e10cSrcweir }
1675cdf0e10cSrcweir 
Copy() const1676cdf0e10cSrcweir SwFieldType* SwHiddenParaFieldType::Copy() const
1677cdf0e10cSrcweir {
1678cdf0e10cSrcweir 	SwHiddenParaFieldType* pTyp = new SwHiddenParaFieldType();
1679cdf0e10cSrcweir 	return pTyp;
1680cdf0e10cSrcweir }
1681cdf0e10cSrcweir 
1682cdf0e10cSrcweir /*--------------------------------------------------------------------
1683cdf0e10cSrcweir 	Beschreibung: Das Feld Zeilenhoehe 0
1684cdf0e10cSrcweir  --------------------------------------------------------------------*/
1685cdf0e10cSrcweir 
SwHiddenParaField(SwHiddenParaFieldType * pTyp,const String & rStr)1686cdf0e10cSrcweir SwHiddenParaField::SwHiddenParaField(SwHiddenParaFieldType* pTyp, const String& rStr)
1687cdf0e10cSrcweir 	: SwField(pTyp), aCond(rStr)
1688cdf0e10cSrcweir {
1689cdf0e10cSrcweir 	bIsHidden = sal_False;
1690cdf0e10cSrcweir }
1691cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1692cdf0e10cSrcweir 
1693cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Expand() const1694cdf0e10cSrcweir String SwHiddenParaField::Expand() const
1695cdf0e10cSrcweir {
1696cdf0e10cSrcweir 	return aEmptyStr;
1697cdf0e10cSrcweir }
1698cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1699cdf0e10cSrcweir 
1700cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Copy() const1701cdf0e10cSrcweir SwField* SwHiddenParaField::Copy() const
1702cdf0e10cSrcweir {
1703cdf0e10cSrcweir 	SwHiddenParaField* pFld = new SwHiddenParaField((SwHiddenParaFieldType*)GetTyp(), aCond);
1704cdf0e10cSrcweir 	pFld->bIsHidden = bIsHidden;
1705cdf0e10cSrcweir 
1706cdf0e10cSrcweir 	return pFld;
1707cdf0e10cSrcweir }
1708cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const1709cdf0e10cSrcweir sal_Bool SwHiddenParaField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
1710cdf0e10cSrcweir {
1711cdf0e10cSrcweir     switch ( nWhichId )
1712cdf0e10cSrcweir 	{
1713cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
1714cdf0e10cSrcweir 		rAny <<= OUString(aCond);
1715cdf0e10cSrcweir 		break;
1716cdf0e10cSrcweir 	case  FIELD_PROP_BOOL1:
1717cdf0e10cSrcweir 		{
1718cdf0e10cSrcweir         	sal_Bool bHidden = bIsHidden;
1719cdf0e10cSrcweir         	rAny.setValue(&bHidden, ::getBooleanCppuType());
1720cdf0e10cSrcweir 		}
1721cdf0e10cSrcweir 		break;
1722cdf0e10cSrcweir 
1723cdf0e10cSrcweir 	default:
1724cdf0e10cSrcweir 		DBG_ERROR("illegal property");
1725cdf0e10cSrcweir 	}
1726cdf0e10cSrcweir 	return sal_True;
1727cdf0e10cSrcweir }
1728cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)1729cdf0e10cSrcweir sal_Bool SwHiddenParaField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
1730cdf0e10cSrcweir {
1731cdf0e10cSrcweir     switch ( nWhichId )
1732cdf0e10cSrcweir 	{
1733cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
1734cdf0e10cSrcweir 		::GetString( rAny, aCond );
1735cdf0e10cSrcweir 		break;
1736cdf0e10cSrcweir 	case FIELD_PROP_BOOL1:
1737cdf0e10cSrcweir         bIsHidden = *(sal_Bool*)rAny.getValue();
1738cdf0e10cSrcweir 		break;
1739cdf0e10cSrcweir 
1740cdf0e10cSrcweir 	default:
1741cdf0e10cSrcweir 		DBG_ERROR("illegal property");
1742cdf0e10cSrcweir 	}
1743cdf0e10cSrcweir 	return sal_True;
1744cdf0e10cSrcweir }
1745cdf0e10cSrcweir 
1746cdf0e10cSrcweir /*--------------------------------------------------------------------
1747cdf0e10cSrcweir 	Beschreibung: Bedingung setzen
1748cdf0e10cSrcweir  --------------------------------------------------------------------*/
1749cdf0e10cSrcweir 
SetPar1(const String & rStr)1750cdf0e10cSrcweir void SwHiddenParaField::SetPar1(const String& rStr)
1751cdf0e10cSrcweir {
1752cdf0e10cSrcweir 	aCond = rStr;
1753cdf0e10cSrcweir }
1754cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1755cdf0e10cSrcweir 
1756cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
GetPar1() const1757cdf0e10cSrcweir const String& SwHiddenParaField::GetPar1() const
1758cdf0e10cSrcweir {
1759cdf0e10cSrcweir 	return aCond;
1760cdf0e10cSrcweir }
1761cdf0e10cSrcweir 
1762cdf0e10cSrcweir /*--------------------------------------------------------------------
1763cdf0e10cSrcweir 	Beschreibung: PostIt
1764cdf0e10cSrcweir  --------------------------------------------------------------------*/
1765cdf0e10cSrcweir 
SwPostItFieldType(SwDoc * pDoc)1766cdf0e10cSrcweir SwPostItFieldType::SwPostItFieldType(SwDoc *pDoc)
1767*dec99bbdSOliver-Rainer Wittmann     : SwFieldType( RES_POSTITFLD )
1768*dec99bbdSOliver-Rainer Wittmann     , mpDoc(pDoc)
1769cdf0e10cSrcweir {}
1770cdf0e10cSrcweir /* ---------------------------------------------------------------------------
1771cdf0e10cSrcweir 
1772cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Copy() const1773cdf0e10cSrcweir SwFieldType* SwPostItFieldType::Copy() const
1774cdf0e10cSrcweir {
1775*dec99bbdSOliver-Rainer Wittmann     return new SwPostItFieldType(mpDoc);
1776cdf0e10cSrcweir }
1777cdf0e10cSrcweir 
1778cdf0e10cSrcweir 
1779cdf0e10cSrcweir 
17803b32dd21SOliver-Rainer Wittmann 
SwPostItField(SwPostItFieldType * pT,const String & rCommentContent,const String & rAuthor,const String & rAuthorInitials,const String & rName,const DateTime & rDateTime)17813b32dd21SOliver-Rainer Wittmann SwPostItField::SwPostItField(
17823b32dd21SOliver-Rainer Wittmann     SwPostItFieldType* pT,
17833b32dd21SOliver-Rainer Wittmann     const String& rCommentContent,
17843b32dd21SOliver-Rainer Wittmann     const String& rAuthor,
17853b32dd21SOliver-Rainer Wittmann     const String& rAuthorInitials,
17863b32dd21SOliver-Rainer Wittmann     const String& rName,
17873b32dd21SOliver-Rainer Wittmann     const DateTime& rDateTime )
17883b32dd21SOliver-Rainer Wittmann     : SwField( pT )
17893b32dd21SOliver-Rainer Wittmann     , msCommentContent( rCommentContent )
17903b32dd21SOliver-Rainer Wittmann     , msAuthor( rAuthor )
17913b32dd21SOliver-Rainer Wittmann     , msAuthorInitials( rAuthorInitials )
17923b32dd21SOliver-Rainer Wittmann     , msName( rName )
17933b32dd21SOliver-Rainer Wittmann     , maDateTime( rDateTime )
1794*dec99bbdSOliver-Rainer Wittmann     , mpText( NULL )
1795*dec99bbdSOliver-Rainer Wittmann     , m_pTextObject( NULL )
1796cdf0e10cSrcweir {
1797cdf0e10cSrcweir }
1798cdf0e10cSrcweir 
1799cdf0e10cSrcweir 
~SwPostItField()1800cdf0e10cSrcweir SwPostItField::~SwPostItField()
1801cdf0e10cSrcweir {
1802*dec99bbdSOliver-Rainer Wittmann     if ( m_pTextObject != NULL )
18033b32dd21SOliver-Rainer Wittmann     {
18043b32dd21SOliver-Rainer Wittmann         m_pTextObject->DisposeEditSource();
18053b32dd21SOliver-Rainer Wittmann         m_pTextObject->release();
18063b32dd21SOliver-Rainer Wittmann     }
1807724ead07SJian Fang Zhang 
18083b32dd21SOliver-Rainer Wittmann     delete mpText;
1809cdf0e10cSrcweir }
1810cdf0e10cSrcweir 
1811cdf0e10cSrcweir 
Expand() const1812cdf0e10cSrcweir String SwPostItField::Expand() const
1813cdf0e10cSrcweir {
18143b32dd21SOliver-Rainer Wittmann     return aEmptyStr;
1815cdf0e10cSrcweir }
1816cdf0e10cSrcweir 
1817cdf0e10cSrcweir 
GetDescription() const1818cdf0e10cSrcweir String SwPostItField::GetDescription() const
1819cdf0e10cSrcweir {
1820cdf0e10cSrcweir     return SW_RES(STR_NOTE);
1821cdf0e10cSrcweir }
1822cdf0e10cSrcweir 
1823cdf0e10cSrcweir 
Copy() const1824cdf0e10cSrcweir SwField* SwPostItField::Copy() const
1825cdf0e10cSrcweir {
18263b32dd21SOliver-Rainer Wittmann     SwPostItField* pRet =
18273b32dd21SOliver-Rainer Wittmann         new SwPostItField(
18283b32dd21SOliver-Rainer Wittmann             (SwPostItFieldType*)GetTyp(),
18293b32dd21SOliver-Rainer Wittmann             msCommentContent,
18303b32dd21SOliver-Rainer Wittmann             msAuthor,
18313b32dd21SOliver-Rainer Wittmann             msAuthorInitials,
18323b32dd21SOliver-Rainer Wittmann             msName,
18333b32dd21SOliver-Rainer Wittmann             maDateTime);
18343b32dd21SOliver-Rainer Wittmann     if ( mpText != NULL )
18353b32dd21SOliver-Rainer Wittmann     {
18363b32dd21SOliver-Rainer Wittmann         pRet->SetTextObject( new OutlinerParaObject(*mpText) );
18373b32dd21SOliver-Rainer Wittmann     }
18383b32dd21SOliver-Rainer Wittmann 
1839*dec99bbdSOliver-Rainer Wittmann     // Note: member <m_pTextObject> not copied.
1840*dec99bbdSOliver-Rainer Wittmann 
18413b32dd21SOliver-Rainer Wittmann     return pRet;
1842cdf0e10cSrcweir }
18433b32dd21SOliver-Rainer Wittmann 
1844cdf0e10cSrcweir 
SetPar1(const String & rStr)1845cdf0e10cSrcweir void SwPostItField::SetPar1(const String& rStr)
1846cdf0e10cSrcweir {
18473b32dd21SOliver-Rainer Wittmann     msAuthor = rStr;
1848cdf0e10cSrcweir }
1849cdf0e10cSrcweir 
GetPar1() const1850cdf0e10cSrcweir const String& SwPostItField::GetPar1() const
1851cdf0e10cSrcweir {
18523b32dd21SOliver-Rainer Wittmann     return msAuthor;
1853cdf0e10cSrcweir }
1854cdf0e10cSrcweir 
1855cdf0e10cSrcweir 
SetPar2(const String & rStr)1856cdf0e10cSrcweir void SwPostItField::SetPar2(const String& rStr)
1857cdf0e10cSrcweir {
18583b32dd21SOliver-Rainer Wittmann     msCommentContent = rStr;
1859cdf0e10cSrcweir }
1860cdf0e10cSrcweir 
GetPar2() const1861cdf0e10cSrcweir String SwPostItField::GetPar2() const
1862cdf0e10cSrcweir {
18633b32dd21SOliver-Rainer Wittmann     return msCommentContent;
18643b32dd21SOliver-Rainer Wittmann }
18653b32dd21SOliver-Rainer Wittmann 
18663b32dd21SOliver-Rainer Wittmann 
SetName(const String & rName)18673b32dd21SOliver-Rainer Wittmann void SwPostItField::SetName(const String& rName)
18683b32dd21SOliver-Rainer Wittmann {
18693b32dd21SOliver-Rainer Wittmann     msName = rName;
1870cdf0e10cSrcweir }
1871cdf0e10cSrcweir 
GetName() const18723b32dd21SOliver-Rainer Wittmann const String& SwPostItField::GetName() const
18733b32dd21SOliver-Rainer Wittmann {
18743b32dd21SOliver-Rainer Wittmann     return msName;
18753b32dd21SOliver-Rainer Wittmann }
18763b32dd21SOliver-Rainer Wittmann 
18773b32dd21SOliver-Rainer Wittmann 
GetTextObject() const1878cdf0e10cSrcweir const OutlinerParaObject* SwPostItField::GetTextObject() const
1879cdf0e10cSrcweir {
18803b32dd21SOliver-Rainer Wittmann     return mpText;
1881cdf0e10cSrcweir }
1882cdf0e10cSrcweir 
SetTextObject(OutlinerParaObject * pText)1883cdf0e10cSrcweir void SwPostItField::SetTextObject( OutlinerParaObject* pText )
1884cdf0e10cSrcweir {
18853b32dd21SOliver-Rainer Wittmann     delete mpText;
18863b32dd21SOliver-Rainer Wittmann     mpText = pText;
1887cdf0e10cSrcweir }
1888cdf0e10cSrcweir 
18893b32dd21SOliver-Rainer Wittmann 
GetNumberOfParagraphs() const1890cdf0e10cSrcweir sal_uInt32 SwPostItField::GetNumberOfParagraphs() const
1891cdf0e10cSrcweir {
1892cdf0e10cSrcweir     return (mpText) ? mpText->Count() : 1;
1893cdf0e10cSrcweir }
1894cdf0e10cSrcweir 
18953b32dd21SOliver-Rainer Wittmann 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const1896cdf0e10cSrcweir sal_Bool SwPostItField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
1897cdf0e10cSrcweir {
1898cdf0e10cSrcweir     switch( nWhichId )
18993b32dd21SOliver-Rainer Wittmann     {
19003b32dd21SOliver-Rainer Wittmann     case FIELD_PROP_PAR1:
19013b32dd21SOliver-Rainer Wittmann         rAny <<= OUString(msAuthor);
19023b32dd21SOliver-Rainer Wittmann         break;
19033b32dd21SOliver-Rainer Wittmann     case FIELD_PROP_PAR2:
19043b32dd21SOliver-Rainer Wittmann         {
19053b32dd21SOliver-Rainer Wittmann             rAny <<= OUString(msCommentContent);
19063b32dd21SOliver-Rainer Wittmann             break;
19073b32dd21SOliver-Rainer Wittmann         }
19083b32dd21SOliver-Rainer Wittmann     case FIELD_PROP_PAR3:
19093b32dd21SOliver-Rainer Wittmann         rAny <<= OUString(msAuthorInitials);
19103b32dd21SOliver-Rainer Wittmann         break;
19113b32dd21SOliver-Rainer Wittmann     case FIELD_PROP_PAR4:
19123b32dd21SOliver-Rainer Wittmann         rAny <<= OUString(msName);
19133b32dd21SOliver-Rainer Wittmann         break;
19143b32dd21SOliver-Rainer Wittmann     case FIELD_PROP_TEXT:
19153b32dd21SOliver-Rainer Wittmann         {
19163b32dd21SOliver-Rainer Wittmann             if ( !m_pTextObject )
19173b32dd21SOliver-Rainer Wittmann             {
19183b32dd21SOliver-Rainer Wittmann                 SwPostItFieldType* pGetType = (SwPostItFieldType*)GetTyp();
19193b32dd21SOliver-Rainer Wittmann                 SwDoc* pDoc = pGetType->GetDoc();
19203b32dd21SOliver-Rainer Wittmann                 SwTextAPIEditSource* pObj = new SwTextAPIEditSource( pDoc );
19213b32dd21SOliver-Rainer Wittmann                 const_cast <SwPostItField*> (this)->m_pTextObject = new SwTextAPIObject( pObj );
19223b32dd21SOliver-Rainer Wittmann                 m_pTextObject->acquire();
19233b32dd21SOliver-Rainer Wittmann             }
1924cdf0e10cSrcweir 
19253b32dd21SOliver-Rainer Wittmann             if ( mpText )
19263b32dd21SOliver-Rainer Wittmann                 m_pTextObject->SetText( *mpText );
19273b32dd21SOliver-Rainer Wittmann             else
19283b32dd21SOliver-Rainer Wittmann                 m_pTextObject->SetString( msCommentContent );
1929cdf0e10cSrcweir 
19303b32dd21SOliver-Rainer Wittmann             uno::Reference < text::XText > xText( m_pTextObject );
19313b32dd21SOliver-Rainer Wittmann             rAny <<= xText;
19323b32dd21SOliver-Rainer Wittmann             break;
19333b32dd21SOliver-Rainer Wittmann         }
19343b32dd21SOliver-Rainer Wittmann     case FIELD_PROP_DATE:
19353b32dd21SOliver-Rainer Wittmann         {
19363b32dd21SOliver-Rainer Wittmann             util::Date aSetDate;
19373b32dd21SOliver-Rainer Wittmann             aSetDate.Day = maDateTime.GetDay();
19383b32dd21SOliver-Rainer Wittmann             aSetDate.Month = maDateTime.GetMonth();
19393b32dd21SOliver-Rainer Wittmann             aSetDate.Year = maDateTime.GetYear();
19403b32dd21SOliver-Rainer Wittmann             rAny.setValue(&aSetDate, ::getCppuType((util::Date*)0));
19413b32dd21SOliver-Rainer Wittmann         }
19423b32dd21SOliver-Rainer Wittmann         break;
19433b32dd21SOliver-Rainer Wittmann     case FIELD_PROP_DATE_TIME:
19443b32dd21SOliver-Rainer Wittmann         {
19453b32dd21SOliver-Rainer Wittmann             util::DateTime DateTimeValue;
19463b32dd21SOliver-Rainer Wittmann             DateTimeValue.HundredthSeconds = maDateTime.Get100Sec();
19473b32dd21SOliver-Rainer Wittmann             DateTimeValue.Seconds = maDateTime.GetSec();
19483b32dd21SOliver-Rainer Wittmann             DateTimeValue.Minutes = maDateTime.GetMin();
19493b32dd21SOliver-Rainer Wittmann             DateTimeValue.Hours = maDateTime.GetHour();
19503b32dd21SOliver-Rainer Wittmann             DateTimeValue.Day = maDateTime.GetDay();
19513b32dd21SOliver-Rainer Wittmann             DateTimeValue.Month = maDateTime.GetMonth();
19523b32dd21SOliver-Rainer Wittmann             DateTimeValue.Year = maDateTime.GetYear();
19533b32dd21SOliver-Rainer Wittmann             rAny <<= DateTimeValue;
19543b32dd21SOliver-Rainer Wittmann         }
19553b32dd21SOliver-Rainer Wittmann         break;
19563b32dd21SOliver-Rainer Wittmann     default:
19573b32dd21SOliver-Rainer Wittmann         DBG_ERROR("illegal property");
19583b32dd21SOliver-Rainer Wittmann     }
19593b32dd21SOliver-Rainer Wittmann     return sal_True;
1960cdf0e10cSrcweir }
1961cdf0e10cSrcweir 
19623b32dd21SOliver-Rainer Wittmann 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)1963cdf0e10cSrcweir sal_Bool SwPostItField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
1964cdf0e10cSrcweir {
1965cdf0e10cSrcweir     switch( nWhichId )
19663b32dd21SOliver-Rainer Wittmann     {
19673b32dd21SOliver-Rainer Wittmann     case FIELD_PROP_PAR1:
19683b32dd21SOliver-Rainer Wittmann         ::GetString( rAny, msAuthor );
19693b32dd21SOliver-Rainer Wittmann         break;
19703b32dd21SOliver-Rainer Wittmann     case FIELD_PROP_PAR2:
19713b32dd21SOliver-Rainer Wittmann         ::GetString( rAny, msCommentContent );
19723b32dd21SOliver-Rainer Wittmann         //#i100374# new string via api, delete complex text object so SwPostItNote picks up the new string
19733b32dd21SOliver-Rainer Wittmann         if (mpText)
19743b32dd21SOliver-Rainer Wittmann         {
19753b32dd21SOliver-Rainer Wittmann             delete mpText;
19763b32dd21SOliver-Rainer Wittmann             mpText = 0;
19773b32dd21SOliver-Rainer Wittmann         }
19783b32dd21SOliver-Rainer Wittmann         break;
19793b32dd21SOliver-Rainer Wittmann     case FIELD_PROP_PAR3:
19803b32dd21SOliver-Rainer Wittmann         ::GetString( rAny, msAuthorInitials );
19813b32dd21SOliver-Rainer Wittmann         break;
19823b32dd21SOliver-Rainer Wittmann     case FIELD_PROP_PAR4:
19833b32dd21SOliver-Rainer Wittmann         ::GetString( rAny, msName );
19843b32dd21SOliver-Rainer Wittmann         break;
19853b32dd21SOliver-Rainer Wittmann     case FIELD_PROP_TEXT:
19863b32dd21SOliver-Rainer Wittmann         DBG_ERROR("Not implemented!");
19873b32dd21SOliver-Rainer Wittmann         // ::GetString( rAny, msCommentContent );
19883b32dd21SOliver-Rainer Wittmann         break;
19893b32dd21SOliver-Rainer Wittmann     case FIELD_PROP_DATE:
19903b32dd21SOliver-Rainer Wittmann         if( rAny.getValueType() == ::getCppuType((util::Date*)0) )
19913b32dd21SOliver-Rainer Wittmann         {
19923b32dd21SOliver-Rainer Wittmann             util::Date aSetDate = *(util::Date*)rAny.getValue();
19933b32dd21SOliver-Rainer Wittmann             maDateTime = Date(aSetDate.Day, aSetDate.Month, aSetDate.Year);
19943b32dd21SOliver-Rainer Wittmann         }
19953b32dd21SOliver-Rainer Wittmann         break;
19963b32dd21SOliver-Rainer Wittmann     case FIELD_PROP_DATE_TIME:
19973b32dd21SOliver-Rainer Wittmann         {
19983b32dd21SOliver-Rainer Wittmann             util::DateTime aDateTimeValue;
19993b32dd21SOliver-Rainer Wittmann             if(!(rAny >>= aDateTimeValue))
20003b32dd21SOliver-Rainer Wittmann                 return sal_False;
20013b32dd21SOliver-Rainer Wittmann             maDateTime.Set100Sec(aDateTimeValue.HundredthSeconds);
20023b32dd21SOliver-Rainer Wittmann             maDateTime.SetSec(aDateTimeValue.Seconds);
20033b32dd21SOliver-Rainer Wittmann             maDateTime.SetMin(aDateTimeValue.Minutes);
20043b32dd21SOliver-Rainer Wittmann             maDateTime.SetHour(aDateTimeValue.Hours);
20053b32dd21SOliver-Rainer Wittmann             maDateTime.SetDay(aDateTimeValue.Day);
20063b32dd21SOliver-Rainer Wittmann             maDateTime.SetMonth(aDateTimeValue.Month);
20073b32dd21SOliver-Rainer Wittmann             maDateTime.SetYear(aDateTimeValue.Year);
20083b32dd21SOliver-Rainer Wittmann         }
20093b32dd21SOliver-Rainer Wittmann         break;
20103b32dd21SOliver-Rainer Wittmann     default:
20113b32dd21SOliver-Rainer Wittmann         DBG_ERROR("illegal property");
20123b32dd21SOliver-Rainer Wittmann     }
20133b32dd21SOliver-Rainer Wittmann     return sal_True;
2014cdf0e10cSrcweir }
20153b32dd21SOliver-Rainer Wittmann 
20163b32dd21SOliver-Rainer Wittmann 
2017cdf0e10cSrcweir /*--------------------------------------------------------------------
2018cdf0e10cSrcweir 	Beschreibung: DokumentinfoFields
2019cdf0e10cSrcweir  --------------------------------------------------------------------*/
2020cdf0e10cSrcweir 
SwExtUserFieldType()2021cdf0e10cSrcweir SwExtUserFieldType::SwExtUserFieldType()
2022cdf0e10cSrcweir 	: SwFieldType( RES_EXTUSERFLD )
2023cdf0e10cSrcweir {
2024cdf0e10cSrcweir }
2025cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2026cdf0e10cSrcweir 
2027cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Copy() const2028cdf0e10cSrcweir SwFieldType* SwExtUserFieldType::Copy() const
2029cdf0e10cSrcweir {
2030cdf0e10cSrcweir 	SwExtUserFieldType* pTyp = new SwExtUserFieldType;
2031cdf0e10cSrcweir 	return pTyp;
2032cdf0e10cSrcweir }
2033cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2034cdf0e10cSrcweir 
2035cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Expand(sal_uInt16 nSub,sal_uInt32) const2036cdf0e10cSrcweir String SwExtUserFieldType::Expand(sal_uInt16 nSub, sal_uInt32 ) const
2037cdf0e10cSrcweir {
2038cdf0e10cSrcweir     String aRet;
2039cdf0e10cSrcweir 	sal_uInt16 nRet = USHRT_MAX;
2040cdf0e10cSrcweir 	switch(nSub)
2041cdf0e10cSrcweir 	{
2042cdf0e10cSrcweir     case EU_FIRSTNAME:      nRet = USER_OPT_FIRSTNAME; break;
2043cdf0e10cSrcweir     case EU_NAME:           nRet = USER_OPT_LASTNAME;  break;
2044cdf0e10cSrcweir     case EU_SHORTCUT:       nRet = USER_OPT_ID; break;
2045cdf0e10cSrcweir 
2046cdf0e10cSrcweir     case EU_COMPANY:        nRet = USER_OPT_COMPANY;        break;
2047cdf0e10cSrcweir     case EU_STREET:         nRet = USER_OPT_STREET;         break;
2048cdf0e10cSrcweir     case EU_TITLE:          nRet = USER_OPT_TITLE;          break;
2049cdf0e10cSrcweir     case EU_POSITION:       nRet = USER_OPT_POSITION;       break;
2050cdf0e10cSrcweir     case EU_PHONE_PRIVATE:  nRet = USER_OPT_TELEPHONEHOME;    break;
2051cdf0e10cSrcweir     case EU_PHONE_COMPANY:  nRet = USER_OPT_TELEPHONEWORK;    break;
2052cdf0e10cSrcweir     case EU_FAX:            nRet = USER_OPT_FAX;            break;
2053cdf0e10cSrcweir     case EU_EMAIL:          nRet = USER_OPT_EMAIL;          break;
2054cdf0e10cSrcweir     case EU_COUNTRY:        nRet = USER_OPT_COUNTRY;        break;
2055cdf0e10cSrcweir     case EU_ZIP:            nRet = USER_OPT_ZIP;            break;
2056cdf0e10cSrcweir     case EU_CITY:           nRet = USER_OPT_CITY;           break;
2057cdf0e10cSrcweir     case EU_STATE:          nRet = USER_OPT_STATE;          break;
2058cdf0e10cSrcweir     case EU_FATHERSNAME:    nRet = USER_OPT_FATHERSNAME;    break;
2059cdf0e10cSrcweir     case EU_APARTMENT:      nRet = USER_OPT_APARTMENT;      break;
2060cdf0e10cSrcweir 	default:				ASSERT( !this, "Field unknown");
2061cdf0e10cSrcweir 	}
2062cdf0e10cSrcweir 	if( USHRT_MAX != nRet )
2063cdf0e10cSrcweir     {
2064cdf0e10cSrcweir         SvtUserOptions&  rUserOpt = SW_MOD()->GetUserOptions();
2065cdf0e10cSrcweir         aRet = rUserOpt.GetToken( nRet );
2066cdf0e10cSrcweir     }
2067cdf0e10cSrcweir 	return aRet;
2068cdf0e10cSrcweir }
2069cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2070cdf0e10cSrcweir 
2071cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SwExtUserField(SwExtUserFieldType * pTyp,sal_uInt16 nSubTyp,sal_uInt32 nFmt)2072cdf0e10cSrcweir SwExtUserField::SwExtUserField(SwExtUserFieldType* pTyp, sal_uInt16 nSubTyp, sal_uInt32 nFmt) :
2073cdf0e10cSrcweir 	SwField(pTyp, nFmt), nType(nSubTyp)
2074cdf0e10cSrcweir {
2075cdf0e10cSrcweir 	aContent = ((SwExtUserFieldType*)GetTyp())->Expand(nType, GetFormat());
2076cdf0e10cSrcweir }
2077cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2078cdf0e10cSrcweir 
2079cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Expand() const2080cdf0e10cSrcweir String SwExtUserField::Expand() const
2081cdf0e10cSrcweir {
2082cdf0e10cSrcweir 	if (!IsFixed())
2083cdf0e10cSrcweir 		((SwExtUserField*)this)->aContent = ((SwExtUserFieldType*)GetTyp())->Expand(nType, GetFormat());
2084cdf0e10cSrcweir 
2085cdf0e10cSrcweir 	return aContent;
2086cdf0e10cSrcweir }
2087cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2088cdf0e10cSrcweir 
2089cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Copy() const2090cdf0e10cSrcweir SwField* SwExtUserField::Copy() const
2091cdf0e10cSrcweir {
2092cdf0e10cSrcweir 	SwExtUserField* pFld = new SwExtUserField((SwExtUserFieldType*)GetTyp(), nType, GetFormat());
2093cdf0e10cSrcweir 	pFld->SetExpansion(aContent);
2094cdf0e10cSrcweir 
2095cdf0e10cSrcweir 	return pFld;
2096cdf0e10cSrcweir }
2097cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2098cdf0e10cSrcweir 
2099cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
GetSubType() const2100cdf0e10cSrcweir sal_uInt16 SwExtUserField::GetSubType() const
2101cdf0e10cSrcweir {
2102cdf0e10cSrcweir 	return nType;
2103cdf0e10cSrcweir }
2104cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2105cdf0e10cSrcweir 
2106cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SetSubType(sal_uInt16 nSub)2107cdf0e10cSrcweir void SwExtUserField::SetSubType(sal_uInt16 nSub)
2108cdf0e10cSrcweir {
2109cdf0e10cSrcweir 	nType = nSub;
2110cdf0e10cSrcweir }
2111cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const2112cdf0e10cSrcweir sal_Bool SwExtUserField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
2113cdf0e10cSrcweir {
2114cdf0e10cSrcweir     switch( nWhichId )
2115cdf0e10cSrcweir 	{
2116cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
2117cdf0e10cSrcweir 		rAny <<= OUString(aContent);
2118cdf0e10cSrcweir 		break;
2119cdf0e10cSrcweir 
2120cdf0e10cSrcweir 	case FIELD_PROP_USHORT1:
2121cdf0e10cSrcweir 		{
2122cdf0e10cSrcweir 			sal_Int16 nTmp = nType;
2123cdf0e10cSrcweir 			rAny <<= nTmp;
2124cdf0e10cSrcweir 		}
2125cdf0e10cSrcweir 		break;
2126cdf0e10cSrcweir 	case FIELD_PROP_BOOL1:
2127cdf0e10cSrcweir 		{
2128cdf0e10cSrcweir 			sal_Bool bTmp = IsFixed();
2129cdf0e10cSrcweir 			rAny.setValue(&bTmp, ::getBooleanCppuType());
2130cdf0e10cSrcweir 		}
2131cdf0e10cSrcweir 		break;
2132cdf0e10cSrcweir 	default:
2133cdf0e10cSrcweir 		DBG_ERROR("illegal property");
2134cdf0e10cSrcweir 	}
2135cdf0e10cSrcweir 	return sal_True;
2136cdf0e10cSrcweir }
2137cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)2138cdf0e10cSrcweir sal_Bool SwExtUserField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
2139cdf0e10cSrcweir {
2140cdf0e10cSrcweir     switch( nWhichId )
2141cdf0e10cSrcweir 	{
2142cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
2143cdf0e10cSrcweir 		::GetString( rAny, aContent );
2144cdf0e10cSrcweir 		break;
2145cdf0e10cSrcweir 
2146cdf0e10cSrcweir 	case FIELD_PROP_USHORT1:
2147cdf0e10cSrcweir 		{
2148cdf0e10cSrcweir 			sal_Int16 nTmp = 0;
2149cdf0e10cSrcweir 			rAny >>= nTmp;
2150cdf0e10cSrcweir 			nType = nTmp;
2151cdf0e10cSrcweir 		}
2152cdf0e10cSrcweir 		break;
2153cdf0e10cSrcweir 	case FIELD_PROP_BOOL1:
2154cdf0e10cSrcweir 		if( *(sal_Bool*)rAny.getValue() )
2155cdf0e10cSrcweir 			SetFormat(GetFormat() | AF_FIXED);
2156cdf0e10cSrcweir 		else
2157cdf0e10cSrcweir 			SetFormat(GetFormat() & ~AF_FIXED);
2158cdf0e10cSrcweir 		break;
2159cdf0e10cSrcweir 	default:
2160cdf0e10cSrcweir 		DBG_ERROR("illegal property");
2161cdf0e10cSrcweir 	}
2162cdf0e10cSrcweir 	return sal_True;
2163cdf0e10cSrcweir }
2164cdf0e10cSrcweir //-------------------------------------------------------------------------
2165cdf0e10cSrcweir 
2166cdf0e10cSrcweir /*--------------------------------------------------------------------
2167cdf0e10cSrcweir 	Beschreibung: Relatives Seitennummern - Feld
2168cdf0e10cSrcweir  --------------------------------------------------------------------*/
2169cdf0e10cSrcweir 
SwRefPageSetFieldType()2170cdf0e10cSrcweir SwRefPageSetFieldType::SwRefPageSetFieldType()
2171cdf0e10cSrcweir 	: SwFieldType( RES_REFPAGESETFLD )
2172cdf0e10cSrcweir {
2173cdf0e10cSrcweir }
2174cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2175cdf0e10cSrcweir 
2176cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Copy() const2177cdf0e10cSrcweir SwFieldType* SwRefPageSetFieldType::Copy() const
2178cdf0e10cSrcweir {
2179cdf0e10cSrcweir 	return new SwRefPageSetFieldType;
2180cdf0e10cSrcweir }
2181cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2182cdf0e10cSrcweir 
2183cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2184cdf0e10cSrcweir // ueberlagert, weil es nichts zum Updaten gibt!
Modify(const SfxPoolItem *,const SfxPoolItem *)2185cdf0e10cSrcweir void SwRefPageSetFieldType::Modify( const SfxPoolItem*, const SfxPoolItem * )
2186cdf0e10cSrcweir {
2187cdf0e10cSrcweir }
2188cdf0e10cSrcweir 
2189cdf0e10cSrcweir /*--------------------------------------------------------------------
2190cdf0e10cSrcweir 	Beschreibung: Relative Seitennummerierung
2191cdf0e10cSrcweir  --------------------------------------------------------------------*/
2192cdf0e10cSrcweir 
SwRefPageSetField(SwRefPageSetFieldType * pTyp,short nOff,sal_Bool bFlag)2193cdf0e10cSrcweir SwRefPageSetField::SwRefPageSetField( SwRefPageSetFieldType* pTyp,
2194cdf0e10cSrcweir 					short nOff, sal_Bool bFlag )
2195cdf0e10cSrcweir 	: SwField( pTyp ), nOffset( nOff ), bOn( bFlag )
2196cdf0e10cSrcweir {
2197cdf0e10cSrcweir }
2198cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2199cdf0e10cSrcweir 
2200cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Expand() const2201cdf0e10cSrcweir String SwRefPageSetField::Expand() const
2202cdf0e10cSrcweir {
2203cdf0e10cSrcweir 	return aEmptyStr;
2204cdf0e10cSrcweir }
2205cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2206cdf0e10cSrcweir 
2207cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Copy() const2208cdf0e10cSrcweir SwField* SwRefPageSetField::Copy() const
2209cdf0e10cSrcweir {
2210cdf0e10cSrcweir 	return new SwRefPageSetField( (SwRefPageSetFieldType*)GetTyp(), nOffset, bOn );
2211cdf0e10cSrcweir }
2212cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2213cdf0e10cSrcweir 
2214cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
GetPar2() const2215cdf0e10cSrcweir String SwRefPageSetField::GetPar2() const
2216cdf0e10cSrcweir {
2217cdf0e10cSrcweir 	return String::CreateFromInt32( GetOffset() );
2218cdf0e10cSrcweir }
2219cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2220cdf0e10cSrcweir 
2221cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SetPar2(const String & rStr)2222cdf0e10cSrcweir void SwRefPageSetField::SetPar2(const String& rStr)
2223cdf0e10cSrcweir {
2224cdf0e10cSrcweir 	SetOffset( (short) rStr.ToInt32() );
2225cdf0e10cSrcweir }
2226cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const2227cdf0e10cSrcweir sal_Bool SwRefPageSetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
2228cdf0e10cSrcweir {
2229cdf0e10cSrcweir     switch( nWhichId )
2230cdf0e10cSrcweir 	{
2231cdf0e10cSrcweir 	case FIELD_PROP_BOOL1:
2232cdf0e10cSrcweir 		rAny.setValue(&bOn, ::getBooleanCppuType());
2233cdf0e10cSrcweir 		break;
2234cdf0e10cSrcweir 	case FIELD_PROP_USHORT1:
2235cdf0e10cSrcweir 		rAny <<= (sal_Int16)nOffset;
2236cdf0e10cSrcweir 		break;
2237cdf0e10cSrcweir 	default:
2238cdf0e10cSrcweir 		DBG_ERROR("illegal property");
2239cdf0e10cSrcweir 	}
2240cdf0e10cSrcweir 	return sal_True;
2241cdf0e10cSrcweir }
2242cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)2243cdf0e10cSrcweir sal_Bool SwRefPageSetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
2244cdf0e10cSrcweir {
2245cdf0e10cSrcweir     switch( nWhichId )
2246cdf0e10cSrcweir 	{
2247cdf0e10cSrcweir 	case FIELD_PROP_BOOL1:
2248cdf0e10cSrcweir 		bOn = *(sal_Bool*)rAny.getValue();
2249cdf0e10cSrcweir 		break;
2250cdf0e10cSrcweir 	case FIELD_PROP_USHORT1:
2251cdf0e10cSrcweir 		rAny >>=nOffset;
2252cdf0e10cSrcweir 		break;
2253cdf0e10cSrcweir 	default:
2254cdf0e10cSrcweir 		DBG_ERROR("illegal property");
2255cdf0e10cSrcweir 	}
2256cdf0e10cSrcweir 	return sal_True;
2257cdf0e10cSrcweir }
2258cdf0e10cSrcweir /*--------------------------------------------------------------------
2259cdf0e10cSrcweir 	Beschreibung: relatives Seitennummern - Abfrage Feld
2260cdf0e10cSrcweir  --------------------------------------------------------------------*/
2261cdf0e10cSrcweir 
SwRefPageGetFieldType(SwDoc * pDc)2262cdf0e10cSrcweir SwRefPageGetFieldType::SwRefPageGetFieldType( SwDoc* pDc )
2263cdf0e10cSrcweir 	: SwFieldType( RES_REFPAGEGETFLD ), pDoc( pDc ), nNumberingType( SVX_NUM_ARABIC )
2264cdf0e10cSrcweir {
2265cdf0e10cSrcweir }
2266cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2267cdf0e10cSrcweir 
2268cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Copy() const2269cdf0e10cSrcweir SwFieldType* SwRefPageGetFieldType::Copy() const
2270cdf0e10cSrcweir {
2271cdf0e10cSrcweir 	SwRefPageGetFieldType* pNew = new SwRefPageGetFieldType( pDoc );
2272cdf0e10cSrcweir 	pNew->nNumberingType = nNumberingType;
2273cdf0e10cSrcweir 	return pNew;
2274cdf0e10cSrcweir }
2275cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2276cdf0e10cSrcweir 
2277cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)2278cdf0e10cSrcweir void SwRefPageGetFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
2279cdf0e10cSrcweir {
2280cdf0e10cSrcweir 	// Update auf alle GetReferenz-Felder
2281cdf0e10cSrcweir 	if( !pNew && !pOld && GetDepends() )
2282cdf0e10cSrcweir 	{
2283cdf0e10cSrcweir 		// sammel erstmal alle SetPageRefFelder ein.
2284cdf0e10cSrcweir 		_SetGetExpFlds aTmpLst( 10, 5 );
2285cdf0e10cSrcweir 		if( MakeSetList( aTmpLst ) )
2286cdf0e10cSrcweir 		{
2287cdf0e10cSrcweir 			SwIterator<SwFmtFld,SwFieldType> aIter( *this );
2288cdf0e10cSrcweir             for ( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
2289cdf0e10cSrcweir 					// nur die GetRef-Felder Updaten
2290cdf0e10cSrcweir 					if( pFmtFld->GetTxtFld() )
2291cdf0e10cSrcweir 						UpdateField( pFmtFld->GetTxtFld(), aTmpLst );
2292cdf0e10cSrcweir 		}
2293cdf0e10cSrcweir 	}
2294cdf0e10cSrcweir 
2295cdf0e10cSrcweir 	// weiter an die Text-Felder, diese "Expandieren" den Text
2296cdf0e10cSrcweir 	NotifyClients( pOld, pNew );
2297cdf0e10cSrcweir }
2298cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2299cdf0e10cSrcweir 
2300cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
MakeSetList(_SetGetExpFlds & rTmpLst)2301cdf0e10cSrcweir sal_uInt16 SwRefPageGetFieldType::MakeSetList( _SetGetExpFlds& rTmpLst )
2302cdf0e10cSrcweir {
2303cdf0e10cSrcweir 	SwIterator<SwFmtFld,SwFieldType> aIter(*pDoc->GetSysFldType( RES_REFPAGESETFLD));
2304cdf0e10cSrcweir     for ( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
2305cdf0e10cSrcweir     {
2306cdf0e10cSrcweir 			// nur die GetRef-Felder Updaten
2307cdf0e10cSrcweir 			const SwTxtFld* pTFld = pFmtFld->GetTxtFld();
2308cdf0e10cSrcweir 			if( pTFld )
2309cdf0e10cSrcweir 			{
2310cdf0e10cSrcweir 				const SwTxtNode& rTxtNd = pTFld->GetTxtNode();
2311cdf0e10cSrcweir 
2312cdf0e10cSrcweir 				// immer den ersten !! (in Tab-Headline, Kopf-/Fuss )
2313cdf0e10cSrcweir 				Point aPt;
2314cdf0e10cSrcweir 				const SwCntntFrm* pFrm = rTxtNd.getLayoutFrm( rTxtNd.GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False );
2315cdf0e10cSrcweir 
2316cdf0e10cSrcweir 				_SetGetExpFld* pNew;
2317cdf0e10cSrcweir 
2318cdf0e10cSrcweir                 if( !pFrm ||
2319cdf0e10cSrcweir                      pFrm->IsInDocBody() ||
2320cdf0e10cSrcweir                     // --> FME 2004-07-27 #i31868#
2321cdf0e10cSrcweir                     // Check if pFrm is not yet connected to the layout.
2322cdf0e10cSrcweir                     !pFrm->FindPageFrm() )
2323cdf0e10cSrcweir                     // <--
2324cdf0e10cSrcweir                 {
2325cdf0e10cSrcweir 					// einen sdbcx::Index fuers bestimmen vom TextNode anlegen
2326cdf0e10cSrcweir 					SwNodeIndex aIdx( rTxtNd );
2327cdf0e10cSrcweir 					pNew = new _SetGetExpFld( aIdx, pTFld );
2328cdf0e10cSrcweir 				}
2329cdf0e10cSrcweir 				else
2330cdf0e10cSrcweir 				{
2331cdf0e10cSrcweir 					// einen sdbcx::Index fuers bestimmen vom TextNode anlegen
2332cdf0e10cSrcweir 					SwPosition aPos( pDoc->GetNodes().GetEndOfPostIts() );
2333cdf0e10cSrcweir #ifdef DBG_UTIL
2334cdf0e10cSrcweir 					ASSERT( GetBodyTxtNode( *pDoc, aPos, *pFrm ),
2335cdf0e10cSrcweir 							"wo steht das Feld" );
2336cdf0e10cSrcweir #else
2337cdf0e10cSrcweir 					GetBodyTxtNode( *pDoc, aPos, *pFrm );
2338cdf0e10cSrcweir #endif
2339cdf0e10cSrcweir 					pNew = new _SetGetExpFld( aPos.nNode, pTFld,
2340cdf0e10cSrcweir 												&aPos.nContent );
2341cdf0e10cSrcweir 				}
2342cdf0e10cSrcweir 
2343cdf0e10cSrcweir 				if( !rTmpLst.Insert( pNew ))
2344cdf0e10cSrcweir 					delete pNew;
2345cdf0e10cSrcweir 			}
2346cdf0e10cSrcweir 	}
2347cdf0e10cSrcweir 
2348cdf0e10cSrcweir 	return rTmpLst.Count();
2349cdf0e10cSrcweir }
2350cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2351cdf0e10cSrcweir 
2352cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
UpdateField(SwTxtFld * pTxtFld,_SetGetExpFlds & rSetList)2353cdf0e10cSrcweir void SwRefPageGetFieldType::UpdateField( SwTxtFld* pTxtFld,
2354cdf0e10cSrcweir 										_SetGetExpFlds& rSetList )
2355cdf0e10cSrcweir {
2356c0286415SOliver-Rainer Wittmann 	SwRefPageGetField* pGetFld = (SwRefPageGetField*)pTxtFld->GetFmtFld().GetField();
2357cdf0e10cSrcweir 	pGetFld->SetText( aEmptyStr );
2358cdf0e10cSrcweir 
2359cdf0e10cSrcweir 	// dann suche mal das richtige RefPageSet-Field
2360cdf0e10cSrcweir 	SwTxtNode* pTxtNode = (SwTxtNode*)&pTxtFld->GetTxtNode();
2361cdf0e10cSrcweir 	if( pTxtNode->StartOfSectionIndex() >
2362cdf0e10cSrcweir 		pDoc->GetNodes().GetEndOfExtras().GetIndex() )
2363cdf0e10cSrcweir 	{
2364cdf0e10cSrcweir 		SwNodeIndex aIdx( *pTxtNode );
2365cdf0e10cSrcweir 		_SetGetExpFld aEndFld( aIdx, pTxtFld );
2366cdf0e10cSrcweir 
2367cdf0e10cSrcweir 		sal_uInt16 nLast;
2368cdf0e10cSrcweir 		rSetList.Seek_Entry( &aEndFld, &nLast );
2369cdf0e10cSrcweir 
2370cdf0e10cSrcweir 		if( nLast-- )
2371cdf0e10cSrcweir 		{
2372c0286415SOliver-Rainer Wittmann 			const SwTxtFld* pRefTxtFld = rSetList[ nLast ]->GetTxtFld();
2373cdf0e10cSrcweir 			const SwRefPageSetField* pSetFld =
2374c0286415SOliver-Rainer Wittmann 						(SwRefPageSetField*)pRefTxtFld->GetFmtFld().GetField();
2375cdf0e10cSrcweir 			if( pSetFld->IsOn() )
2376cdf0e10cSrcweir 			{
2377cdf0e10cSrcweir 				// dann bestimme mal den entsp. Offset
2378cdf0e10cSrcweir 				Point aPt;
2379cdf0e10cSrcweir 				const SwCntntFrm* pFrm = pTxtNode->getLayoutFrm( pTxtNode->GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False );
2380cdf0e10cSrcweir 				const SwCntntFrm* pRefFrm = pRefTxtFld->GetTxtNode().getLayoutFrm( pRefTxtFld->GetTxtNode().GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False );
2381cdf0e10cSrcweir 				const SwPageFrm* pPgFrm = 0;
2382cdf0e10cSrcweir 				sal_uInt16 nDiff = ( pFrm && pRefFrm )
2383cdf0e10cSrcweir 						? 	(pPgFrm = pFrm->FindPageFrm())->GetPhyPageNum() -
2384cdf0e10cSrcweir 							pRefFrm->FindPageFrm()->GetPhyPageNum() + 1
2385cdf0e10cSrcweir 						: 1;
2386cdf0e10cSrcweir 
2387cdf0e10cSrcweir 				sal_uInt32 nTmpFmt = SVX_NUM_PAGEDESC == pGetFld->GetFormat()
2388cdf0e10cSrcweir 						? ( !pPgFrm
2389cdf0e10cSrcweir 								? (sal_uInt32)SVX_NUM_ARABIC
2390cdf0e10cSrcweir 								: pPgFrm->GetPageDesc()->GetNumType().GetNumberingType() )
2391cdf0e10cSrcweir 						: pGetFld->GetFormat();
2392cdf0e10cSrcweir 				short nPageNum = static_cast<short>(Max(0, pSetFld->GetOffset() + (short)nDiff));
2393cdf0e10cSrcweir 				pGetFld->SetText( FormatNumber( nPageNum, nTmpFmt ) );
2394cdf0e10cSrcweir 			}
2395cdf0e10cSrcweir 		}
2396cdf0e10cSrcweir 	}
2397cdf0e10cSrcweir 	// dann die Formatierung anstossen
2398c0286415SOliver-Rainer Wittmann 	((SwFmtFld&)pTxtFld->GetFmtFld()).ModifyNotification( 0, 0 );
2399cdf0e10cSrcweir }
2400cdf0e10cSrcweir 
2401cdf0e10cSrcweir /*--------------------------------------------------------------------
2402cdf0e10cSrcweir 	Beschreibung: Relative Seitennummerierung Abfragen
2403cdf0e10cSrcweir  --------------------------------------------------------------------*/
2404cdf0e10cSrcweir 
SwRefPageGetField(SwRefPageGetFieldType * pTyp,sal_uInt32 nFmt)2405cdf0e10cSrcweir SwRefPageGetField::SwRefPageGetField( SwRefPageGetFieldType* pTyp,
2406cdf0e10cSrcweir 									sal_uInt32 nFmt )
2407cdf0e10cSrcweir 	: SwField( pTyp, nFmt )
2408cdf0e10cSrcweir {
2409cdf0e10cSrcweir }
2410cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2411cdf0e10cSrcweir 
2412cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Expand() const2413cdf0e10cSrcweir String SwRefPageGetField::Expand() const
2414cdf0e10cSrcweir {
2415cdf0e10cSrcweir 	return sTxt;
2416cdf0e10cSrcweir }
2417cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2418cdf0e10cSrcweir 
2419cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Copy() const2420cdf0e10cSrcweir SwField* SwRefPageGetField::Copy() const
2421cdf0e10cSrcweir {
2422cdf0e10cSrcweir 	SwRefPageGetField* pCpy = new SwRefPageGetField(
2423cdf0e10cSrcweir 						(SwRefPageGetFieldType*)GetTyp(), GetFormat() );
2424cdf0e10cSrcweir 	pCpy->SetText( sTxt );
2425cdf0e10cSrcweir 	return pCpy;
2426cdf0e10cSrcweir }
2427cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2428cdf0e10cSrcweir 
2429cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
ChangeExpansion(const SwFrm * pFrm,const SwTxtFld * pFld)2430cdf0e10cSrcweir void SwRefPageGetField::ChangeExpansion( const SwFrm* pFrm,
2431cdf0e10cSrcweir 										const SwTxtFld* pFld )
2432cdf0e10cSrcweir {
2433cdf0e10cSrcweir 	// nur Felder in Footer, Header, FootNote, Flys
2434cdf0e10cSrcweir 	SwTxtNode* pTxtNode = (SwTxtNode*)&pFld->GetTxtNode();
2435cdf0e10cSrcweir 	SwRefPageGetFieldType* pGetType = (SwRefPageGetFieldType*)GetTyp();
2436cdf0e10cSrcweir 	SwDoc* pDoc = pGetType->GetDoc();
2437cdf0e10cSrcweir 	if( pFld->GetTxtNode().StartOfSectionIndex() >
2438cdf0e10cSrcweir 		pDoc->GetNodes().GetEndOfExtras().GetIndex() )
2439cdf0e10cSrcweir 		return;
2440cdf0e10cSrcweir 
2441cdf0e10cSrcweir 	sTxt.Erase();
2442cdf0e10cSrcweir 
2443cdf0e10cSrcweir 	ASSERT( !pFrm->IsInDocBody(), "Flag ist nicht richtig, Frame steht im DocBody" );
2444cdf0e10cSrcweir 
2445cdf0e10cSrcweir 	// sammel erstmal alle SetPageRefFelder ein.
2446cdf0e10cSrcweir 	_SetGetExpFlds aTmpLst( 10, 5 );
2447cdf0e10cSrcweir 	if( !pGetType->MakeSetList( aTmpLst ) )
2448cdf0e10cSrcweir 		return ;
2449cdf0e10cSrcweir 
2450cdf0e10cSrcweir 	// einen sdbcx::Index fuers bestimmen vom TextNode anlegen
2451cdf0e10cSrcweir 	SwPosition aPos( SwNodeIndex( pDoc->GetNodes() ) );
2452cdf0e10cSrcweir 	pTxtNode = (SwTxtNode*) GetBodyTxtNode( *pDoc, aPos, *pFrm );
2453cdf0e10cSrcweir 
2454cdf0e10cSrcweir 	// Wenn kein Layout vorhanden, kommt es in Kopf und Fusszeilen dazu
2455cdf0e10cSrcweir 	// das ChangeExpansion uebers Layout-Formatieren aufgerufen wird
2456cdf0e10cSrcweir 	// aber kein TxtNode vorhanden ist
2457cdf0e10cSrcweir 	//
2458cdf0e10cSrcweir 	if(!pTxtNode)
2459cdf0e10cSrcweir 		return;
2460cdf0e10cSrcweir 
2461cdf0e10cSrcweir 	_SetGetExpFld aEndFld( aPos.nNode, pFld, &aPos.nContent );
2462cdf0e10cSrcweir 
2463cdf0e10cSrcweir 	sal_uInt16 nLast;
2464cdf0e10cSrcweir 	aTmpLst.Seek_Entry( &aEndFld, &nLast );
2465cdf0e10cSrcweir 
2466cdf0e10cSrcweir 	if( !nLast-- )
2467cdf0e10cSrcweir 		return ;		// es gibt kein entsprechendes Set - Feld vor mir
2468cdf0e10cSrcweir 
2469c0286415SOliver-Rainer Wittmann 	const SwTxtFld* pRefTxtFld = aTmpLst[ nLast ]->GetTxtFld();
2470cdf0e10cSrcweir 	const SwRefPageSetField* pSetFld =
2471c0286415SOliver-Rainer Wittmann 						(SwRefPageSetField*)pRefTxtFld->GetFmtFld().GetField();
2472cdf0e10cSrcweir     Point aPt;
2473cdf0e10cSrcweir     const SwCntntFrm* pRefFrm = pRefTxtFld ? pRefTxtFld->GetTxtNode().getLayoutFrm( pFrm->getRootFrm(), &aPt, 0, sal_False ) : 0;
2474cdf0e10cSrcweir     if( pSetFld->IsOn() && pRefFrm )
2475cdf0e10cSrcweir 	{
2476cdf0e10cSrcweir 		// dann bestimme mal den entsp. Offset
2477cdf0e10cSrcweir         const SwPageFrm* pPgFrm = pFrm->FindPageFrm();
2478cdf0e10cSrcweir 		sal_uInt16 nDiff = pPgFrm->GetPhyPageNum() -
2479cdf0e10cSrcweir 							pRefFrm->FindPageFrm()->GetPhyPageNum() + 1;
2480cdf0e10cSrcweir 
2481c0286415SOliver-Rainer Wittmann 		SwRefPageGetField* pGetFld = (SwRefPageGetField*)pFld->GetFmtFld().GetField();
2482cdf0e10cSrcweir 		sal_uInt32 nTmpFmt = SVX_NUM_PAGEDESC == pGetFld->GetFormat()
2483cdf0e10cSrcweir 							? pPgFrm->GetPageDesc()->GetNumType().GetNumberingType()
2484cdf0e10cSrcweir 							: pGetFld->GetFormat();
2485cdf0e10cSrcweir 		short nPageNum = static_cast<short>(Max(0, pSetFld->GetOffset() + (short)nDiff ));
2486cdf0e10cSrcweir 		pGetFld->SetText( FormatNumber( nPageNum, nTmpFmt ) );
2487cdf0e10cSrcweir 	}
2488cdf0e10cSrcweir }
2489cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const2490cdf0e10cSrcweir sal_Bool SwRefPageGetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
2491cdf0e10cSrcweir {
2492cdf0e10cSrcweir     switch( nWhichId )
2493cdf0e10cSrcweir 	{
2494cdf0e10cSrcweir         case FIELD_PROP_USHORT1:
2495cdf0e10cSrcweir             rAny <<= (sal_Int16)GetFormat();
2496cdf0e10cSrcweir         break;
2497cdf0e10cSrcweir         case FIELD_PROP_PAR1:
2498cdf0e10cSrcweir             rAny <<= OUString(sTxt);
2499cdf0e10cSrcweir         break;
2500cdf0e10cSrcweir         default:
2501cdf0e10cSrcweir             DBG_ERROR("illegal property");
2502cdf0e10cSrcweir 	}
2503cdf0e10cSrcweir 	return sal_True;
2504cdf0e10cSrcweir }
2505cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)2506cdf0e10cSrcweir sal_Bool SwRefPageGetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
2507cdf0e10cSrcweir {
2508cdf0e10cSrcweir     switch( nWhichId )
2509cdf0e10cSrcweir 	{
2510cdf0e10cSrcweir         case FIELD_PROP_USHORT1:
2511cdf0e10cSrcweir 		{
2512cdf0e10cSrcweir 			sal_Int16 nSet = 0;
2513cdf0e10cSrcweir 			rAny >>= nSet;
2514cdf0e10cSrcweir 			if(nSet <= SVX_NUM_PAGEDESC )
2515cdf0e10cSrcweir 				SetFormat(nSet);
2516cdf0e10cSrcweir 			else {
2517cdf0e10cSrcweir 				//exception(wrong_value)
2518cdf0e10cSrcweir 				;
2519cdf0e10cSrcweir             }
2520cdf0e10cSrcweir 		}
2521cdf0e10cSrcweir 		break;
2522cdf0e10cSrcweir         case FIELD_PROP_PAR1:
2523cdf0e10cSrcweir         {
2524cdf0e10cSrcweir             OUString sTmp;
2525cdf0e10cSrcweir             rAny >>= sTmp;
2526cdf0e10cSrcweir             sTxt = sTmp;
2527cdf0e10cSrcweir         }
2528cdf0e10cSrcweir         break;
2529cdf0e10cSrcweir     default:
2530cdf0e10cSrcweir 		DBG_ERROR("illegal property");
2531cdf0e10cSrcweir 	}
2532cdf0e10cSrcweir 	return sal_True;
2533cdf0e10cSrcweir }
2534cdf0e10cSrcweir 
2535cdf0e10cSrcweir /*--------------------------------------------------------------------
2536cdf0e10cSrcweir 	Beschreibung: Feld zum Anspringen und Editieren
2537cdf0e10cSrcweir  --------------------------------------------------------------------*/
2538cdf0e10cSrcweir 
SwJumpEditFieldType(SwDoc * pD)2539cdf0e10cSrcweir SwJumpEditFieldType::SwJumpEditFieldType( SwDoc* pD )
2540cdf0e10cSrcweir 	: SwFieldType( RES_JUMPEDITFLD ), pDoc( pD ), aDep( this, 0 )
2541cdf0e10cSrcweir {
2542cdf0e10cSrcweir }
2543cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2544cdf0e10cSrcweir 
2545cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Copy() const2546cdf0e10cSrcweir SwFieldType* SwJumpEditFieldType::Copy() const
2547cdf0e10cSrcweir {
2548cdf0e10cSrcweir 	return new SwJumpEditFieldType( pDoc );
2549cdf0e10cSrcweir }
2550cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2551cdf0e10cSrcweir 
2552cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
GetCharFmt()2553cdf0e10cSrcweir SwCharFmt* SwJumpEditFieldType::GetCharFmt()
2554cdf0e10cSrcweir {
2555cdf0e10cSrcweir 	SwCharFmt* pFmt = pDoc->GetCharFmtFromPool( RES_POOLCHR_JUMPEDIT );
2556cdf0e10cSrcweir 
2557cdf0e10cSrcweir 	// noch nicht registriert ?
2558cdf0e10cSrcweir 	if( !aDep.GetRegisteredIn() )
2559cdf0e10cSrcweir 		pFmt->Add( &aDep );		// anmelden
2560cdf0e10cSrcweir 
2561cdf0e10cSrcweir 	return pFmt;
2562cdf0e10cSrcweir }
2563cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2564cdf0e10cSrcweir 
2565cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SwJumpEditField(SwJumpEditFieldType * pTyp,sal_uInt32 nForm,const String & rTxt,const String & rHelp)2566cdf0e10cSrcweir SwJumpEditField::SwJumpEditField( SwJumpEditFieldType* pTyp, sal_uInt32 nForm,
2567cdf0e10cSrcweir 								const String& rTxt, const String& rHelp )
2568cdf0e10cSrcweir 	: SwField( pTyp, nForm ), sTxt( rTxt ), sHelp( rHelp )
2569cdf0e10cSrcweir {
2570cdf0e10cSrcweir }
2571cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2572cdf0e10cSrcweir 
2573cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Expand() const2574cdf0e10cSrcweir String SwJumpEditField::Expand() const
2575cdf0e10cSrcweir {
2576cdf0e10cSrcweir 	String sTmp( '<' );
2577cdf0e10cSrcweir 	sTmp += sTxt;
2578cdf0e10cSrcweir 	return sTmp += '>';
2579cdf0e10cSrcweir }
2580cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2581cdf0e10cSrcweir 
2582cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Copy() const2583cdf0e10cSrcweir SwField* SwJumpEditField::Copy() const
2584cdf0e10cSrcweir {
2585cdf0e10cSrcweir 	return new SwJumpEditField( (SwJumpEditFieldType*)GetTyp(), GetFormat(),
2586cdf0e10cSrcweir 								sTxt, sHelp );
2587cdf0e10cSrcweir }
2588cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2589cdf0e10cSrcweir 
2590cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2591cdf0e10cSrcweir // Platzhalter-Text
2592cdf0e10cSrcweir 
GetPar1() const2593cdf0e10cSrcweir const String& SwJumpEditField::GetPar1() const
2594cdf0e10cSrcweir {
2595cdf0e10cSrcweir 	return sTxt;
2596cdf0e10cSrcweir }
2597cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2598cdf0e10cSrcweir 
2599cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SetPar1(const String & rStr)2600cdf0e10cSrcweir void SwJumpEditField::SetPar1(const String& rStr)
2601cdf0e10cSrcweir {
2602cdf0e10cSrcweir 	sTxt = rStr;
2603cdf0e10cSrcweir }
2604cdf0e10cSrcweir 
2605cdf0e10cSrcweir // HinweisText
2606cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2607cdf0e10cSrcweir 
2608cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
GetPar2() const2609cdf0e10cSrcweir String SwJumpEditField::GetPar2() const
2610cdf0e10cSrcweir {
2611cdf0e10cSrcweir 	return sHelp;
2612cdf0e10cSrcweir }
2613cdf0e10cSrcweir /* ---------------------------------------------------------------------------
2614cdf0e10cSrcweir 
2615cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SetPar2(const String & rStr)2616cdf0e10cSrcweir void SwJumpEditField::SetPar2(const String& rStr)
2617cdf0e10cSrcweir {
2618cdf0e10cSrcweir 	sHelp = rStr;
2619cdf0e10cSrcweir }
2620cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const2621cdf0e10cSrcweir sal_Bool SwJumpEditField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
2622cdf0e10cSrcweir {
2623cdf0e10cSrcweir     switch( nWhichId )
2624cdf0e10cSrcweir 	{
2625cdf0e10cSrcweir 	case FIELD_PROP_USHORT1:
2626cdf0e10cSrcweir 		{
2627cdf0e10cSrcweir 			sal_Int16 nRet;
2628cdf0e10cSrcweir 			switch( GetFormat() )
2629cdf0e10cSrcweir 			{
2630cdf0e10cSrcweir 			case JE_FMT_TABLE:  nRet = text::PlaceholderType::TABLE; break;
2631cdf0e10cSrcweir 			case JE_FMT_FRAME:  nRet = text::PlaceholderType::TEXTFRAME; break;
2632cdf0e10cSrcweir 			case JE_FMT_GRAPHIC:nRet = text::PlaceholderType::GRAPHIC; break;
2633cdf0e10cSrcweir 			case JE_FMT_OLE:	nRet = text::PlaceholderType::OBJECT; break;
2634cdf0e10cSrcweir //			case JE_FMT_TEXT:
2635cdf0e10cSrcweir 			default:
2636cdf0e10cSrcweir 				nRet = text::PlaceholderType::TEXT; break;
2637cdf0e10cSrcweir 			}
2638cdf0e10cSrcweir 			rAny <<= nRet;
2639cdf0e10cSrcweir 		}
2640cdf0e10cSrcweir 		break;
2641cdf0e10cSrcweir 	case FIELD_PROP_PAR1 :
2642cdf0e10cSrcweir 		rAny <<= OUString(sHelp);
2643cdf0e10cSrcweir 		break;
2644cdf0e10cSrcweir 	case FIELD_PROP_PAR2 :
2645cdf0e10cSrcweir 		 rAny <<= OUString(sTxt);
2646cdf0e10cSrcweir 		 break;
2647cdf0e10cSrcweir 	default:
2648cdf0e10cSrcweir 		DBG_ERROR("illegal property");
2649cdf0e10cSrcweir 	}
2650cdf0e10cSrcweir 	return sal_True;
2651cdf0e10cSrcweir }
2652cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)2653cdf0e10cSrcweir sal_Bool SwJumpEditField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
2654cdf0e10cSrcweir {
2655cdf0e10cSrcweir     switch( nWhichId )
2656cdf0e10cSrcweir 	{
2657cdf0e10cSrcweir 	case FIELD_PROP_USHORT1:
2658cdf0e10cSrcweir 		{
2659cdf0e10cSrcweir 			//JP 24.10.2001: int32 because in UnoField.cxx a putvalue is
2660cdf0e10cSrcweir 			//				called with a int32 value! But normally we need
2661cdf0e10cSrcweir 			//				here only a int16
2662cdf0e10cSrcweir 			sal_Int32 nSet = 0;
2663cdf0e10cSrcweir 			rAny >>= nSet;
2664cdf0e10cSrcweir 			switch( nSet )
2665cdf0e10cSrcweir 			{
2666cdf0e10cSrcweir 				case text::PlaceholderType::TEXT 	 : SetFormat(JE_FMT_TEXT); break;
2667cdf0e10cSrcweir 				case text::PlaceholderType::TABLE 	 : SetFormat(JE_FMT_TABLE); break;
2668cdf0e10cSrcweir 				case text::PlaceholderType::TEXTFRAME: SetFormat(JE_FMT_FRAME); break;
2669cdf0e10cSrcweir 				case text::PlaceholderType::GRAPHIC  : SetFormat(JE_FMT_GRAPHIC); break;
2670cdf0e10cSrcweir 				case text::PlaceholderType::OBJECT 	 : SetFormat(JE_FMT_OLE); break;
2671cdf0e10cSrcweir 			}
2672cdf0e10cSrcweir 		}
2673cdf0e10cSrcweir 		break;
2674cdf0e10cSrcweir 	case FIELD_PROP_PAR1 :
2675cdf0e10cSrcweir 		::GetString( rAny, sHelp );
2676cdf0e10cSrcweir 		break;
2677cdf0e10cSrcweir 	case FIELD_PROP_PAR2 :
2678cdf0e10cSrcweir 		 ::GetString( rAny, sTxt);
2679cdf0e10cSrcweir 		 break;
2680cdf0e10cSrcweir 	default:
2681cdf0e10cSrcweir 		DBG_ERROR("illegal property");
2682cdf0e10cSrcweir 	}
2683cdf0e10cSrcweir 	return sal_True;
2684cdf0e10cSrcweir }
2685cdf0e10cSrcweir 
2686cdf0e10cSrcweir 
2687cdf0e10cSrcweir /*--------------------------------------------------------------------
2688cdf0e10cSrcweir 	Beschreibung: Combined Character Fieldtype / Field
2689cdf0e10cSrcweir  --------------------------------------------------------------------*/
2690cdf0e10cSrcweir 
SwCombinedCharFieldType()2691cdf0e10cSrcweir SwCombinedCharFieldType::SwCombinedCharFieldType()
2692cdf0e10cSrcweir 	: SwFieldType( RES_COMBINED_CHARS )
2693cdf0e10cSrcweir {
2694cdf0e10cSrcweir }
2695cdf0e10cSrcweir 
Copy() const2696cdf0e10cSrcweir SwFieldType* SwCombinedCharFieldType::Copy() const
2697cdf0e10cSrcweir {
2698cdf0e10cSrcweir 	return new SwCombinedCharFieldType;
2699cdf0e10cSrcweir }
2700cdf0e10cSrcweir 
2701cdf0e10cSrcweir /* --------------------------------------------------------------------*/
2702cdf0e10cSrcweir 
SwCombinedCharField(SwCombinedCharFieldType * pFTyp,const String & rChars)2703cdf0e10cSrcweir SwCombinedCharField::SwCombinedCharField( SwCombinedCharFieldType* pFTyp,
2704cdf0e10cSrcweir 											const String& rChars )
2705cdf0e10cSrcweir 	: SwField( pFTyp, 0 ),
2706cdf0e10cSrcweir 	sCharacters( rChars.Copy( 0, MAX_COMBINED_CHARACTERS ))
2707cdf0e10cSrcweir {
2708cdf0e10cSrcweir }
2709cdf0e10cSrcweir 
Expand() const2710cdf0e10cSrcweir String	SwCombinedCharField::Expand() const
2711cdf0e10cSrcweir {
2712cdf0e10cSrcweir 	return sCharacters;
2713cdf0e10cSrcweir }
2714cdf0e10cSrcweir 
Copy() const2715cdf0e10cSrcweir SwField* SwCombinedCharField::Copy() const
2716cdf0e10cSrcweir {
2717cdf0e10cSrcweir 	return new SwCombinedCharField( (SwCombinedCharFieldType*)GetTyp(),
2718cdf0e10cSrcweir 										sCharacters );
2719cdf0e10cSrcweir }
2720cdf0e10cSrcweir 
GetPar1() const2721cdf0e10cSrcweir const String& SwCombinedCharField::GetPar1() const
2722cdf0e10cSrcweir {
2723cdf0e10cSrcweir 	return sCharacters;
2724cdf0e10cSrcweir }
2725cdf0e10cSrcweir 
SetPar1(const String & rStr)2726cdf0e10cSrcweir void SwCombinedCharField::SetPar1(const String& rStr)
2727cdf0e10cSrcweir {
2728cdf0e10cSrcweir 	sCharacters = rStr.Copy( 0, MAX_COMBINED_CHARACTERS );
2729cdf0e10cSrcweir }
2730cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const2731cdf0e10cSrcweir sal_Bool SwCombinedCharField::QueryValue( uno::Any& rAny,
2732cdf0e10cSrcweir                                         sal_uInt16 nWhichId ) const
2733cdf0e10cSrcweir {
2734cdf0e10cSrcweir     switch( nWhichId )
2735cdf0e10cSrcweir 	{
2736cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
2737cdf0e10cSrcweir 		rAny <<= rtl::OUString( sCharacters );
2738cdf0e10cSrcweir 		break;
2739cdf0e10cSrcweir 	default:
2740cdf0e10cSrcweir 		DBG_ERROR("illegal property");
2741cdf0e10cSrcweir 	}
2742cdf0e10cSrcweir 	return sal_True;
2743cdf0e10cSrcweir }
2744cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)2745cdf0e10cSrcweir sal_Bool SwCombinedCharField::PutValue( const uno::Any& rAny,
2746cdf0e10cSrcweir                                         sal_uInt16 nWhichId )
2747cdf0e10cSrcweir {
2748cdf0e10cSrcweir     switch( nWhichId )
2749cdf0e10cSrcweir 	{
2750cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
2751cdf0e10cSrcweir 		::GetString( rAny, sCharacters ).Erase( MAX_COMBINED_CHARACTERS );
2752cdf0e10cSrcweir 		break;
2753cdf0e10cSrcweir 	default:
2754cdf0e10cSrcweir 		DBG_ERROR("illegal property");
2755cdf0e10cSrcweir 	}
2756cdf0e10cSrcweir 	return sal_True;
2757cdf0e10cSrcweir }
2758cdf0e10cSrcweir 
2759