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_sw.hxx"
26
27 #include <hintids.hxx>
28 #include <tools/list.hxx>
29 #include <tools/urlobj.hxx>
30 #include <vcl/cmdevt.hxx>
31 #include <unotools/charclass.hxx>
32 #include <comphelper/processfactory.hxx>
33 #include <unotools/transliterationwrapper.hxx>
34 #include <swwait.hxx>
35 #include <fmtsrnd.hxx>
36 #include <fmtinfmt.hxx>
37 #include <txtinet.hxx>
38 #include <frmfmt.hxx>
39 #include <charfmt.hxx>
40 #include <doc.hxx>
41 #include <IDocumentUndoRedo.hxx>
42 #include <docary.hxx>
43 #include <editsh.hxx>
44 #include <frame.hxx>
45 #include <cntfrm.hxx>
46 #include <pam.hxx>
47 #include <ndtxt.hxx> // fuer SwTxtNode
48 #include <grfatr.hxx>
49 #include <flyfrm.hxx>
50 #include <swtable.hxx>
51 #include <swundo.hxx> // UNDO_START, UNDO_END
52 #include <calc.hxx>
53 #include <edimp.hxx>
54 #include <ndgrf.hxx>
55 #include <ndole.hxx>
56 #include <txtfrm.hxx>
57 #include <rootfrm.hxx>
58 #include <extinput.hxx>
59 #include <crsskip.hxx>
60 #include <scriptinfo.hxx>
61 #include <unocrsrhelper.hxx>
62 #include <section.hxx>
63 #include <unochart.hxx>
64 #include <numrule.hxx>
65 #include <SwNodeNum.hxx>
66 #include <unocrsr.hxx>
67 #include <switerator.hxx>
68
69 using namespace com::sun::star;
70
71
SV_IMPL_PTRARR(SwGetINetAttrs,SwGetINetAttr *)72 SV_IMPL_PTRARR(SwGetINetAttrs, SwGetINetAttr*)
73
74 /******************************************************************************
75 * void SwEditShell::Insert(char c)
76 ******************************************************************************/
77
78
79 void SwEditShell::Insert( sal_Unicode c, sal_Bool bOnlyCurrCrsr )
80 {
81 StartAllAction();
82 FOREACHPAM_START(this)
83
84 const bool bSuccess = GetDoc()->InsertString(*PCURCRSR, c);
85 ASSERT( bSuccess, "Doc->Insert() failed." );
86 (void) bSuccess;
87
88 SaveTblBoxCntnt( PCURCRSR->GetPoint() );
89 if( bOnlyCurrCrsr )
90 break;
91
92 FOREACHPAM_END()
93
94 EndAllAction();
95 }
96
97
98 /******************************************************************************
99 * void SwEditShell::Insert(const String &rStr)
100 ******************************************************************************/
101
102
Insert2(const String & rStr,const bool bForceExpandHints)103 void SwEditShell::Insert2(const String &rStr, const bool bForceExpandHints )
104 {
105 StartAllAction();
106 {
107 const enum IDocumentContentOperations::InsertFlags nInsertFlags =
108 (bForceExpandHints)
109 ? static_cast<IDocumentContentOperations::InsertFlags>(
110 IDocumentContentOperations::INS_FORCEHINTEXPAND |
111 IDocumentContentOperations::INS_EMPTYEXPAND)
112 : IDocumentContentOperations::INS_EMPTYEXPAND;
113
114 SwPaM *_pStartCrsr = getShellCrsr( true ), *__pStartCrsr = _pStartCrsr;
115 do {
116 //OPT: GetSystemCharSet
117 const bool bSuccess =
118 GetDoc()->InsertString(*_pStartCrsr, rStr, nInsertFlags);
119 ASSERT( bSuccess, "Doc->Insert() failed." );
120 (void) bSuccess;
121
122 SaveTblBoxCntnt( _pStartCrsr->GetPoint() );
123
124 } while( (_pStartCrsr=(SwPaM *)_pStartCrsr->GetNext()) != __pStartCrsr );
125 }
126
127 // calculate cursor bidi level
128 SwCursor* pTmpCrsr = _GetCrsr();
129 const sal_Bool bDoNotSetBidiLevel = ! pTmpCrsr ||
130 ( 0 != dynamic_cast<SwUnoCrsr*>(pTmpCrsr) );
131
132 if ( ! bDoNotSetBidiLevel )
133 {
134 SwNode& rNode = pTmpCrsr->GetPoint()->nNode.GetNode();
135 if ( rNode.IsTxtNode() )
136 {
137 SwIndex& rIdx = pTmpCrsr->GetPoint()->nContent;
138 xub_StrLen nPos = rIdx.GetIndex();
139 xub_StrLen nPrevPos = nPos;
140 if ( nPrevPos )
141 --nPrevPos;
142
143 SwScriptInfo* pSI = SwScriptInfo::GetScriptInfo( ((SwTxtNode&)rNode),
144 sal_True );
145
146 sal_uInt8 nLevel = 0;
147 if ( ! pSI )
148 {
149 // seems to be an empty paragraph.
150 Point aPt;
151 SwCntntFrm* pFrm =
152 ((SwTxtNode&)rNode).getLayoutFrm( GetLayout(), &aPt, pTmpCrsr->GetPoint(),
153 sal_False );
154
155 SwScriptInfo aScriptInfo;
156 aScriptInfo.InitScriptInfo( (SwTxtNode&)rNode, pFrm->IsRightToLeft() );
157 nLevel = aScriptInfo.DirType( nPrevPos );
158 }
159 else
160 {
161 if ( STRING_LEN != pSI->GetInvalidity() )
162 pSI->InitScriptInfo( (SwTxtNode&)rNode );
163 nLevel = pSI->DirType( nPrevPos );
164 }
165
166 pTmpCrsr->SetCrsrBidiLevel( nLevel );
167 }
168 }
169
170 SetInFrontOfLabel( sal_False ); // #i27615#
171
172 EndAllAction();
173 }
174
175
176 /******************************************************************************
177 * void SwEditShell::Overwrite(const String &rStr)
178 ******************************************************************************/
179
180
Overwrite(const String & rStr)181 void SwEditShell::Overwrite(const String &rStr)
182 {
183 StartAllAction();
184 FOREACHPAM_START(this)
185 if( !GetDoc()->Overwrite(*PCURCRSR, rStr ) )
186 {
187 ASSERT( sal_False, "Doc->Overwrite(Str) failed." )
188 }
189 SaveTblBoxCntnt( PCURCRSR->GetPoint() );
190 FOREACHPAM_END()
191 EndAllAction();
192 }
193
194
195 /******************************************************************************
196 * long SwEditShell::SplitNode()
197 ******************************************************************************/
198
SplitNode(sal_Bool bAutoFormat,sal_Bool bCheckTableStart)199 long SwEditShell::SplitNode( sal_Bool bAutoFormat, sal_Bool bCheckTableStart )
200 {
201 StartAllAction();
202 GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_EMPTY, NULL);
203
204 FOREACHPAM_START(this)
205 // eine Tabellen Zelle wird jetzt zu einer normalen Textzelle!
206 GetDoc()->ClearBoxNumAttrs( PCURCRSR->GetPoint()->nNode );
207 GetDoc()->SplitNode( *PCURCRSR->GetPoint(), bCheckTableStart );
208 FOREACHPAM_END()
209
210 GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_EMPTY, NULL);
211
212 if( bAutoFormat )
213 AutoFmtBySplitNode();
214
215 ClearTblBoxCntnt();
216
217 EndAllAction();
218 return(1L);
219 }
220
221 /*-- 11.05.2004 09:41:20---------------------------------------------------
222
223 -----------------------------------------------------------------------*/
AppendTxtNode()224 sal_Bool SwEditShell::AppendTxtNode()
225 {
226 sal_Bool bRet = sal_False;
227 StartAllAction();
228 GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_EMPTY, NULL);
229
230 FOREACHPAM_START(this)
231 GetDoc()->ClearBoxNumAttrs( PCURCRSR->GetPoint()->nNode );
232 bRet = GetDoc()->AppendTxtNode( *PCURCRSR->GetPoint()) || bRet;
233 FOREACHPAM_END()
234
235 GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_EMPTY, NULL);
236
237 ClearTblBoxCntnt();
238
239 EndAllAction();
240 return bRet;
241 }
242
243 /******************************************************************************
244 * liefert einen Pointer auf einen SwGrfNode; dieser wird von
245 * GetGraphic() und GetGraphicSize() verwendet.
246 ******************************************************************************/
247
248
_GetGrfNode() const249 SwGrfNode * SwEditShell::_GetGrfNode() const
250 {
251 SwGrfNode *pGrfNode = 0;
252 SwPaM* pCrsr = GetCrsr();
253 if( !pCrsr->HasMark() ||
254 pCrsr->GetPoint()->nNode == pCrsr->GetMark()->nNode )
255 pGrfNode = pCrsr->GetPoint()->nNode.GetNode().GetGrfNode();
256
257 return pGrfNode;
258 }
259 /******************************************************************************
260 * liefert Pointer auf eine Graphic, wenn CurCrsr->GetPoint() auf
261 * einen SwGrfNode zeigt (und GetMark nicht gesetzt ist
262 * oder auf die gleiche Graphic zeigt)
263 ******************************************************************************/
264
265 // --> OD 2005-02-09 #119353# - robust
GetGraphic(sal_Bool bWait) const266 const Graphic* SwEditShell::GetGraphic( sal_Bool bWait ) const
267 {
268 SwGrfNode* pGrfNode = _GetGrfNode();
269 // --> OD 2005-02-09 #119353# - robust
270 const Graphic* pGrf( 0L );
271 if ( pGrfNode )
272 {
273 pGrf = &(pGrfNode->GetGrf());
274 // --> OD 2007-03-01 #i73788#
275 // no load of linked graphic, if its not needed now (bWait = sal_False).
276 if ( bWait )
277 {
278 if( pGrf->IsSwapOut() ||
279 ( pGrfNode->IsLinkedFile() && GRAPHIC_DEFAULT == pGrf->GetType() ) )
280 {
281 #ifdef DBG_UTIL
282 ASSERT( pGrfNode->SwapIn( bWait ) || !bWait, "Grafik konnte nicht geladen werden" );
283 #else
284 pGrfNode->SwapIn( bWait );
285 #endif
286 }
287 }
288 else
289 {
290 if ( pGrf->IsSwapOut() && !pGrfNode->IsLinkedFile() )
291 {
292 #ifdef DBG_UTIL
293 ASSERT( pGrfNode->SwapIn( bWait ) || !bWait, "Grafik konnte nicht geladen werden" );
294 #else
295 pGrfNode->SwapIn( bWait );
296 #endif
297 }
298 }
299 // <--
300 }
301 return pGrf;
302 // <--
303 }
304
IsGrfSwapOut(sal_Bool bOnlyLinked) const305 sal_Bool SwEditShell::IsGrfSwapOut( sal_Bool bOnlyLinked ) const
306 {
307 SwGrfNode *pGrfNode = _GetGrfNode();
308 return pGrfNode &&
309 (bOnlyLinked ? ( pGrfNode->IsLinkedFile() &&
310 ( GRAPHIC_DEFAULT == pGrfNode->GetGrfObj().GetType()||
311 pGrfNode->GetGrfObj().IsSwappedOut()))
312 : pGrfNode->GetGrfObj().IsSwappedOut());
313 }
314
315 // --> OD 2005-02-09 #119353# - robust
GetGraphicObj() const316 const GraphicObject* SwEditShell::GetGraphicObj() const
317 {
318 SwGrfNode* pGrfNode = _GetGrfNode();
319 // --> OD 2005-02-09 #119353# - robust
320 return pGrfNode ? &(pGrfNode->GetGrfObj()) : 0L;
321 // <--
322 }
323
GetGraphicType() const324 sal_uInt16 SwEditShell::GetGraphicType() const
325 {
326 SwGrfNode *pGrfNode = _GetGrfNode();
327 return static_cast<sal_uInt16>(pGrfNode ? pGrfNode->GetGrfObj().GetType() : GRAPHIC_NONE);
328 }
329
330 /******************************************************************************
331 * liefert die Groesse der Graphic, wenn CurCrsr->GetPoint() auf
332 * einen SwGrfNode zeigt (und GetMark nicht gesetzt ist
333 * oder auf die gleiche Graphic zeigt)
334 ******************************************************************************/
335
GetGrfSize(Size & rSz) const336 sal_Bool SwEditShell::GetGrfSize(Size& rSz) const
337 {
338 SwNoTxtNode* pNoTxtNd;
339 SwPaM* pCurrentCrsr = GetCrsr();
340 if( ( !pCurrentCrsr->HasMark()
341 || pCurrentCrsr->GetPoint()->nNode == pCurrentCrsr->GetMark()->nNode )
342 && 0 != ( pNoTxtNd = pCurrentCrsr->GetNode()->GetNoTxtNode() ) )
343 {
344 rSz = pNoTxtNd->GetTwipSize();
345 return sal_True;
346 }
347 return sal_False;
348
349 }
350 /******************************************************************************
351 * erneutes Einlesen, falls Graphic nicht Ok ist. Die
352 * aktuelle wird durch die neue ersetzt.
353 ******************************************************************************/
354
ReRead(const String & rGrfName,const String & rFltName,const Graphic * pGraphic,const GraphicObject * pGrfObj)355 void SwEditShell::ReRead( const String& rGrfName, const String& rFltName,
356 const Graphic* pGraphic, const GraphicObject* pGrfObj )
357 {
358 StartAllAction();
359 pDoc->ReRead( *GetCrsr(), rGrfName, rFltName, pGraphic, pGrfObj );
360 EndAllAction();
361 }
362
363
364 /******************************************************************************
365 * liefert den Namen und den FilterNamen einer Graphic, wenn der Cursor
366 * auf einer Graphic steht
367 * Ist ein String-Ptr != 0 dann returne den entsp. Namen
368 ******************************************************************************/
369
370
GetGrfNms(String * pGrfName,String * pFltName,const SwFlyFrmFmt * pFmt) const371 void SwEditShell::GetGrfNms( String* pGrfName, String* pFltName,
372 const SwFlyFrmFmt* pFmt ) const
373 {
374 ASSERT( pGrfName || pFltName, "was wird denn nun erfragt?" );
375 if( pFmt )
376 GetDoc()->GetGrfNms( *pFmt, pGrfName, pFltName );
377 else
378 {
379 SwGrfNode *pGrfNode = _GetGrfNode();
380 if( pGrfNode && pGrfNode->IsLinkedFile() )
381 pGrfNode->GetFileFilterNms( pGrfName, pFltName );
382 }
383 }
384
385
386 // alternativen Text abfragen/setzen
387 //const String& SwEditShell::GetAlternateText() const
388 //{
389 // SwPaM* pCrsr = GetCrsr();
390 // const SwNoTxtNode* pNd;
391 // if( !pCrsr->HasMark() && 0 != ( pNd = pCrsr->GetNode()->GetNoTxtNode()) )
392 // return pNd->GetAlternateText();
393
394 // return aEmptyStr;
395 //}
396
397
398 //void SwEditShell::SetAlternateText( const String& rTxt )
399 //{
400 // SwPaM* pCrsr = GetCrsr();
401 // SwNoTxtNode* pNd;
402 // if( !pCrsr->HasMark() && 0 != ( pNd = pCrsr->GetNode()->GetNoTxtNode()) )
403 // {
404 // pNd->SetAlternateText( rTxt, sal_True );
405 // GetDoc()->SetModified();
406 // }
407 //}
408
409
GetGraphicPolygon() const410 const PolyPolygon *SwEditShell::GetGraphicPolygon() const
411 {
412 SwNoTxtNode *pNd = GetCrsr()->GetNode()->GetNoTxtNode();
413 return pNd->HasContour();
414 }
415
416
SetGraphicPolygon(const PolyPolygon * pPoly)417 void SwEditShell::SetGraphicPolygon( const PolyPolygon *pPoly )
418 {
419 SwNoTxtNode *pNd = GetCrsr()->GetNode()->GetNoTxtNode();
420 StartAllAction();
421 pNd->SetContour( pPoly );
422 SwFlyFrm *pFly = (SwFlyFrm*)pNd->getLayoutFrm(GetLayout())->GetUpper();
423 const SwFmtSurround &rSur = pFly->GetFmt()->GetSurround();
424 pFly->GetFmt()->NotifyClients( (SwFmtSurround*)&rSur, (SwFmtSurround*)&rSur );
425 GetDoc()->SetModified();
426 EndAllAction();
427 }
428
ClearAutomaticContour()429 void SwEditShell::ClearAutomaticContour()
430 {
431 SwNoTxtNode *pNd = GetCrsr()->GetNode()->GetNoTxtNode();
432 ASSERT( pNd, "is no NoTxtNode!" );
433 if( pNd->HasAutomaticContour() )
434 {
435 StartAllAction();
436 pNd->SetContour( NULL, sal_False );
437 SwFlyFrm *pFly = (SwFlyFrm*)pNd->getLayoutFrm(GetLayout())->GetUpper();
438 const SwFmtSurround &rSur = pFly->GetFmt()->GetSurround();
439 pFly->GetFmt()->NotifyClients( (SwFmtSurround*)&rSur, (SwFmtSurround*)&rSur );
440 GetDoc()->SetModified();
441 EndAllAction();
442 }
443 }
444
445 /******************************************************************************
446 * liefert Pointer auf ein SvInPlaceObjectRef, wenn CurCrsr->GetPoint() auf
447 * einen SwOLENode zeigt (und GetMark nicht gesetzt ist
448 * oder auf das gleiche SvInPlaceObjectRef zeigt)
449 * besorgt den Pointer vom Doc wenn das Objekt per Namen gesucht werden
450 * soll
451 ******************************************************************************/
452
GetOLEObject() const453 svt::EmbeddedObjectRef& SwEditShell::GetOLEObject() const
454 {
455 ASSERT( CNT_OLE == GetCntType(), "GetOLEObj: kein OLENode." );
456 ASSERT( !GetCrsr()->HasMark() ||
457 (GetCrsr()->HasMark() &&
458 GetCrsr()->GetPoint()->nNode == GetCrsr()->GetMark()->nNode),
459 "GetOLEObj: kein OLENode." );
460
461 SwOLENode *pOLENode = GetCrsr()->GetNode()->GetOLENode();
462 ASSERT( pOLENode, "GetOLEObj: kein OLENode." );
463 SwOLEObj& rOObj = pOLENode->GetOLEObj();
464 return rOObj.GetObject();
465 }
466
467
HasOLEObj(const String & rName) const468 sal_Bool SwEditShell::HasOLEObj( const String &rName ) const
469 {
470 SwStartNode *pStNd;
471 SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
472 while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
473 {
474 aIdx++;
475 SwNode& rNd = aIdx.GetNode();
476 if( rNd.IsOLENode() &&
477 rName == ((SwOLENode&)rNd).GetChartTblName() &&
478 ((SwOLENode&)rNd).getLayoutFrm( GetLayout() ) )
479 return sal_True;
480
481 aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
482 }
483 return sal_False;
484 }
485
486
SetChartName(const String & rName)487 void SwEditShell::SetChartName( const String &rName )
488 {
489 SwOLENode *pONd = GetCrsr()->GetNode()->GetOLENode();
490 ASSERT( pONd, "ChartNode not found" );
491 pONd->SetChartTblName( rName );
492 }
493
UpdateCharts(const String & rName)494 void SwEditShell::UpdateCharts( const String &rName )
495 {
496 GetDoc()->UpdateCharts( rName );
497 }
498
499
500 /******************************************************************************
501 * Aenderung des Tabellennamens
502 ******************************************************************************/
503
SetTableName(SwFrmFmt & rTblFmt,const String & rNewName)504 void SwEditShell::SetTableName( SwFrmFmt& rTblFmt, const String &rNewName )
505 {
506 GetDoc()->SetTableName( rTblFmt, rNewName );
507 }
508
509 // erfragen des akt. Wortes
510
GetCurWord()511 String SwEditShell::GetCurWord()
512 {
513 const SwPaM& rPaM = *GetCrsr();
514 const SwTxtNode* pNd = rPaM.GetNode()->GetTxtNode();
515 String aString = pNd ?
516 pNd->GetCurWord(rPaM.GetPoint()->nContent.GetIndex()) :
517 aEmptyStr;
518 return aString;
519 }
520
521 /****************************************************************************
522 * void SwEditShell::UpdateDocStat( SwDocStat& rStat )
523 ****************************************************************************/
524
525
UpdateDocStat(SwDocStat & rStat)526 void SwEditShell::UpdateDocStat( SwDocStat& rStat )
527 {
528 StartAllAction();
529 GetDoc()->UpdateDocStat( rStat );
530 EndAllAction();
531 }
532
533 // OPT: eddocinl.cxx
534
535
536 // returne zum Namen die im Doc gesetzte Referenz
GetRefMark(const String & rName) const537 const SwFmtRefMark* SwEditShell::GetRefMark( const String& rName ) const
538 {
539 return GetDoc()->GetRefMark( rName );
540 }
541
542 // returne die Namen aller im Doc gesetzten Referenzen
GetRefMarks(SvStringsDtor * pStrings) const543 sal_uInt16 SwEditShell::GetRefMarks( SvStringsDtor* pStrings ) const
544 {
545 return GetDoc()->GetRefMarks( pStrings );
546 }
547
548 /******************************************************************************
549 * DropCap-SS
550 ******************************************************************************/
551
552
GetDropTxt(const sal_uInt16 nChars) const553 String SwEditShell::GetDropTxt( const sal_uInt16 nChars ) const
554 {
555 /**
556 * pb: made changes for #i74939#
557 *
558 * always return a string even though there is a selection
559 */
560
561 String aTxt;
562 SwPaM* pCrsr = GetCrsr();
563 if ( IsMultiSelection() )
564 {
565 // if a multi selection exists, search for the first line
566 // -> it is the cursor with the lowest index
567 sal_uLong nIndex = pCrsr->GetMark()->nNode.GetIndex();
568 bool bPrev = true;
569 SwPaM* pLast = pCrsr;
570 SwPaM* pTemp = pCrsr;
571 while ( bPrev )
572 {
573 SwPaM* pPrev2 = dynamic_cast< SwPaM* >( pTemp->GetPrev() );
574 bPrev = ( pPrev2 && pPrev2 != pLast );
575 if ( bPrev )
576 {
577 pTemp = pPrev2;
578 sal_uLong nTemp = pPrev2->GetMark()->nNode.GetIndex();
579 if ( nTemp < nIndex )
580 {
581 nIndex = nTemp;
582 pCrsr = pPrev2;
583 }
584 }
585 }
586 }
587
588 SwTxtNode* pTxtNd = pCrsr->GetNode( !pCrsr->HasMark() )->GetTxtNode();
589 if( pTxtNd )
590 {
591 xub_StrLen nDropLen = pTxtNd->GetDropLen( nChars );
592 if( nDropLen )
593 aTxt = pTxtNd->GetTxt().Copy( 0, nDropLen );
594 }
595
596 return aTxt;
597 }
598
ReplaceDropTxt(const String & rStr)599 void SwEditShell::ReplaceDropTxt( const String &rStr )
600 {
601 SwPaM* pCrsr = GetCrsr();
602 if( pCrsr->GetPoint()->nNode == pCrsr->GetMark()->nNode &&
603 pCrsr->GetNode()->GetTxtNode()->IsTxtNode() )
604 {
605 StartAllAction();
606
607 const SwNodeIndex& rNd = pCrsr->GetPoint()->nNode;
608 SwPaM aPam( rNd, rStr.Len(), rNd, 0 );
609 if( !GetDoc()->Overwrite( aPam, rStr ) )
610 {
611 ASSERT( sal_False, "Doc->Overwrite(Str) failed." );
612 }
613
614 EndAllAction();
615 }
616 }
617
618 /******************************************************************************
619 * Methode :
620 * Beschreibung:
621 * Erstellt : OK 25.04.94 13:45
622 * Aenderung :
623 ******************************************************************************/
624
Calculate()625 String SwEditShell::Calculate()
626 {
627 String aFormel; // die entgueltige Formel
628 SwPaM *pPaMLast = (SwPaM*)GetCrsr()->GetNext(),
629 *pPaM = pPaMLast; // die Pointer auf Cursor
630 SwCalc aCalc( *GetDoc() );
631 const CharClass& rCC = GetAppCharClass();
632
633 do {
634 SwTxtNode* pTxtNd = pPaM->GetNode()->GetTxtNode();
635 if(pTxtNd)
636 {
637 const SwPosition *pStart = pPaM->Start(), *pEnd = pPaM->End();
638 xub_StrLen nStt = pStart->nContent.GetIndex();
639 String aStr = pTxtNd->GetExpandTxt( nStt, pEnd->nContent.
640 GetIndex() - nStt );
641
642 rCC.toLower( aStr );
643
644 sal_Unicode ch;
645 sal_Bool bValidFlds = sal_False;
646 xub_StrLen nPos = 0;
647
648 while( nPos < aStr.Len() )
649 {
650 ch = aStr.GetChar( nPos++ );
651 if( rCC.isLetter( aStr, nPos-1 ) || ch == '_' )
652 {
653 xub_StrLen nTmpStt = nPos-1;
654 while( nPos < aStr.Len() &&
655 0 != ( ch = aStr.GetChar( nPos++ )) &&
656 (rCC.isLetterNumeric( aStr, nPos - 1 ) ||
657 ch == '_'|| ch == '.' ))
658 ;
659
660 if( nPos < aStr.Len() )
661 --nPos;
662
663 String sVar( aStr.Copy( nTmpStt, nPos - nTmpStt ));
664 if( !::FindOperator( sVar ) &&
665 (::Find( sVar, aCalc.GetVarTable(),TBLSZ) ||
666 aCalc.VarLook( sVar )) )
667 {
668 if( !bValidFlds )
669 {
670 GetDoc()->FldsToCalc( aCalc,
671 pStart->nNode.GetIndex(),
672 pStart->nContent.GetIndex() );
673 bValidFlds = sal_True;
674 }
675 (( aFormel += '(' ) +=
676 aCalc.GetStrResult( aCalc.VarLook( sVar )
677 ->nValue )) += ')';
678 }
679 else
680 aFormel += sVar;
681 }
682 else
683 aFormel += ch;
684 }
685 }
686 } while( pPaMLast != (pPaM = (SwPaM*)pPaM->GetNext()) );
687
688 return aCalc.GetStrResult( aCalc.Calculate(aFormel) );
689 }
690
691
GetLinkManager()692 sfx2::LinkManager& SwEditShell::GetLinkManager()
693 {
694 return pDoc->GetLinkManager();
695 }
696
697
GetIMapInventor() const698 void *SwEditShell::GetIMapInventor() const
699 {
700 //Als eindeutige Identifikation sollte der Node, auf dem der Crsr steht
701 //genuegen.
702 return (void*)GetCrsr()->GetNode();
703 }
704
705 // --> OD 2007-03-01 #i73788#
706 // remove default parameter, because method is always called this default value
GetIMapGraphic() const707 Graphic SwEditShell::GetIMapGraphic() const
708 {
709 //Liefert immer eine Graphic, wenn der Crsr in einem Fly steht.
710 SET_CURR_SHELL( (ViewShell*)this );
711 Graphic aRet;
712 SwPaM* pCrsr = GetCrsr();
713 if ( !pCrsr->HasMark() )
714 {
715 SwNode *pNd =pCrsr->GetNode();
716 if( pNd->IsGrfNode() )
717 {
718 const Graphic& rGrf = ((SwGrfNode*)pNd)->GetGrf();
719 if( rGrf.IsSwapOut() || ( ((SwGrfNode*)pNd)->IsLinkedFile() &&
720 GRAPHIC_DEFAULT == rGrf.GetType() ) )
721 {
722 #ifdef DBG_UTIL
723 ASSERT( ((SwGrfNode*)pNd)->SwapIn( sal_True ) || !sal_True, "Grafik konnte nicht geladen werden" );
724 #else
725 ((SwGrfNode*)pNd)->SwapIn( sal_True );
726 #endif
727 }
728 aRet = rGrf;
729 }
730 else if ( pNd->IsOLENode() )
731 {
732 aRet = *((SwOLENode*)pNd)->GetGraphic();
733 }
734 else
735 {
736 SwFlyFrm* pFlyFrm = pNd->GetCntntNode()->getLayoutFrm( GetLayout() )->FindFlyFrm();
737 if(pFlyFrm)
738 aRet = pFlyFrm->GetFmt()->MakeGraphic();
739 }
740 }
741 return aRet;
742 }
743
744
InsertURL(const SwFmtINetFmt & rFmt,const String & rStr,sal_Bool bKeepSelection)745 sal_Bool SwEditShell::InsertURL( const SwFmtINetFmt& rFmt, const String& rStr, sal_Bool bKeepSelection )
746 {
747 // URL und Hinweistext (direkt oder via Selektion) notwendig
748 if( !rFmt.GetValue().Len() || ( !rStr.Len() && !HasSelection() ) )
749 return sal_False;
750 StartAllAction();
751 GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_UI_INSERT_URLTXT, NULL);
752 sal_Bool bInsTxt = sal_True;
753
754 if( rStr.Len() )
755 {
756 SwPaM* pCrsr = GetCrsr();
757 if( pCrsr->HasMark() && *pCrsr->GetPoint() != *pCrsr->GetMark() )
758 {
759 // Selection vorhanden, MehrfachSelektion?
760 sal_Bool bDelTxt = sal_True;
761 if( pCrsr->GetNext() == pCrsr )
762 {
763 // einfach Selection -> Text ueberpruefen
764 String sTxt( GetSelTxt() );
765 sTxt.EraseTrailingChars();
766 if( sTxt == rStr )
767 bDelTxt = bInsTxt = sal_False;
768 }
769 else if( rFmt.GetValue() == rStr ) // Name und URL gleich?
770 bDelTxt = bInsTxt = sal_False;
771
772 if( bDelTxt )
773 Delete();
774 }
775 else if( pCrsr->GetNext() != pCrsr && rFmt.GetValue() == rStr )
776 bInsTxt = sal_False;
777
778 if( bInsTxt )
779 {
780 Insert2( rStr );
781 SetMark();
782 ExtendSelection( sal_False, rStr.Len() );
783 }
784 }
785 else
786 bInsTxt = sal_False;
787
788 SetAttrItem( rFmt );
789 if (bInsTxt && !IsCrsrPtAtEnd())
790 SwapPam();
791 if(!bKeepSelection)
792 ClearMark();
793 if( bInsTxt )
794 DontExpandFmt();
795 GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_UI_INSERT_URLTXT, NULL );
796 EndAllAction();
797 return sal_True;
798 }
799
800
GetINetAttrs(SwGetINetAttrs & rArr)801 sal_uInt16 SwEditShell::GetINetAttrs( SwGetINetAttrs& rArr )
802 {
803 if( rArr.Count() )
804 rArr.DeleteAndDestroy( 0, rArr.Count() );
805
806 const SwTxtNode* pTxtNd;
807 const SwCharFmts* pFmts = GetDoc()->GetCharFmts();
808 for( sal_uInt16 n = pFmts->Count(); 1 < n; )
809 {
810 SwIterator<SwTxtINetFmt,SwCharFmt> aIter(*(*pFmts)[--n]);
811 for( SwTxtINetFmt* pFnd = aIter.First(); pFnd; pFnd = aIter.Next() )
812 {
813 if( 0 != ( pTxtNd = pFnd->GetpTxtNode()) &&
814 pTxtNd->GetNodes().IsDocNodes() )
815 {
816 SwTxtINetFmt& rAttr = *pFnd;
817 String sTxt( pTxtNd->GetExpandTxt( *rAttr.GetStart(),
818 *rAttr.End() - *rAttr.GetStart() ) );
819
820 sTxt.EraseAllChars( 0x0a );
821 sTxt.EraseLeadingChars().EraseTrailingChars();
822
823 if( sTxt.Len() )
824 {
825 SwGetINetAttr* pNew = new SwGetINetAttr( sTxt, rAttr );
826 rArr.C40_INSERT( SwGetINetAttr, pNew, rArr.Count() );
827 }
828 }
829 }
830 }
831 return rArr.Count();
832 }
833
834
835 // ist der Cursor in eine INetAttribut, dann wird das komplett
836 // geloescht; inclusive des Hinweistextes (wird beim Drag&Drop gebraucht)
DelINetAttrWithText()837 sal_Bool SwEditShell::DelINetAttrWithText()
838 {
839 sal_Bool bRet = SelectTxtAttr( RES_TXTATR_INETFMT, sal_False );
840 if( bRet )
841 DeleteSel( *GetCrsr() );
842 return bRet;
843 }
844
845
846 // setzen an den Textzeichenattributen das DontExpand-Flag
DontExpandFmt()847 sal_Bool SwEditShell::DontExpandFmt()
848 {
849 sal_Bool bRet = sal_False;
850 if( !IsTableMode() && GetDoc()->DontExpandFmt( *GetCrsr()->GetPoint() ))
851 {
852 bRet = sal_True;
853 CallChgLnk();
854 }
855 return bRet;
856 }
857
GetNumberFormatter()858 SvNumberFormatter* SwEditShell::GetNumberFormatter()
859 {
860 return GetDoc()->GetNumberFormatter();
861 }
862
RemoveInvisibleContent()863 sal_Bool SwEditShell::RemoveInvisibleContent()
864 {
865 StartAllAction();
866 sal_Bool bRet = GetDoc()->RemoveInvisibleContent();
867 EndAllAction();
868 return bRet;
869 }
ConvertFieldsToText()870 sal_Bool SwEditShell::ConvertFieldsToText()
871 {
872 StartAllAction();
873 sal_Bool bRet = GetDoc()->ConvertFieldsToText();
874 EndAllAction();
875 return bRet;
876 }
SetNumberingRestart()877 void SwEditShell::SetNumberingRestart()
878 {
879 StartAllAction();
880 Push();
881 //iterate over all text contents - body, frames, header, footer, footnote text
882 SwPaM* pCrsr = GetCrsr();
883 for(sal_uInt16 i = 0; i < 2; i++)
884 {
885 if(!i)
886 MakeFindRange(DOCPOS_START, DOCPOS_END, pCrsr); //body content
887 else
888 MakeFindRange(DOCPOS_OTHERSTART, DOCPOS_OTHEREND, pCrsr); //extra content
889 SwPosition* pSttPos = pCrsr->Start(), *pEndPos = pCrsr->End();
890 sal_uLong nCurrNd = pSttPos->nNode.GetIndex();
891 sal_uLong nEndNd = pEndPos->nNode.GetIndex();
892 if( nCurrNd <= nEndNd )
893 {
894 SwCntntFrm* pCntFrm;
895 sal_Bool bGoOn = sal_True;
896 //iterate over all paragraphs
897 while( bGoOn )
898 {
899 SwNode* pNd = GetDoc()->GetNodes()[ nCurrNd ];
900 switch( pNd->GetNodeType() )
901 {
902 case ND_TEXTNODE:
903 if( 0 != ( pCntFrm = ((SwTxtNode*)pNd)->getLayoutFrm( GetLayout() )) )
904 {
905 //jump over hidden frames - ignore protection!
906 if( !((SwTxtFrm*)pCntFrm)->IsHiddenNow() )
907 {
908 //if the node is numbered and the starting value of the numbering equals the
909 //start value of the numbering rule then set this value as hard starting value
910
911 //get the node num
912 // OD 2005-11-09
913 SwTxtNode* pTxtNd( static_cast<SwTxtNode*>(pNd) );
914 SwNumRule* pNumRule( pTxtNd->GetNumRule() );
915
916 if ( pNumRule && pTxtNd->GetNum() &&
917 ( pTxtNd->HasNumber() || pTxtNd->HasBullet() ) &&
918 pTxtNd->IsCountedInList() &&
919 !pTxtNd->IsListRestart() &&
920 pTxtNd->GetNum()->GetNumber() ==
921 pNumRule->Get( static_cast<sal_uInt16>(pTxtNd->GetActualListLevel()) ).GetStart() )
922 {
923 //now set a the start value as attribute
924 SwPosition aCurrentNode(*pNd);
925 GetDoc()->SetNumRuleStart( aCurrentNode, sal_True );
926 }
927 }
928 }
929 break;
930 case ND_SECTIONNODE:
931 // jump over hidden sections - ignore protection!
932 if(((SwSectionNode*)pNd)->GetSection().IsHidden() )
933 nCurrNd = pNd->EndOfSectionIndex();
934 break;
935 case ND_ENDNODE:
936 {
937 break;
938 }
939 }
940
941 bGoOn = nCurrNd < nEndNd;
942 ++nCurrNd;
943 }
944 }
945 }
946
947
948 Pop(sal_False);
949 EndAllAction();
950 }
951
GetLineCount(sal_Bool bActPos)952 sal_uInt16 SwEditShell::GetLineCount( sal_Bool bActPos )
953 {
954 sal_uInt16 nRet = 0;
955 CalcLayout();
956 SwPaM* pPam = GetCrsr();
957 SwNodeIndex& rPtIdx = pPam->GetPoint()->nNode;
958 SwNodeIndex aStart( rPtIdx );
959 SwCntntNode* pCNd;
960 SwCntntFrm *pCntFrm = 0;
961 sal_uLong nTmpPos;
962
963 if( !bActPos )
964 aStart = 0;
965 else if( rPtIdx > ( nTmpPos = GetDoc()->GetNodes().GetEndOfExtras().GetIndex()) )
966 // BodyBereich => Start ist EndOfIcons + 1
967 aStart = nTmpPos + 1;
968 else
969 {
970 if( 0 != ( pCNd = pPam->GetCntntNode() ) &&
971 0 != ( pCntFrm = pCNd->getLayoutFrm( GetLayout() ) ) )
972 {
973 const SwStartNode *pTmp;
974 if( pCntFrm->IsInFly() ) // Fly
975 pTmp = pCNd->FindFlyStartNode();
976 else if( pCntFrm->IsInFtn() ) // Footnote
977 pTmp = pCNd->FindFootnoteStartNode();
978 else
979 { // Footer/Header
980 const sal_uInt16 nTyp = FRM_HEADER | FRM_FOOTER;
981 SwFrm* pFrm = pCntFrm;
982 while( pFrm && !(pFrm->GetType() & nTyp) )
983 pFrm = pFrm->GetUpper();
984 ASSERT( pFrm, "Wo bin ich?" );
985 if( pFrm && ( pFrm->GetType() & FRM_FOOTER ) )
986 pTmp = pCNd->FindFooterStartNode();
987 else
988 pTmp = pCNd->FindHeaderStartNode();
989 }
990 ASSERT( pTmp, "Missing StartNode" );
991 aStart = *pTmp;
992 }
993 ASSERT( pCNd && pCntFrm, "Missing Layout-Information" );
994 }
995
996 while( 0 != ( pCNd = GetDoc()->GetNodes().GoNextSection(
997 &aStart, sal_True, sal_False )) && ( !bActPos || aStart <= rPtIdx ) )
998 {
999 if( 0 != ( pCntFrm = pCNd->getLayoutFrm( GetLayout() ) ) && pCntFrm->IsTxtFrm() )
1000 {
1001 xub_StrLen nActPos = bActPos && aStart == rPtIdx ?
1002 pPam->GetPoint()->nContent.GetIndex() : USHRT_MAX;
1003 nRet = nRet + ((SwTxtFrm*)pCntFrm)->GetLineCount( nActPos );
1004 }
1005 }
1006 return nRet;
1007 }
1008
CompareDoc(const SwDoc & rDoc)1009 long SwEditShell::CompareDoc( const SwDoc& rDoc )
1010 {
1011 StartAllAction();
1012 long nRet = GetDoc()->CompareDoc( rDoc );
1013 EndAllAction();
1014 return nRet;
1015 }
1016
MergeDoc(const SwDoc & rDoc)1017 long SwEditShell::MergeDoc( const SwDoc& rDoc )
1018 {
1019 StartAllAction();
1020 long nRet = GetDoc()->MergeDoc( rDoc );
1021 EndAllAction();
1022 return nRet;
1023 }
1024
1025
GetFtnInfo() const1026 const SwFtnInfo& SwEditShell::GetFtnInfo() const
1027 {
1028 return GetDoc()->GetFtnInfo();
1029 }
1030
SetFtnInfo(const SwFtnInfo & rInfo)1031 void SwEditShell::SetFtnInfo(const SwFtnInfo& rInfo)
1032 {
1033 StartAllAction();
1034 SET_CURR_SHELL( this );
1035 GetDoc()->SetFtnInfo(rInfo);
1036 CallChgLnk();
1037 EndAllAction();
1038 }
1039
GetEndNoteInfo() const1040 const SwEndNoteInfo& SwEditShell::GetEndNoteInfo() const
1041 {
1042 return GetDoc()->GetEndNoteInfo();
1043 }
1044
SetEndNoteInfo(const SwEndNoteInfo & rInfo)1045 void SwEditShell::SetEndNoteInfo(const SwEndNoteInfo& rInfo)
1046 {
1047 StartAllAction();
1048 SET_CURR_SHELL( this );
1049 GetDoc()->SetEndNoteInfo(rInfo);
1050 EndAllAction();
1051 }
1052
GetLineNumberInfo() const1053 const SwLineNumberInfo& SwEditShell::GetLineNumberInfo() const
1054 {
1055 return GetDoc()->GetLineNumberInfo();
1056 }
1057
SetLineNumberInfo(const SwLineNumberInfo & rInfo)1058 void SwEditShell::SetLineNumberInfo(const SwLineNumberInfo& rInfo)
1059 {
1060 StartAllAction();
1061 SET_CURR_SHELL( this );
1062 GetDoc()->SetLineNumberInfo(rInfo);
1063 AddPaintRect( GetLayout()->Frm() );
1064 EndAllAction();
1065 }
1066
GetLinkUpdMode(sal_Bool bDocSettings) const1067 sal_uInt16 SwEditShell::GetLinkUpdMode(sal_Bool bDocSettings) const
1068 {
1069 return getIDocumentSettingAccess()->getLinkUpdateMode( !bDocSettings );
1070 }
1071
SetLinkUpdMode(sal_uInt16 nMode)1072 void SwEditShell::SetLinkUpdMode( sal_uInt16 nMode )
1073 {
1074 getIDocumentSettingAccess()->setLinkUpdateMode( nMode );
1075 }
1076
1077
1078 // Schnittstelle fuer die TextInputDaten - ( fuer die Texteingabe
1079 // von japanischen/chinesischen Zeichen)
CreateExtTextInput(LanguageType eInputLanguage)1080 SwExtTextInput* SwEditShell::CreateExtTextInput(LanguageType eInputLanguage)
1081 {
1082 SwExtTextInput* pRet = GetDoc()->CreateExtTextInput( *GetCrsr() );
1083 pRet->SetLanguage(eInputLanguage);
1084 pRet->SetOverwriteCursor( SwCrsrShell::IsOverwriteCrsr() );
1085 return pRet;
1086 }
1087
DeleteExtTextInput(SwExtTextInput * pDel,sal_Bool bInsText)1088 String SwEditShell::DeleteExtTextInput( SwExtTextInput* pDel, sal_Bool bInsText )
1089 {
1090 if( !pDel )
1091 {
1092 const SwPosition& rPos = *GetCrsr()->GetPoint();
1093 pDel = GetDoc()->GetExtTextInput( rPos.nNode.GetNode(),
1094 rPos.nContent.GetIndex() );
1095 if( !pDel )
1096 {
1097 //JP 25.10.2001: under UNIX the cursor is moved before the Input-
1098 // Engine event comes in. So take any - normally there
1099 // exist only one at the time. -- Task 92016
1100 pDel = GetDoc()->GetExtTextInput();
1101 }
1102 }
1103 String sRet;
1104 if( pDel )
1105 {
1106 rtl::OUString sTmp;
1107 SwUnoCursorHelper::GetTextFromPam(*pDel, sTmp);
1108 sRet = sTmp;
1109 SET_CURR_SHELL( this );
1110 StartAllAction();
1111 pDel->SetInsText( bInsText );
1112 SetOverwriteCrsr( pDel->IsOverwriteCursor() );
1113 const SwPosition aPos( *pDel->GetPoint() );
1114 GetDoc()->DeleteExtTextInput( pDel );
1115
1116 // In this case, the "replace" function did not set the cursor
1117 // to the original position. Therefore we have to do this manually.
1118 if ( ! bInsText && IsOverwriteCrsr() )
1119 *GetCrsr()->GetPoint() = aPos;
1120
1121 EndAllAction();
1122 }
1123 return sRet;
1124 }
1125
SetExtTextInputData(const CommandExtTextInputData & rData)1126 void SwEditShell::SetExtTextInputData( const CommandExtTextInputData& rData )
1127 {
1128 const SwPosition& rPos = *GetCrsr()->GetPoint();
1129 SwExtTextInput* pInput = GetDoc()->GetExtTextInput( rPos.nNode.GetNode()
1130 /*, rPos.nContent.GetIndex()*/ );
1131 if( pInput )
1132 {
1133 StartAllAction();
1134 SET_CURR_SHELL( this );
1135
1136 if( !rData.IsOnlyCursorChanged() )
1137 pInput->SetInputData( rData );
1138 // Cursor positionieren:
1139 const SwPosition& rStt = *pInput->Start();
1140 xub_StrLen nNewCrsrPos = rStt.nContent.GetIndex() + rData.GetCursorPos();
1141
1142 // zwar unschoen aber was hilfts
1143 ShowCrsr();
1144 long nDiff = nNewCrsrPos - rPos.nContent.GetIndex();
1145 if( 0 > nDiff )
1146 Left( (xub_StrLen)-nDiff, CRSR_SKIP_CHARS );
1147 else if( 0 < nDiff )
1148 Right( (xub_StrLen)nDiff, CRSR_SKIP_CHARS );
1149
1150 SetOverwriteCrsr( rData.IsCursorOverwrite() );
1151
1152 EndAllAction();
1153
1154 if( !rData.IsCursorVisible() ) // must be called after the EndAction
1155 HideCrsr();
1156 }
1157 }
1158
TransliterateText(sal_uInt32 nType)1159 void SwEditShell::TransliterateText( sal_uInt32 nType )
1160 {
1161 utl::TransliterationWrapper aTrans( ::comphelper::getProcessServiceFactory(), nType );
1162 StartAllAction();
1163 SET_CURR_SHELL( this );
1164
1165 SwPaM* pCrsr = GetCrsr();
1166 if( pCrsr->GetNext() != pCrsr )
1167 {
1168 GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_EMPTY, NULL);
1169 FOREACHPAM_START( this )
1170
1171 if( PCURCRSR->HasMark() )
1172 GetDoc()->TransliterateText( *PCURCRSR, aTrans );
1173
1174 FOREACHPAM_END()
1175 GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_EMPTY, NULL);
1176 }
1177 else
1178 GetDoc()->TransliterateText( *pCrsr, aTrans );
1179
1180 EndAllAction();
1181 }
1182
CountWords(SwDocStat & rStat) const1183 void SwEditShell::CountWords( SwDocStat& rStat ) const
1184 {
1185 FOREACHPAM_START( this )
1186
1187 if( PCURCRSR->HasMark() )
1188 GetDoc()->CountWords( *PCURCRSR, rStat );
1189
1190 FOREACHPAM_END()
1191 }
1192
ApplyViewOptions(const SwViewOption & rOpt)1193 void SwEditShell::ApplyViewOptions( const SwViewOption &rOpt )
1194 {
1195 SwCrsrShell::StartAction();
1196 ViewShell::ApplyViewOptions( rOpt );
1197 SwEditShell::EndAction();
1198 }
1199
1200
1201