1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef SD_FRAMEWORK_READ_ONLY_MODE_OBSERVER_HXX 29 #define SD_FRAMEWORK_READ_ONLY_MODE_OBSERVER_HXX 30 31 #include "MutexOwner.hxx" 32 33 #include <com/sun/star/beans/XPropertySet.hpp> 34 #include <com/sun/star/frame/XController.hpp> 35 #include <com/sun/star/frame/XStatusListener.hpp> 36 #include <com/sun/star/frame/XDispatch.hpp> 37 #include <com/sun/star/lang/XEventListener.hpp> 38 #include <com/sun/star/util/XModifyListener.hpp> 39 #include <com/sun/star/drawing/framework/XConfigurationController.hpp> 40 #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp> 41 #include <osl/mutex.hxx> 42 #include <cppuhelper/compbase2.hxx> 43 #include <tools/link.hxx> 44 #include <boost/function.hpp> 45 #include <boost/scoped_ptr.hpp> 46 #include <boost/shared_ptr.hpp> 47 48 namespace { 49 50 typedef ::cppu::WeakComponentImplHelper2 < 51 ::com::sun::star::drawing::framework::XConfigurationChangeListener, 52 ::com::sun::star::frame::XStatusListener 53 > ReadOnlyModeObserverInterfaceBase; 54 55 } // end of anonymous namespace. 56 57 58 59 60 namespace sd { namespace framework { 61 62 /** Wait for changes of the read-only mode. On switching between read-only 63 mode and read-write the registered listeners are called. 64 65 This class handles the case that the given controller is not yet 66 connected to a frame and that the dispatcher is not yet set up. It 67 waits for this to happen and then registers at the .uno:EditDoc command 68 and waits for state changes. 69 */ 70 class ReadOnlyModeObserver 71 : private sd::MutexOwner, 72 public ReadOnlyModeObserverInterfaceBase 73 { 74 public: 75 /** Create a new read-only mode observer for the given controller. 76 */ 77 ReadOnlyModeObserver ( 78 const ::com::sun::star::uno::Reference<com::sun::star::frame::XController>& rxController); 79 virtual ~ReadOnlyModeObserver (void); 80 81 virtual void SAL_CALL disposing (void); 82 83 84 /** Add a status listener that is called when the state of the 85 .uno:EditDoc command changes. Note that the listener has to take 86 into account both the IsEnabled and the State fields of the 87 FeatureStateEvent. Only when IsEnabled is true then the State field 88 is valid. 89 */ 90 void AddStatusListener ( 91 const ::com::sun::star::uno::Reference< 92 com::sun::star::frame::XStatusListener>& rxListener); 93 94 // XEventListener 95 96 virtual void SAL_CALL disposing ( 97 const com::sun::star::lang::EventObject& rEvent) 98 throw (com::sun::star::uno::RuntimeException); 99 100 101 // frame::XStatusListener 102 103 /** Called by slot state change broadcasters. 104 @throws DisposedException 105 */ 106 virtual void SAL_CALL 107 statusChanged ( 108 const ::com::sun::star::frame::FeatureStateEvent& rState) 109 throw (::com::sun::star::uno::RuntimeException); 110 111 // XConfigurationChangeListener 112 113 virtual void SAL_CALL notifyConfigurationChange ( 114 const ::com::sun::star::drawing::framework::ConfigurationChangeEvent& rEvent) 115 throw (::com::sun::star::uno::RuntimeException); 116 117 private: 118 ::com::sun::star::util::URL maSlotNameURL; 119 /** The XController is stored to enable repeated calls to 120 ConnectToDispatch() (get access to the XDispatchProvider. 121 */ 122 ::com::sun::star::uno::Reference<com::sun::star::frame::XController> 123 mxController; 124 ::com::sun::star::uno::Reference<com::sun::star::drawing::framework::XConfigurationController> 125 mxConfigurationController; 126 ::com::sun::star::uno::Reference<com::sun::star::frame::XDispatch> 127 mxDispatch; 128 class ModifyBroadcaster; 129 ::boost::scoped_ptr<ModifyBroadcaster> mpBroadcaster; 130 131 /** Listen for the .uno:EditMode command. Returns <TRUE/> when the connection 132 has been established. 133 */ 134 bool ConnectToDispatch (void); 135 }; 136 137 } } // end of namespace sd::framework 138 139 #endif 140