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 :
20 : #include "UndoActions.hxx"
21 : #include "UndoEnv.hxx"
22 : #include "formatnormalizer.hxx"
23 : #include "conditionupdater.hxx"
24 : #include "corestrings.hrc"
25 : #include "rptui_slotid.hrc"
26 : #include "RptDef.hxx"
27 : #include "ModuleHelper.hxx"
28 : #include "RptObject.hxx"
29 : #include "RptPage.hxx"
30 : #include "RptResId.hrc"
31 : #include "RptModel.hxx"
32 :
33 : #include <com/sun/star/script/XEventAttacherManager.hpp>
34 : #include <com/sun/star/container/XChild.hpp>
35 : #include <com/sun/star/container/XNameContainer.hpp>
36 : #include <com/sun/star/beans/PropertyAttribute.hpp>
37 : #include <com/sun/star/util/XModifyBroadcaster.hpp>
38 :
39 : #include <connectivity/dbtools.hxx>
40 : #include <svl/smplhint.hxx>
41 : #include <tools/diagnose_ex.h>
42 : #include <comphelper/stl_types.hxx>
43 : #include <vcl/svapp.hxx>
44 : #include <dbaccess/dbsubcomponentcontroller.hxx>
45 : #include <svx/unoshape.hxx>
46 : #include <osl/mutex.hxx>
47 :
48 : namespace rptui
49 : {
50 : using namespace ::com::sun::star;
51 : using namespace uno;
52 : using namespace lang;
53 : using namespace script;
54 : using namespace beans;
55 : using namespace awt;
56 : using namespace util;
57 : using namespace container;
58 : using namespace report;
59 : //----------------------------------------------------------------------------
60 0 : ::std::mem_fun_t<uno::Reference<report::XSection> , OGroupHelper> OGroupHelper::getMemberFunction(const Reference< XSection >& _xSection)
61 : {
62 0 : ::std::mem_fun_t<uno::Reference<report::XSection> , OGroupHelper> pMemFunSection = ::std::mem_fun(&OGroupHelper::getFooter);
63 0 : uno::Reference< report::XGroup> xGroup = _xSection->getGroup();
64 0 : if ( xGroup->getHeaderOn() && xGroup->getHeader() == _xSection )
65 0 : pMemFunSection = ::std::mem_fun(&OGroupHelper::getHeader);
66 0 : return pMemFunSection;
67 : }
68 : // -----------------------------------------------------------------------------
69 0 : ::std::mem_fun_t<uno::Reference<report::XSection> , OReportHelper> OReportHelper::getMemberFunction(const Reference< XSection >& _xSection)
70 : {
71 0 : uno::Reference< report::XReportDefinition> xReportDefinition(_xSection->getReportDefinition());
72 0 : ::std::mem_fun_t<uno::Reference<report::XSection> , OReportHelper> pMemFunSection = ::std::mem_fun(&OReportHelper::getReportFooter);
73 0 : if ( xReportDefinition->getReportHeaderOn() && xReportDefinition->getReportHeader() == _xSection )
74 0 : pMemFunSection = ::std::mem_fun(&OReportHelper::getReportHeader);
75 0 : else if ( xReportDefinition->getPageHeaderOn() && xReportDefinition->getPageHeader() == _xSection )
76 0 : pMemFunSection = ::std::mem_fun(&OReportHelper::getPageHeader);
77 0 : else if ( xReportDefinition->getPageFooterOn() && xReportDefinition->getPageFooter() == _xSection )
78 0 : pMemFunSection = ::std::mem_fun(&OReportHelper::getPageFooter);
79 0 : else if ( xReportDefinition->getDetail() == _xSection )
80 0 : pMemFunSection = ::std::mem_fun(&OReportHelper::getDetail);
81 0 : return pMemFunSection;
82 : }
83 :
84 : //------------------------------------------------------------------------------
85 0 : TYPEINIT1( OCommentUndoAction, SdrUndoAction );
86 : DBG_NAME(rpt_OCommentUndoAction)
87 : //----------------------------------------------------------------------------
88 0 : OCommentUndoAction::OCommentUndoAction(SdrModel& _rMod,sal_uInt16 nCommentID)
89 0 : :SdrUndoAction(_rMod)
90 : {
91 : DBG_CTOR(rpt_OCommentUndoAction,NULL);
92 0 : m_pController = static_cast< OReportModel& >( _rMod ).getController();
93 0 : if ( nCommentID )
94 0 : m_strComment = String(ModuleRes(nCommentID));
95 0 : }
96 0 : OCommentUndoAction::~OCommentUndoAction()
97 : {
98 : DBG_DTOR(rpt_OCommentUndoAction,NULL);
99 0 : }
100 : //----------------------------------------------------------------------------
101 0 : void OCommentUndoAction::Undo()
102 : {
103 0 : }
104 : //----------------------------------------------------------------------------
105 0 : void OCommentUndoAction::Redo()
106 : {
107 0 : }
108 : DBG_NAME( rpt_OUndoContainerAction );
109 : //------------------------------------------------------------------------------
110 0 : OUndoContainerAction::OUndoContainerAction(SdrModel& _rMod
111 : ,Action _eAction
112 : ,const uno::Reference< container::XIndexContainer > _xContainer
113 : ,const Reference< XInterface > & xElem
114 : ,sal_uInt16 _nCommentId)
115 : :OCommentUndoAction(_rMod,_nCommentId)
116 : ,m_xElement(xElem)
117 : ,m_xContainer(_xContainer)
118 0 : ,m_eAction( _eAction )
119 : {
120 : DBG_CTOR( rpt_OUndoContainerAction,NULL);
121 : // normalize
122 0 : if ( m_eAction == Removed )
123 : // we now own the element
124 0 : m_xOwnElement = m_xElement;
125 0 : }
126 : //------------------------------------------------------------------------------
127 0 : OUndoContainerAction::~OUndoContainerAction()
128 : {
129 : // if we own the object ....
130 0 : Reference< XComponent > xComp( m_xOwnElement, UNO_QUERY );
131 0 : if ( xComp.is() )
132 : {
133 : // and the object does not have a parent
134 0 : Reference< XChild > xChild( m_xOwnElement, UNO_QUERY );
135 0 : if ( xChild.is() && !xChild->getParent().is() )
136 : {
137 0 : OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
138 0 : rEnv.RemoveElement( m_xOwnElement );
139 :
140 : #if OSL_DEBUG_LEVEL > 0
141 : SvxShape* pShape = SvxShape::getImplementation( xChild );
142 : SdrObject* pObject = pShape ? pShape->GetSdrObject() : NULL;
143 : OSL_ENSURE( pObject ? pShape->HasSdrObjectOwnership() && !pObject->IsInserted() : true ,
144 : "OUndoContainerAction::~OUndoContainerAction: inconsistency in the shape/object ownership!" );
145 : #endif
146 : // -> dispose it
147 : try
148 : {
149 0 : comphelper::disposeComponent( xComp );
150 : }
151 0 : catch ( const uno::Exception& )
152 : {
153 : DBG_UNHANDLED_EXCEPTION();
154 : }
155 0 : }
156 : }
157 0 : DBG_DTOR( rpt_OUndoContainerAction,NULL);
158 0 : }
159 : //------------------------------------------------------------------------------
160 0 : void OUndoContainerAction::implReInsert( ) SAL_THROW( ( Exception ) )
161 : {
162 0 : if ( m_xContainer.is() )
163 : {
164 : // insert the element
165 0 : m_xContainer->insertByIndex( m_xContainer->getCount(),uno::makeAny(m_xElement) );
166 : }
167 : // we don't own the object anymore
168 0 : m_xOwnElement = NULL;
169 0 : }
170 :
171 : //------------------------------------------------------------------------------
172 0 : void OUndoContainerAction::implReRemove( ) SAL_THROW( ( Exception ) )
173 : {
174 0 : OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
175 : try
176 : {
177 0 : OXUndoEnvironment::OUndoEnvLock aLock(rEnv);
178 0 : if ( m_xContainer.is() )
179 : {
180 0 : const sal_Int32 nCount = m_xContainer->getCount();
181 0 : for (sal_Int32 i = 0; i < nCount; ++i)
182 : {
183 0 : uno::Reference< uno::XInterface> xObj(m_xContainer->getByIndex(i),uno::UNO_QUERY);
184 0 : if ( xObj == m_xElement )
185 : {
186 0 : m_xContainer->removeByIndex( i );
187 : break;
188 : }
189 0 : }
190 0 : }
191 : }
192 0 : catch(uno::Exception&){}
193 : // from now on, we own this object
194 0 : m_xOwnElement = m_xElement;
195 0 : }
196 :
197 : //------------------------------------------------------------------------------
198 0 : void OUndoContainerAction::Undo()
199 : {
200 0 : if ( m_xElement.is() )
201 : {
202 : // prevents that an undo action will be created for elementInserted
203 : try
204 : {
205 0 : switch ( m_eAction )
206 : {
207 : case Inserted:
208 0 : implReRemove();
209 0 : break;
210 :
211 : case Removed:
212 0 : implReInsert();
213 0 : break;
214 : default:
215 : OSL_FAIL("Illegal case value");
216 0 : break;
217 : }
218 : }
219 0 : catch( const Exception& )
220 : {
221 : OSL_FAIL( "OUndoContainerAction::Undo: caught an exception!" );
222 : }
223 : }
224 0 : }
225 :
226 : //------------------------------------------------------------------------------
227 0 : void OUndoContainerAction::Redo()
228 : {
229 0 : if ( m_xElement.is() )
230 : {
231 : try
232 : {
233 0 : switch ( m_eAction )
234 : {
235 : case Inserted:
236 0 : implReInsert();
237 0 : break;
238 :
239 : case Removed:
240 0 : implReRemove();
241 0 : break;
242 : default:
243 : OSL_FAIL("Illegal case value");
244 0 : break;
245 : }
246 : }
247 0 : catch( const Exception& )
248 : {
249 : OSL_FAIL( "OUndoContainerAction::Redo: caught an exception!" );
250 : }
251 : }
252 0 : }
253 : // -----------------------------------------------------------------------------
254 0 : OUndoGroupSectionAction::OUndoGroupSectionAction(SdrModel& _rMod
255 : ,Action _eAction
256 : ,::std::mem_fun_t< uno::Reference< report::XSection >
257 : ,OGroupHelper> _pMemberFunction
258 : ,const uno::Reference< report::XGroup >& _xGroup
259 : ,const Reference< XInterface > & xElem
260 : ,sal_uInt16 _nCommentId)
261 : :OUndoContainerAction(_rMod,_eAction,NULL,xElem,_nCommentId)
262 : ,m_aGroupHelper(_xGroup)
263 0 : ,m_pMemberFunction(_pMemberFunction)
264 : {
265 0 : }
266 : //------------------------------------------------------------------------------
267 0 : void OUndoGroupSectionAction::implReInsert( ) SAL_THROW( ( Exception ) )
268 : {
269 0 : OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
270 : try
271 : {
272 0 : OXUndoEnvironment::OUndoEnvLock aLock(rEnv);
273 0 : uno::Reference< report::XSection> xSection = m_pMemberFunction(&m_aGroupHelper);
274 0 : if ( xSection.is() )
275 0 : xSection->add(uno::Reference< drawing::XShape>(m_xElement,uno::UNO_QUERY));
276 : }
277 0 : catch(uno::Exception&){}
278 :
279 : // we don't own the object anymore
280 0 : m_xOwnElement = NULL;
281 0 : }
282 :
283 : //------------------------------------------------------------------------------
284 0 : void OUndoGroupSectionAction::implReRemove( ) SAL_THROW( ( Exception ) )
285 : {
286 0 : OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
287 : try
288 : {
289 0 : OXUndoEnvironment::OUndoEnvLock aLock(rEnv);
290 0 : uno::Reference< report::XSection> xSection = m_pMemberFunction(&m_aGroupHelper);
291 0 : if ( xSection.is() )
292 0 : xSection->remove(uno::Reference< drawing::XShape>(m_xElement,uno::UNO_QUERY));
293 : }
294 0 : catch(uno::Exception&){}
295 :
296 : // from now on, we own this object
297 0 : m_xOwnElement = m_xElement;
298 0 : }
299 : //----------------------------------------------------------------------------
300 0 : OUndoReportSectionAction::OUndoReportSectionAction(SdrModel& _rMod
301 : ,Action _eAction
302 : ,::std::mem_fun_t< uno::Reference< report::XSection >
303 : ,OReportHelper> _pMemberFunction
304 : ,const uno::Reference< report::XReportDefinition >& _xReport
305 : ,const Reference< XInterface > & xElem
306 : ,sal_uInt16 _nCommentId)
307 : :OUndoContainerAction(_rMod,_eAction,NULL,xElem,_nCommentId)
308 : ,m_aReportHelper(_xReport)
309 0 : ,m_pMemberFunction(_pMemberFunction)
310 : {
311 0 : }
312 : //------------------------------------------------------------------------------
313 0 : void OUndoReportSectionAction::implReInsert( ) SAL_THROW( ( Exception ) )
314 : {
315 0 : OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
316 : try
317 : {
318 0 : OXUndoEnvironment::OUndoEnvLock aLock(rEnv);
319 0 : uno::Reference< report::XSection> xSection = m_pMemberFunction(&m_aReportHelper);
320 0 : if ( xSection.is() )
321 : {
322 0 : uno::Reference< drawing::XShape> xShape(m_xElement,uno::UNO_QUERY_THROW);
323 0 : awt::Point aPos = xShape->getPosition();
324 0 : awt::Size aSize = xShape->getSize();
325 0 : xSection->add(xShape);
326 0 : xShape->setPosition( aPos );
327 0 : xShape->setSize( aSize );
328 0 : }
329 : }
330 0 : catch(uno::Exception&){}
331 : // we don't own the object anymore
332 0 : m_xOwnElement = NULL;
333 0 : }
334 :
335 : //------------------------------------------------------------------------------
336 0 : void OUndoReportSectionAction::implReRemove( ) SAL_THROW( ( Exception ) )
337 : {
338 0 : OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
339 : try
340 : {
341 0 : OXUndoEnvironment::OUndoEnvLock aLock(rEnv);
342 0 : uno::Reference< report::XSection> xSection = m_pMemberFunction(&m_aReportHelper);
343 0 : if ( xSection.is() )
344 0 : xSection->remove(uno::Reference< drawing::XShape>(m_xElement,uno::UNO_QUERY));
345 : }
346 0 : catch(uno::Exception&){}
347 : // from now on, we own this object
348 0 : m_xOwnElement = m_xElement;
349 0 : }
350 : //------------------------------------------------------------------------------
351 0 : ORptUndoPropertyAction::ORptUndoPropertyAction(SdrModel& rNewMod, const PropertyChangeEvent& evt)
352 : :OCommentUndoAction(rNewMod,0)
353 : ,m_xObj(evt.Source, UNO_QUERY)
354 : ,m_aPropertyName(evt.PropertyName)
355 : ,m_aNewValue(evt.NewValue)
356 0 : ,m_aOldValue(evt.OldValue)
357 : {
358 0 : }
359 : //------------------------------------------------------------------------------
360 0 : void ORptUndoPropertyAction::Undo()
361 : {
362 0 : setProperty(sal_True);
363 0 : }
364 :
365 : //------------------------------------------------------------------------------
366 0 : void ORptUndoPropertyAction::Redo()
367 : {
368 0 : setProperty(sal_False);
369 0 : }
370 : // -----------------------------------------------------------------------------
371 0 : Reference< XPropertySet> ORptUndoPropertyAction::getObject()
372 : {
373 0 : return m_xObj;
374 : }
375 : // -----------------------------------------------------------------------------
376 0 : void ORptUndoPropertyAction::setProperty(sal_Bool _bOld)
377 : {
378 0 : Reference< XPropertySet> xObj = getObject();
379 :
380 0 : if (xObj.is() )
381 : {
382 : try
383 : {
384 0 : xObj->setPropertyValue( m_aPropertyName, _bOld ? m_aOldValue : m_aNewValue );
385 : }
386 0 : catch( const Exception& )
387 : {
388 : OSL_FAIL( "ORptUndoPropertyAction::Redo: caught an exception!" );
389 : }
390 0 : }
391 0 : }
392 :
393 0 : rtl::OUString ORptUndoPropertyAction::GetComment() const
394 : {
395 0 : String aStr(ModuleRes(RID_STR_UNDO_PROPERTY).toString());
396 :
397 0 : aStr.SearchAndReplace(rtl::OUString('#'), m_aPropertyName);
398 0 : return aStr;
399 : }
400 :
401 0 : OUndoPropertyGroupSectionAction::OUndoPropertyGroupSectionAction(SdrModel& _rMod
402 : ,const PropertyChangeEvent& evt
403 : ,::std::mem_fun_t< uno::Reference< report::XSection >
404 : ,OGroupHelper> _pMemberFunction
405 : ,const uno::Reference< report::XGroup >& _xGroup
406 : )
407 : :ORptUndoPropertyAction(_rMod,evt)
408 : ,m_aGroupHelper(_xGroup)
409 0 : ,m_pMemberFunction(_pMemberFunction)
410 : {
411 0 : }
412 : // -----------------------------------------------------------------------------
413 0 : Reference< XPropertySet> OUndoPropertyGroupSectionAction::getObject()
414 : {
415 0 : return m_pMemberFunction(&m_aGroupHelper).get();
416 : }
417 : // -----------------------------------------------------------------------------
418 0 : OUndoPropertyReportSectionAction::OUndoPropertyReportSectionAction(SdrModel& _rMod
419 : ,const PropertyChangeEvent& evt
420 : ,::std::mem_fun_t< uno::Reference< report::XSection >
421 : ,OReportHelper> _pMemberFunction
422 : ,const uno::Reference< report::XReportDefinition >& _xReport
423 : )
424 : :ORptUndoPropertyAction(_rMod,evt)
425 : ,m_aReportHelper(_xReport)
426 0 : ,m_pMemberFunction(_pMemberFunction)
427 : {
428 0 : }
429 : // -----------------------------------------------------------------------------
430 0 : Reference< XPropertySet> OUndoPropertyReportSectionAction::getObject()
431 : {
432 0 : return m_pMemberFunction(&m_aReportHelper).get();
433 : }
434 : //============================================================================
435 : } // rptui
436 : //============================================================================
437 :
438 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|