1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVX_SHAPETYPEHANDLER_HXX
21 #define INCLUDED_SVX_SHAPETYPEHANDLER_HXX
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>
32 #include <rtl/ustring.hxx>
33 #include <unordered_map>
36 namespace accessibility
{
38 /** Use an integer to represent shape type ids. A ShapeTypeId is unique
39 inside one project but is not over the project boundaries.
41 typedef int ShapeTypeId
;
43 /** Define the function type for creating accessible objects for given
46 typedef AccessibleShape
* (*tCreateFunction
)
47 (const AccessibleShapeInfo
& rShapeInfo
,
48 const AccessibleShapeTreeInfo
& rShapeTreeInfo
,
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.
55 struct ShapeTypeDescriptor
57 ShapeTypeId mnShapeTypeId
;
58 OUString msServiceName
;
59 tCreateFunction maCreateFunction
;
61 ShapeTypeId nId
, const OUString
& sName
, tCreateFunction aFunction
)
62 : mnShapeTypeId (nId
),
63 msServiceName (sName
),
64 maCreateFunction (aFunction
)
69 maCreateFunction (NULL
)
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.
78 class SVX_DLLPUBLIC ShapeTypeHandler
81 enum { UNKNOWN_SHAPE_TYPE
= 0 };
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.
86 Returns a reference to a ShapeTypeHandler object.
88 static ShapeTypeHandler
& Instance();
90 /** Determines the type id of a shape with the given service name.
92 Service name of the shape for which to return the type id.
94 Returns the type id of the shape with the given service name or
95 -1 when the service name is not known.
97 ShapeTypeId
GetTypeId (const OUString
& aServiceName
) const;
99 /** Determines the type id of the specified shape.
101 Reference to the shape for which to return the type id.
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.
108 ShapeTypeId
GetTypeId (const ::com::sun::star::uno::Reference
<
109 ::com::sun::star::drawing::XShape
>& rxShape
) const;
111 /** Create a new accessible object for the given shape.
113 Bundle of information passed to the new accessible shape.
114 @param rShapeTreeInfo
115 Bundle of information passed down the shape tree.
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.
122 CreateAccessibleObject (
123 const AccessibleShapeInfo
& rShapeInfo
,
124 const AccessibleShapeTreeInfo
& rShapeTreeInfo
) const;
126 /** Compatibility function.
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
136 AccessibleShapeInfo
aShapeInfo(rxShape
, rxParent
);
137 return CreateAccessibleObject (aShapeInfo
, rShapeTreeInfo
);
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.
144 @param nDescriptorCount
145 Number of new shape types.
146 @param aDescriptorList
147 Array of new shape type descriptors.
149 The returned flag indicates whether the specified shape
150 descriptors have been successfully added.
152 bool AddShapeTypeList (int nDescriptorCount
,
153 ShapeTypeDescriptor aDescriptorList
[]);
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
);
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.
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
168 /** This destructor is never called at the moment. But because this
169 class is a singleton this is not a problem.
171 virtual ~ShapeTypeHandler();
174 /// Pointer to the only instance of this class.
175 static ShapeTypeHandler
* instance
;
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
182 ::std::vector
<ShapeTypeDescriptor
> maShapeTypeDescriptorList
;
184 /** This hash map allows the fast look up of a type descriptor for a
187 typedef std::unordered_map
<OUString
,ShapeTypeId
,
188 OUStringHash
> tServiceNameToSlotId
;
189 mutable tServiceNameToSlotId maServiceNameToSlotId
;
191 /** Determine the slot id of the specified shape type. With this id
192 internal methods can access the associated type descriptor.
194 Service name of the shape for which to return the slot id.
196 Returns the slot id of the shape with the given service name or
197 0 when the service name is not known.
199 SVX_DLLPRIVATE
long GetSlotId (const OUString
& aServiceName
) const;
201 /** Determine the slot id of the specified shape type. With this id
202 internal methods can access the associated type descriptor.
204 Shape for which to return the slot id.
206 Returns the slot id of the shape with the given service name or
207 0 when the service name is not known.
209 SVX_DLLPRIVATE
long GetSlotId (const ::com::sun::star::uno::Reference
<
210 ::com::sun::star::drawing::XShape
>& rxShape
) const;
213 } // end of namespace accessible
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */