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