Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <wrtsh.hxx>
30 : : #include <crsskip.hxx>
31 : : #include <swcrsr.hxx>
32 : : #include <editeng/lrspitem.hxx> // #i23725#
33 : : // #134369#
34 : : #include <view.hxx>
35 : : #include <drawbase.hxx>
36 : :
37 : 0 : inline void SwWrtShell::OpenMark()
38 : : {
39 : 0 : StartAllAction();
40 : 0 : ResetCursorStack();
41 : 0 : KillPams();
42 : 0 : SetMark();
43 : 0 : }
44 : :
45 : 0 : inline void SwWrtShell::CloseMark( sal_Bool bOkFlag )
46 : : {
47 [ # # ]: 0 : if( bOkFlag )
48 : 0 : UpdateAttr();
49 : : else
50 : 0 : SwapPam();
51 : :
52 : 0 : ClearMark();
53 : 0 : EndAllAction();
54 : 0 : }
55 : :
56 : : // #i23725#
57 : 0 : sal_Bool SwWrtShell::TryRemoveIndent()
58 : : {
59 : 0 : sal_Bool bResult = sal_False;
60 : :
61 [ # # ][ # # ]: 0 : SfxItemSet aAttrSet(GetAttrPool(), RES_LR_SPACE, RES_LR_SPACE);
62 [ # # ]: 0 : GetCurAttr(aAttrSet);
63 : :
64 [ # # ][ # # ]: 0 : SvxLRSpaceItem aItem = (const SvxLRSpaceItem &)aAttrSet.Get(RES_LR_SPACE);
65 : 0 : short aOldFirstLineOfst = aItem.GetTxtFirstLineOfst();
66 : :
67 [ # # ]: 0 : if (aOldFirstLineOfst > 0)
68 : : {
69 [ # # ]: 0 : aItem.SetTxtFirstLineOfst(0);
70 : 0 : bResult = sal_True;
71 : : }
72 [ # # ]: 0 : else if (aOldFirstLineOfst < 0)
73 : : {
74 [ # # ]: 0 : aItem.SetTxtFirstLineOfst(0);
75 : 0 : aItem.SetLeft(aItem.GetLeft() + aOldFirstLineOfst);
76 : :
77 : 0 : bResult = sal_True;
78 : : }
79 [ # # ]: 0 : else if (aItem.GetLeft() != 0)
80 : : {
81 : 0 : aItem.SetLeft(0);
82 : 0 : bResult = sal_True;
83 : : }
84 : :
85 [ # # ]: 0 : if (bResult)
86 : : {
87 [ # # ]: 0 : aAttrSet.Put(aItem);
88 [ # # ]: 0 : SetAttr(aAttrSet);
89 : : }
90 : :
91 [ # # ][ # # ]: 0 : return bResult;
92 : : }
93 : :
94 : : /*------------------------------------------------------------------------
95 : : Beschreibung: Zeile loeschen
96 : : ------------------------------------------------------------------------*/
97 : :
98 : :
99 : :
100 : 0 : long SwWrtShell::DelLine()
101 : : {
102 [ # # ]: 0 : ACT_KONTEXT(this);
103 [ # # ]: 0 : ResetCursorStack();
104 : : // alten Cursor merken
105 [ # # ]: 0 : Push();
106 [ # # ]: 0 : ClearMark();
107 [ # # ]: 0 : SwCrsrShell::LeftMargin();
108 [ # # ]: 0 : SetMark();
109 [ # # ]: 0 : SwCrsrShell::RightMargin();
110 : :
111 [ # # ]: 0 : long nRet = Delete();
112 [ # # ]: 0 : Pop(sal_False);
113 [ # # ]: 0 : if( nRet )
114 : 0 : UpdateAttr();
115 [ # # ]: 0 : return nRet;
116 : : }
117 : :
118 : :
119 : :
120 : 0 : long SwWrtShell::DelToStartOfLine()
121 : : {
122 : 0 : OpenMark();
123 : 0 : SwCrsrShell::LeftMargin();
124 : 0 : long nRet = Delete();
125 : 0 : CloseMark( 0 != nRet );
126 : 0 : return nRet;
127 : : }
128 : :
129 : :
130 : :
131 : 0 : long SwWrtShell::DelToEndOfLine()
132 : : {
133 : 0 : OpenMark();
134 : 0 : SwCrsrShell::RightMargin();
135 : 0 : long nRet = Delete();
136 : 0 : CloseMark( 0 != nRet );
137 : 0 : return 1;
138 : : }
139 : :
140 : 0 : long SwWrtShell::DelLeft()
141 : : {
142 : : // wenns denn ein Fly ist, wech damit
143 : 0 : int nSelType = GetSelectionType();
144 : 0 : const int nCmp = nsSelectionType::SEL_FRM | nsSelectionType::SEL_GRF | nsSelectionType::SEL_OLE | nsSelectionType::SEL_DRW;
145 [ # # ]: 0 : if( nCmp & nSelType )
146 : : {
147 : : /* #108205# Remember object's position. */
148 [ # # ][ # # ]: 0 : Point aTmpPt = GetObjRect().TopLeft();
149 : :
150 [ # # ]: 0 : DelSelectedObj();
151 : :
152 : : /* #108205# Set cursor to remembered position. */
153 [ # # ]: 0 : SetCrsr(&aTmpPt);
154 : :
155 [ # # ]: 0 : LeaveSelFrmMode();
156 [ # # ]: 0 : UnSelectFrm();
157 : :
158 [ # # ]: 0 : nSelType = GetSelectionType();
159 [ # # ]: 0 : if ( nCmp & nSelType )
160 : : {
161 [ # # ]: 0 : EnterSelFrmMode();
162 [ # # ]: 0 : GotoNextFly();
163 : : }
164 : :
165 : 0 : return 1L;
166 : : }
167 : :
168 : : // wenn eine Selektion existiert, diese loeschen.
169 [ # # ]: 0 : if ( IsSelection() )
170 : : {
171 [ # # ][ # # ]: 0 : if( !IsBlockMode() || HasSelection() )
[ # # ]
172 : : {
173 : : //OS: wieder einmal Basic: ACT_KONTEXT muss vor
174 : : //EnterStdMode verlassen werden!
175 : : {
176 [ # # ]: 0 : ACT_KONTEXT(this);
177 [ # # ]: 0 : ResetCursorStack();
178 [ # # ]: 0 : Delete();
179 [ # # ]: 0 : UpdateAttr();
180 : : }
181 [ # # ]: 0 : if( IsBlockMode() )
182 : : {
183 : 0 : NormalizePam();
184 : 0 : ClearMark();
185 : 0 : EnterBlockMode();
186 : : }
187 : : else
188 : 0 : EnterStdMode();
189 : 0 : return 1L;
190 : : }
191 : : else
192 : 0 : EnterStdMode();
193 : : }
194 : :
195 : : // JP 29.06.95: nie eine davor stehende Tabelle loeschen.
196 : 0 : sal_Bool bSwap = sal_False;
197 : 0 : const SwTableNode * pWasInTblNd = SwCrsrShell::IsCrsrInTbl();
198 : :
199 [ # # ]: 0 : if( SwCrsrShell::IsSttPara())
200 : : {
201 : : // #i4032# Don't actually call a 'delete' if we
202 : : // changed the table cell, compare DelRight().
203 : : const SwStartNode * pSNdOld = pWasInTblNd ?
204 : 0 : GetSwCrsr()->GetNode()->FindTableBoxStartNode() :
205 [ # # ]: 0 : 0;
206 : :
207 : : /* If the cursor is at the beginning of a paragraph, try to step
208 : : backwards. On failure we are done. */
209 [ # # ]: 0 : if( !SwCrsrShell::Left(1,CRSR_SKIP_CHARS) )
210 : 0 : return 0;
211 : :
212 : : /* If the cursor entered or left a table (or both) we are done. No step
213 : : back. */
214 : 0 : const SwTableNode* pIsInTblNd = SwCrsrShell::IsCrsrInTbl();
215 [ # # ]: 0 : if( pIsInTblNd != pWasInTblNd )
216 : 0 : return 0;
217 : :
218 : : const SwStartNode* pSNdNew = pIsInTblNd ?
219 : 0 : GetSwCrsr()->GetNode()->FindTableBoxStartNode() :
220 [ # # ]: 0 : 0;
221 : :
222 : : // #i4032# Don't actually call a 'delete' if we
223 : : // changed the table cell, compare DelRight().
224 [ # # ]: 0 : if ( pSNdOld != pSNdNew )
225 : 0 : return 0;
226 : :
227 : 0 : OpenMark();
228 : 0 : SwCrsrShell::Right(1,CRSR_SKIP_CHARS);
229 : 0 : SwCrsrShell::SwapPam();
230 : 0 : bSwap = sal_True;
231 : : }
232 : : else
233 : : {
234 : 0 : OpenMark();
235 : 0 : SwCrsrShell::Left(1,CRSR_SKIP_CHARS);
236 : : }
237 : 0 : long nRet = Delete();
238 [ # # ][ # # ]: 0 : if( !nRet && bSwap )
239 : 0 : SwCrsrShell::SwapPam();
240 : 0 : CloseMark( 0 != nRet );
241 : 0 : return nRet;
242 : : }
243 : :
244 : 0 : long SwWrtShell::DelRight()
245 : : {
246 : : // werden verodert, wenn Tabellenselektion vorliegt;
247 : : // wird hier auf nsSelectionType::SEL_TBL umgesetzt.
248 : 0 : long nRet = 0;
249 : 0 : int nSelection = GetSelectionType();
250 [ # # ]: 0 : if(nSelection & nsSelectionType::SEL_TBL_CELLS)
251 : 0 : nSelection = nsSelectionType::SEL_TBL;
252 [ # # ]: 0 : if(nSelection & nsSelectionType::SEL_TXT)
253 : 0 : nSelection = nsSelectionType::SEL_TXT;
254 : :
255 : 0 : const SwTableNode * pWasInTblNd = NULL;
256 : :
257 [ # # # ]: 0 : switch( nSelection & ~(nsSelectionType::SEL_BEZ) )
258 : : {
259 : : case nsSelectionType::SEL_POSTIT:
260 : : case nsSelectionType::SEL_TXT:
261 : : case nsSelectionType::SEL_TBL:
262 : : case nsSelectionType::SEL_NUM:
263 : : // wenn eine Selektion existiert, diese loeschen.
264 [ # # ]: 0 : if( IsSelection() )
265 : : {
266 [ # # ][ # # ]: 0 : if( !IsBlockMode() || HasSelection() )
[ # # ]
267 : : {
268 : : //OS: wieder einmal Basic: ACT_KONTEXT muss vor
269 : : //EnterStdMode verlassen werden!
270 : : {
271 [ # # ]: 0 : ACT_KONTEXT(this);
272 [ # # ]: 0 : ResetCursorStack();
273 [ # # ]: 0 : Delete();
274 [ # # ]: 0 : UpdateAttr();
275 : : }
276 [ # # ]: 0 : if( IsBlockMode() )
277 : : {
278 : 0 : NormalizePam();
279 : 0 : ClearMark();
280 : 0 : EnterBlockMode();
281 : : }
282 : : else
283 : 0 : EnterStdMode();
284 : 0 : nRet = 1L;
285 : 0 : break;
286 : : }
287 : : else
288 : 0 : EnterStdMode();
289 : : }
290 : :
291 : 0 : pWasInTblNd = IsCrsrInTbl();
292 : :
293 [ # # # # ]: 0 : if( nsSelectionType::SEL_TXT & nSelection && SwCrsrShell::IsSttPara() &&
[ # # ][ # # ]
294 : 0 : SwCrsrShell::IsEndPara() )
295 : : {
296 : : // save cursor
297 : 0 : SwCrsrShell::Push();
298 : :
299 : 0 : bool bDelFull = false;
300 [ # # ]: 0 : if ( SwCrsrShell::Right(1,CRSR_SKIP_CHARS) )
301 : : {
302 : 0 : const SwTableNode * pCurrTblNd = IsCrsrInTbl();
303 [ # # ][ # # ]: 0 : bDelFull = pCurrTblNd && pCurrTblNd != pWasInTblNd;
304 : : }
305 : :
306 : : // restore cursor
307 : 0 : SwCrsrShell::Pop( sal_False );
308 : :
309 [ # # ]: 0 : if( bDelFull )
310 : : {
311 : 0 : DelFullPara();
312 : 0 : UpdateAttr();
313 : 0 : break;
314 : : }
315 : : }
316 : :
317 : : {
318 : : /* #108049# Save the startnode of the current cell */
319 : : const SwStartNode * pSNdOld;
320 : 0 : pSNdOld = GetSwCrsr()->GetNode()->
321 : 0 : FindTableBoxStartNode();
322 : :
323 [ # # ]: 0 : if ( SwCrsrShell::IsEndPara() )
324 : : {
325 : : // #i41424# Introduced a couple of
326 : : // Push()-Pop() pairs here. The reason for this is that a
327 : : // Right()-Left() combination does not make sure, that
328 : : // the cursor will be in its initial state, because there
329 : : // may be a numbering in front of the next paragraph.
330 : 0 : SwCrsrShell::Push();
331 : :
332 [ # # ]: 0 : if ( SwCrsrShell::Right(1, CRSR_SKIP_CHARS) )
333 : : {
334 [ # # ][ # # ]: 0 : if (IsCrsrInTbl() || (pWasInTblNd != IsCrsrInTbl()))
[ # # ]
335 : : {
336 : : /* #108049# Save the startnode of the current
337 : : cell. May be different to pSNdOld as we have
338 : : moved. */
339 : 0 : const SwStartNode * pSNdNew = GetSwCrsr()
340 : 0 : ->GetNode()->FindTableBoxStartNode();
341 : :
342 : : /* #108049# Only move instead of deleting if we
343 : : have moved to a different cell */
344 [ # # ]: 0 : if (pSNdOld != pSNdNew)
345 : : {
346 : 0 : SwCrsrShell::Pop( sal_True );
347 : 0 : break;
348 : : }
349 : : }
350 : : }
351 : :
352 : : // restore cursor
353 : 0 : SwCrsrShell::Pop( sal_False );
354 : : }
355 : : }
356 : :
357 : 0 : OpenMark();
358 : 0 : SwCrsrShell::Right(1,CRSR_SKIP_CELLS);
359 : 0 : nRet = Delete();
360 : 0 : CloseMark( 0 != nRet );
361 : 0 : break;
362 : :
363 : : case nsSelectionType::SEL_FRM:
364 : : case nsSelectionType::SEL_GRF:
365 : : case nsSelectionType::SEL_OLE:
366 : : case nsSelectionType::SEL_DRW:
367 : : case nsSelectionType::SEL_DRW_TXT:
368 : : case nsSelectionType::SEL_DRW_FORM:
369 : : {
370 : : /* #108205# Remember object's position. */
371 [ # # ][ # # ]: 0 : Point aTmpPt = GetObjRect().TopLeft();
372 : :
373 [ # # ]: 0 : DelSelectedObj();
374 : :
375 : : /* #108205# Set cursor to remembered position. */
376 [ # # ]: 0 : SetCrsr(&aTmpPt);
377 : :
378 [ # # ]: 0 : LeaveSelFrmMode();
379 [ # # ]: 0 : UnSelectFrm();
380 : : // #134369#
381 : : OSL_ENSURE( !IsFrmSelected(),
382 : : "<SwWrtShell::DelRight(..)> - <SwWrtShell::UnSelectFrm()> should unmark all objects" );
383 : : // #134369#
384 : : // leave draw mode, if necessary.
385 : : {
386 [ # # ]: 0 : if (GetView().GetDrawFuncPtr())
387 : : {
388 [ # # ]: 0 : GetView().GetDrawFuncPtr()->Deactivate();
389 [ # # ]: 0 : GetView().SetDrawFuncPtr(NULL);
390 : : }
391 [ # # ]: 0 : if ( GetView().IsDrawMode() )
392 : : {
393 [ # # ]: 0 : GetView().LeaveDrawCreate();
394 : : }
395 : : }
396 : : }
397 : :
398 : : // #134369#
399 : : // <IsFrmSelected()> can't be true - see above.
400 : : {
401 : 0 : nSelection = GetSelectionType();
402 [ # # ][ # # ]: 0 : if ( nsSelectionType::SEL_FRM & nSelection ||
[ # # ][ # # ]
403 : : nsSelectionType::SEL_GRF & nSelection ||
404 : : nsSelectionType::SEL_OLE & nSelection ||
405 : : nsSelectionType::SEL_DRW & nSelection )
406 : : {
407 : 0 : EnterSelFrmMode();
408 : 0 : GotoNextFly();
409 : : }
410 : : }
411 : 0 : nRet = 1;
412 : 0 : break;
413 : : }
414 : 0 : return nRet;
415 : : }
416 : :
417 : :
418 : :
419 : 0 : long SwWrtShell::DelToEndOfPara()
420 : : {
421 [ # # ]: 0 : ACT_KONTEXT(this);
422 [ # # ]: 0 : ResetCursorStack();
423 [ # # ]: 0 : Push();
424 [ # # ]: 0 : SetMark();
425 [ # # ][ # # ]: 0 : if( !MovePara(fnParaCurr,fnParaEnd))
426 : : {
427 [ # # ]: 0 : Pop(sal_False);
428 : 0 : return 0;
429 : : }
430 [ # # ]: 0 : long nRet = Delete();
431 [ # # ]: 0 : Pop(sal_False);
432 [ # # ]: 0 : if( nRet )
433 : 0 : UpdateAttr();
434 [ # # ]: 0 : return nRet;
435 : : }
436 : :
437 : :
438 : :
439 : 0 : long SwWrtShell::DelToStartOfPara()
440 : : {
441 [ # # ]: 0 : ACT_KONTEXT(this);
442 [ # # ]: 0 : ResetCursorStack();
443 [ # # ]: 0 : Push();
444 [ # # ]: 0 : SetMark();
445 [ # # ][ # # ]: 0 : if( !MovePara(fnParaCurr,fnParaStart))
446 : : {
447 [ # # ]: 0 : Pop(sal_False);
448 : 0 : return 0;
449 : : }
450 [ # # ]: 0 : long nRet = Delete();
451 [ # # ]: 0 : Pop(sal_False);
452 [ # # ]: 0 : if( nRet )
453 : 0 : UpdateAttr();
454 [ # # ]: 0 : return nRet;
455 : : }
456 : : /*
457 : : * alle Loeschoperationen sollten mit Find statt mit
458 : : * Nxt-/PrvDelim arbeiten, da letzteren mit Wrap Around arbeiten
459 : : * -- das ist wohl nicht gewuenscht.
460 : : */
461 : :
462 : :
463 : :
464 : 0 : long SwWrtShell::DelToStartOfSentence()
465 : : {
466 [ # # ]: 0 : if(IsStartOfDoc())
467 : 0 : return 0;
468 : 0 : OpenMark();
469 [ # # ]: 0 : long nRet = _BwdSentence() ? Delete() : 0;
470 : 0 : CloseMark( 0 != nRet );
471 : 0 : return nRet;
472 : : }
473 : :
474 : :
475 : :
476 : 0 : long SwWrtShell::DelToEndOfSentence()
477 : : {
478 [ # # ]: 0 : if(IsEndOfDoc())
479 : 0 : return 0;
480 : 0 : OpenMark();
481 [ # # ]: 0 : long nRet = _FwdSentence() ? Delete() : 0;
482 : 0 : CloseMark( 0 != nRet );
483 : 0 : return nRet;
484 : : }
485 : :
486 : :
487 : :
488 : 0 : long SwWrtShell::DelNxtWord()
489 : : {
490 [ # # ][ # # ]: 0 : if(IsEndOfDoc())
491 : 0 : return 0;
492 [ # # ]: 0 : ACT_KONTEXT(this);
493 [ # # ]: 0 : ResetCursorStack();
494 [ # # ]: 0 : EnterStdMode();
495 [ # # ]: 0 : SetMark();
496 [ # # ][ # # ]: 0 : if(IsEndWrd() && !IsSttWrd())
[ # # ][ # # ]
[ # # ]
497 [ # # ]: 0 : _NxtWrdForDelete(); // #i92468#
498 [ # # ][ # # ]: 0 : if(IsSttWrd() || IsEndPara())
[ # # ][ # # ]
[ # # ]
499 [ # # ]: 0 : _NxtWrdForDelete(); // #i92468#
500 : : else
501 [ # # ]: 0 : _EndWrd();
502 : :
503 [ # # ]: 0 : long nRet = Delete();
504 [ # # ]: 0 : if( nRet )
505 : 0 : UpdateAttr();
506 : : else
507 [ # # ]: 0 : SwapPam();
508 [ # # ]: 0 : ClearMark();
509 [ # # ]: 0 : return nRet;
510 : : }
511 : :
512 : :
513 : :
514 : 0 : long SwWrtShell::DelPrvWord()
515 : : {
516 [ # # ][ # # ]: 0 : if(IsStartOfDoc())
517 : 0 : return 0;
518 [ # # ]: 0 : ACT_KONTEXT(this);
519 [ # # ]: 0 : ResetCursorStack();
520 [ # # ]: 0 : EnterStdMode();
521 [ # # ]: 0 : SetMark();
522 [ # # ][ # # ]: 0 : if ( !IsSttWrd() ||
[ # # ][ # # ]
523 [ # # ]: 0 : !_PrvWrdForDelete() ) // #i92468#
524 : : {
525 [ # # ][ # # ]: 0 : if( IsEndWrd() )
526 : : {
527 [ # # ][ # # ]: 0 : if ( _PrvWrdForDelete() ) // #i92468#
528 : : {
529 : : // skip over all-1 spaces
530 : 0 : short n = -1;
531 [ # # ][ # # ]: 0 : while( ' ' == GetChar( sal_False, n ))
532 : 0 : --n;
533 : :
534 [ # # ]: 0 : if( ++n )
535 [ # # ]: 0 : ExtendSelection( sal_False, -n );
536 : : }
537 : : }
538 [ # # ][ # # ]: 0 : else if( IsSttPara())
539 [ # # ]: 0 : _PrvWrdForDelete(); // #i92468#
540 : : else
541 [ # # ]: 0 : _SttWrd();
542 : : }
543 [ # # ]: 0 : long nRet = Delete();
544 [ # # ]: 0 : if( nRet )
545 : 0 : UpdateAttr();
546 : : else
547 [ # # ]: 0 : SwapPam();
548 [ # # ]: 0 : ClearMark();
549 [ # # ]: 0 : return nRet;
550 : : }
551 : :
552 : :
553 : :
554 : :
555 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|