1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _SVX_ACCESSIBILITY_SHAPE_TYPE_HANDLER_HXX 25 #define _SVX_ACCESSIBILITY_SHAPE_TYPE_HANDLER_HXX 26 27 #include <svx/AccessibleShapeTreeInfo.hxx> 28 #include <svx/AccessibleShapeInfo.hxx> 29 #include <svx/AccessibleShape.hxx> 30 #include <com/sun/star/accessibility/XAccessible.hpp> 31 #include <com/sun/star/uno/XInterface.hpp> 32 #include <com/sun/star/drawing/XShape.hpp> 33 #include <comphelper/stl_types.hxx> 34 #include <com/sun/star/document/XEventBroadcaster.hpp> 35 #include "svx/svxdllapi.h" 36 37 #include <rtl/ustring.hxx> 38 #include <vector> 39 #include <hash_map> 40 41 namespace accessibility { 42 43 /** Use an integer to represent shape type ids. A ShapeTypeId is unique 44 inside one project but is not over the project boundaries. 45 */ 46 typedef int ShapeTypeId; 47 48 /** Define the function type for creating accessible objects for given 49 service names. 50 */ 51 typedef AccessibleShape* (*tCreateFunction) 52 (const AccessibleShapeInfo& rShapeInfo, 53 const AccessibleShapeTreeInfo& rShapeTreeInfo, 54 ShapeTypeId nId); 55 56 /** Each shape type is described by listing its id, its service name and a 57 function which creates a new accessible object that can represent that 58 service. The id has to be unique with respect to the create function. 59 */ 60 struct ShapeTypeDescriptor 61 { 62 ShapeTypeId mnShapeTypeId; 63 rtl::OUString msServiceName; 64 tCreateFunction maCreateFunction; ShapeTypeDescriptoraccessibility::ShapeTypeDescriptor65 ShapeTypeDescriptor ( 66 ShapeTypeId nId, const rtl::OUString& sName, tCreateFunction aFunction) 67 : mnShapeTypeId (nId), 68 msServiceName (sName), 69 maCreateFunction (aFunction) 70 {} ShapeTypeDescriptoraccessibility::ShapeTypeDescriptor71 ShapeTypeDescriptor (void) 72 : mnShapeTypeId (-1), 73 msServiceName (), 74 maCreateFunction (NULL) 75 {} 76 }; 77 78 /** @descr 79 This class is a singleton that has the purpose to transform between 80 service names of shapes and associated enum values and to create new 81 accessible objects for given shapes. 82 */ 83 class SVX_DLLPUBLIC ShapeTypeHandler 84 { 85 public: 86 enum { UNKNOWN_SHAPE_TYPE = 0 }; 87 88 /** This function returns a reference to the only instance of this class. 89 Use this instance to retrieve a shape's type and service name. 90 @return 91 Returns a reference to a <type>ShapeTypeHandler</type> object. 92 */ 93 static ShapeTypeHandler& Instance (void); 94 95 /** Determines the type id of a shape with the given service name. 96 @param aServiceName 97 Service name of the shape for which to return the type id. 98 @return 99 Returns the type id of the shape with the given service name or 100 -1 when the service name is not known. 101 */ 102 ShapeTypeId GetTypeId (const ::rtl::OUString& aServiceName) const; 103 104 /** Determines the type id of the specified shape. 105 @param xShape 106 Reference to the shape for which to return the type id. 107 @return 108 Returns the type id of the specified shape or 109 -1 when the given reference is either not 110 set or the referenced object does not support the 111 <type>XShapeDescriptor</type> interface. 112 */ 113 ShapeTypeId GetTypeId (const ::com::sun::star::uno::Reference< 114 ::com::sun::star::drawing::XShape>& rxShape) const; 115 116 /** Return the service name of a shape with the specified type. 117 @param aTypeId 118 Id of the shape type for which to retrieve the service name. 119 An unknown shape id results in an empty string. 120 @return 121 The returned string contains the service name, with which a 122 shape of the given type can be created. 123 */ 124 const ::rtl::OUString& GetServiceName (ShapeTypeId aTypeId) const; 125 126 /** Create a new accessible object for the given shape. 127 @param rShapeInfo 128 Bundle of information passed to the new accessible shape. 129 @param rShapeTreeInfo 130 Bundle of information passed down the shape tree. 131 @return 132 Pointer to the implementation object that implements the 133 <code>XAccessible</code> interface. This pointer may be NULL 134 if the specified shape is of unknown type. 135 */ 136 AccessibleShape* 137 CreateAccessibleObject ( 138 const AccessibleShapeInfo& rShapeInfo, 139 const AccessibleShapeTreeInfo& rShapeTreeInfo) const; 140 141 /** Compatibility function. 142 */ 143 AccessibleShape* CreateAccessibleObject(const::com::sun::star::uno::Reference<::com::sun::star::drawing::XShape> & rxShape,const::com::sun::star::uno::Reference<::com::sun::star::accessibility::XAccessible> & rxParent,const AccessibleShapeTreeInfo & rShapeTreeInfo) const144 CreateAccessibleObject ( 145 const ::com::sun::star::uno::Reference< 146 ::com::sun::star::drawing::XShape>& rxShape, 147 const ::com::sun::star::uno::Reference< 148 ::com::sun::star::accessibility::XAccessible>& rxParent, 149 const AccessibleShapeTreeInfo& rShapeTreeInfo) const 150 { 151 AccessibleShapeInfo aShapeInfo(rxShape, rxParent); 152 return CreateAccessibleObject (aShapeInfo, rShapeTreeInfo); 153 } 154 155 /** Add new shape types to the internal tables. Each new shape type is 156 described by one shape type descriptor. See 157 <type>ShapeTypeDescriptor</type> for more details. 158 159 @param nDescriptorCount 160 Number of new shape types. 161 @param aDescriptorList 162 Array of new shape type descriptors. 163 @return 164 The returned flag indicates whether the specified shape 165 descriptors have been successfully added. 166 */ 167 bool AddShapeTypeList (int nDescriptorCount, 168 ShapeTypeDescriptor aDescriptorList[]); 169 170 /// get the accessible base name for an object 171 static ::rtl::OUString CreateAccessibleBaseName ( 172 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape) 173 throw (::com::sun::star::uno::RuntimeException); 174 175 protected: 176 // Declare default constructor, copy constructor, destructor, and 177 // assignment operation protected so that no one accidentally creates a 178 // second instance of this singleton class or deletes it. 179 ShapeTypeHandler (void); 180 ShapeTypeHandler (const ShapeTypeHandler& aHandler); // never implemented, this is a singleton class 181 ShapeTypeHandler& operator= (const ShapeTypeHandler& aHandler); // never implemented, this is a singleton class 182 183 /** This destructor is never called at the moment. But because this 184 class is a singleton this is not a problem. 185 */ 186 virtual ~ShapeTypeHandler (void); 187 188 private: 189 /// Pointer to the only instance of this class. 190 static ShapeTypeHandler* instance; 191 192 /** List of shape type descriptors. This list is normally build up in 193 several steps when libraries that implement shapes are loaded and 194 call the addShapeTypeList method. After that no modifications of 195 the list take place. 196 */ 197 ::std::vector<ShapeTypeDescriptor> maShapeTypeDescriptorList; 198 199 /** This hash map allows the fast look up of a type descriptor for a 200 given service name. 201 */ 202 typedef ::std::hash_map< 203 ::rtl::OUString,ShapeTypeId, 204 ::rtl::OUStringHash, 205 // ::comphelper::UStringHash, 206 ::comphelper::UStringEqual> tServiceNameToSlotId; 207 mutable tServiceNameToSlotId maServiceNameToSlotId; 208 209 /** Determine the slot id of the specified shape type. With this id 210 internal methods can access the associated type descriptor. 211 @param aServiceName 212 Service name of the shape for which to return the slot id. 213 @return 214 Returns the slot id of the shape with the given service name or 215 0 when the service name is not known. 216 */ 217 SVX_DLLPRIVATE long GetSlotId (const ::rtl::OUString& aServiceName) const; 218 219 /** Determine the slot id of the specified shape type. With this id 220 internal methods can access the associated type descriptor. 221 @param rxShape 222 Shape for which to return the slot id. 223 @return 224 Returns the slot id of the shape with the given service name or 225 0 when the service name is not known. 226 */ 227 SVX_DLLPRIVATE long GetSlotId (const ::com::sun::star::uno::Reference< 228 ::com::sun::star::drawing::XShape>& rxShape) const; 229 }; 230 231 } // end of namespace accessible 232 233 #endif 234