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 .
22 #include <svx/svxdllapi.h>
24 #include <rtl/ref.hxx>
25 #include <rtl/ustring.hxx>
26 #include <tools/long.hxx>
27 #include <unordered_map>
31 namespace accessibility
{ class AccessibleShape
; }
32 namespace accessibility
{ class AccessibleShapeInfo
; }
33 namespace accessibility
{ class AccessibleShapeTreeInfo
; }
34 namespace com::sun::star::drawing
{ class XShape
; }
35 namespace com::sun::star::uno
{ template <typename
> class Reference
; }
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 rtl::Reference
<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
, OUString sName
, tCreateFunction aFunction
)
63 : mnShapeTypeId (nId
),
64 msServiceName (std::move(sName
)),
65 maCreateFunction (aFunction
)
69 maCreateFunction (nullptr)
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 final
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 css::uno::Reference
<
109 css::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.
121 rtl::Reference
<AccessibleShape
>
122 CreateAccessibleObject (
123 const AccessibleShapeInfo
& rShapeInfo
,
124 const AccessibleShapeTreeInfo
& rShapeTreeInfo
) const;
126 /** Add new shape types to the internal tables. Each new shape type is
127 described by one shape type descriptor. See
128 ShapeTypeDescriptor for more details.
130 @param nDescriptorCount
131 Number of new shape types.
132 @param aDescriptorList
133 Array of new shape type descriptors.
135 void AddShapeTypeList (int nDescriptorCount
,
136 ShapeTypeDescriptor
const aDescriptorList
[]);
138 /// get the accessible base name for an object
140 /// @throws css::uno::RuntimeException
141 static OUString
CreateAccessibleBaseName (
142 const css::uno::Reference
< css::drawing::XShape
>& rxShape
);
145 // Declare default constructor, copy constructor, destructor, and
146 // assignment operation protected so that no one accidentally creates a
147 // second instance of this singleton class or deletes it.
149 ShapeTypeHandler (const ShapeTypeHandler
& aHandler
); // never implemented, this is a singleton class
150 ShapeTypeHandler
& operator= (const ShapeTypeHandler
& aHandler
); // never implemented, this is a singleton class
152 /** This destructor is never called at the moment. But because this
153 class is a singleton this is not a problem.
157 /// Pointer to the only instance of this class.
158 static ShapeTypeHandler
* instance
;
160 /** List of shape type descriptors. This list is normally build up in
161 several steps when libraries that implement shapes are loaded and
162 call the addShapeTypeList method. After that no modifications of
165 ::std::vector
<ShapeTypeDescriptor
> maShapeTypeDescriptorList
;
167 /** This hash map allows the fast look up of a type descriptor for a
170 typedef std::unordered_map
<OUString
,ShapeTypeId
> tServiceNameToSlotId
;
171 mutable tServiceNameToSlotId maServiceNameToSlotId
;
173 /** Determine the slot id of the specified shape type. With this id
174 internal methods can access the associated type descriptor.
176 Service name of the shape for which to return the slot id.
178 Returns the slot id of the shape with the given service name or
179 0 when the service name is not known.
181 SVX_DLLPRIVATE
tools::Long
GetSlotId (const OUString
& aServiceName
) const;
183 /** Determine the slot id of the specified shape type. With this id
184 internal methods can access the associated type descriptor.
186 Shape for which to return the slot id.
188 Returns the slot id of the shape with the given service name or
189 0 when the service name is not known.
191 SVX_DLLPRIVATE
tools::Long
GetSlotId (const css::uno::Reference
<
192 css::drawing::XShape
>& rxShape
) const;
195 } // end of namespace accessible
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */