1 diff --git oovbaapi/ooo/vba/XCommandBarControl.idl oovbaapi/ooo/vba/XCommandBarControl.idl
2 index 167bce8..b10750e 100644
3 --- oovbaapi/ooo/vba/XCommandBarControl.idl
4 +++ oovbaapi/ooo/vba/XCommandBarControl.idl
5 @@ -55,6 +55,7 @@ interface XCommandBarControl
6 [attribute] string OnAction;
7 [attribute] boolean Visible;
8 [attribute, readonly] long Type;
9 + [attribute] boolean Enabled;
11 void Delete() raises ( com::sun::star::script::BasicErrorException );
12 any Controls( [in] any Index ) raises ( com::sun::star::script::BasicErrorException );
13 diff --git vbahelper/source/vbahelper/vbacommandbar.cxx vbahelper/source/vbahelper/vbacommandbar.cxx
14 index 43abe41..8c10277 100644
15 --- vbahelper/source/vbahelper/vbacommandbar.cxx
16 +++ vbahelper/source/vbahelper/vbacommandbar.cxx
17 @@ -128,9 +128,7 @@ ScVbaCommandBar::setVisible( ::sal_Bool _visible ) throw (uno::RuntimeException)
21 - uno::Reference< frame::XFrame > xFrame( pCBarHelper->getModel()->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW );
22 - uno::Reference< beans::XPropertySet > xPropertySet( xFrame, uno::UNO_QUERY_THROW );
23 - uno::Reference< frame::XLayoutManager > xLayoutManager( xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("LayoutManager") ), uno::UNO_QUERY_THROW );
24 + uno::Reference< frame::XLayoutManager > xLayoutManager = pCBarHelper->getLayoutManager();
27 xLayoutManager->createElement( m_sResourceUrl );
28 @@ -151,16 +149,15 @@ ScVbaCommandBar::setVisible( ::sal_Bool _visible ) throw (uno::RuntimeException)
30 ScVbaCommandBar::getEnabled() throw (uno::RuntimeException)
32 - // #FIXME: seems tha main menu is alwayse enabled.
33 - // for the toolbar, need to investigate
35 + // emulated with Visible
36 + return getVisible();
40 -ScVbaCommandBar::setEnabled( sal_Bool/* _enabled */ ) throw (uno::RuntimeException)
41 +ScVbaCommandBar::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException)
43 - // #FIXME: seems tha main menu is alwayse enabled.
44 - // for the toolbar, need to investigate
45 + // emulated with Visible
46 + setVisible( _enabled );
50 @@ -189,7 +186,14 @@ ScVbaCommandBar::Delete( ) throw (script::BasicErrorException, uno::RuntimeExce
52 ScVbaCommandBar::Controls( const uno::Any& aIndex ) throw (script::BasicErrorException, uno::RuntimeException)
54 - uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, m_xBarSettings, pCBarHelper, m_xBarSettings, m_sResourceUrl ) );
55 + uno::Reference< awt::XMenu > xMenu;
58 + uno::Reference< frame::XLayoutManager > xLayoutManager = pCBarHelper->getLayoutManager();
59 + uno::Reference< beans::XPropertySet > xPropertySet( xLayoutManager->getElement( m_sResourceUrl ), uno::UNO_QUERY_THROW );
60 + xMenu.set( xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("XMenuBar") ), uno::UNO_QUERY );
62 + uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, m_xBarSettings, pCBarHelper, m_xBarSettings, m_sResourceUrl, xMenu ) );
63 if( aIndex.hasValue() )
65 return xCommandBarControls->Item( aIndex, uno::Any() );
66 diff --git vbahelper/source/vbahelper/vbacommandbarcontrol.cxx vbahelper/source/vbahelper/vbacommandbarcontrol.cxx
67 index dd20256..050af79 100644
68 --- vbahelper/source/vbahelper/vbacommandbarcontrol.cxx
69 +++ vbahelper/source/vbahelper/vbacommandbarcontrol.cxx
70 @@ -118,6 +118,39 @@ ScVbaCommandBarControl::setVisible( ::sal_Bool _visible ) throw (uno::RuntimeExc
75 +ScVbaCommandBarControl::getEnabled() throw (uno::RuntimeException)
77 + sal_Bool bEnabled = sal_True;
78 + if( m_xParentMenu.is() )
80 + // currently only the menu in the MenuBat support Enable/Disable
81 + // FIXME: how to support the menu item in Toolbar
82 + bEnabled = m_xParentMenu->isItemEnabled( m_xParentMenu->getItemId( m_nPosition ) );
86 + // emulated with Visible
87 + bEnabled = getVisible();
93 +ScVbaCommandBarControl::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException)
95 + if( m_xParentMenu.is() )
97 + // currently only the menu in the MenuBat support Enable/Disable
98 + m_xParentMenu->enableItem( m_xParentMenu->getItemId( m_nPosition ), _enabled );
102 + // emulated with Visible
103 + setVisible( _enabled );
108 ScVbaCommandBarControl::Delete( ) throw (script::BasicErrorException, uno::RuntimeException)
110 @@ -150,8 +183,15 @@ ScVbaCommandBarControl::Controls( const uno::Any& aIndex ) throw (script::BasicE
111 getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_CONTAINER ) ) >>= xSubMenu;
113 throw uno::RuntimeException();
115 + uno::Reference< awt::XMenu > xMenu;
116 + if( m_xParentMenu.is() )
118 + sal_Int32 nItemId = m_xParentMenu->getItemId( m_nPosition );
119 + xMenu.set( m_xParentMenu->getPopupMenu( nItemId ), uno::UNO_QUERY );
122 - uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, xSubMenu, pCBarHelper, m_xBarSettings, m_sResourceUrl ) );
123 + uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, xSubMenu, pCBarHelper, m_xBarSettings, m_sResourceUrl, xMenu ) );
124 if( aIndex.hasValue() )
126 return xCommandBarControls->Item( aIndex, uno::Any() );
127 @@ -179,11 +219,12 @@ ScVbaCommandBarControl::getServiceNames()
130 //////////// ScVbaCommandBarPopup //////////////////////////////
131 -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 )
132 +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, const css::uno::Reference< css::awt::XMenu >& xMenu ) throw (css::uno::RuntimeException) : CommandBarPopup_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl )
134 m_nPosition = nPosition;
135 m_bTemporary = bTemporary;
136 m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues;
137 + m_xParentMenu = xMenu;
141 @@ -205,11 +246,12 @@ ScVbaCommandBarPopup::getServiceNames()
144 //////////// ScVbaCommandBarButton //////////////////////////////
145 -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 )
146 +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, const css::uno::Reference< css::awt::XMenu >& xMenu ) throw (css::uno::RuntimeException) : CommandBarButton_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl )
148 m_nPosition = nPosition;
149 m_bTemporary = bTemporary;
150 m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues;
151 + m_xParentMenu = xMenu;
155 diff --git vbahelper/source/vbahelper/vbacommandbarcontrol.hxx vbahelper/source/vbahelper/vbacommandbarcontrol.hxx
156 index f40ad82..0d2d30b 100644
157 --- vbahelper/source/vbahelper/vbacommandbarcontrol.hxx
158 +++ vbahelper/source/vbahelper/vbacommandbarcontrol.hxx
160 #include <ooo/vba/XCommandBarPopup.hpp>
161 #include <ooo/vba/XCommandBarButton.hpp>
162 #include <ooo/vba/office/MsoControlType.hpp>
163 +#include <com/sun/star/awt/XMenu.hpp>
164 #include <vbahelper/vbahelperinterface.hxx>
165 #include "vbacommandbarhelper.hxx"
166 #include <cppuhelper/implbase1.hxx>
167 @@ -53,6 +54,7 @@ protected:
168 css::uno::Reference< css::container::XIndexAccess > m_xCurrentSettings;
169 css::uno::Reference< css::container::XIndexAccess > m_xBarSettings;
170 css::uno::Sequence< css::beans::PropertyValue > m_aPropertyValues;
171 + css::uno::Reference< css::awt::XMenu > m_xParentMenu;
173 sal_Int32 m_nPosition;
174 sal_Bool m_bTemporary;
175 @@ -71,6 +73,8 @@ public:
176 virtual void SAL_CALL setOnAction( const ::rtl::OUString& _onaction ) throw (css::uno::RuntimeException);
177 virtual ::sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException);
178 virtual void SAL_CALL setVisible( ::sal_Bool _visible ) throw (css::uno::RuntimeException);
179 + virtual ::sal_Bool SAL_CALL getEnabled() throw (css::uno::RuntimeException);
180 + virtual void SAL_CALL setEnabled( ::sal_Bool _enabled ) throw (css::uno::RuntimeException);
181 virtual sal_Int32 SAL_CALL getType() throw (css::uno::RuntimeException)
183 return ov::office::MsoControlType::msoControlButton;
184 @@ -89,7 +93,7 @@ typedef cppu::ImplInheritanceHelper1< ScVbaCommandBarControl, ov::XCommandBarPop
185 class ScVbaCommandBarPopup : public CommandBarPopup_BASE
188 - 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);
189 + 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, const css::uno::Reference< css::awt::XMenu >& xMenu ) throw (css::uno::RuntimeException);
191 virtual sal_Int32 SAL_CALL getType() throw (css::uno::RuntimeException)
193 @@ -104,7 +108,7 @@ typedef cppu::ImplInheritanceHelper1< ScVbaCommandBarControl, ov::XCommandBarBut
194 class ScVbaCommandBarButton : public CommandBarButton_BASE
197 - 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);
198 + 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, const css::uno::Reference< css::awt::XMenu >& xMenu ) throw (css::uno::RuntimeException);
200 virtual sal_Int32 SAL_CALL getType() throw (css::uno::RuntimeException)
202 diff --git vbahelper/source/vbahelper/vbacommandbarcontrols.cxx vbahelper/source/vbahelper/vbacommandbarcontrols.cxx
203 index ea56a09..488b56a 100644
204 --- vbahelper/source/vbahelper/vbacommandbarcontrols.cxx
205 +++ vbahelper/source/vbahelper/vbacommandbarcontrols.cxx
206 @@ -63,7 +63,7 @@ public:
210 -ScVbaCommandBarControls::ScVbaCommandBarControls( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess>& xIndexAccess, VbaCommandBarHelperRef pHelper, const uno::Reference< container::XIndexAccess>& xBarSettings, const rtl::OUString& sResourceUrl ) throw (uno::RuntimeException) : CommandBarControls_BASE( xParent, xContext, xIndexAccess ), pCBarHelper( pHelper ), m_xBarSettings( xBarSettings ), m_sResourceUrl( sResourceUrl )
211 +ScVbaCommandBarControls::ScVbaCommandBarControls( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess>& xIndexAccess, VbaCommandBarHelperRef pHelper, const uno::Reference< container::XIndexAccess>& xBarSettings, const rtl::OUString& sResourceUrl, const uno::Reference< awt::XMenu >& xMenu ) throw (uno::RuntimeException) : CommandBarControls_BASE( xParent, xContext, xIndexAccess ), pCBarHelper( pHelper ), m_xBarSettings( xBarSettings ), m_sResourceUrl( sResourceUrl ), m_xMenu( xMenu )
213 m_bIsMenu = sResourceUrl.equalsAscii( ITEM_MENUBAR_URL ) ? sal_True : sal_False;
215 @@ -132,9 +132,9 @@ ScVbaCommandBarControls::createCollectionObject( const uno::Any& aSource )
216 getPropertyValue( aProps, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_CONTAINER ) ) >>= xSubMenu;
217 ScVbaCommandBarControl* pNewCommandBarControl = NULL;
219 - pNewCommandBarControl = new ScVbaCommandBarPopup( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, sal_True );
220 + pNewCommandBarControl = new ScVbaCommandBarPopup( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, sal_True, m_xMenu );
222 - pNewCommandBarControl = new ScVbaCommandBarButton( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, sal_True );
223 + pNewCommandBarControl = new ScVbaCommandBarButton( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, sal_True, m_xMenu );
225 return uno::makeAny( uno::Reference< XCommandBarControl > ( pNewCommandBarControl ) );
227 @@ -227,11 +227,12 @@ ScVbaCommandBarControls::Add( const uno::Any& Type, const uno::Any& Id, const un
229 pCBarHelper->persistChanges();
231 + // sometimes it would crash if passing m_xMenu instead of uno::Reference< awt::XMenu >() in Linux.
232 ScVbaCommandBarControl* pNewCommandBarControl = NULL;
233 if( nType == office::MsoControlType::msoControlPopup )
234 - pNewCommandBarControl = new ScVbaCommandBarPopup( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, bTemporary );
235 + pNewCommandBarControl = new ScVbaCommandBarPopup( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, bTemporary, uno::Reference< awt::XMenu >() );
237 - pNewCommandBarControl = new ScVbaCommandBarButton( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, bTemporary );
238 + pNewCommandBarControl = new ScVbaCommandBarButton( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, bTemporary, uno::Reference< awt::XMenu >() );
240 return uno::Reference< XCommandBarControl >( pNewCommandBarControl );
242 diff --git vbahelper/source/vbahelper/vbacommandbarcontrols.hxx vbahelper/source/vbahelper/vbacommandbarcontrols.hxx
243 index fa37f10..ce89794 100644
244 --- vbahelper/source/vbahelper/vbacommandbarcontrols.hxx
245 +++ vbahelper/source/vbahelper/vbacommandbarcontrols.hxx
247 #define SC_VBA_COMMANDBARCONTROLS_HXX
249 #include <ooo/vba/XCommandBarControls.hpp>
250 +#include <com/sun/star/awt/XMenu.hpp>
251 #include <vbahelper/vbahelperinterface.hxx>
252 #include <vbahelper/vbacollectionimpl.hxx>
253 #include "vbacommandbarhelper.hxx"
254 @@ -48,13 +49,14 @@ private:
255 VbaCommandBarHelperRef pCBarHelper;
256 css::uno::Reference< css::container::XIndexAccess > m_xBarSettings;
257 rtl::OUString m_sResourceUrl;
258 + css::uno::Reference< css::awt::XMenu > m_xMenu;
261 css::uno::Sequence< css::beans::PropertyValue > CreateMenuItemData( const rtl::OUString& sCommandURL, const rtl::OUString& sHelpURL, const rtl::OUString& sLabel, sal_uInt16 nType, const css::uno::Any& aSubMenu );
262 css::uno::Sequence< css::beans::PropertyValue > CreateToolbarItemData( const rtl::OUString& sCommandURL, const rtl::OUString& sHelpURL, const rtl::OUString& sLabel, sal_uInt16 nType, const css::uno::Any& aSubMenu, sal_Bool isVisible, sal_Int32 nStyle );
265 - ScVbaCommandBarControls( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl ) throw( css::uno::RuntimeException );
266 + ScVbaCommandBarControls( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, const css::uno::Reference< css::awt::XMenu >& xMenu ) throw( css::uno::RuntimeException );
267 sal_Bool IsMenu(){ return m_bIsMenu; }
269 // XEnumerationAccess
270 diff --git vbahelper/source/vbahelper/vbacommandbarhelper.cxx vbahelper/source/vbahelper/vbacommandbarhelper.cxx
271 index b4515b6..034e506 100644
272 --- vbahelper/source/vbahelper/vbacommandbarhelper.cxx
273 +++ vbahelper/source/vbahelper/vbacommandbarhelper.cxx
274 @@ -155,6 +155,14 @@ sal_Bool VbaCommandBarHelper::persistChanges() throw (css::uno::RuntimeException
278 +uno::Reference< frame::XLayoutManager > VbaCommandBarHelper::getLayoutManager() throw (uno::RuntimeException)
280 + uno::Reference< frame::XFrame > xFrame( getModel()->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW );
281 + uno::Reference< beans::XPropertySet > xPropertySet( xFrame, uno::UNO_QUERY_THROW );
282 + uno::Reference< frame::XLayoutManager > xLayoutManager( xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("LayoutManager") ), uno::UNO_QUERY_THROW );
283 + return xLayoutManager;
286 rtl::OUString VbaCommandBarHelper::getMenuBarUrl()
288 static const rtl::OUString sMenuBarUrl( RTL_CONSTASCII_USTRINGPARAM( ITEM_MENUBAR_URL ) );
289 diff --git vbahelper/source/vbahelper/vbacommandbarhelper.hxx vbahelper/source/vbahelper/vbacommandbarhelper.hxx
290 index a6304bc..64a808d 100644
291 --- vbahelper/source/vbahelper/vbacommandbarhelper.hxx
292 +++ vbahelper/source/vbahelper/vbacommandbarhelper.hxx
294 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
295 #include <com/sun/star/container/XIndexAccess.hpp>
296 #include <com/sun/star/container/XNameAccess.hpp>
297 +#include <com/sun/star/frame/XLayoutManager.hpp>
298 #include <boost/shared_ptr.hpp>
301 @@ -95,6 +96,8 @@ public:
303 sal_Bool persistChanges() throw (css::uno::RuntimeException);
305 + css::uno::Reference< css::frame::XLayoutManager > getLayoutManager() throw (css::uno::RuntimeException);
307 const rtl::OUString getModuleId(){ return maModuleId; }
308 static rtl::OUString getMenuBarUrl();
309 rtl::OUString findToolbarByName( const css::uno::Reference< css::container::XNameAccess >& xNameAccess, const rtl::OUString& sName ) throw (css::uno::RuntimeException);