Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/forms/formattributes.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 "formattributes.hxx"
21
22
#include <xmloff/xmlnamespace.hxx>
23
#include <xmloff/xmlimp.hxx>
24
#include <osl/diagnose.h>
25
26
using namespace xmloff::token;
27
28
namespace xmloff
29
{
30
31
    using namespace ::com::sun::star::uno;
32
33
    //= OAttributeMetaData
34
    OUString OAttributeMetaData::getCommonControlAttributeName(CCAFlags _nId)
35
0
    {
36
0
        switch (_nId)
37
0
        {
38
0
            case CCAFlags::Name:              return u"name"_ustr;
39
0
            case CCAFlags::ServiceName:      return u"control-implementation"_ustr;
40
0
            case CCAFlags::ButtonType:       return u"button-type"_ustr;
41
// disabled(AddAttributeIdLegacy)   case CCAFlags::ControlId:        return "id";
42
0
            case CCAFlags::CurrentSelected:  return u"current-selected"_ustr;
43
0
            case CCAFlags::CurrentValue:     return u"current-value"_ustr;
44
0
            case CCAFlags::Disabled:          return u"disabled"_ustr;
45
0
            case CCAFlags::EnableVisible:     return u"visible"_ustr;
46
0
            case CCAFlags::Dropdown:          return u"dropdown"_ustr;
47
0
            case CCAFlags::For:               return u"for"_ustr;
48
0
            case CCAFlags::ImageData:        return u"image-data"_ustr;
49
0
            case CCAFlags::Label:             return u"label"_ustr;
50
0
            case CCAFlags::MaxLength:        return u"max-length"_ustr;
51
0
            case CCAFlags::Printable:         return u"printable"_ustr;
52
0
            case CCAFlags::ReadOnly:          return u"readonly"_ustr;
53
0
            case CCAFlags::Selected:          return u"selected"_ustr;
54
0
            case CCAFlags::Size:              return u"size"_ustr;
55
0
            case CCAFlags::TabIndex:         return u"tab-index"_ustr;
56
0
            case CCAFlags::TargetFrame:      return u"target-frame"_ustr;
57
0
            case CCAFlags::TargetLocation:   return u"href"_ustr;      // the only special thing here: TargetLocation is represented by an xlink:href attribute
58
0
            case CCAFlags::TabStop:          return u"tab-stop"_ustr;
59
0
            case CCAFlags::Title:             return u"title"_ustr;
60
0
            case CCAFlags::Value:             return u"value"_ustr;
61
0
            case CCAFlags::Orientation:       return u"orientation"_ustr;
62
0
            case CCAFlags::VisualEffect:     return u"visual-effect"_ustr;
63
0
            default:
64
0
                OSL_FAIL("OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
65
0
        }
66
0
        return u""_ustr;
67
0
    }
68
69
    sal_Int32 OAttributeMetaData::getCommonControlAttributeToken(CCAFlags _nId)
70
194k
    {
71
194k
        switch (_nId)
72
194k
        {
73
10.7k
            case CCAFlags::Name:             return XML_NAME;
74
0
            case CCAFlags::ServiceName:      return XML_CONTROL_IMPLEMENTATION;
75
10.7k
            case CCAFlags::ButtonType:       return XML_BUTTON_TYPE;
76
// disabled(AddAttributeIdLegacy)   case CCAFlags::ControlId:        return "id";
77
10.7k
            case CCAFlags::CurrentSelected:  return XML_CURRENT_SELECTED;
78
0
            case CCAFlags::CurrentValue:     return XML_CURRENT_VALUE;
79
10.7k
            case CCAFlags::Disabled:         return XML_DISABLED;
80
0
            case CCAFlags::EnableVisible:    return XML_VISIBLE;
81
10.7k
            case CCAFlags::Dropdown:         return XML_DROPDOWN;
82
0
            case CCAFlags::For:              return XML_FOR;
83
0
            case CCAFlags::ImageData:        return XML_IMAGE_DATA;
84
10.7k
            case CCAFlags::Label:            return XML_LABEL;
85
10.7k
            case CCAFlags::MaxLength:        return XML_MAX_LENGTH;
86
10.7k
            case CCAFlags::Printable:        return XML_PRINTABLE;
87
10.7k
            case CCAFlags::ReadOnly:         return XML_READONLY;
88
10.7k
            case CCAFlags::Selected:         return XML_SELECTED;
89
10.7k
            case CCAFlags::Size:             return XML_SIZE;
90
10.7k
            case CCAFlags::TabIndex:         return XML_TAB_INDEX;
91
10.7k
            case CCAFlags::TargetFrame:      return XML_TARGET_FRAME;
92
10.7k
            case CCAFlags::TargetLocation:   return XML_HREF;      // the only special thing here: TargetLocation is represented by an xlink:href attribute
93
10.7k
            case CCAFlags::TabStop:          return XML_TAB_STOP;
94
10.7k
            case CCAFlags::Title:            return XML_TITLE;
95
0
            case CCAFlags::Value:            return XML_VALUE;
96
10.7k
            case CCAFlags::Orientation:      return XML_ORIENTATION;
97
10.7k
            case CCAFlags::VisualEffect:     return XML_VISUAL_EFFECT;
98
0
            default:
99
0
                assert(false && "OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
100
194k
        }
101
0
        return XML_UNKNOWN;
102
194k
    }
103
104
    sal_uInt16 OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags _nId)
105
0
    {
106
0
        if (CCAFlags::TargetLocation == _nId)
107
0
            return XML_NAMESPACE_XLINK;
108
109
0
        if (CCAFlags::TargetFrame == _nId)
110
0
            return XML_NAMESPACE_OFFICE;
111
112
0
        return XML_NAMESPACE_FORM;
113
0
    }
114
115
    OUString OAttributeMetaData::getFormAttributeName(FormAttributes _eAttrib)
116
0
    {
117
0
        switch (_eAttrib)
118
0
        {
119
0
            case faName:                return u"name"_ustr;
120
0
            case faAction:              return u"href"_ustr;      // the only special thing here: Action is represented by an xlink:href attribute
121
0
            case faEnctype:             return u"enctype"_ustr;
122
0
            case faMethod:              return u"method"_ustr;
123
0
            case faAllowDeletes:        return u"allow-deletes"_ustr;
124
0
            case faAllowInserts:        return u"allow-inserts"_ustr;
125
0
            case faAllowUpdates:        return u"allow-updates"_ustr;
126
0
            case faApplyFilter:         return u"apply-filter"_ustr;
127
0
            case faCommand:             return u"command"_ustr;
128
0
            case faCommandType:         return u"command-type"_ustr;
129
0
            case faEscapeProcessing:    return u"escape-processing"_ustr;
130
0
            case faDatasource:          return u"datasource"_ustr;
131
0
            case faDetailFields:        return u"detail-fields"_ustr;
132
0
            case faFilter:              return u"filter"_ustr;
133
0
            case faIgnoreResult:        return u"ignore-result"_ustr;
134
0
            case faMasterFields:        return u"master-fields"_ustr;
135
0
            case faNavigationMode:      return u"navigation-mode"_ustr;
136
0
            case faOrder:               return u"order"_ustr;
137
0
            case faTabbingCycle:        return u"tab-cycle"_ustr;
138
0
            default:
139
0
                OSL_FAIL("OAttributeMetaData::getFormAttributeName: invalid id!");
140
0
        }
141
0
        return u""_ustr;
142
0
    }
143
144
    sal_Int32 OAttributeMetaData::getFormAttributeToken(FormAttributes _eAttrib)
145
161k
    {
146
161k
        switch (_eAttrib)
147
161k
        {
148
0
            case faName:                return XML_NAME;
149
0
            case faAction:              return XML_HREF;      // the only special thing here: Action is represented by an xlink:href attribute
150
10.7k
            case faEnctype:             return XML_ENCTYPE;
151
10.7k
            case faMethod:              return XML_METHOD;
152
10.7k
            case faAllowDeletes:        return XML_ALLOW_DELETES;
153
10.7k
            case faAllowInserts:        return XML_ALLOW_INSERTS;
154
10.7k
            case faAllowUpdates:        return XML_ALLOW_UPDATES;
155
10.7k
            case faApplyFilter:         return XML_APPLY_FILTER;
156
10.7k
            case faCommand:             return XML_COMMAND;
157
10.7k
            case faCommandType:         return XML_COMMAND_TYPE;
158
10.7k
            case faEscapeProcessing:    return XML_ESCAPE_PROCESSING;
159
10.7k
            case faDatasource:          return XML_DATASOURCE;
160
0
            case faDetailFields:        return XML_DETAIL_FIELDS;
161
10.7k
            case faFilter:              return XML_FILTER;
162
10.7k
            case faIgnoreResult:        return XML_IGNORE_RESULT;
163
0
            case faMasterFields:        return XML_MASTER_FIELDS;
164
10.7k
            case faNavigationMode:      return XML_NAVIGATION_MODE;
165
10.7k
            case faOrder:               return XML_ORDER;
166
10.7k
            case faTabbingCycle:        return XML_TAB_CYCLE;
167
0
            default:
168
0
                assert(false && "OAttributeMetaData::getFormAttributeName: invalid id!");
169
161k
        }
170
0
        return XML_NONE;
171
161k
    }
172
173
    sal_uInt16 OAttributeMetaData::getFormAttributeNamespace(FormAttributes _eAttrib)
174
0
    {
175
0
        if (faAction == _eAttrib)
176
0
            return XML_NAMESPACE_XLINK;
177
178
0
        return XML_NAMESPACE_FORM;
179
0
    }
180
181
    OUString OAttributeMetaData::getDatabaseAttributeName(DAFlags _nId)
182
0
    {
183
0
        switch (_nId)
184
0
        {
185
0
            case DAFlags::BoundColumn:       return u"bound-column"_ustr;
186
0
            case DAFlags::ConvertEmpty:      return u"convert-empty-to-null"_ustr;
187
0
            case DAFlags::DataField:         return u"data-field"_ustr;
188
0
            case DAFlags::ListSource:        return u"list-source"_ustr;
189
0
            case DAFlags::ListSource_TYPE:   return u"list-source-type"_ustr;
190
0
            case DAFlags::InputRequired:     return u"input-required"_ustr;
191
0
            default:
192
0
                OSL_FAIL("OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
193
0
        }
194
0
        return u""_ustr;
195
0
    }
196
197
    sal_Int32 OAttributeMetaData::getDatabaseAttributeToken(DAFlags _nId)
198
53.9k
    {
199
53.9k
        switch (_nId)
200
53.9k
        {
201
10.7k
            case DAFlags::BoundColumn:       return XML_BOUND_COLUMN;
202
10.7k
            case DAFlags::ConvertEmpty:      return XML_CONVERT_EMPTY_TO_NULL;
203
10.7k
            case DAFlags::DataField:         return XML_DATA_FIELD;
204
0
            case DAFlags::ListSource:        return XML_LIST_SOURCE;
205
10.7k
            case DAFlags::ListSource_TYPE:   return XML_LIST_SOURCE_TYPE;
206
10.7k
            case DAFlags::InputRequired:     return XML_INPUT_REQUIRED;
207
0
            default:
208
0
                assert(false && "OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
209
53.9k
        }
210
0
        return XML_NONE;
211
53.9k
    }
212
213
    OUString OAttributeMetaData::getBindingAttributeName(BAFlags _nId)
214
0
    {
215
0
        switch (_nId)
216
0
        {
217
0
            case BAFlags::LinkedCell:       return u"linked-cell"_ustr;
218
0
            case BAFlags::ListLinkingType: return u"list-linkage-type"_ustr;
219
0
            case BAFlags::ListCellRange:   return u"source-cell-range"_ustr;
220
0
            default:
221
0
                OSL_FAIL("OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
222
0
        }
223
0
        return u""_ustr;
224
0
    }
225
226
    sal_Int32 OAttributeMetaData::getBindingAttributeToken(BAFlags _nId)
227
0
    {
228
0
        switch (_nId)
229
0
        {
230
0
            case BAFlags::LinkedCell:      return XML_LINKED_CELL;
231
0
            case BAFlags::ListLinkingType: return XML_LIST_LINKAGE_TYPE;
232
0
            case BAFlags::ListCellRange:   return XML_SOURCE_CELL_RANGE;
233
0
            default:
234
0
                assert(false && "OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
235
0
        }
236
0
        return XML_UNKNOWN;
237
0
    }
238
239
    OUString OAttributeMetaData::getSpecialAttributeName(SCAFlags _nId)
240
0
    {
241
0
        switch (_nId)
242
0
        {
243
0
            case SCAFlags::EchoChar:             return u"echo-char"_ustr;
244
0
            case SCAFlags::MaxValue:             return u"max-value"_ustr;
245
0
            case SCAFlags::MinValue:             return u"min-value"_ustr;
246
0
            case SCAFlags::Validation:            return u"validation"_ustr;
247
0
            case SCAFlags::GroupName:            return u"group-name"_ustr;
248
0
            case SCAFlags::MultiLine:            return u"multi-line"_ustr;
249
0
            case SCAFlags::AutoCompletion:  return u"auto-complete"_ustr;
250
0
            case SCAFlags::Multiple:              return u"multiple"_ustr;
251
0
            case SCAFlags::DefaultButton:        return u"default-button"_ustr;
252
0
            case SCAFlags::CurrentState:         return u"current-state"_ustr;
253
0
            case SCAFlags::IsTristate:           return u"is-tristate"_ustr;
254
0
            case SCAFlags::State:                 return u"state"_ustr;
255
0
            case SCAFlags::ColumnStyleName:     return u"text-style-name"_ustr;
256
0
            case SCAFlags::StepSize:             return u"step-size"_ustr;
257
0
            case SCAFlags::PageStepSize:        return u"page-step-size"_ustr;
258
0
            case SCAFlags::RepeatDelay:          return u"delay-for-repeat"_ustr;
259
0
            case SCAFlags::Toggle:                return u"toggle"_ustr;
260
0
            case SCAFlags::FocusOnClick:        return u"focus-on-click"_ustr;
261
0
            default:
262
0
                OSL_FAIL("OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
263
0
        }
264
0
        return u""_ustr;
265
0
    }
266
267
    sal_Int32 OAttributeMetaData::getSpecialAttributeToken(SCAFlags _nId)
268
129k
    {
269
129k
        switch (_nId)
270
129k
        {
271
0
            case SCAFlags::EchoChar:        return XML_ECHO_CHAR;
272
0
            case SCAFlags::MaxValue:        return XML_MAX_VALUE;
273
0
            case SCAFlags::MinValue:        return XML_MIN_VALUE;
274
10.7k
            case SCAFlags::Validation:      return XML_VALIDATION;
275
10.7k
            case SCAFlags::GroupName:       return XML_GROUP_NAME;
276
10.7k
            case SCAFlags::MultiLine:       return XML_MULTI_LINE;
277
10.7k
            case SCAFlags::AutoCompletion:  return XML_AUTO_COMPLETE;
278
10.7k
            case SCAFlags::Multiple:        return XML_MULTIPLE;
279
10.7k
            case SCAFlags::DefaultButton:   return XML_DEFAULT_BUTTON;
280
10.7k
            case SCAFlags::CurrentState:    return XML_CURRENT_STATE;
281
10.7k
            case SCAFlags::IsTristate:      return XML_IS_TRISTATE;
282
10.7k
            case SCAFlags::State:           return XML_STATE;
283
0
            case SCAFlags::ColumnStyleName: return XML_TEXT_STYLE_NAME;
284
0
            case SCAFlags::StepSize:        return XML_STEP_SIZE;
285
10.7k
            case SCAFlags::PageStepSize:    return XML_PAGE_STEP_SIZE;
286
0
            case SCAFlags::RepeatDelay:     return XML_DELAY_FOR_REPEAT;
287
10.7k
            case SCAFlags::Toggle:          return XML_TOGGLE;
288
10.7k
            case SCAFlags::FocusOnClick:    return XML_FOCUS_ON_CLICK;
289
0
            default:
290
0
                assert(false && "OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
291
129k
        }
292
0
        return XML_UNKNOWN;
293
129k
    }
294
295
    sal_uInt16 OAttributeMetaData::getSpecialAttributeNamespace(SCAFlags _nId)
296
0
    {
297
0
        switch( _nId )
298
0
        {
299
0
            case SCAFlags::GroupName:            return XML_NAMESPACE_FORMX;
300
0
            default: break;
301
0
        }
302
0
        return XML_NAMESPACE_FORM;
303
0
    }
304
305
    OUString OAttributeMetaData::getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib)
306
0
    {
307
0
        switch (_eAttrib)
308
0
        {
309
0
            case ofaAutomaticFocus:     return u"automatic-focus"_ustr;
310
0
            case ofaApplyDesignMode:    return u"apply-design-mode"_ustr;
311
0
            default:
312
0
                OSL_FAIL("OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
313
0
        }
314
0
        return u""_ustr;
315
0
    }
316
317
    xmloff::token::XMLTokenEnum OAttributeMetaData::getOfficeFormsAttributeToken(OfficeFormsAttributes _eAttrib)
318
228
    {
319
228
        switch (_eAttrib)
320
228
        {
321
114
            case ofaAutomaticFocus:     return token::XML_AUTOMATIC_FOCUS;
322
114
            case ofaApplyDesignMode:    return token::XML_APPLY_DESIGN_MODE;
323
0
            default:
324
0
                assert(false && "OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
325
228
        }
326
0
        return token::XML_NONE;
327
228
    }
328
329
    //= OAttribute2Property
330
    OAttribute2Property::OAttribute2Property()
331
10.7k
    {
332
10.7k
    }
333
334
    OAttribute2Property::~OAttribute2Property()
335
10.7k
    {
336
10.7k
    }
337
338
    const OAttribute2Property::AttributeAssignment* OAttribute2Property::getAttributeTranslation(
339
            sal_Int32 nAttributeToken)
340
0
    {
341
0
        auto aPos = m_aKnownProperties.find(nAttributeToken & TOKEN_MASK);
342
0
        if (m_aKnownProperties.end() != aPos)
343
0
            return &aPos->second;
344
0
        return nullptr;
345
0
    }
346
347
    void OAttribute2Property::addStringProperty(
348
        sal_Int32 nAttributeToken, const OUString& _rPropertyName)
349
118k
    {
350
118k
        implAdd(nAttributeToken, _rPropertyName, ::cppu::UnoType<OUString>::get());
351
118k
    }
352
353
    void OAttribute2Property::addBooleanProperty(
354
        sal_Int32 nAttributeToken, const OUString& _rPropertyName,
355
        const bool /*_bAttributeDefault*/, const bool _bInverseSemantics)
356
248k
    {
357
248k
        AttributeAssignment& aAssignment = implAdd(nAttributeToken, _rPropertyName, cppu::UnoType<bool>::get());
358
248k
        aAssignment.bInverseSemantics = _bInverseSemantics;
359
248k
    }
360
361
    void OAttribute2Property::addInt16Property(
362
        sal_Int32 nAttributeToken, const OUString& _rPropertyName)
363
43.1k
    {
364
43.1k
        implAdd(nAttributeToken, _rPropertyName, ::cppu::UnoType<sal_Int16>::get());
365
43.1k
    }
366
367
    void OAttribute2Property::addInt32Property(
368
        sal_Int32 nAttributeToken, const OUString& _rPropertyName)
369
10.7k
    {
370
10.7k
        implAdd( nAttributeToken, _rPropertyName, ::cppu::UnoType<sal_Int32>::get() );
371
10.7k
    }
372
373
    void OAttribute2Property::addEnumPropertyImpl(
374
            sal_Int32 nAttributeToken, const OUString& _rPropertyName,
375
            const SvXMLEnumMapEntry<sal_uInt16>* _pValueMap,
376
            const css::uno::Type* _pType)
377
118k
    {
378
118k
        AttributeAssignment& aAssignment = implAdd(nAttributeToken, _rPropertyName,
379
118k
            _pType ? *_pType : ::cppu::UnoType<sal_Int32>::get());
380
118k
        aAssignment.pEnumMap = _pValueMap;
381
118k
    }
382
383
    OAttribute2Property::AttributeAssignment& OAttribute2Property::implAdd(
384
            sal_Int32 nAttributeToken, const OUString& _rPropertyName,
385
            const css::uno::Type& _rType)
386
539k
    {
387
539k
        nAttributeToken &= TOKEN_MASK;
388
539k
        OSL_ENSURE(m_aKnownProperties.end() == m_aKnownProperties.find(nAttributeToken),
389
539k
            "OAttribute2Property::implAdd: already have this attribute!");
390
391
539k
        AttributeAssignment aAssignment;
392
539k
        aAssignment.sPropertyName = _rPropertyName;
393
539k
        aAssignment.aPropertyType = _rType;
394
395
        // redundance, the accessor is stored in aAssignment.sAttributeName, too
396
539k
        m_aKnownProperties[nAttributeToken] = std::move(aAssignment);
397
539k
        return m_aKnownProperties[nAttributeToken];
398
539k
    }
399
400
}   // namespace xmloff
401
402
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */