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 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir #ifndef DBAUI_TABLEUNDO_HXX
31*cdf0e10cSrcweir #include "TableUndo.hxx"
32*cdf0e10cSrcweir #endif
33*cdf0e10cSrcweir #ifndef _DBU_TBL_HRC_
34*cdf0e10cSrcweir #include "dbu_tbl.hrc"
35*cdf0e10cSrcweir #endif
36*cdf0e10cSrcweir #ifndef DBAUI_TABLEEDITORCONTROL_HXX
37*cdf0e10cSrcweir #include "TEditControl.hxx"
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir #ifndef DBAUI_TABLEROW_HXX
40*cdf0e10cSrcweir #include "TableRow.hxx"
41*cdf0e10cSrcweir #endif
42*cdf0e10cSrcweir #ifndef DBACCESS_UI_BROWSER_ID_HXX
43*cdf0e10cSrcweir #include "browserids.hxx"
44*cdf0e10cSrcweir #endif
45*cdf0e10cSrcweir #ifndef DBUI_TABLECONTROLLER_HXX
46*cdf0e10cSrcweir #include "TableController.hxx"
47*cdf0e10cSrcweir #endif
48*cdf0e10cSrcweir #ifndef DBAUI_TABLEDESIGNVIEW_HXX
49*cdf0e10cSrcweir #include "TableDesignView.hxx"
50*cdf0e10cSrcweir #endif
51*cdf0e10cSrcweir #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
52*cdf0e10cSrcweir #include "FieldDescriptions.hxx"
53*cdf0e10cSrcweir #endif
54*cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
55*cdf0e10cSrcweir #include <tools/debug.hxx>
56*cdf0e10cSrcweir #endif
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir using namespace dbaui;
59*cdf0e10cSrcweir using namespace ::svt;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir TYPEINIT1( OCommentUndoAction,          SfxUndoAction );
62*cdf0e10cSrcweir TYPEINIT1( OTableDesignUndoAct,         OCommentUndoAction );
63*cdf0e10cSrcweir TYPEINIT1( OTableEditorUndoAct,         OTableDesignUndoAct );
64*cdf0e10cSrcweir TYPEINIT1( OTableDesignCellUndoAct,     OTableDesignUndoAct );
65*cdf0e10cSrcweir TYPEINIT1( OTableEditorTypeSelUndoAct,  OTableEditorUndoAct );
66*cdf0e10cSrcweir TYPEINIT1( OTableEditorDelUndoAct,      OTableEditorUndoAct );
67*cdf0e10cSrcweir TYPEINIT1( OTableEditorInsUndoAct,      OTableEditorUndoAct );
68*cdf0e10cSrcweir TYPEINIT1( OTableEditorInsNewUndoAct,   OTableEditorUndoAct );
69*cdf0e10cSrcweir TYPEINIT1( OPrimKeyUndoAct,             OTableEditorUndoAct );
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir //==============================================================================
72*cdf0e10cSrcweir // class OTableDesignUndoAct
73*cdf0e10cSrcweir //==============================================================================
74*cdf0e10cSrcweir DBG_NAME(OTableDesignUndoAct);
75*cdf0e10cSrcweir OTableDesignUndoAct::OTableDesignUndoAct( OTableRowView* pOwner,sal_uInt16 nCommentID ) : OCommentUndoAction(nCommentID)
76*cdf0e10cSrcweir 	,m_pTabDgnCtrl(  pOwner )
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir 	DBG_CTOR(OTableDesignUndoAct,NULL);
79*cdf0e10cSrcweir 	m_pTabDgnCtrl->m_nCurUndoActId++;
80*cdf0e10cSrcweir }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir //-------------------------------------------------------------------------
83*cdf0e10cSrcweir OTableDesignUndoAct::~OTableDesignUndoAct()
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir 	DBG_DTOR(OTableDesignUndoAct,NULL);
86*cdf0e10cSrcweir }
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir //-------------------------------------------------------------------------
89*cdf0e10cSrcweir void OTableDesignUndoAct::Undo()
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir 	m_pTabDgnCtrl->m_nCurUndoActId--;
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
94*cdf0e10cSrcweir 	// Wenn erstes Undo zurueckgenommen wurde, ist Doc nicht modifiziert worden
95*cdf0e10cSrcweir 	if( m_pTabDgnCtrl->m_nCurUndoActId == 0 )
96*cdf0e10cSrcweir 	{
97*cdf0e10cSrcweir 		m_pTabDgnCtrl->GetView()->getController().setModified(sal_False);
98*cdf0e10cSrcweir 		m_pTabDgnCtrl->GetView()->getController().InvalidateFeature(SID_SAVEDOC);
99*cdf0e10cSrcweir 	}
100*cdf0e10cSrcweir }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir //-------------------------------------------------------------------------
103*cdf0e10cSrcweir void OTableDesignUndoAct::Redo()
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir 	m_pTabDgnCtrl->m_nCurUndoActId++;
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
108*cdf0e10cSrcweir 	// Wenn Redo fuer erste Undo-Action, muss Modified-Flag wieder gesetzt werden
109*cdf0e10cSrcweir 	if( m_pTabDgnCtrl->m_nCurUndoActId > 0 )
110*cdf0e10cSrcweir 	{
111*cdf0e10cSrcweir 		m_pTabDgnCtrl->GetView()->getController().setModified(sal_True);
112*cdf0e10cSrcweir 		m_pTabDgnCtrl->GetView()->getController().InvalidateFeature(SID_SAVEDOC);
113*cdf0e10cSrcweir 	}
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir //==============================================================================
116*cdf0e10cSrcweir // class OTableDesignCellUndoAct
117*cdf0e10cSrcweir //==============================================================================
118*cdf0e10cSrcweir DBG_NAME(OTableDesignCellUndoAct);
119*cdf0e10cSrcweir OTableDesignCellUndoAct::OTableDesignCellUndoAct( OTableRowView* pOwner, long nRowID, sal_uInt16 nColumn ) :
120*cdf0e10cSrcweir 	 OTableDesignUndoAct( pOwner ,STR_TABED_UNDO_CELLMODIFIED)
121*cdf0e10cSrcweir 	,m_nCol( nColumn )
122*cdf0e10cSrcweir 	,m_nRow( nRowID )
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir 	DBG_CTOR(OTableDesignCellUndoAct,NULL);
125*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
126*cdf0e10cSrcweir 	// Text an der Position (m_nRow, m_nCol) auslesen
127*cdf0e10cSrcweir 	m_sOldText = m_pTabDgnCtrl->GetCellData( m_nRow, m_nCol );
128*cdf0e10cSrcweir }
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir //-------------------------------------------------------------------------
131*cdf0e10cSrcweir OTableDesignCellUndoAct::~OTableDesignCellUndoAct()
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir 	DBG_DTOR(OTableDesignCellUndoAct,NULL);
134*cdf0e10cSrcweir }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir //-------------------------------------------------------------------------
137*cdf0e10cSrcweir void OTableDesignCellUndoAct::Undo()
138*cdf0e10cSrcweir {
139*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
140*cdf0e10cSrcweir 	// Neuen Text der alten Zelle speichern und alten wieder einsetzen
141*cdf0e10cSrcweir 	m_pTabDgnCtrl->ActivateCell( m_nRow, m_nCol );
142*cdf0e10cSrcweir 	m_sNewText = m_pTabDgnCtrl->GetCellData( m_nRow, m_nCol );
143*cdf0e10cSrcweir 	m_pTabDgnCtrl->SetCellData( m_nRow, m_nCol, m_sOldText );
144*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
145*cdf0e10cSrcweir 	// Wenn erstes Undo zurueckgenommen wurde, ist Zelle nicht mehr modifiziert
146*cdf0e10cSrcweir 	if (m_pTabDgnCtrl->GetCurUndoActId() == 1)
147*cdf0e10cSrcweir 	{
148*cdf0e10cSrcweir 		CellControllerRef xController = m_pTabDgnCtrl->Controller();
149*cdf0e10cSrcweir 		if ( xController.Is() )
150*cdf0e10cSrcweir 			xController->ClearModified();
151*cdf0e10cSrcweir 		m_pTabDgnCtrl->GetView()->getController().setModified(sal_False);
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 	}
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 	OTableDesignUndoAct::Undo();
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir //-------------------------------------------------------------------------
159*cdf0e10cSrcweir void OTableDesignCellUndoAct::Redo()
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
162*cdf0e10cSrcweir 	// Neuen Text wieder einseten
163*cdf0e10cSrcweir 	m_pTabDgnCtrl->ActivateCell( m_nRow, m_nCol );
164*cdf0e10cSrcweir 	m_pTabDgnCtrl->SetCellData( m_nRow, m_nCol, m_sNewText );
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 	OTableDesignUndoAct::Redo();
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir //==============================================================================
170*cdf0e10cSrcweir // class OTableEditorUndoAct
171*cdf0e10cSrcweir //==============================================================================
172*cdf0e10cSrcweir DBG_NAME(OTableEditorUndoAct);
173*cdf0e10cSrcweir OTableEditorUndoAct::OTableEditorUndoAct( OTableEditorCtrl* pOwner,sal_uInt16 _nCommentID ) :
174*cdf0e10cSrcweir 	 OTableDesignUndoAct(  pOwner ,_nCommentID)
175*cdf0e10cSrcweir 	,pTabEdCtrl(pOwner)
176*cdf0e10cSrcweir {
177*cdf0e10cSrcweir 	DBG_CTOR(OTableEditorUndoAct,NULL);
178*cdf0e10cSrcweir }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir //-------------------------------------------------------------------------
181*cdf0e10cSrcweir OTableEditorUndoAct::~OTableEditorUndoAct()
182*cdf0e10cSrcweir {
183*cdf0e10cSrcweir 	DBG_DTOR(OTableEditorUndoAct,NULL);
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir //==============================================================================
187*cdf0e10cSrcweir // class OTableEditorTypeSelUndoAct
188*cdf0e10cSrcweir //==============================================================================
189*cdf0e10cSrcweir DBG_NAME(OTableEditorTypeSelUndoAct);
190*cdf0e10cSrcweir OTableEditorTypeSelUndoAct::OTableEditorTypeSelUndoAct( OTableEditorCtrl* pOwner, long nRowID, sal_uInt16 nColumn, const TOTypeInfoSP& _pOldType )
191*cdf0e10cSrcweir     :OTableEditorUndoAct( pOwner ,STR_TABED_UNDO_TYPE_CHANGED)
192*cdf0e10cSrcweir 	,m_nCol( nColumn )
193*cdf0e10cSrcweir 	,m_nRow( nRowID )
194*cdf0e10cSrcweir 	,m_pOldType( _pOldType )
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir 	DBG_CTOR(OTableEditorTypeSelUndoAct,NULL);
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir //-------------------------------------------------------------------------
200*cdf0e10cSrcweir OTableEditorTypeSelUndoAct::~OTableEditorTypeSelUndoAct()
201*cdf0e10cSrcweir {
202*cdf0e10cSrcweir 	DBG_DTOR(OTableEditorTypeSelUndoAct,NULL);
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir //-------------------------------------------------------------------------
206*cdf0e10cSrcweir void OTableEditorTypeSelUndoAct::Undo()
207*cdf0e10cSrcweir {
208*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
209*cdf0e10cSrcweir 	// Typ zuruecksetzen
210*cdf0e10cSrcweir 	OFieldDescription* pFieldDesc = pTabEdCtrl->GetFieldDescr(m_nRow);
211*cdf0e10cSrcweir 	if(pFieldDesc)
212*cdf0e10cSrcweir 		m_pNewType = pFieldDesc->getTypeInfo();
213*cdf0e10cSrcweir 	else
214*cdf0e10cSrcweir 		m_pNewType = TOTypeInfoSP();
215*cdf0e10cSrcweir 	pTabEdCtrl->SetCellData(m_nRow,m_nCol,m_pOldType);
216*cdf0e10cSrcweir 	pTabEdCtrl->SwitchType( m_pOldType );
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 	OTableEditorUndoAct::Undo();
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir //-------------------------------------------------------------------------
222*cdf0e10cSrcweir void OTableEditorTypeSelUndoAct::Redo()
223*cdf0e10cSrcweir {
224*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
225*cdf0e10cSrcweir 	// Neuen Typ
226*cdf0e10cSrcweir 	pTabEdCtrl->GoToRowColumnId( m_nRow ,m_nCol);
227*cdf0e10cSrcweir 	pTabEdCtrl->SetCellData(m_nRow,m_nCol,m_pNewType);
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 	OTableEditorUndoAct::Redo();
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir //==============================================================================
233*cdf0e10cSrcweir // class OTableEditorDelUndoAct
234*cdf0e10cSrcweir //==============================================================================
235*cdf0e10cSrcweir DBG_NAME(OTableEditorDelUndoAct);
236*cdf0e10cSrcweir OTableEditorDelUndoAct::OTableEditorDelUndoAct( OTableEditorCtrl* pOwner) :
237*cdf0e10cSrcweir 	 OTableEditorUndoAct( pOwner ,STR_TABED_UNDO_ROWDELETED)
238*cdf0e10cSrcweir {
239*cdf0e10cSrcweir 	DBG_CTOR(OTableEditorDelUndoAct,NULL);
240*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
241*cdf0e10cSrcweir 	// DeletedRowList fuellen
242*cdf0e10cSrcweir 	::std::vector< ::boost::shared_ptr<OTableRow> >* pOriginalRows = pOwner->GetRowList();
243*cdf0e10cSrcweir 	long nIndex = pOwner->FirstSelectedRow();
244*cdf0e10cSrcweir 	 ::boost::shared_ptr<OTableRow>  pOriginalRow;
245*cdf0e10cSrcweir 	 ::boost::shared_ptr<OTableRow>  pNewRow;
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 	while( nIndex >= 0 )
248*cdf0e10cSrcweir 	{
249*cdf0e10cSrcweir 		pOriginalRow = (*pOriginalRows)[nIndex];
250*cdf0e10cSrcweir 		pNewRow.reset(new OTableRow( *pOriginalRow, nIndex ));
251*cdf0e10cSrcweir 		m_aDeletedRows.push_back( pNewRow);
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir 		nIndex = pOwner->NextSelectedRow();
254*cdf0e10cSrcweir 	}
255*cdf0e10cSrcweir }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir //-------------------------------------------------------------------------
258*cdf0e10cSrcweir OTableEditorDelUndoAct::~OTableEditorDelUndoAct()
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir 	DBG_DTOR(OTableEditorDelUndoAct,NULL);
261*cdf0e10cSrcweir 	m_aDeletedRows.clear();
262*cdf0e10cSrcweir }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir //-------------------------------------------------------------------------
265*cdf0e10cSrcweir void OTableEditorDelUndoAct::Undo()
266*cdf0e10cSrcweir {
267*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
268*cdf0e10cSrcweir 	// Geloeschte Zeilen wieder einfuegen
269*cdf0e10cSrcweir 	sal_uLong nPos;
270*cdf0e10cSrcweir 	::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aIter = m_aDeletedRows.begin();
271*cdf0e10cSrcweir     ::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aEnd = m_aDeletedRows.end();
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 	 ::boost::shared_ptr<OTableRow>  pNewOrigRow;
274*cdf0e10cSrcweir 	::std::vector< ::boost::shared_ptr<OTableRow> >* pOriginalRows = pTabEdCtrl->GetRowList();
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir 	for(;aIter != aEnd;++aIter)
277*cdf0e10cSrcweir 	{
278*cdf0e10cSrcweir 		pNewOrigRow.reset(new OTableRow( **aIter ));
279*cdf0e10cSrcweir 		nPos = (*aIter)->GetPos();
280*cdf0e10cSrcweir 		pOriginalRows->insert( pOriginalRows->begin()+nPos,pNewOrigRow);
281*cdf0e10cSrcweir 	}
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir     pTabEdCtrl->DisplayData(pTabEdCtrl->GetCurRow());
284*cdf0e10cSrcweir 	pTabEdCtrl->Invalidate();
285*cdf0e10cSrcweir 	OTableEditorUndoAct::Undo();
286*cdf0e10cSrcweir }
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir //-------------------------------------------------------------------------
289*cdf0e10cSrcweir void OTableEditorDelUndoAct::Redo()
290*cdf0e10cSrcweir {
291*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
292*cdf0e10cSrcweir 	// Zeilen wieder loeschen
293*cdf0e10cSrcweir 	sal_uLong nPos;
294*cdf0e10cSrcweir 	::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aIter = m_aDeletedRows.begin();
295*cdf0e10cSrcweir     ::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aEnd = m_aDeletedRows.end();
296*cdf0e10cSrcweir 	::std::vector< ::boost::shared_ptr<OTableRow> >* pOriginalRows = pTabEdCtrl->GetRowList();
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 	for(;aIter != aEnd;++aIter)
299*cdf0e10cSrcweir 	{
300*cdf0e10cSrcweir 		nPos = (*aIter)->GetPos();
301*cdf0e10cSrcweir 		pOriginalRows->erase( pOriginalRows->begin()+nPos );
302*cdf0e10cSrcweir 	}
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir     pTabEdCtrl->DisplayData(pTabEdCtrl->GetCurRow());
305*cdf0e10cSrcweir 	pTabEdCtrl->Invalidate();
306*cdf0e10cSrcweir 	OTableEditorUndoAct::Redo();
307*cdf0e10cSrcweir }
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir //-------------------------------------------------------------------------
310*cdf0e10cSrcweir //==============================================================================
311*cdf0e10cSrcweir // class OTableEditorInsUndoAct
312*cdf0e10cSrcweir //==============================================================================
313*cdf0e10cSrcweir DBG_NAME(OTableEditorInsUndoAct);
314*cdf0e10cSrcweir OTableEditorInsUndoAct::OTableEditorInsUndoAct( OTableEditorCtrl* pOwner,
315*cdf0e10cSrcweir 											   long nInsertPosition ,
316*cdf0e10cSrcweir 											   const ::std::vector<  ::boost::shared_ptr<OTableRow> >& _vInsertedRows)
317*cdf0e10cSrcweir 	:OTableEditorUndoAct( pOwner,STR_TABED_UNDO_ROWINSERTED )
318*cdf0e10cSrcweir 	,m_vInsertedRows(_vInsertedRows)
319*cdf0e10cSrcweir 	,m_nInsPos( nInsertPosition )
320*cdf0e10cSrcweir {
321*cdf0e10cSrcweir 	DBG_CTOR(OTableEditorInsUndoAct,NULL);
322*cdf0e10cSrcweir }
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir //-------------------------------------------------------------------------
325*cdf0e10cSrcweir OTableEditorInsUndoAct::~OTableEditorInsUndoAct()
326*cdf0e10cSrcweir {
327*cdf0e10cSrcweir 	DBG_DTOR(OTableEditorInsUndoAct,NULL);
328*cdf0e10cSrcweir 	m_vInsertedRows.clear();
329*cdf0e10cSrcweir }
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir //-------------------------------------------------------------------------
332*cdf0e10cSrcweir void OTableEditorInsUndoAct::Undo()
333*cdf0e10cSrcweir {
334*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
335*cdf0e10cSrcweir 	// Eingefuegte Zeilen wieder loeschen
336*cdf0e10cSrcweir 	::std::vector< ::boost::shared_ptr<OTableRow> >* pOriginalRows = pTabEdCtrl->GetRowList();
337*cdf0e10cSrcweir 	for( long i=(m_nInsPos+m_vInsertedRows.size()-1); i>(m_nInsPos-1); i-- )
338*cdf0e10cSrcweir 	{
339*cdf0e10cSrcweir 		pOriginalRows->erase(pOriginalRows->begin()+i);
340*cdf0e10cSrcweir 	}
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 	pTabEdCtrl->RowRemoved( m_nInsPos, m_vInsertedRows.size(), sal_True );
343*cdf0e10cSrcweir 	pTabEdCtrl->InvalidateHandleColumn();
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 	OTableEditorUndoAct::Undo();
346*cdf0e10cSrcweir }
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir //-------------------------------------------------------------------------
349*cdf0e10cSrcweir void OTableEditorInsUndoAct::Redo()
350*cdf0e10cSrcweir {
351*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
352*cdf0e10cSrcweir 	// Zeilen wieder einfuegen
353*cdf0e10cSrcweir 	long nInsertRow = m_nInsPos;
354*cdf0e10cSrcweir 	 ::boost::shared_ptr<OTableRow>  pRow;
355*cdf0e10cSrcweir 	::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aIter = m_vInsertedRows.begin();
356*cdf0e10cSrcweir     ::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aEnd = m_vInsertedRows.end();
357*cdf0e10cSrcweir 	::std::vector< ::boost::shared_ptr<OTableRow> >* pRowList = pTabEdCtrl->GetRowList();
358*cdf0e10cSrcweir 	for(;aIter != aEnd;++aIter)
359*cdf0e10cSrcweir 	{
360*cdf0e10cSrcweir 		pRow.reset(new OTableRow( **aIter ));
361*cdf0e10cSrcweir 		pRowList->insert( pRowList->begin()+nInsertRow ,pRow );
362*cdf0e10cSrcweir 		nInsertRow++;
363*cdf0e10cSrcweir 	}
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir 	pTabEdCtrl->RowInserted( m_nInsPos, m_vInsertedRows.size(), sal_True );
366*cdf0e10cSrcweir 	pTabEdCtrl->InvalidateHandleColumn();
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir 	OTableEditorUndoAct::Redo();
369*cdf0e10cSrcweir }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir //==============================================================================
372*cdf0e10cSrcweir // class OTableEditorInsNewUndoAct
373*cdf0e10cSrcweir //==============================================================================
374*cdf0e10cSrcweir DBG_NAME(OTableEditorInsNewUndoAct);
375*cdf0e10cSrcweir OTableEditorInsNewUndoAct::OTableEditorInsNewUndoAct( OTableEditorCtrl* pOwner, long nInsertPosition, long nInsertedRows ) :
376*cdf0e10cSrcweir 	 OTableEditorUndoAct( pOwner ,STR_TABED_UNDO_NEWROWINSERTED)
377*cdf0e10cSrcweir 	,m_nInsPos( nInsertPosition )
378*cdf0e10cSrcweir 	,m_nInsRows( nInsertedRows )
379*cdf0e10cSrcweir {
380*cdf0e10cSrcweir 	DBG_CTOR(OTableEditorInsNewUndoAct,NULL);
381*cdf0e10cSrcweir }
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir //-------------------------------------------------------------------------
384*cdf0e10cSrcweir OTableEditorInsNewUndoAct::~OTableEditorInsNewUndoAct()
385*cdf0e10cSrcweir {
386*cdf0e10cSrcweir 	DBG_DTOR(OTableEditorInsNewUndoAct,NULL);
387*cdf0e10cSrcweir }
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir //-------------------------------------------------------------------------
390*cdf0e10cSrcweir void OTableEditorInsNewUndoAct::Undo()
391*cdf0e10cSrcweir {
392*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
393*cdf0e10cSrcweir 	// Eingefuegte Zeilen wieder loeschen
394*cdf0e10cSrcweir 	::std::vector< ::boost::shared_ptr<OTableRow> >* pOriginalRows = pTabEdCtrl->GetRowList();
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir 	for( long i=(m_nInsPos+m_nInsRows-1); i>(m_nInsPos-1); i-- )
397*cdf0e10cSrcweir 	{
398*cdf0e10cSrcweir 		pOriginalRows->erase(pOriginalRows->begin()+i);
399*cdf0e10cSrcweir 	}
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 	pTabEdCtrl->RowRemoved( m_nInsPos, m_nInsRows, sal_True );
402*cdf0e10cSrcweir 	pTabEdCtrl->InvalidateHandleColumn();
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir 	OTableEditorUndoAct::Undo();
405*cdf0e10cSrcweir }
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir //-------------------------------------------------------------------------
408*cdf0e10cSrcweir void OTableEditorInsNewUndoAct::Redo()
409*cdf0e10cSrcweir {
410*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
411*cdf0e10cSrcweir 	// Zeilen wieder einfuegen
412*cdf0e10cSrcweir 	::std::vector< ::boost::shared_ptr<OTableRow> >* pRowList = pTabEdCtrl->GetRowList();
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir 	for( long i=m_nInsPos; i<(m_nInsPos+m_nInsRows); i++ )
415*cdf0e10cSrcweir 		pRowList->insert( pRowList->begin()+i,::boost::shared_ptr<OTableRow>(new OTableRow()) );
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 	pTabEdCtrl->RowInserted( m_nInsPos, m_nInsRows, sal_True );
418*cdf0e10cSrcweir 	pTabEdCtrl->InvalidateHandleColumn();
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 	OTableEditorUndoAct::Redo();
421*cdf0e10cSrcweir }
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir //-------------------------------------------------------------------------
424*cdf0e10cSrcweir //========================================================================
425*cdf0e10cSrcweir // class OPrimKeyUndoAct
426*cdf0e10cSrcweir //========================================================================
427*cdf0e10cSrcweir DBG_NAME(OPrimKeyUndoAct);
428*cdf0e10cSrcweir //-------------------------------------------------------------------------
429*cdf0e10cSrcweir OPrimKeyUndoAct::OPrimKeyUndoAct( OTableEditorCtrl* pOwner, MultiSelection aDeletedKeys, MultiSelection aInsertedKeys) :
430*cdf0e10cSrcweir 	 OTableEditorUndoAct( pOwner ,STR_TABLEDESIGN_UNDO_PRIMKEY)
431*cdf0e10cSrcweir 	,m_aDelKeys( aDeletedKeys )
432*cdf0e10cSrcweir 	,m_aInsKeys( aInsertedKeys )
433*cdf0e10cSrcweir 	,m_pEditorCtrl( pOwner )
434*cdf0e10cSrcweir {
435*cdf0e10cSrcweir 	DBG_CTOR(OPrimKeyUndoAct,NULL);
436*cdf0e10cSrcweir }
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir //-------------------------------------------------------------------------
439*cdf0e10cSrcweir OPrimKeyUndoAct::~OPrimKeyUndoAct()
440*cdf0e10cSrcweir {
441*cdf0e10cSrcweir 	DBG_DTOR(OPrimKeyUndoAct,NULL);
442*cdf0e10cSrcweir }
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir //-------------------------------------------------------------------------
445*cdf0e10cSrcweir void OPrimKeyUndoAct::Undo()
446*cdf0e10cSrcweir {
447*cdf0e10cSrcweir 	::std::vector< ::boost::shared_ptr<OTableRow> >* pRowList = pTabEdCtrl->GetRowList();
448*cdf0e10cSrcweir 	::boost::shared_ptr<OTableRow>  pRow;
449*cdf0e10cSrcweir 	long nIndex;
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
452*cdf0e10cSrcweir 	// Die eingefuegten Keys loeschen
453*cdf0e10cSrcweir 	for( nIndex = m_aInsKeys.FirstSelected(); nIndex != (long)SFX_ENDOFSELECTION; nIndex=m_aInsKeys.NextSelected() )
454*cdf0e10cSrcweir 	{
455*cdf0e10cSrcweir 		OSL_ENSURE(nIndex <= static_cast<long>(pRowList->size()),"Index for undo isn't valid!");
456*cdf0e10cSrcweir 		pRow = (*pRowList)[nIndex];
457*cdf0e10cSrcweir 		pRow->SetPrimaryKey( sal_False );
458*cdf0e10cSrcweir 	}
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
461*cdf0e10cSrcweir 	// Die geloeschten Keys herstellen
462*cdf0e10cSrcweir 	for( nIndex = m_aDelKeys.FirstSelected(); nIndex != (long)SFX_ENDOFSELECTION; nIndex=m_aDelKeys.NextSelected() )
463*cdf0e10cSrcweir 	{
464*cdf0e10cSrcweir 		OSL_ENSURE(nIndex <= static_cast<long>(pRowList->size()),"Index for undo isn't valid!");
465*cdf0e10cSrcweir 		pRow = (*pRowList)[nIndex];
466*cdf0e10cSrcweir 		pRow->SetPrimaryKey( sal_True );
467*cdf0e10cSrcweir 	}
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir 	m_pEditorCtrl->InvalidateHandleColumn();
470*cdf0e10cSrcweir 	OTableEditorUndoAct::Undo();
471*cdf0e10cSrcweir }
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir //-------------------------------------------------------------------------
474*cdf0e10cSrcweir void OPrimKeyUndoAct::Redo()
475*cdf0e10cSrcweir {
476*cdf0e10cSrcweir 	::std::vector< ::boost::shared_ptr<OTableRow> >* pRowList = pTabEdCtrl->GetRowList();
477*cdf0e10cSrcweir 	long nIndex;
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
480*cdf0e10cSrcweir 	// Die geloeschten Keys loeschen
481*cdf0e10cSrcweir     for( nIndex = m_aDelKeys.FirstSelected(); nIndex != (long)SFX_ENDOFSELECTION; nIndex=m_aDelKeys.NextSelected() )
482*cdf0e10cSrcweir 		(*pRowList)[nIndex]->SetPrimaryKey( sal_False );
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
485*cdf0e10cSrcweir 	// Die eingefuegten Keys herstellen
486*cdf0e10cSrcweir     for( nIndex = m_aInsKeys.FirstSelected(); nIndex != (long)SFX_ENDOFSELECTION; nIndex=m_aInsKeys.NextSelected() )
487*cdf0e10cSrcweir 		(*pRowList)[nIndex]->SetPrimaryKey( sal_True );
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir 	m_pEditorCtrl->InvalidateHandleColumn();
490*cdf0e10cSrcweir 	OTableEditorUndoAct::Redo();
491*cdf0e10cSrcweir }
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir 
496