1*e6ed5fbcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*e6ed5fbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e6ed5fbcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e6ed5fbcSAndrew Rist * distributed with this work for additional information 6*e6ed5fbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e6ed5fbcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e6ed5fbcSAndrew Rist * "License"); you may not use this file except in compliance 9*e6ed5fbcSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*e6ed5fbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*e6ed5fbcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e6ed5fbcSAndrew Rist * software distributed under the License is distributed on an 15*e6ed5fbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e6ed5fbcSAndrew Rist * KIND, either express or implied. See the License for the 17*e6ed5fbcSAndrew Rist * specific language governing permissions and limitations 18*e6ed5fbcSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*e6ed5fbcSAndrew Rist *************************************************************/ 21*e6ed5fbcSAndrew Rist 22*e6ed5fbcSAndrew Rist 23cdf0e10cSrcweir #include "vbacommandbarcontrol.hxx" 24cdf0e10cSrcweir #include "vbacommandbarcontrols.hxx" 25cdf0e10cSrcweir #include <vbahelper/vbahelper.hxx> 26cdf0e10cSrcweir #include <filter/msfilter/msvbahelper.hxx> 27cdf0e10cSrcweir 28cdf0e10cSrcweir using namespace com::sun::star; 29cdf0e10cSrcweir using namespace ooo::vba; 30cdf0e10cSrcweir 31cdf0e10cSrcweir 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 ) 32cdf0e10cSrcweir { 33cdf0e10cSrcweir } 34cdf0e10cSrcweir 35cdf0e10cSrcweir 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 ) 36cdf0e10cSrcweir { 37cdf0e10cSrcweir m_xCurrentSettings->getByIndex( nPosition ) >>= m_aPropertyValues; 38cdf0e10cSrcweir } 39cdf0e10cSrcweir 40cdf0e10cSrcweir void ScVbaCommandBarControl::ApplyChange() throw ( uno::RuntimeException ) 41cdf0e10cSrcweir { 42cdf0e10cSrcweir uno::Reference< container::XIndexContainer > xIndexContainer( m_xCurrentSettings, uno::UNO_QUERY_THROW ); 43cdf0e10cSrcweir xIndexContainer->replaceByIndex( m_nPosition, uno::makeAny( m_aPropertyValues ) ); 44cdf0e10cSrcweir pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings ); 45cdf0e10cSrcweir } 46cdf0e10cSrcweir 47cdf0e10cSrcweir ::rtl::OUString SAL_CALL 48cdf0e10cSrcweir ScVbaCommandBarControl::getCaption() throw ( uno::RuntimeException ) 49cdf0e10cSrcweir { 50cdf0e10cSrcweir // "Label" always empty 51cdf0e10cSrcweir rtl::OUString sCaption; 52cdf0e10cSrcweir getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("Label") ) >>= sCaption; 53cdf0e10cSrcweir return sCaption; 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir void SAL_CALL 57cdf0e10cSrcweir ScVbaCommandBarControl::setCaption( const ::rtl::OUString& _caption ) throw (uno::RuntimeException) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir rtl::OUString sCaption = _caption.replace('&','~'); 60cdf0e10cSrcweir setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("Label"), uno::makeAny( sCaption ) ); 61cdf0e10cSrcweir ApplyChange(); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir ::rtl::OUString SAL_CALL 65cdf0e10cSrcweir ScVbaCommandBarControl::getOnAction() throw (uno::RuntimeException) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir rtl::OUString sCommandURL; 68cdf0e10cSrcweir getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("CommandURL") ) >>= sCommandURL; 69cdf0e10cSrcweir return sCommandURL; 70cdf0e10cSrcweir } 71cdf0e10cSrcweir 72cdf0e10cSrcweir void SAL_CALL 73cdf0e10cSrcweir ScVbaCommandBarControl::setOnAction( const ::rtl::OUString& _onaction ) throw (uno::RuntimeException) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir // get the current model 76cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( pCBarHelper->getModel() ); 77cdf0e10cSrcweir MacroResolvedInfo aResolvedMacro = ooo::vba::resolveVBAMacro( getSfxObjShell( xModel ), _onaction, true ); 78cdf0e10cSrcweir if ( aResolvedMacro.mbFound ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir rtl::OUString aCommandURL = ooo::vba::makeMacroURL( aResolvedMacro.msResolvedMacro ); 81cdf0e10cSrcweir OSL_TRACE(" ScVbaCommandBarControl::setOnAction: %s", rtl::OUStringToOString( aCommandURL, RTL_TEXTENCODING_UTF8 ).getStr() ); 82cdf0e10cSrcweir setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("CommandURL"), uno::makeAny( aCommandURL ) ); 83cdf0e10cSrcweir ApplyChange(); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir ::sal_Bool SAL_CALL 88cdf0e10cSrcweir ScVbaCommandBarControl::getVisible() throw (uno::RuntimeException) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir sal_Bool bVisible = sal_True; 91cdf0e10cSrcweir uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ) ); 92cdf0e10cSrcweir if( aValue.hasValue() ) 93cdf0e10cSrcweir aValue >>= bVisible; 94cdf0e10cSrcweir return bVisible; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir void SAL_CALL 97cdf0e10cSrcweir ScVbaCommandBarControl::setVisible( ::sal_Bool _visible ) throw (uno::RuntimeException) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ) ); 100cdf0e10cSrcweir if( aValue.hasValue() ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ), uno::makeAny( _visible ) ); 103cdf0e10cSrcweir ApplyChange(); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir ::sal_Bool SAL_CALL 108cdf0e10cSrcweir ScVbaCommandBarControl::getEnabled() throw (uno::RuntimeException) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir sal_Bool bEnabled = sal_True; 111cdf0e10cSrcweir 112cdf0e10cSrcweir uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED ) ); 113cdf0e10cSrcweir if( aValue.hasValue() ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir aValue >>= bEnabled; 116cdf0e10cSrcweir } 117cdf0e10cSrcweir else 118cdf0e10cSrcweir { 119cdf0e10cSrcweir // emulated with Visible 120cdf0e10cSrcweir bEnabled = getVisible(); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir return bEnabled; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir void SAL_CALL 126cdf0e10cSrcweir ScVbaCommandBarControl::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED ) ); 129cdf0e10cSrcweir if( aValue.hasValue() ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED ), uno::makeAny( _enabled ) ); 132cdf0e10cSrcweir ApplyChange(); 133cdf0e10cSrcweir } 134cdf0e10cSrcweir else 135cdf0e10cSrcweir { 136cdf0e10cSrcweir // emulated with Visible 137cdf0e10cSrcweir setVisible( _enabled ); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir ::sal_Bool SAL_CALL 142cdf0e10cSrcweir ScVbaCommandBarControl::getBeginGroup() throw (css::uno::RuntimeException) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir // TODO: need to check if the item before this item is of type 'separator' 145cdf0e10cSrcweir return sal_False; 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir void SAL_CALL 149cdf0e10cSrcweir ScVbaCommandBarControl::setBeginGroup( ::sal_Bool _begin ) throw (css::uno::RuntimeException) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir if( getBeginGroup() != _begin ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir // TODO: need to insert or remove an item of type 'separator' before this item 154cdf0e10cSrcweir } 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir void SAL_CALL 158cdf0e10cSrcweir ScVbaCommandBarControl::Delete( ) throw (script::BasicErrorException, uno::RuntimeException) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir if( m_xCurrentSettings.is() ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir uno::Reference< container::XIndexContainer > xIndexContainer( m_xCurrentSettings, uno::UNO_QUERY_THROW ); 163cdf0e10cSrcweir xIndexContainer->removeByIndex( m_nPosition ); 164cdf0e10cSrcweir 165cdf0e10cSrcweir pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings ); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir uno::Any SAL_CALL 170cdf0e10cSrcweir ScVbaCommandBarControl::Controls( const uno::Any& aIndex ) throw (script::BasicErrorException, uno::RuntimeException) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir // only Popup Menu has controls 173cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xSubMenu; 174cdf0e10cSrcweir getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_CONTAINER ) ) >>= xSubMenu; 175cdf0e10cSrcweir if( !xSubMenu.is() ) 176cdf0e10cSrcweir throw uno::RuntimeException(); 177cdf0e10cSrcweir 178cdf0e10cSrcweir uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, xSubMenu, pCBarHelper, m_xBarSettings, m_sResourceUrl ) ); 179cdf0e10cSrcweir if( aIndex.hasValue() ) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir return xCommandBarControls->Item( aIndex, uno::Any() ); 182cdf0e10cSrcweir } 183cdf0e10cSrcweir return uno::makeAny( xCommandBarControls ); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir rtl::OUString& 187cdf0e10cSrcweir ScVbaCommandBarControl::getServiceImplName() 188cdf0e10cSrcweir { 189cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCommandBarControl") ); 190cdf0e10cSrcweir return sImplName; 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir uno::Sequence<rtl::OUString> 194cdf0e10cSrcweir ScVbaCommandBarControl::getServiceNames() 195cdf0e10cSrcweir { 196cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 197cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir aServiceNames.realloc( 1 ); 200cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.CommandBarControl" ) ); 201cdf0e10cSrcweir } 202cdf0e10cSrcweir return aServiceNames; 203cdf0e10cSrcweir } 204cdf0e10cSrcweir 205cdf0e10cSrcweir //////////// ScVbaCommandBarPopup ////////////////////////////// 206cdf0e10cSrcweir 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 ) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir m_nPosition = nPosition; 209cdf0e10cSrcweir m_bTemporary = bTemporary; 210cdf0e10cSrcweir m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues; 211cdf0e10cSrcweir } 212cdf0e10cSrcweir 213cdf0e10cSrcweir rtl::OUString& 214cdf0e10cSrcweir ScVbaCommandBarPopup::getServiceImplName() 215cdf0e10cSrcweir { 216cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCommandBarPopup") ); 217cdf0e10cSrcweir return sImplName; 218cdf0e10cSrcweir } 219cdf0e10cSrcweir uno::Sequence<rtl::OUString> 220cdf0e10cSrcweir ScVbaCommandBarPopup::getServiceNames() 221cdf0e10cSrcweir { 222cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 223cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir aServiceNames.realloc( 1 ); 226cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.CommandBarPopup" ) ); 227cdf0e10cSrcweir } 228cdf0e10cSrcweir return aServiceNames; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir //////////// ScVbaCommandBarButton ////////////////////////////// 232cdf0e10cSrcweir 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 ) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir m_nPosition = nPosition; 235cdf0e10cSrcweir m_bTemporary = bTemporary; 236cdf0e10cSrcweir m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues; 237cdf0e10cSrcweir } 238cdf0e10cSrcweir 239cdf0e10cSrcweir rtl::OUString& 240cdf0e10cSrcweir ScVbaCommandBarButton::getServiceImplName() 241cdf0e10cSrcweir { 242cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCommandBarButton") ); 243cdf0e10cSrcweir return sImplName; 244cdf0e10cSrcweir } 245cdf0e10cSrcweir uno::Sequence<rtl::OUString> 246cdf0e10cSrcweir ScVbaCommandBarButton::getServiceNames() 247cdf0e10cSrcweir { 248cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 249cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir aServiceNames.realloc( 1 ); 252cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.CommandBarButton" ) ); 253cdf0e10cSrcweir } 254cdf0e10cSrcweir return aServiceNames; 255cdf0e10cSrcweir } 256