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