LibreOffice Module reportdesign (master) 1
UndoActions.cxx
Go to the documentation of this file.
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
20#include <UndoActions.hxx>
21#include <UndoEnv.hxx>
22#include <core_resource.hxx>
23#include <strings.hrc>
24#include <RptModel.hxx>
25
26#include <com/sun/star/container/XChild.hpp>
27
28#include <comphelper/types.hxx>
30#include <utility>
32#include <svx/unoshape.hxx>
33
34namespace rptui
35{
36 using namespace ::com::sun::star;
37 using namespace uno;
38 using namespace lang;
39 using namespace script;
40 using namespace beans;
41 using namespace awt;
42 using namespace util;
43 using namespace container;
44 using namespace report;
45
46::std::function<uno::Reference<report::XSection>(OGroupHelper *)> OGroupHelper::getMemberFunction(const Reference< XSection >& _xSection)
47{
48 ::std::function<uno::Reference<report::XSection>(OGroupHelper *)> pMemFunSection = ::std::mem_fn(&OGroupHelper::getFooter);
49 uno::Reference< report::XGroup> xGroup = _xSection->getGroup();
50 if ( xGroup->getHeaderOn() && xGroup->getHeader() == _xSection )
51 pMemFunSection = ::std::mem_fn(&OGroupHelper::getHeader);
52 return pMemFunSection;
53}
54
55::std::function<uno::Reference<report::XSection>(OReportHelper *)> OReportHelper::getMemberFunction(const Reference< XSection >& _xSection)
56{
57 uno::Reference< report::XReportDefinition> xReportDefinition(_xSection->getReportDefinition());
58 ::std::function<uno::Reference<report::XSection>(OReportHelper *)> pMemFunSection = ::std::mem_fn(&OReportHelper::getReportFooter);
59 if ( xReportDefinition->getReportHeaderOn() && xReportDefinition->getReportHeader() == _xSection )
60 pMemFunSection = ::std::mem_fn(&OReportHelper::getReportHeader);
61 else if ( xReportDefinition->getPageHeaderOn() && xReportDefinition->getPageHeader() == _xSection )
62 pMemFunSection = ::std::mem_fn(&OReportHelper::getPageHeader);
63 else if ( xReportDefinition->getPageFooterOn() && xReportDefinition->getPageFooter() == _xSection )
64 pMemFunSection = ::std::mem_fn(&OReportHelper::getPageFooter);
65 else if ( xReportDefinition->getDetail() == _xSection )
66 pMemFunSection = ::std::mem_fn(&OReportHelper::getDetail);
67 return pMemFunSection;
68}
69
70
72 :SdrUndoAction(_rMod)
73{
74 m_pController = static_cast< OReportModel& >( _rMod ).getController();
75 if (pCommentID)
76 m_strComment = RptResId(pCommentID);
77}
79{
80}
81
83{
84}
85
87{
88}
89
91 ,Action _eAction
92 ,uno::Reference< container::XIndexContainer > xContainer
93 ,const Reference< XInterface > & xElem
94 ,TranslateId pCommentId)
95 :OCommentUndoAction(_rMod, pCommentId)
96 ,m_xElement(xElem)
97 ,m_xContainer(std::move(xContainer))
98 ,m_eAction( _eAction )
99{
100 // normalize
101 if ( m_eAction == Removed )
102 // we now own the element
103 m_xOwnElement = m_xElement;
104}
105
107{
108 // if we own the object...
109 Reference< XComponent > xComp( m_xOwnElement, UNO_QUERY );
110 if ( !xComp.is() )
111 return;
112
113 // and the object does not have a parent
114 Reference< XChild > xChild( m_xOwnElement, UNO_QUERY );
115 if ( !xChild.is() || xChild->getParent().is() )
116 return;
117
118 OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
120
121 // -> dispose it
122 try
123 {
125 }
126 catch ( const uno::Exception& )
127 {
128 DBG_UNHANDLED_EXCEPTION("reportdesign");
129 }
130}
131
133{
134 if ( m_xContainer.is() )
135 {
136 // insert the element
137 m_xContainer->insertByIndex( m_xContainer->getCount(),uno::Any(m_xElement) );
138 }
139 // we don't own the object anymore
140 m_xOwnElement = nullptr;
141}
142
143
145{
146 OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
147 try
148 {
150 if ( m_xContainer.is() )
151 {
152 const sal_Int32 nCount = m_xContainer->getCount();
153 for (sal_Int32 i = 0; i < nCount; ++i)
154 {
155 uno::Reference< uno::XInterface> xObj(m_xContainer->getByIndex(i),uno::UNO_QUERY);
156 if ( xObj == m_xElement )
157 {
158 m_xContainer->removeByIndex( i );
159 break;
160 }
161 }
162 }
163 }
164 catch(uno::Exception&){}
165 // from now on, we own this object
167}
168
169
171{
172 if ( !m_xElement.is() )
173 return;
174
175 // prevents that an undo action will be created for elementInserted
176 try
177 {
178 switch ( m_eAction )
179 {
180 case Inserted:
181 implReRemove();
182 break;
183
184 case Removed:
185 implReInsert();
186 break;
187 default:
188 OSL_FAIL("Illegal case value");
189 break;
190 }
191 }
192 catch( const Exception& )
193 {
194 TOOLS_WARN_EXCEPTION( "reportdesign", "OUndoContainerAction::Undo" );
195 }
196}
197
198
200{
201 if ( !m_xElement.is() )
202 return;
203
204 try
205 {
206 switch ( m_eAction )
207 {
208 case Inserted:
209 implReInsert();
210 break;
211
212 case Removed:
213 implReRemove();
214 break;
215 default:
216 OSL_FAIL("Illegal case value");
217 break;
218 }
219 }
220 catch( const Exception& )
221 {
222 TOOLS_WARN_EXCEPTION( "reportdesign", "OUndoContainerAction::Redo" );
223 }
224}
225
227 SdrModel& _rMod, Action _eAction,
228 ::std::function<uno::Reference<report::XSection>(OGroupHelper*)> _pMemberFunction,
229 const uno::Reference<report::XGroup>& _xGroup, const Reference<XInterface>& xElem,
230 TranslateId pCommentId)
231 : OUndoContainerAction(_rMod, _eAction, nullptr, xElem, pCommentId)
232 , m_aGroupHelper(_xGroup)
233 , m_pMemberFunction(std::move(_pMemberFunction))
234{
235}
236
238{
239 OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
240 try
241 {
243 uno::Reference< report::XSection> xSection = m_pMemberFunction(&m_aGroupHelper);
244 if ( xSection.is() )
245 xSection->add(uno::Reference< drawing::XShape>(m_xElement,uno::UNO_QUERY));
246 }
247 catch(uno::Exception&){}
248
249 // we don't own the object anymore
250 m_xOwnElement = nullptr;
251}
252
253
255{
256 OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
257 try
258 {
260 uno::Reference< report::XSection> xSection = m_pMemberFunction(&m_aGroupHelper);
261 if ( xSection.is() )
262 xSection->remove(uno::Reference< drawing::XShape>(m_xElement,uno::UNO_QUERY));
263 }
264 catch(uno::Exception&){}
265
266 // from now on, we own this object
268}
269
271 SdrModel& _rMod, Action _eAction,
272 ::std::function<uno::Reference<report::XSection>(OReportHelper*)> _pMemberFunction,
273 const uno::Reference<report::XReportDefinition>& _xReport, const Reference<XInterface>& xElem,
274 TranslateId pCommentId)
275 : OUndoContainerAction(_rMod, _eAction, nullptr, xElem, pCommentId)
276 , m_aReportHelper(_xReport)
277 , m_pMemberFunction(std::move(_pMemberFunction))
278{
279}
280
282{
283 OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
284 try
285 {
287 uno::Reference< report::XSection> xSection = m_pMemberFunction(&m_aReportHelper);
288 if ( xSection.is() )
289 {
290 uno::Reference< drawing::XShape> xShape(m_xElement,uno::UNO_QUERY_THROW);
291 awt::Point aPos = xShape->getPosition();
292 awt::Size aSize = xShape->getSize();
293 xSection->add(xShape);
294 xShape->setPosition( aPos );
295 xShape->setSize( aSize );
296 }
297 }
298 catch(uno::Exception&){}
299 // we don't own the object anymore
300 m_xOwnElement = nullptr;
301}
302
303
305{
306 OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
307 try
308 {
310 uno::Reference< report::XSection> xSection = m_pMemberFunction(&m_aReportHelper);
311 if ( xSection.is() )
312 xSection->remove(uno::Reference< drawing::XShape>(m_xElement,uno::UNO_QUERY));
313 }
314 catch(uno::Exception&){}
315 // from now on, we own this object
317}
318
319ORptUndoPropertyAction::ORptUndoPropertyAction(SdrModel& rNewMod, const PropertyChangeEvent& evt)
320 :OCommentUndoAction(rNewMod,{})
321 ,m_xObj(evt.Source, UNO_QUERY)
322 ,m_aPropertyName(evt.PropertyName)
323 ,m_aNewValue(evt.NewValue)
324 ,m_aOldValue(evt.OldValue)
325{
326}
327
329{
330 setProperty(true);
331}
332
333
335{
336 setProperty(false);
337}
338
340{
341 return m_xObj;
342}
343
345{
347
348 if (xObj.is() )
349 {
350 try
351 {
352 xObj->setPropertyValue( m_aPropertyName, _bOld ? m_aOldValue : m_aNewValue );
353 }
354 catch( const Exception& )
355 {
356 TOOLS_WARN_EXCEPTION( "reportdesign", "ORptUndoPropertyAction::Redo" );
357 }
358 }
359}
360
362{
363 OUString aStr( RptResId(RID_STR_UNDO_PROPERTY) );
364
365 return aStr.replaceFirst("#", m_aPropertyName);
366}
367
369 SdrModel& _rMod, const PropertyChangeEvent& evt,
370 ::std::function<uno::Reference<report::XSection>(OGroupHelper*)> _pMemberFunction,
371 const uno::Reference<report::XGroup>& _xGroup)
372 : ORptUndoPropertyAction(_rMod, evt)
373 , m_aGroupHelper(_xGroup)
374 , m_pMemberFunction(std::move(_pMemberFunction))
375{
376}
377
379{
381}
382
384 SdrModel& _rMod, const PropertyChangeEvent& evt,
385 ::std::function<uno::Reference<report::XSection>(OReportHelper*)> _pMemberFunction,
386 const uno::Reference<report::XReportDefinition>& _xReport)
387 : ORptUndoPropertyAction(_rMod, evt)
388 , m_aReportHelper(_xReport)
389 , m_pMemberFunction(std::move(_pMemberFunction))
390{
391}
392
394{
396}
397
398} // rptui
399
400
401/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SectionViewAction m_eAction
sal_Int16 script
SdrModel & rMod
virtual void Redo() override
Definition: UndoActions.cxx:86
virtual ~OCommentUndoAction() override
Definition: UndoActions.cxx:78
OCommentUndoAction(SdrModel &rMod, TranslateId pCommentID)
Definition: UndoActions.cxx:71
::dbaui::IController * m_pController
virtual void Undo() override
Definition: UndoActions.cxx:82
Helper class to allow std::mem_fun for SAL_CALL.
Definition: UndoActions.hxx:49
css::uno::Reference< css::report::XSection > getHeader()
Definition: UndoActions.hxx:58
css::uno::Reference< css::report::XSection > getFooter()
Definition: UndoActions.hxx:59
static ::std::function< css::uno::Reference< css::report::XSection >(OGroupHelper *)> getMemberFunction(const css::uno::Reference< css::report::XSection > &_xSection)
Definition: UndoActions.cxx:46
Helper class to allow std::mem_fun for SAL_CALL.
Definition: UndoActions.hxx:72
css::uno::Reference< css::report::XSection > getPageFooter()
Definition: UndoActions.hxx:82
css::uno::Reference< css::report::XSection > getReportFooter()
Definition: UndoActions.hxx:80
css::uno::Reference< css::report::XSection > getDetail()
Definition: UndoActions.hxx:83
static ::std::function< css::uno::Reference< css::report::XSection >(OReportHelper *)> getMemberFunction(const css::uno::Reference< css::report::XSection > &_xSection)
Definition: UndoActions.cxx:55
css::uno::Reference< css::report::XSection > getReportHeader()
Definition: UndoActions.hxx:79
css::uno::Reference< css::report::XSection > getPageHeader()
Definition: UndoActions.hxx:81
ORptUndoPropertyAction(SdrModel &rMod, const css::beans::PropertyChangeEvent &evt)
virtual void Redo() override
css::uno::Reference< css::beans::XPropertySet > m_xObj
void setProperty(bool _bOld)
sets either the old value or the new value again at the property set.
virtual css::uno::Reference< css::beans::XPropertySet > getObject()
virtual OUString GetComment() const override
virtual void Undo() override
css::uno::Reference< css::container::XIndexContainer > m_xContainer
virtual void Undo() override
css::uno::Reference< css::uno::XInterface > m_xElement
css::uno::Reference< css::uno::XInterface > m_xOwnElement
virtual void Redo() override
OUndoContainerAction(OUndoContainerAction const &)=delete
virtual ~OUndoContainerAction() override
virtual void implReRemove() override
virtual void implReInsert() override
OUndoGroupSectionAction(SdrModel &rMod, Action _eAction,::std::function< css::uno::Reference< css::report::XSection >(OGroupHelper *)> _pMemberFunction, const css::uno::Reference< css::report::XGroup > &_xGroup, const css::uno::Reference< css::uno::XInterface > &xElem, TranslateId pCommentId)
::std::function< css::uno::Reference< css::report::XSection >(OGroupHelper *)> m_pMemberFunction
::std::function< css::uno::Reference< css::report::XSection >(OGroupHelper *)> m_pMemberFunction
virtual css::uno::Reference< css::beans::XPropertySet > getObject() override
OUndoPropertyGroupSectionAction(SdrModel &rMod, const css::beans::PropertyChangeEvent &evt,::std::function< css::uno::Reference< css::report::XSection >(OGroupHelper *)> _pMemberFunction, const css::uno::Reference< css::report::XGroup > &_xGroup)
OUndoPropertyReportSectionAction(SdrModel &rMod, const css::beans::PropertyChangeEvent &evt,::std::function< css::uno::Reference< css::report::XSection >(OReportHelper *)> _pMemberFunction, const css::uno::Reference< css::report::XReportDefinition > &_xReport)
::std::function< css::uno::Reference< css::report::XSection >(OReportHelper *)> m_pMemberFunction
virtual css::uno::Reference< css::beans::XPropertySet > getObject() override
virtual void implReRemove() override
virtual void implReInsert() override
::std::function< css::uno::Reference< css::report::XSection >(OReportHelper *)> m_pMemberFunction
OUndoReportSectionAction(SdrModel &rMod, Action _eAction,::std::function< css::uno::Reference< css::report::XSection >(OReportHelper *)> _pMemberFunction, const css::uno::Reference< css::report::XReportDefinition > &_xReport, const css::uno::Reference< css::uno::XInterface > &xElem, TranslateId pCommentId)
Create an object ob OUndoEnvLock locks the undo possibility As long as in the OUndoEnvLock scope,...
Definition: UndoEnv.hxx:64
void RemoveElement(const css::uno::Reference< css::uno::XInterface > &Element)
Definition: UndoEnv.cxx:594
OUString RptResId(TranslateId aId)
int nCount
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
aStr
@ Exception
void disposeComponent(css::uno::Reference< TYPE > &_rxComp)
int i
@ Inserted
Definition: UndoActions.hxx:42
Reference< XNameAccess > m_xContainer
Reference< xml::input::XElement > m_xElement