Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/editeng/flditem.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
#ifndef INCLUDED_EDITENG_FLDITEM_HXX
20
#define INCLUDED_EDITENG_FLDITEM_HXX
21
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>
27
28
#include <com/sun/star/text/textfield/Type.hpp>
29
30
namespace com::sun::star::text {
31
    class XTextContent;
32
}
33
34
class SvNumberFormatter;
35
class MetaAction;
36
37
// class SvxFieldItem ---------------------------------------------------
38
39
40
class EDITENG_DLLPUBLIC SvxFieldData
41
{
42
public:
43
44
    static SvxFieldData* Create(const css::uno::Reference<css::text::XTextContent>& xContent);
45
46
    static constexpr auto CLASS_ID = css::text::textfield::Type::UNSPECIFIED;
47
0
    virtual sal_Int32  GetClassId() const { return CLASS_ID; }
48
49
                            SvxFieldData();
50
    virtual                 ~SvxFieldData();
51
52
316k
    SvxFieldData(SvxFieldData const &) = default;
53
    SvxFieldData(SvxFieldData &&) = default;
54
    SvxFieldData & operator =(SvxFieldData const &) = default;
55
0
    SvxFieldData & operator =(SvxFieldData &&) = default;
56
57
    virtual std::unique_ptr<SvxFieldData> Clone() const;
58
    virtual bool            operator==( const SvxFieldData& ) const;
59
    virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
60
};
61
62
/**
63
 * This item stores a field (SvxFieldData).  The field is controlled by or
64
 * belongs to the item.  The field itself is determined by a derivation from
65
 * SvxFieldData (RTTI)
66
 */
67
class EDITENG_DLLPUBLIC SvxFieldItem final : public SfxPoolItem
68
{
69
    std::unique_ptr<SvxFieldData>  mpField;
70
public:
71
            DECLARE_ITEM_TYPE_FUNCTION(SvxFieldItem)
72
            SvxFieldItem( std::unique_ptr<SvxFieldData> pField, const sal_uInt16 nId  );
73
            SvxFieldItem( const SvxFieldData& rField, const sal_uInt16 nId  );
74
            SvxFieldItem( const SvxFieldItem& rItem );
75
            virtual ~SvxFieldItem() override;
76
77
    virtual bool            operator==( const SfxPoolItem& ) const override;
78
    virtual SvxFieldItem*   Clone( SfxItemPool *pPool = nullptr ) const override;
79
    virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
80
81
10.8M
    const SvxFieldData*     GetField() const    { return mpField.get(); }
82
};
83
84
85
// The following are the derivatives of SvxFieldData ...
86
87
88
enum class SvxDateType { Fix, Var };
89
enum class SvxDateFormat {
90
    AppDefault = 0, // Set as in App
91
    System,         // Set as in System
92
    StdSmall,
93
    StdBig,
94
    A,              // 13.02.96
95
    B,              // 13.02.1996
96
    C,              // 13.Feb 1996
97
    D,              // 13.February 1996
98
    E,              // Tue, 13.February 1996
99
    F               // Tuesday, 13.February 1996
100
};
101
102
class EDITENG_DLLPUBLIC SvxDateField final : public SvxFieldData
103
{
104
    sal_Int32               nFixDate;
105
    SvxDateType             eType;
106
    SvxDateFormat           eFormat;
107
108
public:
109
    static constexpr auto CLASS_ID = css::text::textfield::Type::DATE;
110
628k
    virtual sal_Int32  GetClassId() const override { return CLASS_ID; }
111
112
                            SvxDateField();
113
    explicit                SvxDateField( const Date& rDate,
114
                                SvxDateType eType,
115
                                SvxDateFormat eFormat = SvxDateFormat::StdSmall );
116
117
0
    sal_Int32               GetFixDate() const { return nFixDate; }
118
0
    void                    SetFixDate( const Date& rDate ) { nFixDate = rDate.GetDate(); }
119
120
0
    SvxDateType             GetType() const { return eType; }
121
0
    void                    SetType( SvxDateType eTp ) { eType = eTp; }
122
123
0
    SvxDateFormat           GetFormat() const { return eFormat; }
124
3.67k
    void                    SetFormat( SvxDateFormat eFmt ) { eFormat = eFmt; }
125
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 );
130
131
    virtual std::unique_ptr<SvxFieldData> Clone() const override;
132
    virtual bool            operator==( const SvxFieldData& ) const override;
