Bump version to 6.0-36
[LibreOffice.git] / reportdesign / inc / UndoActions.hxx
blob7df624f2841864e7fcf703af7e7fb6c2b139965b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_REPORTDESIGN_INC_UNDOACTIONS_HXX
20 #define INCLUDED_REPORTDESIGN_INC_UNDOACTIONS_HXX
22 #include "dllapi.h"
24 #include "RptModel.hxx"
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/container/XNameContainer.hpp>
30 #include <com/sun/star/container/ContainerEvent.hpp>
31 #include <com/sun/star/report/XReportDefinition.hpp>
32 #include <com/sun/star/report/XGroup.hpp>
33 #include <com/sun/star/document/XUndoManager.hpp>
35 #include <comphelper/uno3.hxx>
36 #include <comphelper/sequence.hxx>
37 #include <svl/lstner.hxx>
38 #include <svx/svdouno.hxx>
39 #include <svx/svdundo.hxx>
41 #include <functional>
43 namespace dbaui
45 class IController;
47 namespace rptui
49 enum Action
51 Inserted = 1,
52 Removed = 2
55 /** Helper class to allow std::mem_fun for SAL_CALL
57 class REPORTDESIGN_DLLPUBLIC OGroupHelper
59 css::uno::Reference< css::report::XGroup > m_xGroup;
60 OGroupHelper(const OGroupHelper&) = delete;
61 OGroupHelper& operator=(const OGroupHelper&) = delete;
62 public:
63 OGroupHelper(const css::uno::Reference< css::report::XGroup >& _xGroup)
64 :m_xGroup(_xGroup)
67 css::uno::Reference< css::report::XSection > getHeader() { return m_xGroup->getHeader(); }
68 css::uno::Reference< css::report::XSection > getFooter() { return m_xGroup->getFooter(); }
69 const css::uno::Reference< css::report::XGroup >& getGroup() { return m_xGroup; }
71 bool getHeaderOn() { return m_xGroup->getHeaderOn(); }
72 bool getFooterOn() { return m_xGroup->getFooterOn(); }
74 static ::std::mem_fun_t< css::uno::Reference< css::report::XSection> , OGroupHelper> getMemberFunction(const css::uno::Reference< css::report::XSection >& _xSection);
78 /** Helper class to allow std::mem_fun for SAL_CALL
80 class REPORTDESIGN_DLLPUBLIC OReportHelper
82 css::uno::Reference< css::report::XReportDefinition > m_xReport;
83 public:
84 OReportHelper(const css::uno::Reference< css::report::XReportDefinition >& _xReport)
85 :m_xReport(_xReport)
88 css::uno::Reference< css::report::XSection > getReportHeader() { return m_xReport->getReportHeader(); }
89 css::uno::Reference< css::report::XSection > getReportFooter() { return m_xReport->getReportFooter(); }
90 css::uno::Reference< css::report::XSection > getPageHeader() { return m_xReport->getPageHeader(); }
91 css::uno::Reference< css::report::XSection > getPageFooter() { return m_xReport->getPageFooter(); }
92 css::uno::Reference< css::report::XSection > getDetail() { return m_xReport->getDetail(); }
94 bool getReportHeaderOn() { return m_xReport->getReportHeaderOn(); }
95 bool getReportFooterOn() { return m_xReport->getReportFooterOn(); }
96 bool getPageHeaderOn() { return m_xReport->getPageHeaderOn(); }
97 bool getPageFooterOn() { return m_xReport->getPageFooterOn(); }
99 static ::std::mem_fun_t< css::uno::Reference< css::report::XSection> , OReportHelper> getMemberFunction(const css::uno::Reference< css::report::XSection >& _xSection);
103 //= UndoContext
105 class UndoContext
107 public:
108 UndoContext( SfxUndoManager& i_undoManager, const OUString& i_undoTitle )
109 :m_rUndoManager( i_undoManager )
111 m_rUndoManager.EnterListAction( i_undoTitle, OUString(), 0, ViewShellId(-1) );
114 ~UndoContext()
116 m_rUndoManager.LeaveListAction();
119 private:
120 SfxUndoManager& m_rUndoManager;
124 //= UndoSuppressor
126 class UndoSuppressor
128 public:
129 UndoSuppressor( SfxUndoManager& i_undoManager )
130 :m_rUndoManager( i_undoManager )
132 m_rUndoManager.EnableUndo( false );
135 ~UndoSuppressor()
137 m_rUndoManager.EnableUndo( true );
140 private:
141 SfxUndoManager& m_rUndoManager;
145 //= OCommentUndoAction
147 class REPORTDESIGN_DLLPUBLIC OCommentUndoAction : public SdrUndoAction
149 protected:
150 OUString m_strComment; // undo, redo comment
151 ::dbaui::IController* m_pController;
153 public:
154 OCommentUndoAction(SdrModel& rMod, const char* pCommentID);
155 virtual ~OCommentUndoAction() override;
157 virtual OUString GetComment() const override { return m_strComment; }
158 virtual void Undo() override;
159 virtual void Redo() override;
162 // OUndoContainerAction
164 class REPORTDESIGN_DLLPUBLIC OUndoContainerAction: public OCommentUndoAction
166 OUndoContainerAction(OUndoContainerAction&) = delete;
167 void operator =(OUndoContainerAction&) = delete;
168 protected:
169 css::uno::Reference< css::uno::XInterface >
170 m_xElement; // object not owned by the action
171 css::uno::Reference< css::uno::XInterface >
172 m_xOwnElement; // object owned by the action
173 css::uno::Reference< css::container::XIndexContainer >
174 m_xContainer;
175 Action m_eAction;
177 public:
178 OUndoContainerAction(SdrModel& rMod
179 ,Action _eAction
180 ,const css::uno::Reference< css::container::XIndexContainer >& rContainer
181 ,const css::uno::Reference< css::uno::XInterface>& xElem
182 ,const char* pCommentId);
183 virtual ~OUndoContainerAction() override;
185 virtual void Undo() override;
186 virtual void Redo() override;
188 protected:
189 virtual void implReInsert( );
190 virtual void implReRemove( );
194 // OUndoReportSectionAction
196 class REPORTDESIGN_DLLPUBLIC OUndoReportSectionAction : public OUndoContainerAction
198 OReportHelper m_aReportHelper;
199 ::std::mem_fun_t< css::uno::Reference< css::report::XSection >
200 ,OReportHelper> m_pMemberFunction;
201 public:
202 OUndoReportSectionAction(SdrModel& rMod
203 ,Action _eAction
204 ,::std::mem_fun_t< css::uno::Reference< css::report::XSection >
205 ,OReportHelper> _pMemberFunction
206 ,const css::uno::Reference< css::report::XReportDefinition >& _xReport
207 ,const css::uno::Reference< css::uno::XInterface>& xElem
208 ,const char* pCommentId);
210 protected:
211 virtual void implReInsert( ) override;
212 virtual void implReRemove( ) override;
216 // OUndoGroupSectionAction
217 class REPORTDESIGN_DLLPUBLIC OUndoGroupSectionAction : public OUndoContainerAction
219 OGroupHelper m_aGroupHelper;
220 ::std::mem_fun_t< css::uno::Reference< css::report::XSection >
221 ,OGroupHelper> m_pMemberFunction;
222 public:
223 OUndoGroupSectionAction(SdrModel& rMod
224 ,Action _eAction
225 ,::std::mem_fun_t< css::uno::Reference< css::report::XSection >
226 ,OGroupHelper> _pMemberFunction
227 ,const css::uno::Reference< css::report::XGroup >& _xGroup
228 ,const css::uno::Reference< css::uno::XInterface>& xElem
229 ,const char* pCommentId);
231 protected:
232 virtual void implReInsert( ) override;
233 virtual void implReRemove( ) override;
236 // ORptUndoPropertyAction
237 class REPORTDESIGN_DLLPUBLIC ORptUndoPropertyAction: public OCommentUndoAction
239 css::uno::Reference< css::beans::XPropertySet> m_xObj;
240 OUString m_aPropertyName;
241 css::uno::Any m_aNewValue;
242 css::uno::Any m_aOldValue;
244 /** sets either the old value or the new value again at the property set.
246 * \param _bOld If set to <TRUE/> than the old value will be set otherwise the new value will be set.
248 void setProperty(bool _bOld);
249 protected:
250 virtual css::uno::Reference< css::beans::XPropertySet> getObject();
252 public:
253 ORptUndoPropertyAction(SdrModel& rMod, const css::beans::PropertyChangeEvent& evt);
255 virtual void Undo() override;
256 virtual void Redo() override;
258 virtual OUString GetComment() const override;
262 // OUndoPropertyReportSectionAction
264 class REPORTDESIGN_DLLPUBLIC OUndoPropertyReportSectionAction : public ORptUndoPropertyAction
266 OReportHelper m_aReportHelper;
267 ::std::mem_fun_t< css::uno::Reference< css::report::XSection >
268 ,OReportHelper> m_pMemberFunction;
269 protected:
270 virtual css::uno::Reference< css::beans::XPropertySet> getObject() override;
271 public:
272 OUndoPropertyReportSectionAction(SdrModel& rMod
273 ,const css::beans::PropertyChangeEvent& evt
274 ,::std::mem_fun_t< css::uno::Reference< css::report::XSection >
275 ,OReportHelper> _pMemberFunction
276 ,const css::uno::Reference< css::report::XReportDefinition >& _xReport
281 // OUndoPropertyGroupSectionAction
283 class REPORTDESIGN_DLLPUBLIC OUndoPropertyGroupSectionAction : public ORptUndoPropertyAction
285 OGroupHelper m_aGroupHelper;
286 ::std::mem_fun_t< css::uno::Reference< css::report::XSection >
287 ,OGroupHelper> m_pMemberFunction;
288 protected:
289 virtual css::uno::Reference< css::beans::XPropertySet> getObject() override;
290 public:
291 OUndoPropertyGroupSectionAction(SdrModel& rMod
292 ,const css::beans::PropertyChangeEvent& evt
293 ,::std::mem_fun_t< css::uno::Reference< css::report::XSection >
294 ,OGroupHelper> _pMemberFunction
295 ,const css::uno::Reference< css::report::XGroup >& _xGroup
300 #endif // INCLUDED_REPORTDESIGN_INC_UNDOACTIONS_HXX
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */