xref: /trunk/main/reportdesign/inc/UndoEnv.hxx (revision cdf0e10c)
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 #ifndef INCLUDED_UNDOENV_HXX
28 #define INCLUDED_UNDOENV_HXX
29 
30 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
31 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
32 #include <com/sun/star/container/XContainerListener.hpp>
33 #include <com/sun/star/report/XReportDefinition.hpp>
34 #include <memory>
35 #include <svl/lstner.hxx>
36 
37 namespace rptui
38 {
39 	class OXUndoEnvironmentImpl;
40 
41 	//========================================================================
42 	class REPORTDESIGN_DLLPUBLIC OXUndoEnvironment
43 		: public ::cppu::WeakImplHelper3<	::com::sun::star::beans::XPropertyChangeListener
44 										,	::com::sun::star::container::XContainerListener
45 										,	::com::sun::star::util::XModifyListener
46 										>
47 		, public SfxListener
48 	{
49         const ::std::auto_ptr<OXUndoEnvironmentImpl> m_pImpl;
50 
51         OXUndoEnvironment(const OXUndoEnvironment&);
52 		OXUndoEnvironment& operator=(const OXUndoEnvironment&);
53 
54 	protected:
55 		virtual ~OXUndoEnvironment();
56 
57         void SetUndoMode(sal_Bool _bUndo);
58 
59 	public:
60 		OXUndoEnvironment(OReportModel& _rModel);
61 
62         /**
63            Create an object ob OUndoEnvLock locks the undo possibility
64            As long as in the OUndoEnvLock scope, no undo is possible for manipulated object.
65          */
66         class OUndoEnvLock
67         {
68             OXUndoEnvironment& m_rUndoEnv;
69         public:
70             OUndoEnvLock(OXUndoEnvironment& _rUndoEnv): m_rUndoEnv(_rUndoEnv){m_rUndoEnv.Lock();}
71             ~OUndoEnvLock(){ m_rUndoEnv.UnLock(); }
72         };
73 
74         /**
75            This is near the same as OUndoEnvLock but it is also possible to ask for the current mode.
76            UndoMode will set if SID_UNDO is called in execute()
77          */
78         class OUndoMode
79         {
80             OXUndoEnvironment& m_rUndoEnv;
81         public:
82             OUndoMode(OXUndoEnvironment& _rUndoEnv)
83                 :m_rUndoEnv(_rUndoEnv)
84             {
85                 m_rUndoEnv.Lock();
86                 m_rUndoEnv.SetUndoMode(sal_True);
87             }
88             ~OUndoMode()
89             {
90                 m_rUndoEnv.SetUndoMode(sal_False);
91                 m_rUndoEnv.UnLock();
92             }
93         };
94 
95 		void Lock();
96 		void UnLock();
97 		sal_Bool IsLocked() const;
98 
99         // returns sal_True is we are in UNDO
100         sal_Bool IsUndoMode() const;
101 
102 		// access control
103 		struct Accessor { friend class OReportModel; private: Accessor() { } };
104         void Clear(const Accessor& _r);
105 
106         void AddElement(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& Element);
107         void RemoveElement(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& Element);
108 
109 		void AddSection( const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection);
110 		void RemoveSection( const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection );
111         /** removes the section from the page out of the undo env
112         *
113         * \param _pPage
114         */
115         void RemoveSection(OReportPage* _pPage);
116 
117 	protected:
118 		// XEventListener
119 		virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
120 
121 		// XPropertyChangeListener
122 		virtual void SAL_CALL propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt) throw(::com::sun::star::uno::RuntimeException);
123 
124 		// XContainerListener
125 		virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
126 		virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
127 		virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
128 
129 		// XModifyListener
130 		virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
131 
132 		void ModeChanged();
133 
134 		virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
135 
136 	private:
137 		void TogglePropertyListening(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& Element);
138 
139 		void    implSetModified();
140 
141 		void    switchListening( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxContainer, bool _bStartListening ) SAL_THROW(());
142 		void    switchListening( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxObject, bool _bStartListening ) SAL_THROW(());
143 
144         ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild> >::const_iterator
145             getSection(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild>& _xContainer) const;
146 	};
147 
148 }
149 #endif //
150 
151