1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "uielement/buttontoolbarcontroller.hxx"
22 #include <com/sun/star/util/URLTransformer.hpp>
23 #include <com/sun/star/util/XURLTransformer.hpp>
24 #include <com/sun/star/frame/XDispatchProvider.hpp>
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <com/sun/star/lang/DisposedException.hpp>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/util/XMacroExpander.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <rtl/uri.hxx>
33 #include <osl/mutex.hxx>
34 #include <cppuhelper/queryinterface.hxx>
35 #include <comphelper/processfactory.hxx>
36 #include <unotools/ucbstreamhelper.hxx>
37 #include <vcl/svapp.hxx>
38 #include <vcl/mnemonic.hxx>
39 #include <vcl/window.hxx>
40 #include <vcl/graph.hxx>
41 #include <vcl/bitmap.hxx>
42 #include <vcl/graphicfilter.hxx>
43 #include <vcl/toolbox.hxx>
44 #include <svtools/miscopt.hxx>
46 using namespace ::com::sun::star
;
47 using namespace ::com::sun::star::awt
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::beans
;
50 using namespace ::com::sun::star::lang
;
51 using namespace ::com::sun::star::frame
;
52 using namespace ::com::sun::star::util
;
57 ButtonToolbarController::ButtonToolbarController(
58 const uno::Reference
< uno::XComponentContext
>& rxContext
,
60 const OUString
& aCommand
) :
62 m_bInitialized( false ),
64 m_aCommandURL( aCommand
),
65 m_xContext( rxContext
),
66 m_pToolbar( pToolBar
)
70 ButtonToolbarController::~ButtonToolbarController()
75 uno::Any SAL_CALL
ButtonToolbarController::queryInterface( const uno::Type
& rType
)
76 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
78 Any a
= ::cppu::queryInterface(
80 static_cast< frame::XStatusListener
* >( this ),
81 static_cast< frame::XToolbarController
* >( this ),
82 static_cast< lang::XInitialization
* >( this ),
83 static_cast< lang::XComponent
* >( this ),
84 static_cast< util::XUpdatable
* >( this ));
89 return cppu::OWeakObject::queryInterface( rType
);
92 void SAL_CALL
ButtonToolbarController::acquire() throw ()
94 cppu::OWeakObject::acquire();
97 void SAL_CALL
ButtonToolbarController::release() throw ()
99 cppu::OWeakObject::release();
103 void SAL_CALL
ButtonToolbarController::initialize(
104 const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& aArguments
)
105 throw (::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
, std::exception
)
107 bool bInitialized( true );
110 SolarMutexGuard aSolarMutexGuard
;
113 throw DisposedException();
115 bInitialized
= m_bInitialized
;
120 SolarMutexGuard aSolarMutexGuard
;
121 m_bInitialized
= true;
123 PropertyValue aPropValue
;
124 for ( int i
= 0; i
< aArguments
.getLength(); i
++ )
126 if ( aArguments
[i
] >>= aPropValue
)
128 if ( aPropValue
.Name
== "Frame" )
129 m_xFrame
.set(aPropValue
.Value
,UNO_QUERY
);
130 else if ( aPropValue
.Name
== "CommandURL" )
131 aPropValue
.Value
>>= m_aCommandURL
;
132 else if ( aPropValue
.Name
== "ServiceManager" )
134 Reference
<XMultiServiceFactory
> xServiceManager(aPropValue
.Value
,UNO_QUERY
);
135 m_xContext
= comphelper::getComponentContext(xServiceManager
);
143 void SAL_CALL
ButtonToolbarController::dispose() throw (::com::sun::star::uno::RuntimeException
, std::exception
)
145 Reference
< XComponent
> xThis( static_cast< OWeakObject
* >(this), UNO_QUERY
);
148 SolarMutexGuard aSolarMutexGuard
;
150 throw DisposedException();
153 m_xURLTransformer
.clear();
160 void SAL_CALL
ButtonToolbarController::addEventListener(
161 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& )
162 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
167 void SAL_CALL
ButtonToolbarController::removeEventListener(
168 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& )
169 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
175 void SAL_CALL
ButtonToolbarController::update()
176 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
178 SolarMutexGuard aSolarMutexGuard
;
180 throw DisposedException();
184 void SAL_CALL
ButtonToolbarController::disposing(
185 const com::sun::star::lang::EventObject
& Source
)
186 throw ( ::com::sun::star::uno::RuntimeException
, std::exception
)
188 uno::Reference
< uno::XInterface
> xSource( Source
.Source
);
190 SolarMutexGuard aSolarMutexGuard
;
195 uno::Reference
< uno::XInterface
> xIfac( m_xFrame
, uno::UNO_QUERY
);
196 if ( xIfac
== xSource
)
200 void SAL_CALL
ButtonToolbarController::statusChanged( const ::com::sun::star::frame::FeatureStateEvent
& )
201 throw ( ::com::sun::star::uno::RuntimeException
, std::exception
)
205 throw DisposedException();
208 // XToolbarController
209 void SAL_CALL
ButtonToolbarController::execute( sal_Int16 KeyModifier
)
210 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
212 uno::Reference
< frame::XDispatch
> xDispatch
;
213 uno::Reference
< frame::XFrame
> xFrame
;
214 uno::Reference
< util::XURLTransformer
> xURLTransformer
;
215 OUString aCommandURL
;
216 ::com::sun::star::util::URL aTargetURL
;
219 SolarMutexGuard aSolarMutexGuard
;
222 throw DisposedException();
224 if ( m_bInitialized
&&
227 !m_aCommandURL
.isEmpty() )
229 if ( !m_xURLTransformer
.is() )
231 m_xURLTransformer
= util::URLTransformer::create( m_xContext
);
235 aCommandURL
= m_aCommandURL
;
236 xURLTransformer
= m_xURLTransformer
;
240 uno::Reference
< frame::XDispatchProvider
> xDispatchProvider( xFrame
, uno::UNO_QUERY
);
241 if ( xDispatchProvider
.is() )
243 aTargetURL
.Complete
= aCommandURL
;
244 xURLTransformer
->parseStrict( aTargetURL
);
245 xDispatch
= xDispatchProvider
->queryDispatch( aTargetURL
, OUString(), 0 );
248 if ( xDispatch
.is() )
252 Sequence
<PropertyValue
> aArgs( 1 );
254 // Provide key modifier information to dispatch function
255 aArgs
[0].Name
= "KeyModifier";
256 aArgs
[0].Value
<<= KeyModifier
;
258 xDispatch
->dispatch( aTargetURL
, aArgs
);
260 catch ( const DisposedException
& )
266 void SAL_CALL
ButtonToolbarController::click()
267 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
269 SolarMutexGuard aSolarMutexGuard
;
272 throw DisposedException();
274 sal_Int16
nKeyModifier( (sal_Int16
)m_pToolbar
->GetModifier() );
275 execute( nKeyModifier
);
278 void SAL_CALL
ButtonToolbarController::doubleClick()
279 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
283 throw DisposedException();
286 uno::Reference
< awt::XWindow
> SAL_CALL
ButtonToolbarController::createPopupWindow()
287 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
290 throw DisposedException();
292 return uno::Reference
< awt::XWindow
>();
295 uno::Reference
< awt::XWindow
> SAL_CALL
ButtonToolbarController::createItemWindow(
296 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& )
297 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
300 throw DisposedException();
302 return uno::Reference
< awt::XWindow
>();
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */