Line data Source code
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 "vbacommandbarcontrol.hxx"
20 : #include "vbacommandbarcontrols.hxx"
21 : #include <vbahelper/vbahelper.hxx>
22 : #include <filter/msfilter/msvbahelper.hxx>
23 :
24 : using namespace com::sun::star;
25 : using namespace ooo::vba;
26 :
27 0 : ScVbaCommandBarControl::ScVbaCommandBarControl( 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 OUString& sResourceUrl ) throw (css::uno::RuntimeException) : CommandBarControl_BASE( xParent, xContext ), pCBarHelper( pHelper ), m_sResourceUrl( sResourceUrl ), m_xCurrentSettings( xSettings ), m_xBarSettings( xBarSettings ), m_nPosition( 0 ), m_bTemporary( true )
28 : {
29 0 : }
30 :
31 0 : void ScVbaCommandBarControl::ApplyChange() throw ( uno::RuntimeException )
32 : {
33 0 : uno::Reference< container::XIndexContainer > xIndexContainer( m_xCurrentSettings, uno::UNO_QUERY_THROW );
34 0 : xIndexContainer->replaceByIndex( m_nPosition, uno::makeAny( m_aPropertyValues ) );
35 0 : pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings );
36 0 : }
37 :
38 : OUString SAL_CALL
39 0 : ScVbaCommandBarControl::getCaption() throw ( uno::RuntimeException, std::exception )
40 : {
41 : // "Label" always empty
42 0 : OUString sCaption;
43 0 : getPropertyValue( m_aPropertyValues, "Label" ) >>= sCaption;
44 0 : return sCaption;
45 : }
46 :
47 : void SAL_CALL
48 0 : ScVbaCommandBarControl::setCaption( const OUString& _caption ) throw (uno::RuntimeException, std::exception)
49 : {
50 0 : OUString sCaption = _caption.replace('&','~');
51 0 : setPropertyValue( m_aPropertyValues, "Label" , uno::makeAny( sCaption ) );
52 0 : ApplyChange();
53 0 : }
54 :
55 : OUString SAL_CALL
56 0 : ScVbaCommandBarControl::getOnAction() throw (uno::RuntimeException, std::exception)
57 : {
58 0 : OUString sCommandURL;
59 0 : getPropertyValue( m_aPropertyValues, "CommandURL" ) >>= sCommandURL;
60 0 : return sCommandURL;
61 : }
62 :
63 : void SAL_CALL
64 0 : ScVbaCommandBarControl::setOnAction( const OUString& _onaction ) throw (uno::RuntimeException, std::exception)
65 : {
66 : // get the current model
67 0 : uno::Reference< frame::XModel > xModel( pCBarHelper->getModel() );
68 0 : MacroResolvedInfo aResolvedMacro = ooo::vba::resolveVBAMacro( getSfxObjShell( xModel ), _onaction, true );
69 0 : if ( aResolvedMacro.mbFound )
70 : {
71 0 : OUString aCommandURL = ooo::vba::makeMacroURL( aResolvedMacro.msResolvedMacro );
72 : SAL_INFO("vbahelper", "ScVbaCommandBarControl::setOnAction: " << aCommandURL);
73 0 : setPropertyValue( m_aPropertyValues, "CommandURL" , uno::makeAny( aCommandURL ) );
74 0 : ApplyChange();
75 0 : }
76 0 : }
77 :
78 : sal_Bool SAL_CALL
79 0 : ScVbaCommandBarControl::getVisible() throw (uno::RuntimeException, std::exception)
80 : {
81 0 : bool bVisible = true;
82 0 : uno::Any aValue = getPropertyValue( m_aPropertyValues, ITEM_DESCRIPTOR_ISVISIBLE );
83 0 : if( aValue.hasValue() )
84 0 : aValue >>= bVisible;
85 0 : return bVisible;
86 : }
87 : void SAL_CALL
88 0 : ScVbaCommandBarControl::setVisible( sal_Bool _visible ) throw (uno::RuntimeException, std::exception)
89 : {
90 0 : uno::Any aValue = getPropertyValue( m_aPropertyValues, ITEM_DESCRIPTOR_ISVISIBLE );
91 0 : if( aValue.hasValue() )
92 : {
93 0 : setPropertyValue( m_aPropertyValues, ITEM_DESCRIPTOR_ISVISIBLE , uno::makeAny( _visible ) );
94 0 : ApplyChange();
95 0 : }
96 0 : }
97 :
98 : sal_Bool SAL_CALL
99 0 : ScVbaCommandBarControl::getEnabled() throw (uno::RuntimeException, std::exception)
100 : {
101 0 : bool bEnabled = true;
102 :
103 0 : uno::Any aValue = getPropertyValue( m_aPropertyValues, ITEM_DESCRIPTOR_ENABLED );
104 0 : if( aValue.hasValue() )
105 : {
106 0 : aValue >>= bEnabled;
107 : }
108 : else
109 : {
110 : // emulated with Visible
111 0 : bEnabled = getVisible();
112 : }
113 0 : return bEnabled;
114 : }
115 :
116 : void SAL_CALL
117 0 : ScVbaCommandBarControl::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException, std::exception)
118 : {
119 0 : uno::Any aValue = getPropertyValue( m_aPropertyValues, ITEM_DESCRIPTOR_ENABLED );
120 0 : if( aValue.hasValue() )
121 : {
122 0 : setPropertyValue( m_aPropertyValues, ITEM_DESCRIPTOR_ENABLED , uno::makeAny( _enabled ) );
123 0 : ApplyChange();
124 : }
125 : else
126 : {
127 : // emulated with Visible
128 0 : setVisible( _enabled );
129 0 : }
130 0 : }
131 :
132 : sal_Bool SAL_CALL
133 0 : ScVbaCommandBarControl::getBeginGroup() throw (css::uno::RuntimeException, std::exception)
134 : {
135 : // TODO: need to check if the item before this item is of type 'separator'
136 : //#STUB
137 0 : return sal_False;
138 : }
139 :
140 : void SAL_CALL
141 0 : ScVbaCommandBarControl::setBeginGroup( sal_Bool _begin ) throw (css::uno::RuntimeException, std::exception)
142 : {
143 0 : if( getBeginGroup() != _begin )
144 : {
145 : // TODO: need to insert or remove an item of type 'separator' before this item
146 : }
147 0 : }
148 :
149 : void SAL_CALL
150 0 : ScVbaCommandBarControl::Delete( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
151 : {
152 0 : if( m_xCurrentSettings.is() )
153 : {
154 0 : uno::Reference< container::XIndexContainer > xIndexContainer( m_xCurrentSettings, uno::UNO_QUERY_THROW );
155 0 : xIndexContainer->removeByIndex( m_nPosition );
156 :
157 0 : pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings );
158 : }
159 0 : }
160 :
161 : uno::Any SAL_CALL
162 0 : ScVbaCommandBarControl::Controls( const uno::Any& aIndex ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
163 : {
164 : // only Popup Menu has controls
165 0 : uno::Reference< container::XIndexAccess > xSubMenu;
166 0 : getPropertyValue( m_aPropertyValues, ITEM_DESCRIPTOR_CONTAINER ) >>= xSubMenu;
167 0 : if( !xSubMenu.is() )
168 0 : throw uno::RuntimeException();
169 :
170 0 : uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, xSubMenu, pCBarHelper, m_xBarSettings, m_sResourceUrl ) );
171 0 : if( aIndex.hasValue() )
172 : {
173 0 : return xCommandBarControls->Item( aIndex, uno::Any() );
174 : }
175 0 : return uno::makeAny( xCommandBarControls );
176 : }
177 :
178 : OUString
179 0 : ScVbaCommandBarControl::getServiceImplName()
180 : {
181 0 : return OUString("ScVbaCommandBarControl");
182 : }
183 :
184 : uno::Sequence<OUString>
185 0 : ScVbaCommandBarControl::getServiceNames()
186 : {
187 0 : static uno::Sequence< OUString > aServiceNames;
188 0 : if ( aServiceNames.getLength() == 0 )
189 : {
190 0 : aServiceNames.realloc( 1 );
191 0 : aServiceNames[ 0 ] = "ooo.vba.CommandBarControl";
192 : }
193 0 : return aServiceNames;
194 : }
195 :
196 : // ScVbaCommandBarPopup
197 0 : ScVbaCommandBarPopup::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 : VbaCommandBarHelperRef pHelper,
201 : const css::uno::Reference< css::container::XIndexAccess >& xBarSettings,
202 : const OUString& sResourceUrl,
203 : sal_Int32 nPosition,
204 : bool bTemporary ) throw (css::uno::RuntimeException)
205 0 : : CommandBarPopup_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl )
206 : {
207 0 : m_nPosition = nPosition;
208 0 : m_bTemporary = bTemporary;
209 0 : m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues;
210 0 : }
211 :
212 : OUString
213 0 : ScVbaCommandBarPopup::getServiceImplName()
214 : {
215 0 : return OUString("ScVbaCommandBarPopup");
216 : }
217 :
218 : uno::Sequence<OUString>
219 0 : ScVbaCommandBarPopup::getServiceNames()
220 : {
221 0 : static uno::Sequence< OUString > aServiceNames;
222 0 : if ( aServiceNames.getLength() == 0 )
223 : {
224 0 : aServiceNames.realloc( 1 );
225 0 : aServiceNames[ 0 ] = "ooo.vba.CommandBarPopup";
226 : }
227 0 : return aServiceNames;
228 : }
229 :
230 : // ScVbaCommandBarButton
231 0 : ScVbaCommandBarButton::ScVbaCommandBarButton( const css::uno::Reference< ov::XHelperInterface >& xParent,
232 : const css::uno::Reference< css::uno::XComponentContext >& xContext,
233 : const css::uno::Reference< css::container::XIndexAccess >& xSettings,
234 : VbaCommandBarHelperRef pHelper,
235 : const css::uno::Reference< css::container::XIndexAccess >& xBarSettings,
236 : const OUString& sResourceUrl,
237 : sal_Int32 nPosition,
238 : bool bTemporary ) throw (css::uno::RuntimeException)
239 0 : : CommandBarButton_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl )
240 : {
241 0 : m_nPosition = nPosition;
242 0 : m_bTemporary = bTemporary;
243 0 : m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues;
244 0 : }
245 :
246 : OUString
247 0 : ScVbaCommandBarButton::getServiceImplName()
248 : {
249 0 : return OUString("ScVbaCommandBarButton");
250 : }
251 :
252 : uno::Sequence<OUString>
253 0 : ScVbaCommandBarButton::getServiceNames()
254 : {
255 0 : static uno::Sequence< OUString > aServiceNames;
256 0 : if ( aServiceNames.getLength() == 0 )
257 : {
258 0 : aServiceNames.realloc( 1 );
259 0 : aServiceNames[ 0 ] = "ooo.vba.CommandBarButton";
260 : }
261 0 : return aServiceNames;
262 : }
263 :
264 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|