1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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.
43 CreateEmptyShapeReference (
44 const AccessibleShapeInfo
& /*rShapeInfo*/,
45 const AccessibleShapeTreeInfo
& /*rShapeTreeInfo*/,
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.
60 SolarMutexGuard aGuard
;
63 // Create the single instance of the shape type handler.
64 instance
= new ShapeTypeHandler
;
66 // Register the basic SVX shape types.
67 RegisterDrawShapeTypes ();
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
;
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());
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.
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 (
123 maShapeTypeDescriptorList
[nSlotId
].mnShapeTypeId
);
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
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
);
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
;
193 long ShapeTypeHandler::GetSlotId (const OUString
& aServiceName
) const
195 tServiceNameToSlotId::iterator
I (maServiceNameToSlotId
.find (aServiceName
));
196 if (I
!= maServiceNameToSlotId
.end())
205 // Extract the given shape's service name and forward request to appropriate
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());
216 /// get the accessible base name for an object
218 ShapeTypeHandler::CreateAccessibleBaseName (const uno::Reference
<drawing::XShape
>& rxShape
)
219 throw (::com::sun::star::uno::RuntimeException
)
221 sal_Int32 nResourceId
;
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
;
232 case DRAWING_3D_EXTRUDE
:
233 nResourceId
= STR_ObjNameSingulExtrude3d
;
235 case DRAWING_3D_LATHE
:
236 nResourceId
= STR_ObjNameSingulLathe3d
;
238 case DRAWING_3D_SCENE
:
239 nResourceId
= STR_ObjNameSingulScene3d
;
241 case DRAWING_3D_SPHERE
:
242 nResourceId
= STR_ObjNameSingulSphere3d
;
244 case DRAWING_CAPTION
:
245 nResourceId
= STR_ObjNameSingulCAPTION
;
247 case DRAWING_CLOSED_BEZIER
:
248 nResourceId
= STR_ObjNameSingulPATHFILL
;
250 case DRAWING_CLOSED_FREEHAND
:
251 nResourceId
= STR_ObjNameSingulFREEFILL
;
253 case DRAWING_CONNECTOR
:
254 nResourceId
= STR_ObjNameSingulEDGE
;
256 case DRAWING_CONTROL
:
257 nResourceId
= STR_ObjNameSingulUno
;
259 case DRAWING_ELLIPSE
:
260 nResourceId
= STR_ObjNameSingulCIRCE
;
263 nResourceId
= STR_ObjNameSingulGRUP
;
266 nResourceId
= STR_ObjNameSingulLINE
;
268 case DRAWING_MEASURE
:
269 nResourceId
= STR_ObjNameSingulMEASURE
;
271 case DRAWING_OPEN_BEZIER
:
272 nResourceId
= STR_ObjNameSingulPATHLINE
;
274 case DRAWING_OPEN_FREEHAND
:
275 nResourceId
= STR_ObjNameSingulFREELINE
;
278 nResourceId
= STR_ObjNameSingulPAGE
;
280 case DRAWING_POLY_LINE
:
281 nResourceId
= STR_ObjNameSingulPLIN
;
283 case DRAWING_POLY_LINE_PATH
:
284 nResourceId
= STR_ObjNameSingulPLIN
;
286 case DRAWING_POLY_POLYGON
:
287 nResourceId
= STR_ObjNameSingulPOLY
;
289 case DRAWING_POLY_POLYGON_PATH
:
290 nResourceId
= STR_ObjNameSingulPOLY
;
292 case DRAWING_RECTANGLE
:
293 nResourceId
= STR_ObjNameSingulRECT
;
296 nResourceId
= STR_ObjNameSingulTEXT
;
300 sName
= "UnknownAccessibleShape";
301 uno::Reference
<drawing::XShapeDescriptor
> xDescriptor (rxShape
, uno::UNO_QUERY
);
302 if (xDescriptor
.is())
303 sName
+= ": " + xDescriptor
->getShapeType();
307 if (nResourceId
!= -1)
309 SolarMutexGuard aGuard
;
310 sName
= OUString (SVX_RESSTR((unsigned short)nResourceId
));
316 } // end of namespace accessibility
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */