LCOV - code coverage report
Current view: top level - vbahelper/source/vbahelper - vbacommandbars.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 101 0.0 %
Date: 2012-08-25 Functions: 0 16 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 204 0.0 %

           Branch data     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                 :            : #include <com/sun/star/lang/XServiceInfo.hpp>
      20                 :            : #include <com/sun/star/frame/XDesktop.hpp>
      21                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      22                 :            : #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
      23                 :            : #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
      24                 :            : #include <com/sun/star/ui/XModuleUIConfigurationManager.hpp>
      25                 :            : #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
      26                 :            : #include <ooo/vba/office/MsoBarType.hpp>
      27                 :            : 
      28                 :            : #include "vbacommandbars.hxx"
      29                 :            : #include "vbacommandbar.hxx"
      30                 :            : 
      31                 :            : using namespace com::sun::star;
      32                 :            : using namespace ooo::vba;
      33                 :            : 
      34                 :            : 
      35                 :            : typedef ::cppu::WeakImplHelper1< container::XEnumeration > CommandBarEnumeration_BASE;
      36                 :            : 
      37 [ #  # ][ #  # ]:          0 : class CommandBarEnumeration : public CommandBarEnumeration_BASE
                 [ #  # ]
      38                 :            : {
      39                 :            :     uno::Reference< XHelperInterface > m_xParent;
      40                 :            :     uno::Reference< uno::XComponentContext > m_xContext;
      41                 :            :     VbaCommandBarHelperRef m_pCBarHelper;
      42                 :            :     uno::Sequence< rtl::OUString > m_sNames;
      43                 :            :     sal_Int32 m_nCurrentPosition;
      44                 :            : public:
      45 [ #  # ][ #  # ]:          0 :     CommandBarEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, VbaCommandBarHelperRef pHelper) throw ( uno::RuntimeException ) : m_xParent( xParent ), m_xContext( xContext ), m_pCBarHelper( pHelper ) , m_nCurrentPosition( 0 )
      46                 :            :     {
      47         [ #  # ]:          0 :         uno::Reference< container::XNameAccess > xNameAccess = m_pCBarHelper->getPersistentWindowState();
      48 [ #  # ][ #  # ]:          0 :         m_sNames = xNameAccess->getElementNames();
         [ #  # ][ #  # ]
      49                 :          0 :     }
      50                 :          0 :     virtual sal_Bool SAL_CALL hasMoreElements() throw ( uno::RuntimeException )
      51                 :            :     {
      52         [ #  # ]:          0 :         if( m_nCurrentPosition < m_sNames.getLength() )
      53                 :          0 :             return sal_True;
      54                 :          0 :         return sal_False;
      55                 :            :     }
      56                 :          0 :     virtual uno::Any SAL_CALL nextElement() throw ( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
      57                 :            :     {
      58                 :            :         // FIXME: should be add menubar
      59         [ #  # ]:          0 :         if( hasMoreElements() )
      60                 :            :         {
      61         [ #  # ]:          0 :             rtl::OUString sResourceUrl( m_sNames[ m_nCurrentPosition++ ] );
      62         [ #  # ]:          0 :             if( sResourceUrl.indexOf( "private:resource/toolbar/" ) != -1 )
      63                 :            :             {
      64         [ #  # ]:          0 :                 uno::Reference< container::XIndexAccess > xCBarSetting = m_pCBarHelper->getSettings( sResourceUrl );
      65 [ #  # ][ #  # ]:          0 :                 uno::Reference< XCommandBar > xCommandBar( new ScVbaCommandBar( m_xParent, m_xContext, m_pCBarHelper, xCBarSetting, sResourceUrl, sal_False, sal_False ) );
         [ #  # ][ #  # ]
                 [ #  # ]
      66                 :            :              }
      67                 :            :              else
      68 [ #  # ][ #  # ]:          0 :                 return nextElement();
      69                 :            :         }
      70                 :            :         else
      71         [ #  # ]:          0 :             throw container::NoSuchElementException();
      72                 :          0 :         return uno::Any();
      73                 :            :     }
      74                 :            : };
      75                 :            : 
      76         [ #  # ]:          0 : ScVbaCommandBars::ScVbaCommandBars( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess, const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) : CommandBars_BASE( xParent, xContext, xIndexAccess )
      77                 :            : {
      78 [ #  # ][ #  # ]:          0 :     m_pCBarHelper.reset( new VbaCommandBarHelper( mxContext, xModel ) );
                 [ #  # ]
      79 [ #  # ][ #  # ]:          0 :     m_xNameAccess = m_pCBarHelper->getPersistentWindowState();
      80                 :          0 : }
      81                 :            : 
      82         [ #  # ]:          0 : ScVbaCommandBars::~ScVbaCommandBars()
      83                 :            : {
      84         [ #  # ]:          0 : }
      85                 :            : 
      86                 :            : // XEnumerationAccess
      87                 :            : uno::Type SAL_CALL
      88                 :          0 : ScVbaCommandBars::getElementType() throw ( uno::RuntimeException )
      89                 :            : {
      90                 :          0 :     return XCommandBar::static_type( 0 );
      91                 :            : }
      92                 :            : 
      93                 :            : uno::Reference< container::XEnumeration >
      94                 :          0 : ScVbaCommandBars::createEnumeration() throw ( uno::RuntimeException )
      95                 :            : {
      96 [ #  # ][ #  # ]:          0 :     return uno::Reference< container::XEnumeration >( new CommandBarEnumeration( this, mxContext, m_pCBarHelper ) );
         [ #  # ][ #  # ]
                 [ #  # ]
      97                 :            : }
      98                 :            : 
      99                 :            : uno::Any
     100                 :          0 : ScVbaCommandBars::createCollectionObject( const uno::Any& aSource )
     101                 :            : {
     102                 :            :     // aSource should be a name at this time, because of the class is API wrapper.
     103                 :          0 :     rtl::OUString sResourceUrl;
     104                 :          0 :     uno::Reference< container::XIndexAccess > xBarSettings;
     105                 :          0 :     rtl::OUString sBarName;
     106                 :          0 :     sal_Bool bMenu = sal_False;
     107                 :          0 :     uno::Any aRet;
     108                 :            : 
     109         [ #  # ]:          0 :     if( aSource >>= sBarName )
     110                 :            :     {
     111                 :            :         // some built-in command bars
     112         [ #  # ]:          0 :         if( m_pCBarHelper->getModuleId() == "com.sun.star.sheet.SpreadsheetDocument" )
     113                 :            :         {
     114         [ #  # ]:          0 :             if( sBarName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM("Worksheet Menu Bar") ) )
     115                 :            :             {
     116                 :            :                 // spreadsheet menu bar
     117                 :          0 :                 sResourceUrl = rtl::OUString( ITEM_MENUBAR_URL );
     118                 :          0 :                 bMenu = sal_True;
     119                 :            :             }
     120         [ #  # ]:          0 :             else if( sBarName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM("Cell") ) )
     121                 :            :             {
     122                 :            :                 // EVIL HACK (tm): spreadsheet cell context menu as dummy object without functionality
     123 [ #  # ][ #  # ]:          0 :                 aRet <<= uno::Reference< XCommandBar >( new VbaDummyCommandBar( this, mxContext, sBarName, office::MsoBarType::msoBarTypePopup ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     124                 :            :             }
     125                 :            :         }
     126         [ #  # ]:          0 :         else if( m_pCBarHelper->getModuleId() == "com.sun.star.text.TextDocument" )
     127                 :            :         {
     128         [ #  # ]:          0 :             if( sBarName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM("Menu Bar") ) )
     129                 :            :             {
     130                 :            :                 // text processor menu bar
     131                 :          0 :                 sResourceUrl = rtl::OUString( ITEM_MENUBAR_URL );
     132                 :          0 :                 bMenu = sal_True;
     133                 :            :             }
     134                 :            :         }
     135                 :            : 
     136                 :            :         // nothing found - try to resolve from name
     137 [ #  # ][ #  # ]:          0 :         if( !aRet.hasValue() && sResourceUrl.isEmpty() )
                 [ #  # ]
     138                 :            :         {
     139         [ #  # ]:          0 :             sResourceUrl = m_pCBarHelper->findToolbarByName( m_xNameAccess, sBarName );
     140                 :          0 :             bMenu = sal_False;
     141                 :            :         }
     142                 :            :     }
     143                 :            : 
     144         [ #  # ]:          0 :     if( !sResourceUrl.isEmpty() )
     145                 :            :     {
     146 [ #  # ][ #  # ]:          0 :         xBarSettings = m_pCBarHelper->getSettings( sResourceUrl );
     147 [ #  # ][ #  # ]:          0 :         aRet <<= uno::Reference< XCommandBar >( new ScVbaCommandBar( this, mxContext, m_pCBarHelper, xBarSettings, sResourceUrl, bMenu, sal_False ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     148                 :            :     }
     149                 :            : 
     150         [ #  # ]:          0 :     if( !aRet.hasValue() )
     151         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( "Toolbar do not exist" ), uno::Reference< uno::XInterface >() );
     152                 :            : 
     153                 :          0 :     return aRet;
     154                 :            : }
     155                 :            : 
     156                 :            : // XCommandBars
     157                 :            : uno::Reference< XCommandBar > SAL_CALL
     158                 :          0 : ScVbaCommandBars::Add( const css::uno::Any& Name, const css::uno::Any& /*Position*/, const css::uno::Any& /*MenuBar*/, const css::uno::Any& Temporary ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
     159                 :            : {
     160                 :            :     // FIXME: only support to add Toolbar
     161                 :            :     // Position - MsoBar MenuBar - sal_Bool
     162                 :            :     // Currently only the Name is supported.
     163                 :          0 :     rtl::OUString sName;
     164         [ #  # ]:          0 :     if( Name.hasValue() )
     165                 :          0 :         Name >>= sName;
     166                 :            : 
     167                 :          0 :     rtl::OUString sResourceUrl;
     168         [ #  # ]:          0 :     if( !sName.isEmpty() )
     169                 :            :     {
     170         [ #  # ]:          0 :         sResourceUrl = m_pCBarHelper->findToolbarByName( m_xNameAccess, sName );
     171         [ #  # ]:          0 :         if( !sResourceUrl.isEmpty() )
     172         [ #  # ]:          0 :             throw uno::RuntimeException( rtl::OUString( "Toolbar exists" ), uno::Reference< uno::XInterface >() );
     173                 :            :     }
     174                 :            :     else
     175                 :            :     {
     176                 :          0 :         sName = rtl::OUString( "Custom1" );
     177                 :            :     }
     178                 :            : 
     179                 :          0 :     sal_Bool bTemporary = sal_False;
     180         [ #  # ]:          0 :     if( Temporary.hasValue() )
     181                 :          0 :         Temporary >>= bTemporary;
     182                 :            : 
     183         [ #  # ]:          0 :     sResourceUrl = VbaCommandBarHelper::generateCustomURL();
     184 [ #  # ][ #  # ]:          0 :     uno::Reference< container::XIndexAccess > xBarSettings( m_pCBarHelper->getSettings( sResourceUrl ), uno::UNO_QUERY_THROW );
     185 [ #  # ][ #  # ]:          0 :     uno::Reference< XCommandBar > xCBar( new ScVbaCommandBar( this, mxContext, m_pCBarHelper, xBarSettings, sResourceUrl, sal_False, bTemporary ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     186 [ #  # ][ #  # ]:          0 :     xCBar->setName( sName );
     187                 :          0 :     return xCBar;
     188                 :            : }
     189                 :            : sal_Int32 SAL_CALL
     190                 :          0 : ScVbaCommandBars::getCount() throw(css::uno::RuntimeException)
     191                 :            : {
     192                 :            :     // Filter out all toolbars from the window collection
     193                 :          0 :     sal_Int32 nCount = 1; // there is a Menubar in OOo
     194 [ #  # ][ #  # ]:          0 :     uno::Sequence< ::rtl::OUString > allNames = m_xNameAccess->getElementNames();
     195         [ #  # ]:          0 :     for( sal_Int32 i = 0; i < allNames.getLength(); i++ )
     196                 :            :     {
     197 [ #  # ][ #  # ]:          0 :         if(allNames[i].indexOf( "private:resource/toolbar/" ) != -1 )
     198                 :            :         {
     199                 :          0 :             nCount++;
     200                 :            :         }
     201                 :            :     }
     202         [ #  # ]:          0 :     return nCount;
     203                 :            : }
     204                 :            : 
     205                 :            : // ScVbaCollectionBaseImpl
     206                 :            : uno::Any SAL_CALL
     207                 :          0 : ScVbaCommandBars::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ ) throw( uno::RuntimeException )
     208                 :            : {
     209         [ #  # ]:          0 :     if( aIndex.getValueTypeClass() == uno::TypeClass_STRING )
     210                 :            :     {
     211         [ #  # ]:          0 :         return createCollectionObject( aIndex );
     212                 :            :     }
     213                 :            : 
     214                 :            :     // hardcode if "aIndex = 1" that would return "main menu".
     215                 :          0 :     sal_Int16 nIndex = 0;
     216                 :          0 :     aIndex >>= nIndex;
     217         [ #  # ]:          0 :     if( nIndex == 1 )
     218                 :            :     {
     219                 :          0 :         uno::Any aSource;
     220         [ #  # ]:          0 :         if( m_pCBarHelper->getModuleId() == "com.sun.star.sheet.SpreadsheetDocument" )
     221         [ #  # ]:          0 :             aSource <<= rtl::OUString("Worksheet Menu Bar");
     222         [ #  # ]:          0 :         else if( m_pCBarHelper->getModuleId() == "com.sun.star.text.TextDocument" )
     223         [ #  # ]:          0 :             aSource <<= rtl::OUString("Menu Bar");
     224         [ #  # ]:          0 :         if( aSource.hasValue() )
     225 [ #  # ][ #  # ]:          0 :             return createCollectionObject( aSource );
     226                 :            :     }
     227                 :          0 :     return uno::Any();
     228                 :            : }
     229                 :            : 
     230                 :            : // XHelperInterface
     231                 :            : rtl::OUString
     232                 :          0 : ScVbaCommandBars::getServiceImplName()
     233                 :            : {
     234                 :          0 :     return rtl::OUString("ScVbaCommandBars");
     235                 :            : }
     236                 :            : 
     237                 :            : uno::Sequence<rtl::OUString>
     238                 :          0 : ScVbaCommandBars::getServiceNames()
     239                 :            : {
     240 [ #  # ][ #  # ]:          0 :     static uno::Sequence< rtl::OUString > aServiceNames;
         [ #  # ][ #  # ]
     241         [ #  # ]:          0 :     if ( aServiceNames.getLength() == 0 )
     242                 :            :     {
     243                 :          0 :         aServiceNames.realloc( 1 );
     244         [ #  # ]:          0 :         aServiceNames[ 0 ] = rtl::OUString( "ooo.vba.CommandBars"  );
     245                 :            :     }
     246                 :          0 :     return aServiceNames;
     247                 :            : }
     248                 :            : 
     249                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10