xref: /aoo42x/main/editeng/source/items/flditem.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_editeng.hxx"
30 #include <vcl/metaact.hxx>
31 #include <svl/zforlist.hxx>
32 #include <tools/urlobj.hxx>
33 
34 #define _SVX_FLDITEM_CXX
35 #include <unotools/localfilehelper.hxx>
36 
37 #include <editeng/flditem.hxx>
38 
39 #include <editeng/measfld.hxx>
40 
41 // #90477#
42 #include <tools/tenccvt.hxx>
43 
44 #define FRAME_MARKER	(sal_uInt32)0x21981357
45 #define CHARSET_MARKER	(FRAME_MARKER+1)
46 
47 // -----------------------------------------------------------------------
48 
49 TYPEINIT1( SvxFieldItem, SfxPoolItem );
50 
51 SV_IMPL_PERSIST1( SvxFieldData, SvPersistBase );
52 
53 // -----------------------------------------------------------------------
54 
55 SvxFieldData::SvxFieldData()
56 {
57 }
58 
59 // -----------------------------------------------------------------------
60 
61 SvxFieldData::~SvxFieldData()
62 {
63 }
64 
65 // -----------------------------------------------------------------------
66 
67 SvxFieldData* SvxFieldData::Clone() const
68 {
69 	return new SvxFieldData;
70 }
71 
72 // -----------------------------------------------------------------------
73 
74 int SvxFieldData::operator==( const SvxFieldData& rFld ) const
75 {
76 	DBG_ASSERT( Type() == rFld.Type(), "==: Verschiedene Typen" );
77 	(void)rFld;
78 	return sal_True;	// Basicklasse immer gleich.
79 }
80 
81 // -----------------------------------------------------------------------
82 
83 void SvxFieldData::Load( SvPersistStream & /*rStm*/ )
84 {
85 }
86 
87 // -----------------------------------------------------------------------
88 
89 void SvxFieldData::Save( SvPersistStream & /*rStm*/ )
90 {
91 }
92 
93 
94 MetaAction* SvxFieldData::createBeginComment() const
95 {
96 	return new MetaCommentAction( "FIELD_SEQ_BEGIN" );
97 }
98 
99 MetaAction* SvxFieldData::createEndComment() const
100 {
101 	return new MetaCommentAction( "FIELD_SEQ_END" );
102 }
103 
104 // -----------------------------------------------------------------------
105 
106 SvxFieldItem::SvxFieldItem( SvxFieldData* pFld, const sal_uInt16 nId ) :
107 	SfxPoolItem( nId )
108 {
109 	pField = pFld;	// gehoert direkt dem Item
110 }
111 
112 // -----------------------------------------------------------------------
113 
114 SvxFieldItem::SvxFieldItem( const SvxFieldData& rField, const sal_uInt16 nId ) :
115 	SfxPoolItem( nId )
116 {
117 	pField = rField.Clone();
118 }
119 
120 // -----------------------------------------------------------------------
121 
122 SvxFieldItem::SvxFieldItem( const SvxFieldItem& rItem ) :
123 	SfxPoolItem	( rItem )
124 {
125 	pField = rItem.GetField() ? rItem.GetField()->Clone() : 0;
126 }
127 
128 // -----------------------------------------------------------------------
129 
130 SvxFieldItem::~SvxFieldItem()
131 {
132 	delete pField;
133 }
134 
135 // -----------------------------------------------------------------------
136 
137 SfxPoolItem* SvxFieldItem::Clone( SfxItemPool* ) const
138 {
139 	return new SvxFieldItem(*this);
140 }
141 
142 // -----------------------------------------------------------------------
143 
144 SfxPoolItem* SvxFieldItem::Create( SvStream& rStrm, sal_uInt16 ) const
145 {
146 	SvxFieldData* pData = 0;
147 	SvPersistStream aPStrm( GetClassManager(), &rStrm );
148 	aPStrm >> pData;
149 
150 	if( aPStrm.IsEof() )
151 		aPStrm.SetError( SVSTREAM_GENERALERROR );
152 
153 	if ( aPStrm.GetError() == ERRCODE_IO_NOFACTORY )
154 		aPStrm.ResetError();	// Eigentlich einen Code, dass nicht alle Attr gelesen wurden...
155 
156 	return new SvxFieldItem( pData, Which() );
157 }
158 
159 // -----------------------------------------------------------------------
160 
161 SvStream& SvxFieldItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
162 {
163 	DBG_ASSERT( pField, "SvxFieldItem::Store: Feld?!" );
164 	SvPersistStream aPStrm( GetClassManager(), &rStrm );
165 	// Das ResetError in der obigen Create-Methode gab es in 3.1 noch nicht,
166 	// deshalb duerfen beim 3.x-Export neuere Items nicht gespeichert werden!
167 	if ( ( rStrm.GetVersion() <= SOFFICE_FILEFORMAT_31 ) && pField &&
168 			pField->GetClassId() == 50 /* SdrMeasureField */ )
169 	{
170 		// SvxFieldData reicht nicht, weil auch nicht am ClassMgr angemeldet
171 		SvxURLField aDummyData;
172 		aPStrm << &aDummyData;
173 	}
174 	else
175 		aPStrm << pField;
176 
177 	return rStrm;
178 }
179 
180 // -----------------------------------------------------------------------
181 
182 int SvxFieldItem::operator==( const SfxPoolItem& rItem ) const
183 {
184 	DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal which or type" );
185 
186 	const SvxFieldData* pOtherFld = ((const SvxFieldItem&)rItem).GetField();
187 	if ( !pField && !pOtherFld )
188 		return sal_True;
189 
190 	if ( ( !pField && pOtherFld ) || ( pField && !pOtherFld ) )
191 		return sal_False;
192 
193 	return ( ( pField->Type() == pOtherFld->Type() )
194 				&& ( *pField == *pOtherFld ) );
195 }
196 
197 // =================================================================
198 // Es folgen die Ableitungen von SvxFieldData...
199 // =================================================================
200 
201 SV_IMPL_PERSIST1( SvxDateField, SvxFieldData );
202 
203 // -----------------------------------------------------------------------
204 
205 SvxDateField::SvxDateField()
206 {
207 	nFixDate = Date().GetDate();
208 	eType = SVXDATETYPE_VAR;
209 	eFormat = SVXDATEFORMAT_STDSMALL;
210 }
211 
212 // -----------------------------------------------------------------------
213 
214 SvxDateField::SvxDateField( const Date& rDate, SvxDateType eT, SvxDateFormat eF )
215 {
216 	nFixDate = rDate.GetDate();
217 	eType = eT;
218 	eFormat = eF;
219 }
220 
221 // -----------------------------------------------------------------------
222 
223 SvxFieldData* SvxDateField::Clone() const
224 {
225 	return new SvxDateField( *this );
226 }
227 
228 // -----------------------------------------------------------------------
229 
230 int SvxDateField::operator==( const SvxFieldData& rOther ) const
231 {
232 	if ( rOther.Type() != Type() )
233 		return sal_False;
234 
235 	const SvxDateField& rOtherFld = (const SvxDateField&) rOther;
236 	return ( ( nFixDate == rOtherFld.nFixDate ) &&
237 				( eType == rOtherFld.eType ) &&
238 				( eFormat == rOtherFld.eFormat ) );
239 }
240 
241 // -----------------------------------------------------------------------
242 
243 void SvxDateField::Load( SvPersistStream & rStm )
244 {
245 	sal_uInt16 nType, nFormat;
246 
247 	rStm >> nFixDate;
248 	rStm >> nType;
249 	rStm >> nFormat;
250 
251 	eType = (SvxDateType)nType;
252 	eFormat= (SvxDateFormat)nFormat;
253 }
254 
255 // -----------------------------------------------------------------------
256 
257 void SvxDateField::Save( SvPersistStream & rStm )
258 {
259 	rStm << nFixDate;
260 	rStm << (sal_uInt16)eType;
261 	rStm << (sal_uInt16)eFormat;
262 }
263 
264 // -----------------------------------------------------------------------
265 
266 String SvxDateField::GetFormatted( SvNumberFormatter& rFormatter, LanguageType eLang ) const
267 {
268     Date aDate; // current date
269 	if ( eType == SVXDATETYPE_FIX )
270 		aDate.SetDate( nFixDate );
271 
272 	return GetFormatted( aDate, eFormat, rFormatter, eLang );
273 }
274 
275 String SvxDateField::GetFormatted( Date& aDate, SvxDateFormat eFormat, SvNumberFormatter& rFormatter, LanguageType eLang )
276 {
277 	if ( eFormat == SVXDATEFORMAT_SYSTEM )
278 	{
279 		DBG_ERROR( "SVXDATEFORMAT_SYSTEM nicht implementiert!" );
280 		eFormat = SVXDATEFORMAT_STDSMALL;
281 	}
282 	else if ( eFormat == SVXDATEFORMAT_APPDEFAULT )
283 	{
284 		DBG_ERROR( "SVXDATEFORMAT_APPDEFAULT: Woher nehmen?" );
285 		eFormat = SVXDATEFORMAT_STDSMALL;
286 	}
287 
288     sal_uLong nFormatKey;
289 
290 	switch( eFormat )
291 	{
292 		case SVXDATEFORMAT_STDSMALL:
293             // short
294             nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYSTEM_SHORT, eLang );
295 		break;
296 		case SVXDATEFORMAT_STDBIG:
297             // long
298             nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYSTEM_LONG, eLang );
299 		break;
300 		case SVXDATEFORMAT_A:
301 			// 13.02.96
302             nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_DDMMYY, eLang );
303 		break;
304 		case SVXDATEFORMAT_B:
305 			// 13.02.1996
306             nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_DDMMYYYY, eLang );
307 		break;
308 		case SVXDATEFORMAT_C:
309             // 13. Feb 1996
310             nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_DMMMYYYY, eLang );
311 		break;
312 		case SVXDATEFORMAT_D:
313             // 13. Februar 1996
314             nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_DMMMMYYYY, eLang );
315 		break;
316 		case SVXDATEFORMAT_E:
317             // Die, 13. Februar 1996
318             nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_NNDMMMMYYYY, eLang );
319 		break;
320 		case SVXDATEFORMAT_F:
321             // Dienstag, 13. Februar 1996
322             nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_NNNNDMMMMYYYY, eLang );
323 		break;
324         default:
325             nFormatKey = rFormatter.GetStandardFormat( NUMBERFORMAT_DATE, eLang );
326 	}
327 
328     double fDiffDate = aDate - *(rFormatter.GetNullDate());
329     String aStr;
330    	Color* pColor = NULL;
331     rFormatter.GetOutputString( fDiffDate, nFormatKey, aStr, &pColor );
332     return aStr;
333 }
334 
335 MetaAction* SvxDateField::createBeginComment() const
336 {
337 	return new MetaCommentAction( "FIELD_SEQ_BEGIN" );
338 }
339 
340 SV_IMPL_PERSIST1( SvxURLField, SvxFieldData );
341 
342 // -----------------------------------------------------------------------
343 
344 SvxURLField::SvxURLField()
345 {
346 	eFormat = SVXURLFORMAT_URL;
347 }
348 
349 // -----------------------------------------------------------------------
350 
351 SvxURLField::SvxURLField( const XubString& rURL, const XubString& rRepres, SvxURLFormat eFmt )
352 	: aURL( rURL ), aRepresentation( rRepres )
353 {
354 	eFormat = eFmt;
355 }
356 
357 // -----------------------------------------------------------------------
358 
359 SvxFieldData* SvxURLField::Clone() const
360 {
361 	return new SvxURLField( *this );
362 }
363 
364 // -----------------------------------------------------------------------
365 
366 int SvxURLField::operator==( const SvxFieldData& rOther ) const
367 {
368 	if ( rOther.Type() != Type() )
369 		return sal_False;
370 
371 	const SvxURLField& rOtherFld = (const SvxURLField&) rOther;
372 	return ( ( eFormat == rOtherFld.eFormat ) &&
373 				( aURL == rOtherFld.aURL ) &&
374 				( aRepresentation == rOtherFld.aRepresentation ) &&
375 				( aTargetFrame == rOtherFld.aTargetFrame ) );
376 }
377 
378 // -----------------------------------------------------------------------
379 
380 static void write_unicode( SvPersistStream & rStm, const String& rString )
381 {
382 	sal_uInt16 nL = rString.Len();
383 	rStm << nL;
384 	rStm.Write( rString.GetBuffer(), nL*sizeof(sal_Unicode) );
385 }
386 
387 static void read_unicode( SvPersistStream & rStm, String& rString )
388 {
389 	sal_uInt16 nL = 0;
390 	rStm >> nL;
391 	if ( nL )
392 	{
393 		rString.AllocBuffer( nL );
394 		rStm.Read( rString.GetBufferAccess(), nL*sizeof(sal_Unicode) );
395 		rString.ReleaseBufferAccess( nL );
396 	}
397 }
398 
399 void SvxURLField::Load( SvPersistStream & rStm )
400 {
401 	sal_uInt16 nFormat = 0;
402 
403 	rStm >> nFormat;
404 	eFormat= (SvxURLFormat)nFormat;
405 
406 	read_unicode( rStm, aURL );
407 	read_unicode( rStm, aRepresentation );
408 	read_unicode( rStm, aTargetFrame );
409 }
410 
411 // -----------------------------------------------------------------------
412 
413 void SvxURLField::Save( SvPersistStream & rStm )
414 {
415 	rStm << (sal_uInt16)eFormat;
416 
417 	write_unicode( rStm, aURL );
418 	write_unicode( rStm, aRepresentation );
419 	write_unicode( rStm, aTargetFrame );
420 }
421 
422 MetaAction* SvxURLField::createBeginComment() const
423 {
424     // #i46618# Adding target URL to metafile comment
425 	return new MetaCommentAction( "FIELD_SEQ_BEGIN",
426                                   0,
427                                   reinterpret_cast<const sal_uInt8*>(aURL.GetBuffer()),
428                                   2*aURL.Len() );
429 }
430 
431 // =================================================================
432 // Die Felder, die aus Calc ausgebaut wurden:
433 // =================================================================
434 
435 SV_IMPL_PERSIST1( SvxPageField, SvxFieldData );
436 
437 SvxFieldData* __EXPORT SvxPageField::Clone() const
438 {
439 	return new SvxPageField;		// leer
440 }
441 
442 int __EXPORT SvxPageField::operator==( const SvxFieldData& rCmp ) const
443 {
444 	return ( rCmp.Type() == TYPE(SvxPageField) );
445 }
446 
447 void __EXPORT SvxPageField::Load( SvPersistStream & /*rStm*/ )
448 {
449 }
450 
451 void __EXPORT SvxPageField::Save( SvPersistStream & /*rStm*/ )
452 {
453 }
454 
455 MetaAction* SvxPageField::createBeginComment() const
456 {
457     return new MetaCommentAction( "FIELD_SEQ_BEGIN;PageField" );
458 }
459 
460 
461 SV_IMPL_PERSIST1( SvxPagesField, SvxFieldData );
462 
463 SvxFieldData* __EXPORT SvxPagesField::Clone() const
464 {
465 	return new SvxPagesField;	// leer
466 }
467 
468 int __EXPORT SvxPagesField::operator==( const SvxFieldData& rCmp ) const
469 {
470 	return ( rCmp.Type() == TYPE(SvxPagesField) );
471 }
472 
473 void __EXPORT SvxPagesField::Load( SvPersistStream & /*rStm*/ )
474 {
475 }
476 
477 void __EXPORT SvxPagesField::Save( SvPersistStream & /*rStm*/ )
478 {
479 }
480 
481 SV_IMPL_PERSIST1( SvxTimeField, SvxFieldData );
482 
483 SvxFieldData* __EXPORT SvxTimeField::Clone() const
484 {
485 	return new SvxTimeField;	// leer
486 }
487 
488 int __EXPORT SvxTimeField::operator==( const SvxFieldData& rCmp ) const
489 {
490 	return ( rCmp.Type() == TYPE(SvxTimeField) );
491 }
492 
493 void __EXPORT SvxTimeField::Load( SvPersistStream & /*rStm*/ )
494 {
495 }
496 
497 void __EXPORT SvxTimeField::Save( SvPersistStream & /*rStm*/ )
498 {
499 }
500 
501 MetaAction* SvxTimeField::createBeginComment() const
502 {
503 	return new MetaCommentAction( "FIELD_SEQ_BEGIN" );
504 }
505 
506 SV_IMPL_PERSIST1( SvxFileField, SvxFieldData );
507 
508 SvxFieldData* __EXPORT SvxFileField::Clone() const
509 {
510 	return new SvxFileField;	// leer
511 }
512 
513 int __EXPORT SvxFileField::operator==( const SvxFieldData& rCmp ) const
514 {
515 	return ( rCmp.Type() == TYPE(SvxFileField) );
516 }
517 
518 void __EXPORT SvxFileField::Load( SvPersistStream & /*rStm*/ )
519 {
520 }
521 
522 void __EXPORT SvxFileField::Save( SvPersistStream & /*rStm*/ )
523 {
524 }
525 
526 SV_IMPL_PERSIST1( SvxTableField, SvxFieldData );
527 
528 SvxFieldData* __EXPORT SvxTableField::Clone() const
529 {
530 	return new SvxTableField;	// leer
531 }
532 
533 int __EXPORT SvxTableField::operator==( const SvxFieldData& rCmp ) const
534 {
535 	return ( rCmp.Type() == TYPE(SvxTableField) );
536 }
537 
538 void __EXPORT SvxTableField::Load( SvPersistStream & /*rStm*/ )
539 {
540 }
541 
542 void __EXPORT SvxTableField::Save( SvPersistStream & /*rStm*/ )
543 {
544 }
545 
546 //----------------------------------------------------------------------------
547 //		SvxExtTimeField
548 //----------------------------------------------------------------------------
549 
550 SV_IMPL_PERSIST1( SvxExtTimeField, SvxFieldData );
551 
552 //----------------------------------------------------------------------------
553 
554 SvxExtTimeField::SvxExtTimeField()
555 {
556 	nFixTime = Time().GetTime();
557 	eType = SVXTIMETYPE_VAR;
558 	eFormat = SVXTIMEFORMAT_STANDARD;
559 }
560 
561 //----------------------------------------------------------------------------
562 
563 SvxExtTimeField::SvxExtTimeField( const Time& rTime, SvxTimeType eT, SvxTimeFormat eF )
564 {
565 	nFixTime = rTime.GetTime();
566 	eType = eT;
567 	eFormat = eF;
568 }
569 
570 //----------------------------------------------------------------------------
571 
572 SvxFieldData* SvxExtTimeField::Clone() const
573 {
574 	return new SvxExtTimeField( *this );
575 }
576 
577 //----------------------------------------------------------------------------
578 
579 int SvxExtTimeField::operator==( const SvxFieldData& rOther ) const
580 {
581 	if ( rOther.Type() != Type() )
582 		return sal_False;
583 
584 	const SvxExtTimeField& rOtherFld = (const SvxExtTimeField&) rOther;
585 	return ( ( nFixTime == rOtherFld.nFixTime ) &&
586 				( eType == rOtherFld.eType ) &&
587 				( eFormat == rOtherFld.eFormat ) );
588 }
589 
590 //----------------------------------------------------------------------------
591 
592 void SvxExtTimeField::Load( SvPersistStream & rStm )
593 {
594 	sal_uInt16 nType, nFormat;
595 
596 	rStm >> nFixTime;
597 	rStm >> nType;
598 	rStm >> nFormat;
599 
600 	eType = (SvxTimeType) nType;
601 	eFormat= (SvxTimeFormat) nFormat;
602 }
603 
604 //----------------------------------------------------------------------------
605 
606 void SvxExtTimeField::Save( SvPersistStream & rStm )
607 {
608 	rStm << nFixTime;
609 	rStm << (sal_uInt16) eType;
610 	rStm << (sal_uInt16) eFormat;
611 }
612 
613 //----------------------------------------------------------------------------
614 
615 String SvxExtTimeField::GetFormatted( SvNumberFormatter& rFormatter, LanguageType eLang ) const
616 {
617     Time aTime; // current time
618 	if ( eType == SVXTIMETYPE_FIX )
619 		aTime.SetTime( nFixTime );
620 	return GetFormatted( aTime, eFormat, rFormatter, eLang );
621 }
622 
623 String SvxExtTimeField::GetFormatted( Time& aTime, SvxTimeFormat eFormat, SvNumberFormatter& rFormatter, LanguageType eLang )
624 {
625 	switch( eFormat )
626 	{
627         case SVXTIMEFORMAT_SYSTEM :
628             DBG_ERROR( "SVXTIMEFORMAT_SYSTEM: not implemented" );
629             eFormat = SVXTIMEFORMAT_STANDARD;
630         break;
631         case SVXTIMEFORMAT_APPDEFAULT :
632             DBG_ERROR( "SVXTIMEFORMAT_APPDEFAULT: not implemented" );
633             eFormat = SVXTIMEFORMAT_STANDARD;
634         break;
635         default: ;//prevent warning
636     }
637 
638     sal_uInt32 nFormatKey;
639 
640 	switch( eFormat )
641 	{
642 		case SVXTIMEFORMAT_12_HM:
643             nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMMAMPM, eLang );
644 		break;
645         case SVXTIMEFORMAT_12_HMSH:
646         {   // no builtin format available, try to insert or reuse
647             String aFormatCode( RTL_CONSTASCII_USTRINGPARAM( "HH:MM:SS.00 AM/PM" ) );
648             xub_StrLen nCheckPos;
649             short nType;
650             /*sal_Bool bInserted = */rFormatter.PutandConvertEntry( aFormatCode,
651                 nCheckPos, nType, nFormatKey, LANGUAGE_ENGLISH_US, eLang );
652             DBG_ASSERT( nCheckPos == 0, "SVXTIMEFORMAT_12_HMSH: could not insert format code" );
653             if ( nCheckPos )
654                 nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HH_MMSS00, eLang );
655         }
656         break;
657 		case SVXTIMEFORMAT_24_HM:
658             nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMM, eLang );
659 		break;
660 		case SVXTIMEFORMAT_24_HMSH:
661             nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HH_MMSS00, eLang );
662 		break;
663 		case SVXTIMEFORMAT_12_HMS:
664             nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMMSSAMPM, eLang );
665 		break;
666 		case SVXTIMEFORMAT_24_HMS:
667             nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMMSS, eLang );
668 		break;
669 		case SVXTIMEFORMAT_STANDARD:
670         default:
671             nFormatKey = rFormatter.GetStandardFormat( NUMBERFORMAT_TIME, eLang );
672 	}
673 
674     double fFracTime = aTime.GetTimeInDays();
675     String aStr;
676    	Color* pColor = NULL;
677     rFormatter.GetOutputString( fFracTime, nFormatKey, aStr, &pColor );
678     return aStr;
679 }
680 
681 MetaAction* SvxExtTimeField::createBeginComment() const
682 {
683 	return new MetaCommentAction( "FIELD_SEQ_BEGIN" );
684 }
685 
686 //----------------------------------------------------------------------------
687 //		SvxExtFileField
688 //----------------------------------------------------------------------------
689 
690 SV_IMPL_PERSIST1( SvxExtFileField, SvxFieldData );
691 
692 //----------------------------------------------------------------------------
693 
694 SvxExtFileField::SvxExtFileField()
695 {
696 	eType = SVXFILETYPE_VAR;
697 	eFormat = SVXFILEFORMAT_FULLPATH;
698 }
699 
700 //----------------------------------------------------------------------------
701 
702 SvxExtFileField::SvxExtFileField( const XubString& rStr, SvxFileType eT, SvxFileFormat eF )
703 {
704 	aFile = rStr;
705 	eType = eT;
706 	eFormat = eF;
707 }
708 
709 //----------------------------------------------------------------------------
710 
711 SvxFieldData* SvxExtFileField::Clone() const
712 {
713 	return new SvxExtFileField( *this );
714 }
715 
716 //----------------------------------------------------------------------------
717 
718 int SvxExtFileField::operator==( const SvxFieldData& rOther ) const
719 {
720 	if ( rOther.Type() != Type() )
721 		return sal_False;
722 
723 	const SvxExtFileField& rOtherFld = (const SvxExtFileField&) rOther;
724 	return ( ( aFile == rOtherFld.aFile ) &&
725 				( eType == rOtherFld.eType ) &&
726 				( eFormat == rOtherFld.eFormat ) );
727 }
728 
729 //----------------------------------------------------------------------------
730 
731 void SvxExtFileField::Load( SvPersistStream & rStm )
732 {
733 	sal_uInt16 nType, nFormat;
734 
735 	// UNICODE: rStm >> aFile;
736 	rStm.ReadByteString(aFile);
737 
738 	rStm >> nType;
739 	rStm >> nFormat;
740 
741 	eType = (SvxFileType) nType;
742 	eFormat= (SvxFileFormat) nFormat;
743 }
744 
745 //----------------------------------------------------------------------------
746 
747 void SvxExtFileField::Save( SvPersistStream & rStm )
748 {
749 	// UNICODE: rStm << aFile;
750 	rStm.WriteByteString(aFile);
751 
752 	rStm << (sal_uInt16) eType;
753 	rStm << (sal_uInt16) eFormat;
754 }
755 
756 //----------------------------------------------------------------------------
757 
758 XubString SvxExtFileField::GetFormatted() const
759 {
760 	XubString aString;
761 
762 	INetURLObject aURLObj( aFile );
763 
764     if( INET_PROT_NOT_VALID == aURLObj.GetProtocol() )
765     {
766         // invalid? try to interpret string as system file name
767         String aURLStr;
768 
769         ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFile, aURLStr );
770 
771         aURLObj.SetURL( aURLStr );
772     }
773 
774     // #92009# Be somewhat liberate when trying to
775     // get formatted content out of the FileField
776     if( INET_PROT_NOT_VALID == aURLObj.GetProtocol() )
777     {
778         // still not valid? Then output as is
779         aString = aFile;
780     }
781 	else if( INET_PROT_FILE == aURLObj.GetProtocol() )
782 	{
783 		switch( eFormat )
784 		{
785 			case SVXFILEFORMAT_FULLPATH:
786 				aString = aURLObj.getFSysPath(INetURLObject::FSYS_DETECT);
787 			break;
788 
789 			case SVXFILEFORMAT_PATH:
790                 aURLObj.removeSegment(INetURLObject::LAST_SEGMENT, false);
791                 // #101742# Leave trailing slash at the pathname
792                 aURLObj.setFinalSlash();
793 				aString = aURLObj.getFSysPath(INetURLObject::FSYS_DETECT);
794 			break;
795 
796 			case SVXFILEFORMAT_NAME:
797 				aString = aURLObj.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_UNAMBIGUOUS);
798 			break;
799 
800 			case SVXFILEFORMAT_NAME_EXT:
801 				aString = aURLObj.getName(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_UNAMBIGUOUS);
802 			break;
803 		}
804 	}
805 	else
806 	{
807 		switch( eFormat )
808 		{
809 			case SVXFILEFORMAT_FULLPATH:
810 				aString = aURLObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
811 			break;
812 
813 			case SVXFILEFORMAT_PATH:
814                 aURLObj.removeSegment(INetURLObject::LAST_SEGMENT, false);
815                 // #101742# Leave trailing slash at the pathname
816                 aURLObj.setFinalSlash();
817 				aString = aURLObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
818 			break;
819 
820 			case SVXFILEFORMAT_NAME:
821 				aString = aURLObj.getBase();
822 			break;
823 
824 			case SVXFILEFORMAT_NAME_EXT:
825 				aString = aURLObj.getName();
826 			break;
827 		}
828 	}
829 
830 	return( aString );
831 }
832 
833 //----------------------------------------------------------------------------
834 //		SvxAuthorField
835 //----------------------------------------------------------------------------
836 
837 SV_IMPL_PERSIST1( SvxAuthorField, SvxFieldData );
838 
839 //----------------------------------------------------------------------------
840 
841 SvxAuthorField::SvxAuthorField()
842 {
843 	eType = SVXAUTHORTYPE_VAR;
844 	eFormat = SVXAUTHORFORMAT_FULLNAME;
845 }
846 
847 //----------------------------------------------------------------------------
848 
849 SvxAuthorField::SvxAuthorField( const XubString& rFirstName,
850                                 const XubString& rLastName,
851                                 const XubString& rShortName,
852 									SvxAuthorType eT, SvxAuthorFormat eF )
853 {
854     aName      = rLastName;
855     aFirstName = rFirstName;
856     aShortName = rShortName;
857 	eType   = eT;
858 	eFormat = eF;
859 }
860 
861 //----------------------------------------------------------------------------
862 
863 SvxFieldData* SvxAuthorField::Clone() const
864 {
865 	return new SvxAuthorField( *this );
866 }
867 
868 //----------------------------------------------------------------------------
869 
870 int SvxAuthorField::operator==( const SvxFieldData& rOther ) const
871 {
872 	if ( rOther.Type() != Type() )
873 		return sal_False;
874 
875 	const SvxAuthorField& rOtherFld = (const SvxAuthorField&) rOther;
876 	return ( ( aName == rOtherFld.aName ) &&
877 				( aFirstName == rOtherFld.aFirstName ) &&
878 				( aShortName == rOtherFld.aShortName ) &&
879 				( eType == rOtherFld.eType ) &&
880 				( eFormat == rOtherFld.eFormat ) );
881 }
882 
883 //----------------------------------------------------------------------------
884 
885 void SvxAuthorField::Load( SvPersistStream & rStm )
886 {
887 	sal_uInt16 nType = 0, nFormat = 0;
888 
889 	read_unicode( rStm, aName );
890 	read_unicode( rStm, aFirstName );
891 	read_unicode( rStm, aShortName );
892 
893 	rStm >> nType;
894 	rStm >> nFormat;
895 
896 	eType = (SvxAuthorType) nType;
897 	eFormat= (SvxAuthorFormat) nFormat;
898 }
899 
900 //----------------------------------------------------------------------------
901 
902 void SvxAuthorField::Save( SvPersistStream & rStm )
903 {
904 	write_unicode( rStm, aName );
905 	write_unicode( rStm, aFirstName );
906 	write_unicode( rStm, aShortName );
907 
908 	rStm << (sal_uInt16) eType;
909 	rStm << (sal_uInt16) eFormat;
910 }
911 
912 //----------------------------------------------------------------------------
913 
914 XubString SvxAuthorField::GetFormatted() const
915 {
916 	XubString aString;
917 
918 	switch( eFormat )
919 	{
920 		case SVXAUTHORFORMAT_FULLNAME:
921 			aString  = aFirstName;
922 			aString += sal_Unicode(' ');
923 			aString += aName;
924 		break;
925 
926 		case SVXAUTHORFORMAT_NAME:
927 			aString = aName;
928 		break;
929 
930 		case SVXAUTHORFORMAT_FIRSTNAME:
931 			aString = aFirstName;
932 		break;
933 
934 		case SVXAUTHORFORMAT_SHORTNAME:
935 			aString = aShortName;
936 		break;
937 	}
938 
939 	return( aString );
940 }
941 
942 static SvClassManager* pClassMgr=0;
943 
944 SvClassManager&	SvxFieldItem::GetClassManager()
945 {
946 	if ( !pClassMgr )
947 	{
948 		pClassMgr = new SvClassManager;
949 		pClassMgr->SV_CLASS_REGISTER( SvxFieldData );
950 		pClassMgr->SV_CLASS_REGISTER( SvxURLField );
951 		pClassMgr->SV_CLASS_REGISTER( SvxDateField );
952 		pClassMgr->SV_CLASS_REGISTER( SvxPageField );
953 		pClassMgr->SV_CLASS_REGISTER( SvxTimeField );
954 		pClassMgr->SV_CLASS_REGISTER( SvxExtTimeField );
955 		pClassMgr->SV_CLASS_REGISTER( SvxExtFileField );
956 		pClassMgr->SV_CLASS_REGISTER( SvxAuthorField );
957 	}
958 
959 	return *pClassMgr;
960 }
961 
962 ///////////////////////////////////////////////////////////////////////
963 
964 SV_IMPL_PERSIST1( SvxHeaderField, SvxFieldData );
965 
966 SvxFieldData* __EXPORT SvxHeaderField::Clone() const
967 {
968 	return new SvxHeaderField;		// leer
969 }
970 
971 int __EXPORT SvxHeaderField::operator==( const SvxFieldData& rCmp ) const
972 {
973 	return ( rCmp.Type() == TYPE(SvxHeaderField) );
974 }
975 
976 void __EXPORT SvxHeaderField::Load( SvPersistStream & /*rStm*/ )
977 {
978 }
979 
980 void __EXPORT SvxHeaderField::Save( SvPersistStream & /*rStm*/ )
981 {
982 }
983 
984 ///////////////////////////////////////////////////////////////////////
985 
986 SV_IMPL_PERSIST1( SvxFooterField, SvxFieldData );
987 
988 SvxFieldData* __EXPORT SvxFooterField::Clone() const
989 {
990 	return new SvxFooterField;		// leer
991 }
992 
993 int __EXPORT SvxFooterField::operator==( const SvxFieldData& rCmp ) const
994 {
995 	return ( rCmp.Type() == TYPE(SvxFooterField) );
996 }
997 
998 void __EXPORT SvxFooterField::Load( SvPersistStream & /*rStm*/ )
999 {
1000 }
1001 
1002 void __EXPORT SvxFooterField::Save( SvPersistStream & /*rStm*/ )
1003 {
1004 }
1005 
1006 ///////////////////////////////////////////////////////////////////////
1007 
1008 SV_IMPL_PERSIST1( SvxDateTimeField, SvxFieldData );
1009 
1010 SvxFieldData* __EXPORT SvxDateTimeField::Clone() const
1011 {
1012 	return new SvxDateTimeField;		// leer
1013 }
1014 
1015 int __EXPORT SvxDateTimeField::operator==( const SvxFieldData& rCmp ) const
1016 {
1017 	return ( rCmp.Type() == TYPE(SvxDateTimeField) );
1018 }
1019 
1020 void __EXPORT SvxDateTimeField::Load( SvPersistStream & /*rStm*/ )
1021 {
1022 }
1023 
1024 void __EXPORT SvxDateTimeField::Save( SvPersistStream & /*rStm*/ )
1025 {
1026 }
1027 
1028 String SvxDateTimeField::GetFormatted( Date& rDate, Time& rTime, int eFormat, SvNumberFormatter& rFormatter, LanguageType eLanguage )
1029 {
1030 	String aRet;
1031 
1032 	SvxDateFormat eDateFormat = (SvxDateFormat)(eFormat & 0x0f);
1033 
1034 	if(eDateFormat)
1035 	{
1036 		aRet = SvxDateField::GetFormatted( rDate, eDateFormat, rFormatter, eLanguage );
1037 	}
1038 
1039 	SvxTimeFormat eTimeFormat = (SvxTimeFormat)((eFormat >> 4) & 0x0f);
1040 
1041 	if(eTimeFormat)
1042 	{
1043 		if(aRet.Len())
1044 			aRet += sal_Unicode(' ');
1045 
1046 		aRet += SvxExtTimeField::GetFormatted( rTime, eTimeFormat, rFormatter, eLanguage );
1047 	}
1048 
1049 	return aRet;
1050 }
1051 
1052