fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / accessibility / ShapeTypeHandler.cxx
blob8eaee7fd7a20a0d50c34d7caaf46a84314d8cffb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <svx/ShapeTypeHandler.hxx>
22 #include <svx/SvxShapeTypes.hxx>
23 #include <svx/AccessibleShapeInfo.hxx>
24 #include <com/sun/star/drawing/XShapeDescriptor.hpp>
25 #include <osl/mutex.hxx>
26 #include <vcl/svapp.hxx>
27 #include <svx/dialmgr.hxx>
28 #include "svx/svdstr.hrc"
31 using namespace ::rtl;
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::accessibility;
35 namespace accessibility {
37 // Pointer to the shape type handler singleton.
38 ShapeTypeHandler* ShapeTypeHandler::instance = NULL;
41 // Create an empty reference to an accessible object.
42 AccessibleShape*
43 CreateEmptyShapeReference (
44 const AccessibleShapeInfo& /*rShapeInfo*/,
45 const AccessibleShapeTreeInfo& /*rShapeTreeInfo*/,
46 ShapeTypeId /*nId*/)
48 return NULL;
54 ShapeTypeHandler& ShapeTypeHandler::Instance (void)
56 // Using double check pattern to make sure that exactly one instance of
57 // the shape type handler is instantiated.
58 if (instance == NULL)
60 SolarMutexGuard aGuard;
61 if (instance == NULL)
63 // Create the single instance of the shape type handler.
64 instance = new ShapeTypeHandler;
66 // Register the basic SVX shape types.
67 RegisterDrawShapeTypes ();
71 return *instance;
77 /** The given service name is first transformed into a slot id that
78 identifies the place of the type descriptor. From that descriptor the
79 shape type id is returned.
81 ShapeTypeId ShapeTypeHandler::GetTypeId (const OUString& aServiceName) const
83 tServiceNameToSlotId::iterator I (maServiceNameToSlotId.find (aServiceName));
84 if (I != maServiceNameToSlotId.end())
86 return maShapeTypeDescriptorList[I->second].mnShapeTypeId;
88 else
89 return -1;
94 /** Extract the specified shape's service name and forward the request to
95 the appropriate method.
97 ShapeTypeId ShapeTypeHandler::GetTypeId (const uno::Reference<drawing::XShape>& rxShape) const
99 uno::Reference<drawing::XShapeDescriptor> xDescriptor (rxShape, uno::UNO_QUERY);
100 if (xDescriptor.is())
101 return GetTypeId (xDescriptor->getShapeType());
102 else
103 return -1;
109 /** This factory method determines the type descriptor for the type of the
110 given shape, then calls the descriptor's create function, and finally
111 initializes the new object.
113 AccessibleShape*
114 ShapeTypeHandler::CreateAccessibleObject (
115 const AccessibleShapeInfo& rShapeInfo,
116 const AccessibleShapeTreeInfo& rShapeTreeInfo) const
118 ShapeTypeId nSlotId (GetSlotId (rShapeInfo.mxShape));
119 AccessibleShape* pShape =
120 maShapeTypeDescriptorList[nSlotId].maCreateFunction (
121 rShapeInfo,
122 rShapeTreeInfo,
123 maShapeTypeDescriptorList[nSlotId].mnShapeTypeId);
124 return pShape;
130 /** Create the single instance of this class and initialize its list of
131 type descriptors with an entry of an unknown type.
133 ShapeTypeHandler::ShapeTypeHandler (void)
134 : maShapeTypeDescriptorList (1)
136 // Make sure that at least the UNKNOWN entry is present.
137 // Resize the list, if necessary, so that the new type can be inserted.
138 maShapeTypeDescriptorList[0].mnShapeTypeId = UNKNOWN_SHAPE_TYPE;
139 maShapeTypeDescriptorList[0].msServiceName = "UNKNOWN_SHAPE_TYPE";
140 maShapeTypeDescriptorList[0].maCreateFunction = CreateEmptyShapeReference;
141 maServiceNameToSlotId[maShapeTypeDescriptorList[0].msServiceName] = 0;
147 ShapeTypeHandler::~ShapeTypeHandler (void)
149 // Because this class is a singleton and the only instance, whose
150 // destructor has just been called, is pointed to from instance,
151 // we reset the static variable instance, so that further calls to
152 // getInstance do not return an undefined object but create a new
153 // singleton.
154 instance = NULL;
160 bool ShapeTypeHandler::AddShapeTypeList (int nDescriptorCount,
161 ShapeTypeDescriptor aDescriptorList[])
163 SolarMutexGuard aGuard;
165 // Determine first id of new type descriptor(s).
166 int nFirstId = maShapeTypeDescriptorList.size();
168 // Resize the list, if necessary, so that the types can be inserted.
169 maShapeTypeDescriptorList.resize (nFirstId + nDescriptorCount);
171 for (int i=0; i<nDescriptorCount; i++)
173 #if OSL_DEBUG_LEVEL > 0
174 ShapeTypeId nId (aDescriptorList[i].mnShapeTypeId);
175 (void)nId;
176 #endif
178 // Fill Type descriptor.
179 maShapeTypeDescriptorList[nFirstId+i].mnShapeTypeId = aDescriptorList[i].mnShapeTypeId;
180 maShapeTypeDescriptorList[nFirstId+i].msServiceName = aDescriptorList[i].msServiceName;
181 maShapeTypeDescriptorList[nFirstId+i].maCreateFunction = aDescriptorList[i].maCreateFunction;
183 // Update inverse mapping from service name to the descriptor's position.
184 maServiceNameToSlotId[aDescriptorList[i].msServiceName] = nFirstId+i;
187 return true;
193 long ShapeTypeHandler::GetSlotId (const OUString& aServiceName) const
195 tServiceNameToSlotId::iterator I (maServiceNameToSlotId.find (aServiceName));
196 if (I != maServiceNameToSlotId.end())
197 return I->second;
198 else
199 return 0;
205 // Extract the given shape's service name and forward request to appropriate
206 // method.
207 long ShapeTypeHandler::GetSlotId (const uno::Reference<drawing::XShape>& rxShape) const
209 uno::Reference<drawing::XShapeDescriptor> xDescriptor (rxShape, uno::UNO_QUERY);
210 if (xDescriptor.is())
211 return GetSlotId (xDescriptor->getShapeType());
212 else
213 return 0;
216 /// get the accessible base name for an object
217 OUString
218 ShapeTypeHandler::CreateAccessibleBaseName (const uno::Reference<drawing::XShape>& rxShape)
219 throw (::com::sun::star::uno::RuntimeException)
221 sal_Int32 nResourceId;
222 OUString sName;
224 switch (ShapeTypeHandler::Instance().GetTypeId (rxShape))
226 // case DRAWING_3D_POLYGON: was removed in original code in
227 // AccessibleShape::CreateAccessibleBaseName. See issue 11190 for details.
228 // Id can be removed from SvxShapeTypes.hxx as well.
229 case DRAWING_3D_CUBE:
230 nResourceId = STR_ObjNameSingulCube3d;
231 break;
232 case DRAWING_3D_EXTRUDE:
233 nResourceId = STR_ObjNameSingulExtrude3d;
234 break;
235 case DRAWING_3D_LATHE:
236 nResourceId = STR_ObjNameSingulLathe3d;
237 break;
238 case DRAWING_3D_SCENE:
239 nResourceId = STR_ObjNameSingulScene3d;
240 break;
241 case DRAWING_3D_SPHERE:
242 nResourceId = STR_ObjNameSingulSphere3d;
243 break;
244 case DRAWING_CAPTION:
245 nResourceId = STR_ObjNameSingulCAPTION;
246 break;
247 case DRAWING_CLOSED_BEZIER:
248 nResourceId = STR_ObjNameSingulPATHFILL;
249 break;
250 case DRAWING_CLOSED_FREEHAND:
251 nResourceId = STR_ObjNameSingulFREEFILL;
252 break;
253 case DRAWING_CONNECTOR:
254 nResourceId = STR_ObjNameSingulEDGE;
255 break;
256 case DRAWING_CONTROL:
257 nResourceId = STR_ObjNameSingulUno;
258 break;
259 case DRAWING_ELLIPSE:
260 nResourceId = STR_ObjNameSingulCIRCE;
261 break;
262 case DRAWING_GROUP:
263 nResourceId = STR_ObjNameSingulGRUP;
264 break;
265 case DRAWING_LINE:
266 nResourceId = STR_ObjNameSingulLINE;
267 break;
268 case DRAWING_MEASURE:
269 nResourceId = STR_ObjNameSingulMEASURE;
270 break;
271 case DRAWING_OPEN_BEZIER:
272 nResourceId = STR_ObjNameSingulPATHLINE;
273 break;
274 case DRAWING_OPEN_FREEHAND:
275 nResourceId = STR_ObjNameSingulFREELINE;
276 break;
277 case DRAWING_PAGE:
278 nResourceId = STR_ObjNameSingulPAGE;
279 break;
280 case DRAWING_POLY_LINE:
281 nResourceId = STR_ObjNameSingulPLIN;
282 break;
283 case DRAWING_POLY_LINE_PATH:
284 nResourceId = STR_ObjNameSingulPLIN;
285 break;
286 case DRAWING_POLY_POLYGON:
287 nResourceId = STR_ObjNameSingulPOLY;
288 break;
289 case DRAWING_POLY_POLYGON_PATH:
290 nResourceId = STR_ObjNameSingulPOLY;
291 break;
292 case DRAWING_RECTANGLE:
293 nResourceId = STR_ObjNameSingulRECT;
294 break;
295 case DRAWING_TEXT:
296 nResourceId = STR_ObjNameSingulTEXT;
297 break;
298 default:
299 nResourceId = -1;
300 sName = "UnknownAccessibleShape";
301 uno::Reference<drawing::XShapeDescriptor> xDescriptor (rxShape, uno::UNO_QUERY);
302 if (xDescriptor.is())
303 sName += ": " + xDescriptor->getShapeType();
304 break;
307 if (nResourceId != -1)
309 SolarMutexGuard aGuard;
310 sName = OUString (SVX_RESSTR((unsigned short)nResourceId));
313 return sName;
316 } // end of namespace accessibility
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */