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 "vbacommandbar.hxx"
20 : #include "vbacommandbarcontrols.hxx"
21 : #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
22 : #include <com/sun/star/frame/XFrame.hpp>
23 : #include <com/sun/star/frame/XDesktop.hpp>
24 : #include <com/sun/star/frame/XLayoutManager.hpp>
25 : #include <com/sun/star/beans/XPropertySet.hpp>
26 : #include <com/sun/star/container/XNameContainer.hpp>
27 : #include <ooo/vba/office/MsoBarType.hpp>
28 :
29 : using namespace com::sun::star;
30 : using namespace ooo::vba;
31 :
32 0 : ScVbaCommandBar::ScVbaCommandBar( const uno::Reference< ov::XHelperInterface >& xParent,
33 : const uno::Reference< uno::XComponentContext >& xContext,
34 : VbaCommandBarHelperRef pHelper,
35 : const uno::Reference< container::XIndexAccess >& xBarSettings,
36 : const OUString& sResourceUrl, bool bIsMenu ) throw( uno::RuntimeException )
37 0 : : CommandBar_BASE( xParent, xContext ), pCBarHelper( pHelper ), m_xBarSettings( xBarSettings ), m_sResourceUrl( sResourceUrl ), m_bIsMenu( bIsMenu )
38 : {
39 0 : }
40 :
41 : OUString SAL_CALL
42 0 : ScVbaCommandBar::getName() throw ( uno::RuntimeException, std::exception )
43 : {
44 : // This will get a "NULL length string" when Name is not set.
45 0 : uno::Reference< beans::XPropertySet > xPropertySet( m_xBarSettings, uno::UNO_QUERY_THROW );
46 0 : uno::Any aName = xPropertySet->getPropertyValue( "UIName" );
47 0 : OUString sName;
48 0 : aName >>= sName;
49 0 : if( sName.isEmpty() )
50 : {
51 0 : if( m_bIsMenu )
52 : {
53 0 : if( m_sResourceUrl == ITEM_MENUBAR_URL )
54 : {
55 0 : if( pCBarHelper->getModuleId() == "com.sun.star.sheet.SpreadsheetDocument" )
56 0 : sName = "Worksheet Menu Bar";
57 0 : else if( pCBarHelper->getModuleId() == "com.sun.star.text.TextDocument" )
58 0 : sName = "Menu Bar";
59 0 : return sName;
60 : }
61 : }
62 : // Toolbar name
63 0 : uno::Reference< container::XNameAccess > xNameAccess = pCBarHelper->getPersistentWindowState();
64 0 : if( xNameAccess->hasByName( m_sResourceUrl ) )
65 : {
66 0 : uno::Sequence< beans::PropertyValue > aToolBar;
67 0 : xNameAccess->getByName( m_sResourceUrl ) >>= aToolBar;
68 0 : getPropertyValue( aToolBar, "UIName" ) >>= sName;
69 0 : }
70 : }
71 0 : return sName;
72 : }
73 : void SAL_CALL
74 0 : ScVbaCommandBar::setName( const OUString& _name ) throw (uno::RuntimeException, std::exception)
75 : {
76 0 : uno::Reference< beans::XPropertySet > xPropertySet( m_xBarSettings, uno::UNO_QUERY_THROW );
77 0 : xPropertySet->setPropertyValue( "UIName" , uno::makeAny( _name ) );
78 :
79 0 : pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings );
80 0 : }
81 : sal_Bool SAL_CALL
82 0 : ScVbaCommandBar::getVisible() throw (uno::RuntimeException, std::exception)
83 : {
84 : // menu bar is always visible in OOo
85 0 : if( m_bIsMenu )
86 0 : return sal_True;
87 :
88 0 : bool bVisible = false;
89 : try
90 : {
91 0 : uno::Reference< container::XNameAccess > xNameAccess = pCBarHelper->getPersistentWindowState();
92 0 : if( xNameAccess->hasByName( m_sResourceUrl ) )
93 : {
94 0 : uno::Sequence< beans::PropertyValue > aToolBar;
95 0 : xNameAccess->getByName( m_sResourceUrl ) >>= aToolBar;
96 0 : getPropertyValue( aToolBar, "Visible" ) >>= bVisible;
97 0 : }
98 : }
99 0 : catch (const uno::Exception&)
100 : {
101 : }
102 0 : return bVisible;
103 : }
104 : void SAL_CALL
105 0 : ScVbaCommandBar::setVisible( sal_Bool _visible ) throw (uno::RuntimeException, std::exception)
106 : {
107 : try
108 : {
109 0 : uno::Reference< frame::XLayoutManager > xLayoutManager = pCBarHelper->getLayoutManager();
110 0 : if( _visible )
111 : {
112 0 : xLayoutManager->createElement( m_sResourceUrl );
113 0 : xLayoutManager->showElement( m_sResourceUrl );
114 : }
115 : else
116 : {
117 0 : xLayoutManager->hideElement( m_sResourceUrl );
118 0 : xLayoutManager->destroyElement( m_sResourceUrl );
119 0 : }
120 : }
121 0 : catch(const uno::Exception&)
122 : {
123 : SAL_INFO("vbahelper", "SetVisible get an exception" );
124 : }
125 0 : }
126 :
127 : sal_Bool SAL_CALL
128 0 : ScVbaCommandBar::getEnabled() throw (uno::RuntimeException, std::exception)
129 : {
130 : // emulated with Visible
131 0 : return getVisible();
132 : }
133 :
134 : void SAL_CALL
135 0 : ScVbaCommandBar::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException, std::exception)
136 : {
137 : // emulated with Visible
138 0 : setVisible( _enabled );
139 0 : }
140 :
141 : void SAL_CALL
142 0 : ScVbaCommandBar::Delete( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
143 : {
144 0 : pCBarHelper->removeSettings( m_sResourceUrl );
145 0 : uno::Reference< container::XNameContainer > xNameContainer( pCBarHelper->getPersistentWindowState(), uno::UNO_QUERY_THROW );
146 0 : if( xNameContainer->hasByName( m_sResourceUrl ) )
147 : {
148 0 : xNameContainer->removeByName( m_sResourceUrl );
149 0 : }
150 0 : }
151 : uno::Any SAL_CALL
152 0 : ScVbaCommandBar::Controls( const uno::Any& aIndex ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
153 : {
154 0 : uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, m_xBarSettings, pCBarHelper, m_xBarSettings, m_sResourceUrl ) );
155 0 : if( aIndex.hasValue() )
156 : {
157 0 : return xCommandBarControls->Item( aIndex, uno::Any() );
158 : }
159 0 : return uno::makeAny( xCommandBarControls );
160 : }
161 :
162 : sal_Int32 SAL_CALL
163 0 : ScVbaCommandBar::Type() throw (script::BasicErrorException, uno::RuntimeException, std::exception)
164 : {
165 : // #FIXME support msoBarTypePopup
166 0 : sal_Int32 nType = office::MsoBarType::msoBarTypePopup;
167 0 : nType = m_bIsMenu? office::MsoBarType::msoBarTypeNormal : office::MsoBarType::msoBarTypeMenuBar;
168 0 : return nType;
169 : }
170 :
171 : uno::Any SAL_CALL
172 0 : ScVbaCommandBar::FindControl( const uno::Any& /*aType*/, const uno::Any& /*aId*/, const uno::Any& /*aTag*/, const uno::Any& /*aVisible*/, const uno::Any& /*aRecursive*/ ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
173 : {
174 : // alwayse fail to find control
175 0 : return uno::makeAny( uno::Reference< XCommandBarControl > () );
176 : }
177 :
178 : OUString
179 0 : ScVbaCommandBar::getServiceImplName()
180 : {
181 0 : return OUString("ScVbaCommandBar");
182 : }
183 :
184 : uno::Sequence<OUString>
185 0 : ScVbaCommandBar::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.CommandBar";
192 : }
193 0 : return aServiceNames;
194 : }
195 :
196 :
197 0 : VbaDummyCommandBar::VbaDummyCommandBar(
198 : const uno::Reference< ov::XHelperInterface >& xParent,
199 : const uno::Reference< uno::XComponentContext >& xContext,
200 : const OUString& rName, sal_Int32 nType ) throw( uno::RuntimeException ) :
201 : CommandBar_BASE( xParent, xContext ),
202 : maName( rName ),
203 0 : mnType( nType )
204 : {
205 0 : }
206 :
207 0 : OUString SAL_CALL VbaDummyCommandBar::getName() throw ( uno::RuntimeException, std::exception )
208 : {
209 0 : return maName;
210 : }
211 :
212 0 : void SAL_CALL VbaDummyCommandBar::setName( const OUString& _name ) throw (uno::RuntimeException, std::exception)
213 : {
214 0 : maName = _name;
215 0 : }
216 :
217 0 : sal_Bool SAL_CALL VbaDummyCommandBar::getVisible() throw (uno::RuntimeException, std::exception)
218 : {
219 : // #STUB
220 0 : return sal_True;
221 : }
222 :
223 0 : void SAL_CALL VbaDummyCommandBar::setVisible( sal_Bool /*_visible*/ ) throw (uno::RuntimeException, std::exception)
224 : {
225 : // #STUB
226 0 : }
227 :
228 0 : sal_Bool SAL_CALL VbaDummyCommandBar::getEnabled() throw (uno::RuntimeException, std::exception)
229 : {
230 : // emulated with Visible
231 0 : return getVisible();
232 : }
233 :
234 0 : void SAL_CALL VbaDummyCommandBar::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException, std::exception)
235 : {
236 : // emulated with Visible
237 0 : setVisible( _enabled );
238 0 : }
239 :
240 0 : void SAL_CALL VbaDummyCommandBar::Delete( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
241 : {
242 : // no-op
243 : // #STUB
244 0 : }
245 :
246 0 : uno::Any SAL_CALL VbaDummyCommandBar::Controls( const uno::Any& aIndex ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
247 : {
248 0 : uno::Reference< XCommandBarControls > xCommandBarControls( new VbaDummyCommandBarControls( this, mxContext ) );
249 0 : if( aIndex.hasValue() )
250 0 : return xCommandBarControls->Item( aIndex, uno::Any() );
251 0 : return uno::Any( xCommandBarControls );
252 : }
253 :
254 0 : sal_Int32 SAL_CALL VbaDummyCommandBar::Type() throw (script::BasicErrorException, uno::RuntimeException, std::exception)
255 : {
256 0 : return mnType;
257 : }
258 :
259 0 : 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*/ ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
260 : {
261 0 : return uno::Any( uno::Reference< XCommandBarControl >() );
262 : }
263 :
264 0 : OUString VbaDummyCommandBar::getServiceImplName()
265 : {
266 0 : return OUString("VbaDummyCommandBar");
267 : }
268 :
269 0 : uno::Sequence< OUString > VbaDummyCommandBar::getServiceNames()
270 : {
271 0 : static uno::Sequence< OUString > aServiceNames;
272 0 : if ( aServiceNames.getLength() == 0 )
273 : {
274 0 : aServiceNames.realloc( 1 );
275 0 : aServiceNames[ 0 ] = "ooo.vba.CommandBar";
276 : }
277 0 : return aServiceNames;
278 : }
279 :
280 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|