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
87class ScVbaObjectForCodeNameProvider :
public ::cppu::WeakImplHelper< container::XNameAccess >
93 explicit ScVbaObjectForCodeNameProvider(
ScDocShell* pDocShell ) : mpDocShell( pDocShell )
95 uno::Sequence< uno::Any > aArgs{
98 uno::Any(uno::Reference(
static_cast<css::sheet::XSpreadsheetDocument*
>(mpDocShell->
GetModel())))
103 virtual sal_Bool SAL_CALL hasByName(
const OUString& aName )
override
112 maCachedObject = maWorkbook;
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();
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; }
173class 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< container::XIndexAccess > xIndex( mrDocShell.
GetModel()->
getDrawPages(), uno::UNO_QUERY_THROW );
186 sal_Int32 nLen = xIndex->getCount();
187 bool bMatched =
false;
188 for ( sal_Int32 index = 0;
index < nLen; ++
index )
192 uno::Reference< form::XFormsSupplier > xFormSupplier( xIndex->getByIndex( index ), uno::UNO_QUERY_THROW );
193 uno::Reference< container::XIndexAccess > xFormIndex( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
195 uno::Reference< container::XIndexAccess > xFormControls( xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW );
196 sal_Int32 nCntrls = xFormControls->getCount();
197 for( sal_Int32 cIndex = 0; cIndex < nCntrls; ++cIndex )
199 uno::Reference< uno::XInterface > xControl( xFormControls->getByIndex( cIndex ), uno::UNO_QUERY_THROW );
200 bMatched = ( xControl == xIf );
209 catch( uno::Exception& ) {}
217 OUString SAL_CALL getCodeNameForContainer(
const uno::Reference<uno::XInterface>& xContainer )
override
220 uno::Reference<container::XIndexAccess> xIndex(mrDocShell.
GetModel()->
getDrawPages(), uno::UNO_QUERY_THROW);
222 for (sal_Int32 i = 0, n = xIndex->getCount(); i < n; ++i)
226 uno::Reference<form::XFormsSupplier> xFormSupplier(xIndex->getByIndex(i), uno::UNO_QUERY_THROW);
227 uno::Reference<container::XIndexAccess> xFormIndex(xFormSupplier->getForms(), uno::UNO_QUERY_THROW);
229 uno::Reference<container::XIndexAccess> xFormControls(xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW);
230 if (xFormControls == xContainer)
237 catch( uno::Exception& ) {}
247struct ProvNamesId_Type
256 {
"com.sun.star.text.TextField.URL", Type::URLFIELD },
257 {
"com.sun.star.text.TextField.PageNumber", Type::PAGEFIELD },
258 {
"com.sun.star.text.TextField.PageCount", Type::PAGESFIELD },
259 {
"com.sun.star.text.TextField.Date", Type::DATEFIELD },
260 {
"com.sun.star.text.TextField.Time", Type::TIMEFIELD },
261 {
"com.sun.star.text.TextField.DateTime", Type::EXT_TIMEFIELD },
262 {
"com.sun.star.text.TextField.DocInfo.Title", Type::TITLEFIELD },
263 {
"com.sun.star.text.TextField.FileName", Type::FILEFIELD },
264 {
"com.sun.star.text.TextField.SheetName", Type::SHEETFIELD },
266 {
"com.sun.star.style.PageStyle", Type::PAGESTYLE },
267 {
"com.sun.star.style.GraphicStyle", Type::GRAPHICSTYLE },
268 {
"com.sun.star.sheet.TableAutoFormat", Type::AUTOFORMAT },
269 {
"com.sun.star.sheet.TableAutoFormats", Type::AUTOFORMATS },
270 {
"com.sun.star.sheet.SheetCellRanges", Type::CELLRANGES },
271 {
"com.sun.star.sheet.FunctionDescriptions", Type::FUNCTIONDESCRIPTIONS },
272 {
"com.sun.star.sheet.GlobalSheetSettings", Type::GLOBALSHEETSETTINGS },
273 {
"com.sun.star.sheet.RecentFunctions", Type::RECENTFUNCTIONS },
274 {
"com.sun.star.drawing.GradientTable", Type::GRADTAB },
275 {
"com.sun.star.drawing.HatchTable", Type::HATCHTAB },
276 {
"com.sun.star.drawing.BitmapTable", Type::BITMAPTAB },
277 {
"com.sun.star.drawing.TransparencyGradientTable", Type::TRGRADTAB },
278 {
"com.sun.star.drawing.MarkerTable", Type::MARKERTAB },
279 {
"com.sun.star.drawing.DashTable", Type::DASHTAB },
280 {
"com.sun.star.text.NumberingRules", Type::NUMRULES },
281 {
"com.sun.star.sheet.Defaults", Type::DOCDEFLTS },
282 {
"com.sun.star.drawing.Defaults", Type::DRAWDEFLTS },
283 {
"com.sun.star.comp.SpreadsheetSettings", Type::DOCSPRSETT },
284 {
"com.sun.star.document.Settings", Type::DOCCONF },
285 {
"com.sun.star.image.ImageMapRectangleObject", Type::IMAP_RECT },
286 {
"com.sun.star.image.ImageMapCircleObject", Type::IMAP_CIRC },
287 {
"com.sun.star.image.ImageMapPolygonObject", Type::IMAP_POLY },
290 {
"com.sun.star.document.ExportGraphicStorageHandler", Type::EXPORT_GRAPHIC_STORAGE_HANDLER },
291 {
"com.sun.star.document.ImportGraphicStorageHandler", Type::IMPORT_GRAPHIC_STORAGE_HANDLER },
292 {
"com.sun.star.document.ExportEmbeddedObjectResolver", Type::EXPORT_EOR },
293 {
"com.sun.star.document.ImportEmbeddedObjectResolver", Type::IMPORT_EOR },
301 {
"com.sun.star.sheet.DocumentSettings",Type::SHEETDOCSET },
307 {
"ooo.vba.VBAObjectModuleObjectProvider", Type::VBAOBJECTPROVIDER },
308 {
"ooo.vba.VBACodeNameProvider", Type::VBACODENAMEPROVIDER },
309 {
"ooo.vba.VBAGlobals", Type::VBAGLOBALS },
312 {
"com.sun.star.text.textfield.URL", Type::URLFIELD },
313 {
"com.sun.star.text.textfield.PageNumber", Type::PAGEFIELD },
314 {
"com.sun.star.text.textfield.PageCount", Type::PAGESFIELD },
315 {
"com.sun.star.text.textfield.Date", Type::DATEFIELD },
316 {
"com.sun.star.text.textfield.Time", Type::TIMEFIELD },
317 {
"com.sun.star.text.textfield.DateTime", Type::EXT_TIMEFIELD },
318 {
"com.sun.star.text.textfield.docinfo.Title", Type::TITLEFIELD },
319 {
"com.sun.star.text.textfield.FileName", Type::FILEFIELD },
320 {
"com.sun.star.text.textfield.SheetName", Type::SHEETFIELD },
321 {
"ooo.vba.VBAGlobals", Type::VBAGLOBALS },
326const ProvNamesId_Type aOldNames[] =
328 {
"stardiv.one.text.TextField.URL", Type::URLFIELD },
329 {
"stardiv.one.text.TextField.PageNumber", Type::PAGEFIELD },
330 {
"stardiv.one.text.TextField.PageCount", Type::PAGESFIELD },
331 {
"stardiv.one.text.TextField.Date", Type::DATEFIELD },
332 {
"stardiv.one.text.TextField.Time", Type::TIMEFIELD },
333 {
"stardiv.one.text.TextField.DocumentTitle", Type::TITLEFIELD },
334 {
"stardiv.one.text.TextField.FileName", Type::FILEFIELD },
335 {
"stardiv.one.text.TextField.SheetName", Type::SHEETFIELD },
337 {
"stardiv.one.style.PageStyle", Type::PAGESTYLE },
345 return text::textfield::Type::URL;
346 case Type::PAGEFIELD:
347 return text::textfield::Type::PAGE;
348 case Type::PAGESFIELD:
349 return text::textfield::Type::PAGES;
350 case Type::DATEFIELD:
352 case Type::TIMEFIELD:
353 return text::textfield::Type::TIME;
354 case Type::EXT_TIMEFIELD:
355 return text::textfield::Type::EXTENDED_TIME;
356 case Type::TITLEFIELD:
357 return text::textfield::Type::DOCINFO_TITLE;
358 case Type::FILEFIELD:
359 return text::textfield::Type::EXTENDED_FILE;
360 case Type::SHEETFIELD:
366 return text::textfield::Type::URL;
374 if (!rServiceName.empty())
378 if (rServiceName ==
i.pName)
384 for (
const ProvNamesId_Type & rOldName : aOldNames)
386 if (rServiceName == rOldName.pName)
388 OSL_FAIL(
"old service name used");
389 return rOldName.nType;
399 uno::Reference<uno::XInterface> xRet;
405 xRet.set(
static_cast<sheet::XSpreadsheet*
>(
new ScTableSheetObj(
nullptr,0)));
417 uno::Reference<text::XTextRange> xNullContent;
418 xRet.set(
static_cast<text::XTextField*
>(
422 xRet.set(
static_cast<style::XStyle*
>(
new ScStyleObj(
nullptr, SfxStyleFamily::Para, OUString() )));
425 xRet.set(
static_cast<style::XStyle*
>(
new ScStyleObj(
nullptr, SfxStyleFamily::Page, OUString() )));
431 xRet.set(
static_cast<style::XStyle*
>(
new ScStyleObj(
nullptr, SfxStyleFamily::Frame, OUString() )));
444 xRet.set(
static_cast<sheet::XSheetCellRanges*
>(
new ScCellRangesObj( pDocShell,
ScRangeList() )));
457 xRet.set(
static_cast<beans::XPropertySet*
>(
new ScDocDefaultsObj( pDocShell )));
532 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->
GetBaseModel(), uno::UNO_QUERY );
539 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->
GetBaseModel(), uno::UNO_QUERY );
569 xRet.set(
static_cast<sheet::XFormulaOpCodeMapper*
>(
new ScFormulaOpCodeMapperObj(::std::unique_ptr<formula::FormulaCompiler> (pComp))));
573#if HAVE_FEATURE_SCRIPTING
577 xRet.set(
static_cast<container::XNameAccess*
>(
new ScVbaObjectForCodeNameProvider( pDocShell )));
581 if ( pDocShell && isInVBAMode( *pDocShell ) )
583 xRet.set(
static_cast<document::XCodeNameQuery*
>(
new ScVbaCodeNameProvider(*pDocShell)));
592 uno::Sequence< uno::Any > aArgs{
uno::Any(uno::Reference(
static_cast<css::sheet::XSpreadsheetDocument*
>(pDocShell->
GetModel()))) };
593 xRet = ::comphelper::getProcessServiceFactory()->createInstanceWithArguments(
"ooo.vba.excel.Globals", aArgs );
600 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents(
601 ::ooo::vba::createVBAUnoAPIServiceWithArgs( pDocShell,
"com.sun.star.script.vba.VBASpreadsheetEventProcessor", aArgs ), uno::UNO_QUERY );
617 uno::Sequence<OUString> aRet(nEntries);
618 OUString* pArray = aRet.getArray();
619 for (sal_uInt16
i = 0;
i < nEntries;
i++)
#define SC_AFMTOBJ_INVALID
void SetGlobalUNOConstant(const OUString &rName, const css::uno::Any &_rValue, css::uno::Any *pOldValue=nullptr)
bool GetGlobalUNOConstant(const OUString &rName, css::uno::Any &aOut)
const ScDocument & GetDocument() const
ScDrawLayer * MakeDrawLayer()
ScModelObj * GetModel() const
void SetVbaEventProcessor(const css::uno::Reference< css::script::vba::XVBAEventProcessor > &rxVbaEvents)
SC_DLLPUBLIC formula::FormulaGrammar::Grammar GetGrammar() const
const OUString & GetCodeName() const
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
SC_DLLPUBLIC SCTAB GetTableCount() const
virtual css::uno::Reference< css::drawing::XDrawPages > SAL_CALL getDrawPages() override
XDrawPagesSupplier.
static css::uno::Sequence< OUString > GetAllServiceNames()
static css::uno::Reference< css::uno::XInterface > MakeInstance(Type nType, ScDocShell *pDocShell)
static Type GetProviderType(std::u16string_view rServiceName)
@ CHART_PIVOTTABLE_DATAPROVIDER
@ IMPORT_GRAPHIC_STORAGE_HANDLER
@ EXPORT_GRAPHIC_STORAGE_HANDLER
static const SvEventDescription * GetSupportedMacroItems()
static BasicManager * GetBasicManager()
css::uno::Reference< css::script::XLibraryContainer > GetBasicContainer()
BasicManager * GetBasicManager() const
css::uno::Reference< css::frame::XModel3 > GetBaseModel() const
#define SAL_N_ELEMENTS(arr)
sal_Int32 getFieldType(guint nCol)
css::uno::Reference< css::uno::XInterface > createVBAUnoAPIServiceWithArgs(SfxObjectShell const *pShell, const char *_pAsciiName, const css::uno::Sequence< css::uno::Any > &aArgs)
Reference< XModel > xModel
const ProvNamesId_Type aProvNamesId[]
SVXCORE_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoDashTable_createInstance(SdrModel *pModel)
SVXCORE_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoGradientTable_createInstance(SdrModel *pModel)
SVXCORE_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoBitmapTable_createInstance(SdrModel *pModel)
SVXCORE_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoMarkerTable_createInstance(SdrModel *pModel)
SVXCORE_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoHatchTable_createInstance(SdrModel *pModel)
SVXCORE_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoTransGradientTable_createInstance(SdrModel *pModel)
SVT_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvUnoImageMapCircleObject_createInstance(const SvEventDescription *pSupportedMacroItems)
SVT_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvUnoImageMapPolygonObject_createInstance(const SvEventDescription *pSupportedMacroItems)
SVT_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvUnoImageMapRectangleObject_createInstance(const SvEventDescription *pSupportedMacroItems)
SVXCORE_DLLPUBLIC css::uno::Reference< css::container::XIndexReplace > SvxCreateNumRule(SdrModel *pModel)
constexpr OUStringLiteral SC_SERVICENAME_LISTCELLBIND
constexpr OUStringLiteral SC_SERVICENAME_CHDATAPROV
constexpr OUStringLiteral SC_SERVICENAME_RANGEADDRESS
constexpr OUStringLiteral SC_SERVICENAME_FORMULAPARS
constexpr OUStringLiteral SC_SERVICENAME_OPCODEMAPPER
constexpr OUStringLiteral SC_SERVICENAME_CELLADDRESS
constexpr OUStringLiteral SC_SERVICENAME_VALBIND
constexpr OUStringLiteral SC_SERVICENAME_LISTSOURCE
constexpr OUStringLiteral SC_SERVICENAME_CHART_PIVOTTABLE_DATAPROVIDER
constexpr OUStringLiteral CELLSTYLE