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 <vcl/svapp.hxx>
25 #include <svx/AccessibleShape.hxx>
26 #include <svx/dialmgr.hxx>
28 #include <svx/svdoashp.hxx>
30 #include <svx/strings.hrc>
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
= nullptr;
41 // Create an empty reference to an accessible object.
42 static rtl::Reference
<AccessibleShape
>
43 CreateEmptyShapeReference (
44 const AccessibleShapeInfo
& /*rShapeInfo*/,
45 const AccessibleShapeTreeInfo
& /*rShapeTreeInfo*/,
52 ShapeTypeHandler
& ShapeTypeHandler::Instance()
54 // Using double check pattern to make sure that exactly one instance of
55 // the shape type handler is instantiated.
56 if (instance
== nullptr)
58 SolarMutexGuard aGuard
;
59 if (instance
== nullptr)
61 // Create the single instance of the shape type handler.
62 instance
= new ShapeTypeHandler
;
64 // Register the basic SVX shape types.
65 RegisterDrawShapeTypes ();
73 /** The given service name is first transformed into a slot id that
74 identifies the place of the type descriptor. From that descriptor the
75 shape type id is returned.
77 ShapeTypeId
ShapeTypeHandler::GetTypeId (const OUString
& aServiceName
) const
79 tServiceNameToSlotId::const_iterator
I (maServiceNameToSlotId
.find (aServiceName
));
80 if (I
!= maServiceNameToSlotId
.end())
82 return maShapeTypeDescriptorList
[I
->second
].mnShapeTypeId
;
89 /** Extract the specified shape's service name and forward the request to
90 the appropriate method.
92 ShapeTypeId
ShapeTypeHandler::GetTypeId (const uno::Reference
<drawing::XShape
>& rxShape
) const
95 return GetTypeId (rxShape
->getShapeType());
101 /** This factory method determines the type descriptor for the type of the
102 given shape, then calls the descriptor's create function, and finally
103 initializes the new object.
105 rtl::Reference
<AccessibleShape
>
106 ShapeTypeHandler::CreateAccessibleObject (
107 const AccessibleShapeInfo
& rShapeInfo
,
108 const AccessibleShapeTreeInfo
& rShapeTreeInfo
) const
110 ShapeTypeId
nSlotId (GetSlotId (rShapeInfo
.mxShape
));
111 rtl::Reference
<AccessibleShape
> pShape(
112 maShapeTypeDescriptorList
[nSlotId
].maCreateFunction (
115 maShapeTypeDescriptorList
[nSlotId
].mnShapeTypeId
));
120 /** Create the single instance of this class and initialize its list of
121 type descriptors with an entry of an unknown type.
123 ShapeTypeHandler::ShapeTypeHandler()
124 : maShapeTypeDescriptorList (1)
126 // Make sure that at least the UNKNOWN entry is present.
127 // Resize the list, if necessary, so that the new type can be inserted.
128 maShapeTypeDescriptorList
[0].mnShapeTypeId
= UNKNOWN_SHAPE_TYPE
;
129 maShapeTypeDescriptorList
[0].msServiceName
= "UNKNOWN_SHAPE_TYPE";
130 maShapeTypeDescriptorList
[0].maCreateFunction
= CreateEmptyShapeReference
;
131 maServiceNameToSlotId
[maShapeTypeDescriptorList
[0].msServiceName
] = 0;
135 ShapeTypeHandler::~ShapeTypeHandler()
137 // Because this class is a singleton and the only instance, whose
138 // destructor has just been called, is pointed to from instance,
139 // we reset the static variable instance, so that further calls to
140 // getInstance do not return an undefined object but create a new
146 void ShapeTypeHandler::AddShapeTypeList (int nDescriptorCount
,
147 ShapeTypeDescriptor
const aDescriptorList
[])
149 SolarMutexGuard aGuard
;
151 // Determine first id of new type descriptor(s).
152 int nFirstId
= maShapeTypeDescriptorList
.size();
154 // Resize the list, if necessary, so that the types can be inserted.
155 maShapeTypeDescriptorList
.resize (nFirstId
+ nDescriptorCount
);
157 for (int i
=0; i
<nDescriptorCount
; i
++)
159 // Fill Type descriptor.
160 maShapeTypeDescriptorList
[nFirstId
+i
].mnShapeTypeId
= aDescriptorList
[i
].mnShapeTypeId
;
161 maShapeTypeDescriptorList
[nFirstId
+i
].msServiceName
= aDescriptorList
[i
].msServiceName
;
162 maShapeTypeDescriptorList
[nFirstId
+i
].maCreateFunction
= aDescriptorList
[i
].maCreateFunction
;
164 // Update inverse mapping from service name to the descriptor's position.
165 maServiceNameToSlotId
[aDescriptorList
[i
].msServiceName
] = nFirstId
+i
;
170 tools::Long
ShapeTypeHandler::GetSlotId (const OUString
& aServiceName
) const
172 tServiceNameToSlotId::const_iterator
I (maServiceNameToSlotId
.find (aServiceName
));
173 if (I
!= maServiceNameToSlotId
.end())
180 // Extract the given shape's service name and forward request to appropriate
182 tools::Long
ShapeTypeHandler::GetSlotId (const uno::Reference
<drawing::XShape
>& rxShape
) const
185 return GetSlotId (rxShape
->getShapeType());
190 /// get the accessible base name for an object
191 OUString
ShapeTypeHandler::CreateAccessibleBaseName (const uno::Reference
<drawing::XShape
>& rxShape
)
193 TranslateId pResourceId
;
196 switch (ShapeTypeHandler::Instance().GetTypeId (rxShape
))
198 // case DRAWING_3D_POLYGON: was removed in original code in
199 // AccessibleShape::CreateAccessibleBaseName. See issue 11190 for details.
200 // Id can be removed from SvxShapeTypes.hxx as well.
201 case DRAWING_3D_CUBE
:
202 pResourceId
= STR_ObjNameSingulCube3d
;
204 case DRAWING_3D_EXTRUDE
:
205 pResourceId
= STR_ObjNameSingulExtrude3d
;
207 case DRAWING_3D_LATHE
:
208 pResourceId
= STR_ObjNameSingulLathe3d
;
210 case DRAWING_3D_SCENE
:
211 pResourceId
= STR_ObjNameSingulScene3d
;
213 case DRAWING_3D_SPHERE
:
214 pResourceId
= STR_ObjNameSingulSphere3d
;
216 case DRAWING_CAPTION
:
217 pResourceId
= STR_ObjNameSingulCAPTION
;
219 case DRAWING_CLOSED_BEZIER
:
220 pResourceId
= STR_ObjNameSingulPATHFILL
;
222 case DRAWING_CLOSED_FREEHAND
:
223 pResourceId
= STR_ObjNameSingulFREEFILL
;
225 case DRAWING_CONNECTOR
:
226 pResourceId
= STR_ObjNameSingulEDGE
;
228 case DRAWING_CONTROL
:
229 pResourceId
= STR_ObjNameSingulUno
;
231 case DRAWING_ELLIPSE
:
232 pResourceId
= STR_ObjNameSingulCIRCE
;
235 pResourceId
= STR_ObjNameSingulGRUP
;
238 pResourceId
= STR_ObjNameSingulLINE
;
240 case DRAWING_MEASURE
:
241 pResourceId
= STR_ObjNameSingulMEASURE
;
243 case DRAWING_OPEN_BEZIER
:
244 pResourceId
= STR_ObjNameSingulPATHLINE
;
246 case DRAWING_OPEN_FREEHAND
:
247 pResourceId
= STR_ObjNameSingulFREELINE
;
250 pResourceId
= STR_ObjNameSingulPAGE
;
252 case DRAWING_POLY_LINE
:
253 pResourceId
= STR_ObjNameSingulPLIN
;
255 case DRAWING_POLY_LINE_PATH
:
256 pResourceId
= STR_ObjNameSingulPLIN
;
258 case DRAWING_POLY_POLYGON
:
259 pResourceId
= STR_ObjNameSingulPOLY
;
261 case DRAWING_POLY_POLYGON_PATH
:
262 pResourceId
= STR_ObjNameSingulPOLY
;
264 case DRAWING_RECTANGLE
:
265 pResourceId
= STR_ObjNameSingulRECT
;
268 pResourceId
= STR_ObjNameSingulCUSTOMSHAPE
;
270 if (SdrObject
* pSdrObject
= SdrObject::getSdrObjectFromXShape(rxShape
))
272 if (auto pCustomShape
= dynamic_cast<SdrObjCustomShape
*>(pSdrObject
))
274 if (pCustomShape
->IsTextPath())
275 pResourceId
= STR_ObjNameSingulFONTWORK
;
279 sName
= pCustomShape
->GetCustomShapeName();
285 pResourceId
= STR_ObjNameSingulTEXT
;
289 sName
= "UnknownAccessibleShape";
291 sName
+= ": " + rxShape
->getShapeType();
297 SolarMutexGuard aGuard
;
298 sName
= SvxResId(pResourceId
);
304 } // end of namespace accessibility
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */