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