diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /include/svx/ShapeTypeHandler.hxx | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | include/svx/ShapeTypeHandler.hxx | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/include/svx/ShapeTypeHandler.hxx b/include/svx/ShapeTypeHandler.hxx new file mode 100644 index 000000000..26d4aafd3 --- /dev/null +++ b/include/svx/ShapeTypeHandler.hxx @@ -0,0 +1,199 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SVX_SHAPETYPEHANDLER_HXX +#define INCLUDED_SVX_SHAPETYPEHANDLER_HXX + +#include <svx/svxdllapi.h> + +#include <rtl/ref.hxx> +#include <rtl/ustring.hxx> +#include <tools/long.hxx> +#include <unordered_map> +#include <vector> + +namespace accessibility { class AccessibleShape; } +namespace accessibility { class AccessibleShapeInfo; } +namespace accessibility { class AccessibleShapeTreeInfo; } +namespace com::sun::star::drawing { class XShape; } +namespace com::sun::star::uno { template <typename > class Reference; } + +namespace accessibility { + +/** Use an integer to represent shape type ids. A ShapeTypeId is unique + inside one project but is not over the project boundaries. +*/ +typedef int ShapeTypeId; + +/** Define the function type for creating accessible objects for given + service names. +*/ +typedef rtl::Reference<AccessibleShape> (*tCreateFunction) + (const AccessibleShapeInfo& rShapeInfo, + const AccessibleShapeTreeInfo& rShapeTreeInfo, + ShapeTypeId nId); + +/** Each shape type is described by listing its id, its service name and a + function which creates a new accessible object that can represent that + service. The id has to be unique with respect to the create function. +*/ +struct ShapeTypeDescriptor +{ + ShapeTypeId mnShapeTypeId; + OUString msServiceName; + tCreateFunction maCreateFunction; + ShapeTypeDescriptor ( + ShapeTypeId nId, const OUString& sName, tCreateFunction aFunction) + : mnShapeTypeId (nId), + msServiceName (sName), + maCreateFunction (aFunction) + {} + ShapeTypeDescriptor() + : mnShapeTypeId (-1), + maCreateFunction (nullptr) + {} +}; + +/** @descr + This class is a singleton that has the purpose to transform between + service names of shapes and associated enum values and to create new + accessible objects for given shapes. +*/ +class SVX_DLLPUBLIC ShapeTypeHandler final +{ +public: + enum { UNKNOWN_SHAPE_TYPE = 0 }; + + /** This function returns a reference to the only instance of this class. + Use this instance to retrieve a shape's type and service name. + @return + Returns a reference to a ShapeTypeHandler object. + */ + static ShapeTypeHandler& Instance(); + + /** Determines the type id of a shape with the given service name. + @param aServiceName + Service name of the shape for which to return the type id. + @return + Returns the type id of the shape with the given service name or + -1 when the service name is not known. + */ + ShapeTypeId GetTypeId (const OUString& aServiceName) const; + + /** Determines the type id of the specified shape. + @param xShape + Reference to the shape for which to return the type id. + @return + Returns the type id of the specified shape or + -1 when the given reference is either not + set or the referenced object does not support the + XShapeDescriptor interface. + */ + ShapeTypeId GetTypeId (const css::uno::Reference< + css::drawing::XShape>& rxShape) const; + + /** Create a new accessible object for the given shape. + @param rShapeInfo + Bundle of information passed to the new accessible shape. + @param rShapeTreeInfo + Bundle of information passed down the shape tree. + @return + Pointer to the implementation object that implements the + <code>XAccessible</code> interface. This pointer may be NULL + if the specified shape is of unknown type. + */ + rtl::Reference<AccessibleShape> + CreateAccessibleObject ( + const AccessibleShapeInfo& rShapeInfo, + const AccessibleShapeTreeInfo& rShapeTreeInfo) const; + + /** Add new shape types to the internal tables. Each new shape type is + described by one shape type descriptor. See + ShapeTypeDescriptor for more details. + + @param nDescriptorCount + Number of new shape types. + @param aDescriptorList + Array of new shape type descriptors. + */ + void AddShapeTypeList (int nDescriptorCount, + ShapeTypeDescriptor const aDescriptorList[]); + + /// get the accessible base name for an object + /// + /// @throws css::uno::RuntimeException + static OUString CreateAccessibleBaseName ( + const css::uno::Reference< css::drawing::XShape >& rxShape); + +private: + // Declare default constructor, copy constructor, destructor, and + // assignment operation protected so that no one accidentally creates a + // second instance of this singleton class or deletes it. + ShapeTypeHandler(); + ShapeTypeHandler (const ShapeTypeHandler& aHandler); // never implemented, this is a singleton class + ShapeTypeHandler& operator= (const ShapeTypeHandler& aHandler); // never implemented, this is a singleton class + + /** This destructor is never called at the moment. But because this + class is a singleton this is not a problem. + */ + ~ShapeTypeHandler(); + + /// Pointer to the only instance of this class. + static ShapeTypeHandler* instance; + + /** List of shape type descriptors. This list is normally build up in + several steps when libraries that implement shapes are loaded and + call the addShapeTypeList method. After that no modifications of + the list take place. + */ + ::std::vector<ShapeTypeDescriptor> maShapeTypeDescriptorList; + + /** This hash map allows the fast look up of a type descriptor for a + given service name. + */ + typedef std::unordered_map<OUString,ShapeTypeId> tServiceNameToSlotId; + mutable tServiceNameToSlotId maServiceNameToSlotId; + + /** Determine the slot id of the specified shape type. With this id + internal methods can access the associated type descriptor. + @param aServiceName + Service name of the shape for which to return the slot id. + @return + Returns the slot id of the shape with the given service name or + 0 when the service name is not known. + */ + SVX_DLLPRIVATE tools::Long GetSlotId (const OUString& aServiceName) const; + + /** Determine the slot id of the specified shape type. With this id + internal methods can access the associated type descriptor. + @param rxShape + Shape for which to return the slot id. + @return + Returns the slot id of the shape with the given service name or + 0 when the service name is not known. + */ + SVX_DLLPRIVATE tools::Long GetSlotId (const css::uno::Reference< + css::drawing::XShape>& rxShape) const; +}; + +} // end of namespace accessible + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |