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