LCOV - code coverage report
Current view: top level - svx/inc/svx - ShapeTypeHandler.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 7 100.0 %
Date: 2012-08-25 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef _SVX_ACCESSIBILITY_SHAPE_TYPE_HANDLER_HXX
      30                 :            : #define _SVX_ACCESSIBILITY_SHAPE_TYPE_HANDLER_HXX
      31                 :            : 
      32                 :            : #include <svx/AccessibleShapeTreeInfo.hxx>
      33                 :            : #include <svx/AccessibleShapeInfo.hxx>
      34                 :            : #include <svx/AccessibleShape.hxx>
      35                 :            : #include <com/sun/star/accessibility/XAccessible.hpp>
      36                 :            : #include <com/sun/star/uno/XInterface.hpp>
      37                 :            : #include <com/sun/star/drawing/XShape.hpp>
      38                 :            : #include <comphelper/stl_types.hxx>
      39                 :            : #include <com/sun/star/document/XEventBroadcaster.hpp>
      40                 :            : #include "svx/svxdllapi.h"
      41                 :            : 
      42                 :            : #include <rtl/ustring.hxx>
      43                 :            : #include <vector>
      44                 :            : #include <boost/unordered_map.hpp>
      45                 :            : 
      46                 :            : namespace accessibility {
      47                 :            : 
      48                 :            : /** Use an integer to represent shape type ids.  A ShapeTypeId is unique
      49                 :            :     inside one project but is not over the project boundaries.
      50                 :            : */
      51                 :            : typedef int ShapeTypeId;
      52                 :            : 
      53                 :            : /** Define the function type for creating accessible objects for given
      54                 :            :     service names.
      55                 :            : */
      56                 :            : typedef AccessibleShape* (*tCreateFunction)
      57                 :            :     (const AccessibleShapeInfo& rShapeInfo,
      58                 :            :     const AccessibleShapeTreeInfo& rShapeTreeInfo,
      59                 :            :     ShapeTypeId nId);
      60                 :            : 
      61                 :            : /** Each shape type is described by listing its id, its service name and a
      62                 :            :     function which creates a new accessible object that can represent that
      63                 :            :     service.  The id has to be unique with respect to the create function.
      64                 :            : */
      65                 :       2134 : struct ShapeTypeDescriptor
      66                 :            : {
      67                 :            :     ShapeTypeId         mnShapeTypeId;
      68                 :            :     rtl::OUString       msServiceName;
      69                 :            :     tCreateFunction     maCreateFunction;
      70                 :        682 :     ShapeTypeDescriptor (
      71                 :            :         ShapeTypeId nId, const rtl::OUString& sName, tCreateFunction aFunction)
      72                 :            :     :   mnShapeTypeId (nId),
      73                 :            :         msServiceName (sName),
      74                 :        682 :            maCreateFunction (aFunction)
      75                 :        682 :     {}
      76                 :       1012 :     ShapeTypeDescriptor (void)
      77                 :            :     :   mnShapeTypeId (-1),
      78                 :            :         msServiceName (),
      79                 :       1012 :            maCreateFunction (NULL)
      80                 :       1012 :     {}
      81                 :            : };
      82                 :            : 
      83                 :            : /** @descr
      84                 :            :         This class is a singleton that has the purpose to transform between
      85                 :            :         service names of shapes and associated enum values and to create new
      86                 :            :         accessible objects for given shapes.
      87                 :            : */
      88                 :            : class SVX_DLLPUBLIC ShapeTypeHandler
      89                 :            : {
      90                 :            : public:
      91                 :            :     enum { UNKNOWN_SHAPE_TYPE = 0 };
      92                 :            : 
      93                 :            :     /** This function returns a reference to the only instance of this class.
      94                 :            :         Use this instance to retrieve a shape's type and service name.
      95                 :            :         @return
      96                 :            :             Returns a reference to a <type>ShapeTypeHandler</type> object.
      97                 :            :      */
      98                 :            :     static ShapeTypeHandler& Instance (void);
      99                 :            : 
     100                 :            :     /**  Determines the type id of a shape with the given service name.
     101                 :            :          @param aServiceName
     102                 :            :              Service name of the shape for which to return the type id.
     103                 :            :          @return
     104                 :            :              Returns the type id of the shape with the given service name or
     105                 :            :              -1 when the service name is not known.
     106                 :            :      */
     107                 :            :     ShapeTypeId GetTypeId (const ::rtl::OUString& aServiceName) const;
     108                 :            : 
     109                 :            :     /**  Determines the type id of the specified shape.
     110                 :            :          @param xShape
     111                 :            :              Reference to the shape for which to return the type id.
     112                 :            :          @return
     113                 :            :              Returns the type id of the specified shape or
     114                 :            :              -1 when the given reference is either not
     115                 :            :              set or the referenced object does not support the
     116                 :            :              <type>XShapeDescriptor</type> interface.
     117                 :            :      */
     118                 :            :     ShapeTypeId GetTypeId (const ::com::sun::star::uno::Reference<
     119                 :            :         ::com::sun::star::drawing::XShape>& rxShape) const;
     120                 :            : 
     121                 :            :     /**  Create a new accessible object for the given shape.
     122                 :            :          @param rShapeInfo
     123                 :            :              Bundle of information passed to the new accessible shape.
     124                 :            :          @param rShapeTreeInfo
     125                 :            :              Bundle of information passed down the shape tree.
     126                 :            :          @return
     127                 :            :              Pointer to the implementation object that implements the
     128                 :            :              <code>XAccessible</code> interface.  This pointer may be NULL
     129                 :            :              if the specified shape is of unknown type.
     130                 :            :      */
     131                 :            :     AccessibleShape*
     132                 :            :         CreateAccessibleObject (
     133                 :            :             const AccessibleShapeInfo& rShapeInfo,
     134                 :            :             const AccessibleShapeTreeInfo& rShapeTreeInfo) const;
     135                 :            : 
     136                 :            :     /** Compatibility function.
     137                 :            :     */
     138                 :            :     AccessibleShape*
     139                 :            :         CreateAccessibleObject (
     140                 :            :             const ::com::sun::star::uno::Reference<
     141                 :            :             ::com::sun::star::drawing::XShape>& rxShape,
     142                 :            :             const ::com::sun::star::uno::Reference<
     143                 :            :             ::com::sun::star::accessibility::XAccessible>& rxParent,
     144                 :            :             const AccessibleShapeTreeInfo& rShapeTreeInfo) const
     145                 :            :     {
     146                 :            :         AccessibleShapeInfo aShapeInfo(rxShape, rxParent);
     147                 :            :         return CreateAccessibleObject (aShapeInfo, rShapeTreeInfo);
     148                 :            :     }
     149                 :            : 
     150                 :            :     /**  Add new shape types to the internal tables.  Each new shape type is
     151                 :            :          described by one shape type descriptor.  See
     152                 :            :          <type>ShapeTypeDescriptor</type> for more details.
     153                 :            : 
     154                 :            :          @param nDescriptorCount
     155                 :            :              Number of new shape types.
     156                 :            :          @param aDescriptorList
     157                 :            :              Array of new shape type descriptors.
     158                 :            :          @return
     159                 :            :              The returned flag indicates whether the specified shape
     160                 :            :              descriptors have been successfully added.
     161                 :            :      */
     162                 :            :     bool AddShapeTypeList (int nDescriptorCount,
     163                 :            :         ShapeTypeDescriptor aDescriptorList[]);
     164                 :            : 
     165                 :            :     /// get the accessible base name for an object
     166                 :            :     static ::rtl::OUString CreateAccessibleBaseName (
     167                 :            :         const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape)
     168                 :            :             throw (::com::sun::star::uno::RuntimeException);
     169                 :            : 
     170                 :            : protected:
     171                 :            :     // Declare default constructor, copy constructor, destructor, and
     172                 :            :     // assignment operation protected so that no one accidentally creates a
     173                 :            :     // second instance of this singleton class or deletes it.
     174                 :            :     ShapeTypeHandler (void);
     175                 :            :     ShapeTypeHandler (const ShapeTypeHandler& aHandler);             // never implemented, this is a singleton class
     176                 :            :     ShapeTypeHandler& operator= (const ShapeTypeHandler& aHandler); // never implemented, this is a singleton class
     177                 :            : 
     178                 :            :     /** This destructor is never called at the moment.  But because this
     179                 :            :         class is a singleton this is not a problem.
     180                 :            :     */
     181                 :            :     virtual ~ShapeTypeHandler (void);
     182                 :            : 
     183                 :            : private:
     184                 :            :     /// Pointer to the only instance of this class.
     185                 :            :     static ShapeTypeHandler* instance;
     186                 :            : 
     187                 :            :     /** List of shape type descriptors.  This list is normally build up in
     188                 :            :         several steps when libraries that implement shapes are loaded and
     189                 :            :         call the addShapeTypeList method.  After that no modifications of
     190                 :            :         the list take place.
     191                 :            :     */
     192                 :            :     ::std::vector<ShapeTypeDescriptor> maShapeTypeDescriptorList;
     193                 :            : 
     194                 :            :     /** This hash map allows the fast look up of a type descriptor for a
     195                 :            :         given service name.
     196                 :            :     */
     197                 :            :     typedef ::boost::unordered_map<
     198                 :            :         ::rtl::OUString,ShapeTypeId,
     199                 :            :         ::rtl::OUStringHash,
     200                 :            :         ::comphelper::UStringEqual> tServiceNameToSlotId;
     201                 :            :     mutable tServiceNameToSlotId maServiceNameToSlotId;
     202                 :            : 
     203                 :            :     /**  Determine the slot id of the specified shape type.  With this id
     204                 :            :          internal methods can access the associated type descriptor.
     205                 :            :          @param aServiceName
     206                 :            :              Service name of the shape for which to return the slot id.
     207                 :            :          @return
     208                 :            :              Returns the slot id of the shape with the given service name or
     209                 :            :              0 when the service name is not known.
     210                 :            :      */
     211                 :            :     SVX_DLLPRIVATE long GetSlotId (const ::rtl::OUString& aServiceName) const;
     212                 :            : 
     213                 :            :     /**  Determine the slot id of the specified shape type.  With this id
     214                 :            :          internal methods can access the associated type descriptor.
     215                 :            :          @param rxShape
     216                 :            :              Shape for which to return the slot id.
     217                 :            :          @return
     218                 :            :              Returns the slot id of the shape with the given service name or
     219                 :            :              0 when the service name is not known.
     220                 :            :      */
     221                 :            :     SVX_DLLPRIVATE long GetSlotId (const ::com::sun::star::uno::Reference<
     222                 :            :         ::com::sun::star::drawing::XShape>& rxShape) const;
     223                 :            : };
     224                 :            : 
     225                 :            : } // end of namespace accessible
     226                 :            : 
     227                 :            : #endif
     228                 :            : 
     229                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10