1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir #include "precompiled_reportdesign.hxx"
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir #include "RptUndo.hxx"
30*cdf0e10cSrcweir #include "uistrings.hrc"
31*cdf0e10cSrcweir #include "rptui_slotid.hrc"
32*cdf0e10cSrcweir #include "UITools.hxx"
33*cdf0e10cSrcweir #include "UndoEnv.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <dbaccess/IController.hxx>
36*cdf0e10cSrcweir #include <com/sun/star/report/XSection.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <com/sun/star/awt/Point.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp>
41*cdf0e10cSrcweir #include <svx/unoshape.hxx>
42*cdf0e10cSrcweir #include <boost/bind.hpp>
43*cdf0e10cSrcweir #include <functional>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir namespace rptui
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir 	using namespace ::com::sun::star;
48*cdf0e10cSrcweir 	using namespace uno;
49*cdf0e10cSrcweir 	using namespace lang;
50*cdf0e10cSrcweir 	using namespace script;
51*cdf0e10cSrcweir 	using namespace beans;
52*cdf0e10cSrcweir 	using namespace awt;
53*cdf0e10cSrcweir 	using namespace util;
54*cdf0e10cSrcweir 	using namespace container;
55*cdf0e10cSrcweir 	using namespace report;
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir //----------------------------------------------------------------------------
58*cdf0e10cSrcweir namespace
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir     void lcl_collectElements(const uno::Reference< report::XSection >& _xSection,::std::vector< uno::Reference< drawing::XShape> >& _rControls)
61*cdf0e10cSrcweir     {
62*cdf0e10cSrcweir         if ( _xSection.is() )
63*cdf0e10cSrcweir 		{
64*cdf0e10cSrcweir 			sal_Int32 nCount = _xSection->getCount();
65*cdf0e10cSrcweir 			_rControls.reserve(nCount);
66*cdf0e10cSrcweir 			while ( nCount )
67*cdf0e10cSrcweir 			{
68*cdf0e10cSrcweir                 uno::Reference< drawing::XShape> xShape(_xSection->getByIndex(nCount-1),uno::UNO_QUERY);
69*cdf0e10cSrcweir 				_rControls.push_back(xShape);
70*cdf0e10cSrcweir 				_xSection->remove(xShape);
71*cdf0e10cSrcweir 				--nCount;
72*cdf0e10cSrcweir 			}
73*cdf0e10cSrcweir 		} // if ( _xSection.is() )
74*cdf0e10cSrcweir     }
75*cdf0e10cSrcweir     //----------------------------------------------------------------------------
76*cdf0e10cSrcweir     void lcl_insertElements(const uno::Reference< report::XSection >& _xSection,const ::std::vector< uno::Reference< drawing::XShape> >& _aControls)
77*cdf0e10cSrcweir     {
78*cdf0e10cSrcweir         if ( _xSection.is() )
79*cdf0e10cSrcweir 	    {
80*cdf0e10cSrcweir 		    ::std::vector< uno::Reference< drawing::XShape> >::const_reverse_iterator aIter = _aControls.rbegin();
81*cdf0e10cSrcweir 		    ::std::vector< uno::Reference< drawing::XShape> >::const_reverse_iterator aEnd = _aControls.rend();
82*cdf0e10cSrcweir 		    for (; aIter != aEnd; ++aIter)
83*cdf0e10cSrcweir             {
84*cdf0e10cSrcweir                 try
85*cdf0e10cSrcweir                 {
86*cdf0e10cSrcweir                     const awt::Point aPos = (*aIter)->getPosition();
87*cdf0e10cSrcweir                     const awt::Size aSize = (*aIter)->getSize();
88*cdf0e10cSrcweir 			        _xSection->add(*aIter);
89*cdf0e10cSrcweir                     (*aIter)->setPosition( aPos );
90*cdf0e10cSrcweir         		    (*aIter)->setSize( aSize );
91*cdf0e10cSrcweir                 }
92*cdf0e10cSrcweir                 catch(const uno::Exception&)
93*cdf0e10cSrcweir                 {
94*cdf0e10cSrcweir                     OSL_ENSURE(0,"lcl_insertElements:Exception caught!");
95*cdf0e10cSrcweir                 }
96*cdf0e10cSrcweir             }
97*cdf0e10cSrcweir 	    }
98*cdf0e10cSrcweir     }
99*cdf0e10cSrcweir     //----------------------------------------------------------------------------
100*cdf0e10cSrcweir     void lcl_setValues(const uno::Reference< report::XSection >& _xSection,const ::std::vector< ::std::pair< ::rtl::OUString ,uno::Any> >& _aValues)
101*cdf0e10cSrcweir     {
102*cdf0e10cSrcweir         if ( _xSection.is() )
103*cdf0e10cSrcweir 	    {
104*cdf0e10cSrcweir 		    ::std::vector< ::std::pair< ::rtl::OUString ,uno::Any> >::const_iterator aIter = _aValues.begin();
105*cdf0e10cSrcweir 		    ::std::vector< ::std::pair< ::rtl::OUString ,uno::Any> >::const_iterator aEnd = _aValues.end();
106*cdf0e10cSrcweir 		    for (; aIter != aEnd; ++aIter)
107*cdf0e10cSrcweir             {
108*cdf0e10cSrcweir                 try
109*cdf0e10cSrcweir                 {
110*cdf0e10cSrcweir 			        _xSection->setPropertyValue(aIter->first,aIter->second);
111*cdf0e10cSrcweir                 }
112*cdf0e10cSrcweir                 catch(const uno::Exception&)
113*cdf0e10cSrcweir                 {
114*cdf0e10cSrcweir                     OSL_ENSURE(0,"lcl_setValues:Exception caught!");
115*cdf0e10cSrcweir                 }
116*cdf0e10cSrcweir             }
117*cdf0e10cSrcweir 	    }
118*cdf0e10cSrcweir     }
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir //----------------------------------------------------------------------------
121*cdf0e10cSrcweir TYPEINIT1( OSectionUndo,         OCommentUndoAction );
122*cdf0e10cSrcweir DBG_NAME(rpt_OSectionUndo)
123*cdf0e10cSrcweir //----------------------------------------------------------------------------
124*cdf0e10cSrcweir OSectionUndo::OSectionUndo(OReportModel& _rMod
125*cdf0e10cSrcweir                            ,sal_uInt16 _nSlot
126*cdf0e10cSrcweir 						   ,Action _eAction
127*cdf0e10cSrcweir 						   ,sal_uInt16 nCommentID)
128*cdf0e10cSrcweir : OCommentUndoAction(_rMod,nCommentID)
129*cdf0e10cSrcweir ,m_eAction(_eAction)
130*cdf0e10cSrcweir ,m_nSlot(_nSlot)
131*cdf0e10cSrcweir ,m_bInserted(false)
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir     DBG_CTOR(rpt_OSectionUndo,NULL);
134*cdf0e10cSrcweir }
135*cdf0e10cSrcweir // -----------------------------------------------------------------------------
136*cdf0e10cSrcweir OSectionUndo::~OSectionUndo()
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir     if ( !m_bInserted )
139*cdf0e10cSrcweir     {
140*cdf0e10cSrcweir         OXUndoEnvironment& rEnv = static_cast< OReportModel& >( rMod ).GetUndoEnv();
141*cdf0e10cSrcweir         ::std::vector< uno::Reference< drawing::XShape> >::iterator aEnd = m_aControls.end();
142*cdf0e10cSrcweir         for (::std::vector< uno::Reference< drawing::XShape> >::iterator aIter = m_aControls.begin(); aIter != aEnd; ++aIter)
143*cdf0e10cSrcweir         {
144*cdf0e10cSrcweir             uno::Reference< drawing::XShape> xShape = *aIter;
145*cdf0e10cSrcweir             rEnv.RemoveElement(xShape);
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
148*cdf0e10cSrcweir             SvxShape* pShape = SvxShape::getImplementation( xShape );
149*cdf0e10cSrcweir             SdrObject* pObject = pShape ? pShape->GetSdrObject() : NULL;
150*cdf0e10cSrcweir             OSL_ENSURE( pShape && pShape->HasSdrObjectOwnership() && pObject && !pObject->IsInserted(),
151*cdf0e10cSrcweir                 "OSectionUndo::~OSectionUndo: inconsistency in the shape/object ownership!" );
152*cdf0e10cSrcweir #endif
153*cdf0e10cSrcweir             try
154*cdf0e10cSrcweir             {
155*cdf0e10cSrcweir                 comphelper::disposeComponent(xShape);
156*cdf0e10cSrcweir             }
157*cdf0e10cSrcweir             catch(uno::Exception)
158*cdf0e10cSrcweir             {
159*cdf0e10cSrcweir                 OSL_ENSURE(0,"Exception caught!");
160*cdf0e10cSrcweir             }
161*cdf0e10cSrcweir         }
162*cdf0e10cSrcweir     }
163*cdf0e10cSrcweir     DBG_DTOR(rpt_OSectionUndo,NULL);
164*cdf0e10cSrcweir }
165*cdf0e10cSrcweir // -----------------------------------------------------------------------------
166*cdf0e10cSrcweir void OSectionUndo::collectControls(const uno::Reference< report::XSection >& _xSection)
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir     m_aControls.clear();
169*cdf0e10cSrcweir 	try
170*cdf0e10cSrcweir 	{
171*cdf0e10cSrcweir         // copy all properties for restoring
172*cdf0e10cSrcweir         uno::Reference< beans::XPropertySetInfo> xInfo = _xSection->getPropertySetInfo();
173*cdf0e10cSrcweir         uno::Sequence< beans::Property> aSeq = xInfo->getProperties();
174*cdf0e10cSrcweir         const beans::Property* pIter = aSeq.getConstArray();
175*cdf0e10cSrcweir         const beans::Property* pEnd	 = pIter + aSeq.getLength();
176*cdf0e10cSrcweir         for(;pIter != pEnd;++pIter)
177*cdf0e10cSrcweir         {
178*cdf0e10cSrcweir             if ( 0 == (pIter->Attributes & beans::PropertyAttribute::READONLY) )
179*cdf0e10cSrcweir                 m_aValues.push_back(::std::pair< ::rtl::OUString ,uno::Any>(pIter->Name,_xSection->getPropertyValue(pIter->Name)));
180*cdf0e10cSrcweir         }
181*cdf0e10cSrcweir         lcl_collectElements(_xSection,m_aControls);
182*cdf0e10cSrcweir 	}
183*cdf0e10cSrcweir 	catch(uno::Exception&)
184*cdf0e10cSrcweir 	{
185*cdf0e10cSrcweir 	}
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir //----------------------------------------------------------------------------
188*cdf0e10cSrcweir void OSectionUndo::Undo()
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir     try
191*cdf0e10cSrcweir     {
192*cdf0e10cSrcweir 		switch ( m_eAction )
193*cdf0e10cSrcweir 		{
194*cdf0e10cSrcweir 		case Inserted:
195*cdf0e10cSrcweir             implReRemove();
196*cdf0e10cSrcweir             break;
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 		case Removed:
199*cdf0e10cSrcweir             implReInsert();
200*cdf0e10cSrcweir             break;
201*cdf0e10cSrcweir     	}
202*cdf0e10cSrcweir     }
203*cdf0e10cSrcweir     catch( const Exception& )
204*cdf0e10cSrcweir     {
205*cdf0e10cSrcweir         OSL_ENSURE( sal_False, "OSectionUndo::Undo: caught an exception!" );
206*cdf0e10cSrcweir     }
207*cdf0e10cSrcweir }
208*cdf0e10cSrcweir //----------------------------------------------------------------------------
209*cdf0e10cSrcweir void OSectionUndo::Redo()
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir     try
212*cdf0e10cSrcweir     {
213*cdf0e10cSrcweir 	    switch ( m_eAction )
214*cdf0e10cSrcweir 		{
215*cdf0e10cSrcweir 		case Inserted:
216*cdf0e10cSrcweir             implReInsert();
217*cdf0e10cSrcweir             break;
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 		case Removed:
220*cdf0e10cSrcweir             implReRemove();
221*cdf0e10cSrcweir 			break;
222*cdf0e10cSrcweir     	}
223*cdf0e10cSrcweir     }
224*cdf0e10cSrcweir     catch( const Exception& )
225*cdf0e10cSrcweir     {
226*cdf0e10cSrcweir         OSL_ENSURE( sal_False, "OSectionUndo::Redo: caught an exception!" );
227*cdf0e10cSrcweir     }
228*cdf0e10cSrcweir }
229*cdf0e10cSrcweir //----------------------------------------------------------------------------
230*cdf0e10cSrcweir TYPEINIT1( OReportSectionUndo,         OSectionUndo );
231*cdf0e10cSrcweir //----------------------------------------------------------------------------
232*cdf0e10cSrcweir OReportSectionUndo::OReportSectionUndo(OReportModel& _rMod,sal_uInt16 _nSlot
233*cdf0e10cSrcweir 									   ,::std::mem_fun_t< uno::Reference< report::XSection >
234*cdf0e10cSrcweir 											,OReportHelper> _pMemberFunction
235*cdf0e10cSrcweir 									   ,const uno::Reference< report::XReportDefinition >& _xReport
236*cdf0e10cSrcweir 									   ,Action _eAction
237*cdf0e10cSrcweir 									   ,sal_uInt16 nCommentID)
238*cdf0e10cSrcweir : OSectionUndo(_rMod,_nSlot,_eAction,nCommentID)
239*cdf0e10cSrcweir ,m_aReportHelper(_xReport)
240*cdf0e10cSrcweir ,m_pMemberFunction(_pMemberFunction)
241*cdf0e10cSrcweir {
242*cdf0e10cSrcweir 	if( m_eAction == Removed )
243*cdf0e10cSrcweir         collectControls(m_pMemberFunction(&m_aReportHelper));
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir // -----------------------------------------------------------------------------
246*cdf0e10cSrcweir OReportSectionUndo::~OReportSectionUndo()
247*cdf0e10cSrcweir {
248*cdf0e10cSrcweir }
249*cdf0e10cSrcweir //----------------------------------------------------------------------------
250*cdf0e10cSrcweir void OReportSectionUndo::implReInsert( )
251*cdf0e10cSrcweir {
252*cdf0e10cSrcweir 	const uno::Sequence< beans::PropertyValue > aArgs;
253*cdf0e10cSrcweir 	m_pController->executeChecked(m_nSlot,aArgs);
254*cdf0e10cSrcweir 	uno::Reference< report::XSection > xSection = m_pMemberFunction(&m_aReportHelper);
255*cdf0e10cSrcweir     lcl_insertElements(xSection,m_aControls);
256*cdf0e10cSrcweir     lcl_setValues(xSection,m_aValues);
257*cdf0e10cSrcweir     m_bInserted = true;
258*cdf0e10cSrcweir }
259*cdf0e10cSrcweir //----------------------------------------------------------------------------
260*cdf0e10cSrcweir void OReportSectionUndo::implReRemove( )
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir     if( m_eAction == Removed )
263*cdf0e10cSrcweir         collectControls(m_pMemberFunction(&m_aReportHelper));
264*cdf0e10cSrcweir 	const uno::Sequence< beans::PropertyValue > aArgs;
265*cdf0e10cSrcweir 	m_pController->executeChecked(m_nSlot,aArgs);
266*cdf0e10cSrcweir     m_bInserted = false;
267*cdf0e10cSrcweir }
268*cdf0e10cSrcweir //----------------------------------------------------------------------------
269*cdf0e10cSrcweir TYPEINIT1( OGroupSectionUndo,         OSectionUndo );
270*cdf0e10cSrcweir //----------------------------------------------------------------------------
271*cdf0e10cSrcweir OGroupSectionUndo::OGroupSectionUndo(OReportModel& _rMod,sal_uInt16 _nSlot
272*cdf0e10cSrcweir 									   ,::std::mem_fun_t< uno::Reference< report::XSection >
273*cdf0e10cSrcweir 											,OGroupHelper> _pMemberFunction
274*cdf0e10cSrcweir 									   ,const uno::Reference< report::XGroup >& _xGroup
275*cdf0e10cSrcweir 									   ,Action _eAction
276*cdf0e10cSrcweir 									   ,sal_uInt16 nCommentID)
277*cdf0e10cSrcweir : OSectionUndo(_rMod,_nSlot,_eAction,nCommentID)
278*cdf0e10cSrcweir ,m_aGroupHelper(_xGroup)
279*cdf0e10cSrcweir ,m_pMemberFunction(_pMemberFunction)
280*cdf0e10cSrcweir {
281*cdf0e10cSrcweir     if( m_eAction == Removed )
282*cdf0e10cSrcweir     {
283*cdf0e10cSrcweir         uno::Reference< report::XSection > xSection = m_pMemberFunction(&m_aGroupHelper);
284*cdf0e10cSrcweir 		if ( xSection.is() )
285*cdf0e10cSrcweir             m_sName = xSection->getName();
286*cdf0e10cSrcweir         collectControls(xSection);
287*cdf0e10cSrcweir     }
288*cdf0e10cSrcweir }
289*cdf0e10cSrcweir //----------------------------------------------------------------------------
290*cdf0e10cSrcweir String OGroupSectionUndo::GetComment() const
291*cdf0e10cSrcweir {
292*cdf0e10cSrcweir     if ( !m_sName.getLength() )
293*cdf0e10cSrcweir     {
294*cdf0e10cSrcweir         try
295*cdf0e10cSrcweir         {
296*cdf0e10cSrcweir             uno::Reference< report::XSection > xSection = const_cast<OGroupSectionUndo*>(this)->m_pMemberFunction(&const_cast<OGroupSectionUndo*>(this)->m_aGroupHelper);
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 		    if ( xSection.is() )
299*cdf0e10cSrcweir                 m_sName = xSection->getName();
300*cdf0e10cSrcweir         }
301*cdf0e10cSrcweir         catch(uno::Exception&)
302*cdf0e10cSrcweir         {}
303*cdf0e10cSrcweir     }
304*cdf0e10cSrcweir     return m_strComment + m_sName;
305*cdf0e10cSrcweir }
306*cdf0e10cSrcweir //----------------------------------------------------------------------------
307*cdf0e10cSrcweir void OGroupSectionUndo::implReInsert( )
308*cdf0e10cSrcweir {
309*cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > aArgs(2);
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 	aArgs[0].Name = SID_GROUPHEADER_WITHOUT_UNDO == m_nSlot? PROPERTY_HEADERON : PROPERTY_FOOTERON;
312*cdf0e10cSrcweir 	aArgs[0].Value <<= sal_True;
313*cdf0e10cSrcweir 	aArgs[1].Name = PROPERTY_GROUP;
314*cdf0e10cSrcweir 	aArgs[1].Value <<= m_aGroupHelper.getGroup();
315*cdf0e10cSrcweir 	m_pController->executeChecked(m_nSlot,aArgs);
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir 	uno::Reference< report::XSection > xSection = m_pMemberFunction(&m_aGroupHelper);
318*cdf0e10cSrcweir     lcl_insertElements(xSection,m_aControls);
319*cdf0e10cSrcweir     lcl_setValues(xSection,m_aValues);
320*cdf0e10cSrcweir     m_bInserted = true;
321*cdf0e10cSrcweir }
322*cdf0e10cSrcweir //----------------------------------------------------------------------------
323*cdf0e10cSrcweir void OGroupSectionUndo::implReRemove( )
324*cdf0e10cSrcweir {
325*cdf0e10cSrcweir     if( m_eAction == Removed )
326*cdf0e10cSrcweir         collectControls(m_pMemberFunction(&m_aGroupHelper));
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir 	uno::Sequence< beans::PropertyValue > aArgs(2);
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 	aArgs[0].Name = SID_GROUPHEADER_WITHOUT_UNDO == m_nSlot? PROPERTY_HEADERON : PROPERTY_FOOTERON;
331*cdf0e10cSrcweir 	aArgs[0].Value <<= sal_False;
332*cdf0e10cSrcweir 	aArgs[1].Name = PROPERTY_GROUP;
333*cdf0e10cSrcweir 	aArgs[1].Value <<= m_aGroupHelper.getGroup();
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 	m_pController->executeChecked(m_nSlot,aArgs);
336*cdf0e10cSrcweir     m_bInserted = false;
337*cdf0e10cSrcweir }
338*cdf0e10cSrcweir //----------------------------------------------------------------------------
339*cdf0e10cSrcweir TYPEINIT1( OGroupUndo,         OCommentUndoAction );
340*cdf0e10cSrcweir //----------------------------------------------------------------------------
341*cdf0e10cSrcweir OGroupUndo::OGroupUndo(OReportModel& _rMod
342*cdf0e10cSrcweir 					   ,sal_uInt16 nCommentID
343*cdf0e10cSrcweir 					   ,Action	_eAction
344*cdf0e10cSrcweir 					   ,const uno::Reference< report::XGroup>& _xGroup
345*cdf0e10cSrcweir 					   ,const uno::Reference< report::XReportDefinition >& _xReportDefinition)
346*cdf0e10cSrcweir : OCommentUndoAction(_rMod,nCommentID)
347*cdf0e10cSrcweir ,m_xGroup(_xGroup)
348*cdf0e10cSrcweir ,m_xReportDefinition(_xReportDefinition)
349*cdf0e10cSrcweir ,m_eAction(_eAction)
350*cdf0e10cSrcweir {
351*cdf0e10cSrcweir 	m_nLastPosition = getPositionInIndexAccess(m_xReportDefinition->getGroups().get(),m_xGroup);
352*cdf0e10cSrcweir }
353*cdf0e10cSrcweir //----------------------------------------------------------------------------
354*cdf0e10cSrcweir void OGroupUndo::implReInsert( )
355*cdf0e10cSrcweir {
356*cdf0e10cSrcweir 	try
357*cdf0e10cSrcweir 	{
358*cdf0e10cSrcweir 		m_xReportDefinition->getGroups()->insertByIndex(m_nLastPosition,uno::makeAny(m_xGroup));
359*cdf0e10cSrcweir 	}
360*cdf0e10cSrcweir 	catch(uno::Exception&)
361*cdf0e10cSrcweir 	{
362*cdf0e10cSrcweir 		OSL_ENSURE(0,"Exception catched while undoing remove group");
363*cdf0e10cSrcweir 	}
364*cdf0e10cSrcweir }
365*cdf0e10cSrcweir //----------------------------------------------------------------------------
366*cdf0e10cSrcweir void OGroupUndo::implReRemove( )
367*cdf0e10cSrcweir {
368*cdf0e10cSrcweir 	try
369*cdf0e10cSrcweir 	{
370*cdf0e10cSrcweir 		m_xReportDefinition->getGroups()->removeByIndex(m_nLastPosition);
371*cdf0e10cSrcweir 	}
372*cdf0e10cSrcweir 	catch(uno::Exception&)
373*cdf0e10cSrcweir 	{
374*cdf0e10cSrcweir 		OSL_ENSURE(0,"Exception catched while redoing remove group");
375*cdf0e10cSrcweir 	}
376*cdf0e10cSrcweir }
377*cdf0e10cSrcweir //----------------------------------------------------------------------------
378*cdf0e10cSrcweir void OGroupUndo::Undo()
379*cdf0e10cSrcweir {
380*cdf0e10cSrcweir 	switch ( m_eAction )
381*cdf0e10cSrcweir 	{
382*cdf0e10cSrcweir 	case Inserted:
383*cdf0e10cSrcweir         implReRemove();
384*cdf0e10cSrcweir         break;
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir 	case Removed:
387*cdf0e10cSrcweir         implReInsert();
388*cdf0e10cSrcweir         break;
389*cdf0e10cSrcweir     }
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir }
392*cdf0e10cSrcweir //----------------------------------------------------------------------------
393*cdf0e10cSrcweir void OGroupUndo::Redo()
394*cdf0e10cSrcweir {
395*cdf0e10cSrcweir 	switch ( m_eAction )
396*cdf0e10cSrcweir 	{
397*cdf0e10cSrcweir 	case Inserted:
398*cdf0e10cSrcweir         implReInsert();
399*cdf0e10cSrcweir         break;
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 	case Removed:
402*cdf0e10cSrcweir         implReRemove();
403*cdf0e10cSrcweir 		break;
404*cdf0e10cSrcweir     }
405*cdf0e10cSrcweir }
406*cdf0e10cSrcweir //----------------------------------------------------------------------------
407*cdf0e10cSrcweir //============================================================================
408*cdf0e10cSrcweir } // rptui
409*cdf0e10cSrcweir //============================================================================
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir 
412