Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/editeng/source/uno/unofield.cxx
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
20
#include <sal/config.h>
21
22
#include <string_view>
23
24
#include <com/sun/star/util/DateTime.hpp>
25
#include <com/sun/star/text/FilenameDisplayFormat.hpp>
26
#include <o3tl/string_view.hxx>
27
#include <utility>
28
#include <vcl/svapp.hxx>
29
#include <tools/debug.hxx>
30
#include <svl/itemprop.hxx>
31
32
#include <editeng/flditem.hxx>
33
#include <editeng/CustomPropertyField.hxx>
34
#include <editeng/measfld.hxx>
35
#include <editeng/unofield.hxx>
36
#include <editeng/unotext.hxx>
37
#include <comphelper/sequence.hxx>
38
#include <comphelper/servicehelper.hxx>
39
#include <cppuhelper/supportsservice.hxx>
40
#include <sal/log.hxx>
41
42
#include <editeng/unonames.hxx>
43
44
using namespace ::cppu;
45
using namespace ::com::sun::star;
46
47
#define QUERYINT( xint ) \
48
470k
    if( rType == cppu::UnoType<xint>::get() ) \
49
470k
        aAny <<= uno::Reference< xint >(this)
50
51
52
41.7k
#define WID_DATE    0
53
161k
#define WID_BOOL1   1
54
161k
#define WID_BOOL2   2
55
81.0k
#define WID_INT32   3
56
157k
#define WID_INT16   4
57
157k
#define WID_STRING1 5
58
117k
#define WID_STRING2 6
59
39.6k
#define WID_STRING3 7
60
61
class SvxUnoFieldData_Impl
62
{
63
public:
64
    bool    mbBoolean1;
65
    bool    mbBoolean2;
66
    sal_Int32   mnInt32;
67
    sal_Int16   mnInt16;
68
    OUString    msString1;
69
    OUString    msString2;
70
    OUString    msString3;
71
    util::DateTime maDateTime;
72
73
    OUString    msPresentation;
74
};
75
76
static const SfxItemPropertySet* ImplGetFieldItemPropertySet( sal_Int32 mnId )
77
39.2k
{
78
39.2k
    static const SfxItemPropertyMapEntry aExDateTimeFieldPropertyMap_Impl[] =
79
39.2k
    {
80
39.2k
        { UNO_TC_PROP_DATE_TIME, WID_DATE,  ::cppu::UnoType<util::DateTime>::get(), 0, 0 },
81
39.2k
        { UNO_TC_PROP_IS_FIXED,  WID_BOOL1, cppu::UnoType<bool>::get(),                  0, 0 },
82
39.2k
        { UNO_TC_PROP_IS_DATE,   WID_BOOL2, cppu::UnoType<bool>::get(),                  0, 0 },
83
39.2k
        { UNO_TC_PROP_NUMFORMAT, WID_INT32, ::cppu::UnoType<sal_Int32>::get(),      0, 0 },
84
39.2k
    };
85
39.2k
    static const SfxItemPropertySet aExDateTimeFieldPropertySet_Impl(aExDateTimeFieldPropertyMap_Impl);
86
87
39.2k
    static const SfxItemPropertyMapEntry aDateTimeFieldPropertyMap_Impl[] =
88
39.2k
    {
89
39.2k
        { UNO_TC_PROP_IS_DATE, WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
90
39.2k
    };
91
39.2k
    static const SfxItemPropertySet aDateTimeFieldPropertySet_Impl(aDateTimeFieldPropertyMap_Impl);
92
93
39.2k
    static const SfxItemPropertyMapEntry aUrlFieldPropertyMap_Impl[] =
94
39.2k
    {
95
39.2k
        { UNO_TC_PROP_URL_FORMAT,         WID_INT16,   ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
96
39.2k
        { UNO_TC_PROP_URL_REPRESENTATION, WID_STRING1, ::cppu::UnoType<OUString>::get(),  0, 0 },
97
39.2k
        { UNO_TC_PROP_URL_TARGET,         WID_STRING2, ::cppu::UnoType<OUString>::get(),  0, 0 },
98
39.2k
        { UNO_TC_PROP_URL,                WID_STRING3, ::cppu::UnoType<OUString>::get(),  0, 0 },
99
39.2k
    };
100
39.2k
    static const SfxItemPropertySet aUrlFieldPropertySet_Impl(aUrlFieldPropertyMap_Impl);
101
102
39.2k
    static const SfxItemPropertySet aEmptyPropertySet_Impl({});
103
104
39.2k
    static const SfxItemPropertyMapEntry aExtFileFieldPropertyMap_Impl[] =
105
39.2k
    {
106
39.2k
        { UNO_TC_PROP_IS_FIXED,             WID_BOOL1,   cppu::UnoType<bool>::get(),             0, 0 },
107
39.2k
        { UNO_TC_PROP_FILE_FORMAT,          WID_INT16,   ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
108
39.2k
        { UNO_TC_PROP_CURRENT_PRESENTATION, WID_STRING1, ::cppu::UnoType<OUString>::get(),  0, 0 },
109
39.2k
    };
110
39.2k
    static const SfxItemPropertySet aExtFileFieldPropertySet_Impl(aExtFileFieldPropertyMap_Impl);
111
112
39.2k
    static const SfxItemPropertyMapEntry aAuthorFieldPropertyMap_Impl[] =
113
39.2k
    {
114
39.2k
        { UNO_TC_PROP_IS_FIXED,             WID_BOOL1,  cppu::UnoType<bool>::get(),             0, 0 },
115
39.2k
        { UNO_TC_PROP_CURRENT_PRESENTATION, WID_STRING1,::cppu::UnoType<OUString>::get(),  0, 0 },
116
39.2k
        { UNO_TC_PROP_AUTHOR_CONTENT,       WID_STRING2,::cppu::UnoType<OUString>::get(),  0, 0 },
117
39.2k
        { UNO_TC_PROP_AUTHOR_FORMAT,        WID_INT16,  ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
118
39.2k
        { UNO_TC_PROP_AUTHOR_FULLNAME,      WID_BOOL2,  cppu::UnoType<bool>::get(),             0, 0 },
119
39.2k
    };
120
39.2k
    static const SfxItemPropertySet aAuthorFieldPropertySet_Impl(aAuthorFieldPropertyMap_Impl);
121
122
39.2k
    static const SfxItemPropertyMapEntry aMeasureFieldPropertyMap_Impl[] =
123
39.2k
    {
124
39.2k
        { UNO_TC_PROP_MEASURE_KIND, WID_INT16,  ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
125
39.2k
    };
126
39.2k
    static const SfxItemPropertySet aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl);
127
128
39.2k
    static const SfxItemPropertyMapEntry aDocInfoCustomFieldPropertyMap_Impl[] =
129
39.2k
    {
130
39.2k
        { UNO_TC_PROP_NAME,                 WID_STRING1, cppu::UnoType<OUString>::get(),   0, 0 },
131
39.2k
        { UNO_TC_PROP_CURRENT_PRESENTATION, WID_STRING2, cppu::UnoType<OUString>::get(),   0, 0 },
132
39.2k
        { UNO_TC_PROP_IS_FIXED,             WID_BOOL1,   cppu::UnoType<bool>::get(),       0, 0 },
133
39.2k
        { UNO_TC_PROP_NUMFORMAT,            WID_INT32,   cppu::UnoType<sal_Int32>::get(),  0, 0 },
134
39.2k
        { UNO_TC_PROP_IS_FIXED_LANGUAGE,    WID_BOOL2,   cppu::UnoType<bool>::get(),       0, 0 },
135
39.2k
    };
136
39.2k
    static const SfxItemPropertySet aDocInfoCustomFieldPropertySet_Impl(aDocInfoCustomFieldPropertyMap_Impl);
137
138
39.2k
    switch( mnId )
139
39.2k
    {
140
0
    case text::textfield::Type::EXTENDED_TIME:
141
2.53k
    case text::textfield::Type::DATE:
142
2.53k
        return &aExDateTimeFieldPropertySet_Impl;
143
324
    case text::textfield::Type::URL:
144
324
        return &aUrlFieldPropertySet_Impl;
145
0
    case text::textfield::Type::TIME:
146
0
        return &aDateTimeFieldPropertySet_Impl;
147
0
    case text::textfield::Type::EXTENDED_FILE:
148
0
        return &aExtFileFieldPropertySet_Impl;
149
0
    case text::textfield::Type::AUTHOR:
150
0
        return &aAuthorFieldPropertySet_Impl;
151
0
    case text::textfield::Type::MEASURE:
152
0
        return &aMeasureFieldPropertySet_Impl;
153
0
    case text::textfield::Type::DOCINFO_CUSTOM:
154
0
        return &aDocInfoCustomFieldPropertySet_Impl;
155
36.3k
    default:
156
36.3k
        return &aEmptyPropertySet_Impl;
157
39.2k
    }
158
39.2k
}
159
160
/* conversion routines */
161
162
static sal_Int16 getFileNameDisplayFormat( SvxFileFormat nFormat )
163
0
{
164
0
    switch( nFormat )
165
0
    {
166
0
    case SvxFileFormat::NameAndExt:    return text::FilenameDisplayFormat::NAME_AND_EXT;
167
0
    case SvxFileFormat::PathFull:    return text::FilenameDisplayFormat::FULL;
168
0
    case SvxFileFormat::PathOnly:    return text::FilenameDisplayFormat::PATH;
169
//  case SvxFileFormat::NameOnly:
170
0
    default: return text::FilenameDisplayFormat::NAME;
171
0
    }
172
0
}
173
174
static SvxFileFormat setFileNameDisplayFormat( sal_Int16 nFormat )
175
0
{
176
0
    switch( nFormat )
177
0
    {
178
0
    case text::FilenameDisplayFormat::FULL: return SvxFileFormat::PathFull;
179
0
    case text::FilenameDisplayFormat::PATH: return SvxFileFormat::PathOnly;
180
0
    case text::FilenameDisplayFormat::NAME: return SvxFileFormat::NameOnly;
181
//  case text::FilenameDisplayFormat::NAME_AND_EXT:
182
0
    default:
183
0
        return SvxFileFormat::NameAndExt;
184
0
    }
185
0
}
186
187
static util::DateTime getDate( sal_Int32 nDate )
188
0
{
189
0
    util::DateTime aDate;
190
191
0
    Date aTempDate( nDate );
192
193
0
    aDate.Day = aTempDate.GetDay();
194
0
    aDate.Month = aTempDate.GetMonth();
195
0
    aDate.Year = aTempDate.GetYear();
196
197
0
    return aDate;
198
0
}
199
200
static Date setDate( util::DateTime const & rDate )
201
0
{
202
0
    return Date( rDate.Day, rDate.Month, rDate.Year );
203
0
}
204
205
static util::DateTime getTime(sal_Int64 const nTime)
206
0
{
207
0
    util::DateTime aTime;
208
209
0
    tools::Time aTempTime(tools::Time::fromEncodedTime(nTime));
210
211
0
    aTime.NanoSeconds = aTempTime.GetNanoSec();
212
0
    aTime.Seconds = aTempTime.GetSec();
213
0
    aTime.Minutes = aTempTime.GetMin();
214
0
    aTime.Hours = aTempTime.GetHour();
215
216
0
    return aTime;
217
0
}
218
219
static tools::Time setTime( util::DateTime const & rDate )
220
0
{
221
0
    return tools::Time( rDate  );
222
0
}
223
224
225
226
SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId ) noexcept
227
39.2k
:   OComponentHelper( m_aMutex )
228
39.2k
,   mpPropSet(nullptr)
229
39.2k
,   mnServiceId(nServiceId)
230
39.2k
,   mpImpl( new SvxUnoFieldData_Impl )
231
39.2k
{
232
39.2k
    mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
233
234
39.2k
    mpImpl->maDateTime.NanoSeconds = 0;
235
39.2k
    mpImpl->maDateTime.Seconds = 0;
236
39.2k
    mpImpl->maDateTime.Minutes = 0;
237
39.2k
    mpImpl->maDateTime.Hours = 0;
238
39.2k
    mpImpl->maDateTime.Day = 0;
239
39.2k
    mpImpl->maDateTime.Month = 0;
240
39.2k
    mpImpl->maDateTime.Year = 0;
241
39.2k
    mpImpl->maDateTime.IsUTC = false;
242
243
39.2k
    switch( nServiceId )
244
39.2k
    {
245
2.53k
    case text::textfield::Type::DATE:
246
2.53k
        mpImpl->mbBoolean2 = true;
247
2.53k
        mpImpl->mnInt32 = static_cast<sal_Int32>(SvxDateFormat::StdSmall);
248
2.53k
        mpImpl->mbBoolean1 = false;
249
2.53k
        break;
250
251
0
    case text::textfield::Type::EXTENDED_TIME:
252
0
    case text::textfield::Type::TIME:
253
0
        mpImpl->mbBoolean2 = false;
254
0
        mpImpl->mbBoolean1 = false;
255
0
        mpImpl->mnInt32 = static_cast<sal_Int32>(SvxTimeFormat::Standard);
256
0
        break;
257
258
324
    case text::textfield::Type::URL:
259
324
        mpImpl->mnInt16 = static_cast<sal_uInt16>(SvxURLFormat::Repr);
260
324
        break;
261
262
0
    case text::textfield::Type::EXTENDED_FILE:
263
0
        mpImpl->mbBoolean1 = false;
264
0
        mpImpl->mnInt16 = text::FilenameDisplayFormat::FULL;
265
0
        break;
266
267
0
    case text::textfield::Type::AUTHOR:
268
0
        mpImpl->mnInt16 = static_cast<sal_uInt16>(SvxAuthorFormat::FullName);
269
0
        mpImpl->mbBoolean1 = false;
270
0
        mpImpl->mbBoolean2 = true;
271
0
        break;
272
273
0
    case text::textfield::Type::MEASURE:
274
0
        mpImpl->mnInt16 = static_cast<sal_uInt16>(SdrMeasureFieldKind::Value);
275
0
        break;
276
277
0
    case text::textfield::Type::DOCINFO_CUSTOM:
278
0
        mpImpl->mbBoolean1 = true;
279
0
        mpImpl->mbBoolean2 = true;
280
0
        mpImpl->mnInt32 = 0;
281
0
        break;
282
283
36.3k
    default:
284
36.3k
        mpImpl->mbBoolean1 = false;
285
36.3k
        mpImpl->mbBoolean2 = false;
286
36.3k
        mpImpl->mnInt32 = 0;
287
36.3k
        mpImpl->mnInt16 = 0;
288
289
39.2k
    }
290
39.2k
}
291
292
SvxUnoTextField::SvxUnoTextField( uno::Reference< text::XTextRange > xAnchor, const OUString& rPresentation, const SvxFieldData* pData ) noexcept
293
0
:   OComponentHelper( m_aMutex )
294
0
,   mxAnchor(std::move( xAnchor ))
295
0
,   mpPropSet(nullptr)
296
0
,   mnServiceId(text::textfield::Type::UNSPECIFIED)
297
0
,   mpImpl( new SvxUnoFieldData_Impl )
298
0
{
299
0
    DBG_ASSERT(pData, "pFieldData == NULL! [CL]" );
300
301
0
    mpImpl->msPresentation = rPresentation;
302
303
0
    if(pData)
304
0
    {
305
0
        mnServiceId = pData->GetClassId();
306
0
        DBG_ASSERT(mnServiceId != text::textfield::Type::UNSPECIFIED, "unknown SvxFieldData! [CL]");
307
0
        if (mnServiceId != text::textfield::Type::UNSPECIFIED)
308
0
        {
309
            // extract field properties from data class
310
0
            switch( mnServiceId )
311
0
            {
312
0
            case text::textfield::Type::DATE:
313
0
                {
314
0
                    mpImpl->mbBoolean2 = true;
315
                    // #i35416# for variable date field, don't use invalid "0000-00-00" date,
316
                    // use current date instead
317
0
                    bool bFixed = static_cast<const SvxDateField*>(pData)->GetType() == SvxDateType::Fix;
318
0
                    mpImpl->maDateTime = getDate( bFixed ?
319
0
                                            static_cast<const SvxDateField*>(pData)->GetFixDate() :
320
0
                                            Date( Date::SYSTEM ).GetDate() );
321
0
                    mpImpl->mnInt32 = static_cast<sal_Int32>(static_cast<const SvxDateField*>(pData)->GetFormat());
322
0
                    mpImpl->mbBoolean1 = bFixed;
323
0
                }
324
0
                break;
325
326
0
            case text::textfield::Type::TIME:
327
0
                mpImpl->mbBoolean2 = false;
328
0
                mpImpl->mbBoolean1 = false;
329
0
                mpImpl->mnInt32 = static_cast<sal_Int32>(SvxTimeFormat::Standard);
330
0
                break;
331
332
0
            case text::textfield::Type::EXTENDED_TIME:
333
0
                mpImpl->mbBoolean2 = false;
334
0
                mpImpl->maDateTime = getTime( static_cast<const SvxExtTimeField*>(pData)->GetFixTime() );
335
0
                mpImpl->mbBoolean1 = static_cast<const SvxExtTimeField*>(pData)->GetType() == SvxTimeType::Fix;
336
0
                mpImpl->mnInt32 = static_cast<sal_Int32>(static_cast<const SvxExtTimeField*>(pData)->GetFormat());
337
0
                break;
338
339
0
            case text::textfield::Type::URL:
340
0
                mpImpl->msString1 = static_cast<const SvxURLField*>(pData)->GetRepresentation();
341
0
                mpImpl->msString2 = static_cast<const SvxURLField*>(pData)->GetTargetFrame();
342
0
                mpImpl->msString3 = static_cast<const SvxURLField*>(pData)->GetURL();
343
0
                mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(
344
0
                    static_cast<const SvxURLField*>(pData)->GetFormat());
345
0
                break;
346
347
0
            case text::textfield::Type::EXTENDED_FILE:
348
0
                mpImpl->msString1 = static_cast<const SvxExtFileField*>(pData)->GetFile();
349
0
                mpImpl->mbBoolean1 = static_cast<const SvxExtFileField*>(pData)->GetType() == SvxFileType::Fix;
350
0
                mpImpl->mnInt16 = getFileNameDisplayFormat(static_cast<const SvxExtFileField*>(pData)->GetFormat());
351
0
                break;
352
353
0
            case text::textfield::Type::AUTHOR:
354
0
                mpImpl->msString1  = static_cast<const SvxAuthorField*>(pData)->GetFormatted();
355
0
                mpImpl->msString2  = static_cast<const SvxAuthorField*>(pData)->GetFormatted();
356
0
                mpImpl->mnInt16    = sal::static_int_cast< sal_Int16 >(
357
0
                    static_cast<const SvxAuthorField*>(pData)->GetFormat());
358
0
                mpImpl->mbBoolean1 = static_cast<const SvxAuthorField*>(pData)->GetType() == SvxAuthorType::Fix;
359
0
                mpImpl->mbBoolean2 = static_cast<const SvxAuthorField*>(pData)->GetFormat() != SvxAuthorFormat::ShortName;
360
0
                break;
361
362
0
            case text::textfield::Type::MEASURE:
363
0
                mpImpl->mnInt16     = sal::static_int_cast< sal_Int16 >(static_cast<const SdrMeasureField*>(pData)->GetMeasureFieldKind());
364
0
                break;
365
366
0
            case text::textfield::Type::DOCINFO_CUSTOM:
367
0
                mpImpl->msString1 = static_cast<const editeng::CustomPropertyField*>(pData)->GetName();
368
0
                mpImpl->msString2 = static_cast<const editeng::CustomPropertyField*>(pData)->GetCurrentPresentation();
369
0
                mpImpl->mbBoolean1 = false;
370
0
                mpImpl->mbBoolean2 = false;
371
0
                mpImpl->mnInt32 = 0;
372
0
                break;
373
374
0
            default:
375
0
                SAL_INFO("editeng", "Id service unknown: " << mnServiceId);
376
0
                break;
377
0
            }
378
0
        }
379
0
    }
380
381
0
    mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
382
0
}
383
384
SvxUnoTextField::~SvxUnoTextField() noexcept
385
39.2k
{
386
39.2k
}
387
388
std::unique_ptr<SvxFieldData> SvxUnoTextField::CreateFieldData() const noexcept
389
0
{
390
0
    std::unique_ptr<SvxFieldData> pData;
391
392
0
    switch( mnServiceId )
393
0
    {
394
0
    case text::textfield::Type::TIME:
395
0
    case text::textfield::Type::EXTENDED_TIME:
396
0
    case text::textfield::Type::DATE:
397
0
    {
398
0
        if( mpImpl->mbBoolean2 ) // IsDate?
399
0
        {
400
0
            Date aDate( setDate( mpImpl->maDateTime ) );
401
0
            pData.reset( new SvxDateField( aDate, mpImpl->mbBoolean1?SvxDateType::Fix:SvxDateType::Var ) );
402
0
            if( mpImpl->mnInt32 >= static_cast<sal_Int32>(SvxDateFormat::AppDefault) &&
403
0
                mpImpl->mnInt32 <= static_cast<sal_Int32>(SvxDateFormat::F) )
404
0
                static_cast<SvxDateField*>(pData.get())->SetFormat( static_cast<SvxDateFormat>(mpImpl->mnInt32) );
405
0
        }
406
0
        else
407
0
        {
408
0
            if( mnServiceId != text::textfield::Type::TIME && mnServiceId != text::textfield::Type::DATE )
409
0
            {
410
0
                tools::Time aTime( setTime( mpImpl->maDateTime ) );
411
0
                pData.reset( new SvxExtTimeField( aTime, mpImpl->mbBoolean1?SvxTimeType::Fix:SvxTimeType::Var ) );
412
413
0
                if( static_cast<SvxTimeFormat>(mpImpl->mnInt32) >= SvxTimeFormat::AppDefault &&
414
0
                    static_cast<SvxTimeFormat>(mpImpl->mnInt32) <= SvxTimeFormat::HH12_MM_SS_00_AMPM )
415
0
                    static_cast<SvxExtTimeField*>(pData.get())->SetFormat( static_cast<SvxTimeFormat>(mpImpl->mnInt32) );
416
0
            }
417
0
            else
418
0
            {
419
0
                pData.reset( new SvxTimeField() );
420
0
            }
421
0
        }
422
423
0
    }
424
0
        break;
425
426
0
    case text::textfield::Type::URL:
427
0
        pData.reset( new SvxURLField( mpImpl->msString3, mpImpl->msString1, !mpImpl->msString1.isEmpty() ? SvxURLFormat::Repr : SvxURLFormat::Url ) );
428
0
        static_cast<SvxURLField*>(pData.get())->SetTargetFrame( mpImpl->msString2 );
429
0
        if( static_cast<SvxURLFormat>(mpImpl->mnInt16) >= SvxURLFormat::AppDefault &&
430
0
            static_cast<SvxURLFormat>(mpImpl->mnInt16) <= SvxURLFormat::Repr )
431
0
            static_cast<SvxURLField*>(pData.get())->SetFormat( static_cast<SvxURLFormat>(mpImpl->mnInt16) );
432
0
        break;
433
434
0
    case text::textfield::Type::PAGE:
435
0
        pData.reset( new SvxPageField() );
436
0
        break;
437
438
0
    case text::textfield::Type::PAGES:
439
0
        pData.reset( new SvxPagesField() );
440
0
        break;
441
442
0
    case text::textfield::Type::DOCINFO_TITLE:
443
0
        pData.reset( new SvxFileField() );
444
0
        break;
445
446
0
    case text::textfield::Type::TABLE:
447
0
        pData.reset( new SvxTableField() );
448
0
        break;
449
450
0
    case text::textfield::Type::EXTENDED_FILE:
451
0
    {
452
        // #92009# pass fixed attribute to constructor
453
0
        pData.reset( new SvxExtFileField( mpImpl->msString1,
454
0
                                     mpImpl->mbBoolean1 ? SvxFileType::Fix : SvxFileType::Var,
455
0
                                     setFileNameDisplayFormat(mpImpl->mnInt16 ) ) );
456
0
        break;
457
0
    }
458
459
0
    case text::textfield::Type::AUTHOR:
460
0
    {
461
0
        OUString aContent;
462
0
        OUString aFirstName;
463
0
        OUString aLastName;
464
465
        // do we have CurrentPresentation given?
466
        // mimic behaviour of writer, which means:
467
        // prefer CurrentPresentation over Content
468
        // if both are given.
469
0
        if( !mpImpl->msString1.isEmpty() )
470
0
            aContent = mpImpl->msString1;
471
0
        else
472
0
            aContent = mpImpl->msString2;
473
474
0
        sal_Int32 nPos = aContent.lastIndexOf( ' ', 0 );
475
0
        if( nPos > 0 )
476
0
        {
477
0
            aFirstName = aContent.copy( 0, nPos );
478
0
            aLastName = aContent.copy( nPos + 1 );
479
0
        }
480
0
        else
481
0
        {
482
0
            aLastName = aContent;
483
0
        }
484
485
        // #92009# pass fixed attribute to constructor
486
0
        pData.reset( new SvxAuthorField( aFirstName, aLastName, u""_ustr,
487
0
                                    mpImpl->mbBoolean1 ? SvxAuthorType::Fix : SvxAuthorType::Var ) );
488
489
0
        if( !mpImpl->mbBoolean2 )
490
0
        {
491
0
            static_cast<SvxAuthorField*>(pData.get())->SetFormat( SvxAuthorFormat::ShortName );
492
0
        }
493
0
        else if( static_cast<SvxAuthorFormat>(mpImpl->mnInt16) >= SvxAuthorFormat::FullName &&
494
0
                 static_cast<SvxAuthorFormat>(mpImpl->mnInt16) <= SvxAuthorFormat::ShortName )
495
0
        {
496
0
            static_cast<SvxAuthorField*>(pData.get())->SetFormat( static_cast<SvxAuthorFormat>(mpImpl->mnInt16) );
497
0
        }
498
499
0
        break;
500
0
    }
501
502
0
    case text::textfield::Type::MEASURE:
503
0
    {
504
0
        SdrMeasureFieldKind eKind = SdrMeasureFieldKind::Value;
505
0
        if( mpImpl->mnInt16 == sal_Int16(SdrMeasureFieldKind::Unit) || mpImpl->mnInt16 == sal_Int16(SdrMeasureFieldKind::Rotate90Blanks) )
506
0
            eKind = static_cast<SdrMeasureFieldKind>(mpImpl->mnInt16);
507
0
        pData.reset( new SdrMeasureField( eKind) );
508
0
        break;
509
0
    }
510
0
    case text::textfield::Type::PRESENTATION_HEADER:
511
0
        pData.reset( new SvxHeaderField() );
512
0
        break;
513
0
    case text::textfield::Type::PRESENTATION_FOOTER:
514
0
        pData.reset( new SvxFooterField() );
515
0
        break;
516
0
    case text::textfield::Type::PRESENTATION_DATE_TIME:
517
0
        pData.reset( new SvxDateTimeField() );
518
0
        break;
519
0
    case text::textfield::Type::PAGE_NAME:
520
0
        pData.reset( new SvxPageTitleField() );
521
0
        break;
522
0
    case text::textfield::Type::DOCINFO_CUSTOM:
523
0
        pData.reset( new editeng::CustomPropertyField(mpImpl->msString1, mpImpl->msString2) );
524
0
        break;
525
0
    }
526
527
0
    return pData;
528
0
}
529
530
// uno::XInterface
531
uno::Any SAL_CALL SvxUnoTextField::queryAggregation( const uno::Type & rType )
532
212k
{
533
212k
    uno::Any aAny;
534
535
212k
    QUERYINT( beans::XPropertySet );
536
110k
    else QUERYINT( text::XTextContent );
537
81.5k
    else QUERYINT( text::XTextField );
538
65.3k
    else QUERYINT( lang::XServiceInfo );
539
65.3k
    else
540
65.3k
        return OComponentHelper::queryAggregation( rType );
541
542
146k
    return aAny;
543
212k
}
544
545
// XTypeProvider
546
547
uno::Sequence< uno::Type > SAL_CALL SvxUnoTextField::getTypes()
548
0
{
549
0
    if( !maTypeSequence.hasElements() )
550
0
    {
551
0
        maTypeSequence = comphelper::concatSequences(
552
0
            OComponentHelper::getTypes(),
553
0
            std::initializer_list<uno::Type>{
554
0
                cppu::UnoType<text::XTextField>::get(),
555
0
                cppu::UnoType<beans::XPropertySet>::get(),
556
0
                cppu::UnoType<lang::XServiceInfo>::get(),
557
0
                cppu::UnoType<lang::XUnoTunnel>::get() });
558
0
    }
559
0
    return maTypeSequence;
560
0
}
561
562
uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextField::getImplementationId()
563
0
{
564
0
    return css::uno::Sequence<sal_Int8>();
565
0
}
566
567
uno::Any SAL_CALL SvxUnoTextField::queryInterface( const uno::Type & rType )
568
212k
{
569
212k
    return OComponentHelper::queryInterface(rType);
570
212k
}
571
572
void SAL_CALL SvxUnoTextField::acquire() noexcept
573
460k
{
574
460k
    OComponentHelper::acquire();
575
460k
}
576
577
void SAL_CALL SvxUnoTextField::release() noexcept
578
460k
{
579
460k
    OComponentHelper::release();
580
460k
}
581
582
// Interface text::XTextField
583
OUString SAL_CALL SvxUnoTextField::getPresentation( sal_Bool bShowCommand )
584
0
{
585
0
    SolarMutexGuard aGuard;
586
0
    if (bShowCommand)
587
0
    {
588
0
        switch (mnServiceId)
589
0
        {
590
0
            case text::textfield::Type::DATE:
591
0
                return u"Date"_ustr;
592
0
            case text::textfield::Type::URL:
593
0
                return u"URL"_ustr;
594
0
            case text::textfield::Type::PAGE:
595
0
                return u"Page"_ustr;
596
0
            case text::textfield::Type::PAGES:
597
0
                return u"Pages"_ustr;
598
0
            case text::textfield::Type::TIME:
599
0
                return u"Time"_ustr;
600
0
            case text::textfield::Type::DOCINFO_TITLE:
601
0
                return u"File"_ustr;
602
0
            case text::textfield::Type::TABLE:
603
0
                return u"Table"_ustr;
604
0
            case text::textfield::Type::EXTENDED_TIME:
605
0
                return u"ExtTime"_ustr;
606
0
            case text::textfield::Type::EXTENDED_FILE:
607
0
                return u"ExtFile"_ustr;
608
0
            case text::textfield::Type::AUTHOR:
609
0
                return u"Author"_ustr;
610
0
            case text::textfield::Type::MEASURE:
611
0
                return u"Measure"_ustr;
612
0
            case text::textfield::Type::PRESENTATION_HEADER:
613
0
                return u"Header"_ustr;
614
0
            case text::textfield::Type::PRESENTATION_FOOTER:
615
0
                return u"Footer"_ustr;
616
0
            case text::textfield::Type::PRESENTATION_DATE_TIME:
617
0
                return u"DateTime"_ustr;
618
0
            case text::textfield::Type::PAGE_NAME:
619
0
                return u"PageName"_ustr;
620
0
            case text::textfield::Type::DOCINFO_CUSTOM:
621
0
                return u"Custom"_ustr;
622
0
            default:
623
0
                return u"Unknown"_ustr;
624
0
        }
625
0
    }
626
0
    else
627
0
    {
628
0
        return mpImpl->msPresentation;
629
0
    }
630
0
}
631
632
// Interface text::XTextContent
633
void SAL_CALL SvxUnoTextField::attach( const uno::Reference< text::XTextRange >& xTextRange )
634
69
{
635
69
    SvxUnoTextRangeBase* pRange = comphelper::getFromUnoTunnel<SvxUnoTextRange>( xTextRange );
636
69
    if(pRange == nullptr)
637
69
        throw lang::IllegalArgumentException();
638
639
0
    std::unique_ptr<SvxFieldData> pData = CreateFieldData();
640
0
    if( pData )
641
0
        pRange->attachField( std::move(pData) );
642
0
}
643
644
uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextField::getAnchor()
645
0
{
646
0
    return mxAnchor;
647
0
}
648
649
// lang::XComponent
650
void SAL_CALL SvxUnoTextField::dispose()
651
39.2k
{
652
39.2k
    OComponentHelper::dispose();
653
39.2k
    mxAnchor.clear();
654
39.2k
}
655
656
void SAL_CALL SvxUnoTextField::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
657
0
{
658
0
    OComponentHelper::addEventListener(xListener);
659
0
}
660
661
void SAL_CALL SvxUnoTextField::removeEventListener( const uno::Reference< lang::XEventListener >& aListener )
662
0
{
663
0
    OComponentHelper::removeEventListener(aListener);
664
0
}
665
666
667
// Interface beans::XPropertySet
668
uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextField::getPropertySetInfo(  )
669
22.0k
{
670
22.0k
    SolarMutexGuard aGuard;
671
22.0k
    return mpPropSet->getPropertySetInfo();
672
22.0k
}
673
674
void SAL_CALL SvxUnoTextField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
675
44.6k
{
676
44.6k
    SolarMutexGuard aGuard;
677
678
44.6k
    if( mpImpl == nullptr )
679
0
        throw uno::RuntimeException();
680
681
44.6k
    if (aPropertyName == UNO_TC_PROP_ANCHOR)
682
39.0k
    {
683
39.0k
        aValue >>= mxAnchor;
684
39.0k
        return;
685
39.0k
    }
686
687
5.55k
    const SfxItemPropertyMapEntry* pMap = mpPropSet->getPropertyMap().getByName( aPropertyName );
688
5.55k
    if ( !pMap )
689
0
        throw beans::UnknownPropertyException(aPropertyName);
690
691
5.55k
    switch( pMap->nWID )
692
5.55k
    {
693
0
    case WID_DATE:
694
0
        if(aValue >>= mpImpl->maDateTime)
695
0
            return;
696
0
        break;
697
2.53k
    case WID_BOOL1:
698
2.53k
        if(aValue >>= mpImpl->mbBoolean1)
699
2.53k
            return;
700
0
        break;
701
2.53k
    case WID_BOOL2:
702
2.53k
        if(aValue >>= mpImpl->mbBoolean2)
703
2.53k
            return;
704
0
        break;
705
0
    case WID_INT16:
706
0
        if(aValue >>= mpImpl->mnInt16)
707
0
            return;
708
0
        break;
709
72
    case WID_INT32:
710
72
        if(aValue >>= mpImpl->mnInt32)
711
72
            return;
712
0
        break;
713
207
    case WID_STRING1:
714
207
        if(aValue >>= mpImpl->msString1)
715
207
            return;
716
0
        break;
717
0
    case WID_STRING2:
718
0
        if(aValue >>= mpImpl->msString2)
719
0
            return;
720
0
        break;
721
207
    case WID_STRING3:
722
207
        if(aValue >>= mpImpl->msString3)
723
207
            return;
724
0
        break;
725
5.55k
    }
726
727
0
    throw lang::IllegalArgumentException();
728
5.55k
}
729
730
uno::Any SAL_CALL SvxUnoTextField::getPropertyValue( const OUString& PropertyName )
731
50.2k
{
732
50.2k
    SolarMutexGuard aGuard;
733
734
50.2k
    if (PropertyName == UNO_TC_PROP_ANCHOR)
735
0
        return uno::Any(mxAnchor);
736
737
50.2k
    if (PropertyName == UNO_TC_PROP_TEXTFIELD_TYPE)
738
39.0k
        return uno::Any(mnServiceId);
739
740
11.2k
    uno::Any aValue;
741
742
11.2k
    const SfxItemPropertyMapEntry* pMap = mpPropSet->getPropertyMap().getByName( PropertyName );
743
11.2k
    if ( !pMap )
744
0
        throw beans::UnknownPropertyException(PropertyName);
745
746
11.2k
    switch( pMap->nWID )
747
11.2k
    {
748
2.53k
    case WID_DATE:
749
2.53k
        aValue <<= mpImpl->maDateTime;
750
2.53k
        break;
751
2.53k
    case WID_BOOL1:
752
2.53k
        aValue <<= mpImpl->mbBoolean1;
753
2.53k
        break;
754
2.53k
    case WID_BOOL2:
755
2.53k
        aValue <<= mpImpl->mbBoolean2;
756
2.53k
        break;
757
266
    case WID_INT16:
758
266
        aValue <<= mpImpl->mnInt16;
759
266
        break;
760
2.53k
    case WID_INT32:
761
2.53k
        aValue <<= mpImpl->mnInt32;
762
2.53k
        break;
763
266
    case WID_STRING1:
764
266
        aValue <<= mpImpl->msString1;
765
266
        break;
766
266
    case WID_STRING2:
767
266
        aValue <<= mpImpl->msString2;
768
266
        break;
769
266
    case WID_STRING3:
770
266
        aValue <<= mpImpl->msString3;
771
266
        break;
772
11.2k
    }
773
774
11.2k
    return aValue;
775
11.2k
}
776
777
0
void SAL_CALL SvxUnoTextField::addPropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) {}
778
0
void SAL_CALL SvxUnoTextField::removePropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) {}
779
0
void SAL_CALL SvxUnoTextField::addVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) {}
780
0
void SAL_CALL SvxUnoTextField::removeVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) {}
781
782
// OComponentHelper
783
void SvxUnoTextField::disposing()
784
39.2k
{
785
    // nothing to do
786
39.2k
}
787
788
// lang::XServiceInfo
789
OUString SAL_CALL SvxUnoTextField::getImplementationName()
790
0
{
791
0
    return u"SvxUnoTextField"_ustr;
792
0
}
793
794
uno::Sequence< OUString > SAL_CALL SvxUnoTextField::getSupportedServiceNames()
795
0
{
796
0
    uno::Sequence<OUString> aSeq(4);
797
0
    OUString* pServices = aSeq.getArray();
798
0
    pServices[0] = "com.sun.star.text.TextContent";
799
0
    pServices[1] = "com.sun.star.text.TextField";
800
801
0
    switch (mnServiceId)
802
0
    {
803
0
        case text::textfield::Type::DATE:
804
0
        case text::textfield::Type::TIME:
805
0
        case text::textfield::Type::EXTENDED_TIME:
806
0
            pServices[2] = "com.sun.star.text.TextField.DateTime";
807
0
            pServices[3] = "com.sun.star.text.textfield.DateTime";
808
0
        break;
809
0
        case text::textfield::Type::URL:
810
0
            pServices[2] = "com.sun.star.text.TextField.URL";
811
0
            pServices[3] = "com.sun.star.text.textfield.URL";
812
0
        break;
813
0
        case text::textfield::Type::PAGE:
814
0
            pServices[2] = "com.sun.star.text.TextField.PageNumber";
815
0
            pServices[3] = "com.sun.star.text.textfield.PageNumber";
816
0
        break;
817
0
        case text::textfield::Type::PAGES:
818
0
            pServices[2] = "com.sun.star.text.TextField.PageCount";
819
0
            pServices[3] = "com.sun.star.text.textfield.PageCount";
820
0
        break;
821
0
        case text::textfield::Type::DOCINFO_TITLE:
822
0
            pServices[2] = "com.sun.star.text.TextField.docinfo.Title";
823
0
            pServices[3] = "com.sun.star.text.textfield.docinfo.Title";
824
0
        break;
825
0
        case text::textfield::Type::TABLE:
826
0
            pServices[2] = "com.sun.star.text.TextField.SheetName";
827
0
            pServices[3] = "com.sun.star.text.textfield.SheetName";
828
0
        break;
829
0
        case text::textfield::Type::EXTENDED_FILE:
830
0
            pServices[2] = "com.sun.star.text.TextField.FileName";
831
0
            pServices[3] = "com.sun.star.text.textfield.FileName";
832
0
        break;
833
0
        case text::textfield::Type::AUTHOR:
834
0
            pServices[2] = "com.sun.star.text.TextField.Author";
835
0
            pServices[3] = "com.sun.star.text.textfield.Author";
836
0
        break;
837
0
        case text::textfield::Type::MEASURE:
838
0
            pServices[2] = "com.sun.star.text.TextField.Measure";
839
0
            pServices[3] = "com.sun.star.text.textfield.Measure";
840
0
        break;
841
0
        case text::textfield::Type::PRESENTATION_HEADER:
842
0
            pServices[2] = "com.sun.star.presentation.TextField.Header";
843
0
            pServices[3] = "com.sun.star.presentation.textfield.Header";
844
0
        break;
845
0
        case text::textfield::Type::PRESENTATION_FOOTER:
846
0
            pServices[2] = "com.sun.star.presentation.TextField.Footer";
847
0
            pServices[3] = "com.sun.star.presentation.textfield.Footer";
848
0
        break;
849
0
        case text::textfield::Type::PRESENTATION_DATE_TIME:
850
0
            pServices[2] = "com.sun.star.presentation.TextField.DateTime";
851
0
            pServices[3] = "com.sun.star.presentation.textfield.DateTime";
852
0
        break;
853
0
        case text::textfield::Type::PAGE_NAME:
854
0
            pServices[2] = "com.sun.star.text.TextField.PageName";
855
0
            pServices[3] = "com.sun.star.text.textfield.PageName";
856
0
        break;
857
0
        case text::textfield::Type::DOCINFO_CUSTOM:
858
0
            pServices[2] = "com.sun.star.text.TextField.DocInfo.Custom";
859
0
            pServices[3] = "com.sun.star.text.textfield.DocInfo.Custom";
860
0
        break;
861
0
        default:
862
0
            aSeq.realloc(0);
863
0
    }
864
865
0
    return aSeq;
866
0
}
867
868
sal_Bool SAL_CALL SvxUnoTextField::supportsService( const OUString& ServiceName )
869
0
{
870
0
    return cppu::supportsService( this, ServiceName );
871
0
}
872
873
uno::Reference< uno::XInterface > SvxUnoTextCreateTextField( std::u16string_view ServiceSpecifier )
874
27.4k
{
875
27.4k
    uno::Reference< uno::XInterface > xRet;
876
877
    // #i93308# up to OOo 3.2 we used this wrong namespace name with the capital T & F. This is
878
    // fixed since OOo 3.2 but for compatibility we will still provide support for the wrong notation.
879
880
27.4k
    std::u16string_view aFieldType;
881
27.4k
    if( (o3tl::starts_with( ServiceSpecifier, u"com.sun.star.text.textfield.", &aFieldType )) ||
882
27.4k
        (o3tl::starts_with( ServiceSpecifier, u"com.sun.star.text.TextField.", &aFieldType )) )
883
26.8k
    {
884
26.8k
        sal_Int32 nId = text::textfield::Type::UNSPECIFIED;
885
886
26.8k
        if ( aFieldType == u"DateTime" )
887
0
        {
888
0
            nId = text::textfield::Type::DATE;
889
0
        }
890
26.8k
        else if ( aFieldType == u"URL" )
891
207
        {
892
207
            nId = text::textfield::Type::URL;
893
207
        }
894
26.6k
        else if ( aFieldType == u"PageNumber" )
895
25.7k
        {
896
25.7k
            nId = text::textfield::Type::PAGE;
897
25.7k
        }
898
909
        else if ( aFieldType == u"PageCount" )
899
42
        {
900
42
            nId = text::textfield::Type::PAGES;
901
42
        }
902
867
        else if ( aFieldType == u"SheetName" )
903
69
        {
904
69
            nId = text::textfield::Type::TABLE;
905
69
        }
906
798
        else if ( aFieldType == u"FileName" )
907
0
        {
908
0
            nId = text::textfield::Type::EXTENDED_FILE;
909
0
        }
910
798
        else if (aFieldType == u"docinfo.Title" ||
911
798
                 aFieldType == u"DocInfo.Title" )
912
0
        {
913
0
            nId = text::textfield::Type::DOCINFO_TITLE;
914
0
        }
915
798
        else if ( aFieldType == u"Author" )
916
0
        {
917
0
            nId = text::textfield::Type::AUTHOR;
918
0
        }
919
798
        else if ( aFieldType == u"Measure" )
920
0
        {
921
0
            nId = text::textfield::Type::MEASURE;
922
0
        }
923
798
        else if (aFieldType == u"DocInfo.Custom")
924
0
        {
925
0
            nId = text::textfield::Type::DOCINFO_CUSTOM;
926
0
        }
927
928
26.8k
        if (nId != text::textfield::Type::UNSPECIFIED)
929
26.0k
            xRet = getXWeak(new SvxUnoTextField( nId ));
930
26.8k
    }
931
932
27.4k
    return xRet;
933
27.4k
}
934
935
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */