Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <uielement/objectmenucontroller.hxx>
21 :
22 : #include <threadhelp/resetableguard.hxx>
23 : #include "services.h"
24 :
25 : #include <com/sun/star/awt/XDevice.hpp>
26 : #include <com/sun/star/beans/PropertyValue.hpp>
27 : #include <com/sun/star/awt/MenuItemStyle.hpp>
28 : #include <com/sun/star/frame/XDispatchProvider.hpp>
29 :
30 : #include <com/sun/star/embed/VerbAttributes.hpp>
31 :
32 : #include <vcl/menu.hxx>
33 : #include <vcl/svapp.hxx>
34 : #include <vcl/i18nhelp.hxx>
35 : #include <rtl/ustrbuf.hxx>
36 : #include <osl/mutex.hxx>
37 :
38 : //_________________________________________________________________________________________________________________
39 : // Defines
40 : //_________________________________________________________________________________________________________________
41 :
42 : using namespace com::sun::star::uno;
43 : using namespace com::sun::star::lang;
44 : using namespace com::sun::star::frame;
45 : using namespace com::sun::star::beans;
46 : using namespace com::sun::star::util;
47 :
48 : namespace framework
49 : {
50 :
51 157 : DEFINE_XSERVICEINFO_MULTISERVICE ( ObjectMenuController ,
52 : OWeakObject ,
53 : SERVICENAME_POPUPMENUCONTROLLER ,
54 : IMPLEMENTATIONNAME_OBJECTMENUCONTROLLER
55 : )
56 :
57 0 : DEFINE_INIT_SERVICE ( ObjectMenuController, {} )
58 :
59 0 : ObjectMenuController::ObjectMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
60 0 : svt::PopupMenuControllerBase( xServiceManager )
61 : {
62 0 : }
63 :
64 0 : ObjectMenuController::~ObjectMenuController()
65 : {
66 0 : }
67 :
68 : // private function
69 0 : void ObjectMenuController::fillPopupMenu( const Sequence< com::sun::star::embed::VerbDescriptor >& rVerbCommandSeq, Reference< css::awt::XPopupMenu >& rPopupMenu )
70 : {
71 0 : const com::sun::star::embed::VerbDescriptor* pVerbCommandArray = rVerbCommandSeq.getConstArray();
72 0 : VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu );
73 0 : PopupMenu* pVCLPopupMenu = 0;
74 :
75 0 : SolarMutexGuard aSolarMutexGuard;
76 :
77 0 : resetPopupMenu( rPopupMenu );
78 0 : if ( pPopupMenu )
79 0 : pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
80 :
81 0 : if ( pVCLPopupMenu )
82 : {
83 0 : const rtl::OUString aVerbCommand( ".uno:ObjectMenue?VerbID:short=" );
84 0 : for ( sal_uInt16 i = 0; i < rVerbCommandSeq.getLength(); i++ )
85 : {
86 0 : const com::sun::star::embed::VerbDescriptor& rVerb = pVerbCommandArray[i];
87 0 : if ( rVerb.VerbAttributes & com::sun::star::embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU )
88 : {
89 0 : m_xPopupMenu->insertItem( i+1, rVerb.VerbName, 0, i );
90 : // use VCL popup menu pointer to set vital information that are not part of the awt implementation
91 :
92 0 : rtl::OUString aCommand( aVerbCommand );
93 0 : aCommand += rtl::OUString::valueOf( rVerb.VerbID );
94 0 : pVCLPopupMenu->SetItemCommand( i+1, aCommand ); // Store verb command
95 : }
96 0 : }
97 0 : }
98 0 : }
99 :
100 : // XEventListener
101 0 : void SAL_CALL ObjectMenuController::disposing( const EventObject& ) throw ( RuntimeException )
102 : {
103 0 : Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
104 :
105 0 : osl::MutexGuard aLock( m_aMutex );
106 0 : m_xFrame.clear();
107 0 : m_xDispatch.clear();
108 0 : m_xObjectUpdateDispatch.clear();
109 0 : m_xServiceManager.clear();
110 :
111 0 : if ( m_xPopupMenu.is() )
112 0 : m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
113 0 : m_xPopupMenu.clear();
114 0 : }
115 :
116 : // XStatusListener
117 0 : void SAL_CALL ObjectMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException )
118 : {
119 0 : Sequence < com::sun::star::embed::VerbDescriptor > aVerbCommandSeq;
120 0 : if ( Event.State >>= aVerbCommandSeq )
121 : {
122 0 : osl::MutexGuard aLock( m_aMutex );
123 0 : if ( m_xPopupMenu.is() )
124 0 : fillPopupMenu( aVerbCommandSeq, m_xPopupMenu );
125 0 : }
126 0 : }
127 :
128 : // XMenuListener
129 0 : void ObjectMenuController::impl_select(const Reference< XDispatch >& _xDispatch,const ::com::sun::star::util::URL& aTargetURL)
130 : {
131 0 : Sequence<PropertyValue> aArgs;
132 : OSL_ENSURE(_xDispatch.is(),"ObjectMenuController::impl_select: No dispatch");
133 0 : if ( _xDispatch.is() )
134 0 : _xDispatch->dispatch( aTargetURL, aArgs );
135 0 : }
136 :
137 : }
138 :
139 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|