LCOV - code coverage report
Current view: top level - sw/source/core/unocore - unoobj.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1183 1423 83.1 %
Date: 2014-04-11 Functions: 101 117 86.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10