summaryrefslogtreecommitdiff
path: root/sd/source/ui/inc/EventMultiplexer.hxx
blob: 45e8e8f841331cddfd826141ba491d4e2debfff2 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* -*- 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/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_SD_SOURCE_UI_INC_EVENTMULTIPLEXER_HXX
#define INCLUDED_SD_SOURCE_UI_INC_EVENTMULTIPLEXER_HXX

#include <sal/config.h>

#include <rtl/ref.hxx>
#include <svl/lstner.hxx>
#include <tools/link.hxx>
#include <o3tl/typed_flags_set.hxx>

#include <set>
#include <memory>

namespace sd {
class ViewShellBase;
}


enum class EventMultiplexerEventId
{
    /** The EventMultiplexer itself is being disposed.  Called for a live
        EventMultiplexer.  Removing a listener as response is not necessary,
        though.
    */
    Disposing,

    /** The selection in the center pane has changed.
    */
    EditViewSelection,

    /** The selection in the slide sorter has changed, regardless of whether
        the slide sorter is displayed in the left pane or the center pane.
    */
    SlideSortedSelection,

    /** The current page has changed.
    */
    CurrentPageChanged,

    /** The current MainViewShell (the ViewShell displayed in the center
        pane) has been removed.
    */
    MainViewRemoved,

    /** A new ViewShell has been made the MainViewShell.
    */
    MainViewAdded,

    /** A new ViewShell is being displayed in one of the panes.  Note that
        for the ViewShell in the center pane both this event type and
        EventId::MainViewAdded is broadcasted.
    */
    ViewAdded,

    /** The PaneManager is being destroyed.
    */
    PaneManagerDying,

    /** Edit mode was (or is being) switched to normal mode.  Find
        EventId::EditModeMaster below.
    */
    EditModeNormal,

    /** One or more pages have been inserted into or deleted from the model.
    */
    PageOrder,

    /** Text editing in one of the shapes in the MainViewShell has started.
    */
    BeginTextEdit,

    /** Text editing in one of the shapes in the MainViewShell has ended.
    */
    EndTextEdit,

    /** A UNO controller has been attached to the UNO frame.
    */
    ControllerAttached,

    /** A UNO controller has been detached to the UNO frame.
    */
    ControllerDetached,

    /** The state of a shape has changed.  The page is available in the user data.
    */
    ShapeChanged,

    /** A shape has been inserted to a page.  The page is available in the
        user data.
    */
    ShapeInserted,

    /** A shape has been removed from a page.  The page is available in the
        user data.
    */
    ShapeRemoved,

    /** A configuration update has been completed.
    */
    ConfigurationUpdated,

    /** Edit mode was (or is being) switched to master mode.
    */
    EditModeMaster,
};

namespace sd { namespace tools {

class EventMultiplexerEvent
{
public:
    EventMultiplexerEventId meEventId;
    const void* mpUserData;

    EventMultiplexerEvent (
        EventMultiplexerEventId eEventId,
        const void* pUserData);
};

/** This convenience class makes it easy to listen to various events that
    originally are broadcasted via different channels.

    There is usually one EventMultiplexer instance per ViewShellBase().
    Call the laters GetEventMultiplexer() method to get access to that
    instance.
*/
class EventMultiplexer
{
public:
    /** Create new EventMultiplexer for the given ViewShellBase object.
    */
    EventMultiplexer (ViewShellBase& rBase);
    ~EventMultiplexer();

    /** Add an event listener that will be informed about the specified
        event types.
        @param rCallback
            The callback to call as soon as one of the event specified by
            aEventTypeSet is received by the EventMultiplexer.
    */
    void AddEventListener(const Link<EventMultiplexerEvent&,void>& rCallback);

    /** Remove an event listener for the specified event types.
    */
    void RemoveEventListener(const Link<EventMultiplexerEvent&,void>& rCallback);

    /** This method is used for out-of-line events.  An event of the
        specified type will be sent to all listeners that are registered for
        that type.
        @param eEventId
            The type of the event.
        @param pUserData
            Some data sent to the listeners along with the event.
    */
    void MultiplexEvent(
        EventMultiplexerEventId eEventId,
        void* pUserData);

private:
    class Implementation;
    rtl::Reference<Implementation> mpImpl;
};

} } // end of namespace ::sd::tools

#endif

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