1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <com/sun/star/embed/VerbAttributes.hpp>
23 #include <com/sun/star/embed/VerbDescriptor.hpp>
25 #include <svtools/popupmenucontrollerbase.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <cppuhelper/weak.hxx>
28 #include <vcl/svapp.hxx>
29 #include <osl/mutex.hxx>
30 #include <toolkit/awt/vclxmenu.hxx>
32 using namespace com::sun::star::uno
;
33 using namespace com::sun::star::lang
;
34 using namespace com::sun::star::frame
;
38 class ObjectMenuController
: public svt::PopupMenuControllerBase
40 using svt::PopupMenuControllerBase::disposing
;
43 explicit ObjectMenuController( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
46 virtual OUString SAL_CALL
getImplementationName() override
48 return u
"com.sun.star.comp.framework.ObjectMenuController"_ustr
;
51 virtual sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
) override
53 return cppu::supportsService(this, ServiceName
);
56 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
58 return {u
"com.sun.star.frame.PopupMenuController"_ustr
};
62 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& Event
) override
;
65 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
68 void fillPopupMenu( const css::uno::Sequence
< css::embed::VerbDescriptor
>& rVerbCommandSeq
, css::uno::Reference
< css::awt::XPopupMenu
> const & rPopupMenu
);
71 ObjectMenuController::ObjectMenuController( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
) :
72 svt::PopupMenuControllerBase( xContext
)
77 void ObjectMenuController::fillPopupMenu( const Sequence
< css::embed::VerbDescriptor
>& rVerbCommandSeq
, Reference
< css::awt::XPopupMenu
> const & rPopupMenu
)
79 const css::embed::VerbDescriptor
* pVerbCommandArray
= rVerbCommandSeq
.getConstArray();
81 SolarMutexGuard aSolarMutexGuard
;
83 resetPopupMenu( rPopupMenu
);
85 static constexpr OUStringLiteral
aVerbCommand( u
".uno:ObjectMenue?VerbID:short=" );
86 for ( sal_Int32 i
= 0; i
< rVerbCommandSeq
.getLength(); i
++ )
88 const css::embed::VerbDescriptor
& rVerb
= pVerbCommandArray
[i
];
89 if ( rVerb
.VerbAttributes
& css::embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU
)
91 m_xPopupMenu
->insertItem( i
+1, rVerb
.VerbName
, 0, i
);
92 OUString aCommand
= aVerbCommand
+ OUString::number( rVerb
.VerbID
);
93 m_xPopupMenu
->setCommand( i
+1, aCommand
); // Store verb command
99 void SAL_CALL
ObjectMenuController::disposing( const EventObject
& )
101 Reference
< css::awt::XMenuListener
> xHolder(this);
103 std::unique_lock
aLock( m_aMutex
);
107 if ( m_xPopupMenu
.is() )
108 m_xPopupMenu
->removeMenuListener( Reference
< css::awt::XMenuListener
>(this) );
109 m_xPopupMenu
.clear();
113 void SAL_CALL
ObjectMenuController::statusChanged( const FeatureStateEvent
& Event
)
115 Sequence
< css::embed::VerbDescriptor
> aVerbCommandSeq
;
116 if ( Event
.State
>>= aVerbCommandSeq
)
118 std::unique_lock
aLock( m_aMutex
);
119 if ( m_xPopupMenu
.is() )
120 fillPopupMenu( aVerbCommandSeq
, m_xPopupMenu
);
126 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
127 com_sun_star_comp_framework_ObjectMenuController_get_implementation(
128 css::uno::XComponentContext
*context
,
129 css::uno::Sequence
<css::uno::Any
> const &)
131 return cppu::acquire(new ObjectMenuController(context
));
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */