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 _SVX_ACCESSIBILITY_SHAPE_TYPE_HANDLER_HXX
21 #define _SVX_ACCESSIBILITY_SHAPE_TYPE_HANDLER_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 <comphelper/stl_types.hxx>
30 #include <com/sun/star/document/XEventBroadcaster.hpp>
31 #include "svx/svxdllapi.h"
33 #include <rtl/ustring.hxx>
35 #include <boost/unordered_map.hpp>
37 namespace accessibility
{
39 /** Use an integer to represent shape type ids. A ShapeTypeId is unique
40 inside one project but is not over the project boundaries.
42 typedef int ShapeTypeId
;
44 /** Define the function type for creating accessible objects for given
47 typedef AccessibleShape
* (*tCreateFunction
)
48 (const AccessibleShapeInfo
& rShapeInfo
,
49 const AccessibleShapeTreeInfo
& rShapeTreeInfo
,
52 /** Each shape type is described by listing its id, its service name and a
53 function which creates a new accessible object that can represent that
54 service. The id has to be unique with respect to the create function.
56 struct ShapeTypeDescriptor
58 ShapeTypeId mnShapeTypeId
;
59 OUString msServiceName
;
60 tCreateFunction maCreateFunction
;
62 ShapeTypeId nId
, const OUString
& sName
, tCreateFunction aFunction
)
63 : mnShapeTypeId (nId
),
64 msServiceName (sName
),
65 maCreateFunction (aFunction
)
67 ShapeTypeDescriptor (void)
70 maCreateFunction (NULL
)
75 This class is a singleton that has the purpose to transform between
76 service names of shapes and associated enum values and to create new
77 accessible objects for given shapes.
79 class SVX_DLLPUBLIC ShapeTypeHandler
82 enum { UNKNOWN_SHAPE_TYPE
= 0 };
84 /** This function returns a reference to the only instance of this class.
85 Use this instance to retrieve a shape's type and service name.
87 Returns a reference to a <type>ShapeTypeHandler</type> object.
89 static ShapeTypeHandler
& Instance (void);
91 /** Determines the type id of a shape with the given service name.
93 Service name of the shape for which to return the type id.
95 Returns the type id of the shape with the given service name or
96 -1 when the service name is not known.
98 ShapeTypeId
GetTypeId (const OUString
& aServiceName
) const;
100 /** Determines the type id of the specified shape.
102 Reference to the shape for which to return the type id.
104 Returns the type id of the specified shape or
105 -1 when the given reference is either not
106 set or the referenced object does not support the
107 <type>XShapeDescriptor</type> interface.
109 ShapeTypeId
GetTypeId (const ::com::sun::star::uno::Reference
<
110 ::com::sun::star::drawing::XShape
>& rxShape
) const;
112 /** Create a new accessible object for the given shape.
114 Bundle of information passed to the new accessible shape.
115 @param rShapeTreeInfo
116 Bundle of information passed down the shape tree.
118 Pointer to the implementation object that implements the
119 <code>XAccessible</code> interface. This pointer may be NULL
120 if the specified shape is of unknown type.
123 CreateAccessibleObject (
124 const AccessibleShapeInfo
& rShapeInfo
,
125 const AccessibleShapeTreeInfo
& rShapeTreeInfo
) const;
127 /** Compatibility function.
130 CreateAccessibleObject (
131 const ::com::sun::star::uno::Reference
<
132 ::com::sun::star::drawing::XShape
>& rxShape
,
133 const ::com::sun::star::uno::Reference
<
134 ::com::sun::star::accessibility::XAccessible
>& rxParent
,
135 const AccessibleShapeTreeInfo
& rShapeTreeInfo
) const
137 AccessibleShapeInfo
aShapeInfo(rxShape
, rxParent
);
138 return CreateAccessibleObject (aShapeInfo
, rShapeTreeInfo
);
141 /** Add new shape types to the internal tables. Each new shape type is
142 described by one shape type descriptor. See
143 <type>ShapeTypeDescriptor</type> for more details.
145 @param nDescriptorCount
146 Number of new shape types.
147 @param aDescriptorList
148 Array of new shape type descriptors.
150 The returned flag indicates whether the specified shape
151 descriptors have been successfully added.
153 bool AddShapeTypeList (int nDescriptorCount
,
154 ShapeTypeDescriptor aDescriptorList
[]);
156 /// get the accessible base name for an object
157 static OUString
CreateAccessibleBaseName (
158 const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>& rxShape
)
159 throw (::com::sun::star::uno::RuntimeException
);
162 // Declare default constructor, copy constructor, destructor, and
163 // assignment operation protected so that no one accidentally creates a
164 // second instance of this singleton class or deletes it.
165 ShapeTypeHandler (void);
166 ShapeTypeHandler (const ShapeTypeHandler
& aHandler
); // never implemented, this is a singleton class
167 ShapeTypeHandler
& operator= (const ShapeTypeHandler
& aHandler
); // never implemented, this is a singleton class
169 /** This destructor is never called at the moment. But because this
170 class is a singleton this is not a problem.
172 virtual ~ShapeTypeHandler (void);
175 /// Pointer to the only instance of this class.
176 static ShapeTypeHandler
* instance
;
178 /** List of shape type descriptors. This list is normally build up in
179 several steps when libraries that implement shapes are loaded and
180 call the addShapeTypeList method. After that no modifications of
183 ::std::vector
<ShapeTypeDescriptor
> maShapeTypeDescriptorList
;
185 /** This hash map allows the fast look up of a type descriptor for a
188 typedef ::boost::unordered_map
<
189 OUString
,ShapeTypeId
,
191 ::comphelper::UStringEqual
> tServiceNameToSlotId
;
192 mutable tServiceNameToSlotId maServiceNameToSlotId
;
194 /** Determine the slot id of the specified shape type. With this id
195 internal methods can access the associated type descriptor.
197 Service name of the shape for which to return the slot id.
199 Returns the slot id of the shape with the given service name or
200 0 when the service name is not known.
202 SVX_DLLPRIVATE
long GetSlotId (const OUString
& aServiceName
) const;
204 /** Determine the slot id of the specified shape type. With this id
205 internal methods can access the associated type descriptor.
207 Shape for which to return the slot id.
209 Returns the slot id of the shape with the given service name or
210 0 when the service name is not known.
212 SVX_DLLPRIVATE
long GetSlotId (const ::com::sun::star::uno::Reference
<
213 ::com::sun::star::drawing::XShape
>& rxShape
) const;
216 } // end of namespace accessible
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */