LibreOffice Module vbahelper (master) 1
vbacommandbarcontrol.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 */
21#include <utility>
24#include <sal/log.hxx>
25
26using namespace com::sun::star;
27using namespace ooo::vba;
28
29ScVbaCommandBarControl::ScVbaCommandBarControl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, css::uno::Reference< css::container::XIndexAccess > xSettings, VbaCommandBarHelperRef pHelper, css::uno::Reference< css::container::XIndexAccess > xBarSettings, OUString sResourceUrl ) : CommandBarControl_BASE( xParent, xContext ), pCBarHelper(std::move( pHelper )), m_sResourceUrl(std::move( sResourceUrl )), m_xCurrentSettings(std::move( xSettings )), m_xBarSettings(std::move( xBarSettings )), m_nPosition( 0 )
30{
31}
32
34{
35 uno::Reference< container::XIndexContainer > xIndexContainer( m_xCurrentSettings, uno::UNO_QUERY_THROW );
36 xIndexContainer->replaceByIndex( m_nPosition, uno::Any( m_aPropertyValues ) );
37 pCBarHelper->ApplyTempChange( m_sResourceUrl, m_xBarSettings );
38}
39
40OUString SAL_CALL
42{
43 // "Label" always empty
44 OUString sCaption;
45 getPropertyValue( m_aPropertyValues, "Label" ) >>= sCaption;
46 return sCaption;
47}
48
49void SAL_CALL
50ScVbaCommandBarControl::setCaption( const OUString& _caption )
51{
52 OUString sCaption = _caption.replace('&','~');
53 setPropertyValue( m_aPropertyValues, "Label" , uno::Any( sCaption ) );
55}
56
57OUString SAL_CALL
59{
60 OUString sCommandURL;
61 getPropertyValue( m_aPropertyValues, "CommandURL" ) >>= sCommandURL;
62 return sCommandURL;
63}
64
65void SAL_CALL
66ScVbaCommandBarControl::setOnAction( const OUString& _onaction )
67{
68 // get the current model
69 uno::Reference< frame::XModel > xModel( pCBarHelper->getModel() );
70 MacroResolvedInfo aResolvedMacro = ooo::vba::resolveVBAMacro( getSfxObjShell( xModel ), _onaction, true );
71 if ( aResolvedMacro.mbFound )
72 {
73 OUString aCommandURL = ooo::vba::makeMacroURL( aResolvedMacro.msResolvedMacro );
74 SAL_INFO("vbahelper", "ScVbaCommandBarControl::setOnAction: " << aCommandURL);
75 setPropertyValue( m_aPropertyValues, "CommandURL" , uno::Any( aCommandURL ) );
77 }
78}
79
80sal_Bool SAL_CALL
82{
83 bool bVisible = true;
85 if( aValue.hasValue() )
86 aValue >>= bVisible;
87 return bVisible;
88}
89void SAL_CALL
91{
93 if( aValue.hasValue() )
94 {
97 }
98}
99
100sal_Bool SAL_CALL
102{
103 bool bEnabled = true;
104
106 if( aValue.hasValue() )
107 {
108 aValue >>= bEnabled;
109 }
110 else
111 {
112 // emulated with Visible
113 bEnabled = getVisible();
114 }
115 return bEnabled;
116}
117
118void SAL_CALL
120{
122 if( aValue.hasValue() )
123 {
125 ApplyChange();
126 }
127 else
128 {
129 // emulated with Visible
130 setVisible( _enabled );
131 }
132}
133
134sal_Bool SAL_CALL
136{
137 // TODO: need to check if the item before this item is of type 'separator'
138 //#STUB
139 return false;
140}
141
142void SAL_CALL
144{
145 if( getBeginGroup() != _begin )
146 {
147 // TODO: need to insert or remove an item of type 'separator' before this item
148 }
149}
150
151void SAL_CALL
153{
154 if( m_xCurrentSettings.is() )
155 {
156 uno::Reference< container::XIndexContainer > xIndexContainer( m_xCurrentSettings, uno::UNO_QUERY_THROW );
157 xIndexContainer->removeByIndex( m_nPosition );
158
159 pCBarHelper->ApplyTempChange( m_sResourceUrl, m_xBarSettings );
160 }
161}
162
163uno::Any SAL_CALL
165{
166 // only Popup Menu has controls
167 uno::Reference< container::XIndexAccess > xSubMenu;
169 if( !xSubMenu.is() )
170 throw uno::RuntimeException();
171
172 uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, xSubMenu, pCBarHelper, m_xBarSettings, m_sResourceUrl ) );
173 if( aIndex.hasValue() )
174 {
175 return xCommandBarControls->Item( aIndex, uno::Any() );
176 }
177 return uno::Any( xCommandBarControls );
178}
179
180OUString
182{
183 return "ScVbaCommandBarControl";
184}
185
186uno::Sequence<OUString>
188{
189 static uno::Sequence< OUString > const aServiceNames
190 {
191 "ooo.vba.CommandBarControl"
192 };
193 return aServiceNames;
194}
195
196// ScVbaCommandBarPopup
197ScVbaCommandBarPopup::ScVbaCommandBarPopup( const css::uno::Reference< ov::XHelperInterface >& xParent,
198 const css::uno::Reference< css::uno::XComponentContext >& xContext,
199 const css::uno::Reference< css::container::XIndexAccess >& xSettings,
200 const VbaCommandBarHelperRef& pHelper,
201 const css::uno::Reference< css::container::XIndexAccess >& xBarSettings,
202 const OUString& sResourceUrl,
203 sal_Int32 nPosition )
204 : CommandBarPopup_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl )
205{
206 m_nPosition = nPosition;
207 m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues;
208}
209
210OUString
212{
213 return "ScVbaCommandBarPopup";
214}
215
216uno::Sequence<OUString>
218{
219 static uno::Sequence< OUString > const aServiceNames
220 {
221 "ooo.vba.CommandBarPopup"
222 };
223 return aServiceNames;
224}
225
226// ScVbaCommandBarButton
227ScVbaCommandBarButton::ScVbaCommandBarButton( const css::uno::Reference< ov::XHelperInterface >& xParent,
228 const css::uno::Reference< css::uno::XComponentContext >& xContext,
229 const css::uno::Reference< css::container::XIndexAccess >& xSettings,
230 const VbaCommandBarHelperRef& pHelper,
231 const css::uno::Reference< css::container::XIndexAccess >& xBarSettings,
232 const OUString& sResourceUrl,
233 sal_Int32 nPosition )
234 : CommandBarButton_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl )
235{
236 m_nPosition = nPosition;
237 m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues;
238}
239
240OUString
242{
243 return "ScVbaCommandBarButton";
244}
245
246uno::Sequence<OUString>
248{
249 static uno::Sequence< OUString > const aServiceNames
250 {
251 "ooo.vba.CommandBarButton"
252 };
253 return aServiceNames;
254}
255
256/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 m_nPosition
css::uno::Reference< css::uno::XComponentContext > mxContext
ScVbaCommandBarButton(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::container::XIndexAccess > &xSettings, const VbaCommandBarHelperRef &pHelper, const css::uno::Reference< css::container::XIndexAccess > &xBarSettings, const OUString &sResourceUrl, sal_Int32 nPosition)
virtual OUString getServiceImplName() override
virtual css::uno::Sequence< OUString > getServiceNames() override
css::uno::Sequence< css::beans::PropertyValue > m_aPropertyValues
css::uno::Reference< css::container::XIndexAccess > m_xBarSettings
virtual css::uno::Any SAL_CALL Controls(const css::uno::Any &aIndex) override
virtual void SAL_CALL setCaption(const OUString &_caption) override
virtual OUString SAL_CALL getOnAction() override
virtual OUString getServiceImplName() override
virtual OUString SAL_CALL getCaption() override
virtual void SAL_CALL setVisible(sal_Bool _visible) override
VbaCommandBarHelperRef pCBarHelper
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual void SAL_CALL Delete() override
virtual void SAL_CALL setEnabled(sal_Bool _enabled) override
css::uno::Reference< css::container::XIndexAccess > m_xCurrentSettings
virtual void SAL_CALL setOnAction(const OUString &_onaction) override
ScVbaCommandBarControl(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, css::uno::Reference< css::container::XIndexAccess > xSettings, VbaCommandBarHelperRef pHelper, css::uno::Reference< css::container::XIndexAccess > xBarSettings, OUString sResourceUrl)
virtual sal_Bool SAL_CALL getBeginGroup() override
virtual void SAL_CALL setBeginGroup(sal_Bool _begin) override
virtual sal_Bool SAL_CALL getEnabled() override
virtual sal_Bool SAL_CALL getVisible() override
virtual OUString getServiceImplName() override
virtual css::uno::Sequence< OUString > getServiceNames() override
ScVbaCommandBarPopup(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::container::XIndexAccess > &xSettings, const VbaCommandBarHelperRef &pHelper, const css::uno::Reference< css::container::XIndexAccess > &xBarSettings, const OUString &sResourceUrl, sal_Int32 nPosition)
std::deque< AttacherIndex_Impl > aIndex
Sequence< OUString > aServiceNames
#define SAL_INFO(area, stream)
void setPropertyValue(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
OUString makeMacroURL(std::u16string_view sMacroName)
uno::Any getPropertyValue(const uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName)
Definition: vbahelper.cxx:714
SfxObjectShell * getSfxObjShell(const uno::Reference< frame::XModel > &xModel)
Definition: vbahelper.cxx:1113
OUString resolveVBAMacro(SfxObjectShell const *pShell, const OUString &rLibName, const OUString &rModuleName, const OUString &rMacroName, bool bOnlyPublic, const OUString &sSkipModule)
bool hasValue()
Reference< XModel > xModel
PropertyValues m_aPropertyValues
bool bVisible
unsigned char sal_Bool
cppu::ImplInheritanceHelper< ScVbaCommandBarControl, ov::XCommandBarPopup > CommandBarPopup_BASE
cppu::ImplInheritanceHelper< ScVbaCommandBarControl, ov::XCommandBarButton > CommandBarButton_BASE
constexpr OUStringLiteral ITEM_DESCRIPTOR_ISVISIBLE
std::shared_ptr< VbaCommandBarHelper > VbaCommandBarHelperRef
constexpr OUStringLiteral ITEM_DESCRIPTOR_ENABLED
constexpr OUStringLiteral ITEM_DESCRIPTOR_CONTAINER