LibreOffice Module vbahelper (master) 1
vbacommandbar.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#include "vbacommandbar.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>
27
28using namespace com::sun::star;
29using namespace ooo::vba;
30
31ScVbaCommandBar::ScVbaCommandBar( const uno::Reference< ov::XHelperInterface >& xParent,
32 const uno::Reference< uno::XComponentContext >& xContext,
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 )
37{
38}
39
40OUString SAL_CALL
42{
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() )
49 {
50 if( m_bIsMenu )
51 {
53 {
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;
59 }
60 }
61 // Toolbar name
62 uno::Reference< container::XNameAccess > xNameAccess = pCBarHelper->getPersistentWindowState();
63 if( xNameAccess->hasByName( m_sResourceUrl ) )
64 {
65 uno::Sequence< beans::PropertyValue > aToolBar;
66 xNameAccess->getByName( m_sResourceUrl ) >>= aToolBar;
67 getPropertyValue( aToolBar, "UIName" ) >>= sName;
68 }
69 }
70 return sName;
71}
72void SAL_CALL
73ScVbaCommandBar::setName( const OUString& _name )
74{
75 uno::Reference< beans::XPropertySet > xPropertySet( m_xBarSettings, uno::UNO_QUERY_THROW );
76 xPropertySet->setPropertyValue( "UIName" , uno::Any( _name ) );
77
78 pCBarHelper->ApplyTempChange( m_sResourceUrl, m_xBarSettings );
79}
80sal_Bool SAL_CALL
82{
83 // menu bar is always visible in OOo
84 if( m_bIsMenu )
85 return true;
86
87 bool bVisible = false;
88 try
89 {
90 uno::Reference< container::XNameAccess > xNameAccess = pCBarHelper->getPersistentWindowState();
91 if( xNameAccess->hasByName( m_sResourceUrl ) )
92 {
93 uno::Sequence< beans::PropertyValue > aToolBar;
94 xNameAccess->getByName( m_sResourceUrl ) >>= aToolBar;
95 getPropertyValue( aToolBar, "Visible" ) >>= bVisible;
96 }
97 }
98 catch (const uno::Exception&)
99 {
100 }
101 return bVisible;
102}
103void SAL_CALL
105{
106 try
107 {
108 uno::Reference< frame::XLayoutManager > xLayoutManager = pCBarHelper->getLayoutManager();
109 if( _visible )
110 {
111 xLayoutManager->createElement( m_sResourceUrl );
112 xLayoutManager->showElement( m_sResourceUrl );
113 }
114 else
115 {
116 xLayoutManager->hideElement( m_sResourceUrl );
117 xLayoutManager->destroyElement( m_sResourceUrl );
118 }
119 }
120 catch(const uno::Exception&)
121 {
122 SAL_INFO("vbahelper", "SetVisible get an exception" );
123 }
124}
125
126sal_Bool SAL_CALL
128{
129 // emulated with Visible
130 return getVisible();
131}
132
133void SAL_CALL
135{
136 // emulated with Visible
137 setVisible( _enabled );
138}
139
140void SAL_CALL
142{
143 pCBarHelper->removeSettings( m_sResourceUrl );
144 uno::Reference< container::XNameContainer > xNameContainer( pCBarHelper->getPersistentWindowState(), uno::UNO_QUERY_THROW );
145 if( xNameContainer->hasByName( m_sResourceUrl ) )
146 {
147 xNameContainer->removeByName( m_sResourceUrl );
148 }
149}
150uno::Any SAL_CALL
152{
153 uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, m_xBarSettings, pCBarHelper, m_xBarSettings, m_sResourceUrl ) );
154 if( aIndex.hasValue() )
155 {
156 return xCommandBarControls->Item( aIndex, uno::Any() );
157 }
158 return uno::Any( xCommandBarControls );
159}
160
161sal_Int32 SAL_CALL
163{
164 // #FIXME support msoBarTypePopup
165 sal_Int32 nType
166 = m_bIsMenu ? office::MsoBarType::msoBarTypeNormal : office::MsoBarType::msoBarTypeMenuBar;
167 return nType;
168}
169
170uno::Any SAL_CALL
171ScVbaCommandBar::FindControl( const uno::Any& /*aType*/, const uno::Any& /*aId*/, const uno::Any& /*aTag*/, const uno::Any& /*aVisible*/, const uno::Any& /*aRecursive*/ )
172{
173 // alwayse fail to find control
174 return uno::Any( uno::Reference< XCommandBarControl > () );
175}
176
177OUString
179{
180 return "ScVbaCommandBar";
181}
182
183uno::Sequence<OUString>
185{
186 static uno::Sequence< OUString > const aServiceNames
187 {
188 "ooo.vba.CommandBar"
189 };
190 return aServiceNames;
191}
192
193
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 ))
200{
201}
202
204{
205 return maName;
206}
207
208void SAL_CALL VbaDummyCommandBar::setName( const OUString& _name )
209{
210 maName = _name;
211}
212
214{
215 // #STUB
216 return true;
217}
218
219void SAL_CALL VbaDummyCommandBar::setVisible( sal_Bool /*_visible*/ )
220{
221 // #STUB
222}
223
225{
226 // emulated with Visible
227 return getVisible();
228}
229
231{
232 // emulated with Visible
233 setVisible( _enabled );
234}
235
237{
238 // no-op
239 // #STUB
240}
241
243{
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 );
248}
249
250sal_Int32 SAL_CALL VbaDummyCommandBar::Type()
251{
252 return office::MsoBarType::msoBarTypePopup;
253}
254
255uno::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*/ )
256{
257 return uno::Any( uno::Reference< XCommandBarControl >() );
258}
259
261{
262 return "VbaDummyCommandBar";
263}
264
265uno::Sequence< OUString > VbaDummyCommandBar::getServiceNames()
266{
267 static uno::Sequence< OUString > const aServiceNames
268 {
269 "ooo.vba.CommandBar"
270 };
271 return aServiceNames;
272}
273
274/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString maName
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual sal_Bool SAL_CALL getEnabled() override
virtual void SAL_CALL setEnabled(sal_Bool _enabled) override
virtual void SAL_CALL setVisible(sal_Bool _visible) override
virtual void SAL_CALL setName(const OUString &_name) override
virtual sal_Int32 SAL_CALL Type() override
virtual OUString getServiceImplName() override
virtual css::uno::Any SAL_CALL FindControl(const css::uno::Any &aType, const css::uno::Any &aId, const css::uno::Any &aTag, const css::uno::Any &aVisible, const css::uno::Any &aRecursive) override
virtual sal_Bool SAL_CALL getVisible() override
VbaCommandBarHelperRef pCBarHelper
virtual void SAL_CALL Delete() override
virtual OUString SAL_CALL getName() override
OUString m_sResourceUrl
css::uno::Reference< css::container::XIndexAccess > m_xBarSettings
virtual css::uno::Sequence< OUString > getServiceNames() override
ScVbaCommandBar(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, VbaCommandBarHelperRef pHelper, css::uno::Reference< css::container::XIndexAccess > xBarSettings, OUString sResourceUrl, bool bIsMenu)
virtual css::uno::Any SAL_CALL Controls(const css::uno::Any &aIndex) override
VbaDummyCommandBar(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, OUString aName)
virtual void SAL_CALL setName(const OUString &_name) override
virtual void SAL_CALL setEnabled(sal_Bool _enabled) override
virtual void SAL_CALL setVisible(sal_Bool _visible) override
virtual css::uno::Any SAL_CALL FindControl(const css::uno::Any &aType, const css::uno::Any &aId, const css::uno::Any &aTag, const css::uno::Any &aVisible, const css::uno::Any &aRecursive) override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual css::uno::Any SAL_CALL Controls(const css::uno::Any &aIndex) override
virtual void SAL_CALL Delete() override
virtual sal_Int32 SAL_CALL Type() override
virtual sal_Bool SAL_CALL getEnabled() override
virtual OUString SAL_CALL getName() override
virtual sal_Bool SAL_CALL getVisible() override
virtual OUString getServiceImplName() override
std::deque< AttacherIndex_Impl > aIndex
Sequence< OUString > aServiceNames
OUString sName
OUString aName
#define SAL_INFO(area, stream)
uno::Any getPropertyValue(const uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName)
Definition: vbahelper.cxx:714
QPRO_FUNC_TYPE nType
bool bVisible
unsigned char sal_Bool
std::shared_ptr< VbaCommandBarHelper > VbaCommandBarHelperRef
constexpr OUStringLiteral ITEM_MENUBAR_URL