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