lok: initialize the load-language
[LibreOffice.git] / include / svx / ShapeTypeHandler.hxx
blob065e96bee5f08b4a54d617c75352e2d0351f4853
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/svxdllapi.h>
25 #include <rtl/ref.hxx>
26 #include <rtl/ustring.hxx>
27 #include <tools/long.hxx>
28 #include <unordered_map>
29 #include <utility>
30 #include <vector>
32 namespace accessibility { class AccessibleShape; }
33 namespace accessibility { class AccessibleShapeInfo; }
34 namespace accessibility { class AccessibleShapeTreeInfo; }
35 namespace com::sun::star::drawing { class XShape; }
36 namespace com::sun::star::uno { template <typename > class Reference; }
38 namespace accessibility {
40 /** Use an integer to represent shape type ids. A ShapeTypeId is unique
41 inside one project but is not over the project boundaries.
43 typedef int ShapeTypeId;
45 /** Define the function type for creating accessible objects for given
46 service names.
48 typedef rtl::Reference<AccessibleShape> (*tCreateFunction)
49 (const AccessibleShapeInfo& rShapeInfo,
50 const AccessibleShapeTreeInfo& rShapeTreeInfo,
51 ShapeTypeId nId);
53 /** Each shape type is described by listing its id, its service name and a
54 function which creates a new accessible object that can represent that
55 service. The id has to be unique with respect to the create function.
57 struct ShapeTypeDescriptor
59 ShapeTypeId mnShapeTypeId;
60 OUString msServiceName;
61 tCreateFunction maCreateFunction;
62 ShapeTypeDescriptor (
63 ShapeTypeId nId, OUString sName, tCreateFunction aFunction)
64 : mnShapeTypeId (nId),
65 msServiceName (std::move(sName)),
66 maCreateFunction (aFunction)
68 ShapeTypeDescriptor()
69 : mnShapeTypeId (-1),
70 maCreateFunction (nullptr)
74 /** @descr
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 final
81 public:
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.
86 @return
87 Returns a reference to a ShapeTypeHandler object.
89 static ShapeTypeHandler& Instance();
91 /** Determines the type id of a shape with the given service name.
92 @param aServiceName
93 Service name of the shape for which to return the type id.
94 @return
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.
101 @param xShape
102 Reference to the shape for which to return the type id.
103 @return
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 XShapeDescriptor interface.
109 ShapeTypeId GetTypeId (const css::uno::Reference<
110 css::drawing::XShape>& rxShape) const;
112 /** Create a new accessible object for the given shape.
113 @param rShapeInfo
114 Bundle of information passed to the new accessible shape.
115 @param rShapeTreeInfo
116 Bundle of information passed down the shape tree.
117 @return
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.
122 rtl::Reference<AccessibleShape>
123 CreateAccessibleObject (
124 const AccessibleShapeInfo& rShapeInfo,
125 const AccessibleShapeTreeInfo& rShapeTreeInfo) const;
127 /** Add new shape types to the internal tables. Each new shape type is
128 described by one shape type descriptor. See
129 ShapeTypeDescriptor for more details.
131 @param nDescriptorCount
132 Number of new shape types.
133 @param aDescriptorList
134 Array of new shape type descriptors.
136 void AddShapeTypeList (int nDescriptorCount,
137 ShapeTypeDescriptor const aDescriptorList[]);
139 /// get the accessible base name for an object
141 /// @throws css::uno::RuntimeException
142 static OUString CreateAccessibleBaseName (
143 const css::uno::Reference< css::drawing::XShape >& rxShape);
145 private:
146 // Declare default constructor, copy constructor, destructor, and
147 // assignment operation protected so that no one accidentally creates a
148 // second instance of this singleton class or deletes it.
149 ShapeTypeHandler();
150 ShapeTypeHandler (const ShapeTypeHandler& aHandler); // never implemented, this is a singleton class
151 ShapeTypeHandler& operator= (const ShapeTypeHandler& aHandler); // never implemented, this is a singleton class
153 /** This destructor is never called at the moment. But because this
154 class is a singleton this is not a problem.
156 ~ShapeTypeHandler();
158 /// Pointer to the only instance of this class.
159 static ShapeTypeHandler* instance;
161 /** List of shape type descriptors. This list is normally build up in
162 several steps when libraries that implement shapes are loaded and
163 call the addShapeTypeList method. After that no modifications of
164 the list take place.
166 ::std::vector<ShapeTypeDescriptor> maShapeTypeDescriptorList;
168 /** This hash map allows the fast look up of a type descriptor for a
169 given service name.
171 typedef std::unordered_map<OUString,ShapeTypeId> tServiceNameToSlotId;
172 mutable tServiceNameToSlotId maServiceNameToSlotId;
174 /** Determine the slot id of the specified shape type. With this id
175 internal methods can access the associated type descriptor.
176 @param aServiceName
177 Service name of the shape for which to return the slot id.
178 @return
179 Returns the slot id of the shape with the given service name or
180 0 when the service name is not known.
182 SVX_DLLPRIVATE tools::Long GetSlotId (const OUString& aServiceName) const;
184 /** Determine the slot id of the specified shape type. With this id
185 internal methods can access the associated type descriptor.
186 @param rxShape
187 Shape for which to return the slot id.
188 @return
189 Returns the slot id of the shape with the given service name or
190 0 when the service name is not known.
192 SVX_DLLPRIVATE tools::Long GetSlotId (const css::uno::Reference<
193 css::drawing::XShape>& rxShape) const;
196 } // end of namespace accessible
198 #endif
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */