1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_XMLOFF_SOURCE_FORMS_FORMATTRIBUTES_HXX
#define INCLUDED_XMLOFF_SOURCE_FORMS_FORMATTRIBUTES_HXX

#include <sal/config.h>

#include <map>

#include <com/sun/star/uno/Type.hxx>
#include <rtl/ustring.hxx>
#include <sal/types.h>
#include <xmloff/xmlnmspe.hxx>
#include <o3tl/typed_flags_set.hxx>

template<typename EnumT>
struct SvXMLEnumMapEntry;

    // flags for common control attributes
enum class CCAFlags {
    NONE                  = 0x00000000,
    Name                  = 0x00000001,
    ServiceName           = 0x00000002,
    ButtonType            = 0x00000004,
    ControlId             = 0x00000008,
    CurrentSelected       = 0x00000010,
    CurrentValue          = 0x00000020,
    Disabled              = 0x00000040,
    Dropdown              = 0x00000080,
    For                   = 0x00000100,
    ImageData             = 0x00000200,
    Label                 = 0x00000400,
    MaxLength             = 0x00000800,
    Printable             = 0x00001000,
    ReadOnly              = 0x00002000,
    Selected              = 0x00004000,
    Size                  = 0x00008000,
    TabIndex              = 0x00010000,
    TargetFrame           = 0x00020000,
    TargetLocation        = 0x00040000,
    TabStop               = 0x00080000,
    Title                 = 0x00100000,
    Value                 = 0x00200000,
    Orientation           = 0x00400000,
    VisualEffect          = 0x00800000,
    EnableVisible         = 0x01000000,
};
namespace o3tl {
    template<> struct typed_flags<CCAFlags> : is_typed_flags<CCAFlags, 0x01ffffff> {};
}

    // flags for database control attributes
enum class DAFlags {
    NONE                  = 0x0000,
    BoundColumn           = 0x0001,
    ConvertEmpty          = 0x0002,
    DataField             = 0x0004,
    ListSource            = 0x0008,
    ListSource_TYPE       = 0x0010,
    InputRequired         = 0x0020,
};
namespace o3tl {
    template<> struct typed_flags<DAFlags> : is_typed_flags<DAFlags, 0x003f> {};
}

    // flags for binding related control attributes
enum class BAFlags {
    NONE                  = 0x0000,
    LinkedCell            = 0x0001,
    ListLinkingType       = 0x0002,
    ListCellRange         = 0x0004,
    XFormsBind            = 0x0008,
    XFormsListBind        = 0x0010,
    XFormsSubmission      = 0x0020
};
namespace o3tl {
    template<> struct typed_flags<BAFlags> : is_typed_flags<BAFlags, 0x003f> {};
}

    // flags for event attributes
enum class EAFlags {
    NONE                  = 0x0000,
    ControlEvents         = 0x0001,
    OnChange              = 0x0002,
    OnClick               = 0x0004,
    OnDoubleClick         = 0x0008,
    OnSelect              = 0x0010
};
namespace o3tl {
    template<> struct typed_flags<EAFlags> : is_typed_flags<EAFlags, 0x001f> {};
}

    // any other attributes, which are special to some control types
enum class SCAFlags {
    NONE                  = 0x000000,
    EchoChar              = 0x000001,
    MaxValue              = 0x000002,
    MinValue              = 0x000004,
    Validation            = 0x000008,
    GroupName             = 0x000010,
    MultiLine             = 0x000020,
    AutoCompletion        = 0x000080,
    Multiple              = 0x000100,
    DefaultButton         = 0x000200,
    CurrentState          = 0x000400,
    IsTristate            = 0x000800,
    State                 = 0x001000,
    ColumnStyleName       = 0x002000,
    StepSize              = 0x004000,
    PageStepSize          = 0x008000,
    RepeatDelay           = 0x010000,
    Toggle                = 0x020000,
    FocusOnClick          = 0x040000,
    ImagePosition         = 0x080000
};
namespace o3tl {
    template<> struct typed_flags<SCAFlags> : is_typed_flags<SCAFlags, 0x0fffbf> {};
}


