1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_framework.hxx" 26 27 #ifndef __FRAMEWORK_UIELEMENT_BUTTONTOOLBARCONTROLLER_HXX 28 #include "uielement/buttontoolbarcontroller.hxx" 29 #endif 30 31 //_________________________________________________________________________________________________________________ 32 // my own includes 33 //_________________________________________________________________________________________________________________ 34 35 #ifndef __FRAMEWORK_TOOLBAR_HXX_ 36 #include "uielement/toolbar.hxx" 37 #endif 38 39 //_________________________________________________________________________________________________________________ 40 // interface includes 41 //_________________________________________________________________________________________________________________ 42 #include <com/sun/star/util/XURLTransformer.hpp> 43 #include <com/sun/star/frame/XDispatchProvider.hpp> 44 #include <com/sun/star/beans/PropertyValue.hpp> 45 #include <com/sun/star/lang/DisposedException.hpp> 46 #include "com/sun/star/util/XMacroExpander.hpp" 47 #include "com/sun/star/uno/XComponentContext.hpp" 48 #include "com/sun/star/beans/XPropertySet.hpp" 49 50 //_________________________________________________________________________________________________________________ 51 // other includes 52 //_________________________________________________________________________________________________________________ 53 54 #include <rtl/uri.hxx> 55 #include <vos/mutex.hxx> 56 #include <comphelper/processfactory.hxx> 57 #include <unotools/ucbstreamhelper.hxx> 58 #include <tools/urlobj.hxx> 59 #include <vcl/svapp.hxx> 60 #include <vcl/mnemonic.hxx> 61 #include <vcl/window.hxx> 62 #include <vcl/graph.hxx> 63 #include <vcl/bitmap.hxx> 64 #include <svtools/filter.hxx> 65 #include <svtools/miscopt.hxx> 66 #include <dispatch/uieventloghelper.hxx> 67 68 using namespace ::com::sun::star; 69 using namespace ::com::sun::star::awt; 70 using namespace ::com::sun::star::uno; 71 using namespace ::com::sun::star::beans; 72 using namespace ::com::sun::star::lang; 73 using namespace ::com::sun::star::frame; 74 using namespace ::com::sun::star::util; 75 76 namespace framework 77 { 78 79 ButtonToolbarController::ButtonToolbarController( 80 const uno::Reference< lang::XMultiServiceFactory >& rServiceManager, 81 ToolBox* pToolBar, 82 const rtl::OUString& aCommand ) : 83 cppu::OWeakObject(), 84 m_bInitialized( sal_False ), 85 m_bDisposed( sal_False ), 86 m_aCommandURL( aCommand ), 87 m_xServiceManager( rServiceManager ), 88 m_pToolbar( pToolBar ) 89 { 90 } 91 92 ButtonToolbarController::~ButtonToolbarController() 93 { 94 } 95 96 // XInterface 97 uno::Any SAL_CALL ButtonToolbarController::queryInterface( const uno::Type& rType ) 98 throw (::com::sun::star::uno::RuntimeException) 99 { 100 Any a = ::cppu::queryInterface( 101 rType , 102 static_cast< frame::XStatusListener* >( this ), 103 static_cast< frame::XToolbarController* >( this ), 104 static_cast< lang::XInitialization* >( this ), 105 static_cast< lang::XComponent* >( this ), 106 static_cast< util::XUpdatable* >( this )); 107 108 if ( a.hasValue() ) 109 return a; 110 111 return cppu::OWeakObject::queryInterface( rType ); 112 } 113 114 void SAL_CALL ButtonToolbarController::acquire() throw () 115 { 116 cppu::OWeakObject::acquire(); 117 } 118 119 void SAL_CALL ButtonToolbarController::release() throw () 120 { 121 cppu::OWeakObject::release(); 122 } 123 124 // XInitialization 125 void SAL_CALL ButtonToolbarController::initialize( 126 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) 127 throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) 128 { 129 const rtl::OUString aFrameName( RTL_CONSTASCII_USTRINGPARAM( "Frame" )); 130 const rtl::OUString aCommandURLName( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" )); 131 const rtl::OUString aServiceManagerName( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" )); 132 133 bool bInitialized( true ); 134 135 { 136 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 137 138 if ( m_bDisposed ) 139 throw DisposedException(); 140 141 bInitialized = m_bInitialized; 142 } 143 144 if ( !bInitialized ) 145 { 146 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 147 m_bInitialized = sal_True; 148 149 PropertyValue aPropValue; 150 for ( int i = 0; i < aArguments.getLength(); i++ ) 151 { 152 if ( aArguments[i] >>= aPropValue ) 153 { 154 if ( aPropValue.Name.equalsAscii( "Frame" )) 155 m_xFrame.set(aPropValue.Value,UNO_QUERY); 156 else if ( aPropValue.Name.equalsAscii( "CommandURL" )) 157 aPropValue.Value >>= m_aCommandURL; 158 else if ( aPropValue.Name.equalsAscii( "ServiceManager" )) 159 m_xServiceManager.set(aPropValue.Value,UNO_QUERY); 160 } 161 } 162 } 163 } 164 165 // XComponent 166 void SAL_CALL ButtonToolbarController::dispose() throw (::com::sun::star::uno::RuntimeException) 167 { 168 Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY ); 169 170 { 171 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 172 if ( m_bDisposed ) 173 throw DisposedException(); 174 175 m_xServiceManager.clear(); 176 m_xURLTransformer.clear(); 177 m_xFrame.clear(); 178 m_pToolbar = 0; 179 m_bDisposed = sal_True; 180 } 181 } 182 183 void SAL_CALL ButtonToolbarController::addEventListener( 184 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& ) 185 throw (::com::sun::star::uno::RuntimeException) 186 { 187 // do nothing 188 } 189 190 void SAL_CALL ButtonToolbarController::removeEventListener( 191 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& ) 192 throw (::com::sun::star::uno::RuntimeException) 193 { 194 // do nothing 195 } 196 197 // XUpdatable 198 void SAL_CALL ButtonToolbarController::update() 199 throw (::com::sun::star::uno::RuntimeException) 200 { 201 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 202 if ( m_bDisposed ) 203 throw DisposedException(); 204 } 205 206 // XEventListener 207 void SAL_CALL ButtonToolbarController::disposing( 208 const com::sun::star::lang::EventObject& Source ) 209 throw ( ::com::sun::star::uno::RuntimeException ) 210 { 211 uno::Reference< uno::XInterface > xSource( Source.Source ); 212 213 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 214 215 if ( m_bDisposed ) 216 return; 217 218 uno::Reference< uno::XInterface > xIfac( m_xFrame, uno::UNO_QUERY ); 219 if ( xIfac == xSource ) 220 m_xFrame.clear(); 221 } 222 223 void SAL_CALL ButtonToolbarController::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& ) 224 throw ( ::com::sun::star::uno::RuntimeException ) 225 { 226 // do nothing 227 if ( m_bDisposed ) 228 throw DisposedException(); 229 } 230 231 // XToolbarController 232 void SAL_CALL ButtonToolbarController::execute( sal_Int16 KeyModifier ) 233 throw (::com::sun::star::uno::RuntimeException) 234 { 235 uno::Reference< frame::XDispatch > xDispatch; 236 uno::Reference< frame::XFrame > xFrame; 237 uno::Reference< util::XURLTransformer > xURLTransformer; 238 rtl::OUString aCommandURL; 239 ::com::sun::star::util::URL aTargetURL; 240 241 { 242 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 243 244 if ( m_bDisposed ) 245 throw DisposedException(); 246 247 if ( m_bInitialized && 248 m_xFrame.is() && 249 m_xServiceManager.is() && 250 m_aCommandURL.getLength() ) 251 { 252 if ( !m_xURLTransformer.is() ) 253 { 254 m_xURLTransformer = uno::Reference< util::XURLTransformer >( 255 m_xServiceManager->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ))), 256 uno::UNO_QUERY_THROW ); 257 } 258 259 xFrame = m_xFrame; 260 aCommandURL = m_aCommandURL; 261 xURLTransformer = m_xURLTransformer; 262 } 263 } 264 265 uno::Reference< frame::XDispatchProvider > xDispatchProvider( xFrame, uno::UNO_QUERY ); 266 if ( xDispatchProvider.is() ) 267 { 268 aTargetURL.Complete = aCommandURL; 269 xURLTransformer->parseStrict( aTargetURL ); 270 xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 ); 271 } 272 273 if ( xDispatch.is() ) 274 { 275 try 276 { 277 Sequence<PropertyValue> aArgs( 1 ); 278 279 // Provide key modifier information to dispatch function 280 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" )); 281 aArgs[0].Value <<= KeyModifier; 282 283 if(::comphelper::UiEventsLogger::isEnabled()) //#i88653# 284 UiEventLogHelper(::rtl::OUString::createFromAscii("ButtonToolbarController")).log(m_xServiceManager, m_xFrame, aTargetURL, aArgs); 285 xDispatch->dispatch( aTargetURL, aArgs ); 286 } 287 catch ( DisposedException& ) 288 { 289 } 290 } 291 } 292 293 void SAL_CALL ButtonToolbarController::click() 294 throw (::com::sun::star::uno::RuntimeException) 295 { 296 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 297 298 if ( m_bDisposed ) 299 throw DisposedException(); 300 301 sal_Int16 nKeyModifier( (sal_Int16)m_pToolbar->GetModifier() ); 302 execute( nKeyModifier ); 303 } 304 305 void SAL_CALL ButtonToolbarController::doubleClick() 306 throw (::com::sun::star::uno::RuntimeException) 307 { 308 // do nothing 309 if ( m_bDisposed ) 310 throw DisposedException(); 311 } 312 313 uno::Reference< awt::XWindow > SAL_CALL ButtonToolbarController::createPopupWindow() 314 throw (::com::sun::star::uno::RuntimeException) 315 { 316 if ( m_bDisposed ) 317 throw DisposedException(); 318 319 return uno::Reference< awt::XWindow >(); 320 } 321 322 uno::Reference< awt::XWindow > SAL_CALL ButtonToolbarController::createItemWindow( 323 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& ) 324 throw (::com::sun::star::uno::RuntimeException) 325 { 326 if ( m_bDisposed ) 327 throw DisposedException(); 328 329 return uno::Reference< awt::XWindow >(); 330 } 331 332 } // namespace 333 334