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/unoshape.hxx>
29 #include <svx/svdoashp.hxx>
30 
31 #include <svx/strings.hrc>
32 
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::accessibility;
35 
36 namespace accessibility {
37 
38 // Pointer to the shape type handler singleton.
39 ShapeTypeHandler* ShapeTypeHandler::instance = nullptr;
40 
41 
42 // Create an empty reference to an accessible object.
43 static AccessibleShape*
45  const AccessibleShapeInfo& /*rShapeInfo*/,
46  const AccessibleShapeTreeInfo& /*rShapeTreeInfo*/,
47  ShapeTypeId /*nId*/)
48 {
49  return nullptr;
50 }
51 
52 
54 {
55  // Using double check pattern to make sure that exactly one instance of
56  // the shape type handler is instantiated.
57  if (instance == nullptr)
58  {
59  SolarMutexGuard aGuard;
60  if (instance == nullptr)
61  {
62  // Create the single instance of the shape type handler.
64 
65  // Register the basic SVX shape types.
67  }
68  }
69 
70  return *instance;
71 }
72 
73 
78 ShapeTypeId ShapeTypeHandler::GetTypeId (const OUString& aServiceName) const
79 {
80  tServiceNameToSlotId::const_iterator I (maServiceNameToSlotId.find (aServiceName));
81  if (I != maServiceNameToSlotId.end())
82  {
83  return maShapeTypeDescriptorList[I->second].mnShapeTypeId;
84  }
85  else
86  return -1;
87 }
88 
89 
93 ShapeTypeId ShapeTypeHandler::GetTypeId (const uno::Reference<drawing::XShape>& rxShape) const
94 {
95  if (rxShape.is())
96  return GetTypeId (rxShape->getShapeType());
97  else
98  return -1;
99 }
100 
101 
108  const AccessibleShapeInfo& rShapeInfo,
109  const AccessibleShapeTreeInfo& rShapeTreeInfo) const
110 {
111  ShapeTypeId nSlotId (GetSlotId (rShapeInfo.mxShape));
113  maShapeTypeDescriptorList[nSlotId].maCreateFunction (
114  rShapeInfo,
115  rShapeTreeInfo,
116  maShapeTypeDescriptorList[nSlotId].mnShapeTypeId));
117  return pShape;
118 }
119 
120 
125  : maShapeTypeDescriptorList (1)
126 {
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.
130  maShapeTypeDescriptorList[0].msServiceName = "UNKNOWN_SHAPE_TYPE";
132  maServiceNameToSlotId[maShapeTypeDescriptorList[0].msServiceName] = 0;
133 }
134 
135 
137 {
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
142  // singleton.
143  instance = nullptr;
144 }
145 
146 
147 void ShapeTypeHandler::AddShapeTypeList (int nDescriptorCount,
148  ShapeTypeDescriptor const aDescriptorList[])
149 {
150  SolarMutexGuard aGuard;
151 
152  // Determine first id of new type descriptor(s).
153  int nFirstId = maShapeTypeDescriptorList.size();
154 
155  // Resize the list, if necessary, so that the types can be inserted.
156  maShapeTypeDescriptorList.resize (nFirstId + nDescriptorCount);
157 
158  for (int i=0; i<nDescriptorCount; i++)
159  {
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;
164 
165  // Update inverse mapping from service name to the descriptor's position.
166  maServiceNameToSlotId[aDescriptorList[i].msServiceName] = nFirstId+i;
167  }
168 }
169 
170 
171 long ShapeTypeHandler::GetSlotId (const OUString& aServiceName) const
172 {
173  tServiceNameToSlotId::const_iterator I (maServiceNameToSlotId.find (aServiceName));
174  if (I != maServiceNameToSlotId.end())
175  return I->second;
176  else
177  return 0;
178 }
179 
180 
181 // Extract the given shape's service name and forward request to appropriate
182 // method.
183 long ShapeTypeHandler::GetSlotId (const uno::Reference<drawing::XShape>& rxShape) const
184 {
185  if (rxShape.is())
186  return GetSlotId (rxShape->getShapeType());
187  else
188  return 0;
189 }
190 
192 OUString ShapeTypeHandler::CreateAccessibleBaseName (const uno::Reference<drawing::XShape>& rxShape)
193 {
194  const char* pResourceId;
195  OUString sName;
196 
197  switch (ShapeTypeHandler::Instance().GetTypeId (rxShape))
198  {
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;
204  break;
205  case DRAWING_3D_EXTRUDE:
206  pResourceId = STR_ObjNameSingulExtrude3d;
207  break;
208  case DRAWING_3D_LATHE:
209  pResourceId = STR_ObjNameSingulLathe3d;
210  break;
211  case DRAWING_3D_SCENE:
212  pResourceId = STR_ObjNameSingulScene3d;
213  break;
214  case DRAWING_3D_SPHERE:
215  pResourceId = STR_ObjNameSingulSphere3d;
216  break;
217  case DRAWING_CAPTION:
218  pResourceId = STR_ObjNameSingulCAPTION;
219  break;
221  pResourceId = STR_ObjNameSingulPATHFILL;
222  break;
224  pResourceId = STR_ObjNameSingulFREEFILL;
225  break;
226  case DRAWING_CONNECTOR:
227  pResourceId = STR_ObjNameSingulEDGE;
228  break;
229  case DRAWING_CONTROL:
230  pResourceId = STR_ObjNameSingulUno;
231  break;
232  case DRAWING_ELLIPSE:
233  pResourceId = STR_ObjNameSingulCIRCE;
234  break;
235  case DRAWING_GROUP:
236  pResourceId = STR_ObjNameSingulGRUP;
237  break;
238  case DRAWING_LINE:
239  pResourceId = STR_ObjNameSingulLINE;
240  break;
241  case DRAWING_MEASURE:
242  pResourceId = STR_ObjNameSingulMEASURE;
243  break;
244  case DRAWING_OPEN_BEZIER:
245  pResourceId = STR_ObjNameSingulPATHLINE;
246  break;
248  pResourceId = STR_ObjNameSingulFREELINE;
249  break;
250  case DRAWING_PAGE:
251  pResourceId = STR_ObjNameSingulPAGE;
252  break;
253  case DRAWING_POLY_LINE:
254  pResourceId = STR_ObjNameSingulPLIN;
255  break;
257  pResourceId = STR_ObjNameSingulPLIN;
258  break;
260  pResourceId = STR_ObjNameSingulPOLY;
261  break;
263  pResourceId = STR_ObjNameSingulPOLY;
264  break;
265  case DRAWING_RECTANGLE:
266  pResourceId = STR_ObjNameSingulRECT;
267  break;
268  case DRAWING_CUSTOM:
269  pResourceId = STR_ObjNameSingulCUSTOMSHAPE;
270 
271  if (SvxShape* pShape = comphelper::getUnoTunnelImplementation<SvxShape>(rxShape))
272  {
273  if (auto pCustomShape = dynamic_cast<SdrObjCustomShape*>(pShape->GetSdrObject()))
274  {
275  if (pCustomShape->IsTextPath())
276  pResourceId = STR_ObjNameSingulFONTWORK;
277  else
278  {
279  pResourceId = nullptr;
280  sName = pCustomShape->GetCustomShapeName();
281  }
282  }
283  }
284  break;
285  case DRAWING_TEXT:
286  pResourceId = STR_ObjNameSingulTEXT;
287  break;
288  default:
289  pResourceId = nullptr;
290  sName = "UnknownAccessibleShape";
291  if (rxShape.is())
292  sName += ": " + rxShape->getShapeType();
293  break;
294  }
295 
296  if (pResourceId)
297  {
298  SolarMutexGuard aGuard;
299  sName = SvxResId(pResourceId);
300  }
301 
302  return sName;
303 }
304 
305 } // end of namespace accessibility
306 
307 /* 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...
css::uno::Reference< css::drawing::XShape > mxShape
The shape itself for which an accessible object is to be constructed.
tServiceNameToSlotId maServiceNameToSlotId
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(const char *pId)
Definition: dialmgr.cxx:28
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.
OUString sName
int ShapeTypeId
Use an integer to represent shape type ids.
SVX_DLLPRIVATE long GetSlotId(const OUString &aServiceName) const
Determine the slot id of the specified shape type.
int i
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
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...
static AccessibleShape * CreateEmptyShapeReference(const AccessibleShapeInfo &, const AccessibleShapeTreeInfo &, ShapeTypeId)
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.