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 $
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>
41 #include <fmtsrnd.hxx>
42 #include <fmtinfmt.hxx>
43 #include <txtinet.hxx>
45 #include <charfmt.hxx>
52 #include <ndtxt.hxx> // fuer SwTxtNode
55 #include <swtable.hxx>
56 #include <swundo.hxx> // UNDO_START, UNDO_END
62 #include <rootfrm.hxx>
63 #include <extinput.hxx>
64 #include <crsskip.hxx>
65 #include <scriptinfo.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
)
87 FOREACHPAM_START(this)
89 if( !GetDoc()->Insert(*PCURCRSR
, c
) )
91 ASSERT( FALSE
, "Doc->Insert(c) failed." )
94 SaveTblBoxCntnt( PCURCRSR
->GetPoint() );
104 /******************************************************************************
105 * void SwEditShell::Insert(const String &rStr)
106 ******************************************************************************/
109 void SwEditShell::Insert(const String
&rStr
)
113 SwPaM
*_pStartCrsr
= getShellCrsr( true ), *__pStartCrsr
= _pStartCrsr
;
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
;
142 SwScriptInfo
* pSI
= SwScriptInfo::GetScriptInfo( ((SwTxtNode
&)rNode
),
148 // seems to be an empty paragraph.
151 ((SwTxtNode
&)rNode
).GetFrm( &aPt
, pTmpCrsr
->GetPoint(),
154 SwScriptInfo aScriptInfo
;
155 aScriptInfo
.InitScriptInfo( (SwTxtNode
&)rNode
, pFrm
->IsRightToLeft() );
156 nLevel
= aScriptInfo
.DirType( nPrevPos
);
160 if ( STRING_LEN
!= pSI
->GetInvalidity() )
161 pSI
->InitScriptInfo( (SwTxtNode
&)rNode
);
162 nLevel
= pSI
->DirType( nPrevPos
);
165 pTmpCrsr
->SetCrsrBidiLevel( nLevel
);
169 SetInFrontOfLabel( FALSE
); // #i27615#
175 /******************************************************************************
176 * void SwEditShell::Overwrite(const String &rStr)
177 ******************************************************************************/
180 void SwEditShell::Overwrite(const String
&rStr
)
183 FOREACHPAM_START(this)
184 if( !GetDoc()->Overwrite(*PCURCRSR
, rStr
) )
186 ASSERT( FALSE
, "Doc->Overwrite(Str) failed." )
188 SaveTblBoxCntnt( PCURCRSR
->GetPoint() );
194 /******************************************************************************
195 * long SwEditShell::SplitNode()
196 ******************************************************************************/
198 long SwEditShell::SplitNode( BOOL bAutoFormat
, BOOL bCheckTableStart
)
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
);
209 GetDoc()->EndUndo(UNDO_EMPTY
, NULL
);
212 AutoFmtBySplitNode();
220 /*-- 11.05.2004 09:41:20---------------------------------------------------
222 -----------------------------------------------------------------------*/
223 sal_Bool
SwEditShell::AppendTxtNode()
225 sal_Bool bRet
= sal_False
;
227 GetDoc()->StartUndo(UNDO_EMPTY
, NULL
);
229 FOREACHPAM_START(this)
230 GetDoc()->ClearBoxNumAttrs( PCURCRSR
->GetPoint()->nNode
);
231 bRet
= GetDoc()->AppendTxtNode( *PCURCRSR
->GetPoint()) || bRet
;
234 GetDoc()->EndUndo(UNDO_EMPTY
, NULL
);
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();
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 );
272 pGrf
= &(pGrfNode
->GetGrf());
273 // --> OD 2007-03-01 #i73788#
274 // no load of linked graphic, if its not needed now (bWait = FALSE).
277 if( pGrf
->IsSwapOut() ||
278 ( pGrfNode
->IsLinkedFile() && GRAPHIC_DEFAULT
== pGrf
->GetType() ) )
281 ASSERT( pGrfNode
->SwapIn( bWait
) || !bWait
, "Grafik konnte nicht geladen werden" );
283 pGrfNode
->SwapIn( bWait
);
289 if ( pGrf
->IsSwapOut() && !pGrfNode
->IsLinkedFile() )
292 ASSERT( pGrfNode
->SwapIn( bWait
) || !bWait
, "Grafik konnte nicht geladen werden" );
294 pGrfNode
->SwapIn( bWait
);
304 BOOL
SwEditShell::IsGrfSwapOut( BOOL bOnlyLinked
) const
306 SwGrfNode
*pGrfNode
= _GetGrfNode();
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;
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();
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
)
358 pDoc
->ReRead( *GetCrsr(), rGrfName
, rFltName
, pGraphic
, pGrfObj
);
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?" );
375 GetDoc()->GetGrfNms( *pFmt
, pGrfName
, pFltName
);
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();
397 //void SwEditShell::SetAlternateText( const String& rTxt )
399 // SwPaM* pCrsr = GetCrsr();
401 // if( !pCrsr->HasMark() && 0 != ( pNd = pCrsr->GetNode()->GetNoTxtNode()) )
403 // pNd->SetAlternateText( rTxt, sal_True );
404 // GetDoc()->SetModified();
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();
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();
429 void SwEditShell::ClearAutomaticContour()
431 SwNoTxtNode
*pNd
= GetCrsr()->GetNode()->GetNoTxtNode();
432 ASSERT( pNd
, "is no NoTxtNode!" );
433 if( pNd
->HasAutomaticContour() )
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();
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
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
472 SwNodeIndex
aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
473 while ( 0 != (pStNd
= aIdx
.GetNode().GetStartNode()) )
476 SwNode
& rNd
= aIdx
.GetNode();
477 if( rNd
.IsOLENode() &&
478 rName
== ((SwOLENode
&)rNd
).GetChartTblName() &&
479 ((SwOLENode
&)rNd
).GetFrm() )
482 aIdx
.Assign( *pStNd
->EndOfSectionNode(), + 1 );
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()) :
522 /****************************************************************************
523 * void SwEditShell::UpdateDocStat( SwDocStat& rStat )
524 ****************************************************************************/
527 void SwEditShell::UpdateDocStat( SwDocStat
& rStat
)
530 GetDoc()->UpdateDocStat( rStat
);
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 /******************************************************************************
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
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();
570 SwPaM
* pLast
= pCrsr
;
571 SwPaM
* pTemp
= pCrsr
;
574 SwPaM
* pPrev2
= dynamic_cast< SwPaM
* >( pTemp
->GetPrev() );
575 bPrev
= ( pPrev2
&& pPrev2
!= pLast
);
579 ULONG nTemp
= pPrev2
->GetMark()->nNode
.GetIndex();
580 if ( nTemp
< nIndex
)
589 SwTxtNode
* pTxtNd
= pCrsr
->GetNode( !pCrsr
->HasMark() )->GetTxtNode();
592 xub_StrLen nDropLen
= pTxtNd
->GetDropLen( nChars
);
594 aTxt
= pTxtNd
->GetTxt().Copy( 0, nDropLen
);
600 void SwEditShell::ReplaceDropTxt( const String
&rStr
)
602 SwPaM
* pCrsr
= GetCrsr();
603 if( pCrsr
->GetPoint()->nNode
== pCrsr
->GetMark()->nNode
&&
604 pCrsr
->GetNode()->GetTxtNode()->IsTxtNode() )
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." );
619 /******************************************************************************
622 * Erstellt : OK 25.04.94 13:45
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();
635 SwTxtNode
* pTxtNd
= pPaM
->GetNode()->GetTxtNode();
638 const SwPosition
*pStart
= pPaM
->Start(), *pEnd
= pPaM
->End();
639 xub_StrLen nStt
= pStart
->nContent
.GetIndex();
640 String aStr
= pTxtNd
->GetExpandTxt( nStt
, pEnd
->nContent
.
646 BOOL bValidFlds
= FALSE
;
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() )
664 String
sVar( aStr
.Copy( nTmpStt
, nPos
- nTmpStt
));
665 if( !::FindOperator( sVar
) &&
666 (::Find( sVar
, aCalc
.GetVarTable(),TBLSZ
) ||
667 aCalc
.VarLook( sVar
)) )
671 GetDoc()->FldsToCalc( aCalc
,
672 pStart
->nNode
.GetIndex(),
673 pStart
->nContent
.GetIndex() );
676 (( aFormel
+= '(' ) +=
677 aCalc
.GetStrResult( aCalc
.VarLook( sVar
)
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
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 );
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() ) )
724 ASSERT( ((SwGrfNode
*)pNd
)->SwapIn( TRUE
) || !TRUE
, "Grafik konnte nicht geladen werden" );
726 ((SwGrfNode
*)pNd
)->SwapIn( TRUE
);
731 else if ( pNd
->IsOLENode() )
733 aRet
= *((SwOLENode
*)pNd
)->GetGraphic();
737 SwFlyFrm
* pFlyFrm
= pNd
->GetCntntNode()->GetFrm()->FindFlyFrm();
739 aRet
= pFlyFrm
->GetFmt()->MakeGraphic();
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() ) )
752 GetDoc()->StartUndo( UNDO_UI_INSERT_URLTXT
, NULL
);
757 SwPaM
* pCrsr
= GetCrsr();
758 if( pCrsr
->HasMark() && *pCrsr
->GetPoint() != *pCrsr
->GetMark() )
760 // Selection vorhanden, MehrfachSelektion?
762 if( pCrsr
->GetNext() == pCrsr
)
764 // einfach Selection -> Text ueberpruefen
765 String
sTxt( GetSelTxt() );
766 sTxt
.EraseTrailingChars();
768 bDelTxt
= bInsTxt
= FALSE
;
770 else if( rFmt
.GetValue() == rStr
) // Name und URL gleich?
771 bDelTxt
= bInsTxt
= FALSE
;
776 else if( pCrsr
->GetNext() != pCrsr
&& rFmt
.GetValue() == rStr
)
783 ExtendSelection( FALSE
, rStr
.Len() );
790 if (bInsTxt
&& !IsCrsrPtAtEnd())
796 GetDoc()->EndUndo( UNDO_UI_INSERT_URLTXT
, NULL
);
802 USHORT
SwEditShell::GetINetAttrs( SwGetINetAttrs
& rArr
)
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();
827 SwGetINetAttr
* pNew
= new SwGetINetAttr( sTxt
, rAttr
);
828 rArr
.C40_INSERT( SwGetINetAttr
, pNew
, 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
);
842 DeleteSel( *GetCrsr() );
847 // setzen an den Textzeichenattributen das DontExpand-Flag
848 BOOL
SwEditShell::DontExpandFmt()
851 if( !IsTableMode() && GetDoc()->DontExpandFmt( *GetCrsr()->GetPoint() ))
859 SvNumberFormatter
* SwEditShell::GetNumberFormatter()
861 return GetDoc()->GetNumberFormatter();
864 BOOL
SwEditShell::RemoveInvisibleContent()
867 BOOL bRet
= GetDoc()->RemoveInvisibleContent();
871 BOOL
SwEditShell::ConvertFieldsToText()
874 BOOL bRet
= GetDoc()->ConvertFieldsToText();
878 void SwEditShell::SetNumberingRestart()
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
++)
887 MakeFindRange(DOCPOS_START
, DOCPOS_END
, pCrsr
); //body content
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
)
896 sal_Bool bGoOn
= sal_True
;
897 //iterate over all paragraphs
900 SwNode
* pNd
= GetDoc()->GetNodes()[ nCurrNd
];
901 switch( pNd
->GetNodeType() )
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
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
);
932 // jump over hidden sections - ignore protection!
933 if(((SwSectionNode
*)pNd
)->GetSection().IsHidden() )
934 nCurrNd
= pNd
->EndOfSectionIndex();
942 bGoOn
= nCurrNd
< nEndNd
;
953 USHORT
SwEditShell::GetLineCount( BOOL bActPos
)
957 SwPaM
* pPam
= GetCrsr();
958 SwNodeIndex
& rPtIdx
= pPam
->GetPoint()->nNode
;
959 SwNodeIndex
aStart( rPtIdx
);
961 SwCntntFrm
*pCntFrm
= 0;
966 else if( rPtIdx
> ( nTmpPos
= GetDoc()->GetNodes().GetEndOfExtras().GetIndex()) )
967 // BodyBereich => Start ist EndOfIcons + 1
968 aStart
= nTmpPos
+ 1;
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();
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();
989 pTmp
= pCNd
->FindHeaderStartNode();
991 ASSERT( pTmp
, "Missing StartNode" );
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
);
1010 long SwEditShell::CompareDoc( const SwDoc
& rDoc
)
1013 long nRet
= GetDoc()->CompareDoc( rDoc
);
1018 long SwEditShell::MergeDoc( const SwDoc
& rDoc
)
1021 long nRet
= GetDoc()->MergeDoc( rDoc
);
1027 const SwFtnInfo
& SwEditShell::GetFtnInfo() const
1029 return GetDoc()->GetFtnInfo();
1032 void SwEditShell::SetFtnInfo(const SwFtnInfo
& rInfo
)
1035 SET_CURR_SHELL( this );
1036 GetDoc()->SetFtnInfo(rInfo
);
1041 const SwEndNoteInfo
& SwEditShell::GetEndNoteInfo() const
1043 return GetDoc()->GetEndNoteInfo();
1046 void SwEditShell::SetEndNoteInfo(const SwEndNoteInfo
& rInfo
)
1049 SET_CURR_SHELL( this );
1050 GetDoc()->SetEndNoteInfo(rInfo
);
1054 const SwLineNumberInfo
& SwEditShell::GetLineNumberInfo() const
1056 return GetDoc()->GetLineNumberInfo();
1059 void SwEditShell::SetLineNumberInfo(const SwLineNumberInfo
& rInfo
)
1062 SET_CURR_SHELL( this );
1063 GetDoc()->SetLineNumberInfo(rInfo
);
1064 AddPaintRect( GetLayout()->Frm() );
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() );
1089 String
SwEditShell::DeleteExtTextInput( SwExtTextInput
* pDel
, BOOL bInsText
)
1093 const SwPosition
& rPos
= *GetCrsr()->GetPoint();
1094 pDel
= GetDoc()->GetExtTextInput( rPos
.nNode
.GetNode(),
1095 rPos
.nContent
.GetIndex() );
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();
1108 SwXTextCursor::getTextFromPam(*pDel
, sTmp
);
1110 SET_CURR_SHELL( this );
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
;
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()*/ );
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
1145 long nDiff
= nNewCrsrPos
- rPos
.nContent
.GetIndex();
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() );
1155 if( !rData
.IsCursorVisible() ) // must be called after the EndAction
1160 void SwEditShell::TransliterateText( sal_uInt32 nType
)
1162 utl::TransliterationWrapper
aTrans(
1163 ::comphelper::getProcessServiceFactory(), nType
);
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
);
1177 GetDoc()->EndUndo(UNDO_EMPTY
, NULL
);
1180 GetDoc()->TransliterateText( *pCrsr
, aTrans
);
1185 void SwEditShell::CountWords( SwDocStat
& rStat
) const
1187 FOREACHPAM_START( this )
1189 if( PCURCRSR
->HasMark() )
1190 GetDoc()->CountWords( *PCURCRSR
, rStat
);