LibreOffice Module sc (master)  1
servuno.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 #include <memory>
21 #include <config_features.h>
22 
23 #include <sal/macros.h>
24 #include <svtools/unoimap.hxx>
25 #include <svx/unofill.hxx>
26 #include <vcl/svapp.hxx>
27 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
28 #include <com/sun/star/container/XNameAccess.hpp>
29 #include <com/sun/star/text/textfield/Type.hpp>
30 
31 #include <editsrc.hxx>
32 #include <servuno.hxx>
33 #include <unonames.hxx>
34 #include <appluno.hxx>
35 #include <cellsuno.hxx>
36 #include <fielduno.hxx>
37 #include <styleuno.hxx>
38 #include <afmtuno.hxx>
39 #include <defltuno.hxx>
40 #include <drdefuno.hxx>
41 #include <docsh.hxx>
42 #include <drwlayer.hxx>
43 #include <confuno.hxx>
44 #include <shapeuno.hxx>
45 #include "cellvaluebinding.hxx"
46 #include "celllistsource.hxx"
47 #include <addruno.hxx>
48 #include <chart2uno.hxx>
49 #include <tokenuno.hxx>
51 
52 // Support creation of GraphicStorageHandler and EmbeddedObjectResolver
53 #include <svx/xmleohlp.hxx>
54 #include <svx/xmlgrhlp.hxx>
55 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
56 #include <com/sun/star/document/XCodeNameQuery.hpp>
57 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
58 #include <com/sun/star/form/XFormsSupplier.hpp>
59 #include <svx/unomod.hxx>
61 
63 #include <basic/basmgr.hxx>
64 #include <sfx2/app.hxx>
65 
66 #include <cppuhelper/implbase.hxx>
67 #include <com/sun/star/script/vba/XVBACompatibility.hpp>
68 
69 using namespace ::com::sun::star;
70 
71 #if HAVE_FEATURE_SCRIPTING
72 
73 static bool isInVBAMode( ScDocShell& rDocSh )
74 {
75  uno::Reference<script::XLibraryContainer> xLibContainer = rDocSh.GetBasicContainer();
76  uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY );
77  if ( xVBACompat.is() )
78  return xVBACompat->getVBACompatibilityMode();
79  return false;
80 }
81 
82 #endif
83 
84 namespace {
85 
86 #if HAVE_FEATURE_SCRIPTING
87 class ScVbaObjectForCodeNameProvider : public ::cppu::WeakImplHelper< container::XNameAccess >
88 {
89  uno::Any maWorkbook;
90  uno::Any maCachedObject;
91  ScDocShell* mpDocShell;
92 public:
93  explicit ScVbaObjectForCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell )
94  {
95  uno::Sequence< uno::Any > aArgs{
96  // access the application object ( parent for workbook )
97  uno::Any(ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.Application", {} )),
98  uno::Any(mpDocShell->GetModel())
99  };
100  maWorkbook <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Workbook", aArgs );
101  }
102 
103  virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override
104  {
105  SolarMutexGuard aGuard;
106  maCachedObject = uno::Any(); // clear cached object
107 
108  ScDocument& rDoc = mpDocShell->GetDocument();
109  // aName is generated from the stream name which can be different ( case-wise )
110  // from the code name
111  if( aName.equalsIgnoreAsciiCase( rDoc.GetCodeName() ) )
112  maCachedObject = maWorkbook;
113  else
114  {
115  OUString sCodeName;
116  SCTAB nCount = rDoc.GetTableCount();
117  for( SCTAB i = 0; i < nCount; i++ )
118  {
119  rDoc.GetCodeName( i, sCodeName );
120  // aName is generated from the stream name which can be different ( case-wise )
121  // from the code name
122  if( sCodeName.equalsIgnoreAsciiCase( aName ) )
123  {
124  OUString sSheetName;
125  if( rDoc.GetName( i, sSheetName ) )
126  {
127  uno::Reference< frame::XModel > xModel( mpDocShell->GetModel() );
128  uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
129  uno::Reference<sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_SET_THROW );
130  uno::Reference< container::XIndexAccess > xIndexAccess( xSheets, uno::UNO_QUERY_THROW );
131  uno::Reference< sheet::XSpreadsheet > xSheet( xIndexAccess->getByIndex( i ), uno::UNO_QUERY_THROW );
132  uno::Sequence< uno::Any > aArgs{ maWorkbook, uno::Any(xModel), uno::Any(sSheetName) };
133  // use the convenience function
134  maCachedObject <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Worksheet", aArgs );
135  break;
136  }
137  }
138  }
139  }
140  return maCachedObject.hasValue();
141 
142  }
143  css::uno::Any SAL_CALL getByName( const OUString& aName ) override
144  {
145  SolarMutexGuard aGuard;
146  if ( !hasByName( aName ) )
147  throw css::container::NoSuchElementException();
148  return maCachedObject;
149  }
150  virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override
151  {
152  SolarMutexGuard aGuard;
153  ScDocument& rDoc = mpDocShell->GetDocument();
154  SCTAB nCount = rDoc.GetTableCount();
155  uno::Sequence< OUString > aNames( nCount + 1 );
156  auto pNames = aNames.getArray();
157  SCTAB index = 0;
158  OUString sCodeName;
159  for( ; index < nCount; ++index )
160  {
161  rDoc.GetCodeName( index, sCodeName );
162  pNames[ index ] = sCodeName;
163  }
164  pNames[ index ] = rDoc.GetCodeName();
165  return aNames;
166  }
167  // XElemenAccess
168  virtual css::uno::Type SAL_CALL getElementType( ) override { return uno::Type(); }
169  virtual sal_Bool SAL_CALL hasElements( ) override { return true; }
170 
171 };
172 
173 class ScVbaCodeNameProvider : public ::cppu::WeakImplHelper< document::XCodeNameQuery >
174 {
175  ScDocShell& mrDocShell;
176 public:
177  explicit ScVbaCodeNameProvider( ScDocShell& rDocShell ) : mrDocShell(rDocShell) {}
178  // XCodeNameQuery
179  OUString SAL_CALL getCodeNameForObject( const uno::Reference< uno::XInterface >& xIf ) override
180  {
181  SolarMutexGuard aGuard;
182  OUString sCodeName;
183 
184  // need to find the page ( and index ) for this control
185  uno::Reference< drawing::XDrawPagesSupplier > xSupplier( mrDocShell.GetModel(), uno::UNO_QUERY_THROW );
186  uno::Reference< container::XIndexAccess > xIndex( xSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
187  sal_Int32 nLen = xIndex->getCount();
188  bool bMatched = false;
189  for ( sal_Int32 index = 0; index < nLen; ++index )
190  {
191  try
192  {
193  uno::Reference< form::XFormsSupplier > xFormSupplier( xIndex->getByIndex( index ), uno::UNO_QUERY_THROW );
194  uno::Reference< container::XIndexAccess > xFormIndex( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
195  // get the www-standard container
196  uno::Reference< container::XIndexAccess > xFormControls( xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW );
197  sal_Int32 nCntrls = xFormControls->getCount();
198  for( sal_Int32 cIndex = 0; cIndex < nCntrls; ++cIndex )
199  {
200  uno::Reference< uno::XInterface > xControl( xFormControls->getByIndex( cIndex ), uno::UNO_QUERY_THROW );
201  bMatched = ( xControl == xIf );
202  if ( bMatched )
203  {
204  OUString sName;
205  mrDocShell.GetDocument().GetCodeName( static_cast<SCTAB>( index ), sName );
206  sCodeName = sName;
207  }
208  }
209  }
210  catch( uno::Exception& ) {}
211  if ( bMatched )
212  break;
213  }
214  // Probably should throw here ( if !bMatched )
215  return sCodeName;
216  }
217 
218  OUString SAL_CALL getCodeNameForContainer( const uno::Reference<uno::XInterface>& xContainer ) override
219  {
220  SolarMutexGuard aGuard;
221  uno::Reference<drawing::XDrawPagesSupplier> xSupplier(mrDocShell.GetModel(), uno::UNO_QUERY_THROW);
222  uno::Reference<container::XIndexAccess> xIndex(xSupplier->getDrawPages(), uno::UNO_QUERY_THROW);
223 
224  for (sal_Int32 i = 0, n = xIndex->getCount(); i < n; ++i)
225  {
226  try
227  {
228  uno::Reference<form::XFormsSupplier> xFormSupplier(xIndex->getByIndex(i), uno::UNO_QUERY_THROW);
229  uno::Reference<container::XIndexAccess> xFormIndex(xFormSupplier->getForms(), uno::UNO_QUERY_THROW);
230  // get the www-standard container
231  uno::Reference<container::XIndexAccess> xFormControls(xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW);
232  if (xFormControls == xContainer)
233  {
234  OUString aName;
235  if (mrDocShell.GetDocument().GetCodeName(static_cast<SCTAB>(i), aName))
236  return aName;
237  }
238  }
239  catch( uno::Exception& ) {}
240  }
241  return OUString();
242  }
243 };
244 
245 #endif
246 
248 
249 struct ProvNamesId_Type
250 {
251  OUString pName;
253 };
254 
255 const ProvNamesId_Type aProvNamesId[] =
256 {
257  { "com.sun.star.sheet.Spreadsheet", Type::SHEET },
258  { "com.sun.star.text.TextField.URL", Type::URLFIELD },
259  { "com.sun.star.text.TextField.PageNumber", Type::PAGEFIELD },
260  { "com.sun.star.text.TextField.PageCount", Type::PAGESFIELD },
261  { "com.sun.star.text.TextField.Date", Type::DATEFIELD },
262  { "com.sun.star.text.TextField.Time", Type::TIMEFIELD },
263  { "com.sun.star.text.TextField.DateTime", Type::EXT_TIMEFIELD },
264  { "com.sun.star.text.TextField.DocInfo.Title", Type::TITLEFIELD },
265  { "com.sun.star.text.TextField.FileName", Type::FILEFIELD },
266  { "com.sun.star.text.TextField.SheetName", Type::SHEETFIELD },
267  { "com.sun.star.style.CellStyle", Type::CELLSTYLE },
268  { "com.sun.star.style.PageStyle", Type::PAGESTYLE },
269  { "com.sun.star.sheet.TableAutoFormat", Type::AUTOFORMAT },
270  { "com.sun.star.sheet.TableAutoFormats", Type::AUTOFORMATS },
271  { "com.sun.star.sheet.SheetCellRanges", Type::CELLRANGES },
272  { "com.sun.star.sheet.FunctionDescriptions", Type::FUNCTIONDESCRIPTIONS },
273  { "com.sun.star.sheet.GlobalSheetSettings", Type::GLOBALSHEETSETTINGS },
274  { "com.sun.star.sheet.RecentFunctions", Type::RECENTFUNCTIONS },
275  { "com.sun.star.drawing.GradientTable", Type::GRADTAB },
276  { "com.sun.star.drawing.HatchTable", Type::HATCHTAB },
277  { "com.sun.star.drawing.BitmapTable", Type::BITMAPTAB },
278  { "com.sun.star.drawing.TransparencyGradientTable", Type::TRGRADTAB },
279  { "com.sun.star.drawing.MarkerTable", Type::MARKERTAB },
280  { "com.sun.star.drawing.DashTable", Type::DASHTAB },
281  { "com.sun.star.text.NumberingRules", Type::NUMRULES },
282  { "com.sun.star.sheet.Defaults", Type::DOCDEFLTS },
283  { "com.sun.star.drawing.Defaults", Type::DRAWDEFLTS },
284  { "com.sun.star.comp.SpreadsheetSettings", Type::DOCSPRSETT },
285  { "com.sun.star.document.Settings", Type::DOCCONF },
286  { "com.sun.star.image.ImageMapRectangleObject", Type::IMAP_RECT },
287  { "com.sun.star.image.ImageMapCircleObject", Type::IMAP_CIRC },
288  { "com.sun.star.image.ImageMapPolygonObject", Type::IMAP_POLY },
289 
290  // Support creation of GraphicStorageHandler and EmbeddedObjectResolver
291  { "com.sun.star.document.ExportGraphicStorageHandler", Type::EXPORT_GRAPHIC_STORAGE_HANDLER },
292  { "com.sun.star.document.ImportGraphicStorageHandler", Type::IMPORT_GRAPHIC_STORAGE_HANDLER },
293  { "com.sun.star.document.ExportEmbeddedObjectResolver", Type::EXPORT_EOR },
294  { "com.sun.star.document.ImportEmbeddedObjectResolver", Type::IMPORT_EOR },
295 
296  { SC_SERVICENAME_VALBIND, Type::VALBIND },
297  { SC_SERVICENAME_LISTCELLBIND, Type::LISTCELLBIND },
298  { SC_SERVICENAME_LISTSOURCE, Type::LISTSOURCE },
299  { SC_SERVICENAME_CELLADDRESS, Type::CELLADDRESS },
300  { SC_SERVICENAME_RANGEADDRESS, Type::RANGEADDRESS },
301 
302  { "com.sun.star.sheet.DocumentSettings",Type::SHEETDOCSET },
303 
304  { SC_SERVICENAME_CHDATAPROV, Type::CHDATAPROV },
305  { SC_SERVICENAME_CHART_PIVOTTABLE_DATAPROVIDER, Type::CHART_PIVOTTABLE_DATAPROVIDER },
306  { SC_SERVICENAME_FORMULAPARS, Type::FORMULAPARS },
307  { SC_SERVICENAME_OPCODEMAPPER, Type::OPCODEMAPPER },
308  { "ooo.vba.VBAObjectModuleObjectProvider", Type::VBAOBJECTPROVIDER },
309  { "ooo.vba.VBACodeNameProvider", Type::VBACODENAMEPROVIDER },
310  { "ooo.vba.VBAGlobals", Type::VBAGLOBALS },
311 
312  // case-correct versions of the service names (#i102468#)
313  { "com.sun.star.text.textfield.URL", Type::URLFIELD },
314  { "com.sun.star.text.textfield.PageNumber", Type::PAGEFIELD },
315  { "com.sun.star.text.textfield.PageCount", Type::PAGESFIELD },
316  { "com.sun.star.text.textfield.Date", Type::DATEFIELD },
317  { "com.sun.star.text.textfield.Time", Type::TIMEFIELD },
318  { "com.sun.star.text.textfield.DateTime", Type::EXT_TIMEFIELD },
319  { "com.sun.star.text.textfield.docinfo.Title", Type::TITLEFIELD },
320  { "com.sun.star.text.textfield.FileName", Type::FILEFIELD },
321  { "com.sun.star.text.textfield.SheetName", Type::SHEETFIELD },
322  { "ooo.vba.VBAGlobals", Type::VBAGLOBALS },
323 };
324 
325 // old service names that were in 567 still work in createInstance,
326 // in case some macro is still using them
327 const ProvNamesId_Type aOldNames[] =
328 {
329  { "stardiv.one.text.TextField.URL", Type::URLFIELD },
330  { "stardiv.one.text.TextField.PageNumber", Type::PAGEFIELD },
331  { "stardiv.one.text.TextField.PageCount", Type::PAGESFIELD },
332  { "stardiv.one.text.TextField.Date", Type::DATEFIELD },
333  { "stardiv.one.text.TextField.Time", Type::TIMEFIELD },
334  { "stardiv.one.text.TextField.DocumentTitle", Type::TITLEFIELD },
335  { "stardiv.one.text.TextField.FileName", Type::FILEFIELD },
336  { "stardiv.one.text.TextField.SheetName", Type::SHEETFIELD },
337  { "stardiv.one.style.CellStyle", Type::CELLSTYLE },
338  { "stardiv.one.style.PageStyle", Type::PAGESTYLE },
339 };
340 
341 sal_Int32 getFieldType(ScServiceProvider::Type nOldType)
342 {
343  switch (nOldType)
344  {
345  case Type::URLFIELD:
346  return text::textfield::Type::URL;
347  case Type::PAGEFIELD:
348  return text::textfield::Type::PAGE;
349  case Type::PAGESFIELD:
350  return text::textfield::Type::PAGES;
351  case Type::DATEFIELD:
353  case Type::TIMEFIELD:
354  return text::textfield::Type::TIME;
355  case Type::EXT_TIMEFIELD:
356  return text::textfield::Type::EXTENDED_TIME;
357  case Type::TITLEFIELD:
358  return text::textfield::Type::DOCINFO_TITLE;
359  case Type::FILEFIELD:
360  return text::textfield::Type::EXTENDED_FILE;
361  case Type::SHEETFIELD:
363  default:
364  ;
365  }
366 
367  return text::textfield::Type::URL; // default to URL for no reason whatsoever.
368 }
369 
370 } // namespace
371 
372 
374 {
375  if (!rServiceName.empty())
376  {
377  for (const ProvNamesId_Type & i : aProvNamesId)
378  {
379  if (rServiceName == i.pName)
380  {
381  return i.nType;
382  }
383  }
384 
385  for (const ProvNamesId_Type & rOldName : aOldNames)
386  {
387  if (rServiceName == rOldName.pName)
388  {
389  OSL_FAIL("old service name used");
390  return rOldName.nType;
391  }
392  }
393  }
394  return Type::INVALID;
395 }
396 
397 uno::Reference<uno::XInterface> ScServiceProvider::MakeInstance(
398  Type nType, ScDocShell* pDocShell )
399 {
400  uno::Reference<uno::XInterface> xRet;
401 
402  switch (nType)
403  {
404  case Type::SHEET:
405  // not inserted yet - DocShell=Null
406  xRet.set(static_cast<sheet::XSpreadsheet*>(new ScTableSheetObj(nullptr,0)));
407  break;
408  case Type::URLFIELD:
409  case Type::PAGEFIELD:
410  case Type::PAGESFIELD:
411  case Type::DATEFIELD:
412  case Type::TIMEFIELD:
413  case Type::EXT_TIMEFIELD:
414  case Type::TITLEFIELD:
415  case Type::FILEFIELD:
416  case Type::SHEETFIELD:
417  {
418  uno::Reference<text::XTextRange> xNullContent;
419  xRet.set(static_cast<text::XTextField*>(
420  new ScEditFieldObj(xNullContent, nullptr, getFieldType(nType), ESelection())));
421  } break;
422  case Type::CELLSTYLE:
423  xRet.set(static_cast<style::XStyle*>(new ScStyleObj( nullptr, SfxStyleFamily::Para, OUString() )));
424  break;
425  case Type::PAGESTYLE:
426  xRet.set(static_cast<style::XStyle*>(new ScStyleObj( nullptr, SfxStyleFamily::Page, OUString() )));
427  break;
428  case Type::AUTOFORMAT:
429  xRet.set(static_cast<container::XIndexAccess*>(new ScAutoFormatObj( SC_AFMTOBJ_INVALID )));
430  break;
431  case Type::AUTOFORMATS:
432  xRet.set(static_cast<container::XIndexAccess*>(new ScAutoFormatsObj()));
433  break;
434  case Type::CELLRANGES:
435  // isn't inserted, rather filled
436  // -> DocShell must be set, but empty ranges
437  if (pDocShell)
438  xRet.set(static_cast<sheet::XSheetCellRanges*>(new ScCellRangesObj( pDocShell, ScRangeList() )));
439  break;
441  xRet.set(static_cast<sheet::XFunctionDescriptions*>(new ScFunctionListObj()));
442  break;
444  xRet.set(static_cast<sheet::XGlobalSheetSettings*>(new ScSpreadsheetSettings()));
445  break;
447  xRet.set(static_cast<sheet::XRecentFunctions*>(new ScRecentFunctionsObj()));
448  break;
449  case Type::DOCDEFLTS:
450  if (pDocShell)
451  xRet.set(static_cast<beans::XPropertySet*>(new ScDocDefaultsObj( pDocShell )));
452  break;
453  case Type::DRAWDEFLTS:
454  if (pDocShell)
455  xRet.set(static_cast<beans::XPropertySet*>(new ScDrawDefaultsObj( pDocShell )));
456  break;
457 
458  // Drawing layer tables are not in SvxUnoDrawMSFactory,
459  // because SvxUnoDrawMSFactory doesn't have a SdrModel pointer.
460  // Drawing layer is always allocated if not there (MakeDrawLayer).
461 
462  case Type::GRADTAB:
463  if (pDocShell)
464  xRet.set(SvxUnoGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
465  break;
466  case Type::HATCHTAB:
467  if (pDocShell)
468  xRet.set(SvxUnoHatchTable_createInstance( pDocShell->MakeDrawLayer() ));
469  break;
470  case Type::BITMAPTAB:
471  if (pDocShell)
472  xRet.set(SvxUnoBitmapTable_createInstance( pDocShell->MakeDrawLayer() ));
473  break;
474  case Type::TRGRADTAB:
475  if (pDocShell)
476  xRet.set(SvxUnoTransGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
477  break;
478  case Type::MARKERTAB:
479  if (pDocShell)
480  xRet.set(SvxUnoMarkerTable_createInstance( pDocShell->MakeDrawLayer() ));
481  break;
482  case Type::DASHTAB:
483  if (pDocShell)
484  xRet.set(SvxUnoDashTable_createInstance( pDocShell->MakeDrawLayer() ));
485  break;
486  case Type::NUMRULES:
487  if (pDocShell)
488  xRet.set(SvxCreateNumRule( pDocShell->MakeDrawLayer() ));
489  break;
490  case Type::DOCSPRSETT:
491  case Type::SHEETDOCSET:
492  case Type::DOCCONF:
493  if (pDocShell)
494  xRet.set(static_cast<beans::XPropertySet*>(new ScDocumentConfiguration(pDocShell)));
495  break;
496  case Type::IMAP_RECT:
498  break;
499  case Type::IMAP_CIRC:
501  break;
502  case Type::IMAP_POLY:
504  break;
505 
506  // Support creation of GraphicStorageHandler and EmbeddedObjectResolver
508  xRet.set(static_cast<cppu::OWeakObject *>(new SvXMLGraphicHelper( SvXMLGraphicHelperMode::Write )));
509  break;
511  xRet.set(static_cast<cppu::OWeakObject *>(new SvXMLGraphicHelper( SvXMLGraphicHelperMode::Read )));
512  break;
513  case Type::EXPORT_EOR:
514  if (pDocShell)
515  xRet.set(static_cast<cppu::OWeakObject *>(new SvXMLEmbeddedObjectHelper( *pDocShell, SvXMLEmbeddedObjectHelperMode::Write )));
516  break;
517  case Type::IMPORT_EOR:
518  if (pDocShell)
519  xRet.set(static_cast<cppu::OWeakObject *>(new SvXMLEmbeddedObjectHelper( *pDocShell, SvXMLEmbeddedObjectHelperMode::Read )));
520  break;
521  case Type::VALBIND:
522  case Type::LISTCELLBIND:
523  if (pDocShell)
524  {
525  bool bListPos = ( nType == Type::LISTCELLBIND );
526  uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
527  xRet.set(*new calc::OCellValueBinding( xDoc, bListPos ));
528  }
529  break;
530  case Type::LISTSOURCE:
531  if (pDocShell)
532  {
533  uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
534  xRet.set(*new calc::OCellListSource( xDoc ));
535  }
536  break;
537  case Type::CELLADDRESS:
538  case Type::RANGEADDRESS:
539  if (pDocShell)
540  {
541  bool bIsRange = ( nType == Type::RANGEADDRESS );
542  xRet.set(*new ScAddressConversionObj( pDocShell, bIsRange ));
543  }
544  break;
545  case Type::CHDATAPROV:
546  if (pDocShell)
547  xRet = *new ScChart2DataProvider( &pDocShell->GetDocument() );
548  break;
550  if (pDocShell)
551  xRet = *new sc::PivotTableDataProvider(pDocShell->GetDocument());
552  break;
553  case Type::FORMULAPARS:
554  if (pDocShell)
555  xRet.set(static_cast<sheet::XFormulaParser*>(new ScFormulaParserObj( pDocShell )));
556  break;
557  case Type::OPCODEMAPPER:
558  if (pDocShell)
559  {
560  ScDocument& rDoc = pDocShell->GetDocument();
561  ScAddress aAddress;
562  ScCompiler* pComp = new ScCompiler(rDoc, aAddress, rDoc.GetGrammar());
563  xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(new ScFormulaOpCodeMapperObj(::std::unique_ptr<formula::FormulaCompiler> (pComp))));
564  break;
565  }
566  break;
567 #if HAVE_FEATURE_SCRIPTING
569  if (pDocShell && pDocShell->GetDocument().IsInVBAMode())
570  {
571  xRet.set(static_cast<container::XNameAccess*>(new ScVbaObjectForCodeNameProvider( pDocShell )));
572  }
573  break;
575  if ( pDocShell && isInVBAMode( *pDocShell ) )
576  {
577  xRet.set(static_cast<document::XCodeNameQuery*>(new ScVbaCodeNameProvider(*pDocShell)));
578  }
579  break;
580  case Type::VBAGLOBALS:
581  if (pDocShell)
582  {
583  uno::Any aGlobs;
584  if ( !pDocShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aGlobs ) )
585  {
586  uno::Sequence< uno::Any > aArgs{ uno::Any(pDocShell->GetModel()) };
587  xRet = ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( "ooo.vba.excel.Globals", aArgs );
588  pDocShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", uno::Any( xRet ) );
589  BasicManager* pAppMgr = SfxApplication::GetBasicManager();
590  if ( pAppMgr )
591  pAppMgr->SetGlobalUNOConstant( "ThisExcelDoc", aArgs[ 0 ] );
592 
593  // create the VBA document event processor
594  uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents(
595  ::ooo::vba::createVBAUnoAPIServiceWithArgs( pDocShell, "com.sun.star.script.vba.VBASpreadsheetEventProcessor", aArgs ), uno::UNO_QUERY );
596  pDocShell->GetDocument().SetVbaEventProcessor( xVbaEvents );
597  }
598  }
599  break;
600 #endif
601  default:
602  break;
603  }
604 
605  return xRet;
606 }
607 
608 uno::Sequence<OUString> ScServiceProvider::GetAllServiceNames()
609 {
610  const sal_uInt16 nEntries = SAL_N_ELEMENTS(aProvNamesId);
611  uno::Sequence<OUString> aRet(nEntries);
612  OUString* pArray = aRet.getArray();
613  for (sal_uInt16 i = 0; i < nEntries; i++)
614  {
615  pArray[i] = aProvNamesId[i].pName;
616  }
617  return aRet;
618 }
619 
620 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type
bool hasValue()
constexpr OUStringLiteral SC_SERVICENAME_LISTCELLBIND
Definition: unonames.hxx:26
Reference< XInterface > SvUnoImageMapRectangleObject_createInstance(const SvEventDescription *pSupportedMacroItems)
sal_Int64 n
css::uno::Reference< css::frame::XModel3 > GetModel() const
Reference< XInterface > SvUnoImageMapCircleObject_createInstance(const SvEventDescription *pSupportedMacroItems)
SC_DLLPUBLIC formula::FormulaGrammar::Grammar GetGrammar() const
Definition: document.hxx:1007
constexpr OUStringLiteral SC_SERVICENAME_CELLADDRESS
Definition: unonames.hxx:28
SVXCORE_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoMarkerTable_createInstance(SdrModel *pModel)
css::uno::Reference< css::container::XIndexReplace > SvxCreateNumRule(SdrModel *pModel)
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:315
int nCount
css::uno::Reference< css::uno::XInterface > createVBAUnoAPIServiceWithArgs(SfxObjectShell const *pShell, const char *_pAsciiName, const css::uno::Sequence< css::uno::Any > &aArgs)
const char * sName
ScDrawLayer * MakeDrawLayer()
Definition: docsh2.cxx:172
SVXCORE_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoTransGradientTable_createInstance(SdrModel *pModel)
constexpr OUStringLiteral SC_SERVICENAME_OPCODEMAPPER
Definition: unonames.hxx:32
#define SAL_N_ELEMENTS(arr)
static css::uno::Reference< css::uno::XInterface > MakeInstance(Type nType, ScDocShell *pDocShell)
Definition: servuno.cxx:397
sal_Int32 getFieldType(guint nCol)
sal_uInt16 char * pName
Definition: callform.cxx:57
int i
void SetVbaEventProcessor(const css::uno::Reference< css::script::vba::XVBAEventProcessor > &rxVbaEvents)
Definition: document.hxx:2526
SVXCORE_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoGradientTable_createInstance(SdrModel *pModel)
constexpr OUStringLiteral SC_SERVICENAME_CHDATAPROV
Definition: unonames.hxx:34
unsigned char sal_Bool
css::uno::Reference< css::frame::XModel3 > GetBaseModel() const
uno::Reference< uno::XInterface > SvxUnoBitmapTable_createInstance(SdrModel *pModel)
tuple index
constexpr OUStringLiteral SC_SERVICENAME_RANGEADDRESS
Definition: unonames.hxx:29
constexpr OUStringLiteral CELLSTYLE
Definition: vbarange.cxx:678
static Type GetProviderType(std::u16string_view rServiceName)
Definition: servuno.cxx:373
constexpr OUStringLiteral SC_SERVICENAME_LISTSOURCE
Definition: unonames.hxx:27
SVXCORE_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoHatchTable_createInstance(SdrModel *pModel)
static BasicManager * GetBasicManager()
#define SC_AFMTOBJ_INVALID
Definition: afmtuno.hxx:39
uno::Reference< uno::XInterface > SvxUnoDashTable_createInstance(SdrModel *pModel)
bool IsInVBAMode() const
Definition: document.cxx:6593
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
const ScDocument & GetDocument() const
Definition: docsh.hxx:220
constexpr OUStringLiteral SC_SERVICENAME_VALBIND
Definition: unonames.hxx:25
constexpr OUStringLiteral SC_SERVICENAME_FORMULAPARS
Definition: unonames.hxx:31
Reference< XModel > xModel
const OUString & GetCodeName() const
Definition: document.hxx:607
const ProvNamesId_Type aProvNamesId[]
static css::uno::Sequence< OUString > GetAllServiceNames()
Definition: servuno.cxx:608
Reference< XInterface > SvUnoImageMapPolygonObject_createInstance(const SvEventDescription *pSupportedMacroItems)
static const SvEventDescription * GetSupportedMacroItems()
Definition: shapeuno.cxx:67
constexpr OUStringLiteral SC_SERVICENAME_CHART_PIVOTTABLE_DATAPROVIDER
Definition: unonames.hxx:36
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
Definition: document.cxx:215
BasicManager * GetBasicManager() const
sal_Int16 SCTAB
Definition: types.hxx:22
css::uno::Reference< css::script::XLibraryContainer > GetBasicContainer()