LibreOffice Module framework (master) 1
objectmenucontroller.cxx
Go to the documentation of this file.
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 <stdtypes.h>
21
22#include <com/sun/star/embed/VerbAttributes.hpp>
23#include <com/sun/star/embed/VerbDescriptor.hpp>
24
27#include <cppuhelper/weak.hxx>
28#include <vcl/svapp.hxx>
29#include <osl/mutex.hxx>
31
32using namespace com::sun::star::uno;
33using namespace com::sun::star::lang;
34using namespace com::sun::star::frame;
35using namespace com::sun::star::beans;
36using namespace com::sun::star::util;
37using namespace framework;
38
39namespace {
40
41class ObjectMenuController : public svt::PopupMenuControllerBase
42{
43 using svt::PopupMenuControllerBase::disposing;
44
45public:
46 explicit ObjectMenuController( const css::uno::Reference< css::uno::XComponentContext >& xContext );
47
48 // XServiceInfo
49 virtual OUString SAL_CALL getImplementationName() override
50 {
51 return "com.sun.star.comp.framework.ObjectMenuController";
52 }
53
54 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
55 {
56 return cppu::supportsService(this, ServiceName);
57 }
58
59 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
60 {
61 return {"com.sun.star.frame.PopupMenuController"};
62 }
63
64 // XStatusListener
65 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override;
66
67 // XEventListener
68 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
69
70private:
71 void fillPopupMenu( const css::uno::Sequence< css::embed::VerbDescriptor >& rVerbCommandSeq, css::uno::Reference< css::awt::XPopupMenu > const & rPopupMenu );
72};
73
74ObjectMenuController::ObjectMenuController( const css::uno::Reference< css::uno::XComponentContext >& xContext ) :
75 svt::PopupMenuControllerBase( xContext )
76{
77}
78
79// private function
80void ObjectMenuController::fillPopupMenu( const Sequence< css::embed::VerbDescriptor >& rVerbCommandSeq, Reference< css::awt::XPopupMenu > const & rPopupMenu )
81{
82 const css::embed::VerbDescriptor* pVerbCommandArray = rVerbCommandSeq.getConstArray();
83
84 SolarMutexGuard aSolarMutexGuard;
85
86 resetPopupMenu( rPopupMenu );
87
88 static constexpr OUStringLiteral aVerbCommand( u".uno:ObjectMenue?VerbID:short=" );
89 for ( sal_Int32 i = 0; i < rVerbCommandSeq.getLength(); i++ )
90 {
91 const css::embed::VerbDescriptor& rVerb = pVerbCommandArray[i];
92 if ( rVerb.VerbAttributes & css::embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU )
93 {
94 m_xPopupMenu->insertItem( i+1, rVerb.VerbName, 0, i );
95 OUString aCommand = aVerbCommand + OUString::number( rVerb.VerbID );
96 m_xPopupMenu->setCommand( i+1, aCommand ); // Store verb command
97 }
98 }
99}
100
101// XEventListener
102void SAL_CALL ObjectMenuController::disposing( const EventObject& )
103{
105
106 std::unique_lock aLock( m_aMutex );
107 m_xFrame.clear();
108 m_xDispatch.clear();
109
110 if ( m_xPopupMenu.is() )
111 m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(this) );
112 m_xPopupMenu.clear();
113}
114
115// XStatusListener
116void SAL_CALL ObjectMenuController::statusChanged( const FeatureStateEvent& Event )
117{
119 if ( Event.State >>= aVerbCommandSeq )
120 {
121 std::unique_lock aLock( m_aMutex );
122 if ( m_xPopupMenu.is() )
123 fillPopupMenu( aVerbCommandSeq, m_xPopupMenu );
124 }
125}
126
127}
128
129extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
131 css::uno::XComponentContext *context,
132 css::uno::Sequence<css::uno::Any> const &)
133{
134 return cppu::acquire(new ObjectMenuController(context));
135}
136
137/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::lang::XComponent > m_xFrame
css::uno::Reference< css::frame::XDispatch > m_xDispatch
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_framework_ObjectMenuController_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
OUString aCommand
unsigned char sal_Bool
std::mutex m_aMutex