Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / unoobj / servuno.cxx
blob0347209f7e52944eee9fdc1f3b581a447fe18b1f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <sal/macros.h>
22 #include <svtools/unoimap.hxx>
23 #include <svx/unofill.hxx>
24 #include <editeng/unonrule.hxx>
25 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
26 #include <com/sun/star/container/XNameAccess.hpp>
27 #include <com/sun/star/text/textfield/Type.hpp>
29 #include "servuno.hxx"
30 #include "unonames.hxx"
31 #include "cellsuno.hxx"
32 #include "fielduno.hxx"
33 #include "styleuno.hxx"
34 #include "afmtuno.hxx"
35 #include "defltuno.hxx"
36 #include "drdefuno.hxx"
37 #include "docsh.hxx"
38 #include "drwlayer.hxx"
39 #include "confuno.hxx"
40 #include "shapeuno.hxx"
41 #include "cellvaluebinding.hxx"
42 #include "celllistsource.hxx"
43 #include "addruno.hxx"
44 #include "chart2uno.hxx"
45 #include "tokenuno.hxx"
47 // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
48 #include <svx/xmleohlp.hxx>
49 #include <svx/xmlgrhlp.hxx>
50 #include <sfx2/docfile.hxx>
51 #include <sfx2/docfilt.hxx>
52 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
53 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
54 #include <com/sun/star/document/XCodeNameQuery.hpp>
55 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
56 #include <com/sun/star/form/XFormsSupplier.hpp>
57 #include <svx/unomod.hxx>
58 #include <vbahelper/vbaaccesshelper.hxx>
60 #include <comphelper/processfactory.hxx>
61 #include <basic/basmgr.hxx>
62 #include <sfx2/app.hxx>
64 #include <cppuhelper/component_context.hxx>
65 #include <com/sun/star/script/vba/XVBACompatibility.hpp>
67 using namespace ::com::sun::star;
69 bool isInVBAMode( ScDocShell& rDocSh )
71 uno::Reference<script::XLibraryContainer> xLibContainer = rDocSh.GetBasicContainer();
72 uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY );
73 if ( xVBACompat.is() )
74 return xVBACompat->getVBACompatibilityMode();
75 return false;
78 class ScVbaObjectForCodeNameProvider : public ::cppu::WeakImplHelper1< container::XNameAccess >
80 uno::Any maWorkbook;
81 uno::Any maCachedObject;
82 ScDocShell* mpDocShell;
83 public:
84 ScVbaObjectForCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell )
86 ScDocument* pDoc = mpDocShell->GetDocument();
87 if ( !pDoc )
88 throw uno::RuntimeException("", uno::Reference< uno::XInterface >() );
90 uno::Sequence< uno::Any > aArgs(2);
91 // access the application object ( parent for workbook )
92 aArgs[0] = uno::Any( ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.Application", uno::Sequence< uno::Any >() ) );
93 aArgs[1] = uno::Any( mpDocShell->GetModel() );
94 maWorkbook <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Workbook", aArgs );
97 virtual ::sal_Bool SAL_CALL hasByName( const OUString& aName ) throw (::com::sun::star::uno::RuntimeException )
99 SolarMutexGuard aGuard;
100 maCachedObject = uno::Any(); // clear cached object
102 ScDocument* pDoc = mpDocShell->GetDocument();
103 if ( !pDoc )
104 throw uno::RuntimeException();
105 // aName is generated from the stream name which can be different ( case-wise )
106 // from the code name
107 if( aName.equalsIgnoreAsciiCase( pDoc->GetCodeName() ) )
108 maCachedObject = maWorkbook;
109 else
111 OUString sCodeName;
112 SCTAB nCount = pDoc->GetTableCount();
113 for( SCTAB i = 0; i < nCount; i++ )
115 pDoc->GetCodeName( i, sCodeName );
116 // aName is generated from the stream name which can be different ( case-wise )
117 // from the code name
118 if( sCodeName.equalsIgnoreAsciiCase( aName ) )
120 OUString sSheetName;
121 if( pDoc->GetName( i, sSheetName ) )
123 uno::Reference< frame::XModel > xModel( mpDocShell->GetModel() );
124 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
125 uno::Reference<sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
126 uno::Reference< container::XIndexAccess > xIndexAccess( xSheets, uno::UNO_QUERY_THROW );
127 uno::Reference< sheet::XSpreadsheet > xSheet( xIndexAccess->getByIndex( i ), uno::UNO_QUERY_THROW );
128 uno::Sequence< uno::Any > aArgs(3);
129 aArgs[0] = maWorkbook;
130 aArgs[1] = uno::Any( xModel );
131 aArgs[2] = uno::Any( OUString( sSheetName ) );
132 // use the convience function
133 maCachedObject <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Worksheet", aArgs );
134 break;
139 return maCachedObject.hasValue();
142 ::com::sun::star::uno::Any SAL_CALL getByName( const OUString& aName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
144 SolarMutexGuard aGuard;
145 OSL_TRACE("ScVbaObjectForCodeNameProvider::getByName( %s )",
146 OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr() );
147 if ( !hasByName( aName ) )
148 throw ::com::sun::star::container::NoSuchElementException();
149 return maCachedObject;
151 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames( ) throw (::com::sun::star::uno::RuntimeException)
153 SolarMutexGuard aGuard;
154 ScDocument* pDoc = mpDocShell->GetDocument();
155 if ( !pDoc )
156 throw uno::RuntimeException();
157 SCTAB nCount = pDoc->GetTableCount();
158 uno::Sequence< OUString > aNames( nCount + 1 );
159 SCTAB index = 0;
160 OUString sCodeName;
161 for( ; index < nCount; ++index )
163 pDoc->GetCodeName( index, sCodeName );
164 aNames[ index ] = sCodeName;
166 aNames[ index ] = pDoc->GetCodeName();
167 return aNames;
169 // XElemenAccess
170 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException){ return uno::Type(); }
171 virtual ::sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException ) { return sal_True; }
175 class ScVbaCodeNameProvider : public ::cppu::WeakImplHelper1< document::XCodeNameQuery >
177 ScDocShell& mrDocShell;
178 public:
179 ScVbaCodeNameProvider( ScDocShell& rDocShell ) : mrDocShell(rDocShell) {}
180 // XCodeNameQuery
181 OUString SAL_CALL getCodeNameForObject( const uno::Reference< uno::XInterface >& xIf ) throw( uno::RuntimeException )
183 SolarMutexGuard aGuard;
184 OUString sCodeName;
186 // need to find the page ( and index ) for this control
187 uno::Reference< drawing::XDrawPagesSupplier > xSupplier( mrDocShell.GetModel(), uno::UNO_QUERY_THROW );
188 uno::Reference< container::XIndexAccess > xIndex( xSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
189 sal_Int32 nLen = xIndex->getCount();
190 bool bMatched = false;
191 for ( sal_Int32 index = 0; index < nLen; ++index )
195 uno::Reference< form::XFormsSupplier > xFormSupplier( xIndex->getByIndex( index ), uno::UNO_QUERY_THROW );
196 uno::Reference< container::XIndexAccess > xFormIndex( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
197 // get the www-standard container
198 uno::Reference< container::XIndexAccess > xFormControls( xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW );
199 sal_Int32 nCntrls = xFormControls->getCount();
200 for( sal_Int32 cIndex = 0; cIndex < nCntrls; ++cIndex )
202 uno::Reference< uno::XInterface > xControl( xFormControls->getByIndex( cIndex ), uno::UNO_QUERY_THROW );
203 bMatched = ( xControl == xIf );
204 if ( bMatched )
206 OUString sName;
207 mrDocShell.GetDocument()->GetCodeName( static_cast<SCTAB>( index ), sName );
208 sCodeName = sName;
212 catch( uno::Exception& ) {}
213 if ( bMatched )
214 break;
216 // Probably should throw here ( if !bMatched )
217 return sCodeName;
220 OUString SAL_CALL getCodeNameForContainer( const uno::Reference<uno::XInterface>& xContainer )
221 throw( uno::RuntimeException )
223 SolarMutexGuard aGuard;
224 uno::Reference<drawing::XDrawPagesSupplier> xSupplier(mrDocShell.GetModel(), uno::UNO_QUERY_THROW);
225 uno::Reference<container::XIndexAccess> xIndex(xSupplier->getDrawPages(), uno::UNO_QUERY_THROW);
227 for (sal_Int32 i = 0, n = xIndex->getCount(); i < n; ++i)
231 uno::Reference<form::XFormsSupplier> xFormSupplier(xIndex->getByIndex(i), uno::UNO_QUERY_THROW);
232 uno::Reference<container::XIndexAccess> xFormIndex(xFormSupplier->getForms(), uno::UNO_QUERY_THROW);
233 // get the www-standard container
234 uno::Reference<container::XIndexAccess> xFormControls(xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW);
235 if (xFormControls == xContainer)
237 OUString aName;
238 if (mrDocShell.GetDocument()->GetCodeName(static_cast<SCTAB>(i), aName))
239 return aName;
242 catch( uno::Exception& ) {}
244 return OUString();
248 //------------------------------------------------------------------------
250 struct ProvNamesId_Type
252 const char * pName;
253 sal_uInt16 nType;
256 static const ProvNamesId_Type aProvNamesId[] =
258 { "com.sun.star.sheet.Spreadsheet", SC_SERVICE_SHEET },
259 { "com.sun.star.text.TextField.URL", SC_SERVICE_URLFIELD },
260 { "com.sun.star.text.TextField.PageNumber", SC_SERVICE_PAGEFIELD },
261 { "com.sun.star.text.TextField.PageCount", SC_SERVICE_PAGESFIELD },
262 { "com.sun.star.text.TextField.Date", SC_SERVICE_DATEFIELD },
263 { "com.sun.star.text.TextField.Time", SC_SERVICE_TIMEFIELD },
264 { "com.sun.star.text.TextField.DateTime", SC_SERVICE_EXT_TIMEFIELD },
265 { "com.sun.star.text.TextField.DocInfo.Title", SC_SERVICE_TITLEFIELD },
266 { "com.sun.star.text.TextField.FileName", SC_SERVICE_FILEFIELD },
267 { "com.sun.star.text.TextField.SheetName", SC_SERVICE_SHEETFIELD },
268 { "com.sun.star.style.CellStyle", SC_SERVICE_CELLSTYLE },
269 { "com.sun.star.style.PageStyle", SC_SERVICE_PAGESTYLE },
270 { "com.sun.star.sheet.TableAutoFormat", SC_SERVICE_AUTOFORMAT },
271 { "com.sun.star.sheet.SheetCellRanges", SC_SERVICE_CELLRANGES },
272 { "com.sun.star.drawing.GradientTable", SC_SERVICE_GRADTAB },
273 { "com.sun.star.drawing.HatchTable", SC_SERVICE_HATCHTAB },
274 { "com.sun.star.drawing.BitmapTable", SC_SERVICE_BITMAPTAB },
275 { "com.sun.star.drawing.TransparencyGradientTable", SC_SERVICE_TRGRADTAB },
276 { "com.sun.star.drawing.MarkerTable", SC_SERVICE_MARKERTAB },
277 { "com.sun.star.drawing.DashTable", SC_SERVICE_DASHTAB },
278 { "com.sun.star.text.NumberingRules", SC_SERVICE_NUMRULES },
279 { "com.sun.star.sheet.Defaults", SC_SERVICE_DOCDEFLTS },
280 { "com.sun.star.drawing.Defaults", SC_SERVICE_DRAWDEFLTS },
281 { "com.sun.star.comp.SpreadsheetSettings", SC_SERVICE_DOCSPRSETT },
282 { "com.sun.star.document.Settings", SC_SERVICE_DOCCONF },
283 { "com.sun.star.image.ImageMapRectangleObject", SC_SERVICE_IMAP_RECT },
284 { "com.sun.star.image.ImageMapCircleObject", SC_SERVICE_IMAP_CIRC },
285 { "com.sun.star.image.ImageMapPolygonObject", SC_SERVICE_IMAP_POLY },
287 // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
288 { "com.sun.star.document.ExportGraphicObjectResolver", SC_SERVICE_EXPORT_GOR },
289 { "com.sun.star.document.ImportGraphicObjectResolver", SC_SERVICE_IMPORT_GOR },
290 { "com.sun.star.document.ExportEmbeddedObjectResolver", SC_SERVICE_EXPORT_EOR },
291 { "com.sun.star.document.ImportEmbeddedObjectResolver", SC_SERVICE_IMPORT_EOR },
293 { SC_SERVICENAME_VALBIND, SC_SERVICE_VALBIND },
294 { SC_SERVICENAME_LISTCELLBIND, SC_SERVICE_LISTCELLBIND },
295 { SC_SERVICENAME_LISTSOURCE, SC_SERVICE_LISTSOURCE },
296 { SC_SERVICENAME_CELLADDRESS, SC_SERVICE_CELLADDRESS },
297 { SC_SERVICENAME_RANGEADDRESS, SC_SERVICE_RANGEADDRESS },
299 { "com.sun.star.sheet.DocumentSettings",SC_SERVICE_SHEETDOCSET },
301 { SC_SERVICENAME_CHDATAPROV, SC_SERVICE_CHDATAPROV },
302 { SC_SERVICENAME_FORMULAPARS, SC_SERVICE_FORMULAPARS },
303 { SC_SERVICENAME_OPCODEMAPPER, SC_SERVICE_OPCODEMAPPER },
304 { "ooo.vba.VBAObjectModuleObjectProvider", SC_SERVICE_VBAOBJECTPROVIDER },
305 { "ooo.vba.VBACodeNameProvider", SC_SERVICE_VBACODENAMEPROVIDER },
306 { "ooo.vba.VBAGlobals", SC_SERVICE_VBAGLOBALS },
308 // case-correct versions of the service names (#i102468#)
309 { "com.sun.star.text.textfield.URL", SC_SERVICE_URLFIELD },
310 { "com.sun.star.text.textfield.PageNumber", SC_SERVICE_PAGEFIELD },
311 { "com.sun.star.text.textfield.PageCount", SC_SERVICE_PAGESFIELD },
312 { "com.sun.star.text.textfield.Date", SC_SERVICE_DATEFIELD },
313 { "com.sun.star.text.textfield.Time", SC_SERVICE_TIMEFIELD },
314 { "com.sun.star.text.textfield.DateTime", SC_SERVICE_EXT_TIMEFIELD },
315 { "com.sun.star.text.textfield.docinfo.Title", SC_SERVICE_TITLEFIELD },
316 { "com.sun.star.text.textfield.FileName", SC_SERVICE_FILEFIELD },
317 { "com.sun.star.text.textfield.SheetName", SC_SERVICE_SHEETFIELD },
318 { "ooo.vba.VBAGlobals", SC_SERVICE_VBAGLOBALS },
322 // old service names that were in 567 still work in createInstance,
323 // in case some macro is still using them
326 static const sal_Char* aOldNames[SC_SERVICE_COUNT] =
328 "", // SC_SERVICE_SHEET
329 "stardiv.one.text.TextField.URL", // SC_SERVICE_URLFIELD
330 "stardiv.one.text.TextField.PageNumber", // SC_SERVICE_PAGEFIELD
331 "stardiv.one.text.TextField.PageCount", // SC_SERVICE_PAGESFIELD
332 "stardiv.one.text.TextField.Date", // SC_SERVICE_DATEFIELD
333 "stardiv.one.text.TextField.Time", // SC_SERVICE_TIMEFIELD
334 "stardiv.one.text.TextField.DocumentTitle", // SC_SERVICE_TITLEFIELD
335 "stardiv.one.text.TextField.FileName", // SC_SERVICE_FILEFIELD
336 "stardiv.one.text.TextField.SheetName", // SC_SERVICE_SHEETFIELD
337 "stardiv.one.style.CellStyle", // SC_SERVICE_CELLSTYLE
338 "stardiv.one.style.PageStyle", // SC_SERVICE_PAGESTYLE
339 "", // SC_SERVICE_AUTOFORMAT
340 "", // SC_SERVICE_CELLRANGES
341 "", // SC_SERVICE_GRADTAB
342 "", // SC_SERVICE_HATCHTAB
343 "", // SC_SERVICE_BITMAPTAB
344 "", // SC_SERVICE_TRGRADTAB
345 "", // SC_SERVICE_MARKERTAB
346 "", // SC_SERVICE_DASHTAB
347 "", // SC_SERVICE_NUMRULES
348 "", // SC_SERVICE_DOCDEFLTS
349 "", // SC_SERVICE_DRAWDEFLTS
350 "", // SC_SERVICE_DOCSPRSETT
351 "", // SC_SERVICE_DOCCONF
352 "", // SC_SERVICE_IMAP_RECT
353 "", // SC_SERVICE_IMAP_CIRC
354 "", // SC_SERVICE_IMAP_POLY
356 // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
357 "", // SC_SERVICE_EXPORT_GOR
358 "", // SC_SERVICE_IMPORT_GOR
359 "", // SC_SERVICE_EXPORT_EOR
360 "", // SC_SERVICE_IMPORT_EOR
362 "", // SC_SERVICE_VALBIND
363 "", // SC_SERVICE_LISTCELLBIND
364 "", // SC_SERVICE_LISTSOURCE
365 "", // SC_SERVICE_CELLADDRESS
366 "", // SC_SERVICE_RANGEADDRESS
367 "", // SC_SERVICE_SHEETDOCSET
368 "", // SC_SERVICE_CHDATAPROV
369 "", // SC_SERVICE_FORMULAPARS
370 "", // SC_SERVICE_OPCODEMAPPER
371 "", // SC_SERVICE_VBAOBJECTPROVIDER
372 "", // SC_SERVICE_VBACODENAMEPROVIDER
373 "", // SC_SERVICE_VBAGLOBALS
374 "", // SC_SERVICE_EXT_TIMEFIELD
380 //------------------------------------------------------------------------
382 // alles static
385 sal_uInt16 ScServiceProvider::GetProviderType(const OUString& rServiceName)
387 if (!rServiceName.isEmpty())
389 const sal_uInt16 nEntries =
390 sizeof(aProvNamesId) / sizeof(aProvNamesId[0]);
391 for (sal_uInt16 i = 0; i < nEntries; i++)
393 if (rServiceName.equalsAscii( aProvNamesId[i].pName ))
395 return aProvNamesId[i].nType;
399 sal_uInt16 i;
400 for (i=0; i<SC_SERVICE_COUNT; i++)
402 OSL_ENSURE( aOldNames[i], "ScServiceProvider::GetProviderType: no oldname => crash");
403 if (rServiceName.equalsAscii( aOldNames[i] ))
405 OSL_FAIL("old service name used");
406 return i;
410 return SC_SERVICE_INVALID;
413 namespace {
415 sal_Int32 getFieldType(sal_uInt16 nOldType)
417 switch (nOldType)
419 case SC_SERVICE_URLFIELD:
420 return text::textfield::Type::URL;
421 case SC_SERVICE_PAGEFIELD:
422 return text::textfield::Type::PAGE;
423 case SC_SERVICE_PAGESFIELD:
424 return text::textfield::Type::PAGES;
425 case SC_SERVICE_DATEFIELD:
426 return text::textfield::Type::DATE;
427 case SC_SERVICE_TIMEFIELD:
428 return text::textfield::Type::TIME;
429 case SC_SERVICE_EXT_TIMEFIELD:
430 return text::textfield::Type::EXTENDED_TIME;
431 case SC_SERVICE_TITLEFIELD:
432 return text::textfield::Type::DOCINFO_TITLE;
433 case SC_SERVICE_FILEFIELD:
434 return text::textfield::Type::EXTENDED_FILE;
435 case SC_SERVICE_SHEETFIELD:
436 return text::textfield::Type::TABLE;
437 default:
441 return text::textfield::Type::URL; // default to URL for no reason whatsoever.
446 uno::Reference<uno::XInterface> ScServiceProvider::MakeInstance(
447 sal_uInt16 nType, ScDocShell* pDocShell )
449 uno::Reference<uno::XInterface> xRet;
450 switch (nType)
452 case SC_SERVICE_SHEET:
453 // noch nicht eingefuegt - DocShell=Null
454 xRet.set((sheet::XSpreadsheet*)new ScTableSheetObj(NULL,0));
455 break;
456 case SC_SERVICE_URLFIELD:
457 case SC_SERVICE_PAGEFIELD:
458 case SC_SERVICE_PAGESFIELD:
459 case SC_SERVICE_DATEFIELD:
460 case SC_SERVICE_TIMEFIELD:
461 case SC_SERVICE_EXT_TIMEFIELD:
462 case SC_SERVICE_TITLEFIELD:
463 case SC_SERVICE_FILEFIELD:
464 case SC_SERVICE_SHEETFIELD:
466 uno::Reference<text::XTextRange> xNullContent;
467 xRet.set(static_cast<text::XTextField*>(
468 new ScEditFieldObj(xNullContent, NULL, getFieldType(nType), ESelection())));
470 break;
471 case SC_SERVICE_CELLSTYLE:
472 xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PARA, OUString() ));
473 break;
474 case SC_SERVICE_PAGESTYLE:
475 xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PAGE, OUString() ));
476 break;
477 case SC_SERVICE_AUTOFORMAT:
478 xRet.set((container::XIndexAccess*)new ScAutoFormatObj( SC_AFMTOBJ_INVALID ));
479 break;
480 case SC_SERVICE_CELLRANGES:
481 // wird nicht eingefuegt, sondern gefuellt
482 // -> DocShell muss gesetzt sein, aber leere Ranges
483 if (pDocShell)
484 xRet.set((sheet::XSheetCellRanges*)new ScCellRangesObj( pDocShell, ScRangeList() ));
485 break;
487 case SC_SERVICE_DOCDEFLTS:
488 if (pDocShell)
489 xRet.set((beans::XPropertySet*)new ScDocDefaultsObj( pDocShell ));
490 break;
491 case SC_SERVICE_DRAWDEFLTS:
492 if (pDocShell)
493 xRet.set((beans::XPropertySet*)new ScDrawDefaultsObj( pDocShell ));
494 break;
496 // Drawing layer tables are not in SvxUnoDrawMSFactory,
497 // because SvxUnoDrawMSFactory doesn't have a SdrModel pointer.
498 // Drawing layer is always allocated if not there (MakeDrawLayer).
500 case SC_SERVICE_GRADTAB:
501 if (pDocShell)
502 xRet.set(SvxUnoGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
503 break;
504 case SC_SERVICE_HATCHTAB:
505 if (pDocShell)
506 xRet.set(SvxUnoHatchTable_createInstance( pDocShell->MakeDrawLayer() ));
507 break;
508 case SC_SERVICE_BITMAPTAB:
509 if (pDocShell)
510 xRet.set(SvxUnoBitmapTable_createInstance( pDocShell->MakeDrawLayer() ));
511 break;
512 case SC_SERVICE_TRGRADTAB:
513 if (pDocShell)
514 xRet.set(SvxUnoTransGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
515 break;
516 case SC_SERVICE_MARKERTAB:
517 if (pDocShell)
518 xRet.set(SvxUnoMarkerTable_createInstance( pDocShell->MakeDrawLayer() ));
519 break;
520 case SC_SERVICE_DASHTAB:
521 if (pDocShell)
522 xRet.set(SvxUnoDashTable_createInstance( pDocShell->MakeDrawLayer() ));
523 break;
524 case SC_SERVICE_NUMRULES:
525 if (pDocShell)
526 xRet.set(SvxCreateNumRule( pDocShell->MakeDrawLayer() ));
527 break;
528 case SC_SERVICE_DOCSPRSETT:
529 case SC_SERVICE_SHEETDOCSET:
530 case SC_SERVICE_DOCCONF:
531 if (pDocShell)
532 xRet.set((beans::XPropertySet*)new ScDocumentConfiguration(pDocShell));
533 break;
535 case SC_SERVICE_IMAP_RECT:
536 xRet.set(SvUnoImageMapRectangleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
537 break;
538 case SC_SERVICE_IMAP_CIRC:
539 xRet.set(SvUnoImageMapCircleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
540 break;
541 case SC_SERVICE_IMAP_POLY:
542 xRet.set(SvUnoImageMapPolygonObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
543 break;
545 // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
546 case SC_SERVICE_EXPORT_GOR:
547 xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_WRITE ));
548 break;
550 case SC_SERVICE_IMPORT_GOR:
551 xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_READ ));
552 break;
554 case SC_SERVICE_EXPORT_EOR:
555 if (pDocShell)
556 xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_WRITE ));
557 break;
559 case SC_SERVICE_IMPORT_EOR:
560 if (pDocShell)
561 xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_READ ));
562 break;
564 case SC_SERVICE_VALBIND:
565 case SC_SERVICE_LISTCELLBIND:
566 if (pDocShell)
568 sal_Bool bListPos = ( nType == SC_SERVICE_LISTCELLBIND );
569 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
570 xRet.set(*new calc::OCellValueBinding( xDoc, bListPos ));
572 break;
573 case SC_SERVICE_LISTSOURCE:
574 if (pDocShell)
576 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
577 xRet.set(*new calc::OCellListSource( xDoc ));
579 break;
580 case SC_SERVICE_CELLADDRESS:
581 case SC_SERVICE_RANGEADDRESS:
582 if (pDocShell)
584 sal_Bool bRange = ( nType == SC_SERVICE_RANGEADDRESS );
585 xRet.set(*new ScAddressConversionObj( pDocShell, bRange ));
587 break;
589 case SC_SERVICE_CHDATAPROV:
590 if (pDocShell && pDocShell->GetDocument())
591 xRet = *new ScChart2DataProvider( pDocShell->GetDocument() );
592 break;
594 case SC_SERVICE_FORMULAPARS:
595 if (pDocShell)
596 xRet.set(static_cast<sheet::XFormulaParser*>(new ScFormulaParserObj( pDocShell )));
597 break;
599 case SC_SERVICE_OPCODEMAPPER:
600 if (pDocShell)
602 ScDocument* pDoc = pDocShell->GetDocument();
603 ScAddress aAddress;
604 ScCompiler* pComp = new ScCompiler(pDoc,aAddress);
605 pComp->SetGrammar( pDoc->GetGrammar() );
606 SAL_WNODEPRECATED_DECLARATIONS_PUSH
607 xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(new ScFormulaOpCodeMapperObj(::std::auto_ptr<formula::FormulaCompiler> (pComp))));
608 SAL_WNODEPRECATED_DECLARATIONS_POP
609 break;
611 #ifndef DISABLE_SCRIPTING
612 case SC_SERVICE_VBAOBJECTPROVIDER:
613 if (pDocShell && pDocShell->GetDocument()->IsInVBAMode())
615 OSL_TRACE("**** creating VBA Object mapper");
616 xRet.set(static_cast<container::XNameAccess*>(new ScVbaObjectForCodeNameProvider( pDocShell )));
618 break;
619 case SC_SERVICE_VBACODENAMEPROVIDER:
620 if ( pDocShell && isInVBAMode( *pDocShell ) )
622 OSL_TRACE("**** creating VBA Object provider");
623 xRet.set(static_cast<document::XCodeNameQuery*>(new ScVbaCodeNameProvider(*pDocShell)));
625 break;
626 case SC_SERVICE_VBAGLOBALS:
627 if (pDocShell)
629 uno::Any aGlobs;
630 if ( !pDocShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aGlobs ) )
632 uno::Sequence< uno::Any > aArgs(1);
633 aArgs[ 0 ] <<= pDocShell->GetModel();
634 xRet = ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( OUString( "ooo.vba.excel.Globals" ), aArgs );
635 pDocShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", uno::Any( xRet ) );
636 BasicManager* pAppMgr = SFX_APP()->GetBasicManager();
637 if ( pAppMgr )
638 pAppMgr->SetGlobalUNOConstant( "ThisExcelDoc", aArgs[ 0 ] );
640 // create the VBA document event processor
641 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents(
642 ::ooo::vba::createVBAUnoAPIServiceWithArgs( pDocShell, "com.sun.star.script.vba.VBASpreadsheetEventProcessor", aArgs ), uno::UNO_QUERY );
643 pDocShell->GetDocument()->SetVbaEventProcessor( xVbaEvents );
646 break;
647 #endif
650 return xRet;
653 uno::Sequence<OUString> ScServiceProvider::GetAllServiceNames()
655 const sal_uInt16 nEntries = sizeof(aProvNamesId) / sizeof(aProvNamesId[0]);
656 uno::Sequence<OUString> aRet(nEntries);
657 OUString* pArray = aRet.getArray();
658 for (sal_uInt16 i = 0; i < nEntries; i++)
660 pArray[i] = OUString::createFromAscii( aProvNamesId[i].pName );
662 return aRet;
668 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */