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 INCLUDED_REPORTDESIGN_INC_UNDOACTIONS_HXX
20 #define INCLUDED_REPORTDESIGN_INC_UNDOACTIONS_HXX
21 
22 #include "dllapi.h"
23 
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
26 #include <com/sun/star/report/XReportDefinition.hpp>
27 #include <com/sun/star/report/XGroup.hpp>
28 
29 #include <svx/svdundo.hxx>
30 
31 #include <functional>
32 
33 namespace dbaui
34 {
35     class IController;
36 }
37 namespace rptui
38 {
39     enum Action
40     {
41         Inserted = 1,
42         Removed  = 2
43     };
44 
45     /** Helper class to allow std::mem_fun for SAL_CALL
46     */
47     class OGroupHelper
48     {
49         css::uno::Reference< css::report::XGroup > m_xGroup;
50         OGroupHelper(const OGroupHelper&) = delete;
51         OGroupHelper& operator=(const OGroupHelper&) = delete;
52     public:
OGroupHelper(const css::uno::Reference<css::report::XGroup> & _xGroup)53         OGroupHelper(const css::uno::Reference< css::report::XGroup >& _xGroup)
54             :m_xGroup(_xGroup)
55         {
56         }
getHeader()57         css::uno::Reference< css::report::XSection >   getHeader() { return m_xGroup->getHeader(); }
getFooter()58         css::uno::Reference< css::report::XSection >   getFooter() { return m_xGroup->getFooter(); }
getGroup() const59         const css::uno::Reference< css::report::XGroup >&     getGroup() const { return m_xGroup; }
60 
getHeaderOn()61         bool getHeaderOn() { return m_xGroup->getHeaderOn(); }
getFooterOn()62         bool getFooterOn() { return m_xGroup->getFooterOn(); }
63 
64         static ::std::function<css::uno::Reference< css::report::XSection>(OGroupHelper *)> getMemberFunction(const css::uno::Reference< css::report::XSection >& _xSection);
65 
66     };
67 
68     /** Helper class to allow std::mem_fun for SAL_CALL
69     */
70     class OReportHelper
71     {
72         css::uno::Reference< css::report::XReportDefinition > m_xReport;
73     public:
OReportHelper(const css::uno::Reference<css::report::XReportDefinition> & _xReport)74         OReportHelper(const css::uno::Reference< css::report::XReportDefinition >& _xReport)
75             :m_xReport(_xReport)
76         {
77         }
getReportHeader()78         css::uno::Reference< css::report::XSection > getReportHeader() { return m_xReport->getReportHeader(); }
getReportFooter()79         css::uno::Reference< css::report::XSection > getReportFooter() { return m_xReport->getReportFooter(); }
getPageHeader()80         css::uno::Reference< css::report::XSection > getPageHeader()   { return m_xReport->getPageHeader(); }
getPageFooter()81         css::uno::Reference< css::report::XSection > getPageFooter()   { return m_xReport->getPageFooter(); }
getDetail()82         css::uno::Reference< css::report::XSection > getDetail()       { return m_xReport->getDetail(); }
83 
getReportHeaderOn()84         bool getReportHeaderOn() { return m_xReport->getReportHeaderOn(); }
getReportFooterOn()85         bool getReportFooterOn() { return m_xReport->getReportFooterOn(); }
getPageHeaderOn()86         bool getPageHeaderOn() { return m_xReport->getPageHeaderOn(); }
getPageFooterOn()87         bool getPageFooterOn() { return m_xReport->getPageFooterOn(); }
88 
89         static ::std::function<css::uno::Reference< css::report::XSection>(OReportHelper *)> getMemberFunction(const css::uno::Reference< css::report::XSection >& _xSection);
90     };
91 
92 
93     //= UndoContext
94 
95     class UndoContext
96     {
97     public:
UndoContext(SfxUndoManager & i_undoManager,const OUString & i_undoTitle)98         UndoContext( SfxUndoManager& i_undoManager, const OUString& i_undoTitle )
99             :m_rUndoManager( i_undoManager )
100         {
101             m_rUndoManager.EnterListAction( i_undoTitle, OUString(), 0, ViewShellId(-1) );
102         }
103 
~UndoContext()104         ~UndoContext()
105         {
106             m_rUndoManager.LeaveListAction();
107         }
108 
109     private:
110         SfxUndoManager& m_rUndoManager;
111     };
112 
113 
114     //= UndoSuppressor
115 
116     class UndoSuppressor
117     {
118     public:
UndoSuppressor(SfxUndoManager & i_undoManager)119         UndoSuppressor( SfxUndoManager& i_undoManager )
120             :m_rUndoManager( i_undoManager )
121         {
122             m_rUndoManager.EnableUndo( false );
123         }
124 
~UndoSuppressor()125         ~UndoSuppressor()
126         {
127             m_rUndoManager.EnableUndo( true );
128         }
129 
130     private:
131         SfxUndoManager& m_rUndoManager;
132     };
133 
134 
135     //= OCommentUndoAction
136 
137     class REPORTDESIGN_DLLPUBLIC OCommentUndoAction : public SdrUndoAction
138     {
139     protected:
140         OUString                m_strComment; // undo, redo comment
141         ::dbaui::IController*   m_pController;
142 
143     public:
144         OCommentUndoAction(SdrModel& rMod, const char* pCommentID);
145         virtual ~OCommentUndoAction() override;
146 
GetComment() const147         virtual OUString GetComment() const override { return m_strComment; }
148         virtual void        Undo() override;
149         virtual void        Redo() override;
150     };
151 
152     // OUndoContainerAction
153 
154     class OUndoContainerAction: public OCommentUndoAction
155     {
156         OUndoContainerAction(OUndoContainerAction const &) = delete;
157         void operator =(OUndoContainerAction const &) = delete;
158     protected:
159         css::uno::Reference< css::uno::XInterface >
160                         m_xElement;     // object not owned by the action
161         css::uno::Reference< css::uno::XInterface >
162                         m_xOwnElement;  // object owned by the action
163         css::uno::Reference< css::container::XIndexContainer >
164                         m_xContainer;
165         Action          m_eAction;
166 
167     public:
168         OUndoContainerAction(SdrModel& rMod
169                             ,Action _eAction
170                             ,const css::uno::Reference< css::container::XIndexContainer >& rContainer
171                             ,const css::uno::Reference< css::uno::XInterface>& xElem
172                             ,const char* pCommentId);
173         virtual ~OUndoContainerAction() override;
174 
175         virtual void Undo() override;
176         virtual void Redo() override;
177 
178     protected:
179         virtual void    implReInsert( );
180         virtual void    implReRemove( );
181     };
182 
183 
184     // OUndoReportSectionAction
185 
186     class OUndoReportSectionAction final : public OUndoContainerAction
187     {
188         OReportHelper                               m_aReportHelper;
189         ::std::function<css::uno::Reference< css::report::XSection >(OReportHelper *)> m_pMemberFunction;
190     public:
191         OUndoReportSectionAction(SdrModel& rMod
192                             ,Action _eAction
193                             ,::std::function<css::uno::Reference< css::report::XSection >(OReportHelper *)> _pMemberFunction
194                             ,const css::uno::Reference< css::report::XReportDefinition >& _xReport
195                             ,const css::uno::Reference< css::uno::XInterface>& xElem
196                             ,const char* pCommentId);
197 
198     private:
199         virtual void    implReInsert( ) override;
200         virtual void    implReRemove( ) override;
201     };
202 
203 
204     // OUndoGroupSectionAction
205     class OUndoGroupSectionAction final : public OUndoContainerAction
206     {
207         OGroupHelper                                m_aGroupHelper;
208         ::std::function<css::uno::Reference< css::report::XSection >(OGroupHelper *)> m_pMemberFunction;
209     public:
210         OUndoGroupSectionAction(SdrModel& rMod
211                             ,Action _eAction
212                             ,::std::function<css::uno::Reference< css::report::XSection >(OGroupHelper *)> _pMemberFunction
213                             ,const css::uno::Reference< css::report::XGroup >& _xGroup
214                             ,const css::uno::Reference< css::uno::XInterface>& xElem
215                             ,const char* pCommentId);
216 
217     private:
218         virtual void    implReInsert( ) override;
219         virtual void    implReRemove( ) override;
220     };
221 
222     // ORptUndoPropertyAction
223     class ORptUndoPropertyAction: public OCommentUndoAction
224     {
225         css::uno::Reference< css::beans::XPropertySet> m_xObj;
226         OUString               m_aPropertyName;
227         css::uno::Any          m_aNewValue;
228         css::uno::Any          m_aOldValue;
229 
230         /** sets either the old value or the new value again at the property set.
231          *
232          * \param _bOld If set to <TRUE/> than the old value will be set otherwise the new value will be set.
233          */
234         void setProperty(bool _bOld);
235     protected:
236         virtual css::uno::Reference< css::beans::XPropertySet> getObject();
237 
238     public:
239         ORptUndoPropertyAction(SdrModel& rMod, const css::beans::PropertyChangeEvent& evt);
240 
241         virtual void Undo() override;
242         virtual void Redo() override;
243 
244         virtual OUString GetComment() const override;
245     };
246 
247 
248     // OUndoPropertyReportSectionAction
249 
250     class OUndoPropertyReportSectionAction final : public ORptUndoPropertyAction
251     {
252         OReportHelper                               m_aReportHelper;
253         ::std::function<css::uno::Reference< css::report::XSection >(OReportHelper *)> m_pMemberFunction;
254 
255         virtual css::uno::Reference< css::beans::XPropertySet> getObject() override;
256     public:
257         OUndoPropertyReportSectionAction(SdrModel& rMod
258                             ,const css::beans::PropertyChangeEvent& evt
259                             ,::std::function<css::uno::Reference< css::report::XSection >(OReportHelper *)> _pMemberFunction
260                             ,const css::uno::Reference< css::report::XReportDefinition >& _xReport
261                             );
262     };
263 
264 
265     // OUndoPropertyGroupSectionAction
266 
267     class OUndoPropertyGroupSectionAction final : public ORptUndoPropertyAction
268     {
269         OGroupHelper                                m_aGroupHelper;
270         ::std::function<css::uno::Reference< css::report::XSection >(OGroupHelper *)> m_pMemberFunction;
271 
272         virtual css::uno::Reference< css::beans::XPropertySet> getObject() override;
273     public:
274         OUndoPropertyGroupSectionAction(SdrModel& rMod
275                             ,const css::beans::PropertyChangeEvent& evt
276                             ,::std::function<css::uno::Reference< css::report::XSection >(OGroupHelper *)> _pMemberFunction
277                             ,const css::uno::Reference< css::report::XGroup >& _xGroup
278                             );
279     };
280 
281 }
282 #endif // INCLUDED_REPORTDESIGN_INC_UNDOACTIONS_HXX
283 
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
285