xref: /AOO41X/main/editeng/source/outliner/outlundo.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_editeng.hxx"
30 
31 #include <svl/intitem.hxx>
32 #include <editeng/editeng.hxx>
33 #include <editeng/editview.hxx>
34 #include <editeng/editdata.hxx>
35 #include <editeng/eerdll.hxx>
36 #include <editeng/lrspitem.hxx>
37 #include <editeng/fhgtitem.hxx>
38 
39 #define _OUTLINER_CXX
40 #include <editeng/outliner.hxx>
41 #include <outlundo.hxx>
42 
43 
44 OutlinerUndoBase::OutlinerUndoBase( sal_uInt16 _nId, Outliner* pOutliner )
45 	: EditUndo( _nId, NULL )
46 {
47 	DBG_ASSERT( pOutliner, "Undo: Outliner?!" );
48 	mpOutliner = pOutliner;
49 }
50 
51 OutlinerUndoChangeParaFlags::OutlinerUndoChangeParaFlags( Outliner* pOutliner, sal_uInt16 nPara, sal_uInt16 nOldFlags, sal_uInt16 nNewFlags )
52 : OutlinerUndoBase( OLUNDO_DEPTH, pOutliner )
53 {
54 	mnPara = nPara;
55 	mnOldFlags = nOldFlags;
56 	mnNewFlags = nNewFlags;
57 }
58 
59 void OutlinerUndoChangeParaFlags::Undo()
60 {
61 	ImplChangeFlags( mnOldFlags );
62 }
63 
64 void OutlinerUndoChangeParaFlags::Redo()
65 {
66 	ImplChangeFlags( mnNewFlags );
67 }
68 
69 void OutlinerUndoChangeParaFlags::ImplChangeFlags( sal_uInt16 nFlags )
70 {
71 	Outliner* pOutliner = GetOutliner();
72 	Paragraph* pPara = pOutliner->GetParagraph( mnPara );
73 	if( pPara )
74 	{
75 		pOutliner->nDepthChangedHdlPrevDepth = pPara->GetDepth();
76 		pOutliner->mnDepthChangeHdlPrevFlags = pPara->nFlags;
77 		pOutliner->pHdlParagraph = pPara;
78 
79 		pPara->nFlags = nFlags;
80 		pOutliner->DepthChangedHdl();
81 	}
82 }
83 
84 OutlinerUndoChangeParaNumberingRestart::OutlinerUndoChangeParaNumberingRestart( Outliner* pOutliner, sal_uInt16 nPara,
85         sal_Int16 nOldNumberingStartValue, sal_Int16 nNewNumberingStartValue,
86         sal_Bool  bOldParaIsNumberingRestart, sal_Bool bNewParaIsNumberingRestart )
87 : OutlinerUndoBase( OLUNDO_DEPTH, pOutliner )
88 {
89 	mnPara = nPara;
90 
91     maUndoData.mnNumberingStartValue = nOldNumberingStartValue;
92     maUndoData.mbParaIsNumberingRestart = bOldParaIsNumberingRestart;
93     maRedoData.mnNumberingStartValue = nNewNumberingStartValue;
94     maRedoData.mbParaIsNumberingRestart = bNewParaIsNumberingRestart;
95 }
96 
97 void OutlinerUndoChangeParaNumberingRestart::Undo()
98 {
99 	ImplApplyData( maUndoData );
100 }
101 
102 void OutlinerUndoChangeParaNumberingRestart::Redo()
103 {
104 	ImplApplyData( maRedoData );
105 }
106 
107 void OutlinerUndoChangeParaNumberingRestart::ImplApplyData( const ParaRestartData& rData )
108 {
109 	Outliner* pOutliner = GetOutliner();
110     pOutliner->SetNumberingStartValue( mnPara, rData.mnNumberingStartValue );
111     pOutliner->SetParaIsNumberingRestart( mnPara, rData.mbParaIsNumberingRestart );
112 }
113 
114 OutlinerUndoChangeDepth::OutlinerUndoChangeDepth( Outliner* pOutliner, sal_uInt16 nPara, sal_Int16 nOldDepth, sal_Int16 nNewDepth )
115 	: OutlinerUndoBase( OLUNDO_DEPTH, pOutliner )
116 {
117 	mnPara = nPara;
118 	mnOldDepth = nOldDepth;
119 	mnNewDepth = nNewDepth;
120 }
121 
122 void OutlinerUndoChangeDepth::Undo()
123 {
124 	GetOutliner()->ImplInitDepth( mnPara, mnOldDepth, sal_False );
125 }
126 
127 void OutlinerUndoChangeDepth::Redo()
128 {
129 	GetOutliner()->ImplInitDepth( mnPara, mnNewDepth, sal_False );
130 }
131 
132 void OutlinerUndoChangeDepth::Repeat()
133 {
134 	DBG_ERROR( "Repeat not implemented!" );
135 }
136 
137 
138 OutlinerUndoCheckPara::OutlinerUndoCheckPara( Outliner* pOutliner, sal_uInt16 nPara )
139 	: OutlinerUndoBase( OLUNDO_DEPTH, pOutliner )
140 {
141 	mnPara = nPara;
142 }
143 
144 void OutlinerUndoCheckPara::Undo()
145 {
146 	Paragraph* pPara = GetOutliner()->GetParagraph( mnPara );
147 	pPara->Invalidate();
148 	GetOutliner()->ImplCalcBulletText( mnPara, sal_False, sal_False );
149 }
150 
151 void OutlinerUndoCheckPara::Redo()
152 {
153 	Paragraph* pPara = GetOutliner()->GetParagraph( mnPara );
154 	pPara->Invalidate();
155 	GetOutliner()->ImplCalcBulletText( mnPara, sal_False, sal_False );
156 }
157 
158 void OutlinerUndoCheckPara::Repeat()
159 {
160 	DBG_ERROR( "Repeat not implemented!" );
161 }
162 
163 DBG_NAME(OLUndoExpand);
164 
165 OLUndoExpand::OLUndoExpand(Outliner* pOut, sal_uInt16 _nId )
166 	: EditUndo( _nId, 0 )
167 {
168 	DBG_CTOR(OLUndoExpand,0);
169 	DBG_ASSERT(pOut,"Undo:No Outliner");
170 	pOutliner = pOut;
171 	nCount = 0;
172 	pParas = 0;
173 }
174 
175 
176 OLUndoExpand::~OLUndoExpand()
177 {
178 	DBG_DTOR(OLUndoExpand,0);
179 	delete pParas;
180 }
181 
182 
183 void OLUndoExpand::Restore( sal_Bool bUndo )
184 {
185 	DBG_CHKTHIS(OLUndoExpand,0);
186 	DBG_ASSERT(pOutliner,"Undo:No Outliner");
187 	DBG_ASSERT(pOutliner->pEditEngine,"Outliner already deleted");
188 	Paragraph* pPara;
189 
190 	sal_Bool bExpand = sal_False;
191 	sal_uInt16 _nId = GetId();
192 	if((_nId == OLUNDO_EXPAND && !bUndo) || (_nId == OLUNDO_COLLAPSE && bUndo))
193 		bExpand = sal_True;
194 	if( !pParas )
195 	{
196 		pPara = pOutliner->GetParagraph( (sal_uLong)nCount );
197 		if( bExpand )
198 			pOutliner->Expand( pPara );
199 		else
200 			pOutliner->Collapse( pPara );
201 	}
202 	else
203 	{
204 		for( sal_uInt16 nIdx = 0; nIdx < nCount; nIdx++ )
205 		{
206 			pPara = pOutliner->GetParagraph( (sal_uLong)(pParas[nIdx]) );
207 			if( bExpand )
208 				pOutliner->Expand( pPara );
209 			else
210 				pOutliner->Collapse( pPara );
211 		}
212 	}
213 }
214 
215 
216 void OLUndoExpand::Undo()
217 {
218 	DBG_CHKTHIS(OLUndoExpand,0);
219 	Restore( sal_True );
220 }
221 
222 
223 void OLUndoExpand::Redo()
224 {
225 	DBG_CHKTHIS(OLUndoExpand,0);
226 	Restore( sal_False );
227 }
228 
229 
230 void OLUndoExpand::Repeat()
231 {
232 	DBG_CHKTHIS(OLUndoExpand,0);
233 	DBG_ERROR("Not implemented");
234 }
235