update dev300-m58
[ooovba.git] / framework / source / uielement / objectmenucontroller.cxx
blobaccc576f315846f204f2e314b49ca8f464fd8cd1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: objectmenucontroller.cxx,v $
10 * $Revision: 1.10.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"
33 #include <uielement/objectmenucontroller.hxx>
35 //_________________________________________________________________________________________________________________
36 // my own includes
37 //_________________________________________________________________________________________________________________
38 #include <threadhelp/resetableguard.hxx>
39 #include "services.h"
41 //_________________________________________________________________________________________________________________
42 // interface includes
43 //_________________________________________________________________________________________________________________
44 #include <com/sun/star/awt/XDevice.hpp>
45 #include <com/sun/star/beans/PropertyValue.hpp>
46 #include <com/sun/star/awt/MenuItemStyle.hpp>
47 #include <com/sun/star/frame/XDispatchProvider.hpp>
49 #ifndef _COM_SUN_STAR_EMBED_VERBDATTRIBUTES_HPP_
50 #include <com/sun/star/embed/VerbAttributes.hpp>
51 #endif
53 //_________________________________________________________________________________________________________________
54 // includes of other projects
55 //_________________________________________________________________________________________________________________
57 #ifndef _VCL_MENU_HXX_
58 #include <vcl/menu.hxx>
59 #endif
60 #include <vcl/svapp.hxx>
61 #include <vcl/i18nhelp.hxx>
62 #include <tools/urlobj.hxx>
63 #include <rtl/ustrbuf.hxx>
64 #include <dispatch/uieventloghelper.hxx>
66 //_________________________________________________________________________________________________________________
67 // Defines
68 //_________________________________________________________________________________________________________________
71 using namespace com::sun::star::uno;
72 using namespace com::sun::star::lang;
73 using namespace com::sun::star::frame;
74 using namespace com::sun::star::beans;
75 using namespace com::sun::star::util;
77 namespace framework
80 DEFINE_XSERVICEINFO_MULTISERVICE ( ObjectMenuController ,
81 OWeakObject ,
82 SERVICENAME_POPUPMENUCONTROLLER ,
83 IMPLEMENTATIONNAME_OBJECTMENUCONTROLLER
86 DEFINE_INIT_SERVICE ( ObjectMenuController, {} )
88 ObjectMenuController::ObjectMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
89 PopupMenuControllerBase( xServiceManager )
93 ObjectMenuController::~ObjectMenuController()
97 // private function
98 void ObjectMenuController::fillPopupMenu( const Sequence< com::sun::star::embed::VerbDescriptor >& rVerbCommandSeq, Reference< css::awt::XPopupMenu >& rPopupMenu )
100 const com::sun::star::embed::VerbDescriptor* pVerbCommandArray = rVerbCommandSeq.getConstArray();
101 VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu );
102 PopupMenu* pVCLPopupMenu = 0;
104 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
106 resetPopupMenu( rPopupMenu );
107 if ( pPopupMenu )
108 pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
110 if ( pVCLPopupMenu )
112 const rtl::OUString aVerbCommand( RTL_CONSTASCII_USTRINGPARAM( ".uno:ObjectMenue?VerbID:short=" ));
113 for ( USHORT i = 0; i < rVerbCommandSeq.getLength(); i++ )
115 const com::sun::star::embed::VerbDescriptor& rVerb = pVerbCommandArray[i];
116 if ( rVerb.VerbAttributes & com::sun::star::embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU )
118 m_xPopupMenu->insertItem( i+1, rVerb.VerbName, 0, i );
119 // use VCL popup menu pointer to set vital information that are not part of the awt implementation
121 rtl::OUString aCommand( aVerbCommand );
122 aCommand += rtl::OUString::valueOf( rVerb.VerbID );
123 pVCLPopupMenu->SetItemCommand( i+1, aCommand ); // Store verb command
129 // XEventListener
130 void SAL_CALL ObjectMenuController::disposing( const EventObject& ) throw ( RuntimeException )
132 Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
134 ResetableGuard aLock( m_aLock );
135 m_xFrame.clear();
136 m_xDispatch.clear();
137 m_xObjectUpdateDispatch.clear();
138 m_xServiceManager.clear();
140 if ( m_xPopupMenu.is() )
141 m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
142 m_xPopupMenu.clear();
145 // XStatusListener
146 void SAL_CALL ObjectMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException )
148 Sequence < com::sun::star::embed::VerbDescriptor > aVerbCommandSeq;
149 if ( Event.State >>= aVerbCommandSeq )
151 ResetableGuard aLock( m_aLock );
152 if ( m_xPopupMenu.is() )
153 fillPopupMenu( aVerbCommandSeq, m_xPopupMenu );
157 // XMenuListener
158 void ObjectMenuController::impl_select(const Reference< XDispatch >& _xDispatch,const ::com::sun::star::util::URL& aTargetURL)
160 Sequence<PropertyValue> aArgs;
161 if(::comphelper::UiEventsLogger::isEnabled()) //#i88653#
162 UiEventLogHelper(::rtl::OUString::createFromAscii("ObjectMenuController")).log(m_xServiceManager, m_xFrame, aTargetURL, aArgs);
163 _xDispatch->dispatch( aTargetURL, aArgs );