LibreOffice Module svx (master)  1
ShapeTypeHandler.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 
21 #include <svx/ShapeTypeHandler.hxx>
22 #include <svx/SvxShapeTypes.hxx>
24 #include <vcl/svapp.hxx>
25 #include <svx/AccessibleShape.hxx>
26 #include <svx/dialmgr.hxx>
27 
28 #include <svx/svdoashp.hxx>
29 
30 #include <svx/strings.hrc>
31 
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::accessibility;
34 
35 namespace accessibility {
36 
37 // Pointer to the shape type handler singleton.
38 ShapeTypeHandler* ShapeTypeHandler::instance = nullptr;
39 
40 
41 // Create an empty reference to an accessible object.
44  const AccessibleShapeInfo& /*rShapeInfo*/,
45  const AccessibleShapeTreeInfo& /*rShapeTreeInfo*/,
46  ShapeTypeId /*nId*/)
47 {
48  return nullptr;
49 }
50 
51 
53 {
54  // Using double check pattern to make sure that exactly one instance of
55  // the shape type handler is instantiated.
56  if (instance == nullptr)
57  {
58  SolarMutexGuard aGuard;
59  if (instance == nullptr)
60  {
61  // Create the single instance of the shape type handler.
63 
64  // Register the basic SVX shape types.
66  }
67  }
68 
69  return *instance;
70 }
71 
72 
77 ShapeTypeId ShapeTypeHandler::GetTypeId (const OUString& aServiceName) const
78 {
79  tServiceNameToSlotId::const_iterator I (maServiceNameToSlotId.find (aServiceName));
80  if (I != maServiceNameToSlotId.end())
81  {
82  return maShapeTypeDescriptorList[I->second].mnShapeTypeId;
83  }
84  else
85  return -1;
86 }
87 
88 
92 ShapeTypeId ShapeTypeHandler::GetTypeId (const uno::Reference<drawing::XShape>& rxShape) const
93 {
94  if (rxShape.is())
95  return GetTypeId (rxShape->getShapeType());
96  else
97  return -1;
98 }
99 
100 
107  const AccessibleShapeInfo& rShapeInfo,
108  const AccessibleShapeTreeInfo& rShapeTreeInfo) const
109 {
110  ShapeTypeId nSlotId (GetSlotId (rShapeInfo.mxShape));
112  maShapeTypeDescriptorList[nSlotId].maCreateFunction (
113  rShapeInfo,
114  rShapeTreeInfo,
115  maShapeTypeDescriptorList[nSlotId].mnShapeTypeId));
116  return pShape;
117 }
118 
119 
124  : maShapeTypeDescriptorList (1)
125 {
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.
129  maShapeTypeDescriptorList[0].msServiceName = "UNKNOWN_SHAPE_TYPE";
131  maServiceNameToSlotId[maShapeTypeDescriptorList[0].msServiceName] = 0;
132 }
133 
134 
136 {
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
141  // singleton.
142  instance = nullptr;
143 }
144 
145 
146 void ShapeTypeHandler::AddShapeTypeList (int nDescriptorCount,
147  ShapeTypeDescriptor const aDescriptorList[])
148 {
149  SolarMutexGuard aGuard;
150 
151  // Determine first id of new type descriptor(s).
152  int nFirstId = maShapeTypeDescriptorList.size();
153 
154  // Resize the list, if necessary, so that the types can be inserted.
155  maShapeTypeDescriptorList.resize (nFirstId + nDescriptorCount);
156 
157  for (int i=0; i<nDescriptorCount; i++)
158  {
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;
163 
164  // Update inverse mapping from service name to the descriptor's position.
165  maServiceNameToSlotId[aDescriptorList[i].msServiceName] = nFirstId+i;
166  }
167 }
168 
169 
170 tools::Long ShapeTypeHandler::GetSlotId (const OUString& aServiceName) const
171 {
172  tServiceNameToSlotId::const_iterator I (maServiceNameToSlotId.find (aServiceName));
173  if (I != maServiceNameToSlotId.end())
174  return I->second;
175  else
176  return 0;
177 }
178 
179 
180 // Extract the given shape's service name and forward request to appropriate
181 // method.
182 tools::Long ShapeTypeHandler::GetSlotId (const uno::Reference<drawing::XShape>& rxShape) const
183 {
184  if (rxShape.is())
185  return GetSlotId (rxShape->getShapeType());
186  else
187  return 0;
188 }
189 
191 OUString ShapeTypeHandler::CreateAccessibleBaseName (const uno::Reference<drawing::XShape>& rxShape)
192 {
193  TranslateId pResourceId;
194  OUString sName;
195 
196  switch (ShapeTypeHandler::Instance().GetTypeId (rxShape))
197  {
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;
203  break;
204  case DRAWING_3D_EXTRUDE:
205  pResourceId = STR_ObjNameSingulExtrude3d;
206  break;
207  case DRAWING_3D_LATHE:
208  pResourceId = STR_ObjNameSingulLathe3d;
209  break;
210  case DRAWING_3D_SCENE:
211  pResourceId = STR_ObjNameSingulScene3d;
212  break;
213  case DRAWING_3D_SPHERE:
214  pResourceId = STR_ObjNameSingulSphere3d;
215  break;
216  case DRAWING_CAPTION:
217  pResourceId = STR_ObjNameSingulCAPTION;
218  break;
220  pResourceId = STR_ObjNameSingulPATHFILL;
221  break;
223  pResourceId = STR_ObjNameSingulFREEFILL;
224  break;
225  case DRAWING_CONNECTOR:
226  pResourceId = STR_ObjNameSingulEDGE;
227  break;
228  case DRAWING_CONTROL:
229  pResourceId = STR_ObjNameSingulUno;
230  break;
231  case DRAWING_ELLIPSE:
232  pResourceId = STR_ObjNameSingulCIRCE;
233  break;
234  case DRAWING_GROUP:
235  pResourceId = STR_ObjNameSingulGRUP;
236  break;
237  case DRAWING_LINE:
238  pResourceId = STR_ObjNameSingulLINE;
239  break;
240  case DRAWING_MEASURE:
241  pResourceId = STR_ObjNameSingulMEASURE;
242  break;
243  case DRAWING_OPEN_BEZIER:
244  pResourceId = STR_ObjNameSingulPATHLINE;
245  break;
247  pResourceId = STR_ObjNameSingulFREELINE;
248  break;
249  case DRAWING_PAGE:
250  pResourceId = STR_ObjNameSingulPAGE;
251  break;
252  case DRAWING_POLY_LINE:
253  pResourceId = STR_ObjNameSingulPLIN;
254  break;
256  pResourceId = STR_ObjNameSingulPLIN;
257  break;
259  pResourceId = STR_ObjNameSingulPOLY;
260  break;
262  pResourceId = STR_ObjNameSingulPOLY;
263  break;
264  case DRAWING_RECTANGLE:
265  pResourceId = STR_ObjNameSingulRECT;
266  break;
267  case DRAWING_CUSTOM:
268  pResourceId = STR_ObjNameSingulCUSTOMSHAPE;
269 
270  if (SdrObject* pSdrObject = SdrObject::getSdrObjectFromXShape(rxShape))
271  {
272  if (auto pCustomShape = dynamic_cast<SdrObjCustomShape*>(pSdrObject))
273  {
274  if (pCustomShape->IsTextPath())
275  pResourceId = STR_ObjNameSingulFONTWORK;
276  else
277  {
278  pResourceId = {};
279  sName = pCustomShape->GetCustomShapeName();
280  }
281  }
282  }
283  break;
284  case DRAWING_TEXT:
285  pResourceId = STR_ObjNameSingulTEXT;
286  break;
287  default:
288  pResourceId = {};
289  sName = "UnknownAccessibleShape";
290  if (rxShape.is())
291  sName += ": " + rxShape->getShapeType();
292  break;
293  }
294 
295  if (pResourceId)
296  {
297  SolarMutexGuard aGuard;
298  sName = SvxResId(pResourceId);
299  }
300 
301  return sName;
302 }
303 
304 } // end of namespace accessibility
305 
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Each shape type is described by listing its id, its service name and a function which creates a new a...
long Long
static SdrObject * getSdrObjectFromXShape(const css::uno::Reference< css::uno::XInterface > &xInt)
Definition: unoshape.cxx:4021
css::uno::Reference< css::drawing::XShape > mxShape
The shape itself for which an accessible object is to be constructed.
tServiceNameToSlotId maServiceNameToSlotId
static rtl::Reference< AccessibleShape > CreateEmptyShapeReference(const AccessibleShapeInfo &, const AccessibleShapeTreeInfo &, ShapeTypeId)
void RegisterDrawShapeTypes()
Register the SVX draw shape types with the ShapeTypeHandler singleton.
rtl::Reference< AccessibleShape > CreateAccessibleObject(const AccessibleShapeInfo &rShapeInfo, const AccessibleShapeTreeInfo &rShapeTreeInfo) const
Create a new accessible object for the given shape.
::std::vector< ShapeTypeDescriptor > maShapeTypeDescriptorList
List of shape type descriptors.
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
This class is a singleton that has the purpose to transform between service names of shapes and assoc...
static ShapeTypeHandler * instance
Pointer to the only instance of this class.
void AddShapeTypeList(int nDescriptorCount, ShapeTypeDescriptor const aDescriptorList[])
Add new shape types to the internal tables.
int i
OUString sName
int ShapeTypeId
Use an integer to represent shape type ids.
static ShapeTypeHandler & Instance()
This function returns a reference to the only instance of this class.
ShapeTypeHandler()
Create the single instance of this class and initialize its list of type descriptors with an entry of...
static OUString CreateAccessibleBaseName(const css::uno::Reference< css::drawing::XShape > &rxShape)
get the accessible base name for an object
Abstract DrawObject.
Definition: svdobj.hxx:260
SVX_DLLPRIVATE tools::Long GetSlotId(const OUString &aServiceName) const
Determine the slot id of the specified shape type.
ShapeTypeId GetTypeId(const OUString &aServiceName) const
Determines the type id of a shape with the given service name.
This class is a container for the information specific for a single shape that is passed to the const...
This class bundles all information that is passed down the tree of accessible shapes so that each sha...
~ShapeTypeHandler()
This destructor is never called at the moment.