summaryrefslogtreecommitdiffstats
path: root/framework/inc/uielement/styletoolbarcontroller.hxx
blob: 45b1ad7ecccedd82410dcca8a645518cd1a50f05 (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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
 * 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/.
 */

#pragma once

#include <svtools/toolboxcontroller.hxx>
#include <com/sun/star/frame/XDispatchProvider.hpp>

namespace framework {

/**
 * A dispatcher that serves as a proxy for style commands with arguments
 * i.e. .uno:StyleApply?... in order to provide useful status updates to
 * generic UI elements such as toolbars or menubar. It listens to special
 * status commands, and computes a boolean status out of them. Then it
 * forwards that boolean status to the listener, as if it was the status
 * of the original command.
 *
 * Note that the implementation is minimal: Although the UI element appears
 * to be the owner of the dispatcher, it's still responsible, as usual, to
 * call removeStatusListener same amount of times as addStatusListener,
 * otherwise the dispatcher might not be destructed. In addition this
 * implementation might hold a hard reference on the owner, and it's the
 * responsibility of the owner to destroy the dispatcher first, in order
 * to break the cycle.
 */
class StyleDispatcher final : public cppu::WeakImplHelper< css::frame::XDispatch, css::frame::XStatusListener >
{
public:
    StyleDispatcher( const css::uno::Reference< css::frame::XFrame >& rFrame,
                     css::uno::Reference< css::util::XURLTransformer > xUrlTransformer,
                     const css::util::URL& rURL );

    // XDispatch
    void SAL_CALL dispatch( const css::util::URL& rURL, const css::uno::Sequence< css::beans::PropertyValue >& rArguments ) override;
    void SAL_CALL addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& rListener, const css::util::URL& rURL ) override;
    void SAL_CALL removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& rListener, const css::util::URL& rURL ) override;

    // XStatusListener
    void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;

    // XEventListener
    void SAL_CALL disposing( const css::lang::EventObject& rSource ) override;

private:
    OUString m_aStyleName, m_aCommand, m_aStatusCommand;
    css::uno::Reference< css::util::XURLTransformer > m_xUrlTransformer;
    css::uno::Reference< css::frame::XDispatchProvider > m_xFrame;
    css::uno::Reference< css::frame::XDispatch > m_xStatusDispatch;
    css::uno::Reference< css::frame::XStatusListener > m_xOwner;
};

class StyleToolbarController final : public svt::ToolboxController
{
public:
    StyleToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rContext,
                            const css::uno::Reference< css::frame::XFrame >& rFrame,
                            const OUString& rCommand );

    // XUpdatable
    void SAL_CALL update() override;

    // XStatusListener
    void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;

    // XComponent
    void SAL_CALL dispose() override;
};

}

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */