1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_editeng.hxx"
26 
27 #include <svl/intitem.hxx>
28 #include <editeng/editeng.hxx>
29 #include <editeng/editview.hxx>
30 #include <editeng/editdata.hxx>
31 #include <editeng/eerdll.hxx>
32 #include <editeng/lrspitem.hxx>
33 #include <editeng/fhgtitem.hxx>
34 
35 #define _OUTLINER_CXX
36 #include <editeng/outliner.hxx>
37 #include <outlundo.hxx>
38 
39 
OutlinerUndoBase(sal_uInt16 _nId,Outliner * pOutliner)40 OutlinerUndoBase::OutlinerUndoBase( sal_uInt16 _nId, Outliner* pOutliner )
41 	: EditUndo( _nId, NULL )
42 {
43 	DBG_ASSERT( pOutliner, "Undo: Outliner?!" );
44 	mpOutliner = pOutliner;
45 }
46 
OutlinerUndoChangeParaFlags(Outliner * pOutliner,sal_uInt32 nPara,sal_uInt16 nOldFlags,sal_uInt16 nNewFlags)47 OutlinerUndoChangeParaFlags::OutlinerUndoChangeParaFlags( Outliner* pOutliner, sal_uInt32 nPara, sal_uInt16 nOldFlags, sal_uInt16 nNewFlags )
48 : OutlinerUndoBase( OLUNDO_DEPTH, pOutliner )
49 {
50 	mnPara = nPara;
51 	mnOldFlags = nOldFlags;
52 	mnNewFlags = nNewFlags;
53 }
54 
Undo()55 void OutlinerUndoChangeParaFlags::Undo()
56 {
57 	ImplChangeFlags( mnOldFlags );
58 }
59 
Redo()60 void OutlinerUndoChangeParaFlags::Redo()
61 {
62 	ImplChangeFlags( mnNewFlags );
63 }
64 
ImplChangeFlags(sal_uInt16 nFlags)65 void OutlinerUndoChangeParaFlags::ImplChangeFlags( sal_uInt16 nFlags )
66 {
67 	Outliner* pOutliner = GetOutliner();
68 	Paragraph* pPara = pOutliner->GetParagraph( mnPara );
69 	if( pPara )
70 	{
71 		pOutliner->nDepthChangedHdlPrevDepth = pPara->GetDepth();
72 		pOutliner->mnDepthChangeHdlPrevFlags = pPara->nFlags;
73 		pOutliner->pHdlParagraph = pPara;
74 
75 		pPara->nFlags = nFlags;
76 		pOutliner->DepthChangedHdl();
77 	}
78 }
79 
OutlinerUndoChangeParaNumberingRestart(Outliner * pOutliner,sal_uInt32 nPara,sal_Int16 nOldNumberingStartValue,sal_Int16 nNewNumberingStartValue,sal_Bool bOldParaIsNumberingRestart,sal_Bool bNewParaIsNumberingRestart)80 OutlinerUndoChangeParaNumberingRestart::OutlinerUndoChangeParaNumberingRestart( Outliner* pOutliner, sal_uInt32 nPara,
81         sal_Int16 nOldNumberingStartValue, sal_Int16 nNewNumberingStartValue,
82         sal_Bool  bOldParaIsNumberingRestart, sal_Bool bNewParaIsNumberingRestart )
83 : OutlinerUndoBase( OLUNDO_DEPTH, pOutliner )
84 {
85 	mnPara = nPara;
86 
87     maUndoData.mnNumberingStartValue = nOldNumberingStartValue;
88     maUndoData.mbParaIsNumberingRestart = bOldParaIsNumberingRestart;
89     maRedoData.mnNumberingStartValue = nNewNumberingStartValue;
90     maRedoData.mbParaIsNumberingRestart = bNewParaIsNumberingRestart;
91 }
92 
Undo()93 void OutlinerUndoChangeParaNumberingRestart::Undo()
94 {
95 	ImplApplyData( maUndoData );
96 }
97 
Redo()98 void OutlinerUndoChangeParaNumberingRestart::Redo()
99 {
100 	ImplApplyData( maRedoData );
101 }
102 
ImplApplyData(const ParaRestartData & rData)103 void OutlinerUndoChangeParaNumberingRestart::ImplApplyData( const ParaRestartData& rData )
104 {
105 	Outliner* pOutliner = GetOutliner();
106     pOutliner->SetNumberingStartValue( mnPara, rData.mnNumberingStartValue );
107     pOutliner->SetParaIsNumberingRestart( mnPara, rData.mbParaIsNumberingRestart );
108 }
109 
OutlinerUndoChangeDepth(Outliner * pOutliner,sal_uInt32 nPara,sal_Int16 nOldDepth,sal_Int16 nNewDepth)110 OutlinerUndoChangeDepth::OutlinerUndoChangeDepth( Outliner* pOutliner, sal_uInt32 nPara, sal_Int16 nOldDepth, sal_Int16 nNewDepth )
111 	: OutlinerUndoBase( OLUNDO_DEPTH, pOutliner )
112 {
113 	mnPara = nPara;
114 	mnOldDepth = nOldDepth;
115 	mnNewDepth = nNewDepth;
116 }
117 
Undo()118 void OutlinerUndoChangeDepth::Undo()
119 {
120 	GetOutliner()->ImplInitDepth( mnPara, mnOldDepth, sal_False );
121 }
122 
Redo()123 void OutlinerUndoChangeDepth::Redo()
124 {
125 	GetOutliner()->ImplInitDepth( mnPara, mnNewDepth, sal_False );
126 }
127 
Repeat()128 void OutlinerUndoChangeDepth::Repeat()
129 {
130 	DBG_ERROR( "Repeat not implemented!" );
131 }
132 
133 
OutlinerUndoCheckPara(Outliner * pOutliner,sal_uInt32 nPara)134 OutlinerUndoCheckPara::OutlinerUndoCheckPara( Outliner* pOutliner, sal_uInt32 nPara )
135 	: OutlinerUndoBase( OLUNDO_DEPTH, pOutliner )
136 {
137 	mnPara = nPara;
138 }
139 
Undo()140 void OutlinerUndoCheckPara::Undo()
141 {
142 	Paragraph* pPara = GetOutliner()->GetParagraph( mnPara );
143 	pPara->Invalidate();
144 	GetOutliner()->ImplCalcBulletText( mnPara, sal_False, sal_False );
145 }
146 
Redo()147 void OutlinerUndoCheckPara::Redo()
148 {
149 	Paragraph* pPara = GetOutliner()->GetParagraph( mnPara );
150 	pPara->Invalidate();
151 	GetOutliner()->ImplCalcBulletText( mnPara, sal_False, sal_False );
152 }
153 
Repeat()154 void OutlinerUndoCheckPara::Repeat()
155 {
156 	DBG_ERROR( "Repeat not implemented!" );
157 }
158 
159 DBG_NAME(OLUndoExpand);
160 
OLUndoExpand(Outliner * pOut,sal_uInt16 _nId)161 OLUndoExpand::OLUndoExpand(Outliner* pOut, sal_uInt16 _nId )
162 	: EditUndo( _nId, 0 )
163 {
164 	DBG_CTOR(OLUndoExpand,0);
165 	DBG_ASSERT(pOut,"Undo:No Outliner");
166 	pOutliner = pOut;
167 	nCount = 0;
168 	pParas = 0;
169 }
170 
171 
~OLUndoExpand()172 OLUndoExpand::~OLUndoExpand()
173 {
174 	DBG_DTOR(OLUndoExpand,0);
175 	delete pParas;
176 }
177 
178 
Restore(sal_Bool bUndo)179 void OLUndoExpand::Restore( sal_Bool bUndo )
180 {
181 	DBG_CHKTHIS(OLUndoExpand,0);
182 	DBG_ASSERT(pOutliner,"Undo:No Outliner");
183 	DBG_ASSERT(pOutliner->pEditEngine,"Outliner already deleted");
184 	Paragraph* pPara;
185 
186 	sal_Bool bExpand = sal_False;
187 	sal_uInt16 _nId = GetId();
188 	if((_nId == OLUNDO_EXPAND && !bUndo) || (_nId == OLUNDO_COLLAPSE && bUndo))
189 		bExpand = sal_True;
190 	if( !pParas )
191 	{
192 		pPara = pOutliner->GetParagraph( nCount );
193 		if( bExpand )
194 			pOutliner->Expand( pPara );
195 		else
196 			pOutliner->Collapse( pPara );
197 	}
198 	else
199 	{
200 		for( sal_uInt32 nIdx = 0; nIdx < nCount; nIdx++ )
201 		{
202 			pPara = pOutliner->GetParagraph( pParas[nIdx] );
203 			if( bExpand )
204 				pOutliner->Expand( pPara );
205 			else
206 				pOutliner->Collapse( pPara );
207 		}
208 	}
209 }
210 
211 
Undo()212 void OLUndoExpand::Undo()
213 {
214 	DBG_CHKTHIS(OLUndoExpand,0);
215 	Restore( sal_True );
216 }
217 
218 
Redo()219 void OLUndoExpand::Redo()
220 {
221 	DBG_CHKTHIS(OLUndoExpand,0);
222 	Restore( sal_False );
223 }
224 
225 
Repeat()226 void OLUndoExpand::Repeat()
227 {
228 	DBG_CHKTHIS(OLUndoExpand,0);
229 	DBG_ERROR("Not implemented");
230 }
231