xref: /aoo41x/main/reportdesign/inc/UndoEnv.hxx (revision 9ee13d13)
1*9ee13d13SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9ee13d13SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9ee13d13SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9ee13d13SAndrew Rist  * distributed with this work for additional information
6*9ee13d13SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9ee13d13SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9ee13d13SAndrew Rist  * "License"); you may not use this file except in compliance
9*9ee13d13SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9ee13d13SAndrew Rist  *
11*9ee13d13SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9ee13d13SAndrew Rist  *
13*9ee13d13SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9ee13d13SAndrew Rist  * software distributed under the License is distributed on an
15*9ee13d13SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9ee13d13SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9ee13d13SAndrew Rist  * specific language governing permissions and limitations
18*9ee13d13SAndrew Rist  * under the License.
19*9ee13d13SAndrew Rist  *
20*9ee13d13SAndrew Rist  *************************************************************/
21*9ee13d13SAndrew Rist 
22*9ee13d13SAndrew Rist 
23cdf0e10cSrcweir #ifndef INCLUDED_UNDOENV_HXX
24cdf0e10cSrcweir #define INCLUDED_UNDOENV_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyChangeListener.hpp>
27cdf0e10cSrcweir #include <com/sun/star/beans/PropertyChangeEvent.hpp>
28cdf0e10cSrcweir #include <com/sun/star/container/XContainerListener.hpp>
29cdf0e10cSrcweir #include <com/sun/star/report/XReportDefinition.hpp>
30cdf0e10cSrcweir #include <memory>
31cdf0e10cSrcweir #include <svl/lstner.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace rptui
34cdf0e10cSrcweir {
35cdf0e10cSrcweir 	class OXUndoEnvironmentImpl;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir 	//========================================================================
38cdf0e10cSrcweir 	class REPORTDESIGN_DLLPUBLIC OXUndoEnvironment
39cdf0e10cSrcweir 		: public ::cppu::WeakImplHelper3<	::com::sun::star::beans::XPropertyChangeListener
40cdf0e10cSrcweir 										,	::com::sun::star::container::XContainerListener
41cdf0e10cSrcweir 										,	::com::sun::star::util::XModifyListener
42cdf0e10cSrcweir 										>
43cdf0e10cSrcweir 		, public SfxListener
44cdf0e10cSrcweir 	{
45cdf0e10cSrcweir         const ::std::auto_ptr<OXUndoEnvironmentImpl> m_pImpl;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir         OXUndoEnvironment(const OXUndoEnvironment&);
48cdf0e10cSrcweir 		OXUndoEnvironment& operator=(const OXUndoEnvironment&);
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 	protected:
51cdf0e10cSrcweir 		virtual ~OXUndoEnvironment();
52cdf0e10cSrcweir 
53cdf0e10cSrcweir         void SetUndoMode(sal_Bool _bUndo);
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 	public:
56cdf0e10cSrcweir 		OXUndoEnvironment(OReportModel& _rModel);
57cdf0e10cSrcweir 
58cdf0e10cSrcweir         /**
59cdf0e10cSrcweir            Create an object ob OUndoEnvLock locks the undo possibility
60cdf0e10cSrcweir            As long as in the OUndoEnvLock scope, no undo is possible for manipulated object.
61cdf0e10cSrcweir          */
62cdf0e10cSrcweir         class OUndoEnvLock
63cdf0e10cSrcweir         {
64cdf0e10cSrcweir             OXUndoEnvironment& m_rUndoEnv;
65cdf0e10cSrcweir         public:
OUndoEnvLock(OXUndoEnvironment & _rUndoEnv)66cdf0e10cSrcweir             OUndoEnvLock(OXUndoEnvironment& _rUndoEnv): m_rUndoEnv(_rUndoEnv){m_rUndoEnv.Lock();}
~OUndoEnvLock()67cdf0e10cSrcweir             ~OUndoEnvLock(){ m_rUndoEnv.UnLock(); }
68cdf0e10cSrcweir         };
69cdf0e10cSrcweir 
70cdf0e10cSrcweir         /**
71cdf0e10cSrcweir            This is near the same as OUndoEnvLock but it is also possible to ask for the current mode.
72cdf0e10cSrcweir            UndoMode will set if SID_UNDO is called in execute()
73cdf0e10cSrcweir          */
74cdf0e10cSrcweir         class OUndoMode
75cdf0e10cSrcweir         {
76cdf0e10cSrcweir             OXUndoEnvironment& m_rUndoEnv;
77cdf0e10cSrcweir         public:
OUndoMode(OXUndoEnvironment & _rUndoEnv)78cdf0e10cSrcweir             OUndoMode(OXUndoEnvironment& _rUndoEnv)
79cdf0e10cSrcweir                 :m_rUndoEnv(_rUndoEnv)
80cdf0e10cSrcweir             {
81cdf0e10cSrcweir                 m_rUndoEnv.Lock();
82cdf0e10cSrcweir                 m_rUndoEnv.SetUndoMode(sal_True);
83cdf0e10cSrcweir             }
~OUndoMode()84cdf0e10cSrcweir             ~OUndoMode()
85cdf0e10cSrcweir             {
86cdf0e10cSrcweir                 m_rUndoEnv.SetUndoMode(sal_False);
87cdf0e10cSrcweir                 m_rUndoEnv.UnLock();
88cdf0e10cSrcweir             }
89cdf0e10cSrcweir         };
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 		void Lock();
92cdf0e10cSrcweir 		void UnLock();
93cdf0e10cSrcweir 		sal_Bool IsLocked() const;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         // returns sal_True is we are in UNDO
96cdf0e10cSrcweir         sal_Bool IsUndoMode() const;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 		// access control
Accessorrptui::OXUndoEnvironment::Accessor99cdf0e10cSrcweir 		struct Accessor { friend class OReportModel; private: Accessor() { } };
100cdf0e10cSrcweir         void Clear(const Accessor& _r);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         void AddElement(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& Element);
103cdf0e10cSrcweir         void RemoveElement(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& Element);
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 		void AddSection( const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection);
106cdf0e10cSrcweir 		void RemoveSection( const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection );
107cdf0e10cSrcweir         /** removes the section from the page out of the undo env
108cdf0e10cSrcweir         *
109cdf0e10cSrcweir         * \param _pPage
110cdf0e10cSrcweir         */
111cdf0e10cSrcweir         void RemoveSection(OReportPage* _pPage);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	protected:
114cdf0e10cSrcweir 		// XEventListener
115cdf0e10cSrcweir 		virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 		// XPropertyChangeListener
118cdf0e10cSrcweir 		virtual void SAL_CALL propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt) throw(::com::sun::star::uno::RuntimeException);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 		// XContainerListener
121cdf0e10cSrcweir 		virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
122cdf0e10cSrcweir 		virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
123cdf0e10cSrcweir 		virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 		// XModifyListener
126cdf0e10cSrcweir 		virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 		void ModeChanged();
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 		virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	private:
133cdf0e10cSrcweir 		void TogglePropertyListening(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& Element);
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 		void    implSetModified();
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 		void    switchListening( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxContainer, bool _bStartListening ) SAL_THROW(());
138cdf0e10cSrcweir 		void    switchListening( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxObject, bool _bStartListening ) SAL_THROW(());
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild> >::const_iterator
141cdf0e10cSrcweir             getSection(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild>& _xContainer) const;
142cdf0e10cSrcweir 	};
143cdf0e10cSrcweir 
144cdf0e10cSrcweir }
145cdf0e10cSrcweir #endif //
146cdf0e10cSrcweir 
147