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 successfull 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         throw (::com::sun::star::uno::RuntimeException);
106 
107 
108     //=====  document::XEventListener  ========================================
109     virtual void SAL_CALL
110         notifyEvent (
111             const ::com::sun::star::document::EventObject& rEventObject)
112         throw (::com::sun::star::uno::RuntimeException);
113 
114     //=====  beans::XPropertySetListener  =====================================
115     virtual void SAL_CALL
116         propertyChange (
117             const com::sun::star::beans::PropertyChangeEvent& rEvent)
118         throw (::com::sun::star::uno::RuntimeException);
119 
120     //===== accessibility::XAccessibleEventListener  ==========================
121     virtual void SAL_CALL
122         notifyEvent (
123             const ::com::sun::star::accessibility::AccessibleEventObject&
124             rEvent)
125         throw (::com::sun::star::uno::RuntimeException);
126 
127     //===== frame::XFrameActionListener  ======================================
128     /** For certain actions the listener connects to a new controller of the
129         frame it is listening to.  This usually happens when the view shell
130         in the center pane is replaced by another view shell.
131     */
132     virtual void SAL_CALL
133         frameAction (const ::com::sun::star::frame::FrameActionEvent& rEvent)
134         throw (::com::sun::star::uno::RuntimeException);
135 
136     virtual void SAL_CALL disposing (void);
137 
138 private:
139     SlideSorter& mrSlideSorter;
140     SlideSorterController& mrController;
141     ViewShellBase* mpBase;
142 
143     /// Remember whether we are listening to the document.
144     bool mbListeningToDocument;
145     /// Remember whether we are listening to the UNO document.
146     bool mbListeningToUNODocument;
147     /// Remember whether we are listening to the UNO controller.
148     bool mbListeningToController;
149     /// Remember whether we are listening to the frame.
150     bool mbListeningToFrame;
151     bool mbIsMainViewChangePending;
152 
153     ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XController> mxControllerWeak;
154     ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XFrame> mxFrameWeak;
155 
156     /** This object is used to lock the model between some
157         events.  It is refernce counted in order to cope with events that
158         are expected but never sent.
159     */
160     ::boost::shared_ptr<SlideSorterController::ModelChangeLock> mpModelChangeLock;
161 
162     void ReleaseListeners (void);
163 
164     /** Called when the edit mode has changed.  Update model accordingly.
165     */
166     void UpdateEditMode (void);
167 
168     /** Handle a change in the order of slides or when the set of slides has
169         changed, i.e. a slide has been created.
170     */
171     void HandleModelChange (const SdrPage* pPage);
172 
173     /** Handle a modification to a shape on the given page.  When this is a
174         regular page then update its preview.  When it is a master page then
175         additionally update the previews of all pages linked to it.
176     */
177     void HandleShapeModification (const SdrPage* pPage);
178 
179     /** This method throws a DisposedException when the object has already been
180         disposed.
181     */
182     void ThrowIfDisposed (void)
183         throw (::com::sun::star::lang::DisposedException);
184 
185     DECL_LINK(EventMultiplexerCallback, tools::EventMultiplexerEvent*);
186 };
187 
188 } } } // end of namespace ::sd::slidesorter::controller
189 
190 #endif
191