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