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_SLIDESORTER_SLIDE_SORTER_LISTENER_HXX 25 #define SD_SLIDESORTER_SLIDE_SORTER_LISTENER_HXX 26 27 #include "MutexOwner.hxx" 28 #include "controller/SlideSorterController.hxx" 29 #include <com/sun/star/document/XEventListener.hpp> 30 #include <com/sun/star/beans/XPropertyChangeListener.hpp> 31 #include <com/sun/star/accessibility/XAccessibleEventListener.hpp> 32 #include <com/sun/star/lang/DisposedException.hpp> 33 #include <com/sun/star/beans/XPropertySet.hpp> 34 #include <com/sun/star/frame/XFrameActionListener.hpp> 35 #include <cppuhelper/compbase4.hxx> 36 37 #include <svl/lstner.hxx> 38 #include <tools/link.hxx> 39 #include <boost/shared_ptr.hpp> 40 41 namespace sd { 42 class ViewShellBase; 43 } 44 45 namespace sd { namespace tools { 46 class EventMultiplexerEvent; 47 } } 48 49 namespace sd { namespace slidesorter { 50 class SlideSorter; 51 } } 52 53 54 namespace sd { namespace slidesorter { namespace controller { 55 56 typedef cppu::WeakComponentImplHelper4< 57 ::com::sun::star::document::XEventListener, 58 ::com::sun::star::beans::XPropertyChangeListener, 59 ::com::sun::star::accessibility::XAccessibleEventListener, 60 ::com::sun::star::frame::XFrameActionListener 61 > ListenerInterfaceBase; 62 63 class SlideSorterController; 64 65 /** Listen for events of various types and sources and react to them. This 66 class is a part of the controller. 67 68 When the view shell in the center pane is replaced by another the 69 associated controller is replaced as well. Therefore we have to 70 register at the frame and on certain FrameActionEvents to stop listening 71 to the old controller and register as listener at the new one. 72 */ 73 class Listener 74 : protected MutexOwner, 75 public ListenerInterfaceBase, 76 public SfxListener 77 { 78 public: 79 Listener (SlideSorter& rSlideSorter); 80 virtual ~Listener (void); 81 82 /** Connect to the current controller of the view shell as listener. 83 This method is called once during initialization and every time a 84 FrameActionEvent signals the current controller being exchanged. 85 When the connection is successful then the flag 86 mbListeningToController is set to <TRUE/>. 87 */ 88 void ConnectToController (void); 89 90 /** Disconnect from the current controller of the view shell as 91 listener. This method is called once during initialization and 92 every time a FrameActionEvent signals the current controller being 93 exchanged. When this method terminates then mbListeningToController 94 is <FALSE/>. 95 */ 96 void DisconnectFromController (void); 97 98 virtual void Notify ( 99 SfxBroadcaster& rBroadcaster, 100 const SfxHint& rHint); 101 102 //===== lang::XEventListener ============================================ 103 virtual void SAL_CALL 104 disposing (const ::com::sun::star::lang::EventObject& rEventObject); 105 106 107 //===== document::XEventListener ======================================== 108 virtual void SAL_CALL 109 notifyEvent ( 110 const ::com::sun::star::document::EventObject& rEventObject); 111 112 //===== beans::XPropertySetListener ===================================== 113 virtual void SAL_CALL 114 propertyChange ( 115 const com::sun::star::beans::PropertyChangeEvent& rEvent); 116 117 //===== accessibility::XAccessibleEventListener ========================== 118 virtual void SAL_CALL 119 notifyEvent ( 120 const ::com::sun::star::accessibility::AccessibleEventObject& 121 rEvent); 122 123 //===== frame::XFrameActionListener ====================================== 124 /** For certain actions the listener connects to a new controller of the 125 frame it is listening to. This usually happens when the view shell 126 in the center pane is replaced by another view shell. 127 */ 128 virtual void SAL_CALL 129 frameAction (const ::com::sun::star::frame::FrameActionEvent& rEvent); 130 131 virtual void SAL_CALL disposing (void); 132 133 private: 134 SlideSorter& mrSlideSorter; 135 SlideSorterController& mrController; 136 ViewShellBase* mpBase; 137 138 /// Remember whether we are listening to the document. 139 bool mbListeningToDocument; 140 /// Remember whether we are listening to the UNO document. 141 bool mbListeningToUNODocument; 142 /// Remember whether we are listening to the UNO controller. 143 bool mbListeningToController; 144 /// Remember whether we are listening to the frame. 145 bool mbListeningToFrame; 146 bool mbIsMainViewChangePending; 147 148 ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XController> mxControllerWeak; 149 ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XFrame> mxFrameWeak; 150 151 /** This object is used to lock the model between some 152 events. It is references counted in order to cope with events that 153 are expected but never sent. 154 */ 155 ::boost::shared_ptr<SlideSorterController::ModelChangeLock> mpModelChangeLock; 156 157 void ReleaseListeners (void); 158 159 /** Called when the edit mode has changed. Update model accordingly. 160 */ 161 void UpdateEditMode (void); 162 163 /** Handle a change in the order of slides or when the set of slides has 164 changed, i.e. a slide has been created. 165 */ 166 void HandleModelChange (const SdrPage* pPage); 167 168 /** Handle a modification to a shape on the given page. When this is a 169 regular page then update its preview. When it is a master page then 170 additionally update the previews of all pages linked to it. 171 */ 172 void HandleShapeModification (const SdrPage* pPage); 173 174 /** This method throws a DisposedException when the object has already been 175 disposed. 176 */ 177 void ThrowIfDisposed (void); 178 179 DECL_LINK(EventMultiplexerCallback, tools::EventMultiplexerEvent*); 180 }; 181 182 } } } // end of namespace ::sd::slidesorter::controller 183 184 #endif 185