Line data Source code
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 : #ifndef INCLUDED_SVX_SHAPETYPEHANDLER_HXX
21 : #define INCLUDED_SVX_SHAPETYPEHANDLER_HXX
22 :
23 : #include <svx/AccessibleShapeTreeInfo.hxx>
24 : #include <svx/AccessibleShapeInfo.hxx>
25 : #include <svx/AccessibleShape.hxx>
26 : #include <com/sun/star/accessibility/XAccessible.hpp>
27 : #include <com/sun/star/uno/XInterface.hpp>
28 : #include <com/sun/star/drawing/XShape.hpp>
29 : #include <com/sun/star/document/XEventBroadcaster.hpp>
30 : #include <svx/svxdllapi.h>
31 :
32 : #include <rtl/ustring.hxx>
33 : #include <vector>
34 : #include <boost/unordered_map.hpp>
35 :
36 : namespace accessibility {
37 :
38 : /** Use an integer to represent shape type ids. A ShapeTypeId is unique
39 : inside one project but is not over the project boundaries.
40 : */
41 : typedef int ShapeTypeId;
42 :
43 : /** Define the function type for creating accessible objects for given
44 : service names.
45 : */
46 : typedef AccessibleShape* (*tCreateFunction)
47 : (const AccessibleShapeInfo& rShapeInfo,
48 : const AccessibleShapeTreeInfo& rShapeTreeInfo,
49 : ShapeTypeId nId);
50 :
51 : /** Each shape type is described by listing its id, its service name and a
52 : function which creates a new accessible object that can represent that
53 : service. The id has to be unique with respect to the create function.
54 : */
55 3996 : struct ShapeTypeDescriptor
56 : {
57 : ShapeTypeId mnShapeTypeId;
58 : OUString msServiceName;
59 : tCreateFunction maCreateFunction;
60 1620 : ShapeTypeDescriptor (
61 : ShapeTypeId nId, const OUString& sName, tCreateFunction aFunction)
62 : : mnShapeTypeId (nId),
63 : msServiceName (sName),
64 1620 : maCreateFunction (aFunction)
65 1620 : {}
66 1656 : ShapeTypeDescriptor (void)
67 : : mnShapeTypeId (-1),
68 : msServiceName (),
69 1656 : maCreateFunction (NULL)
70 1656 : {}
71 : };
72 :
73 : /** @descr
74 : This class is a singleton that has the purpose to transform between
75 : service names of shapes and associated enum values and to create new
76 : accessible objects for given shapes.
77 : */
78 : class SVX_DLLPUBLIC ShapeTypeHandler
79 : {
80 : public:
81 : enum { UNKNOWN_SHAPE_TYPE = 0 };
82 :
83 : /** This function returns a reference to the only instance of this class.
84 : Use this instance to retrieve a shape's type and service name.
85 : @return
86 : Returns a reference to a ShapeTypeHandler object.
87 : */
88 : static ShapeTypeHandler& Instance (void);
89 :
90 : /** Determines the type id of a shape with the given service name.
91 : @param aServiceName
92 : Service name of the shape for which to return the type id.
93 : @return
94 : Returns the type id of the shape with the given service name or
95 : -1 when the service name is not known.
96 : */
97 : ShapeTypeId GetTypeId (const OUString& aServiceName) const;
98 :
99 : /** Determines the type id of the specified shape.
100 : @param xShape
101 : Reference to the shape for which to return the type id.
102 : @return
103 : Returns the type id of the specified shape or
104 : -1 when the given reference is either not
105 : set or the referenced object does not support the
106 : XShapeDescriptor interface.
107 : */
108 : ShapeTypeId GetTypeId (const ::com::sun::star::uno::Reference<
109 : ::com::sun::star::drawing::XShape>& rxShape) const;
110 :
111 : /** Create a new accessible object for the given shape.
112 : @param rShapeInfo
113 : Bundle of information passed to the new accessible shape.
114 : @param rShapeTreeInfo
115 : Bundle of information passed down the shape tree.
116 : @return
117 : Pointer to the implementation object that implements the
118 : <code>XAccessible</code> interface. This pointer may be NULL
119 : if the specified shape is of unknown type.
120 : */
121 : AccessibleShape*
122 : CreateAccessibleObject (
123 : const AccessibleShapeInfo& rShapeInfo,
124 : const AccessibleShapeTreeInfo& rShapeTreeInfo) const;
125 :
126 : /** Compatibility function.
127 : */
128 : AccessibleShape*
129 : CreateAccessibleObject (
130 : const ::com::sun::star::uno::Reference<
131 : ::com::sun::star::drawing::XShape>& rxShape,
132 : const ::com::sun::star::uno::Reference<
133 : ::com::sun::star::accessibility::XAccessible>& rxParent,
134 : const AccessibleShapeTreeInfo& rShapeTreeInfo) const
135 : {
136 : AccessibleShapeInfo aShapeInfo(rxShape, rxParent);
137 : return CreateAccessibleObject (aShapeInfo, rShapeTreeInfo);
138 : }
139 :
140 : /** Add new shape types to the internal tables. Each new shape type is
141 : described by one shape type descriptor. See
142 : ShapeTypeDescriptor for more details.
143 :
144 : @param nDescriptorCount
145 : Number of new shape types.
146 : @param aDescriptorList
147 : Array of new shape type descriptors.
148 : @return
149 : The returned flag indicates whether the specified shape
150 : descriptors have been successfully added.
151 : */
152 : bool AddShapeTypeList (int nDescriptorCount,
153 : ShapeTypeDescriptor aDescriptorList[]);
154 :
155 : /// get the accessible base name for an object
156 : static OUString CreateAccessibleBaseName (
157 : const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape)
158 : throw (::com::sun::star::uno::RuntimeException);
159 :
160 : protected:
161 : // Declare default constructor, copy constructor, destructor, and
162 : // assignment operation protected so that no one accidentally creates a
163 : // second instance of this singleton class or deletes it.
164 : ShapeTypeHandler (void);
165 : ShapeTypeHandler (const ShapeTypeHandler& aHandler); // never implemented, this is a singleton class
166 : ShapeTypeHandler& operator= (const ShapeTypeHandler& aHandler); // never implemented, this is a singleton class
167 :
168 : /** This destructor is never called at the moment. But because this
169 : class is a singleton this is not a problem.
170 : */
171 : virtual ~ShapeTypeHandler (void);
172 :
173 : private:
174 : /// Pointer to the only instance of this class.
175 : static ShapeTypeHandler* instance;
176 :
177 : /** List of shape type descriptors. This list is normally build up in
178 : several steps when libraries that implement shapes are loaded and
179 : call the addShapeTypeList method. After that no modifications of
180 : the list take place.
181 : */
182 : ::std::vector<ShapeTypeDescriptor> maShapeTypeDescriptorList;
183 :
184 : /** This hash map allows the fast look up of a type descriptor for a
185 : given service name.
186 : */
187 : typedef ::boost::unordered_map<
188 : OUString,ShapeTypeId,
189 : OUStringHash> tServiceNameToSlotId;
190 : mutable tServiceNameToSlotId maServiceNameToSlotId;
191 :
192 : /** Determine the slot id of the specified shape type. With this id
193 : internal methods can access the associated type descriptor.
194 : @param aServiceName
195 : Service name of the shape for which to return the slot id.
196 : @return
197 : Returns the slot id of the shape with the given service name or
198 : 0 when the service name is not known.
199 : */
200 : SVX_DLLPRIVATE long GetSlotId (const OUString& aServiceName) const;
201 :
202 : /** Determine the slot id of the specified shape type. With this id
203 : internal methods can access the associated type descriptor.
204 : @param rxShape
205 : Shape for which to return the slot id.
206 : @return
207 : Returns the slot id of the shape with the given service name or
208 : 0 when the service name is not known.
209 : */
210 : SVX_DLLPRIVATE long GetSlotId (const ::com::sun::star::uno::Reference<
211 : ::com::sun::star::drawing::XShape>& rxShape) const;
212 : };
213 :
214 : } // end of namespace accessible
215 :
216 : #endif
217 :
218 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|