133
};
134
135
136
enum class SvxURLFormat {
137
    AppDefault = 0, // App setting
138
    Url,            // Show URL
139
    Repr            // Show representation
140
};
141
142
class EDITENG_DLLPUBLIC SvxURLField final : public SvxFieldData
143
{
144
private:
145
    SvxURLFormat            eFormat;
146
    OUString                aURL;               // URL-Address
147
    OUString                aRepresentation;    // Text shown in document
148
    OUString                aTargetFrame;       // Frame to open in
149
    OUString                m_Name;             // Alt-text
150
151
public:
152
    static constexpr auto CLASS_ID = css::text::textfield::Type::URL;
153
948k
    virtual sal_Int32  GetClassId() const override { return CLASS_ID; }
154
155
                            SvxURLField();
156
                            SvxURLField( OUString aURL, OUString aRepres, SvxURLFormat eFmt = SvxURLFormat::Url );
157
158
974k
    const OUString&         GetURL() const { return aURL; }
159
3
    void                    SetURL( const OUString& rURL ) { aURL = rURL; }
160
161
968k
    const OUString&         GetRepresentation() const { return aRepresentation; }
162
0
    void                    SetRepresentation( const OUString& rRep ) { aRepresentation= rRep; }
163
164
0
    OUString const&         GetName() const { return m_Name; }
165
0
    void                    SetName(OUString const& rName) { m_Name = rName; }
166
167
0
    const OUString&         GetTargetFrame() const { return aTargetFrame; }
168
402
    void                    SetTargetFrame( const OUString& rFrm ) { aTargetFrame = rFrm; }
169
170
968k
    SvxURLFormat            GetFormat() const { return eFormat; }
171
402
    void                    SetFormat( SvxURLFormat eFmt ) { eFormat = eFmt; }
172
173
    virtual std::unique_ptr<SvxFieldData> Clone() const override;
174
    virtual bool            operator==( const SvxFieldData& ) const override;
175
    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
176
};
177
178
class EDITENG_DLLPUBLIC SvxPageField final: public SvxFieldData
179
{
180
public:
181
115k
    virtual sal_Int32  GetClassId() const override { return css::text::textfield::Type::PAGE; }
182
    SvxPageField();
183
184
    virtual std::unique_ptr<SvxFieldData> Clone() const override;
185
    virtual bool            operator==( const SvxFieldData& ) const override;
186
};
187
188
class EDITENG_DLLPUBLIC SvxPageTitleField final: public SvxFieldData
189
{
190
public:
191
    static constexpr auto CLASS_ID = css::text::textfield::Type::PAGE_NAME;
192
0
    virtual sal_Int32  GetClassId() const override { return CLASS_ID; }
193
    SvxPageTitleField();
194
195
    virtual std::unique_ptr<SvxFieldData> Clone() const override;
196
    virtual bool            operator==( const SvxFieldData& ) const override;
197
};
198
199
class EDITENG_DLLPUBLIC SvxPagesField final: public SvxFieldData
200
{
201
public:
202
    static constexpr auto CLASS_ID = css::text::textfield::Type::PAGES;
203
1.18M
    virtual sal_Int32  GetClassId() const override { return CLASS_ID; }
204
    SvxPagesField();
205
206
    virtual std::unique_ptr<SvxFieldData> Clone() const override;
207
    virtual bool            operator==( const SvxFieldData& ) const override;
208
};
209
210
class EDITENG_DLLPUBLIC SvxTimeField final: public SvxFieldData
211
{
212
public:
213
    static constexpr auto CLASS_ID = css::text::textfield::Type::TIME;
214
2
    virtual sal_Int32  GetClassId() const override { return CLASS_ID; }
215
    SvxTimeField();
216
217
    virtual std::unique_ptr<SvxFieldData> Clone() const override;
218
    virtual bool            operator==( const SvxFieldData& ) const override;
219
};
220
221
class EDITENG_DLLPUBLIC SvxFileField final: public SvxFieldData
222
{
223
public:
224
    static constexpr auto CLASS_ID = css::text::textfield::Type::DOCINFO_TITLE;
225
1.49k
    virtual sal_Int32  GetClassId() const override { return CLASS_ID; }
226
    SvxFileField();
227
228
    virtual std::unique_ptr<SvxFieldData> Clone() const override;
229
    virtual bool            operator==( const SvxFieldData& ) const override;
230
};
231
232
class EDITENG_DLLPUBLIC SvxTableField final: public SvxFieldData
233
{
234
    int mnTab;
235
public:
236
    static constexpr auto CLASS_ID = css::text::textfield::Type::TABLE;
237
93.8k
    virtual sal_Int32  GetClassId() const override { return CLASS_ID; }
238
    SvxTableField();
239
    explicit SvxTableField(int nTab);
240
241
    void SetTab(int nTab);
242
0
    int GetTab() const { return mnTab;}
243
244
    virtual std::unique_ptr<SvxFieldData> Clone() const override;
245
    virtual bool            operator==( const SvxFieldData& ) const override;
246
};
247
248
249
enum class SvxTimeType {
250
    Fix,
251
    Var
252
};
253
enum class SvxTimeFormat {
254
    AppDefault = 0,    // Set as in App
255
    System,            // Set as in System
256
    Standard,
257
    HH24_MM,           // 13:49
258
    HH24_MM_SS,        // 13:49:38
259
    HH24_MM_SS_00,     // 13:49:38.78
260
    HH12_MM,           // 01:49
261
    HH12_MM_SS,        // 01:49:38
262
    HH12_MM_SS_00,     // 01:49:38.78
263
    HH12_MM_AMPM,      // 01:49 PM
264
    HH12_MM_SS_AMPM,   // 01:49:38 PM
265
    HH12_MM_SS_00_AMPM // 01:49:38.78 PM
266
};
267
268
class EDITENG_DLLPUBLIC SvxExtTimeField final : public SvxFieldData
269
{
270
private:
271
    sal_Int64               m_nFixTime;
272
    SvxTimeType             eType;
273
    SvxTimeFormat           eFormat;
274
275
public:
276
    static constexpr auto CLASS_ID = css::text::textfield::Type::EXTENDED_TIME;
277
1.16M
    virtual sal_Int32  GetClassId() const override { return CLASS_ID; }
278
                            SvxExtTimeField();
279
    explicit                SvxExtTimeField( const tools::Time& rTime,
280
                                SvxTimeType eType,
281
                                SvxTimeFormat eFormat = SvxTimeFormat::Standard );
282
283
0
    sal_Int64               GetFixTime() const { return m_nFixTime; }
284
0
    void                    SetFixTime( const tools::Time& rTime ) { m_nFixTime = rTime.GetTime(); }
285
286
0
    SvxTimeType             GetType() const { return eType; }
287
0
    void                    SetType( SvxTimeType eTp ) { eType = eTp; }
288
289
0
    SvxTimeFormat           GetFormat() const { return eFormat; }
290
12
    void                    SetFormat( SvxTimeFormat eFmt ) { eFormat = eFmt; }
291
292
                            // If eLanguage==LANGUAGE_DONTKNOW the language/country
293
                            // used in number formatter initialization is taken.
294
    OUString                GetFormatted( SvNumberFormatter& rFormatter, LanguageType eLanguage ) const;
295
    static OUString         GetFormatted( tools::Time const & rTime, SvxTimeFormat eFormat, SvNumberFormatter& rFormatter, LanguageType eLanguage );
296
297
    virtual std::unique_ptr<SvxFieldData> Clone() const override;
298
    virtual bool            operator==( const SvxFieldData& ) const override;
299
};
300
301
302
enum class SvxFileType {
303
    Fix,
304
    Var
305
};
306
enum class SvxFileFormat {
307
    NameAndExt = 0, // File name with Extension
308
    PathFull,       // full path
309
    PathOnly,       // only path
310
    NameOnly        // only file name
311
};
312
313
314
class EDITENG_DLLPUBLIC SvxExtFileField final : public SvxFieldData
315
{
316
private:
317
    OUString           aFile;
318
    SvxFileType             eType;
319
    SvxFileFormat           eFormat;
320
321
public:
322
    static constexpr auto CLASS_ID = css::text::textfield::Type::EXTENDED_FILE;
323
189
    virtual sal_Int32  GetClassId() const override { return CLASS_ID; }
324
                            SvxExtFileField();
325
    explicit                SvxExtFileField( const OUString& rString,
326
                                SvxFileType eType = SvxFileType::Var,
327
                                SvxFileFormat eFormat = SvxFileFormat::PathFull );
328
329
0
    const OUString&         GetFile() const { return aFile; }
330
0
    void                    SetFile( const OUString& rString ) { aFile = rString; }
331
332
0
    SvxFileType             GetType() const { return eType; }
333
0
    void                    SetType( SvxFileType eTp ) { eType = eTp; }
334
335
189
    SvxFileFormat           GetFormat() const { return eFormat; }
336
50
    void                    SetFormat( SvxFileFormat eFmt ) { eFormat = eFmt; }
337
338
    OUString                GetFormatted() const;
339
340
    virtual std::unique_ptr<SvxFieldData> Clone() const override;
341
    virtual bool            operator==( const SvxFieldData& ) const override;
342
};
343
344
345
enum class SvxAuthorType {
346
    Fix, Var
347
};
348
enum class SvxAuthorFormat {
349
    FullName,   // full name
350
    LastName,   // Only Last name
351
    FirstName,  // Only first name
352
    ShortName   // Initials
353
};
354
355
class EDITENG_DLLPUBLIC SvxAuthorField final : public SvxFieldData
356
{
357
private:
358
    OUString   aName;
359
    OUString   aFirstName;
360
    OUString   aShortName;
361
    SvxAuthorType   eType;
362
    SvxAuthorFormat eFormat;
363
364
public:
365
    static constexpr auto CLASS_ID = css::text::textfield::Type::AUTHOR;
366
0
    virtual sal_Int32  GetClassId() const override { return CLASS_ID; }
367
                            SvxAuthorField(
368
                                const OUString& rFirstName,
369
                                const OUString& rLastName,
370
                                const OUString& rShortName,
371
                                SvxAuthorType eType = SvxAuthorType::Var,
372
                                SvxAuthorFormat eFormat = SvxAuthorFormat::FullName );
373
374
0
    SvxAuthorType           GetType() const { return eType; }
375
0
    void                    SetType( SvxAuthorType eTp ) { eType = eTp; }
376
377
0
    SvxAuthorFormat         GetFormat() const { return eFormat; }
378
0
    void                    SetFormat( SvxAuthorFormat eFmt ) { eFormat = eFmt; }
379
380
    OUString                GetFormatted() const;
381
382
    virtual std::unique_ptr<SvxFieldData> Clone() const override;
383
    virtual bool            operator==( const SvxFieldData& ) const override;
384
};
385
386
/** this field is used as a placeholder for a header&footer in impress. The actual
387
    value is stored at the page */