namespace xmloff
{

    /// attributes in the xml tag representing a form
    enum FormAttributes
    {
        faName,
        faAction,
        faEnctype,
        faMethod,
        faAllowDeletes,
        faAllowInserts,
        faAllowUpdates,
        faApplyFilter,
        faCommand,
        faCommandType,
        faEscapeProcessing,
        faDatasource,
        faDetailFiels,
        faFilter,
        faIgnoreResult,
        faMasterFields,
        faNavigationMode,
        faOrder,
        faTabbingCycle
    };

    // attributes of the office:forms element
    enum OfficeFormsAttributes
    {
        ofaAutomaticFocus,
        ofaApplyDesignMode
    };

    //= OAttributeMetaData
    /** allows the translation of attribute ids into strings.

        <p>This class does not allow to connect xml attributes to property names or
        something like that, it only deals with the xml side</p>
    */
    class OAttributeMetaData
    {
    public:
        /** calculates the xml attribute representation of a common control attribute.
            @param _nId
                the id of the attribute. Has to be one of the CCA_* constants.
        */
        static const char* getCommonControlAttributeName(CCAFlags _nId);

        /** calculates the xml namespace key to use for a common control attribute
            @param _nId
                the id of the attribute. Has to be one of the CCA_* constants.
        */
        static sal_uInt16 getCommonControlAttributeNamespace(CCAFlags _nId);

        /** retrieves the name of an attribute of a form xml representation
            @param  _eAttrib
                enum value specifying the attribute
        */
        static const char* getFormAttributeName(FormAttributes _eAttrib);

        /** calculates the xml namespace key to use for an attribute of a form xml representation
            @param  _eAttrib
                enum value specifying the attribute
        */
        static sal_uInt16 getFormAttributeNamespace(FormAttributes _eAttrib);

        /** calculates the xml attribute representation of a database attribute.
            @param _nId
                the id of the attribute. Has to be one of the DA_* constants.
        */
        static const char* getDatabaseAttributeName(DAFlags _nId);

        /** calculates the xml namespace key to use for a database attribute.
            @param _nId
                the id of the attribute. Has to be one of the DA_* constants.
        */
        static sal_uInt16 getDatabaseAttributeNamespace()
        {
            // nothing special here
            return XML_NAMESPACE_FORM;
        }

        /** calculates the xml attribute representation of a special attribute.
            @param _nId
                the id of the attribute. Has to be one of the SCA_* constants.
        */
        static const char* getSpecialAttributeName(SCAFlags _nId);

        /** calculates the xml attribute representation of a binding attribute.
            @param _nId
                the id of the attribute. Has to be one of the BA_* constants.
        */
        static const char* getBindingAttributeName(BAFlags _nId);

        /** calculates the xml namespace key to use for a binding attribute.
            @param _nId
                the id of the attribute. Has to be one of the BA_* constants.
        */
        static sal_uInt16 getBindingAttributeNamespace()
        {
            // nothing special here
            return XML_NAMESPACE_FORM;
        }

        /** calculates the xml namespace key to use for a special attribute.
            @param _nId
                the id of the attribute. Has to be one of the SCA_* constants.
        */
        static sal_uInt16 getSpecialAttributeNamespace(SCAFlags _nId);

        /** calculates the xml attribute representation of an attribute of the office:forms element
            @param _nId
                the id of the attribute
        */
        static const char* getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib);

