1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: buttontoolbarcontroller.cxx,v $
10 * $Revision: 1.8.40.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 #ifndef __FRAMEWORK_UIELEMENT_BUTTONTOOLBARCONTROLLER_HXX
35 #include "uielement/buttontoolbarcontroller.hxx"
38 //_________________________________________________________________________________________________________________
40 //_________________________________________________________________________________________________________________
42 #ifndef __FRAMEWORK_TOOLBAR_HXX_
43 #include "uielement/toolbar.hxx"
46 //_________________________________________________________________________________________________________________
48 //_________________________________________________________________________________________________________________
49 #include <com/sun/star/util/XURLTransformer.hpp>
50 #include <com/sun/star/frame/XDispatchProvider.hpp>
51 #include <com/sun/star/beans/PropertyValue.hpp>
52 #include <com/sun/star/lang/DisposedException.hpp>
53 #include "com/sun/star/util/XMacroExpander.hpp"
54 #include "com/sun/star/uno/XComponentContext.hpp"
55 #include "com/sun/star/beans/XPropertySet.hpp"
57 //_________________________________________________________________________________________________________________
59 //_________________________________________________________________________________________________________________
61 #include <rtl/uri.hxx>
62 #include <vos/mutex.hxx>
63 #include <comphelper/processfactory.hxx>
64 #include <unotools/ucbstreamhelper.hxx>
65 #include <tools/urlobj.hxx>
66 #include <vcl/svapp.hxx>
67 #include <vcl/mnemonic.hxx>
68 #include <vcl/window.hxx>
69 #include <vcl/graph.hxx>
70 #include <vcl/bitmap.hxx>
71 #include <svtools/filter.hxx>
72 #include <svtools/miscopt.hxx>
73 #include <dispatch/uieventloghelper.hxx>
75 using namespace ::com::sun::star
;
76 using namespace ::com::sun::star::awt
;
77 using namespace ::com::sun::star::uno
;
78 using namespace ::com::sun::star::beans
;
79 using namespace ::com::sun::star::lang
;
80 using namespace ::com::sun::star::frame
;
81 using namespace ::com::sun::star::util
;
86 ButtonToolbarController::ButtonToolbarController(
87 const uno::Reference
< lang::XMultiServiceFactory
>& rServiceManager
,
89 const rtl::OUString
& aCommand
) :
91 m_bInitialized( sal_False
),
92 m_bDisposed( sal_False
),
93 m_aCommandURL( aCommand
),
94 m_xServiceManager( rServiceManager
),
95 m_pToolbar( pToolBar
)
99 ButtonToolbarController::~ButtonToolbarController()
104 uno::Any SAL_CALL
ButtonToolbarController::queryInterface( const uno::Type
& rType
)
105 throw (::com::sun::star::uno::RuntimeException
)
107 Any a
= ::cppu::queryInterface(
109 static_cast< frame::XStatusListener
* >( this ),
110 static_cast< frame::XToolbarController
* >( this ),
111 static_cast< lang::XInitialization
* >( this ),
112 static_cast< lang::XComponent
* >( this ),
113 static_cast< util::XUpdatable
* >( this ));
118 return cppu::OWeakObject::queryInterface( rType
);
121 void SAL_CALL
ButtonToolbarController::acquire() throw ()
123 cppu::OWeakObject::acquire();
126 void SAL_CALL
ButtonToolbarController::release() throw ()
128 cppu::OWeakObject::release();
132 void SAL_CALL
ButtonToolbarController::initialize(
133 const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& aArguments
)
134 throw (::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
)
136 const rtl::OUString
aFrameName( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
137 const rtl::OUString
aCommandURLName( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" ));
138 const rtl::OUString
aServiceManagerName( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" ));
140 bool bInitialized( true );
143 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
146 throw DisposedException();
148 bInitialized
= m_bInitialized
;
153 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
154 m_bInitialized
= sal_True
;
156 PropertyValue aPropValue
;
157 for ( int i
= 0; i
< aArguments
.getLength(); i
++ )
159 if ( aArguments
[i
] >>= aPropValue
)
161 if ( aPropValue
.Name
.equalsAscii( "Frame" ))
162 m_xFrame
.set(aPropValue
.Value
,UNO_QUERY
);
163 else if ( aPropValue
.Name
.equalsAscii( "CommandURL" ))
164 aPropValue
.Value
>>= m_aCommandURL
;
165 else if ( aPropValue
.Name
.equalsAscii( "ServiceManager" ))
166 m_xServiceManager
.set(aPropValue
.Value
,UNO_QUERY
);
173 void SAL_CALL
ButtonToolbarController::dispose() throw (::com::sun::star::uno::RuntimeException
)
175 Reference
< XComponent
> xThis( static_cast< OWeakObject
* >(this), UNO_QUERY
);
178 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
180 throw DisposedException();
182 m_xServiceManager
.clear();
183 m_xURLTransformer
.clear();
186 m_bDisposed
= sal_True
;
190 void SAL_CALL
ButtonToolbarController::addEventListener(
191 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& )
192 throw (::com::sun::star::uno::RuntimeException
)
197 void SAL_CALL
ButtonToolbarController::removeEventListener(
198 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& )
199 throw (::com::sun::star::uno::RuntimeException
)
205 void SAL_CALL
ButtonToolbarController::update()
206 throw (::com::sun::star::uno::RuntimeException
)
208 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
210 throw DisposedException();
214 void SAL_CALL
ButtonToolbarController::disposing(
215 const com::sun::star::lang::EventObject
& Source
)
216 throw ( ::com::sun::star::uno::RuntimeException
)
218 uno::Reference
< uno::XInterface
> xSource( Source
.Source
);
220 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
225 uno::Reference
< uno::XInterface
> xIfac( m_xFrame
, uno::UNO_QUERY
);
226 if ( xIfac
== xSource
)
230 void SAL_CALL
ButtonToolbarController::statusChanged( const ::com::sun::star::frame::FeatureStateEvent
& )
231 throw ( ::com::sun::star::uno::RuntimeException
)
235 throw DisposedException();
238 // XToolbarController
239 void SAL_CALL
ButtonToolbarController::execute( sal_Int16 KeyModifier
)
240 throw (::com::sun::star::uno::RuntimeException
)
242 uno::Reference
< frame::XDispatch
> xDispatch
;
243 uno::Reference
< frame::XFrame
> xFrame
;
244 uno::Reference
< util::XURLTransformer
> xURLTransformer
;
245 rtl::OUString aCommandURL
;
246 ::com::sun::star::util::URL aTargetURL
;
249 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
252 throw DisposedException();
254 if ( m_bInitialized
&&
256 m_xServiceManager
.is() &&
257 m_aCommandURL
.getLength() )
259 if ( !m_xURLTransformer
.is() )
261 m_xURLTransformer
= uno::Reference
< util::XURLTransformer
>(
262 m_xServiceManager
->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ))),
263 uno::UNO_QUERY_THROW
);
267 aCommandURL
= m_aCommandURL
;
268 xURLTransformer
= m_xURLTransformer
;
272 uno::Reference
< frame::XDispatchProvider
> xDispatchProvider( xFrame
, uno::UNO_QUERY
);
273 if ( xDispatchProvider
.is() )
275 aTargetURL
.Complete
= aCommandURL
;
276 xURLTransformer
->parseStrict( aTargetURL
);
277 xDispatch
= xDispatchProvider
->queryDispatch( aTargetURL
, ::rtl::OUString(), 0 );
280 if ( xDispatch
.is() )
284 Sequence
<PropertyValue
> aArgs( 1 );
286 // Provide key modifier information to dispatch function
287 aArgs
[0].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
288 aArgs
[0].Value
<<= KeyModifier
;
290 if(::comphelper::UiEventsLogger::isEnabled()) //#i88653#
291 UiEventLogHelper(::rtl::OUString::createFromAscii("ButtonToolbarController")).log(m_xServiceManager
, m_xFrame
, aTargetURL
, aArgs
);
292 xDispatch
->dispatch( aTargetURL
, aArgs
);
294 catch ( DisposedException
& )
300 void SAL_CALL
ButtonToolbarController::click()
301 throw (::com::sun::star::uno::RuntimeException
)
303 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
306 throw DisposedException();
308 sal_Int16
nKeyModifier( (sal_Int16
)m_pToolbar
->GetModifier() );
309 execute( nKeyModifier
);
312 void SAL_CALL
ButtonToolbarController::doubleClick()
313 throw (::com::sun::star::uno::RuntimeException
)
317 throw DisposedException();
320 uno::Reference
< awt::XWindow
> SAL_CALL
ButtonToolbarController::createPopupWindow()
321 throw (::com::sun::star::uno::RuntimeException
)
324 throw DisposedException();
326 return uno::Reference
< awt::XWindow
>();
329 uno::Reference
< awt::XWindow
> SAL_CALL
ButtonToolbarController::createItemWindow(
330 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& )
331 throw (::com::sun::star::uno::RuntimeException
)
334 throw DisposedException();
336 return uno::Reference
< awt::XWindow
>();