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