summaryrefslogtreecommitdiffstats
path: root/framework/source/inc/dispatch/dispatchdisabler.hxx
blob: ed64a656ea7a7d5e3d616a624d2578829277e428 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
#ifndef INCLUDED_FRAMEWORK_INC_SERVICES_DISPATCH_DISABLER_HXX
#define INCLUDED_FRAMEWORK_INC_SERVICES_DISPATCH_DISABLER_HXX

#include <set>

#include <cppuhelper/implbase.hxx>

#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/frame/XDispatch.hpp>
#include <com/sun/star/frame/XInterceptorInfo.hpp>
#include <com/sun/star/frame/XDispatchProvider.hpp>
#include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>

#include <macros/xserviceinfo.hxx>

namespace framework {

/**
 * Implementation of a service to make it easy to disable a whole
 * suite of UNO commands in a batch - and have that act in-process.
 *
 * Often external re-use of LibreOffice wants a very cut-down set
 * of functionality included, and disabling elements remotely one
 * by one performs poorly.
 */
class DispatchDisabler : public ::cppu::WeakImplHelper<
                                        css::lang::XInitialization,
                                        css::container::XNameContainer,
                                        css::frame::XDispatchProviderInterceptor,
                                        css::frame::XInterceptorInfo,
                                        css::lang::XServiceInfo >
{
    std::set<OUString> maDisabledURLs;
    css::uno::Reference< css::frame::XDispatchProvider > mxSlave;
    css::uno::Reference< css::frame::XDispatchProvider > mxMaster;
public:
             DispatchDisabler(const css::uno::Reference< css::uno::XComponentContext >& rxContext);

    // XInitialization
    virtual void SAL_CALL initialize( const ::css::uno::Sequence< ::css::uno::Any >& aArguments ) override;

    // XDispatchProvider
    virtual ::css::uno::Reference< ::css::frame::XDispatch > SAL_CALL
        queryDispatch( const ::css::util::URL& URL,
               const OUString& TargetFrameName,
               ::sal_Int32 SearchFlags ) override;
    virtual ::css::uno::Sequence< ::css::uno::Reference< ::css::frame::XDispatch > > SAL_CALL
        queryDispatches( const ::css::uno::Sequence< ::css::frame::DispatchDescriptor >& Requests ) override;

    // XDispatchProviderInterceptor
    virtual ::css::uno::Reference< ::css::frame::XDispatchProvider > SAL_CALL
        getSlaveDispatchProvider() override;
    virtual void SAL_CALL
        setSlaveDispatchProvider( const ::css::uno::Reference< ::css::frame::XDispatchProvider >& NewDispatchProvider ) override;
    virtual ::css::uno::Reference< ::css::frame::XDispatchProvider > SAL_CALL
        getMasterDispatchProvider() override;
    virtual void SAL_CALL
        setMasterDispatchProvider( const ::css::uno::Reference< ::css::frame::XDispatchProvider >& NewSupplier ) override;

    // XInterceptorInfo
    virtual ::css::uno::Sequence< OUString > SAL_CALL
        getInterceptedURLs() override;

    // XElementAccess
    virtual ::css::uno::Type SAL_CALL getElementType() override;
    virtual ::sal_Bool SAL_CALL hasElements() override;

    // XNameAccess
    virtual ::css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
    virtual ::css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
    virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;

    // XNameReplace
    virtual void SAL_CALL replaceByName( const OUString& aName, const ::css::uno::Any& aElement ) override;

    // XNameContainer
    virtual void SAL_CALL insertByName( const OUString& aName, const ::css::uno::Any& aElement ) override;
    virtual void SAL_CALL removeByName( const OUString& Name ) override;

    DECLARE_XSERVICEINFO_NOFACTORY
    /* Helper for registry */
    /// @throws css::uno::Exception
    static css::uno::Reference< css::uno::XInterface >             SAL_CALL impl_createInstance                ( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager );
    static css::uno::Reference< css::lang::XSingleServiceFactory > impl_createFactory                 ( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager );
};

} // namespace framework

#endif // INCLUDED_FRAMEWORK_INC_SERVICES_DISPATCH_DISABLER_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */