tdf#124953: Use rangelist's combined range top-left address...
[LibreOffice.git] / include / svx / ShapeTypeHandler.hxx
blobe252ae30cc01f3c26b0bfe6461ce102b64f98166
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
34 #include <vector>
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
44 service names.
46 typedef AccessibleShape* (*tCreateFunction)
47 (const AccessibleShapeInfo& rShapeInfo,
48 const AccessibleShapeTreeInfo& rShapeTreeInfo,
49 ShapeTypeId nId);
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;
60 ShapeTypeDescriptor (
61 ShapeTypeId nId, const OUString& sName, tCreateFunction aFunction)
62 : mnShapeTypeId (nId),
63 msServiceName (sName),
64 maCreateFunction (aFunction)
66 ShapeTypeDescriptor()
67 : mnShapeTypeId (-1),
68 msServiceName (),
69 maCreateFunction (nullptr)
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.
78 class SVX_DLLPUBLIC ShapeTypeHandler final
80 public:
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.
85 @return
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.
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.
97 ShapeTypeId GetTypeId (const OUString& aServiceName) const;
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.
108 ShapeTypeId GetTypeId (const css::uno::Reference<
109 css::drawing::XShape>& rxShape) const;
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.
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);
144 private:
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.
148 ShapeTypeHandler();
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.
155 ~ShapeTypeHandler();
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
163 the list take place.
165 ::std::vector<ShapeTypeDescriptor> maShapeTypeDescriptorList;
167 /** This hash map allows the fast look up of a type descriptor for a
168 given service name.
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.
175 @param aServiceName
176 Service name of the shape for which to return the slot id.
177 @return
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 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.
185 @param rxShape
186 Shape for which to return the slot id.
187 @return
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 long GetSlotId (const css::uno::Reference<
192 css::drawing::XShape>& rxShape) const;
195 } // end of namespace accessible
197 #endif
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */