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 <osl/file.hxx>
22 #include <vcl/metaact.hxx>
23 #include <svl/numformat.hxx>
24 #include <svl/zforlist.hxx>
25 #include <tools/urlobj.hxx>
27 #include <editeng/flditem.hxx>
28 #include <editeng/CustomPropertyField.hxx>
29 #include <editeng/measfld.hxx>
30 #include <editeng/unonames.hxx>
32 #include <tools/debug.hxx>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/text/XTextContent.hpp>
36 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
37 #include <com/sun/star/util/DateTime.hpp>
39 using namespace com::sun::star
;
41 SvxFieldData
* SvxFieldData::Create(const uno::Reference
<text::XTextContent
>& xTextContent
)
43 uno::Reference
<beans::XPropertySet
> xPropSet(xTextContent
, uno::UNO_QUERY
);
47 // we do not support these fields from Writer, so make sure we do not throw
48 // here - see fdo#63436 how to possibly extend Writer to make use of this
51 aAny
= xPropSet
->getPropertyValue(UNO_TC_PROP_TEXTFIELD_TYPE
);
52 if ( !aAny
.has
<sal_Int32
>() )
55 sal_Int32 nFieldType
= aAny
.get
<sal_Int32
>();
59 case text::textfield::Type::TIME
:
60 case text::textfield::Type::EXTENDED_TIME
:
61 case text::textfield::Type::DATE
:
64 xPropSet
->getPropertyValue(UNO_TC_PROP_IS_DATE
) >>= bIsDate
;
68 util::DateTime aDateTime
= xPropSet
->getPropertyValue(UNO_TC_PROP_DATE_TIME
).get
<util::DateTime
>();
69 Date
aDate(aDateTime
.Day
, aDateTime
.Month
, aDateTime
.Year
);
70 bool bIsFixed
= false;
71 xPropSet
->getPropertyValue(UNO_TC_PROP_IS_FIXED
) >>= bIsFixed
;
73 SvxDateField
* pData
= new SvxDateField(aDate
, bIsFixed
? SvxDateType::Fix
: SvxDateType::Var
);
74 sal_Int32 nNumFmt
= -1;
75 xPropSet
->getPropertyValue(UNO_TC_PROP_NUMFORMAT
) >>= nNumFmt
;
76 if (static_cast<SvxDateFormat
>(nNumFmt
) >= SvxDateFormat::AppDefault
&&
77 static_cast<SvxDateFormat
>(nNumFmt
) <= SvxDateFormat::F
)
78 pData
->SetFormat(static_cast<SvxDateFormat
>(nNumFmt
));
83 if (nFieldType
!= text::textfield::Type::TIME
)
85 util::DateTime aDateTime
= xPropSet
->getPropertyValue(UNO_TC_PROP_DATE_TIME
).get
<util::DateTime
>();
86 tools::Time
aTime(aDateTime
);
88 bool bIsFixed
= false;
89 xPropSet
->getPropertyValue(UNO_TC_PROP_IS_FIXED
) >>= bIsFixed
;
91 SvxExtTimeField
* pData
= new SvxExtTimeField(aTime
, bIsFixed
? SvxTimeType::Fix
: SvxTimeType::Var
);
93 sal_Int32 nNumFmt
= -1;
94 xPropSet
->getPropertyValue(UNO_TC_PROP_NUMFORMAT
) >>= nNumFmt
;
95 if (static_cast<SvxTimeFormat
>(nNumFmt
) >= SvxTimeFormat::AppDefault
&&
96 static_cast<SvxTimeFormat
>(nNumFmt
) <= SvxTimeFormat::HH12_MM_SS_00_AMPM
)
97 pData
->SetFormat(static_cast<SvxTimeFormat
>(nNumFmt
));
102 return new SvxTimeField();
104 case text::textfield::Type::URL
:
106 OUString aRep
, aTarget
, aURL
;
108 xPropSet
->getPropertyValue(UNO_TC_PROP_URL_REPRESENTATION
) >>= aRep
;
109 xPropSet
->getPropertyValue(UNO_TC_PROP_URL_TARGET
) >>= aTarget
;
110 xPropSet
->getPropertyValue(UNO_TC_PROP_URL
) >>= aURL
;
111 xPropSet
->getPropertyValue(UNO_TC_PROP_URL_FORMAT
) >>= nFmt
;
112 SvxURLField
* pData
= new SvxURLField(aURL
, aRep
, aRep
.isEmpty() ? SvxURLFormat::Url
: SvxURLFormat::Repr
);
113 pData
->SetTargetFrame(aTarget
);
114 if (static_cast<SvxURLFormat
>(nFmt
) >= SvxURLFormat::AppDefault
&&
115 static_cast<SvxURLFormat
>(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::PAGE_NAME
:
125 return new SvxPageTitleField();
126 case text::textfield::Type::DOCINFO_TITLE
:
127 return new SvxFileField();
128 case text::textfield::Type::TABLE
:
131 xPropSet
->getPropertyValue(UNO_TC_PROP_TABLE_POSITION
) >>= nTab
;
132 return new SvxTableField(nTab
);
134 case text::textfield::Type::EXTENDED_FILE
:
136 OUString aPresentation
;
137 bool bIsFixed
= false;
138 sal_Int16 nFmt
= text::FilenameDisplayFormat::FULL
;
139 xPropSet
->getPropertyValue(UNO_TC_PROP_IS_FIXED
) >>= bIsFixed
;
140 xPropSet
->getPropertyValue(UNO_TC_PROP_CURRENT_PRESENTATION
) >>= aPresentation
;
141 xPropSet
->getPropertyValue(UNO_TC_PROP_FILE_FORMAT
) >>= nFmt
;
143 SvxFileFormat eFmt
= SvxFileFormat::NameAndExt
;
146 case text::FilenameDisplayFormat::FULL
: eFmt
= SvxFileFormat::PathFull
; break;
147 case text::FilenameDisplayFormat::PATH
: eFmt
= SvxFileFormat::PathOnly
; break;
148 case text::FilenameDisplayFormat::NAME
: eFmt
= SvxFileFormat::NameOnly
; break;
152 // pass fixed attribute to constructor
153 return new SvxExtFileField(
154 aPresentation
, bIsFixed
? SvxFileType::Fix
: SvxFileType::Var
, eFmt
);
156 case text::textfield::Type::AUTHOR
:
158 bool bIsFixed
= false;
159 bool bFullName
= false;
161 OUString aPresentation
, aContent
, aFirstName
, aLastName
;
162 xPropSet
->getPropertyValue(UNO_TC_PROP_IS_FIXED
) >>= bIsFixed
;
163 xPropSet
->getPropertyValue(UNO_TC_PROP_AUTHOR_FULLNAME
) >>= bFullName
;
164 xPropSet
->getPropertyValue(UNO_TC_PROP_CURRENT_PRESENTATION
) >>= aPresentation
;
165 xPropSet
->getPropertyValue(UNO_TC_PROP_AUTHOR_CONTENT
) >>= aContent
;
166 xPropSet
->getPropertyValue(UNO_TC_PROP_AUTHOR_FORMAT
) >>= nFmt
;
168 // do we have CurrentPresentation given? Mimic behaviour of
169 // writer, which means: prefer CurrentPresentation over Content
170 // if both are given.
171 if (!aPresentation
.isEmpty())
172 aContent
= aPresentation
;
174 sal_Int32 nPos
= aContent
.lastIndexOf(' ', 0);
177 aFirstName
= aContent
.copy(0, nPos
);
178 aLastName
= aContent
.copy(nPos
+ 1);
182 aLastName
= aContent
;
185 // #92009# pass fixed attribute to constructor
186 SvxAuthorField
* pData
= new SvxAuthorField(
187 aFirstName
, aLastName
, OUString(), bIsFixed
? SvxAuthorType::Fix
: SvxAuthorType::Var
);
193 pData
->SetFormat(SvxAuthorFormat::ShortName
);
195 else if (static_cast<SvxAuthorFormat
>(nFmt
) >= SvxAuthorFormat::FullName
&&
196 static_cast<SvxAuthorFormat
>(nFmt
) <= SvxAuthorFormat::ShortName
)
198 pData
->SetFormat(static_cast<SvxAuthorFormat
>(nFmt
));
204 case text::textfield::Type::MEASURE
:
206 SdrMeasureFieldKind eKind
= SdrMeasureFieldKind::Value
;
208 xPropSet
->getPropertyValue(UNO_TC_PROP_MEASURE_KIND
) >>= nTmp
;
209 if (nTmp
== static_cast<sal_Int16
>(SdrMeasureFieldKind::Unit
) ||
210 nTmp
== static_cast<sal_Int16
>(SdrMeasureFieldKind::Rotate90Blanks
))
211 eKind
= static_cast<SdrMeasureFieldKind
>(nTmp
);
213 return new SdrMeasureField(eKind
);
215 case text::textfield::Type::PRESENTATION_HEADER
:
216 return new SvxHeaderField();
217 case text::textfield::Type::PRESENTATION_FOOTER
:
218 return new SvxFooterField();
219 case text::textfield::Type::PRESENTATION_DATE_TIME
:
220 return new SvxDateTimeField();
221 case text::textfield::Type::DOCINFO_CUSTOM
:
224 xPropSet
->getPropertyValue(UNO_TC_PROP_NAME
) >>= sName
;
226 OUString sCurrentPresentation
;
227 xPropSet
->getPropertyValue(UNO_TC_PROP_CURRENT_PRESENTATION
) >>= sCurrentPresentation
;
229 return new editeng::CustomPropertyField(sName
, sCurrentPresentation
);
234 } catch ( const beans::UnknownPropertyException
& )
243 SvxFieldData::SvxFieldData()
248 SvxFieldData::~SvxFieldData()
253 std::unique_ptr
<SvxFieldData
> SvxFieldData::Clone() const
255 return std::make_unique
<SvxFieldData
>();
259 bool SvxFieldData::operator==( const SvxFieldData
& rFld
) const
261 DBG_ASSERT( typeid(*this) == typeid(rFld
), "==: Different Types" );
263 return true; // Basic class is always the same.
267 MetaAction
* SvxFieldData::createBeginComment() const
269 return new MetaCommentAction( "FIELD_SEQ_BEGIN"_ostr
);
272 MetaAction
* SvxFieldData::createEndComment()
274 return new MetaCommentAction( "FIELD_SEQ_END"_ostr
);
278 SvxFieldItem::SvxFieldItem( std::unique_ptr
<SvxFieldData
> pField
, const sal_uInt16 nId
) :
280 , mpField( std::move(pField
) )
284 SvxFieldItem::SvxFieldItem( const SvxFieldData
& rField
, const sal_uInt16 nId
) :
286 , mpField( rField
.Clone() )
291 SvxFieldItem::SvxFieldItem( const SvxFieldItem
& rItem
) :
292 SfxPoolItem ( rItem
)
293 , mpField( rItem
.mpField
? rItem
.mpField
->Clone() : nullptr )
297 SvxFieldItem::~SvxFieldItem()
301 SvxFieldItem
* SvxFieldItem::Clone( SfxItemPool
* ) const
303 return new SvxFieldItem(*this);
306 bool SvxFieldItem::operator==( const SfxPoolItem
& rItem
) const
308 assert(SfxPoolItem::operator==(rItem
));
310 const SvxFieldData
* pOtherFld
= static_cast<const SvxFieldItem
&>(rItem
).GetField();
311 if( mpField
.get() == pOtherFld
)
313 if( mpField
== nullptr || pOtherFld
== nullptr )
315 return ( typeid(*mpField
) == typeid(*pOtherFld
) )
316 && ( *mpField
== *pOtherFld
);
320 // The following are the derivatives of SvxFieldData ...
323 SvxDateField::SvxDateField()
325 nFixDate
= Date( Date::SYSTEM
).GetDate();
326 eType
= SvxDateType::Var
;
327 eFormat
= SvxDateFormat::StdSmall
;
331 SvxDateField::SvxDateField( const Date
& rDate
, SvxDateType eT
, SvxDateFormat eF
)
333 nFixDate
= rDate
.GetDate();
339 std::unique_ptr
<SvxFieldData
> SvxDateField::Clone() const
341 return std::make_unique
<SvxDateField
>( *this );
345 bool SvxDateField::operator==( const SvxFieldData
& rOther
) const
347 if ( typeid(rOther
) != typeid(*this) )
350 const SvxDateField
& rOtherFld
= static_cast<const SvxDateField
&>(rOther
);
351 return ( ( nFixDate
== rOtherFld
.nFixDate
) &&
352 ( eType
== rOtherFld
.eType
) &&
353 ( eFormat
== rOtherFld
.eFormat
) );
358 OUString
SvxDateField::GetFormatted( SvNumberFormatter
& rFormatter
, LanguageType eLang
) const
360 Date
aDate( Date::EMPTY
);
361 if ( eType
== SvxDateType::Fix
)
362 aDate
.SetDate( nFixDate
);
364 aDate
= Date( Date::SYSTEM
); // current date
366 return GetFormatted( aDate
, eFormat
, rFormatter
, eLang
);
369 OUString
SvxDateField::GetFormatted( Date
const & aDate
, SvxDateFormat eFormat
, SvNumberFormatter
& rFormatter
, LanguageType eLang
)
371 if ( eFormat
== SvxDateFormat::System
)
373 OSL_FAIL( "SvxDateFormat::System not implemented!" );
374 eFormat
= SvxDateFormat::StdSmall
;
376 else if ( eFormat
== SvxDateFormat::AppDefault
)
378 OSL_FAIL( "SvxDateFormat::AppDefault: take them from where? ");
379 eFormat
= SvxDateFormat::StdSmall
;
382 sal_uInt32 nFormatKey
;
386 case SvxDateFormat::StdSmall
:
388 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYSTEM_SHORT
, eLang
);
390 case SvxDateFormat::StdBig
:
392 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYSTEM_LONG
, eLang
);
394 case SvxDateFormat::A
:
396 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYS_DDMMYY
, eLang
);
398 case SvxDateFormat::B
:
400 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYS_DDMMYYYY
, eLang
);
402 case SvxDateFormat::C
:
404 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYS_DMMMYYYY
, eLang
);
406 case SvxDateFormat::D
:
408 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYS_DMMMMYYYY
, eLang
);
410 case SvxDateFormat::E
:
411 // The, 13. February 1996
412 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYS_NNDMMMMYYYY
, eLang
);
414 case SvxDateFormat::F
:
415 // Tuesday, 13. February 1996
416 nFormatKey
= rFormatter
.GetFormatIndex( NF_DATE_SYS_NNNNDMMMMYYYY
, eLang
);
419 nFormatKey
= rFormatter
.GetStandardFormat( SvNumFormatType::DATE
, eLang
);
422 double fDiffDate
= aDate
- rFormatter
.GetNullDate();
424 const Color
* pColor
= nullptr;
425 rFormatter
.GetOutputString( fDiffDate
, nFormatKey
, aStr
, &pColor
);
429 MetaAction
* SvxDateField::createBeginComment() const
431 return new MetaCommentAction( "FIELD_SEQ_BEGIN"_ostr
);
434 SvxURLField::SvxURLField()
436 eFormat
= SvxURLFormat::Url
;
440 SvxURLField::SvxURLField( OUString _aURL
, OUString aRepres
, SvxURLFormat eFmt
)
441 : aURL(std::move( _aURL
)), aRepresentation(std::move( aRepres
))
447 std::unique_ptr
<SvxFieldData
> SvxURLField::Clone() const
449 return std::make_unique
<SvxURLField
>( *this );
453 bool SvxURLField::operator==( const SvxFieldData
& rOther
) const
455 if ( typeid(rOther
) != typeid(*this) )
458 const SvxURLField
& rOtherFld
= static_cast<const SvxURLField
&>(rOther
);
459 return ( ( eFormat
== rOtherFld
.eFormat
) &&
460 ( aURL
== rOtherFld
.aURL
) &&
461 ( aRepresentation
== rOtherFld
.aRepresentation
) &&
462 ( aTargetFrame
== rOtherFld
.aTargetFrame
) );
466 MetaAction
* SvxURLField::createBeginComment() const
468 // #i46618# Adding target URL to metafile comment
469 return new MetaCommentAction( "FIELD_SEQ_BEGIN"_ostr
,
471 reinterpret_cast<const sal_uInt8
*>(aURL
.getStr()),
472 2*aURL
.getLength() );
476 // SvxPageTitleField methods
479 SvxPageTitleField::SvxPageTitleField() {}
481 std::unique_ptr
<SvxFieldData
> SvxPageTitleField::Clone() const
483 return std::make_unique
<SvxPageTitleField
>();
486 bool SvxPageTitleField::operator==( const SvxFieldData
& rCmp
) const
488 return ( dynamic_cast< const SvxPageTitleField
*>(&rCmp
) != nullptr );
491 MetaAction
* SvxPageTitleField::createBeginComment() const
493 return new MetaCommentAction( "FIELD_SEQ_BEGIN;PageTitleField"_ostr
);
499 // The fields that were removed from Calc:
502 SvxPageField::SvxPageField() {}
504 std::unique_ptr
<SvxFieldData
> SvxPageField::Clone() const
506 return std::make_unique
<SvxPageField
>(); // empty
509 bool SvxPageField::operator==( const SvxFieldData
& rCmp
) const
511 return ( dynamic_cast< const SvxPageField
*>(&rCmp
) != nullptr );
514 MetaAction
* SvxPageField::createBeginComment() const
516 return new MetaCommentAction( "FIELD_SEQ_BEGIN;PageField"_ostr
);
520 SvxPagesField::SvxPagesField() {}
522 std::unique_ptr
<SvxFieldData
> SvxPagesField::Clone() const
524 return std::make_unique
<SvxPagesField
>(); // empty
527 bool SvxPagesField::operator==( const SvxFieldData
& rCmp
) const
529 return ( dynamic_cast< const SvxPagesField
*>(&rCmp
) != nullptr);
532 SvxTimeField::SvxTimeField() {}
534 std::unique_ptr
<SvxFieldData
> SvxTimeField::Clone() const
536 return std::make_unique
<SvxTimeField
>(); // empty
539 bool SvxTimeField::operator==( const SvxFieldData
& rCmp
) const
541 return ( dynamic_cast< const SvxTimeField
*>(&rCmp
) != nullptr);
544 MetaAction
* SvxTimeField::createBeginComment() const
546 return new MetaCommentAction( "FIELD_SEQ_BEGIN"_ostr
);
549 SvxFileField::SvxFileField() {}
551 std::unique_ptr
<SvxFieldData
> SvxFileField::Clone() const
553 return std::make_unique
<SvxFileField
>(); // empty
556 bool SvxFileField::operator==( const SvxFieldData
& rCmp
) const
558 return ( dynamic_cast< const SvxFileField
*>(&rCmp
) != nullptr );
561 SvxTableField::SvxTableField() : mnTab(0) {}
563 SvxTableField::SvxTableField(int nTab
) : mnTab(nTab
) {}
565 void SvxTableField::SetTab(int nTab
)
571 std::unique_ptr
<SvxFieldData
> SvxTableField::Clone() const
573 return std::make_unique
<SvxTableField
>(mnTab
);
576 bool SvxTableField::operator==( const SvxFieldData
& rCmp
) const
578 if (dynamic_cast<const SvxTableField
*>(&rCmp
) == nullptr)
581 return mnTab
== static_cast<const SvxTableField
&>(rCmp
).mnTab
;
587 SvxExtTimeField::SvxExtTimeField()
588 : m_nFixTime( tools::Time(tools::Time::SYSTEM
).GetTime() )
590 eType
= SvxTimeType::Var
;
591 eFormat
= SvxTimeFormat::Standard
;
595 SvxExtTimeField::SvxExtTimeField( const tools::Time
& rTime
, SvxTimeType eT
, SvxTimeFormat eF
)
596 : m_nFixTime( rTime
.GetTime() )
603 std::unique_ptr
<SvxFieldData
> SvxExtTimeField::Clone() const
605 return std::make_unique
<SvxExtTimeField
>( *this );
609 bool SvxExtTimeField::operator==( const SvxFieldData
& rOther
) const
611 if ( typeid(rOther
) != typeid(*this) )
614 const SvxExtTimeField
& rOtherFld
= static_cast<const SvxExtTimeField
&>(rOther
);
615 return ((m_nFixTime
== rOtherFld
.m_nFixTime
) &&
616 ( eType
== rOtherFld
.eType
) &&
617 ( eFormat
== rOtherFld
.eFormat
) );
621 OUString
SvxExtTimeField::GetFormatted( SvNumberFormatter
& rFormatter
, LanguageType eLang
) const
623 tools::Time
aTime( tools::Time::EMPTY
);
624 if ( eType
== SvxTimeType::Fix
)
625 aTime
.SetTime(m_nFixTime
);
627 aTime
= tools::Time( tools::Time::SYSTEM
); // current time
628 return GetFormatted( aTime
, eFormat
, rFormatter
, eLang
);
631 OUString
SvxExtTimeField::GetFormatted( tools::Time
const & aTime
, SvxTimeFormat eFormat
, SvNumberFormatter
& rFormatter
, LanguageType eLang
)
635 case SvxTimeFormat::System
:
636 OSL_FAIL( "SvxTimeFormat::System: not implemented" );
637 eFormat
= SvxTimeFormat::Standard
;
639 case SvxTimeFormat::AppDefault
:
640 OSL_FAIL( "SvxTimeFormat::AppDefault: not implemented" );
641 eFormat
= SvxTimeFormat::Standard
;
643 default: ;//prevent warning
646 sal_uInt32 nFormatKey
;
650 case SvxTimeFormat::HH12_MM
:
651 nFormatKey
= rFormatter
.GetFormatIndex( NF_TIME_HHMMAMPM
, eLang
);
653 case SvxTimeFormat::HH12_MM_SS_00
:
655 // no builtin format available, try to insert or reuse
656 OUString
aFormatCode( "HH:MM:SS.00 AM/PM" );
658 SvNumFormatType nType
;
659 rFormatter
.PutandConvertEntry( aFormatCode
, nCheckPos
, nType
,
660 nFormatKey
, LANGUAGE_ENGLISH_US
, eLang
, true);
661 DBG_ASSERT( nCheckPos
== 0, "SvxTimeFormat::HH12_MM_SS_00: could not insert format code" );
664 nFormatKey
= rFormatter
.GetFormatIndex( NF_TIME_HH_MMSS00
, eLang
);
668 case SvxTimeFormat::HH24_MM
:
669 nFormatKey
= rFormatter
.GetFormatIndex( NF_TIME_HHMM
, eLang
);
671 case SvxTimeFormat::HH24_MM_SS_00
:
672 nFormatKey
= rFormatter
.GetFormatIndex( NF_TIME_HH_MMSS00
, eLang
);
674 case SvxTimeFormat::HH12_MM_SS
:
675 nFormatKey
= rFormatter
.GetFormatIndex( NF_TIME_HHMMSSAMPM
, eLang
);
677 case SvxTimeFormat::HH24_MM_SS
:
678 nFormatKey
= rFormatter
.GetFormatIndex( NF_TIME_HHMMSS
, eLang
);
680 case SvxTimeFormat::Standard
:
682 nFormatKey
= rFormatter
.GetStandardFormat( SvNumFormatType::TIME
, eLang
);
685 double fFracTime
= aTime
.GetTimeInDays();
687 const Color
* pColor
= nullptr;
688 rFormatter
.GetOutputString( fFracTime
, nFormatKey
, aStr
, &pColor
);
692 MetaAction
* SvxExtTimeField::createBeginComment() const
694 return new MetaCommentAction( "FIELD_SEQ_BEGIN"_ostr
);
701 SvxExtFileField::SvxExtFileField()
703 eType
= SvxFileType::Var
;
704 eFormat
= SvxFileFormat::PathFull
;
708 SvxExtFileField::SvxExtFileField( const OUString
& rStr
, SvxFileType eT
, SvxFileFormat eF
)
716 std::unique_ptr
<SvxFieldData
> SvxExtFileField::Clone() const
718 return std::make_unique
<SvxExtFileField
>( *this );
722 bool SvxExtFileField::operator==( const SvxFieldData
& rOther
) const
724 if ( typeid(rOther
) != typeid(*this) )
727 const SvxExtFileField
& rOtherFld
= static_cast<const SvxExtFileField
&>(rOther
);
728 return ( ( aFile
== rOtherFld
.aFile
) &&
729 ( eType
== rOtherFld
.eType
) &&
730 ( eFormat
== rOtherFld
.eFormat
) );
734 OUString
SvxExtFileField::GetFormatted() const
738 INetURLObject
aURLObj( aFile
);
740 if( INetProtocol::NotValid
== aURLObj
.GetProtocol() )
742 // invalid? try to interpret string as system file name
745 osl::FileBase::getFileURLFromSystemPath( aFile
, aURLStr
);
747 aURLObj
.SetURL( aURLStr
);
750 // #92009# Be somewhat liberate when trying to
751 // get formatted content out of the FileField
752 if( INetProtocol::NotValid
== aURLObj
.GetProtocol() )
754 // still not valid? Then output as is
757 else if( INetProtocol::File
== aURLObj
.GetProtocol() )
761 case SvxFileFormat::PathFull
:
762 aString
= aURLObj
.getFSysPath(FSysStyle::Detect
);
765 case SvxFileFormat::PathOnly
:
766 aURLObj
.removeSegment(INetURLObject::LAST_SEGMENT
, false);
767 // #101742# Leave trailing slash at the pathname
768 aURLObj
.setFinalSlash();
769 aString
= aURLObj
.getFSysPath(FSysStyle::Detect
);
772 case SvxFileFormat::NameOnly
:
773 aString
= aURLObj
.getBase(INetURLObject::LAST_SEGMENT
,true,INetURLObject::DecodeMechanism::Unambiguous
);
776 case SvxFileFormat::NameAndExt
:
777 aString
= aURLObj
.getName(INetURLObject::LAST_SEGMENT
,true,INetURLObject::DecodeMechanism::Unambiguous
);
785 case SvxFileFormat::PathFull
:
786 aString
= aURLObj
.GetMainURL( INetURLObject::DecodeMechanism::ToIUri
);
789 case SvxFileFormat::PathOnly
:
790 aURLObj
.removeSegment(INetURLObject::LAST_SEGMENT
, false);
791 // #101742# Leave trailing slash at the pathname
792 aURLObj
.setFinalSlash();
793 aString
= aURLObj
.GetMainURL( INetURLObject::DecodeMechanism::ToIUri
);
796 case SvxFileFormat::NameOnly
:
797 aString
= aURLObj
.getBase();
800 case SvxFileFormat::NameAndExt
:
801 aString
= aURLObj
.getName();
813 SvxAuthorField::SvxAuthorField( const OUString
& rFirstName
,
814 const OUString
& rLastName
,
815 const OUString
& rShortName
,
816 SvxAuthorType eT
, SvxAuthorFormat eF
)
819 aFirstName
= rFirstName
;
820 aShortName
= rShortName
;
826 std::unique_ptr
<SvxFieldData
> SvxAuthorField::Clone() const
828 return std::make_unique
<SvxAuthorField
>( *this );
832 bool SvxAuthorField::operator==( const SvxFieldData
& rOther
) const
834 if ( typeid(rOther
) != typeid(*this) )
837 const SvxAuthorField
& rOtherFld
= static_cast<const SvxAuthorField
&>(rOther
);
838 return ( ( aName
== rOtherFld
.aName
) &&
839 ( aFirstName
== rOtherFld
.aFirstName
) &&
840 ( aShortName
== rOtherFld
.aShortName
) &&
841 ( eType
== rOtherFld
.eType
) &&
842 ( eFormat
== rOtherFld
.eFormat
) );
846 OUString
SvxAuthorField::GetFormatted() const
852 case SvxAuthorFormat::FullName
:
853 aString
= aFirstName
+ " " + aName
;
855 case SvxAuthorFormat::LastName
:
859 case SvxAuthorFormat::FirstName
:
860 aString
= aFirstName
;
863 case SvxAuthorFormat::ShortName
:
864 aString
= aShortName
;
871 SvxHeaderField::SvxHeaderField() {}
873 std::unique_ptr
<SvxFieldData
> SvxHeaderField::Clone() const
875 return std::make_unique
<SvxHeaderField
>(); // empty
878 bool SvxHeaderField::operator==( const SvxFieldData
& rCmp
) const
880 return ( dynamic_cast< const SvxHeaderField
*>(&rCmp
) != nullptr );
883 SvxFooterField::SvxFooterField() {}
885 std::unique_ptr
<SvxFieldData
> SvxFooterField::Clone() const
887 return std::make_unique
<SvxFooterField
>(); // empty
890 bool SvxFooterField::operator==( const SvxFieldData
& rCmp
) const
892 return ( dynamic_cast< const SvxFooterField
*>(&rCmp
) != nullptr );
895 std::unique_ptr
<SvxFieldData
> SvxDateTimeField::Clone() const
897 return std::make_unique
<SvxDateTimeField
>(); // empty
900 bool SvxDateTimeField::operator==( const SvxFieldData
& rCmp
) const
902 return ( dynamic_cast< const SvxDateTimeField
*>(&rCmp
) != nullptr );
905 SvxDateTimeField::SvxDateTimeField() {}
907 OUString
SvxDateTimeField::GetFormatted(
908 Date
const & rDate
, tools::Time
const & rTime
,
909 SvxDateFormat eDateFormat
, SvxTimeFormat eTimeFormat
,
910 SvNumberFormatter
& rFormatter
, LanguageType eLanguage
)
914 if(eDateFormat
!= SvxDateFormat::AppDefault
)
916 aRet
= SvxDateField::GetFormatted( rDate
, eDateFormat
, rFormatter
, eLanguage
);
919 if(eTimeFormat
!= SvxTimeFormat::AppDefault
)
921 OUStringBuffer
aBuf(aRet
);
927 SvxExtTimeField::GetFormatted(rTime
, eTimeFormat
, rFormatter
, eLanguage
));
929 aRet
= aBuf
.makeStringAndClear();
935 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */