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