        /** calculates the xml namedspace key of an attribute of the office:forms element
            @param _nId
                the id of the attribute
        */
        static sal_uInt16 getOfficeFormsAttributeNamespace()
        { // nothing special here
          return XML_NAMESPACE_FORM;
        }
    };

    //= OAttribute2Property
    /** some kind of opposite to the OAttributeMetaData class. Able to translate
        attributes into property names/types

        <p>The construction of this class is rather expensive (or at least it's initialization from outside),
        so it should be shared</p>
    */
    class OAttribute2Property final
    {
    public:
        // TODO: maybe the following struct should be used for exports, too. In this case we would not need to
        // store it's instances in a map, but in a vector for faster access.
        struct AttributeAssignment
        {
            OUString                 sPropertyName;          // the property name
            css::uno::Type           aPropertyType;          // the property type

            // entries which are special to some value types
            const SvXMLEnumMapEntry<sal_uInt16>*
                                     pEnumMap;               // the enum map, if applicable
            bool                     bInverseSemantics;      // for booleans: attribute and property value have the same or an inverse semantics?

            AttributeAssignment() : pEnumMap(nullptr), bInverseSemantics(false) { }
        };

    private:
        typedef std::map<OUString, AttributeAssignment> AttributeAssignments;
        AttributeAssignments        m_aKnownProperties;

    public:
        OAttribute2Property();
        ~OAttribute2Property();

        /** return the AttributeAssignment which corresponds to the given attribute

            @param _rAttribName
                the name of the attribute
            @return
                a pointer to the <type>AttributeAssignment</type> structure as requested, NULL if the attribute
                does not represent a property.
        */
        const AttributeAssignment* getAttributeTranslation(
            const OUString& _rAttribName);

        /** add an attribute assignment referring to a string property to the map
            @param _pAttributeName
                the name of the attribute
            @param _rPropertyName
                the name of the property assigned to the attribute
        */
        void    addStringProperty(
            const char* _pAttributeName, const OUString& _rPropertyName);

        /** add an attribute assignment referring to a boolean property to the map

            @param _pAttributeName
                the name of the attribute
            @param _rPropertyName
                the name of the property assigned to the attribute
            @param _bAttributeDefault
                the default value for the attribute.
            @param _bInverseSemantics
                if <TRUE/>, an attribute value of <TRUE/> means a property value of <FALSE/> and vice verse.<br/>
                if <FALSE/>, the attribute value is used as property value directly
        */
        void    addBooleanProperty(
            const char* _pAttributeName, const OUString& _rPropertyName,
            const bool _bAttributeDefault, const bool _bInverseSemantics = false);

        /** add an attribute assignment referring to an int16 property to the map

            @param _pAttributeName
                the name of the attribute
            @param _rPropertyName
                the name of the property assigned to the attribute
        */
        void    addInt16Property(
            const char* _pAttributeName, const OUString& _rPropertyName);

        /** add an attribute assignment referring to an int32 property to the map

            @param _pAttributeName
                the name of the attribute
            @param _rPropertyName
                the name of the property assigned to the attribute
        */
        void    addInt32Property(
            const char* _pAttributeName, const OUString& _rPropertyName );

        /** add an attribute assignment referring to an enum property to the map

            @param _pAttributeName
                the name of the attribute
            @param _rPropertyName
                the name of the property assigned to the attribute
            @param _pValueMap
                the map to translate strings into enum values
            @param _pType
                the type of the property. May be NULL, in this case 32bit integer is assumed.
        */
        template<typename EnumT>
        void    addEnumProperty(
            const char* _pAttributeName, const OUString& _rPropertyName,
            const SvXMLEnumMapEntry<EnumT>* _pValueMap,
            const css::uno::Type* _pType = nullptr)
        {
            addEnumPropertyImpl(_pAttributeName, _rPropertyName,
                                reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(_pValueMap), _pType);
        }

    private:
        void addEnumPropertyImpl(<--- Unused private function: 'OAttribute2Property::addEnumPropertyImpl'
            const char* _pAttributeName, const OUString& _rPropertyName,
            const SvXMLEnumMapEntry<sal_uInt16>* _pValueMap,
            const css::uno::Type* _pType);
        /// some common code for the various add*Property methods
        AttributeAssignment& implAdd(
            const char* _pAttributeName, const OUString& _rPropertyName,
            const css::uno::Type& _rType);
    };
}   // namespace xmloff

#endif // INCLUDED_XMLOFF_SOURCE_FORMS_FORMATTRIBUTES_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */