LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/unoobj - servuno.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 112 247 45.3 %
Date: 2012-12-27 Functions: 5 18 27.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      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>
      28             : 
      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"
      46             : 
      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>
      59             : 
      60             : #include <comphelper/processfactory.hxx>
      61             : #include <basic/basmgr.hxx>
      62             : #include <sfx2/app.hxx>
      63             : 
      64             : #include <comphelper/componentcontext.hxx>
      65             : #include <cppuhelper/component_context.hxx>
      66             : #include <com/sun/star/script/vba/XVBACompatibility.hpp>
      67             : 
      68             : using namespace ::com::sun::star;
      69             : 
      70           0 : bool isInVBAMode( ScDocShell& rDocSh )
      71             : {
      72           0 :     uno::Reference<script::XLibraryContainer> xLibContainer = rDocSh.GetBasicContainer();
      73           0 :     uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY );
      74           0 :     if ( xVBACompat.is() )
      75           0 :         return xVBACompat->getVBACompatibilityMode();
      76           0 :     return false;
      77             : }
      78             : 
      79           0 : class ScVbaObjectForCodeNameProvider : public ::cppu::WeakImplHelper1< container::XNameAccess >
      80             : {
      81             :     uno::Any maWorkbook;
      82             :     uno::Any maCachedObject;
      83             :     ScDocShell* mpDocShell;
      84             : public:
      85           6 :     ScVbaObjectForCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell )
      86             :     {
      87           3 :         ScDocument* pDoc = mpDocShell->GetDocument();
      88           3 :         if ( !pDoc )
      89           0 :             throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("")), uno::Reference< uno::XInterface >() );
      90             : 
      91           3 :         uno::Sequence< uno::Any > aArgs(2);
      92             :         // access the application object ( parent for workbook )
      93           3 :         aArgs[0] = uno::Any( ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.Application", uno::Sequence< uno::Any >() ) );
      94           0 :         aArgs[1] = uno::Any( mpDocShell->GetModel() );
      95           0 :         maWorkbook <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Workbook", aArgs );
      96           0 :     }
      97             : 
      98           0 :     virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException )
      99             :     {
     100           0 :         SolarMutexGuard aGuard;
     101           0 :         maCachedObject = uno::Any(); // clear cached object
     102           0 :         String sName = aName;
     103             : 
     104           0 :         ScDocument* pDoc = mpDocShell->GetDocument();
     105           0 :         if ( !pDoc )
     106           0 :             throw uno::RuntimeException();
     107             :         // aName ( sName ) is generated from the stream name which can be different ( case-wise )
     108             :         // from the code name
     109           0 :         if( sName.EqualsIgnoreCaseAscii( pDoc->GetCodeName() ) )
     110           0 :             maCachedObject = maWorkbook;
     111             :         else
     112             :         {
     113           0 :             rtl::OUString sCodeName;
     114           0 :             SCTAB nCount = pDoc->GetTableCount();
     115           0 :             for( SCTAB i = 0; i < nCount; i++ )
     116             :             {
     117           0 :                 pDoc->GetCodeName( i, sCodeName );
     118             :                 // aName ( sName ) is generated from the stream name which can be different ( case-wise )
     119             :                 // from the code name
     120           0 :                 if( String(sCodeName).EqualsIgnoreCaseAscii( sName ) )
     121             :                 {
     122           0 :                     rtl::OUString sSheetName;
     123           0 :                     if( pDoc->GetName( i, sSheetName ) )
     124             :                     {
     125           0 :                         uno::Reference< frame::XModel > xModel( mpDocShell->GetModel() );
     126           0 :                         uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
     127           0 :                         uno::Reference<sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
     128           0 :                         uno::Reference< container::XIndexAccess > xIndexAccess( xSheets, uno::UNO_QUERY_THROW );
     129           0 :                         uno::Reference< sheet::XSpreadsheet > xSheet( xIndexAccess->getByIndex( i ), uno::UNO_QUERY_THROW );
     130           0 :                         uno::Sequence< uno::Any > aArgs(3);
     131           0 :                         aArgs[0] = maWorkbook;
     132           0 :                         aArgs[1] = uno::Any( xModel );
     133           0 :                         aArgs[2] = uno::Any( rtl::OUString( sSheetName ) );
     134             :                         // use the convience function
     135           0 :                         maCachedObject <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Worksheet", aArgs );
     136           0 :                         break;
     137           0 :                     }
     138             :                 }
     139           0 :             }
     140             :         }
     141           0 :         return maCachedObject.hasValue();
     142             : 
     143             :     }
     144           0 :     ::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)
     145             :     {
     146           0 :         SolarMutexGuard aGuard;
     147             :         OSL_TRACE("ScVbaObjectForCodeNameProvider::getByName( %s )",
     148             :             rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr() );
     149           0 :         if ( !hasByName( aName ) )
     150           0 :             throw ::com::sun::star::container::NoSuchElementException();
     151           0 :         return maCachedObject;
     152             :     }
     153           0 :     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  ) throw (::com::sun::star::uno::RuntimeException)
     154             :     {
     155           0 :         SolarMutexGuard aGuard;
     156           0 :         ScDocument* pDoc = mpDocShell->GetDocument();
     157           0 :         if ( !pDoc )
     158           0 :             throw uno::RuntimeException();
     159           0 :         SCTAB nCount = pDoc->GetTableCount();
     160           0 :         uno::Sequence< rtl::OUString > aNames( nCount + 1 );
     161           0 :         SCTAB index = 0;
     162           0 :         rtl::OUString sCodeName;
     163           0 :         for( ; index < nCount; ++index )
     164             :         {
     165           0 :             pDoc->GetCodeName( index, sCodeName );
     166           0 :             aNames[ index ] = sCodeName;
     167             :         }
     168           0 :         aNames[ index ] = pDoc->GetCodeName();
     169           0 :         return aNames;
     170             :     }
     171             :     // XElemenAccess
     172           0 :     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw (::com::sun::star::uno::RuntimeException){ return uno::Type(); }
     173           0 :     virtual ::sal_Bool SAL_CALL hasElements(  ) throw (::com::sun::star::uno::RuntimeException ) { return sal_True; }
     174             : 
     175             : };
     176             : 
     177           0 : class ScVbaCodeNameProvider : public ::cppu::WeakImplHelper1< document::XCodeNameQuery >
     178             : {
     179             :     ScDocShell& mrDocShell;
     180             : public:
     181           0 :     ScVbaCodeNameProvider( ScDocShell& rDocShell ) : mrDocShell(rDocShell) {}
     182             :     // XCodeNameQuery
     183           0 :     rtl::OUString SAL_CALL getCodeNameForObject( const uno::Reference< uno::XInterface >& xIf ) throw( uno::RuntimeException )
     184             :     {
     185           0 :         SolarMutexGuard aGuard;
     186           0 :         rtl::OUString sCodeName;
     187             : 
     188             :         // need to find the page ( and index )  for this control
     189           0 :         uno::Reference< drawing::XDrawPagesSupplier > xSupplier( mrDocShell.GetModel(), uno::UNO_QUERY_THROW );
     190           0 :         uno::Reference< container::XIndexAccess > xIndex( xSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
     191           0 :         sal_Int32 nLen = xIndex->getCount();
     192           0 :         bool bMatched = false;
     193           0 :         uno::Sequence< script::ScriptEventDescriptor > aFakeEvents;
     194           0 :         for ( sal_Int32 index = 0; index < nLen; ++index )
     195             :         {
     196             :             try
     197             :             {
     198           0 :                 uno::Reference< form::XFormsSupplier >  xFormSupplier( xIndex->getByIndex( index ), uno::UNO_QUERY_THROW );
     199           0 :                 uno::Reference< container::XIndexAccess > xFormIndex( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
     200             :                 // get the www-standard container
     201           0 :                 uno::Reference< container::XIndexAccess > xFormControls( xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW );
     202           0 :                 sal_Int32 nCntrls = xFormControls->getCount();
     203           0 :                 for( sal_Int32 cIndex = 0; cIndex < nCntrls; ++cIndex )
     204             :                 {
     205           0 :                     uno::Reference< uno::XInterface > xControl( xFormControls->getByIndex( cIndex ), uno::UNO_QUERY_THROW );
     206           0 :                     bMatched = ( xControl == xIf );
     207           0 :                     if ( bMatched )
     208             :                     {
     209           0 :                         rtl::OUString sName;
     210           0 :                         mrDocShell.GetDocument()->GetCodeName( static_cast<SCTAB>( index ), sName );
     211           0 :                         sCodeName = sName;
     212             :                     }
     213           0 :                 }
     214             :             }
     215           0 :             catch( uno::Exception& ) {}
     216           0 :             if ( bMatched )
     217           0 :                 break;
     218             :         }
     219             :         // Probably should throw here ( if !bMatched )
     220           0 :          return sCodeName;
     221             :     }
     222             : 
     223           0 :     rtl::OUString SAL_CALL getCodeNameForContainer( const uno::Reference<uno::XInterface>& xContainer )
     224             :             throw( uno::RuntimeException )
     225             :     {
     226           0 :         SolarMutexGuard aGuard;
     227           0 :         uno::Reference<drawing::XDrawPagesSupplier> xSupplier(mrDocShell.GetModel(), uno::UNO_QUERY_THROW);
     228           0 :         uno::Reference<container::XIndexAccess> xIndex(xSupplier->getDrawPages(), uno::UNO_QUERY_THROW);
     229             : 
     230           0 :         for (sal_Int32 i = 0, n = xIndex->getCount(); i < n; ++i)
     231             :         {
     232             :             try
     233             :             {
     234           0 :                 uno::Reference<form::XFormsSupplier>  xFormSupplier(xIndex->getByIndex(i), uno::UNO_QUERY_THROW);
     235           0 :                 uno::Reference<container::XIndexAccess> xFormIndex(xFormSupplier->getForms(), uno::UNO_QUERY_THROW);
     236             :                 // get the www-standard container
     237           0 :                 uno::Reference<container::XIndexAccess> xFormControls(xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW);
     238           0 :                 if (xFormControls == xContainer)
     239             :                 {
     240           0 :                     rtl::OUString aName;
     241           0 :                     if (mrDocShell.GetDocument()->GetCodeName(static_cast<SCTAB>(i), aName))
     242           0 :                         return aName;
     243           0 :                 }
     244             :             }
     245           0 :             catch( uno::Exception& ) {}
     246             :         }
     247           0 :         return rtl::OUString();
     248             :     }
     249             : };
     250             : 
     251             : //------------------------------------------------------------------------
     252             : //
     253             : struct ProvNamesId_Type
     254             : {
     255             :     const char *    pName;
     256             :     sal_uInt16      nType;
     257             : };
     258             : 
     259             : static const ProvNamesId_Type aProvNamesId[] =
     260             : {
     261             :     { "com.sun.star.sheet.Spreadsheet",                 SC_SERVICE_SHEET },
     262             :     { "com.sun.star.text.TextField.URL",                SC_SERVICE_URLFIELD },
     263             :     { "com.sun.star.text.TextField.PageNumber",         SC_SERVICE_PAGEFIELD },
     264             :     { "com.sun.star.text.TextField.PageCount",          SC_SERVICE_PAGESFIELD },
     265             :     { "com.sun.star.text.TextField.Date",               SC_SERVICE_DATEFIELD },
     266             :     { "com.sun.star.text.TextField.Time",               SC_SERVICE_TIMEFIELD },
     267             :     { "com.sun.star.text.TextField.DateTime",           SC_SERVICE_EXT_TIMEFIELD },
     268             :     { "com.sun.star.text.TextField.DocInfo.Title",      SC_SERVICE_TITLEFIELD },
     269             :     { "com.sun.star.text.TextField.FileName",           SC_SERVICE_FILEFIELD },
     270             :     { "com.sun.star.text.TextField.SheetName",          SC_SERVICE_SHEETFIELD },
     271             :     { "com.sun.star.style.CellStyle",                   SC_SERVICE_CELLSTYLE },
     272             :     { "com.sun.star.style.PageStyle",                   SC_SERVICE_PAGESTYLE },
     273             :     { "com.sun.star.sheet.TableAutoFormat",             SC_SERVICE_AUTOFORMAT },
     274             :     { "com.sun.star.sheet.SheetCellRanges",             SC_SERVICE_CELLRANGES },
     275             :     { "com.sun.star.drawing.GradientTable",             SC_SERVICE_GRADTAB },
     276             :     { "com.sun.star.drawing.HatchTable",                SC_SERVICE_HATCHTAB },
     277             :     { "com.sun.star.drawing.BitmapTable",               SC_SERVICE_BITMAPTAB },
     278             :     { "com.sun.star.drawing.TransparencyGradientTable", SC_SERVICE_TRGRADTAB },
     279             :     { "com.sun.star.drawing.MarkerTable",               SC_SERVICE_MARKERTAB },
     280             :     { "com.sun.star.drawing.DashTable",                 SC_SERVICE_DASHTAB },
     281             :     { "com.sun.star.text.NumberingRules",               SC_SERVICE_NUMRULES },
     282             :     { "com.sun.star.sheet.Defaults",                    SC_SERVICE_DOCDEFLTS },
     283             :     { "com.sun.star.drawing.Defaults",                  SC_SERVICE_DRAWDEFLTS },
     284             :     { "com.sun.star.comp.SpreadsheetSettings",          SC_SERVICE_DOCSPRSETT },
     285             :     { "com.sun.star.document.Settings",                 SC_SERVICE_DOCCONF },
     286             :     { "com.sun.star.image.ImageMapRectangleObject",     SC_SERVICE_IMAP_RECT },
     287             :     { "com.sun.star.image.ImageMapCircleObject",        SC_SERVICE_IMAP_CIRC },
     288             :     { "com.sun.star.image.ImageMapPolygonObject",       SC_SERVICE_IMAP_POLY },
     289             : 
     290             :         // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
     291             :     { "com.sun.star.document.ExportGraphicObjectResolver",  SC_SERVICE_EXPORT_GOR },
     292             :     { "com.sun.star.document.ImportGraphicObjectResolver",  SC_SERVICE_IMPORT_GOR },
     293             :     { "com.sun.star.document.ExportEmbeddedObjectResolver", SC_SERVICE_EXPORT_EOR },
     294             :     { "com.sun.star.document.ImportEmbeddedObjectResolver", SC_SERVICE_IMPORT_EOR },
     295             : 
     296             :     { SC_SERVICENAME_VALBIND,               SC_SERVICE_VALBIND },
     297             :     { SC_SERVICENAME_LISTCELLBIND,          SC_SERVICE_LISTCELLBIND },
     298             :     { SC_SERVICENAME_LISTSOURCE,            SC_SERVICE_LISTSOURCE },
     299             :     { SC_SERVICENAME_CELLADDRESS,           SC_SERVICE_CELLADDRESS },
     300             :     { SC_SERVICENAME_RANGEADDRESS,          SC_SERVICE_RANGEADDRESS },
     301             : 
     302             :     { "com.sun.star.sheet.DocumentSettings",SC_SERVICE_SHEETDOCSET },
     303             : 
     304             :     { SC_SERVICENAME_CHDATAPROV,            SC_SERVICE_CHDATAPROV },
     305             :     { SC_SERVICENAME_FORMULAPARS,           SC_SERVICE_FORMULAPARS },
     306             :     { SC_SERVICENAME_OPCODEMAPPER,          SC_SERVICE_OPCODEMAPPER },
     307             :     { "ooo.vba.VBAObjectModuleObjectProvider", SC_SERVICE_VBAOBJECTPROVIDER },
     308             :     { "ooo.vba.VBACodeNameProvider",        SC_SERVICE_VBACODENAMEPROVIDER },
     309             :     { "ooo.vba.VBAGlobals",                 SC_SERVICE_VBAGLOBALS },
     310             : 
     311             :     // case-correct versions of the service names (#i102468#)
     312             :     { "com.sun.star.text.textfield.URL",                SC_SERVICE_URLFIELD },
     313             :     { "com.sun.star.text.textfield.PageNumber",         SC_SERVICE_PAGEFIELD },
     314             :     { "com.sun.star.text.textfield.PageCount",          SC_SERVICE_PAGESFIELD },
     315             :     { "com.sun.star.text.textfield.Date",               SC_SERVICE_DATEFIELD },
     316             :     { "com.sun.star.text.textfield.Time",               SC_SERVICE_TIMEFIELD },
     317             :     { "com.sun.star.text.textfield.DateTime",           SC_SERVICE_EXT_TIMEFIELD },
     318             :     { "com.sun.star.text.textfield.docinfo.Title",      SC_SERVICE_TITLEFIELD },
     319             :     { "com.sun.star.text.textfield.FileName",           SC_SERVICE_FILEFIELD },
     320             :     { "com.sun.star.text.textfield.SheetName",          SC_SERVICE_SHEETFIELD },
     321             :     { "ooo.vba.VBAGlobals",          SC_SERVICE_VBAGLOBALS },
     322             : };
     323             : 
     324             : //
     325             : //  old service names that were in 567 still work in createInstance,
     326             : //  in case some macro is still using them
     327             : //
     328             : 
     329             : static const sal_Char* aOldNames[SC_SERVICE_COUNT] =
     330             :     {
     331             :         "",                                         // SC_SERVICE_SHEET
     332             :         "stardiv.one.text.TextField.URL",           // SC_SERVICE_URLFIELD
     333             :         "stardiv.one.text.TextField.PageNumber",    // SC_SERVICE_PAGEFIELD
     334             :         "stardiv.one.text.TextField.PageCount",     // SC_SERVICE_PAGESFIELD
     335             :         "stardiv.one.text.TextField.Date",          // SC_SERVICE_DATEFIELD
     336             :         "stardiv.one.text.TextField.Time",          // SC_SERVICE_TIMEFIELD
     337             :         "stardiv.one.text.TextField.DocumentTitle", // SC_SERVICE_TITLEFIELD
     338             :         "stardiv.one.text.TextField.FileName",      // SC_SERVICE_FILEFIELD
     339             :         "stardiv.one.text.TextField.SheetName",     // SC_SERVICE_SHEETFIELD
     340             :         "stardiv.one.style.CellStyle",              // SC_SERVICE_CELLSTYLE
     341             :         "stardiv.one.style.PageStyle",              // SC_SERVICE_PAGESTYLE
     342             :         "",                                         // SC_SERVICE_AUTOFORMAT
     343             :         "",                                         // SC_SERVICE_CELLRANGES
     344             :         "",                                         // SC_SERVICE_GRADTAB
     345             :         "",                                         // SC_SERVICE_HATCHTAB
     346             :         "",                                         // SC_SERVICE_BITMAPTAB
     347             :         "",                                         // SC_SERVICE_TRGRADTAB
     348             :         "",                                         // SC_SERVICE_MARKERTAB
     349             :         "",                                         // SC_SERVICE_DASHTAB
     350             :         "",                                         // SC_SERVICE_NUMRULES
     351             :         "",                                         // SC_SERVICE_DOCDEFLTS
     352             :         "",                                         // SC_SERVICE_DRAWDEFLTS
     353             :         "",                                         // SC_SERVICE_DOCSPRSETT
     354             :         "",                                         // SC_SERVICE_DOCCONF
     355             :         "",                                         // SC_SERVICE_IMAP_RECT
     356             :         "",                                         // SC_SERVICE_IMAP_CIRC
     357             :         "",                                         // SC_SERVICE_IMAP_POLY
     358             : 
     359             :         // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
     360             :         "",                                         // SC_SERVICE_EXPORT_GOR
     361             :         "",                                         // SC_SERVICE_IMPORT_GOR
     362             :         "",                                         // SC_SERVICE_EXPORT_EOR
     363             :         "",                                         // SC_SERVICE_IMPORT_EOR
     364             : 
     365             :         "",                                         // SC_SERVICE_VALBIND
     366             :         "",                                         // SC_SERVICE_LISTCELLBIND
     367             :         "",                                         // SC_SERVICE_LISTSOURCE
     368             :         "",                                         // SC_SERVICE_CELLADDRESS
     369             :         "",                                         // SC_SERVICE_RANGEADDRESS
     370             :         "",                                         // SC_SERVICE_SHEETDOCSET
     371             :         "",                                         // SC_SERVICE_CHDATAPROV
     372             :         "",                                         // SC_SERVICE_FORMULAPARS
     373             :         "",                                         // SC_SERVICE_OPCODEMAPPER
     374             :         "",                                         // SC_SERVICE_VBAOBJECTPROVIDER
     375             :         "",                                         // SC_SERVICE_VBACODENAMEPROVIDER
     376             :         "",                                         // SC_SERVICE_VBAGLOBALS
     377             :         "",                                         // SC_SERVICE_EXT_TIMEFIELD
     378             :     };
     379             : 
     380             : 
     381             : 
     382             : 
     383             : //------------------------------------------------------------------------
     384             : 
     385             : //  alles static
     386             : 
     387             : 
     388         748 : sal_uInt16 ScServiceProvider::GetProviderType(const String& rServiceName)
     389             : {
     390         748 :     if (rServiceName.Len())
     391             :     {
     392             :         const sal_uInt16 nEntries =
     393         748 :             sizeof(aProvNamesId) / sizeof(aProvNamesId[0]);
     394       13864 :         for (sal_uInt16 i = 0; i < nEntries; i++)
     395             :         {
     396       13836 :             if (rServiceName.EqualsAscii( aProvNamesId[i].pName ))
     397             :             {
     398         720 :                 return aProvNamesId[i].nType;
     399             :             }
     400             :         }
     401             : 
     402             :         sal_uInt16 i;
     403        1260 :         for (i=0; i<SC_SERVICE_COUNT; i++)
     404             :         {
     405             :             OSL_ENSURE( aOldNames[i], "ScServiceProvider::GetProviderType: no oldname => crash");
     406        1232 :             if (rServiceName.EqualsAscii( aOldNames[i] ))
     407             :             {
     408             :                 OSL_FAIL("old service name used");
     409           0 :                 return i;
     410             :             }
     411             :         }
     412             :     }
     413          28 :     return SC_SERVICE_INVALID;
     414             : }
     415             : 
     416             : namespace {
     417             : 
     418         214 : sal_Int32 getFieldType(sal_uInt16 nOldType)
     419             : {
     420         214 :     switch (nOldType)
     421             :     {
     422             :         case SC_SERVICE_URLFIELD:
     423           0 :             return text::textfield::Type::URL;
     424             :         case SC_SERVICE_PAGEFIELD:
     425          63 :             return text::textfield::Type::PAGE;
     426             :         case SC_SERVICE_PAGESFIELD:
     427          22 :             return text::textfield::Type::PAGES;
     428             :         case SC_SERVICE_DATEFIELD:
     429           0 :             return text::textfield::Type::DATE;
     430             :         case SC_SERVICE_TIMEFIELD:
     431           0 :             return text::textfield::Type::TIME;
     432             :         case SC_SERVICE_EXT_TIMEFIELD:
     433          44 :             return text::textfield::Type::EXTENDED_TIME;
     434             :         case SC_SERVICE_TITLEFIELD:
     435          22 :             return text::textfield::Type::DOCINFO_TITLE;
     436             :         case SC_SERVICE_FILEFIELD:
     437           0 :             return text::textfield::Type::EXTENDED_FILE;
     438             :         case SC_SERVICE_SHEETFIELD:
     439          63 :             return text::textfield::Type::TABLE;
     440             :         default:
     441             :             ;
     442             :     }
     443             : 
     444           0 :     return text::textfield::Type::URL; // default to URL for no reason whatsoever.
     445             : }
     446             : 
     447             : }
     448             : 
     449         683 : uno::Reference<uno::XInterface> ScServiceProvider::MakeInstance(
     450             :                                     sal_uInt16 nType, ScDocShell* pDocShell )
     451             : {
     452         683 :     uno::Reference<uno::XInterface> xRet;
     453         683 :     switch (nType)
     454             :     {
     455             :         case SC_SERVICE_SHEET:
     456             :             //  noch nicht eingefuegt - DocShell=Null
     457           0 :             xRet.set((sheet::XSpreadsheet*)new ScTableSheetObj(NULL,0));
     458           0 :             break;
     459             :         case SC_SERVICE_URLFIELD:
     460             :         case SC_SERVICE_PAGEFIELD:
     461             :         case SC_SERVICE_PAGESFIELD:
     462             :         case SC_SERVICE_DATEFIELD:
     463             :         case SC_SERVICE_TIMEFIELD:
     464             :         case SC_SERVICE_EXT_TIMEFIELD:
     465             :         case SC_SERVICE_TITLEFIELD:
     466             :         case SC_SERVICE_FILEFIELD:
     467             :         case SC_SERVICE_SHEETFIELD:
     468             :         {
     469         214 :             uno::Reference<text::XTextRange> xNullContent;
     470             :             xRet.set(static_cast<text::XTextField*>(
     471         214 :                 new ScEditFieldObj(xNullContent, NULL, getFieldType(nType), ESelection())));
     472             :         }
     473         214 :         break;
     474             :         case SC_SERVICE_CELLSTYLE:
     475          51 :             xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PARA, String() ));
     476          51 :             break;
     477             :         case SC_SERVICE_PAGESTYLE:
     478          25 :             xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PAGE, String() ));
     479          25 :             break;
     480             :         case SC_SERVICE_AUTOFORMAT:
     481           0 :             xRet.set((container::XIndexAccess*)new ScAutoFormatObj( SC_AFMTOBJ_INVALID ));
     482           0 :             break;
     483             :         case SC_SERVICE_CELLRANGES:
     484             :             //  wird nicht eingefuegt, sondern gefuellt
     485             :             //  -> DocShell muss gesetzt sein, aber leere Ranges
     486         195 :             if (pDocShell)
     487         195 :                 xRet.set((sheet::XSheetCellRanges*)new ScCellRangesObj( pDocShell, ScRangeList() ));
     488         195 :             break;
     489             : 
     490             :         case SC_SERVICE_DOCDEFLTS:
     491          24 :             if (pDocShell)
     492          24 :                 xRet.set((beans::XPropertySet*)new ScDocDefaultsObj( pDocShell ));
     493          24 :             break;
     494             :         case SC_SERVICE_DRAWDEFLTS:
     495           1 :             if (pDocShell)
     496           1 :                 xRet.set((beans::XPropertySet*)new ScDrawDefaultsObj( pDocShell ));
     497           1 :             break;
     498             : 
     499             :         //  Drawing layer tables are not in SvxUnoDrawMSFactory,
     500             :         //  because SvxUnoDrawMSFactory doesn't have a SdrModel pointer.
     501             :         //  Drawing layer is always allocated if not there (MakeDrawLayer).
     502             : 
     503             :         case SC_SERVICE_GRADTAB:
     504           2 :             if (pDocShell)
     505           2 :                 xRet.set(SvxUnoGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
     506           2 :             break;
     507             :         case SC_SERVICE_HATCHTAB:
     508           2 :             if (pDocShell)
     509           2 :                 xRet.set(SvxUnoHatchTable_createInstance( pDocShell->MakeDrawLayer() ));
     510           2 :             break;
     511             :         case SC_SERVICE_BITMAPTAB:
     512           2 :             if (pDocShell)
     513           2 :                 xRet.set(SvxUnoBitmapTable_createInstance( pDocShell->MakeDrawLayer() ));
     514           2 :             break;
     515             :         case SC_SERVICE_TRGRADTAB:
     516           2 :             if (pDocShell)
     517           2 :                 xRet.set(SvxUnoTransGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
     518           2 :             break;
     519             :         case SC_SERVICE_MARKERTAB:
     520           4 :             if (pDocShell)
     521           4 :                 xRet.set(SvxUnoMarkerTable_createInstance( pDocShell->MakeDrawLayer() ));
     522           4 :             break;
     523             :         case SC_SERVICE_DASHTAB:
     524           2 :             if (pDocShell)
     525           2 :                 xRet.set(SvxUnoDashTable_createInstance( pDocShell->MakeDrawLayer() ));
     526           2 :             break;
     527             :         case SC_SERVICE_NUMRULES:
     528           0 :             if (pDocShell)
     529           0 :                 xRet.set(SvxCreateNumRule( pDocShell->MakeDrawLayer() ));
     530           0 :             break;
     531             :         case SC_SERVICE_DOCSPRSETT:
     532             :         case SC_SERVICE_SHEETDOCSET:
     533             :         case SC_SERVICE_DOCCONF:
     534          25 :             if (pDocShell)
     535          25 :                 xRet.set((beans::XPropertySet*)new ScDocumentConfiguration(pDocShell));
     536          25 :             break;
     537             : 
     538             :         case SC_SERVICE_IMAP_RECT:
     539           0 :             xRet.set(SvUnoImageMapRectangleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
     540           0 :             break;
     541             :         case SC_SERVICE_IMAP_CIRC:
     542           0 :             xRet.set(SvUnoImageMapCircleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
     543           0 :             break;
     544             :         case SC_SERVICE_IMAP_POLY:
     545           0 :             xRet.set(SvUnoImageMapPolygonObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
     546           0 :             break;
     547             : 
     548             :         // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
     549             :         case SC_SERVICE_EXPORT_GOR:
     550           4 :             xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_WRITE ));
     551           4 :             break;
     552             : 
     553             :         case SC_SERVICE_IMPORT_GOR:
     554          44 :             xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_READ ));
     555          44 :             break;
     556             : 
     557             :         case SC_SERVICE_EXPORT_EOR:
     558           4 :             if (pDocShell)
     559           4 :                 xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_WRITE ));
     560           4 :             break;
     561             : 
     562             :         case SC_SERVICE_IMPORT_EOR:
     563          44 :             if (pDocShell)
     564          44 :                 xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_READ ));
     565          44 :             break;
     566             : 
     567             :         case SC_SERVICE_VALBIND:
     568             :         case SC_SERVICE_LISTCELLBIND:
     569           4 :             if (pDocShell)
     570             :             {
     571           4 :                 sal_Bool bListPos = ( nType == SC_SERVICE_LISTCELLBIND );
     572           4 :                 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
     573           4 :                 xRet.set(*new calc::OCellValueBinding( xDoc, bListPos ));
     574             :             }
     575           4 :             break;
     576             :         case SC_SERVICE_LISTSOURCE:
     577           0 :             if (pDocShell)
     578             :             {
     579           0 :                 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
     580           0 :                 xRet.set(*new calc::OCellListSource( xDoc ));
     581             :             }
     582           0 :             break;
     583             :         case SC_SERVICE_CELLADDRESS:
     584             :         case SC_SERVICE_RANGEADDRESS:
     585           0 :             if (pDocShell)
     586             :             {
     587           0 :                 sal_Bool bRange = ( nType == SC_SERVICE_RANGEADDRESS );
     588           0 :                 xRet.set(*new ScAddressConversionObj( pDocShell, bRange ));
     589             :             }
     590           0 :             break;
     591             : 
     592             :         case SC_SERVICE_CHDATAPROV:
     593           3 :             if (pDocShell && pDocShell->GetDocument())
     594           3 :                 xRet = *new ScChart2DataProvider( pDocShell->GetDocument() );
     595           3 :             break;
     596             : 
     597             :         case SC_SERVICE_FORMULAPARS:
     598          11 :             if (pDocShell)
     599          11 :                 xRet.set(static_cast<sheet::XFormulaParser*>(new ScFormulaParserObj( pDocShell )));
     600          11 :             break;
     601             : 
     602             :         case SC_SERVICE_OPCODEMAPPER:
     603          11 :             if (pDocShell)
     604             :             {
     605          11 :                 ScDocument* pDoc = pDocShell->GetDocument();
     606          11 :                 ScAddress aAddress;
     607          11 :                 ScCompiler* pComp = new ScCompiler(pDoc,aAddress);
     608          11 :                 pComp->SetGrammar( pDoc->GetGrammar() );
     609          11 :                 xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(new ScFormulaOpCodeMapperObj(::std::auto_ptr<formula::FormulaCompiler> (pComp))));
     610             :                 break;
     611             :             }
     612             : #ifndef DISABLE_SCRIPTING
     613             :         case SC_SERVICE_VBAOBJECTPROVIDER:
     614           3 :             if (pDocShell && pDocShell->GetDocument()->IsInVBAMode())
     615             :             {
     616             :                 OSL_TRACE("**** creating VBA Object mapper");
     617           6 :                 xRet.set(static_cast<container::XNameAccess*>(new ScVbaObjectForCodeNameProvider( pDocShell )));
     618             :             }
     619           0 :             break;
     620             :         case SC_SERVICE_VBACODENAMEPROVIDER:
     621           3 :             if ( pDocShell && ooo::vba::isAlienExcelDoc( *pDocShell ) && isInVBAMode( *pDocShell ) )
     622             :             {
     623             :                 OSL_TRACE("**** creating VBA Object provider");
     624           0 :                 xRet.set(static_cast<document::XCodeNameQuery*>(new ScVbaCodeNameProvider(*pDocShell)));
     625             :             }
     626           3 :             break;
     627             :         case SC_SERVICE_VBAGLOBALS:
     628           3 :             if (pDocShell)
     629             :             {
     630           3 :                 uno::Any aGlobs;
     631           3 :                 if ( !pDocShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aGlobs ) )
     632             :                 {
     633           3 :                     uno::Sequence< uno::Any > aArgs(1);
     634           3 :                     aArgs[ 0 ] <<= pDocShell->GetModel();
     635           3 :                     xRet = ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.excel.Globals" ) ), aArgs );
     636           3 :                     pDocShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", uno::Any( xRet ) );
     637           3 :                     BasicManager* pAppMgr = SFX_APP()->GetBasicManager();
     638           3 :                     if ( pAppMgr )
     639           3 :                         pAppMgr->SetGlobalUNOConstant( "ThisExcelDoc", aArgs[ 0 ] );
     640             : 
     641             :                     // create the VBA document event processor
     642             :                     uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents(
     643           3 :                         ::ooo::vba::createVBAUnoAPIServiceWithArgs( pDocShell, "com.sun.star.script.vba.VBASpreadsheetEventProcessor", aArgs ), uno::UNO_QUERY );
     644           0 :                     pDocShell->GetDocument()->SetVbaEventProcessor( xVbaEvents );
     645           3 :                 }
     646             :             }
     647           0 :         break;
     648             : #endif
     649             :     }
     650             : 
     651         683 :     return xRet;
     652             : }
     653             : 
     654           4 : uno::Sequence<rtl::OUString> ScServiceProvider::GetAllServiceNames()
     655             : {
     656           4 :     const sal_uInt16 nEntries = sizeof(aProvNamesId) / sizeof(aProvNamesId[0]);
     657           4 :     uno::Sequence<rtl::OUString> aRet(nEntries);
     658           4 :     rtl::OUString* pArray = aRet.getArray();
     659         220 :     for (sal_uInt16 i = 0; i < nEntries; i++)
     660             :     {
     661         216 :         pArray[i] = rtl::OUString::createFromAscii( aProvNamesId[i].pName );
     662             :     }
     663           4 :     return aRet;
     664             : }
     665             : 
     666             : 
     667             : 
     668             : 
     669             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10