tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / reportdesign / inc / UndoActions.hxx
blob3ce12eabaf3d61756dbb0ccf4a6be5d8274e5d67
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 <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>
29 #include <svx/svdundo.hxx>
31 #include <functional>
32 #include <utility>
34 namespace dbaui
36 class IController;
38 namespace rptui
40 enum Action
42 Inserted = 1,
43 Removed = 2
46 /** Helper class to allow std::mem_fun for SAL_CALL
48 class OGroupHelper
50 css::uno::Reference< css::report::XGroup > m_xGroup;
51 OGroupHelper(const OGroupHelper&) = delete;
52 OGroupHelper& operator=(const OGroupHelper&) = delete;
53 public:
54 OGroupHelper(css::uno::Reference< css::report::XGroup > _xGroup)
55 :m_xGroup(std::move(_xGroup))
58 css::uno::Reference< css::report::XSection > getHeader() { return m_xGroup->getHeader(); }
59 css::uno::Reference< css::report::XSection > getFooter() { return m_xGroup->getFooter(); }
60 const css::uno::Reference< css::report::XGroup >& getGroup() const { return m_xGroup; }
62 bool getHeaderOn() { return m_xGroup->getHeaderOn(); }
63 bool getFooterOn() { return m_xGroup->getFooterOn(); }
65 static ::std::function<css::uno::Reference< css::report::XSection>(OGroupHelper *)> getMemberFunction(const css::uno::Reference< css::report::XSection >& _xSection);
69 /** Helper class to allow std::mem_fun for SAL_CALL
71 class OReportHelper
73 css::uno::Reference< css::report::XReportDefinition > m_xReport;
74 public:
75 OReportHelper(css::uno::Reference< css::report::XReportDefinition > _xReport)
76 :m_xReport(std::move(_xReport))
79 css::uno::Reference< css::report::XSection > getReportHeader() { return m_xReport->getReportHeader(); }
80 css::uno::Reference< css::report::XSection > getReportFooter() { return m_xReport->getReportFooter(); }
81 css::uno::Reference< css::report::XSection > getPageHeader() { return m_xReport->getPageHeader(); }
82 css::uno::Reference< css::report::XSection > getPageFooter() { return m_xReport->getPageFooter(); }
83 css::uno::Reference< css::report::XSection > getDetail() { return m_xReport->getDetail(); }
85 bool getReportHeaderOn() { return m_xReport->getReportHeaderOn(); }
86 bool getReportFooterOn() { return m_xReport->getReportFooterOn(); }
87 bool getPageHeaderOn() { return m_xReport->getPageHeaderOn(); }
88 bool getPageFooterOn() { return m_xReport->getPageFooterOn(); }
90 static ::std::function<css::uno::Reference< css::report::XSection>(OReportHelper *)> getMemberFunction(const css::uno::Reference< css::report::XSection >& _xSection);
94 //= UndoContext
96 class UndoContext
98 public:
99 UndoContext( SfxUndoManager& i_undoManager, const OUString& i_undoTitle )
100 :m_rUndoManager( i_undoManager )
102 m_rUndoManager.EnterListAction( i_undoTitle, OUString(), 0, ViewShellId(-1) );
105 ~UndoContext()
107 m_rUndoManager.LeaveListAction();
110 private:
111 SfxUndoManager& m_rUndoManager;
115 //= UndoSuppressor
117 class UndoSuppressor
119 public:
120 UndoSuppressor( SfxUndoManager& i_undoManager )
121 :m_rUndoManager( i_undoManager )
123 m_rUndoManager.EnableUndo( false );
126 ~UndoSuppressor()
128 m_rUndoManager.EnableUndo( true );
131 private:
132 SfxUndoManager& m_rUndoManager;
136 //= OCommentUndoAction
138 class UNLESS_MERGELIBS_MORE(REPORTDESIGN_DLLPUBLIC) OCommentUndoAction : public SdrUndoAction
140 protected:
141 OUString m_strComment; // undo, redo comment
142 ::dbaui::IController* m_pController;
144 public:
145 OCommentUndoAction(SdrModel& rMod, TranslateId pCommentID);
146 virtual ~OCommentUndoAction() override;
148 virtual OUString GetComment() const override { return m_strComment; }
149 virtual void Undo() override;
150 virtual void Redo() override;
153 // OUndoContainerAction
155 class OUndoContainerAction: public OCommentUndoAction
157 OUndoContainerAction(OUndoContainerAction const &) = delete;
158 void operator =(OUndoContainerAction const &) = delete;
159 protected:
160 css::uno::Reference< css::uno::XInterface >
161 m_xElement; // object not owned by the action
162 css::uno::Reference< css::uno::XInterface >
163 m_xOwnElement; // object owned by the action
164 css::uno::Reference< css::container::XIndexContainer >
165 m_xContainer;
166 Action m_eAction;
168 public:
169 OUndoContainerAction(SdrModel& rMod
170 ,Action _eAction
171 ,css::uno::Reference< css::container::XIndexContainer > xContainer
172 ,const css::uno::Reference< css::uno::XInterface>& xElem
173 ,TranslateId pCommentId);
174 virtual ~OUndoContainerAction() override;
176 virtual void Undo() override;
177 virtual void Redo() override;
179 protected:
180 virtual void implReInsert( );
181 virtual void implReRemove( );
185 // OUndoReportSectionAction
187 class OUndoReportSectionAction final : public OUndoContainerAction
189 OReportHelper m_aReportHelper;
190 ::std::function<css::uno::Reference< css::report::XSection >(OReportHelper *)> m_pMemberFunction;
191 public:
192 OUndoReportSectionAction(SdrModel& rMod
193 ,Action _eAction
194 ,::std::function<css::uno::Reference< css::report::XSection >(OReportHelper *)> _pMemberFunction
195 ,const css::uno::Reference< css::report::XReportDefinition >& _xReport
196 ,const css::uno::Reference< css::uno::XInterface>& xElem
197 ,TranslateId pCommentId);
199 private:
200 virtual void implReInsert( ) override;
201 virtual void implReRemove( ) override;
205 // OUndoGroupSectionAction
206 class OUndoGroupSectionAction final : public OUndoContainerAction
208 OGroupHelper m_aGroupHelper;
209 ::std::function<css::uno::Reference< css::report::XSection >(OGroupHelper *)> m_pMemberFunction;
210 public:
211 OUndoGroupSectionAction(SdrModel& rMod
212 ,Action _eAction
213 ,::std::function<css::uno::Reference< css::report::XSection >(OGroupHelper *)> _pMemberFunction
214 ,const css::uno::Reference< css::report::XGroup >& _xGroup
215 ,const css::uno::Reference< css::uno::XInterface>& xElem
216 ,TranslateId pCommentId);
218 private:
219 virtual void implReInsert( ) override;
220 virtual void implReRemove( ) override;
223 // ORptUndoPropertyAction
224 class ORptUndoPropertyAction: public OCommentUndoAction
226 css::uno::Reference< css::beans::XPropertySet> m_xObj;
227 OUString m_aPropertyName;
228 css::uno::Any m_aNewValue;
229 css::uno::Any m_aOldValue;
231 /** sets either the old value or the new value again at the property set.
233 * \param _bOld If set to <TRUE/> than the old value will be set otherwise the new value will be set.
235 void setProperty(bool _bOld);
236 protected:
237 virtual css::uno::Reference< css::beans::XPropertySet> getObject();
239 public:
240 ORptUndoPropertyAction(SdrModel& rMod, const css::beans::PropertyChangeEvent& evt);
242 virtual void Undo() override;
243 virtual void Redo() override;
245 virtual OUString GetComment() const override;
249 // OUndoPropertyReportSectionAction
251 class OUndoPropertyReportSectionAction final : public ORptUndoPropertyAction
253 OReportHelper m_aReportHelper;
254 ::std::function<css::uno::Reference< css::report::XSection >(OReportHelper *)> m_pMemberFunction;
256 virtual css::uno::Reference< css::beans::XPropertySet> getObject() override;
257 public:
258 OUndoPropertyReportSectionAction(SdrModel& rMod
259 ,const css::beans::PropertyChangeEvent& evt
260 ,::std::function<css::uno::Reference< css::report::XSection >(OReportHelper *)> _pMemberFunction
261 ,const css::uno::Reference< css::report::XReportDefinition >& _xReport
266 // OUndoPropertyGroupSectionAction
268 class OUndoPropertyGroupSectionAction final : public ORptUndoPropertyAction
270 OGroupHelper m_aGroupHelper;
271 ::std::function<css::uno::Reference< css::report::XSection >(OGroupHelper *)> m_pMemberFunction;
273 virtual css::uno::Reference< css::beans::XPropertySet> getObject() override;
274 public:
275 OUndoPropertyGroupSectionAction(SdrModel& rMod
276 ,const css::beans::PropertyChangeEvent& evt
277 ,::std::function<css::uno::Reference< css::report::XSection >(OGroupHelper *)> _pMemberFunction
278 ,const css::uno::Reference< css::report::XGroup >& _xGroup
283 #endif // INCLUDED_REPORTDESIGN_INC_UNDOACTIONS_HXX
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */