xref: /trunk/main/sd/source/ui/inc/EventMultiplexer.hxx (revision 67e470da)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SD_TOOLS_EVENT_MULTIPLEXER_HXX
25 #define SD_TOOLS_EVENT_MULTIPLEXER_HXX
26 
27 #include <svl/lstner.hxx>
28 
29 #include <set>
30 #include <memory>
31 
32 class Link;
33 
34 namespace sd {
35 class ViewShellBase;
36 }
37 
38 namespace sd { namespace tools {
39 
40 class EventMultiplexerEvent
41 {
42 public:
43     typedef sal_uInt32 EventId;
44     /** The EventMultiplexer itself is being disposed.  Called for a live
45         EventMultiplexer.  Removing a listener as response is not necessary,
46         though.
47     */
48     static const EventId EID_DISPOSING              = 0x00000001;
49 
50     /** The selection in the center pane has changed.
51     */
52     static const EventId EID_EDIT_VIEW_SELECTION    = 0x00000002;
53 
54     /** The selection in the slide sorter has changed, regardless of whether
55         the slide sorter is displayed in the left pane or the center pane.
56     */
57     static const EventId EID_SLIDE_SORTER_SELECTION = 0x00000004;
58 
59     /** The current page has changed.
60     */
61     static const EventId EID_CURRENT_PAGE           = 0x00000008;
62 
63     /** The current MainViewShell (the ViewShell displayed in the center
64         pane) has been removed.
65     */
66     static const EventId EID_MAIN_VIEW_REMOVED      = 0x00000010;
67 
68     /** A new ViewShell has been made the MainViewShell.
69     */
70     static const EventId EID_MAIN_VIEW_ADDED        = 0x00000020;
71 
72     /** A ViewShell has been removed from one of the panes.  Note that for
73         the ViewShell in the center pane bth this event type and
74         EID_MAIN_VIEW_REMOVED is broadcasted.
75     */
76     static const EventId EID_VIEW_REMOVED           = 0x00000040;
77 
78     /** A new ViewShell is being displayed in one of the panes.  Note that
79         for the ViewShell in the center pane both this event type and
80         EID_MAIN_VIEW_ADDED is broadcasted.
81     */
82     static const EventId EID_VIEW_ADDED             = 0x00000080;
83 
84     /** The PaneManager is being destroyed.
85     */
86     static const EventId EID_PANE_MANAGER_DYING     = 0x00000100;
87 
88     /** Edit mode was (or is being) switched to normal mode.  Find
89         EID_EDIT_MODE_MASTER below.
90     */
91     static const EventId EID_EDIT_MODE_NORMAL       = 0x00000200;
92 
93     /** One or more pages have been inserted into or deleted from the model.
94     */
95     static const EventId EID_PAGE_ORDER             = 0x00000400;
96 
97     /** Text editing in one of the shapes in the MainViewShell has started.
98     */
99     static const EventId EID_BEGIN_TEXT_EDIT        = 0x00000800;
100 
101     /** Text editing in one of the shapes in the MainViewShell has ended.
102     */
103     static const EventId EID_END_TEXT_EDIT          = 0x00001000;
104 
105     /** A UNO controller has been attached to the UNO frame.
106     */
107     static const EventId EID_CONTROLLER_ATTACHED    = 0x00002000;
108 
109     /** A UNO controller has been detached to the UNO frame.
110     */
111     static const EventId EID_CONTROLLER_DETACHED    = 0x00004000;
112 
113     /** The state of a shape has changed.  The page is available in the user data.
114     */
115     static const EventId EID_SHAPE_CHANGED          = 0x00008000;
116 
117     /** A shape has been inserted to a page.  The page is available in the
118         user data.
119     */
120     static const EventId EID_SHAPE_INSERTED         = 0x00010000;
121 
122     /** A shape has been removed from a page.  The page is available in the
123         user data.
124     */
125     static const EventId EID_SHAPE_REMOVED          = 0x00020000;
126 
127     /** A configuration update has been completed.
128     */
129     static const EventId EID_CONFIGURATION_UPDATED  = 0x00040000;
130 
131     /** Edit mode was (or is being) switched to master mode.
132     */
133     static const EventId EID_EDIT_MODE_MASTER       = 0x00080000;
134 
135     const ViewShellBase& mrBase;
136     EventId meEventId;
137     const void* mpUserData;
138 
139     EventMultiplexerEvent (
140         const ViewShellBase& rBase,
141         EventId eEventId,
142         const void* pUserData);
143 };
144 
145 
146 /** This convenience class makes it easy to listen to various events that
147     originally are broadcasted via different channels.
148 
149     There is usually one EventMultiplexer instance per ViewShellBase().
150     Call the laters GetEventMultiplexer() method to get access to that
151     instance.
152 
153     When a listener is registered it can specify the events it
154     wants to be informed of.  This can be done with code like the following:
155 
156     mrViewShellBase.GetEventMultiplexer().AddEventListener (
157         LINK(this,MasterPagesSelector,EventMultiplexerListener),
158         tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
159         | tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED);
160 */
161 class EventMultiplexer
162 {
163 public:
164     /** Create new EventMultiplexer for the given ViewShellBase object.
165     */
166     EventMultiplexer (ViewShellBase& rBase);
167     ~EventMultiplexer (void);
168 
169     /** Some constants that make it easier to remove a listener for all
170         event types at once.
171     */
172     static const EventMultiplexerEvent::EventId EID_FULL_SET = 0xffffffff;
173     static const EventMultiplexerEvent::EventId EID_EMPTY_SET = 0x00000000;
174 
175     /** Add an event listener that will be informed about the specified
176         event types.
177         @param rCallback
178             The callback to call as soon as one of the event specified by
179             aEventTypeSet is received by the EventMultiplexer.
180         @param aEventTypeSet
181             A, possibly empty, set of event types that the listener wants to
182             be informed about.
183     */
184     void AddEventListener (
185         Link& rCallback,
186         EventMultiplexerEvent::EventId aEventTypeSet);
187 
188     /** Remove an event listener for the specified event types.
189         @param aEventTypeSet
190             The listener will not be called anymore for any of the event
191             types in this set.  Use EID_FULL_SET, the default value, to
192             remove the listener for all event types it has been registered
193             for.
194     */
195     void RemoveEventListener (
196         Link& rCallback,
197         EventMultiplexerEvent::EventId aEventTypeSet = EID_FULL_SET);
198 
199     /** This method is used for out-of-line events.  An event of the
200         specified type will be sent to all listeners that are registered for
201         that type.
202         @param eEventId
203             The type of the event.
204         @param pUserData
205             Some data sent to the listeners along with the event.
206     */
207 	void MultiplexEvent(
208 		EventMultiplexerEvent::EventId eEventId,
209 		void* pUserData = 0);
210 
211 private:
212     class Implementation;
213     ::std::auto_ptr<Implementation> mpImpl;
214 };
215 
216 } } // end of namespace ::sd::tools
217 
218 #endif
219