Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/framework/source/uielement/objectmenucontroller.cxx
Line
Count
Source
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
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>
31
32
using namespace com::sun::star::uno;
33
using namespace com::sun::star::lang;
34
using namespace com::sun::star::frame;
35
36
namespace {
37
38
class ObjectMenuController :  public svt::PopupMenuControllerBase
39
{
40
    using svt::PopupMenuControllerBase::disposing;
41
42
public:
43
    explicit ObjectMenuController( const css::uno::Reference< css::uno::XComponentContext >& xContext );
44
45
    // XServiceInfo
46
    virtual OUString SAL_CALL getImplementationName() override
47
0
    {
48
0
        return u"com.sun.star.comp.framework.ObjectMenuController"_ustr;
49
0
    }
50
51
    virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
52
0
    {
53
0
        return cppu::supportsService(this, ServiceName);
54
0
    }
55
56
    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
57
0
    {
58
0
        return {u"com.sun.star.frame.PopupMenuController"_ustr};
59
0
    }
60
61
    // XStatusListener
62
    virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override;
63
64
    // XEventListener
65
    virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
66
67
private:
68
    void fillPopupMenu( const css::uno::Sequence< css::embed::VerbDescriptor >& rVerbCommandSeq, css::uno::Reference< css::awt::XPopupMenu > const & rPopupMenu );
69
};
70
71
ObjectMenuController::ObjectMenuController( const css::uno::Reference< css::uno::XComponentContext >& xContext ) :
72
0
    svt::PopupMenuControllerBase( xContext )
73
0
{
74
0
}
75
76
// private function
77
void ObjectMenuController::fillPopupMenu( const Sequence< css::embed::VerbDescriptor >& rVerbCommandSeq, Reference< css::awt::XPopupMenu > const & rPopupMenu )
78
0
{
79
0
    SolarMutexGuard aSolarMutexGuard;
80
81
0
    resetPopupMenu( rPopupMenu );
82
83
0
    static constexpr OUStringLiteral aVerbCommand( u".uno:ObjectMenue?VerbID:short=" );
84
0
    for ( sal_Int32 i = 0; i < rVerbCommandSeq.getLength(); i++ )
85
0
    {
86
0
        const css::embed::VerbDescriptor& rVerb = rVerbCommandSeq[i];
87
0
        if ( rVerb.VerbAttributes & css::embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU )
88
0
        {
89
0
            m_xPopupMenu->insertItem( i+1, rVerb.VerbName, 0, i );
90
0
            OUString aCommand = aVerbCommand + OUString::number( rVerb.VerbID );
91
0
            m_xPopupMenu->setCommand( i+1, aCommand ); // Store verb command
92
0
        }
93
0
    }
94
0
}
95
96
// XEventListener
97
void SAL_CALL ObjectMenuController::disposing( const EventObject& )
98
0
{
99
0
    Reference< css::awt::XMenuListener > xHolder(this);
100
101
0
    std::unique_lock aLock( m_aMutex );
102
0
    m_xFrame.clear();
103
0
    m_xDispatch.clear();
104
105
0
    if ( m_xPopupMenu.is() )
106
0
        m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(this) );
107
0
    m_xPopupMenu.clear();
108
0
}
109
110
// XStatusListener
111
void SAL_CALL ObjectMenuController::statusChanged( const FeatureStateEvent& Event )
112
0
{
113
0
    Sequence < css::embed::VerbDescriptor > aVerbCommandSeq;
114
0
    if ( Event.State >>= aVerbCommandSeq )
115
0
    {
116
0
        std::unique_lock aLock( m_aMutex );
117
0
        if ( m_xPopupMenu.is() )
118
0
            fillPopupMenu( aVerbCommandSeq, m_xPopupMenu );
119
0
    }
120
0
}
121
122
}
123
124
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
125
com_sun_star_comp_framework_ObjectMenuController_get_implementation(
126
    css::uno::XComponentContext *context,
127
    css::uno::Sequence<css::uno::Any> const &)
128
0
{
129
0
    return cppu::acquire(new ObjectMenuController(context));
130
0
}
131
132
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */