1 /************************************************************************/
2 /* */
3 /* Editor functionality. */
4 /* */
5 /************************************************************************/
6
7 # include "tedConfig.h"
8
9 # include <stddef.h>
10 # include <stdio.h>
11 # include <ctype.h>
12
13 # include "tedEdit.h"
14 # include "tedDocFront.h"
15 # include <docRtfTrace.h>
16 # include <docEditImpl.h>
17 # include <docTreeNode.h>
18 # include <docNodeTree.h>
19 # include <docEditCommand.h>
20
21 # include <appDebugon.h>
22
23 /************************************************************************/
24 /* */
25 /* Delete the current paragraph from a document. */
26 /* */
27 /************************************************************************/
28
tedEditDeleteSelectedParagaphs(DocumentPosition * dpNew,int * pSide,TedEditOperation * teo)29 static int tedEditDeleteSelectedParagaphs( DocumentPosition * dpNew,
30 int * pSide,
31 TedEditOperation * teo )
32 {
33 int rval= 0;
34 EditOperation * eo= &(teo->teoEo);
35
36 BufferItem * parentNode;
37 int child0;
38 int child1;
39
40 const int direction= 0;
41 int side;
42
43 DocumentSelection dsParas;
44
45 docInitDocumentSelection( &dsParas );
46 docEditOperationGetSelection( &dsParas, eo );
47 if ( docSelectWholeParagraph( &dsParas, direction ) )
48 { LDEB(1); rval= -1; goto ready; }
49
50 if ( docEditDeleteFieldsForBlockDelete( eo, &dsParas ) )
51 { LDEB(1); rval= -1; goto ready; }
52
53 if ( docEditFindPositionOutsideBlockDelete( &side, dpNew, &dsParas ) )
54 { LDEB(1); rval= -1; goto ready; }
55
56 parentNode= dsParas.dsHead.dpNode->biParent;
57 child0= dsParas.dsHead.dpNode->biNumberInParent;
58 child1= dsParas.dsTail.dpNode->biNumberInParent;
59
60 if ( child0 <= child1 )
61 {
62 int firstParaDeleted= -1;
63 int sectionsDeleted= 0;
64 int paragraphsDeleted= 0;
65
66 tedEditIncludeNodeInRedraw( teo, dsParas.dsHead.dpNode );
67
68 docEditDeleteNodes( eo, §ionsDeleted,
69 &firstParaDeleted, ¶graphsDeleted,
70 parentNode, child0, child1- child0+ 1 );
71
72 docEditIncludeNodeInReformatRange( eo, parentNode );
73 eo->eoHeadDp= *dpNew;
74 eo->eoTailDp= *dpNew;
75 }
76
77 *pSide= side;
78
79 ready:
80
81 return rval;
82 }
83
tedDocDeleteSelectedParagraphs(EditDocument * ed,int traced)84 int tedDocDeleteSelectedParagraphs( EditDocument * ed,
85 int traced )
86 {
87 int rval= 0;
88 TedEditOperation teo;
89 EditOperation * eo= &(teo.teoEo);
90 SelectionGeometry sg;
91 SelectionDescription sd;
92
93 DocumentPosition dpNew;
94 int allChildren= 0;
95 int side;
96 DocumentSelection dsTraced;
97
98 const int fullWidth= 1;
99
100 tedStartEditOperation( &teo, &sg, &sd, ed, fullWidth, traced );
101
102 if ( ! sd.sdInContiguousParagraphs )
103 { LDEB(sd.sdInContiguousParagraphs); rval= -1; goto ready; }
104
105 if ( eo->eoHeadDp.dpNode->biNumberInParent == 0 )
106 {
107 BufferItem * parentNode= eo->eoHeadDp.dpNode->biParent;
108
109 if ( eo->eoTailDp.dpNode->biNumberInParent ==
110 parentNode->biChildCount -1 )
111 { allChildren= 1; }
112 }
113
114 if ( allChildren )
115 {
116 if ( tedEditStartReplace( &dsTraced, &teo,
117 EDITcmdDELETE_PARA, DOClevPARA, 0 ) )
118 { LDEB(1); goto ready; }
119
120 /* Fraudulous HACK */
121 if ( docHeadPosition( &(eo->eoHeadDp), eo->eoHeadDp.dpNode ) )
122 { LDEB(1); goto ready; }
123 if ( docTailPosition( &(eo->eoTailDp), eo->eoTailDp.dpNode ) )
124 { LDEB(1); goto ready; }
125 eo->eoLastDp= eo->eoTailDp;
126
127 if ( tedDeleteSelectionImpl( &teo ) )
128 { LDEB(allChildren); goto ready; }
129 }
130 else{
131 if ( tedEditStartReplace( &dsTraced, &teo,
132 EDITcmdDELETE_PARA, DOClevPARA, 0 ) )
133 { LDEB(1); rval= -1; goto ready; }
134
135 if ( tedEditDeleteSelectedParagaphs( &dpNew, &side, &teo ) )
136 { LDEB(1); rval= -1; goto ready; }
137
138 docSetIBarRange( &(eo->eoAffectedRange), &dpNew );
139 docSetIBarRange( &(eo->eoSelectedRange), &dpNew );
140 tedEditFinishSelectionTail( &teo );
141
142 if ( teo.teoEditTrace )
143 {
144 const SelectionScope * const s0= (const SelectionScope *)0;
145
146 if ( side > 0 )
147 { docRtfTraceNewPosition( eo, s0, SELposAFTER ); }
148 else{ docRtfTraceNewPosition( eo, s0, SELposBEFORE ); }
149 }
150
151 tedFinishEditOperation( &teo );
152 }
153
154 ready:
155
156 tedCleanEditOperation( &teo );
157
158 return rval;
159 }
160
tedDocDeleteCurrentFrame(EditDocument * ed,int traced)161 int tedDocDeleteCurrentFrame( EditDocument * ed,
162 int traced )
163 {
164 if ( tedDocSelectCurrentFrame( ed ) )
165 { LDEB(1); return -1; }
166
167 return tedDocDeleteSelectedParagraphs( ed, traced );
168 }
169
170 /************************************************************************/
171 /* */
172 /* Delete the current section. */
173 /* */
174 /************************************************************************/
175
tedEditDeleteSelectedSections(DocumentPosition * dpNew,int * pSide,BufferItem * sectNode0,BufferItem * sectNode1,TedEditOperation * teo)176 static int tedEditDeleteSelectedSections(
177 DocumentPosition * dpNew,
178 int * pSide,
179 BufferItem * sectNode0,
180 BufferItem * sectNode1,
181 TedEditOperation * teo )
182 {
183 int rval= 0;
184 EditOperation * eo= &(teo->teoEo);
185
186 BufferItem * parentNode;
187 int child0;
188 int child1;
189
190 const int direction= 0;
191 int side;
192
193 DocumentSelection dsSects;
194
195 docInitDocumentSelection( &dsSects );
196 docEditOperationGetSelection( &dsSects, eo );
197 if ( docSelectWholeSection( &dsSects, direction ) )
198 { LDEB(1); rval= -1; goto ready; }
199
200 if ( docEditDeleteFieldsForBlockDelete( eo, &dsSects ) )
201 { LDEB(1); rval= -1; goto ready; }
202
203 if ( docEditFindPositionOutsideBlockDelete( &side, dpNew, &dsSects ) )
204 { LDEB(1); rval= -1; goto ready; }
205
206 parentNode= sectNode0->biParent;
207 child0= sectNode0->biNumberInParent;
208 child1= sectNode1->biNumberInParent;
209
210 if ( child0 <= child1 )
211 {
212 int firstParaDeleted= -1;
213 int sectionsDeleted= 0;
214 int paragraphsDeleted= 0;
215
216 tedEditIncludeNodeInRedraw( teo, sectNode0 );
217
218 docEditDeleteNodes( eo, §ionsDeleted,
219 &firstParaDeleted, ¶graphsDeleted,
220 parentNode, child0, child1- child0+ 1 );
221
222 docEditIncludeNodeInReformatRange( eo, parentNode );
223 eo->eoHeadDp= *dpNew;
224 eo->eoTailDp= *dpNew;
225
226 docGetSelectionScope( &(eo->eoSelectionScope), dpNew->dpNode );
227 }
228
229 *pSide= side;
230
231 ready:
232
233 return rval;
234 }
235
236 /************************************************************************/
237 /* */
238 /* Delete the current section. */
239 /* */
240 /************************************************************************/
241
tedDocDeleteSelectedSections(EditDocument * ed,int traced)242 int tedDocDeleteSelectedSections( EditDocument * ed,
243 int traced )
244 {
245 int rval= 0;
246
247 TedEditOperation teo;
248 EditOperation * eo= &(teo.teoEo);
249 SelectionGeometry sg;
250 SelectionDescription sd;
251
252 DocumentPosition dpNew;
253 int side;
254 int allChildren= 0;
255
256 BufferItem * sectNode0;
257 BufferItem * sectNode1;
258 DocumentSelection dsTraced;
259
260 const int fullWidth= 1;
261
262 tedStartEditOperation( &teo, &sg, &sd, ed, fullWidth, traced );
263
264 sectNode0= docGetSectNode( eo->eoHeadDp.dpNode );
265 sectNode1= docGetSectNode( eo->eoTailDp.dpNode );
266 if ( ! sectNode0 || ! sectNode1 )
267 { XXDEB(sectNode0,sectNode1); rval= -1; goto ready; }
268 if ( ! sectNode0->biParent ||
269 sectNode0->biParent != sectNode1->biParent )
270 {
271 XXDEB(sectNode0->biParent,sectNode1->biParent);
272 rval= -1; goto ready;
273 }
274
275 if ( sectNode0->biNumberInParent == 0 )
276 {
277 BufferItem * parentNode= sectNode0->biParent;
278
279 if ( sectNode1->biNumberInParent == parentNode->biChildCount -1 )
280 { allChildren= 1; }
281 }
282
283 if ( allChildren )
284 {
285 if ( tedEditStartReplace( &dsTraced, &teo,
286 EDITcmdDELETE_SECT, DOClevSECT, 0 ) )
287 { LDEB(1); goto ready; }
288
289 /* Fraudulous HACK */
290 if ( docHeadPosition( &(eo->eoHeadDp), sectNode0 ) )
291 { LDEB(1); goto ready; }
292 if ( docTailPosition( &(eo->eoTailDp), sectNode1 ) )
293 { LDEB(1); goto ready; }
294 eo->eoLastDp= eo->eoTailDp;
295
296 if ( tedDeleteSelectionImpl( &teo ) )
297 { LDEB(allChildren); goto ready; }
298 }
299 else{
300 if ( tedEditStartReplace( &dsTraced, &teo,
301 EDITcmdDELETE_SECT, DOClevSECT, 0 ) )
302 { LDEB(1); goto ready; }
303
304 if ( tedEditDeleteSelectedSections( &dpNew, &side,
305 sectNode0, sectNode1, &teo ) )
306 { LDEB(1); rval= -1; goto ready; }
307
308 docSetIBarRange( &(eo->eoAffectedRange), &dpNew );
309 docSetIBarRange( &(eo->eoSelectedRange), &dpNew );
310 tedEditFinishSelectionTail( &teo );
311
312 if ( teo.teoEditTrace )
313 {
314 const SelectionScope * const s0= (const SelectionScope *)0;
315
316 if ( side > 0 )
317 { docRtfTraceNewPosition( eo, s0, SELposAFTER ); }
318 else{ docRtfTraceNewPosition( eo, s0, SELposBEFORE ); }
319 }
320
321 tedFinishEditOperation( &teo );
322 }
323
324 ready:
325
326 tedCleanEditOperation( &teo );
327
328 return rval;
329 }
330
331