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_SLOT_STATE_LISTENER_HXX 25 #define SD_TOOLS_SLOT_STATE_LISTENER_HXX 26 27 #include "MutexOwner.hxx" 28 #include <com/sun/star/frame/XStatusListener.hpp> 29 #include <com/sun/star/frame/XFrame.hpp> 30 #include <com/sun/star/frame/FeatureStateEvent.hpp> 31 #include <com/sun/star/frame/XDispatchProvider.hpp> 32 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTIOIN_HPP_ 33 #include <com/sun/star/lang/DisposedException.hpp> 34 #endif 35 #include <com/sun/star/lang/XComponent.hpp> 36 #include <cppuhelper/compbase1.hxx> 37 #include <tools/link.hxx> 38 39 namespace sd { namespace tools { 40 41 42 typedef cppu::WeakComponentImplHelper1< 43 ::com::sun::star::frame::XStatusListener 44 > SlotStateListenerInterfaceBase; 45 46 47 /** Listen for state changes of slots. This class has been created in order 48 to be informed when the support for vertical writing changes but it can 49 be used to relay state changes of other slots as well. 50 */ 51 class SlotStateListener 52 : protected MutexOwner, 53 public SlotStateListenerInterfaceBase 54 { 55 public: 56 /** This convenience version of the constructor takes all parameters 57 that are necessary to observe a single slot. See descriptions of 58 the SetCallback(), ConnectToFrame(), and ObserveSlot() methods for 59 explanations about the parameters. 60 */ 61 SlotStateListener ( 62 Link& rCallback, 63 const ::com::sun::star::uno::Reference< 64 ::com::sun::star::frame::XDispatchProvider>& rxDispatchProvider, 65 const ::rtl::OUString& rSlotName); 66 67 /** The constructor de-registers all remaining listeners. Usually a prior 68 dispose() call should have done that already. 69 */ 70 virtual ~SlotStateListener (void); 71 72 /** Set the callback to the given value. Whenever one of the observed 73 slots changes its state this callback is informed about it. 74 Changing the callback does not release the listeners. 75 @throws DisposedException 76 */ 77 void SetCallback (const Link& rCallback); 78 79 /** Set the frame whose slots shall be observed. When an object of this 80 class is already observing slots of another frame then these 81 listeners are released first. 82 @throws DisposedException 83 */ 84 void ConnectToDispatchProvider ( 85 const ::com::sun::star::uno::Reference< 86 ::com::sun::star::frame::XDispatchProvider>& rxDispatchProvider); 87 88 /** Observe the slot specified by the given name. Note that 89 ConnectToFrame() has to have been called earlier. 90 @param rSlotName 91 The name of the slot to observe. An example is 92 ".uno:VerticalTextState". 93 @throws DisposedException 94 */ 95 void ObserveSlot (const ::rtl::OUString& rSlotName); 96 97 //===== frame::XStatusListener ========================================== 98 99 /** Called by slot state change broadcasters. In turn the callback is 100 informed about the state chage. 101 @throws DisposedException 102 */ 103 virtual void SAL_CALL 104 statusChanged ( 105 const ::com::sun::star::frame::FeatureStateEvent& rState) 106 throw (::com::sun::star::uno::RuntimeException); 107 108 //===== lang::XEventListener ============================================ 109 110 virtual void SAL_CALL 111 disposing(const com::sun::star::lang::EventObject& rEvent) 112 throw(com::sun::star::uno::RuntimeException); 113 114 protected: 115 /** This method is called by the WeakComponentImplHelper base class in 116 reaction to a XComponent::dispose() call. It releases all currently 117 active listeners. 118 */ 119 virtual void SAL_CALL disposing (void); 120 121 private: 122 Link maCallback; 123 124 /** Remember the URLs that describe slots whose state changes we are 125 listening to. 126 */ 127 typedef ::std::vector<com::sun::star::util::URL> RegisteredURLList; 128 RegisteredURLList maRegisteredURLList; 129 130 ::com::sun::star::uno::WeakReference< 131 ::com::sun::star::frame::XDispatchProvider> mxDispatchProviderWeak; 132 133 /** Deregister all currently active state change listeners. 134 */ 135 void ReleaseListeners (void); 136 137 /** This method throws a DisposedException when the object has already been 138 disposed. 139 */ 140 void ThrowIfDisposed (void) 141 throw (::com::sun::star::lang::DisposedException); 142 143 /** Transform the given string into a URL object. 144 */ 145 ::com::sun::star::util::URL MakeURL (const ::rtl::OUString& rSlotName) const; 146 147 /** Return an XDispatch object for the given URL. 148 */ 149 ::com::sun::star::uno::Reference<com::sun::star::frame::XDispatch> 150 GetDispatch ( 151 const ::com::sun::star::util::URL& rURL) const; 152 }; 153 154 } } // end of namespace ::sd::tools 155 156 #endif 157