Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
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"
38 : :
39 : :
40 : : using namespace ::rtl;
41 : : using namespace ::com::sun::star;
42 : : using namespace ::com::sun::star::accessibility;
43 : :
44 : : namespace accessibility {
45 : :
46 : : // Pointer to the shape type handler singleton.
47 : : ShapeTypeHandler* ShapeTypeHandler::instance = NULL;
48 : :
49 : :
50 : : // Create an empty reference to an accessible object.
51 : : AccessibleShape*
52 : 0 : CreateEmptyShapeReference (
53 : : const AccessibleShapeInfo& /*rShapeInfo*/,
54 : : const AccessibleShapeTreeInfo& /*rShapeTreeInfo*/,
55 : : ShapeTypeId /*nId*/)
56 : : {
57 : 0 : return NULL;
58 : : }
59 : :
60 : :
61 : :
62 : :
63 : 78 : ShapeTypeHandler& ShapeTypeHandler::Instance (void)
64 : : {
65 : : // Using double check pattern to make sure that exactly one instance of
66 : : // the shape type handler is instantiated.
67 [ + + ]: 78 : if (instance == NULL)
68 : : {
69 [ + - ]: 22 : SolarMutexGuard aGuard;
70 [ + - ]: 22 : if (instance == NULL)
71 : : {
72 : : // Create the single instance of the shape type handler.
73 [ + - ][ + - ]: 22 : instance = new ShapeTypeHandler;
74 : :
75 : : // Register the basic SVX shape types.
76 [ + - ]: 22 : RegisterDrawShapeTypes ();
77 [ + - ]: 22 : }
78 : : }
79 : :
80 : 78 : return *instance;
81 : : }
82 : :
83 : :
84 : :
85 : :
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.
89 : : */
90 : 12 : ShapeTypeId ShapeTypeHandler::GetTypeId (const OUString& aServiceName) const
91 : : {
92 [ + - ]: 12 : tServiceNameToSlotId::iterator I (maServiceNameToSlotId.find (aServiceName));
93 [ + - ][ + - ]: 12 : if (I != maServiceNameToSlotId.end())
94 : : {
95 [ + - ]: 12 : return maShapeTypeDescriptorList[I->second].mnShapeTypeId;
96 : : }
97 : : else
98 : 12 : return -1;
99 : : }
100 : :
101 : :
102 : :
103 : : /** Extract the specified shape's service name and forward the request to
104 : : the appropriate method.
105 : : */
106 : 26 : ShapeTypeId ShapeTypeHandler::GetTypeId (const uno::Reference<drawing::XShape>& rxShape) const
107 : : {
108 [ + - ]: 26 : uno::Reference<drawing::XShapeDescriptor> xDescriptor (rxShape, uno::UNO_QUERY);
109 [ + + ]: 26 : if (xDescriptor.is())
110 [ + - ][ + - ]: 12 : return GetTypeId (xDescriptor->getShapeType());
[ + - ]
111 : : else
112 : 26 : return -1;
113 : : }
114 : :
115 : :
116 : :
117 : :
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.
121 : : */
122 : : AccessibleShape*
123 : 8 : ShapeTypeHandler::CreateAccessibleObject (
124 : : const AccessibleShapeInfo& rShapeInfo,
125 : : const AccessibleShapeTreeInfo& rShapeTreeInfo) const
126 : : {
127 : 8 : ShapeTypeId nSlotId (GetSlotId (rShapeInfo.mxShape));
128 : : AccessibleShape* pShape =
129 : 8 : maShapeTypeDescriptorList[nSlotId].maCreateFunction (
130 : : rShapeInfo,
131 : : rShapeTreeInfo,
132 : 8 : maShapeTypeDescriptorList[nSlotId].mnShapeTypeId);
133 : 8 : return pShape;
134 : : }
135 : :
136 : :
137 : :
138 : :
139 : : /** Create the single instance of this class and initialize its list of
140 : : type descriptors with an entry of an unknown type.
141 : : */
142 : 22 : ShapeTypeHandler::ShapeTypeHandler (void)
143 [ + - ]: 22 : : maShapeTypeDescriptorList (1)
144 : : {
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 : 22 : maShapeTypeDescriptorList[0].mnShapeTypeId = UNKNOWN_SHAPE_TYPE;
148 : 22 : maShapeTypeDescriptorList[0].msServiceName =
149 [ + - ]: 44 : OUString(RTL_CONSTASCII_USTRINGPARAM("UNKNOWN_SHAPE_TYPE"));
150 : 22 : maShapeTypeDescriptorList[0].maCreateFunction = CreateEmptyShapeReference;
151 [ + - ]: 22 : maServiceNameToSlotId[maShapeTypeDescriptorList[0].msServiceName] = 0;
152 : 22 : }
153 : :
154 : :
155 : :
156 : :
157 [ # # ]: 0 : ShapeTypeHandler::~ShapeTypeHandler (void)
158 : : {
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 : 0 : instance = NULL;
165 [ # # ]: 0 : }
166 : :
167 : :
168 : :
169 : :
170 : 44 : bool ShapeTypeHandler::AddShapeTypeList (int nDescriptorCount,
171 : : ShapeTypeDescriptor aDescriptorList[])
172 : : {
173 [ + - ]: 44 : SolarMutexGuard aGuard;
174 : :
175 : : // Determine first id of new type descriptor(s).
176 : 44 : int nFirstId = maShapeTypeDescriptorList.size();
177 : :
178 : : // Resize the list, if necessary, so that the types can be inserted.
179 [ + - ]: 44 : maShapeTypeDescriptorList.resize (nFirstId + nDescriptorCount);
180 : :
181 [ + + ]: 1034 : for (int i=0; i<nDescriptorCount; i++)
182 : : {
183 : : #if OSL_DEBUG_LEVEL > 0
184 : : ShapeTypeId nId (aDescriptorList[i].mnShapeTypeId);
185 : : (void)nId;
186 : : #endif
187 : :
188 : : // Fill Type descriptor.
189 : 990 : maShapeTypeDescriptorList[nFirstId+i].mnShapeTypeId = aDescriptorList[i].mnShapeTypeId;
190 : 990 : maShapeTypeDescriptorList[nFirstId+i].msServiceName = aDescriptorList[i].msServiceName;
191 : 990 : maShapeTypeDescriptorList[nFirstId+i].maCreateFunction = aDescriptorList[i].maCreateFunction;
192 : :
193 : : // Update inverse mapping from service name to the descriptor's position.
194 [ + - ]: 990 : maServiceNameToSlotId[aDescriptorList[i].msServiceName] = nFirstId+i;
195 : : }
196 : :
197 [ + - ]: 44 : return true;
198 : : }
199 : :
200 : :
201 : :
202 : :
203 : 8 : long ShapeTypeHandler::GetSlotId (const OUString& aServiceName) const
204 : : {
205 [ + - ]: 8 : tServiceNameToSlotId::iterator I (maServiceNameToSlotId.find (aServiceName));
206 [ + - ][ + - ]: 8 : if (I != maServiceNameToSlotId.end())
207 [ + - ]: 8 : return I->second;
208 : : else
209 : 8 : return 0;
210 : : }
211 : :
212 : :
213 : :
214 : :
215 : : // Extract the given shape's service name and forward request to appropriate
216 : : // method.
217 : 8 : long ShapeTypeHandler::GetSlotId (const uno::Reference<drawing::XShape>& rxShape) const
218 : : {
219 [ + - ]: 8 : uno::Reference<drawing::XShapeDescriptor> xDescriptor (rxShape, uno::UNO_QUERY);
220 [ + - ]: 8 : if (xDescriptor.is())
221 [ + - ][ + - ]: 8 : return GetSlotId (xDescriptor->getShapeType());
[ + - ]
222 : : else
223 : 8 : return 0;
224 : : }
225 : :
226 : : /// get the accessible base name for an object
227 : : ::rtl::OUString
228 : 4 : ShapeTypeHandler::CreateAccessibleBaseName (const uno::Reference<drawing::XShape>& rxShape)
229 : : throw (::com::sun::star::uno::RuntimeException)
230 : : {
231 : : sal_Int32 nResourceId;
232 : 4 : OUString sName;
233 : :
234 [ + - ][ - - : 4 : switch (ShapeTypeHandler::Instance().GetTypeId (rxShape))
- - - - -
- - - - -
- - - - -
- - - - +
- - ][ + - ]
235 : : {
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 : 0 : nResourceId = STR_ObjNameSingulCube3d;
241 : : break;
242 : : case DRAWING_3D_EXTRUDE:
243 : 0 : nResourceId = STR_ObjNameSingulExtrude3d;
244 : : break;
245 : : case DRAWING_3D_LATHE:
246 : 0 : nResourceId = STR_ObjNameSingulLathe3d;
247 : : break;
248 : : case DRAWING_3D_SCENE:
249 : 0 : nResourceId = STR_ObjNameSingulScene3d;
250 : : break;
251 : : case DRAWING_3D_SPHERE:
252 : 0 : nResourceId = STR_ObjNameSingulSphere3d;
253 : : break;
254 : : case DRAWING_CAPTION:
255 : 0 : nResourceId = STR_ObjNameSingulCAPTION;
256 : : break;
257 : : case DRAWING_CLOSED_BEZIER:
258 : 0 : nResourceId = STR_ObjNameSingulPATHFILL;
259 : : break;
260 : : case DRAWING_CLOSED_FREEHAND:
261 : 0 : nResourceId = STR_ObjNameSingulFREEFILL;
262 : : break;
263 : : case DRAWING_CONNECTOR:
264 : 0 : nResourceId = STR_ObjNameSingulEDGE;
265 : : break;
266 : : case DRAWING_CONTROL:
267 : 0 : nResourceId = STR_ObjNameSingulUno;
268 : : break;
269 : : case DRAWING_ELLIPSE:
270 : 0 : nResourceId = STR_ObjNameSingulCIRCE;
271 : : break;
272 : : case DRAWING_GROUP:
273 : 0 : nResourceId = STR_ObjNameSingulGRUP;
274 : : break;
275 : : case DRAWING_LINE:
276 : 0 : nResourceId = STR_ObjNameSingulLINE;
277 : : break;
278 : : case DRAWING_MEASURE:
279 : 0 : nResourceId = STR_ObjNameSingulMEASURE;
280 : : break;
281 : : case DRAWING_OPEN_BEZIER:
282 : 0 : nResourceId = STR_ObjNameSingulPATHLINE;
283 : : break;
284 : : case DRAWING_OPEN_FREEHAND:
285 : 0 : nResourceId = STR_ObjNameSingulFREELINE;
286 : : break;
287 : : case DRAWING_PAGE:
288 : 0 : nResourceId = STR_ObjNameSingulPAGE;
289 : : break;
290 : : case DRAWING_POLY_LINE:
291 : 0 : nResourceId = STR_ObjNameSingulPLIN;
292 : : break;
293 : : case DRAWING_POLY_LINE_PATH:
294 : 0 : nResourceId = STR_ObjNameSingulPLIN;
295 : : break;
296 : : case DRAWING_POLY_POLYGON:
297 : 0 : nResourceId = STR_ObjNameSingulPOLY;
298 : : break;
299 : : case DRAWING_POLY_POLYGON_PATH:
300 : 0 : nResourceId = STR_ObjNameSingulPOLY;
301 : : break;
302 : : case DRAWING_RECTANGLE:
303 : 4 : nResourceId = STR_ObjNameSingulRECT;
304 : : break;
305 : : case DRAWING_TEXT:
306 : 0 : nResourceId = STR_ObjNameSingulTEXT;
307 : : break;
308 : : default:
309 : 0 : nResourceId = -1;
310 [ # # ]: 0 : sName = ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("UnknownAccessibleShape"));
311 [ # # ]: 0 : uno::Reference<drawing::XShapeDescriptor> xDescriptor (rxShape, uno::UNO_QUERY);
312 [ # # ]: 0 : if (xDescriptor.is())
313 : : sName += ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM(": "))
314 [ # # ][ # # ]: 0 : + xDescriptor->getShapeType();
[ # # ]
315 : 0 : break;
316 : : }
317 : :
318 [ + - ]: 4 : if (nResourceId != -1)
319 : : {
320 [ + - ]: 4 : SolarMutexGuard aGuard;
321 [ + - ][ + - ]: 4 : sName = OUString (SVX_RESSTR((unsigned short)nResourceId));
[ + - ]
322 : : }
323 : :
324 : 4 : return sName;
325 : : }
326 : :
327 : : } // end of namespace accessibility
328 : :
329 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|