Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / accessibility / ShapeTypeHandler.cxx
blobda662969ff09e0d3188d9145360c9ebcc98743ed
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
30 #include <svx/ShapeTypeHandler.hxx>
31 #include <svx/SvxShapeTypes.hxx>
32 #include <svx/AccessibleShapeInfo.hxx>
33 #include <com/sun/star/drawing/XShapeDescriptor.hpp>
34 #include <osl/mutex.hxx>
35 #include <vcl/svapp.hxx>
36 #include <svx/dialmgr.hxx>
37 #include "svx/svdstr.hrc"
40 using namespace ::rtl;
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::accessibility;
44 namespace accessibility {
46 // Pointer to the shape type handler singleton.
47 ShapeTypeHandler* ShapeTypeHandler::instance = NULL;
50 // Create an empty reference to an accessible object.
51 AccessibleShape*
52 CreateEmptyShapeReference (
53 const AccessibleShapeInfo& /*rShapeInfo*/,
54 const AccessibleShapeTreeInfo& /*rShapeTreeInfo*/,
55 ShapeTypeId /*nId*/)
57 return NULL;
63 ShapeTypeHandler& ShapeTypeHandler::Instance (void)
65 // Using double check pattern to make sure that exactly one instance of
66 // the shape type handler is instantiated.
67 if (instance == NULL)
69 SolarMutexGuard aGuard;
70 if (instance == NULL)
72 // Create the single instance of the shape type handler.
73 instance = new ShapeTypeHandler;
75 // Register the basic SVX shape types.
76 RegisterDrawShapeTypes ();
80 return *instance;
86 /** The given service name is first transformed into a slot id that
87 identifies the place of the type descriptor. From that descriptor the
88 shape type id is returned.
90 ShapeTypeId ShapeTypeHandler::GetTypeId (const OUString& aServiceName) const
92 tServiceNameToSlotId::iterator I (maServiceNameToSlotId.find (aServiceName));
93 if (I != maServiceNameToSlotId.end())
95 return maShapeTypeDescriptorList[I->second].mnShapeTypeId;
97 else
98 return -1;
103 /** Extract the specified shape's service name and forward the request to
104 the appropriate method.
106 ShapeTypeId ShapeTypeHandler::GetTypeId (const uno::Reference<drawing::XShape>& rxShape) const
108 uno::Reference<drawing::XShapeDescriptor> xDescriptor (rxShape, uno::UNO_QUERY);
109 if (xDescriptor.is())
110 return GetTypeId (xDescriptor->getShapeType());
111 else
112 return -1;
118 /** This factory method determines the type descriptor for the type of the
119 given shape, then calls the descriptor's create function, and finally
120 initializes the new object.
122 AccessibleShape*
123 ShapeTypeHandler::CreateAccessibleObject (
124 const AccessibleShapeInfo& rShapeInfo,
125 const AccessibleShapeTreeInfo& rShapeTreeInfo) const
127 ShapeTypeId nSlotId (GetSlotId (rShapeInfo.mxShape));
128 AccessibleShape* pShape =
129 maShapeTypeDescriptorList[nSlotId].maCreateFunction (
130 rShapeInfo,
131 rShapeTreeInfo,
132 maShapeTypeDescriptorList[nSlotId].mnShapeTypeId);
133 return pShape;
139 /** Create the single instance of this class and initialize its list of
140 type descriptors with an entry of an unknown type.
142 ShapeTypeHandler::ShapeTypeHandler (void)
143 : maShapeTypeDescriptorList (1)
145 // Make sure that at least the UNKNOWN entry is present.
146 // Resize the list, if necessary, so that the new type can be inserted.
147 maShapeTypeDescriptorList[0].mnShapeTypeId = UNKNOWN_SHAPE_TYPE;
148 maShapeTypeDescriptorList[0].msServiceName =
149 OUString(RTL_CONSTASCII_USTRINGPARAM("UNKNOWN_SHAPE_TYPE"));
150 maShapeTypeDescriptorList[0].maCreateFunction = CreateEmptyShapeReference;
151 maServiceNameToSlotId[maShapeTypeDescriptorList[0].msServiceName] = 0;
157 ShapeTypeHandler::~ShapeTypeHandler (void)
159 // Because this class is a singleton and the only instance, whose
160 // destructor has just been called, is pointed to from instance,
161 // we reset the static variable instance, so that further calls to
162 // getInstance do not return an undefined object but create a new
163 // singleton.
164 instance = NULL;
170 bool ShapeTypeHandler::AddShapeTypeList (int nDescriptorCount,
171 ShapeTypeDescriptor aDescriptorList[])
173 SolarMutexGuard aGuard;
175 // Determine first id of new type descriptor(s).
176 int nFirstId = maShapeTypeDescriptorList.size();
178 // Resize the list, if necessary, so that the types can be inserted.
179 maShapeTypeDescriptorList.resize (nFirstId + nDescriptorCount);
181 for (int i=0; i<nDescriptorCount; i++)
183 #if OSL_DEBUG_LEVEL > 0
184 ShapeTypeId nId (aDescriptorList[i].mnShapeTypeId);
185 (void)nId;
186 #endif
188 // Fill Type descriptor.
189 maShapeTypeDescriptorList[nFirstId+i].mnShapeTypeId = aDescriptorList[i].mnShapeTypeId;
190 maShapeTypeDescriptorList[nFirstId+i].msServiceName = aDescriptorList[i].msServiceName;
191 maShapeTypeDescriptorList[nFirstId+i].maCreateFunction = aDescriptorList[i].maCreateFunction;
193 // Update inverse mapping from service name to the descriptor's position.
194 maServiceNameToSlotId[aDescriptorList[i].msServiceName] = nFirstId+i;
197 return true;
203 long ShapeTypeHandler::GetSlotId (const OUString& aServiceName) const
205 tServiceNameToSlotId::iterator I (maServiceNameToSlotId.find (aServiceName));
206 if (I != maServiceNameToSlotId.end())
207 return I->second;
208 else
209 return 0;
215 // Extract the given shape's service name and forward request to appropriate
216 // method.
217 long ShapeTypeHandler::GetSlotId (const uno::Reference<drawing::XShape>& rxShape) const
219 uno::Reference<drawing::XShapeDescriptor> xDescriptor (rxShape, uno::UNO_QUERY);
220 if (xDescriptor.is())
221 return GetSlotId (xDescriptor->getShapeType());
222 else
223 return 0;
226 /// get the accessible base name for an object
227 ::rtl::OUString
228 ShapeTypeHandler::CreateAccessibleBaseName (const uno::Reference<drawing::XShape>& rxShape)
229 throw (::com::sun::star::uno::RuntimeException)
231 sal_Int32 nResourceId;
232 OUString sName;
234 switch (ShapeTypeHandler::Instance().GetTypeId (rxShape))
236 // case DRAWING_3D_POLYGON: was removed in original code in
237 // AccessibleShape::CreateAccessibleBaseName. See issue 11190 for details.
238 // Id can be removed from SvxShapeTypes.hxx as well.
239 case DRAWING_3D_CUBE:
240 nResourceId = STR_ObjNameSingulCube3d;
241 break;
242 case DRAWING_3D_EXTRUDE:
243 nResourceId = STR_ObjNameSingulExtrude3d;
244 break;
245 case DRAWING_3D_LATHE:
246 nResourceId = STR_ObjNameSingulLathe3d;
247 break;
248 case DRAWING_3D_SCENE:
249 nResourceId = STR_ObjNameSingulScene3d;
250 break;
251 case DRAWING_3D_SPHERE:
252 nResourceId = STR_ObjNameSingulSphere3d;
253 break;
254 case DRAWING_CAPTION:
255 nResourceId = STR_ObjNameSingulCAPTION;
256 break;
257 case DRAWING_CLOSED_BEZIER:
258 nResourceId = STR_ObjNameSingulPATHFILL;
259 break;
260 case DRAWING_CLOSED_FREEHAND:
261 nResourceId = STR_ObjNameSingulFREEFILL;
262 break;
263 case DRAWING_CONNECTOR:
264 nResourceId = STR_ObjNameSingulEDGE;
265 break;
266 case DRAWING_CONTROL:
267 nResourceId = STR_ObjNameSingulUno;
268 break;
269 case DRAWING_ELLIPSE:
270 nResourceId = STR_ObjNameSingulCIRCE;
271 break;
272 case DRAWING_GROUP:
273 nResourceId = STR_ObjNameSingulGRUP;
274 break;
275 case DRAWING_LINE:
276 nResourceId = STR_ObjNameSingulLINE;
277 break;
278 case DRAWING_MEASURE:
279 nResourceId = STR_ObjNameSingulMEASURE;
280 break;
281 case DRAWING_OPEN_BEZIER:
282 nResourceId = STR_ObjNameSingulPATHLINE;
283 break;
284 case DRAWING_OPEN_FREEHAND:
285 nResourceId = STR_ObjNameSingulFREELINE;
286 break;
287 case DRAWING_PAGE:
288 nResourceId = STR_ObjNameSingulPAGE;
289 break;
290 case DRAWING_POLY_LINE:
291 nResourceId = STR_ObjNameSingulPLIN;
292 break;
293 case DRAWING_POLY_LINE_PATH:
294 nResourceId = STR_ObjNameSingulPLIN;
295 break;
296 case DRAWING_POLY_POLYGON:
297 nResourceId = STR_ObjNameSingulPOLY;
298 break;
299 case DRAWING_POLY_POLYGON_PATH:
300 nResourceId = STR_ObjNameSingulPOLY;
301 break;
302 case DRAWING_RECTANGLE:
303 nResourceId = STR_ObjNameSingulRECT;
304 break;
305 case DRAWING_TEXT:
306 nResourceId = STR_ObjNameSingulTEXT;
307 break;
308 default:
309 nResourceId = -1;
310 sName = ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("UnknownAccessibleShape"));
311 uno::Reference<drawing::XShapeDescriptor> xDescriptor (rxShape, uno::UNO_QUERY);
312 if (xDescriptor.is())
313 sName += ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM(": "))
314 + xDescriptor->getShapeType();
315 break;
318 if (nResourceId != -1)
320 SolarMutexGuard aGuard;
321 sName = OUString (SVX_RESSTR((unsigned short)nResourceId));
324 return sName;
327 } // end of namespace accessibility
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */