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