1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ShapeTypeHandler.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svx/ShapeTypeHandler.hxx>
35 #include <svx/SvxShapeTypes.hxx>
36 #include <svx/AccessibleShapeInfo.hxx>
37 #include <com/sun/star/drawing/XShapeDescriptor.hpp>
38 #include <vos/mutex.hxx>
39 #include <vcl/svapp.hxx>
40 #include <svx/dialmgr.hxx>
44 using namespace ::rtl
;
45 using namespace ::com::sun::star
;
46 using namespace ::com::sun::star::accessibility
;
48 namespace accessibility
{
50 // Pointer to the shape type handler singleton.
51 ShapeTypeHandler
* ShapeTypeHandler::instance
= NULL
;
54 // Create an empty reference to an accessible object.
56 CreateEmptyShapeReference (
57 const AccessibleShapeInfo
& /*rShapeInfo*/,
58 const AccessibleShapeTreeInfo
& /*rShapeTreeInfo*/,
67 ShapeTypeHandler
& ShapeTypeHandler::Instance (void)
69 // Using double check pattern to make sure that exactly one instance of
70 // the shape type handler is instantiated.
73 ::vos::OGuard
aGuard (::Application::GetSolarMutex());
76 // Create the single instance of the shape type handler.
77 instance
= new ShapeTypeHandler
;
79 // Register the basic SVX shape types.
80 RegisterDrawShapeTypes ();
90 /** The given service name is first transformed into a slot id that
91 identifies the place of the type descriptor. From that descriptor the
92 shape type id is returned.
94 ShapeTypeId
ShapeTypeHandler::GetTypeId (const OUString
& aServiceName
) const
96 tServiceNameToSlotId::iterator
I (maServiceNameToSlotId
.find (aServiceName
));
97 if (I
!= maServiceNameToSlotId
.end())
99 // long nSlotId = maServiceNameToSlotId[aServiceName];
100 return maShapeTypeDescriptorList
[I
->second
].mnShapeTypeId
;
108 /** Extract the specified shape's service name and forward the request to
109 the appropriate method.
111 ShapeTypeId
ShapeTypeHandler::GetTypeId (const uno::Reference
<drawing::XShape
>& rxShape
) const
113 uno::Reference
<drawing::XShapeDescriptor
> xDescriptor (rxShape
, uno::UNO_QUERY
);
114 if (xDescriptor
.is())
115 return GetTypeId (xDescriptor
->getShapeType());
123 const OUString
& ShapeTypeHandler::GetServiceName (ShapeTypeId aTypeId
) const
125 return maShapeTypeDescriptorList
[aTypeId
].msServiceName
;
131 /** This factory method determines the type descriptor for the type of the
132 given shape, then calls the descriptor's create function, and finally
133 initializes the new object.
136 ShapeTypeHandler::CreateAccessibleObject (
137 const AccessibleShapeInfo
& rShapeInfo
,
138 const AccessibleShapeTreeInfo
& rShapeTreeInfo
) const
140 ShapeTypeId
nSlotId (GetSlotId (rShapeInfo
.mxShape
));
141 AccessibleShape
* pShape
=
142 maShapeTypeDescriptorList
[nSlotId
].maCreateFunction (
145 maShapeTypeDescriptorList
[nSlotId
].mnShapeTypeId
);
152 /** Create the single instance of this class and initialize its list of
153 type descriptors with an entry of an unknown type.
155 ShapeTypeHandler::ShapeTypeHandler (void)
156 : maShapeTypeDescriptorList (1)
158 // Make sure that at least the UNKNOWN entry is present.
159 // Resize the list, if necessary, so that the new type can be inserted.
160 maShapeTypeDescriptorList
[0].mnShapeTypeId
= UNKNOWN_SHAPE_TYPE
;
161 maShapeTypeDescriptorList
[0].msServiceName
=
162 OUString::createFromAscii ("UNKNOWN_SHAPE_TYPE");
163 maShapeTypeDescriptorList
[0].maCreateFunction
= CreateEmptyShapeReference
;
164 maServiceNameToSlotId
[maShapeTypeDescriptorList
[0].msServiceName
] = 0;
170 ShapeTypeHandler::~ShapeTypeHandler (void)
172 // Because this class is a singleton and the only instance, whose
173 // destructor has just been called, is pointed to from instance,
174 // we reset the static variable instance, so that further calls to
175 // getInstance do not return an undefined object but create a new
183 bool ShapeTypeHandler::AddShapeTypeList (int nDescriptorCount
,
184 ShapeTypeDescriptor aDescriptorList
[])
186 ::vos::OGuard
aGuard (::Application::GetSolarMutex());
188 // Determine first id of new type descriptor(s).
189 int nFirstId
= maShapeTypeDescriptorList
.size();
191 // Resize the list, if necessary, so that the types can be inserted.
192 maShapeTypeDescriptorList
.resize (nFirstId
+ nDescriptorCount
);
194 for (int i
=0; i
<nDescriptorCount
; i
++)
196 #if OSL_DEBUG_LEVEL > 0
197 ShapeTypeId
nId (aDescriptorList
[i
].mnShapeTypeId
);
201 // Fill Type descriptor.
202 maShapeTypeDescriptorList
[nFirstId
+i
].mnShapeTypeId
= aDescriptorList
[i
].mnShapeTypeId
;
203 maShapeTypeDescriptorList
[nFirstId
+i
].msServiceName
= aDescriptorList
[i
].msServiceName
;
204 maShapeTypeDescriptorList
[nFirstId
+i
].maCreateFunction
= aDescriptorList
[i
].maCreateFunction
;
206 // Update inverse mapping from service name to the descriptor's position.
207 maServiceNameToSlotId
[aDescriptorList
[i
].msServiceName
] = nFirstId
+i
;
216 #include <tools/string.hxx>
217 long ShapeTypeHandler::GetSlotId (const OUString
& aServiceName
) const
219 tServiceNameToSlotId::iterator
I (maServiceNameToSlotId
.find (aServiceName
));
220 if (I
!= maServiceNameToSlotId
.end())
229 // Extract the given shape's service name and forward request to appropriate
231 long ShapeTypeHandler::GetSlotId (const uno::Reference
<drawing::XShape
>& rxShape
) const
233 uno::Reference
<drawing::XShapeDescriptor
> xDescriptor (rxShape
, uno::UNO_QUERY
);
234 if (xDescriptor
.is())
235 return GetSlotId (xDescriptor
->getShapeType());
240 /// get the accessible base name for an object
242 ShapeTypeHandler::CreateAccessibleBaseName (const uno::Reference
<drawing::XShape
>& rxShape
)
243 throw (::com::sun::star::uno::RuntimeException
)
245 sal_Int32 nResourceId
;
248 switch (ShapeTypeHandler::Instance().GetTypeId (rxShape
))
250 // case DRAWING_3D_POLYGON: was removed in original code in
251 // AccessibleShape::CreateAccessibleBaseName. See issue 11190 for details.
252 // Id can be removed from SvxShapeTypes.hxx as well.
253 case DRAWING_3D_CUBE
:
254 nResourceId
= STR_ObjNameSingulCube3d
;
256 case DRAWING_3D_EXTRUDE
:
257 nResourceId
= STR_ObjNameSingulExtrude3d
;
259 case DRAWING_3D_LATHE
:
260 nResourceId
= STR_ObjNameSingulLathe3d
;
262 case DRAWING_3D_SCENE
:
263 nResourceId
= STR_ObjNameSingulScene3d
;
265 case DRAWING_3D_SPHERE
:
266 nResourceId
= STR_ObjNameSingulSphere3d
;
268 case DRAWING_CAPTION
:
269 nResourceId
= STR_ObjNameSingulCAPTION
;
271 case DRAWING_CLOSED_BEZIER
:
272 nResourceId
= STR_ObjNameSingulPATHFILL
;
274 case DRAWING_CLOSED_FREEHAND
:
275 nResourceId
= STR_ObjNameSingulFREEFILL
;
277 case DRAWING_CONNECTOR
:
278 nResourceId
= STR_ObjNameSingulEDGE
;
280 case DRAWING_CONTROL
:
281 nResourceId
= STR_ObjNameSingulUno
;
283 case DRAWING_ELLIPSE
:
284 nResourceId
= STR_ObjNameSingulCIRCE
;
287 nResourceId
= STR_ObjNameSingulGRUP
;
290 nResourceId
= STR_ObjNameSingulLINE
;
292 case DRAWING_MEASURE
:
293 nResourceId
= STR_ObjNameSingulMEASURE
;
295 case DRAWING_OPEN_BEZIER
:
296 nResourceId
= STR_ObjNameSingulPATHLINE
;
298 case DRAWING_OPEN_FREEHAND
:
299 nResourceId
= STR_ObjNameSingulFREELINE
;
302 nResourceId
= STR_ObjNameSingulPAGE
;
304 case DRAWING_POLY_LINE
:
305 nResourceId
= STR_ObjNameSingulPLIN
;
307 case DRAWING_POLY_LINE_PATH
:
308 nResourceId
= STR_ObjNameSingulPLIN
;
310 case DRAWING_POLY_POLYGON
:
311 nResourceId
= STR_ObjNameSingulPOLY
;
313 case DRAWING_POLY_POLYGON_PATH
:
314 nResourceId
= STR_ObjNameSingulPOLY
;
316 case DRAWING_RECTANGLE
:
317 nResourceId
= STR_ObjNameSingulRECT
;
320 nResourceId
= STR_ObjNameSingulTEXT
;
324 sName
= ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("UnknownAccessibleShape"));
325 uno::Reference
<drawing::XShapeDescriptor
> xDescriptor (rxShape
, uno::UNO_QUERY
);
326 if (xDescriptor
.is())
327 sName
+= ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM(": "))
328 + xDescriptor
->getShapeType();
332 if (nResourceId
!= -1)
334 ::vos::OGuard
aGuard (::Application::GetSolarMutex());
335 sName
= OUString (SVX_RESSTR((unsigned short)nResourceId
));
341 } // end of namespace accessibility