Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef RPTUI_UNDOACTIONS_HXX
20 : #define RPTUI_UNDOACTIONS_HXX
21 :
22 : #include "dllapi.h"
23 :
24 : #include "RptModel.hxx"
25 :
26 : #include <com/sun/star/util/XModifyListener.hpp>
27 : #include <com/sun/star/beans/XPropertySet.hpp>
28 : #include <com/sun/star/beans/PropertyChangeEvent.hpp>
29 : #include <com/sun/star/script/ScriptEvent.hpp>
30 : #include <com/sun/star/script/XScriptListener.hpp>
31 : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
32 : #include <com/sun/star/container/XNameContainer.hpp>
33 : #include <com/sun/star/container/ContainerEvent.hpp>
34 : #include <com/sun/star/container/XNameContainer.hpp>
35 : #include <com/sun/star/report/XReportComponent.hpp>
36 : #include <com/sun/star/report/XReportDefinition.hpp>
37 : #include <com/sun/star/report/XGroup.hpp>
38 : #include <com/sun/star/document/XUndoManager.hpp>
39 :
40 : #include <cppuhelper/implbase3.hxx>
41 : #include <comphelper/uno3.hxx>
42 : #include <comphelper/sequence.hxx>
43 : #include <svl/lstner.hxx>
44 : #include <svx/svdouno.hxx>
45 : #include <svx/svdundo.hxx>
46 : #include <tools/string.hxx>
47 :
48 : #include <functional>
49 : #include <memory>
50 :
51 : namespace dbaui
52 : {
53 : class IController;
54 : }
55 : namespace rptui
56 : {
57 : enum Action
58 : {
59 : Inserted = 1,
60 : Removed = 2
61 : };
62 :
63 : /** Helper class to allow std::mem_fun for SAL_CALL
64 : */
65 0 : class REPORTDESIGN_DLLPUBLIC OGroupHelper
66 : {
67 : ::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup > m_xGroup;
68 : OGroupHelper(const OGroupHelper&);
69 : OGroupHelper& operator=(const OGroupHelper&);
70 : public:
71 0 : OGroupHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup >& _xGroup)
72 0 : :m_xGroup(_xGroup)
73 : {
74 0 : }
75 0 : inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getHeader() { return m_xGroup->getHeader(); }
76 0 : inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getFooter() { return m_xGroup->getFooter(); }
77 0 : inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup > getGroup() { return m_xGroup; }
78 :
79 0 : inline ::sal_Bool getHeaderOn() { return m_xGroup->getHeaderOn(); }
80 0 : inline ::sal_Bool getFooterOn() { return m_xGroup->getFooterOn(); }
81 :
82 : 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);
83 :
84 : };
85 : typedef com::sun::star::uno::Reference< ::com::sun::star::report::XSection > TSection;
86 :
87 : /** Helper class to allow std::mem_fun for SAL_CALL
88 : */
89 0 : class REPORTDESIGN_DLLPUBLIC OReportHelper
90 : {
91 : ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportDefinition > m_xReport;
92 : public:
93 0 : OReportHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportDefinition >& _xReport)
94 0 : :m_xReport(_xReport)
95 : {
96 0 : }
97 0 : inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getReportHeader() { return m_xReport->getReportHeader(); }
98 0 : inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getReportFooter() { return m_xReport->getReportFooter(); }
99 0 : inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getPageHeader() { return m_xReport->getPageHeader(); }
100 0 : inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getPageFooter() { return m_xReport->getPageFooter(); }
101 0 : inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getDetail() { return m_xReport->getDetail(); }
102 :
103 0 : inline ::sal_Bool getReportHeaderOn() { return m_xReport->getReportHeaderOn(); }
104 0 : inline ::sal_Bool getReportFooterOn() { return m_xReport->getReportFooterOn(); }
105 0 : inline ::sal_Bool getPageHeaderOn() { return m_xReport->getPageHeaderOn(); }
106 0 : inline ::sal_Bool getPageFooterOn() { return m_xReport->getPageFooterOn(); }
107 :
108 : 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);
109 : };
110 :
111 : //==================================================================================================================
112 : //= UndoContext
113 : //==================================================================================================================
114 : class UndoContext
115 : {
116 : public:
117 0 : UndoContext( SfxUndoManager& i_undoManager, const ::rtl::OUString& i_undoTitle )
118 0 : :m_rUndoManager( i_undoManager )
119 : {
120 0 : m_rUndoManager.EnterListAction( i_undoTitle, String() );
121 0 : }
122 :
123 0 : ~UndoContext()
124 : {
125 0 : m_rUndoManager.LeaveListAction();
126 0 : }
127 :
128 : private:
129 : SfxUndoManager& m_rUndoManager;
130 : };
131 :
132 : //==================================================================================================================
133 : //= UndoSuppressor
134 : //==================================================================================================================
135 : class UndoSuppressor
136 : {
137 : public:
138 0 : UndoSuppressor( SfxUndoManager& i_undoManager )
139 0 : :m_rUndoManager( i_undoManager )
140 : {
141 0 : m_rUndoManager.EnableUndo( false );
142 0 : }
143 :
144 0 : ~UndoSuppressor()
145 : {
146 0 : m_rUndoManager.EnableUndo( true );
147 0 : }
148 :
149 : private:
150 : SfxUndoManager& m_rUndoManager;
151 : };
152 :
153 : //==================================================================================================================
154 : //= OCommentUndoAction
155 : //==================================================================================================================
156 : class REPORTDESIGN_DLLPUBLIC OCommentUndoAction : public SdrUndoAction
157 : {
158 : protected:
159 : String m_strComment; // undo, redo comment
160 : ::dbaui::IController* m_pController;
161 :
162 : public:
163 : TYPEINFO();
164 : OCommentUndoAction( SdrModel& rMod
165 : ,sal_uInt16 nCommentID);
166 : virtual ~OCommentUndoAction();
167 :
168 0 : virtual rtl::OUString GetComment() const { return m_strComment; }
169 : virtual void Undo();
170 : virtual void Redo();
171 : };
172 : //==================================================================
173 : // OUndoContainerAction
174 : //==================================================================
175 : class REPORTDESIGN_DLLPUBLIC OUndoContainerAction: public OCommentUndoAction
176 : {
177 : OUndoContainerAction(OUndoContainerAction&);
178 : void operator =(OUndoContainerAction&);
179 : protected:
180 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
181 : m_xElement; // object not owned by the action
182 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
183 : m_xOwnElement; // object owned by the action
184 : ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >
185 : m_xContainer;
186 : ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
187 : m_xSection;
188 : Action m_eAction;
189 :
190 : public:
191 : OUndoContainerAction(SdrModel& rMod
192 : ,Action _eAction
193 : ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > _xContainer
194 : ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& xElem
195 : ,sal_uInt16 _nCommentId);
196 : virtual ~OUndoContainerAction();
197 :
198 : virtual void Undo();
199 : virtual void Redo();
200 :
201 : protected:
202 : virtual void implReInsert( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
203 : virtual void implReRemove( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
204 : };
205 :
206 : //==================================================================
207 : // OUndoReportSectionAction
208 : //==================================================================
209 0 : class REPORTDESIGN_DLLPUBLIC OUndoReportSectionAction : public OUndoContainerAction
210 : {
211 : OReportHelper m_aReportHelper;
212 : ::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
213 : ,OReportHelper> m_pMemberFunction;
214 : public:
215 : OUndoReportSectionAction(SdrModel& rMod
216 : ,Action _eAction
217 : ,::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
218 : ,OReportHelper> _pMemberFunction
219 : ,const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportDefinition >& _xReport
220 : ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& xElem
221 : ,sal_uInt16 _nCommentId);
222 :
223 : protected:
224 : virtual void implReInsert( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
225 : virtual void implReRemove( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
226 : };
227 :
228 : //==================================================================
229 : // OUndoGroupSectionAction
230 : //==================================================================
231 0 : class REPORTDESIGN_DLLPUBLIC OUndoGroupSectionAction : public OUndoContainerAction
232 : {
233 : OGroupHelper m_aGroupHelper;
234 : ::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
235 : ,OGroupHelper> m_pMemberFunction;
236 : public:
237 : OUndoGroupSectionAction(SdrModel& rMod
238 : ,Action _eAction
239 : ,::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
240 : ,OGroupHelper> _pMemberFunction
241 : ,const ::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup >& _xGroup
242 : ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& xElem
243 : ,sal_uInt16 _nCommentId);
244 :
245 : protected:
246 : virtual void implReInsert( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
247 : virtual void implReRemove( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) );
248 : };
249 :
250 : ///==================================================================
251 : /// ORptUndoPropertyAction
252 : ///==================================================================
253 0 : class REPORTDESIGN_DLLPUBLIC ORptUndoPropertyAction: public OCommentUndoAction
254 : {
255 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xObj;
256 : ::rtl::OUString m_aPropertyName;
257 : ::com::sun::star::uno::Any m_aNewValue;
258 : ::com::sun::star::uno::Any m_aOldValue;
259 :
260 : /** sets either the old value or the new value again at the property set.
261 : *
262 : * \param _bOld If set to <TRUE/> than the old value will be set otherwise the new value will be set.
263 : */
264 : void setProperty(sal_Bool _bOld);
265 : protected:
266 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> getObject();
267 :
268 : public:
269 : ORptUndoPropertyAction(SdrModel& rMod, const ::com::sun::star::beans::PropertyChangeEvent& evt);
270 :
271 : virtual void Undo();
272 : virtual void Redo();
273 :
274 : virtual rtl::OUString GetComment() const;
275 : };
276 :
277 : //==================================================================
278 : // OUndoPropertyReportSectionAction
279 : //==================================================================
280 0 : class REPORTDESIGN_DLLPUBLIC OUndoPropertyReportSectionAction : public ORptUndoPropertyAction
281 : {
282 : OReportHelper m_aReportHelper;
283 : ::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
284 : ,OReportHelper> m_pMemberFunction;
285 : protected:
286 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> getObject();
287 : public:
288 : OUndoPropertyReportSectionAction(SdrModel& rMod
289 : ,const ::com::sun::star::beans::PropertyChangeEvent& evt
290 : ,::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
291 : ,OReportHelper> _pMemberFunction
292 : ,const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportDefinition >& _xReport
293 : );
294 : };
295 :
296 : //==================================================================
297 : // OUndoPropertyGroupSectionAction
298 : //==================================================================
299 0 : class REPORTDESIGN_DLLPUBLIC OUndoPropertyGroupSectionAction : public ORptUndoPropertyAction
300 : {
301 : OGroupHelper m_aGroupHelper;
302 : ::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
303 : ,OGroupHelper> m_pMemberFunction;
304 : protected:
305 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> getObject();
306 : public:
307 : OUndoPropertyGroupSectionAction(SdrModel& rMod
308 : ,const ::com::sun::star::beans::PropertyChangeEvent& evt
309 : ,::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >
310 : ,OGroupHelper> _pMemberFunction
311 : ,const ::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup >& _xGroup
312 : );
313 : };
314 :
315 : }
316 : #endif //RPTUI_UNDOACTIONS_HXX
317 :
318 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|