1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #include "vbacommandbarcontrol.hxx" 28*cdf0e10cSrcweir #include "vbacommandbarcontrols.hxx" 29*cdf0e10cSrcweir #include <vbahelper/vbahelper.hxx> 30*cdf0e10cSrcweir #include <filter/msfilter/msvbahelper.hxx> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir using namespace com::sun::star; 33*cdf0e10cSrcweir using namespace ooo::vba; 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir ScVbaCommandBarControl::ScVbaCommandBarControl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl ) throw (css::uno::RuntimeException) : CommandBarControl_BASE( xParent, xContext ), pCBarHelper( pHelper ), m_sResourceUrl( sResourceUrl ), m_xCurrentSettings( xSettings ), m_xBarSettings( xBarSettings ), m_nPosition( 0 ), m_bTemporary( sal_True ) 36*cdf0e10cSrcweir { 37*cdf0e10cSrcweir } 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir ScVbaCommandBarControl::ScVbaCommandBarControl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException) : CommandBarControl_BASE( xParent, xContext ), pCBarHelper( pHelper ), m_sResourceUrl( sResourceUrl ), m_xCurrentSettings( xSettings ), m_xBarSettings( xBarSettings ), m_nPosition( nPosition ), m_bTemporary( bTemporary ) 40*cdf0e10cSrcweir { 41*cdf0e10cSrcweir m_xCurrentSettings->getByIndex( nPosition ) >>= m_aPropertyValues; 42*cdf0e10cSrcweir } 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir void ScVbaCommandBarControl::ApplyChange() throw ( uno::RuntimeException ) 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir uno::Reference< container::XIndexContainer > xIndexContainer( m_xCurrentSettings, uno::UNO_QUERY_THROW ); 47*cdf0e10cSrcweir xIndexContainer->replaceByIndex( m_nPosition, uno::makeAny( m_aPropertyValues ) ); 48*cdf0e10cSrcweir pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings ); 49*cdf0e10cSrcweir } 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir ::rtl::OUString SAL_CALL 52*cdf0e10cSrcweir ScVbaCommandBarControl::getCaption() throw ( uno::RuntimeException ) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir // "Label" always empty 55*cdf0e10cSrcweir rtl::OUString sCaption; 56*cdf0e10cSrcweir getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("Label") ) >>= sCaption; 57*cdf0e10cSrcweir return sCaption; 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir void SAL_CALL 61*cdf0e10cSrcweir ScVbaCommandBarControl::setCaption( const ::rtl::OUString& _caption ) throw (uno::RuntimeException) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir rtl::OUString sCaption = _caption.replace('&','~'); 64*cdf0e10cSrcweir setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("Label"), uno::makeAny( sCaption ) ); 65*cdf0e10cSrcweir ApplyChange(); 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir ::rtl::OUString SAL_CALL 69*cdf0e10cSrcweir ScVbaCommandBarControl::getOnAction() throw (uno::RuntimeException) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir rtl::OUString sCommandURL; 72*cdf0e10cSrcweir getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("CommandURL") ) >>= sCommandURL; 73*cdf0e10cSrcweir return sCommandURL; 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir void SAL_CALL 77*cdf0e10cSrcweir ScVbaCommandBarControl::setOnAction( const ::rtl::OUString& _onaction ) throw (uno::RuntimeException) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir // get the current model 80*cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( pCBarHelper->getModel() ); 81*cdf0e10cSrcweir MacroResolvedInfo aResolvedMacro = ooo::vba::resolveVBAMacro( getSfxObjShell( xModel ), _onaction, true ); 82*cdf0e10cSrcweir if ( aResolvedMacro.mbFound ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir rtl::OUString aCommandURL = ooo::vba::makeMacroURL( aResolvedMacro.msResolvedMacro ); 85*cdf0e10cSrcweir OSL_TRACE(" ScVbaCommandBarControl::setOnAction: %s", rtl::OUStringToOString( aCommandURL, RTL_TEXTENCODING_UTF8 ).getStr() ); 86*cdf0e10cSrcweir setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("CommandURL"), uno::makeAny( aCommandURL ) ); 87*cdf0e10cSrcweir ApplyChange(); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir ::sal_Bool SAL_CALL 92*cdf0e10cSrcweir ScVbaCommandBarControl::getVisible() throw (uno::RuntimeException) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir sal_Bool bVisible = sal_True; 95*cdf0e10cSrcweir uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ) ); 96*cdf0e10cSrcweir if( aValue.hasValue() ) 97*cdf0e10cSrcweir aValue >>= bVisible; 98*cdf0e10cSrcweir return bVisible; 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir void SAL_CALL 101*cdf0e10cSrcweir ScVbaCommandBarControl::setVisible( ::sal_Bool _visible ) throw (uno::RuntimeException) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ) ); 104*cdf0e10cSrcweir if( aValue.hasValue() ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ), uno::makeAny( _visible ) ); 107*cdf0e10cSrcweir ApplyChange(); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir ::sal_Bool SAL_CALL 112*cdf0e10cSrcweir ScVbaCommandBarControl::getEnabled() throw (uno::RuntimeException) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir sal_Bool bEnabled = sal_True; 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED ) ); 117*cdf0e10cSrcweir if( aValue.hasValue() ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir aValue >>= bEnabled; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir else 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir // emulated with Visible 124*cdf0e10cSrcweir bEnabled = getVisible(); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir return bEnabled; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir void SAL_CALL 130*cdf0e10cSrcweir ScVbaCommandBarControl::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED ) ); 133*cdf0e10cSrcweir if( aValue.hasValue() ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED ), uno::makeAny( _enabled ) ); 136*cdf0e10cSrcweir ApplyChange(); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir else 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir // emulated with Visible 141*cdf0e10cSrcweir setVisible( _enabled ); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir ::sal_Bool SAL_CALL 146*cdf0e10cSrcweir ScVbaCommandBarControl::getBeginGroup() throw (css::uno::RuntimeException) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir // TODO: need to check if the item before this item is of type 'separator' 149*cdf0e10cSrcweir return sal_False; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir void SAL_CALL 153*cdf0e10cSrcweir ScVbaCommandBarControl::setBeginGroup( ::sal_Bool _begin ) throw (css::uno::RuntimeException) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir if( getBeginGroup() != _begin ) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir // TODO: need to insert or remove an item of type 'separator' before this item 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir void SAL_CALL 162*cdf0e10cSrcweir ScVbaCommandBarControl::Delete( ) throw (script::BasicErrorException, uno::RuntimeException) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir if( m_xCurrentSettings.is() ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir uno::Reference< container::XIndexContainer > xIndexContainer( m_xCurrentSettings, uno::UNO_QUERY_THROW ); 167*cdf0e10cSrcweir xIndexContainer->removeByIndex( m_nPosition ); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings ); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir uno::Any SAL_CALL 174*cdf0e10cSrcweir ScVbaCommandBarControl::Controls( const uno::Any& aIndex ) throw (script::BasicErrorException, uno::RuntimeException) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir // only Popup Menu has controls 177*cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xSubMenu; 178*cdf0e10cSrcweir getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_CONTAINER ) ) >>= xSubMenu; 179*cdf0e10cSrcweir if( !xSubMenu.is() ) 180*cdf0e10cSrcweir throw uno::RuntimeException(); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, xSubMenu, pCBarHelper, m_xBarSettings, m_sResourceUrl ) ); 183*cdf0e10cSrcweir if( aIndex.hasValue() ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir return xCommandBarControls->Item( aIndex, uno::Any() ); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir return uno::makeAny( xCommandBarControls ); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir rtl::OUString& 191*cdf0e10cSrcweir ScVbaCommandBarControl::getServiceImplName() 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCommandBarControl") ); 194*cdf0e10cSrcweir return sImplName; 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir uno::Sequence<rtl::OUString> 198*cdf0e10cSrcweir ScVbaCommandBarControl::getServiceNames() 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 201*cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir aServiceNames.realloc( 1 ); 204*cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.CommandBarControl" ) ); 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir return aServiceNames; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir //////////// ScVbaCommandBarPopup ////////////////////////////// 210*cdf0e10cSrcweir ScVbaCommandBarPopup::ScVbaCommandBarPopup( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException) : CommandBarPopup_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir m_nPosition = nPosition; 213*cdf0e10cSrcweir m_bTemporary = bTemporary; 214*cdf0e10cSrcweir m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir rtl::OUString& 218*cdf0e10cSrcweir ScVbaCommandBarPopup::getServiceImplName() 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCommandBarPopup") ); 221*cdf0e10cSrcweir return sImplName; 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir uno::Sequence<rtl::OUString> 224*cdf0e10cSrcweir ScVbaCommandBarPopup::getServiceNames() 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 227*cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir aServiceNames.realloc( 1 ); 230*cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.CommandBarPopup" ) ); 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir return aServiceNames; 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir //////////// ScVbaCommandBarButton ////////////////////////////// 236*cdf0e10cSrcweir ScVbaCommandBarButton::ScVbaCommandBarButton( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException) : CommandBarButton_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl ) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir m_nPosition = nPosition; 239*cdf0e10cSrcweir m_bTemporary = bTemporary; 240*cdf0e10cSrcweir m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir rtl::OUString& 244*cdf0e10cSrcweir ScVbaCommandBarButton::getServiceImplName() 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCommandBarButton") ); 247*cdf0e10cSrcweir return sImplName; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir uno::Sequence<rtl::OUString> 250*cdf0e10cSrcweir ScVbaCommandBarButton::getServiceNames() 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 253*cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir aServiceNames.realloc( 1 ); 256*cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.CommandBarButton" ) ); 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir return aServiceNames; 259*cdf0e10cSrcweir } 260