Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
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 :
29 : #include <svx/unoshape.hxx>
30 : #include <svx/svdoashp.hxx>
31 : #include "svx/unoapi.hxx"
32 :
33 : #include "svx/svdstr.hrc"
34 :
35 : using namespace ::rtl;
36 : using namespace ::com::sun::star;
37 : using namespace ::com::sun::star::accessibility;
38 :
39 : namespace accessibility {
40 :
41 : // Pointer to the shape type handler singleton.
42 : ShapeTypeHandler* ShapeTypeHandler::instance = NULL;
43 :
44 :
45 : // Create an empty reference to an accessible object.
46 : AccessibleShape*
47 0 : CreateEmptyShapeReference (
48 : const AccessibleShapeInfo& /*rShapeInfo*/,
49 : const AccessibleShapeTreeInfo& /*rShapeTreeInfo*/,
50 : ShapeTypeId /*nId*/)
51 : {
52 0 : return NULL;
53 : }
54 :
55 :
56 :
57 :
58 0 : ShapeTypeHandler& ShapeTypeHandler::Instance (void)
59 : {
60 : // Using double check pattern to make sure that exactly one instance of
61 : // the shape type handler is instantiated.
62 0 : if (instance == NULL)
63 : {
64 0 : SolarMutexGuard aGuard;
65 0 : if (instance == NULL)
66 : {
67 : // Create the single instance of the shape type handler.
68 0 : instance = new ShapeTypeHandler;
69 :
70 : // Register the basic SVX shape types.
71 0 : RegisterDrawShapeTypes ();
72 0 : }
73 : }
74 :
75 0 : return *instance;
76 : }
77 :
78 :
79 :
80 :
81 : /** The given service name is first transformed into a slot id that
82 : identifies the place of the type descriptor. From that descriptor the
83 : shape type id is returned.
84 : */
85 0 : ShapeTypeId ShapeTypeHandler::GetTypeId (const OUString& aServiceName) const
86 : {
87 0 : tServiceNameToSlotId::iterator I (maServiceNameToSlotId.find (aServiceName));
88 0 : if (I != maServiceNameToSlotId.end())
89 : {
90 0 : return maShapeTypeDescriptorList[I->second].mnShapeTypeId;
91 : }
92 : else
93 0 : return -1;
94 : }
95 :
96 :
97 :
98 : /** Extract the specified shape's service name and forward the request to
99 : the appropriate method.
100 : */
101 0 : ShapeTypeId ShapeTypeHandler::GetTypeId (const uno::Reference<drawing::XShape>& rxShape) const
102 : {
103 0 : uno::Reference<drawing::XShapeDescriptor> xDescriptor (rxShape, uno::UNO_QUERY);
104 0 : if (xDescriptor.is())
105 0 : return GetTypeId (xDescriptor->getShapeType());
106 : else
107 0 : return -1;
108 : }
109 :
110 :
111 :
112 :
113 : /** This factory method determines the type descriptor for the type of the
114 : given shape, then calls the descriptor's create function, and finally
115 : initializes the new object.
116 : */
117 : AccessibleShape*
118 0 : ShapeTypeHandler::CreateAccessibleObject (
119 : const AccessibleShapeInfo& rShapeInfo,
120 : const AccessibleShapeTreeInfo& rShapeTreeInfo) const
121 : {
122 0 : ShapeTypeId nSlotId (GetSlotId (rShapeInfo.mxShape));
123 : AccessibleShape* pShape =
124 0 : maShapeTypeDescriptorList[nSlotId].maCreateFunction (
125 : rShapeInfo,
126 : rShapeTreeInfo,
127 0 : maShapeTypeDescriptorList[nSlotId].mnShapeTypeId);
128 0 : return pShape;
129 : }
130 :
131 :
132 :
133 :
134 : /** Create the single instance of this class and initialize its list of
135 : type descriptors with an entry of an unknown type.
136 : */
137 0 : ShapeTypeHandler::ShapeTypeHandler (void)
138 0 : : maShapeTypeDescriptorList (1)
139 : {
140 : // Make sure that at least the UNKNOWN entry is present.
141 : // Resize the list, if necessary, so that the new type can be inserted.
142 0 : maShapeTypeDescriptorList[0].mnShapeTypeId = UNKNOWN_SHAPE_TYPE;
143 0 : maShapeTypeDescriptorList[0].msServiceName = "UNKNOWN_SHAPE_TYPE";
144 0 : maShapeTypeDescriptorList[0].maCreateFunction = CreateEmptyShapeReference;
145 0 : maServiceNameToSlotId[maShapeTypeDescriptorList[0].msServiceName] = 0;
146 0 : }
147 :
148 :
149 :
150 :
151 0 : ShapeTypeHandler::~ShapeTypeHandler (void)
152 : {
153 : // Because this class is a singleton and the only instance, whose
154 : // destructor has just been called, is pointed to from instance,
155 : // we reset the static variable instance, so that further calls to
156 : // getInstance do not return an undefined object but create a new
157 : // singleton.
158 0 : instance = NULL;
159 0 : }
160 :
161 :
162 :
163 :
164 0 : bool ShapeTypeHandler::AddShapeTypeList (int nDescriptorCount,
165 : ShapeTypeDescriptor aDescriptorList[])
166 : {
167 0 : SolarMutexGuard aGuard;
168 :
169 : // Determine first id of new type descriptor(s).
170 0 : int nFirstId = maShapeTypeDescriptorList.size();
171 :
172 : // Resize the list, if necessary, so that the types can be inserted.
173 0 : maShapeTypeDescriptorList.resize (nFirstId + nDescriptorCount);
174 :
175 0 : for (int i=0; i<nDescriptorCount; i++)
176 : {
177 : #if OSL_DEBUG_LEVEL > 0
178 : ShapeTypeId nId (aDescriptorList[i].mnShapeTypeId);
179 : (void)nId;
180 : #endif
181 :
182 : // Fill Type descriptor.
183 0 : maShapeTypeDescriptorList[nFirstId+i].mnShapeTypeId = aDescriptorList[i].mnShapeTypeId;
184 0 : maShapeTypeDescriptorList[nFirstId+i].msServiceName = aDescriptorList[i].msServiceName;
185 0 : maShapeTypeDescriptorList[nFirstId+i].maCreateFunction = aDescriptorList[i].maCreateFunction;
186 :
187 : // Update inverse mapping from service name to the descriptor's position.
188 0 : maServiceNameToSlotId[aDescriptorList[i].msServiceName] = nFirstId+i;
189 : }
190 :
191 0 : return true;
192 : }
193 :
194 :
195 :
196 :
197 0 : long ShapeTypeHandler::GetSlotId (const OUString& aServiceName) const
198 : {
199 0 : tServiceNameToSlotId::iterator I (maServiceNameToSlotId.find (aServiceName));
200 0 : if (I != maServiceNameToSlotId.end())
201 0 : return I->second;
202 : else
203 0 : return 0;
204 : }
205 :
206 :
207 :
208 :
209 : // Extract the given shape's service name and forward request to appropriate
210 : // method.
211 0 : long ShapeTypeHandler::GetSlotId (const uno::Reference<drawing::XShape>& rxShape) const
212 : {
213 0 : uno::Reference<drawing::XShapeDescriptor> xDescriptor (rxShape, uno::UNO_QUERY);
214 0 : if (xDescriptor.is())
215 0 : return GetSlotId (xDescriptor->getShapeType());
216 : else
217 0 : return 0;
218 : }
219 :
220 : /// get the accessible base name for an object
221 : OUString
222 0 : ShapeTypeHandler::CreateAccessibleBaseName (const uno::Reference<drawing::XShape>& rxShape)
223 : throw (::com::sun::star::uno::RuntimeException)
224 : {
225 : sal_Int32 nResourceId;
226 0 : OUString sName;
227 :
228 0 : switch (ShapeTypeHandler::Instance().GetTypeId (rxShape))
229 : {
230 : // case DRAWING_3D_POLYGON: was removed in original code in
231 : // AccessibleShape::CreateAccessibleBaseName. See issue 11190 for details.
232 : // Id can be removed from SvxShapeTypes.hxx as well.
233 : case DRAWING_3D_CUBE:
234 0 : nResourceId = STR_ObjNameSingulCube3d;
235 0 : break;
236 : case DRAWING_3D_EXTRUDE:
237 0 : nResourceId = STR_ObjNameSingulExtrude3d;
238 0 : break;
239 : case DRAWING_3D_LATHE:
240 0 : nResourceId = STR_ObjNameSingulLathe3d;
241 0 : break;
242 : case DRAWING_3D_SCENE:
243 0 : nResourceId = STR_ObjNameSingulScene3d;
244 0 : break;
245 : case DRAWING_3D_SPHERE:
246 0 : nResourceId = STR_ObjNameSingulSphere3d;
247 0 : break;
248 : case DRAWING_CAPTION:
249 0 : nResourceId = STR_ObjNameSingulCAPTION;
250 0 : break;
251 : case DRAWING_CLOSED_BEZIER:
252 0 : nResourceId = STR_ObjNameSingulPATHFILL;
253 0 : break;
254 : case DRAWING_CLOSED_FREEHAND:
255 0 : nResourceId = STR_ObjNameSingulFREEFILL;
256 0 : break;
257 : case DRAWING_CONNECTOR:
258 0 : nResourceId = STR_ObjNameSingulEDGE;
259 0 : break;
260 : case DRAWING_CONTROL:
261 0 : nResourceId = STR_ObjNameSingulUno;
262 0 : break;
263 : case DRAWING_ELLIPSE:
264 0 : nResourceId = STR_ObjNameSingulCIRCE;
265 0 : break;
266 : case DRAWING_GROUP:
267 0 : nResourceId = STR_ObjNameSingulGRUP;
268 0 : break;
269 : case DRAWING_LINE:
270 0 : nResourceId = STR_ObjNameSingulLINE;
271 0 : break;
272 : case DRAWING_MEASURE:
273 0 : nResourceId = STR_ObjNameSingulMEASURE;
274 0 : break;
275 : case DRAWING_OPEN_BEZIER:
276 0 : nResourceId = STR_ObjNameSingulPATHLINE;
277 0 : break;
278 : case DRAWING_OPEN_FREEHAND:
279 0 : nResourceId = STR_ObjNameSingulFREELINE;
280 0 : break;
281 : case DRAWING_PAGE:
282 0 : nResourceId = STR_ObjNameSingulPAGE;
283 0 : break;
284 : case DRAWING_POLY_LINE:
285 0 : nResourceId = STR_ObjNameSingulPLIN;
286 0 : break;
287 : case DRAWING_POLY_LINE_PATH:
288 0 : nResourceId = STR_ObjNameSingulPLIN;
289 0 : break;
290 : case DRAWING_POLY_POLYGON:
291 0 : nResourceId = STR_ObjNameSingulPOLY;
292 0 : break;
293 : case DRAWING_POLY_POLYGON_PATH:
294 0 : nResourceId = STR_ObjNameSingulPOLY;
295 0 : break;
296 : case DRAWING_RECTANGLE:
297 0 : nResourceId = STR_ObjNameSingulRECT;
298 0 : break;
299 : case DRAWING_CUSTOM:
300 : {
301 0 : nResourceId = STR_ObjNameSingulCUSTOMSHAPE;
302 :
303 0 : SvxShape* pShape = SvxShape::getImplementation( rxShape );
304 0 : if (pShape)
305 : {
306 0 : SdrObject *pSdrObj = pShape->GetSdrObject();
307 0 : if (pSdrObj)
308 : {
309 0 : if(pSdrObj->ISA(SdrObjCustomShape))
310 : {
311 0 : SdrObjCustomShape* pCustomShape = (SdrObjCustomShape*)pSdrObj;
312 0 : if(pCustomShape)
313 : {
314 0 : if (pCustomShape->IsTextPath())
315 0 : nResourceId = STR_ObjNameSingulFONTWORK;
316 : else
317 : {
318 0 : nResourceId = -1;
319 0 : sName = pCustomShape->GetCustomShapeName();
320 : }
321 : }
322 : }
323 : }
324 : }
325 0 : break;
326 : }
327 : case DRAWING_TEXT:
328 0 : nResourceId = STR_ObjNameSingulTEXT;
329 0 : break;
330 : default:
331 0 : nResourceId = -1;
332 0 : sName = "UnknownAccessibleShape";
333 0 : uno::Reference<drawing::XShapeDescriptor> xDescriptor (rxShape, uno::UNO_QUERY);
334 0 : if (xDescriptor.is())
335 0 : sName += ": " + xDescriptor->getShapeType();
336 0 : break;
337 : }
338 :
339 0 : if (nResourceId != -1)
340 : {
341 0 : SolarMutexGuard aGuard;
342 0 : sName = OUString (SVX_RESSTR((unsigned short)nResourceId));
343 : }
344 :
345 0 : return sName;
346 : }
347 :
348 : } // end of namespace accessibility
349 :
350 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|