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

Generated by: LCOV version 1.10