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 const bool bSuccess
= GetDoc()->InsertString(*PCURCRSR
, c
);
90 ASSERT( bSuccess
, "Doc->Insert() failed." );
93 SaveTblBoxCntnt( PCURCRSR
->GetPoint() );
103 /******************************************************************************
104 * void SwEditShell::Insert(const String &rStr)
105 ******************************************************************************/
108 void SwEditShell::Insert2(const String
&rStr
, const bool bForceExpandHints
)
112 const enum IDocumentContentOperations::InsertFlags nInsertFlags
=
114 ? static_cast<IDocumentContentOperations::InsertFlags
>(
115 IDocumentContentOperations::INS_FORCEHINTEXPAND
|
116 IDocumentContentOperations::INS_EMPTYEXPAND
)
117 : IDocumentContentOperations::INS_EMPTYEXPAND
;
119 SwPaM
*_pStartCrsr
= getShellCrsr( true ), *__pStartCrsr
= _pStartCrsr
;
121 //OPT: GetSystemCharSet
122 const bool bSuccess
=
123 GetDoc()->InsertString(*_pStartCrsr
, rStr
, nInsertFlags
);
124 ASSERT( bSuccess
, "Doc->Insert() failed." );
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
;
148 SwScriptInfo
* pSI
= SwScriptInfo::GetScriptInfo( ((SwTxtNode
&)rNode
),
154 // seems to be an empty paragraph.
157 ((SwTxtNode
&)rNode
).GetFrm( &aPt
, pTmpCrsr
->GetPoint(),
160 SwScriptInfo aScriptInfo
;
161 aScriptInfo
.InitScriptInfo( (SwTxtNode
&)rNode
, pFrm
->IsRightToLeft() );
162 nLevel
= aScriptInfo
.DirType( nPrevPos
);
166 if ( STRING_LEN
!= pSI
->GetInvalidity() )
167 pSI
->InitScriptInfo( (SwTxtNode
&)rNode
);
168 nLevel
= pSI
->DirType( nPrevPos
);
171 pTmpCrsr
->SetCrsrBidiLevel( nLevel
);
175 SetInFrontOfLabel( FALSE
); // #i27615#
181 /******************************************************************************
182 * void SwEditShell::Overwrite(const String &rStr)
183 ******************************************************************************/
186 void SwEditShell::Overwrite(const String
&rStr
)
189 FOREACHPAM_START(this)
190 if( !GetDoc()->Overwrite(*PCURCRSR
, rStr
) )
192 ASSERT( FALSE
, "Doc->Overwrite(Str) failed." )
194 SaveTblBoxCntnt( PCURCRSR
->GetPoint() );
200 /******************************************************************************
201 * long SwEditShell::SplitNode()
202 ******************************************************************************/
204 long SwEditShell::SplitNode( BOOL bAutoFormat
, BOOL bCheckTableStart
)
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
);
215 GetDoc()->EndUndo(UNDO_EMPTY
, NULL
);
218 AutoFmtBySplitNode();
226 /*-- 11.05.2004 09:41:20---------------------------------------------------
228 -----------------------------------------------------------------------*/
229 sal_Bool
SwEditShell::AppendTxtNode()
231 sal_Bool bRet
= sal_False
;
233 GetDoc()->StartUndo(UNDO_EMPTY
, NULL
);
235 FOREACHPAM_START(this)
236 GetDoc()->ClearBoxNumAttrs( PCURCRSR
->GetPoint()->nNode
);
237 bRet
= GetDoc()->AppendTxtNode( *PCURCRSR
->GetPoint()) || bRet
;
240 GetDoc()->EndUndo(UNDO_EMPTY
, NULL
);
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();
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 );
278 pGrf
= &(pGrfNode
->GetGrf());
279 // --> OD 2007-03-01 #i73788#
280 // no load of linked graphic, if its not needed now (bWait = FALSE).
283 if( pGrf
->IsSwapOut() ||
284 ( pGrfNode
->IsLinkedFile() && GRAPHIC_DEFAULT
== pGrf
->GetType() ) )
287 ASSERT( pGrfNode
->SwapIn( bWait
) || !bWait
, "Grafik konnte nicht geladen werden" );
289 pGrfNode
->SwapIn( bWait
);
295 if ( pGrf
->IsSwapOut() && !pGrfNode
->IsLinkedFile() )
298 ASSERT( pGrfNode
->SwapIn( bWait
) || !bWait
, "Grafik konnte nicht geladen werden" );
300 pGrfNode
->SwapIn( bWait
);
310 BOOL
SwEditShell::IsGrfSwapOut( BOOL bOnlyLinked
) const
312 SwGrfNode
*pGrfNode
= _GetGrfNode();
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;
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();
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
)
364 pDoc
->ReRead( *GetCrsr(), rGrfName
, rFltName
, pGraphic
, pGrfObj
);
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?" );
381 GetDoc()->GetGrfNms( *pFmt
, pGrfName
, pFltName
);
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();
403 //void SwEditShell::SetAlternateText( const String& rTxt )
405 // SwPaM* pCrsr = GetCrsr();
407 // if( !pCrsr->HasMark() && 0 != ( pNd = pCrsr->GetNode()->GetNoTxtNode()) )
409 // pNd->SetAlternateText( rTxt, sal_True );
410 // GetDoc()->SetModified();
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();
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();
435 void SwEditShell::ClearAutomaticContour()
437 SwNoTxtNode
*pNd
= GetCrsr()->GetNode()->GetNoTxtNode();
438 ASSERT( pNd
, "is no NoTxtNode!" );
439 if( pNd
->HasAutomaticContour() )
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();
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
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
478 SwNodeIndex
aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
479 while ( 0 != (pStNd
= aIdx
.GetNode().GetStartNode()) )
482 SwNode
& rNd
= aIdx
.GetNode();
483 if( rNd
.IsOLENode() &&
484 rName
== ((SwOLENode
&)rNd
).GetChartTblName() &&
485 ((SwOLENode
&)rNd
).GetFrm() )
488 aIdx
.Assign( *pStNd
->EndOfSectionNode(), + 1 );
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()) :
528 /****************************************************************************
529 * void SwEditShell::UpdateDocStat( SwDocStat& rStat )
530 ****************************************************************************/
533 void SwEditShell::UpdateDocStat( SwDocStat
& rStat
)
536 GetDoc()->UpdateDocStat( rStat
);
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 /******************************************************************************
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
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();
576 SwPaM
* pLast
= pCrsr
;
577 SwPaM
* pTemp
= pCrsr
;
580 SwPaM
* pPrev2
= dynamic_cast< SwPaM
* >( pTemp
->GetPrev() );
581 bPrev
= ( pPrev2
&& pPrev2
!= pLast
);
585 ULONG nTemp
= pPrev2
->GetMark()->nNode
.GetIndex();
586 if ( nTemp
< nIndex
)
595 SwTxtNode
* pTxtNd
= pCrsr
->GetNode( !pCrsr
->HasMark() )->GetTxtNode();
598 xub_StrLen nDropLen
= pTxtNd
->GetDropLen( nChars
);
600 aTxt
= pTxtNd
->GetTxt().Copy( 0, nDropLen
);
606 void SwEditShell::ReplaceDropTxt( const String
&rStr
)
608 SwPaM
* pCrsr
= GetCrsr();
609 if( pCrsr
->GetPoint()->nNode
== pCrsr
->GetMark()->nNode
&&
610 pCrsr
->GetNode()->GetTxtNode()->IsTxtNode() )
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." );
625 /******************************************************************************
628 * Erstellt : OK 25.04.94 13:45
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();
641 SwTxtNode
* pTxtNd
= pPaM
->GetNode()->GetTxtNode();
644 const SwPosition
*pStart
= pPaM
->Start(), *pEnd
= pPaM
->End();
645 xub_StrLen nStt
= pStart
->nContent
.GetIndex();
646 String aStr
= pTxtNd
->GetExpandTxt( nStt
, pEnd
->nContent
.
652 BOOL bValidFlds
= FALSE
;
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() )
670 String
sVar( aStr
.Copy( nTmpStt
, nPos
- nTmpStt
));
671 if( !::FindOperator( sVar
) &&
672 (::Find( sVar
, aCalc
.GetVarTable(),TBLSZ
) ||
673 aCalc
.VarLook( sVar
)) )
677 GetDoc()->FldsToCalc( aCalc
,
678 pStart
->nNode
.GetIndex(),
679 pStart
->nContent
.GetIndex() );
682 (( aFormel
+= '(' ) +=
683 aCalc
.GetStrResult( aCalc
.VarLook( sVar
)
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
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 );
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() ) )
730 ASSERT( ((SwGrfNode
*)pNd
)->SwapIn( TRUE
) || !TRUE
, "Grafik konnte nicht geladen werden" );
732 ((SwGrfNode
*)pNd
)->SwapIn( TRUE
);
737 else if ( pNd
->IsOLENode() )
739 aRet
= *((SwOLENode
*)pNd
)->GetGraphic();
743 SwFlyFrm
* pFlyFrm
= pNd
->GetCntntNode()->GetFrm()->FindFlyFrm();
745 aRet
= pFlyFrm
->GetFmt()->MakeGraphic();
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() ) )
758 GetDoc()->StartUndo( UNDO_UI_INSERT_URLTXT
, NULL
);
763 SwPaM
* pCrsr
= GetCrsr();
764 if( pCrsr
->HasMark() && *pCrsr
->GetPoint() != *pCrsr
->GetMark() )
766 // Selection vorhanden, MehrfachSelektion?
768 if( pCrsr
->GetNext() == pCrsr
)
770 // einfach Selection -> Text ueberpruefen
771 String
sTxt( GetSelTxt() );
772 sTxt
.EraseTrailingChars();
774 bDelTxt
= bInsTxt
= FALSE
;
776 else if( rFmt
.GetValue() == rStr
) // Name und URL gleich?
777 bDelTxt
= bInsTxt
= FALSE
;
782 else if( pCrsr
->GetNext() != pCrsr
&& rFmt
.GetValue() == rStr
)
789 ExtendSelection( FALSE
, rStr
.Len() );
796 if (bInsTxt
&& !IsCrsrPtAtEnd())
802 GetDoc()->EndUndo( UNDO_UI_INSERT_URLTXT
, NULL
);
808 USHORT
SwEditShell::GetINetAttrs( SwGetINetAttrs
& rArr
)
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();
833 SwGetINetAttr
* pNew
= new SwGetINetAttr( sTxt
, rAttr
);
834 rArr
.C40_INSERT( SwGetINetAttr
, pNew
, 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
);
848 DeleteSel( *GetCrsr() );
853 // setzen an den Textzeichenattributen das DontExpand-Flag
854 BOOL
SwEditShell::DontExpandFmt()
857 if( !IsTableMode() && GetDoc()->DontExpandFmt( *GetCrsr()->GetPoint() ))
865 SvNumberFormatter
* SwEditShell::GetNumberFormatter()
867 return GetDoc()->GetNumberFormatter();
870 BOOL
SwEditShell::RemoveInvisibleContent()
873 BOOL bRet
= GetDoc()->RemoveInvisibleContent();
877 BOOL
SwEditShell::ConvertFieldsToText()
880 BOOL bRet
= GetDoc()->ConvertFieldsToText();
884 void SwEditShell::SetNumberingRestart()
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
++)
893 MakeFindRange(DOCPOS_START
, DOCPOS_END
, pCrsr
); //body content
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
)
902 sal_Bool bGoOn
= sal_True
;
903 //iterate over all paragraphs
906 SwNode
* pNd
= GetDoc()->GetNodes()[ nCurrNd
];
907 switch( pNd
->GetNodeType() )
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
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
);
938 // jump over hidden sections - ignore protection!
939 if(((SwSectionNode
*)pNd
)->GetSection().IsHidden() )
940 nCurrNd
= pNd
->EndOfSectionIndex();
948 bGoOn
= nCurrNd
< nEndNd
;
959 USHORT
SwEditShell::GetLineCount( BOOL bActPos
)
963 SwPaM
* pPam
= GetCrsr();
964 SwNodeIndex
& rPtIdx
= pPam
->GetPoint()->nNode
;
965 SwNodeIndex
aStart( rPtIdx
);
967 SwCntntFrm
*pCntFrm
= 0;
972 else if( rPtIdx
> ( nTmpPos
= GetDoc()->GetNodes().GetEndOfExtras().GetIndex()) )
973 // BodyBereich => Start ist EndOfIcons + 1
974 aStart
= nTmpPos
+ 1;
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();
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();
995 pTmp
= pCNd
->FindHeaderStartNode();
997 ASSERT( pTmp
, "Missing StartNode" );
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
);
1016 long SwEditShell::CompareDoc( const SwDoc
& rDoc
)
1019 long nRet
= GetDoc()->CompareDoc( rDoc
);
1024 long SwEditShell::MergeDoc( const SwDoc
& rDoc
)
1027 long nRet
= GetDoc()->MergeDoc( rDoc
);
1033 const SwFtnInfo
& SwEditShell::GetFtnInfo() const
1035 return GetDoc()->GetFtnInfo();
1038 void SwEditShell::SetFtnInfo(const SwFtnInfo
& rInfo
)
1041 SET_CURR_SHELL( this );
1042 GetDoc()->SetFtnInfo(rInfo
);
1047 const SwEndNoteInfo
& SwEditShell::GetEndNoteInfo() const
1049 return GetDoc()->GetEndNoteInfo();
1052 void SwEditShell::SetEndNoteInfo(const SwEndNoteInfo
& rInfo
)
1055 SET_CURR_SHELL( this );
1056 GetDoc()->SetEndNoteInfo(rInfo
);
1060 const SwLineNumberInfo
& SwEditShell::GetLineNumberInfo() const
1062 return GetDoc()->GetLineNumberInfo();
1065 void SwEditShell::SetLineNumberInfo(const SwLineNumberInfo
& rInfo
)
1068 SET_CURR_SHELL( this );
1069 GetDoc()->SetLineNumberInfo(rInfo
);
1070 AddPaintRect( GetLayout()->Frm() );
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() );
1095 String
SwEditShell::DeleteExtTextInput( SwExtTextInput
* pDel
, BOOL bInsText
)
1099 const SwPosition
& rPos
= *GetCrsr()->GetPoint();
1100 pDel
= GetDoc()->GetExtTextInput( rPos
.nNode
.GetNode(),
1101 rPos
.nContent
.GetIndex() );
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();
1114 SwXTextCursor::getTextFromPam(*pDel
, sTmp
);
1116 SET_CURR_SHELL( this );
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
;
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()*/ );
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
1151 long nDiff
= nNewCrsrPos
- rPos
.nContent
.GetIndex();
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() );
1161 if( !rData
.IsCursorVisible() ) // must be called after the EndAction
1166 void SwEditShell::TransliterateText( sal_uInt32 nType
)
1168 utl::TransliterationWrapper
aTrans(
1169 ::comphelper::getProcessServiceFactory(), nType
);
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
);
1183 GetDoc()->EndUndo(UNDO_EMPTY
, NULL
);
1186 GetDoc()->TransliterateText( *pCrsr
, aTrans
);
1191 void SwEditShell::CountWords( SwDocStat
& rStat
) const
1193 FOREACHPAM_START( this )
1195 if( PCURCRSR
->HasMark() )
1196 GetDoc()->CountWords( *PCURCRSR
, rStat
);