388
class EDITENG_DLLPUBLIC SvxHeaderField final: public SvxFieldData
389
{
390
public:
391
    static constexpr auto CLASS_ID = css::text::textfield::Type::PRESENTATION_HEADER;
392
224
    virtual sal_Int32  GetClassId() const override { return CLASS_ID; }
393
    SvxHeaderField();
394
395
    virtual std::unique_ptr<SvxFieldData> Clone() const override;
396
    virtual bool            operator==( const SvxFieldData& ) const override;
397
};
398
399
/** this field is used as a placeholder for a header&footer in impress. The actual
400
    value is stored at the page */
401
class EDITENG_DLLPUBLIC SvxFooterField final: public SvxFieldData
402
{
403
public:
404
    static constexpr auto CLASS_ID = css::text::textfield::Type::PRESENTATION_FOOTER;
405
355
    virtual sal_Int32  GetClassId() const override { return CLASS_ID; }
406
    SvxFooterField();
407
    virtual std::unique_ptr<SvxFieldData> Clone() const override;
408
    virtual bool            operator==( const SvxFieldData& ) const override;
409
};
410
411
/** this field is used as a placeholder for a header&footer in impress. The actual
412
    value is stored at the page */
413
class EDITENG_DLLPUBLIC SvxDateTimeField final: public SvxFieldData
414
{
415
public:
416
    static constexpr auto CLASS_ID = css::text::textfield::Type::PRESENTATION_DATE_TIME;
417
356
    virtual sal_Int32  GetClassId() const override { return CLASS_ID; }
418
    SvxDateTimeField();
419
420
    static OUString    GetFormatted( Date const & rDate, tools::Time const & rTime,
421
                                     SvxDateFormat eDateFormat, SvxTimeFormat eTimeFormat,
422
                                     SvNumberFormatter& rFormatter, LanguageType eLanguage );
423
424
    virtual std::unique_ptr<SvxFieldData> Clone() const override;
425
    virtual bool            operator==( const SvxFieldData& ) const override;
426
};
427
428
429
#endif
430
431
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */