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_framework.hxx" 30*cdf0e10cSrcweir #include <uielement/objectmenucontroller.hxx> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 33*cdf0e10cSrcweir // my own includes 34*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 35*cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx> 36*cdf0e10cSrcweir #include "services.h" 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 39*cdf0e10cSrcweir // interface includes 40*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 41*cdf0e10cSrcweir #include <com/sun/star/awt/XDevice.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/awt/MenuItemStyle.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_EMBED_VERBDATTRIBUTES_HPP_ 47*cdf0e10cSrcweir #include <com/sun/star/embed/VerbAttributes.hpp> 48*cdf0e10cSrcweir #endif 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 51*cdf0e10cSrcweir // includes of other projects 52*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir #ifndef _VCL_MENU_HXX_ 55*cdf0e10cSrcweir #include <vcl/menu.hxx> 56*cdf0e10cSrcweir #endif 57*cdf0e10cSrcweir #include <vcl/svapp.hxx> 58*cdf0e10cSrcweir #include <vcl/i18nhelp.hxx> 59*cdf0e10cSrcweir #include <tools/urlobj.hxx> 60*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 61*cdf0e10cSrcweir #include <dispatch/uieventloghelper.hxx> 62*cdf0e10cSrcweir #include <vos/mutex.hxx> 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 65*cdf0e10cSrcweir // Defines 66*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 67*cdf0e10cSrcweir // 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir using namespace com::sun::star::uno; 70*cdf0e10cSrcweir using namespace com::sun::star::lang; 71*cdf0e10cSrcweir using namespace com::sun::star::frame; 72*cdf0e10cSrcweir using namespace com::sun::star::beans; 73*cdf0e10cSrcweir using namespace com::sun::star::util; 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir namespace framework 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE ( ObjectMenuController , 79*cdf0e10cSrcweir OWeakObject , 80*cdf0e10cSrcweir SERVICENAME_POPUPMENUCONTROLLER , 81*cdf0e10cSrcweir IMPLEMENTATIONNAME_OBJECTMENUCONTROLLER 82*cdf0e10cSrcweir ) 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir DEFINE_INIT_SERVICE ( ObjectMenuController, {} ) 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir ObjectMenuController::ObjectMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) : 87*cdf0e10cSrcweir svt::PopupMenuControllerBase( xServiceManager ) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir ObjectMenuController::~ObjectMenuController() 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir // private function 96*cdf0e10cSrcweir void ObjectMenuController::fillPopupMenu( const Sequence< com::sun::star::embed::VerbDescriptor >& rVerbCommandSeq, Reference< css::awt::XPopupMenu >& rPopupMenu ) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir const com::sun::star::embed::VerbDescriptor* pVerbCommandArray = rVerbCommandSeq.getConstArray(); 99*cdf0e10cSrcweir VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu ); 100*cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = 0; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir resetPopupMenu( rPopupMenu ); 105*cdf0e10cSrcweir if ( pPopupMenu ) 106*cdf0e10cSrcweir pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu(); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir if ( pVCLPopupMenu ) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir const rtl::OUString aVerbCommand( RTL_CONSTASCII_USTRINGPARAM( ".uno:ObjectMenue?VerbID:short=" )); 111*cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < rVerbCommandSeq.getLength(); i++ ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir const com::sun::star::embed::VerbDescriptor& rVerb = pVerbCommandArray[i]; 114*cdf0e10cSrcweir if ( rVerb.VerbAttributes & com::sun::star::embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir m_xPopupMenu->insertItem( i+1, rVerb.VerbName, 0, i ); 117*cdf0e10cSrcweir // use VCL popup menu pointer to set vital information that are not part of the awt implementation 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir rtl::OUString aCommand( aVerbCommand ); 120*cdf0e10cSrcweir aCommand += rtl::OUString::valueOf( rVerb.VerbID ); 121*cdf0e10cSrcweir pVCLPopupMenu->SetItemCommand( i+1, aCommand ); // Store verb command 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir // XEventListener 128*cdf0e10cSrcweir void SAL_CALL ObjectMenuController::disposing( const EventObject& ) throw ( RuntimeException ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY ); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 133*cdf0e10cSrcweir m_xFrame.clear(); 134*cdf0e10cSrcweir m_xDispatch.clear(); 135*cdf0e10cSrcweir m_xObjectUpdateDispatch.clear(); 136*cdf0e10cSrcweir m_xServiceManager.clear(); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir if ( m_xPopupMenu.is() ) 139*cdf0e10cSrcweir m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY )); 140*cdf0e10cSrcweir m_xPopupMenu.clear(); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir // XStatusListener 144*cdf0e10cSrcweir void SAL_CALL ObjectMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir Sequence < com::sun::star::embed::VerbDescriptor > aVerbCommandSeq; 147*cdf0e10cSrcweir if ( Event.State >>= aVerbCommandSeq ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir osl::MutexGuard aLock( m_aMutex ); 150*cdf0e10cSrcweir if ( m_xPopupMenu.is() ) 151*cdf0e10cSrcweir fillPopupMenu( aVerbCommandSeq, m_xPopupMenu ); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir // XMenuListener 156*cdf0e10cSrcweir void ObjectMenuController::impl_select(const Reference< XDispatch >& _xDispatch,const ::com::sun::star::util::URL& aTargetURL) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir Sequence<PropertyValue> aArgs; 159*cdf0e10cSrcweir if(::comphelper::UiEventsLogger::isEnabled()) //#i88653# 160*cdf0e10cSrcweir UiEventLogHelper(::rtl::OUString::createFromAscii("ObjectMenuController")).log(m_xServiceManager, m_xFrame, aTargetURL, aArgs); 161*cdf0e10cSrcweir OSL_ENSURE(_xDispatch.is(),"ObjectMenuController::impl_select: No dispatch"); 162*cdf0e10cSrcweir if ( _xDispatch.is() ) 163*cdf0e10cSrcweir _xDispatch->dispatch( aTargetURL, aArgs ); 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir } 167