Update ooo320-m1
[ooovba.git] / sw / source / core / edit / editsh.cxx
blob8e796037197b83ef277ccee6a0cfa9b68e5196e0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: editsh.cxx,v $
10 * $Revision: 1.58 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <hintids.hxx>
34 #include <tools/list.hxx>
35 #include <tools/urlobj.hxx>
36 #include <vcl/cmdevt.hxx>
37 #include <unotools/charclass.hxx>
38 #include <comphelper/processfactory.hxx>
39 #include <unotools/transliterationwrapper.hxx>
40 #include <swwait.hxx>
41 #include <fmtsrnd.hxx>
42 #include <fmtinfmt.hxx>
43 #include <txtinet.hxx>
44 #include <frmfmt.hxx>
45 #include <charfmt.hxx>
46 #include <doc.hxx>
47 #include <docary.hxx>
48 #include <editsh.hxx>
49 #include <frame.hxx>
50 #include <cntfrm.hxx>
51 #include <pam.hxx>
52 #include <ndtxt.hxx> // fuer SwTxtNode
53 #include <grfatr.hxx>
54 #include <flyfrm.hxx>
55 #include <swtable.hxx>
56 #include <swundo.hxx> // UNDO_START, UNDO_END
57 #include <calc.hxx>
58 #include <edimp.hxx>
59 #include <ndgrf.hxx>
60 #include <ndole.hxx>
61 #include <txtfrm.hxx>
62 #include <rootfrm.hxx>
63 #include <extinput.hxx>
64 #include <crsskip.hxx>
65 #include <scriptinfo.hxx>
66 #include <unoobj.hxx>
67 #include <section.hxx>
68 #include <unochart.hxx>
69 #include <numrule.hxx>
70 #include <SwNodeNum.hxx>
71 #include <unocrsr.hxx>
74 using namespace com::sun::star;
77 SV_IMPL_PTRARR(SwGetINetAttrs, SwGetINetAttr*)
79 /******************************************************************************
80 * void SwEditShell::Insert(char c)
81 ******************************************************************************/
84 void SwEditShell::Insert( sal_Unicode c, BOOL bOnlyCurrCrsr )
86 StartAllAction();
87 FOREACHPAM_START(this)
89 const bool bSuccess = GetDoc()->InsertString(*PCURCRSR, c);
90 ASSERT( bSuccess, "Doc->Insert() failed." );
91 (void) bSuccess;
93 SaveTblBoxCntnt( PCURCRSR->GetPoint() );
94 if( bOnlyCurrCrsr )
95 break;
97 FOREACHPAM_END()
99 EndAllAction();
103 /******************************************************************************
104 * void SwEditShell::Insert(const String &rStr)
105 ******************************************************************************/
108 void SwEditShell::Insert2(const String &rStr, const bool bForceExpandHints )
110 StartAllAction();
112 const enum IDocumentContentOperations::InsertFlags nInsertFlags =
113 (bForceExpandHints)
114 ? static_cast<IDocumentContentOperations::InsertFlags>(
115 IDocumentContentOperations::INS_FORCEHINTEXPAND |
116 IDocumentContentOperations::INS_EMPTYEXPAND)
117 : IDocumentContentOperations::INS_EMPTYEXPAND;
119 SwPaM *_pStartCrsr = getShellCrsr( true ), *__pStartCrsr = _pStartCrsr;
120 do {
121 //OPT: GetSystemCharSet
122 const bool bSuccess =
123 GetDoc()->InsertString(*_pStartCrsr, rStr, nInsertFlags);
124 ASSERT( bSuccess, "Doc->Insert() failed." );
125 (void) bSuccess;
127 SaveTblBoxCntnt( _pStartCrsr->GetPoint() );
129 } while( (_pStartCrsr=(SwPaM *)_pStartCrsr->GetNext()) != __pStartCrsr );
132 // calculate cursor bidi level
133 SwCursor* pTmpCrsr = _GetCrsr();
134 const BOOL bDoNotSetBidiLevel = ! pTmpCrsr ||
135 ( 0 != dynamic_cast<SwUnoCrsr*>(pTmpCrsr) );
137 if ( ! bDoNotSetBidiLevel )
139 SwNode& rNode = pTmpCrsr->GetPoint()->nNode.GetNode();
140 if ( rNode.IsTxtNode() )
142 SwIndex& rIdx = pTmpCrsr->GetPoint()->nContent;
143 xub_StrLen nPos = rIdx.GetIndex();
144 xub_StrLen nPrevPos = nPos;
145 if ( nPrevPos )
146 --nPrevPos;
148 SwScriptInfo* pSI = SwScriptInfo::GetScriptInfo( ((SwTxtNode&)rNode),
149 sal_True );
151 BYTE nLevel = 0;
152 if ( ! pSI )
154 // seems to be an empty paragraph.
155 Point aPt;
156 SwCntntFrm* pFrm =
157 ((SwTxtNode&)rNode).GetFrm( &aPt, pTmpCrsr->GetPoint(),
158 sal_False );
160 SwScriptInfo aScriptInfo;
161 aScriptInfo.InitScriptInfo( (SwTxtNode&)rNode, pFrm->IsRightToLeft() );
162 nLevel = aScriptInfo.DirType( nPrevPos );
164 else
166 if ( STRING_LEN != pSI->GetInvalidity() )
167 pSI->InitScriptInfo( (SwTxtNode&)rNode );
168 nLevel = pSI->DirType( nPrevPos );
171 pTmpCrsr->SetCrsrBidiLevel( nLevel );
175 SetInFrontOfLabel( FALSE ); // #i27615#
177 EndAllAction();
181 /******************************************************************************
182 * void SwEditShell::Overwrite(const String &rStr)
183 ******************************************************************************/
186 void SwEditShell::Overwrite(const String &rStr)
188 StartAllAction();
189 FOREACHPAM_START(this)
190 if( !GetDoc()->Overwrite(*PCURCRSR, rStr ) )
192 ASSERT( FALSE, "Doc->Overwrite(Str) failed." )
194 SaveTblBoxCntnt( PCURCRSR->GetPoint() );
195 FOREACHPAM_END()
196 EndAllAction();
200 /******************************************************************************
201 * long SwEditShell::SplitNode()
202 ******************************************************************************/
204 long SwEditShell::SplitNode( BOOL bAutoFormat, BOOL bCheckTableStart )
206 StartAllAction();
207 GetDoc()->StartUndo(UNDO_EMPTY, NULL);
209 FOREACHPAM_START(this)
210 // eine Tabellen Zelle wird jetzt zu einer normalen Textzelle!
211 GetDoc()->ClearBoxNumAttrs( PCURCRSR->GetPoint()->nNode );
212 GetDoc()->SplitNode( *PCURCRSR->GetPoint(), bCheckTableStart );
213 FOREACHPAM_END()
215 GetDoc()->EndUndo(UNDO_EMPTY, NULL);
217 if( bAutoFormat )
218 AutoFmtBySplitNode();
220 ClearTblBoxCntnt();
222 EndAllAction();
223 return(1L);
226 /*-- 11.05.2004 09:41:20---------------------------------------------------
228 -----------------------------------------------------------------------*/
229 sal_Bool SwEditShell::AppendTxtNode()
231 sal_Bool bRet = sal_False;
232 StartAllAction();
233 GetDoc()->StartUndo(UNDO_EMPTY, NULL);
235 FOREACHPAM_START(this)
236 GetDoc()->ClearBoxNumAttrs( PCURCRSR->GetPoint()->nNode );
237 bRet = GetDoc()->AppendTxtNode( *PCURCRSR->GetPoint()) || bRet;
238 FOREACHPAM_END()
240 GetDoc()->EndUndo(UNDO_EMPTY, NULL);
242 ClearTblBoxCntnt();
244 EndAllAction();
245 return bRet;
248 /******************************************************************************
249 * liefert einen Pointer auf einen SwGrfNode; dieser wird von
250 * GetGraphic() und GetGraphicSize() verwendet.
251 ******************************************************************************/
254 SwGrfNode * SwEditShell::_GetGrfNode() const
256 SwGrfNode *pGrfNode = 0;
257 SwPaM* pCrsr = GetCrsr();
258 if( !pCrsr->HasMark() ||
259 pCrsr->GetPoint()->nNode == pCrsr->GetMark()->nNode )
260 pGrfNode = pCrsr->GetPoint()->nNode.GetNode().GetGrfNode();
262 return pGrfNode;
264 /******************************************************************************
265 * liefert Pointer auf eine Graphic, wenn CurCrsr->GetPoint() auf
266 * einen SwGrfNode zeigt (und GetMark nicht gesetzt ist
267 * oder auf die gleiche Graphic zeigt)
268 ******************************************************************************/
270 // --> OD 2005-02-09 #119353# - robust
271 const Graphic* SwEditShell::GetGraphic( BOOL bWait ) const
273 SwGrfNode* pGrfNode = _GetGrfNode();
274 // --> OD 2005-02-09 #119353# - robust
275 const Graphic* pGrf( 0L );
276 if ( pGrfNode )
278 pGrf = &(pGrfNode->GetGrf());
279 // --> OD 2007-03-01 #i73788#
280 // no load of linked graphic, if its not needed now (bWait = FALSE).
281 if ( bWait )
283 if( pGrf->IsSwapOut() ||
284 ( pGrfNode->IsLinkedFile() && GRAPHIC_DEFAULT == pGrf->GetType() ) )
286 #ifndef PRODUCT
287 ASSERT( pGrfNode->SwapIn( bWait ) || !bWait, "Grafik konnte nicht geladen werden" );
288 #else
289 pGrfNode->SwapIn( bWait );
290 #endif
293 else
295 if ( pGrf->IsSwapOut() && !pGrfNode->IsLinkedFile() )
297 #ifndef PRODUCT
298 ASSERT( pGrfNode->SwapIn( bWait ) || !bWait, "Grafik konnte nicht geladen werden" );
299 #else
300 pGrfNode->SwapIn( bWait );
301 #endif
304 // <--
306 return pGrf;
307 // <--
310 BOOL SwEditShell::IsGrfSwapOut( BOOL bOnlyLinked ) const
312 SwGrfNode *pGrfNode = _GetGrfNode();
313 return pGrfNode &&
314 (bOnlyLinked ? ( pGrfNode->IsLinkedFile() &&
315 ( GRAPHIC_DEFAULT == pGrfNode->GetGrfObj().GetType()||
316 pGrfNode->GetGrfObj().IsSwappedOut()))
317 : pGrfNode->GetGrfObj().IsSwappedOut());
320 // --> OD 2005-02-09 #119353# - robust
321 const GraphicObject* SwEditShell::GetGraphicObj() const
323 SwGrfNode* pGrfNode = _GetGrfNode();
324 // --> OD 2005-02-09 #119353# - robust
325 return pGrfNode ? &(pGrfNode->GetGrfObj()) : 0L;
326 // <--
329 USHORT SwEditShell::GetGraphicType() const
331 SwGrfNode *pGrfNode = _GetGrfNode();
332 return static_cast<USHORT>(pGrfNode ? pGrfNode->GetGrfObj().GetType() : GRAPHIC_NONE);
335 /******************************************************************************
336 * liefert die Groesse der Graphic, wenn CurCrsr->GetPoint() auf
337 * einen SwGrfNode zeigt (und GetMark nicht gesetzt ist
338 * oder auf die gleiche Graphic zeigt)
339 ******************************************************************************/
341 BOOL SwEditShell::GetGrfSize(Size& rSz) const
343 SwNoTxtNode* pNoTxtNd;
344 SwPaM* pCurrentCrsr = GetCrsr();
345 if( ( !pCurrentCrsr->HasMark()
346 || pCurrentCrsr->GetPoint()->nNode == pCurrentCrsr->GetMark()->nNode )
347 && 0 != ( pNoTxtNd = pCurrentCrsr->GetNode()->GetNoTxtNode() ) )
349 rSz = pNoTxtNd->GetTwipSize();
350 return TRUE;
352 return FALSE;
355 /******************************************************************************
356 * erneutes Einlesen, falls Graphic nicht Ok ist. Die
357 * aktuelle wird durch die neue ersetzt.
358 ******************************************************************************/
360 void SwEditShell::ReRead( const String& rGrfName, const String& rFltName,
361 const Graphic* pGraphic, const GraphicObject* pGrfObj )
363 StartAllAction();
364 pDoc->ReRead( *GetCrsr(), rGrfName, rFltName, pGraphic, pGrfObj );
365 EndAllAction();
369 /******************************************************************************
370 * liefert den Namen und den FilterNamen einer Graphic, wenn der Cursor
371 * auf einer Graphic steht
372 * Ist ein String-Ptr != 0 dann returne den entsp. Namen
373 ******************************************************************************/
376 void SwEditShell::GetGrfNms( String* pGrfName, String* pFltName,
377 const SwFlyFrmFmt* pFmt ) const
379 ASSERT( pGrfName || pFltName, "was wird denn nun erfragt?" );
380 if( pFmt )
381 GetDoc()->GetGrfNms( *pFmt, pGrfName, pFltName );
382 else
384 SwGrfNode *pGrfNode = _GetGrfNode();
385 if( pGrfNode && pGrfNode->IsLinkedFile() )
386 pGrfNode->GetFileFilterNms( pGrfName, pFltName );
391 // alternativen Text abfragen/setzen
392 //const String& SwEditShell::GetAlternateText() const
394 // SwPaM* pCrsr = GetCrsr();
395 // const SwNoTxtNode* pNd;
396 // if( !pCrsr->HasMark() && 0 != ( pNd = pCrsr->GetNode()->GetNoTxtNode()) )
397 // return pNd->GetAlternateText();
399 // return aEmptyStr;
403 //void SwEditShell::SetAlternateText( const String& rTxt )
405 // SwPaM* pCrsr = GetCrsr();
406 // SwNoTxtNode* pNd;
407 // if( !pCrsr->HasMark() && 0 != ( pNd = pCrsr->GetNode()->GetNoTxtNode()) )
408 // {
409 // pNd->SetAlternateText( rTxt, sal_True );
410 // GetDoc()->SetModified();
411 // }
415 const PolyPolygon *SwEditShell::GetGraphicPolygon() const
417 SwNoTxtNode *pNd = GetCrsr()->GetNode()->GetNoTxtNode();
418 return pNd->HasContour();
422 void SwEditShell::SetGraphicPolygon( const PolyPolygon *pPoly )
424 SwNoTxtNode *pNd = GetCrsr()->GetNode()->GetNoTxtNode();
425 StartAllAction();
426 pNd->SetContour( pPoly );
427 SwFlyFrm *pFly = (SwFlyFrm*)pNd->GetFrm()->GetUpper();
428 const SwFmtSurround &rSur = pFly->GetFmt()->GetSurround();
429 pFly->GetFmt()->SwModify::Modify( (SwFmtSurround*)&rSur,
430 (SwFmtSurround*)&rSur );
431 GetDoc()->SetModified();
432 EndAllAction();
435 void SwEditShell::ClearAutomaticContour()
437 SwNoTxtNode *pNd = GetCrsr()->GetNode()->GetNoTxtNode();
438 ASSERT( pNd, "is no NoTxtNode!" );
439 if( pNd->HasAutomaticContour() )
441 StartAllAction();
442 pNd->SetContour( NULL, FALSE );
443 SwFlyFrm *pFly = (SwFlyFrm*)pNd->GetFrm()->GetUpper();
444 const SwFmtSurround &rSur = pFly->GetFmt()->GetSurround();
445 pFly->GetFmt()->SwModify::Modify( (SwFmtSurround*)&rSur,
446 (SwFmtSurround*)&rSur );
447 GetDoc()->SetModified();
448 EndAllAction();
452 /******************************************************************************
453 * liefert Pointer auf ein SvInPlaceObjectRef, wenn CurCrsr->GetPoint() auf
454 * einen SwOLENode zeigt (und GetMark nicht gesetzt ist
455 * oder auf das gleiche SvInPlaceObjectRef zeigt)
456 * besorgt den Pointer vom Doc wenn das Objekt per Namen gesucht werden
457 * soll
458 ******************************************************************************/
460 svt::EmbeddedObjectRef& SwEditShell::GetOLEObject() const
462 ASSERT( CNT_OLE == GetCntType(), "GetOLEObj: kein OLENode." );
463 ASSERT( !GetCrsr()->HasMark() ||
464 (GetCrsr()->HasMark() &&
465 GetCrsr()->GetPoint()->nNode == GetCrsr()->GetMark()->nNode),
466 "GetOLEObj: kein OLENode." );
468 SwOLENode *pOLENode = GetCrsr()->GetNode()->GetOLENode();
469 ASSERT( pOLENode, "GetOLEObj: kein OLENode." );
470 SwOLEObj& rOObj = pOLENode->GetOLEObj();
471 return rOObj.GetObject();
475 BOOL SwEditShell::HasOLEObj( const String &rName ) const
477 SwStartNode *pStNd;
478 SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
479 while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
481 aIdx++;
482 SwNode& rNd = aIdx.GetNode();
483 if( rNd.IsOLENode() &&
484 rName == ((SwOLENode&)rNd).GetChartTblName() &&
485 ((SwOLENode&)rNd).GetFrm() )
486 return TRUE;
488 aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
490 return FALSE;
494 void SwEditShell::SetChartName( const String &rName )
496 SwOLENode *pONd = GetCrsr()->GetNode()->GetOLENode();
497 ASSERT( pONd, "ChartNode not found" );
498 pONd->SetChartTblName( rName );
501 void SwEditShell::UpdateCharts( const String &rName )
503 GetDoc()->UpdateCharts( rName );
507 /******************************************************************************
508 * Aenderung des Tabellennamens
509 ******************************************************************************/
511 void SwEditShell::SetTableName( SwFrmFmt& rTblFmt, const String &rNewName )
513 GetDoc()->SetTableName( rTblFmt, rNewName );
516 // erfragen des akt. Wortes
518 String SwEditShell::GetCurWord()
520 const SwPaM& rPaM = *GetCrsr();
521 const SwTxtNode* pNd = rPaM.GetNode()->GetTxtNode();
522 String aString = pNd ?
523 pNd->GetCurWord(rPaM.GetPoint()->nContent.GetIndex()) :
524 aEmptyStr;
525 return aString;
528 /****************************************************************************
529 * void SwEditShell::UpdateDocStat( SwDocStat& rStat )
530 ****************************************************************************/
533 void SwEditShell::UpdateDocStat( SwDocStat& rStat )
535 StartAllAction();
536 GetDoc()->UpdateDocStat( rStat );
537 EndAllAction();
540 // OPT: eddocinl.cxx
543 // returne zum Namen die im Doc gesetzte Referenz
544 const SwFmtRefMark* SwEditShell::GetRefMark( const String& rName ) const
546 return GetDoc()->GetRefMark( rName );
549 // returne die Namen aller im Doc gesetzten Referenzen
550 USHORT SwEditShell::GetRefMarks( SvStringsDtor* pStrings ) const
552 return GetDoc()->GetRefMarks( pStrings );
555 /******************************************************************************
556 * DropCap-SS
557 ******************************************************************************/
560 String SwEditShell::GetDropTxt( const USHORT nChars ) const
563 * pb: made changes for #i74939#
565 * always return a string even though there is a selection
568 String aTxt;
569 SwPaM* pCrsr = GetCrsr();
570 if ( IsMultiSelection() )
572 // if a multi selection exists, search for the first line
573 // -> it is the cursor with the lowest index
574 ULONG nIndex = pCrsr->GetMark()->nNode.GetIndex();
575 bool bPrev = true;
576 SwPaM* pLast = pCrsr;
577 SwPaM* pTemp = pCrsr;
578 while ( bPrev )
580 SwPaM* pPrev2 = dynamic_cast< SwPaM* >( pTemp->GetPrev() );
581 bPrev = ( pPrev2 && pPrev2 != pLast );
582 if ( bPrev )
584 pTemp = pPrev2;
585 ULONG nTemp = pPrev2->GetMark()->nNode.GetIndex();
586 if ( nTemp < nIndex )
588 nIndex = nTemp;
589 pCrsr = pPrev2;
595 SwTxtNode* pTxtNd = pCrsr->GetNode( !pCrsr->HasMark() )->GetTxtNode();
596 if( pTxtNd )
598 xub_StrLen nDropLen = pTxtNd->GetDropLen( nChars );
599 if( nDropLen )
600 aTxt = pTxtNd->GetTxt().Copy( 0, nDropLen );
603 return aTxt;
606 void SwEditShell::ReplaceDropTxt( const String &rStr )
608 SwPaM* pCrsr = GetCrsr();
609 if( pCrsr->GetPoint()->nNode == pCrsr->GetMark()->nNode &&
610 pCrsr->GetNode()->GetTxtNode()->IsTxtNode() )
612 StartAllAction();
614 const SwNodeIndex& rNd = pCrsr->GetPoint()->nNode;
615 SwPaM aPam( rNd, rStr.Len(), rNd, 0 );
616 if( !GetDoc()->Overwrite( aPam, rStr ) )
618 ASSERT( FALSE, "Doc->Overwrite(Str) failed." );
621 EndAllAction();
625 /******************************************************************************
626 * Methode :
627 * Beschreibung:
628 * Erstellt : OK 25.04.94 13:45
629 * Aenderung :
630 ******************************************************************************/
632 String SwEditShell::Calculate()
634 String aFormel; // die entgueltige Formel
635 SwPaM *pPaMLast = (SwPaM*)GetCrsr()->GetNext(),
636 *pPaM = pPaMLast; // die Pointer auf Cursor
637 SwCalc aCalc( *GetDoc() );
638 const CharClass& rCC = GetAppCharClass();
640 do {
641 SwTxtNode* pTxtNd = pPaM->GetNode()->GetTxtNode();
642 if(pTxtNd)
644 const SwPosition *pStart = pPaM->Start(), *pEnd = pPaM->End();
645 xub_StrLen nStt = pStart->nContent.GetIndex();
646 String aStr = pTxtNd->GetExpandTxt( nStt, pEnd->nContent.
647 GetIndex() - nStt );
649 rCC.toLower( aStr );
651 sal_Unicode ch;
652 BOOL bValidFlds = FALSE;
653 xub_StrLen nPos = 0;
655 while( nPos < aStr.Len() )
657 ch = aStr.GetChar( nPos++ );
658 if( rCC.isLetter( aStr, nPos-1 ) || ch == '_' )
660 xub_StrLen nTmpStt = nPos-1;
661 while( nPos < aStr.Len() &&
662 0 != ( ch = aStr.GetChar( nPos++ )) &&
663 (rCC.isLetterNumeric( aStr, nPos - 1 ) ||
664 ch == '_'|| ch == '.' ))
667 if( nPos < aStr.Len() )
668 --nPos;
670 String sVar( aStr.Copy( nTmpStt, nPos - nTmpStt ));
671 if( !::FindOperator( sVar ) &&
672 (::Find( sVar, aCalc.GetVarTable(),TBLSZ) ||
673 aCalc.VarLook( sVar )) )
675 if( !bValidFlds )
677 GetDoc()->FldsToCalc( aCalc,
678 pStart->nNode.GetIndex(),
679 pStart->nContent.GetIndex() );
680 bValidFlds = TRUE;
682 (( aFormel += '(' ) +=
683 aCalc.GetStrResult( aCalc.VarLook( sVar )
684 ->nValue )) += ')';
686 else
687 aFormel += sVar;
689 else
690 aFormel += ch;
693 } while( pPaMLast != (pPaM = (SwPaM*)pPaM->GetNext()) );
695 return aCalc.GetStrResult( aCalc.Calculate(aFormel) );
699 SvxLinkManager& SwEditShell::GetLinkManager()
701 return pDoc->GetLinkManager();
705 void *SwEditShell::GetIMapInventor() const
707 //Als eindeutige Identifikation sollte der Node, auf dem der Crsr steht
708 //genuegen.
709 return (void*)GetCrsr()->GetNode();
712 // --> OD 2007-03-01 #i73788#
713 // remove default parameter, because method is always called this default value
714 Graphic SwEditShell::GetIMapGraphic() const
716 //Liefert immer eine Graphic, wenn der Crsr in einem Fly steht.
717 SET_CURR_SHELL( (ViewShell*)this );
718 Graphic aRet;
719 SwPaM* pCrsr = GetCrsr();
720 if ( !pCrsr->HasMark() )
722 SwNode *pNd =pCrsr->GetNode();
723 if( pNd->IsGrfNode() )
725 const Graphic& rGrf = ((SwGrfNode*)pNd)->GetGrf();
726 if( rGrf.IsSwapOut() || ( ((SwGrfNode*)pNd)->IsLinkedFile() &&
727 GRAPHIC_DEFAULT == rGrf.GetType() ) )
729 #ifndef PRODUCT
730 ASSERT( ((SwGrfNode*)pNd)->SwapIn( TRUE ) || !TRUE, "Grafik konnte nicht geladen werden" );
731 #else
732 ((SwGrfNode*)pNd)->SwapIn( TRUE );
733 #endif
735 aRet = rGrf;
737 else if ( pNd->IsOLENode() )
739 aRet = *((SwOLENode*)pNd)->GetGraphic();
741 else
743 SwFlyFrm* pFlyFrm = pNd->GetCntntNode()->GetFrm()->FindFlyFrm();
744 if(pFlyFrm)
745 aRet = pFlyFrm->GetFmt()->MakeGraphic();
748 return aRet;
752 BOOL SwEditShell::InsertURL( const SwFmtINetFmt& rFmt, const String& rStr, BOOL bKeepSelection )
754 // URL und Hinweistext (direkt oder via Selektion) notwendig
755 if( !rFmt.GetValue().Len() || ( !rStr.Len() && !HasSelection() ) )
756 return FALSE;
757 StartAllAction();
758 GetDoc()->StartUndo( UNDO_UI_INSERT_URLTXT, NULL);
759 BOOL bInsTxt = TRUE;
761 if( rStr.Len() )
763 SwPaM* pCrsr = GetCrsr();
764 if( pCrsr->HasMark() && *pCrsr->GetPoint() != *pCrsr->GetMark() )
766 // Selection vorhanden, MehrfachSelektion?
767 BOOL bDelTxt = TRUE;
768 if( pCrsr->GetNext() == pCrsr )
770 // einfach Selection -> Text ueberpruefen
771 String sTxt( GetSelTxt() );
772 sTxt.EraseTrailingChars();
773 if( sTxt == rStr )
774 bDelTxt = bInsTxt = FALSE;
776 else if( rFmt.GetValue() == rStr ) // Name und URL gleich?
777 bDelTxt = bInsTxt = FALSE;
779 if( bDelTxt )
780 Delete();
782 else if( pCrsr->GetNext() != pCrsr && rFmt.GetValue() == rStr )
783 bInsTxt = FALSE;
785 if( bInsTxt )
787 Insert2( rStr );
788 SetMark();
789 ExtendSelection( FALSE, rStr.Len() );
792 else
793 bInsTxt = FALSE;
795 SetAttr( rFmt );
796 if (bInsTxt && !IsCrsrPtAtEnd())
797 SwapPam();
798 if(!bKeepSelection)
799 ClearMark();
800 if( bInsTxt )
801 DontExpandFmt();
802 GetDoc()->EndUndo( UNDO_UI_INSERT_URLTXT, NULL );
803 EndAllAction();
804 return TRUE;
808 USHORT SwEditShell::GetINetAttrs( SwGetINetAttrs& rArr )
810 if( rArr.Count() )
811 rArr.DeleteAndDestroy( 0, rArr.Count() );
813 const SwTxtNode* pTxtNd;
814 const SwCharFmts* pFmts = GetDoc()->GetCharFmts();
815 for( USHORT n = pFmts->Count(); 1 < n; )
817 SwClientIter aIter( *(*pFmts)[ --n ] );
819 for( SwClient* pFnd = aIter.First(TYPE( SwTxtINetFmt ));
820 pFnd; pFnd = aIter.Next() )
821 if( 0 != ( pTxtNd = ((SwTxtINetFmt*)pFnd)->GetpTxtNode()) &&
822 pTxtNd->GetNodes().IsDocNodes() )
824 SwTxtINetFmt& rAttr = *(SwTxtINetFmt*)pFnd;
825 String sTxt( pTxtNd->GetExpandTxt( *rAttr.GetStart(),
826 *rAttr.GetEnd() - *rAttr.GetStart() ) );
828 sTxt.EraseAllChars( 0x0a );
829 sTxt.EraseLeadingChars().EraseTrailingChars();
831 if( sTxt.Len() )
833 SwGetINetAttr* pNew = new SwGetINetAttr( sTxt, rAttr );
834 rArr.C40_INSERT( SwGetINetAttr, pNew, rArr.Count() );
838 return rArr.Count();
842 // ist der Cursor in eine INetAttribut, dann wird das komplett
843 // geloescht; inclusive des Hinweistextes (wird beim Drag&Drop gebraucht)
844 BOOL SwEditShell::DelINetAttrWithText()
846 BOOL bRet = SelectTxtAttr( RES_TXTATR_INETFMT, FALSE );
847 if( bRet )
848 DeleteSel( *GetCrsr() );
849 return bRet;
853 // setzen an den Textzeichenattributen das DontExpand-Flag
854 BOOL SwEditShell::DontExpandFmt()
856 BOOL bRet = FALSE;
857 if( !IsTableMode() && GetDoc()->DontExpandFmt( *GetCrsr()->GetPoint() ))
859 bRet = TRUE;
860 CallChgLnk();
862 return bRet;
865 SvNumberFormatter* SwEditShell::GetNumberFormatter()
867 return GetDoc()->GetNumberFormatter();
870 BOOL SwEditShell::RemoveInvisibleContent()
872 StartAllAction();
873 BOOL bRet = GetDoc()->RemoveInvisibleContent();
874 EndAllAction();
875 return bRet;
877 BOOL SwEditShell::ConvertFieldsToText()
879 StartAllAction();
880 BOOL bRet = GetDoc()->ConvertFieldsToText();
881 EndAllAction();
882 return bRet;
884 void SwEditShell::SetNumberingRestart()
886 StartAllAction();
887 Push();
888 //iterate over all text contents - body, frames, header, footer, footnote text
889 SwPaM* pCrsr = GetCrsr();
890 for(sal_uInt16 i = 0; i < 2; i++)
892 if(!i)
893 MakeFindRange(DOCPOS_START, DOCPOS_END, pCrsr); //body content
894 else
895 MakeFindRange(DOCPOS_OTHERSTART, DOCPOS_OTHEREND, pCrsr); //extra content
896 SwPosition* pSttPos = pCrsr->Start(), *pEndPos = pCrsr->End();
897 ULONG nCurrNd = pSttPos->nNode.GetIndex();
898 ULONG nEndNd = pEndPos->nNode.GetIndex();
899 if( nCurrNd <= nEndNd )
901 SwCntntFrm* pCntFrm;
902 sal_Bool bGoOn = sal_True;
903 //iterate over all paragraphs
904 while( bGoOn )
906 SwNode* pNd = GetDoc()->GetNodes()[ nCurrNd ];
907 switch( pNd->GetNodeType() )
909 case ND_TEXTNODE:
910 if( 0 != ( pCntFrm = ((SwTxtNode*)pNd)->GetFrm()) )
912 //jump over hidden frames - ignore protection!
913 if( !((SwTxtFrm*)pCntFrm)->IsHiddenNow() )
915 //if the node is numbered and the starting value of the numbering equals the
916 //start value of the numbering rule then set this value as hard starting value
918 //get the node num
919 // OD 2005-11-09
920 SwTxtNode* pTxtNd( static_cast<SwTxtNode*>(pNd) );
921 SwNumRule* pNumRule( pTxtNd->GetNumRule() );
923 if ( pNumRule && pTxtNd->GetNum() &&
924 ( pTxtNd->HasNumber() || pTxtNd->HasBullet() ) &&
925 pTxtNd->IsCountedInList() &&
926 !pTxtNd->IsListRestart() &&
927 pTxtNd->GetNum()->GetNumber() ==
928 pNumRule->Get( static_cast<USHORT>(pTxtNd->GetActualListLevel()) ).GetStart() )
930 //now set a the start value as attribute
931 SwPosition aCurrentNode(*pNd);
932 GetDoc()->SetNumRuleStart( aCurrentNode, sal_True );
936 break;
937 case ND_SECTIONNODE:
938 // jump over hidden sections - ignore protection!
939 if(((SwSectionNode*)pNd)->GetSection().IsHidden() )
940 nCurrNd = pNd->EndOfSectionIndex();
941 break;
942 case ND_ENDNODE:
944 break;
948 bGoOn = nCurrNd < nEndNd;
949 ++nCurrNd;
955 Pop(FALSE);
956 EndAllAction();
959 USHORT SwEditShell::GetLineCount( BOOL bActPos )
961 USHORT nRet = 0;
962 CalcLayout();
963 SwPaM* pPam = GetCrsr();
964 SwNodeIndex& rPtIdx = pPam->GetPoint()->nNode;
965 SwNodeIndex aStart( rPtIdx );
966 SwCntntNode* pCNd;
967 SwCntntFrm *pCntFrm = 0;
968 ULONG nTmpPos;
970 if( !bActPos )
971 aStart = 0;
972 else if( rPtIdx > ( nTmpPos = GetDoc()->GetNodes().GetEndOfExtras().GetIndex()) )
973 // BodyBereich => Start ist EndOfIcons + 1
974 aStart = nTmpPos + 1;
975 else
977 if( 0 != ( pCNd = pPam->GetCntntNode() ) &&
978 0 != ( pCntFrm = pCNd->GetFrm() ) )
980 const SwStartNode *pTmp;
981 if( pCntFrm->IsInFly() ) // Fly
982 pTmp = pCNd->FindFlyStartNode();
983 else if( pCntFrm->IsInFtn() ) // Footnote
984 pTmp = pCNd->FindFootnoteStartNode();
985 else
986 { // Footer/Header
987 const USHORT nTyp = FRM_HEADER | FRM_FOOTER;
988 SwFrm* pFrm = pCntFrm;
989 while( pFrm && !(pFrm->GetType() & nTyp) )
990 pFrm = pFrm->GetUpper();
991 ASSERT( pFrm, "Wo bin ich?" );
992 if( pFrm && ( pFrm->GetType() & FRM_FOOTER ) )
993 pTmp = pCNd->FindFooterStartNode();
994 else
995 pTmp = pCNd->FindHeaderStartNode();
997 ASSERT( pTmp, "Missing StartNode" );
998 aStart = *pTmp;
1000 ASSERT( pCNd && pCntFrm, "Missing Layout-Information" );
1003 while( 0 != ( pCNd = GetDoc()->GetNodes().GoNextSection(
1004 &aStart, TRUE, FALSE )) && ( !bActPos || aStart <= rPtIdx ) )
1006 if( 0 != ( pCntFrm = pCNd->GetFrm() ) && pCntFrm->IsTxtFrm() )
1008 xub_StrLen nActPos = bActPos && aStart == rPtIdx ?
1009 pPam->GetPoint()->nContent.GetIndex() : USHRT_MAX;
1010 nRet = nRet + ((SwTxtFrm*)pCntFrm)->GetLineCount( nActPos );
1013 return nRet;
1016 long SwEditShell::CompareDoc( const SwDoc& rDoc )
1018 StartAllAction();
1019 long nRet = GetDoc()->CompareDoc( rDoc );
1020 EndAllAction();
1021 return nRet;
1024 long SwEditShell::MergeDoc( const SwDoc& rDoc )
1026 StartAllAction();
1027 long nRet = GetDoc()->MergeDoc( rDoc );
1028 EndAllAction();
1029 return nRet;
1033 const SwFtnInfo& SwEditShell::GetFtnInfo() const
1035 return GetDoc()->GetFtnInfo();
1038 void SwEditShell::SetFtnInfo(const SwFtnInfo& rInfo)
1040 StartAllAction();
1041 SET_CURR_SHELL( this );
1042 GetDoc()->SetFtnInfo(rInfo);
1043 CallChgLnk();
1044 EndAllAction();
1047 const SwEndNoteInfo& SwEditShell::GetEndNoteInfo() const
1049 return GetDoc()->GetEndNoteInfo();
1052 void SwEditShell::SetEndNoteInfo(const SwEndNoteInfo& rInfo)
1054 StartAllAction();
1055 SET_CURR_SHELL( this );
1056 GetDoc()->SetEndNoteInfo(rInfo);
1057 EndAllAction();
1060 const SwLineNumberInfo& SwEditShell::GetLineNumberInfo() const
1062 return GetDoc()->GetLineNumberInfo();
1065 void SwEditShell::SetLineNumberInfo(const SwLineNumberInfo& rInfo)
1067 StartAllAction();
1068 SET_CURR_SHELL( this );
1069 GetDoc()->SetLineNumberInfo(rInfo);
1070 AddPaintRect( GetLayout()->Frm() );
1071 EndAllAction();
1074 USHORT SwEditShell::GetLinkUpdMode(BOOL bDocSettings) const
1076 return getIDocumentSettingAccess()->getLinkUpdateMode( !bDocSettings );
1079 void SwEditShell::SetLinkUpdMode( USHORT nMode )
1081 getIDocumentSettingAccess()->setLinkUpdateMode( nMode );
1085 // Schnittstelle fuer die TextInputDaten - ( fuer die Texteingabe
1086 // von japanischen/chinesischen Zeichen)
1087 SwExtTextInput* SwEditShell::CreateExtTextInput(LanguageType eInputLanguage)
1089 SwExtTextInput* pRet = GetDoc()->CreateExtTextInput( *GetCrsr() );
1090 pRet->SetLanguage(eInputLanguage);
1091 pRet->SetOverwriteCursor( SwCrsrShell::IsOverwriteCrsr() );
1092 return pRet;
1095 String SwEditShell::DeleteExtTextInput( SwExtTextInput* pDel, BOOL bInsText )
1097 if( !pDel )
1099 const SwPosition& rPos = *GetCrsr()->GetPoint();
1100 pDel = GetDoc()->GetExtTextInput( rPos.nNode.GetNode(),
1101 rPos.nContent.GetIndex() );
1102 if( !pDel )
1104 //JP 25.10.2001: under UNIX the cursor is moved before the Input-
1105 // Engine event comes in. So take any - normally there
1106 // exist only one at the time. -- Task 92016
1107 pDel = GetDoc()->GetExtTextInput();
1110 String sRet;
1111 if( pDel )
1113 rtl::OUString sTmp;
1114 SwXTextCursor::getTextFromPam(*pDel, sTmp);
1115 sRet = sTmp;
1116 SET_CURR_SHELL( this );
1117 StartAllAction();
1118 pDel->SetInsText( bInsText );
1119 SetOverwriteCrsr( pDel->IsOverwriteCursor() );
1120 const SwPosition aPos( *pDel->GetPoint() );
1121 GetDoc()->DeleteExtTextInput( pDel );
1123 // In this case, the "replace" function did not set the cursor
1124 // to the original position. Therefore we have to do this manually.
1125 if ( ! bInsText && IsOverwriteCrsr() )
1126 *GetCrsr()->GetPoint() = aPos;
1128 EndAllAction();
1130 return sRet;
1133 void SwEditShell::SetExtTextInputData( const CommandExtTextInputData& rData )
1135 const SwPosition& rPos = *GetCrsr()->GetPoint();
1136 SwExtTextInput* pInput = GetDoc()->GetExtTextInput( rPos.nNode.GetNode()
1137 /*, rPos.nContent.GetIndex()*/ );
1138 if( pInput )
1140 StartAllAction();
1141 SET_CURR_SHELL( this );
1143 if( !rData.IsOnlyCursorChanged() )
1144 pInput->SetInputData( rData );
1145 // Cursor positionieren:
1146 const SwPosition& rStt = *pInput->Start();
1147 xub_StrLen nNewCrsrPos = rStt.nContent.GetIndex() + rData.GetCursorPos();
1149 // zwar unschoen aber was hilfts
1150 ShowCrsr();
1151 long nDiff = nNewCrsrPos - rPos.nContent.GetIndex();
1152 if( 0 > nDiff )
1153 Left( (xub_StrLen)-nDiff, CRSR_SKIP_CHARS );
1154 else if( 0 < nDiff )
1155 Right( (xub_StrLen)nDiff, CRSR_SKIP_CHARS );
1157 SetOverwriteCrsr( rData.IsCursorOverwrite() );
1159 EndAllAction();
1161 if( !rData.IsCursorVisible() ) // must be called after the EndAction
1162 HideCrsr();
1166 void SwEditShell::TransliterateText( sal_uInt32 nType )
1168 utl::TransliterationWrapper aTrans(
1169 ::comphelper::getProcessServiceFactory(), nType );
1170 StartAllAction();
1171 SET_CURR_SHELL( this );
1173 SwPaM* pCrsr = GetCrsr();
1174 if( pCrsr->GetNext() != pCrsr )
1176 GetDoc()->StartUndo(UNDO_EMPTY, NULL);
1177 FOREACHPAM_START( this )
1179 if( PCURCRSR->HasMark() )
1180 GetDoc()->TransliterateText( *PCURCRSR, aTrans );
1182 FOREACHPAM_END()
1183 GetDoc()->EndUndo(UNDO_EMPTY, NULL);
1185 else
1186 GetDoc()->TransliterateText( *pCrsr, aTrans );
1188 EndAllAction();
1191 void SwEditShell::CountWords( SwDocStat& rStat ) const
1193 FOREACHPAM_START( this )
1195 if( PCURCRSR->HasMark() )
1196 GetDoc()->CountWords( *PCURCRSR, rStat );
1198 FOREACHPAM_END()