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>
29 #include <svx/unoshape.hxx>
30 #include <svx/svdoashp.hxx>
31 #include "svx/unoapi.hxx"
33 #include "svx/svdstr.hrc"
35 using namespace ::rtl
;
36 using namespace ::com::sun::star
;
37 using namespace ::com::sun::star::accessibility
;
39 namespace accessibility
{
41 // Pointer to the shape type handler singleton.
42 ShapeTypeHandler
* ShapeTypeHandler::instance
= NULL
;
45 // Create an empty reference to an accessible object.
47 CreateEmptyShapeReference (
48 const AccessibleShapeInfo
& /*rShapeInfo*/,
49 const AccessibleShapeTreeInfo
& /*rShapeTreeInfo*/,
58 ShapeTypeHandler
& ShapeTypeHandler::Instance (void)
60 // Using double check pattern to make sure that exactly one instance of
61 // the shape type handler is instantiated.
64 SolarMutexGuard aGuard
;
67 // Create the single instance of the shape type handler.
68 instance
= new ShapeTypeHandler
;
70 // Register the basic SVX shape types.
71 RegisterDrawShapeTypes ();
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.
85 ShapeTypeId
ShapeTypeHandler::GetTypeId (const OUString
& aServiceName
) const
87 tServiceNameToSlotId::iterator
I (maServiceNameToSlotId
.find (aServiceName
));
88 if (I
!= maServiceNameToSlotId
.end())
90 return maShapeTypeDescriptorList
[I
->second
].mnShapeTypeId
;
98 /** Extract the specified shape's service name and forward the request to
99 the appropriate method.
101 ShapeTypeId
ShapeTypeHandler::GetTypeId (const uno::Reference
<drawing::XShape
>& rxShape
) const
103 uno::Reference
<drawing::XShapeDescriptor
> xDescriptor (rxShape
, uno::UNO_QUERY
);
104 if (xDescriptor
.is())
105 return GetTypeId (xDescriptor
->getShapeType());
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.
118 ShapeTypeHandler::CreateAccessibleObject (
119 const AccessibleShapeInfo
& rShapeInfo
,
120 const AccessibleShapeTreeInfo
& rShapeTreeInfo
) const
122 ShapeTypeId
nSlotId (GetSlotId (rShapeInfo
.mxShape
));
123 AccessibleShape
* pShape
=
124 maShapeTypeDescriptorList
[nSlotId
].maCreateFunction (
127 maShapeTypeDescriptorList
[nSlotId
].mnShapeTypeId
);
134 /** Create the single instance of this class and initialize its list of
135 type descriptors with an entry of an unknown type.
137 ShapeTypeHandler::ShapeTypeHandler (void)
138 : maShapeTypeDescriptorList (1)
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 maShapeTypeDescriptorList
[0].mnShapeTypeId
= UNKNOWN_SHAPE_TYPE
;
143 maShapeTypeDescriptorList
[0].msServiceName
= "UNKNOWN_SHAPE_TYPE";
144 maShapeTypeDescriptorList
[0].maCreateFunction
= CreateEmptyShapeReference
;
145 maServiceNameToSlotId
[maShapeTypeDescriptorList
[0].msServiceName
] = 0;
151 ShapeTypeHandler::~ShapeTypeHandler (void)
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
164 bool ShapeTypeHandler::AddShapeTypeList (int nDescriptorCount
,
165 ShapeTypeDescriptor aDescriptorList
[])
167 SolarMutexGuard aGuard
;
169 // Determine first id of new type descriptor(s).
170 int nFirstId
= maShapeTypeDescriptorList
.size();
172 // Resize the list, if necessary, so that the types can be inserted.
173 maShapeTypeDescriptorList
.resize (nFirstId
+ nDescriptorCount
);
175 for (int i
=0; i
<nDescriptorCount
; i
++)
177 #if OSL_DEBUG_LEVEL > 0
178 ShapeTypeId
nId (aDescriptorList
[i
].mnShapeTypeId
);
182 // Fill Type descriptor.
183 maShapeTypeDescriptorList
[nFirstId
+i
].mnShapeTypeId
= aDescriptorList
[i
].mnShapeTypeId
;
184 maShapeTypeDescriptorList
[nFirstId
+i
].msServiceName
= aDescriptorList
[i
].msServiceName
;
185 maShapeTypeDescriptorList
[nFirstId
+i
].maCreateFunction
= aDescriptorList
[i
].maCreateFunction
;
187 // Update inverse mapping from service name to the descriptor's position.
188 maServiceNameToSlotId
[aDescriptorList
[i
].msServiceName
] = nFirstId
+i
;
197 long ShapeTypeHandler::GetSlotId (const OUString
& aServiceName
) const
199 tServiceNameToSlotId::iterator
I (maServiceNameToSlotId
.find (aServiceName
));
200 if (I
!= maServiceNameToSlotId
.end())
209 // Extract the given shape's service name and forward request to appropriate
211 long ShapeTypeHandler::GetSlotId (const uno::Reference
<drawing::XShape
>& rxShape
) const
213 uno::Reference
<drawing::XShapeDescriptor
> xDescriptor (rxShape
, uno::UNO_QUERY
);
214 if (xDescriptor
.is())
215 return GetSlotId (xDescriptor
->getShapeType());
220 /// get the accessible base name for an object
222 ShapeTypeHandler::CreateAccessibleBaseName (const uno::Reference
<drawing::XShape
>& rxShape
)
223 throw (::com::sun::star::uno::RuntimeException
)
225 sal_Int32 nResourceId
;
228 switch (ShapeTypeHandler::Instance().GetTypeId (rxShape
))
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 nResourceId
= STR_ObjNameSingulCube3d
;
236 case DRAWING_3D_EXTRUDE
:
237 nResourceId
= STR_ObjNameSingulExtrude3d
;
239 case DRAWING_3D_LATHE
:
240 nResourceId
= STR_ObjNameSingulLathe3d
;
242 case DRAWING_3D_SCENE
:
243 nResourceId
= STR_ObjNameSingulScene3d
;
245 case DRAWING_3D_SPHERE
:
246 nResourceId
= STR_ObjNameSingulSphere3d
;
248 case DRAWING_CAPTION
:
249 nResourceId
= STR_ObjNameSingulCAPTION
;
251 case DRAWING_CLOSED_BEZIER
:
252 nResourceId
= STR_ObjNameSingulPATHFILL
;
254 case DRAWING_CLOSED_FREEHAND
:
255 nResourceId
= STR_ObjNameSingulFREEFILL
;
257 case DRAWING_CONNECTOR
:
258 nResourceId
= STR_ObjNameSingulEDGE
;
260 case DRAWING_CONTROL
:
261 nResourceId
= STR_ObjNameSingulUno
;
263 case DRAWING_ELLIPSE
:
264 nResourceId
= STR_ObjNameSingulCIRCE
;
267 nResourceId
= STR_ObjNameSingulGRUP
;
270 nResourceId
= STR_ObjNameSingulLINE
;
272 case DRAWING_MEASURE
:
273 nResourceId
= STR_ObjNameSingulMEASURE
;
275 case DRAWING_OPEN_BEZIER
:
276 nResourceId
= STR_ObjNameSingulPATHLINE
;
278 case DRAWING_OPEN_FREEHAND
:
279 nResourceId
= STR_ObjNameSingulFREELINE
;
282 nResourceId
= STR_ObjNameSingulPAGE
;
284 case DRAWING_POLY_LINE
:
285 nResourceId
= STR_ObjNameSingulPLIN
;
287 case DRAWING_POLY_LINE_PATH
:
288 nResourceId
= STR_ObjNameSingulPLIN
;
290 case DRAWING_POLY_POLYGON
:
291 nResourceId
= STR_ObjNameSingulPOLY
;
293 case DRAWING_POLY_POLYGON_PATH
:
294 nResourceId
= STR_ObjNameSingulPOLY
;
296 case DRAWING_RECTANGLE
:
297 nResourceId
= STR_ObjNameSingulRECT
;
301 nResourceId
= STR_ObjNameSingulCUSTOMSHAPE
;
303 SvxShape
* pShape
= SvxShape::getImplementation( rxShape
);
306 SdrObject
*pSdrObj
= pShape
->GetSdrObject();
309 if(pSdrObj
->ISA(SdrObjCustomShape
))
311 SdrObjCustomShape
* pCustomShape
= (SdrObjCustomShape
*)pSdrObj
;
314 if (pCustomShape
->IsTextPath())
315 nResourceId
= STR_ObjNameSingulFONTWORK
;
319 sName
= pCustomShape
->GetCustomShapeName();
328 nResourceId
= STR_ObjNameSingulTEXT
;
332 sName
= "UnknownAccessibleShape";
333 uno::Reference
<drawing::XShapeDescriptor
> xDescriptor (rxShape
, uno::UNO_QUERY
);
334 if (xDescriptor
.is())
335 sName
+= ": " + xDescriptor
->getShapeType();
339 if (nResourceId
!= -1)
341 SolarMutexGuard aGuard
;
342 sName
= OUString (SVX_RESSTR((unsigned short)nResourceId
));
348 } // end of namespace accessibility
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */