merge the formfield patch from ooo-build
[ooovba.git] / svx / source / accessibility / ShapeTypeHandler.cxx
blob3145870d38736ed2ad8da09161f66828ea1aefc9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ShapeTypeHandler.cxx,v $
10 * $Revision: 1.18 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svx/ShapeTypeHandler.hxx>
35 #include <svx/SvxShapeTypes.hxx>
36 #include <svx/AccessibleShapeInfo.hxx>
37 #include <com/sun/star/drawing/XShapeDescriptor.hpp>
38 #include <vos/mutex.hxx>
39 #include <vcl/svapp.hxx>
40 #include <svx/dialmgr.hxx>
41 #include "svdstr.hrc"
44 using namespace ::rtl;
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::accessibility;
48 namespace accessibility {
50 // Pointer to the shape type handler singleton.
51 ShapeTypeHandler* ShapeTypeHandler::instance = NULL;
54 // Create an empty reference to an accessible object.
55 AccessibleShape*
56 CreateEmptyShapeReference (
57 const AccessibleShapeInfo& /*rShapeInfo*/,
58 const AccessibleShapeTreeInfo& /*rShapeTreeInfo*/,
59 ShapeTypeId /*nId*/)
61 return NULL;
67 ShapeTypeHandler& ShapeTypeHandler::Instance (void)
69 // Using double check pattern to make sure that exactly one instance of
70 // the shape type handler is instantiated.
71 if (instance == NULL)
73 ::vos::OGuard aGuard (::Application::GetSolarMutex());
74 if (instance == NULL)
76 // Create the single instance of the shape type handler.
77 instance = new ShapeTypeHandler;
79 // Register the basic SVX shape types.
80 RegisterDrawShapeTypes ();
84 return *instance;
90 /** The given service name is first transformed into a slot id that
91 identifies the place of the type descriptor. From that descriptor the
92 shape type id is returned.
94 ShapeTypeId ShapeTypeHandler::GetTypeId (const OUString& aServiceName) const
96 tServiceNameToSlotId::iterator I (maServiceNameToSlotId.find (aServiceName));
97 if (I != maServiceNameToSlotId.end())
99 // long nSlotId = maServiceNameToSlotId[aServiceName];
100 return maShapeTypeDescriptorList[I->second].mnShapeTypeId;
102 else
103 return -1;
108 /** Extract the specified shape's service name and forward the request to
109 the appropriate method.
111 ShapeTypeId ShapeTypeHandler::GetTypeId (const uno::Reference<drawing::XShape>& rxShape) const
113 uno::Reference<drawing::XShapeDescriptor> xDescriptor (rxShape, uno::UNO_QUERY);
114 if (xDescriptor.is())
115 return GetTypeId (xDescriptor->getShapeType());
116 else
117 return -1;
123 const OUString& ShapeTypeHandler::GetServiceName (ShapeTypeId aTypeId) const
125 return maShapeTypeDescriptorList[aTypeId].msServiceName;
131 /** This factory method determines the type descriptor for the type of the
132 given shape, then calls the descriptor's create function, and finally
133 initializes the new object.
135 AccessibleShape*
136 ShapeTypeHandler::CreateAccessibleObject (
137 const AccessibleShapeInfo& rShapeInfo,
138 const AccessibleShapeTreeInfo& rShapeTreeInfo) const
140 ShapeTypeId nSlotId (GetSlotId (rShapeInfo.mxShape));
141 AccessibleShape* pShape =
142 maShapeTypeDescriptorList[nSlotId].maCreateFunction (
143 rShapeInfo,
144 rShapeTreeInfo,
145 maShapeTypeDescriptorList[nSlotId].mnShapeTypeId);
146 return pShape;
152 /** Create the single instance of this class and initialize its list of
153 type descriptors with an entry of an unknown type.
155 ShapeTypeHandler::ShapeTypeHandler (void)
156 : maShapeTypeDescriptorList (1)
158 // Make sure that at least the UNKNOWN entry is present.
159 // Resize the list, if necessary, so that the new type can be inserted.
160 maShapeTypeDescriptorList[0].mnShapeTypeId = UNKNOWN_SHAPE_TYPE;
161 maShapeTypeDescriptorList[0].msServiceName =
162 OUString::createFromAscii ("UNKNOWN_SHAPE_TYPE");
163 maShapeTypeDescriptorList[0].maCreateFunction = CreateEmptyShapeReference;
164 maServiceNameToSlotId[maShapeTypeDescriptorList[0].msServiceName] = 0;
170 ShapeTypeHandler::~ShapeTypeHandler (void)
172 // Because this class is a singleton and the only instance, whose
173 // destructor has just been called, is pointed to from instance,
174 // we reset the static variable instance, so that further calls to
175 // getInstance do not return an undefined object but create a new
176 // singleton.
177 instance = NULL;
183 bool ShapeTypeHandler::AddShapeTypeList (int nDescriptorCount,
184 ShapeTypeDescriptor aDescriptorList[])
186 ::vos::OGuard aGuard (::Application::GetSolarMutex());
188 // Determine first id of new type descriptor(s).
189 int nFirstId = maShapeTypeDescriptorList.size();
191 // Resize the list, if necessary, so that the types can be inserted.
192 maShapeTypeDescriptorList.resize (nFirstId + nDescriptorCount);
194 for (int i=0; i<nDescriptorCount; i++)
196 #if OSL_DEBUG_LEVEL > 0
197 ShapeTypeId nId (aDescriptorList[i].mnShapeTypeId);
198 (void)nId;
199 #endif
201 // Fill Type descriptor.
202 maShapeTypeDescriptorList[nFirstId+i].mnShapeTypeId = aDescriptorList[i].mnShapeTypeId;
203 maShapeTypeDescriptorList[nFirstId+i].msServiceName = aDescriptorList[i].msServiceName;
204 maShapeTypeDescriptorList[nFirstId+i].maCreateFunction = aDescriptorList[i].maCreateFunction;
206 // Update inverse mapping from service name to the descriptor's position.
207 maServiceNameToSlotId[aDescriptorList[i].msServiceName] = nFirstId+i;
210 return true;
216 #include <tools/string.hxx>
217 long ShapeTypeHandler::GetSlotId (const OUString& aServiceName) const
219 tServiceNameToSlotId::iterator I (maServiceNameToSlotId.find (aServiceName));
220 if (I != maServiceNameToSlotId.end())
221 return I->second;
222 else
223 return 0;
229 // Extract the given shape's service name and forward request to appropriate
230 // method.
231 long ShapeTypeHandler::GetSlotId (const uno::Reference<drawing::XShape>& rxShape) const
233 uno::Reference<drawing::XShapeDescriptor> xDescriptor (rxShape, uno::UNO_QUERY);
234 if (xDescriptor.is())
235 return GetSlotId (xDescriptor->getShapeType());
236 else
237 return 0;
240 /// get the accessible base name for an object
241 ::rtl::OUString
242 ShapeTypeHandler::CreateAccessibleBaseName (const uno::Reference<drawing::XShape>& rxShape)
243 throw (::com::sun::star::uno::RuntimeException)
245 sal_Int32 nResourceId;
246 OUString sName;
248 switch (ShapeTypeHandler::Instance().GetTypeId (rxShape))
250 // case DRAWING_3D_POLYGON: was removed in original code in
251 // AccessibleShape::CreateAccessibleBaseName. See issue 11190 for details.
252 // Id can be removed from SvxShapeTypes.hxx as well.
253 case DRAWING_3D_CUBE:
254 nResourceId = STR_ObjNameSingulCube3d;
255 break;
256 case DRAWING_3D_EXTRUDE:
257 nResourceId = STR_ObjNameSingulExtrude3d;
258 break;
259 case DRAWING_3D_LATHE:
260 nResourceId = STR_ObjNameSingulLathe3d;
261 break;
262 case DRAWING_3D_SCENE:
263 nResourceId = STR_ObjNameSingulScene3d;
264 break;
265 case DRAWING_3D_SPHERE:
266 nResourceId = STR_ObjNameSingulSphere3d;
267 break;
268 case DRAWING_CAPTION:
269 nResourceId = STR_ObjNameSingulCAPTION;
270 break;
271 case DRAWING_CLOSED_BEZIER:
272 nResourceId = STR_ObjNameSingulPATHFILL;
273 break;
274 case DRAWING_CLOSED_FREEHAND:
275 nResourceId = STR_ObjNameSingulFREEFILL;
276 break;
277 case DRAWING_CONNECTOR:
278 nResourceId = STR_ObjNameSingulEDGE;
279 break;
280 case DRAWING_CONTROL:
281 nResourceId = STR_ObjNameSingulUno;
282 break;
283 case DRAWING_ELLIPSE:
284 nResourceId = STR_ObjNameSingulCIRCE;
285 break;
286 case DRAWING_GROUP:
287 nResourceId = STR_ObjNameSingulGRUP;
288 break;
289 case DRAWING_LINE:
290 nResourceId = STR_ObjNameSingulLINE;
291 break;
292 case DRAWING_MEASURE:
293 nResourceId = STR_ObjNameSingulMEASURE;
294 break;
295 case DRAWING_OPEN_BEZIER:
296 nResourceId = STR_ObjNameSingulPATHLINE;
297 break;
298 case DRAWING_OPEN_FREEHAND:
299 nResourceId = STR_ObjNameSingulFREELINE;
300 break;
301 case DRAWING_PAGE:
302 nResourceId = STR_ObjNameSingulPAGE;
303 break;
304 case DRAWING_POLY_LINE:
305 nResourceId = STR_ObjNameSingulPLIN;
306 break;
307 case DRAWING_POLY_LINE_PATH:
308 nResourceId = STR_ObjNameSingulPLIN;
309 break;
310 case DRAWING_POLY_POLYGON:
311 nResourceId = STR_ObjNameSingulPOLY;
312 break;
313 case DRAWING_POLY_POLYGON_PATH:
314 nResourceId = STR_ObjNameSingulPOLY;
315 break;
316 case DRAWING_RECTANGLE:
317 nResourceId = STR_ObjNameSingulRECT;
318 break;
319 case DRAWING_TEXT:
320 nResourceId = STR_ObjNameSingulTEXT;
321 break;
322 default:
323 nResourceId = -1;
324 sName = ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("UnknownAccessibleShape"));
325 uno::Reference<drawing::XShapeDescriptor> xDescriptor (rxShape, uno::UNO_QUERY);
326 if (xDescriptor.is())
327 sName += ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM(": "))
328 + xDescriptor->getShapeType();
329 break;
332 if (nResourceId != -1)
334 ::vos::OGuard aGuard (::Application::GetSolarMutex());
335 sName = OUString (SVX_RESSTR((unsigned short)nResourceId));
338 return sName;
341 } // end of namespace accessibility