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