Branch data 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 rtl::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( sal_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 : : ::rtl::OUString SAL_CALL
39 : 0 : ScVbaCommandBarControl::getCaption() throw ( uno::RuntimeException )
40 : : {
41 : : // "Label" always empty
42 : 0 : rtl::OUString sCaption;
43 [ # # ]: 0 : getPropertyValue( m_aPropertyValues, rtl::OUString("Label") ) >>= sCaption;
44 : 0 : return sCaption;
45 : : }
46 : :
47 : : void SAL_CALL
48 : 0 : ScVbaCommandBarControl::setCaption( const ::rtl::OUString& _caption ) throw (uno::RuntimeException)
49 : : {
50 : 0 : rtl::OUString sCaption = _caption.replace('&','~');
51 [ # # ][ # # ]: 0 : setPropertyValue( m_aPropertyValues, rtl::OUString("Label"), uno::makeAny( sCaption ) );
52 [ # # ]: 0 : ApplyChange();
53 : 0 : }
54 : :
55 : : ::rtl::OUString SAL_CALL
56 : 0 : ScVbaCommandBarControl::getOnAction() throw (uno::RuntimeException)
57 : : {
58 : 0 : rtl::OUString sCommandURL;
59 [ # # ]: 0 : getPropertyValue( m_aPropertyValues, rtl::OUString("CommandURL") ) >>= sCommandURL;
60 : 0 : return sCommandURL;
61 : : }
62 : :
63 : : void SAL_CALL
64 : 0 : ScVbaCommandBarControl::setOnAction( const ::rtl::OUString& _onaction ) throw (uno::RuntimeException)
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 : rtl::OUString aCommandURL = ooo::vba::makeMacroURL( aResolvedMacro.msResolvedMacro );
[ # # ]
72 : : OSL_TRACE(" ScVbaCommandBarControl::setOnAction: %s", rtl::OUStringToOString( aCommandURL, RTL_TEXTENCODING_UTF8 ).getStr() );
73 [ # # ][ # # ]: 0 : setPropertyValue( m_aPropertyValues, rtl::OUString("CommandURL"), uno::makeAny( aCommandURL ) );
74 [ # # ]: 0 : ApplyChange();
75 [ # # ]: 0 : }
76 : 0 : }
77 : :
78 : : ::sal_Bool SAL_CALL
79 : 0 : ScVbaCommandBarControl::getVisible() throw (uno::RuntimeException)
80 : : {
81 : 0 : sal_Bool bVisible = sal_True;
82 [ # # ]: 0 : uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( 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)
89 : : {
90 [ # # ]: 0 : uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ) );
91 [ # # ]: 0 : if( aValue.hasValue() )
92 : : {
93 [ # # ][ # # ]: 0 : setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( 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)
100 : : {
101 : 0 : sal_Bool bEnabled = sal_True;
102 : :
103 [ # # ]: 0 : uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( 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)
118 : : {
119 [ # # ]: 0 : uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED ) );
120 [ # # ]: 0 : if( aValue.hasValue() )
121 : : {
122 [ # # ][ # # ]: 0 : setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( 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)
134 : : {
135 : : // TODO: need to check if the item before this item is of type 'separator'
136 : 0 : return sal_False;
137 : : }
138 : :
139 : : void SAL_CALL
140 : 0 : ScVbaCommandBarControl::setBeginGroup( ::sal_Bool _begin ) throw (css::uno::RuntimeException)
141 : : {
142 : 0 : if( getBeginGroup() != _begin )
143 : : {
144 : : // TODO: need to insert or remove an item of type 'separator' before this item
145 : : }
146 : 0 : }
147 : :
148 : : void SAL_CALL
149 : 0 : ScVbaCommandBarControl::Delete( ) throw (script::BasicErrorException, uno::RuntimeException)
150 : : {
151 [ # # ]: 0 : if( m_xCurrentSettings.is() )
152 : : {
153 [ # # ]: 0 : uno::Reference< container::XIndexContainer > xIndexContainer( m_xCurrentSettings, uno::UNO_QUERY_THROW );
154 [ # # ][ # # ]: 0 : xIndexContainer->removeByIndex( m_nPosition );
155 : :
156 [ # # ]: 0 : pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings );
157 : : }
158 : 0 : }
159 : :
160 : : uno::Any SAL_CALL
161 : 0 : ScVbaCommandBarControl::Controls( const uno::Any& aIndex ) throw (script::BasicErrorException, uno::RuntimeException)
162 : : {
163 : : // only Popup Menu has controls
164 : 0 : uno::Reference< container::XIndexAccess > xSubMenu;
165 [ # # ][ # # ]: 0 : getPropertyValue( m_aPropertyValues, rtl::OUString( ITEM_DESCRIPTOR_CONTAINER ) ) >>= xSubMenu;
166 [ # # ]: 0 : if( !xSubMenu.is() )
167 [ # # ]: 0 : throw uno::RuntimeException();
168 : :
169 [ # # ][ # # ]: 0 : uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, xSubMenu, pCBarHelper, m_xBarSettings, m_sResourceUrl ) );
[ # # ][ # # ]
[ # # ][ # # ]
170 [ # # ]: 0 : if( aIndex.hasValue() )
171 : : {
172 [ # # ][ # # ]: 0 : return xCommandBarControls->Item( aIndex, uno::Any() );
173 : : }
174 [ # # ]: 0 : return uno::makeAny( xCommandBarControls );
175 : : }
176 : :
177 : : rtl::OUString
178 : 0 : ScVbaCommandBarControl::getServiceImplName()
179 : : {
180 : 0 : return rtl::OUString("ScVbaCommandBarControl");
181 : : }
182 : :
183 : : uno::Sequence<rtl::OUString>
184 : 0 : ScVbaCommandBarControl::getServiceNames()
185 : : {
186 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
187 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
188 : : {
189 : 0 : aServiceNames.realloc( 1 );
190 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( "ooo.vba.CommandBarControl" );
191 : : }
192 : 0 : return aServiceNames;
193 : : }
194 : :
195 : : //////////// ScVbaCommandBarPopup //////////////////////////////
196 : 0 : ScVbaCommandBarPopup::ScVbaCommandBarPopup( 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 rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException) : CommandBarPopup_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl )
197 : : {
198 : 0 : m_nPosition = nPosition;
199 : 0 : m_bTemporary = bTemporary;
200 [ # # ][ # # ]: 0 : m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues;
[ # # ]
201 : 0 : }
202 : :
203 : : rtl::OUString
204 : 0 : ScVbaCommandBarPopup::getServiceImplName()
205 : : {
206 : 0 : return rtl::OUString("ScVbaCommandBarPopup");
207 : : }
208 : :
209 : : uno::Sequence<rtl::OUString>
210 : 0 : ScVbaCommandBarPopup::getServiceNames()
211 : : {
212 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
213 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
214 : : {
215 : 0 : aServiceNames.realloc( 1 );
216 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( "ooo.vba.CommandBarPopup" );
217 : : }
218 : 0 : return aServiceNames;
219 : : }
220 : :
221 : : //////////// ScVbaCommandBarButton //////////////////////////////
222 : 0 : ScVbaCommandBarButton::ScVbaCommandBarButton( 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 rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException) : CommandBarButton_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl )
223 : : {
224 : 0 : m_nPosition = nPosition;
225 : 0 : m_bTemporary = bTemporary;
226 [ # # ][ # # ]: 0 : m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues;
[ # # ]
227 : 0 : }
228 : :
229 : : rtl::OUString
230 : 0 : ScVbaCommandBarButton::getServiceImplName()
231 : : {
232 : 0 : return rtl::OUString("ScVbaCommandBarButton");
233 : : }
234 : :
235 : : uno::Sequence<rtl::OUString>
236 : 0 : ScVbaCommandBarButton::getServiceNames()
237 : : {
238 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
239 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
240 : : {
241 : 0 : aServiceNames.realloc( 1 );
242 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( "ooo.vba.CommandBarButton" );
243 : : }
244 : 0 : return aServiceNames;
245 : : }
246 : :
247 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|