update dev300-m58
[ooovba.git] / sw / source / core / unocore / unoobj.cxx
blobd03c6b67c8cc039635090f9a7bc637f89fda4f1c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unoobj.cxx,v $
10 * $Revision: 1.111.80.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <osl/endian.h>
36 #include <rtl/ustrbuf.hxx>
37 #include <swtypes.hxx>
38 #include <hintids.hxx>
39 #include <cmdid.h>
40 #include <hints.hxx>
41 #include <IMark.hxx>
42 #include <frmfmt.hxx>
43 #include <doc.hxx>
44 #include <istyleaccess.hxx>
45 #include <ndtxt.hxx>
46 #include <ndnotxt.hxx>
47 #include <unocrsrhelper.hxx>
48 #include <swundo.hxx>
49 #include <rootfrm.hxx>
50 #include <flyfrm.hxx>
51 #include <ftnidx.hxx>
52 #include <sfx2/linkmgr.hxx>
53 #include <docary.hxx>
54 #include <paratr.hxx>
55 #include <tools/urlobj.hxx>
56 #include <pam.hxx>
57 #include <tools/cachestr.hxx>
58 #include <shellio.hxx>
59 #include <swerror.h>
60 #include <swtblfmt.hxx>
61 #include <fmtruby.hxx>
62 #include <fmthbsh.hxx>
63 #include <docsh.hxx>
64 #include <docstyle.hxx>
65 #include <charfmt.hxx>
66 #include <txtfld.hxx>
67 #include <fmtfld.hxx>
68 #include <fmtpdsc.hxx>
69 #include <pagedesc.hxx>
70 #ifndef _POOLFMT_HRC
71 #include <poolfmt.hrc>
72 #endif
73 #include <poolfmt.hxx>
74 #include <edimp.hxx>
75 #include <fchrfmt.hxx>
76 #include <fmtautofmt.hxx>
77 #include <cntfrm.hxx>
78 #include <pagefrm.hxx>
79 #include <doctxm.hxx>
80 #include <sfx2/docfilt.hxx>
81 #include <sfx2/docfile.hxx>
82 #include <sfx2/fcontnr.hxx>
83 #include <fmtrfmrk.hxx>
84 #include <txtrfmrk.hxx>
85 #include <unoclbck.hxx>
86 #include <unoobj.hxx>
87 #include <unomap.hxx>
88 #include <unosett.hxx>
89 #include <unoprnms.hxx>
90 #include <unotbl.hxx>
91 #include <unodraw.hxx>
92 #include <unocoll.hxx>
93 #include <unostyle.hxx>
94 #include <unofield.hxx>
95 #include <fmtanchr.hxx>
96 #include <svx/flstitem.hxx>
97 #include <svtools/ctrltool.hxx>
98 #include <flypos.hxx>
99 #include <txtftn.hxx>
100 #include <fmtftn.hxx>
101 #include <com/sun/star/text/WrapTextMode.hpp>
102 #include <com/sun/star/text/TextContentAnchorType.hpp>
103 #include <com/sun/star/style/PageStyleLayout.hpp>
104 #include <com/sun/star/text/XTextDocument.hpp>
105 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
106 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
107 #include <unoidx.hxx>
108 #include <unoframe.hxx>
109 #include <fmthdft.hxx>
110 #include <vos/mutex.hxx>
111 #include <vcl/svapp.hxx>
112 #include <fmtflcnt.hxx>
113 #define _SVSTDARR_USHORTS
114 #define _SVSTDARR_USHORTSSORT
115 #include <svtools/svstdarr.hxx>
116 #include <svx/brshitem.hxx>
117 #include <fmtclds.hxx>
118 #include <dcontact.hxx>
119 #include <SwStyleNameMapper.hxx>
120 #include <crsskip.hxx>
121 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPPP_
122 #include <com/sun/star/beans/PropertyAttribute.hpp>
123 #endif
124 #include <memory>
126 using namespace ::com::sun::star;
127 using namespace ::com::sun::star::uno;
128 using namespace ::com::sun::star::lang;
129 using namespace ::com::sun::star::uno;
130 using namespace ::com::sun::star::text;
131 using namespace ::com::sun::star::container;
132 using namespace ::com::sun::star::beans;
133 using namespace ::com::sun::star::drawing;
134 using std::auto_ptr;
135 using ::rtl::OUString;
136 using ::rtl::OUStringBuffer;
138 /****************************************************************************
139 static methods
140 ****************************************************************************/
141 uno::Sequence< sal_Int8 > CreateUnoTunnelId()
143 static osl::Mutex aCreateMutex;
144 osl::Guard<osl::Mutex> aGuard( aCreateMutex );
145 uno::Sequence< sal_Int8 > aSeq( 16 );
146 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
147 return aSeq;
149 /****************************************************************************
150 Hilfsklassen
151 ****************************************************************************/
153 /* -----------------13.05.98 12:15-------------------
155 * --------------------------------------------------*/
156 SwUnoInternalPaM::SwUnoInternalPaM(SwDoc& rDoc) :
157 SwPaM(rDoc.GetNodes())
160 SwUnoInternalPaM::~SwUnoInternalPaM()
162 while( GetNext() != this)
164 delete GetNext();
168 SwUnoInternalPaM& SwUnoInternalPaM::operator=(const SwPaM& rPaM)
170 const SwPaM* pTmp = &rPaM;
171 *GetPoint() = *rPaM.GetPoint();
172 if(rPaM.HasMark())
174 SetMark();
175 *GetMark() = *rPaM.GetMark();
177 else
178 DeleteMark();
179 while(&rPaM != (pTmp = (const SwPaM*)pTmp->GetNext()))
181 if(pTmp->HasMark())
182 new SwPaM(*pTmp->GetMark(), *pTmp->GetPoint(), this);
183 else
184 new SwPaM(*pTmp->GetPoint(), this);
186 return *this;
188 /****************************************************************************
189 ActionContext
190 ****************************************************************************/
191 UnoActionContext::UnoActionContext(SwDoc* pDc) :
192 pDoc(pDc)
194 SwRootFrm* pRootFrm = pDoc->GetRootFrm();
195 if(pRootFrm)
196 pRootFrm->StartAllAction();
198 /*-----------------04.03.98 11:56-------------------
200 --------------------------------------------------*/
201 UnoActionContext::~UnoActionContext()
203 //das Doc kann hier schon entfernt worden sein
204 if(pDoc)
206 SwRootFrm* pRootFrm = pDoc->GetRootFrm();
207 if(pRootFrm)
208 pRootFrm->EndAllAction();
212 /****************************************************************************
213 ActionRemoveContext
214 ****************************************************************************/
215 UnoActionRemoveContext::UnoActionRemoveContext(SwDoc* pDc) :
216 pDoc(pDc)
218 SwRootFrm* pRootFrm = pDoc->GetRootFrm();
219 if(pRootFrm)
220 pRootFrm->UnoRemoveAllActions();
222 /* -----------------07.07.98 12:05-------------------
224 * --------------------------------------------------*/
225 UnoActionRemoveContext::~UnoActionRemoveContext()
227 SwRootFrm* pRootFrm = pDoc->GetRootFrm();
228 if(pRootFrm)
229 pRootFrm->UnoRestoreAllActions();
233 /*-----------------09.03.98 08:29-------------------
235 --------------------------------------------------*/
236 void SwXTextCursor::SelectPam(SwPaM& rCrsr, sal_Bool bExpand)
238 if(bExpand)
240 if(!rCrsr.HasMark())
241 rCrsr.SetMark();
243 else if(rCrsr.HasMark())
244 rCrsr.DeleteMark();
248 /* -----------------20.05.98 14:59-------------------
250 * --------------------------------------------------*/
251 void SwXTextCursor::getTextFromPam(SwPaM& aCrsr, OUString& rBuffer)
253 if(!aCrsr.HasMark())
254 return;
255 SvCacheStream aStream( 20480 );
256 #ifdef OSL_BIGENDIAN
257 aStream.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
258 #else
259 aStream.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
260 #endif
261 WriterRef xWrt;
262 // TODO/MBA: looks like a BaseURL doesn't make sense here
263 SwReaderWriter::GetWriter( C2S(FILTER_TEXT_DLG), String(), xWrt );
264 if( xWrt.Is() )
266 SwWriter aWriter( aStream, aCrsr );
267 xWrt->bASCII_NoLastLineEnd = sal_True;
268 xWrt->bExportPargraphNumbering = sal_False;
269 SwAsciiOptions aOpt = xWrt->GetAsciiOptions();
270 aOpt.SetCharSet( RTL_TEXTENCODING_UNICODE );
271 xWrt->SetAsciiOptions( aOpt );
272 xWrt->bUCS2_WithStartChar = FALSE;
273 // --> FME #i68522#
274 const BOOL bOldShowProgress = xWrt->bShowProgress;
275 xWrt->bShowProgress = FALSE;
276 // <--
278 long lLen;
279 if( !IsError( aWriter.Write( xWrt ) ) &&
280 0x7ffffff > (( lLen = aStream.GetSize() )
281 / sizeof( sal_Unicode )) + 1 )
283 aStream << (sal_Unicode)'\0';
285 long lUniLen = (lLen / sizeof( sal_Unicode ));
286 ::rtl::OUStringBuffer aStrBuffer( lUniLen );
287 aStream.Seek( 0 );
288 aStream.ResetError();
289 while(lUniLen)
291 String sBuf;
292 sal_Int32 nLocalLen = 0;
293 if( lUniLen >= STRING_MAXLEN )
294 nLocalLen = STRING_MAXLEN - 1;
295 else
296 nLocalLen = lUniLen;
297 sal_Unicode* pStrBuf = sBuf.AllocBuffer( xub_StrLen( nLocalLen + 1));
298 aStream.Read( pStrBuf, 2 * nLocalLen );
299 pStrBuf[ nLocalLen ] = '\0';
300 aStrBuffer.append( pStrBuf, nLocalLen );
301 lUniLen -= nLocalLen;
303 rBuffer = aStrBuffer.makeStringAndClear();
305 xWrt->bShowProgress = bOldShowProgress;
309 /* -----------------06.07.98 07:33-------------------
311 * --------------------------------------------------*/
312 void lcl_setCharStyle(SwDoc* pDoc, const uno::Any aValue, SfxItemSet& rSet)
313 throw (lang::IllegalArgumentException)
315 SwDocShell* pDocSh = pDoc->GetDocShell();
316 if(pDocSh)
318 OUString uStyle;
319 aValue >>= uStyle;
320 String sStyle;
321 SwStyleNameMapper::FillUIName(uStyle, sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
322 SwDocStyleSheet* pStyle =
323 (SwDocStyleSheet*)pDocSh->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_CHAR);
324 if(pStyle)
326 SwFmtCharFmt aFmt(pStyle->GetCharFmt());
327 rSet.Put(aFmt);
329 else
331 throw lang::IllegalArgumentException();
336 /* -----------------08.06.06 10:43-------------------
338 * --------------------------------------------------*/
339 void lcl_setAutoStyle(IStyleAccess& rStyleAccess, const uno::Any aValue, SfxItemSet& rSet, bool bPara )
340 throw (lang::IllegalArgumentException)
342 OUString uStyle;
343 aValue >>= uStyle;
344 String sStyle;
345 StylePool::SfxItemSet_Pointer_t pStyle = bPara ?
346 rStyleAccess.getByName(uStyle, IStyleAccess::AUTO_STYLE_PARA ):
347 rStyleAccess.getByName(uStyle, IStyleAccess::AUTO_STYLE_CHAR );
348 if(pStyle.get())
350 SwFmtAutoFmt aFmt( bPara ? sal::static_int_cast< USHORT >(RES_AUTO_STYLE)
351 : sal::static_int_cast< USHORT >(RES_TXTATR_AUTOFMT) );
352 aFmt.SetStyleHandle( pStyle );
353 rSet.Put(aFmt);
355 else
357 throw lang::IllegalArgumentException();
360 /* -----------------30.06.98 08:46-------------------
362 * --------------------------------------------------*/
363 void lcl_SetTxtFmtColl(const uno::Any& rAny, SwPaM& rPaM)
364 throw (lang::IllegalArgumentException)
366 SwDoc* pDoc = rPaM.GetDoc();
367 SwDocShell* pDocSh = pDoc->GetDocShell();
368 if(!pDocSh)
369 return;
370 OUString uStyle;
371 rAny >>= uStyle;
372 String sStyle;
373 SwStyleNameMapper::FillUIName(uStyle, sStyle, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True );
374 SwDocStyleSheet* pStyle =
375 (SwDocStyleSheet*)pDocSh->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_PARA);
376 if(pStyle)
378 SwTxtFmtColl *pLocal = pStyle->GetCollection();
379 UnoActionContext aAction(pDoc);
380 pDoc->StartUndo( UNDO_START, NULL );
381 FOREACHUNOPAM_START(&rPaM)
382 pDoc->SetTxtFmtColl(*PUNOPAM, pLocal);
383 FOREACHUNOPAM_END()
384 pDoc->EndUndo( UNDO_END, NULL );
386 else
388 throw lang::IllegalArgumentException();
392 /* -----------------06.07.98 07:38-------------------
394 * --------------------------------------------------*/
395 void lcl_setPageDesc(SwDoc* pDoc, const uno::Any& aValue, SfxItemSet& rSet)
397 if(aValue.getValueType() != ::getCppuType((const OUString*)0))
398 return;
399 SwFmtPageDesc *pNewDesc = 0 ;
400 const SfxPoolItem* pItem;
401 if(SFX_ITEM_SET == rSet.GetItemState( RES_PAGEDESC, sal_True, &pItem ) )
403 pNewDesc = new SwFmtPageDesc(*((SwFmtPageDesc*)pItem));
405 if(!pNewDesc)
406 pNewDesc = new SwFmtPageDesc();
407 OUString uDescName;
408 aValue >>= uDescName;
409 String sDescName;
410 SwStyleNameMapper::FillUIName(uDescName, sDescName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, sal_True );
411 if(!pNewDesc->GetPageDesc() || pNewDesc->GetPageDesc()->GetName() != sDescName)
413 sal_Bool bPut = sal_False;
414 if(sDescName.Len())
416 SwPageDesc* pPageDesc = ::GetPageDescByName_Impl(*pDoc, sDescName);
417 if(pPageDesc)
419 pPageDesc->Add( pNewDesc );
420 bPut = sal_True;
422 else
424 throw lang::IllegalArgumentException();
427 if(!bPut)
429 rSet.ClearItem(RES_BREAK);
430 rSet.Put(SwFmtPageDesc());
432 else
433 rSet.Put(*pNewDesc);
435 delete pNewDesc;
437 /* -----------------30.06.98 10:29-------------------
439 * --------------------------------------------------*/
440 void lcl_SetNodeNumStart( SwPaM& rCrsr, uno::Any aValue )
442 sal_Int16 nTmp = 1;
443 aValue >>= nTmp;
444 sal_uInt16 nStt = (nTmp < 0 ? USHRT_MAX : (sal_uInt16)nTmp);
445 SwDoc* pDoc = rCrsr.GetDoc();
446 UnoActionContext aAction(pDoc);
448 if( rCrsr.GetNext() != &rCrsr ) // Mehrfachselektion ?
450 pDoc->StartUndo( UNDO_START, NULL );
451 SwPamRanges aRangeArr( rCrsr );
452 SwPaM aPam( *rCrsr.GetPoint() );
453 for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
455 pDoc->SetNumRuleStart(*aRangeArr.SetPam( n, aPam ).GetPoint());
456 pDoc->SetNodeNumStart(*aRangeArr.SetPam( n, aPam ).GetPoint(),
457 nStt );
459 pDoc->EndUndo( UNDO_END, NULL);
461 else
463 pDoc->SetNumRuleStart( *rCrsr.GetPoint());
464 pDoc->SetNodeNumStart( *rCrsr.GetPoint(), nStt );
468 /* -----------------17.09.98 09:44-------------------
470 * --------------------------------------------------*/
471 sal_Bool lcl_setCrsrPropertyValue(const SfxItemPropertySimpleEntry* pEntry,
472 SwPaM& rPam,
473 SfxItemSet& rItemSet,
474 const uno::Any& aValue ) throw (lang::IllegalArgumentException)
476 sal_Bool bRet = sal_True;
477 if(0 == ( pEntry->nFlags&PropertyAttribute::MAYBEVOID ) &&
478 aValue.getValueType() == ::getCppuVoidType())
479 bRet = sal_False;
480 else
482 switch(pEntry->nWID)
484 case RES_TXTATR_CHARFMT:
485 lcl_setCharStyle(rPam.GetDoc(), aValue, rItemSet );
486 break;
487 case RES_TXTATR_AUTOFMT:
488 lcl_setAutoStyle(rPam.GetDoc()->GetIStyleAccess(), aValue, rItemSet, false );
489 break;
490 case FN_UNO_CHARFMT_SEQUENCE:
492 Sequence<OUString> aCharStyles;
493 if(aValue >>= aCharStyles)
495 for(sal_Int32 nStyle = 0; nStyle < aCharStyles.getLength(); nStyle++)
497 Any aStyle;
498 rPam.GetDoc()->StartUndo( UNDO_START, NULL);
499 aStyle <<= aCharStyles.getConstArray()[nStyle];
500 //create a local set and apply each format directly
501 SfxItemSet aSet(rPam.GetDoc()->GetAttrPool(), RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT );
502 lcl_setCharStyle(rPam.GetDoc(), aStyle, aSet );
503 //the first style should replace the current attributes, all other have to be added
504 SwXTextCursor::SetCrsrAttr(rPam, aSet, nStyle ? CRSR_ATTR_MODE_DONTREPLACE : 0);
505 rPam.GetDoc()->EndUndo( UNDO_START, NULL );
508 else
509 bRet = sal_False;
511 break;
512 case FN_UNO_PARA_STYLE :
513 lcl_SetTxtFmtColl(aValue, rPam);
514 break;
515 case RES_AUTO_STYLE:
516 lcl_setAutoStyle(rPam.GetDoc()->GetIStyleAccess(), aValue, rItemSet, true );
517 break;
518 case FN_UNO_PAGE_STYLE :
519 break;
520 case FN_UNO_NUM_START_VALUE :
521 lcl_SetNodeNumStart( rPam, aValue );
522 break;
523 case FN_UNO_NUM_LEVEL :
524 // --> OD 2008-07-14 #i91601#
525 case FN_UNO_LIST_ID:
526 // <--
527 case FN_UNO_IS_NUMBER :
529 // multi selection is not considered
530 SwTxtNode* pTxtNd = rPam.GetNode()->GetTxtNode();
531 // --> OD 2008-05-14 #refactorlists# - check on list style not needed
532 // const SwNumRule* pRule = pTxtNd->GetNumRule();
533 // if( FN_UNO_NUM_LEVEL == pEntry->nWID && pRule != NULL )
534 if ( FN_UNO_NUM_LEVEL == pEntry->nWID )
535 // <--
537 sal_Int16 nLevel = 0;
538 aValue >>= nLevel;
540 pTxtNd->SetAttrListLevel(nLevel);
543 // --> OD 2008-07-14 #i91601#
544 else if( FN_UNO_LIST_ID == pEntry->nWID )
546 ::rtl::OUString sListId;
547 aValue >>= sListId;
548 pTxtNd->SetListId( sListId );
550 // <--
551 else if( FN_UNO_IS_NUMBER == pEntry->nWID )
553 BOOL bIsNumber = *(sal_Bool*) aValue.getValue();
554 if(!bIsNumber)
555 pTxtNd->SetCountedInList( false );
557 //PROPERTY_MAYBEVOID!
559 break;
560 case FN_NUMBER_NEWSTART :
562 sal_Bool bVal = sal_False;
563 if (aValue >>= bVal)
564 rPam.GetDoc()->SetNumRuleStart(*rPam.GetPoint(), bVal);
565 else
566 throw lang::IllegalArgumentException();
568 break;
569 case FN_UNO_NUM_RULES:
570 SwUnoCursorHelper::setNumberingProperty(aValue, rPam);
571 break;
572 case RES_PARATR_DROP:
574 if( MID_DROPCAP_CHAR_STYLE_NAME == pEntry->nMemberId)
576 OUString uStyle;
577 if(aValue >>= uStyle)
579 String sStyle;
580 SwStyleNameMapper::FillUIName(uStyle, sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
581 SwDoc* pDoc = rPam.GetDoc();
582 //default character style mustn't be set as default format
583 SwDocStyleSheet* pStyle =
584 (SwDocStyleSheet*)pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_CHAR);
585 SwFmtDrop* pDrop = 0;
586 if(pStyle &&
587 ((SwDocStyleSheet*)pStyle)->GetCharFmt() != pDoc->GetDfltCharFmt())
589 const SfxPoolItem* pItem;
590 if(SFX_ITEM_SET == rItemSet.GetItemState( RES_PARATR_DROP, sal_True, &pItem ) )
591 pDrop = new SwFmtDrop(*((SwFmtDrop*)pItem));
592 if(!pDrop)
593 pDrop = new SwFmtDrop();
594 rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *(SwDocStyleSheet*)pStyle ) );
595 pDrop->SetCharFmt(xStyle->GetCharFmt());
597 else
598 throw lang::IllegalArgumentException();
599 rItemSet.Put(*pDrop);
600 delete pDrop;
602 else
603 throw lang::IllegalArgumentException();
605 else
606 bRet = sal_False;
608 break;
609 case RES_TXTATR_CJK_RUBY:
610 if(MID_RUBY_CHARSTYLE == pEntry->nMemberId )
612 OUString sTmp;
613 if(aValue >>= sTmp)
615 SwFmtRuby* pRuby = 0;
616 const SfxPoolItem* pItem;
617 if(SFX_ITEM_SET == rItemSet.GetItemState( RES_TXTATR_CJK_RUBY, sal_True, &pItem ) )
618 pRuby = new SwFmtRuby(*((SwFmtRuby*)pItem));
619 if(!pRuby)
620 pRuby = new SwFmtRuby(aEmptyStr);
621 String sStyle;
622 SwStyleNameMapper::FillUIName(sTmp, sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
623 pRuby->SetCharFmtName( sStyle );
624 pRuby->SetCharFmtId( 0 );
625 if(sStyle.Len() > 0)
627 sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
628 pRuby->SetCharFmtId(nId);
630 rItemSet.Put(*pRuby);
631 delete pRuby;
633 else
634 throw lang::IllegalArgumentException();
635 bRet = sal_True;
637 else
638 bRet = sal_False;
639 break;
640 case RES_PAGEDESC :
641 if(MID_PAGEDESC_PAGEDESCNAME == pEntry->nMemberId )
643 lcl_setPageDesc(rPam.GetDoc(), aValue, rItemSet);
644 break;
646 //hier kein break
647 default: bRet = sal_False;
650 return bRet;
653 /* -----------------30.06.98 08:39-------------------
655 * --------------------------------------------------*/
656 SwFmtColl* SwXTextCursor::GetCurTxtFmtColl(SwPaM& rPam, BOOL bConditional)
658 static const sal_uInt16 nMaxLookup = 1000;
659 SwFmtColl *pFmt = 0;
661 // if ( GetCrsrCnt() > nMaxLookup )
662 // return 0;
663 sal_Bool bError = sal_False;
664 FOREACHUNOPAM_START(&rPam)
666 ULONG nSttNd = PUNOPAM->GetMark()->nNode.GetIndex(),
667 nEndNd = PUNOPAM->GetPoint()->nNode.GetIndex();
668 xub_StrLen nSttCnt = PUNOPAM->GetMark()->nContent.GetIndex(),
669 nEndCnt = PUNOPAM->GetPoint()->nContent.GetIndex();
671 if( nSttNd > nEndNd || ( nSttNd == nEndNd && nSttCnt > nEndCnt ))
673 sal_uInt32 nTmp = nSttNd; nSttNd = nEndNd; nEndNd = nTmp;
674 nTmp = nSttCnt; nSttCnt = nEndCnt; nEndCnt = (sal_uInt16)nTmp;
677 if( nEndNd - nSttNd >= nMaxLookup )
679 pFmt = 0;
680 break;
683 const SwNodes& rNds = rPam.GetDoc()->GetNodes();
684 for( ULONG n = nSttNd; n <= nEndNd; ++n )
686 const SwTxtNode* pNd = rNds[ n ]->GetTxtNode();
687 if( pNd )
689 SwFmtColl* pNdFmt = bConditional ? pNd->GetFmtColl()
690 : &pNd->GetAnyFmtColl();
691 if( !pFmt )
692 pFmt = pNdFmt;
693 else if( pFmt != pNdFmt )
695 bError = sal_True;
696 break;
700 if(bError)
701 break;
702 FOREACHUNOPAM_END()
703 return bError ? 0 : pFmt;
706 /* -----------------26.06.98 16:20-------------------
707 * Hilfsfunktion fuer PageDesc
708 * --------------------------------------------------*/
709 SwPageDesc* GetPageDescByName_Impl(SwDoc& rDoc, const String& rName)
711 SwPageDesc* pRet = 0;
712 sal_uInt16 nDCount = rDoc.GetPageDescCnt();
713 sal_uInt16 i;
715 for( i = 0; i < nDCount; i++ )
717 SwPageDesc* pDsc = &rDoc._GetPageDesc( i );
718 if(pDsc->GetName() == rName)
720 pRet = pDsc;
721 break;
724 if(!pRet)
726 for(i = RC_POOLPAGEDESC_BEGIN; i <= STR_POOLPAGE_LANDSCAPE; ++i)
728 const String aFmtName(SW_RES(i));
729 if(aFmtName == rName)
731 pRet = rDoc.GetPageDescFromPool( static_cast< sal_uInt16 >(RES_POOLPAGE_BEGIN + i - RC_POOLPAGEDESC_BEGIN) );
732 break;
737 return pRet;
739 /******************************************************************************
740 ******************************************************************************
741 ******************************************************************************
742 * Taskforce ONE51
743 ******************************************************************************/
745 /******************************************************************
746 * SwXTextCursor
747 ******************************************************************/
749 /*-- 09.12.98 14:19:19---------------------------------------------------
751 -----------------------------------------------------------------------*/
752 OUString SwXTextCursor::getImplementationName(void) throw( RuntimeException )
754 return C2U("SwXTextCursor");
756 /*-- 09.12.98 14:19:19---------------------------------------------------
758 -----------------------------------------------------------------------*/
759 BOOL SwXTextCursor::supportsService(const OUString& rServiceName) throw( RuntimeException )
761 String sServiceName(rServiceName);
762 return sServiceName.EqualsAscii("com.sun.star.text.TextCursor") ||
763 sServiceName.EqualsAscii("com.sun.star.style.CharacterProperties")||
764 sServiceName.EqualsAscii("com.sun.star.style.CharacterPropertiesAsian")||
765 sServiceName.EqualsAscii("com.sun.star.style.CharacterPropertiesComplex")||
766 sServiceName.EqualsAscii("com.sun.star.style.ParagraphProperties") ||
767 sServiceName.EqualsAscii("com.sun.star.style.ParagraphPropertiesAsian") ||
768 sServiceName.EqualsAscii("com.sun.star.style.ParagraphPropertiesComplex") ||
769 sServiceName.EqualsAscii("com.sun.star.text.TextSortable");
771 /*-- 09.12.98 14:19:19---------------------------------------------------
773 -----------------------------------------------------------------------*/
774 Sequence< OUString > SwXTextCursor::getSupportedServiceNames(void) throw( RuntimeException )
776 Sequence< OUString > aRet(8);
777 OUString* pArray = aRet.getArray();
778 pArray[0] = C2U("com.sun.star.text.TextCursor");
779 pArray[1] = C2U("com.sun.star.style.CharacterProperties");
780 pArray[2] = C2U("com.sun.star.style.CharacterPropertiesAsian");
781 pArray[3] = C2U("com.sun.star.style.CharacterPropertiesComplex");
782 pArray[4] = C2U("com.sun.star.style.ParagraphProperties");
783 pArray[5] = C2U("com.sun.star.style.ParagraphPropertiesAsian");
784 pArray[6] = C2U("com.sun.star.style.ParagraphPropertiesComplex");
785 pArray[7] = C2U("com.sun.star.text.TextSortable");
786 return aRet;
788 /*-- 09.12.98 14:19:19---------------------------------------------------
790 -----------------------------------------------------------------------*/
791 SwXTextCursor::SwXTextCursor(uno::Reference< XText > xParent, const SwPosition& rPos,
792 CursorType eSet, SwDoc* pDoc, const SwPosition* pMark) :
793 aLstnrCntnr(( util::XSortable*)this),
794 m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR)),
795 xParentText(xParent),
796 pLastSortOptions(0),
797 eType(eSet),
798 mbRemoveUserEvent( false )
800 SwUnoCrsr* pUnoCrsr = pDoc->CreateUnoCrsr(rPos, sal_False);
801 if(pMark)
803 pUnoCrsr->SetMark();
804 *pUnoCrsr->GetMark() = *pMark;
806 pUnoCrsr->Add(this);
809 /* -----------------04.03.99 09:02-------------------
811 * --------------------------------------------------*/
812 SwXTextCursor::SwXTextCursor(uno::Reference< XText > xParent,
813 SwUnoCrsr* pSourceCrsr, CursorType eSet) :
814 aLstnrCntnr( (util::XSortable*)this),
815 m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR)),
816 xParentText(xParent),
817 pLastSortOptions(0),
818 eType(eSet),
819 mbRemoveUserEvent( false )
821 SwUnoCrsr* pUnoCrsr = pSourceCrsr->GetDoc()->CreateUnoCrsr(*pSourceCrsr->GetPoint(), sal_False);
822 if(pSourceCrsr->HasMark())
824 pUnoCrsr->SetMark();
825 *pUnoCrsr->GetMark() = *pSourceCrsr->GetMark();
827 pUnoCrsr->Add(this);
830 /*-- 09.12.98 14:19:20---------------------------------------------------
832 -----------------------------------------------------------------------*/
833 SwXTextCursor::~SwXTextCursor()
835 vos::OGuard aGuard(Application::GetSolarMutex());
837 // --> FME 2006-03-07 #126177# A user event has been posted in order
838 // to delete the SwUnoCursor. Remove the user event if the SwXTextCursor
839 // is destroyed before the user event could be handled.
840 if ( mbRemoveUserEvent )
842 mbRemoveUserEvent = false;
843 Application::RemoveUserEvent( mnUserEventId );
845 // <--
847 SwUnoCrsr* pUnoCrsr = GetCrsr();
848 delete pUnoCrsr;
849 delete pLastSortOptions;
851 /*-- 09.12.98 14:19:18---------------------------------------------------
853 -----------------------------------------------------------------------*/
854 void SwXTextCursor::DeleteAndInsert(const String& rText)
856 SwUnoCrsr* pUnoCrsr = GetCrsr();
857 if(pUnoCrsr)
859 // Start/EndAction
860 SwDoc* pDoc = pUnoCrsr->GetDoc();
861 UnoActionContext aAction(pDoc);
862 xub_StrLen nTxtLen = rText.Len();
863 pDoc->StartUndo(UNDO_INSERT, NULL);
864 SwCursor *_pStartCrsr = pUnoCrsr;
867 if(_pStartCrsr->HasMark())
869 pDoc->DeleteAndJoin(*_pStartCrsr);
871 if(nTxtLen)
873 if( !SwUnoCursorHelper::DocInsertStringSplitCR( *pDoc, *_pStartCrsr, rText ) )
875 DBG_ASSERT( sal_False, "Doc->Insert(Str) failed." );
877 SwXTextCursor::SelectPam(*pUnoCrsr, sal_True);
878 _pStartCrsr->Left(rText.Len(), CRSR_SKIP_CHARS, FALSE, FALSE);
880 } while( (_pStartCrsr=(SwCursor*)_pStartCrsr->GetNext()) != pUnoCrsr );
881 pDoc->EndUndo(UNDO_INSERT, NULL);
884 /* -----------------------------10.03.00 18:02--------------------------------
886 ---------------------------------------------------------------------------*/
887 const uno::Sequence< sal_Int8 > & SwXTextCursor::getUnoTunnelId()
889 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
890 return aSeq;
892 /* -----------------------------10.03.00 18:04--------------------------------
894 ---------------------------------------------------------------------------*/
895 sal_Int64 SAL_CALL SwXTextCursor::getSomething( const uno::Sequence< sal_Int8 >& rId )
896 throw(uno::RuntimeException)
898 if( rId.getLength() == 16
899 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
900 rId.getConstArray(), 16 ) )
902 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
904 return OTextCursorHelper::getSomething(rId);
907 /*-- 09.12.98 14:18:12---------------------------------------------------
909 -----------------------------------------------------------------------*/
910 void SwXTextCursor::collapseToStart(void) throw( uno::RuntimeException )
912 vos::OGuard aGuard(Application::GetSolarMutex());
913 SwUnoCrsr* pUnoCrsr = GetCrsr();
914 if(pUnoCrsr)
916 if(pUnoCrsr->HasMark())
918 if(*pUnoCrsr->GetPoint() > *pUnoCrsr->GetMark())
919 pUnoCrsr->Exchange();
920 pUnoCrsr->DeleteMark();
923 else
925 throw uno::RuntimeException();
928 /*-- 09.12.98 14:18:14---------------------------------------------------
930 -----------------------------------------------------------------------*/
931 void SwXTextCursor::collapseToEnd(void) throw( uno::RuntimeException )
933 vos::OGuard aGuard(Application::GetSolarMutex());
934 SwUnoCrsr* pUnoCrsr = GetCrsr();
935 if(pUnoCrsr)
937 if(pUnoCrsr->HasMark())
939 if(*pUnoCrsr->GetPoint() < *pUnoCrsr->GetMark())
940 pUnoCrsr->Exchange();
941 pUnoCrsr->DeleteMark();
944 else
946 throw uno::RuntimeException();
949 /*-- 09.12.98 14:18:41---------------------------------------------------
951 -----------------------------------------------------------------------*/
952 sal_Bool SwXTextCursor::isCollapsed(void) throw( uno::RuntimeException )
954 vos::OGuard aGuard(Application::GetSolarMutex());
955 sal_Bool bRet = sal_True;
956 SwUnoCrsr* pUnoCrsr = GetCrsr();
957 if(pUnoCrsr && pUnoCrsr->GetMark())
959 bRet = (*pUnoCrsr->GetPoint() == *pUnoCrsr->GetMark());
961 return bRet;
963 /*-- 09.12.98 14:18:42---------------------------------------------------
965 -----------------------------------------------------------------------*/
966 sal_Bool SwXTextCursor::goLeft(sal_Int16 nCount, sal_Bool Expand) throw( uno::RuntimeException )
968 vos::OGuard aGuard(Application::GetSolarMutex());
969 sal_Bool bRet = sal_False;
970 SwUnoCrsr* pUnoCrsr = GetCrsr();
971 if(pUnoCrsr)
973 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
974 bRet = pUnoCrsr->Left( nCount, CRSR_SKIP_CHARS, FALSE, FALSE);
976 else
978 throw uno::RuntimeException();
980 return bRet;
982 /*-- 09.12.98 14:18:42---------------------------------------------------
984 -----------------------------------------------------------------------*/
985 sal_Bool SwXTextCursor::goRight(sal_Int16 nCount, sal_Bool Expand) throw( uno::RuntimeException )
987 vos::OGuard aGuard(Application::GetSolarMutex());
988 sal_Bool bRet = sal_False;
989 SwUnoCrsr* pUnoCrsr = GetCrsr();
990 if(pUnoCrsr)
992 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
993 bRet = pUnoCrsr->Right(nCount, CRSR_SKIP_CHARS, FALSE, FALSE);
995 else
997 throw uno::RuntimeException();
999 return bRet;
1001 /*-- 09.12.98 14:18:43---------------------------------------------------
1003 -----------------------------------------------------------------------*/
1004 void SwXTextCursor::gotoStart(sal_Bool Expand) throw( uno::RuntimeException )
1006 vos::OGuard aGuard(Application::GetSolarMutex());
1007 SwUnoCrsr* pUnoCrsr = GetCrsr();
1008 if(pUnoCrsr)
1010 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
1011 if(eType == CURSOR_BODY)
1013 pUnoCrsr->Move( fnMoveBackward, fnGoDoc );
1014 //check, that the cursor is not in a table
1015 SwTableNode* pTblNode = pUnoCrsr->GetNode()->FindTableNode();
1016 SwCntntNode* pCont = 0;
1017 while( pTblNode )
1019 pUnoCrsr->GetPoint()->nNode = *pTblNode->EndOfSectionNode();
1020 pCont = GetDoc()->GetNodes().GoNext(&pUnoCrsr->GetPoint()->nNode);
1021 pTblNode = pCont ? pCont->FindTableNode() : 0;
1023 if(pCont)
1024 pUnoCrsr->GetPoint()->nContent.Assign(pCont, 0);
1025 const SwStartNode* pTmp = pUnoCrsr->GetNode()->StartOfSectionNode();
1026 if(pTmp->IsSectionNode())
1028 SwSectionNode* pSectionStartNode = (SwSectionNode*)pTmp;
1029 if(pSectionStartNode->GetSection().IsHiddenFlag())
1031 pCont = GetDoc()->GetNodes().GoNextSection(
1032 &pUnoCrsr->GetPoint()->nNode, sal_True, sal_False);
1033 if(pCont)
1034 pUnoCrsr->GetPoint()->nContent.Assign(pCont, 0);
1038 else if(eType == CURSOR_FRAME ||
1039 eType == CURSOR_TBLTEXT ||
1040 eType == CURSOR_HEADER ||
1041 eType == CURSOR_FOOTER ||
1042 eType == CURSOR_FOOTNOTE||
1043 eType == CURSOR_REDLINE)
1045 pUnoCrsr->MoveSection( fnSectionCurr, fnSectionStart);
1048 else
1050 throw uno::RuntimeException();
1053 /*-- 09.12.98 14:18:43---------------------------------------------------
1055 -----------------------------------------------------------------------*/
1056 void SwXTextCursor::gotoEnd(sal_Bool Expand) throw( uno::RuntimeException )
1058 vos::OGuard aGuard(Application::GetSolarMutex());
1059 SwUnoCrsr* pUnoCrsr = GetCrsr();
1060 if(pUnoCrsr)
1062 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
1063 if(eType == CURSOR_BODY)
1064 pUnoCrsr->Move( fnMoveForward, fnGoDoc );
1065 else if(eType == CURSOR_FRAME ||
1066 eType == CURSOR_TBLTEXT ||
1067 eType == CURSOR_HEADER ||
1068 eType == CURSOR_FOOTER ||
1069 eType == CURSOR_FOOTNOTE||
1070 eType == CURSOR_REDLINE)
1072 pUnoCrsr->MoveSection( fnSectionCurr, fnSectionEnd);
1075 else
1077 throw uno::RuntimeException();
1081 void SwXTextCursor::gotoRange(const uno::Reference< XTextRange > & xRange, sal_Bool bExpand )
1082 throw( uno::RuntimeException )
1084 vos::OGuard aGuard(Application::GetSolarMutex());
1085 SwUnoCrsr* pOwnCursor = GetCrsr();
1086 if(!pOwnCursor || !xRange.is())
1088 throw uno::RuntimeException();
1091 uno::Reference<lang::XUnoTunnel> xRangeTunnel( xRange, uno::UNO_QUERY);
1092 SwXTextRange* pRange = 0;
1093 OTextCursorHelper* pCursor = 0;
1094 if(xRangeTunnel.is())
1096 pRange = reinterpret_cast< SwXTextRange * >(
1097 sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId()) ));
1098 pCursor = reinterpret_cast< OTextCursorHelper * >(
1099 sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
1102 SwStartNodeType eSearchNodeType = SwNormalStartNode;
1103 switch(eType)
1105 case CURSOR_FRAME: eSearchNodeType = SwFlyStartNode; break;
1106 case CURSOR_TBLTEXT: eSearchNodeType = SwTableBoxStartNode; break;
1107 case CURSOR_FOOTNOTE: eSearchNodeType = SwFootnoteStartNode; break;
1108 case CURSOR_HEADER: eSearchNodeType = SwHeaderStartNode; break;
1109 case CURSOR_FOOTER: eSearchNodeType = SwFooterStartNode; break;
1110 //case CURSOR_INVALID:
1111 //case CURSOR_BODY:
1112 default:
1115 const SwStartNode* pOwnStartNode = pOwnCursor->GetNode()->
1116 FindSttNodeByType(eSearchNodeType);
1118 const SwNode* pSrcNode = 0;
1119 if(pCursor && pCursor->GetPaM())
1121 pSrcNode = pCursor->GetPaM()->GetNode();
1123 else if(pRange && pRange->GetBookmark())
1125 ::sw::mark::IMark const * const pBkmk = pRange->GetBookmark();
1126 pSrcNode = &pBkmk->GetMarkPos().nNode.GetNode();
1128 const SwStartNode* pTmp = pSrcNode ? pSrcNode->FindSttNodeByType(eSearchNodeType) : 0;
1130 //SectionNodes ueberspringen
1131 while(pTmp && pTmp->IsSectionNode())
1133 pTmp = pTmp->StartOfSectionNode();
1135 while(pOwnStartNode && pOwnStartNode->IsSectionNode())
1137 pOwnStartNode = pOwnStartNode->StartOfSectionNode();
1139 if(pOwnStartNode != pTmp)
1141 throw uno::RuntimeException();
1144 //jetzt muss die Selektion erweitert werden
1145 if(bExpand)
1147 // der Cursor soll alles einschliessen, was bisher von ihm und dem uebergebenen
1148 // Range eingeschlossen wurde
1149 SwPosition aOwnLeft(*pOwnCursor->GetPoint());
1150 SwPosition aOwnRight(pOwnCursor->HasMark() ? *pOwnCursor->GetMark() : aOwnLeft);
1151 if(aOwnRight < aOwnLeft)
1153 SwPosition aTmp = aOwnLeft;
1154 aOwnLeft = aOwnRight;
1155 aOwnRight = aTmp;
1157 SwPosition* pParamLeft;
1158 SwPosition* pParamRight;
1159 if(pCursor)
1161 const SwPaM* pTmp2 = pCursor->GetPaM();
1162 pParamLeft = new SwPosition(*pTmp2->GetPoint());
1163 pParamRight = new SwPosition(pTmp2->HasMark() ? *pTmp2->GetMark() : *pParamLeft);
1165 else
1167 ::sw::mark::IMark const * const pBkmk = pRange->GetBookmark();
1168 pParamLeft = new SwPosition(pBkmk->GetMarkPos());
1169 pParamRight = new SwPosition(pBkmk->IsExpanded() ? pBkmk->GetOtherMarkPos() : *pParamLeft);
1171 if(*pParamRight < *pParamLeft)
1173 SwPosition* pTmp2 = pParamLeft;
1174 pParamLeft = pParamRight;
1175 pParamRight = pTmp2;
1177 // jetzt sind vier SwPositions da, zwei davon werden gebraucht, also welche?
1178 if(aOwnRight > *pParamRight)
1179 *pOwnCursor->GetPoint() = aOwnRight;
1180 else
1181 *pOwnCursor->GetPoint() = *pParamRight;
1182 pOwnCursor->SetMark();
1183 if(aOwnLeft < *pParamLeft)
1184 *pOwnCursor->GetMark() = aOwnLeft;
1185 else
1186 *pOwnCursor->GetMark() = *pParamLeft;
1187 delete pParamLeft;
1188 delete pParamRight;
1190 else
1192 //der Cursor soll dem uebergebenen Range entsprechen
1193 if(pCursor)
1195 const SwPaM* pTmp2 = pCursor->GetPaM();
1196 *pOwnCursor->GetPoint() = *pTmp2->GetPoint();
1197 if(pTmp2->HasMark())
1199 pOwnCursor->SetMark();
1200 *pOwnCursor->GetMark() = *pTmp2->GetMark();
1202 else
1203 pOwnCursor->DeleteMark();
1205 else
1207 ::sw::mark::IMark const * const pBkmk = pRange->GetBookmark();
1208 *pOwnCursor->GetPoint() = pBkmk->GetMarkPos();
1209 if(pBkmk->IsExpanded())
1211 pOwnCursor->SetMark();
1212 *pOwnCursor->GetMark() = pBkmk->GetOtherMarkPos();
1214 else
1215 pOwnCursor->DeleteMark();
1220 /*-- 09.12.98 14:18:44---------------------------------------------------
1222 -----------------------------------------------------------------------*/
1223 sal_Bool SwXTextCursor::isStartOfWord(void) throw( uno::RuntimeException )
1225 vos::OGuard aGuard(Application::GetSolarMutex());
1226 sal_Bool bRet = sal_False;
1227 SwUnoCrsr* pUnoCrsr = GetCrsr();
1228 if(pUnoCrsr)
1230 bRet = pUnoCrsr->IsStartWordWT( i18n::WordType::DICTIONARY_WORD );
1232 else
1234 throw uno::RuntimeException();
1236 return bRet;
1238 /*-- 09.12.98 14:18:44---------------------------------------------------
1240 -----------------------------------------------------------------------*/
1241 sal_Bool SwXTextCursor::isEndOfWord(void) throw( uno::RuntimeException )
1243 vos::OGuard aGuard(Application::GetSolarMutex());
1244 sal_Bool bRet = sal_False;
1245 SwUnoCrsr* pUnoCrsr = GetCrsr();
1246 if(pUnoCrsr)
1248 bRet = pUnoCrsr->IsEndWordWT( i18n::WordType::DICTIONARY_WORD );
1250 else
1252 throw uno::RuntimeException();
1254 return bRet;
1256 /*-- 09.12.98 14:18:44---------------------------------------------------
1258 -----------------------------------------------------------------------*/
1259 sal_Bool SwXTextCursor::gotoNextWord(sal_Bool Expand) throw( uno::RuntimeException )
1261 vos::OGuard aGuard(Application::GetSolarMutex());
1262 //Probleme gibt's noch mit einem Absatzanfang, an dem kein Wort beginnt.
1264 SwUnoCrsr* pUnoCrsr = GetCrsr();
1266 sal_Bool bRet = sal_False;
1267 if(pUnoCrsr)
1269 // remember old position to check if cursor has moved
1270 // since the called functions are sometimes a bit unreliable
1271 // in specific cases...
1272 SwPosition *pPoint = pUnoCrsr->GetPoint();
1273 SwNode *pOldNode = &pPoint->nNode.GetNode();
1274 xub_StrLen nOldIndex = pPoint->nContent.GetIndex();
1276 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
1277 //Absatzende?
1278 if(pUnoCrsr->GetCntntNode() &&
1279 pPoint->nContent == pUnoCrsr->GetCntntNode()->Len())
1280 pUnoCrsr->Right(1, CRSR_SKIP_CHARS, FALSE, FALSE);
1281 else
1283 sal_Bool bTmp = pUnoCrsr->GoNextWordWT( i18n::WordType::DICTIONARY_WORD );
1284 //if there is no next word within the current paragraph try to go to the start of the next paragraph
1285 if(!bTmp)
1286 pUnoCrsr->MovePara(fnParaNext, fnParaStart);
1289 // return true if cursor has moved
1290 bRet = &pPoint->nNode.GetNode() != pOldNode ||
1291 pPoint->nContent.GetIndex() != nOldIndex;
1293 else
1295 throw uno::RuntimeException();
1298 return bRet;
1300 /*-- 09.12.98 14:18:45---------------------------------------------------
1302 -----------------------------------------------------------------------*/
1303 sal_Bool SwXTextCursor::gotoPreviousWord(sal_Bool Expand) throw( uno::RuntimeException )
1305 vos::OGuard aGuard(Application::GetSolarMutex());
1306 // hier machen Leerzeichen am Absatzanfang Probleme
1307 SwUnoCrsr* pUnoCrsr = GetCrsr();
1309 sal_Bool bRet = sal_False;
1310 if(pUnoCrsr)
1312 SwPosition *pPoint = pUnoCrsr->GetPoint();
1313 SwNode *pOldNode = &pPoint->nNode.GetNode();
1314 xub_StrLen nOldIndex = pPoint->nContent.GetIndex();
1316 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
1317 //Absatzanfang ?
1318 if(pPoint->nContent == 0)
1319 pUnoCrsr->Left(1, CRSR_SKIP_CHARS, FALSE, FALSE);
1320 else
1322 pUnoCrsr->GoPrevWordWT( i18n::WordType::DICTIONARY_WORD );
1323 if(pPoint->nContent == 0)
1324 pUnoCrsr->Left(1, CRSR_SKIP_CHARS, FALSE, FALSE);
1327 // return true if cursor has moved
1328 bRet = &pPoint->nNode.GetNode() != pOldNode ||
1329 pPoint->nContent.GetIndex() != nOldIndex;
1331 else
1333 throw uno::RuntimeException();
1336 return bRet;
1338 /*-- 09.12.98 14:18:45---------------------------------------------------
1340 -----------------------------------------------------------------------*/
1341 sal_Bool SwXTextCursor::gotoEndOfWord(sal_Bool Expand) throw( uno::RuntimeException )
1343 vos::OGuard aGuard(Application::GetSolarMutex());
1344 SwUnoCrsr* pUnoCrsr = GetCrsr();
1346 sal_Bool bRet = sal_False;
1347 if(pUnoCrsr)
1349 SwPosition *pPoint = pUnoCrsr->GetPoint();
1350 SwNode &rOldNode = pPoint->nNode.GetNode();
1351 xub_StrLen nOldIndex = pPoint->nContent.GetIndex();
1353 sal_Int16 nWordType = i18n::WordType::DICTIONARY_WORD;
1354 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
1355 if(!pUnoCrsr->IsEndWordWT( nWordType ))
1356 pUnoCrsr->GoEndWordWT( nWordType );
1358 // restore old cursor if we are not at the end of a word by now
1359 // otherwise use current one
1360 bRet = pUnoCrsr->IsEndWordWT( nWordType );
1361 if (!bRet)
1363 pPoint->nNode = rOldNode;
1364 pPoint->nContent = nOldIndex;
1367 else
1369 throw uno::RuntimeException();
1372 return bRet;
1374 /*-- 09.12.98 14:18:46---------------------------------------------------
1376 -----------------------------------------------------------------------*/
1377 sal_Bool SwXTextCursor::gotoStartOfWord(sal_Bool Expand) throw( uno::RuntimeException )
1379 vos::OGuard aGuard(Application::GetSolarMutex());
1380 SwUnoCrsr* pUnoCrsr = GetCrsr();
1382 sal_Bool bRet = sal_False;
1383 if(pUnoCrsr)
1385 SwPosition *pPoint = pUnoCrsr->GetPoint();
1386 SwNode &rOldNode = pPoint->nNode.GetNode();
1387 xub_StrLen nOldIndex = pPoint->nContent.GetIndex();
1389 sal_Int16 nWordType = i18n::WordType::DICTIONARY_WORD;
1390 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
1391 if(!pUnoCrsr->IsStartWordWT( nWordType ))
1392 pUnoCrsr->GoStartWordWT( nWordType );
1394 // restore old cursor if we are not at the start of a word by now
1395 // otherwise use current one
1396 bRet = pUnoCrsr->IsStartWordWT( nWordType );
1397 if (!bRet)
1399 pPoint->nNode = rOldNode;
1400 pPoint->nContent = nOldIndex;
1403 else
1405 throw uno::RuntimeException();
1408 return bRet;
1410 /*-- 09.12.98 14:18:46---------------------------------------------------
1412 -----------------------------------------------------------------------*/
1413 sal_Bool SwXTextCursor::isStartOfSentence(void) throw( uno::RuntimeException )
1415 vos::OGuard aGuard(Application::GetSolarMutex());
1416 sal_Bool bRet = sal_False;
1417 SwUnoCrsr* pUnoCrsr = GetCrsr();
1418 if(pUnoCrsr)
1420 // start of paragraph?
1421 bRet = pUnoCrsr->GetPoint()->nContent == 0;
1422 // with mark ->no sentence start
1423 // (check if cursor is no selection, i.e. it does not have
1424 // a mark or else point and mark are identical)
1425 if(!bRet && (!pUnoCrsr->HasMark() ||
1426 *pUnoCrsr->GetPoint() == *pUnoCrsr->GetMark()))
1428 SwCursor aCrsr(*pUnoCrsr->GetPoint(),0,false);
1429 SwPosition aOrigPos = *aCrsr.GetPoint();
1430 aCrsr.GoSentence(SwCursor::START_SENT );
1431 bRet = aOrigPos == *aCrsr.GetPoint();
1434 else
1435 throw uno::RuntimeException();
1436 return bRet;
1438 /*-- 09.12.98 14:18:47---------------------------------------------------
1440 -----------------------------------------------------------------------*/
1441 sal_Bool SwXTextCursor::isEndOfSentence(void) throw( uno::RuntimeException )
1443 vos::OGuard aGuard(Application::GetSolarMutex());
1444 sal_Bool bRet = sal_False;
1445 SwUnoCrsr* pUnoCrsr = GetCrsr();
1446 if(pUnoCrsr)
1448 //end of paragraph?
1449 bRet = pUnoCrsr->GetCntntNode() &&
1450 pUnoCrsr->GetPoint()->nContent == pUnoCrsr->GetCntntNode()->Len();
1451 // with mark->no sentence end
1452 // (check if cursor is no selection, i.e. it does not have
1453 // a mark or else point and mark are identical)
1454 if(!bRet && (!pUnoCrsr->HasMark() ||
1455 *pUnoCrsr->GetPoint() == *pUnoCrsr->GetMark()))
1457 SwCursor aCrsr(*pUnoCrsr->GetPoint(),0,false);
1458 SwPosition aOrigPos = *aCrsr.GetPoint();
1459 aCrsr.GoSentence(SwCursor::END_SENT );
1460 bRet = aOrigPos == *aCrsr.GetPoint();
1463 else
1464 throw uno::RuntimeException();
1465 return bRet;
1467 /*-- 09.12.98 14:18:47---------------------------------------------------
1469 -----------------------------------------------------------------------*/
1470 sal_Bool SwXTextCursor::gotoNextSentence(sal_Bool Expand) throw( uno::RuntimeException )
1472 vos::OGuard aGuard(Application::GetSolarMutex());
1473 sal_Bool bRet = sal_False;
1474 SwUnoCrsr* pUnoCrsr = GetCrsr();
1475 if(pUnoCrsr)
1477 BOOL bWasEOS = isEndOfSentence();
1478 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
1479 bRet = pUnoCrsr->GoSentence(SwCursor::NEXT_SENT);
1480 if(!bRet)
1481 bRet = pUnoCrsr->MovePara(fnParaNext, fnParaStart);
1483 // if at the end of the sentence (i.e. at the space after the '.')
1484 // advance to next word in order for GoSentence to work properly
1485 // next time and have isStartOfSentence return true after this call
1486 if (!pUnoCrsr->IsStartWord())
1488 BOOL bNextWord = pUnoCrsr->GoNextWord();
1489 if (bWasEOS && !bNextWord)
1490 bRet = sal_False;
1493 else
1494 throw uno::RuntimeException();
1495 return bRet;
1497 /*-- 09.12.98 14:18:47---------------------------------------------------
1499 -----------------------------------------------------------------------*/
1500 sal_Bool SwXTextCursor::gotoPreviousSentence(sal_Bool Expand) throw( uno::RuntimeException )
1502 vos::OGuard aGuard(Application::GetSolarMutex());
1503 sal_Bool bRet = sal_False;
1504 SwUnoCrsr* pUnoCrsr = GetCrsr();
1505 if(pUnoCrsr)
1507 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
1508 bRet = pUnoCrsr->GoSentence(SwCursor::PREV_SENT);
1509 if(!bRet)
1511 if(0 != (bRet = pUnoCrsr->MovePara(fnParaPrev, fnParaStart)))
1513 pUnoCrsr->MovePara(fnParaCurr, fnParaEnd);
1514 //at the end of a paragraph move to the sentence end again
1516 pUnoCrsr->GoSentence(SwCursor::PREV_SENT);
1520 else
1521 throw uno::RuntimeException();
1522 return bRet;
1524 /* -----------------15.10.99 08:24-------------------
1526 --------------------------------------------------*/
1527 sal_Bool SwXTextCursor::gotoStartOfSentence(sal_Bool Expand) throw( uno::RuntimeException )
1529 vos::OGuard aGuard(Application::GetSolarMutex());
1530 sal_Bool bRet = sal_False;
1531 SwUnoCrsr* pUnoCrsr = GetCrsr();
1532 if(pUnoCrsr)
1534 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
1535 // if we're at the para start then we wont move
1536 // but bRet is also true if GoSentence failed but
1537 // the start of the sentence is reached
1538 bRet = SwUnoCursorHelper::IsStartOfPara(*pUnoCrsr)
1539 || pUnoCrsr->GoSentence(SwCursor::START_SENT) ||
1540 SwUnoCursorHelper::IsStartOfPara(*pUnoCrsr);
1542 else
1543 throw uno::RuntimeException();
1544 return bRet;
1546 /* -----------------15.10.99 08:24-------------------
1548 --------------------------------------------------*/
1549 sal_Bool SwXTextCursor::gotoEndOfSentence(sal_Bool Expand) throw( uno::RuntimeException )
1551 vos::OGuard aGuard(Application::GetSolarMutex());
1552 sal_Bool bRet = sal_False;
1553 SwUnoCrsr* pUnoCrsr = GetCrsr();
1554 if(pUnoCrsr)
1556 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
1557 // bRet is true if GoSentence() succeeded or if the
1558 // MovePara() succeeded while the end of the para is
1559 // not reached already
1560 sal_Bool bAlreadyParaEnd = SwUnoCursorHelper::IsEndOfPara(*pUnoCrsr);
1561 bRet = !bAlreadyParaEnd &&
1562 (pUnoCrsr->GoSentence(SwCursor::END_SENT) ||
1563 pUnoCrsr->MovePara(fnParaCurr, fnParaEnd));
1566 else
1567 throw uno::RuntimeException();
1568 return bRet;
1571 /*-- 09.12.98 14:18:48---------------------------------------------------
1573 -----------------------------------------------------------------------*/
1574 sal_Bool SwXTextCursor::isStartOfParagraph(void) throw( uno::RuntimeException )
1576 vos::OGuard aGuard(Application::GetSolarMutex());
1577 sal_Bool bRet = sal_False;
1578 SwUnoCrsr* pUnoCrsr = GetCrsr();
1579 if(pUnoCrsr)
1580 bRet = SwUnoCursorHelper::IsStartOfPara(*pUnoCrsr);
1581 else
1582 throw uno::RuntimeException();
1583 return bRet;
1585 /*-- 09.12.98 14:18:48---------------------------------------------------
1587 -----------------------------------------------------------------------*/
1588 sal_Bool SwXTextCursor::isEndOfParagraph(void) throw( uno::RuntimeException )
1590 vos::OGuard aGuard(Application::GetSolarMutex());
1591 sal_Bool bRet = sal_False;
1592 SwUnoCrsr* pUnoCrsr = GetCrsr();
1593 if(pUnoCrsr)
1594 bRet = SwUnoCursorHelper::IsEndOfPara(*pUnoCrsr);
1595 else
1596 throw uno::RuntimeException();
1597 return bRet;
1599 /*-- 09.12.98 14:18:49---------------------------------------------------
1601 -----------------------------------------------------------------------*/
1602 sal_Bool SwXTextCursor::gotoStartOfParagraph(sal_Bool Expand) throw( uno::RuntimeException )
1604 vos::OGuard aGuard(Application::GetSolarMutex());
1605 sal_Bool bRet = sal_False;
1606 SwUnoCrsr* pUnoCrsr = GetCrsr();
1607 if(pUnoCrsr )
1609 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
1610 bRet = SwUnoCursorHelper::IsStartOfPara(*pUnoCrsr);
1611 if(!bRet)
1612 bRet = pUnoCrsr->MovePara(fnParaCurr, fnParaStart);
1614 else
1615 throw uno::RuntimeException();
1617 // since MovePara(fnParaCurr, fnParaStart) only returns false
1618 // if we were already at the start of the paragraph this function
1619 // should always complete successfully.
1620 DBG_ASSERT( bRet, "gotoStartOfParagraph failed" );
1621 return bRet;
1623 /*-- 09.12.98 14:18:49---------------------------------------------------
1625 -----------------------------------------------------------------------*/
1626 sal_Bool SwXTextCursor::gotoEndOfParagraph(sal_Bool Expand) throw( uno::RuntimeException )
1628 vos::OGuard aGuard(Application::GetSolarMutex());
1629 sal_Bool bRet = sal_False;
1630 SwUnoCrsr* pUnoCrsr = GetCrsr();
1631 if(pUnoCrsr)
1633 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
1634 bRet = SwUnoCursorHelper::IsEndOfPara(*pUnoCrsr);
1635 if(!bRet)
1636 bRet = pUnoCrsr->MovePara(fnParaCurr, fnParaEnd);
1638 else
1639 throw uno::RuntimeException();
1641 // since MovePara(fnParaCurr, fnParaEnd) only returns false
1642 // if we were already at the end of the paragraph this function
1643 // should always complete successfully.
1644 DBG_ASSERT( bRet, "gotoEndOfParagraph failed" );
1645 return bRet;
1647 /*-- 09.12.98 14:18:50---------------------------------------------------
1649 -----------------------------------------------------------------------*/
1650 sal_Bool SwXTextCursor::gotoNextParagraph(sal_Bool Expand) throw( uno::RuntimeException )
1652 vos::OGuard aGuard(Application::GetSolarMutex());
1653 sal_Bool bRet = sal_False;
1654 SwUnoCrsr* pUnoCrsr = GetCrsr();
1655 if(pUnoCrsr)
1657 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
1658 bRet = pUnoCrsr->MovePara(fnParaNext, fnParaStart);
1660 else
1661 throw uno::RuntimeException();
1662 return bRet;
1664 /*-- 09.12.98 14:18:50---------------------------------------------------
1666 -----------------------------------------------------------------------*/
1667 sal_Bool SwXTextCursor::gotoPreviousParagraph(sal_Bool Expand) throw( uno::RuntimeException )
1669 vos::OGuard aGuard(Application::GetSolarMutex());
1670 sal_Bool bRet = sal_False;
1671 SwUnoCrsr* pUnoCrsr = GetCrsr();
1672 if(pUnoCrsr)
1674 SwXTextCursor::SelectPam(*pUnoCrsr, Expand);
1675 bRet = pUnoCrsr->MovePara(fnParaPrev, fnParaStart);
1677 else
1678 throw uno::RuntimeException();
1679 return bRet;
1681 /*-- 09.12.98 14:18:50---------------------------------------------------
1683 -----------------------------------------------------------------------*/
1684 uno::Reference< XText > SwXTextCursor::getText(void) throw( uno::RuntimeException )
1686 return xParentText;
1688 /*-- 09.12.98 14:18:50---------------------------------------------------
1690 -----------------------------------------------------------------------*/
1691 uno::Reference< XTextRange > SwXTextCursor::getStart(void) throw( uno::RuntimeException )
1693 vos::OGuard aGuard(Application::GetSolarMutex());
1694 uno::Reference< XTextRange > xRet;
1695 SwUnoCrsr* pUnoCrsr = ((SwXTextCursor*)this)->GetCrsr();
1696 if( pUnoCrsr)
1698 SwPaM aPam(*pUnoCrsr->Start());
1699 uno::Reference< XText > xParent = getText();
1700 xRet = new SwXTextRange(aPam, xParent);
1702 else
1703 throw uno::RuntimeException();
1704 return xRet;
1706 /*-- 09.12.98 14:18:51---------------------------------------------------
1708 -----------------------------------------------------------------------*/
1709 uno::Reference< XTextRange > SwXTextCursor::getEnd(void) throw( uno::RuntimeException )
1711 vos::OGuard aGuard(Application::GetSolarMutex());
1712 uno::Reference< XTextRange > xRet;
1713 SwUnoCrsr* pUnoCrsr = ((SwXTextCursor*)this)->GetCrsr();
1714 if( pUnoCrsr)
1716 SwPaM aPam(*pUnoCrsr->End());
1717 uno::Reference< XText > xParent = getText();
1718 xRet = new SwXTextRange(aPam, xParent);
1720 else
1721 throw uno::RuntimeException();
1722 return xRet;
1724 /*-- 09.12.98 14:18:51---------------------------------------------------
1726 -----------------------------------------------------------------------*/
1727 OUString SwXTextCursor::getString(void) throw( uno::RuntimeException )
1729 vos::OGuard aGuard(Application::GetSolarMutex());
1730 OUString aTxt;
1731 SwUnoCrsr* pUnoCrsr = ((SwXTextCursor*)this)->GetCrsr();
1732 if( pUnoCrsr)
1734 /* if( pUnoCrsr->GetPoint()->nNode.GetIndex() ==
1735 pUnoCrsr->GetMark()->nNode.GetIndex() )
1737 SwTxtNode* pTxtNd = pUnoCrsr->GetNode()->GetTxtNode();
1738 if( pTxtNd )
1740 sal_uInt16 nStt = pUnoCrsr->Start()->nContent.GetIndex();
1741 aTxt = pTxtNd->GetExpandTxt( nStt,
1742 pUnoCrsr->End()->nContent.GetIndex() - nStt );
1745 else
1746 */ {
1747 //Text ueber mehrere Absaetze
1748 SwXTextCursor::getTextFromPam(*pUnoCrsr, aTxt);
1751 else
1752 throw uno::RuntimeException();
1753 return aTxt;
1755 /*-- 09.12.98 14:18:52---------------------------------------------------
1757 -----------------------------------------------------------------------*/
1758 void SwXTextCursor::setString(const OUString& aString) throw( uno::RuntimeException )
1760 vos::OGuard aGuard(Application::GetSolarMutex());
1761 SwUnoCrsr* pUnoCrsr = GetCrsr();
1762 if(!pUnoCrsr)
1763 throw uno::RuntimeException();
1765 DeleteAndInsert(aString);
1767 /* -----------------------------03.05.00 12:56--------------------------------
1769 ---------------------------------------------------------------------------*/
1770 Any SwXTextCursor::GetPropertyValue(
1771 SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
1772 const OUString& rPropertyName)
1773 throw( UnknownPropertyException, WrappedTargetException, RuntimeException)
1775 Any aAny;
1776 const SfxItemPropertySimpleEntry* pEntry = rPropSet.getPropertyMap()->getByName(
1777 rPropertyName);
1778 if(pEntry)
1780 PropertyState eTemp;
1781 BOOL bDone = SwUnoCursorHelper::getCrsrPropertyValue( *pEntry, rPaM, &aAny, eTemp );
1782 if(!bDone)
1784 SfxItemSet aSet(rPaM.GetDoc()->GetAttrPool(),
1785 RES_CHRATR_BEGIN, RES_FRMATR_END -1,
1786 RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER,
1787 RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER,
1788 0L);
1789 SwXTextCursor::GetCrsrAttr(rPaM, aSet);
1791 rPropSet.getPropertyValue(*pEntry, aSet, aAny);
1794 else
1795 throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( 0 ) );
1797 return aAny;
1799 /* -----------------------------03.05.00 12:57--------------------------------
1801 ---------------------------------------------------------------------------*/
1802 void SwXTextCursor::SetPropertyValue(
1803 SwPaM& rPaM, const SfxItemPropertySet& rPropSet, const OUString& rPropertyName,
1804 const Any& aValue, USHORT nAttrMode)
1805 throw (UnknownPropertyException, PropertyVetoException,
1806 IllegalArgumentException, WrappedTargetException, RuntimeException)
1808 SwDoc* pDoc = rPaM.GetDoc();
1809 const SfxItemPropertySimpleEntry* pEntry = rPropSet.getPropertyMap()->getByName(rPropertyName);
1810 if(pEntry)
1812 if( pEntry->nFlags & PropertyAttribute::READONLY)
1813 throw PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( 0 ) );
1815 SfxItemSet aItemSet( pDoc->GetAttrPool(), pEntry->nWID, pEntry->nWID );
1816 SwXTextCursor::GetCrsrAttr( rPaM, aItemSet );
1818 if(!lcl_setCrsrPropertyValue( pEntry, rPaM, aItemSet, aValue ))
1819 rPropSet.setPropertyValue(*pEntry, aValue, aItemSet );
1820 SwXTextCursor::SetCrsrAttr(rPaM, aItemSet, nAttrMode );
1822 else
1823 throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( 0 ) );
1825 /* -----------------------------03.05.00 13:16--------------------------------
1827 ---------------------------------------------------------------------------*/
1828 Sequence< PropertyState > SwXTextCursor::GetPropertyStates(
1829 SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
1830 const Sequence< OUString >& PropertyNames,
1831 SwGetPropertyStatesCaller eCaller )
1832 throw(UnknownPropertyException, RuntimeException)
1834 const OUString* pNames = PropertyNames.getConstArray();
1835 Sequence< PropertyState > aRet ( PropertyNames.getLength() );
1836 PropertyState* pStates = aRet.getArray();
1838 SfxItemSet *pSet = 0, *pSetParent = 0;
1839 const SfxItemPropertyMap *pMap = rPropSet.getPropertyMap();
1840 for( INT32 i = 0, nEnd = PropertyNames.getLength(); i < nEnd; i++ )
1842 const SfxItemPropertySimpleEntry* pEntry = pMap->getByName( pNames[i] );
1843 if(!pEntry)
1845 if(pNames[i].equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)) ||
1846 pNames[i].equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT)))
1848 pStates[i] = beans::PropertyState_DEFAULT_VALUE;
1849 continue;
1851 else if( SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT == eCaller )
1853 //this values marks the element as unknown property
1854 pStates[i] = beans::PropertyState_MAKE_FIXED_SIZE;
1855 continue;
1857 else
1858 throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + pNames[i], static_cast < cppu::OWeakObject * > ( 0 ) );
1860 if ((eCaller == SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION || eCaller == SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT) &&
1861 pEntry->nWID < FN_UNO_RANGE_BEGIN &&
1862 pEntry->nWID > FN_UNO_RANGE_END &&
1863 pEntry->nWID < RES_CHRATR_BEGIN &&
1864 pEntry->nWID > RES_TXTATR_END )
1865 pStates[i] = beans::PropertyState_DEFAULT_VALUE;
1866 else
1868 if ( pEntry->nWID >= FN_UNO_RANGE_BEGIN &&
1869 pEntry->nWID <= FN_UNO_RANGE_END )
1870 SwUnoCursorHelper::getCrsrPropertyValue(*pEntry, rPaM, 0, pStates[i] );
1871 else
1873 if( !pSet )
1875 switch ( eCaller )
1877 case SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT:
1878 case SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION:
1879 pSet = new SfxItemSet( rPaM.GetDoc()->GetAttrPool(),
1880 RES_CHRATR_BEGIN, RES_TXTATR_END );
1881 break;
1882 case SW_PROPERTY_STATE_CALLER_SINGLE_VALUE_ONLY:
1883 pSet = new SfxItemSet( rPaM.GetDoc()->GetAttrPool(),
1884 pEntry->nWID, pEntry->nWID );
1885 break;
1886 default:
1887 pSet = new SfxItemSet( rPaM.GetDoc()->GetAttrPool(),
1888 RES_CHRATR_BEGIN, RES_FRMATR_END - 1,
1889 RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER,
1890 RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER,
1891 0L );
1893 // --> OD 2006-07-12 #i63870#
1894 SwXTextCursor::GetCrsrAttr( rPaM, *pSet );
1895 // <--
1898 if( pSet->Count() )
1899 pStates[i] = rPropSet.getPropertyState( *pEntry, *pSet );
1900 else
1901 pStates[i] = PropertyState_DEFAULT_VALUE;
1903 //try again to find out if a value has been inherited
1904 if( beans::PropertyState_DIRECT_VALUE == pStates[i] )
1906 if( !pSetParent )
1908 pSetParent = pSet->Clone( FALSE );
1909 // --> OD 2006-07-12 #i63870#
1910 SwXTextCursor::GetCrsrAttr( rPaM, *pSetParent, TRUE, FALSE );
1911 // <--
1914 if( (pSetParent)->Count() )
1915 pStates[i] = rPropSet.getPropertyState( *pEntry, *pSetParent );
1916 else
1917 pStates[i] = PropertyState_DEFAULT_VALUE;
1922 delete pSet;
1923 delete pSetParent;
1924 return aRet;
1926 /* -----------------------------03.05.00 13:17--------------------------------
1928 ---------------------------------------------------------------------------*/
1929 PropertyState SwXTextCursor::GetPropertyState(
1930 SwPaM& rPaM, const SfxItemPropertySet& rPropSet, const OUString& rPropertyName)
1931 throw(UnknownPropertyException, RuntimeException)
1933 Sequence < OUString > aStrings ( 1 );
1934 aStrings[0] = rPropertyName;
1935 Sequence < PropertyState > aSeq = GetPropertyStates( rPaM, rPropSet, aStrings, SW_PROPERTY_STATE_CALLER_SINGLE_VALUE_ONLY );
1936 return aSeq[0];
1938 /* -----------------------------03.05.00 13:20--------------------------------
1940 ---------------------------------------------------------------------------*/
1941 void lcl_SelectParaAndReset ( SwPaM &rPaM, SwDoc* pDoc, const SvUShortsSort* pWhichIds = 0 )
1943 // if we are reseting paragraph attributes, we need to select the full paragraph first
1944 SwPosition aStart = *rPaM.Start();
1945 SwPosition aEnd = *rPaM.End();
1946 auto_ptr < SwUnoCrsr > pTemp ( pDoc->CreateUnoCrsr(aStart, FALSE) );
1947 if(!SwUnoCursorHelper::IsStartOfPara(*pTemp))
1948 pTemp->MovePara(fnParaCurr, fnParaStart);
1949 pTemp->SetMark();
1950 *pTemp->GetPoint() = aEnd;
1951 SwXTextCursor::SelectPam(*pTemp, sal_True);
1952 if(!SwUnoCursorHelper::IsEndOfPara(*pTemp))
1953 pTemp->MovePara(fnParaCurr, fnParaEnd);
1954 pDoc->ResetAttrs(*pTemp, sal_True, pWhichIds);
1958 void SwXTextCursor::SetPropertyToDefault(
1959 SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
1960 const OUString& rPropertyName)
1961 throw(UnknownPropertyException, RuntimeException)
1963 NAMESPACE_VOS(OGuard) aGuard(Application::GetSolarMutex());
1964 SwDoc* pDoc = rPaM.GetDoc();
1965 const SfxItemPropertySimpleEntry* pEntry = rPropSet.getPropertyMap()->getByName( rPropertyName);
1966 if(pEntry)
1968 if ( pEntry->nFlags & PropertyAttribute::READONLY)
1969 throw RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "setPropertyToDefault: property is read-only: " ) ) + rPropertyName, 0 );
1970 if(pEntry->nWID < RES_FRMATR_END)
1972 SvUShortsSort aWhichIds;
1973 aWhichIds.Insert(pEntry->nWID);
1974 if(pEntry->nWID < RES_PARATR_BEGIN)
1975 pDoc->ResetAttrs(rPaM, sal_True, &aWhichIds);
1976 else
1977 lcl_SelectParaAndReset ( rPaM, pDoc, &aWhichIds );
1979 else
1980 SwUnoCursorHelper::resetCrsrPropertyValue(*pEntry, rPaM);
1982 else
1983 throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( 0 ) );
1985 /* -----------------------------03.05.00 13:19--------------------------------
1987 ---------------------------------------------------------------------------*/
1988 Any SwXTextCursor::GetPropertyDefault(
1989 SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
1990 const OUString& rPropertyName)
1991 throw( UnknownPropertyException, WrappedTargetException, RuntimeException)
1993 Any aRet;
1994 SwDoc* pDoc = rPaM.GetDoc();
1995 const SfxItemPropertySimpleEntry* pEntry = rPropSet.getPropertyMap()->getByName( rPropertyName);
1996 if(pEntry)
1998 if(pEntry->nWID < RES_FRMATR_END)
2000 const SfxPoolItem& rDefItem = pDoc->GetAttrPool().GetDefaultItem(pEntry->nWID);
2001 rDefItem.QueryValue(aRet, pEntry->nMemberId);
2004 else
2005 throw UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( 0 ) );
2006 return aRet;
2008 /*-- 09.12.98 14:18:54---------------------------------------------------
2010 -----------------------------------------------------------------------*/
2011 uno::Reference< beans::XPropertySetInfo > SwXTextCursor::getPropertySetInfo(void) throw( uno::RuntimeException )
2013 static uno::Reference< beans::XPropertySetInfo > xRef;
2014 if(!xRef.is())
2016 static SfxItemPropertyMapEntry aCrsrExtMap_Impl[] =
2018 { SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT), FN_SKIP_HIDDEN_TEXT, &::getBooleanCppuType(), PROPERTY_NONE, 0},
2019 { SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT), FN_SKIP_PROTECTED_TEXT, &::getBooleanCppuType(), PROPERTY_NONE, 0},
2020 {0,0,0,0,0,0}
2022 uno::Reference< beans::XPropertySetInfo > xInfo = m_pPropSet->getPropertySetInfo();
2023 // PropertySetInfo verlaengern!
2024 const uno::Sequence<beans::Property> aPropSeq = xInfo->getProperties();
2025 xRef = new SfxExtItemPropertySetInfo(
2026 aCrsrExtMap_Impl,
2027 aPropSeq );
2029 return xRef;
2031 /*-- 09.12.98 14:18:54---------------------------------------------------
2033 -----------------------------------------------------------------------*/
2034 void SwXTextCursor::setPropertyValue(const OUString& rPropertyName, const uno::Any& aValue)
2035 throw( beans::UnknownPropertyException, beans::PropertyVetoException,
2036 lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
2038 vos::OGuard aGuard(Application::GetSolarMutex());
2039 SwUnoCrsr* pUnoCrsr = GetCrsr();
2040 if(pUnoCrsr)
2042 if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)))
2044 sal_Bool bSet = *(sal_Bool*)aValue.getValue();
2045 pUnoCrsr->SetSkipOverHiddenSections(bSet);
2047 else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT)))
2049 sal_Bool bSet = *(sal_Bool*)aValue.getValue();
2050 pUnoCrsr->SetSkipOverProtectSections(bSet);
2052 else
2053 SetPropertyValue(*pUnoCrsr, *m_pPropSet, rPropertyName, aValue);
2055 else
2056 throw uno::RuntimeException();
2059 /*-- 09.12.98 14:18:55---------------------------------------------------
2061 -----------------------------------------------------------------------*/
2062 Any SwXTextCursor::getPropertyValue(const OUString& rPropertyName)
2063 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
2065 vos::OGuard aGuard(Application::GetSolarMutex());
2066 uno::Any aAny;
2067 SwUnoCrsr* pUnoCrsr = GetCrsr();
2068 if(pUnoCrsr)
2070 if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)))
2072 BOOL bSet = pUnoCrsr->IsSkipOverHiddenSections();
2073 aAny.setValue(&bSet, ::getBooleanCppuType());
2075 else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT)))
2077 BOOL bSet = pUnoCrsr->IsSkipOverProtectSections();
2078 aAny.setValue(&bSet, ::getBooleanCppuType());
2080 else
2081 aAny = GetPropertyValue(*pUnoCrsr, *m_pPropSet, rPropertyName);
2083 else
2084 throw uno::RuntimeException();
2085 return aAny;
2088 /*-- 09.12.98 14:18:55---------------------------------------------------
2090 -----------------------------------------------------------------------*/
2091 void SwXTextCursor::addPropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
2093 DBG_WARNING("not implemented");
2095 /*-- 09.12.98 14:18:57---------------------------------------------------
2097 -----------------------------------------------------------------------*/
2098 void SwXTextCursor::removePropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
2100 DBG_WARNING("not implemented");
2102 /*-- 09.12.98 14:18:57---------------------------------------------------
2104 -----------------------------------------------------------------------*/
2105 void SwXTextCursor::addVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
2107 DBG_WARNING("not implemented");
2109 /*-- 09.12.98 14:18:58---------------------------------------------------
2111 -----------------------------------------------------------------------*/
2112 void SwXTextCursor::removeVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
2114 DBG_WARNING("not implemented");
2116 /*-- 05.03.99 11:36:11---------------------------------------------------
2118 -----------------------------------------------------------------------*/
2119 beans::PropertyState SwXTextCursor::getPropertyState(const OUString& rPropertyName)
2120 throw( beans::UnknownPropertyException, uno::RuntimeException )
2122 vos::OGuard aGuard(Application::GetSolarMutex());
2123 beans::PropertyState eRet = beans::PropertyState_DEFAULT_VALUE;
2124 SwUnoCrsr* pUnoCrsr = GetCrsr();
2125 if(pUnoCrsr)
2127 eRet = GetPropertyState(*pUnoCrsr, *m_pPropSet, rPropertyName);
2129 else
2130 throw RuntimeException();
2131 return eRet;
2133 /*-- 05.03.99 11:36:11---------------------------------------------------
2135 -----------------------------------------------------------------------*/
2136 uno::Sequence< beans::PropertyState > SwXTextCursor::getPropertyStates(
2137 const uno::Sequence< OUString >& PropertyNames)
2138 throw( beans::UnknownPropertyException, uno::RuntimeException )
2140 vos::OGuard aGuard(Application::GetSolarMutex());
2141 SwUnoCrsr* pUnoCrsr = GetCrsr();
2142 if(!pUnoCrsr)
2143 throw RuntimeException();
2144 return GetPropertyStates(*pUnoCrsr, *m_pPropSet, PropertyNames);
2146 /*-- 05.03.99 11:36:12---------------------------------------------------
2148 -----------------------------------------------------------------------*/
2149 void SwXTextCursor::setPropertyToDefault(const OUString& rPropertyName)
2150 throw( beans::UnknownPropertyException, uno::RuntimeException )
2152 Sequence < OUString > aSequence ( &rPropertyName, 1 );
2153 setPropertiesToDefault ( aSequence );
2155 /*-- 05.03.99 11:36:12---------------------------------------------------
2157 -----------------------------------------------------------------------*/
2158 uno::Any SwXTextCursor::getPropertyDefault(const OUString& rPropertyName)
2159 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
2161 const Sequence < OUString > aSequence ( &rPropertyName, 1 );
2162 return getPropertyDefaults ( aSequence ).getConstArray()[0];
2165 void SAL_CALL SwXTextCursor::setAllPropertiesToDefault()
2166 throw (RuntimeException)
2168 vos::OGuard aGuard(Application::GetSolarMutex());
2170 SwUnoCrsr* pUnoCrsr = GetCrsr();
2171 if (pUnoCrsr)
2173 // para specific attribut ranges
2174 USHORT aParaResetableSetRange[] = {
2175 RES_FRMATR_BEGIN, RES_FRMATR_END-1,
2176 RES_PARATR_BEGIN, RES_PARATR_END-1,
2177 // --> OD 2008-02-25 #refactorlists#
2178 RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1,
2179 // <--
2180 RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1,
2183 // selection specific attribut ranges
2184 USHORT aResetableSetRange[] = {
2185 RES_CHRATR_BEGIN, RES_CHRATR_END-1,
2186 RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT,
2187 RES_TXTATR_INETFMT, RES_TXTATR_INETFMT,
2188 RES_TXTATR_CJK_RUBY, RES_TXTATR_UNKNOWN_CONTAINER,
2191 SvUShortsSort aParaWhichIds;
2192 SvUShortsSort aWhichIds;
2193 for (USHORT k = 0; k < 2; ++k)
2195 SvUShortsSort &rWhichIds = k == 0? aParaWhichIds : aWhichIds;
2196 USHORT *pResetableSetRange = k == 0? aParaResetableSetRange : aResetableSetRange;
2197 while (*pResetableSetRange)
2199 USHORT nStart = sal::static_int_cast< USHORT >(*pResetableSetRange++);
2200 USHORT nEnd = sal::static_int_cast< USHORT >(*pResetableSetRange++);
2201 for (USHORT nId = nStart + 1; nId <= nEnd; ++nId)
2202 rWhichIds.Insert( nId );
2205 if (aParaWhichIds.Count())
2206 lcl_SelectParaAndReset( *pUnoCrsr, pUnoCrsr->GetDoc(), &aParaWhichIds );
2207 if (aWhichIds.Count() )
2208 pUnoCrsr->GetDoc()->ResetAttrs( *pUnoCrsr, sal_True, &aWhichIds );
2210 else
2211 throw uno::RuntimeException();
2214 void SAL_CALL SwXTextCursor::setPropertiesToDefault( const Sequence< OUString >& aPropertyNames )
2215 throw (UnknownPropertyException, RuntimeException)
2217 vos::OGuard aGuard(Application::GetSolarMutex());
2218 sal_Int32 nCount = aPropertyNames.getLength();
2219 if ( nCount )
2221 SwUnoCrsr* pUnoCrsr = GetCrsr();
2222 if(pUnoCrsr)
2224 SwDoc* pDoc = pUnoCrsr->GetDoc();
2225 const OUString * pNames = aPropertyNames.getConstArray();
2226 SvUShortsSort aWhichIds, aParaWhichIds;
2227 for ( sal_Int32 i = 0; i < nCount; i++ )
2229 const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap()->getByName( pNames[i] );
2230 if(!pEntry)
2232 if(pNames[i].equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)) ||
2233 pNames[i].equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT)))
2235 continue;
2237 else
2238 throw UnknownPropertyException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + pNames[i], static_cast < cppu::OWeakObject * > ( 0 ) );
2240 if( pEntry->nFlags & PropertyAttribute::READONLY)
2241 throw RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "setPropertiesToDefault: property is read-only: " ) ) + pNames[i], static_cast < cppu::OWeakObject * > ( this ) );
2243 if( pEntry->nWID < RES_FRMATR_END)
2245 if(pEntry->nWID < RES_PARATR_BEGIN)
2246 aWhichIds.Insert(pEntry->nWID);
2247 else
2248 aParaWhichIds.Insert (pEntry->nWID);
2250 else if ( pEntry->nWID == FN_UNO_NUM_START_VALUE )
2251 SwUnoCursorHelper::resetCrsrPropertyValue(*pEntry, *pUnoCrsr);
2254 if ( aParaWhichIds.Count() )
2255 lcl_SelectParaAndReset ( *pUnoCrsr, pDoc, &aParaWhichIds );
2256 if (aWhichIds.Count() )
2257 pDoc->ResetAttrs(*pUnoCrsr, sal_True, &aWhichIds);
2259 else
2260 throw uno::RuntimeException();
2263 Sequence< Any > SAL_CALL SwXTextCursor::getPropertyDefaults( const Sequence< OUString >& aPropertyNames )
2264 throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
2266 vos::OGuard aGuard(Application::GetSolarMutex());
2267 sal_Int32 nCount = aPropertyNames.getLength();
2268 Sequence < Any > aRet ( nCount );
2269 if ( nCount )
2271 SwUnoCrsr* pUnoCrsr = GetCrsr();
2272 if (pUnoCrsr)
2274 SwDoc* pDoc = pUnoCrsr->GetDoc();
2275 const OUString *pNames = aPropertyNames.getConstArray();
2276 Any *pAny = aRet.getArray();
2277 for ( sal_Int32 i = 0; i < nCount; i++)
2279 const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap()->getByName( pNames[i] );
2280 if(!pEntry)
2282 if(pNames[i].equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)) ||
2283 pNames[i].equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT)))
2285 continue;
2287 else
2288 throw UnknownPropertyException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + pNames[i], static_cast < cppu::OWeakObject * > ( 0 ) );
2290 if(pEntry->nWID < RES_FRMATR_END)
2292 const SfxPoolItem& rDefItem = pDoc->GetAttrPool().GetDefaultItem(pEntry->nWID);
2293 rDefItem.QueryValue(pAny[i], pEntry->nMemberId);
2297 else
2298 throw UnknownPropertyException();
2300 return aRet;
2303 /*-- 10.03.2008 09:58:47---------------------------------------------------
2305 -----------------------------------------------------------------------*/
2306 void SwXTextCursor::makeRedline(
2307 const ::rtl::OUString& rRedlineType,
2308 const uno::Sequence< beans::PropertyValue >& rRedlineProperties )
2309 throw (lang::IllegalArgumentException, uno::RuntimeException)
2311 vos::OGuard aGuard(Application::GetSolarMutex());
2312 SwUnoCrsr* pUnoCrsr = GetCrsr();
2313 if(pUnoCrsr)
2314 SwUnoCursorHelper::makeRedline( *pUnoCrsr, rRedlineType, rRedlineProperties );
2315 else
2316 throw uno::RuntimeException();