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

Generated by: LCOV version 1.10