1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include "vbacommandbar.hxx"
20 #include "vbacommandbarcontrols.hxx"
21 #include <com/sun/star/frame/XLayoutManager.hpp>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/container/XNameContainer.hpp>
24 #include <ooo/vba/office/MsoBarType.hpp>
25 #include <sal/log.hxx>
28 using namespace com::sun::star
;
29 using namespace ooo::vba
;
31 ScVbaCommandBar::ScVbaCommandBar( const uno::Reference
< ov::XHelperInterface
>& xParent
,
32 const uno::Reference
< uno::XComponentContext
>& xContext
,
33 VbaCommandBarHelperRef pHelper
,
34 uno::Reference
< container::XIndexAccess
> xBarSettings
,
35 OUString sResourceUrl
, bool bIsMenu
)
36 : CommandBar_BASE( xParent
, xContext
), pCBarHelper(std::move( pHelper
)), m_xBarSettings(std::move( xBarSettings
)), m_sResourceUrl(std::move( sResourceUrl
)), m_bIsMenu( bIsMenu
)
41 ScVbaCommandBar::getName()
43 // This will get a "NULL length string" when Name is not set.
44 uno::Reference
< beans::XPropertySet
> xPropertySet( m_xBarSettings
, uno::UNO_QUERY_THROW
);
45 uno::Any aName
= xPropertySet
->getPropertyValue( "UIName" );
52 if( m_sResourceUrl
== ITEM_MENUBAR_URL
)
54 if( pCBarHelper
->getModuleId() == "com.sun.star.sheet.SpreadsheetDocument" )
55 sName
= "Worksheet Menu Bar";
56 else if( pCBarHelper
->getModuleId() == "com.sun.star.text.TextDocument" )
62 uno::Reference
< container::XNameAccess
> xNameAccess
= pCBarHelper
->getPersistentWindowState();
63 if( xNameAccess
->hasByName( m_sResourceUrl
) )
65 uno::Sequence
< beans::PropertyValue
> aToolBar
;
66 xNameAccess
->getByName( m_sResourceUrl
) >>= aToolBar
;
67 getPropertyValue( aToolBar
, "UIName" ) >>= sName
;
73 ScVbaCommandBar::setName( const OUString
& _name
)
75 uno::Reference
< beans::XPropertySet
> xPropertySet( m_xBarSettings
, uno::UNO_QUERY_THROW
);
76 xPropertySet
->setPropertyValue( "UIName" , uno::Any( _name
) );
78 pCBarHelper
->ApplyTempChange( m_sResourceUrl
, m_xBarSettings
);
81 ScVbaCommandBar::getVisible()
83 // menu bar is always visible in OOo
87 bool bVisible
= false;
90 uno::Reference
< container::XNameAccess
> xNameAccess
= pCBarHelper
->getPersistentWindowState();
91 if( xNameAccess
->hasByName( m_sResourceUrl
) )
93 uno::Sequence
< beans::PropertyValue
> aToolBar
;
94 xNameAccess
->getByName( m_sResourceUrl
) >>= aToolBar
;
95 getPropertyValue( aToolBar
, "Visible" ) >>= bVisible
;
98 catch (const uno::Exception
&)
104 ScVbaCommandBar::setVisible( sal_Bool _visible
)
108 uno::Reference
< frame::XLayoutManager
> xLayoutManager
= pCBarHelper
->getLayoutManager();
111 xLayoutManager
->createElement( m_sResourceUrl
);
112 xLayoutManager
->showElement( m_sResourceUrl
);
116 xLayoutManager
->hideElement( m_sResourceUrl
);
117 xLayoutManager
->destroyElement( m_sResourceUrl
);
120 catch(const uno::Exception
&)
122 SAL_INFO("vbahelper", "SetVisible get an exception" );
127 ScVbaCommandBar::getEnabled()
129 // emulated with Visible
134 ScVbaCommandBar::setEnabled( sal_Bool _enabled
)
136 // emulated with Visible
137 setVisible( _enabled
);
141 ScVbaCommandBar::Delete( )
143 pCBarHelper
->removeSettings( m_sResourceUrl
);
144 uno::Reference
< container::XNameContainer
> xNameContainer( pCBarHelper
->getPersistentWindowState(), uno::UNO_QUERY_THROW
);
145 if( xNameContainer
->hasByName( m_sResourceUrl
) )
147 xNameContainer
->removeByName( m_sResourceUrl
);
151 ScVbaCommandBar::Controls( const uno::Any
& aIndex
)
153 uno::Reference
< XCommandBarControls
> xCommandBarControls( new ScVbaCommandBarControls( this, mxContext
, m_xBarSettings
, pCBarHelper
, m_xBarSettings
, m_sResourceUrl
) );
154 if( aIndex
.hasValue() )
156 return xCommandBarControls
->Item( aIndex
, uno::Any() );
158 return uno::Any( xCommandBarControls
);
162 ScVbaCommandBar::Type()
164 // #FIXME support msoBarTypePopup
166 = m_bIsMenu
? office::MsoBarType::msoBarTypeNormal
: office::MsoBarType::msoBarTypeMenuBar
;
171 ScVbaCommandBar::FindControl( const uno::Any
& /*aType*/, const uno::Any
& /*aId*/, const uno::Any
& /*aTag*/, const uno::Any
& /*aVisible*/, const uno::Any
& /*aRecursive*/ )
173 // alwayse fail to find control
174 return uno::Any( uno::Reference
< XCommandBarControl
> () );
178 ScVbaCommandBar::getServiceImplName()
180 return "ScVbaCommandBar";
183 uno::Sequence
<OUString
>
184 ScVbaCommandBar::getServiceNames()
186 static uno::Sequence
< OUString
> const aServiceNames
190 return aServiceNames
;
194 VbaDummyCommandBar::VbaDummyCommandBar(
195 const uno::Reference
< ov::XHelperInterface
>& xParent
,
196 const uno::Reference
< uno::XComponentContext
>& xContext
,
198 CommandBar_BASE( xParent
, xContext
),
199 maName(std::move( sName
))
203 OUString SAL_CALL
VbaDummyCommandBar::getName()
208 void SAL_CALL
VbaDummyCommandBar::setName( const OUString
& _name
)
213 sal_Bool SAL_CALL
VbaDummyCommandBar::getVisible()
219 void SAL_CALL
VbaDummyCommandBar::setVisible( sal_Bool
/*_visible*/ )
224 sal_Bool SAL_CALL
VbaDummyCommandBar::getEnabled()
226 // emulated with Visible
230 void SAL_CALL
VbaDummyCommandBar::setEnabled( sal_Bool _enabled
)
232 // emulated with Visible
233 setVisible( _enabled
);
236 void SAL_CALL
VbaDummyCommandBar::Delete( )
242 uno::Any SAL_CALL
VbaDummyCommandBar::Controls( const uno::Any
& aIndex
)
244 uno::Reference
< XCommandBarControls
> xCommandBarControls( new VbaDummyCommandBarControls( this, mxContext
) );
245 if( aIndex
.hasValue() )
246 return xCommandBarControls
->Item( aIndex
, uno::Any() );
247 return uno::Any( xCommandBarControls
);
250 sal_Int32 SAL_CALL
VbaDummyCommandBar::Type()
252 return office::MsoBarType::msoBarTypePopup
;
255 uno::Any SAL_CALL
VbaDummyCommandBar::FindControl( const uno::Any
& /*aType*/, const uno::Any
& /*aId*/, const uno::Any
& /*aTag*/, const uno::Any
& /*aVisible*/, const uno::Any
& /*aRecursive*/ )
257 return uno::Any( uno::Reference
< XCommandBarControl
>() );
260 OUString
VbaDummyCommandBar::getServiceImplName()
262 return "VbaDummyCommandBar";
265 uno::Sequence
< OUString
> VbaDummyCommandBar::getServiceNames()
267 static uno::Sequence
< OUString
> const aServiceNames
271 return aServiceNames
;
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */