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_FRAMEWORK_READ_ONLY_MODE_OBSERVER_HXX 25 #define SD_FRAMEWORK_READ_ONLY_MODE_OBSERVER_HXX 26 27 #include "MutexOwner.hxx" 28 29 #include <com/sun/star/beans/XPropertySet.hpp> 30 #include <com/sun/star/frame/XController.hpp> 31 #include <com/sun/star/frame/XStatusListener.hpp> 32 #include <com/sun/star/frame/XDispatch.hpp> 33 #include <com/sun/star/lang/XEventListener.hpp> 34 #include <com/sun/star/util/XModifyListener.hpp> 35 #include <com/sun/star/drawing/framework/XConfigurationController.hpp> 36 #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp> 37 #include <osl/mutex.hxx> 38 #include <cppuhelper/compbase2.hxx> 39 #include <tools/link.hxx> 40 #include <boost/function.hpp> 41 #include <boost/scoped_ptr.hpp> 42 #include <boost/shared_ptr.hpp> 43 44 namespace { 45 46 typedef ::cppu::WeakComponentImplHelper2 < 47 ::com::sun::star::drawing::framework::XConfigurationChangeListener, 48 ::com::sun::star::frame::XStatusListener 49 > ReadOnlyModeObserverInterfaceBase; 50 51 } // end of anonymous namespace. 52 53 54 55 56 namespace sd { namespace framework { 57 58 /** Wait for changes of the read-only mode. On switching between read-only 59 mode and read-write the registered listeners are called. 60 61 This class handles the case that the given controller is not yet 62 connected to a frame and that the dispatcher is not yet set up. It 63 waits for this to happen and then registers at the .uno:EditDoc command 64 and waits for state changes. 65 */ 66 class ReadOnlyModeObserver 67 : private sd::MutexOwner, 68 public ReadOnlyModeObserverInterfaceBase 69 { 70 public: 71 /** Create a new read-only mode observer for the given controller. 72 */ 73 ReadOnlyModeObserver ( 74 const ::com::sun::star::uno::Reference<com::sun::star::frame::XController>& rxController); 75 virtual ~ReadOnlyModeObserver (void); 76 77 virtual void SAL_CALL disposing (void); 78 79 80 /** Add a status listener that is called when the state of the 81 .uno:EditDoc command changes. Note that the listener has to take 82 into account both the IsEnabled and the State fields of the 83 FeatureStateEvent. Only when IsEnabled is true then the State field 84 is valid. 85 */ 86 void AddStatusListener ( 87 const ::com::sun::star::uno::Reference< 88 com::sun::star::frame::XStatusListener>& rxListener); 89 90 // XEventListener 91 92 virtual void SAL_CALL disposing ( 93 const com::sun::star::lang::EventObject& rEvent) 94 throw (com::sun::star::uno::RuntimeException); 95 96 97 // frame::XStatusListener 98 99 /** Called by slot state change broadcasters. 100 @throws DisposedException 101 */ 102 virtual void SAL_CALL 103 statusChanged ( 104 const ::com::sun::star::frame::FeatureStateEvent& rState) 105 throw (::com::sun::star::uno::RuntimeException); 106 107 // XConfigurationChangeListener 108 109 virtual void SAL_CALL notifyConfigurationChange ( 110 const ::com::sun::star::drawing::framework::ConfigurationChangeEvent& rEvent) 111 throw (::com::sun::star::uno::RuntimeException); 112 113 private: 114 ::com::sun::star::util::URL maSlotNameURL; 115 /** The XController is stored to enable repeated calls to 116 ConnectToDispatch() (get access to the XDispatchProvider. 117 */ 118 ::com::sun::star::uno::Reference<com::sun::star::frame::XController> 119 mxController; 120 ::com::sun::star::uno::Reference<com::sun::star::drawing::framework::XConfigurationController> 121 mxConfigurationController; 122 ::com::sun::star::uno::Reference<com::sun::star::frame::XDispatch> 123 mxDispatch; 124 class ModifyBroadcaster; 125 ::boost::scoped_ptr<ModifyBroadcaster> mpBroadcaster; 126 127 /** Listen for the .uno:EditMode command. Returns <TRUE/> when the connection 128 has been established. 129 */ 130 bool ConnectToDispatch (void); 131 }; 132 133 } } // end of namespace sd::framework 134 135 #endif 136