xref: /AOO41X/main/sw/source/core/unocore/unoobj.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #include <com/sun/star/table/TableSortField.hpp>
32 
33 #include <osl/endian.h>
34 #include <rtl/ustrbuf.hxx>
35 #include <unotools/collatorwrapper.hxx>
36 #include <swtypes.hxx>
37 #include <hintids.hxx>
38 #include <cmdid.h>
39 #include <hints.hxx>
40 #include <IMark.hxx>
41 #include <frmfmt.hxx>
42 #include <doc.hxx>
43 #include <IDocumentUndoRedo.hxx>
44 #include <istyleaccess.hxx>
45 #include <ndtxt.hxx>
46 #include <ndnotxt.hxx>
47 #include <unocrsr.hxx>
48 #include <unocrsrhelper.hxx>
49 #include <swundo.hxx>
50 #include <rootfrm.hxx>
51 #include <flyfrm.hxx>
52 #include <ftnidx.hxx>
53 #include <sfx2/linkmgr.hxx>
54 #include <docary.hxx>
55 #include <paratr.hxx>
56 #include <tools/urlobj.hxx>
57 #include <pam.hxx>
58 #include <tools/cachestr.hxx>
59 #include <shellio.hxx>
60 #include <swerror.h>
61 #include <swtblfmt.hxx>
62 #include <fmtruby.hxx>
63 #include <docsh.hxx>
64 #include <docstyle.hxx>
65 #include <charfmt.hxx>
66 #include <txtfld.hxx>
67 #include <fmtfld.hxx>
68 #include <fmtpdsc.hxx>
69 #include <pagedesc.hxx>
70 #include <poolfmt.hrc>
71 #include <poolfmt.hxx>
72 #include <edimp.hxx>
73 #include <fchrfmt.hxx>
74 #include <fmtautofmt.hxx>
75 #include <cntfrm.hxx>
76 #include <pagefrm.hxx>
77 #include <doctxm.hxx>
78 #include <sfx2/docfilt.hxx>
79 #include <sfx2/docfile.hxx>
80 #include <sfx2/fcontnr.hxx>
81 #include <fmtrfmrk.hxx>
82 #include <txtrfmrk.hxx>
83 #include <unotextrange.hxx>
84 #include <unotextcursor.hxx>
85 #include <unomap.hxx>
86 #include <unosett.hxx>
87 #include <unoprnms.hxx>
88 #include <unotbl.hxx>
89 #include <unodraw.hxx>
90 #include <unocoll.hxx>
91 #include <unostyle.hxx>
92 #include <unofield.hxx>
93 #include <unometa.hxx>
94 #include <fmtanchr.hxx>
95 #include <editeng/flstitem.hxx>
96 #include <svtools/ctrltool.hxx>
97 #include <flypos.hxx>
98 #include <txtftn.hxx>
99 #include <fmtftn.hxx>
100 #include <com/sun/star/text/WrapTextMode.hpp>
101 #include <com/sun/star/text/TextContentAnchorType.hpp>
102 #include <com/sun/star/style/PageStyleLayout.hpp>
103 #include <com/sun/star/text/XTextDocument.hpp>
104 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
105 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
106 #include <unoidx.hxx>
107 #include <unoframe.hxx>
108 #include <fmthdft.hxx>
109 #include <vos/mutex.hxx>
110 #include <vcl/svapp.hxx>
111 #include <fmtflcnt.hxx>
112 #define _SVSTDARR_USHORTS
113 #define _SVSTDARR_USHORTSSORT
114 #include <svl/svstdarr.hxx>
115 #include <editeng/brshitem.hxx>
116 #include <editeng/unolingu.hxx>
117 #include <fmtclds.hxx>
118 #include <dcontact.hxx>
119 #include <SwStyleNameMapper.hxx>
120 #include <crsskip.hxx>
121 #include <sortopt.hxx>
122 #include <com/sun/star/beans/PropertyAttribute.hpp>
123 #include <memory>
124 #include <unoparaframeenum.hxx>
125 #include <unoparagraph.hxx>
126 
127 
128 using namespace ::com::sun::star;
129 using ::rtl::OUString;
130 using ::rtl::OUStringBuffer;
131 
132 
133 /****************************************************************************
134 	static methods
135 ****************************************************************************/
136 uno::Sequence< sal_Int8 >  CreateUnoTunnelId()
137 {
138 	static osl::Mutex aCreateMutex;
139 	osl::Guard<osl::Mutex> aGuard( aCreateMutex );
140 	uno::Sequence< sal_Int8 > aSeq( 16 );
141     rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0,	sal_True );
142 	return aSeq;
143 }
144 /****************************************************************************
145 	Hilfsklassen
146 ****************************************************************************/
147 
148 /* -----------------13.05.98 12:15-------------------
149  *
150  * --------------------------------------------------*/
151 SwUnoInternalPaM::SwUnoInternalPaM(SwDoc& rDoc) :
152 	SwPaM(rDoc.GetNodes())
153 {
154 }
155 SwUnoInternalPaM::~SwUnoInternalPaM()
156 {
157 	while( GetNext() != this)
158 	{
159 		delete GetNext();
160 	}
161 }
162 
163 SwUnoInternalPaM&	SwUnoInternalPaM::operator=(const SwPaM& rPaM)
164 {
165 	const SwPaM* pTmp = &rPaM;
166 	*GetPoint() = *rPaM.GetPoint();
167 	if(rPaM.HasMark())
168 	{
169 		SetMark();
170 		*GetMark() = *rPaM.GetMark();
171 	}
172 	else
173 		DeleteMark();
174 	while(&rPaM != (pTmp = (const SwPaM*)pTmp->GetNext()))
175 	{
176 		if(pTmp->HasMark())
177 			new SwPaM(*pTmp->GetMark(), *pTmp->GetPoint(), this);
178 		else
179 			new SwPaM(*pTmp->GetPoint(), this);
180 	}
181 	return *this;
182 }
183 
184 /*-----------------09.03.98 08:29-------------------
185 
186 --------------------------------------------------*/
187 void SwUnoCursorHelper::SelectPam(SwPaM & rPam, const bool bExpand)
188 {
189     if (bExpand)
190     {
191         if (!rPam.HasMark())
192         {
193             rPam.SetMark();
194         }
195     }
196     else if (rPam.HasMark())
197     {
198         rPam.DeleteMark();
199     }
200 }
201 
202 /* -----------------20.05.98 14:59-------------------
203  *
204  * --------------------------------------------------*/
205 void SwUnoCursorHelper::GetTextFromPam(SwPaM & rPam, OUString & rBuffer)
206 {
207     if (!rPam.HasMark())
208     {
209 		return;
210     }
211 	SvCacheStream aStream( 20480 );
212 #ifdef OSL_BIGENDIAN
213     aStream.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
214 #else
215     aStream.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
216 #endif
217     WriterRef xWrt;
218     // TODO/MBA: looks like a BaseURL doesn't make sense here
219     SwReaderWriter::GetWriter( C2S(FILTER_TEXT_DLG), String(), xWrt );
220 	if( xWrt.Is() )
221 	{
222         SwWriter aWriter( aStream, rPam );
223 		xWrt->bASCII_NoLastLineEnd = sal_True;
224 		xWrt->bExportPargraphNumbering = sal_False;
225 		SwAsciiOptions aOpt = xWrt->GetAsciiOptions();
226 		aOpt.SetCharSet( RTL_TEXTENCODING_UNICODE );
227 		xWrt->SetAsciiOptions( aOpt );
228 		xWrt->bUCS2_WithStartChar = sal_False;
229         // --> FME #i68522#
230         const sal_Bool bOldShowProgress = xWrt->bShowProgress;
231         xWrt->bShowProgress = sal_False;
232         // <--
233 
234 		long lLen;
235 		if( !IsError( aWriter.Write( xWrt ) ) &&
236 			0x7ffffff > (( lLen  = aStream.GetSize() )
237 									/ sizeof( sal_Unicode )) + 1 )
238 		{
239 			aStream << (sal_Unicode)'\0';
240 
241             long lUniLen = (lLen / sizeof( sal_Unicode ));
242 			::rtl::OUStringBuffer aStrBuffer( lUniLen );
243 			aStream.Seek( 0 );
244 			aStream.ResetError();
245 			while(lUniLen)
246 			{
247 				String sBuf;
248 				sal_Int32 nLocalLen = 0;
249 				if( lUniLen >= STRING_MAXLEN )
250                 {
251 					nLocalLen =  STRING_MAXLEN - 1;
252                 }
253                 else
254                 {
255 					nLocalLen = lUniLen;
256                 }
257                 sal_Unicode *const pStrBuf =
258                     sBuf.AllocBuffer( xub_StrLen( nLocalLen + 1));
259 				aStream.Read( pStrBuf, 2 * nLocalLen );
260 				pStrBuf[ nLocalLen ] = '\0';
261 				aStrBuffer.append( pStrBuf, nLocalLen );
262 				lUniLen -= nLocalLen;
263 			}
264 			rBuffer = aStrBuffer.makeStringAndClear();
265 		}
266         xWrt->bShowProgress = bOldShowProgress;
267 	}
268 }
269 
270 /* -----------------06.07.98 07:33-------------------
271  *
272  * --------------------------------------------------*/
273 static void
274 lcl_setCharStyle(SwDoc *const pDoc, const uno::Any & rValue, SfxItemSet & rSet)
275 throw (lang::IllegalArgumentException)
276 {
277     SwDocShell *const pDocSh = pDoc->GetDocShell();
278 	if(pDocSh)
279 	{
280 		OUString uStyle;
281         if (!(rValue >>= uStyle))
282         {
283             throw lang::IllegalArgumentException();
284         }
285 		String sStyle;
286         SwStyleNameMapper::FillUIName(uStyle, sStyle,
287                 nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True);
288         SwDocStyleSheet *const pStyle = static_cast<SwDocStyleSheet*>(
289             pDocSh->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_CHAR));
290         if (!pStyle)
291         {
292             throw lang::IllegalArgumentException();
293         }
294         const SwFmtCharFmt aFmt(pStyle->GetCharFmt());
295         rSet.Put(aFmt);
296 	}
297 };
298 /* -----------------08.06.06 10:43-------------------
299  *
300  * --------------------------------------------------*/
301 static void
302 lcl_setAutoStyle(IStyleAccess & rStyleAccess, const uno::Any & rValue,
303         SfxItemSet & rSet, const bool bPara)
304 throw (lang::IllegalArgumentException)
305 {
306     OUString uStyle;
307     if (!(rValue >>= uStyle))
308     {
309          throw lang::IllegalArgumentException();
310     }
311     StylePool::SfxItemSet_Pointer_t pStyle = bPara ?
312         rStyleAccess.getByName(uStyle, IStyleAccess::AUTO_STYLE_PARA ):
313         rStyleAccess.getByName(uStyle, IStyleAccess::AUTO_STYLE_CHAR );
314     if(pStyle.get())
315     {
316         SwFmtAutoFmt aFmt( (bPara)
317             ? sal::static_int_cast< sal_uInt16 >(RES_AUTO_STYLE)
318             : sal::static_int_cast< sal_uInt16 >(RES_TXTATR_AUTOFMT) );
319         aFmt.SetStyleHandle( pStyle );
320         rSet.Put(aFmt);
321     }
322     else
323     {
324          throw lang::IllegalArgumentException();
325     }
326 };
327 /* -----------------30.06.98 08:46-------------------
328  *
329  * --------------------------------------------------*/
330 void
331 SwUnoCursorHelper::SetTxtFmtColl(const uno::Any & rAny, SwPaM & rPaM)
332 throw (lang::IllegalArgumentException)
333 {
334     SwDoc *const pDoc = rPaM.GetDoc();
335     SwDocShell *const pDocSh = pDoc->GetDocShell();
336 	if(!pDocSh)
337 		return;
338 	OUString uStyle;
339 	rAny >>= uStyle;
340 	String sStyle;
341     SwStyleNameMapper::FillUIName(uStyle, sStyle,
342             nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True );
343     SwDocStyleSheet *const pStyle = static_cast<SwDocStyleSheet*>(
344             pDocSh->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_PARA));
345     if (!pStyle)
346     {
347         throw lang::IllegalArgumentException();
348     }
349 
350     SwTxtFmtColl *const pLocal = pStyle->GetCollection();
351     UnoActionContext aAction(pDoc);
352     pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
353     SwPaM *pTmpCrsr = &rPaM;
354     do {
355         pDoc->SetTxtFmtColl(*pTmpCrsr, pLocal);
356         pTmpCrsr = static_cast<SwPaM*>(pTmpCrsr->GetNext());
357     } while ( pTmpCrsr != &rPaM );
358     pDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
359 }
360 
361 /* -----------------06.07.98 07:38-------------------
362  *
363  * --------------------------------------------------*/
364 bool
365 SwUnoCursorHelper::SetPageDesc(
366         const uno::Any& rValue, SwDoc & rDoc, SfxItemSet & rSet)
367 {
368     OUString uDescName;
369     if (!(rValue >>= uDescName))
370     {
371         return false;
372     }
373     ::std::auto_ptr<SwFmtPageDesc> pNewDesc;
374 	const SfxPoolItem* pItem;
375 	if(SFX_ITEM_SET == rSet.GetItemState( RES_PAGEDESC, sal_True, &pItem ) )
376     {
377         pNewDesc.reset(new SwFmtPageDesc(
378                     *static_cast<const SwFmtPageDesc*>(pItem)));
379     }
380     if (!pNewDesc.get())
381     {
382         pNewDesc.reset(new SwFmtPageDesc());
383     }
384 	String sDescName;
385     SwStyleNameMapper::FillUIName(uDescName, sDescName,
386             nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, sal_True);
387     if (!pNewDesc->GetPageDesc() ||
388         (pNewDesc->GetPageDesc()->GetName() != sDescName))
389 	{
390 		sal_Bool bPut = sal_False;
391 		if(sDescName.Len())
392 		{
393             SwPageDesc *const pPageDesc =
394                 ::GetPageDescByName_Impl(rDoc, sDescName);
395             if (!pPageDesc)
396             {
397                 throw lang::IllegalArgumentException();
398             }
399             pNewDesc.get()->RegisterToPageDesc( *pPageDesc );
400             bPut = sal_True;
401 		}
402 		if(!bPut)
403 		{
404 			rSet.ClearItem(RES_BREAK);
405 			rSet.Put(SwFmtPageDesc());
406 		}
407 		else
408         {
409 			rSet.Put(*pNewDesc);
410         }
411 	}
412     return true;
413 }
414 
415 /* -----------------30.06.98 10:29-------------------
416  *
417  * --------------------------------------------------*/
418 static void
419 lcl_SetNodeNumStart(SwPaM & rCrsr, uno::Any const& rValue)
420 {
421 	sal_Int16 nTmp = 1;
422 	rValue >>= nTmp;
423 	sal_uInt16 nStt = (nTmp < 0 ? USHRT_MAX : (sal_uInt16)nTmp);
424 	SwDoc* pDoc = rCrsr.GetDoc();
425 	UnoActionContext aAction(pDoc);
426 
427 	if( rCrsr.GetNext() != &rCrsr )			// Mehrfachselektion ?
428 	{
429         pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
430 		SwPamRanges aRangeArr( rCrsr );
431 		SwPaM aPam( *rCrsr.GetPoint() );
432 		for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
433 		{
434 		  pDoc->SetNumRuleStart(*aRangeArr.SetPam( n, aPam ).GetPoint());
435 		  pDoc->SetNodeNumStart(*aRangeArr.SetPam( n, aPam ).GetPoint(),
436 					nStt );
437         }
438         pDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
439     }
440     else
441     {
442         pDoc->SetNumRuleStart( *rCrsr.GetPoint());
443 		pDoc->SetNodeNumStart( *rCrsr.GetPoint(), nStt );
444     }
445 }
446 
447 static bool
448 lcl_setCharFmtSequence(SwPaM & rPam, uno::Any const& rValue)
449 {
450     uno::Sequence<OUString> aCharStyles;
451     if (!(rValue >>= aCharStyles))
452     {
453         return false;
454     }
455 
456     for (sal_Int32 nStyle = 0; nStyle < aCharStyles.getLength(); nStyle++)
457     {
458         uno::Any aStyle;
459         rPam.GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_START, NULL);
460         aStyle <<= aCharStyles.getConstArray()[nStyle];
461         // create a local set and apply each format directly
462         SfxItemSet aSet(rPam.GetDoc()->GetAttrPool(),
463                 RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT);
464         lcl_setCharStyle(rPam.GetDoc(), aStyle, aSet);
465         // the first style should replace the current attributes,
466         // all other have to be added
467         SwUnoCursorHelper::SetCrsrAttr(rPam, aSet, (nStyle)
468                 ? nsSetAttrMode::SETATTR_DONTREPLACE
469                 : nsSetAttrMode::SETATTR_DEFAULT);
470         rPam.GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_START, NULL);
471     }
472     return true;
473 }
474 
475 static void
476 lcl_setDropcapCharStyle(SwPaM & rPam, SfxItemSet & rItemSet,
477         uno::Any const& rValue)
478 {
479     OUString uStyle;
480     if (!(rValue >>= uStyle))
481     {
482         throw lang::IllegalArgumentException();
483     }
484     String sStyle;
485     SwStyleNameMapper::FillUIName(uStyle, sStyle,
486             nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True);
487     SwDoc *const pDoc = rPam.GetDoc();
488     //default character style must not be set as default format
489     SwDocStyleSheet *const pStyle = static_cast<SwDocStyleSheet*>(
490             pDoc->GetDocShell()
491             ->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_CHAR));
492     if (!pStyle ||
493         (static_cast<SwDocStyleSheet*>(pStyle)->GetCharFmt() ==
494              pDoc->GetDfltCharFmt()))
495     {
496         throw lang::IllegalArgumentException();
497     }
498     ::std::auto_ptr<SwFmtDrop> pDrop;
499     SfxPoolItem const* pItem(0);
500     if (SFX_ITEM_SET ==
501             rItemSet.GetItemState(RES_PARATR_DROP, sal_True, &pItem))
502     {
503         pDrop.reset(new SwFmtDrop(*static_cast<const SwFmtDrop*>(pItem)));
504     }
505     if (!pDrop.get())
506     {
507         pDrop.reset(new SwFmtDrop);
508     }
509     const rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*pStyle));
510     pDrop->SetCharFmt(xStyle->GetCharFmt());
511     rItemSet.Put(*pDrop);
512 }
513 
514 static void
515 lcl_setRubyCharstyle(SfxItemSet & rItemSet, uno::Any const& rValue)
516 {
517     OUString sTmp;
518     if (!(rValue >>= sTmp))
519     {
520         throw lang::IllegalArgumentException();
521     }
522 
523     ::std::auto_ptr<SwFmtRuby> pRuby;
524     const SfxPoolItem* pItem;
525     if (SFX_ITEM_SET ==
526             rItemSet.GetItemState(RES_TXTATR_CJK_RUBY, sal_True, &pItem))
527     {
528         pRuby.reset(new SwFmtRuby(*static_cast<const SwFmtRuby*>(pItem)));
529     }
530     if (!pRuby.get())
531     {
532         pRuby.reset(new SwFmtRuby(aEmptyStr));
533     }
534     String sStyle;
535     SwStyleNameMapper::FillUIName(sTmp, sStyle,
536             nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
537     pRuby->SetCharFmtName(sStyle);
538     pRuby->SetCharFmtId(0);
539     if (sStyle.Len() > 0)
540     {
541         const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(
542                 sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
543         pRuby->SetCharFmtId(nId);
544     }
545     rItemSet.Put(*pRuby);
546 }
547 
548 /* -----------------17.09.98 09:44-------------------
549  *
550  * --------------------------------------------------*/
551 bool
552 SwUnoCursorHelper::SetCursorPropertyValue(
553         SfxItemPropertySimpleEntry const& rEntry, const uno::Any& rValue,
554         SwPaM & rPam, SfxItemSet & rItemSet)
555 throw (lang::IllegalArgumentException)
556 {
557     if (!(rEntry.nFlags & beans::PropertyAttribute::MAYBEVOID) &&
558         (rValue.getValueType() == ::getCppuVoidType()))
559     {
560         return false;
561     }
562     bool bRet = true;
563     switch (rEntry.nWID)
564     {
565         case RES_TXTATR_CHARFMT:
566             lcl_setCharStyle(rPam.GetDoc(), rValue, rItemSet);
567         break;
568         case RES_TXTATR_AUTOFMT:
569             lcl_setAutoStyle(rPam.GetDoc()->GetIStyleAccess(),
570                     rValue, rItemSet, false);
571         break;
572         case FN_UNO_CHARFMT_SEQUENCE:
573             lcl_setCharFmtSequence(rPam, rValue);
574         break;
575         case FN_UNO_PARA_STYLE :
576             SwUnoCursorHelper::SetTxtFmtColl(rValue, rPam);
577         break;
578         case RES_AUTO_STYLE:
579             lcl_setAutoStyle(rPam.GetDoc()->GetIStyleAccess(),
580                     rValue, rItemSet, true);
581         break;
582         case FN_UNO_PAGE_STYLE:
583             //FIXME nothing here?
584         break;
585         case FN_UNO_NUM_START_VALUE:
586             lcl_SetNodeNumStart( rPam, rValue );
587         break;
588         case FN_UNO_NUM_LEVEL:
589         // --> OD 2008-07-14 #i91601#
590         case FN_UNO_LIST_ID:
591         // <--
592         case FN_UNO_IS_NUMBER:
593         {
594             // multi selection is not considered
595             SwTxtNode *const pTxtNd = rPam.GetNode()->GetTxtNode();
596             // --> OD 2008-05-14 #refactorlists# - check on list style not needed
597 //                const SwNumRule* pRule = pTxtNd->GetNumRule();
598 //                if( FN_UNO_NUM_LEVEL == rEntry.nWID  &&  pRule != NULL )
599             if (FN_UNO_NUM_LEVEL == rEntry.nWID)
600             // <--
601             {
602                 sal_Int16 nLevel = 0;
603                 if (rValue >>= nLevel)
604                 {
605                     pTxtNd->SetAttrListLevel(nLevel);
606                 }
607             }
608             // --> OD 2008-07-14 #i91601#
609             else if (FN_UNO_LIST_ID == rEntry.nWID)
610             {
611                 ::rtl::OUString sListId;
612                 if (rValue >>= sListId)
613                 {
614                     pTxtNd->SetListId( sListId );
615                 }
616             }
617             // <--
618             else if (FN_UNO_IS_NUMBER == rEntry.nWID)
619             {
620                 sal_Bool bIsNumber(sal_False);
621                 if (rValue >>= bIsNumber)
622                 {
623                     if (!bIsNumber)
624                     {
625                         pTxtNd->SetCountedInList( false );
626                     }
627                 }
628             }
629             //PROPERTY_MAYBEVOID!
630         }
631         break;
632         case FN_NUMBER_NEWSTART:
633         {
634             sal_Bool bVal = sal_False;
635             if (!(rValue >>= bVal))
636             {
637                 throw lang::IllegalArgumentException();
638             }
639             rPam.GetDoc()->SetNumRuleStart(*rPam.GetPoint(), bVal);
640         }
641         break;
642         case FN_UNO_NUM_RULES:
643             SwUnoCursorHelper::setNumberingProperty(rValue, rPam);
644         break;
645         case RES_PARATR_DROP:
646         {
647             if (MID_DROPCAP_CHAR_STYLE_NAME == rEntry.nMemberId)
648             {
649                 lcl_setDropcapCharStyle(rPam, rItemSet, rValue);
650             }
651             else
652             {
653                 bRet = false;
654             }
655         }
656         break;
657         case RES_TXTATR_CJK_RUBY:
658         {
659             if (MID_RUBY_CHARSTYLE == rEntry.nMemberId)
660             {
661                 lcl_setRubyCharstyle(rItemSet, rValue);
662             }
663             else
664             {
665                 bRet = false;
666             }
667         }
668         break;
669         case RES_PAGEDESC:
670         {
671             if (MID_PAGEDESC_PAGEDESCNAME == rEntry.nMemberId)
672             {
673                 SwUnoCursorHelper::SetPageDesc(
674                         rValue, *rPam.GetDoc(), rItemSet);
675             }
676             else
677             {
678                 bRet = false;
679             }
680         }
681         break;
682         default:
683             bRet = false;
684     }
685     return bRet;
686 }
687 
688 /* -----------------30.06.98 08:39-------------------
689  *
690  * --------------------------------------------------*/
691 SwFmtColl *
692 SwUnoCursorHelper::GetCurTxtFmtColl(SwPaM & rPaM, const bool bConditional)
693 {
694 	static const sal_uInt16 nMaxLookup = 1000;
695 	SwFmtColl *pFmt = 0;
696 
697 //	if ( GetCrsrCnt() > nMaxLookup )
698 //		return 0;
699     bool bError = false;
700     SwPaM *pTmpCrsr = &rPaM;
701     do
702     {
703         const sal_uLong nSttNd = pTmpCrsr->Start()->nNode.GetIndex();
704         const sal_uLong nEndNd = pTmpCrsr->End()->nNode.GetIndex();
705 
706 		if( nEndNd - nSttNd >= nMaxLookup )
707 		{
708 			pFmt = 0;
709 			break;
710 		}
711 
712         const SwNodes& rNds = rPaM.GetDoc()->GetNodes();
713 		for( sal_uLong n = nSttNd; n <= nEndNd; ++n )
714 		{
715             SwTxtNode const*const pNd = rNds[ n ]->GetTxtNode();
716 			if( pNd )
717 			{
718                 SwFmtColl *const pNdFmt = (bConditional)
719                     ? pNd->GetFmtColl() : &pNd->GetAnyFmtColl();
720 				if( !pFmt )
721                 {
722 					pFmt = pNdFmt;
723                 }
724 				else if( pFmt != pNdFmt )
725 				{
726                     bError = true;
727 					break;
728 				}
729 			}
730 		}
731 
732         pTmpCrsr = static_cast<SwPaM*>(pTmpCrsr->GetNext());
733     } while ( pTmpCrsr != &rPaM );
734     return (bError) ? 0 : pFmt;
735 }
736 
737 /* -----------------26.06.98 16:20-------------------
738  * 	Hilfsfunktion fuer PageDesc
739  * --------------------------------------------------*/
740 SwPageDesc*	GetPageDescByName_Impl(SwDoc& rDoc, const String& rName)
741 {
742 	SwPageDesc* pRet = 0;
743 	sal_uInt16 nDCount = rDoc.GetPageDescCnt();
744 	sal_uInt16 i;
745 
746 	for( i = 0; i < nDCount; i++ )
747 	{
748 		SwPageDesc* pDsc = &rDoc._GetPageDesc( i );
749 		if(pDsc->GetName() == rName)
750 		{
751 			pRet = pDsc;
752 			break;
753 		}
754 	}
755 	if(!pRet)
756 	{
757         for(i = RC_POOLPAGEDESC_BEGIN; i <= STR_POOLPAGE_LANDSCAPE; ++i)
758 		{
759 			const String aFmtName(SW_RES(i));
760 			if(aFmtName == rName)
761 			{
762                 pRet = rDoc.GetPageDescFromPool( static_cast< sal_uInt16 >(
763                             RES_POOLPAGE_BEGIN + i - RC_POOLPAGEDESC_BEGIN) );
764 				break;
765 			}
766 		}
767 	}
768 
769 	return pRet;
770  }
771 
772 /******************************************************************
773  * SwXTextCursor
774  ******************************************************************/
775 
776 class SwXTextCursor::Impl
777     : public SwClient
778 {
779 
780 public:
781 
782     const SfxItemPropertySet &  m_rPropSet;
783     const enum CursorType       m_eType;
784     const uno::Reference< text::XText > m_xParentText;
785     SwEventListenerContainer    m_ListenerContainer;
786     bool                        m_bIsDisposed;
787 
788     Impl(   SwXTextCursor & rThis,
789             SwDoc & rDoc,
790             const enum CursorType eType,
791             uno::Reference<text::XText> xParent,
792             SwPosition const& rPoint, SwPosition const*const pMark)
793         : SwClient(rDoc.CreateUnoCrsr(rPoint, sal_False))
794         , m_rPropSet(*aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR))
795         , m_eType(eType)
796         , m_xParentText(xParent)
797         , m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis))
798         , m_bIsDisposed(false)
799     {
800         if (pMark)
801         {
802             GetCursor()->SetMark();
803             *GetCursor()->GetMark() = *pMark;
804         }
805     }
806 
807     ~Impl() {
808         // Impl owns the cursor; delete it here: SolarMutex is locked
809         delete GetRegisteredIn();
810     }
811 
812     SwUnoCrsr * GetCursor() {
813         return (m_bIsDisposed) ? 0 :
814             static_cast<SwUnoCrsr*>(const_cast<SwModify*>(GetRegisteredIn()));
815     }
816 
817     SwUnoCrsr & GetCursorOrThrow() {
818         SwUnoCrsr *const pUnoCursor( GetCursor() );
819         if (!pUnoCursor) {
820             throw uno::RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM(
821                         "SwXTextCursor: disposed or invalid")), 0);
822         }
823         return *pUnoCursor;
824     }
825 
826     void Invalidate() {
827         m_bIsDisposed = true;
828         m_ListenerContainer.Disposing();
829     }
830 protected:
831     // SwClient
832     virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew);
833 
834 };
835 
836 void SwXTextCursor::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
837 {
838     ClientModify(this, pOld, pNew);
839 
840     if (!GetRegisteredIn() ||
841         // if the cursor leaves its designated section, it becomes invalid
842         ((pOld != NULL) && (pOld->Which() == RES_UNOCURSOR_LEAVES_SECTION)))
843     {
844         Invalidate();
845     }
846 }
847 
848 
849 SwUnoCrsr const* SwXTextCursor::GetCursor() const
850 {
851     return m_pImpl->GetCursor();
852 }
853 
854 SwUnoCrsr * SwXTextCursor::GetCursor()
855 {
856     return m_pImpl->GetCursor();
857 }
858 
859 /*-- 09.12.98 14:19:01---------------------------------------------------
860 
861   -----------------------------------------------------------------------*/
862 SwPaM const* SwXTextCursor::GetPaM() const
863 {
864     return m_pImpl->GetCursor();
865 }
866 
867 SwPaM * SwXTextCursor::GetPaM()
868 {
869     return m_pImpl->GetCursor();
870 }
871 
872 /*-- 09.12.98 14:19:02---------------------------------------------------
873 
874   -----------------------------------------------------------------------*/
875 SwDoc const* SwXTextCursor::GetDoc() const
876 {
877     return m_pImpl->GetCursor() ? m_pImpl->GetCursor()->GetDoc() : 0;
878 }
879 /* -----------------22.07.99 13:52-------------------
880 
881  --------------------------------------------------*/
882 SwDoc * SwXTextCursor::GetDoc()
883 {
884     return m_pImpl->GetCursor() ? m_pImpl->GetCursor()->GetDoc() : 0;
885 }
886 
887 
888 /*-- 09.12.98 14:19:19---------------------------------------------------
889 
890   -----------------------------------------------------------------------*/
891 SwXTextCursor::SwXTextCursor(
892         SwDoc & rDoc,
893         uno::Reference< text::XText > const& xParent,
894         const enum CursorType eType,
895         const SwPosition& rPos,
896         SwPosition const*const pMark)
897     : m_pImpl( new SwXTextCursor::Impl(*this, rDoc, eType, xParent,
898                 rPos, pMark ) )
899 {
900 }
901 
902 /* -----------------04.03.99 09:02-------------------
903  *
904  * --------------------------------------------------*/
905 SwXTextCursor::SwXTextCursor(uno::Reference< text::XText > const& xParent,
906         SwPaM const& rSourceCursor, const enum CursorType eType)
907     : m_pImpl( new SwXTextCursor::Impl(*this, *rSourceCursor.GetDoc(), eType,
908                 xParent, *rSourceCursor.GetPoint(),
909                 rSourceCursor.HasMark() ? rSourceCursor.GetMark() : 0) )
910 {
911 }
912 
913 /*-- 09.12.98 14:19:20---------------------------------------------------
914 
915   -----------------------------------------------------------------------*/
916 SwXTextCursor::~SwXTextCursor()
917 {
918 }
919 
920 /*-- 09.12.98 14:19:18---------------------------------------------------
921 
922   -----------------------------------------------------------------------*/
923 void SwXTextCursor::DeleteAndInsert(const ::rtl::OUString& rText,
924         const bool bForceExpandHints)
925 {
926     SwUnoCrsr *const pUnoCrsr = m_pImpl->GetCursor();
927 	if(pUnoCrsr)
928 	{
929 		// Start/EndAction
930 		SwDoc* pDoc = pUnoCrsr->GetDoc();
931 		UnoActionContext aAction(pDoc);
932         const xub_StrLen nTxtLen = rText.getLength();
933         pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_INSERT, NULL);
934         SwCursor * pCurrent = pUnoCrsr;
935         do
936         {
937             if (pCurrent->HasMark())
938             {
939                 pDoc->DeleteAndJoin(*pCurrent);
940             }
941 			if(nTxtLen)
942 			{
943                 const bool bSuccess(
944                     SwUnoCursorHelper::DocInsertStringSplitCR(
945                         *pDoc, *pCurrent, rText, bForceExpandHints ) );
946                 DBG_ASSERT( bSuccess, "Doc->Insert(Str) failed." );
947                 (void) bSuccess;
948 
949                 SwUnoCursorHelper::SelectPam(*pUnoCrsr, true);
950                 pCurrent->Left(rText.getLength(),
951                         CRSR_SKIP_CHARS, sal_False, sal_False);
952             }
953             pCurrent = static_cast<SwCursor *>(pCurrent->GetNext());
954         } while (pCurrent != pUnoCrsr);
955         pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_INSERT, NULL);
956     }
957 }
958 
959 
960 enum ForceIntoMetaMode { META_CHECK_BOTH, META_INIT_START, META_INIT_END };
961 
962 static sal_Bool
963 lcl_ForceIntoMeta(SwPaM & rCursor,
964         uno::Reference<text::XText> const & xParentText,
965         const enum ForceIntoMetaMode eMode)
966 {
967     sal_Bool bRet( sal_True ); // means not forced in META_CHECK_BOTH
968     SwXMeta const * const pXMeta( dynamic_cast<SwXMeta*>(xParentText.get()) );
969     ASSERT(pXMeta, "no parent?");
970     if (!pXMeta)
971         throw uno::RuntimeException();
972     SwTxtNode * pTxtNode;
973     xub_StrLen nStart;
974     xub_StrLen nEnd;
975     const bool bSuccess( pXMeta->SetContentRange(pTxtNode, nStart, nEnd) );
976     ASSERT(bSuccess, "no pam?");
977     if (!bSuccess)
978         throw uno::RuntimeException();
979     // force the cursor back into the meta if it has moved outside
980     SwPosition start(*pTxtNode, nStart);
981     SwPosition end(*pTxtNode, nEnd);
982     switch (eMode)
983     {
984         case META_INIT_START:
985             *rCursor.GetPoint() = start;
986             break;
987         case META_INIT_END:
988             *rCursor.GetPoint() = end;
989             break;
990         case META_CHECK_BOTH:
991             if (*rCursor.Start() < start)
992             {
993                 *rCursor.Start() = start;
994                 bRet = sal_False;
995             }
996             if (*rCursor.End() > end)
997             {
998                 *rCursor.End() = end;
999                 bRet = sal_False;
1000             }
1001             break;
1002     }
1003     return bRet;
1004 }
1005 
1006 bool SwXTextCursor::IsAtEndOfMeta() const
1007 {
1008     if (CURSOR_META == m_pImpl->m_eType)
1009     {
1010         SwUnoCrsr const * const pCursor( m_pImpl->GetCursor() );
1011         SwXMeta const*const pXMeta(
1012                 dynamic_cast<SwXMeta*>(m_pImpl->m_xParentText.get()) );
1013         ASSERT(pXMeta, "no meta?");
1014         if (pCursor && pXMeta)
1015         {
1016             SwTxtNode * pTxtNode;
1017             xub_StrLen nStart;
1018             xub_StrLen nEnd;
1019             const bool bSuccess(
1020                     pXMeta->SetContentRange(pTxtNode, nStart, nEnd) );
1021             ASSERT(bSuccess, "no pam?");
1022             if (bSuccess)
1023             {
1024                 const SwPosition end(*pTxtNode, nEnd);
1025                 if (   (*pCursor->GetPoint() == end)
1026                     || (*pCursor->GetMark()  == end))
1027                 {
1028                     return true;
1029                 }
1030             }
1031         }
1032     }
1033     return false;
1034 }
1035 
1036 /*-- 09.12.98 14:19:19---------------------------------------------------
1037 
1038   -----------------------------------------------------------------------*/
1039 OUString SwXTextCursor::getImplementationName() throw (uno::RuntimeException)
1040 {
1041 	return C2U("SwXTextCursor");
1042 }
1043 
1044 /*-- 09.12.98 14:19:19---------------------------------------------------
1045 
1046   -----------------------------------------------------------------------*/
1047 static char const*const g_ServicesTextCursor[] =
1048 {
1049     "com.sun.star.text.TextCursor",
1050     "com.sun.star.style.CharacterProperties",
1051     "com.sun.star.style.CharacterPropertiesAsian",
1052     "com.sun.star.style.CharacterPropertiesComplex",
1053     "com.sun.star.style.ParagraphProperties",
1054     "com.sun.star.style.ParagraphPropertiesAsian",
1055     "com.sun.star.style.ParagraphPropertiesComplex",
1056     "com.sun.star.text.TextSortable",
1057 };
1058 static const size_t g_nServicesTextCursor(
1059     sizeof(g_ServicesTextCursor)/sizeof(g_ServicesTextCursor[0]));
1060 
1061 sal_Bool SAL_CALL SwXTextCursor::supportsService(const OUString& rServiceName)
1062 throw (uno::RuntimeException)
1063 {
1064     return ::sw::SupportsServiceImpl(
1065             g_nServicesTextCursor, g_ServicesTextCursor, rServiceName);
1066 }
1067 
1068 uno::Sequence< OUString > SAL_CALL
1069 SwXTextCursor::getSupportedServiceNames() throw (uno::RuntimeException)
1070 {
1071     return ::sw::GetSupportedServiceNamesImpl(
1072             g_nServicesTextCursor, g_ServicesTextCursor);
1073 }
1074 
1075 /* -----------------------------10.03.00 18:02--------------------------------
1076 
1077  ---------------------------------------------------------------------------*/
1078 const uno::Sequence< sal_Int8 > & SwXTextCursor::getUnoTunnelId()
1079 {
1080     static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
1081 	return aSeq;
1082 }
1083 /* -----------------------------10.03.00 18:04--------------------------------
1084 
1085  ---------------------------------------------------------------------------*/
1086 sal_Int64 SAL_CALL
1087 SwXTextCursor::getSomething(const uno::Sequence< sal_Int8 >& rId)
1088 throw (uno::RuntimeException)
1089 {
1090     const sal_Int64 nRet( ::sw::UnoTunnelImpl<SwXTextCursor>(rId, this) );
1091     return (nRet) ? nRet : OTextCursorHelper::getSomething(rId);
1092 }
1093 
1094 /*-- 09.12.98 14:18:12---------------------------------------------------
1095 
1096   -----------------------------------------------------------------------*/
1097 void SAL_CALL SwXTextCursor::collapseToStart() throw (uno::RuntimeException)
1098 {
1099 	vos::OGuard aGuard(Application::GetSolarMutex());
1100 
1101     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1102 
1103     if (rUnoCursor.HasMark())
1104     {
1105         if (*rUnoCursor.GetPoint() > *rUnoCursor.GetMark())
1106         {
1107             rUnoCursor.Exchange();
1108         }
1109         rUnoCursor.DeleteMark();
1110     }
1111 }
1112 /*-- 09.12.98 14:18:14---------------------------------------------------
1113 
1114   -----------------------------------------------------------------------*/
1115 void SAL_CALL SwXTextCursor::collapseToEnd() throw (uno::RuntimeException)
1116 {
1117 	vos::OGuard aGuard(Application::GetSolarMutex());
1118 
1119     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1120 
1121     if (rUnoCursor.HasMark())
1122     {
1123         if (*rUnoCursor.GetPoint() < *rUnoCursor.GetMark())
1124         {
1125             rUnoCursor.Exchange();
1126         }
1127         rUnoCursor.DeleteMark();
1128     }
1129 }
1130 /*-- 09.12.98 14:18:41---------------------------------------------------
1131 
1132   -----------------------------------------------------------------------*/
1133 sal_Bool SAL_CALL SwXTextCursor::isCollapsed() throw (uno::RuntimeException)
1134 {
1135 	vos::OGuard aGuard(Application::GetSolarMutex());
1136 
1137 	sal_Bool bRet = sal_True;
1138     SwUnoCrsr *const pUnoCrsr = m_pImpl->GetCursor();
1139 	if(pUnoCrsr && pUnoCrsr->GetMark())
1140 	{
1141 		bRet = (*pUnoCrsr->GetPoint() == *pUnoCrsr->GetMark());
1142 	}
1143 	return bRet;
1144 }
1145 
1146 /*-- 09.12.98 14:18:42---------------------------------------------------
1147 
1148   -----------------------------------------------------------------------*/
1149 sal_Bool SAL_CALL
1150 SwXTextCursor::goLeft(sal_Int16 nCount, sal_Bool Expand)
1151 throw (uno::RuntimeException)
1152 {
1153 	vos::OGuard aGuard(Application::GetSolarMutex());
1154 
1155     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1156 
1157     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1158     sal_Bool bRet = rUnoCursor.Left( nCount, CRSR_SKIP_CHARS, sal_False, sal_False);
1159     if (CURSOR_META == m_pImpl->m_eType)
1160     {
1161         bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1162                     META_CHECK_BOTH)
1163             && bRet;
1164     }
1165 	return bRet;
1166 }
1167 /*-- 09.12.98 14:18:42---------------------------------------------------
1168 
1169   -----------------------------------------------------------------------*/
1170 sal_Bool SAL_CALL
1171 SwXTextCursor::goRight(sal_Int16 nCount, sal_Bool Expand)
1172 throw (uno::RuntimeException)
1173 {
1174 	vos::OGuard aGuard(Application::GetSolarMutex());
1175 
1176     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1177 
1178     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1179     sal_Bool bRet = rUnoCursor.Right(nCount, CRSR_SKIP_CHARS, sal_False, sal_False);
1180     if (CURSOR_META == m_pImpl->m_eType)
1181     {
1182         bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1183                     META_CHECK_BOTH)
1184             && bRet;
1185     }
1186 	return bRet;
1187 }
1188 
1189 /*-- 09.12.98 14:18:43---------------------------------------------------
1190 
1191   -----------------------------------------------------------------------*/
1192 void SAL_CALL
1193 SwXTextCursor::gotoStart(sal_Bool Expand) throw (uno::RuntimeException)
1194 {
1195 	vos::OGuard aGuard(Application::GetSolarMutex());
1196 
1197     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1198 
1199     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1200     if (CURSOR_BODY == m_pImpl->m_eType)
1201     {
1202         rUnoCursor.Move( fnMoveBackward, fnGoDoc );
1203         //check, that the cursor is not in a table
1204         SwTableNode * pTblNode = rUnoCursor.GetNode()->FindTableNode();
1205         SwCntntNode * pCNode = 0;
1206         while (pTblNode)
1207         {
1208             rUnoCursor.GetPoint()->nNode = *pTblNode->EndOfSectionNode();
1209             pCNode = GetDoc()->GetNodes().GoNext(&rUnoCursor.GetPoint()->nNode);
1210             pTblNode = (pCNode) ? pCNode->FindTableNode() : 0;
1211         }
1212         if (pCNode)
1213         {
1214             rUnoCursor.GetPoint()->nContent.Assign(pCNode, 0);
1215         }
1216         SwStartNode const*const pTmp =
1217             rUnoCursor.GetNode()->StartOfSectionNode();
1218         if (pTmp->IsSectionNode())
1219         {
1220             SwSectionNode const*const pSectionStartNode =
1221                 static_cast<SwSectionNode const*>(pTmp);
1222             if (pSectionStartNode->GetSection().IsHiddenFlag())
1223             {
1224                 pCNode = GetDoc()->GetNodes().GoNextSection(
1225                         &rUnoCursor.GetPoint()->nNode, sal_True, sal_False);
1226                 if (pCNode)
1227                 {
1228                     rUnoCursor.GetPoint()->nContent.Assign(pCNode, 0);
1229                 }
1230             }
1231         }
1232     }
1233     else if (   (CURSOR_FRAME   == m_pImpl->m_eType)
1234             ||  (CURSOR_TBLTEXT == m_pImpl->m_eType)
1235             ||  (CURSOR_HEADER  == m_pImpl->m_eType)
1236             ||  (CURSOR_FOOTER  == m_pImpl->m_eType)
1237             ||  (CURSOR_FOOTNOTE== m_pImpl->m_eType)
1238             ||  (CURSOR_REDLINE == m_pImpl->m_eType))
1239     {
1240         rUnoCursor.MoveSection(fnSectionCurr, fnSectionStart);
1241     }
1242     else if (CURSOR_META == m_pImpl->m_eType)
1243     {
1244         lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, META_INIT_START);
1245     }
1246 }
1247 /*-- 09.12.98 14:18:43---------------------------------------------------
1248 
1249   -----------------------------------------------------------------------*/
1250 void SAL_CALL
1251 SwXTextCursor::gotoEnd(sal_Bool Expand) throw (uno::RuntimeException)
1252 {
1253 	vos::OGuard aGuard(Application::GetSolarMutex());
1254 
1255     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1256 
1257     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1258     if (CURSOR_BODY == m_pImpl->m_eType)
1259     {
1260         rUnoCursor.Move( fnMoveForward, fnGoDoc );
1261     }
1262     else if (   (CURSOR_FRAME   == m_pImpl->m_eType)
1263             ||  (CURSOR_TBLTEXT == m_pImpl->m_eType)
1264             ||  (CURSOR_HEADER  == m_pImpl->m_eType)
1265             ||  (CURSOR_FOOTER  == m_pImpl->m_eType)
1266             ||  (CURSOR_FOOTNOTE== m_pImpl->m_eType)
1267             ||  (CURSOR_REDLINE == m_pImpl->m_eType))
1268     {
1269         rUnoCursor.MoveSection( fnSectionCurr, fnSectionEnd);
1270     }
1271     else if (CURSOR_META == m_pImpl->m_eType)
1272     {
1273         lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, META_INIT_END);
1274     }
1275 }
1276 
1277 void SAL_CALL
1278 SwXTextCursor::gotoRange(
1279     const uno::Reference< text::XTextRange > & xRange, sal_Bool bExpand)
1280 throw (uno::RuntimeException)
1281 {
1282     vos::OGuard aGuard(Application::GetSolarMutex());
1283 
1284     if (!xRange.is())
1285     {
1286         throw uno::RuntimeException();
1287     }
1288 
1289     SwUnoCrsr & rOwnCursor( m_pImpl->GetCursorOrThrow() );
1290 
1291     uno::Reference<lang::XUnoTunnel> xRangeTunnel( xRange, uno::UNO_QUERY);
1292     SwXTextRange* pRange = 0;
1293     OTextCursorHelper* pCursor = 0;
1294     if(xRangeTunnel.is())
1295     {
1296         pRange  = ::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel);
1297         pCursor =
1298             ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel);
1299     }
1300 
1301     if (!pRange && !pCursor)
1302     {
1303         throw uno::RuntimeException();
1304     }
1305 
1306     SwStartNodeType eSearchNodeType = SwNormalStartNode;
1307     switch (m_pImpl->m_eType)
1308     {
1309         case CURSOR_FRAME:      eSearchNodeType = SwFlyStartNode;       break;
1310         case CURSOR_TBLTEXT:    eSearchNodeType = SwTableBoxStartNode;  break;
1311         case CURSOR_FOOTNOTE:   eSearchNodeType = SwFootnoteStartNode;  break;
1312         case CURSOR_HEADER:     eSearchNodeType = SwHeaderStartNode;    break;
1313         case CURSOR_FOOTER:     eSearchNodeType = SwFooterStartNode;    break;
1314         //case CURSOR_INVALID:
1315         //case CURSOR_BODY:
1316         default:
1317             ;
1318     }
1319     const SwStartNode* pOwnStartNode =
1320         rOwnCursor.GetNode()->FindSttNodeByType(eSearchNodeType);
1321 
1322     SwPaM aPam(GetDoc()->GetNodes());
1323     const SwPaM * pPam(0);
1324     if (pCursor)
1325     {
1326         pPam = pCursor->GetPaM();
1327     }
1328     else if (pRange)
1329     {
1330         if (pRange->GetPositions(aPam))
1331         {
1332             pPam = & aPam;
1333         }
1334     }
1335 
1336     if (!pPam)
1337     {
1338         throw uno::RuntimeException();
1339     }
1340     const SwStartNode* pTmp =
1341         pPam->GetNode()->FindSttNodeByType(eSearchNodeType);
1342 
1343     //SectionNodes ueberspringen
1344     while(pTmp && pTmp->IsSectionNode())
1345     {
1346         pTmp = pTmp->StartOfSectionNode();
1347     }
1348     while(pOwnStartNode && pOwnStartNode->IsSectionNode())
1349     {
1350         pOwnStartNode = pOwnStartNode->StartOfSectionNode();
1351     }
1352     if(pOwnStartNode != pTmp)
1353     {
1354         throw uno::RuntimeException();
1355     }
1356 
1357     if (CURSOR_META == m_pImpl->m_eType)
1358     {
1359         SwPaM CopyPam(*pPam->GetMark(), *pPam->GetPoint());
1360         const bool bNotForced( lcl_ForceIntoMeta(
1361                     CopyPam, m_pImpl->m_xParentText, META_CHECK_BOTH) );
1362         if (!bNotForced)
1363         {
1364             throw uno::RuntimeException(
1365                 C2U("gotoRange: parameter range not contained in nesting"
1366                     " text content for which this cursor was created"),
1367                 static_cast<text::XWordCursor*>(this));
1368         }
1369     }
1370 
1371     //jetzt muss die Selektion erweitert werden
1372     if(bExpand)
1373     {
1374         // der Cursor soll alles einschliessen, was bisher von ihm und dem uebergebenen
1375         // Range eingeschlossen wurde
1376         const SwPosition aOwnLeft(*rOwnCursor.Start());
1377         const SwPosition aOwnRight(*rOwnCursor.End());
1378         SwPosition const& rParamLeft  = *pPam->Start();
1379         SwPosition const& rParamRight = *pPam->End();
1380 
1381         // jetzt sind vier SwPositions da, zwei davon werden gebraucht, also welche?
1382         *rOwnCursor.GetPoint() = (aOwnRight > rParamRight)
1383             ? aOwnRight : *rOwnCursor.GetPoint() = rParamRight;
1384         rOwnCursor.SetMark();
1385         *rOwnCursor.GetMark() = (aOwnLeft < rParamLeft)
1386             ? aOwnLeft : *rOwnCursor.GetMark() = rParamLeft;
1387     }
1388     else
1389     {
1390         // cursor should be the given range
1391         *rOwnCursor.GetPoint() = *pPam->GetPoint();
1392         if (pPam->HasMark())
1393         {
1394             rOwnCursor.SetMark();
1395             *rOwnCursor.GetMark() = *pPam->GetMark();
1396         }
1397         else
1398         {
1399             rOwnCursor.DeleteMark();
1400         }
1401     }
1402 }
1403 
1404 /*-- 09.12.98 14:18:44---------------------------------------------------
1405 
1406   -----------------------------------------------------------------------*/
1407 sal_Bool SAL_CALL SwXTextCursor::isStartOfWord() throw (uno::RuntimeException)
1408 {
1409 	vos::OGuard aGuard(Application::GetSolarMutex());
1410 
1411     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1412 
1413     const sal_Bool bRet =
1414         rUnoCursor.IsStartWordWT( i18n::WordType::DICTIONARY_WORD );
1415 	return bRet;
1416 }
1417 /*-- 09.12.98 14:18:44---------------------------------------------------
1418 
1419   -----------------------------------------------------------------------*/
1420 sal_Bool SAL_CALL SwXTextCursor::isEndOfWord() throw (uno::RuntimeException)
1421 {
1422 	vos::OGuard aGuard(Application::GetSolarMutex());
1423 
1424     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1425 
1426     const sal_Bool bRet =
1427         rUnoCursor.IsEndWordWT( i18n::WordType::DICTIONARY_WORD );
1428 	return bRet;
1429 }
1430 
1431 /*-- 09.12.98 14:18:44---------------------------------------------------
1432 
1433   -----------------------------------------------------------------------*/
1434 sal_Bool SAL_CALL
1435 SwXTextCursor::gotoNextWord(sal_Bool Expand) throw (uno::RuntimeException)
1436 {
1437 	vos::OGuard aGuard(Application::GetSolarMutex());
1438 
1439     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1440 
1441 	//Probleme gibt's noch mit einem Absatzanfang, an dem kein Wort beginnt.
1442 	sal_Bool bRet = sal_False;
1443     // remember old position to check if cursor has moved
1444     // since the called functions are sometimes a bit unreliable
1445     // in specific cases...
1446     SwPosition  *const pPoint     = rUnoCursor.GetPoint();
1447     SwNode      *const pOldNode   = &pPoint->nNode.GetNode();
1448     xub_StrLen   const nOldIndex  = pPoint->nContent.GetIndex();
1449 
1450     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1451     // end of paragraph
1452     if (rUnoCursor.GetCntntNode() &&
1453             (pPoint->nContent == rUnoCursor.GetCntntNode()->Len()))
1454     {
1455         rUnoCursor.Right(1, CRSR_SKIP_CHARS, sal_False, sal_False);
1456     }
1457     else
1458     {
1459         const bool bTmp =
1460             rUnoCursor.GoNextWordWT( i18n::WordType::DICTIONARY_WORD );
1461         // if there is no next word within the current paragraph
1462         // try to go to the start of the next paragraph
1463         if (!bTmp)
1464         {
1465             rUnoCursor.MovePara(fnParaNext, fnParaStart);
1466         }
1467     }
1468 
1469     // return true if cursor has moved
1470     bRet =  (&pPoint->nNode.GetNode() != pOldNode)  ||
1471             (pPoint->nContent.GetIndex() != nOldIndex);
1472     if (bRet && (CURSOR_META == m_pImpl->m_eType))
1473     {
1474         bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1475                     META_CHECK_BOTH);
1476     }
1477 
1478 	return bRet;
1479 }
1480 
1481 /*-- 09.12.98 14:18:45---------------------------------------------------
1482 
1483   -----------------------------------------------------------------------*/
1484 sal_Bool SAL_CALL
1485 SwXTextCursor::gotoPreviousWord(sal_Bool Expand) throw (uno::RuntimeException)
1486 {
1487 	vos::OGuard aGuard(Application::GetSolarMutex());
1488 
1489     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1490 
1491 	// hier machen Leerzeichen am Absatzanfang Probleme
1492 	sal_Bool bRet = sal_False;
1493     SwPosition  *const pPoint     = rUnoCursor.GetPoint();
1494     SwNode      *const pOldNode   = &pPoint->nNode.GetNode();
1495     xub_StrLen   const nOldIndex  = pPoint->nContent.GetIndex();
1496 
1497     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1498     // start of paragraph?
1499     if (pPoint->nContent == 0)
1500     {
1501         rUnoCursor.Left(1, CRSR_SKIP_CHARS, sal_False, sal_False);
1502     }
1503     else
1504     {
1505         rUnoCursor.GoPrevWordWT( i18n::WordType::DICTIONARY_WORD );
1506         if (pPoint->nContent == 0)
1507         {
1508             rUnoCursor.Left(1, CRSR_SKIP_CHARS, sal_False, sal_False);
1509         }
1510     }
1511 
1512     // return true if cursor has moved
1513     bRet =  (&pPoint->nNode.GetNode() != pOldNode)  ||
1514             (pPoint->nContent.GetIndex() != nOldIndex);
1515     if (bRet && (CURSOR_META == m_pImpl->m_eType))
1516     {
1517         bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1518                     META_CHECK_BOTH);
1519     }
1520 
1521 	return bRet;
1522 }
1523 
1524 /*-- 09.12.98 14:18:45---------------------------------------------------
1525 
1526   -----------------------------------------------------------------------*/
1527 sal_Bool SAL_CALL
1528 SwXTextCursor::gotoEndOfWord(sal_Bool Expand) throw (uno::RuntimeException)
1529 {
1530 	vos::OGuard aGuard(Application::GetSolarMutex());
1531 
1532     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1533 
1534 	sal_Bool bRet = sal_False;
1535     SwPosition  *const pPoint     = rUnoCursor.GetPoint();
1536     SwNode      &      rOldNode   = pPoint->nNode.GetNode();
1537     xub_StrLen   const nOldIndex  = pPoint->nContent.GetIndex();
1538 
1539     const sal_Int16 nWordType = i18n::WordType::DICTIONARY_WORD;
1540     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1541     if (!rUnoCursor.IsEndWordWT( nWordType ))
1542     {
1543         rUnoCursor.GoEndWordWT( nWordType );
1544     }
1545 
1546     // restore old cursor if we are not at the end of a word by now
1547     // otherwise use current one
1548     bRet = rUnoCursor.IsEndWordWT( nWordType );
1549     if (!bRet)
1550     {
1551         pPoint->nNode       = rOldNode;
1552         pPoint->nContent    = nOldIndex;
1553     }
1554     else if (CURSOR_META == m_pImpl->m_eType)
1555     {
1556         bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1557                     META_CHECK_BOTH);
1558     }
1559 
1560 	return bRet;
1561 }
1562 /*-- 09.12.98 14:18:46---------------------------------------------------
1563 
1564   -----------------------------------------------------------------------*/
1565 sal_Bool SAL_CALL
1566 SwXTextCursor::gotoStartOfWord(sal_Bool Expand) throw (uno::RuntimeException)
1567 {
1568 	vos::OGuard aGuard(Application::GetSolarMutex());
1569 
1570     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1571 
1572 	sal_Bool bRet = sal_False;
1573     SwPosition  *const pPoint     = rUnoCursor.GetPoint();
1574     SwNode      &      rOldNode   = pPoint->nNode.GetNode();
1575     xub_StrLen   const nOldIndex  = pPoint->nContent.GetIndex();
1576 
1577     const sal_Int16 nWordType = i18n::WordType::DICTIONARY_WORD;
1578     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1579     if (!rUnoCursor.IsStartWordWT( nWordType ))
1580     {
1581         rUnoCursor.GoStartWordWT( nWordType );
1582     }
1583 
1584     // restore old cursor if we are not at the start of a word by now
1585     // otherwise use current one
1586     bRet = rUnoCursor.IsStartWordWT( nWordType );
1587     if (!bRet)
1588     {
1589         pPoint->nNode       = rOldNode;
1590         pPoint->nContent    = nOldIndex;
1591     }
1592     else if (CURSOR_META == m_pImpl->m_eType)
1593     {
1594         bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1595                     META_CHECK_BOTH);
1596     }
1597 
1598 	return bRet;
1599 }
1600 
1601 /*-- 09.12.98 14:18:46---------------------------------------------------
1602 
1603   -----------------------------------------------------------------------*/
1604 sal_Bool SAL_CALL
1605 SwXTextCursor::isStartOfSentence() throw (uno::RuntimeException)
1606 {
1607 	vos::OGuard aGuard(Application::GetSolarMutex());
1608 
1609     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1610 
1611     // start of paragraph?
1612     sal_Bool bRet = rUnoCursor.GetPoint()->nContent == 0;
1613     // with mark ->no sentence start
1614     // (check if cursor is no selection, i.e. it does not have
1615     // a mark or else point and mark are identical)
1616     if (!bRet && (!rUnoCursor.HasMark() ||
1617                     *rUnoCursor.GetPoint() == *rUnoCursor.GetMark()))
1618     {
1619         SwCursor aCrsr(*rUnoCursor.GetPoint(),0,false);
1620         SwPosition aOrigPos = *aCrsr.GetPoint();
1621         aCrsr.GoSentence(SwCursor::START_SENT );
1622         bRet = aOrigPos == *aCrsr.GetPoint();
1623     }
1624 	return bRet;
1625 }
1626 /*-- 09.12.98 14:18:47---------------------------------------------------
1627 
1628   -----------------------------------------------------------------------*/
1629 sal_Bool SAL_CALL
1630 SwXTextCursor::isEndOfSentence() throw (uno::RuntimeException)
1631 {
1632 	vos::OGuard aGuard(Application::GetSolarMutex());
1633 
1634     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1635 
1636     // end of paragraph?
1637     sal_Bool bRet = rUnoCursor.GetCntntNode() &&
1638         (rUnoCursor.GetPoint()->nContent == rUnoCursor.GetCntntNode()->Len());
1639     // with mark->no sentence end
1640     // (check if cursor is no selection, i.e. it does not have
1641     // a mark or else point and mark are identical)
1642     if (!bRet && (!rUnoCursor.HasMark() ||
1643                     *rUnoCursor.GetPoint() == *rUnoCursor.GetMark()))
1644     {
1645         SwCursor aCrsr(*rUnoCursor.GetPoint(), 0, false);
1646         SwPosition aOrigPos = *aCrsr.GetPoint();
1647         aCrsr.GoSentence(SwCursor::END_SENT);
1648         bRet = aOrigPos == *aCrsr.GetPoint();
1649     }
1650 	return bRet;
1651 }
1652 
1653 /*-- 09.12.98 14:18:47---------------------------------------------------
1654 
1655   -----------------------------------------------------------------------*/
1656 sal_Bool SAL_CALL
1657 SwXTextCursor::gotoNextSentence(sal_Bool Expand) throw (uno::RuntimeException)
1658 {
1659 	vos::OGuard aGuard(Application::GetSolarMutex());
1660 
1661     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1662 
1663     const bool bWasEOS = isEndOfSentence();
1664     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1665     sal_Bool bRet = rUnoCursor.GoSentence(SwCursor::NEXT_SENT);
1666     if (!bRet)
1667     {
1668         bRet = rUnoCursor.MovePara(fnParaNext, fnParaStart);
1669     }
1670 
1671     // if at the end of the sentence (i.e. at the space after the '.')
1672     // advance to next word in order for GoSentence to work properly
1673     // next time and have isStartOfSentence return true after this call
1674     if (!rUnoCursor.IsStartWord())
1675     {
1676         const bool bNextWord = rUnoCursor.GoNextWord();
1677         if (bWasEOS && !bNextWord)
1678         {
1679             bRet = sal_False;
1680         }
1681     }
1682     if (CURSOR_META == m_pImpl->m_eType)
1683     {
1684         bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1685                     META_CHECK_BOTH)
1686             && bRet;
1687     }
1688 	return bRet;
1689 }
1690 /*-- 09.12.98 14:18:47---------------------------------------------------
1691 
1692   -----------------------------------------------------------------------*/
1693 sal_Bool SAL_CALL
1694 SwXTextCursor::gotoPreviousSentence(sal_Bool Expand)
1695 throw (uno::RuntimeException)
1696 {
1697 	vos::OGuard aGuard(Application::GetSolarMutex());
1698 
1699     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1700 
1701     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1702     sal_Bool bRet = rUnoCursor.GoSentence(SwCursor::PREV_SENT);
1703     if (!bRet)
1704     {
1705         bRet = rUnoCursor.MovePara(fnParaPrev, fnParaStart);
1706         if (bRet)
1707         {
1708             rUnoCursor.MovePara(fnParaCurr, fnParaEnd);
1709             // at the end of a paragraph move to the sentence end again
1710             rUnoCursor.GoSentence(SwCursor::PREV_SENT);
1711         }
1712     }
1713     if (CURSOR_META == m_pImpl->m_eType)
1714     {
1715         bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1716                     META_CHECK_BOTH)
1717             && bRet;
1718     }
1719 	return bRet;
1720 }
1721 
1722 /* -----------------15.10.99 08:24-------------------
1723 
1724  --------------------------------------------------*/
1725 sal_Bool SAL_CALL
1726 SwXTextCursor::gotoStartOfSentence(sal_Bool Expand)
1727 throw (uno::RuntimeException)
1728 {
1729 	vos::OGuard aGuard(Application::GetSolarMutex());
1730 
1731     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1732 
1733 	sal_Bool bRet = sal_False;
1734     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1735     // if we're at the para start then we wont move
1736     // but bRet is also true if GoSentence failed but
1737     // the start of the sentence is reached
1738     bRet = SwUnoCursorHelper::IsStartOfPara(rUnoCursor)
1739         || rUnoCursor.GoSentence(SwCursor::START_SENT)
1740         || SwUnoCursorHelper::IsStartOfPara(rUnoCursor);
1741     if (CURSOR_META == m_pImpl->m_eType)
1742     {
1743         bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1744                     META_CHECK_BOTH)
1745             && bRet;
1746     }
1747 	return bRet;
1748 }
1749 /* -----------------15.10.99 08:24-------------------
1750 
1751  --------------------------------------------------*/
1752 sal_Bool SAL_CALL
1753 SwXTextCursor::gotoEndOfSentence(sal_Bool Expand) throw (uno::RuntimeException)
1754 {
1755 	vos::OGuard aGuard(Application::GetSolarMutex());
1756 
1757     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1758 
1759 	sal_Bool bRet = sal_False;
1760     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1761     // bRet is true if GoSentence() succeeded or if the
1762     // MovePara() succeeded while the end of the para is
1763     // not reached already
1764     sal_Bool bAlreadyParaEnd = SwUnoCursorHelper::IsEndOfPara(rUnoCursor);
1765     bRet = !bAlreadyParaEnd
1766             &&  (rUnoCursor.GoSentence(SwCursor::END_SENT)
1767                  || rUnoCursor.MovePara(fnParaCurr, fnParaEnd));
1768     if (CURSOR_META == m_pImpl->m_eType)
1769     {
1770         bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1771                     META_CHECK_BOTH)
1772             && bRet;
1773     }
1774 	return bRet;
1775 }
1776 
1777 /*-- 09.12.98 14:18:48---------------------------------------------------
1778 
1779   -----------------------------------------------------------------------*/
1780 sal_Bool SAL_CALL
1781 SwXTextCursor::isStartOfParagraph() throw (uno::RuntimeException)
1782 {
1783 	vos::OGuard aGuard(Application::GetSolarMutex());
1784 
1785     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1786 
1787     const sal_Bool bRet = SwUnoCursorHelper::IsStartOfPara(rUnoCursor);
1788 	return bRet;
1789 }
1790 /*-- 09.12.98 14:18:48---------------------------------------------------
1791 
1792   -----------------------------------------------------------------------*/
1793 sal_Bool SAL_CALL
1794 SwXTextCursor::isEndOfParagraph() throw (uno::RuntimeException)
1795 {
1796 	vos::OGuard aGuard(Application::GetSolarMutex());
1797 
1798     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1799 
1800     const sal_Bool bRet = SwUnoCursorHelper::IsEndOfPara(rUnoCursor);
1801 	return bRet;
1802 }
1803 
1804 /*-- 09.12.98 14:18:49---------------------------------------------------
1805 
1806   -----------------------------------------------------------------------*/
1807 sal_Bool SAL_CALL
1808 SwXTextCursor::gotoStartOfParagraph(sal_Bool Expand)
1809 throw (uno::RuntimeException)
1810 {
1811 	vos::OGuard aGuard(Application::GetSolarMutex());
1812 
1813     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1814 
1815     if (CURSOR_META == m_pImpl->m_eType)
1816     {
1817         return sal_False;
1818     }
1819     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1820     sal_Bool bRet = SwUnoCursorHelper::IsStartOfPara(rUnoCursor);
1821     if (!bRet)
1822     {
1823         bRet = rUnoCursor.MovePara(fnParaCurr, fnParaStart);
1824     }
1825 
1826 	// since MovePara(fnParaCurr, fnParaStart) only returns false
1827 	// if we were already at the start of the paragraph this function
1828 	// should always complete successfully.
1829 	DBG_ASSERT( bRet, "gotoStartOfParagraph failed" );
1830 	return bRet;
1831 }
1832 /*-- 09.12.98 14:18:49---------------------------------------------------
1833 
1834   -----------------------------------------------------------------------*/
1835 sal_Bool SAL_CALL
1836 SwXTextCursor::gotoEndOfParagraph(sal_Bool Expand) throw (uno::RuntimeException)
1837 {
1838 	vos::OGuard aGuard(Application::GetSolarMutex());
1839 
1840     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1841 
1842     if (CURSOR_META == m_pImpl->m_eType)
1843     {
1844         return sal_False;
1845     }
1846     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1847     sal_Bool bRet = SwUnoCursorHelper::IsEndOfPara(rUnoCursor);
1848     if (!bRet)
1849     {
1850         bRet = rUnoCursor.MovePara(fnParaCurr, fnParaEnd);
1851     }
1852 
1853 	// since MovePara(fnParaCurr, fnParaEnd) only returns false
1854 	// if we were already at the end of the paragraph this function
1855 	// should always complete successfully.
1856 	DBG_ASSERT( bRet, "gotoEndOfParagraph failed" );
1857 	return bRet;
1858 }
1859 
1860 /*-- 09.12.98 14:18:50---------------------------------------------------
1861 
1862   -----------------------------------------------------------------------*/
1863 sal_Bool SAL_CALL
1864 SwXTextCursor::gotoNextParagraph(sal_Bool Expand) throw (uno::RuntimeException)
1865 {
1866 	vos::OGuard aGuard(Application::GetSolarMutex());
1867 
1868     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1869 
1870     if (CURSOR_META == m_pImpl->m_eType)
1871     {
1872         return sal_False;
1873     }
1874     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1875     const sal_Bool bRet = rUnoCursor.MovePara(fnParaNext, fnParaStart);
1876 	return bRet;
1877 }
1878 /*-- 09.12.98 14:18:50---------------------------------------------------
1879 
1880   -----------------------------------------------------------------------*/
1881 sal_Bool SAL_CALL
1882 SwXTextCursor::gotoPreviousParagraph(sal_Bool Expand)
1883 throw (uno::RuntimeException)
1884 {
1885 	vos::OGuard aGuard(Application::GetSolarMutex());
1886 
1887     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1888 
1889     if (CURSOR_META == m_pImpl->m_eType)
1890     {
1891         return sal_False;
1892     }
1893     SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1894     const sal_Bool bRet = rUnoCursor.MovePara(fnParaPrev, fnParaStart);
1895 	return bRet;
1896 }
1897 
1898 /*-- 09.12.98 14:18:50---------------------------------------------------
1899 
1900   -----------------------------------------------------------------------*/
1901 uno::Reference< text::XText > SAL_CALL
1902 SwXTextCursor::getText() throw (uno::RuntimeException)
1903 {
1904     vos::OGuard g(Application::GetSolarMutex());
1905 
1906 	return m_pImpl->m_xParentText;
1907 }
1908 
1909 /*-- 09.12.98 14:18:50---------------------------------------------------
1910 
1911   -----------------------------------------------------------------------*/
1912 uno::Reference< text::XTextRange > SAL_CALL
1913 SwXTextCursor::getStart() throw (uno::RuntimeException)
1914 {
1915 	vos::OGuard aGuard(Application::GetSolarMutex());
1916 
1917     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1918 
1919     uno::Reference< text::XTextRange > xRet;
1920     SwPaM aPam(*rUnoCursor.Start());
1921     const uno::Reference< text::XText >  xParent = getText();
1922     if (CURSOR_META == m_pImpl->m_eType)
1923     {
1924         // return cursor to prevent modifying SwXTextRange for META
1925         SwXTextCursor * const pXCursor(
1926             new SwXTextCursor(*rUnoCursor.GetDoc(), xParent, CURSOR_META,
1927                 *rUnoCursor.GetPoint()) );
1928         pXCursor->gotoStart(sal_False);
1929         xRet = static_cast<text::XWordCursor*>(pXCursor);
1930     }
1931     else
1932     {
1933         xRet = new SwXTextRange(aPam, xParent);
1934     }
1935 	return xRet;
1936 }
1937 /*-- 09.12.98 14:18:51---------------------------------------------------
1938 
1939   -----------------------------------------------------------------------*/
1940 uno::Reference< text::XTextRange > SAL_CALL
1941 SwXTextCursor::getEnd() throw (uno::RuntimeException)
1942 {
1943 	vos::OGuard aGuard(Application::GetSolarMutex());
1944 
1945     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1946 
1947     uno::Reference< text::XTextRange >  xRet;
1948     SwPaM aPam(*rUnoCursor.End());
1949     const uno::Reference< text::XText >  xParent = getText();
1950     if (CURSOR_META == m_pImpl->m_eType)
1951     {
1952         // return cursor to prevent modifying SwXTextRange for META
1953         SwXTextCursor * const pXCursor(
1954             new SwXTextCursor(*rUnoCursor.GetDoc(), xParent, CURSOR_META,
1955                 *rUnoCursor.GetPoint()) );
1956         pXCursor->gotoEnd(sal_False);
1957         xRet = static_cast<text::XWordCursor*>(pXCursor);
1958     }
1959     else
1960     {
1961         xRet = new SwXTextRange(aPam, xParent);
1962     }
1963 	return xRet;
1964 }
1965 
1966 /*-- 09.12.98 14:18:51---------------------------------------------------
1967 
1968   -----------------------------------------------------------------------*/
1969 OUString SAL_CALL SwXTextCursor::getString() throw (uno::RuntimeException)
1970 {
1971 	vos::OGuard aGuard(Application::GetSolarMutex());
1972 
1973     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1974 
1975     OUString aTxt;
1976     SwUnoCursorHelper::GetTextFromPam(rUnoCursor, aTxt);
1977 	return aTxt;
1978 }
1979 /*-- 09.12.98 14:18:52---------------------------------------------------
1980 
1981   -----------------------------------------------------------------------*/
1982 void SAL_CALL
1983 SwXTextCursor::setString(const OUString& aString) throw (uno::RuntimeException)
1984 {
1985 	vos::OGuard aGuard(Application::GetSolarMutex());
1986 
1987     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1988     (void) rUnoCursor; // just to check if valid
1989 
1990     const bool bForceExpandHints( (CURSOR_META != m_pImpl->m_eType)
1991         ? false
1992         : dynamic_cast<SwXMeta*>(m_pImpl->m_xParentText.get())
1993                 ->CheckForOwnMemberMeta(*GetPaM(), true) );
1994     DeleteAndInsert(aString, bForceExpandHints);
1995 }
1996 
1997 /* -----------------------------03.05.00 12:56--------------------------------
1998 
1999  ---------------------------------------------------------------------------*/
2000 uno::Any SwUnoCursorHelper::GetPropertyValue(
2001     SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
2002     const OUString& rPropertyName)
2003 throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2004         uno::RuntimeException)
2005 {
2006     uno::Any aAny;
2007     SfxItemPropertySimpleEntry const*const pEntry =
2008         rPropSet.getPropertyMap()->getByName(rPropertyName);
2009 
2010     if (!pEntry)
2011     {
2012         throw beans::UnknownPropertyException(
2013             OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
2014                 + rPropertyName, static_cast<cppu::OWeakObject *>(0));
2015     }
2016 
2017     beans::PropertyState eTemp;
2018     const sal_Bool bDone = SwUnoCursorHelper::getCrsrPropertyValue(
2019             *pEntry, rPaM, &aAny, eTemp );
2020 
2021     if (!bDone)
2022     {
2023         SfxItemSet aSet(rPaM.GetDoc()->GetAttrPool(),
2024             RES_CHRATR_BEGIN, RES_FRMATR_END - 1,
2025             RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER,
2026             RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER,
2027             0L);
2028         SwUnoCursorHelper::GetCrsrAttr(rPaM, aSet);
2029 
2030         rPropSet.getPropertyValue(*pEntry, aSet, aAny);
2031     }
2032 
2033 	return aAny;
2034 }
2035 /* -----------------------------03.05.00 12:57--------------------------------
2036 
2037  ---------------------------------------------------------------------------*/
2038 void SwUnoCursorHelper::SetPropertyValue(
2039     SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
2040     const OUString& rPropertyName,
2041     const uno::Any& rValue,
2042     const SetAttrMode nAttrMode, const bool bTableMode)
2043 throw (beans::UnknownPropertyException, beans::PropertyVetoException,
2044         lang::IllegalArgumentException, lang::WrappedTargetException,
2045         uno::RuntimeException)
2046 {
2047     SwDoc *const pDoc = rPaM.GetDoc();
2048     SfxItemPropertySimpleEntry const*const pEntry =
2049         rPropSet.getPropertyMap()->getByName(rPropertyName);
2050     if (!pEntry)
2051     {
2052         throw beans::UnknownPropertyException(
2053             OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
2054                 + rPropertyName,
2055             static_cast<cppu::OWeakObject *>(0));
2056     }
2057 
2058     if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
2059     {
2060         throw beans::PropertyVetoException(
2061             OUString(RTL_CONSTASCII_USTRINGPARAM("Property is read-only: "))
2062                 + rPropertyName,
2063             static_cast<cppu::OWeakObject *>(0));
2064     }
2065 
2066     SfxItemSet aItemSet( pDoc->GetAttrPool(), pEntry->nWID, pEntry->nWID );
2067     SwUnoCursorHelper::GetCrsrAttr( rPaM, aItemSet );
2068 
2069     if (!SwUnoCursorHelper::SetCursorPropertyValue(
2070                 *pEntry, rValue, rPaM, aItemSet))
2071     {
2072         rPropSet.setPropertyValue(*pEntry, rValue, aItemSet );
2073     }
2074     SwUnoCursorHelper::SetCrsrAttr(rPaM, aItemSet, nAttrMode, bTableMode);
2075 }
2076 
2077 /* -----------------------------03.05.00 13:16--------------------------------
2078 
2079  ---------------------------------------------------------------------------*/
2080 uno::Sequence< beans::PropertyState >
2081 SwUnoCursorHelper::GetPropertyStates(
2082             SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
2083             const uno::Sequence< OUString >& rPropertyNames,
2084             const SwGetPropertyStatesCaller eCaller)
2085 throw (beans::UnknownPropertyException, uno::RuntimeException)
2086 {
2087     const OUString* pNames = rPropertyNames.getConstArray();
2088     uno::Sequence< beans::PropertyState > aRet(rPropertyNames.getLength());
2089     beans::PropertyState* pStates = aRet.getArray();
2090     SfxItemPropertyMap const*const pMap = rPropSet.getPropertyMap();
2091     ::std::auto_ptr<SfxItemSet> pSet;
2092     ::std::auto_ptr<SfxItemSet> pSetParent;
2093 
2094     for (sal_Int32 i = 0, nEnd = rPropertyNames.getLength(); i < nEnd; i++)
2095     {
2096         SfxItemPropertySimpleEntry const*const pEntry =
2097                 pMap->getByName( pNames[i] );
2098         if(!pEntry)
2099         {
2100 			if (pNames[i].equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)) ||
2101 		        pNames[i].equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT)))
2102 			{
2103 				pStates[i] = beans::PropertyState_DEFAULT_VALUE;
2104 				continue;
2105 			}
2106 			else if (SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT ==
2107                         eCaller)
2108             {
2109                 //this values marks the element as unknown property
2110                 pStates[i] = beans::PropertyState_MAKE_FIXED_SIZE;
2111                 continue;
2112             }
2113             else
2114             {
2115                 throw beans::UnknownPropertyException(
2116                     OUString( RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
2117                         + pNames[i],
2118                     static_cast<cppu::OWeakObject *>(0));
2119             }
2120 		}
2121         if (((SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION == eCaller)  ||
2122              (SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT == eCaller)) &&
2123             pEntry->nWID < FN_UNO_RANGE_BEGIN &&
2124             pEntry->nWID > FN_UNO_RANGE_END  &&
2125             pEntry->nWID < RES_CHRATR_BEGIN &&
2126             pEntry->nWID > RES_TXTATR_END )
2127         {
2128 			pStates[i] = beans::PropertyState_DEFAULT_VALUE;
2129         }
2130 		else
2131 		{
2132             if ( pEntry->nWID >= FN_UNO_RANGE_BEGIN &&
2133                  pEntry->nWID <= FN_UNO_RANGE_END )
2134             {
2135                 SwUnoCursorHelper::getCrsrPropertyValue(
2136                     *pEntry, rPaM, 0, pStates[i] );
2137             }
2138 			else
2139 			{
2140                 if (!pSet.get())
2141 				{
2142 					switch ( eCaller )
2143 					{
2144                         case SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT:
2145                         case SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION:
2146                             pSet.reset(
2147                                 new SfxItemSet( rPaM.GetDoc()->GetAttrPool(),
2148                                     RES_CHRATR_BEGIN,   RES_TXTATR_END ));
2149 						break;
2150 						case SW_PROPERTY_STATE_CALLER_SINGLE_VALUE_ONLY:
2151                             pSet.reset(
2152                                 new SfxItemSet( rPaM.GetDoc()->GetAttrPool(),
2153                                     pEntry->nWID, pEntry->nWID ));
2154 						break;
2155 						default:
2156                             pSet.reset( new SfxItemSet(
2157                                 rPaM.GetDoc()->GetAttrPool(),
2158                                 RES_CHRATR_BEGIN, RES_FRMATR_END - 1,
2159 								RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER,
2160 								RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER,
2161                                 0L ));
2162 					}
2163                     // --> OD 2006-07-12 #i63870#
2164                     SwUnoCursorHelper::GetCrsrAttr( rPaM, *pSet );
2165                     // <--
2166 				}
2167 
2168                 pStates[i] = ( pSet->Count() )
2169                     ? rPropSet.getPropertyState( *pEntry, *pSet )
2170                     : beans::PropertyState_DEFAULT_VALUE;
2171 
2172 				//try again to find out if a value has been inherited
2173 				if( beans::PropertyState_DIRECT_VALUE == pStates[i] )
2174                 {
2175                     if (!pSetParent.get())
2176                     {
2177                         pSetParent.reset( pSet->Clone( sal_False ) );
2178                         // --> OD 2006-07-12 #i63870#
2179                         SwUnoCursorHelper::GetCrsrAttr(
2180                                 rPaM, *pSetParent, sal_True, sal_False );
2181                         // <--
2182                     }
2183 
2184                     pStates[i] = ( (pSetParent)->Count() )
2185                         ? rPropSet.getPropertyState( *pEntry, *pSetParent )
2186                         : beans::PropertyState_DEFAULT_VALUE;
2187                 }
2188             }
2189         }
2190     }
2191 	return aRet;
2192 }
2193 /* -----------------------------03.05.00 13:17--------------------------------
2194 
2195  ---------------------------------------------------------------------------*/
2196 beans::PropertyState SwUnoCursorHelper::GetPropertyState(
2197     SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
2198     const OUString& rPropertyName)
2199 throw (beans::UnknownPropertyException, uno::RuntimeException)
2200 {
2201     uno::Sequence< OUString > aStrings ( 1 );
2202 	aStrings[0] = rPropertyName;
2203     uno::Sequence< beans::PropertyState > aSeq =
2204         GetPropertyStates(rPaM, rPropSet, aStrings,
2205                 SW_PROPERTY_STATE_CALLER_SINGLE_VALUE_ONLY );
2206 	return aSeq[0];
2207 }
2208 /* -----------------------------03.05.00 13:20--------------------------------
2209 
2210  ---------------------------------------------------------------------------*/
2211 static void
2212 lcl_SelectParaAndReset( SwPaM &rPaM, SwDoc & rDoc,
2213         SvUShortsSort const*const pWhichIds = 0 )
2214 {
2215 	// if we are reseting paragraph attributes, we need to select the full paragraph first
2216 	SwPosition aStart = *rPaM.Start();
2217 	SwPosition aEnd = *rPaM.End();
2218     ::std::auto_ptr< SwUnoCrsr > pTemp ( rDoc.CreateUnoCrsr(aStart, sal_False) );
2219 	if(!SwUnoCursorHelper::IsStartOfPara(*pTemp))
2220     {
2221 		pTemp->MovePara(fnParaCurr, fnParaStart);
2222     }
2223 	pTemp->SetMark();
2224 	*pTemp->GetPoint() = aEnd;
2225     SwUnoCursorHelper::SelectPam(*pTemp, true);
2226 	if(!SwUnoCursorHelper::IsEndOfPara(*pTemp))
2227     {
2228 		pTemp->MovePara(fnParaCurr, fnParaEnd);
2229     }
2230     rDoc.ResetAttrs(*pTemp, sal_True, pWhichIds);
2231 }
2232 
2233 
2234 void SwUnoCursorHelper::SetPropertyToDefault(
2235 	SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
2236 	const OUString& rPropertyName)
2237 throw (beans::UnknownPropertyException, uno::RuntimeException)
2238 {
2239     SwDoc & rDoc = *rPaM.GetDoc();
2240     SfxItemPropertySimpleEntry const*const pEntry =
2241         rPropSet.getPropertyMap()->getByName(rPropertyName);
2242     if (!pEntry)
2243     {
2244         throw beans::UnknownPropertyException(
2245             OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
2246                 + rPropertyName, static_cast<cppu::OWeakObject *>(0));
2247     }
2248 
2249     if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
2250     {
2251         throw uno::RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM(
2252                 "setPropertyToDefault: property is read-only: "))
2253                 + rPropertyName, 0);
2254     }
2255 
2256     if (pEntry->nWID < RES_FRMATR_END)
2257     {
2258         SvUShortsSort aWhichIds;
2259         aWhichIds.Insert(pEntry->nWID);
2260         if (pEntry->nWID < RES_PARATR_BEGIN)
2261         {
2262             rDoc.ResetAttrs(rPaM, sal_True, &aWhichIds);
2263         }
2264         else
2265         {
2266             lcl_SelectParaAndReset ( rPaM, rDoc, &aWhichIds );
2267         }
2268     }
2269     else
2270     {
2271         SwUnoCursorHelper::resetCrsrPropertyValue(*pEntry, rPaM);
2272     }
2273 }
2274 
2275 /* -----------------------------03.05.00 13:19--------------------------------
2276 
2277  ---------------------------------------------------------------------------*/
2278 uno::Any SwUnoCursorHelper::GetPropertyDefault(
2279 	SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
2280 	const OUString& rPropertyName)
2281 throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2282         uno::RuntimeException)
2283 {
2284     SfxItemPropertySimpleEntry const*const pEntry =
2285         rPropSet.getPropertyMap()->getByName(rPropertyName);
2286     if (!pEntry)
2287     {
2288         throw beans::UnknownPropertyException(
2289             OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
2290                 + rPropertyName, static_cast<cppu::OWeakObject *>(0));
2291     }
2292 
2293     uno::Any aRet;
2294     if (pEntry->nWID < RES_FRMATR_END)
2295     {
2296         SwDoc & rDoc = *rPaM.GetDoc();
2297         const SfxPoolItem& rDefItem =
2298             rDoc.GetAttrPool().GetDefaultItem(pEntry->nWID);
2299         rDefItem.QueryValue(aRet, pEntry->nMemberId);
2300     }
2301 	return aRet;
2302 }
2303 
2304 /*-- 09.12.98 14:18:54---------------------------------------------------
2305 
2306   -----------------------------------------------------------------------*/
2307 uno::Reference< beans::XPropertySetInfo > SAL_CALL
2308 SwXTextCursor::getPropertySetInfo() throw (uno::RuntimeException)
2309 {
2310     vos::OGuard g(Application::GetSolarMutex());
2311 
2312 	static uno::Reference< beans::XPropertySetInfo >  xRef;
2313 	if(!xRef.is())
2314 	{
2315         static SfxItemPropertyMapEntry aCrsrExtMap_Impl[] =
2316 		{
2317 			{ SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT), FN_SKIP_HIDDEN_TEXT, &::getBooleanCppuType(), PROPERTY_NONE,     0},
2318 			{ SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT), FN_SKIP_PROTECTED_TEXT, &::getBooleanCppuType(), PROPERTY_NONE,     0},
2319 			{0,0,0,0,0,0}
2320 		};
2321         const uno::Reference< beans::XPropertySetInfo >  xInfo =
2322             m_pImpl->m_rPropSet.getPropertySetInfo();
2323 		// PropertySetInfo verlaengern!
2324 		const uno::Sequence<beans::Property> aPropSeq = xInfo->getProperties();
2325 		xRef = new SfxExtItemPropertySetInfo(
2326 			aCrsrExtMap_Impl,
2327 			aPropSeq );
2328 	}
2329 	return xRef;
2330 }
2331 
2332 /*-- 09.12.98 14:18:54---------------------------------------------------
2333 
2334   -----------------------------------------------------------------------*/
2335 void SAL_CALL
2336 SwXTextCursor::setPropertyValue(
2337         const OUString& rPropertyName, const uno::Any& rValue)
2338 throw (beans::UnknownPropertyException, beans::PropertyVetoException,
2339         lang::IllegalArgumentException, lang::WrappedTargetException,
2340         uno::RuntimeException)
2341 {
2342 	vos::OGuard aGuard(Application::GetSolarMutex());
2343 
2344     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2345 
2346     if (rPropertyName.equalsAsciiL(SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)))
2347     {
2348         sal_Bool bSet(sal_False);
2349         if (!(rValue >>= bSet))
2350         {
2351             throw lang::IllegalArgumentException();
2352         }
2353         rUnoCursor.SetSkipOverHiddenSections(bSet);
2354     }
2355     else if (rPropertyName.equalsAsciiL(
2356                 SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT)))
2357     {
2358         sal_Bool bSet(sal_False);
2359         if (!(rValue >>= bSet))
2360         {
2361             throw lang::IllegalArgumentException();
2362         }
2363         rUnoCursor.SetSkipOverProtectSections(bSet);
2364     }
2365     else
2366     {
2367         SwUnoCursorHelper::SetPropertyValue(rUnoCursor,
2368                 m_pImpl->m_rPropSet, rPropertyName, rValue);
2369     }
2370 }
2371 
2372 /*-- 09.12.98 14:18:55---------------------------------------------------
2373 
2374   -----------------------------------------------------------------------*/
2375 uno::Any SAL_CALL
2376 SwXTextCursor::getPropertyValue(const OUString& rPropertyName)
2377 throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2378         uno::RuntimeException)
2379 {
2380 	vos::OGuard aGuard(Application::GetSolarMutex());
2381 
2382     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2383 
2384 	uno::Any aAny;
2385     if (rPropertyName.equalsAsciiL(SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)))
2386     {
2387         const sal_Bool bSet = rUnoCursor.IsSkipOverHiddenSections();
2388         aAny <<= bSet;
2389     }
2390     else if (rPropertyName.equalsAsciiL(
2391                 SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT)))
2392     {
2393         const sal_Bool bSet = rUnoCursor.IsSkipOverProtectSections();
2394         aAny <<= bSet;
2395     }
2396     else
2397     {
2398         aAny = SwUnoCursorHelper::GetPropertyValue(rUnoCursor,
2399                 m_pImpl->m_rPropSet, rPropertyName);
2400     }
2401 	return aAny;
2402 }
2403 
2404 /*-- 09.12.98 14:18:55---------------------------------------------------
2405 
2406   -----------------------------------------------------------------------*/
2407 void SAL_CALL
2408 SwXTextCursor::addPropertyChangeListener(
2409         const ::rtl::OUString& /*rPropertyName*/,
2410         const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
2411 throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2412     uno::RuntimeException)
2413 {
2414     OSL_ENSURE(false,
2415         "SwXTextCursor::addPropertyChangeListener(): not implemented");
2416 }
2417 
2418 /*-- 09.12.98 14:18:57---------------------------------------------------
2419 
2420   -----------------------------------------------------------------------*/
2421 void SAL_CALL
2422 SwXTextCursor::removePropertyChangeListener(
2423         const ::rtl::OUString& /*rPropertyName*/,
2424         const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
2425 throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2426     uno::RuntimeException)
2427 {
2428     OSL_ENSURE(false,
2429         "SwXTextCursor::removePropertyChangeListener(): not implemented");
2430 }
2431 
2432 /*-- 09.12.98 14:18:57---------------------------------------------------
2433 
2434   -----------------------------------------------------------------------*/
2435 void SAL_CALL
2436 SwXTextCursor::addVetoableChangeListener(
2437         const ::rtl::OUString& /*rPropertyName*/,
2438         const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
2439 throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2440     uno::RuntimeException)
2441 {
2442     OSL_ENSURE(false,
2443         "SwXTextCursor::addVetoableChangeListener(): not implemented");
2444 }
2445 
2446 /*-- 09.12.98 14:18:58---------------------------------------------------
2447 
2448   -----------------------------------------------------------------------*/
2449 void SAL_CALL
2450 SwXTextCursor::removeVetoableChangeListener(
2451         const ::rtl::OUString& /*rPropertyName*/,
2452         const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
2453 throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2454         uno::RuntimeException)
2455 {
2456     OSL_ENSURE(false,
2457         "SwXTextCursor::removeVetoableChangeListener(): not implemented");
2458 }
2459 
2460 /*-- 05.03.99 11:36:11---------------------------------------------------
2461 
2462   -----------------------------------------------------------------------*/
2463 beans::PropertyState SAL_CALL
2464 SwXTextCursor::getPropertyState(const OUString& rPropertyName)
2465 throw (beans::UnknownPropertyException, uno::RuntimeException)
2466 {
2467 	vos::OGuard aGuard(Application::GetSolarMutex());
2468 
2469     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2470 
2471     const beans::PropertyState eRet = SwUnoCursorHelper::GetPropertyState(
2472             rUnoCursor, m_pImpl->m_rPropSet, rPropertyName);
2473     return eRet;
2474 }
2475 /*-- 05.03.99 11:36:11---------------------------------------------------
2476 
2477   -----------------------------------------------------------------------*/
2478 uno::Sequence< beans::PropertyState > SAL_CALL
2479 SwXTextCursor::getPropertyStates(
2480         const uno::Sequence< OUString >& rPropertyNames)
2481 throw (beans::UnknownPropertyException, uno::RuntimeException)
2482 {
2483 	vos::OGuard aGuard(Application::GetSolarMutex());
2484 
2485     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2486 
2487     return SwUnoCursorHelper::GetPropertyStates(
2488             rUnoCursor, m_pImpl->m_rPropSet, rPropertyNames);
2489 }
2490 
2491 /*-- 05.03.99 11:36:12---------------------------------------------------
2492 
2493   -----------------------------------------------------------------------*/
2494 void SAL_CALL
2495 SwXTextCursor::setPropertyToDefault(const OUString& rPropertyName)
2496 throw (beans::UnknownPropertyException, uno::RuntimeException)
2497 {
2498     // forward: need no solar mutex here
2499     uno::Sequence < OUString > aSequence ( &rPropertyName, 1 );
2500 	setPropertiesToDefault ( aSequence );
2501 }
2502 /*-- 05.03.99 11:36:12---------------------------------------------------
2503 
2504   -----------------------------------------------------------------------*/
2505 uno::Any SAL_CALL
2506 SwXTextCursor::getPropertyDefault(const OUString& rPropertyName)
2507 throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2508         uno::RuntimeException)
2509 {
2510     // forward: need no solar mutex here
2511     const uno::Sequence < OUString > aSequence ( &rPropertyName, 1 );
2512 	return getPropertyDefaults ( aSequence ).getConstArray()[0];
2513 }
2514 
2515 // para specific attribut ranges
2516 static sal_uInt16 g_ParaResetableSetRange[] = {
2517     RES_FRMATR_BEGIN, RES_FRMATR_END-1,
2518     RES_PARATR_BEGIN, RES_PARATR_END-1,
2519     // --> OD 2008-02-25 #refactorlists#
2520     RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1,
2521     // <--
2522     RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1,
2523     0
2524 };
2525 
2526 // selection specific attribut ranges
2527 static sal_uInt16 g_ResetableSetRange[] = {
2528     RES_CHRATR_BEGIN, RES_CHRATR_END-1,
2529     RES_TXTATR_INETFMT, RES_TXTATR_INETFMT,
2530     RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT,
2531     RES_TXTATR_CJK_RUBY, RES_TXTATR_CJK_RUBY,
2532     RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER,
2533     0
2534 };
2535 
2536 static void
2537 lcl_EnumerateIds(sal_uInt16 const* pIdRange, SvUShortsSort & rWhichIds)
2538 {
2539     while (*pIdRange)
2540     {
2541         const sal_uInt16 nStart = sal::static_int_cast<sal_uInt16>(*pIdRange++);
2542         const sal_uInt16 nEnd   = sal::static_int_cast<sal_uInt16>(*pIdRange++);
2543         for (sal_uInt16 nId = nStart + 1;  nId <= nEnd;  ++nId)
2544         {
2545             rWhichIds.Insert( nId );
2546         }
2547     }
2548 }
2549 
2550 void SAL_CALL
2551 SwXTextCursor::setAllPropertiesToDefault()
2552 throw (uno::RuntimeException)
2553 {
2554 	vos::OGuard aGuard(Application::GetSolarMutex());
2555 
2556     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2557 
2558     SvUShortsSort aParaWhichIds;
2559     SvUShortsSort aWhichIds;
2560     lcl_EnumerateIds(g_ParaResetableSetRange, aParaWhichIds);
2561     lcl_EnumerateIds(g_ResetableSetRange, aWhichIds);
2562     if (aParaWhichIds.Count())
2563     {
2564         lcl_SelectParaAndReset(rUnoCursor, *rUnoCursor.GetDoc(),
2565             &aParaWhichIds);
2566     }
2567     if (aWhichIds.Count())
2568     {
2569         rUnoCursor.GetDoc()->ResetAttrs(rUnoCursor, sal_True, &aWhichIds);
2570     }
2571 }
2572 
2573 void SAL_CALL
2574 SwXTextCursor::setPropertiesToDefault(
2575         const uno::Sequence< OUString >& rPropertyNames)
2576 throw (beans::UnknownPropertyException, uno::RuntimeException)
2577 {
2578 	vos::OGuard aGuard(Application::GetSolarMutex());
2579 
2580     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2581 
2582     const sal_Int32 nCount = rPropertyNames.getLength();
2583 	if ( nCount )
2584     {
2585         SwDoc & rDoc = *rUnoCursor.GetDoc();
2586         const OUString * pNames = rPropertyNames.getConstArray();
2587         SvUShortsSort aWhichIds;
2588         SvUShortsSort aParaWhichIds;
2589         for (sal_Int32 i = 0; i < nCount; i++)
2590         {
2591             SfxItemPropertySimpleEntry const*const  pEntry =
2592                 m_pImpl->m_rPropSet.getPropertyMap()->getByName( pNames[i] );
2593             if (!pEntry)
2594             {
2595                 if (pNames[i].equalsAsciiL(
2596                         SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)) ||
2597                     pNames[i].equalsAsciiL(
2598                         SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT)))
2599                 {
2600                     continue;
2601                 }
2602                 throw beans::UnknownPropertyException(
2603                     OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
2604                         + pNames[i],
2605                     static_cast<cppu::OWeakObject *>(this));
2606             }
2607             if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
2608             {
2609                 throw uno::RuntimeException(
2610                     OUString(RTL_CONSTASCII_USTRINGPARAM(
2611                             "setPropertiesToDefault: property is read-only: "))
2612                         + pNames[i],
2613                     static_cast<cppu::OWeakObject *>(this));
2614             }
2615 
2616             if (pEntry->nWID < RES_FRMATR_END)
2617             {
2618                 if (pEntry->nWID < RES_PARATR_BEGIN)
2619                 {
2620                     aWhichIds.Insert(pEntry->nWID);
2621                 }
2622                 else
2623                 {
2624                     aParaWhichIds.Insert(pEntry->nWID);
2625                 }
2626             }
2627             else if (pEntry->nWID == FN_UNO_NUM_START_VALUE)
2628             {
2629                 SwUnoCursorHelper::resetCrsrPropertyValue(*pEntry, rUnoCursor);
2630             }
2631         }
2632 
2633         if (aParaWhichIds.Count())
2634         {
2635             lcl_SelectParaAndReset(rUnoCursor, rDoc, &aParaWhichIds);
2636         }
2637         if (aWhichIds.Count())
2638         {
2639             rDoc.ResetAttrs(rUnoCursor, sal_True, &aWhichIds);
2640         }
2641     }
2642 }
2643 
2644 uno::Sequence< uno::Any > SAL_CALL
2645 SwXTextCursor::getPropertyDefaults(
2646         const uno::Sequence< OUString >& rPropertyNames)
2647 throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2648         uno::RuntimeException)
2649 {
2650 	vos::OGuard aGuard(Application::GetSolarMutex());
2651 
2652     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2653 
2654     const sal_Int32 nCount = rPropertyNames.getLength();
2655     uno::Sequence< uno::Any > aRet(nCount);
2656 	if ( nCount )
2657     {
2658         SwDoc & rDoc = *rUnoCursor.GetDoc();
2659         const OUString *pNames = rPropertyNames.getConstArray();
2660         uno::Any *pAny = aRet.getArray();
2661         for (sal_Int32 i = 0; i < nCount; i++)
2662         {
2663             SfxItemPropertySimpleEntry const*const pEntry =
2664                 m_pImpl->m_rPropSet.getPropertyMap()->getByName( pNames[i] );
2665             if (!pEntry)
2666             {
2667                 if (pNames[i].equalsAsciiL(
2668                         SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)) ||
2669                     pNames[i].equalsAsciiL(
2670                         SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT)))
2671                 {
2672                     continue;
2673                 }
2674                 throw beans::UnknownPropertyException(
2675                     OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
2676                         + pNames[i],
2677                     static_cast<cppu::OWeakObject *>(0));
2678             }
2679             if (pEntry->nWID < RES_FRMATR_END)
2680             {
2681                 const SfxPoolItem& rDefItem =
2682                     rDoc.GetAttrPool().GetDefaultItem(pEntry->nWID);
2683                 rDefItem.QueryValue(pAny[i], pEntry->nMemberId);
2684             }
2685         }
2686     }
2687 	return aRet;
2688 }
2689 
2690 /*-- 10.03.2008 09:58:47---------------------------------------------------
2691 
2692   -----------------------------------------------------------------------*/
2693 void SAL_CALL
2694 SwXTextCursor::makeRedline(
2695     const ::rtl::OUString& rRedlineType,
2696     const uno::Sequence< beans::PropertyValue >& rRedlineProperties)
2697 throw (lang::IllegalArgumentException, uno::RuntimeException)
2698 {
2699     vos::OGuard aGuard(Application::GetSolarMutex());
2700 
2701     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2702 
2703     SwUnoCursorHelper::makeRedline(rUnoCursor, rRedlineType, rRedlineProperties);
2704 }
2705 
2706 /*-- 09.12.98 14:18:58---------------------------------------------------
2707 
2708   -----------------------------------------------------------------------*/
2709 void SAL_CALL SwXTextCursor::insertDocumentFromURL(const OUString& rURL,
2710     const uno::Sequence< beans::PropertyValue >& rOptions)
2711 throw (lang::IllegalArgumentException, io::IOException,
2712         uno::RuntimeException)
2713 {
2714     vos::OGuard aGuard(Application::GetSolarMutex());
2715 
2716     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2717 
2718     SwUnoCursorHelper::InsertFile(&rUnoCursor, rURL, rOptions);
2719 }
2720 
2721 /* -----------------------------15.12.00 14:01--------------------------------
2722 
2723  ---------------------------------------------------------------------------*/
2724 uno::Sequence< beans::PropertyValue >
2725 SwUnoCursorHelper::CreateSortDescriptor(const bool bFromTable)
2726 {
2727     uno::Sequence< beans::PropertyValue > aRet(5);
2728     beans::PropertyValue* pArray = aRet.getArray();
2729 
2730     uno::Any aVal;
2731     aVal.setValue( &bFromTable, ::getCppuBooleanType());
2732     pArray[0] = beans::PropertyValue(C2U("IsSortInTable"), -1, aVal,
2733                     beans::PropertyState_DIRECT_VALUE);
2734 
2735     aVal <<= sal_Unicode(' ');
2736     pArray[1] = beans::PropertyValue(C2U("Delimiter"), -1, aVal,
2737                     beans::PropertyState_DIRECT_VALUE);
2738 
2739     aVal <<= (sal_Bool) sal_False;
2740     pArray[2] = beans::PropertyValue(C2U("IsSortColumns"), -1, aVal,
2741                     beans::PropertyState_DIRECT_VALUE);
2742 
2743     aVal <<= (sal_Int32) 3;
2744     pArray[3] = beans::PropertyValue(C2U("MaxSortFieldsCount"), -1, aVal,
2745                     beans::PropertyState_DIRECT_VALUE);
2746 
2747     uno::Sequence< table::TableSortField > aFields(3);
2748     table::TableSortField* pFields = aFields.getArray();
2749 
2750     lang::Locale aLang( SvxCreateLocale( LANGUAGE_SYSTEM ) );
2751     // get collator algorithm to be used for the locale
2752     uno::Sequence< OUString > aSeq(
2753             GetAppCollator().listCollatorAlgorithms( aLang ) );
2754     const sal_Int32 nLen = aSeq.getLength();
2755     DBG_ASSERT( nLen > 0, "list of collator algorithms is empty!");
2756     OUString aCollAlg;
2757     if (nLen > 0)
2758     {
2759         aCollAlg = aSeq.getConstArray()[0];
2760     }
2761 
2762 #if OSL_DEBUG_LEVEL > 1
2763     const OUString *pTxt = aSeq.getConstArray();
2764     (void)pTxt;
2765 #endif
2766 
2767     pFields[0].Field = 1;
2768     pFields[0].IsAscending = sal_True;
2769     pFields[0].IsCaseSensitive = sal_False;
2770     pFields[0].FieldType = table::TableSortFieldType_ALPHANUMERIC;
2771     pFields[0].CollatorLocale = aLang;
2772     pFields[0].CollatorAlgorithm = aCollAlg;
2773 
2774     pFields[1].Field = 1;
2775     pFields[1].IsAscending = sal_True;
2776     pFields[1].IsCaseSensitive = sal_False;
2777     pFields[1].FieldType = table::TableSortFieldType_ALPHANUMERIC;
2778     pFields[1].CollatorLocale = aLang;
2779     pFields[1].CollatorAlgorithm = aCollAlg;
2780 
2781     pFields[2].Field = 1;
2782     pFields[2].IsAscending = sal_True;
2783     pFields[2].IsCaseSensitive = sal_False;
2784     pFields[2].FieldType = table::TableSortFieldType_ALPHANUMERIC;
2785     pFields[2].CollatorLocale = aLang;
2786     pFields[2].CollatorAlgorithm = aCollAlg;
2787 
2788     aVal <<= aFields;
2789     pArray[4] = beans::PropertyValue(C2U("SortFields"), -1, aVal,
2790                     beans::PropertyState_DIRECT_VALUE);
2791 
2792     return aRet;
2793 }
2794 
2795 /*-- 09.12.98 14:18:58---------------------------------------------------
2796 
2797   -----------------------------------------------------------------------*/
2798 uno::Sequence< beans::PropertyValue > SAL_CALL
2799 SwXTextCursor::createSortDescriptor() throw (uno::RuntimeException)
2800 {
2801     vos::OGuard aGuard(Application::GetSolarMutex());
2802 
2803     return SwUnoCursorHelper::CreateSortDescriptor(false);
2804 }
2805 
2806 /* -----------------------------15.12.00 14:06--------------------------------
2807 
2808  ---------------------------------------------------------------------------*/
2809 sal_Bool SwUnoCursorHelper::ConvertSortProperties(
2810     const uno::Sequence< beans::PropertyValue >& rDescriptor,
2811     SwSortOptions& rSortOpt)
2812 {
2813     sal_Bool bRet = sal_True;
2814     const beans::PropertyValue* pProperties = rDescriptor.getConstArray();
2815 
2816     rSortOpt.bTable = sal_False;
2817     rSortOpt.cDeli = ' ';
2818     rSortOpt.eDirection = SRT_COLUMNS;  //!! UI text may be contrary though !!
2819 
2820     SwSortKey* pKey1 = new SwSortKey;
2821     pKey1->nColumnId = USHRT_MAX;
2822     pKey1->bIsNumeric = sal_True;
2823     pKey1->eSortOrder = SRT_ASCENDING;
2824 
2825     SwSortKey* pKey2 = new SwSortKey;
2826     pKey2->nColumnId = USHRT_MAX;
2827     pKey2->bIsNumeric = sal_True;
2828     pKey2->eSortOrder = SRT_ASCENDING;
2829 
2830     SwSortKey* pKey3 = new SwSortKey;
2831     pKey3->nColumnId = USHRT_MAX;
2832     pKey3->bIsNumeric = sal_True;
2833     pKey3->eSortOrder = SRT_ASCENDING;
2834     SwSortKey* aKeys[3] = {pKey1, pKey2, pKey3};
2835 
2836     sal_Bool bOldSortdescriptor(sal_False);
2837     sal_Bool bNewSortdescriptor(sal_False);
2838 
2839     for (sal_Int32 n = 0; n < rDescriptor.getLength(); ++n)
2840     {
2841         uno::Any aValue( pProperties[n].Value );
2842 //      String sPropName = pProperties[n].Name;
2843         const OUString& rPropName = pProperties[n].Name;
2844 
2845         // old and new sortdescriptor
2846         if (rPropName.equalsAscii("IsSortInTable"))
2847         {
2848             if (aValue.getValueType() == ::getBooleanCppuType())
2849             {
2850                 rSortOpt.bTable = *(sal_Bool*)aValue.getValue();
2851             }
2852             else
2853             {
2854                 bRet = sal_False;
2855             }
2856         }
2857         else if (rPropName.equalsAscii("Delimiter"))
2858         {
2859             sal_Unicode uChar = sal_Unicode();
2860             if (aValue >>= uChar)
2861             {
2862                 rSortOpt.cDeli = uChar;
2863             }
2864             else
2865             {
2866                 bRet = sal_False;
2867             }
2868         }
2869         // old sortdescriptor
2870         else if (rPropName.equalsAscii("SortColumns"))
2871         {
2872             bOldSortdescriptor = sal_True;
2873             sal_Bool bTemp(sal_False);
2874             if (aValue >>= bTemp)
2875             {
2876                 rSortOpt.eDirection = bTemp ? SRT_COLUMNS : SRT_ROWS;
2877             }
2878             else
2879             {
2880                 bRet = sal_False;
2881             }
2882         }
2883         else if ( rPropName.equalsAscii("IsCaseSensitive"))
2884         {
2885             bOldSortdescriptor = sal_True;
2886             sal_Bool bTemp(sal_False);
2887             if (aValue >>= bTemp)
2888             {
2889                 rSortOpt.bIgnoreCase = !bTemp;
2890             }
2891             else
2892             {
2893                 bRet = sal_False;
2894             }
2895         }
2896         else if (rPropName.equalsAscii("CollatorLocale"))
2897         {
2898             bOldSortdescriptor = sal_True;
2899             lang::Locale aLocale;
2900             if (aValue >>= aLocale)
2901             {
2902                 rSortOpt.nLanguage = SvxLocaleToLanguage( aLocale );
2903             }
2904             else
2905             {
2906                 bRet = sal_False;
2907             }
2908         }
2909         else if (rPropName.matchAsciiL("CollatorAlgorithm", 17) &&
2910             rPropName.getLength() == 18 &&
2911             (rPropName.getStr()[17] >= '0' && rPropName.getStr()[17] <= '9'))
2912         {
2913             bOldSortdescriptor = sal_True;
2914             sal_uInt16 nIndex = rPropName.getStr()[17];
2915             nIndex -= '0';
2916             OUString aTxt;
2917             if ((aValue >>= aTxt) && nIndex < 3)
2918             {
2919                 aKeys[nIndex]->sSortType = aTxt;
2920             }
2921             else
2922             {
2923                 bRet = sal_False;
2924             }
2925         }
2926         else if (rPropName.matchAsciiL("SortRowOrColumnNo", 17) &&
2927             rPropName.getLength() == 18 &&
2928             (rPropName.getStr()[17] >= '0' && rPropName.getStr()[17] <= '9'))
2929         {
2930             bOldSortdescriptor = sal_True;
2931             sal_uInt16 nIndex = rPropName.getStr()[17];
2932             nIndex -= '0';
2933             sal_Int16 nCol = -1;
2934             if (aValue.getValueType() == ::getCppuType((const sal_Int16*)0)
2935                 && nIndex < 3)
2936             {
2937                 aValue >>= nCol;
2938             }
2939             if (nCol >= 0)
2940             {
2941                 aKeys[nIndex]->nColumnId = nCol;
2942             }
2943             else
2944             {
2945                 bRet = sal_False;
2946             }
2947         }
2948         else if (0 == rPropName.indexOf(C2U("IsSortNumeric")) &&
2949             rPropName.getLength() == 14 &&
2950             (rPropName.getStr()[13] >= '0' && rPropName.getStr()[13] <= '9'))
2951         {
2952             bOldSortdescriptor = sal_True;
2953             sal_uInt16 nIndex = rPropName.getStr()[13];
2954             nIndex = nIndex - '0';
2955             if (aValue.getValueType() == ::getBooleanCppuType() && nIndex < 3)
2956             {
2957                 sal_Bool bTemp = *(sal_Bool*)aValue.getValue();
2958                 aKeys[nIndex]->bIsNumeric = bTemp;
2959             }
2960             else
2961             {
2962                 bRet = sal_False;
2963             }
2964         }
2965         else if (0 == rPropName.indexOf(C2U("IsSortAscending")) &&
2966             rPropName.getLength() == 16 &&
2967             (rPropName.getStr()[15] >= '0' && rPropName.getStr()[15] <= '9'))
2968         {
2969             bOldSortdescriptor = sal_True;
2970             sal_uInt16 nIndex = rPropName.getStr()[15];
2971             nIndex -= '0';
2972             if (aValue.getValueType() == ::getBooleanCppuType() && nIndex < 3)
2973             {
2974                 sal_Bool bTemp = *(sal_Bool*)aValue.getValue();
2975                 aKeys[nIndex]->eSortOrder = (bTemp)
2976                     ? SRT_ASCENDING : SRT_DESCENDING;
2977             }
2978             else
2979             {
2980                 bRet = sal_False;
2981             }
2982         }
2983         // new sortdescriptor
2984         else if (rPropName.equalsAscii("IsSortColumns"))
2985         {
2986             bNewSortdescriptor = sal_True;
2987             if (aValue.getValueType() == ::getBooleanCppuType())
2988             {
2989                 sal_Bool bTemp = *(sal_Bool*)aValue.getValue();
2990                 rSortOpt.eDirection = bTemp ? SRT_COLUMNS : SRT_ROWS;
2991             }
2992             else
2993             {
2994                 bRet = sal_False;
2995             }
2996         }
2997         else if (rPropName.equalsAscii("SortFields"))
2998         {
2999             bNewSortdescriptor = sal_True;
3000             uno::Sequence < table::TableSortField > aFields;
3001             if (aValue >>= aFields)
3002             {
3003                 sal_Int32 nCount(aFields.getLength());
3004                 if (nCount <= 3)
3005                 {
3006                     table::TableSortField* pFields = aFields.getArray();
3007                     for (sal_Int32 i = 0; i < nCount; ++i)
3008                     {
3009                         rSortOpt.bIgnoreCase = !pFields[i].IsCaseSensitive;
3010                         rSortOpt.nLanguage =
3011                             SvxLocaleToLanguage( pFields[i].CollatorLocale );
3012                         aKeys[i]->sSortType = pFields[i].CollatorAlgorithm;
3013                         aKeys[i]->nColumnId =
3014                             static_cast<sal_uInt16>(pFields[i].Field);
3015                         aKeys[i]->bIsNumeric = (pFields[i].FieldType ==
3016                                 table::TableSortFieldType_NUMERIC);
3017                         aKeys[i]->eSortOrder = (pFields[i].IsAscending)
3018                             ? SRT_ASCENDING : SRT_DESCENDING;
3019                     }
3020                 }
3021                 else
3022                 {
3023                     bRet = sal_False;
3024                 }
3025             }
3026             else
3027             {
3028                 bRet = sal_False;
3029             }
3030         }
3031     }
3032 
3033     if (bNewSortdescriptor && bOldSortdescriptor)
3034     {
3035         DBG_ERROR("someone tried to set the old deprecated and "
3036             "the new sortdescriptor");
3037         bRet = sal_False;
3038     }
3039 
3040     if (pKey1->nColumnId != USHRT_MAX)
3041     {
3042         rSortOpt.aKeys.C40_INSERT(SwSortKey, pKey1, rSortOpt.aKeys.Count());
3043     }
3044     if (pKey2->nColumnId != USHRT_MAX)
3045     {
3046         rSortOpt.aKeys.C40_INSERT(SwSortKey, pKey2, rSortOpt.aKeys.Count());
3047     }
3048     if (pKey3->nColumnId != USHRT_MAX)
3049     {
3050         rSortOpt.aKeys.C40_INSERT(SwSortKey, pKey3, rSortOpt.aKeys.Count());
3051     }
3052 
3053     return bRet && rSortOpt.aKeys.Count() > 0;
3054 }
3055 
3056 /*-- 09.12.98 14:19:00---------------------------------------------------
3057 
3058   -----------------------------------------------------------------------*/
3059 void SAL_CALL
3060 SwXTextCursor::sort(const uno::Sequence< beans::PropertyValue >& rDescriptor)
3061 throw (uno::RuntimeException)
3062 {
3063     vos::OGuard aGuard(Application::GetSolarMutex());
3064 
3065     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
3066 
3067     if (rUnoCursor.HasMark())
3068     {
3069         SwSortOptions aSortOpt;
3070         if (!SwUnoCursorHelper::ConvertSortProperties(rDescriptor, aSortOpt))
3071         {
3072             throw uno::RuntimeException();
3073         }
3074         UnoActionContext aContext( rUnoCursor.GetDoc() );
3075 
3076         SwPosition & rStart = *rUnoCursor.Start();
3077         SwPosition & rEnd   = *rUnoCursor.End();
3078 
3079         SwNodeIndex aPrevIdx( rStart.nNode, -1 );
3080         const sal_uLong nOffset = rEnd.nNode.GetIndex() - rStart.nNode.GetIndex();
3081         const xub_StrLen nCntStt  = rStart.nContent.GetIndex();
3082 
3083         rUnoCursor.GetDoc()->SortText(rUnoCursor, aSortOpt);
3084 
3085         // Selektion wieder setzen
3086         rUnoCursor.DeleteMark();
3087         rUnoCursor.GetPoint()->nNode.Assign( aPrevIdx.GetNode(), +1 );
3088         SwCntntNode *const pCNd = rUnoCursor.GetCntntNode();
3089         xub_StrLen nLen = pCNd->Len();
3090         if (nLen > nCntStt)
3091         {
3092             nLen = nCntStt;
3093         }
3094         rUnoCursor.GetPoint()->nContent.Assign(pCNd, nLen );
3095         rUnoCursor.SetMark();
3096 
3097         rUnoCursor.GetPoint()->nNode += nOffset;
3098         SwCntntNode *const pCNd2 = rUnoCursor.GetCntntNode();
3099         rUnoCursor.GetPoint()->nContent.Assign( pCNd2, pCNd2->Len() );
3100     }
3101 }
3102 
3103 /* -----------------------------03.04.00 09:11--------------------------------
3104 
3105  ---------------------------------------------------------------------------*/
3106 uno::Reference< container::XEnumeration > SAL_CALL
3107 SwXTextCursor::createContentEnumeration(const OUString& rServiceName)
3108 throw (uno::RuntimeException)
3109 {
3110     vos::OGuard g(Application::GetSolarMutex());
3111 
3112     if (!rServiceName.equalsAscii("com.sun.star.text.TextContent"))
3113     {
3114         throw uno::RuntimeException();
3115     }
3116 
3117     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
3118 
3119     uno::Reference< container::XEnumeration > xRet =
3120         new SwXParaFrameEnumeration(rUnoCursor, PARAFRAME_PORTION_TEXTRANGE);
3121     return xRet;
3122 }
3123 
3124 /* -----------------------------07.03.01 14:53--------------------------------
3125 
3126  ---------------------------------------------------------------------------*/
3127 uno::Reference< container::XEnumeration > SAL_CALL
3128 SwXTextCursor::createEnumeration() throw (uno::RuntimeException)
3129 {
3130     vos::OGuard g(Application::GetSolarMutex());
3131 
3132     SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
3133 
3134     const uno::Reference<lang::XUnoTunnel> xTunnel(
3135             m_pImpl->m_xParentText, uno::UNO_QUERY);
3136     SwXText* pParentText = 0;
3137     if (xTunnel.is())
3138     {
3139         pParentText = ::sw::UnoTunnelGetImplementation<SwXText>(xTunnel);
3140     }
3141     DBG_ASSERT(pParentText, "parent is not a SwXText");
3142     if (!pParentText)
3143     {
3144         throw uno::RuntimeException();
3145     }
3146 
3147     ::std::auto_ptr<SwUnoCrsr> pNewCrsr(
3148         rUnoCursor.GetDoc()->CreateUnoCrsr(*rUnoCursor.GetPoint()) );
3149     if (rUnoCursor.HasMark())
3150     {
3151         pNewCrsr->SetMark();
3152         *pNewCrsr->GetMark() = *rUnoCursor.GetMark();
3153     }
3154     const CursorType eSetType = (CURSOR_TBLTEXT == m_pImpl->m_eType)
3155             ? CURSOR_SELECTION_IN_TABLE : CURSOR_SELECTION;
3156     SwTableNode const*const pStartNode( (CURSOR_TBLTEXT == m_pImpl->m_eType)
3157             ? rUnoCursor.GetPoint()->nNode.GetNode().FindTableNode()
3158             : 0);
3159     SwTable const*const pTable(
3160             (pStartNode) ? & pStartNode->GetTable() : 0 );
3161     const uno::Reference< container::XEnumeration > xRet =
3162         new SwXParagraphEnumeration(
3163                 pParentText, pNewCrsr, eSetType, pStartNode, pTable);
3164 
3165     return xRet;
3166 }
3167 
3168 /* -----------------------------07.03.01 15:43--------------------------------
3169 
3170  ---------------------------------------------------------------------------*/
3171 uno::Type SAL_CALL
3172 SwXTextCursor::getElementType() throw (uno::RuntimeException)
3173 {
3174     return text::XTextRange::static_type();
3175 }
3176 
3177 /* -----------------------------07.03.01 15:43--------------------------------
3178 
3179  ---------------------------------------------------------------------------*/
3180 sal_Bool SAL_CALL SwXTextCursor::hasElements() throw (uno::RuntimeException)
3181 {
3182     return sal_True;
3183 }
3184 
3185 /* -----------------------------03.04.00 09:11--------------------------------
3186 
3187  ---------------------------------------------------------------------------*/
3188 uno::Sequence< OUString > SAL_CALL
3189 SwXTextCursor::getAvailableServiceNames() throw (uno::RuntimeException)
3190 {
3191     uno::Sequence< OUString > aRet(1);
3192     OUString* pArray = aRet.getArray();
3193     pArray[0] = OUString::createFromAscii("com.sun.star.text.TextContent");
3194     return aRet;
3195 }
3196 
3197 // ---------------------------------------------------------------------------
3198 IMPLEMENT_FORWARD_REFCOUNT( SwXTextCursor,SwXTextCursor_Base )
3199 
3200 uno::Any SAL_CALL
3201 SwXTextCursor::queryInterface(const uno::Type& rType)
3202 throw (uno::RuntimeException)
3203 {
3204     return (rType == lang::XUnoTunnel::static_type())
3205         ? OTextCursorHelper::queryInterface(rType)
3206         : SwXTextCursor_Base::queryInterface(rType);
3207 }
3208 
3209