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 RPTUI_UNDOACTIONS_HXX
28 #define RPTUI_UNDOACTIONS_HXX
29 
30 #include "dllapi.h"
31 
32 #include "RptModel.hxx"
33 
34 /** === begin UNO includes === **/
35 #include <com/sun/star/util/XModifyListener.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
38 #include <com/sun/star/script/ScriptEvent.hpp>
39 #include <com/sun/star/script/XScriptListener.hpp>
40 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
41 #include <com/sun/star/container/XNameContainer.hpp>
42 #include <com/sun/star/container/ContainerEvent.hpp>
43 #include <com/sun/star/container/XNameContainer.hpp>
44 #include <com/sun/star/report/XReportComponent.hpp>
45 #include <com/sun/star/report/XReportDefinition.hpp>
46 #include <com/sun/star/report/XGroup.hpp>
47 #include <com/sun/star/document/XUndoManager.hpp>
48 /** === end UNO includes === **/
49 
50 #include <cppuhelper/implbase3.hxx>
51 #include <comphelper/uno3.hxx>
52 #include <comphelper/sequence.hxx>
53 #include <svl/lstner.hxx>
54 #include <svx/svdouno.hxx>
55 #include <svx/svdundo.hxx>
56 #include <tools/string.hxx>
57 
58 #include <functional>
59 #include <memory>
60 #include <boost/shared_ptr.hpp>
61 
62 FORWARD_DECLARE_INTERFACE(awt,XControl)
63 FORWARD_DECLARE_INTERFACE(awt,XControlContainer)
64 namespace dbaui
65 {
66 	class IController;
67 }
68 namespace rptui
69 {
70 	class OObjectBase;
71 
72     enum Action
73 	{
74 		Inserted = 1,
75 		Removed	 = 2
76 	};
77 
78     /** Helper class to allow std::mem_fun for SAL_CALL
79 	*/
80 	class REPORTDESIGN_DLLPUBLIC OGroupHelper
81 	{
82 		::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup > m_xGroup;
83 		OGroupHelper(const OGroupHelper&);
84 		OGroupHelper& operator=(const OGroupHelper&);
85 	public:
86 		OGroupHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup >& _xGroup)
87 			:m_xGroup(_xGroup)
88 		{
89 		}
90 		inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >	getHeader() { return m_xGroup->getHeader(); }
91 		inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >	getFooter() { return m_xGroup->getFooter(); }
92 		inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup >		getGroup() { return m_xGroup; }
93 
94 		inline ::sal_Bool getHeaderOn() { return m_xGroup->getHeaderOn(); }
95 		inline ::sal_Bool getFooterOn() { return m_xGroup->getFooterOn(); }
96 
97         static ::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection> , OGroupHelper> getMemberFunction(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >& _xSection);
98 
99 	};
100 	typedef com::sun::star::uno::Reference< ::com::sun::star::report::XSection > TSection;
101 
102 	/** Helper class to allow std::mem_fun for SAL_CALL
103 	*/
104 	class REPORTDESIGN_DLLPUBLIC OReportHelper
105 	{
106 		::com::sun::star::uno::Reference< ::com::sun::star::report::XReportDefinition > m_xReport;
107 	public:
108 		OReportHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportDefinition >& _xReport)
109 			:m_xReport(_xReport)
110 		{
111 		}
112 		inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getReportHeader() { return m_xReport->getReportHeader(); }
113 		inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getReportFooter() { return m_xReport->getReportFooter(); }
114 		inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getPageHeader()	{ return m_xReport->getPageHeader(); }
115 		inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getPageFooter()	{ return m_xReport->getPageFooter(); }
116         inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getDetail()	    { return m_xReport->getDetail(); }
117 
118         inline ::sal_Bool getReportHeaderOn() { return m_xReport->getReportHeaderOn(); }
119 		inline ::sal_Bool getReportFooterOn() { return m_xReport->getReportFooterOn(); }
120         inline ::sal_Bool getPageHeaderOn() { return m_xReport->getPageHeaderOn(); }
121 		inline ::sal_Bool getPageFooterOn() { return m_xReport->getPageFooterOn(); }
122 
123         static ::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection> , OReportHelper> getMemberFunction(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >& _xSection);
124 	};
125 
126 	//==================================================================================================================
127 	//= UndoContext
128 	//==================================================================================================================
129     class UndoContext
130     {
131     public:
132         UndoContext( SfxUndoManager& i_undoManager, const ::rtl::OUString& i_undoTitle )
133             :m_rUndoManager( i_undoManager )
134         {
135             m_rUndoManager.EnterListAction( i_undoTitle, String() );
136         }
137 
138         ~UndoContext()
139         {
140             m_rUndoManager.LeaveListAction();
141         }
142 
143     private:
144         SfxUndoManager& m_rUndoManager;
145     };
146 
147 	//==================================================================================================================
148 	//= UndoSuppressor
149 	//==================================================================================================================
150     class UndoSuppressor
151     {
152     public:
153         UndoSuppressor( SfxUndoManager& i_undoManager )
154             :m_rUndoManager( i_undoManager )
155         {
156             m_rUndoManager.EnableUndo( false );
157         }
158 
159         ~UndoSuppressor()
160         {
161             m_rUndoManager.EnableUndo( true );
162         }
163 
164     private:
165         SfxUndoManager& m_rUndoManager;
166     };
167 
168 	//==================================================================================================================
169 	//= OCommentUndoAction
170 	//==================================================================================================================
171     class REPORTDESIGN_DLLPUBLIC OCommentUndoAction : public SdrUndoAction
172 	{
173 	protected:
174 		String					m_strComment; // undo, redo comment
175 		::dbaui::IController*	m_pController;
176 
177 	public:
178         TYPEINFO();
179 		OCommentUndoAction(	SdrModel& rMod
180 							,sal_uInt16 nCommentID);
181         virtual ~OCommentUndoAction();
182 
183 		virtual UniString	GetComment() const { return m_strComment; }
184 		virtual void		Undo();
185 		virtual void		Redo();
186 	};
187     //==================================================================
188 	// OUndoContainerAction
189 	//==================================================================
190 	class REPORTDESIGN_DLLPUBLIC OUndoContainerAction: public OCommentUndoAction
191 	{
192         OUndoContainerAction(OUndoContainerAction&);
193         void operator =(OUndoContainerAction&);
194     protected:
195 		::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
196 						m_xElement;     // object not owned by the action
197 		::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
198 						m_xOwnElement;	// object owned by the action
199         ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >
200                         m_xContainer;
201         ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
202                         m_xSection;
203 		Action			m_eAction;
204 
205 	public:
206 		OUndoContainerAction(SdrModel& rMod
207 							,Action _eAction
208 							,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > _xContainer
209                             ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& xElem
210                             ,sal_uInt16 _nCommentId);
211 		virtual ~OUndoContainerAction();
212 
213 		virtual void Undo();
214 		virtual void Redo();
215 
216 	protected:
217 		virtual void    implReInsert( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
218 		virtual void    implReRemove( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
219 	};
220 
221     //==================================================================
222 	// OUndoReportSectionAction
223 	//==================================================================
224 	class REPORTDESIGN_DLLPUBLIC OUndoReportSectionAction : public OUndoContainerAction
225 	{
226         OReportHelper								m_aReportHelper;
227 		::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
228 									,OReportHelper> m_pMemberFunction;
229 	public:
230 		OUndoReportSectionAction(SdrModel& rMod
231 							,Action _eAction
232 							,::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
233 							    ,OReportHelper> _pMemberFunction
234 							,const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportDefinition >& _xReport
235                             ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& xElem
236                             ,sal_uInt16 _nCommentId);
237 
238 	protected:
239 		virtual void    implReInsert( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
240 		virtual void    implReRemove( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
241 	};
242 
243     //==================================================================
244 	// OUndoGroupSectionAction
245 	//==================================================================
246 	class REPORTDESIGN_DLLPUBLIC OUndoGroupSectionAction : public OUndoContainerAction
247 	{
248         OGroupHelper								m_aGroupHelper;
249 		::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
250 									,OGroupHelper> m_pMemberFunction;
251 	public:
252 		OUndoGroupSectionAction(SdrModel& rMod
253 							,Action _eAction
254 							,::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
255 											,OGroupHelper> _pMemberFunction
256 							,const ::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup >& _xGroup
257                             ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& xElem
258                             ,sal_uInt16 _nCommentId);
259 
260 	protected:
261 		virtual void    implReInsert( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
262 		virtual void    implReRemove( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
263 	};
264 
265     ///==================================================================
266 	/// ORptUndoPropertyAction
267 	///==================================================================
268 	class REPORTDESIGN_DLLPUBLIC ORptUndoPropertyAction: public OCommentUndoAction
269 	{
270 		::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xObj;
271 		::rtl::OUString						m_aPropertyName;
272 		::com::sun::star::uno::Any			m_aNewValue;
273 		::com::sun::star::uno::Any			m_aOldValue;
274 
275         /** sets either the old value or the new value again at the property set.
276          *
277          * \param _bOld If set to <TRUE/> than the old value will be set otherwise the new value will be set.
278          */
279         void setProperty(sal_Bool _bOld);
280     protected:
281         virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> getObject();
282 
283 	public:
284 		ORptUndoPropertyAction(SdrModel& rMod, const ::com::sun::star::beans::PropertyChangeEvent& evt);
285 
286 		virtual void Undo();
287 		virtual void Redo();
288 
289 		virtual String			GetComment() const;
290 	};
291 
292     //==================================================================
293 	// OUndoPropertyReportSectionAction
294 	//==================================================================
295 	class REPORTDESIGN_DLLPUBLIC OUndoPropertyReportSectionAction : public ORptUndoPropertyAction
296 	{
297         OReportHelper								m_aReportHelper;
298 		::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
299 									,OReportHelper> m_pMemberFunction;
300     protected:
301         virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> getObject();
302 	public:
303 		OUndoPropertyReportSectionAction(SdrModel& rMod
304 							,const ::com::sun::star::beans::PropertyChangeEvent& evt
305 							,::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
306 							    ,OReportHelper> _pMemberFunction
307                             ,const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportDefinition >& _xReport
308 							);
309 	};
310 
311     //==================================================================
312 	// OUndoPropertyGroupSectionAction
313 	//==================================================================
314 	class REPORTDESIGN_DLLPUBLIC OUndoPropertyGroupSectionAction : public ORptUndoPropertyAction
315 	{
316         OGroupHelper								m_aGroupHelper;
317 		::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
318 									,OGroupHelper> m_pMemberFunction;
319     protected:
320         virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> getObject();
321 	public:
322 		OUndoPropertyGroupSectionAction(SdrModel& rMod
323 							,const ::com::sun::star::beans::PropertyChangeEvent& evt
324 							,::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
325 											,OGroupHelper> _pMemberFunction
326                             ,const ::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup >& _xGroup
327                             );
328 	};
329 
330 }
331 #endif //RPTUI_UNDOACTIONS_HXX
332 
333