1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 
29 #ifndef _SVX_ACCESSIBILITY_DESCRIPTION_GENERATOR_HXX
30 #define _SVX_ACCESSIBILITY_DESCRIPTION_GENERATOR_HXX
31 
32 #include <com/sun/star/drawing/XShape.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <rtl/ustrbuf.hxx>
35 #include "svx/svxdllapi.h"
36 
37 
38 namespace accessibility {
39 
40 /** This class creates description strings for shapes.
41     <p>Initialized with a given shape additional calls to the
42     <member>addProperty</member> method will build a descriptive string that
43     starts with a general shape description and the shapes style.  Appended
44     are all the specified property names and values that differ from the
45     default values in the style.</p>
46 */
47 class SVX_DLLPUBLIC DescriptionGenerator
48 {
49 public:
50     enum PropertyType {
51         COLOR,
52         INTEGER,
53         STRING,
54         FILL_STYLE
55     };
56 
57     /** Creates a new description generator with an empty description
58         string.  Usually you will want to call initialize next to specifiy
59         a general description of the shape.
60         @param xShape
61             The shape from which properties will be extracted by later calls
62             to <member>addProperty</member>.
63     */
64     DescriptionGenerator (const ::com::sun::star::uno::Reference<
65         ::com::sun::star::drawing::XShape>& xShape);
66 
67     ~DescriptionGenerator (void);
68 
69     /** Initialize the description with the given prefix followed by the
70         shape's style in parantheses and a colon.
71         @param sPrefix
72             An introductory description of the shape that is made more
73             specific by later calls to <member>addProperty</member>.
74     */
75     void Initialize (::rtl::OUString sPrefix);
76 
77     /** Initialize the description with the specified string from the
78         resource followed by the shape's style in parantheses and a colon.
79         @param nResourceId
80             A resource id the specifies the introductory description of the
81             shape that is made more specific by later calls to
82             <member>addProperty</member>.
83     */
84     void Initialize (sal_Int32 nResourceId);
85 
86     /**  Returns the description string and then resets it.  Usually called
87          as last method before destroying the object.
88          @return
89              The description string in its current form.
90     */
91     ::rtl::OUString operator() (void);
92 
93     /** Add the given property name and its associated value to the
94         description string.  If the property value does not differ from the
95         default value of the shape's style then the description string is
96         not modified.
97         @param sPropertyName
98             The Name of the property to append.
99         @param aType
100             Type of the property's value.  It controls the transformation
101             into the value's string representation.
102         @param sLocalizedName
103             Localized name of the property.  An empty string tells the
104             method to use the property name instead.
105         @param nWhichId
106             This which id is used to localize the property value.  If it is
107             not known a value of -1 signals to use a default representation.
108     */
109     void AddProperty (const ::rtl::OUString& sPropertyName,
110         PropertyType aType,
111         const ::rtl::OUString& sLocalizedName=::rtl::OUString(),
112         long nWhichId=-1);
113 
114     /** Add the given property name and its associated value to the
115         description string.  If the property value does not differ from the
116         default value of the shape's style then the description string is
117         not modified.  This method forwards the request to its cousing but
118         first replaces the id of the localized name by the associated string
119         from the resource.
120         @param sPropertyName
121             The Name of the property to append.
122         @param aType
123             Type of the property's value.  It controls the transformation
124             into the value's string representation.
125         @param nResourceId
126             Id of the kocalized name of the property int the resource.
127         @param nWhichId
128             This which id is used to localize the property value.  If it is
129             not known a value of -1 signals to use a default representation.
130     */
131     void AddProperty (const ::rtl::OUString& sPropertyName,
132         PropertyType aType,
133         sal_Int32 nResourceId,
134         long nWhichId=-1);
135 
136     /** Append the given string as is to the current description.
137         @param sString
138             String to append to the current description.  It is not modified
139             in any way.
140     */
141     void AppendString (const ::rtl::OUString& sString);
142 
143     /** This method adds for debuging and development the list of all known
144         properties to the description.   Don't use in production code.
145     */
146     void AddPropertyNames (void);
147 
148     /** Add properties that describe line and border attributes.
149     */
150     void AddLineProperties (void);
151 
152     /** Add properties that describe how areas are filled.
153     */
154     void AddFillProperties (void);
155 
156     /** Add properties that describesattributes of 3D objects.
157     */
158     void Add3DProperties (void);
159 
160     /** Add properties that describe text attributes.
161     */
162     void AddTextProperties (void);
163 
164 private:
165     /// Reference to the shape from which the properties are extracted.
166     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape> mxShape;
167 
168     /// Reference to the shape's property set.
169     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> mxSet;
170 
171     /// The description string that is build.
172     ::rtl::OUStringBuffer msDescription;
173 
174     /** This flag is used to determine whether to insert a separator e.g. a
175         comma before the next property.
176     */
177     bool mbIsFirstProperty;
178 
179     /** Add a property value formated as color to the description string.
180     */
181     SVX_DLLPRIVATE void AddColor (const ::rtl::OUString& sPropertyName,
182         const ::rtl::OUString& sLocalizedName);
183 
184     /** Add a property value of unknown type to the description string.
185     */
186     SVX_DLLPRIVATE void AddUnknown (const ::rtl::OUString& sPropertyName,
187         const ::rtl::OUString& sLocalizedName);
188 
189     /** Add a property value formated as integer to the description string.
190     */
191     SVX_DLLPRIVATE void AddInteger (const ::rtl::OUString& sPropertyName,
192         const ::rtl::OUString& sLocalizedName);
193 
194     /** Add a property value formated as string to the description string.
195         @param sPropertyName
196             Name of the property.
197     */
198     SVX_DLLPRIVATE void AddString (const ::rtl::OUString& sPropertyName,
199         const ::rtl::OUString& sLocalizedName, long nWhichId = -1);
200 
201     /** Add a property value formated as fill style to the description
202         string.  If the fill style is <const>HATCH</const>,
203         <const>GRADIENT</const>, or <const>BITMAP</const>, then the of the
204         hatch, gradient, or bitmap is appended as well.
205         @param sPropertyName
206             Name of the property.  Usually this will be "FillStyle".
207     */
208     SVX_DLLPRIVATE void AddFillStyle (const ::rtl::OUString& sPropertyName,
209         const ::rtl::OUString& sLocalizedName);
210 };
211 
212 
213 } // end of namespace accessibility
214 
215 
216 #endif
217 
218