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