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 107 //===== lang::XEventListener ============================================ 108 109 virtual void SAL_CALL 110 disposing(const com::sun::star::lang::EventObject& rEvent); 111 112 protected: 113 /** This method is called by the WeakComponentImplHelper base class in 114 reaction to a XComponent::dispose() call. It releases all currently 115 active listeners. 116 */ 117 virtual void SAL_CALL disposing (void); 118 119 private: 120 Link maCallback; 121 122 /** Remember the URLs that describe slots whose state changes we are 123 listening to. 124 */ 125 typedef ::std::vector<com::sun::star::util::URL> RegisteredURLList; 126 RegisteredURLList maRegisteredURLList; 127 128 ::com::sun::star::uno::WeakReference< 129 ::com::sun::star::frame::XDispatchProvider> mxDispatchProviderWeak; 130 131 /** Deregister all currently active state change listeners. 132 */ 133 void ReleaseListeners (void); 134 135 /** This method throws a DisposedException when the object has already been 136 disposed. 137 */ 138 void ThrowIfDisposed (void); 139 140 /** Transform the given string into a URL object. 141 */ 142 ::com::sun::star::util::URL MakeURL (const ::rtl::OUString& rSlotName) const; 143 144 /** Return an XDispatch object for the given URL. 145 */ 146 ::com::sun::star::uno::Reference<com::sun::star::frame::XDispatch> 147 GetDispatch ( 148 const ::com::sun::star::util::URL& rURL) const; 149 }; 150 151 } } // end of namespace ::sd::tools 152 153 #endif 154