update dev300-m58
[ooovba.git] / sw / source / core / edit / editsh.cxx
blobbff28a1d29f15d9f9b7e4dbb5b7396c841cbfbac
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 if( !GetDoc()->Insert(*PCURCRSR, c) )
91 ASSERT( FALSE, "Doc->Insert(c) failed." )
94 SaveTblBoxCntnt( PCURCRSR->GetPoint() );
95 if( bOnlyCurrCrsr )
96 break;
98 FOREACHPAM_END()
100 EndAllAction();
104 /******************************************************************************
105 * void SwEditShell::Insert(const String &rStr)
106 ******************************************************************************/
109 void SwEditShell::Insert(const String &rStr)
111 StartAllAction();
113 SwPaM *_pStartCrsr = getShellCrsr( true ), *__pStartCrsr = _pStartCrsr;
114 do {
115 //OPT: GetSystemCharSet
116 if( !GetDoc()->Insert( *_pStartCrsr, rStr, true ) )
118 ASSERT( FALSE, "Doc->Insert(Str) failed." )
121 SaveTblBoxCntnt( _pStartCrsr->GetPoint() );
123 } while( (_pStartCrsr=(SwPaM *)_pStartCrsr->GetNext()) != __pStartCrsr );
126 // calculate cursor bidi level
127 SwCursor* pTmpCrsr = _GetCrsr();
128 const BOOL bDoNotSetBidiLevel = ! pTmpCrsr ||
129 ( 0 != dynamic_cast<SwUnoCrsr*>(pTmpCrsr) );
131 if ( ! bDoNotSetBidiLevel )
133 SwNode& rNode = pTmpCrsr->GetPoint()->nNode.GetNode();
134 if ( rNode.IsTxtNode() )
136 SwIndex& rIdx = pTmpCrsr->GetPoint()->nContent;
137 xub_StrLen nPos = rIdx.GetIndex();
138 xub_StrLen nPrevPos = nPos;
139 if ( nPrevPos )
140 --nPrevPos;
142 SwScriptInfo* pSI = SwScriptInfo::GetScriptInfo( ((SwTxtNode&)rNode),
143 sal_True );
145 BYTE nLevel = 0;
146 if ( ! pSI )
148 // seems to be an empty paragraph.
149 Point aPt;
150 SwCntntFrm* pFrm =
151 ((SwTxtNode&)rNode).GetFrm( &aPt, pTmpCrsr->GetPoint(),
152 sal_False );
154 SwScriptInfo aScriptInfo;
155 aScriptInfo.InitScriptInfo( (SwTxtNode&)rNode, pFrm->IsRightToLeft() );
156 nLevel = aScriptInfo.DirType( nPrevPos );
158 else
160 if ( STRING_LEN != pSI->GetInvalidity() )
161 pSI->InitScriptInfo( (SwTxtNode&)rNode );
162 nLevel = pSI->DirType( nPrevPos );
165 pTmpCrsr->SetCrsrBidiLevel( nLevel );
169 SetInFrontOfLabel( FALSE ); // #i27615#
171 EndAllAction();
175 /******************************************************************************
176 * void SwEditShell::Overwrite(const String &rStr)
177 ******************************************************************************/
180 void SwEditShell::Overwrite(const String &rStr)
182 StartAllAction();
183 FOREACHPAM_START(this)
184 if( !GetDoc()->Overwrite(*PCURCRSR, rStr ) )
186 ASSERT( FALSE, "Doc->Overwrite(Str) failed." )
188 SaveTblBoxCntnt( PCURCRSR->GetPoint() );
189 FOREACHPAM_END()
190 EndAllAction();
194 /******************************************************************************
195 * long SwEditShell::SplitNode()
196 ******************************************************************************/
198 long SwEditShell::SplitNode( BOOL bAutoFormat, BOOL bCheckTableStart )
200 StartAllAction();
201 GetDoc()->StartUndo(UNDO_EMPTY, NULL);
203 FOREACHPAM_START(this)
204 // eine Tabellen Zelle wird jetzt zu einer normalen Textzelle!
205 GetDoc()->ClearBoxNumAttrs( PCURCRSR->GetPoint()->nNode );
206 GetDoc()->SplitNode( *PCURCRSR->GetPoint(), bCheckTableStart );
207 FOREACHPAM_END()
209 GetDoc()->EndUndo(UNDO_EMPTY, NULL);
211 if( bAutoFormat )
212 AutoFmtBySplitNode();
214 ClearTblBoxCntnt();
216 EndAllAction();
217 return(1L);
220 /*-- 11.05.2004 09:41:20---------------------------------------------------
222 -----------------------------------------------------------------------*/
223 sal_Bool SwEditShell::AppendTxtNode()
225 sal_Bool bRet = sal_False;
226 StartAllAction();
227 GetDoc()->StartUndo(UNDO_EMPTY, NULL);
229 FOREACHPAM_START(this)
230 GetDoc()->ClearBoxNumAttrs( PCURCRSR->GetPoint()->nNode );
231 bRet = GetDoc()->AppendTxtNode( *PCURCRSR->GetPoint()) || bRet;
232 FOREACHPAM_END()
234 GetDoc()->EndUndo(UNDO_EMPTY, NULL);
236 ClearTblBoxCntnt();
238 EndAllAction();
239 return bRet;
242 /******************************************************************************
243 * liefert einen Pointer auf einen SwGrfNode; dieser wird von
244 * GetGraphic() und GetGraphicSize() verwendet.
245 ******************************************************************************/
248 SwGrfNode * SwEditShell::_GetGrfNode() const
250 SwGrfNode *pGrfNode = 0;
251 SwPaM* pCrsr = GetCrsr();
252 if( !pCrsr->HasMark() ||
253 pCrsr->GetPoint()->nNode == pCrsr->GetMark()->nNode )
254 pGrfNode = pCrsr->GetPoint()->nNode.GetNode().GetGrfNode();
256 return pGrfNode;
258 /******************************************************************************
259 * liefert Pointer auf eine Graphic, wenn CurCrsr->GetPoint() auf
260 * einen SwGrfNode zeigt (und GetMark nicht gesetzt ist
261 * oder auf die gleiche Graphic zeigt)
262 ******************************************************************************/
264 // --> OD 2005-02-09 #119353# - robust
265 const Graphic* SwEditShell::GetGraphic( BOOL bWait ) const
267 SwGrfNode* pGrfNode = _GetGrfNode();
268 // --> OD 2005-02-09 #119353# - robust
269 const Graphic* pGrf( 0L );
270 if ( pGrfNode )
272 pGrf = &(pGrfNode->GetGrf());
273 // --> OD 2007-03-01 #i73788#
274 // no load of linked graphic, if its not needed now (bWait = FALSE).
275 if ( bWait )
277 if( pGrf->IsSwapOut() ||
278 ( pGrfNode->IsLinkedFile() && GRAPHIC_DEFAULT == pGrf->GetType() ) )
280 #ifndef PRODUCT
281 ASSERT( pGrfNode->SwapIn( bWait ) || !bWait, "Grafik konnte nicht geladen werden" );
282 #else
283 pGrfNode->SwapIn( bWait );
284 #endif
287 else
289 if ( pGrf->IsSwapOut() && !pGrfNode->IsLinkedFile() )
291 #ifndef PRODUCT
292 ASSERT( pGrfNode->SwapIn( bWait ) || !bWait, "Grafik konnte nicht geladen werden" );
293 #else
294 pGrfNode->SwapIn( bWait );
295 #endif
298 // <--
300 return pGrf;
301 // <--
304 BOOL SwEditShell::IsGrfSwapOut( BOOL bOnlyLinked ) const
306 SwGrfNode *pGrfNode = _GetGrfNode();
307 return pGrfNode &&
308 (bOnlyLinked ? ( pGrfNode->IsLinkedFile() &&
309 ( GRAPHIC_DEFAULT == pGrfNode->GetGrfObj().GetType()||
310 pGrfNode->GetGrfObj().IsSwappedOut()))
311 : pGrfNode->GetGrfObj().IsSwappedOut());
314 // --> OD 2005-02-09 #119353# - robust
315 const GraphicObject* SwEditShell::GetGraphicObj() const
317 SwGrfNode* pGrfNode = _GetGrfNode();
318 // --> OD 2005-02-09 #119353# - robust
319 return pGrfNode ? &(pGrfNode->GetGrfObj()) : 0L;
320 // <--
323 USHORT SwEditShell::GetGraphicType() const
325 SwGrfNode *pGrfNode = _GetGrfNode();
326 return static_cast<USHORT>(pGrfNode ? pGrfNode->GetGrfObj().GetType() : GRAPHIC_NONE);
329 /******************************************************************************
330 * liefert die Groesse der Graphic, wenn CurCrsr->GetPoint() auf
331 * einen SwGrfNode zeigt (und GetMark nicht gesetzt ist
332 * oder auf die gleiche Graphic zeigt)
333 ******************************************************************************/
335 BOOL SwEditShell::GetGrfSize(Size& rSz) const
337 SwNoTxtNode* pNoTxtNd;
338 SwPaM* pCurrentCrsr = GetCrsr();
339 if( ( !pCurrentCrsr->HasMark()
340 || pCurrentCrsr->GetPoint()->nNode == pCurrentCrsr->GetMark()->nNode )
341 && 0 != ( pNoTxtNd = pCurrentCrsr->GetNode()->GetNoTxtNode() ) )
343 rSz = pNoTxtNd->GetTwipSize();
344 return TRUE;
346 return FALSE;
349 /******************************************************************************
350 * erneutes Einlesen, falls Graphic nicht Ok ist. Die
351 * aktuelle wird durch die neue ersetzt.
352 ******************************************************************************/
354 void SwEditShell::ReRead( const String& rGrfName, const String& rFltName,
355 const Graphic* pGraphic, const GraphicObject* pGrfObj )
357 StartAllAction();
358 pDoc->ReRead( *GetCrsr(), rGrfName, rFltName, pGraphic, pGrfObj );
359 EndAllAction();
363 /******************************************************************************
364 * liefert den Namen und den FilterNamen einer Graphic, wenn der Cursor
365 * auf einer Graphic steht
366 * Ist ein String-Ptr != 0 dann returne den entsp. Namen
367 ******************************************************************************/
370 void SwEditShell::GetGrfNms( String* pGrfName, String* pFltName,
371 const SwFlyFrmFmt* pFmt ) const
373 ASSERT( pGrfName || pFltName, "was wird denn nun erfragt?" );
374 if( pFmt )
375 GetDoc()->GetGrfNms( *pFmt, pGrfName, pFltName );
376 else
378 SwGrfNode *pGrfNode = _GetGrfNode();
379 if( pGrfNode && pGrfNode->IsLinkedFile() )
380 pGrfNode->GetFileFilterNms( pGrfName, pFltName );
385 // alternativen Text abfragen/setzen
386 //const String& SwEditShell::GetAlternateText() const
388 // SwPaM* pCrsr = GetCrsr();
389 // const SwNoTxtNode* pNd;
390 // if( !pCrsr->HasMark() && 0 != ( pNd = pCrsr->GetNode()->GetNoTxtNode()) )
391 // return pNd->GetAlternateText();
393 // return aEmptyStr;
397 //void SwEditShell::SetAlternateText( const String& rTxt )
399 // SwPaM* pCrsr = GetCrsr();
400 // SwNoTxtNode* pNd;
401 // if( !pCrsr->HasMark() && 0 != ( pNd = pCrsr->GetNode()->GetNoTxtNode()) )
402 // {
403 // pNd->SetAlternateText( rTxt, sal_True );
404 // GetDoc()->SetModified();
405 // }
409 const PolyPolygon *SwEditShell::GetGraphicPolygon() const
411 SwNoTxtNode *pNd = GetCrsr()->GetNode()->GetNoTxtNode();
412 return pNd->HasContour();
416 void SwEditShell::SetGraphicPolygon( const PolyPolygon *pPoly )
418 SwNoTxtNode *pNd = GetCrsr()->GetNode()->GetNoTxtNode();
419 StartAllAction();
420 pNd->SetContour( pPoly );
421 SwFlyFrm *pFly = (SwFlyFrm*)pNd->GetFrm()->GetUpper();
422 const SwFmtSurround &rSur = pFly->GetFmt()->GetSurround();
423 pFly->GetFmt()->SwModify::Modify( (SwFmtSurround*)&rSur,
424 (SwFmtSurround*)&rSur );
425 GetDoc()->SetModified();
426 EndAllAction();
429 void SwEditShell::ClearAutomaticContour()
431 SwNoTxtNode *pNd = GetCrsr()->GetNode()->GetNoTxtNode();
432 ASSERT( pNd, "is no NoTxtNode!" );
433 if( pNd->HasAutomaticContour() )
435 StartAllAction();
436 pNd->SetContour( NULL, FALSE );
437 SwFlyFrm *pFly = (SwFlyFrm*)pNd->GetFrm()->GetUpper();
438 const SwFmtSurround &rSur = pFly->GetFmt()->GetSurround();
439 pFly->GetFmt()->SwModify::Modify( (SwFmtSurround*)&rSur,
440 (SwFmtSurround*)&rSur );
441 GetDoc()->SetModified();
442 EndAllAction();
446 /******************************************************************************
447 * liefert Pointer auf ein SvInPlaceObjectRef, wenn CurCrsr->GetPoint() auf
448 * einen SwOLENode zeigt (und GetMark nicht gesetzt ist
449 * oder auf das gleiche SvInPlaceObjectRef zeigt)
450 * besorgt den Pointer vom Doc wenn das Objekt per Namen gesucht werden
451 * soll
452 ******************************************************************************/
454 svt::EmbeddedObjectRef& SwEditShell::GetOLEObject() const
456 ASSERT( CNT_OLE == GetCntType(), "GetOLEObj: kein OLENode." );
457 ASSERT( !GetCrsr()->HasMark() ||
458 (GetCrsr()->HasMark() &&
459 GetCrsr()->GetPoint()->nNode == GetCrsr()->GetMark()->nNode),
460 "GetOLEObj: kein OLENode." );
462 SwOLENode *pOLENode = GetCrsr()->GetNode()->GetOLENode();
463 ASSERT( pOLENode, "GetOLEObj: kein OLENode." );
464 SwOLEObj& rOObj = pOLENode->GetOLEObj();
465 return rOObj.GetObject();
469 BOOL SwEditShell::HasOLEObj( const String &rName ) const
471 SwStartNode *pStNd;
472 SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
473 while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
475 aIdx++;
476 SwNode& rNd = aIdx.GetNode();
477 if( rNd.IsOLENode() &&
478 rName == ((SwOLENode&)rNd).GetChartTblName() &&
479 ((SwOLENode&)rNd).GetFrm() )
480 return TRUE;
482 aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
484 return FALSE;
488 void SwEditShell::SetChartName( const String &rName )
490 SwOLENode *pONd = GetCrsr()->GetNode()->GetOLENode();
491 ASSERT( pONd, "ChartNode not found" );
492 pONd->SetChartTblName( rName );
495 void SwEditShell::UpdateCharts( const String &rName )
497 GetDoc()->UpdateCharts( rName );
501 /******************************************************************************
502 * Aenderung des Tabellennamens
503 ******************************************************************************/
505 void SwEditShell::SetTableName( SwFrmFmt& rTblFmt, const String &rNewName )
507 GetDoc()->SetTableName( rTblFmt, rNewName );
510 // erfragen des akt. Wortes
512 String SwEditShell::GetCurWord()
514 const SwPaM& rPaM = *GetCrsr();
515 const SwTxtNode* pNd = rPaM.GetNode()->GetTxtNode();
516 String aString = pNd ?
517 pNd->GetCurWord(rPaM.GetPoint()->nContent.GetIndex()) :
518 aEmptyStr;
519 return aString;
522 /****************************************************************************
523 * void SwEditShell::UpdateDocStat( SwDocStat& rStat )
524 ****************************************************************************/
527 void SwEditShell::UpdateDocStat( SwDocStat& rStat )
529 StartAllAction();
530 GetDoc()->UpdateDocStat( rStat );
531 EndAllAction();
534 // OPT: eddocinl.cxx
537 // returne zum Namen die im Doc gesetzte Referenz
538 const SwFmtRefMark* SwEditShell::GetRefMark( const String& rName ) const
540 return GetDoc()->GetRefMark( rName );
543 // returne die Namen aller im Doc gesetzten Referenzen
544 USHORT SwEditShell::GetRefMarks( SvStringsDtor* pStrings ) const
546 return GetDoc()->GetRefMarks( pStrings );
549 /******************************************************************************
550 * DropCap-SS
551 ******************************************************************************/
554 String SwEditShell::GetDropTxt( const USHORT nChars ) const
557 * pb: made changes for #i74939#
559 * always return a string even though there is a selection
562 String aTxt;
563 SwPaM* pCrsr = GetCrsr();
564 if ( IsMultiSelection() )
566 // if a multi selection exists, search for the first line
567 // -> it is the cursor with the lowest index
568 ULONG nIndex = pCrsr->GetMark()->nNode.GetIndex();
569 bool bPrev = true;
570 SwPaM* pLast = pCrsr;
571 SwPaM* pTemp = pCrsr;
572 while ( bPrev )
574 SwPaM* pPrev2 = dynamic_cast< SwPaM* >( pTemp->GetPrev() );
575 bPrev = ( pPrev2 && pPrev2 != pLast );
576 if ( bPrev )
578 pTemp = pPrev2;
579 ULONG nTemp = pPrev2->GetMark()->nNode.GetIndex();
580 if ( nTemp < nIndex )
582 nIndex = nTemp;
583 pCrsr = pPrev2;
589 SwTxtNode* pTxtNd = pCrsr->GetNode( !pCrsr->HasMark() )->GetTxtNode();
590 if( pTxtNd )
592 xub_StrLen nDropLen = pTxtNd->GetDropLen( nChars );
593 if( nDropLen )
594 aTxt = pTxtNd->GetTxt().Copy( 0, nDropLen );
597 return aTxt;
600 void SwEditShell::ReplaceDropTxt( const String &rStr )
602 SwPaM* pCrsr = GetCrsr();
603 if( pCrsr->GetPoint()->nNode == pCrsr->GetMark()->nNode &&
604 pCrsr->GetNode()->GetTxtNode()->IsTxtNode() )
606 StartAllAction();
608 const SwNodeIndex& rNd = pCrsr->GetPoint()->nNode;
609 SwPaM aPam( rNd, rStr.Len(), rNd, 0 );
610 if( !GetDoc()->Overwrite( aPam, rStr ) )
612 ASSERT( FALSE, "Doc->Overwrite(Str) failed." );
615 EndAllAction();
619 /******************************************************************************
620 * Methode :
621 * Beschreibung:
622 * Erstellt : OK 25.04.94 13:45
623 * Aenderung :
624 ******************************************************************************/
626 String SwEditShell::Calculate()
628 String aFormel; // die entgueltige Formel
629 SwPaM *pPaMLast = (SwPaM*)GetCrsr()->GetNext(),
630 *pPaM = pPaMLast; // die Pointer auf Cursor
631 SwCalc aCalc( *GetDoc() );
632 const CharClass& rCC = GetAppCharClass();
634 do {
635 SwTxtNode* pTxtNd = pPaM->GetNode()->GetTxtNode();
636 if(pTxtNd)
638 const SwPosition *pStart = pPaM->Start(), *pEnd = pPaM->End();
639 xub_StrLen nStt = pStart->nContent.GetIndex();
640 String aStr = pTxtNd->GetExpandTxt( nStt, pEnd->nContent.
641 GetIndex() - nStt );
643 rCC.toLower( aStr );
645 sal_Unicode ch;
646 BOOL bValidFlds = FALSE;
647 xub_StrLen nPos = 0;
649 while( nPos < aStr.Len() )
651 ch = aStr.GetChar( nPos++ );
652 if( rCC.isLetter( aStr, nPos-1 ) || ch == '_' )
654 xub_StrLen nTmpStt = nPos-1;
655 while( nPos < aStr.Len() &&
656 0 != ( ch = aStr.GetChar( nPos++ )) &&
657 (rCC.isLetterNumeric( aStr, nPos - 1 ) ||
658 ch == '_'|| ch == '.' ))
661 if( nPos < aStr.Len() )
662 --nPos;
664 String sVar( aStr.Copy( nTmpStt, nPos - nTmpStt ));
665 if( !::FindOperator( sVar ) &&
666 (::Find( sVar, aCalc.GetVarTable(),TBLSZ) ||
667 aCalc.VarLook( sVar )) )
669 if( !bValidFlds )
671 GetDoc()->FldsToCalc( aCalc,
672 pStart->nNode.GetIndex(),
673 pStart->nContent.GetIndex() );
674 bValidFlds = TRUE;
676 (( aFormel += '(' ) +=
677 aCalc.GetStrResult( aCalc.VarLook( sVar )
678 ->nValue )) += ')';
680 else
681 aFormel += sVar;
683 else
684 aFormel += ch;
687 } while( pPaMLast != (pPaM = (SwPaM*)pPaM->GetNext()) );
689 return aCalc.GetStrResult( aCalc.Calculate(aFormel) );
693 SvxLinkManager& SwEditShell::GetLinkManager()
695 return pDoc->GetLinkManager();
699 void *SwEditShell::GetIMapInventor() const
701 //Als eindeutige Identifikation sollte der Node, auf dem der Crsr steht
702 //genuegen.
703 return (void*)GetCrsr()->GetNode();
706 // --> OD 2007-03-01 #i73788#
707 // remove default parameter, because method is always called this default value
708 Graphic SwEditShell::GetIMapGraphic() const
710 //Liefert immer eine Graphic, wenn der Crsr in einem Fly steht.
711 SET_CURR_SHELL( (ViewShell*)this );
712 Graphic aRet;
713 SwPaM* pCrsr = GetCrsr();
714 if ( !pCrsr->HasMark() )
716 SwNode *pNd =pCrsr->GetNode();
717 if( pNd->IsGrfNode() )
719 const Graphic& rGrf = ((SwGrfNode*)pNd)->GetGrf();
720 if( rGrf.IsSwapOut() || ( ((SwGrfNode*)pNd)->IsLinkedFile() &&
721 GRAPHIC_DEFAULT == rGrf.GetType() ) )
723 #ifndef PRODUCT
724 ASSERT( ((SwGrfNode*)pNd)->SwapIn( TRUE ) || !TRUE, "Grafik konnte nicht geladen werden" );
725 #else
726 ((SwGrfNode*)pNd)->SwapIn( TRUE );
727 #endif
729 aRet = rGrf;
731 else if ( pNd->IsOLENode() )
733 aRet = *((SwOLENode*)pNd)->GetGraphic();
735 else
737 SwFlyFrm* pFlyFrm = pNd->GetCntntNode()->GetFrm()->FindFlyFrm();
738 if(pFlyFrm)
739 aRet = pFlyFrm->GetFmt()->MakeGraphic();
742 return aRet;
746 BOOL SwEditShell::InsertURL( const SwFmtINetFmt& rFmt, const String& rStr, BOOL bKeepSelection )
748 // URL und Hinweistext (direkt oder via Selektion) notwendig
749 if( !rFmt.GetValue().Len() || ( !rStr.Len() && !HasSelection() ) )
750 return FALSE;
751 StartAllAction();
752 GetDoc()->StartUndo( UNDO_UI_INSERT_URLTXT, NULL);
753 BOOL bInsTxt = TRUE;
755 if( rStr.Len() )
757 SwPaM* pCrsr = GetCrsr();
758 if( pCrsr->HasMark() && *pCrsr->GetPoint() != *pCrsr->GetMark() )
760 // Selection vorhanden, MehrfachSelektion?
761 BOOL bDelTxt = TRUE;
762 if( pCrsr->GetNext() == pCrsr )
764 // einfach Selection -> Text ueberpruefen
765 String sTxt( GetSelTxt() );
766 sTxt.EraseTrailingChars();
767 if( sTxt == rStr )
768 bDelTxt = bInsTxt = FALSE;
770 else if( rFmt.GetValue() == rStr ) // Name und URL gleich?
771 bDelTxt = bInsTxt = FALSE;
773 if( bDelTxt )
774 Delete();
776 else if( pCrsr->GetNext() != pCrsr && rFmt.GetValue() == rStr )
777 bInsTxt = FALSE;
779 if( bInsTxt )
781 Insert( rStr );
782 SetMark();
783 ExtendSelection( FALSE, rStr.Len() );
786 else
787 bInsTxt = FALSE;
789 SetAttr( rFmt );
790 if (bInsTxt && !IsCrsrPtAtEnd())
791 SwapPam();
792 if(!bKeepSelection)
793 ClearMark();
794 if( bInsTxt )
795 DontExpandFmt();
796 GetDoc()->EndUndo( UNDO_UI_INSERT_URLTXT, NULL );
797 EndAllAction();
798 return TRUE;
802 USHORT SwEditShell::GetINetAttrs( SwGetINetAttrs& rArr )
804 if( rArr.Count() )
805 rArr.DeleteAndDestroy( 0, rArr.Count() );
807 const SwTxtNode* pTxtNd;
808 const SwCharFmts* pFmts = GetDoc()->GetCharFmts();
809 for( USHORT n = pFmts->Count(); 1 < n; )
811 SwClientIter aIter( *(*pFmts)[ --n ] );
813 for( SwClient* pFnd = aIter.First(TYPE( SwTxtINetFmt ));
814 pFnd; pFnd = aIter.Next() )
815 if( 0 != ( pTxtNd = ((SwTxtINetFmt*)pFnd)->GetpTxtNode()) &&
816 pTxtNd->GetNodes().IsDocNodes() )
818 SwTxtINetFmt& rAttr = *(SwTxtINetFmt*)pFnd;
819 String sTxt( pTxtNd->GetExpandTxt( *rAttr.GetStart(),
820 *rAttr.GetEnd() - *rAttr.GetStart() ) );
822 sTxt.EraseAllChars( 0x0a );
823 sTxt.EraseLeadingChars().EraseTrailingChars();
825 if( sTxt.Len() )
827 SwGetINetAttr* pNew = new SwGetINetAttr( sTxt, rAttr );
828 rArr.C40_INSERT( SwGetINetAttr, pNew, rArr.Count() );
832 return rArr.Count();
836 // ist der Cursor in eine INetAttribut, dann wird das komplett
837 // geloescht; inclusive des Hinweistextes (wird beim Drag&Drop gebraucht)
838 BOOL SwEditShell::DelINetAttrWithText()
840 BOOL bRet = SelectTxtAttr( RES_TXTATR_INETFMT, FALSE );
841 if( bRet )
842 DeleteSel( *GetCrsr() );
843 return bRet;
847 // setzen an den Textzeichenattributen das DontExpand-Flag
848 BOOL SwEditShell::DontExpandFmt()
850 BOOL bRet = FALSE;
851 if( !IsTableMode() && GetDoc()->DontExpandFmt( *GetCrsr()->GetPoint() ))
853 bRet = TRUE;
854 CallChgLnk();
856 return bRet;
859 SvNumberFormatter* SwEditShell::GetNumberFormatter()
861 return GetDoc()->GetNumberFormatter();
864 BOOL SwEditShell::RemoveInvisibleContent()
866 StartAllAction();
867 BOOL bRet = GetDoc()->RemoveInvisibleContent();
868 EndAllAction();
869 return bRet;
871 BOOL SwEditShell::ConvertFieldsToText()
873 StartAllAction();
874 BOOL bRet = GetDoc()->ConvertFieldsToText();
875 EndAllAction();
876 return bRet;
878 void SwEditShell::SetNumberingRestart()
880 StartAllAction();
881 Push();
882 //iterate over all text contents - body, frames, header, footer, footnote text
883 SwPaM* pCrsr = GetCrsr();
884 for(sal_uInt16 i = 0; i < 2; i++)
886 if(!i)
887 MakeFindRange(DOCPOS_START, DOCPOS_END, pCrsr); //body content
888 else
889 MakeFindRange(DOCPOS_OTHERSTART, DOCPOS_OTHEREND, pCrsr); //extra content
890 SwPosition* pSttPos = pCrsr->Start(), *pEndPos = pCrsr->End();
891 ULONG nCurrNd = pSttPos->nNode.GetIndex();
892 ULONG nEndNd = pEndPos->nNode.GetIndex();
893 if( nCurrNd <= nEndNd )
895 SwCntntFrm* pCntFrm;
896 sal_Bool bGoOn = sal_True;
897 //iterate over all paragraphs
898 while( bGoOn )
900 SwNode* pNd = GetDoc()->GetNodes()[ nCurrNd ];
901 switch( pNd->GetNodeType() )
903 case ND_TEXTNODE:
904 if( 0 != ( pCntFrm = ((SwTxtNode*)pNd)->GetFrm()) )
906 //jump over hidden frames - ignore protection!
907 if( !((SwTxtFrm*)pCntFrm)->IsHiddenNow() )
909 //if the node is numbered and the starting value of the numbering equals the
910 //start value of the numbering rule then set this value as hard starting value
912 //get the node num
913 // OD 2005-11-09
914 SwTxtNode* pTxtNd( static_cast<SwTxtNode*>(pNd) );
915 SwNumRule* pNumRule( pTxtNd->GetNumRule() );
917 if ( pNumRule && pTxtNd->GetNum() &&
918 ( pTxtNd->HasNumber() || pTxtNd->HasBullet() ) &&
919 pTxtNd->IsCountedInList() &&
920 !pTxtNd->IsListRestart() &&
921 pTxtNd->GetNum()->GetNumber() ==
922 pNumRule->Get( static_cast<USHORT>(pTxtNd->GetActualListLevel()) ).GetStart() )
924 //now set a the start value as attribute
925 SwPosition aCurrentNode(*pNd);
926 GetDoc()->SetNumRuleStart( aCurrentNode, sal_True );
930 break;
931 case ND_SECTIONNODE:
932 // jump over hidden sections - ignore protection!
933 if(((SwSectionNode*)pNd)->GetSection().IsHidden() )
934 nCurrNd = pNd->EndOfSectionIndex();
935 break;
936 case ND_ENDNODE:
938 break;
942 bGoOn = nCurrNd < nEndNd;
943 ++nCurrNd;
949 Pop(FALSE);
950 EndAllAction();
953 USHORT SwEditShell::GetLineCount( BOOL bActPos )
955 USHORT nRet = 0;
956 CalcLayout();
957 SwPaM* pPam = GetCrsr();
958 SwNodeIndex& rPtIdx = pPam->GetPoint()->nNode;
959 SwNodeIndex aStart( rPtIdx );
960 SwCntntNode* pCNd;
961 SwCntntFrm *pCntFrm = 0;
962 ULONG nTmpPos;
964 if( !bActPos )
965 aStart = 0;
966 else if( rPtIdx > ( nTmpPos = GetDoc()->GetNodes().GetEndOfExtras().GetIndex()) )
967 // BodyBereich => Start ist EndOfIcons + 1
968 aStart = nTmpPos + 1;
969 else
971 if( 0 != ( pCNd = pPam->GetCntntNode() ) &&
972 0 != ( pCntFrm = pCNd->GetFrm() ) )
974 const SwStartNode *pTmp;
975 if( pCntFrm->IsInFly() ) // Fly
976 pTmp = pCNd->FindFlyStartNode();
977 else if( pCntFrm->IsInFtn() ) // Footnote
978 pTmp = pCNd->FindFootnoteStartNode();
979 else
980 { // Footer/Header
981 const USHORT nTyp = FRM_HEADER | FRM_FOOTER;
982 SwFrm* pFrm = pCntFrm;
983 while( pFrm && !(pFrm->GetType() & nTyp) )
984 pFrm = pFrm->GetUpper();
985 ASSERT( pFrm, "Wo bin ich?" );
986 if( pFrm && ( pFrm->GetType() & FRM_FOOTER ) )
987 pTmp = pCNd->FindFooterStartNode();
988 else
989 pTmp = pCNd->FindHeaderStartNode();
991 ASSERT( pTmp, "Missing StartNode" );
992 aStart = *pTmp;
994 ASSERT( pCNd && pCntFrm, "Missing Layout-Information" );
997 while( 0 != ( pCNd = GetDoc()->GetNodes().GoNextSection(
998 &aStart, TRUE, FALSE )) && ( !bActPos || aStart <= rPtIdx ) )
1000 if( 0 != ( pCntFrm = pCNd->GetFrm() ) && pCntFrm->IsTxtFrm() )
1002 xub_StrLen nActPos = bActPos && aStart == rPtIdx ?
1003 pPam->GetPoint()->nContent.GetIndex() : USHRT_MAX;
1004 nRet = nRet + ((SwTxtFrm*)pCntFrm)->GetLineCount( nActPos );
1007 return nRet;
1010 long SwEditShell::CompareDoc( const SwDoc& rDoc )
1012 StartAllAction();
1013 long nRet = GetDoc()->CompareDoc( rDoc );
1014 EndAllAction();
1015 return nRet;
1018 long SwEditShell::MergeDoc( const SwDoc& rDoc )
1020 StartAllAction();
1021 long nRet = GetDoc()->MergeDoc( rDoc );
1022 EndAllAction();
1023 return nRet;
1027 const SwFtnInfo& SwEditShell::GetFtnInfo() const
1029 return GetDoc()->GetFtnInfo();
1032 void SwEditShell::SetFtnInfo(const SwFtnInfo& rInfo)
1034 StartAllAction();
1035 SET_CURR_SHELL( this );
1036 GetDoc()->SetFtnInfo(rInfo);
1037 CallChgLnk();
1038 EndAllAction();
1041 const SwEndNoteInfo& SwEditShell::GetEndNoteInfo() const
1043 return GetDoc()->GetEndNoteInfo();
1046 void SwEditShell::SetEndNoteInfo(const SwEndNoteInfo& rInfo)
1048 StartAllAction();
1049 SET_CURR_SHELL( this );
1050 GetDoc()->SetEndNoteInfo(rInfo);
1051 EndAllAction();
1054 const SwLineNumberInfo& SwEditShell::GetLineNumberInfo() const
1056 return GetDoc()->GetLineNumberInfo();
1059 void SwEditShell::SetLineNumberInfo(const SwLineNumberInfo& rInfo)
1061 StartAllAction();
1062 SET_CURR_SHELL( this );
1063 GetDoc()->SetLineNumberInfo(rInfo);
1064 AddPaintRect( GetLayout()->Frm() );
1065 EndAllAction();
1068 USHORT SwEditShell::GetLinkUpdMode(BOOL bDocSettings) const
1070 return getIDocumentSettingAccess()->getLinkUpdateMode( !bDocSettings );
1073 void SwEditShell::SetLinkUpdMode( USHORT nMode )
1075 getIDocumentSettingAccess()->setLinkUpdateMode( nMode );
1079 // Schnittstelle fuer die TextInputDaten - ( fuer die Texteingabe
1080 // von japanischen/chinesischen Zeichen)
1081 SwExtTextInput* SwEditShell::CreateExtTextInput(LanguageType eInputLanguage)
1083 SwExtTextInput* pRet = GetDoc()->CreateExtTextInput( *GetCrsr() );
1084 pRet->SetLanguage(eInputLanguage);
1085 pRet->SetOverwriteCursor( SwCrsrShell::IsOverwriteCrsr() );
1086 return pRet;
1089 String SwEditShell::DeleteExtTextInput( SwExtTextInput* pDel, BOOL bInsText )
1091 if( !pDel )
1093 const SwPosition& rPos = *GetCrsr()->GetPoint();
1094 pDel = GetDoc()->GetExtTextInput( rPos.nNode.GetNode(),
1095 rPos.nContent.GetIndex() );
1096 if( !pDel )
1098 //JP 25.10.2001: under UNIX the cursor is moved before the Input-
1099 // Engine event comes in. So take any - normally there
1100 // exist only one at the time. -- Task 92016
1101 pDel = GetDoc()->GetExtTextInput();
1104 String sRet;
1105 if( pDel )
1107 rtl::OUString sTmp;
1108 SwXTextCursor::getTextFromPam(*pDel, sTmp);
1109 sRet = sTmp;
1110 SET_CURR_SHELL( this );
1111 StartAllAction();
1112 pDel->SetInsText( bInsText );
1113 SetOverwriteCrsr( pDel->IsOverwriteCursor() );
1114 const SwPosition aPos( *pDel->GetPoint() );
1115 GetDoc()->DeleteExtTextInput( pDel );
1117 // In this case, the "replace" function did not set the cursor
1118 // to the original position. Therefore we have to do this manually.
1119 if ( ! bInsText && IsOverwriteCrsr() )
1120 *GetCrsr()->GetPoint() = aPos;
1122 EndAllAction();
1124 return sRet;
1127 void SwEditShell::SetExtTextInputData( const CommandExtTextInputData& rData )
1129 const SwPosition& rPos = *GetCrsr()->GetPoint();
1130 SwExtTextInput* pInput = GetDoc()->GetExtTextInput( rPos.nNode.GetNode()
1131 /*, rPos.nContent.GetIndex()*/ );
1132 if( pInput )
1134 StartAllAction();
1135 SET_CURR_SHELL( this );
1137 if( !rData.IsOnlyCursorChanged() )
1138 pInput->SetInputData( rData );
1139 // Cursor positionieren:
1140 const SwPosition& rStt = *pInput->Start();
1141 xub_StrLen nNewCrsrPos = rStt.nContent.GetIndex() + rData.GetCursorPos();
1143 // zwar unschoen aber was hilfts
1144 ShowCrsr();
1145 long nDiff = nNewCrsrPos - rPos.nContent.GetIndex();
1146 if( 0 > nDiff )
1147 Left( (xub_StrLen)-nDiff, CRSR_SKIP_CHARS );
1148 else if( 0 < nDiff )
1149 Right( (xub_StrLen)nDiff, CRSR_SKIP_CHARS );
1151 SetOverwriteCrsr( rData.IsCursorOverwrite() );
1153 EndAllAction();
1155 if( !rData.IsCursorVisible() ) // must be called after the EndAction
1156 HideCrsr();
1160 void SwEditShell::TransliterateText( sal_uInt32 nType )
1162 utl::TransliterationWrapper aTrans(
1163 ::comphelper::getProcessServiceFactory(), nType );
1164 StartAllAction();
1165 SET_CURR_SHELL( this );
1167 SwPaM* pCrsr = GetCrsr();
1168 if( pCrsr->GetNext() != pCrsr )
1170 GetDoc()->StartUndo(UNDO_EMPTY, NULL);
1171 FOREACHPAM_START( this )
1173 if( PCURCRSR->HasMark() )
1174 GetDoc()->TransliterateText( *PCURCRSR, aTrans );
1176 FOREACHPAM_END()
1177 GetDoc()->EndUndo(UNDO_EMPTY, NULL);
1179 else
1180 GetDoc()->TransliterateText( *pCrsr, aTrans );
1182 EndAllAction();
1185 void SwEditShell::CountWords( SwDocStat& rStat ) const
1187 FOREACHPAM_START( this )
1189 if( PCURCRSR->HasMark() )
1190 GetDoc()->CountWords( *PCURCRSR, rStat );
1192 FOREACHPAM_END()