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