summaryrefslogtreecommitdiff
path: root/include/svx/DescriptionGenerator.hxx
blob: 6a7b57fc6bdeabb45cdf10dec0310e12c8c1fe7f (plain)
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
/* -*- 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_SVX_DESCRIPTIONGENERATOR_HXX
#define INCLUDED_SVX_DESCRIPTIONGENERATOR_HXX

#include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <rtl/ustrbuf.hxx>
#include <svx/svxdllapi.h>


namespace accessibility {

/** This class creates description strings for shapes.
    <p>Initialized with a given shape additional calls to the
    <member>addProperty</member> method will build a descriptive string that
    starts with a general shape description and the shapes style.  Appended
    are all the specified property names and values that differ from the
    default values in the style.</p>
*/
class SVX_DLLPUBLIC DescriptionGenerator
{
public:
    enum class PropertyType {
        Color,
        Integer,
        String,
        FillStyle
    };

    /** Creates a new description generator with an empty description
        string.  Usually you will want to call initialize next to specify
        a general description of the shape.
        @param xShape
            The shape from which properties will be extracted by later calls
            to <member>addProperty</member>.
    */
    DescriptionGenerator (const css::uno::Reference<
        css::drawing::XShape>& xShape);

    ~DescriptionGenerator();

    /** Initialize the description with the given prefix followed by the
        shape style in parentheses and a colon.
        @param sPrefix
            An introductory description of the shape that is made more
            specific by later calls to <member>addProperty</member>.
    */
    void Initialize (const OUString& sPrefix);

    /** Initialize the description with the specified string from the
        resource followed by the shape style in parentheses and a colon.
        @param pResourceId
            A resource id the specifies the introductory description of the
            shape that is made more specific by later calls to
            <member>addProperty</member>.
    */
    void Initialize(const char* pResourceId);

    /**  Returns the description string and then resets it.  Usually called
         as last method before destroying the object.
         @return
             The description string in its current form.
    */
    OUString operator() (void);

    /** Add the given property name and its associated value to the
        description string.  If the property value does not differ from the
        default value of the shape's style then the description string is
        not modified.
        @param sPropertyName
            The Name of the property to append.
        @param aType
            Type of the property's value.  It controls the transformation
            into the value's string representation.
        @param sLocalizedName
            Localized name of the property.  An empty string tells the
            method to use the property name instead.
        @param nWhichId
            This which id is used to localize the property value.  If it is
            not known a value of -1 signals to use a default representation.
    */
    void AddProperty (const OUString& sPropertyName,
        PropertyType aType,
        const OUString& sLocalizedName=OUString(),
        sal_uInt16 nWhichId = 0xffff);

    /** Add the given property name and its associated value to the
        description string.  If the property value does not differ from the
        default value of the shape's style then the description string is
        not modified.  This method forwards the request to its cousin but
        first replaces the id of the localized name by the associated string
        from the resource.
        @param sPropertyName
            The Name of the property to append.
        @param aType
            Type of the property's value.  It controls the transformation
            into the value's string representation.
        @param pResourceId
            Id of the localized name of the property int the resource.
        @param nWhichId
            This which id is used to localize the property value.  If it is
            not known a value of -1 signals to use a default representation.
    */
    void AddProperty (const OUString& sPropertyName,
        PropertyType aType,
        const char* pResourceId,
        sal_uInt16 nWhichId = 0xffff);

    /** Append the given string as is to the current description.
        @param sString
            String to append to the current description.  It is not modified
            in any way.
    */
    void AppendString (const OUString& sString);

    /** Add properties that describe line and border attributes.
    */
    void AddLineProperties();

    /** Add properties that describe how areas are filled.
    */
    void AddFillProperties();

    /** Add properties that describes attributes of 3D objects.
    */
    void Add3DProperties();

    /** Add properties that describe text attributes.
    */
    void AddTextProperties();

private:
    /// Reference to the shape from which the properties are extracted.
    css::uno::Reference< css::drawing::XShape> mxShape;

    /// Reference to the shape's property set.
    css::uno::Reference< css::beans::XPropertySet> mxSet;

    /// The description string that is build.
    OUStringBuffer msDescription;

    /** This flag is used to determine whether to insert a separator e.g. a
        comma before the next property.
    */
    bool mbIsFirstProperty;

    /** Add a property value formatted as color to the description string.
    */
    SVX_DLLPRIVATE void AddColor (const OUString& sPropertyName,
        const OUString& sLocalizedName);

    /** Add a property value formatted as integer to the description string.
    */
    SVX_DLLPRIVATE void AddInteger (const OUString& sPropertyName,
        const OUString& sLocalizedName);

    /** Add a property value formatted as string to the description string.
        @param sPropertyName
            Name of the property.
    */
    SVX_DLLPRIVATE void AddString (const OUString& sPropertyName,
        const OUString& sLocalizedName, sal_uInt16 nWhichId);

    /** Add a property value formatted as fill style to the description
        string.  If the fill style is <const>HATCH</const>,
        <const>GRADIENT</const>, or <const>BITMAP</const>, then the of the
        hatch, gradient, or bitmap is appended as well.
        @param sPropertyName
            Name of the property.  Usually this will be "FillStyle".
    */
    SVX_DLLPRIVATE void AddFillStyle (const OUString& sPropertyName,
        const OUString& sLocalizedName);
};


} // end of namespace accessibility


#endif

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