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/unoshape.hxx>
29 #include <svx/svdoashp.hxx>
31 #include <svx/strings.hrc>
33 using namespace ::com::sun::star
;
34 using namespace ::com::sun::star::accessibility
;
36 namespace accessibility
{
38 // Pointer to the shape type handler singleton.
39 ShapeTypeHandler
* ShapeTypeHandler::instance
= nullptr;
42 // Create an empty reference to an accessible object.
43 static rtl::Reference
<AccessibleShape
>
44 CreateEmptyShapeReference (
45 const AccessibleShapeInfo
& /*rShapeInfo*/,
46 const AccessibleShapeTreeInfo
& /*rShapeTreeInfo*/,
53 ShapeTypeHandler
& ShapeTypeHandler::Instance()
55 // Using double check pattern to make sure that exactly one instance of
56 // the shape type handler is instantiated.
57 if (instance
== nullptr)
59 SolarMutexGuard aGuard
;
60 if (instance
== nullptr)
62 // Create the single instance of the shape type handler.
63 instance
= new ShapeTypeHandler
;
65 // Register the basic SVX shape types.
66 RegisterDrawShapeTypes ();
74 /** The given service name is first transformed into a slot id that
75 identifies the place of the type descriptor. From that descriptor the
76 shape type id is returned.
78 ShapeTypeId
ShapeTypeHandler::GetTypeId (const OUString
& aServiceName
) const
80 tServiceNameToSlotId::const_iterator
I (maServiceNameToSlotId
.find (aServiceName
));
81 if (I
!= maServiceNameToSlotId
.end())
83 return maShapeTypeDescriptorList
[I
->second
].mnShapeTypeId
;
90 /** Extract the specified shape's service name and forward the request to
91 the appropriate method.
93 ShapeTypeId
ShapeTypeHandler::GetTypeId (const uno::Reference
<drawing::XShape
>& rxShape
) const
96 return GetTypeId (rxShape
->getShapeType());
102 /** This factory method determines the type descriptor for the type of the
103 given shape, then calls the descriptor's create function, and finally
104 initializes the new object.
106 rtl::Reference
<AccessibleShape
>
107 ShapeTypeHandler::CreateAccessibleObject (
108 const AccessibleShapeInfo
& rShapeInfo
,
109 const AccessibleShapeTreeInfo
& rShapeTreeInfo
) const
111 ShapeTypeId
nSlotId (GetSlotId (rShapeInfo
.mxShape
));
112 rtl::Reference
<AccessibleShape
> pShape(
113 maShapeTypeDescriptorList
[nSlotId
].maCreateFunction (
116 maShapeTypeDescriptorList
[nSlotId
].mnShapeTypeId
));
121 /** Create the single instance of this class and initialize its list of
122 type descriptors with an entry of an unknown type.
124 ShapeTypeHandler::ShapeTypeHandler()
125 : maShapeTypeDescriptorList (1)
127 // Make sure that at least the UNKNOWN entry is present.
128 // Resize the list, if necessary, so that the new type can be inserted.
129 maShapeTypeDescriptorList
[0].mnShapeTypeId
= UNKNOWN_SHAPE_TYPE
;
130 maShapeTypeDescriptorList
[0].msServiceName
= "UNKNOWN_SHAPE_TYPE";
131 maShapeTypeDescriptorList
[0].maCreateFunction
= CreateEmptyShapeReference
;
132 maServiceNameToSlotId
[maShapeTypeDescriptorList
[0].msServiceName
] = 0;
136 ShapeTypeHandler::~ShapeTypeHandler()
138 // Because this class is a singleton and the only instance, whose
139 // destructor has just been called, is pointed to from instance,
140 // we reset the static variable instance, so that further calls to
141 // getInstance do not return an undefined object but create a new
147 void ShapeTypeHandler::AddShapeTypeList (int nDescriptorCount
,
148 ShapeTypeDescriptor
const aDescriptorList
[])
150 SolarMutexGuard aGuard
;
152 // Determine first id of new type descriptor(s).
153 int nFirstId
= maShapeTypeDescriptorList
.size();
155 // Resize the list, if necessary, so that the types can be inserted.
156 maShapeTypeDescriptorList
.resize (nFirstId
+ nDescriptorCount
);
158 for (int i
=0; i
<nDescriptorCount
; i
++)
160 // Fill Type descriptor.
161 maShapeTypeDescriptorList
[nFirstId
+i
].mnShapeTypeId
= aDescriptorList
[i
].mnShapeTypeId
;
162 maShapeTypeDescriptorList
[nFirstId
+i
].msServiceName
= aDescriptorList
[i
].msServiceName
;
163 maShapeTypeDescriptorList
[nFirstId
+i
].maCreateFunction
= aDescriptorList
[i
].maCreateFunction
;
165 // Update inverse mapping from service name to the descriptor's position.
166 maServiceNameToSlotId
[aDescriptorList
[i
].msServiceName
] = nFirstId
+i
;
171 tools::Long
ShapeTypeHandler::GetSlotId (const OUString
& aServiceName
) const
173 tServiceNameToSlotId::const_iterator
I (maServiceNameToSlotId
.find (aServiceName
));
174 if (I
!= maServiceNameToSlotId
.end())
181 // Extract the given shape's service name and forward request to appropriate
183 tools::Long
ShapeTypeHandler::GetSlotId (const uno::Reference
<drawing::XShape
>& rxShape
) const
186 return GetSlotId (rxShape
->getShapeType());
191 /// get the accessible base name for an object
192 OUString
ShapeTypeHandler::CreateAccessibleBaseName (const uno::Reference
<drawing::XShape
>& rxShape
)
194 const char* pResourceId
;
197 switch (ShapeTypeHandler::Instance().GetTypeId (rxShape
))
199 // case DRAWING_3D_POLYGON: was removed in original code in
200 // AccessibleShape::CreateAccessibleBaseName. See issue 11190 for details.
201 // Id can be removed from SvxShapeTypes.hxx as well.
202 case DRAWING_3D_CUBE
:
203 pResourceId
= STR_ObjNameSingulCube3d
;
205 case DRAWING_3D_EXTRUDE
:
206 pResourceId
= STR_ObjNameSingulExtrude3d
;
208 case DRAWING_3D_LATHE
:
209 pResourceId
= STR_ObjNameSingulLathe3d
;
211 case DRAWING_3D_SCENE
:
212 pResourceId
= STR_ObjNameSingulScene3d
;
214 case DRAWING_3D_SPHERE
:
215 pResourceId
= STR_ObjNameSingulSphere3d
;
217 case DRAWING_CAPTION
:
218 pResourceId
= STR_ObjNameSingulCAPTION
;
220 case DRAWING_CLOSED_BEZIER
:
221 pResourceId
= STR_ObjNameSingulPATHFILL
;
223 case DRAWING_CLOSED_FREEHAND
:
224 pResourceId
= STR_ObjNameSingulFREEFILL
;
226 case DRAWING_CONNECTOR
:
227 pResourceId
= STR_ObjNameSingulEDGE
;
229 case DRAWING_CONTROL
:
230 pResourceId
= STR_ObjNameSingulUno
;
232 case DRAWING_ELLIPSE
:
233 pResourceId
= STR_ObjNameSingulCIRCE
;
236 pResourceId
= STR_ObjNameSingulGRUP
;
239 pResourceId
= STR_ObjNameSingulLINE
;
241 case DRAWING_MEASURE
:
242 pResourceId
= STR_ObjNameSingulMEASURE
;
244 case DRAWING_OPEN_BEZIER
:
245 pResourceId
= STR_ObjNameSingulPATHLINE
;
247 case DRAWING_OPEN_FREEHAND
:
248 pResourceId
= STR_ObjNameSingulFREELINE
;
251 pResourceId
= STR_ObjNameSingulPAGE
;
253 case DRAWING_POLY_LINE
:
254 pResourceId
= STR_ObjNameSingulPLIN
;
256 case DRAWING_POLY_LINE_PATH
:
257 pResourceId
= STR_ObjNameSingulPLIN
;
259 case DRAWING_POLY_POLYGON
:
260 pResourceId
= STR_ObjNameSingulPOLY
;
262 case DRAWING_POLY_POLYGON_PATH
:
263 pResourceId
= STR_ObjNameSingulPOLY
;
265 case DRAWING_RECTANGLE
:
266 pResourceId
= STR_ObjNameSingulRECT
;
269 pResourceId
= STR_ObjNameSingulCUSTOMSHAPE
;
271 if (SdrObject
* pSdrObject
= SdrObject::getSdrObjectFromXShape(rxShape
))
273 if (auto pCustomShape
= dynamic_cast<SdrObjCustomShape
*>(pSdrObject
))
275 if (pCustomShape
->IsTextPath())
276 pResourceId
= STR_ObjNameSingulFONTWORK
;
279 pResourceId
= nullptr;
280 sName
= pCustomShape
->GetCustomShapeName();
286 pResourceId
= STR_ObjNameSingulTEXT
;
289 pResourceId
= nullptr;
290 sName
= "UnknownAccessibleShape";
292 sName
+= ": " + rxShape
->getShapeType();
298 SolarMutexGuard aGuard
;
299 sName
= SvxResId(pResourceId
);
305 } // end of namespace accessibility
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */