LCOV - code coverage report
Current view: top level - sc/source/ui/unoobj - servuno.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 246 0.0 %
Date: 2014-04-14 Functions: 0 18 0.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           0 : bool isInVBAMode( ScDocShell& rDocSh )
      70             : {
      71           0 :     uno::Reference<script::XLibraryContainer> xLibContainer = rDocSh.GetBasicContainer();
      72           0 :     uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY );
      73           0 :     if ( xVBACompat.is() )
      74           0 :         return xVBACompat->getVBACompatibilityMode();
      75           0 :     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           0 :     ScVbaObjectForCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell )
      85             :     {
      86           0 :         ScDocument* pDoc = mpDocShell->GetDocument();
      87           0 :         if ( !pDoc )
      88           0 :             throw uno::RuntimeException("", uno::Reference< uno::XInterface >() );
      89             : 
      90           0 :         uno::Sequence< uno::Any > aArgs(2);
      91             :         // access the application object ( parent for workbook )
      92           0 :         aArgs[0] = uno::Any( ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.Application", uno::Sequence< uno::Any >() ) );
      93           0 :         aArgs[1] = uno::Any( mpDocShell->GetModel() );
      94           0 :         maWorkbook <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Workbook", aArgs );
      95           0 :     }
      96             : 
      97           0 :     virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw (::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE
      98             :     {
      99           0 :         SolarMutexGuard aGuard;
     100           0 :         maCachedObject = uno::Any(); // clear cached object
     101             : 
     102           0 :         ScDocument* pDoc = mpDocShell->GetDocument();
     103           0 :         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           0 :         if( aName.equalsIgnoreAsciiCase( pDoc->GetCodeName() ) )
     108           0 :             maCachedObject = maWorkbook;
     109             :         else
     110             :         {
     111           0 :             OUString sCodeName;
     112           0 :             SCTAB nCount = pDoc->GetTableCount();
     113           0 :             for( SCTAB i = 0; i < nCount; i++ )
     114             :             {
     115           0 :                 pDoc->GetCodeName( i, sCodeName );
     116             :                 // aName is generated from the stream name which can be different ( case-wise )
     117             :                 // from the code name
     118           0 :                 if( sCodeName.equalsIgnoreAsciiCase( aName ) )
     119             :                 {
     120           0 :                     OUString sSheetName;
     121           0 :                     if( pDoc->GetName( i, sSheetName ) )
     122             :                     {
     123           0 :                         uno::Reference< frame::XModel > xModel( mpDocShell->GetModel() );
     124           0 :                         uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
     125           0 :                         uno::Reference<sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
     126           0 :                         uno::Reference< container::XIndexAccess > xIndexAccess( xSheets, uno::UNO_QUERY_THROW );
     127           0 :                         uno::Reference< sheet::XSpreadsheet > xSheet( xIndexAccess->getByIndex( i ), uno::UNO_QUERY_THROW );
     128           0 :                         uno::Sequence< uno::Any > aArgs(3);
     129           0 :                         aArgs[0] = maWorkbook;
     130           0 :                         aArgs[1] = uno::Any( xModel );
     131           0 :                         aArgs[2] = uno::Any( OUString( sSheetName ) );
     132             :                         // use the convience function
     133           0 :                         maCachedObject <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Worksheet", aArgs );
     134           0 :                         break;
     135           0 :                     }
     136             :                 }
     137           0 :             }
     138             :         }
     139           0 :         return maCachedObject.hasValue();
     140             : 
     141             :     }
     142           0 :     ::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           0 :         SolarMutexGuard aGuard;
     145             :         OSL_TRACE("ScVbaObjectForCodeNameProvider::getByName( %s )",
     146             :             OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr() );
     147           0 :         if ( !hasByName( aName ) )
     148           0 :             throw ::com::sun::star::container::NoSuchElementException();
     149           0 :         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           0 : class ScVbaCodeNameProvider : public ::cppu::WeakImplHelper1< document::XCodeNameQuery >
     176             : {
     177             :     ScDocShell& mrDocShell;
     178             : public:
     179           0 :     ScVbaCodeNameProvider( ScDocShell& rDocShell ) : mrDocShell(rDocShell) {}
     180             :     // XCodeNameQuery
     181           0 :     OUString SAL_CALL getCodeNameForObject( const uno::Reference< uno::XInterface >& xIf ) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE
     182             :     {
     183           0 :         SolarMutexGuard aGuard;
     184           0 :         OUString sCodeName;
     185             : 
     186             :         // need to find the page ( and index )  for this control
     187           0 :         uno::Reference< drawing::XDrawPagesSupplier > xSupplier( mrDocShell.GetModel(), uno::UNO_QUERY_THROW );
     188           0 :         uno::Reference< container::XIndexAccess > xIndex( xSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
     189           0 :         sal_Int32 nLen = xIndex->getCount();
     190           0 :         bool bMatched = false;
     191           0 :         for ( sal_Int32 index = 0; index < nLen; ++index )
     192             :         {
     193             :             try
     194             :             {
     195           0 :                 uno::Reference< form::XFormsSupplier >  xFormSupplier( xIndex->getByIndex( index ), uno::UNO_QUERY_THROW );
     196           0 :                 uno::Reference< container::XIndexAccess > xFormIndex( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
     197             :                 // get the www-standard container
     198           0 :                 uno::Reference< container::XIndexAccess > xFormControls( xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW );
     199           0 :                 sal_Int32 nCntrls = xFormControls->getCount();
     200           0 :                 for( sal_Int32 cIndex = 0; cIndex < nCntrls; ++cIndex )
     201             :                 {
     202           0 :                     uno::Reference< uno::XInterface > xControl( xFormControls->getByIndex( cIndex ), uno::UNO_QUERY_THROW );
     203           0 :                     bMatched = ( xControl == xIf );
     204           0 :                     if ( bMatched )
     205             :                     {
     206           0 :                         OUString sName;
     207           0 :                         mrDocShell.GetDocument()->GetCodeName( static_cast<SCTAB>( index ), sName );
     208           0 :                         sCodeName = sName;
     209             :                     }
     210           0 :                 }
     211             :             }
     212           0 :             catch( uno::Exception& ) {}
     213           0 :             if ( bMatched )
     214           0 :                 break;
     215             :         }
     216             :         // Probably should throw here ( if !bMatched )
     217           0 :          return sCodeName;
     218             :     }
     219             : 
     220           0 :     OUString SAL_CALL getCodeNameForContainer( const uno::Reference<uno::XInterface>& xContainer )
     221             :             throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE
     222             :     {
     223           0 :         SolarMutexGuard aGuard;
     224           0 :         uno::Reference<drawing::XDrawPagesSupplier> xSupplier(mrDocShell.GetModel(), uno::UNO_QUERY_THROW);
     225           0 :         uno::Reference<container::XIndexAccess> xIndex(xSupplier->getDrawPages(), uno::UNO_QUERY_THROW);
     226             : 
     227           0 :         for (sal_Int32 i = 0, n = xIndex->getCount(); i < n; ++i)
     228             :         {
     229             :             try
     230             :             {
     231           0 :                 uno::Reference<form::XFormsSupplier>  xFormSupplier(xIndex->getByIndex(i), uno::UNO_QUERY_THROW);
     232           0 :                 uno::Reference<container::XIndexAccess> xFormIndex(xFormSupplier->getForms(), uno::UNO_QUERY_THROW);
     233             :                 // get the www-standard container
     234           0 :                 uno::Reference<container::XIndexAccess> xFormControls(xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW);
     235           0 :                 if (xFormControls == xContainer)
     236             :                 {
     237           0 :                     OUString aName;
     238           0 :                     if (mrDocShell.GetDocument()->GetCodeName(static_cast<SCTAB>(i), aName))
     239           0 :                         return aName;
     240           0 :                 }
     241             :             }
     242           0 :             catch( uno::Exception& ) {}
     243             :         }
     244           0 :         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           0 : sal_uInt16 ScServiceProvider::GetProviderType(const OUString& rServiceName)
     382             : {
     383           0 :     if (!rServiceName.isEmpty())
     384             :     {
     385             :         const sal_uInt16 nEntries =
     386           0 :             sizeof(aProvNamesId) / sizeof(aProvNamesId[0]);
     387           0 :         for (sal_uInt16 i = 0; i < nEntries; i++)
     388             :         {
     389           0 :             if (rServiceName.equalsAscii( aProvNamesId[i].pName ))
     390             :             {
     391           0 :                 return aProvNamesId[i].nType;
     392             :             }
     393             :         }
     394             : 
     395             :         sal_uInt16 i;
     396           0 :         for (i=0; i<SC_SERVICE_COUNT; i++)
     397             :         {
     398             :             OSL_ENSURE( aOldNames[i], "ScServiceProvider::GetProviderType: no oldname => crash");
     399           0 :             if (rServiceName.equalsAscii( aOldNames[i] ))
     400             :             {
     401             :                 OSL_FAIL("old service name used");
     402           0 :                 return i;
     403             :             }
     404             :         }
     405             :     }
     406           0 :     return SC_SERVICE_INVALID;
     407             : }
     408             : 
     409             : namespace {
     410             : 
     411           0 : sal_Int32 getFieldType(sal_uInt16 nOldType)
     412             : {
     413           0 :     switch (nOldType)
     414             :     {
     415             :         case SC_SERVICE_URLFIELD:
     416           0 :             return text::textfield::Type::URL;
     417             :         case SC_SERVICE_PAGEFIELD:
     418           0 :             return text::textfield::Type::PAGE;
     419             :         case SC_SERVICE_PAGESFIELD:
     420           0 :             return text::textfield::Type::PAGES;
     421             :         case SC_SERVICE_DATEFIELD:
     422           0 :             return text::textfield::Type::DATE;
     423             :         case SC_SERVICE_TIMEFIELD:
     424           0 :             return text::textfield::Type::TIME;
     425             :         case SC_SERVICE_EXT_TIMEFIELD:
     426           0 :             return text::textfield::Type::EXTENDED_TIME;
     427             :         case SC_SERVICE_TITLEFIELD:
     428           0 :             return text::textfield::Type::DOCINFO_TITLE;
     429             :         case SC_SERVICE_FILEFIELD:
     430           0 :             return text::textfield::Type::EXTENDED_FILE;
     431             :         case SC_SERVICE_SHEETFIELD:
     432           0 :             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           0 : uno::Reference<uno::XInterface> ScServiceProvider::MakeInstance(
     443             :                                     sal_uInt16 nType, ScDocShell* pDocShell )
     444             : {
     445           0 :     uno::Reference<uno::XInterface> xRet;
     446           0 :     switch (nType)
     447             :     {
     448             :         case SC_SERVICE_SHEET:
     449             :             //  noch nicht eingefuegt - DocShell=Null
     450           0 :             xRet.set((sheet::XSpreadsheet*)new ScTableSheetObj(NULL,0));
     451           0 :             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           0 :             uno::Reference<text::XTextRange> xNullContent;
     463             :             xRet.set(static_cast<text::XTextField*>(
     464           0 :                 new ScEditFieldObj(xNullContent, NULL, getFieldType(nType), ESelection())));
     465             :         }
     466           0 :         break;
     467             :         case SC_SERVICE_CELLSTYLE:
     468           0 :             xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PARA, OUString() ));
     469           0 :             break;
     470             :         case SC_SERVICE_PAGESTYLE:
     471           0 :             xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PAGE, OUString() ));
     472           0 :             break;
     473             :         case SC_SERVICE_AUTOFORMAT:
     474           0 :             xRet.set((container::XIndexAccess*)new ScAutoFormatObj( SC_AFMTOBJ_INVALID ));
     475           0 :             break;
     476             :         case SC_SERVICE_CELLRANGES:
     477             :             //  wird nicht eingefuegt, sondern gefuellt
     478             :             //  -> DocShell muss gesetzt sein, aber leere Ranges
     479           0 :             if (pDocShell)
     480           0 :                 xRet.set((sheet::XSheetCellRanges*)new ScCellRangesObj( pDocShell, ScRangeList() ));
     481           0 :             break;
     482             : 
     483             :         case SC_SERVICE_DOCDEFLTS:
     484           0 :             if (pDocShell)
     485           0 :                 xRet.set((beans::XPropertySet*)new ScDocDefaultsObj( pDocShell ));
     486           0 :             break;
     487             :         case SC_SERVICE_DRAWDEFLTS:
     488           0 :             if (pDocShell)
     489           0 :                 xRet.set((beans::XPropertySet*)new ScDrawDefaultsObj( pDocShell ));
     490           0 :             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           0 :             if (pDocShell)
     498           0 :                 xRet.set(SvxUnoGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
     499           0 :             break;
     500             :         case SC_SERVICE_HATCHTAB:
     501           0 :             if (pDocShell)
     502           0 :                 xRet.set(SvxUnoHatchTable_createInstance( pDocShell->MakeDrawLayer() ));
     503           0 :             break;
     504             :         case SC_SERVICE_BITMAPTAB:
     505           0 :             if (pDocShell)
     506           0 :                 xRet.set(SvxUnoBitmapTable_createInstance( pDocShell->MakeDrawLayer() ));
     507           0 :             break;
     508             :         case SC_SERVICE_TRGRADTAB:
     509           0 :             if (pDocShell)
     510           0 :                 xRet.set(SvxUnoTransGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
     511           0 :             break;
     512             :         case SC_SERVICE_MARKERTAB:
     513           0 :             if (pDocShell)
     514           0 :                 xRet.set(SvxUnoMarkerTable_createInstance( pDocShell->MakeDrawLayer() ));
     515           0 :             break;
     516             :         case SC_SERVICE_DASHTAB:
     517           0 :             if (pDocShell)
     518           0 :                 xRet.set(SvxUnoDashTable_createInstance( pDocShell->MakeDrawLayer() ));
     519           0 :             break;
     520             :         case SC_SERVICE_NUMRULES:
     521           0 :             if (pDocShell)
     522           0 :                 xRet.set(SvxCreateNumRule( pDocShell->MakeDrawLayer() ));
     523           0 :             break;
     524             :         case SC_SERVICE_DOCSPRSETT:
     525             :         case SC_SERVICE_SHEETDOCSET:
     526             :         case SC_SERVICE_DOCCONF:
     527           0 :             if (pDocShell)
     528           0 :                 xRet.set((beans::XPropertySet*)new ScDocumentConfiguration(pDocShell));
     529           0 :             break;
     530             : 
     531             :         case SC_SERVICE_IMAP_RECT:
     532           0 :             xRet.set(SvUnoImageMapRectangleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
     533           0 :             break;
     534             :         case SC_SERVICE_IMAP_CIRC:
     535           0 :             xRet.set(SvUnoImageMapCircleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
     536           0 :             break;
     537             :         case SC_SERVICE_IMAP_POLY:
     538           0 :             xRet.set(SvUnoImageMapPolygonObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
     539           0 :             break;
     540             : 
     541             :         // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
     542             :         case SC_SERVICE_EXPORT_GOR:
     543           0 :             xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_WRITE ));
     544           0 :             break;
     545             : 
     546             :         case SC_SERVICE_IMPORT_GOR:
     547           0 :             xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_READ ));
     548           0 :             break;
     549             : 
     550             :         case SC_SERVICE_EXPORT_EOR:
     551           0 :             if (pDocShell)
     552           0 :                 xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_WRITE ));
     553           0 :             break;
     554             : 
     555             :         case SC_SERVICE_IMPORT_EOR:
     556           0 :             if (pDocShell)
     557           0 :                 xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_READ ));
     558           0 :             break;
     559             : 
     560             :         case SC_SERVICE_VALBIND:
     561             :         case SC_SERVICE_LISTCELLBIND:
     562           0 :             if (pDocShell)
     563             :             {
     564           0 :                 sal_Bool bListPos = ( nType == SC_SERVICE_LISTCELLBIND );
     565           0 :                 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
     566           0 :                 xRet.set(*new calc::OCellValueBinding( xDoc, bListPos ));
     567             :             }
     568           0 :             break;
     569             :         case SC_SERVICE_LISTSOURCE:
     570           0 :             if (pDocShell)
     571             :             {
     572           0 :                 uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
     573           0 :                 xRet.set(*new calc::OCellListSource( xDoc ));
     574             :             }
     575           0 :             break;
     576             :         case SC_SERVICE_CELLADDRESS:
     577             :         case SC_SERVICE_RANGEADDRESS:
     578           0 :             if (pDocShell)
     579             :             {
     580           0 :                 bool bIsRange = ( nType == SC_SERVICE_RANGEADDRESS );
     581           0 :                 xRet.set(*new ScAddressConversionObj( pDocShell, bIsRange ));
     582             :             }
     583           0 :             break;
     584             : 
     585             :         case SC_SERVICE_CHDATAPROV:
     586           0 :             if (pDocShell && pDocShell->GetDocument())
     587           0 :                 xRet = *new ScChart2DataProvider( pDocShell->GetDocument() );
     588           0 :             break;
     589             : 
     590             :         case SC_SERVICE_FORMULAPARS:
     591           0 :             if (pDocShell)
     592           0 :                 xRet.set(static_cast<sheet::XFormulaParser*>(new ScFormulaParserObj( pDocShell )));
     593           0 :             break;
     594             : 
     595             :         case SC_SERVICE_OPCODEMAPPER:
     596           0 :             if (pDocShell)
     597             :             {
     598           0 :                 ScDocument* pDoc = pDocShell->GetDocument();
     599           0 :                 ScAddress aAddress;
     600           0 :                 ScCompiler* pComp = new ScCompiler(pDoc,aAddress);
     601           0 :                 pComp->SetGrammar( pDoc->GetGrammar() );
     602             :                 SAL_WNODEPRECATED_DECLARATIONS_PUSH
     603           0 :                 xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(new ScFormulaOpCodeMapperObj(::std::auto_ptr<formula::FormulaCompiler> (pComp))));
     604             :                 SAL_WNODEPRECATED_DECLARATIONS_POP
     605           0 :                 break;
     606             :             }
     607             : #ifndef DISABLE_SCRIPTING
     608             :         case SC_SERVICE_VBAOBJECTPROVIDER:
     609           0 :             if (pDocShell && pDocShell->GetDocument()->IsInVBAMode())
     610             :             {
     611             :                 OSL_TRACE("**** creating VBA Object mapper");
     612           0 :                 xRet.set(static_cast<container::XNameAccess*>(new ScVbaObjectForCodeNameProvider( pDocShell )));
     613             :             }
     614           0 :             break;
     615             :         case SC_SERVICE_VBACODENAMEPROVIDER:
     616           0 :             if ( pDocShell && isInVBAMode( *pDocShell ) )
     617             :             {
     618             :                 OSL_TRACE("**** creating VBA Object provider");
     619           0 :                 xRet.set(static_cast<document::XCodeNameQuery*>(new ScVbaCodeNameProvider(*pDocShell)));
     620             :             }
     621           0 :             break;
     622             :         case SC_SERVICE_VBAGLOBALS:
     623           0 :             if (pDocShell)
     624             :             {
     625           0 :                 uno::Any aGlobs;
     626           0 :                 if ( !pDocShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aGlobs ) )
     627             :                 {
     628           0 :                     uno::Sequence< uno::Any > aArgs(1);
     629           0 :                     aArgs[ 0 ] <<= pDocShell->GetModel();
     630           0 :                     xRet = ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( OUString( "ooo.vba.excel.Globals" ), aArgs );
     631           0 :                     pDocShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", uno::Any( xRet ) );
     632           0 :                     BasicManager* pAppMgr = SFX_APP()->GetBasicManager();
     633           0 :                     if ( pAppMgr )
     634           0 :                         pAppMgr->SetGlobalUNOConstant( "ThisExcelDoc", aArgs[ 0 ] );
     635             : 
     636             :                     // create the VBA document event processor
     637             :                     uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents(
     638           0 :                         ::ooo::vba::createVBAUnoAPIServiceWithArgs( pDocShell, "com.sun.star.script.vba.VBASpreadsheetEventProcessor", aArgs ), uno::UNO_QUERY );
     639           0 :                     pDocShell->GetDocument()->SetVbaEventProcessor( xVbaEvents );
     640           0 :                 }
     641             :             }
     642           0 :         break;
     643             : #endif
     644             :     }
     645             : 
     646           0 :     return xRet;
     647             : }
     648             : 
     649           0 : uno::Sequence<OUString> ScServiceProvider::GetAllServiceNames()
     650             : {
     651           0 :     const sal_uInt16 nEntries = sizeof(aProvNamesId) / sizeof(aProvNamesId[0]);
     652           0 :     uno::Sequence<OUString> aRet(nEntries);
     653           0 :     OUString* pArray = aRet.getArray();
     654           0 :     for (sal_uInt16 i = 0; i < nEntries; i++)
     655             :     {
     656           0 :         pArray[i] = OUString::createFromAscii( aProvNamesId[i].pName );
     657             :     }
     658           0 :     return aRet;
     659             : }
     660             : 
     661             : 
     662             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10