21 #include <config_features.h>
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>
33 #include <unonames.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>
67 #include <com/sun/star/script/vba/XVBACompatibility.hpp>
71 #if HAVE_FEATURE_SCRIPTING
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();
86 #if HAVE_FEATURE_SCRIPTING
87 class ScVbaObjectForCodeNameProvider :
public ::cppu::WeakImplHelper< container::XNameAccess >
93 explicit ScVbaObjectForCodeNameProvider(
ScDocShell* pDocShell ) : mpDocShell( pDocShell )
95 uno::Sequence< uno::Any > aArgs{
103 virtual sal_Bool SAL_CALL hasByName(
const OUString& aName )
override
111 if( aName.equalsIgnoreAsciiCase( rDoc.
GetCodeName() ) )
112 maCachedObject = maWorkbook;
117 for(
SCTAB i = 0;
i < nCount;
i++ )
122 if( sCodeName.equalsIgnoreAsciiCase( aName ) )
125 if( rDoc.
GetName( i, sSheetName ) )
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) };
143 css::uno::Any SAL_CALL getByName(
const OUString& aName )
override
146 if ( !hasByName( aName ) )
147 throw css::container::NoSuchElementException();
148 return maCachedObject;
150 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( )
override
155 uno::Sequence< OUString > aNames( nCount + 1 );
156 auto pNames = aNames.getArray();
159 for( ; index < nCount; ++index )
162 pNames[ index ] = sCodeName;
168 virtual css::uno::Type SAL_CALL getElementType( )
override {
return uno::Type(); }
169 virtual sal_Bool SAL_CALL hasElements( )
override {
return true; }
173 class ScVbaCodeNameProvider :
public ::cppu::WeakImplHelper< document::XCodeNameQuery >
177 explicit ScVbaCodeNameProvider(
ScDocShell& rDocShell ) : mrDocShell(rDocShell) {}
179 OUString SAL_CALL getCodeNameForObject(
const uno::Reference< uno::XInterface >& xIf )
override
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 )
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 );
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 )
200 uno::Reference< uno::XInterface > xControl( xFormControls->getByIndex( cIndex ), uno::UNO_QUERY_THROW );
201 bMatched = ( xControl == xIf );
210 catch( uno::Exception& ) {}
218 OUString SAL_CALL getCodeNameForContainer(
const uno::Reference<uno::XInterface>& xContainer )
override
221 uno::Reference<drawing::XDrawPagesSupplier> xSupplier(mrDocShell.
GetModel(), uno::UNO_QUERY_THROW);
222 uno::Reference<container::XIndexAccess> xIndex(xSupplier->getDrawPages(), uno::UNO_QUERY_THROW);
224 for (sal_Int32 i = 0, n = xIndex->getCount();
i <
n; ++
i)
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);
231 uno::Reference<container::XIndexAccess> xFormControls(xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW);
232 if (xFormControls == xContainer)
239 catch( uno::Exception& ) {}
249 struct ProvNamesId_Type
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 },
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 },
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 },
302 {
"com.sun.star.sheet.DocumentSettings",Type::SHEETDOCSET },
308 {
"ooo.vba.VBAObjectModuleObjectProvider", Type::VBAOBJECTPROVIDER },
309 {
"ooo.vba.VBACodeNameProvider", Type::VBACODENAMEPROVIDER },
310 {
"ooo.vba.VBAGlobals", Type::VBAGLOBALS },
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 },
327 const ProvNamesId_Type aOldNames[] =
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 },
338 {
"stardiv.one.style.PageStyle", Type::PAGESTYLE },
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:
367 return text::textfield::Type::URL;
375 if (!rServiceName.empty())
377 for (
const ProvNamesId_Type &
i : aProvNamesId)
379 if (rServiceName ==
i.pName)
385 for (
const ProvNamesId_Type & rOldName : aOldNames)
387 if (rServiceName == rOldName.pName)
389 OSL_FAIL(
"old service name used");
390 return rOldName.nType;
400 uno::Reference<uno::XInterface> xRet;
406 xRet.set(static_cast<sheet::XSpreadsheet*>(
new ScTableSheetObj(
nullptr,0)));
418 uno::Reference<text::XTextRange> xNullContent;
419 xRet.set(static_cast<text::XTextField*>(
423 xRet.set(static_cast<style::XStyle*>(
new ScStyleObj(
nullptr, SfxStyleFamily::Para, OUString() )));
426 xRet.set(static_cast<style::XStyle*>(
new ScStyleObj(
nullptr, SfxStyleFamily::Page, OUString() )));
438 xRet.set(static_cast<sheet::XSheetCellRanges*>(
new ScCellRangesObj( pDocShell,
ScRangeList() )));
451 xRet.set(static_cast<beans::XPropertySet*>(
new ScDocDefaultsObj( pDocShell )));
508 xRet.set(static_cast<cppu::OWeakObject *>(
new SvXMLGraphicHelper( SvXMLGraphicHelperMode::Write )));
511 xRet.set(static_cast<cppu::OWeakObject *>(
new SvXMLGraphicHelper( SvXMLGraphicHelperMode::Read )));
515 xRet.set(static_cast<cppu::OWeakObject *>(
new SvXMLEmbeddedObjectHelper( *pDocShell, SvXMLEmbeddedObjectHelperMode::Write )));
519 xRet.set(static_cast<cppu::OWeakObject *>(
new SvXMLEmbeddedObjectHelper( *pDocShell, SvXMLEmbeddedObjectHelperMode::Read )));
526 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->
GetBaseModel(), uno::UNO_QUERY );
533 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->
GetBaseModel(), uno::UNO_QUERY );
563 xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(
new ScFormulaOpCodeMapperObj(::std::unique_ptr<formula::FormulaCompiler> (pComp))));
567 #if HAVE_FEATURE_SCRIPTING
571 xRet.set(static_cast<container::XNameAccess*>(
new ScVbaObjectForCodeNameProvider( pDocShell )));
575 if ( pDocShell && isInVBAMode( *pDocShell ) )
577 xRet.set(static_cast<document::XCodeNameQuery*>(
new ScVbaCodeNameProvider(*pDocShell)));
584 if ( !pDocShell->
GetBasicManager()->GetGlobalUNOConstant(
"VBAGlobals", aGlobs ) )
587 xRet = ::comphelper::getProcessServiceFactory()->createInstanceWithArguments(
"ooo.vba.excel.Globals", aArgs );
591 pAppMgr->SetGlobalUNOConstant(
"ThisExcelDoc", aArgs[ 0 ] );
594 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents(
611 uno::Sequence<OUString> aRet(nEntries);
612 OUString* pArray = aRet.getArray();
613 for (sal_uInt16
i = 0;
i < nEntries;
i++)
615 pArray[
i] = aProvNamesId[
i].pName;
constexpr OUStringLiteral SC_SERVICENAME_LISTCELLBIND
Reference< XInterface > SvUnoImageMapRectangleObject_createInstance(const SvEventDescription *pSupportedMacroItems)
css::uno::Reference< css::frame::XModel3 > GetModel() const
Reference< XInterface > SvUnoImageMapCircleObject_createInstance(const SvEventDescription *pSupportedMacroItems)
SC_DLLPUBLIC formula::FormulaGrammar::Grammar GetGrammar() const
constexpr OUStringLiteral SC_SERVICENAME_CELLADDRESS
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
css::uno::Reference< css::uno::XInterface > createVBAUnoAPIServiceWithArgs(SfxObjectShell const *pShell, const char *_pAsciiName, const css::uno::Sequence< css::uno::Any > &aArgs)
ScDrawLayer * MakeDrawLayer()
SVXCORE_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoTransGradientTable_createInstance(SdrModel *pModel)
constexpr OUStringLiteral SC_SERVICENAME_OPCODEMAPPER
#define SAL_N_ELEMENTS(arr)
static css::uno::Reference< css::uno::XInterface > MakeInstance(Type nType, ScDocShell *pDocShell)
sal_Int32 getFieldType(guint nCol)
void SetVbaEventProcessor(const css::uno::Reference< css::script::vba::XVBAEventProcessor > &rxVbaEvents)
SVXCORE_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoGradientTable_createInstance(SdrModel *pModel)
constexpr OUStringLiteral SC_SERVICENAME_CHDATAPROV
css::uno::Reference< css::frame::XModel3 > GetBaseModel() const
uno::Reference< uno::XInterface > SvxUnoBitmapTable_createInstance(SdrModel *pModel)
constexpr OUStringLiteral SC_SERVICENAME_RANGEADDRESS
constexpr OUStringLiteral CELLSTYLE
static Type GetProviderType(std::u16string_view rServiceName)
constexpr OUStringLiteral SC_SERVICENAME_LISTSOURCE
SVXCORE_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoHatchTable_createInstance(SdrModel *pModel)
static BasicManager * GetBasicManager()
#define SC_AFMTOBJ_INVALID
uno::Reference< uno::XInterface > SvxUnoDashTable_createInstance(SdrModel *pModel)
const ScDocument & GetDocument() const
constexpr OUStringLiteral SC_SERVICENAME_VALBIND
constexpr OUStringLiteral SC_SERVICENAME_FORMULAPARS
Reference< XModel > xModel
const OUString & GetCodeName() const
const ProvNamesId_Type aProvNamesId[]
static css::uno::Sequence< OUString > GetAllServiceNames()
Reference< XInterface > SvUnoImageMapPolygonObject_createInstance(const SvEventDescription *pSupportedMacroItems)
static const SvEventDescription * GetSupportedMacroItems()
constexpr OUStringLiteral SC_SERVICENAME_CHART_PIVOTTABLE_DATAPROVIDER
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
BasicManager * GetBasicManager() const
css::uno::Reference< css::script::XLibraryContainer > GetBasicContainer()