1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <comphelper/string.hxx>
21 #include <vcl/metaact.hxx>
22 #include <svl/zforlist.hxx>
23 #include <tools/urlobj.hxx>
25 #include <unotools/localfilehelper.hxx>
27 #include <editeng/flditem.hxx>
28 #include <editeng/measfld.hxx>
29 #include "editeng/unonames.hxx"
31 #include <tools/tenccvt.hxx>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/text/XTextContent.hpp>
35 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
36 #include <com/sun/star/util/DateTime.hpp>
38 using namespace com::sun::star
;
40 SvxFieldData
* SvxFieldData::Create(const uno::Reference
<text::XTextContent
>& xTextContent
)
42 uno::Reference
<beans::XPropertySet
> xPropSet(xTextContent
, uno::UNO_QUERY
);
46 // we do not support these fields from Writer, so make sure we do not throw
47 // here - see fdo#63436 how to possibly extend Writer to make use of this
50 aAny
= xPropSet
->getPropertyValue(UNO_TC_PROP_TEXTFIELD_TYPE
);
51 if ( !aAny
.has
<sal_Int32
>() )
53 } catch ( const beans::UnknownPropertyException
& )
58 sal_Int32 nFieldType
= aAny
.get
<sal_Int32
>();
62 case text::textfield::Type::TIME
:
63 case text::textfield::Type::EXTENDED_TIME
:
64 case text::textfield::Type::DATE
:
66 sal_Bool bIsDate
= false;
67 xPropSet
->getPropertyValue(UNO_TC_PROP_IS_DATE
) >>= bIsDate
;
71 util::DateTime aDateTime
= xPropSet
->getPropertyValue(UNO_TC_PROP_DATE_TIME
).get
<util::DateTime
>();
72 Date
aDate(aDateTime
.Day
, aDateTime
.Month
, aDateTime
.Year
);
73 sal_Bool bIsFixed
= false;
74 xPropSet
->getPropertyValue(UNO_TC_PROP_IS_FIXED
) >>= bIsFixed
;
76 SvxDateField
* pData
= new SvxDateField(aDate
, bIsFixed
? SVXDATETYPE_FIX
: SVXDATETYPE_VAR
);
77 sal_Int32 nNumFmt
= -1;
78 xPropSet
->getPropertyValue(UNO_TC_PROP_NUMFORMAT
) >>= nNumFmt
;
79 if (nNumFmt
>= SVXDATEFORMAT_APPDEFAULT
&& nNumFmt
<= SVXDATEFORMAT_F
)
80 pData
->SetFormat(static_cast<SvxDateFormat
>(nNumFmt
));
85 if (nFieldType
!= text::textfield::Type::TIME
)
87 util::DateTime aDateTime
= xPropSet
->getPropertyValue(UNO_TC_PROP_DATE_TIME
).get
<util::DateTime
>();
88 Time
aTime(aDateTime
.Hours
, aDateTime
.Minutes
, aDateTime
.Seconds
, aDateTime
.NanoSeconds
);
90 sal_Bool bIsFixed
= false;
91 xPropSet
->getPropertyValue(UNO_TC_PROP_IS_FIXED
) >>= bIsFixed
;
93 SvxExtTimeField
* pData
= new SvxExtTimeField(aTime
, bIsFixed
? SVXTIMETYPE_FIX
: SVXTIMETYPE_VAR
);
95 sal_Int32 nNumFmt
= -1;
96 xPropSet
->getPropertyValue(UNO_TC_PROP_NUMFORMAT
) >>= nNumFmt
;
97 if (nNumFmt
>= SVXTIMEFORMAT_APPDEFAULT
&& nNumFmt
<= SVXTIMEFORMAT_AM_HMSH
)
98 pData
->SetFormat(static_cast<SvxTimeFormat
>(nNumFmt
));
103 return new SvxTimeField();
105 case text::textfield::Type::URL
:
107 OUString aRep
, aTarget
, aURL
;
109 xPropSet
->getPropertyValue(UNO_TC_PROP_URL_REPRESENTATION
) >>= aRep
;
110 xPropSet
->getPropertyValue(UNO_TC_PROP_URL_TARGET
) >>= aTarget
;
111 xPropSet
->getPropertyValue(UNO_TC_PROP_URL
) >>= aURL
;
112 xPropSet
->getPropertyValue(UNO_TC_PROP_URL_FORMAT
) >>= nFmt
;
113 SvxURLField
* pData
= new SvxURLField(aURL
, aRep
, aRep
.isEmpty() ? SVXURLFORMAT_URL
: SVXURLFORMAT_REPR
);
114 pData
->SetTargetFrame(aTarget
);
115 if (nFmt
>= SVXURLFORMAT_APPDEFAULT
&& nFmt
<= SVXURLFORMAT_REPR
)
116 pData
->SetFormat(static_cast<SvxURLFormat
>(nFmt
));
120 case text::textfield::Type::PAGE
:
121 return new SvxPageField();
122 case text::textfield::Type::PAGES
:
123 return new SvxPagesField();
124 case text::textfield::Type::DOCINFO_TITLE
:
125 return new SvxFileField();
126 case text::textfield::Type::TABLE
:
129 xPropSet
->getPropertyValue(UNO_TC_PROP_TABLE_POSITION
) >>= nTab
;
130 return new SvxTableField(nTab
);
132 case text::textfield::Type::EXTENDED_FILE
:
134 OUString aPresentation
;
135 sal_Bool bIsFixed
= false;
136 sal_Int16 nFmt
= text::FilenameDisplayFormat::FULL
;
137 xPropSet
->getPropertyValue(UNO_TC_PROP_IS_FIXED
) >>= bIsFixed
;
138 xPropSet
->getPropertyValue(UNO_TC_PROP_CURRENT_PRESENTATION
) >>= aPresentation
;
139 xPropSet
->getPropertyValue(UNO_TC_PROP_FILE_FORMAT
) >>= nFmt
;
141 SvxFileFormat eFmt
= SVXFILEFORMAT_NAME_EXT
;
144 case text::FilenameDisplayFormat::FULL
: eFmt
= SVXFILEFORMAT_FULLPATH
; break;
145 case text::FilenameDisplayFormat::PATH
: eFmt
= SVXFILEFORMAT_PATH
; break;
146 case text::FilenameDisplayFormat::NAME
: eFmt
= SVXFILEFORMAT_NAME
; break;
150 // pass fixed attribute to constructor
151 return new SvxExtFileField(
152 aPresentation
, bIsFixed
? SVXFILETYPE_FIX
: SVXFILETYPE_VAR
, eFmt
);
154 case text::textfield::Type::AUTHOR
:
156 sal_Bool bIsFixed
= false;
157 sal_Bool bFullName
= false;
159 OUString aPresentation
, aContent
, aFirstName
, aLastName
;
160 xPropSet
->getPropertyValue(UNO_TC_PROP_IS_FIXED
) >>= bIsFixed
;
161 xPropSet
->getPropertyValue(UNO_TC_PROP_AUTHOR_FULLNAME
) >>= bFullName
;
162 xPropSet
->getPropertyValue(UNO_TC_PROP_CURRENT_PRESENTATION
) >>= aPresentation
;
163 xPropSet
->getPropertyValue(UNO_TC_PROP_AUTHOR_CONTENT
) >>= aContent
;
164 xPropSet
->getPropertyValue(UNO_TC_PROP_AUTHOR_FORMAT
) >>= nFmt
;
166 // do we have CurrentPresentation given? Mimic behaviour of
167 // writer, which means: prefer CurrentPresentation over Content
168 // if both are given.
169 if (!aPresentation
.isEmpty())
170 aContent
= aPresentation
;
172 sal_Int32 nPos
= aContent
.lastIndexOf(sal_Unicode(' '), 0);
175 aFirstName
= aContent
.copy(0, nPos
);
176 aLastName
= aContent
.copy(nPos
+ 1);
180 aLastName
= aContent
;
183 // #92009# pass fixed attribute to constructor
184 SvxAuthorField
* pData
= new SvxAuthorField(
185 aFirstName
, aLastName
, OUString(), bIsFixed
? SVXAUTHORTYPE_FIX
: SVXAUTHORTYPE_VAR
);
189 pData
->SetFormat(SVXAUTHORFORMAT_SHORTNAME
);
191 else if (nFmt
>= SVXAUTHORFORMAT_FULLNAME
|| nFmt
<= SVXAUTHORFORMAT_SHORTNAME
)
193 pData
->SetFormat(static_cast<SvxAuthorFormat
>(nFmt
));
198 case text::textfield::Type::MEASURE
:
200 SdrMeasureFieldKind eKind
= SDRMEASUREFIELD_VALUE
;
202 xPropSet
->getPropertyValue(UNO_TC_PROP_MEASURE_KIND
) >>= nTmp
;
203 if (nTmp
== static_cast<sal_Int16
>(SDRMEASUREFIELD_UNIT
) ||
204 nTmp
== static_cast<sal_Int16
>(SDRMEASUREFIELD_ROTA90BLANCS
))
205 eKind
= static_cast<SdrMeasureFieldKind
>(nTmp
);
207 return new SdrMeasureField(eKind
);
209 case text::textfield::Type::PRESENTATION_HEADER
:
210 return new SvxHeaderField();
211 case text::textfield::Type::PRESENTATION_FOOTER
:
212 return new SvxFooterField();
213 case text::textfield::Type::PRESENTATION_DATE_TIME
:
214 return new SvxDateTimeField();
222 TYPEINIT1( SvxFieldItem
, SfxPoolItem
);
224 SV_IMPL_PERSIST1( SvxFieldData
, SvPersistBase
);
226 // -----------------------------------------------------------------------
228 SvxFieldData::SvxFieldData()
232 // -----------------------------------------------------------------------
234 SvxFieldData::~SvxFieldData()
238 // -----------------------------------------------------------------------
240 SvxFieldData
* SvxFieldData::Clone() const
242 return new SvxFieldData
;
245 // -----------------------------------------------------------------------
247 int SvxFieldData::operator==( const SvxFieldData
& rFld
) const
249 DBG_ASSERT( Type() == rFld
.Type(), "==: Different Types" );
251 return sal_True
; // Basic class is always the same.
254 // -----------------------------------------------------------------------
256 void SvxFieldData::Load( SvPersistStream
& /*rStm*/ )
260 // -----------------------------------------------------------------------
262 void SvxFieldData::Save( SvPersistStream
& /*rStm*/ )
267 MetaAction
* SvxFieldData::createBeginComment() const
269 return new MetaCommentAction( "FIELD_SEQ_BEGIN" );
272 MetaAction
* SvxFieldData::createEndComment() const
274 return new MetaCommentAction( "FIELD_SEQ_END" );
277 // -----------------------------------------------------------------------
279 SvxFieldItem::SvxFieldItem( SvxFieldData
* pFld
, const sal_uInt16 nId
) :
282 pField
= pFld
; // belongs directly to the item
285 // -----------------------------------------------------------------------
287 SvxFieldItem::SvxFieldItem( const SvxFieldData
& rField
, const sal_uInt16 nId
) :
290 pField
= rField
.Clone();
293 // -----------------------------------------------------------------------
295 SvxFieldItem::SvxFieldItem( const SvxFieldItem
& rItem
) :
296 SfxPoolItem ( rItem
)
298 pField
= rItem
.GetField() ? rItem
.GetField()->Clone() : 0;
301 // -----------------------------------------------------------------------
303 SvxFieldItem::~SvxFieldItem()
308 // -----------------------------------------------------------------------
310 SfxPoolItem
* SvxFieldItem::Clone( SfxItemPool
* ) const
312 return new SvxFieldItem(*this);
315 // -----------------------------------------------------------------------
317 SfxPoolItem
* SvxFieldItem::Create( SvStream
& rStrm
, sal_uInt16
) const
319 SvxFieldData
* pData
= 0;
320 SvPersistStream
aPStrm( GetClassManager(), &rStrm
);
324 aPStrm
.SetError( SVSTREAM_GENERALERROR
);
326 if ( aPStrm
.GetError() == ERRCODE_IO_NOFACTORY
)
327 aPStrm
.ResetError(); // Actually a code for that not all were read Attr ...
329 return new SvxFieldItem( pData
, Which() );
332 // -----------------------------------------------------------------------
334 SvStream
& SvxFieldItem::Store( SvStream
& rStrm
, sal_uInt16
/*nItemVersion*/ ) const
336 DBG_ASSERT( pField
, "SvxFieldItem::Store: Field?!" );
337 SvPersistStream
aPStrm( GetClassManager(), &rStrm
);
338 // The reset error in the above Create method did not exist in 3.1,
339 // therefore newer items can not be saved for 3.x-exports!
340 if ( ( rStrm
.GetVersion() <= SOFFICE_FILEFORMAT_31
) && pField
&&
341 pField
->GetClassId() == 50 /* SdrMeasureField */ )
343 // SvxFieldData not enough, because not registered on ClassMgr.
344 SvxURLField aDummyData
;
345 aPStrm
<< &aDummyData
;
353 // -----------------------------------------------------------------------
355 int SvxFieldItem::operator==( const SfxPoolItem
& rItem
) const
357 DBG_ASSERT( SfxPoolItem::operator==( rItem
), "unequal which or type" );
359 const SvxFieldData
* pOtherFld
= ((const SvxFieldItem
&)rItem
).GetField();
360 if ( !pField
&& !pOtherFld
)
363 if ( ( !pField
&& pOtherFld
) || ( pField
&& !pOtherFld
) )
366 return ( ( pField
->Type() == pOtherFld
->Type() )
367 && ( *pField
== *pOtherFld
) );
370 // =================================================================
371 // The following are the derivatives of SvxFieldData ...
372 // =================================================================
374 SV_IMPL_PERSIST1( SvxDateField
, SvxFieldData
);
376 // -----------------------------------------------------------------------
378 SvxDateField::SvxDateField()
380 nFixDate
= Date( Date::SYSTEM
).GetDate();
381 eType
= SVXDATETYPE_VAR
;
382 eFormat
= SVXDATEFORMAT_STDSMALL
;
385 // -----------------------------------------------------------------------
387 SvxDateField::SvxDateField( const Date
& rDate
, SvxDateType eT
, SvxDateFormat eF
)
389 nFixDate
= rDate
.GetDate();
394 // -----------------------------------------------------------------------
396 SvxFieldData
* SvxDateField::Clone() const
398 return new SvxDateField( *this );
401 // -----------------------------------------------------------------------
403 int SvxDateField::operator==( const SvxFieldData
& rOther
) const
405 if ( rOther
.Type() != Type() )
408 const SvxDateField
& rOtherFld
= (const SvxDateField
&) rOther
;
409 return ( ( nFixDate
== rOtherFld
.nFixDate
) &&
410 ( eType
== rOtherFld
.eType
) &&
411 ( eFormat
== rOtherFld
.eFormat
) );
414 // -----------------------------------------------------------------------
416 void SvxDateField::Load( SvPersistStream
& rStm
)
418 sal_uInt16 nType
, nFormat
;
424 eType
= (SvxDateType
)nType
;
425 eFormat
= (SvxDateFormat
)nFormat
;
428 // -----------------------------------------------------------------------
430 void SvxDateField::Save( SvPersistStream
& rStm
)
433 rStm
<< (sal_uInt16
)eType
;
434 rStm
<< (sal_uInt16
)eFormat
;
437 // -----------------------------------------------------------------------
439 OUString
SvxDateField::GetFormatted( SvNumberFormatter
& rFormatter
, LanguageType eLang
) const
441 Date
aDate( Date::EMPTY
);
442 if ( eType
== SVXDATETYPE_FIX
)
443 aDate
.SetDate( nFixDate
);
445 aDate
= Date( Date::SYSTEM
); // current date
447 return GetFormatted( aDate
, eFormat
, rFormatter
, eLang
);
450 OUString
SvxDateField::GetFormatted( Date
& aDate
, SvxDateFormat eFormat
, SvNumberFormatter
& rFormatter
, LanguageType eLang
)
452 if ( eFormat
== SVXDATEFORMAT_SYSTEM
)
454 OSL_FAIL( "SVXDATEFORMAT_SYSTEM not implemented!" );
455 eFormat
= SVXDATEFORMAT_STDSMALL
;
457 else if ( eFormat
== SVXDATEFORMAT_APPDEFAULT
)
459 OSL_FAIL( "SVXDATEFORMAT_APPDEFAULT: take them from where? ");
460 eFormat
= SVXDATEFORMAT_STDSMALL
;
463 sal_uLong nFormatKey
;
467 case SVXDATEFORMAT_STDSMALL
:
469 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYSTEM_SHORT
, eLang
);
471 case SVXDATEFORMAT_STDBIG
:
473 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYSTEM_LONG
, eLang
);
475 case SVXDATEFORMAT_A
:
477 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYS_DDMMYY
, eLang
);
479 case SVXDATEFORMAT_B
:
481 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYS_DDMMYYYY
, eLang
);
483 case SVXDATEFORMAT_C
:
485 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYS_DMMMYYYY
, eLang
);
487 case SVXDATEFORMAT_D
:
489 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYS_DMMMMYYYY
, eLang
);
491 case SVXDATEFORMAT_E
:
492 // The, 13. February 1996
493 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYS_NNDMMMMYYYY
, eLang
);
495 case SVXDATEFORMAT_F
:
496 // Tuesday, 13. February 1996
497 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYS_NNNNDMMMMYYYY
, eLang
);
500 nFormatKey
= rFormatter
.GetStandardFormat( NUMBERFORMAT_DATE
, eLang
);
503 double fDiffDate
= aDate
- *(rFormatter
.GetNullDate());
505 Color
* pColor
= NULL
;
506 rFormatter
.GetOutputString( fDiffDate
, nFormatKey
, aStr
, &pColor
);
510 MetaAction
* SvxDateField::createBeginComment() const
512 return new MetaCommentAction( "FIELD_SEQ_BEGIN" );
515 SV_IMPL_PERSIST1( SvxURLField
, SvxFieldData
);
517 // -----------------------------------------------------------------------
519 SvxURLField::SvxURLField()
521 eFormat
= SVXURLFORMAT_URL
;
524 // -----------------------------------------------------------------------
526 SvxURLField::SvxURLField( const OUString
& rURL
, const OUString
& rRepres
, SvxURLFormat eFmt
)
527 : aURL( rURL
), aRepresentation( rRepres
)
532 // -----------------------------------------------------------------------
534 SvxFieldData
* SvxURLField::Clone() const
536 return new SvxURLField( *this );
539 // -----------------------------------------------------------------------
541 int SvxURLField::operator==( const SvxFieldData
& rOther
) const
543 if ( rOther
.Type() != Type() )
546 const SvxURLField
& rOtherFld
= (const SvxURLField
&) rOther
;
547 return ( ( eFormat
== rOtherFld
.eFormat
) &&
548 ( aURL
== rOtherFld
.aURL
) &&
549 ( aRepresentation
== rOtherFld
.aRepresentation
) &&
550 ( aTargetFrame
== rOtherFld
.aTargetFrame
) );
553 // -----------------------------------------------------------------------
555 static void write_unicode( SvPersistStream
& rStm
, const OUString
& rString
)
557 sal_uInt16 nL
= sal::static_int_cast
<sal_uInt16
>(rString
.getLength());
559 //endian specific?, yipes!
560 rStm
.Write( rString
.getStr(), nL
*sizeof(sal_Unicode
) );
563 static OUString
read_unicode( SvPersistStream
& rStm
)
565 rtl_uString
*pStr
= NULL
;
570 pStr
= rtl_uString_alloc(nL
);
571 //endian specific?, yipes!
572 rStm
.Read(pStr
->buffer
, nL
*sizeof(sal_Unicode
));
574 //take ownership of buffer and return, otherwise return empty string
575 return pStr
? OUString(pStr
, SAL_NO_ACQUIRE
) : OUString();
578 void SvxURLField::Load( SvPersistStream
& rStm
)
580 sal_uInt16 nFormat
= 0;
583 eFormat
= (SvxURLFormat
)nFormat
;
585 aURL
= read_unicode( rStm
);
586 aRepresentation
= read_unicode( rStm
);
587 aTargetFrame
= read_unicode( rStm
);
590 // -----------------------------------------------------------------------
592 void SvxURLField::Save( SvPersistStream
& rStm
)
594 rStm
<< (sal_uInt16
)eFormat
;
596 write_unicode( rStm
, aURL
);
597 write_unicode( rStm
, aRepresentation
);
598 write_unicode( rStm
, aTargetFrame
);
601 MetaAction
* SvxURLField::createBeginComment() const
603 // #i46618# Adding target URL to metafile comment
604 return new MetaCommentAction( "FIELD_SEQ_BEGIN",
606 reinterpret_cast<const sal_uInt8
*>(aURL
.getStr()),
607 2*aURL
.getLength() );
610 // =================================================================
611 // The fields that were removed from Calc:
612 // =================================================================
614 SV_IMPL_PERSIST1( SvxPageField
, SvxFieldData
);
616 SvxPageField::SvxPageField() {}
618 SvxFieldData
* SvxPageField::Clone() const
620 return new SvxPageField
; // empty
623 int SvxPageField::operator==( const SvxFieldData
& rCmp
) const
625 return ( rCmp
.Type() == TYPE(SvxPageField
) );
628 void SvxPageField::Load( SvPersistStream
& /*rStm*/ )
632 void SvxPageField::Save( SvPersistStream
& /*rStm*/ )
636 MetaAction
* SvxPageField::createBeginComment() const
638 return new MetaCommentAction( "FIELD_SEQ_BEGIN;PageField" );
642 SV_IMPL_PERSIST1( SvxPagesField
, SvxFieldData
);
644 SvxPagesField::SvxPagesField() {}
646 SvxFieldData
* SvxPagesField::Clone() const
648 return new SvxPagesField
; // empty
651 int SvxPagesField::operator==( const SvxFieldData
& rCmp
) const
653 return ( rCmp
.Type() == TYPE(SvxPagesField
) );
656 void SvxPagesField::Load( SvPersistStream
& /*rStm*/ )
660 void SvxPagesField::Save( SvPersistStream
& /*rStm*/ )
664 SV_IMPL_PERSIST1( SvxTimeField
, SvxFieldData
);
666 SvxTimeField::SvxTimeField() {}
668 SvxFieldData
* SvxTimeField::Clone() const
670 return new SvxTimeField
; // empty
673 int SvxTimeField::operator==( const SvxFieldData
& rCmp
) const
675 return ( rCmp
.Type() == TYPE(SvxTimeField
) );
678 void SvxTimeField::Load( SvPersistStream
& /*rStm*/ )
682 void SvxTimeField::Save( SvPersistStream
& /*rStm*/ )
686 MetaAction
* SvxTimeField::createBeginComment() const
688 return new MetaCommentAction( "FIELD_SEQ_BEGIN" );
691 SV_IMPL_PERSIST1( SvxFileField
, SvxFieldData
);
693 SvxFileField::SvxFileField() {}
695 SvxFieldData
* SvxFileField::Clone() const
697 return new SvxFileField
; // empty
700 int SvxFileField::operator==( const SvxFieldData
& rCmp
) const
702 return ( rCmp
.Type() == TYPE(SvxFileField
) );
705 void SvxFileField::Load( SvPersistStream
& /*rStm*/ )
709 void SvxFileField::Save( SvPersistStream
& /*rStm*/ )
713 SV_IMPL_PERSIST1( SvxTableField
, SvxFieldData
);
715 SvxTableField::SvxTableField() : mnTab(0) {}
717 SvxTableField::SvxTableField(int nTab
) : mnTab(nTab
) {}
719 void SvxTableField::SetTab(int nTab
)
724 int SvxTableField::GetTab() const
729 SvxFieldData
* SvxTableField::Clone() const
731 return new SvxTableField(mnTab
);
734 int SvxTableField::operator==( const SvxFieldData
& rCmp
) const
736 if (rCmp
.Type() != TYPE(SvxTableField
))
739 return mnTab
== static_cast<const SvxTableField
&>(rCmp
).mnTab
;
742 void SvxTableField::Load( SvPersistStream
& /*rStm*/ )
746 void SvxTableField::Save( SvPersistStream
& /*rStm*/ )
750 //----------------------------------------------------------------------------
752 //----------------------------------------------------------------------------
754 SV_IMPL_PERSIST1( SvxExtTimeField
, SvxFieldData
);
756 //----------------------------------------------------------------------------
758 SvxExtTimeField::SvxExtTimeField()
759 : m_nFixTime( Time(Time::SYSTEM
).GetTime() )
761 eType
= SVXTIMETYPE_VAR
;
762 eFormat
= SVXTIMEFORMAT_STANDARD
;
765 //----------------------------------------------------------------------------
767 SvxExtTimeField::SvxExtTimeField( const Time
& rTime
, SvxTimeType eT
, SvxTimeFormat eF
)
768 : m_nFixTime( rTime
.GetTime() )
774 //----------------------------------------------------------------------------
776 SvxFieldData
* SvxExtTimeField::Clone() const
778 return new SvxExtTimeField( *this );
781 //----------------------------------------------------------------------------
783 int SvxExtTimeField::operator==( const SvxFieldData
& rOther
) const
785 if ( rOther
.Type() != Type() )
788 const SvxExtTimeField
& rOtherFld
= (const SvxExtTimeField
&) rOther
;
789 return ((m_nFixTime
== rOtherFld
.m_nFixTime
) &&
790 ( eType
== rOtherFld
.eType
) &&
791 ( eFormat
== rOtherFld
.eFormat
) );
794 //----------------------------------------------------------------------------
796 void SvxExtTimeField::Load( SvPersistStream
& rStm
)
798 sal_uInt16 nType
, nFormat
;
800 rStm
.ReadInt64(m_nFixTime
);
804 eType
= (SvxTimeType
) nType
;
805 eFormat
= (SvxTimeFormat
) nFormat
;
808 //----------------------------------------------------------------------------
810 void SvxExtTimeField::Save( SvPersistStream
& rStm
)
812 rStm
.WriteInt64(m_nFixTime
);
813 rStm
<< (sal_uInt16
) eType
;
814 rStm
<< (sal_uInt16
) eFormat
;
817 //----------------------------------------------------------------------------
819 OUString
SvxExtTimeField::GetFormatted( SvNumberFormatter
& rFormatter
, LanguageType eLang
) const
821 Time
aTime( Time::EMPTY
);
822 if ( eType
== SVXTIMETYPE_FIX
)
823 aTime
.SetTime(m_nFixTime
);
825 aTime
= Time( Time::SYSTEM
); // current time
826 return GetFormatted( aTime
, eFormat
, rFormatter
, eLang
);
829 OUString
SvxExtTimeField::GetFormatted( Time
& aTime
, SvxTimeFormat eFormat
, SvNumberFormatter
& rFormatter
, LanguageType eLang
)
833 case SVXTIMEFORMAT_SYSTEM
:
834 OSL_FAIL( "SVXTIMEFORMAT_SYSTEM: not implemented" );
835 eFormat
= SVXTIMEFORMAT_STANDARD
;
837 case SVXTIMEFORMAT_APPDEFAULT
:
838 OSL_FAIL( "SVXTIMEFORMAT_APPDEFAULT: not implemented" );
839 eFormat
= SVXTIMEFORMAT_STANDARD
;
841 default: ;//prevent warning
844 sal_uInt32 nFormatKey
;
848 case SVXTIMEFORMAT_12_HM
:
849 nFormatKey
= rFormatter
.GetFormatIndex( NF_TIME_HHMMAMPM
, eLang
);
851 case SVXTIMEFORMAT_12_HMSH
:
853 // no builtin format available, try to insert or reuse
854 OUString
aFormatCode( "HH:MM:SS.00 AM/PM" );
857 rFormatter
.PutandConvertEntry( aFormatCode
, nCheckPos
, nType
,
858 nFormatKey
, LANGUAGE_ENGLISH_US
, eLang
);
859 DBG_ASSERT( nCheckPos
== 0, "SVXTIMEFORMAT_12_HMSH: could not insert format code" );
862 nFormatKey
= rFormatter
.GetFormatIndex( NF_TIME_HH_MMSS00
, eLang
);
866 case SVXTIMEFORMAT_24_HM
:
867 nFormatKey
= rFormatter
.GetFormatIndex( NF_TIME_HHMM
, eLang
);
869 case SVXTIMEFORMAT_24_HMSH
:
870 nFormatKey
= rFormatter
.GetFormatIndex( NF_TIME_HH_MMSS00
, eLang
);
872 case SVXTIMEFORMAT_12_HMS
:
873 nFormatKey
= rFormatter
.GetFormatIndex( NF_TIME_HHMMSSAMPM
, eLang
);
875 case SVXTIMEFORMAT_24_HMS
:
876 nFormatKey
= rFormatter
.GetFormatIndex( NF_TIME_HHMMSS
, eLang
);
878 case SVXTIMEFORMAT_STANDARD
:
880 nFormatKey
= rFormatter
.GetStandardFormat( NUMBERFORMAT_TIME
, eLang
);
883 double fFracTime
= aTime
.GetTimeInDays();
885 Color
* pColor
= NULL
;
886 rFormatter
.GetOutputString( fFracTime
, nFormatKey
, aStr
, &pColor
);
890 MetaAction
* SvxExtTimeField::createBeginComment() const
892 return new MetaCommentAction( "FIELD_SEQ_BEGIN" );
895 //----------------------------------------------------------------------------
897 //----------------------------------------------------------------------------
899 SV_IMPL_PERSIST1( SvxExtFileField
, SvxFieldData
);
901 //----------------------------------------------------------------------------
903 SvxExtFileField::SvxExtFileField()
905 eType
= SVXFILETYPE_VAR
;
906 eFormat
= SVXFILEFORMAT_FULLPATH
;
909 //----------------------------------------------------------------------------
911 SvxExtFileField::SvxExtFileField( const OUString
& rStr
, SvxFileType eT
, SvxFileFormat eF
)
918 //----------------------------------------------------------------------------
920 SvxFieldData
* SvxExtFileField::Clone() const
922 return new SvxExtFileField( *this );
925 //----------------------------------------------------------------------------
927 int SvxExtFileField::operator==( const SvxFieldData
& rOther
) const
929 if ( rOther
.Type() != Type() )
932 const SvxExtFileField
& rOtherFld
= (const SvxExtFileField
&) rOther
;
933 return ( ( aFile
== rOtherFld
.aFile
) &&
934 ( eType
== rOtherFld
.eType
) &&
935 ( eFormat
== rOtherFld
.eFormat
) );
938 //----------------------------------------------------------------------------
940 void SvxExtFileField::Load( SvPersistStream
& rStm
)
942 sal_uInt16 nType
, nFormat
;
944 // UNICODE: rStm >> aFile;
945 aFile
= rStm
.ReadUniOrByteString(rStm
.GetStreamCharSet());
950 eType
= (SvxFileType
) nType
;
951 eFormat
= (SvxFileFormat
) nFormat
;
954 //----------------------------------------------------------------------------
956 void SvxExtFileField::Save( SvPersistStream
& rStm
)
958 // UNICODE: rStm << aFile;
959 rStm
.WriteUniOrByteString(aFile
, rStm
.GetStreamCharSet());
961 rStm
<< (sal_uInt16
) eType
;
962 rStm
<< (sal_uInt16
) eFormat
;
965 //----------------------------------------------------------------------------
967 OUString
SvxExtFileField::GetFormatted() const
971 INetURLObject
aURLObj( aFile
);
973 if( INET_PROT_NOT_VALID
== aURLObj
.GetProtocol() )
975 // invalid? try to interpret string as system file name
978 ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFile
, aURLStr
);
980 aURLObj
.SetURL( aURLStr
);
983 // #92009# Be somewhat liberate when trying to
984 // get formatted content out of the FileField
985 if( INET_PROT_NOT_VALID
== aURLObj
.GetProtocol() )
987 // still not valid? Then output as is
990 else if( INET_PROT_FILE
== aURLObj
.GetProtocol() )
994 case SVXFILEFORMAT_FULLPATH
:
995 aString
= aURLObj
.getFSysPath(INetURLObject::FSYS_DETECT
);
998 case SVXFILEFORMAT_PATH
:
999 aURLObj
.removeSegment(INetURLObject::LAST_SEGMENT
, false);
1000 // #101742# Leave trailing slash at the pathname
1001 aURLObj
.setFinalSlash();
1002 aString
= aURLObj
.getFSysPath(INetURLObject::FSYS_DETECT
);
1005 case SVXFILEFORMAT_NAME
:
1006 aString
= aURLObj
.getBase(INetURLObject::LAST_SEGMENT
,true,INetURLObject::DECODE_UNAMBIGUOUS
);
1009 case SVXFILEFORMAT_NAME_EXT
:
1010 aString
= aURLObj
.getName(INetURLObject::LAST_SEGMENT
,true,INetURLObject::DECODE_UNAMBIGUOUS
);
1018 case SVXFILEFORMAT_FULLPATH
:
1019 aString
= aURLObj
.GetMainURL( INetURLObject::DECODE_TO_IURI
);
1022 case SVXFILEFORMAT_PATH
:
1023 aURLObj
.removeSegment(INetURLObject::LAST_SEGMENT
, false);
1024 // #101742# Leave trailing slash at the pathname
1025 aURLObj
.setFinalSlash();
1026 aString
= aURLObj
.GetMainURL( INetURLObject::DECODE_TO_IURI
);
1029 case SVXFILEFORMAT_NAME
:
1030 aString
= aURLObj
.getBase();
1033 case SVXFILEFORMAT_NAME_EXT
:
1034 aString
= aURLObj
.getName();
1042 //----------------------------------------------------------------------------
1044 //----------------------------------------------------------------------------
1046 SV_IMPL_PERSIST1( SvxAuthorField
, SvxFieldData
);
1048 //----------------------------------------------------------------------------
1050 SvxAuthorField::SvxAuthorField()
1052 eType
= SVXAUTHORTYPE_VAR
;
1053 eFormat
= SVXAUTHORFORMAT_FULLNAME
;
1056 //----------------------------------------------------------------------------
1058 SvxAuthorField::SvxAuthorField( const OUString
& rFirstName
,
1059 const OUString
& rLastName
,
1060 const OUString
& rShortName
,
1061 SvxAuthorType eT
, SvxAuthorFormat eF
)
1064 aFirstName
= rFirstName
;
1065 aShortName
= rShortName
;
1070 //----------------------------------------------------------------------------
1072 SvxFieldData
* SvxAuthorField::Clone() const
1074 return new SvxAuthorField( *this );
1077 //----------------------------------------------------------------------------
1079 int SvxAuthorField::operator==( const SvxFieldData
& rOther
) const
1081 if ( rOther
.Type() != Type() )
1084 const SvxAuthorField
& rOtherFld
= (const SvxAuthorField
&) rOther
;
1085 return ( ( aName
== rOtherFld
.aName
) &&
1086 ( aFirstName
== rOtherFld
.aFirstName
) &&
1087 ( aShortName
== rOtherFld
.aShortName
) &&
1088 ( eType
== rOtherFld
.eType
) &&
1089 ( eFormat
== rOtherFld
.eFormat
) );
1092 //----------------------------------------------------------------------------
1094 void SvxAuthorField::Load( SvPersistStream
& rStm
)
1096 sal_uInt16 nType
= 0, nFormat
= 0;
1098 aName
= read_unicode( rStm
);
1099 aFirstName
= read_unicode( rStm
);
1100 aShortName
= read_unicode( rStm
);
1105 eType
= (SvxAuthorType
) nType
;
1106 eFormat
= (SvxAuthorFormat
) nFormat
;
1109 //----------------------------------------------------------------------------
1111 void SvxAuthorField::Save( SvPersistStream
& rStm
)
1113 write_unicode( rStm
, aName
);
1114 write_unicode( rStm
, aFirstName
);
1115 write_unicode( rStm
, aShortName
);
1117 rStm
<< (sal_uInt16
) eType
;
1118 rStm
<< (sal_uInt16
) eFormat
;
1121 //----------------------------------------------------------------------------
1123 OUString
SvxAuthorField::GetFormatted() const
1129 case SVXAUTHORFORMAT_FULLNAME
:
1131 OUStringBuffer
aBuf(aFirstName
);
1132 aBuf
.append(sal_Unicode(' '));
1134 aString
= aBuf
.makeStringAndClear();
1137 case SVXAUTHORFORMAT_NAME
:
1141 case SVXAUTHORFORMAT_FIRSTNAME
:
1142 aString
= aFirstName
;
1145 case SVXAUTHORFORMAT_SHORTNAME
:
1146 aString
= aShortName
;
1153 static SvClassManager
* pClassMgr
=0;
1155 SvClassManager
& SvxFieldItem::GetClassManager()
1159 pClassMgr
= new SvClassManager
;
1160 pClassMgr
->Register(SvxFieldData::StaticClassId(), SvxFieldData::CreateInstance
);
1161 pClassMgr
->Register(SvxURLField::StaticClassId(), SvxURLField::CreateInstance
);
1162 pClassMgr
->Register(SvxDateField::StaticClassId(), SvxDateField::CreateInstance
);
1163 pClassMgr
->Register(SvxPageField::StaticClassId(), SvxPageField::CreateInstance
);
1164 pClassMgr
->Register(SvxTimeField::StaticClassId(), SvxTimeField::CreateInstance
);
1165 pClassMgr
->Register(SvxExtTimeField::StaticClassId(), SvxExtTimeField::CreateInstance
);
1166 pClassMgr
->Register(SvxExtFileField::StaticClassId(), SvxExtFileField::CreateInstance
);
1167 pClassMgr
->Register(SvxAuthorField::StaticClassId(), SvxAuthorField::CreateInstance
);
1173 ///////////////////////////////////////////////////////////////////////
1175 SV_IMPL_PERSIST1( SvxHeaderField
, SvxFieldData
);
1177 SvxHeaderField::SvxHeaderField() {}
1179 SvxFieldData
* SvxHeaderField::Clone() const
1181 return new SvxHeaderField
; // empty
1184 int SvxHeaderField::operator==( const SvxFieldData
& rCmp
) const
1186 return ( rCmp
.Type() == TYPE(SvxHeaderField
) );
1189 void SvxHeaderField::Load( SvPersistStream
& /*rStm*/ )
1193 void SvxHeaderField::Save( SvPersistStream
& /*rStm*/ )
1197 ///////////////////////////////////////////////////////////////////////
1199 SV_IMPL_PERSIST1( SvxFooterField
, SvxFieldData
);
1200 SvxFooterField::SvxFooterField() {}
1202 SvxFieldData
* SvxFooterField::Clone() const
1204 return new SvxFooterField
; // empty
1207 int SvxFooterField::operator==( const SvxFieldData
& rCmp
) const
1209 return ( rCmp
.Type() == TYPE(SvxFooterField
) );
1212 void SvxFooterField::Load( SvPersistStream
& /*rStm*/ )
1216 void SvxFooterField::Save( SvPersistStream
& /*rStm*/ )
1220 ///////////////////////////////////////////////////////////////////////
1222 SV_IMPL_PERSIST1( SvxDateTimeField
, SvxFieldData
);
1224 SvxFieldData
* SvxDateTimeField::Clone() const
1226 return new SvxDateTimeField
; // empty
1229 int SvxDateTimeField::operator==( const SvxFieldData
& rCmp
) const
1231 return ( rCmp
.Type() == TYPE(SvxDateTimeField
) );
1234 void SvxDateTimeField::Load( SvPersistStream
& /*rStm*/ )
1238 void SvxDateTimeField::Save( SvPersistStream
& /*rStm*/ )
1242 SvxDateTimeField::SvxDateTimeField() {}
1244 OUString
SvxDateTimeField::GetFormatted(
1245 Date
& rDate
, Time
& rTime
, int eFormat
, SvNumberFormatter
& rFormatter
, LanguageType eLanguage
)
1249 SvxDateFormat eDateFormat
= (SvxDateFormat
)(eFormat
& 0x0f);
1253 aRet
= SvxDateField::GetFormatted( rDate
, eDateFormat
, rFormatter
, eLanguage
);
1256 SvxTimeFormat eTimeFormat
= (SvxTimeFormat
)((eFormat
>> 4) & 0x0f);
1260 OUStringBuffer
aBuf(aRet
);
1262 if (!aRet
.isEmpty())
1263 aBuf
.append(sal_Unicode(' '));
1266 SvxExtTimeField::GetFormatted(rTime
, eTimeFormat
, rFormatter
, eLanguage
));
1268 aRet
= aBuf
.makeStringAndClear();
1274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */