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

Generated by: LCOV version 1.10