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::sun::star::text
{
34 class SvNumberFormatter
;
37 // class SvxFieldItem ---------------------------------------------------
40 class EDITENG_DLLPUBLIC SvxFieldData
44 static SvxFieldData
* Create(const css::uno::Reference
<css::text::XTextContent
>& xContent
);
46 static constexpr auto CLASS_ID
= css::text::textfield::Type::UNSPECIFIED
;
47 virtual sal_Int32
GetClassId() const { return CLASS_ID
; }
50 virtual ~SvxFieldData();
52 SvxFieldData(SvxFieldData
const &) = default;
53 SvxFieldData(SvxFieldData
&&) = default;
54 SvxFieldData
& operator =(SvxFieldData
const &) = default;
55 SvxFieldData
& operator =(SvxFieldData
&&) = default;
57 virtual std::unique_ptr
<SvxFieldData
> Clone() const;
58 virtual bool operator==( const SvxFieldData
& ) const;
60 virtual MetaAction
* createBeginComment() const;
61 static MetaAction
* createEndComment();
65 * This item stores a field (SvxFieldData). The field is controlled by or
66 * belongs to the item. The field itself is determined by a derivation from
69 class EDITENG_DLLPUBLIC SvxFieldItem final
: public SfxPoolItem
71 std::unique_ptr
<SvxFieldData
> mpField
;
73 SvxFieldItem( std::unique_ptr
<SvxFieldData
> pField
, const sal_uInt16 nId
);
74 SvxFieldItem( const SvxFieldData
& rField
, const sal_uInt16 nId
);
75 SvxFieldItem( const SvxFieldItem
& rItem
);
76 virtual ~SvxFieldItem() override
;
78 virtual bool operator==( const SfxPoolItem
& ) const override
;
79 virtual SvxFieldItem
* Clone( SfxItemPool
*pPool
= nullptr ) const override
;
81 const SvxFieldData
* GetField() const { return mpField
.get(); }
85 // The following are the derivatives of SvxFieldData ...
88 enum class SvxDateType
{ Fix
, Var
};
89 enum class SvxDateFormat
{
90 AppDefault
= 0, // Set as in App
91 System
, // Set as in System
97 D
, // 13.February 1996
98 E
, // Tue, 13.February 1996
99 F
// Tuesday, 13.February 1996
102 class EDITENG_DLLPUBLIC SvxDateField final
: public SvxFieldData
106 SvxDateFormat eFormat
;
109 static constexpr auto CLASS_ID
= css::text::textfield::Type::DATE
;
110 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
113 explicit SvxDateField( const Date
& rDate
,
115 SvxDateFormat eFormat
= SvxDateFormat::StdSmall
);
117 sal_Int32
GetFixDate() const { return nFixDate
; }
118 void SetFixDate( const Date
& rDate
) { nFixDate
= rDate
.GetDate(); }
120 SvxDateType
GetType() const { return eType
; }
121 void SetType( SvxDateType eTp
) { eType
= eTp
; }
123 SvxDateFormat
GetFormat() const { return eFormat
; }
124 void SetFormat( SvxDateFormat eFmt
) { eFormat
= eFmt
; }
126 // If eLanguage==LANGUAGE_DONTKNOW the language/country
127 // used in number formatter initialization is taken.
128 OUString
GetFormatted( SvNumberFormatter
& rFormatter
, LanguageType eLanguage
) const;
129 static OUString
GetFormatted( Date
const & rDate
, SvxDateFormat eFormat
, SvNumberFormatter
& rFormatter
, LanguageType eLanguage
);
131 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
132 virtual bool operator==( const SvxFieldData
& ) const override
;
134 virtual MetaAction
* createBeginComment() const override
;
138 enum class SvxURLFormat
{
139 AppDefault
= 0, // Set as in App
140 Url
, // Represent URL
141 Repr
// Constitute representation
144 class EDITENG_DLLPUBLIC SvxURLField final
: public SvxFieldData
147 SvxURLFormat eFormat
;
148 OUString aURL
; // URL-Address
149 OUString aRepresentation
; // What is shown
150 OUString aTargetFrame
; // In what Frame
153 static constexpr auto CLASS_ID
= css::text::textfield::Type::URL
;
154 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
157 SvxURLField( OUString aURL
, OUString aRepres
, SvxURLFormat eFmt
= SvxURLFormat::Url
);
159 const OUString
& GetURL() const { return aURL
; }
160 void SetURL( const OUString
& rURL
) { aURL
= rURL
; }
162 const OUString
& GetRepresentation() const { return aRepresentation
; }
163 void SetRepresentation( const OUString
& rRep
) { aRepresentation
= rRep
; }
165 const OUString
& GetTargetFrame() const { return aTargetFrame
; }
166 void SetTargetFrame( const OUString
& rFrm
) { aTargetFrame
= rFrm
; }
168 SvxURLFormat
GetFormat() const { return eFormat
; }
169 void SetFormat( SvxURLFormat eFmt
) { eFormat
= eFmt
; }
171 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
172 virtual bool operator==( const SvxFieldData
& ) const override
;
174 virtual MetaAction
* createBeginComment() const override
;
177 class EDITENG_DLLPUBLIC SvxPageField final
: public SvxFieldData
180 virtual sal_Int32
GetClassId() const override
{ return css::text::textfield::Type::PAGE
; }
183 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
184 virtual bool operator==( const SvxFieldData
& ) const override
;
186 virtual MetaAction
* createBeginComment() const override
;
189 class EDITENG_DLLPUBLIC SvxPageTitleField final
: public SvxFieldData
192 static constexpr auto CLASS_ID
= css::text::textfield::Type::PAGE_NAME
;
193 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
196 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
197 virtual bool operator==( const SvxFieldData
& ) const override
;
199 virtual MetaAction
* createBeginComment() const override
;
202 class EDITENG_DLLPUBLIC SvxPagesField final
: public SvxFieldData
205 static constexpr auto CLASS_ID
= css::text::textfield::Type::PAGES
;
206 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
209 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
210 virtual bool operator==( const SvxFieldData
& ) const override
;
213 class EDITENG_DLLPUBLIC SvxTimeField final
: public SvxFieldData
216 static constexpr auto CLASS_ID
= css::text::textfield::Type::TIME
;
217 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
220 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
221 virtual bool operator==( const SvxFieldData
& ) const override
;
223 virtual MetaAction
* createBeginComment() const override
;
226 class EDITENG_DLLPUBLIC SvxFileField final
: public SvxFieldData
229 static constexpr auto CLASS_ID
= css::text::textfield::Type::DOCINFO_TITLE
;
230 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
233 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
234 virtual bool operator==( const SvxFieldData
& ) const override
;
237 class EDITENG_DLLPUBLIC SvxTableField final
: public SvxFieldData
241 static constexpr auto CLASS_ID
= css::text::textfield::Type::TABLE
;
242 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
244 explicit SvxTableField(int nTab
);
246 void SetTab(int nTab
);
247 int GetTab() const { return mnTab
;}
249 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
250 virtual bool operator==( const SvxFieldData
& ) const override
;
254 enum class SvxTimeType
{
258 enum class SvxTimeFormat
{
259 AppDefault
= 0, // Set as in App
260 System
, // Set as in System
263 HH24_MM_SS
, // 13:49:38
264 HH24_MM_SS_00
, // 13:49:38.78
266 HH12_MM_SS
, // 01:49:38
267 HH12_MM_SS_00
, // 01:49:38.78
268 HH12_MM_AMPM
, // 01:49 PM
269 HH12_MM_SS_AMPM
, // 01:49:38 PM
270 HH12_MM_SS_00_AMPM
// 01:49:38.78 PM
273 class EDITENG_DLLPUBLIC SvxExtTimeField final
: public SvxFieldData
276 sal_Int64 m_nFixTime
;
278 SvxTimeFormat eFormat
;
281 static constexpr auto CLASS_ID
= css::text::textfield::Type::EXTENDED_TIME
;
282 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
284 explicit SvxExtTimeField( const tools::Time
& rTime
,
286 SvxTimeFormat eFormat
= SvxTimeFormat::Standard
);
288 sal_Int64
GetFixTime() const { return m_nFixTime
; }
289 void SetFixTime( const tools::Time
& rTime
) { m_nFixTime
= rTime
.GetTime(); }
291 SvxTimeType
GetType() const { return eType
; }
292 void SetType( SvxTimeType eTp
) { eType
= eTp
; }
294 SvxTimeFormat
GetFormat() const { return eFormat
; }
295 void SetFormat( SvxTimeFormat eFmt
) { eFormat
= eFmt
; }
297 // If eLanguage==LANGUAGE_DONTKNOW the language/country
298 // used in number formatter initialization is taken.
299 OUString
GetFormatted( SvNumberFormatter
& rFormatter
, LanguageType eLanguage
) const;
300 static OUString
GetFormatted( tools::Time
const & rTime
, SvxTimeFormat eFormat
, SvNumberFormatter
& rFormatter
, LanguageType eLanguage
);
302 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
303 virtual bool operator==( const SvxFieldData
& ) const override
;
305 virtual MetaAction
* createBeginComment() const override
;
309 enum class SvxFileType
{
313 enum class SvxFileFormat
{
314 NameAndExt
= 0, // File name with Extension
315 PathFull
, // full path
316 PathOnly
, // only path
317 NameOnly
// only file name
321 class EDITENG_DLLPUBLIC SvxExtFileField final
: public SvxFieldData
326 SvxFileFormat eFormat
;
329 static constexpr auto CLASS_ID
= css::text::textfield::Type::EXTENDED_FILE
;
330 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
332 explicit SvxExtFileField( const OUString
& rString
,
333 SvxFileType eType
= SvxFileType::Var
,
334 SvxFileFormat eFormat
= SvxFileFormat::PathFull
);
336 const OUString
& GetFile() const { return aFile
; }
337 void SetFile( const OUString
& rString
) { aFile
= rString
; }
339 SvxFileType
GetType() const { return eType
; }
340 void SetType( SvxFileType eTp
) { eType
= eTp
; }
342 SvxFileFormat
GetFormat() const { return eFormat
; }
343 void SetFormat( SvxFileFormat eFmt
) { eFormat
= eFmt
; }
345 OUString
GetFormatted() const;
347 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
348 virtual bool operator==( const SvxFieldData
& ) const override
;
352 enum class SvxAuthorType
{
355 enum class SvxAuthorFormat
{
356 FullName
, // full name
357 LastName
, // Only Last name
358 FirstName
, // Only first name
359 ShortName
// Initials
362 class EDITENG_DLLPUBLIC SvxAuthorField final
: public SvxFieldData
369 SvxAuthorFormat eFormat
;
372 static constexpr auto CLASS_ID
= css::text::textfield::Type::AUTHOR
;
373 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
375 const OUString
& rFirstName
,
376 const OUString
& rLastName
,
377 const OUString
& rShortName
,
378 SvxAuthorType eType
= SvxAuthorType::Var
,
379 SvxAuthorFormat eFormat
= SvxAuthorFormat::FullName
);
381 SvxAuthorType
GetType() const { return eType
; }
382 void SetType( SvxAuthorType eTp
) { eType
= eTp
; }
384 SvxAuthorFormat
GetFormat() const { return eFormat
; }
385 void SetFormat( SvxAuthorFormat eFmt
) { eFormat
= eFmt
; }
387 OUString
GetFormatted() const;
389 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
390 virtual bool operator==( const SvxFieldData
& ) const override
;
393 /** this field is used as a placeholder for a header&footer in impress. The actual
394 value is stored at the page */
395 class EDITENG_DLLPUBLIC SvxHeaderField final
: public SvxFieldData
398 static constexpr auto CLASS_ID
= css::text::textfield::Type::PRESENTATION_HEADER
;
399 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
402 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
403 virtual bool operator==( const SvxFieldData
& ) const override
;
406 /** this field is used as a placeholder for a header&footer in impress. The actual
407 value is stored at the page */
408 class EDITENG_DLLPUBLIC SvxFooterField final
: public SvxFieldData
411 static constexpr auto CLASS_ID
= css::text::textfield::Type::PRESENTATION_FOOTER
;
412 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
414 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
415 virtual bool operator==( const SvxFieldData
& ) const override
;
418 /** this field is used as a placeholder for a header&footer in impress. The actual
419 value is stored at the page */
420 class EDITENG_DLLPUBLIC SvxDateTimeField final
: public SvxFieldData
423 static constexpr auto CLASS_ID
= css::text::textfield::Type::PRESENTATION_DATE_TIME
;
424 virtual sal_Int32
GetClassId() const override
{ return CLASS_ID
; }
427 static OUString
GetFormatted( Date
const & rDate
, tools::Time
const & rTime
,
428 SvxDateFormat eDateFormat
, SvxTimeFormat eTimeFormat
,
429 SvNumberFormatter
& rFormatter
, LanguageType eLanguage
);
431 virtual std::unique_ptr
<SvxFieldData
> Clone() const override
;
432 virtual bool operator==( const SvxFieldData
& ) const override
;
438 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */