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

Generated by: LCOV version 1.11