1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svtools.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 32*cdf0e10cSrcweir // my own includes 33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 34*cdf0e10cSrcweir #include "svtools/popupmenucontrollerbase.hxx" 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 38*cdf0e10cSrcweir // interface includes 39*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 40*cdf0e10cSrcweir #include <com/sun/star/awt/XDevice.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/awt/MenuItemStyle.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/awt/XMenuExtended.hpp> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 48*cdf0e10cSrcweir // includes of other projects 49*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir #ifndef _VCL_MENU_HXX_ 52*cdf0e10cSrcweir #include <vcl/menu.hxx> 53*cdf0e10cSrcweir #endif 54*cdf0e10cSrcweir #include <vcl/svapp.hxx> 55*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 56*cdf0e10cSrcweir #include <rtl/logfile.hxx> 57*cdf0e10cSrcweir #include <vos/mutex.hxx> 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 60*cdf0e10cSrcweir // Defines 61*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 62*cdf0e10cSrcweir // 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir using ::rtl::OUString; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir using namespace com::sun::star; 67*cdf0e10cSrcweir using namespace com::sun::star::uno; 68*cdf0e10cSrcweir using namespace com::sun::star::lang; 69*cdf0e10cSrcweir using namespace com::sun::star::frame; 70*cdf0e10cSrcweir using namespace com::sun::star::beans; 71*cdf0e10cSrcweir using namespace com::sun::star::util; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir namespace svt 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir struct PopupMenuControllerBaseDispatchInfo 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir Reference< XDispatch > mxDispatch; 79*cdf0e10cSrcweir const URL maURL; 80*cdf0e10cSrcweir const Sequence< PropertyValue > maArgs; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir PopupMenuControllerBaseDispatchInfo( const Reference< XDispatch >& xDispatch, const URL& rURL, const Sequence< PropertyValue >& rArgs ) 83*cdf0e10cSrcweir : mxDispatch( xDispatch ), maURL( rURL ), maArgs( rArgs ) {} 84*cdf0e10cSrcweir }; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir PopupMenuControllerBase::PopupMenuControllerBase( const Reference< XMultiServiceFactory >& xServiceManager ) : 87*cdf0e10cSrcweir ::comphelper::OBaseMutex(), 88*cdf0e10cSrcweir PopupMenuControllerBaseType(m_aMutex), 89*cdf0e10cSrcweir m_bInitialized( false ), 90*cdf0e10cSrcweir m_xServiceManager( xServiceManager ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir if ( m_xServiceManager.is() ) 93*cdf0e10cSrcweir m_xURLTransformer.set( m_xServiceManager->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.URLTransformer"))),UNO_QUERY ); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir PopupMenuControllerBase::~PopupMenuControllerBase() 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir // protected function 101*cdf0e10cSrcweir void PopupMenuControllerBase::throwIfDisposed() throw ( RuntimeException ) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir if (rBHelper.bDisposed || rBHelper.bInDispose) 104*cdf0e10cSrcweir throw com::sun::star::lang::DisposedException(); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir // protected function 108*cdf0e10cSrcweir void PopupMenuControllerBase::resetPopupMenu( com::sun::star::uno::Reference< com::sun::star::awt::XPopupMenu >& rPopupMenu ) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir VCLXPopupMenu* pPopupMenu = 0; 111*cdf0e10cSrcweir if ( rPopupMenu.is() && rPopupMenu->getItemCount() > 0 ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir pPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu ); 114*cdf0e10cSrcweir if ( pPopupMenu ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu(); 119*cdf0e10cSrcweir pVCLPopupMenu->Clear(); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir void SAL_CALL PopupMenuControllerBase::disposing() 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir // Reset our members and set disposed flag 127*cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 128*cdf0e10cSrcweir m_xFrame.clear(); 129*cdf0e10cSrcweir m_xDispatch.clear(); 130*cdf0e10cSrcweir m_xPopupMenu.clear(); 131*cdf0e10cSrcweir m_xServiceManager.clear(); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir // XServiceInfo 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir sal_Bool SAL_CALL PopupMenuControllerBase::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir const Sequence< rtl::OUString > aSNL( getSupportedServiceNames() ); 139*cdf0e10cSrcweir const rtl::OUString * pArray = aSNL.getConstArray(); 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 142*cdf0e10cSrcweir if( pArray[i] == ServiceName ) 143*cdf0e10cSrcweir return true; 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir return false; 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir // XEventListener 149*cdf0e10cSrcweir void SAL_CALL PopupMenuControllerBase::disposing( const EventObject& ) throw ( RuntimeException ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 152*cdf0e10cSrcweir m_xFrame.clear(); 153*cdf0e10cSrcweir m_xDispatch.clear(); 154*cdf0e10cSrcweir m_xPopupMenu.clear(); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir // XMenuListener 158*cdf0e10cSrcweir void SAL_CALL PopupMenuControllerBase::highlight( const awt::MenuEvent& ) throw (RuntimeException) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir void PopupMenuControllerBase::impl_select(const Reference< XDispatch >& _xDispatch,const URL& aURL) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir Sequence<PropertyValue> aArgs; 165*cdf0e10cSrcweir OSL_ENSURE(_xDispatch.is(),"PopupMenuControllerBase::impl_select: No dispatch"); 166*cdf0e10cSrcweir if ( _xDispatch.is() ) 167*cdf0e10cSrcweir _xDispatch->dispatch( aURL, aArgs ); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir void SAL_CALL PopupMenuControllerBase::select( const awt::MenuEvent& rEvent ) throw (RuntimeException) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir throwIfDisposed(); 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir Reference< awt::XMenuExtended > xExtMenu( m_xPopupMenu, UNO_QUERY ); 177*cdf0e10cSrcweir if( xExtMenu.is() ) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir Sequence<PropertyValue> aArgs; 180*cdf0e10cSrcweir dispatchCommand( xExtMenu->getCommand( rEvent.MenuId ), aArgs ); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir void PopupMenuControllerBase::dispatchCommand( const ::rtl::OUString& sCommandURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir throwIfDisposed(); 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir try 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY_THROW ); 193*cdf0e10cSrcweir URL aURL; 194*cdf0e10cSrcweir aURL.Complete = sCommandURL; 195*cdf0e10cSrcweir m_xURLTransformer->parseStrict( aURL ); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir Reference< XDispatch > xDispatch( xDispatchProvider->queryDispatch( aURL, OUString(), 0 ), UNO_QUERY_THROW ); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir Application::PostUserEvent( STATIC_LINK(0, PopupMenuControllerBase, ExecuteHdl_Impl), new PopupMenuControllerBaseDispatchInfo( xDispatch, aURL, rArgs ) ); 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir catch( Exception& ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir IMPL_STATIC_LINK_NOINSTANCE( PopupMenuControllerBase, ExecuteHdl_Impl, PopupMenuControllerBaseDispatchInfo*, pDispatchInfo ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir pDispatchInfo->mxDispatch->dispatch( pDispatchInfo->maURL, pDispatchInfo->maArgs ); 211*cdf0e10cSrcweir delete pDispatchInfo; 212*cdf0e10cSrcweir return 0; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir void SAL_CALL PopupMenuControllerBase::activate( const awt::MenuEvent& ) throw (RuntimeException) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir void SAL_CALL PopupMenuControllerBase::deactivate( const awt::MenuEvent& ) throw (RuntimeException) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir void SAL_CALL PopupMenuControllerBase::updatePopupMenu() throw ( ::com::sun::star::uno::RuntimeException ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir osl::ClearableMutexGuard aLock( m_aMutex ); 226*cdf0e10cSrcweir throwIfDisposed(); 227*cdf0e10cSrcweir aLock.clear(); 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir updateCommand( m_aCommandURL ); 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir void SAL_CALL PopupMenuControllerBase::updateCommand( const rtl::OUString& rCommandURL ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir osl::ClearableMutexGuard aLock( m_aMutex ); 235*cdf0e10cSrcweir Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY ); 236*cdf0e10cSrcweir Reference< XDispatch > xDispatch( m_xDispatch ); 237*cdf0e10cSrcweir URL aTargetURL; 238*cdf0e10cSrcweir aTargetURL.Complete = rCommandURL; 239*cdf0e10cSrcweir m_xURLTransformer->parseStrict( aTargetURL ); 240*cdf0e10cSrcweir aLock.clear(); 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir // Add/remove status listener to get a status update once 243*cdf0e10cSrcweir if ( xDispatch.is() ) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir xDispatch->addStatusListener( xStatusListener, aTargetURL ); 246*cdf0e10cSrcweir xDispatch->removeStatusListener( xStatusListener, aTargetURL ); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir // XDispatchProvider 252*cdf0e10cSrcweir Reference< XDispatch > SAL_CALL 253*cdf0e10cSrcweir PopupMenuControllerBase::queryDispatch( 254*cdf0e10cSrcweir const URL& /*aURL*/, 255*cdf0e10cSrcweir const rtl::OUString& /*sTarget*/, 256*cdf0e10cSrcweir sal_Int32 /*nFlags*/ ) 257*cdf0e10cSrcweir throw( RuntimeException ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir // must be implemented by subclass 260*cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 261*cdf0e10cSrcweir throwIfDisposed(); 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir return Reference< XDispatch >(); 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir Sequence< Reference< XDispatch > > SAL_CALL PopupMenuControllerBase::queryDispatches( const Sequence< DispatchDescriptor >& lDescriptor ) throw( RuntimeException ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir // Create return list - which must have same size then the given descriptor 269*cdf0e10cSrcweir // It's not allowed to pack it! 270*cdf0e10cSrcweir osl::ClearableMutexGuard aLock( m_aMutex ); 271*cdf0e10cSrcweir throwIfDisposed(); 272*cdf0e10cSrcweir aLock.clear(); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir sal_Int32 nCount = lDescriptor.getLength(); 275*cdf0e10cSrcweir uno::Sequence< uno::Reference< frame::XDispatch > > lDispatcher( nCount ); 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir // Step over all descriptors and try to get any dispatcher for it. 278*cdf0e10cSrcweir for( sal_Int32 i=0; i<nCount; ++i ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir lDispatcher[i] = queryDispatch( lDescriptor[i].FeatureURL , 281*cdf0e10cSrcweir lDescriptor[i].FrameName , 282*cdf0e10cSrcweir lDescriptor[i].SearchFlags ); 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir return lDispatcher; 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir // XDispatch 289*cdf0e10cSrcweir void SAL_CALL 290*cdf0e10cSrcweir PopupMenuControllerBase::dispatch( 291*cdf0e10cSrcweir const URL& /*aURL*/, 292*cdf0e10cSrcweir const Sequence< PropertyValue >& /*seqProperties*/ ) 293*cdf0e10cSrcweir throw( ::com::sun::star::uno::RuntimeException ) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir // must be implemented by subclass 296*cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 297*cdf0e10cSrcweir throwIfDisposed(); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir void SAL_CALL 301*cdf0e10cSrcweir PopupMenuControllerBase::addStatusListener( 302*cdf0e10cSrcweir const Reference< XStatusListener >& xControl, 303*cdf0e10cSrcweir const URL& aURL ) 304*cdf0e10cSrcweir throw( ::com::sun::star::uno::RuntimeException ) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir osl::ResettableMutexGuard aLock( m_aMutex ); 307*cdf0e10cSrcweir throwIfDisposed(); 308*cdf0e10cSrcweir aLock.clear(); 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir bool bStatusUpdate( false ); 311*cdf0e10cSrcweir rBHelper.addListener( ::getCppuType( &xControl ), xControl ); 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir aLock.reset(); 314*cdf0e10cSrcweir if ( aURL.Complete.indexOf( m_aBaseURL ) == 0 ) 315*cdf0e10cSrcweir bStatusUpdate = true; 316*cdf0e10cSrcweir aLock.clear(); 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir if ( bStatusUpdate ) 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir // Dummy update for popup menu controllers 321*cdf0e10cSrcweir FeatureStateEvent aEvent; 322*cdf0e10cSrcweir aEvent.FeatureURL = aURL; 323*cdf0e10cSrcweir aEvent.IsEnabled = sal_True; 324*cdf0e10cSrcweir aEvent.Requery = sal_False; 325*cdf0e10cSrcweir aEvent.State = Any(); 326*cdf0e10cSrcweir xControl->statusChanged( aEvent ); 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir void SAL_CALL PopupMenuControllerBase::removeStatusListener( 331*cdf0e10cSrcweir const Reference< XStatusListener >& xControl, 332*cdf0e10cSrcweir const URL& /*aURL*/ ) 333*cdf0e10cSrcweir throw( ::com::sun::star::uno::RuntimeException ) 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir rBHelper.removeListener( ::getCppuType( &xControl ), xControl ); 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir ::rtl::OUString PopupMenuControllerBase::determineBaseURL( const ::rtl::OUString& aURL ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir // Just use the main part of the URL for popup menu controllers 341*cdf0e10cSrcweir sal_Int32 nQueryPart( 0 ); 342*cdf0e10cSrcweir sal_Int32 nSchemePart( 0 ); 343*cdf0e10cSrcweir rtl::OUString aMainURL( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.popup:" )); 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir nSchemePart = aURL.indexOf( ':' ); 346*cdf0e10cSrcweir if (( nSchemePart > 0 ) && 347*cdf0e10cSrcweir ( aURL.getLength() > ( nSchemePart+1 ))) 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir nQueryPart = aURL.indexOf( '?', nSchemePart ); 350*cdf0e10cSrcweir if ( nQueryPart > 0 ) 351*cdf0e10cSrcweir aMainURL += aURL.copy( nSchemePart, nQueryPart-nSchemePart ); 352*cdf0e10cSrcweir else if ( nQueryPart == -1 ) 353*cdf0e10cSrcweir aMainURL += aURL.copy( nSchemePart+1 ); 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir return aMainURL; 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir // XInitialization 360*cdf0e10cSrcweir void SAL_CALL PopupMenuControllerBase::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException ) 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir sal_Bool bInitalized( m_bInitialized ); 365*cdf0e10cSrcweir if ( !bInitalized ) 366*cdf0e10cSrcweir { 367*cdf0e10cSrcweir PropertyValue aPropValue; 368*cdf0e10cSrcweir rtl::OUString aCommandURL; 369*cdf0e10cSrcweir Reference< XFrame > xFrame; 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir for ( int i = 0; i < aArguments.getLength(); i++ ) 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir if ( aArguments[i] >>= aPropValue ) 374*cdf0e10cSrcweir { 375*cdf0e10cSrcweir if ( aPropValue.Name.equalsAscii( "Frame" )) 376*cdf0e10cSrcweir aPropValue.Value >>= xFrame; 377*cdf0e10cSrcweir else if ( aPropValue.Name.equalsAscii( "CommandURL" )) 378*cdf0e10cSrcweir aPropValue.Value >>= aCommandURL; 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir if ( xFrame.is() && aCommandURL.getLength() ) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir m_xFrame = xFrame; 385*cdf0e10cSrcweir m_aCommandURL = aCommandURL; 386*cdf0e10cSrcweir m_aBaseURL = determineBaseURL( aCommandURL ); 387*cdf0e10cSrcweir m_bInitialized = true; 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir // XPopupMenuController 392*cdf0e10cSrcweir void SAL_CALL PopupMenuControllerBase::setPopupMenu( const Reference< awt::XPopupMenu >& xPopupMenu ) throw ( RuntimeException ) 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 395*cdf0e10cSrcweir throwIfDisposed(); 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir if ( m_xFrame.is() && !m_xPopupMenu.is() ) 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir // Create popup menu on demand 400*cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir m_xPopupMenu = xPopupMenu; 403*cdf0e10cSrcweir m_xPopupMenu->addMenuListener( Reference< awt::XMenuListener >( (OWeakObject*)this, UNO_QUERY )); 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir URL aTargetURL; 408*cdf0e10cSrcweir aTargetURL.Complete = m_aCommandURL; 409*cdf0e10cSrcweir m_xURLTransformer->parseStrict( aTargetURL ); 410*cdf0e10cSrcweir m_xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 ); 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir impl_setPopupMenu(); 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir updatePopupMenu(); 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir void PopupMenuControllerBase::impl_setPopupMenu() 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir } 421