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: unotext.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"
35 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
36 #include <com/sun/star/text/ControlCharacter.hpp>
39 #include <vos/mutex.hxx>
40 #include <vcl/svapp.hxx>
43 #include <unoport.hxx>
46 #include <unoframe.hxx>
47 #include <unofield.hxx>
48 #include <unometa.hxx>
49 #include <unodraw.hxx>
50 #include <unoredline.hxx>
52 #include <unoprnms.hxx>
54 #include <unocrsrhelper.hxx>
58 #include <redline.hxx>
60 #include <section.hxx>
62 #include <fmtanchr.hxx>
63 #include <crsskip.hxx>
65 #include <com/sun/star/text/TableColumnSeparator.hpp>
72 using namespace ::com::sun::star
;
73 using ::rtl::OUString
;
75 const sal_Char cInvalidObject
[] = "this object is invalid";
76 /******************************************************************
78 ******************************************************************/
79 /*-- 09.12.98 12:44:07---------------------------------------------------
81 -----------------------------------------------------------------------*/
83 void SwXText::PrepareForAttach( ::com::sun::star::uno::Reference
<
84 ::com::sun::star::text::XTextRange
> &,
85 const SwXTextRange
* const, const SwPaM
* const)
89 bool SwXText::CheckForOwnMemberMeta(const SwXTextRange
* const,
90 const SwPaM
* const, bool)
91 throw (::com::sun::star::lang::IllegalArgumentException
,
92 ::com::sun::star::uno::RuntimeException
)
94 ASSERT(CURSOR_META
!= eCrsrType
, "should not be called!");
98 const SwStartNode
*SwXText::GetStartNode() const
100 return GetDoc()->GetNodes().GetEndOfContent().StartOfSectionNode();
103 uno::Reference
< text::XTextCursor
> SwXText::createCursor() throw (uno::RuntimeException
)
105 uno::Reference
< text::XTextCursor
> xRet
;
108 SwNode
& rNode
= GetDoc()->GetNodes().GetEndOfContent();
109 SwPosition
aPos(rNode
);
110 xRet
= static_cast<text::XWordCursor
*>(
111 new SwXTextCursor(this, aPos
, GetTextType(), GetDoc()));
112 xRet
->gotoStart(sal_False
);
116 /* -----------------------------15.03.2002 12:39------------------------------
118 ---------------------------------------------------------------------------*/
119 SwXText::SwXText(SwDoc
* pDc
, CursorType eType
) :
121 bObjectValid(0 != pDc
),
123 m_pPropSet(aSwMapProvider
.GetPropertySet(PROPERTY_MAP_TEXT
))
126 /*-- 09.12.98 12:43:55---------------------------------------------------
128 -----------------------------------------------------------------------*/
132 /*-- 09.12.98 12:43:02---------------------------------------------------
134 -----------------------------------------------------------------------*/
135 uno::Any SAL_CALL
SwXText::queryInterface( const uno::Type
& rType
) throw(uno::RuntimeException
)
137 const uno::Type
& rXTextType
= ::getCppuType((uno::Reference
< text::XText
>*)0);
138 const uno::Type
& rXTextRangeCompareType
= ::getCppuType((uno::Reference
< text::XTextRangeCompare
>*)0);
139 const uno::Type
& rXSimpleTextType
= ::getCppuType((const uno::Reference
< XSimpleText
>*)0);
140 const uno::Type
& rXTextRangeType
= ::getCppuType((uno::Reference
< text::XTextRange
>*)0);
141 const uno::Type
& rXTypeProviderType
= ::getCppuType((uno::Reference
< lang::XTypeProvider
>*)0);
142 const uno::Type
& rXTextContentInsert
= ::getCppuType((uno::Reference
< text::XRelativeTextContentInsert
>*)0);
143 const uno::Type
& rXTextContentRemove
= ::getCppuType((uno::Reference
< text::XRelativeTextContentRemove
>*)0);
144 const uno::Type
& rXPropertySet
= ::getCppuType((uno::Reference
<beans::XPropertySet
>*)0);
145 const uno::Type
& rXUnoTunnel
= ::getCppuType((uno::Reference
< lang::XUnoTunnel
>*)0);
146 const uno::Type
& rXTextPortionAppend
= ::getCppuType((uno::Reference
< text::XTextPortionAppend
>*)0);
147 const uno::Type
& rXParagraphAppend
= ::getCppuType((uno::Reference
< text::XParagraphAppend
>*)0);
148 const uno::Type
& rXTextContentAppend
= ::getCppuType((uno::Reference
< text::XTextContentAppend
>*)0);
149 const uno::Type
& rXTextConvert
= ::getCppuType((uno::Reference
< text::XTextConvert
>*)0);
150 const uno::Type
& rXTextAppend
= ::getCppuType((uno::Reference
< text::XTextAppend
>*)0);
151 const uno::Type
& rXTextAppendAndConvert
= ::getCppuType((uno::Reference
< text::XTextAppendAndConvert
>*)0);
152 const uno::Type
& rXTextCopy
= ::getCppuType((uno::Reference
< text::XTextCopy
>*)0);
155 if(rType
== rXTextType
)
157 uno::Reference
< text::XText
> xRet
= this;
158 aRet
.setValue(&xRet
, rXTextType
);
160 else if(rType
== rXSimpleTextType
)
162 uno::Reference
< XSimpleText
> xRet
= this;
163 aRet
.setValue(&xRet
, rXSimpleTextType
);
165 else if(rType
== rXTextRangeType
)
167 uno::Reference
< text::XTextRange
> xRet
= this;
168 aRet
.setValue(&xRet
, rXTextRangeType
);
170 else if(rType
== rXTextRangeCompareType
)
172 uno::Reference
< text::XTextRangeCompare
> xRet
= this;
173 aRet
.setValue(&xRet
, rXTextRangeCompareType
);
175 else if(rType
== rXTypeProviderType
)
177 uno::Reference
< lang::XTypeProvider
> xRet
= this;
178 aRet
.setValue(&xRet
, rXTypeProviderType
);
180 else if(rType
== rXTextContentInsert
)
182 uno::Reference
< text::XRelativeTextContentInsert
> xRet
= this;
183 aRet
.setValue(&xRet
, rXTextContentInsert
);
185 else if(rType
== rXTextContentRemove
)
187 uno::Reference
< text::XRelativeTextContentRemove
> xRet
= this;
188 aRet
.setValue(&xRet
, rXTextContentRemove
);
190 else if(rType
== rXPropertySet
)
192 uno::Reference
< beans::XPropertySet
> xRet
= this;
193 aRet
.setValue(&xRet
, rXPropertySet
);
195 else if(rType
== rXUnoTunnel
)
197 uno::Reference
< lang::XUnoTunnel
> xRet
= this;
198 aRet
.setValue(&xRet
, rXUnoTunnel
);
200 else if(rType
== rXTextAppendAndConvert
)
202 uno::Reference
< XTextAppendAndConvert
> xRet
= this;
203 aRet
.setValue(&xRet
, rXTextAppendAndConvert
);
205 else if(rType
== rXTextAppend
)
207 uno::Reference
< XTextAppend
> xRet
= this;
208 aRet
.setValue(&xRet
, rXTextAppend
);
210 else if(rType
== rXTextPortionAppend
)
212 uno::Reference
< XTextPortionAppend
> xRet
= this;
213 aRet
.setValue(&xRet
, rXTextPortionAppend
);
215 else if(rType
== rXParagraphAppend
)
217 uno::Reference
< XParagraphAppend
> xRet
= this;
218 aRet
.setValue(&xRet
, rXParagraphAppend
);
220 else if(rType
== rXTextConvert
)
222 uno::Reference
< XTextConvert
> xRet
= this;
223 aRet
.setValue(&xRet
, rXParagraphAppend
);
225 else if(rType
== rXTextContentAppend
)
227 uno::Reference
< XTextContentAppend
> xRet
= this;
228 aRet
.setValue(&xRet
, rXTextContentAppend
);
230 else if(rType
== rXTextCopy
)
232 uno::Reference
< XTextCopy
> xRet
= this;
233 aRet
.setValue(&xRet
, rXTextCopy
);
237 /* -----------------------------15.03.00 17:42--------------------------------
239 ---------------------------------------------------------------------------*/
240 uno::Sequence
< uno::Type
> SAL_CALL
SwXText::getTypes() throw(uno::RuntimeException
)
242 uno::Sequence
< uno::Type
> aRet(12);
243 uno::Type
* pTypes
= aRet
.getArray();
244 pTypes
[0] = ::getCppuType((uno::Reference
< text::XText
>*)0);
245 pTypes
[1] = ::getCppuType((uno::Reference
< text::XTextRangeCompare
>*)0);
246 pTypes
[2] = ::getCppuType((uno::Reference
< text::XRelativeTextContentInsert
>*)0);
247 pTypes
[3] = ::getCppuType((uno::Reference
< text::XRelativeTextContentRemove
>*)0);
248 pTypes
[4] = ::getCppuType((uno::Reference
< lang::XUnoTunnel
>*)0);
249 pTypes
[5] = ::getCppuType((uno::Reference
< beans::XPropertySet
>*)0);
250 pTypes
[6] = ::getCppuType((uno::Reference
< text::XTextPortionAppend
>*)0);
251 pTypes
[7] = ::getCppuType((uno::Reference
< text::XParagraphAppend
>*)0);
252 pTypes
[8] = ::getCppuType((uno::Reference
< text::XTextContentAppend
>*)0);
253 pTypes
[9] = ::getCppuType((uno::Reference
< text::XTextConvert
>*)0);
254 pTypes
[10] = ::getCppuType((uno::Reference
< text::XTextAppend
>*)0);
255 pTypes
[11] = ::getCppuType((uno::Reference
< text::XTextAppendAndConvert
>*)0);
260 // belongs the range in the text ? insert it then.
261 void SwXText::insertString(const uno::Reference
< text::XTextRange
>& xTextRange
,
262 const OUString
& aString
,
264 throw( uno::RuntimeException
)
266 vos::OGuard
aGuard(Application::GetSolarMutex());
267 if(GetDoc() && xTextRange
.is())
269 uno::Reference
<lang::XUnoTunnel
> xRangeTunnel( xTextRange
, uno::UNO_QUERY
);
270 SwXTextRange
* pRange
= 0;
271 OTextCursorHelper
* pCursor
= 0;
272 if(xRangeTunnel
.is())
274 pRange
= reinterpret_cast< SwXTextRange
* >(
275 sal::static_int_cast
< sal_IntPtr
>( xRangeTunnel
->getSomething( SwXTextRange::getUnoTunnelId()) ));
276 pCursor
= reinterpret_cast< OTextCursorHelper
* >(
277 sal::static_int_cast
< sal_IntPtr
>( xRangeTunnel
->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
280 if( ( pRange
&& pRange
->GetDoc() == GetDoc() ) ||
281 ( pCursor
&& pCursor
->GetDoc() == GetDoc() ) )
283 const SwStartNode
* pOwnStartNode
= GetStartNode();
286 const SwStartNode
* pTmp
= pCursor
->GetPaM()->GetNode()->StartOfSectionNode();
287 while(pTmp
&& pTmp
->IsSectionNode())
289 pTmp
= pTmp
->StartOfSectionNode();
291 if( !pOwnStartNode
|| pOwnStartNode
!= pTmp
)
293 throw uno::RuntimeException();
298 ::sw::mark::IMark
const * const pBkmk
= pRange
->GetBookmark();
299 const SwStartNode
* pTmp
= pBkmk
->GetMarkPos().nNode
.GetNode().StartOfSectionNode();
300 while(pTmp
&& pTmp
->IsSectionNode())
301 pTmp
= pTmp
->StartOfSectionNode();
302 if(!pOwnStartNode
|| pOwnStartNode
!= pTmp
)
303 throw uno::RuntimeException();
305 bool bForceExpandHints( false );
306 if (CURSOR_META
== eCrsrType
)
310 bForceExpandHints
= CheckForOwnMemberMeta(
311 pRange
, (pCursor
) ? pCursor
->GetPaM() : 0, bAbsorb
);
313 catch (lang::IllegalArgumentException
& iae
)
315 // stupid method not allowed to throw iae
316 throw uno::RuntimeException(iae
.Message
, 0);
321 //!! scan for CR characters and inserting the paragraph breaks
322 //!! has to be done in the called function.
323 //!! Implemented in SwXTextRange::DeleteAndInsert
326 SwXTextCursor
* const pTextCursor( dynamic_cast<SwXTextCursor
*>(pCursor
) );
329 pTextCursor
->DeleteAndInsert(aString
, bForceExpandHints
);
333 xTextRange
->setString(aString
);
338 pRange
->DeleteAndInsert(aString
, bForceExpandHints
);
343 //hier wird ein PaM angelegt, der vor dem Parameter-PaM liegt, damit der
344 //Text davor eingefuegt wird
345 UnoActionContext
aContext(GetDoc());
346 const SwPosition
* pPos
= pCursor
347 ? pCursor
->GetPaM()->Start()
348 : &pRange
->GetBookmark()->GetMarkStart();
349 SwPaM
aInsertPam(*pPos
);
350 const sal_Bool bGroupUndo
= GetDoc()->DoesGroupUndo();
351 GetDoc()->DoGroupUndo(sal_False
);
353 SwUnoCursorHelper::DocInsertStringSplitCR(
354 *GetDoc(), aInsertPam
, aString
, bForceExpandHints
);
355 GetDoc()->DoGroupUndo(bGroupUndo
);
359 throw uno::RuntimeException();
362 throw uno::RuntimeException();
365 /*-- 09.12.98 12:43:16---------------------------------------------------
367 -----------------------------------------------------------------------*/
368 void SwXText::insertControlCharacter(const uno::Reference
< text::XTextRange
> & xTextRange
,
369 sal_Int16 nControlCharacter
, sal_Bool bAbsorb
)
370 throw( lang::IllegalArgumentException
, uno::RuntimeException
)
372 vos::OGuard
aGuard(Application::GetSolarMutex());
373 if (!xTextRange
.is())
374 throw lang::IllegalArgumentException();
377 SwUnoInternalPaM
aPam(*GetDoc());
378 if(SwXTextRange::XTextRangeToSwPaM(aPam
, xTextRange
))
380 const bool bForceExpandHints(
381 CheckForOwnMemberMeta( 0, &aPam
, bAbsorb
) );
383 const enum IDocumentContentOperations::InsertFlags nInsertFlags
=
385 ? static_cast<IDocumentContentOperations::InsertFlags
>(
386 IDocumentContentOperations::INS_FORCEHINTEXPAND
|
387 IDocumentContentOperations::INS_EMPTYEXPAND
)
388 : IDocumentContentOperations::INS_EMPTYEXPAND
;
390 //Steuerzeichen einfuegen
391 SwPaM
aTmp(*aPam
.Start());
392 if(bAbsorb
&& aPam
.HasMark())
394 pDoc
->DeleteAndJoin(aPam
);
397 sal_Unicode cIns
= 0;
398 switch( nControlCharacter
)
400 case text::ControlCharacter::PARAGRAPH_BREAK
:
401 // eine Tabellen Zelle wird jetzt zu einer normalen Textzelle!
402 pDoc
->ClearBoxNumAttrs( aTmp
.GetPoint()->nNode
);
403 pDoc
->SplitNode( *aTmp
.GetPoint(), sal_False
);
405 case text::ControlCharacter::APPEND_PARAGRAPH
:
407 pDoc
->ClearBoxNumAttrs( aTmp
.GetPoint()->nNode
);
408 pDoc
->AppendTxtNode( *aTmp
.GetPoint() );
410 uno::Reference
<lang::XUnoTunnel
> xRangeTunnel( xTextRange
, uno::UNO_QUERY
);
411 SwXTextRange
* pRange
= 0;
412 OTextCursorHelper
* pCursor
= 0;
413 if(xRangeTunnel
.is())
415 pRange
= reinterpret_cast< SwXTextRange
* >(
416 sal::static_int_cast
< sal_IntPtr
>( xRangeTunnel
->getSomething( SwXTextRange::getUnoTunnelId()) ));
417 pCursor
= reinterpret_cast< OTextCursorHelper
* >(
418 sal::static_int_cast
< sal_IntPtr
>( xRangeTunnel
->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
422 pRange
->_CreateNewBookmark(aTmp
);
426 SwPaM
* pCrsr
= pCursor
->GetPaM();
427 *pCrsr
->GetPoint() = *aTmp
.GetPoint();
432 case text::ControlCharacter::LINE_BREAK
: cIns
= 10; break;
433 case text::ControlCharacter::SOFT_HYPHEN
: cIns
= CHAR_SOFTHYPHEN
; break;
434 case text::ControlCharacter::HARD_HYPHEN
: cIns
= CHAR_HARDHYPHEN
; break;
435 case text::ControlCharacter::HARD_SPACE
: cIns
= CHAR_HARDBLANK
; break;
439 pDoc
->InsertString( aTmp
, cIns
, nInsertFlags
);
444 uno::Reference
<lang::XUnoTunnel
> xRangeTunnel( xTextRange
, uno::UNO_QUERY
);
445 SwXTextRange
* pRange
= 0;
446 OTextCursorHelper
* pCursor
= 0;
447 if(xRangeTunnel
.is())
449 pRange
= reinterpret_cast< SwXTextRange
* >(
450 sal::static_int_cast
< sal_IntPtr
>( xRangeTunnel
->getSomething( SwXTextRange::getUnoTunnelId()) ));
451 pCursor
= reinterpret_cast< OTextCursorHelper
* >(
452 sal::static_int_cast
< sal_IntPtr
>( xRangeTunnel
->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
455 SwCursor
aCrsr(*aTmp
.GetPoint(),0,false);
456 SwXTextCursor::SelectPam(aCrsr
, sal_True
);
457 aCrsr
.Left(1, CRSR_SKIP_CHARS
, FALSE
, FALSE
);
458 //hier muss der uebergebene PaM umgesetzt werden:
460 pRange
->_CreateNewBookmark(aCrsr
);
463 SwPaM
* pUnoCrsr
= pCursor
->GetPaM();
464 *pUnoCrsr
->GetPoint() = *aCrsr
.GetPoint();
468 *pUnoCrsr
->GetMark() = *aCrsr
.GetMark();
471 pUnoCrsr
->DeleteMark();
477 throw uno::RuntimeException();
479 /*-- 09.12.98 12:43:17---------------------------------------------------
481 -----------------------------------------------------------------------*/
483 void SwXText::insertTextContent(const uno::Reference
< text::XTextRange
> & xRange
,
484 const uno::Reference
< text::XTextContent
> & xContent
, sal_Bool bAbsorb
)
485 throw( lang::IllegalArgumentException
, uno::RuntimeException
)
487 vos::OGuard
aGuard(Application::GetSolarMutex());
488 // erstmal testen, ob der Range an der richtigen Stelle ist und dann
489 // am Sw-Content attachToRange aufrufen
492 uno::RuntimeException aRuntime
;
493 aRuntime
.Message
= C2U(cInvalidObject
);
496 if(xRange
.is() && xContent
.is())
498 SwUnoInternalPaM
aPam(*GetDoc());
499 if(SwXTextRange::XTextRangeToSwPaM(aPam
, xRange
))
501 uno::Reference
<lang::XUnoTunnel
> xRangeTunnel( xRange
, uno::UNO_QUERY
);
502 SwXTextRange
* pRange
= 0;
503 OTextCursorHelper
* pCursor
= 0;
504 SwXTextPortion
* pPortion
= 0;
506 if(xRangeTunnel
.is())
508 pRange
= reinterpret_cast< SwXTextRange
* >(
509 sal::static_int_cast
< sal_IntPtr
>( xRangeTunnel
->getSomething( SwXTextRange::getUnoTunnelId()) ));
510 pCursor
= reinterpret_cast< OTextCursorHelper
* >(
511 sal::static_int_cast
< sal_IntPtr
>( xRangeTunnel
->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
512 pPortion
= reinterpret_cast< SwXTextPortion
* >(
513 sal::static_int_cast
< sal_IntPtr
>( xRangeTunnel
->getSomething( SwXTextPortion::getUnoTunnelId()) ));
514 pText
= reinterpret_cast< SwXText
* >(
515 sal::static_int_cast
< sal_IntPtr
>( xRangeTunnel
->getSomething( SwXText::getUnoTunnelId()) ));
519 uno::Reference
< text::XTextCursor
> xOwnCursor
= createCursor();
520 uno::Reference
<lang::XUnoTunnel
> xOwnTunnel( xOwnCursor
, uno::UNO_QUERY
);
521 // OTextCursorHelper* pOwnCursor = reinterpret_cast< OTextCursorHelper * >(
522 // sal::static_int_cast< sal_IntPtr >( xOwnTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
524 const SwStartNode
* pOwnStartNode
= GetStartNode();
525 SwStartNodeType eSearchNodeType
= SwNormalStartNode
;
528 case CURSOR_FRAME
: eSearchNodeType
= SwFlyStartNode
; break;
529 case CURSOR_TBLTEXT
: eSearchNodeType
= SwTableBoxStartNode
; break;
530 case CURSOR_FOOTNOTE
: eSearchNodeType
= SwFootnoteStartNode
; break;
531 case CURSOR_HEADER
: eSearchNodeType
= SwHeaderStartNode
; break;
532 case CURSOR_FOOTER
: eSearchNodeType
= SwFooterStartNode
; break;
533 //case CURSOR_INVALID:
539 const SwNode
* pSrcNode
= 0;
540 if(pCursor
&& pCursor
->GetPaM())
542 pSrcNode
= pCursor
->GetPaM()->GetNode();
544 else if (pRange
&& pRange
->GetBookmark())
546 ::sw::mark::IMark
const * const pBkmk
= pRange
->GetBookmark();
547 pSrcNode
= &pBkmk
->GetMarkPos().nNode
.GetNode();
549 else if (pPortion
&& pPortion
->GetCursor())
551 pSrcNode
= pPortion
->GetCursor()->GetNode();
555 uno::Reference
<text::XTextCursor
> xTextCursor
= pText
->createCursor();
556 xTextCursor
->gotoEnd(sal_True
);
557 uno::Reference
<lang::XUnoTunnel
> xCrsrTunnel( xTextCursor
, uno::UNO_QUERY
);
558 pCursor
= reinterpret_cast< OTextCursorHelper
* >(
559 sal::static_int_cast
< sal_IntPtr
>( xCrsrTunnel
->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
560 pSrcNode
= pCursor
->GetPaM()->GetNode();
563 throw lang::IllegalArgumentException();
565 const SwStartNode
* pTmp
= pSrcNode
->FindSttNodeByType(eSearchNodeType
);
567 //SectionNodes ueberspringen
568 while(pTmp
&& pTmp
->IsSectionNode())
570 pTmp
= pTmp
->StartOfSectionNode();
572 //if the document starts with a section
573 while(pOwnStartNode
->IsSectionNode())
575 pOwnStartNode
= pOwnStartNode
->StartOfSectionNode();
577 //this checks if (this) and xRange are in the same text::XText interface
578 if(pOwnStartNode
!= pTmp
)
580 uno::RuntimeException aRunException
;
581 aRunException
.Message
= C2U("text interface and cursor not related");
585 const bool bForceExpandHints( CheckForOwnMemberMeta(
586 pRange
, (pCursor
) ? pCursor
->GetPaM() : 0, bAbsorb
) );
588 // Sonderbehandlung fuer Contents, die den Range nicht ersetzen, sonder darueber gelegt werden
589 // Bookmarks, IndexEntry
590 uno::Reference
<lang::XUnoTunnel
> xContentTunnel( xContent
, uno::UNO_QUERY
);
591 if(!xContentTunnel
.is())
593 lang::IllegalArgumentException aArgException
;
594 aArgException
.Message
= C2U("text content doesn't support lang::XUnoTunnel");
597 SwXDocumentIndexMark
* pDocumentIndexMark
= reinterpret_cast< SwXDocumentIndexMark
* >(
598 sal::static_int_cast
< sal_IntPtr
>( xContentTunnel
->getSomething( SwXDocumentIndexMark::getUnoTunnelId()) ));
599 SwXTextSection
* pSection
= reinterpret_cast< SwXTextSection
* >(
600 sal::static_int_cast
< sal_IntPtr
>( xContentTunnel
->getSomething( SwXTextSection::getUnoTunnelId()) ));
601 SwXBookmark
* pBookmark
= reinterpret_cast< SwXBookmark
* >(
602 sal::static_int_cast
< sal_IntPtr
>( xContentTunnel
->getSomething( SwXBookmark::getUnoTunnelId()) ));
603 SwXReferenceMark
* pReferenceMark
= reinterpret_cast< SwXReferenceMark
* >(
604 sal::static_int_cast
< sal_IntPtr
>( xContentTunnel
->getSomething( SwXReferenceMark::getUnoTunnelId()) ));
605 SwXMeta
*const pMeta
= reinterpret_cast< SwXMeta
* >(
606 sal::static_int_cast
< sal_IntPtr
>(
607 xContentTunnel
->getSomething( SwXMeta::getUnoTunnelId())));
609 const bool bAttribute
= pBookmark
|| pDocumentIndexMark
610 || pSection
|| pReferenceMark
|| pMeta
;
612 if(bAbsorb
&& !bAttribute
)
614 xRange
->setString(aEmptyStr
);
616 //hier wird tatsaechlich eingefuegt
617 uno::Reference
< text::XTextRange
> xTempRange
;
618 if(bAttribute
&& bAbsorb
)
621 xTempRange
= xRange
->getStart();
622 if (bForceExpandHints
)
624 // if necessary, replace xTempRange with a new SwXTextCursor
625 PrepareForAttach(xTempRange
, pRange
,
626 (pCursor
) ? pCursor
->GetPaM() : 0);
628 xContent
->attach(xTempRange
);
632 lang::IllegalArgumentException aIllegal
;
633 aIllegal
.Message
= C2U("first parameter invalid");
639 lang::IllegalArgumentException aIllegal
;
641 aIllegal
.Message
= C2U("first parameter invalid;");
643 aIllegal
.Message
+= C2U("second parameter invalid");
648 /* -----------------------------10.07.00 15:40--------------------------------
650 ---------------------------------------------------------------------------*/
651 void SwXText::insertTextContentBefore(
652 const uno::Reference
< text::XTextContent
>& xNewContent
,
653 const uno::Reference
< text::XTextContent
>& xSuccessor
)
654 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
656 vos::OGuard
aGuard(Application::GetSolarMutex());
659 uno::RuntimeException aRuntime
;
660 aRuntime
.Message
= C2U(cInvalidObject
);
664 SwXParagraph
* pPara
= SwXParagraph::GetImplementation(xNewContent
);
665 if(!pPara
|| !pPara
->IsDescriptor() || !xSuccessor
.is())
666 throw lang::IllegalArgumentException();
668 sal_Bool bRet
= sal_False
;
669 SwXTextSection
* pXSection
= SwXTextSection::GetImplementation( xSuccessor
);
670 SwXTextTable
* pXTable
= SwXTextTable::GetImplementation(xSuccessor
);
671 SwFrmFmt
* pTableFmt
= pXTable
? pXTable
->GetFrmFmt() : 0;
672 SwUnoCrsr
* pUnoCrsr
= 0;
673 if(pTableFmt
&& pTableFmt
->GetDoc() == GetDoc())
675 SwTable
* pTable
= SwTable::FindTable( pTableFmt
);
676 SwTableNode
* pTblNode
= pTable
->GetTableNode();
678 SwNodeIndex
aTblIdx( *pTblNode
, -1 );
679 SwPosition
aBefore(aTblIdx
);
680 bRet
= GetDoc()->AppendTxtNode( aBefore
);
681 pUnoCrsr
= GetDoc()->CreateUnoCrsr( aBefore
, FALSE
);
684 pXSection
->GetFmt() &&
685 pXSection
->GetFmt()->GetDoc() == GetDoc())
687 SwSectionFmt
* pSectFmt
= pXSection
->GetFmt();
688 SwSectionNode
* pSectNode
= pSectFmt
->GetSectionNode();
690 SwNodeIndex
aSectIdx( *pSectNode
, -1 );
691 SwPosition
aBefore(aSectIdx
);
692 bRet
= GetDoc()->AppendTxtNode( aBefore
);
693 pUnoCrsr
= GetDoc()->CreateUnoCrsr( aBefore
, FALSE
);
696 throw lang::IllegalArgumentException();
699 pPara
->attachToText(this, pUnoCrsr
);
703 /* -----------------------------10.07.00 15:40--------------------------------
705 ---------------------------------------------------------------------------*/
706 void SwXText::insertTextContentAfter(
707 const uno::Reference
< text::XTextContent
>& xNewContent
,
708 const uno::Reference
< text::XTextContent
>& xPredecessor
)
709 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
711 vos::OGuard
aGuard(Application::GetSolarMutex());
713 throw uno::RuntimeException();
714 SwXParagraph
* pPara
= SwXParagraph::GetImplementation(xNewContent
);
715 if(!pPara
|| !pPara
->IsDescriptor() || !xPredecessor
.is())
716 throw lang::IllegalArgumentException();
718 SwUnoCrsr
* pUnoCrsr
= 0;
719 SwXTextSection
* pXSection
= SwXTextSection::GetImplementation( xPredecessor
);
720 SwXTextTable
* pXTable
= SwXTextTable::GetImplementation(xPredecessor
);
721 SwFrmFmt
* pTableFmt
= pXTable
? pXTable
->GetFrmFmt() : 0;
722 sal_Bool bRet
= sal_False
;
723 if(pTableFmt
&& pTableFmt
->GetDoc() == GetDoc())
725 SwTable
* pTable
= SwTable::FindTable( pTableFmt
);
726 SwTableNode
* pTblNode
= pTable
->GetTableNode();
728 SwEndNode
* pTableEnd
= pTblNode
->EndOfSectionNode();
729 SwPosition
aTableEnd(*pTableEnd
);
730 bRet
= GetDoc()->AppendTxtNode( aTableEnd
);
731 pUnoCrsr
= GetDoc()->CreateUnoCrsr( aTableEnd
, FALSE
);
734 pXSection
->GetFmt() &&
735 pXSection
->GetFmt()->GetDoc() == GetDoc())
737 SwSectionFmt
* pSectFmt
= pXSection
->GetFmt();
738 SwSectionNode
* pSectNode
= pSectFmt
->GetSectionNode();
739 SwEndNode
* pEnd
= pSectNode
->EndOfSectionNode();
740 SwPosition
aEnd(*pEnd
);
741 bRet
= GetDoc()->AppendTxtNode( aEnd
);
742 pUnoCrsr
= GetDoc()->CreateUnoCrsr( aEnd
, FALSE
);
745 throw lang::IllegalArgumentException();
748 pPara
->attachToText(this, pUnoCrsr
);
751 /* -----------------------------10.07.00 15:40--------------------------------
753 ---------------------------------------------------------------------------*/
754 void SwXText::removeTextContentBefore(
755 const uno::Reference
< text::XTextContent
>& xSuccessor
)
756 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
758 vos::OGuard
aGuard(Application::GetSolarMutex());
761 uno::RuntimeException aRuntime
;
762 aRuntime
.Message
= C2U(cInvalidObject
);
766 sal_Bool bRet
= sal_False
;
767 SwXTextSection
* pXSection
= SwXTextSection::GetImplementation( xSuccessor
);
768 SwXTextTable
* pXTable
= SwXTextTable::GetImplementation( xSuccessor
);
769 SwFrmFmt
* pTableFmt
= pXTable
? pXTable
->GetFrmFmt() : 0;
770 if(pTableFmt
&& pTableFmt
->GetDoc() == GetDoc())
772 SwTable
* pTable
= SwTable::FindTable( pTableFmt
);
773 SwTableNode
* pTblNode
= pTable
->GetTableNode();
775 SwNodeIndex
aTblIdx( *pTblNode
, -1 );
776 if(aTblIdx
.GetNode().IsTxtNode())
778 SwPaM
aBefore(aTblIdx
);
779 bRet
= GetDoc()->DelFullPara( aBefore
);
783 pXSection
->GetFmt() &&
784 pXSection
->GetFmt()->GetDoc() == GetDoc())
786 SwSectionFmt
* pSectFmt
= pXSection
->GetFmt();
787 SwSectionNode
* pSectNode
= pSectFmt
->GetSectionNode();
789 SwNodeIndex
aSectIdx( *pSectNode
, -1 );
790 if(aSectIdx
.GetNode().IsTxtNode())
792 SwPaM
aBefore(aSectIdx
);
793 bRet
= GetDoc()->DelFullPara( aBefore
);
797 throw lang::IllegalArgumentException();
799 /* -----------------------------10.07.00 15:40--------------------------------
801 ---------------------------------------------------------------------------*/
802 void SwXText::removeTextContentAfter(const uno::Reference
< text::XTextContent
>& xPredecessor
)
803 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
805 vos::OGuard
aGuard(Application::GetSolarMutex());
808 uno::RuntimeException aRuntime
;
809 aRuntime
.Message
= C2U(cInvalidObject
);
813 sal_Bool bRet
= sal_False
;
814 SwXTextSection
* pXSection
= SwXTextSection::GetImplementation( xPredecessor
);
815 SwXTextTable
* pXTable
= SwXTextTable::GetImplementation(xPredecessor
);
816 SwFrmFmt
* pTableFmt
= pXTable
? pXTable
->GetFrmFmt() : 0;
817 if(pTableFmt
&& pTableFmt
->GetDoc() == GetDoc())
819 SwTable
* pTable
= SwTable::FindTable( pTableFmt
);
820 SwTableNode
* pTblNode
= pTable
->GetTableNode();
821 SwEndNode
* pTableEnd
= pTblNode
->EndOfSectionNode();
823 SwNodeIndex
aTblIdx( *pTableEnd
, 1 );
824 if(aTblIdx
.GetNode().IsTxtNode())
827 bRet
= GetDoc()->DelFullPara( aPaM
);
831 pXSection
->GetFmt() &&
832 pXSection
->GetFmt()->GetDoc() == GetDoc())
834 SwSectionFmt
* pSectFmt
= pXSection
->GetFmt();
835 SwSectionNode
* pSectNode
= pSectFmt
->GetSectionNode();
836 SwEndNode
* pEnd
= pSectNode
->EndOfSectionNode();
837 SwNodeIndex
aSectIdx( *pEnd
, 1 );
838 if(aSectIdx
.GetNode().IsTxtNode())
840 SwPaM
aAfter(aSectIdx
);
841 bRet
= GetDoc()->DelFullPara( aAfter
);
845 throw lang::IllegalArgumentException();
847 /*-- 09.12.98 12:43:19---------------------------------------------------
849 -----------------------------------------------------------------------*/
850 void SwXText::removeTextContent(const uno::Reference
< text::XTextContent
> & xContent
)
851 throw( container::NoSuchElementException
, uno::RuntimeException
)
853 vos::OGuard
aGuard(Application::GetSolarMutex());
856 uno::RuntimeException aRuntime
;
857 aRuntime
.Message
= C2U("first parameter invalid");
863 /*-- 09.12.98 12:43:22---------------------------------------------------
865 -----------------------------------------------------------------------*/
866 uno::Reference
< text::XText
> SwXText::getText(void)
867 throw( uno::RuntimeException
)
869 vos::OGuard
aGuard(Application::GetSolarMutex());
870 uno::Reference
< text::XText
> xRet
= (SwXText
*)this;
874 /*-- 09.12.98 12:43:24---------------------------------------------------
876 -----------------------------------------------------------------------*/
877 uno::Reference
< text::XTextRange
> SwXText::getStart(void) throw( uno::RuntimeException
)
879 vos::OGuard
aGuard(Application::GetSolarMutex());
880 uno::Reference
< text::XTextCursor
> xRef
= createCursor();
883 uno::RuntimeException aRuntime
;
884 aRuntime
.Message
= C2U(cInvalidObject
);
887 xRef
->gotoStart(sal_False
);
888 uno::Reference
< text::XTextRange
> xRet(xRef
, uno::UNO_QUERY
);
891 /*-- 09.12.98 12:43:27---------------------------------------------------
893 -----------------------------------------------------------------------*/
894 uno::Reference
< text::XTextRange
> SwXText::getEnd(void) throw( uno::RuntimeException
)
896 vos::OGuard
aGuard(Application::GetSolarMutex());
897 uno::Reference
< text::XTextCursor
> xRef
= createCursor();
900 uno::RuntimeException aRuntime
;
901 aRuntime
.Message
= C2U(cInvalidObject
);
904 xRef
->gotoEnd(sal_False
);
905 uno::Reference
< text::XTextRange
> xRet(xRef
, uno::UNO_QUERY
);
908 /*-- 09.12.98 12:43:29---------------------------------------------------
910 -----------------------------------------------------------------------*/
911 OUString
SwXText::getString(void) throw( uno::RuntimeException
)
913 vos::OGuard
aGuard(Application::GetSolarMutex());
914 uno::Reference
< text::XTextCursor
> xRet
= createCursor();
917 uno::RuntimeException aRuntime
;
918 aRuntime
.Message
= C2U(cInvalidObject
);
923 xRet
->gotoEnd(sal_True
);
925 return xRet
->getString();
927 /*-- 09.12.98 12:43:30---------------------------------------------------
929 -----------------------------------------------------------------------*/
930 void SwXText::setString(const OUString
& aString
) throw( uno::RuntimeException
)
932 vos::OGuard
aGuard(Application::GetSolarMutex());
933 const SwStartNode
* pStartNode
= GetStartNode();
935 throw uno::RuntimeException();
937 GetDoc()->StartUndo(UNDO_START
, NULL
);
938 //insert an empty paragraph at the start and at the end to ensure that
939 //all tables and sections can be removed by the selecting text::XTextCursor
940 if (CURSOR_META
!= eCrsrType
)
942 SwPosition
aStartPos(*pStartNode
);
943 const SwEndNode
* pEnd
= pStartNode
->EndOfSectionNode();
944 SwNodeIndex
aEndIdx(*pEnd
);
946 //the inserting of nodes should only be done if really necessary
947 //to prevent #97924# (removes paragraph attributes when setting the text
948 //e.g. of a table cell
949 BOOL bInsertNodes
= FALSE
;
950 SwNodeIndex
aStartIdx(*pStartNode
);
954 SwNode
& rCurrentNode
= aStartIdx
.GetNode();
955 if(rCurrentNode
.GetNodeType() == ND_SECTIONNODE
956 ||rCurrentNode
.GetNodeType() == ND_TABLENODE
)
962 while(aStartIdx
< aEndIdx
);
965 GetDoc()->AppendTxtNode( aStartPos
);
966 SwPosition
aEndPos(aEndIdx
.GetNode());
968 GetDoc()->AppendTxtNode( *aPam
.Start() );
972 uno::Reference
< text::XTextCursor
> xRet
= createCursor();
975 GetDoc()->EndUndo(UNDO_END
, NULL
);
976 uno::RuntimeException aRuntime
;
977 aRuntime
.Message
= C2U(cInvalidObject
);
982 xRet
->gotoEnd(sal_True
);
984 xRet
->setString(aString
);
985 GetDoc()->EndUndo(UNDO_END
, NULL
);
988 //FIXME why is CheckForOwnMember duplicated in some insert methods?
989 // Description: Checks if pRange/pCursor are member of the same text interface.
990 // Only one of the pointers has to be set!
991 sal_Bool
SwXText::CheckForOwnMember(
992 const SwXTextRange
* pRange
,
993 const OTextCursorHelper
* pCursor
)
994 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
996 DBG_ASSERT((!pRange
|| !pCursor
) && (pRange
|| pCursor
), "only one pointer will be checked" );
997 uno::Reference
<text::XTextCursor
> xOwnCursor
= createCursor();
999 uno::Reference
<lang::XUnoTunnel
> xTunnel( xOwnCursor
, uno::UNO_QUERY
);
1000 OTextCursorHelper
* pOwnCursor
= 0;
1003 pOwnCursor
= reinterpret_cast< OTextCursorHelper
* >(
1004 sal::static_int_cast
< sal_IntPtr
>( xTunnel
->getSomething(OTextCursorHelper::getUnoTunnelId()) ));
1006 DBG_ASSERT(pOwnCursor
, "OTextCursorHelper::getUnoTunnelId() ??? ");
1007 const SwStartNode
* pOwnStartNode
= pOwnCursor
->GetPaM()->GetNode()->StartOfSectionNode();
1008 SwStartNodeType eSearchNodeType
= SwNormalStartNode
;
1011 case CURSOR_FRAME
: eSearchNodeType
= SwFlyStartNode
; break;
1012 case CURSOR_TBLTEXT
: eSearchNodeType
= SwTableBoxStartNode
; break;
1013 case CURSOR_FOOTNOTE
: eSearchNodeType
= SwFootnoteStartNode
; break;
1014 case CURSOR_HEADER
: eSearchNodeType
= SwHeaderStartNode
; break;
1015 case CURSOR_FOOTER
: eSearchNodeType
= SwFooterStartNode
; break;
1016 //case CURSOR_INVALID:
1022 const SwNode
* pSrcNode
;
1024 pSrcNode
= pCursor
->GetPaM()->GetNode();
1027 ::sw::mark::IMark
const * const pBkmk
= pRange
->GetBookmark();
1028 pSrcNode
= &pBkmk
->GetMarkPos().nNode
.GetNode();
1030 const SwStartNode
* pTmp
= pSrcNode
->FindSttNodeByType(eSearchNodeType
);
1032 //SectionNodes ueberspringen
1033 while(pTmp
&& pTmp
->IsSectionNode())
1034 pTmp
= pTmp
->StartOfSectionNode();
1036 //if the document starts with a section
1037 while(pOwnStartNode
->IsSectionNode())
1038 pOwnStartNode
= pOwnStartNode
->StartOfSectionNode();
1040 //this checks if (this) and xRange are in the same text::XText interface
1041 return(pOwnStartNode
== pTmp
);
1044 sal_Int16
SwXText::ComparePositions(
1045 const uno::Reference
<text::XTextRange
>& xPos1
,
1046 const uno::Reference
<text::XTextRange
>& xPos2
)
1047 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
1049 sal_Int16 nCompare
= 0;
1050 SwUnoInternalPaM
aPam1(*GetDoc());
1051 SwUnoInternalPaM
aPam2(*GetDoc());
1053 BOOL bExcept
= FALSE
;
1054 if(SwXTextRange::XTextRangeToSwPaM(aPam1
, xPos1
) &&
1055 SwXTextRange::XTextRangeToSwPaM(aPam2
, xPos2
))
1057 uno::Reference
<lang::XUnoTunnel
> xRangeTunnel1( xPos1
, uno::UNO_QUERY
);
1058 SwXTextRange
* pRange1
= 0;
1059 OTextCursorHelper
* pCursor1
= 0;
1060 if(xRangeTunnel1
.is())
1062 pRange1
= reinterpret_cast< SwXTextRange
* >(
1063 sal::static_int_cast
< sal_IntPtr
>( xRangeTunnel1
->getSomething( SwXTextRange::getUnoTunnelId()) ));
1064 pCursor1
= reinterpret_cast< OTextCursorHelper
* >(
1065 sal::static_int_cast
< sal_IntPtr
>( xRangeTunnel1
->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
1067 uno::Reference
<lang::XUnoTunnel
> xRangeTunnel2( xPos2
, uno::UNO_QUERY
);
1068 SwXTextRange
* pRange2
= 0;
1069 OTextCursorHelper
* pCursor2
= 0;
1070 if(xRangeTunnel2
.is())
1072 pRange2
= reinterpret_cast< SwXTextRange
* >(
1073 sal::static_int_cast
< sal_IntPtr
>( xRangeTunnel2
->getSomething( SwXTextRange::getUnoTunnelId()) ));
1074 pCursor2
= reinterpret_cast< OTextCursorHelper
* >(
1075 sal::static_int_cast
< sal_IntPtr
>( xRangeTunnel2
->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
1078 if((pRange1
||pCursor1
) && (pRange2
||pCursor2
))
1080 if(CheckForOwnMember(pRange1
, pCursor1
)
1081 && CheckForOwnMember( pRange2
, pCursor2
))
1083 const SwPosition
*pStart1
= 0;
1084 const SwPosition
*pStart2
= 0;
1087 pStart1
= pRange1
->GetBookmark() ? &(pRange1
->GetBookmark()->GetMarkStart()) : 0;
1089 pStart1
= pCursor1
->GetPaM() ? pCursor1
->GetPaM()->Start() : 0;
1092 pStart2
= pRange2
->GetBookmark() ? &(pRange2
->GetBookmark()->GetMarkStart()) : 0;
1094 pStart2
= pCursor2
->GetPaM() ? pCursor2
->GetPaM()->Start() : 0;
1096 if(pStart1
&& pStart2
)
1098 if(*pStart1
< *pStart2
)
1100 else if(*pStart1
> *pStart2
)
1104 DBG_ASSERT(*pStart1
== *pStart2
, "SwPositions should be equal here");
1120 throw lang::IllegalArgumentException();
1125 /*-- 28.03.00 10:37:22---------------------------------------------------
1127 -----------------------------------------------------------------------*/
1128 sal_Int16
SwXText::compareRegionStarts(
1129 const uno::Reference
<text::XTextRange
>& xR1
,
1130 const uno::Reference
<text::XTextRange
>& xR2
)
1131 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
1133 vos::OGuard
aGuard(Application::GetSolarMutex());
1134 if(!xR1
.is() || !xR2
.is())
1135 throw lang::IllegalArgumentException();
1136 uno::Reference
<text::XTextRange
> xStart1
= xR1
->getStart();
1137 uno::Reference
<text::XTextRange
> xStart2
= xR2
->getStart();
1139 return ComparePositions(xStart1
, xStart2
);
1141 /*-- 28.03.00 10:37:25---------------------------------------------------
1143 -----------------------------------------------------------------------*/
1144 sal_Int16
SwXText::compareRegionEnds(
1145 const uno::Reference
<text::XTextRange
>& xR1
,
1146 const uno::Reference
<text::XTextRange
>& xR2
)
1147 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
1149 vos::OGuard
aGuard(Application::GetSolarMutex());
1150 if(!xR1
.is() || !xR2
.is())
1151 throw lang::IllegalArgumentException();
1152 uno::Reference
<text::XTextRange
> xEnd1
= xR1
->getEnd();
1153 uno::Reference
<text::XTextRange
> xEnd2
= xR2
->getEnd();
1155 return ComparePositions(xEnd1
, xEnd2
);
1158 /*-- 15.03.2002 12:30:40---------------------------------------------------
1160 -----------------------------------------------------------------------*/
1161 uno::Reference
< beans::XPropertySetInfo
> SwXText::getPropertySetInfo( )
1162 throw(uno::RuntimeException
)
1164 static uno::Reference
< beans::XPropertySetInfo
> xInfo
= m_pPropSet
->getPropertySetInfo();
1167 /*-- 15.03.2002 12:30:42---------------------------------------------------
1169 -----------------------------------------------------------------------*/
1170 void SwXText::setPropertyValue( const ::rtl::OUString
& /*aPropertyName*/, const uno::Any
& /*aValue*/ )
1171 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
1172 lang::IllegalArgumentException
, lang::WrappedTargetException
,
1173 uno::RuntimeException
)
1175 throw lang::IllegalArgumentException();
1177 /*-- 15.03.2002 12:30:42---------------------------------------------------
1179 -----------------------------------------------------------------------*/
1180 uno::Any
SwXText::getPropertyValue(
1181 const ::rtl::OUString
& rPropertyName
)
1182 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
1183 uno::RuntimeException
)
1185 vos::OGuard
aGuard(Application::GetSolarMutex());
1187 throw uno::RuntimeException();
1188 const SfxItemPropertySimpleEntry
* pEntry
= m_pPropSet
->getPropertyMap()->getByName(rPropertyName
);
1192 switch(pEntry
->nWID
)
1194 // no code necessary - the redline is always located at the end node
1195 // case FN_UNO_REDLINE_NODE_START:
1197 case FN_UNO_REDLINE_NODE_END
:
1199 const SwRedlineTbl
& rRedTbl
= GetDoc()->GetRedlineTbl();
1200 USHORT nRedTblCount
= rRedTbl
.Count();
1201 if ( nRedTblCount
> 0 )
1203 const SwStartNode
* pStartNode
= GetStartNode();
1204 ULONG nOwnIndex
= pStartNode
->EndOfSectionIndex();
1205 for(USHORT nRed
= 0; nRed
< nRedTblCount
; nRed
++)
1207 const SwRedline
* pRedline
= rRedTbl
[nRed
];
1208 const SwPosition
* pRedStart
= pRedline
->Start();
1209 const SwNodeIndex nRedNode
= pRedStart
->nNode
;
1210 if(nOwnIndex
== nRedNode
.GetIndex())
1212 aRet
<<= SwXRedlinePortion::CreateRedlineProperties(*pRedline
, TRUE
);
1223 beans::UnknownPropertyException aExcept
;
1224 aExcept
.Message
= C2U("Unknown property: ");
1225 aExcept
.Message
+= rPropertyName
;
1231 /*-- 15.03.2002 12:30:42---------------------------------------------------
1233 -----------------------------------------------------------------------*/
1234 void SwXText::addPropertyChangeListener(
1235 const ::rtl::OUString
& /*aPropertyName*/,
1236 const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
1237 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
1238 uno::RuntimeException
)
1240 throw uno::RuntimeException();
1242 /*-- 15.03.2002 12:30:43---------------------------------------------------
1244 -----------------------------------------------------------------------*/
1245 void SwXText::removePropertyChangeListener(
1246 const ::rtl::OUString
& /*aPropertyName*/,
1247 const uno::Reference
< beans::XPropertyChangeListener
>& /*aListener*/ )
1248 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
1249 uno::RuntimeException
)
1251 throw uno::RuntimeException();
1253 /*-- 15.03.2002 12:30:43---------------------------------------------------
1255 -----------------------------------------------------------------------*/
1256 void SwXText::addVetoableChangeListener(
1257 const ::rtl::OUString
& /*PropertyName*/,
1258 const uno::Reference
< beans::XVetoableChangeListener
>& /*xListener*/ )
1259 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
1260 uno::RuntimeException
)
1262 throw uno::RuntimeException();
1264 /*-- 15.03.2002 12:30:43---------------------------------------------------
1266 -----------------------------------------------------------------------*/
1267 void SwXText::removeVetoableChangeListener(
1268 const ::rtl::OUString
& /*rPropertyName*/,
1269 const uno::Reference
< beans::XVetoableChangeListener
>& /*xListener*/ )
1270 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
1271 uno::RuntimeException
)
1273 throw uno::RuntimeException();
1276 /* -----------------------------08.01.01 09:07--------------------------------
1278 ---------------------------------------------------------------------------*/
1279 const uno::Sequence
< sal_Int8
> & SwXText::getUnoTunnelId()
1281 static uno::Sequence
< sal_Int8
> aSeq
= ::CreateUnoTunnelId();
1284 /* -----------------------------08.01.01 09:07--------------------------------
1286 ---------------------------------------------------------------------------*/
1287 sal_Int64
SwXText::getSomething( const uno::Sequence
< sal_Int8
>& rId
)
1288 throw(uno::RuntimeException
)
1290 if( rId
.getLength() == 16
1291 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
1292 rId
.getConstArray(), 16 ) )
1294 return sal::static_int_cast
< sal_Int64
>( reinterpret_cast< sal_IntPtr
>(this) );
1298 /*-- 23.06.2006 08:56:30---------------------------------------------------
1300 -----------------------------------------------------------------------*/
1301 uno::Reference
< text::XTextRange
> SwXText::appendParagraph(
1302 const uno::Sequence
< beans::PropertyValue
> & rProperties
)
1303 throw (lang::IllegalArgumentException
, uno::RuntimeException
)
1305 return finishOrAppendParagraph(false, rProperties
);
1307 /*-- 23.06.2006 08:56:22---------------------------------------------------
1309 -----------------------------------------------------------------------*/
1310 uno::Reference
< text::XTextRange
> SwXText::finishParagraph(
1311 const uno::Sequence
< beans::PropertyValue
> & rProperties
)
1312 throw (lang::IllegalArgumentException
, uno::RuntimeException
)
1314 return finishOrAppendParagraph(true, rProperties
);
1317 /*-- 08.05.2006 13:26:26---------------------------------------------------
1319 -----------------------------------------------------------------------*/
1320 uno::Reference
< text::XTextRange
> SwXText::finishOrAppendParagraph(
1322 const uno::Sequence
< beans::PropertyValue
> & rProperties
)
1323 throw (lang::IllegalArgumentException
, uno::RuntimeException
)
1326 vos::OGuard
aGuard(Application::GetSolarMutex());
1328 throw uno::RuntimeException();
1329 uno::Reference
< text::XTextRange
> xRet
;
1331 const SwStartNode
* pStartNode
= GetStartNode();
1333 throw uno::RuntimeException();
1335 bool bIllegalException
= false;
1336 bool bRuntimeException
= false;
1337 ::rtl::OUString sMessage
;
1338 pDoc
->StartUndo(UNDO_START
, NULL
);
1339 //find end node, go backward - don't skip tables because the new paragraph has to be the last node
1340 //aPam.Move( fnMoveBackward, fnGoNode );
1341 SwPosition
aInsertPosition( SwNodeIndex( *pStartNode
->EndOfSectionNode(), -1 ) );
1342 SwPaM
aPam(aInsertPosition
);
1343 pDoc
->AppendTxtNode( *aPam
.GetPoint() );
1344 //remove attributes from the previous paragraph
1345 pDoc
->ResetAttrs(aPam
);
1346 //in case of finishParagraph the PaM needs to be moved to the previous paragraph
1348 aPam
.Move( fnMoveBackward
, fnGoNode
);
1349 if(rProperties
.getLength())
1351 // now set the properties
1352 const SfxItemPropertySet
* pParaPropSet
= aSwMapProvider
.GetPropertySet(PROPERTY_MAP_PARAGRAPH
);
1353 const SfxItemPropertyMap
* pParagraphMap
= pParaPropSet
->getPropertyMap();
1355 const beans::PropertyValue
* pValues
= rProperties
.getConstArray();
1357 for( sal_Int32 nProp
= 0; nProp
< rProperties
.getLength(); ++nProp
)
1359 if(pParagraphMap
->getByName( pValues
[nProp
].Name
))
1363 SwXTextCursor::SetPropertyValue(
1366 pValues
[nProp
].Name
,
1367 pValues
[nProp
].Value
);
1369 catch( lang::IllegalArgumentException
& rIllegal
)
1371 sMessage
= rIllegal
.Message
;
1372 bIllegalException
= true;
1374 catch( uno::RuntimeException
& rRuntime
)
1376 sMessage
= rRuntime
.Message
;
1377 bRuntimeException
= true;
1381 bIllegalException
= true;
1382 if( bIllegalException
|| bRuntimeException
)
1388 pDoc
->EndUndo(UNDO_END
, NULL
);
1389 if( bIllegalException
|| bRuntimeException
)
1391 SwUndoIter
aUndoIter( &aPam
, UNDO_EMPTY
);
1392 pDoc
->Undo(aUndoIter
);
1393 if(bIllegalException
)
1395 lang::IllegalArgumentException aEx
;
1396 aEx
.Message
= sMessage
;
1399 else //if(bRuntimeException)
1401 uno::RuntimeException aEx
;
1402 aEx
.Message
= sMessage
;
1406 SwTxtNode
* pTxtNode( aPam
.Start()->nNode
.GetNode().GetTxtNode() );
1407 OSL_ENSURE(pTxtNode
, "no SwTxtNode?");
1408 xRet
= new SwXParagraph(this, pTxtNode
);
1413 /*-- 08.05.2006 13:28:26---------------------------------------------------
1414 Append text portions at the end of the last paragraph of the text
1415 interface. Support of import filters.
1416 -----------------------------------------------------------------------*/
1417 uno::Reference
< text::XTextRange
> SwXText::appendTextPortion(
1418 const ::rtl::OUString
& rText
,
1419 const uno::Sequence
< beans::PropertyValue
> & rCharacterAndParagraphProperties
)
1420 throw (lang::IllegalArgumentException
, uno::RuntimeException
)
1422 vos::OGuard
aGuard(Application::GetSolarMutex());
1424 throw uno::RuntimeException();
1425 uno::Reference
< text::XTextRange
> xRet
;
1426 uno::Reference
< text::XTextCursor
> xTextCursor
= createCursor();
1427 xTextCursor
->gotoEnd(sal_False
);
1429 uno::Reference
< lang::XUnoTunnel
> xRangeTunnel( xTextCursor
, uno::UNO_QUERY_THROW
);
1430 SwXTextCursor
* pTextCursor
= reinterpret_cast< SwXTextCursor
* >(
1431 sal::static_int_cast
< sal_IntPtr
>( xRangeTunnel
->getSomething( SwXTextCursor::getUnoTunnelId())));
1433 bool bIllegalException
= false;
1434 bool bRuntimeException
= false;
1435 ::rtl::OUString sMessage
;
1436 pDoc
->StartUndo(UNDO_INSERT
, NULL
);
1438 // SwPaM aPam(*pStartNode->EndOfSectionNode());
1439 //aPam.Move( fnMoveBackward, fnGoNode );
1440 SwUnoCrsr
* pCursor
= pTextCursor
->GetCrsr();
1441 pCursor
->MovePara( fnParaCurr
, fnParaEnd
);
1442 pDoc
->DontExpandFmt( *pCursor
->Start() );
1444 if(rText
.getLength())
1446 xub_StrLen nContentPos
= pCursor
->GetPoint()->nContent
.GetIndex();
1447 SwUnoCursorHelper::DocInsertStringSplitCR( *pDoc
, *pCursor
, rText
,
1449 SwXTextCursor::SelectPam(*pCursor
, sal_True
);
1450 pCursor
->GetPoint()->nContent
= nContentPos
;
1453 if(rCharacterAndParagraphProperties
.getLength())
1455 const SfxItemPropertyMap
* pCursorMap
= aSwMapProvider
.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR
)->getPropertyMap();
1456 const beans::PropertyValue
* pValues
= rCharacterAndParagraphProperties
.getConstArray();
1457 const SfxItemPropertySet
* pCursorPropSet
= aSwMapProvider
.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR
);
1458 for( sal_Int32 nProp
= 0; nProp
< rCharacterAndParagraphProperties
.getLength(); ++nProp
)
1460 if( pCursorMap
->getByName( pValues
[nProp
].Name
) )
1464 SwXTextCursor::SetPropertyValue(
1467 pValues
[nProp
].Name
,
1468 pValues
[nProp
].Value
,
1469 nsSetAttrMode::SETATTR_NOFORMATATTR
);
1471 catch( lang::IllegalArgumentException
& rIllegal
)
1473 sMessage
= rIllegal
.Message
;
1474 bIllegalException
= true;
1476 catch( uno::RuntimeException
& rRuntime
)
1478 sMessage
= rRuntime
.Message
;
1479 bRuntimeException
= true;
1483 bIllegalException
= true;
1484 if( bIllegalException
|| bRuntimeException
)
1490 pDoc
->EndUndo(UNDO_INSERT
, NULL
);
1491 if( bIllegalException
|| bRuntimeException
)
1493 SwUndoIter
aUndoIter( pCursor
, UNDO_EMPTY
);
1494 pDoc
->Undo(aUndoIter
);
1497 if(bIllegalException
)
1499 lang::IllegalArgumentException aEx
;
1500 aEx
.Message
= sMessage
;
1503 else //if(bRuntimeException)
1505 uno::RuntimeException aEx
;
1506 aEx
.Message
= sMessage
;
1510 xRet
= new SwXTextRange(*pCursor
, this);
1515 /*-- 11.05.2006 15:46:26---------------------------------------------------
1516 enable appending text contents like graphic objects, shapes and so on
1517 to support import filters
1518 -----------------------------------------------------------------------*/
1519 uno::Reference
< text::XTextRange
> SwXText::appendTextContent(
1520 const uno::Reference
< text::XTextContent
>& xTextContent
,
1521 const uno::Sequence
< beans::PropertyValue
>& rCharacterAndParagraphProperties
)
1522 throw (lang::IllegalArgumentException
, uno::RuntimeException
)
1524 vos::OGuard
aGuard(Application::GetSolarMutex());
1526 throw uno::RuntimeException();
1527 const SwStartNode
* pStartNode
= GetStartNode();
1529 throw uno::RuntimeException();
1530 uno::Reference
< text::XTextRange
> xRet
;
1532 pDoc
->StartUndo(UNDO_INSERT
, NULL
);
1533 //find end node, go backward - don't skip tables because the new paragraph has to be the last node
1534 SwPaM
aPam(*pStartNode
->EndOfSectionNode());
1535 aPam
.Move( fnMoveBackward
, fnGoNode
);
1536 //set cursor to the end of the last text node
1537 SwCursor
* pCursor
= new SwCursor( *aPam
.Start(),0,false );
1538 xRet
= new SwXTextRange(*pCursor
, this);
1539 pCursor
->MovePara( fnParaCurr
, fnParaEnd
);
1540 pDoc
->DontExpandFmt( *pCursor
->Start() );
1541 //now attach the text content here
1542 insertTextContent( xRet
, xTextContent
, false );
1543 //now apply the properties to the anchor
1544 if( rCharacterAndParagraphProperties
.getLength())
1548 uno::Reference
< beans::XPropertySet
> xAnchor( xTextContent
->getAnchor(), uno::UNO_QUERY
);
1551 for( sal_Int32 nElement
= 0; nElement
< rCharacterAndParagraphProperties
.getLength(); ++nElement
)
1553 xAnchor
->setPropertyValue( rCharacterAndParagraphProperties
[nElement
].Name
, rCharacterAndParagraphProperties
[nElement
].Value
);
1558 catch(const uno::Exception
&)
1560 throw uno::RuntimeException();
1564 pDoc
->EndUndo(UNDO_INSERT
, NULL
);
1569 // move previously appended paragraphs into a text frames
1570 // to support import filters
1571 uno::Reference
< text::XTextContent
> SwXText::convertToTextFrame(
1572 const uno::Reference
< text::XTextRange
>& xStart
,
1573 const uno::Reference
< text::XTextRange
>& xEnd
,
1574 const uno::Sequence
< beans::PropertyValue
>& rFrameProperties
)
1575 throw (lang::IllegalArgumentException
, uno::RuntimeException
)
1577 vos::OGuard
aGuard(Application::GetSolarMutex());
1579 throw uno::RuntimeException();
1580 uno::Reference
< text::XTextContent
> xRet
;
1581 SwUnoInternalPaM
aStartPam(*GetDoc());
1582 std::auto_ptr
< SwUnoInternalPaM
> pEndPam( new SwUnoInternalPaM(*GetDoc()));
1583 if(SwXTextRange::XTextRangeToSwPaM(aStartPam
, xStart
) &&
1584 SwXTextRange::XTextRangeToSwPaM(*pEndPam
, xEnd
) )
1586 uno::Reference
<lang::XUnoTunnel
> xStartRangeTunnel( xStart
, uno::UNO_QUERY
);
1587 SwXTextRange
* pStartRange
= reinterpret_cast< SwXTextRange
* >(
1588 sal::static_int_cast
< sal_IntPtr
>( xStartRangeTunnel
->getSomething( SwXTextRange::getUnoTunnelId()) ));
1589 uno::Reference
<lang::XUnoTunnel
> xEndRangeTunnel( xEnd
, uno::UNO_QUERY
);
1590 SwXTextRange
* pEndRange
= reinterpret_cast< SwXTextRange
* >(
1591 sal::static_int_cast
< sal_IntPtr
>( xEndRangeTunnel
->getSomething( SwXTextRange::getUnoTunnelId()) ));
1592 //bookmarks have to be removed before the referenced text node is deleted in DelFullPara
1595 ::sw::mark::IMark
const * const pStartBookmark
= pStartRange
->GetBookmark();
1597 pDoc
->getIDocumentMarkAccess()->deleteMark(pStartBookmark
);
1601 ::sw::mark::IMark
const * const pEndBookmark
= pEndRange
->GetBookmark();
1603 pDoc
->getIDocumentMarkAccess()->deleteMark(pEndBookmark
);
1606 pDoc
->StartUndo( UNDO_START
, NULL
);
1607 bool bIllegalException
= false;
1608 bool bRuntimeException
= false;
1609 ::rtl::OUString sMessage
;
1610 SwStartNode
* pStartStartNode
= aStartPam
.GetNode()->StartOfSectionNode();
1611 while(pStartStartNode
&& pStartStartNode
->IsSectionNode())
1613 pStartStartNode
= pStartStartNode
->StartOfSectionNode();
1615 SwStartNode
* pEndStartNode
= pEndPam
->GetNode()->StartOfSectionNode();
1616 while(pEndStartNode
&& pEndStartNode
->IsSectionNode())
1618 pEndStartNode
= pEndStartNode
->StartOfSectionNode();
1620 bool bParaAfterInserted
= false;
1621 bool bParaBeforeInserted
= false;
1622 if(pStartStartNode
!= pEndStartNode
|| pStartStartNode
!= GetStartNode())
1624 //todo: if the start/end is in a table then insert a paragraph before/after, move
1625 //the start/end nodes, then convert and remove the addtional paragraphs in the end
1626 if( pStartStartNode
->GetStartNodeType() == SwTableBoxStartNode
)
1628 SwTableNode
* pSartTableNode
= pStartStartNode
->FindTableNode();
1629 SwNodeIndex
aTblIdx( *pSartTableNode
, -1 );
1630 SwPosition
aBefore(aTblIdx
);
1631 bParaBeforeInserted
= GetDoc()->AppendTxtNode( aBefore
);
1632 aStartPam
.DeleteMark();
1633 *aStartPam
.GetPoint() = aBefore
;
1634 pStartStartNode
= aStartPam
.GetNode()->StartOfSectionNode();
1636 if( pEndStartNode
->GetStartNodeType() == SwTableBoxStartNode
)
1638 SwTableNode
* pEndTableNode
= pEndStartNode
->FindTableNode();
1639 SwEndNode
* pTableEnd
= pEndTableNode
->EndOfSectionNode();
1640 SwPosition
aTableEnd(*pTableEnd
);
1641 bParaAfterInserted
= GetDoc()->AppendTxtNode( aTableEnd
);
1642 pEndPam
->DeleteMark();
1643 *pEndPam
->GetPoint() = aTableEnd
;
1644 pEndStartNode
= pEndPam
->GetNode()->StartOfSectionNode();
1646 //now we should have the positions in the same hierarchy
1647 if(pStartStartNode
!= pEndStartNode
|| pStartStartNode
!= GetStartNode())
1649 //if not - remove the additional paragraphs and throw
1650 if( bParaBeforeInserted
)
1652 SwCursor
aDelete(*aStartPam
.GetPoint(), 0, false);
1653 aDelete
.MovePara(fnParaCurr
, fnParaStart
);
1655 aDelete
.MovePara(fnParaCurr
, fnParaEnd
);
1656 GetDoc()->DelFullPara(aDelete
);
1658 if( bParaAfterInserted
)
1660 SwCursor
aDelete(*pEndPam
->GetPoint(), 0, false);
1661 aDelete
.MovePara(fnParaCurr
, fnParaStart
);
1663 aDelete
.MovePara(fnParaCurr
, fnParaEnd
);
1664 GetDoc()->DelFullPara(aDelete
);
1666 throw lang::IllegalArgumentException();
1670 //make a selection from aStartPam to a EndPam
1672 SfxItemSet
aFrameItemSet(pDoc
->GetAttrPool(),
1673 RES_FRMATR_BEGIN
, RES_FRMATR_END
-1,
1676 aStartPam
.SetMark();
1677 *aStartPam
.End() = *pEndPam
->End();
1680 SwXTextFrame
* pNewFrame
;
1681 uno::Reference
< text::XTextFrame
> xNewFrame
= pNewFrame
= new SwXTextFrame( pDoc
);
1682 pNewFrame
->SetSelection( aStartPam
);
1685 const beans::PropertyValue
* pValues
= rFrameProperties
.getConstArray();
1686 for(sal_Int32 nProp
= 0; nProp
< rFrameProperties
.getLength(); ++nProp
)
1687 pNewFrame
->SwXFrame::setPropertyValue(pValues
[nProp
].Name
, pValues
[nProp
].Value
);
1689 {//has to be in a block to remove the SwIndexes before DelFullPara is called
1690 uno::Reference
< text::XTextRange
> xInsertTextRange
= new SwXTextRange(aStartPam
, this);
1691 pNewFrame
->attach( xInsertTextRange
);
1692 pNewFrame
->setName(pDoc
->GetUniqueFrameName());
1695 if( !aStartPam
.GetTxt().Len() )
1698 bool bMoved
= false;
1699 {//has to be in a block to remove the SwIndexes before DelFullPara is called
1700 SwPaM
aMovePam( *aStartPam
.GetNode() );
1701 if( aMovePam
.Move( fnMoveForward
, fnGoCntnt
) )
1703 //move the anchor to the next paragraph
1704 SwFmtAnchor
aNewAnchor( pNewFrame
->GetFrmFmt()->GetAnchor() );
1705 aNewAnchor
.SetAnchor( aMovePam
.Start() );
1706 pDoc
->SetAttr( aNewAnchor
, *pNewFrame
->GetFrmFmt() );
1712 aStartPam
.DeleteMark();
1713 // SwPaM aDelPam( *aStartPam.GetNode() );
1714 pDoc
->DelFullPara(aStartPam
/*aDelPam*/);
1718 catch( lang::IllegalArgumentException
& rIllegal
)
1720 sMessage
= rIllegal
.Message
;
1721 bIllegalException
= true;
1723 catch( uno::RuntimeException
& rRuntime
)
1725 sMessage
= rRuntime
.Message
;
1726 bRuntimeException
= true;
1729 uno::Reference
<text::XTextCursor
> xFrameTextCursor
;
1730 if( bParaBeforeInserted
)
1732 //todo: remove paragraph before frame
1733 xFrameTextCursor
= pNewFrame
->createTextCursor();
1734 uno::Reference
<XUnoTunnel
> xTunnel(xFrameTextCursor
, uno::UNO_QUERY
);
1735 SwXTextCursor
* pFrameCursor
= reinterpret_cast< SwXTextCursor
* >(
1736 sal::static_int_cast
< sal_IntPtr
>( xTunnel
->getSomething(SwXTextCursor::getUnoTunnelId()) ));
1737 pDoc
->DelFullPara(*pFrameCursor
->GetPaM());
1739 if( bParaAfterInserted
)
1741 //todo: remove paragraph after frame
1742 if( xFrameTextCursor
.is() )
1743 xFrameTextCursor
= pNewFrame
->createTextCursor();
1744 xFrameTextCursor
->gotoEnd( false );
1745 uno::Reference
<XUnoTunnel
> xTunnel(xFrameTextCursor
, uno::UNO_QUERY
);
1746 SwXTextCursor
* pFrameCursor
= reinterpret_cast< SwXTextCursor
* >(
1747 sal::static_int_cast
< sal_IntPtr
>( xTunnel
->getSomething(SwXTextCursor::getUnoTunnelId()) ));
1748 pDoc
->DelFullPara(*pFrameCursor
->GetPaM());
1751 pDoc
->EndUndo(UNDO_END
, NULL
);
1752 if( bIllegalException
|| bRuntimeException
)
1754 SwUndoIter
aUndoIter( &aStartPam
, UNDO_EMPTY
);
1755 pDoc
->Undo(aUndoIter
);
1756 if(bIllegalException
)
1758 lang::IllegalArgumentException aEx
;
1759 aEx
.Message
= sMessage
;
1762 else //if(bRuntimeException)
1764 uno::RuntimeException aEx
;
1765 aEx
.Message
= sMessage
;
1771 throw lang::IllegalArgumentException();
1774 /*-- 11.05.2006 15:46:26---------------------------------------------------
1775 Move previously imported paragraphs into a new text table.
1777 -----------------------------------------------------------------------*/
1778 struct VerticallyMergedCell
1780 std::vector
<uno::Reference
< beans::XPropertySet
> > aCells
;
1781 sal_Int32 nLeftPosition
;
1784 VerticallyMergedCell( uno::Reference
< beans::XPropertySet
>& rxCell
, sal_Int32 nLeft
) :
1785 nLeftPosition( nLeft
),
1788 aCells
.push_back( rxCell
);
1791 #define COL_POS_FUZZY 2
1792 bool lcl_SimilarPosition( sal_Int32 nPos1
, sal_Int32 nPos2
)
1794 return abs( nPos1
- nPos2
) < COL_POS_FUZZY
;
1797 void SwXText::copyText(
1798 const uno::Reference
< text::XTextCopy
>& xSource
)
1799 throw ( uno::RuntimeException
)
1802 clog
<< "TODO - SwXText::copyText()" << endl
;
1804 uno::Reference
< lang::XUnoTunnel
> xTTunnel( xSource
, uno::UNO_QUERY_THROW
);
1806 pText
= reinterpret_cast< SwXText
* >(
1807 sal::static_int_cast
< sal_IntPtr
>( xTTunnel
->getSomething( SwXText::getUnoTunnelId()) ));
1810 uno::Reference
< text::XText
> xText( xSource
, uno::UNO_QUERY_THROW
);
1811 uno::Reference
< text::XTextCursor
> xCursor
= xText
->createTextCursor( );
1812 xCursor
->gotoEnd( sal_True
);
1814 uno::Reference
< lang::XUnoTunnel
> xTunnel( xCursor
, uno::UNO_QUERY_THROW
);
1816 OTextCursorHelper
* pCursor
= 0;
1817 pCursor
= reinterpret_cast< OTextCursorHelper
* >(
1818 sal::static_int_cast
< sal_IntPtr
>( xTunnel
->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
1821 SwNodeIndex
rNdIndex( *GetStartNode( ), 1 );
1822 SwPosition
rPos( rNdIndex
);
1823 pDoc
->CopyRange( *pCursor
->GetPaM( ), rPos
, false );
1827 uno::Reference
< text::XTextTable
> SwXText::convertToTable(
1828 const uno::Sequence
< uno::Sequence
< uno::Sequence
< uno::Reference
< text::XTextRange
> > > >& rTableRanges
,
1829 const uno::Sequence
< uno::Sequence
< uno::Sequence
< beans::PropertyValue
> > >& rCellProperties
,
1830 const uno::Sequence
< uno::Sequence
< beans::PropertyValue
> >& rRowProperties
,
1831 const uno::Sequence
< beans::PropertyValue
>& rTableProperties
)
1832 throw (lang::IllegalArgumentException
, uno::RuntimeException
)
1834 vos::OGuard
aGuard(Application::GetSolarMutex());
1836 throw uno::RuntimeException();
1838 //at first collect the text ranges as SwPaMs
1839 const uno::Sequence
< uno::Sequence
< uno::Reference
< text::XTextRange
> > >* pTableRanges
= rTableRanges
.getConstArray();
1840 std::auto_ptr
< SwPaM
> pFirstPaM
;
1841 std::vector
< std::vector
<SwNodeRange
> > aTableNodes
;
1842 bool bExcept
= false;
1843 SwPaM
aLastPaM(pDoc
->GetNodes());
1844 for( sal_Int32 nRow
= 0; !bExcept
&& (nRow
< rTableRanges
.getLength()); ++nRow
)
1846 std::vector
<SwNodeRange
> aRowNodes
;
1847 const uno::Sequence
< uno::Sequence
< uno::Reference
< text::XTextRange
> > >& rRow
= pTableRanges
[nRow
];
1848 const uno::Sequence
< uno::Reference
< text::XTextRange
> >* pRow
= pTableRanges
[nRow
].getConstArray();
1850 for( sal_Int32 nCell
= 0; nCell
< rRow
.getLength(); ++nCell
)
1852 if( pRow
[nCell
].getLength() != 2 )
1853 throw lang::IllegalArgumentException();
1854 const uno::Reference
< text::XTextRange
> xStartRange
= pRow
[nCell
][0];
1855 const uno::Reference
< text::XTextRange
> xEndRange
= pRow
[nCell
][1];
1856 SwUnoInternalPaM
aStartCellPam(*pDoc
);
1857 SwUnoInternalPaM
aEndCellPam(*pDoc
);
1859 // !!! TODO - PaMs in tables and sections do not work here - the same applies to PaMs in frames !!!
1861 if(!SwXTextRange::XTextRangeToSwPaM(aStartCellPam
, xStartRange
) ||
1862 !SwXTextRange::XTextRangeToSwPaM(aEndCellPam
, xEndRange
) )
1863 throw lang::IllegalArgumentException();
1864 /** check the nodes between start and end
1865 it is allowed to have pairs of StartNode/EndNodes
1867 if(aStartCellPam
.Start()->nNode
< aEndCellPam
.End()->nNode
)
1869 // increment on each StartNode and decrement on each EndNode
1870 // we must reach zero at the end and must not go below zero
1871 long nOpenNodeBlock
= 0;
1872 SwNodeIndex aCellIndex
= aStartCellPam
.Start()->nNode
;
1873 while( aCellIndex
< aEndCellPam
.End()->nNode
.GetIndex())
1875 if( aCellIndex
.GetNode().IsStartNode() )
1877 else if(aCellIndex
.GetNode().IsEndNode() )
1879 if( nOpenNodeBlock
< 0 )
1886 if( nOpenNodeBlock
!= 0)
1893 /** The vector<vector> NodeRanges has to contain consecutive nodes.
1894 In rTableRanges the ranges don't need to be full paragraphs but they have to follow
1895 each other. To process the ranges they have to be aligned on paragraph borders
1896 by inserting paragraph breaks. Non-consecutive ranges must initiate an
1902 //align the beginning - if necessary
1903 if(aStartCellPam
.Start()->nContent
.GetIndex())
1904 pDoc
->SplitNode(*aStartCellPam
.Start(), sal_False
);
1908 //check the predecessor
1909 ULONG nLastNodeIndex
= aLastPaM
.End()->nNode
.GetIndex();
1910 ULONG nStartCellNodeIndex
= aStartCellPam
.Start()->nNode
.GetIndex();
1911 ULONG nLastNodeEndIndex
= aLastPaM
.End()->nNode
.GetIndex();
1912 if( nLastNodeIndex
== nStartCellNodeIndex
)
1914 //- same node as predecessor then equal nContent?
1915 if(aLastPaM
.End()->nContent
!= aStartCellPam
.Start()->nContent
)
1919 pDoc
->SplitNode(*aStartCellPam
.Start(), sal_False
);
1922 else if(nStartCellNodeIndex
== ( nLastNodeEndIndex
+ 1))
1924 //next paragraph - now the content index of the new should be 0
1925 //and of the old one should be equal to the text length
1926 //but if it isn't we don't care - the cell is being inserted on the
1927 //node border anyway
1934 //now check if there's a need to insert another paragraph break
1935 if( aEndCellPam
.End()->nContent
.GetIndex() < aEndCellPam
.End()->nNode
.GetNode().GetTxtNode()->Len())
1937 pDoc
->SplitNode(*aEndCellPam
.End(), sal_False
);
1938 //take care that the new start/endcell is moved to the right position
1939 //aStartCellPam has to point to the start of the new (previous) node
1940 //aEndCellPam has to point the the end of the new (previous) node
1941 aStartCellPam
.DeleteMark();
1942 aStartCellPam
.Move(fnMoveBackward
, fnGoNode
);
1943 aStartCellPam
.GetPoint()->nContent
= 0;
1944 aEndCellPam
.DeleteMark();
1945 aEndCellPam
.Move(fnMoveBackward
, fnGoNode
);
1946 aEndCellPam
.GetPoint()->nContent
= aEndCellPam
.GetNode()->GetTxtNode()->Len();
1950 *aLastPaM
.GetPoint() = *aEndCellPam
.Start();
1951 if( aStartCellPam
.HasMark() )
1954 *aLastPaM
.GetMark() = *aEndCellPam
.End();
1957 aLastPaM
.DeleteMark();
1959 SwNodeRange
aCellRange( aStartCellPam
.Start()->nNode
, aEndCellPam
.End()->nNode
);
1960 aRowNodes
.push_back(aCellRange
);
1961 if( !nRow
&& !nCell
)
1962 pFirstPaM
.reset( new SwPaM(*aStartCellPam
.Start()));
1964 aTableNodes
.push_back(aRowNodes
);
1969 SwUndoIter
aUndoIter( &aLastPaM
, UNDO_EMPTY
);
1970 pDoc
->Undo(aUndoIter
);
1971 throw lang::IllegalArgumentException();
1974 typedef uno::Sequence
< text::TableColumnSeparator
> TableColumnSeparators
;
1975 std::vector
< TableColumnSeparators
> aRowSeparators(rRowProperties
.getLength());
1976 std::vector
<VerticallyMergedCell
> aMergedCells
;
1978 const SwTable
* pTable
= pDoc
->TextToTable( aTableNodes
);
1979 SwXTextTable
* pTextTable
= 0;
1980 uno::Reference
< text::XTextTable
> xRet
= pTextTable
= new SwXTextTable( *pTable
->GetFrmFmt() );
1981 uno::Reference
< beans::XPropertySet
> xPrSet
= pTextTable
;
1982 // set properties to the table - catch lang::WrappedTargetException and lang::IndexOutOfBoundsException
1985 //apply table properties
1986 const beans::PropertyValue
* pTableProperties
= rTableProperties
.getConstArray();
1987 sal_Int32 nProperty
= 0;
1988 for( ; nProperty
< rTableProperties
.getLength(); ++nProperty
)
1992 xPrSet
->setPropertyValue( pTableProperties
[nProperty
].Name
, pTableProperties
[nProperty
].Value
);
1994 catch ( const uno::Exception e
)
1997 std::clog
<< "Exception when setting property: ";
1998 std::clog
<< rtl::OUStringToOString( pTableProperties
[nProperty
].Name
, RTL_TEXTENCODING_UTF8
).getStr( );
1999 std::clog
<< ". Message: ";
2000 std::clog
<< rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_UTF8
).getStr( );
2001 std::clog
<< std::endl
;
2006 //apply row properties
2007 uno::Reference
< table::XTableRows
> xRows
= xRet
->getRows();
2008 const beans::PropertyValues
* pRowProperties
= rRowProperties
.getConstArray();
2010 for( ; nRow
< xRows
->getCount(); ++nRow
)
2012 if( nRow
>= rRowProperties
.getLength())
2016 uno::Reference
< beans::XPropertySet
> xRow
;
2017 xRows
->getByIndex( nRow
) >>= xRow
;
2018 const beans::PropertyValue
* pProperties
= pRowProperties
[nRow
].getConstArray();
2019 for( nProperty
= 0; nProperty
< pRowProperties
[nRow
].getLength(); ++nProperty
)
2021 if( pProperties
[ nProperty
].Name
.equalsAsciiL(
2022 RTL_CONSTASCII_STRINGPARAM ( "TableColumnSeparators" )))
2024 //add the separators to access the cell's positions for vertical merging later
2025 TableColumnSeparators aSeparators
;
2026 pProperties
[ nProperty
].Value
>>= aSeparators
;
2027 aRowSeparators
[nRow
] = aSeparators
;
2029 xRow
->setPropertyValue( pProperties
[ nProperty
].Name
, pProperties
[ nProperty
].Value
);
2034 //-->debug cell properties of all rows
2036 ::rtl::OUString sNames
;
2037 for( sal_Int32 nDebugRow
= 0; nDebugRow
< rCellProperties
.getLength(); ++nDebugRow
)
2039 const uno::Sequence
< beans::PropertyValues
> aDebugCurrentRow
= rCellProperties
[nDebugRow
];
2040 sal_Int32 nDebugCells
= aDebugCurrentRow
.getLength();
2042 for( sal_Int32 nDebugCell
= 0; nDebugCell
< nDebugCells
; ++nDebugCell
)
2044 const uno::Sequence
< beans::PropertyValue
>& aDebugCellProperties
= aDebugCurrentRow
[nDebugCell
];
2045 sal_Int32 nDebugCellProperties
= aDebugCellProperties
.getLength();
2046 for( sal_Int32 nDebugProperty
= 0; nDebugProperty
< nDebugCellProperties
; ++nDebugProperty
)
2048 const ::rtl::OUString sName
= aDebugCellProperties
[nDebugProperty
].Name
;
2050 sNames
+= ::rtl::OUString('-');
2052 sNames
+= ::rtl::OUString('+');
2054 sNames
+= ::rtl::OUString('|');
2062 //apply cell properties
2063 for( nRow
= 0; nRow
< rCellProperties
.getLength(); ++nRow
)
2065 const uno::Sequence
< beans::PropertyValues
> aCurrentRow
= rCellProperties
[nRow
];
2066 sal_Int32 nCells
= aCurrentRow
.getLength();
2067 for( sal_Int32 nCell
= 0; nCell
< nCells
; ++nCell
)
2069 const uno::Sequence
< beans::PropertyValue
>& aCellProperties
= aCurrentRow
[nCell
];
2070 sal_Int32 nCellProperties
= aCellProperties
.getLength();
2071 uno::Reference
< beans::XPropertySet
> xCell( pTextTable
->getCellByPosition(nCell
, nRow
), uno::UNO_QUERY
);
2072 for( nProperty
= 0; nProperty
< nCellProperties
; ++nProperty
)
2074 const OUString
& rName
= aCellProperties
[nProperty
].Name
;
2075 if( rName
.equalsAsciiL(
2076 RTL_CONSTASCII_STRINGPARAM ( "VerticalMerge")))
2078 //determine left border position
2079 //add the cell to a queue of merged cells
2081 sal_Bool bMerge
= sal_False
;
2082 aCellProperties
[nProperty
].Value
>>= bMerge
;
2083 sal_Int32 nLeftPos
= -1;
2086 else if( aRowSeparators
[nRow
].getLength() >= nCell
)
2088 const text::TableColumnSeparator
* pSeparators
= aRowSeparators
[nRow
].getConstArray();
2089 nLeftPos
= pSeparators
[nCell
- 1].Position
;
2093 // 'close' all the cell with the same left position
2094 // if separate vertical merges in the same column exist
2095 if( aMergedCells
.size() )
2097 std::vector
<VerticallyMergedCell
>::iterator aMergedIter
= aMergedCells
.begin();
2098 while( aMergedIter
!= aMergedCells
.end())
2100 if( lcl_SimilarPosition( aMergedIter
->nLeftPosition
, nLeftPos
) )
2102 aMergedIter
->bOpen
= false;
2107 //add the new group of merged cells
2108 aMergedCells
.push_back(VerticallyMergedCell(xCell
, nLeftPos
));
2112 //find the cell that
2113 DBG_ASSERT(aMergedCells
.size(), "the first merged cell is missing");
2114 if( aMergedCells
.size() )
2116 std::vector
<VerticallyMergedCell
>::iterator aMergedIter
= aMergedCells
.begin();
2117 #if OSL_DEBUG_LEVEL > 1
2118 bool bDbgFound
= false;
2120 while( aMergedIter
!= aMergedCells
.end())
2122 if( aMergedIter
->bOpen
&&
2123 lcl_SimilarPosition( aMergedIter
->nLeftPosition
, nLeftPos
) )
2125 aMergedIter
->aCells
.push_back( xCell
);
2126 #if OSL_DEBUG_LEVEL > 1
2132 #if OSL_DEBUG_LEVEL > 1
2133 DBG_ASSERT( bDbgFound
, "couldn't find first vertically merged cell" );
2142 xCell
->setPropertyValue(rName
, aCellProperties
[nProperty
].Value
);
2144 catch ( const uno::Exception e
)
2146 // Apply the paragraph and char properties to the cell's content
2147 uno::Reference
< text::XText
> xCellText( xCell
, uno::UNO_QUERY
);
2148 uno::Reference
< text::XTextCursor
> xCellCurs
= xCellText
->createTextCursor( );
2149 xCellCurs
->gotoStart( false );
2150 xCellCurs
->gotoEnd( true );
2152 uno::Reference
< beans::XPropertySet
> xCellTextProps( xCellCurs
, uno::UNO_QUERY
);
2153 xCellTextProps
->setPropertyValue( rName
, aCellProperties
[nProperty
].Value
);
2159 //now that the cell properties are set the vertical merge values have to be applied
2160 if( aMergedCells
.size() )
2162 std::vector
<VerticallyMergedCell
>::iterator aMergedIter
= aMergedCells
.begin();
2163 while( aMergedIter
!= aMergedCells
.end())
2165 sal_Int32 nCellCount
= (sal_Int32
)aMergedIter
->aCells
.size();
2166 std::vector
<uno::Reference
< beans::XPropertySet
> >::iterator aCellIter
= aMergedIter
->aCells
.begin();
2167 bool bFirstCell
= true;
2168 //the first of the cells get's the number of cells set as RowSpan
2169 //the others get the inverted number of remaining merged cells (3,-2,-1)
2170 while( aCellIter
!= aMergedIter
->aCells
.end() )
2172 (*aCellIter
)->setPropertyValue(C2U(SW_PROP_NAME_STR(UNO_NAME_ROW_SPAN
)), uno::makeAny( nCellCount
));
2185 catch( const lang::WrappedTargetException
& rWrapped
)
2189 catch ( const lang::IndexOutOfBoundsException
& rBounds
)
2196 /******************************************************************
2198 ******************************************************************/
2199 SwXBodyText::SwXBodyText(SwDoc
* _pDoc
) :
2200 SwXText(_pDoc
, CURSOR_BODY
)
2204 /*-- 10.12.98 11:17:27---------------------------------------------------
2206 -----------------------------------------------------------------------*/
2207 SwXBodyText::~SwXBodyText()
2211 /* -----------------------------06.04.00 16:33--------------------------------
2213 ---------------------------------------------------------------------------*/
2214 OUString
SwXBodyText::getImplementationName(void) throw( uno::RuntimeException
)
2216 return C2U("SwXBodyText");
2218 /* -----------------------------06.04.00 16:33--------------------------------
2220 ---------------------------------------------------------------------------*/
2221 BOOL
SwXBodyText::supportsService(const OUString
& rServiceName
) throw( uno::RuntimeException
)
2223 return C2U("com.sun.star.text.Text") == rServiceName
;
2225 /* -----------------------------06.04.00 16:33--------------------------------
2227 ---------------------------------------------------------------------------*/
2228 uno::Sequence
< OUString
> SwXBodyText::getSupportedServiceNames(void) throw( uno::RuntimeException
)
2230 uno::Sequence
< OUString
> aRet(1);
2231 OUString
* pArray
= aRet
.getArray();
2232 pArray
[0] = C2U("com.sun.star.text.Text");
2235 /*-- 10.12.98 11:17:27---------------------------------------------------
2237 -----------------------------------------------------------------------*/
2238 uno::Any
SwXBodyText::queryAggregation(
2239 const uno::Type
& rType
)
2240 throw(uno::RuntimeException
)
2243 const uno::Type
& rXEnumerationAccessType
= ::getCppuType((uno::Reference
< container::XEnumerationAccess
>*)0);
2244 const uno::Type
& rXElementAccessType
= ::getCppuType((uno::Reference
< container::XElementAccess
>*)0);
2245 const uno::Type
& rXServiceInfoType
= ::getCppuType((uno::Reference
< lang::XServiceInfo
>*)0);
2247 if(rType
== rXEnumerationAccessType
)
2249 uno::Reference
<container::XEnumerationAccess
> xRet
= this;
2250 aRet
.setValue(&xRet
, rXEnumerationAccessType
);
2252 else if(rType
== rXElementAccessType
)
2254 uno::Reference
<container::XElementAccess
> xRet
= this;
2255 aRet
.setValue(&xRet
, rXElementAccessType
);
2257 else if(rType
== rXServiceInfoType
)
2259 uno::Reference
<lang::XServiceInfo
> xRet
= this;
2260 aRet
.setValue(&xRet
, rXServiceInfoType
);
2264 aRet
= SwXText::queryInterface( rType
);
2266 if(aRet
.getValueType() == ::getCppuVoidType())
2267 aRet
= OWeakAggObject::queryAggregation( rType
);
2271 /*-- 10.12.98 11:17:28---------------------------------------------------
2273 -----------------------------------------------------------------------*/
2274 uno::Sequence
< uno::Type
> SwXBodyText::getTypes( ) throw(uno::RuntimeException
)
2276 uno::Sequence
< uno::Type
> aTypes
= SwXBodyTextBaseClass::getTypes();
2277 uno::Sequence
< uno::Type
> aTextTypes
= SwXText::getTypes();
2278 long nIndex
= aTypes
.getLength();
2279 aTypes
.realloc(aTypes
.getLength() + aTextTypes
.getLength());
2280 uno::Type
* pTypes
= aTypes
.getArray();
2281 const uno::Type
* pTextTypes
= aTextTypes
.getConstArray();
2282 for(int i
= 0; i
< aTextTypes
.getLength(); i
++)
2283 pTypes
[nIndex
++] = pTextTypes
[i
];
2286 /* -----------------------------21.03.00 15:39--------------------------------
2288 ---------------------------------------------------------------------------*/
2289 uno::Sequence
< sal_Int8
> SwXBodyText::getImplementationId( ) throw(uno::RuntimeException
)
2291 vos::OGuard
aGuard(Application::GetSolarMutex());
2292 static uno::Sequence
< sal_Int8
> aId( 16 );
2293 static sal_Bool bInit
= sal_False
;
2296 rtl_createUuid( (sal_uInt8
*)(aId
.getArray() ), 0, sal_True
);
2301 /*-- 10.12.98 11:17:28---------------------------------------------------
2303 -----------------------------------------------------------------------*/
2305 SwXBodyText::queryInterface( const uno::Type
& rType
)
2306 throw(uno::RuntimeException
)
2308 uno::Any aRet
= SwXText::queryInterface( rType
);
2309 if(aRet
.getValueType() == ::getCppuVoidType())
2310 aRet
= SwXBodyTextBaseClass::queryInterface( rType
);
2313 /* -----------------------------05.01.00 11:07--------------------------------
2315 ---------------------------------------------------------------------------*/
2316 uno::Reference
< text::XTextCursor
> SwXBodyText::CreateTextCursor(sal_Bool bIgnoreTables
)
2318 uno::Reference
< text::XTextCursor
> xRet
;
2321 SwNode
& rNode
= GetDoc()->GetNodes().GetEndOfContent();
2322 //the cursor has to skip tables contained in this text
2324 aPam
.Move( fnMoveBackward
, fnGoDoc
);
2327 SwTableNode
* pTblNode
= aPam
.GetNode()->FindTableNode();
2328 SwCntntNode
* pCont
= 0;
2331 aPam
.GetPoint()->nNode
= *pTblNode
->EndOfSectionNode();
2332 pCont
= GetDoc()->GetNodes().GoNext(&aPam
.GetPoint()->nNode
);
2333 pTblNode
= pCont
->FindTableNode();
2336 aPam
.GetPoint()->nContent
.Assign(pCont
, 0);
2338 xRet
= (text::XWordCursor
*)new SwXTextCursor(this, *aPam
.GetPoint(), CURSOR_BODY
, GetDoc());
2342 /*-- 10.12.98 11:17:29---------------------------------------------------
2344 -----------------------------------------------------------------------*/
2345 uno::Reference
< text::XTextCursor
> SwXBodyText::createTextCursor(void) throw( uno::RuntimeException
)
2347 vos::OGuard
aGuard(Application::GetSolarMutex());
2348 uno::Reference
< text::XTextCursor
> aRef
= CreateTextCursor(sal_False
);
2351 uno::RuntimeException aRuntime
;
2352 aRuntime
.Message
= C2U(cInvalidObject
);
2357 /*-- 10.12.98 11:17:29---------------------------------------------------
2359 -----------------------------------------------------------------------*/
2360 uno::Reference
< text::XTextCursor
> SwXBodyText::createTextCursorByRange(
2361 const uno::Reference
< text::XTextRange
> & aTextPosition
) throw( uno::RuntimeException
)
2363 vos::OGuard
aGuard(Application::GetSolarMutex());
2364 uno::Reference
< text::XTextCursor
> aRef
;
2367 uno::RuntimeException aRuntime
;
2368 aRuntime
.Message
= C2U(cInvalidObject
);
2371 SwUnoInternalPaM
aPam(*GetDoc());
2372 if(SwXTextRange::XTextRangeToSwPaM(aPam
, aTextPosition
))
2374 SwNode
& rNode
= GetDoc()->GetNodes().GetEndOfContent();
2376 SwStartNode
* p1
= aPam
.GetNode()->StartOfSectionNode();
2377 //document starts with a section?
2378 while(p1
->IsSectionNode())
2380 p1
= p1
->StartOfSectionNode();
2382 SwStartNode
* p2
= rNode
.StartOfSectionNode();
2385 aRef
= (text::XWordCursor
*)new SwXTextCursor(this , *aPam
.GetPoint(), CURSOR_BODY
, GetDoc(), aPam
.GetMark());
2388 throw uno::RuntimeException();
2391 /*-- 10.12.98 11:17:30---------------------------------------------------
2393 -----------------------------------------------------------------------*/
2394 uno::Reference
< container::XEnumeration
> SwXBodyText::createEnumeration(void)
2395 throw( uno::RuntimeException
)
2397 vos::OGuard
aGuard(Application::GetSolarMutex());
2398 uno::Reference
< container::XEnumeration
> aRef
;
2401 SwNode
& rNode
= GetDoc()->GetNodes().GetEndOfContent();
2402 SwPosition
aPos(rNode
);
2403 SwUnoCrsr
* pUnoCrsr
= GetDoc()->CreateUnoCrsr(aPos
, sal_False
);
2404 pUnoCrsr
->Move( fnMoveBackward
, fnGoDoc
);
2405 aRef
= new SwXParagraphEnumeration(this, pUnoCrsr
, CURSOR_BODY
);
2409 uno::RuntimeException aRuntime
;
2410 aRuntime
.Message
= C2U(cInvalidObject
);
2416 /* -----------------18.12.98 13:36-------------------
2418 * --------------------------------------------------*/
2419 uno::Type
SwXBodyText::getElementType(void) throw( uno::RuntimeException
)
2421 return ::getCppuType((uno::Reference
<text::XTextRange
>*)0);
2423 /* -----------------18.12.98 13:36-------------------
2425 * --------------------------------------------------*/
2426 sal_Bool
SwXBodyText::hasElements(void) throw( uno::RuntimeException
)
2428 vos::OGuard
aGuard(Application::GetSolarMutex());
2433 uno::RuntimeException aRuntime
;
2434 aRuntime
.Message
= C2U(cInvalidObject
);
2438 /******************************************************************
2440 ******************************************************************/
2441 TYPEINIT1(SwXHeadFootText
, SwClient
);
2442 /* -----------------------------06.04.00 16:40--------------------------------
2444 ---------------------------------------------------------------------------*/
2445 OUString
SwXHeadFootText::getImplementationName(void) throw( uno::RuntimeException
)
2447 return C2U("SwXHeadFootText");
2449 /* -----------------------------06.04.00 16:40--------------------------------
2451 ---------------------------------------------------------------------------*/
2452 BOOL
SwXHeadFootText::supportsService(const OUString
& rServiceName
) throw( uno::RuntimeException
)
2454 return C2U("com.sun.star.text.Text") == rServiceName
;
2456 /* -----------------------------06.04.00 16:40--------------------------------
2458 ---------------------------------------------------------------------------*/
2459 uno::Sequence
< OUString
> SwXHeadFootText::getSupportedServiceNames(void) throw( uno::RuntimeException
)
2461 uno::Sequence
< OUString
> aRet(1);
2462 OUString
* pArray
= aRet
.getArray();
2463 pArray
[0] = C2U("com.sun.star.text.Text");
2466 /*-- 11.12.98 10:14:48---------------------------------------------------
2468 -----------------------------------------------------------------------*/
2469 SwXHeadFootText::SwXHeadFootText(SwFrmFmt
& rHeadFootFmt
, BOOL bHeader
) :
2470 SwXText(rHeadFootFmt
.GetDoc(), bHeader
? CURSOR_HEADER
: CURSOR_FOOTER
),
2471 SwClient(&rHeadFootFmt
),
2476 /*-- 11.12.98 10:14:48---------------------------------------------------
2478 -----------------------------------------------------------------------*/
2479 SwXHeadFootText::~SwXHeadFootText()
2483 /*-- 11.12.98 10:14:49---------------------------------------------------
2485 -----------------------------------------------------------------------*/
2486 const SwStartNode
*SwXHeadFootText::GetStartNode() const
2488 const SwStartNode
*pSttNd
= 0;
2489 SwFrmFmt
* pHeadFootFmt
= GetFmt();
2492 const SwFmtCntnt
& rFlyCntnt
= pHeadFootFmt
->GetCntnt();
2493 if( rFlyCntnt
.GetCntntIdx() )
2494 pSttNd
= rFlyCntnt
.GetCntntIdx()->GetNode().GetStartNode();
2499 uno::Reference
< text::XTextCursor
> SwXHeadFootText::createCursor() throw(uno::RuntimeException
)
2501 return createTextCursor();
2503 /* -----------------------------21.03.00 15:39--------------------------------
2505 ---------------------------------------------------------------------------*/
2506 uno::Sequence
< uno::Type
> SwXHeadFootText::getTypes( ) throw(uno::RuntimeException
)
2508 uno::Sequence
< uno::Type
> aHFTypes
= SwXHeadFootTextBaseClass::getTypes();
2509 uno::Sequence
< uno::Type
> aTextTypes
= SwXText::getTypes();
2511 long nIndex
= aHFTypes
.getLength();
2513 aHFTypes
.getLength() +
2514 aTextTypes
.getLength());
2516 uno::Type
* pHFTypes
= aHFTypes
.getArray();
2517 const uno::Type
* pTextTypes
= aTextTypes
.getConstArray();
2518 for(long nPos
= 0; nPos
< aTextTypes
.getLength(); nPos
++)
2519 pHFTypes
[nIndex
++] = pTextTypes
[nPos
];
2524 /* -----------------------------21.03.00 15:39--------------------------------
2526 ---------------------------------------------------------------------------*/
2527 uno::Sequence
< sal_Int8
> SwXHeadFootText::getImplementationId( ) throw(uno::RuntimeException
)
2529 vos::OGuard
aGuard(Application::GetSolarMutex());
2530 static uno::Sequence
< sal_Int8
> aId( 16 );
2531 static sal_Bool bInit
= sal_False
;
2534 rtl_createUuid( (sal_uInt8
*)(aId
.getArray() ), 0, sal_True
);
2539 /* -----------------------------21.03.00 15:46--------------------------------
2541 ---------------------------------------------------------------------------*/
2542 uno::Any
SwXHeadFootText::queryInterface( const uno::Type
& aType
) throw(uno::RuntimeException
)
2544 uno::Any aRet
= SwXHeadFootTextBaseClass::queryInterface(aType
);
2545 if(aRet
.getValueType() == ::getCppuVoidType() )
2546 aRet
= SwXText::queryInterface(aType
);
2550 /*-- 11.12.98 10:14:50---------------------------------------------------
2552 -----------------------------------------------------------------------*/
2553 uno::Reference
< text::XTextCursor
> SwXHeadFootText::createTextCursor(void) throw( uno::RuntimeException
)
2555 vos::OGuard
aGuard(Application::GetSolarMutex());
2556 uno::Reference
< text::XTextCursor
> xRet
;
2557 SwFrmFmt
* pHeadFootFmt
= GetFmt();
2560 const SwFmtCntnt
& rFlyCntnt
= pHeadFootFmt
->GetCntnt();
2561 const SwNode
& rNode
= rFlyCntnt
.GetCntntIdx()->GetNode();
2562 SwPosition
aPos(rNode
);
2563 SwXTextCursor
* pCrsr
= new SwXTextCursor(this, aPos
, bIsHeader
? CURSOR_HEADER
: CURSOR_FOOTER
, GetDoc());
2564 SwUnoCrsr
* pUnoCrsr
= pCrsr
->GetCrsr();
2565 pUnoCrsr
->Move(fnMoveForward
, fnGoNode
);
2567 //save current start node to be able to check if there is content after the table -
2568 //otherwise the cursor would be in the body text!
2570 const SwStartNode
* pOwnStartNode
= rNode
.FindSttNodeByType(
2571 bIsHeader
? SwHeaderStartNode
: SwFooterStartNode
);
2572 //steht hier eine Tabelle?
2573 SwTableNode
* pTblNode
= pUnoCrsr
->GetNode()->FindTableNode();
2574 SwCntntNode
* pCont
= 0;
2577 pUnoCrsr
->GetPoint()->nNode
= *pTblNode
->EndOfSectionNode();
2578 pCont
= GetDoc()->GetNodes().GoNext(&pUnoCrsr
->GetPoint()->nNode
);
2579 pTblNode
= pCont
->FindTableNode();
2582 pUnoCrsr
->GetPoint()->nContent
.Assign(pCont
, 0);
2583 const SwStartNode
* pNewStartNode
= pUnoCrsr
->GetNode()->FindSttNodeByType(
2584 bIsHeader
? SwHeaderStartNode
: SwFooterStartNode
);
2585 if(!pNewStartNode
|| pNewStartNode
!= pOwnStartNode
)
2588 uno::RuntimeException aExcept
;
2589 aExcept
.Message
= S2U("no text available");
2592 xRet
= (text::XWordCursor
*)pCrsr
;
2596 uno::RuntimeException aRuntime
;
2597 aRuntime
.Message
= C2U(cInvalidObject
);
2602 /*-- 11.12.98 10:14:50---------------------------------------------------
2604 -----------------------------------------------------------------------*/
2605 uno::Reference
< text::XTextCursor
> SwXHeadFootText::createTextCursorByRange(
2606 const uno::Reference
< text::XTextRange
> & aTextPosition
) throw( uno::RuntimeException
)
2608 vos::OGuard
aGuard(Application::GetSolarMutex());
2609 uno::Reference
< text::XTextCursor
> xRet
;
2610 SwFrmFmt
* pHeadFootFmt
= GetFmt();
2611 SwUnoInternalPaM
aPam(*GetDoc());
2612 if(pHeadFootFmt
&& SwXTextRange::XTextRangeToSwPaM(aPam
, aTextPosition
))
2614 SwNode
& rNode
= pHeadFootFmt
->GetCntnt().GetCntntIdx()->GetNode();
2615 SwPosition
aPos(rNode
);
2617 aHFPam
.Move(fnMoveForward
, fnGoNode
);
2618 SwStartNode
* pOwnStartNode
= aHFPam
.GetNode()->FindSttNodeByType(
2619 bIsHeader
? SwHeaderStartNode
: SwFooterStartNode
);
2620 SwStartNode
* p1
= aPam
.GetNode()->FindSttNodeByType(
2621 bIsHeader
? SwHeaderStartNode
: SwFooterStartNode
);
2622 if(p1
== pOwnStartNode
)
2623 xRet
= (text::XWordCursor
*)new SwXTextCursor(this, *aPam
.GetPoint(),
2624 bIsHeader
? CURSOR_HEADER
: CURSOR_FOOTER
, GetDoc(), aPam
.GetMark());
2628 /* -----------------19.03.99 15:44-------------------
2630 * --------------------------------------------------*/
2631 uno::Reference
< container::XEnumeration
> SwXHeadFootText::createEnumeration(void)
2632 throw( uno::RuntimeException
)
2634 vos::OGuard
aGuard(Application::GetSolarMutex());
2635 uno::Reference
< container::XEnumeration
> aRef
;
2636 //wenn this ungueltig ist, dann kommt die uno::Exception aus createTextCursor()
2637 SwFrmFmt
* pHeadFootFmt
= GetFmt();
2640 const SwFmtCntnt
& rFlyCntnt
= pHeadFootFmt
->GetCntnt();
2641 const SwNode
& rNode
= rFlyCntnt
.GetCntntIdx()->GetNode();
2642 SwPosition
aPos(rNode
);
2643 SwUnoCrsr
* pUnoCrsr
= GetDoc()->CreateUnoCrsr(aPos
, sal_False
);
2644 pUnoCrsr
->Move(fnMoveForward
, fnGoNode
);
2645 aRef
= new SwXParagraphEnumeration(this, pUnoCrsr
, bIsHeader
? CURSOR_HEADER
: CURSOR_FOOTER
);
2649 uno::RuntimeException aRuntime
;
2650 aRuntime
.Message
= C2U(cInvalidObject
);
2656 /* -----------------19.03.99 15:50-------------------
2658 * --------------------------------------------------*/
2659 uno::Type
SwXHeadFootText::getElementType(void) throw( uno::RuntimeException
)
2661 return ::getCppuType((uno::Reference
<text::XTextRange
>*)0);
2663 /* -----------------19.03.99 15:50-------------------
2665 * --------------------------------------------------*/
2666 sal_Bool
SwXHeadFootText::hasElements(void) throw( uno::RuntimeException
)
2671 /*-- 11.12.98 10:14:51---------------------------------------------------
2673 -----------------------------------------------------------------------*/
2674 void SwXHeadFootText::Modify( SfxPoolItem
*pOld
, SfxPoolItem
*pNew
)
2676 ClientModify( this, pOld
, pNew
);