android: Update app-specific/MIME type icons
[LibreOffice.git] / vbahelper / source / vbahelper / vbacommandbar.cxx
blob9df3dd9b0f2b727e2cee4d657cf221961c7fa9b5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 #include <utility>
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 )
40 OUString SAL_CALL
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" );
46 OUString sName;
47 aName >>= sName;
48 if( sName.isEmpty() )
50 if( m_bIsMenu )
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" )
57 sName = "Menu Bar";
58 return sName;
61 // Toolbar name
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;
70 return sName;
72 void SAL_CALL
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 );
80 sal_Bool SAL_CALL
81 ScVbaCommandBar::getVisible()
83 // menu bar is always visible in OOo
84 if( m_bIsMenu )
85 return true;
87 bool bVisible = false;
88 try
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&)
101 return bVisible;
103 void SAL_CALL
104 ScVbaCommandBar::setVisible( sal_Bool _visible )
108 uno::Reference< frame::XLayoutManager > xLayoutManager = pCBarHelper->getLayoutManager();
109 if( _visible )
111 xLayoutManager->createElement( m_sResourceUrl );
112 xLayoutManager->showElement( m_sResourceUrl );
114 else
116 xLayoutManager->hideElement( m_sResourceUrl );
117 xLayoutManager->destroyElement( m_sResourceUrl );
120 catch(const uno::Exception&)
122 SAL_INFO("vbahelper", "SetVisible get an exception" );
126 sal_Bool SAL_CALL
127 ScVbaCommandBar::getEnabled()
129 // emulated with Visible
130 return getVisible();
133 void SAL_CALL
134 ScVbaCommandBar::setEnabled( sal_Bool _enabled )
136 // emulated with Visible
137 setVisible( _enabled );
140 void SAL_CALL
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 );
150 uno::Any SAL_CALL
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 );
161 sal_Int32 SAL_CALL
162 ScVbaCommandBar::Type()
164 // #FIXME support msoBarTypePopup
165 sal_Int32 nType
166 = m_bIsMenu ? office::MsoBarType::msoBarTypeNormal : office::MsoBarType::msoBarTypeMenuBar;
167 return nType;
170 uno::Any SAL_CALL
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 > () );
177 OUString
178 ScVbaCommandBar::getServiceImplName()
180 return "ScVbaCommandBar";
183 uno::Sequence<OUString>
184 ScVbaCommandBar::getServiceNames()
186 static uno::Sequence< OUString > const aServiceNames
188 "ooo.vba.CommandBar"
190 return aServiceNames;
194 VbaDummyCommandBar::VbaDummyCommandBar(
195 const uno::Reference< ov::XHelperInterface >& xParent,
196 const uno::Reference< uno::XComponentContext >& xContext,
197 OUString sName ) :
198 CommandBar_BASE( xParent, xContext ),
199 maName(std::move( sName ))
203 OUString SAL_CALL VbaDummyCommandBar::getName()
205 return maName;
208 void SAL_CALL VbaDummyCommandBar::setName( const OUString& _name )
210 maName = _name;
213 sal_Bool SAL_CALL VbaDummyCommandBar::getVisible()
215 // #STUB
216 return true;
219 void SAL_CALL VbaDummyCommandBar::setVisible( sal_Bool /*_visible*/ )
221 // #STUB
224 sal_Bool SAL_CALL VbaDummyCommandBar::getEnabled()
226 // emulated with Visible
227 return getVisible();
230 void SAL_CALL VbaDummyCommandBar::setEnabled( sal_Bool _enabled )
232 // emulated with Visible
233 setVisible( _enabled );
236 void SAL_CALL VbaDummyCommandBar::Delete( )
238 // no-op
239 // #STUB
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
269 "ooo.vba.CommandBar"
271 return aServiceNames;
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */