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 .
19 #ifndef INCLUDED_EDITENG_FLDITEM_HXX
20 #define INCLUDED_EDITENG_FLDITEM_HXX
22 #include <i18nlangtag/lang.h>
23 #include <tools/time.hxx>
24 #include <tools/date.hxx>
25 #include <svl/poolitem.hxx>
26 #include <editeng/editengdllapi.h>
28 #include <com/sun/star/text/textfield/Type.hpp>
30 namespace com
{ namespace sun
{ namespace star
{ namespace text
{
36 class SvNumberFormatter
;
39 // class SvxFieldItem ---------------------------------------------------
42 class EDITENG_DLLPUBLIC SvxFieldData
45 static const sal_Int32 UNKNOWN_FIELD
;
47 static SvxFieldData
* Create(const css::uno::Reference
<css::text::XTextContent
>& xContent
);
49 static constexpr auto CLASS_ID
= css::text::textfield::Type::UNSPECIFIED
;
50 virtual sal_Int32
GetClassId() const { return CLASS_ID
; }
53 virtual ~SvxFieldData();
55 SvxFieldData(SvxFieldData
const &) = default;
56 SvxFieldData(SvxFieldData
&&) = default;
57 SvxFieldData
& operator =(SvxFieldData
const &) = default;
58 SvxFieldData
& operator =(SvxFieldData
&&) = default;
60 virtual std::unique_ptr
<SvxFieldData
> Clone() const;
61 virtual bool operator==( const SvxFieldData
& ) const;
63 virtual MetaAction
* createBeginComment() const;
64 static MetaAction
* createEndComment();
68 * This item stores a field (SvxFieldData). The field is controlled by or
69 * belongs to the item. The field itself is determined by a derivation from
72 class EDITENG_DLLPUBLIC SvxFieldItem
: public SfxPoolItem
74 std::unique_ptr
<SvxFieldData
> mpField
;
76 SvxFieldItem( std::unique_ptr
<SvxFieldData
> pField
, const sal_uInt16 nId
);
77 SvxFieldItem( const SvxFieldData
& rField
, const sal_uInt16 nId
);
78 SvxFieldItem( const SvxFieldItem
& rItem
);
79 virtual ~SvxFieldItem() override
;
81 virtual bool operator==( const SfxPoolItem
& ) const override
;
82 virtual SfxPoolItem
* Clone( SfxItemPool
*pPool
= nullptr ) const override
;
84 const SvxFieldData
* GetField() const { return mpField
.get(); }
88 // The following are the derivatives of SvxFieldData ...
91 enum class SvxDateType
{ Fix
, Var
};
92 enum class SvxDateFormat
{
93 AppDefault
= 0, // Set as in App
94 System
, // Set as in System
100 D
, // 13.February 1996
101 E
, // Tue, 13.February 1996
102 F
// Tuesday, 13.February 1996
105 class EDITENG_DLLPUBLIC SvxDateField
: public SvxFieldData
109 SvxDateFormat eFormat
;
112 static constexpr auto CLASS_ID
= css::text::textfield::Type::DATE
;
113 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
116 explicit SvxDateField( const Date
& rDate
,
118 SvxDateFormat eFormat
= SvxDateFormat::StdSmall
);
120 sal_Int32
GetFixDate() const { return nFixDate
; }
121 void SetFixDate( const Date
& rDate
) { nFixDate
= rDate
.GetDate(); }
123 SvxDateType
GetType() const { return eType
; }
124 void SetType( SvxDateType eTp
) { eType
= eTp
; }
126 SvxDateFormat
GetFormat() const { return eFormat
; }
127 void SetFormat( SvxDateFormat eFmt
) { eFormat
= eFmt
; }
129 // If eLanguage==LANGUAGE_DONTKNOW the language/country
130 // used in number formatter initialization is taken.
131 OUString
GetFormatted( SvNumberFormatter
& rFormatter
, LanguageType eLanguage
) const;
132 static OUString
GetFormatted( Date
const & rDate
, SvxDateFormat eFormat
, SvNumberFormatter
& rFormatter
, LanguageType eLanguage
);
134 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
135 virtual bool operator==( const SvxFieldData
& ) const override
;
137 virtual MetaAction
* createBeginComment() const override
;
141 enum class SvxURLFormat
{
142 AppDefault
= 0, // Set as in App
143 Url
, // Represent URL
144 Repr
// Constitute representation
147 class EDITENG_DLLPUBLIC SvxURLField
: public SvxFieldData
150 SvxURLFormat eFormat
;
151 OUString aURL
; // URL-Address
152 OUString aRepresentation
; // What is shown
153 OUString aTargetFrame
; // In what Frame
156 static constexpr auto CLASS_ID
= css::text::textfield::Type::URL
;
157 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
160 SvxURLField( const OUString
& rURL
, const OUString
& rRepres
, SvxURLFormat eFmt
= SvxURLFormat::Url
);
162 const OUString
& GetURL() const { return aURL
; }
163 void SetURL( const OUString
& rURL
) { aURL
= rURL
; }
165 const OUString
& GetRepresentation() const { return aRepresentation
; }
166 void SetRepresentation( const OUString
& rRep
) { aRepresentation
= rRep
; }
168 const OUString
& GetTargetFrame() const { return aTargetFrame
; }
169 void SetTargetFrame( const OUString
& rFrm
) { aTargetFrame
= rFrm
; }
171 SvxURLFormat
GetFormat() const { return eFormat
; }
172 void SetFormat( SvxURLFormat eFmt
) { eFormat
= eFmt
; }
174 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
175 virtual bool operator==( const SvxFieldData
& ) const override
;
177 virtual MetaAction
* createBeginComment() const override
;
180 class EDITENG_DLLPUBLIC SvxPageField final
: public SvxFieldData
183 virtual sal_Int32
GetClassId() const override
{ return css::text::textfield::Type::PAGE
; }
186 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
187 virtual bool operator==( const SvxFieldData
& ) const override
;
189 virtual MetaAction
* createBeginComment() const override
;
192 class EDITENG_DLLPUBLIC SvxPageTitleField final
: public SvxFieldData
195 static constexpr auto CLASS_ID
= css::text::textfield::Type::PAGE_NAME
;
196 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
199 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
200 virtual bool operator==( const SvxFieldData
& ) const override
;
202 virtual MetaAction
* createBeginComment() const override
;
205 class EDITENG_DLLPUBLIC SvxPagesField final
: public SvxFieldData
208 static constexpr auto CLASS_ID
= css::text::textfield::Type::PAGES
;
209 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
212 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
213 virtual bool operator==( const SvxFieldData
& ) const override
;
216 class EDITENG_DLLPUBLIC SvxTimeField final
: public SvxFieldData
219 static constexpr auto CLASS_ID
= css::text::textfield::Type::TIME
;
220 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
223 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
224 virtual bool operator==( const SvxFieldData
& ) const override
;
226 virtual MetaAction
* createBeginComment() const override
;
229 class EDITENG_DLLPUBLIC SvxFileField final
: public SvxFieldData
232 static constexpr auto CLASS_ID
= css::text::textfield::Type::DOCINFO_TITLE
;
233 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
236 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
237 virtual bool operator==( const SvxFieldData
& ) const override
;
240 class EDITENG_DLLPUBLIC SvxTableField final
: public SvxFieldData
244 static constexpr auto CLASS_ID
= css::text::textfield::Type::TABLE
;
245 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
247 explicit SvxTableField(int nTab
);
249 void SetTab(int nTab
);
250 int GetTab() const { return mnTab
;}
252 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
253 virtual bool operator==( const SvxFieldData
& ) const override
;
257 enum class SvxTimeType
{
261 enum class SvxTimeFormat
{
262 AppDefault
= 0, // Set as in App
263 System
, // Set as in System
266 HH24_MM_SS
, // 13:49:38
267 HH24_MM_SS_00
, // 13:49:38.78
269 HH12_MM_SS
, // 01:49:38
270 HH12_MM_SS_00
, // 01:49:38.78
271 HH12_MM_AMPM
, // 01:49 PM
272 HH12_MM_SS_AMPM
, // 01:49:38 PM
273 HH12_MM_SS_00_AMPM
// 01:49:38.78 PM
276 class EDITENG_DLLPUBLIC SvxExtTimeField
: public SvxFieldData
279 sal_Int64 m_nFixTime
;
281 SvxTimeFormat eFormat
;
284 static constexpr auto CLASS_ID
= css::text::textfield::Type::EXTENDED_TIME
;
285 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
287 explicit SvxExtTimeField( const tools::Time
& rTime
,
289 SvxTimeFormat eFormat
= SvxTimeFormat::Standard
);
291 sal_Int64
GetFixTime() const { return m_nFixTime
; }
292 void SetFixTime( const tools::Time
& rTime
) { m_nFixTime
= rTime
.GetTime(); }
294 SvxTimeType
GetType() const { return eType
; }
295 void SetType( SvxTimeType eTp
) { eType
= eTp
; }
297 SvxTimeFormat
GetFormat() const { return eFormat
; }
298 void SetFormat( SvxTimeFormat eFmt
) { eFormat
= eFmt
; }
300 // If eLanguage==LANGUAGE_DONTKNOW the language/country
301 // used in number formatter initialization is taken.
302 OUString
GetFormatted( SvNumberFormatter
& rFormatter
, LanguageType eLanguage
) const;
303 static OUString
GetFormatted( tools::Time
const & rTime
, SvxTimeFormat eFormat
, SvNumberFormatter
& rFormatter
, LanguageType eLanguage
);
305 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
306 virtual bool operator==( const SvxFieldData
& ) const override
;
308 virtual MetaAction
* createBeginComment() const override
;
312 enum class SvxFileType
{
316 enum class SvxFileFormat
{
317 NameAndExt
= 0, // File name with Extension
318 PathFull
, // full path
319 PathOnly
, // only path
320 NameOnly
// only file name
324 class EDITENG_DLLPUBLIC SvxExtFileField
: public SvxFieldData
329 SvxFileFormat eFormat
;
332 static constexpr auto CLASS_ID
= css::text::textfield::Type::EXTENDED_FILE
;
333 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
335 explicit SvxExtFileField( const OUString
& rString
,
336 SvxFileType eType
= SvxFileType::Var
,
337 SvxFileFormat eFormat
= SvxFileFormat::PathFull
);
339 const OUString
& GetFile() const { return aFile
; }
340 void SetFile( const OUString
& rString
) { aFile
= rString
; }
342 SvxFileType
GetType() const { return eType
; }
343 void SetType( SvxFileType eTp
) { eType
= eTp
; }
345 SvxFileFormat
GetFormat() const { return eFormat
; }
346 void SetFormat( SvxFileFormat eFmt
) { eFormat
= eFmt
; }
348 OUString
GetFormatted() const;
350 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
351 virtual bool operator==( const SvxFieldData
& ) const override
;
355 enum class SvxAuthorType
{
358 enum class SvxAuthorFormat
{
359 FullName
, // full name
360 LastName
, // Only Last name
361 FirstName
, // Only first name
362 ShortName
// Initials
365 class EDITENG_DLLPUBLIC SvxAuthorField
: public SvxFieldData
372 SvxAuthorFormat eFormat
;
375 static constexpr auto CLASS_ID
= css::text::textfield::Type::AUTHOR
;
376 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
378 const OUString
& rFirstName
,
379 const OUString
& rLastName
,
380 const OUString
& rShortName
,
381 SvxAuthorType eType
= SvxAuthorType::Var
,
382 SvxAuthorFormat eFormat
= SvxAuthorFormat::FullName
);
384 SvxAuthorType
GetType() const { return eType
; }
385 void SetType( SvxAuthorType eTp
) { eType
= eTp
; }
387 SvxAuthorFormat
GetFormat() const { return eFormat
; }
388 void SetFormat( SvxAuthorFormat eFmt
) { eFormat
= eFmt
; }
390 OUString
GetFormatted() const;
392 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
393 virtual bool operator==( const SvxFieldData
& ) const override
;
396 /** this field is used as a placeholder for a header&footer in impress. The actual
397 value is stored at the page */
398 class EDITENG_DLLPUBLIC SvxHeaderField final
: public SvxFieldData
401 static constexpr auto CLASS_ID
= css::text::textfield::Type::PRESENTATION_HEADER
;
402 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
405 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
406 virtual bool operator==( const SvxFieldData
& ) const override
;
409 /** this field is used as a placeholder for a header&footer in impress. The actual
410 value is stored at the page */
411 class EDITENG_DLLPUBLIC SvxFooterField final
: public SvxFieldData
414 static constexpr auto CLASS_ID
= css::text::textfield::Type::PRESENTATION_FOOTER
;
415 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
417 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
418 virtual bool operator==( const SvxFieldData
& ) const override
;
421 /** this field is used as a placeholder for a header&footer in impress. The actual
422 value is stored at the page */
423 class EDITENG_DLLPUBLIC SvxDateTimeField final
: public SvxFieldData
426 static constexpr auto CLASS_ID
= css::text::textfield::Type::PRESENTATION_DATE_TIME
;
427 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
430 static OUString
GetFormatted( Date
const & rDate
, tools::Time
const & rTime
,
431 SvxDateFormat eDateFormat
, SvxTimeFormat eTimeFormat
,
432 SvNumberFormatter
& rFormatter
, LanguageType eLanguage
);
434 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
435 virtual bool operator==( const SvxFieldData
& ) const override
;
441 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */