xref: /AOO41X/main/sc/source/ui/unoobj/servuno.cxx (revision b3f79822e811ac3493b185030a72c3c5a51f32d8) !
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 #include <tools/debug.hxx>
28 #include <svtools/unoimap.hxx>
29 #include <svx/unofill.hxx>
30 #include <editeng/unonrule.hxx>
31 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
32 
33 #include "servuno.hxx"
34 #include "unoguard.hxx"
35 #include "unonames.hxx"
36 #include "cellsuno.hxx"
37 #include "fielduno.hxx"
38 #include "styleuno.hxx"
39 #include "afmtuno.hxx"
40 #include "defltuno.hxx"
41 #include "drdefuno.hxx"
42 #include "docsh.hxx"
43 #include "drwlayer.hxx"
44 #include "confuno.hxx"
45 #include "shapeuno.hxx"
46 #include "cellvaluebinding.hxx"
47 #include "celllistsource.hxx"
48 #include "addruno.hxx"
49 #include "chart2uno.hxx"
50 #include "tokenuno.hxx"
51 
52 // #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
53 #include <svx/xmleohlp.hxx>
54 #include <svx/xmlgrhlp.hxx>
55 #include <sfx2/docfile.hxx>
56 #include <sfx2/docfilt.hxx>
57 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
58 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
59 #include <com/sun/star/document/XCodeNameQuery.hpp>
60 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
61 #include <com/sun/star/form/XFormsSupplier.hpp>
62 #include <svx/unomod.hxx>
63 #include <vbahelper/vbaaccesshelper.hxx>
64 
65 #include <comphelper/processfactory.hxx>
66 #include <basic/basmgr.hxx>
67 #include <sfx2/app.hxx>
68 
69 using namespace ::com::sun::star;
70 
71 class ScVbaObjectForCodeNameProvider : public ::cppu::WeakImplHelper1< container::XNameAccess >
72 {
73     uno::Any maWorkbook;
74     uno::Any maCachedObject;
75     ScDocShell* mpDocShell;
76 public:
ScVbaObjectForCodeNameProvider(ScDocShell * pDocShell)77     ScVbaObjectForCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell )
78     {
79         ScDocument* pDoc = mpDocShell->GetDocument();
80         if ( !pDoc )
81             throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("")), uno::Reference< uno::XInterface >() );
82 
83         uno::Sequence< uno::Any > aArgs(2);
84         // access the application object ( parent for workbook )
85         aArgs[0] = uno::Any( ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.Application", uno::Sequence< uno::Any >() ) );
86         aArgs[1] = uno::Any( mpDocShell->GetModel() );
87         maWorkbook <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Workbook", aArgs );
88     }
89 
hasByName(const::rtl::OUString & aName)90     virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException )
91     {
92         ScUnoGuard aGuard;
93         maCachedObject = uno::Any(); // clear cached object
94         String sName = aName;
95 
96         ScDocument* pDoc = mpDocShell->GetDocument();
97         if ( !pDoc )
98             throw uno::RuntimeException();
99         if ( sName == pDoc->GetCodeName() )
100             maCachedObject = maWorkbook;
101         else
102         {
103             String sCodeName;
104             SCTAB nCount = pDoc->GetTableCount();
105             for( SCTAB i = 0; i < nCount; i++ )
106             {
107                 pDoc->GetCodeName( i, sCodeName );
108                 if( sCodeName == sName )
109                 {
110                     String sSheetName;
111                     if( pDoc->GetName( i, sSheetName ) )
112                     {
113                         uno::Reference< frame::XModel > xModel( mpDocShell->GetModel() );
114                         uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
115                         uno::Reference<sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
116                         uno::Reference< container::XIndexAccess > xIndexAccess( xSheets, uno::UNO_QUERY_THROW );
117                         uno::Reference< sheet::XSpreadsheet > xSheet( xIndexAccess->getByIndex( i ), uno::UNO_QUERY_THROW );
118                         uno::Sequence< uno::Any > aArgs(3);
119                         aArgs[0] = maWorkbook;
120                         aArgs[1] = uno::Any( xModel );
121                         aArgs[2] = uno::Any( rtl::OUString( sSheetName ) );
122                         // use the convience function
123                         maCachedObject <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Worksheet", aArgs );
124                         break;
125                     }
126                 }
127             }
128         }
129         return maCachedObject.hasValue();
130 
131     }
getByName(const::rtl::OUString & aName)132     ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
133     {
134         ScUnoGuard aGuard;
135         OSL_TRACE("ScVbaObjectForCodeNameProvider::getByName( %s )",
136             rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr() );
137         if ( !hasByName( aName ) )
138             throw ::com::sun::star::container::NoSuchElementException();
139         return maCachedObject;
140     }
getElementNames()141     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  ) throw (::com::sun::star::uno::RuntimeException)
142     {
143         ScUnoGuard aGuard;
144         ScDocument* pDoc = mpDocShell->GetDocument();
145         if ( !pDoc )
146             throw uno::RuntimeException();
147         SCTAB nCount = pDoc->GetTableCount();
148         uno::Sequence< rtl::OUString > aNames( nCount + 1 );
149         SCTAB index = 0;
150         String sCodeName;
151         for( ; index < nCount; ++index )
152         {
153             pDoc->GetCodeName( index, sCodeName );
154             aNames[ index ] = sCodeName;
155         }
156         aNames[ index ] = pDoc->GetCodeName();
157         return aNames;
158     }
159     // XElemenAccess
getElementType()160     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw (::com::sun::star::uno::RuntimeException){ return uno::Type(); }
hasElements()161     virtual ::sal_Bool SAL_CALL hasElements(  ) throw (::com::sun::star::uno::RuntimeException ) { return sal_True; }
162 
163 };
164 
165 class ScVbaCodeNameProvider : public ::cppu::WeakImplHelper1< document::XCodeNameQuery >
166 {
167 ScDocShell* mpDocShell;
168 public:
ScVbaCodeNameProvider(ScDocShell * pDocShell)169     ScVbaCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell ) {}
170     // XCodeNameQuery
getCodeNameForObject(const uno::Reference<uno::XInterface> & xIf)171     rtl::OUString SAL_CALL getCodeNameForObject( const uno::Reference< uno::XInterface >& xIf ) throw( uno::RuntimeException )
172     {
173         ScUnoGuard aGuard;
174         rtl::OUString sCodeName;
175         if ( mpDocShell )
176         {
177             OSL_TRACE( "*** In ScVbaCodeNameProvider::getCodeNameForObject");
178             // need to find the page ( and index )  for this control
179             uno::Reference< drawing::XDrawPagesSupplier > xSupplier( mpDocShell->GetModel(), uno::UNO_QUERY_THROW );
180             uno::Reference< container::XIndexAccess > xIndex( xSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
181             sal_Int32 nLen = xIndex->getCount();
182             bool bMatched = false;
183             uno::Sequence< script::ScriptEventDescriptor > aFakeEvents;
184             for ( sal_Int32 index = 0; index < nLen; ++index )
185             {
186                 try
187                 {
188                     uno::Reference< form::XFormsSupplier >  xFormSupplier( xIndex->getByIndex( index ), uno::UNO_QUERY_THROW );
189                     uno::Reference< container::XIndexAccess > xFormIndex( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
190                     // get the www-standard container
191                     uno::Reference< container::XIndexAccess > xFormControls( xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW );
192                     sal_Int32 nCntrls = xFormControls->getCount();
193                     for( sal_Int32 cIndex = 0; cIndex < nCntrls; ++cIndex )
194                     {
195                         uno::Reference< uno::XInterface > xControl( xFormControls->getByIndex( cIndex ), uno::UNO_QUERY_THROW );
196                         bMatched = ( xControl == xIf );
197                         if ( bMatched )
198                         {
199                             String sName;
200                             mpDocShell->GetDocument()->GetCodeName( static_cast<SCTAB>( index ), sName );
201                             sCodeName = sName;
202                         }
203                     }
204                 }
205                 catch( uno::Exception& ) {}
206                 if ( bMatched )
207                     break;
208             }
209         }
210         // Probably should throw here ( if !bMatched )
211          return sCodeName;
212     }
213 
214 };
215 
216 //------------------------------------------------------------------------
217 //
218 struct ProvNamesId_Type
219 {
220     const char *    pName;
221     sal_uInt16      nType;
222 };
223 
224 static const ProvNamesId_Type __FAR_DATA aProvNamesId[] =
225 {
226     { "com.sun.star.sheet.Spreadsheet",                 SC_SERVICE_SHEET },
227     { "com.sun.star.text.TextField.URL",                SC_SERVICE_URLFIELD },
228     { "com.sun.star.text.TextField.PageNumber",         SC_SERVICE_PAGEFIELD },
229     { "com.sun.star.text.TextField.PageCount",          SC_SERVICE_PAGESFIELD },
230     { "com.sun.star.text.TextField.Date",               SC_SERVICE_DATEFIELD },
231     { "com.sun.star.text.TextField.Time",               SC_SERVICE_TIMEFIELD },
232     { "com.sun.star.text.TextField.DocumentTitle",      SC_SERVICE_TITLEFIELD },
233     { "com.sun.star.text.TextField.FileName",           SC_SERVICE_FILEFIELD },
234     { "com.sun.star.text.TextField.SheetName",          SC_SERVICE_SHEETFIELD },
235     { "com.sun.star.style.CellStyle",                   SC_SERVICE_CELLSTYLE },
236     { "com.sun.star.style.PageStyle",                   SC_SERVICE_PAGESTYLE },
237     { "com.sun.star.sheet.TableAutoFormat",             SC_SERVICE_AUTOFORMAT },
238     { "com.sun.star.sheet.SheetCellRanges",             SC_SERVICE_CELLRANGES },
239     { "com.sun.star.drawing.GradientTable",             SC_SERVICE_GRADTAB },
240     { "com.sun.star.drawing.HatchTable",                SC_SERVICE_HATCHTAB },
241     { "com.sun.star.drawing.BitmapTable",               SC_SERVICE_BITMAPTAB },
242     { "com.sun.star.drawing.TransparencyGradientTable", SC_SERVICE_TRGRADTAB },
243     { "com.sun.star.drawing.MarkerTable",               SC_SERVICE_MARKERTAB },
244     { "com.sun.star.drawing.DashTable",                 SC_SERVICE_DASHTAB },
245     { "com.sun.star.text.NumberingRules",               SC_SERVICE_NUMRULES },
246     { "com.sun.star.sheet.Defaults",                    SC_SERVICE_DOCDEFLTS },
247     { "com.sun.star.drawing.Defaults",                  SC_SERVICE_DRAWDEFLTS },
248     { "com.sun.star.comp.SpreadsheetSettings",          SC_SERVICE_DOCSPRSETT },
249     { "com.sun.star.document.Settings",                 SC_SERVICE_DOCCONF },
250     { "com.sun.star.image.ImageMapRectangleObject",     SC_SERVICE_IMAP_RECT },
251     { "com.sun.star.image.ImageMapCircleObject",        SC_SERVICE_IMAP_CIRC },
252     { "com.sun.star.image.ImageMapPolygonObject",       SC_SERVICE_IMAP_POLY },
253 
254         // #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
255     { "com.sun.star.document.ExportGraphicObjectResolver",  SC_SERVICE_EXPORT_GOR },
256     { "com.sun.star.document.ImportGraphicObjectResolver",  SC_SERVICE_IMPORT_GOR },
257     { "com.sun.star.document.ExportEmbeddedObjectResolver", SC_SERVICE_EXPORT_EOR },
258     { "com.sun.star.document.ImportEmbeddedObjectResolver", SC_SERVICE_IMPORT_EOR },
259 
260     { SC_SERVICENAME_VALBIND,               SC_SERVICE_VALBIND },
261     { SC_SERVICENAME_LISTCELLBIND,          SC_SERVICE_LISTCELLBIND },
262     { SC_SERVICENAME_LISTSOURCE,            SC_SERVICE_LISTSOURCE },
263     { SC_SERVICENAME_CELLADDRESS,           SC_SERVICE_CELLADDRESS },
264     { SC_SERVICENAME_RANGEADDRESS,          SC_SERVICE_RANGEADDRESS },
265 
266     { "com.sun.star.sheet.DocumentSettings",SC_SERVICE_SHEETDOCSET },
267 
268     { SC_SERVICENAME_CHDATAPROV,            SC_SERVICE_CHDATAPROV },
269     { SC_SERVICENAME_FORMULAPARS,           SC_SERVICE_FORMULAPARS },
270     { SC_SERVICENAME_OPCODEMAPPER,          SC_SERVICE_OPCODEMAPPER },
271     { "ooo.vba.VBAObjectModuleObjectProvider", SC_SERVICE_VBAOBJECTPROVIDER },
272     { "ooo.vba.VBACodeNameProvider",        SC_SERVICE_VBACODENAMEPROVIDER },
273     { "ooo.vba.VBAGlobals",                 SC_SERVICE_VBAGLOBALS },
274 
275     // case-correct versions of the service names (#i102468#)
276     { "com.sun.star.text.textfield.URL",                SC_SERVICE_URLFIELD },
277     { "com.sun.star.text.textfield.PageNumber",         SC_SERVICE_PAGEFIELD },
278     { "com.sun.star.text.textfield.PageCount",          SC_SERVICE_PAGESFIELD },
279     { "com.sun.star.text.textfield.Date",               SC_SERVICE_DATEFIELD },
280     { "com.sun.star.text.textfield.Time",               SC_SERVICE_TIMEFIELD },
281     { "com.sun.star.text.textfield.DocumentTitle",      SC_SERVICE_TITLEFIELD },
282     { "com.sun.star.text.textfield.FileName",           SC_SERVICE_FILEFIELD },
283     { "com.sun.star.text.textfield.SheetName",          SC_SERVICE_SHEETFIELD }
284 };
285 
286 //
287 //  old service names that were in 567 still work in createInstance,
288 //  in case some macro is still using them
289 //
290 
291 static const sal_Char* __FAR_DATA aOldNames[SC_SERVICE_COUNT] =
292     {
293         "",                                         // SC_SERVICE_SHEET
294         "stardiv.one.text.TextField.URL",           // SC_SERVICE_URLFIELD
295         "stardiv.one.text.TextField.PageNumber",    // SC_SERVICE_PAGEFIELD
296         "stardiv.one.text.TextField.PageCount",     // SC_SERVICE_PAGESFIELD
297         "stardiv.one.text.TextField.Date",          // SC_SERVICE_DATEFIELD
298         "stardiv.one.text.TextField.Time",          // SC_SERVICE_TIMEFIELD
299         "stardiv.one.text.TextField.DocumentTitle", // SC_SERVICE_TITLEFIELD
300         "stardiv.one.text.TextField.FileName",      // SC_SERVICE_FILEFIELD
301         "stardiv.one.text.TextField.SheetName",     // SC_SERVICE_SHEETFIELD
302         "stardiv.one.style.CellStyle",              // SC_SERVICE_CELLSTYLE
303         "stardiv.one.style.PageStyle",              // SC_SERVICE_PAGESTYLE
304         "",                                         // SC_SERVICE_AUTOFORMAT
305         "",                                         // SC_SERVICE_CELLRANGES
306         "",                                         // SC_SERVICE_GRADTAB
307         "",                                         // SC_SERVICE_HATCHTAB
308         "",                                         // SC_SERVICE_BITMAPTAB
309         "",                                         // SC_SERVICE_TRGRADTAB
310         "",                                         // SC_SERVICE_MARKERTAB
311         "",                                         // SC_SERVICE_DASHTAB
312         "",                                         // SC_SERVICE_NUMRULES
313         "",                                         // SC_SERVICE_DOCDEFLTS
314         "",                                         // SC_SERVICE_DRAWDEFLTS
315         "",                                         // SC_SERVICE_DOCSPRSETT
316         "",                                         // SC_SERVICE_DOCCONF
317         "",                                         // SC_SERVICE_IMAP_RECT
318         "",                                         // SC_SERVICE_IMAP_CIRC
319         "",                                         // SC_SERVICE_IMAP_POLY
320 
321         // #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
322         "",                                         // SC_SERVICE_EXPORT_GOR
323         "",                                         // SC_SERVICE_IMPORT_GOR
324         "",                                         // SC_SERVICE_EXPORT_EOR
325         "",                                         // SC_SERVICE_IMPORT_EOR
326 
327         "",                                         // SC_SERVICE_VALBIND
328         "",                                         // SC_SERVICE_LISTCELLBIND
329         "",                                         // SC_SERVICE_LISTSOURCE
330         "",                                         // SC_SERVICE_CELLADDRESS
331         "",                                         // SC_SERVICE_RANGEADDRESS
332         "",                                         // SC_SERVICE_SHEETDOCSET
333         "",                                         // SC_SERVICE_CHDATAPROV
334         "",                                         // SC_SERVICE_FORMULAPARS
335         "",                                         // SC_SERVICE_OPCODEMAPPER
336         "",                                         // SC_SERVICE_VBAOBJECTPROVIDER
337         "",                                         // SC_SERVICE_VBACODENAMEPROVIDER
338         "",                                         // SC_SERVICE_VBAGLOBALS
339     };
340 
341 
342 
343 
344 //------------------------------------------------------------------------
345 
346 //  alles static
347 
348 //UNUSED2008-05  String ScServiceProvider::GetProviderName(sal_uInt16 nObjectType)
349 //UNUSED2008-05  {
350 //UNUSED2008-05      String sRet;
351 //UNUSED2008-05      if (nObjectType < SC_SERVICE_COUNT)
352 //UNUSED2008-05          sRet = String::CreateFromAscii( aProvNames[nObjectType] );
353 //UNUSED2008-05      return sRet;
354 //UNUSED2008-05  }
355 
GetProviderType(const String & rServiceName)356 sal_uInt16 ScServiceProvider::GetProviderType(const String& rServiceName)
357 {
358     if (rServiceName.Len())
359     {
360         const sal_uInt16 nEntries =
361             sizeof(aProvNamesId) / sizeof(aProvNamesId[0]);
362         for (sal_uInt16 i = 0; i < nEntries; i++)
363         {
364             if (rServiceName.EqualsAscii( aProvNamesId[i].pName ))
365             {
366                 return aProvNamesId[i].nType;
367             }
368         }
369 
370         sal_uInt16 i;
371         for (i=0; i<SC_SERVICE_COUNT; i++)
372         {
373             DBG_ASSERT( aOldNames[i], "ScServiceProvider::GetProviderType: no oldname => crash");
374             if (rServiceName.EqualsAscii( aOldNames[i] ))
375             {
376                 DBG_ERROR("old service name used");
377                 return i;
378             }
379         }
380     }
381     return SC_SERVICE_INVALID;
382 }
383 
MakeInstance(sal_uInt16 nType,ScDocShell * pDocShell)384 uno::Reference<uno::XInterface> ScServiceProvider::MakeInstance(
385                                     sal_uInt16 nType, ScDocShell* pDocShell )
386 {
387     uno::Reference<uno::XInterface> xRet;
388     switch (nType)
389     {
390         case SC_SERVICE_SHEET:
391             //  noch nicht eingefuegt - DocShell=Null
392             xRet.set((sheet::XSpreadsheet*)new ScTableSheetObj(NULL,0));
393             break;
394         case SC_SERVICE_URLFIELD:
395             xRet.set((text::XTextField*)new ScCellFieldObj( NULL, ScAddress(), ESelection() ));
396             break;
397         case SC_SERVICE_PAGEFIELD:
398         case SC_SERVICE_PAGESFIELD:
399         case SC_SERVICE_DATEFIELD:
400         case SC_SERVICE_TIMEFIELD:
401         case SC_SERVICE_TITLEFIELD:
402         case SC_SERVICE_FILEFIELD:
403         case SC_SERVICE_SHEETFIELD:
404             xRet.set((text::XTextField*)new ScHeaderFieldObj( NULL, 0, nType, ESelection() ));
405             break;
406         case SC_SERVICE_CELLSTYLE:
407             xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PARA, String() ));
408             break;
409         case SC_SERVICE_PAGESTYLE:
410             xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PAGE, String() ));
411             break;
412         case SC_SERVICE_AUTOFORMAT:
413             xRet.set((container::XIndexAccess*)new ScAutoFormatObj( SC_AFMTOBJ_INVALID ));
414             break;
415         case SC_SERVICE_CELLRANGES:
416             //  wird nicht eingefuegt, sondern gefuellt
417             //  -> DocShell muss gesetzt sein, aber leere Ranges
418             if (pDocShell)
419                 xRet.set((sheet::XSheetCellRanges*)new ScCellRangesObj( pDocShell, ScRangeList() ));
420             break;
421 
422         case SC_SERVICE_DOCDEFLTS:
423             if (pDocShell)
424                 xRet.set((beans::XPropertySet*)new ScDocDefaultsObj( pDocShell ));
425             break;
426         case SC_SERVICE_DRAWDEFLTS:
427             if (pDocShell)
428                 xRet.set((beans::XPropertySet*)new ScDrawDefaultsObj( pDocShell ));
429             break;
430 
431         //  Drawing layer tables are not in SvxUnoDrawMSFactory,
432         //  because SvxUnoDrawMSFactory doesn't have a SdrModel pointer.
433         //  Drawing layer is always allocated if not there (MakeDrawLayer).
434 
435         case SC_SERVICE_GRADTAB:
436             if (pDocShell)
437                 xRet.set(SvxUnoGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
438             break;
439         case SC_SERVICE_HATCHTAB:
440             if (pDocShell)
441                 xRet.set(SvxUnoHatchTable_createInstance( pDocShell->MakeDrawLayer() ));
442             break;
443         case SC_SERVICE_BITMAPTAB:
444             if (pDocShell)
445                 xRet.set(SvxUnoBitmapTable_createInstance( pDocShell->MakeDrawLayer() ));
446             break;
447         case SC_SERVICE_TRGRADTAB:
448             if (pDocShell)
449                 xRet.set(SvxUnoTransGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
450             break;
451         case SC_SERVICE_MARKERTAB:
452             if (pDocShell)
453                 xRet.set(SvxUnoMarkerTable_createInstance( pDocShell->MakeDrawLayer() ));
454             break;
455         case SC_SERVICE_DASHTAB:
456             if (pDocShell)
457                 xRet.set(SvxUnoDashTable_createInstance( pDocShell->MakeDrawLayer() ));
458             break;
459         case SC_SERVICE_NUMRULES:
460             if (pDocShell)
461                 xRet.set(SvxCreateNumRule( pDocShell->MakeDrawLayer() ));
462             break;
463         case SC_SERVICE_DOCSPRSETT:
464         case SC_SERVICE_SHEETDOCSET:
465         case SC_SERVICE_DOCCONF:
466             if (pDocShell)
467                 xRet.set((beans::XPropertySet*)new ScDocumentConfiguration(pDocShell));
468             break;
469 
470         case SC_SERVICE_IMAP_RECT:
471             xRet.set(SvUnoImageMapRectangleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
472             break;
473         case SC_SERVICE_IMAP_CIRC:
474             xRet.set(SvUnoImageMapCircleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
475             break;
476         case SC_SERVICE_IMAP_POLY:
477             xRet.set(SvUnoImageMapPolygonObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
478             break;
479 
480         // #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
481         case SC_SERVICE_EXPORT_GOR:
482             xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_WRITE ));
483             break;
484 
485         case SC_SERVICE_IMPORT_GOR:
486             xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_READ ));
487             break;
488 
489         case SC_SERVICE_EXPORT_EOR:
490             if (pDocShell)
491                 xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_WRITE ));
492             break;
493 
494         case SC_SERVICE_IMPORT_EOR:
495             if (pDocShell)
496                 xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_READ ));
497             break;
498 
499         case SC_SERVICE_VALBIND:
500         case SC_SERVICE_LISTCELLBIND:
501             if (pDocShell)
502             {
503                 sal_Bool bListPos = ( nType == SC_SERVICE_LISTCELLBIND );
504                 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
505                 xRet.set(*new calc::OCellValueBinding( xDoc, bListPos ));
506             }
507             break;
508         case SC_SERVICE_LISTSOURCE:
509             if (pDocShell)
510             {
511                 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
512                 xRet.set(*new calc::OCellListSource( xDoc ));
513             }
514             break;
515         case SC_SERVICE_CELLADDRESS:
516         case SC_SERVICE_RANGEADDRESS:
517             if (pDocShell)
518             {
519                 sal_Bool bRange = ( nType == SC_SERVICE_RANGEADDRESS );
520                 xRet.set(*new ScAddressConversionObj( pDocShell, bRange ));
521             }
522             break;
523 
524         case SC_SERVICE_CHDATAPROV:
525             if (pDocShell && pDocShell->GetDocument())
526                 xRet = *new ScChart2DataProvider( pDocShell->GetDocument() );
527             break;
528 
529         case SC_SERVICE_FORMULAPARS:
530             if (pDocShell)
531                 xRet.set(static_cast<sheet::XFormulaParser*>(new ScFormulaParserObj( pDocShell )));
532             break;
533 
534         case SC_SERVICE_OPCODEMAPPER:
535             if (pDocShell)
536             {
537                 ScDocument* pDoc = pDocShell->GetDocument();
538                 ScAddress aAddress;
539                 ScCompiler* pComp = new ScCompiler(pDoc,aAddress);
540                 pComp->SetGrammar( pDoc->GetGrammar() );
541                 xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(new ScFormulaOpCodeMapperObj(::std::auto_ptr<formula::FormulaCompiler> (pComp))));
542                 break;
543             }
544         case SC_SERVICE_VBAOBJECTPROVIDER:
545             if (pDocShell && pDocShell->GetDocument()->IsInVBAMode())
546             {
547                 OSL_TRACE("**** creating VBA Object mapper");
548                 xRet.set(static_cast<container::XNameAccess*>(new ScVbaObjectForCodeNameProvider( pDocShell )));
549             }
550             break;
551         case SC_SERVICE_VBACODENAMEPROVIDER:
552             if (pDocShell && pDocShell->GetDocument()->IsInVBAMode())
553             {
554                 OSL_TRACE("**** creating VBA Object provider");
555                 xRet.set(static_cast<document::XCodeNameQuery*>(new ScVbaCodeNameProvider( pDocShell )));
556             }
557             break;
558         case SC_SERVICE_VBAGLOBALS:
559             if (pDocShell)
560             {
561                 uno::Any aGlobs;
562                 if ( !pDocShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aGlobs ) )
563                 {
564                     uno::Sequence< uno::Any > aArgs(1);
565                     aArgs[ 0 ] <<= pDocShell->GetModel();
566                     xRet = ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.excel.Globals" ) ), aArgs );
567                     pDocShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", uno::Any( xRet ) );
568                     BasicManager* pAppMgr = SFX_APP()->GetBasicManager();
569                     if ( pAppMgr )
570                         pAppMgr->SetGlobalUNOConstant( "ThisExcelDoc", aArgs[ 0 ] );
571 
572                     // create the VBA document event processor
573                     uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents(
574                         ::ooo::vba::createVBAUnoAPIServiceWithArgs( pDocShell, "com.sun.star.script.vba.VBASpreadsheetEventProcessor", aArgs ), uno::UNO_QUERY );
575                     pDocShell->GetDocument()->SetVbaEventProcessor( xVbaEvents );
576                 }
577             }
578         break;
579     }
580 
581     return xRet;
582 }
583 
GetAllServiceNames()584 uno::Sequence<rtl::OUString> ScServiceProvider::GetAllServiceNames()
585 {
586     const sal_uInt16 nEntries = sizeof(aProvNamesId) / sizeof(aProvNamesId[0]);
587     uno::Sequence<rtl::OUString> aRet(nEntries);
588     rtl::OUString* pArray = aRet.getArray();
589     for (sal_uInt16 i = 0; i < nEntries; i++)
590     {
591         pArray[i] = rtl::OUString::createFromAscii( aProvNamesId[i].pName );
592     }
593     return aRet;
594 }
595 
596 
597 
598 
599