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