LCOV - code coverage report
Current view: top level - libreoffice/vbahelper/source/vbahelper - vbacommandbars.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 98 0.0 %
Date: 2012-12-27 Functions: 0 16 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             : #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< 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 :             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 ) );
      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 :     OUString sResourceUrl;
     104           0 :     uno::Reference< container::XIndexAccess > xBarSettings;
     105           0 :     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 = 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 = 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 ) );
     148             :     }
     149             : 
     150           0 :     if( !aRet.hasValue() )
     151           0 :         throw uno::RuntimeException( "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 :     OUString sName;
     164           0 :     if( Name.hasValue() )
     165           0 :         Name >>= sName;
     166             : 
     167           0 :     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( "Toolbar exists" , uno::Reference< uno::XInterface >() );
     173             :     }
     174             :     else
     175             :     {
     176           0 :         sName = "Custom1";
     177             :     }
     178             : 
     179           0 :     sResourceUrl = VbaCommandBarHelper::generateCustomURL();
     180           0 :     uno::Reference< container::XIndexAccess > xBarSettings( m_pCBarHelper->getSettings( sResourceUrl ), uno::UNO_QUERY_THROW );
     181           0 :     uno::Reference< XCommandBar > xCBar( new ScVbaCommandBar( this, mxContext, m_pCBarHelper, xBarSettings, sResourceUrl, sal_False ) );
     182           0 :     xCBar->setName( sName );
     183           0 :     return xCBar;
     184             : }
     185             : sal_Int32 SAL_CALL
     186           0 : ScVbaCommandBars::getCount() throw(css::uno::RuntimeException)
     187             : {
     188             :     // Filter out all toolbars from the window collection
     189           0 :     sal_Int32 nCount = 1; // there is a Menubar in OOo
     190           0 :     uno::Sequence< ::OUString > allNames = m_xNameAccess->getElementNames();
     191           0 :     for( sal_Int32 i = 0; i < allNames.getLength(); i++ )
     192             :     {
     193           0 :         if(allNames[i].indexOf( "private:resource/toolbar/" ) != -1 )
     194             :         {
     195           0 :             nCount++;
     196             :         }
     197             :     }
     198           0 :     return nCount;
     199             : }
     200             : 
     201             : // ScVbaCollectionBaseImpl
     202             : uno::Any SAL_CALL
     203           0 : ScVbaCommandBars::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ ) throw( uno::RuntimeException )
     204             : {
     205           0 :     if( aIndex.getValueTypeClass() == uno::TypeClass_STRING )
     206             :     {
     207           0 :         return createCollectionObject( aIndex );
     208             :     }
     209             : 
     210             :     // hardcode if "aIndex = 1" that would return "main menu".
     211           0 :     sal_Int16 nIndex = 0;
     212           0 :     aIndex >>= nIndex;
     213           0 :     if( nIndex == 1 )
     214             :     {
     215           0 :         uno::Any aSource;
     216           0 :         if( m_pCBarHelper->getModuleId() == "com.sun.star.sheet.SpreadsheetDocument" )
     217           0 :             aSource <<= OUString("Worksheet Menu Bar");
     218           0 :         else if( m_pCBarHelper->getModuleId() == "com.sun.star.text.TextDocument" )
     219           0 :             aSource <<= OUString("Menu Bar");
     220           0 :         if( aSource.hasValue() )
     221           0 :             return createCollectionObject( aSource );
     222             :     }
     223           0 :     return uno::Any();
     224             : }
     225             : 
     226             : // XHelperInterface
     227             : OUString
     228           0 : ScVbaCommandBars::getServiceImplName()
     229             : {
     230           0 :     return OUString("ScVbaCommandBars");
     231             : }
     232             : 
     233             : uno::Sequence<OUString>
     234           0 : ScVbaCommandBars::getServiceNames()
     235             : {
     236           0 :     static uno::Sequence< OUString > aServiceNames;
     237           0 :     if ( aServiceNames.getLength() == 0 )
     238             :     {
     239           0 :         aServiceNames.realloc( 1 );
     240           0 :         aServiceNames[ 0 ] = "ooo.vba.CommandBars";
     241             :     }
     242           0 :     return aServiceNames;
     243             : }
     244             : 
     245             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10