LCOV - code coverage report
Current view: top level - include/svx - ShapeTypeHandler.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 7 7 100.0 %
Date: 2015-06-13 12:38:46 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SVX_SHAPETYPEHANDLER_HXX
      21             : #define INCLUDED_SVX_SHAPETYPEHANDLER_HXX
      22             : 
      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>
      31             : 
      32             : #include <rtl/ustring.hxx>
      33             : #include <unordered_map>
      34             : #include <vector>
      35             : 
      36             : namespace accessibility {
      37             : 
      38             : /** Use an integer to represent shape type ids.  A ShapeTypeId is unique
      39             :     inside one project but is not over the project boundaries.
      40             : */
      41             : typedef int ShapeTypeId;
      42             : 
      43             : /** Define the function type for creating accessible objects for given
      44             :     service names.
      45             : */
      46             : typedef AccessibleShape* (*tCreateFunction)
      47             :     (const AccessibleShapeInfo& rShapeInfo,
      48             :     const AccessibleShapeTreeInfo& rShapeTreeInfo,
      49             :     ShapeTypeId nId);
      50             : 
      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.
      54             : */
      55        2331 : struct ShapeTypeDescriptor
      56             : {
      57             :     ShapeTypeId         mnShapeTypeId;
      58             :     OUString       msServiceName;
      59             :     tCreateFunction     maCreateFunction;
      60         945 :     ShapeTypeDescriptor (
      61             :         ShapeTypeId nId, const OUString& sName, tCreateFunction aFunction)
      62             :     :   mnShapeTypeId (nId),
      63             :         msServiceName (sName),
      64         945 :            maCreateFunction (aFunction)
      65         945 :     {}
      66         966 :     ShapeTypeDescriptor()
      67             :     :   mnShapeTypeId (-1),
      68             :         msServiceName (),
      69         966 :            maCreateFunction (NULL)
      70         966 :     {}
      71             : };
      72             : 
      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.
      77             : */
      78             : class SVX_DLLPUBLIC ShapeTypeHandler
      79             : {
      80             : public:
      81             :     enum { UNKNOWN_SHAPE_TYPE = 0 };
      82             : 
      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.
      87             :      */
      88             :     static ShapeTypeHandler& Instance();
      89             : 
      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.
      96             :      */
      97             :     ShapeTypeId GetTypeId (const OUString& aServiceName) const;
      98             : 
      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.
     107             :      */
     108             :     ShapeTypeId GetTypeId (const ::com::sun::star::uno::Reference<
     109             :         ::com::sun::star::drawing::XShape>& rxShape) const;
     110             : 
     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.
     120             :      */
     121             :     AccessibleShape*
     122             :         CreateAccessibleObject (
     123             :             const AccessibleShapeInfo& rShapeInfo,
     124             :             const AccessibleShapeTreeInfo& rShapeTreeInfo) const;
     125             : 
     126             :     /** Compatibility function.
     127             :     */
     128             :     AccessibleShape*
     129             :         CreateAccessibleObject (
     130             :             const ::com::sun::star::uno::Reference<
     131             :             ::com::sun::star::drawing::XShape>& rxShape,
     132             :             const ::com::sun::star::uno::Reference<
     133             :             ::com::sun::star::accessibility::XAccessible>& rxParent,
     134             :             const AccessibleShapeTreeInfo& rShapeTreeInfo) const
     135             :     {
     136             :         AccessibleShapeInfo aShapeInfo(rxShape, rxParent);
     137             :         return CreateAccessibleObject (aShapeInfo, rShapeTreeInfo);
     138             :     }
     139             : 
     140             :     /**  Add new shape types to the internal tables.  Each new shape type is
     141             :          described by one shape type descriptor.  See
     142             :          ShapeTypeDescriptor for more details.
     143             : 
     144             :          @param nDescriptorCount
     145             :              Number of new shape types.
     146             :          @param aDescriptorList
     147             :              Array of new shape type descriptors.
     148             :          @return
     149             :              The returned flag indicates whether the specified shape
     150             :              descriptors have been successfully added.
     151             :      */
     152             :     bool AddShapeTypeList (int nDescriptorCount,
     153             :         ShapeTypeDescriptor aDescriptorList[]);
     154             : 
     155             :     /// get the accessible base name for an object
     156             :     static OUString CreateAccessibleBaseName (
     157             :         const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape)
     158             :             throw (::com::sun::star::uno::RuntimeException);
     159             : 
     160             : protected:
     161             :     // Declare default constructor, copy constructor, destructor, and
     162             :     // assignment operation protected so that no one accidentally creates a
     163             :     // second instance of this singleton class or deletes it.
     164             :     ShapeTypeHandler();
     165             :     ShapeTypeHandler (const ShapeTypeHandler& aHandler);             // never implemented, this is a singleton class
     166             :     ShapeTypeHandler& operator= (const ShapeTypeHandler& aHandler); // never implemented, this is a singleton class
     167             : 
     168             :     /** This destructor is never called at the moment.  But because this
     169             :         class is a singleton this is not a problem.
     170             :     */
     171             :     virtual ~ShapeTypeHandler();
     172             : 
     173             : private:
     174             :     /// Pointer to the only instance of this class.
     175             :     static ShapeTypeHandler* instance;
     176             : 
     177             :     /** List of shape type descriptors.  This list is normally build up in
     178             :         several steps when libraries that implement shapes are loaded and
     179             :         call the addShapeTypeList method.  After that no modifications of
     180             :         the list take place.
     181             :     */
     182             :     ::std::vector<ShapeTypeDescriptor> maShapeTypeDescriptorList;
     183             : 
     184             :     /** This hash map allows the fast look up of a type descriptor for a
     185             :         given service name.
     186             :     */
     187             :     typedef std::unordered_map<OUString,ShapeTypeId,
     188             :                                OUStringHash> tServiceNameToSlotId;
     189             :     mutable tServiceNameToSlotId maServiceNameToSlotId;
     190             : 
     191             :     /**  Determine the slot id of the specified shape type.  With this id
     192             :          internal methods can access the associated type descriptor.
     193             :          @param aServiceName
     194             :              Service name of the shape for which to return the slot id.
     195             :          @return
     196             :              Returns the slot id of the shape with the given service name or
     197             :              0 when the service name is not known.
     198             :      */
     199             :     SVX_DLLPRIVATE long GetSlotId (const OUString& aServiceName) const;
     200             : 
     201             :     /**  Determine the slot id of the specified shape type.  With this id
     202             :          internal methods can access the associated type descriptor.
     203             :          @param rxShape
     204             :              Shape for which to return the slot id.
     205             :          @return
     206             :              Returns the slot id of the shape with the given service name or
     207             :              0 when the service name is not known.
     208             :      */
     209             :     SVX_DLLPRIVATE long GetSlotId (const ::com::sun::star::uno::Reference<
     210             :         ::com::sun::star::drawing::XShape>& rxShape) const;
     211             : };
     212             : 
     213             : } // end of namespace accessible
     214             : 
     215             : #endif
     216             : 
     217             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11