LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/uno - unotxdoc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 915 2087 43.8 %
Date: 2013-07-09 Functions: 85 166 51.2 %
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             : 
      21             : #include <osl/mutex.hxx>
      22             : #include <vcl/image.hxx>
      23             : #include <vcl/virdev.hxx>
      24             : #include <vcl/svapp.hxx>
      25             : #include <vcl/print.hxx>
      26             : #include <sfx2/viewfrm.hxx>
      27             : #include <sfx2/sfxbasecontroller.hxx>
      28             : #include <sfx2/docfile.hxx>
      29             : #include <sfx2/printer.hxx>
      30             : #include <toolkit/helper/vclunohelper.hxx>
      31             : #include <toolkit/awt/vclxdevice.hxx>
      32             : #include <cmdid.h>
      33             : #include <swtypes.hxx>
      34             : #include <wdocsh.hxx>
      35             : #include <wrtsh.hxx>
      36             : #include <pview.hxx>
      37             : #include <viewsh.hxx>
      38             : #include <pvprtdat.hxx>
      39             : #include <printdata.hxx>
      40             : #include <svl/stritem.hxx>
      41             : #include <unotxdoc.hxx>
      42             : #include <svl/numuno.hxx>
      43             : #include <fldbas.hxx>
      44             : #include <unotextbodyhf.hxx>
      45             : #include <unotextrange.hxx>
      46             : #include <unotextcursor.hxx>
      47             : #include <unosett.hxx>
      48             : #include <unocoll.hxx>
      49             : #include <unoredlines.hxx>
      50             : #include <unosrch.hxx>
      51             : #include <sfx2/dispatch.hxx>
      52             : #include <sfx2/request.hxx>
      53             : #include <sfx2/objsh.hxx>   // SfxObjectShellRef <-> SV_DECL_REF(SfxObjectShell)
      54             : #include <unoprnms.hxx>
      55             : #include <unostyle.hxx>
      56             : #include <unodraw.hxx>
      57             : #include <svl/eitem.hxx>
      58             : #include <pagedesc.hxx>
      59             : #include <unotools/textsearch.hxx>
      60             : #include <unocrsr.hxx>
      61             : #include <unofieldcoll.hxx>
      62             : #include <unoidxcoll.hxx>
      63             : #include <unocrsrhelper.hxx>
      64             : #include <unotxvw.hxx>
      65             : #include <poolfmt.hxx>
      66             : #include <globdoc.hxx>
      67             : #include <viewopt.hxx>
      68             : #include <unochart.hxx>
      69             : #include <charatr.hxx>
      70             : #include <svx/xmleohlp.hxx>
      71             : #include <globals.hrc>
      72             : #include <unomid.h>
      73             : #include <unotools/printwarningoptions.hxx>
      74             : #include <com/sun/star/util/SearchOptions.hpp>
      75             : #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
      76             : #include <com/sun/star/lang/DisposedException.hpp>
      77             : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      78             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      79             : #include <com/sun/star/beans/XFastPropertySet.hpp>
      80             : #include <com/sun/star/document/RedlineDisplayType.hpp>
      81             : #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
      82             : #include <com/sun/star/frame/XController.hpp>
      83             : #include <com/sun/star/frame/XFrame.hpp>
      84             : #include <com/sun/star/script/XInvocation.hpp>
      85             : #include <sfx2/linkmgr.hxx>
      86             : #include <svx/unofill.hxx>
      87             : #include <editeng/unolingu.hxx>
      88             : #include <sfx2/progress.hxx>
      89             : #include <swmodule.hxx>
      90             : #include <docstat.hxx>
      91             : #include <modcfg.hxx>
      92             : #include <ndtxt.hxx>
      93             : #include <utlui.hrc>
      94             : #include <swcont.hxx>
      95             : #include <unodefaults.hxx>
      96             : #include <SwXDocumentSettings.hxx>
      97             : #include <doc.hxx>
      98             : #include <editeng/forbiddencharacterstable.hxx>
      99             : #include <svl/zforlist.hxx>
     100             : #include <drawdoc.hxx>
     101             : #include <SwStyleNameMapper.hxx>
     102             : #include <osl/file.hxx>
     103             : #include <comphelper/storagehelper.hxx>
     104             : 
     105             : // #i12836# enhanced pdf export
     106             : #include <EnhancedPDFExportHelper.hxx>
     107             : #include <numrule.hxx>
     108             : 
     109             : #include <editeng/langitem.hxx>
     110             : #include <docary.hxx>      //SwCharFmts
     111             : #include <i18nlangtag/languagetag.hxx>
     112             : 
     113             : #include <format.hxx>
     114             : #include <charfmt.hxx>    //SwCharFmt
     115             : #include <fmtcol.hxx>     //SwTxtFmtColl
     116             : #include <unostyle.hxx>   //SwAutoStyleFamily
     117             : #include <istyleaccess.hxx> // handling of automatic styles
     118             : 
     119             : #include <svl/stylepool.hxx>
     120             : #include <swatrset.hxx>
     121             : #include <view.hxx>
     122             : #include <srcview.hxx>
     123             : 
     124             : #include <svtools/langtab.hxx>
     125             : #include <map>
     126             : #include <set>
     127             : #include <vector>
     128             : 
     129             : #include <editeng/eeitem.hxx>
     130             : #include <editeng/editeng.hxx>
     131             : #include <svx/svdoutl.hxx>
     132             : #include <svl/languageoptions.hxx>
     133             : #include <svx/svdview.hxx>
     134             : #include <comphelper/processfactory.hxx>
     135             : #include <comphelper/servicehelper.hxx>
     136             : 
     137             : using namespace ::com::sun::star;
     138             : using namespace ::com::sun::star::text;
     139             : using namespace ::com::sun::star::i18n;
     140             : using namespace ::com::sun::star::uno;
     141             : using namespace ::com::sun::star::beans;
     142             : using namespace ::com::sun::star::lang;
     143             : using namespace ::com::sun::star::container;
     144             : using namespace ::com::sun::star::document;
     145             : using ::osl::FileBase;
     146             : 
     147             : #define SW_CREATE_DASH_TABLE            0x01
     148             : #define SW_CREATE_GRADIENT_TABLE        0x02
     149             : #define SW_CREATE_HATCH_TABLE           0x03
     150             : #define SW_CREATE_BITMAP_TABLE          0x04
     151             : #define SW_CREATE_TRANSGRADIENT_TABLE   0x05
     152             : #define SW_CREATE_MARKER_TABLE          0x06
     153             : #define SW_CREATE_DRAW_DEFAULTS         0x07
     154             : 
     155             : extern bool sw_GetPostIts( IDocumentFieldsAccess* pIDFA, _SetGetExpFlds * pSrtLst );
     156             : 
     157           0 : static SwPrintUIOptions * lcl_GetPrintUIOptions(
     158             :     SwDocShell * pDocShell,
     159             :     const SfxViewShell * pView )
     160             : {
     161           0 :     if (!pDocShell)
     162           0 :         return NULL;
     163             : 
     164           0 :     const sal_Bool bWebDoc      = NULL != dynamic_cast< const SwWebDocShell * >(pDocShell);
     165           0 :     const bool bSwSrcView   = NULL != dynamic_cast< const SwSrcView * >(pView);
     166           0 :     const SwView * pSwView = dynamic_cast< const SwView * >(pView);
     167           0 :     const bool bHasSelection    = pSwView ? pSwView->HasSelection( sal_False ) : false;  // check for any selection, not just text selection
     168           0 :     const bool bHasPostIts      = sw_GetPostIts( pDocShell->GetDoc(), 0 );
     169             : 
     170             :     // get default values to use in dialog from documents SwPrintData
     171           0 :     const SwPrintData &rPrintData = pDocShell->GetDoc()->getPrintData();
     172             : 
     173             :     // Get current page number
     174           0 :     sal_uInt16 nCurrentPage = 1;
     175           0 :     SwWrtShell* pSh = pDocShell->GetWrtShell();
     176           0 :     if (pSh)
     177             :     {
     178           0 :         SwPaM* pShellCrsr = pSh->GetCrsr();
     179           0 :         nCurrentPage = pShellCrsr->GetPageNum(true, 0);
     180             :     }
     181           0 :     else if (!bSwSrcView)
     182             :     {
     183           0 :         const SwPagePreView* pPreView = dynamic_cast< const SwPagePreView* >(pView);
     184             :         OSL_ENSURE(pPreView, "Unexpected type of the view shell");
     185           0 :         if (pPreView)
     186           0 :             nCurrentPage = pPreView->GetSelectedPage();
     187             :     }
     188           0 :     return new SwPrintUIOptions( nCurrentPage, bWebDoc, bSwSrcView, bHasSelection, bHasPostIts, rPrintData );
     189             : }
     190             : 
     191           0 : static SwTxtFmtColl *lcl_GetParaStyle(const String& rCollName, SwDoc* pDoc)
     192             : {
     193           0 :     SwTxtFmtColl* pColl = pDoc->FindTxtFmtCollByName( rCollName );
     194           0 :     if( !pColl )
     195             :     {
     196           0 :         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( rCollName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
     197           0 :         if( USHRT_MAX != nId )
     198           0 :             pColl = pDoc->GetTxtCollFromPool( nId );
     199             :     }
     200           0 :     return pColl;
     201             : }
     202             : 
     203           0 : static void lcl_DisposeView( SfxViewFrame* pToClose, SwDocShell* pDocShell )
     204             : {
     205             :     // check if the view frame still exists
     206             :     SfxViewFrame* pFound = SfxViewFrame::GetFirst( pDocShell,
     207           0 :                                 sal_False );
     208           0 :     while(pFound)
     209             :     {
     210           0 :         if( pFound == pToClose)
     211             :         {
     212           0 :             pToClose->DoClose();
     213           0 :             break;
     214             :         }
     215             :         pFound = SfxViewFrame::GetNext( *pFound,
     216             :                                 pDocShell,
     217           0 :                                 sal_False );
     218             :     }
     219           0 : }
     220             : 
     221         655 : class SwXTextDocument::Impl
     222             : {
     223             : private:
     224             :     ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper
     225             : 
     226             : public:
     227             :     ::cppu::OInterfaceContainerHelper m_RefreshListeners;
     228             : 
     229         902 :     Impl() : m_RefreshListeners(m_Mutex) { }
     230             : 
     231             : };
     232             : 
     233             : namespace
     234             : {
     235             :     class theSwXTextDocumentUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXTextDocumentUnoTunnelId > {};
     236             : }
     237             : 
     238       29496 : const Sequence< sal_Int8 > & SwXTextDocument::getUnoTunnelId()
     239             : {
     240       29496 :     return theSwXTextDocumentUnoTunnelId::get().getSeq();
     241             : }
     242             : 
     243       29256 : sal_Int64 SAL_CALL SwXTextDocument::getSomething( const Sequence< sal_Int8 >& rId )
     244             :     throw(RuntimeException)
     245             : {
     246       58512 :     if( rId.getLength() == 16
     247       87768 :         && 0 == memcmp( getUnoTunnelId().getConstArray(),
     248       58512 :                                         rId.getConstArray(), 16 ) )
     249             :     {
     250         240 :             return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
     251             :     }
     252       58032 :     if( rId.getLength() == 16
     253       87048 :         && 0 == memcmp( SfxObjectShell::getUnoTunnelId().getConstArray(),
     254       58032 :                                         rId.getConstArray(), 16 ) )
     255             :     {
     256           0 :         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(pDocShell ));
     257             :     }
     258             : 
     259       29016 :     sal_Int64 nRet = SfxBaseModel::getSomething( rId );
     260       29016 :     if ( nRet )
     261       28851 :         return nRet;
     262             :     else
     263             :     {
     264         165 :         GetNumberFormatter();
     265         165 :         Any aNumTunnel = xNumFmtAgg->queryAggregation(::getCppuType((Reference<XUnoTunnel>*)0));
     266         165 :         Reference<XUnoTunnel> xNumTunnel;
     267         165 :         aNumTunnel >>= xNumTunnel;
     268         165 :         if(xNumTunnel.is())
     269         165 :             return xNumTunnel->getSomething(rId);
     270             :     }
     271             : 
     272           0 :     return SfxBaseModel::getSomething( rId );
     273             : }
     274             : 
     275      342281 : Any SAL_CALL SwXTextDocument::queryInterface( const uno::Type& rType ) throw(RuntimeException)
     276             : {
     277      342281 :     Any aRet = SwXTextDocumentBaseClass::queryInterface(rType);
     278      342281 :     if ( !aRet.hasValue() )
     279      211850 :         aRet = SfxBaseModel::queryInterface(rType);
     280      384944 :     if ( !aRet.hasValue() &&
     281       42663 :         rType == ::getCppuType((Reference<lang::XMultiServiceFactory>*)0))
     282             :     {
     283        3680 :         Reference<lang::XMultiServiceFactory> xTmp = this;
     284        3680 :         aRet <<= xTmp;
     285             :     }
     286             : 
     287      684562 :     if ( !aRet.hasValue()
     288       38983 :         && rType != ::getCppuType((Reference< com::sun::star::document::XDocumentEventBroadcaster>*)0)
     289       38983 :         && rType != ::getCppuType((Reference< com::sun::star::frame::XController>*)0)
     290       25746 :         && rType != ::getCppuType((Reference< com::sun::star::frame::XFrame>*)0)
     291       12509 :         && rType != ::getCppuType((Reference< com::sun::star::script::XInvocation>*)0)
     292       11501 :         && rType != ::getCppuType((Reference< com::sun::star::beans::XFastPropertySet>*)0)
     293      353752 :         && rType != ::getCppuType((Reference< com::sun::star::awt::XWindow>*)0))
     294             :     {
     295        1031 :         GetNumberFormatter();
     296        1031 :         if(xNumFmtAgg.is())
     297        1031 :             aRet = xNumFmtAgg->queryAggregation(rType);
     298             :     }
     299      342281 :     return aRet;
     300             : }
     301             : 
     302     1030650 : void SAL_CALL SwXTextDocument::acquire()throw()
     303             : {
     304     1030650 :     SfxBaseModel::acquire();
     305     1030650 : }
     306             : 
     307     1030113 : void SAL_CALL SwXTextDocument::release()throw()
     308             : {
     309     1030113 :     SfxBaseModel::release();
     310     1030113 : }
     311             : 
     312        9378 : Reference< XAdapter > SwXTextDocument::queryAdapter(  ) throw(RuntimeException)
     313             : {
     314        9378 :     return SfxBaseModel::queryAdapter();
     315             : }
     316             : 
     317         805 : Sequence< uno::Type > SAL_CALL SwXTextDocument::getTypes() throw(RuntimeException)
     318             : {
     319         805 :     Sequence< uno::Type > aBaseTypes = SfxBaseModel::getTypes();
     320        1610 :     Sequence< uno::Type > aTextTypes = SwXTextDocumentBaseClass::getTypes();
     321             : 
     322        1610 :     Sequence< uno::Type > aNumTypes;
     323         805 :     GetNumberFormatter();
     324         805 :     if(xNumFmtAgg.is())
     325             :     {
     326         805 :         const uno::Type& rProvType = ::getCppuType((Reference <XTypeProvider>*)0);
     327         805 :         Any aNumProv = xNumFmtAgg->queryAggregation(rProvType);
     328        1610 :         Reference<XTypeProvider> xNumProv;
     329         805 :         if(aNumProv >>= xNumProv)
     330             :         {
     331         805 :             aNumTypes = xNumProv->getTypes();
     332         805 :         }
     333             :     }
     334         805 :     long nIndex = aBaseTypes.getLength();
     335             :     // don't forget the lang::XMultiServiceFactory
     336         805 :     aBaseTypes.realloc(aBaseTypes.getLength() + aTextTypes.getLength() + aNumTypes.getLength() + 1);
     337         805 :     uno::Type* pBaseTypes = aBaseTypes.getArray();
     338         805 :     const uno::Type* pTextTypes = aTextTypes.getConstArray();
     339             :     long nPos;
     340       28175 :     for(nPos = 0; nPos < aTextTypes.getLength(); nPos++)
     341             :     {
     342       27370 :         pBaseTypes[nIndex++] = pTextTypes[nPos];
     343             :     }
     344         805 :     const uno::Type* pNumTypes = aNumTypes.getConstArray();
     345        4830 :     for(nPos = 0; nPos < aNumTypes.getLength(); nPos++)
     346             :     {
     347        4025 :         pBaseTypes[nIndex++] = pNumTypes[nPos];
     348             :     }
     349         805 :     pBaseTypes[nIndex++] = ::getCppuType((Reference<lang::XMultiServiceFactory>*)0);
     350        1610 :     return aBaseTypes;
     351             : }
     352             : 
     353         902 : SwXTextDocument::SwXTextDocument(SwDocShell* pShell)
     354             :     : SfxBaseModel(pShell)
     355         902 :     , m_pImpl(new Impl)
     356             :     ,
     357         902 :     pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_DOCUMENT)),
     358             : 
     359             :     pDocShell(pShell),
     360             : 
     361         902 :     bObjectValid(pShell != 0),
     362             : 
     363             :     pDrawPage(0),
     364             :     pxXDrawPage(0),
     365             : 
     366             :     pxXNumberingRules(0),
     367             :     pxXFootnotes(0),
     368             :     pxXFootnoteSettings(0),
     369             :     pxXEndnotes(0),
     370             :     pxXEndnoteSettings(0),
     371             :     pxXReferenceMarks(0),
     372             :     pxXTextFieldTypes(0),
     373             :     pxXTextFieldMasters(0),
     374             :     pxXTextSections(0),
     375             :     pxXBookmarks(0),
     376             :     pxXTextTables(0),
     377             :     pxXTextFrames(0),
     378             :     pxXGraphicObjects(0),
     379             :     pxXEmbeddedObjects(0),
     380             :     pxXStyleFamilies(0),
     381             :     pxXAutoStyles(0),
     382             :     pxXChapterNumbering(0),
     383             :     pxXDocumentIndexes(0),
     384             : 
     385             :     pxXLineNumberingProperties(0),
     386             :     pxLinkTargetSupplier(0),
     387             :     pxXRedlines(0),
     388             :     m_pHiddenViewFrame(0),
     389             :     m_pPrintUIOptions( NULL ),
     390             :     m_pRenderData( NULL ),
     391             :     // #i117783#
     392        3608 :     bApplyPagePrintSettingsFromXPagePrintable( sal_False )
     393             : {
     394         902 : }
     395             : 
     396        1965 : SwXTextDocument::~SwXTextDocument()
     397             : {
     398         655 :     InitNewDoc();
     399         655 :     if(xNumFmtAgg.is())
     400             :     {
     401         587 :         Reference< XInterface >  x0;
     402         587 :         xNumFmtAgg->setDelegator(x0);
     403         587 :         xNumFmtAgg = 0;
     404             :     }
     405         655 :     delete m_pPrintUIOptions;
     406         655 :     if (m_pRenderData && m_pRenderData->IsViewOptionAdjust())
     407             :     {   // rhbz#827695: this can happen if the last page is not printed
     408             :         // the ViewShell has been deleted already by SwView::~SwView
     409             :         // FIXME: replace this awful implementation of XRenderable with
     410             :         // something less insane that has its own view
     411           0 :         m_pRenderData->ViewOptionAdjustCrashPreventionKludge();
     412             :     }
     413         655 :     delete m_pRenderData;
     414        1310 : }
     415             : 
     416         196 : SwXDocumentPropertyHelper * SwXTextDocument::GetPropertyHelper ()
     417             : {
     418         196 :     if(!xPropertyHelper.is())
     419             :     {
     420          66 :         pPropertyHelper = new SwXDocumentPropertyHelper(*pDocShell->GetDoc());
     421          66 :         xPropertyHelper = (cppu::OWeakObject*)pPropertyHelper;
     422             :     }
     423         196 :     return pPropertyHelper;
     424             : }
     425             : 
     426        2001 : void SwXTextDocument::GetNumberFormatter()
     427             : {
     428        2001 :     if(IsValid())
     429             :     {
     430        1999 :         if(!xNumFmtAgg.is())
     431             :         {
     432         795 :             if ( pDocShell->GetDoc() )
     433             :             {
     434             :                 SvNumberFormatsSupplierObj* pNumFmt = new SvNumberFormatsSupplierObj(
     435         795 :                                     pDocShell->GetDoc()->GetNumberFormatter( sal_True ));
     436         795 :                 Reference< util::XNumberFormatsSupplier >  xTmp = pNumFmt;
     437         795 :                 xNumFmtAgg = Reference< XAggregation >(xTmp, UNO_QUERY);
     438             :             }
     439         795 :             if(xNumFmtAgg.is())
     440         795 :                 xNumFmtAgg->setDelegator((cppu::OWeakObject*)(SwXTextDocumentBaseClass*)this);
     441             :         }
     442             :         else
     443             :         {
     444        1204 :             const uno::Type& rTunnelType = ::getCppuType((Reference <XUnoTunnel>*)0);
     445        1204 :             Any aNumTunnel = xNumFmtAgg->queryAggregation(rTunnelType);
     446        1204 :             SvNumberFormatsSupplierObj* pNumFmt = 0;
     447        2408 :             Reference< XUnoTunnel > xNumTunnel;
     448        1204 :             if(aNumTunnel >>= xNumTunnel)
     449             :             {
     450             :                 pNumFmt = reinterpret_cast<SvNumberFormatsSupplierObj*>(
     451        1204 :                         xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
     452             : 
     453             :             }
     454             :             OSL_ENSURE(pNumFmt, "No number formatter available");
     455        1204 :             if(!pNumFmt->GetNumberFormatter())
     456        1204 :                 pNumFmt->SetNumberFormatter(pDocShell->GetDoc()->GetNumberFormatter( sal_True ));
     457             :         }
     458             :     }
     459        2001 : }
     460             : 
     461        7406 : Reference< XText >  SwXTextDocument::getText(void) throw( RuntimeException )
     462             : {
     463        7406 :     SolarMutexGuard aGuard;
     464        7406 :     if(!IsValid())
     465           0 :         throw RuntimeException();
     466        7406 :     if(!xBodyText.is())
     467             :     {
     468         575 :         pBodyText = new SwXBodyText(pDocShell->GetDoc());
     469         575 :         xBodyText = pBodyText;
     470             :     }
     471        7406 :     return xBodyText;
     472             : }
     473             : 
     474           1 : void SwXTextDocument::reformat(void) throw( RuntimeException )
     475             : {
     476           1 :     SolarMutexGuard aGuard;
     477           1 :     if(!IsValid())
     478           0 :         throw RuntimeException();
     479           1 : }
     480             : 
     481         119 : void SwXTextDocument::lockControllers(void) throw( RuntimeException )
     482             : {
     483         119 :     SolarMutexGuard aGuard;
     484         119 :     if(IsValid())
     485             :     {
     486         119 :         UnoActionContext* pContext = new UnoActionContext(pDocShell->GetDoc());
     487         119 :         aActionArr.push_front(pContext);
     488             :     }
     489             :     else
     490           0 :         throw RuntimeException();
     491         119 : }
     492             : 
     493         120 : void SwXTextDocument::unlockControllers(void) throw( RuntimeException )
     494             : {
     495         120 :     SolarMutexGuard aGuard;
     496         120 :     if(!aActionArr.empty())
     497             :     {
     498         119 :         UnoActionContext* pContext = aActionArr.front();
     499         119 :         aActionArr.pop_front();
     500         119 :         delete pContext;
     501             :     }
     502             :     else
     503           1 :         throw RuntimeException();
     504         119 : }
     505             : 
     506          51 : sal_Bool SwXTextDocument::hasControllersLocked(void) throw( RuntimeException )
     507             : {
     508          51 :     SolarMutexGuard aGuard;
     509          51 :     return !aActionArr.empty();
     510             : }
     511             : 
     512        1333 : Reference< frame::XController >  SwXTextDocument::getCurrentController(void) throw( RuntimeException )
     513             : {
     514        1333 :     return SfxBaseModel::getCurrentController();
     515             : }
     516             : 
     517        1575 : void SwXTextDocument::setCurrentController(const Reference< frame::XController > & xController)
     518             :     throw( NoSuchElementException, RuntimeException )
     519             : {
     520        1575 :     SfxBaseModel::setCurrentController(xController);
     521        1575 : }
     522             : 
     523           1 : Reference< XInterface >  SwXTextDocument::getCurrentSelection() throw( RuntimeException )
     524             : {
     525           1 :     SolarMutexGuard aGuard;
     526           1 :     Reference< XInterface >  xRef;
     527           1 :     if(IsValid())
     528             :     {
     529             : 
     530           1 :         const TypeId aTypeId = TYPE(SwView);
     531           1 :         SwView* pView = (SwView*)SfxViewShell::GetFirst(&aTypeId);
     532           2 :         while(pView && pView->GetObjectShell() != pDocShell)
     533             :         {
     534           0 :             pView = (SwView*)SfxViewShell::GetNext(*pView, &aTypeId);
     535             :         }
     536           1 :         if(pView)
     537             :         {
     538           1 :             Any aRef = pView->GetUNOObject()->getSelection();
     539           1 :             aRef >>= xRef;
     540             :         }
     541             :     }
     542           1 :     return xRef;
     543             : }
     544             : 
     545        1303 : sal_Bool SwXTextDocument::attachResource(const OUString& aURL, const Sequence< beans::PropertyValue >& aArgs)
     546             :         throw( RuntimeException )
     547             : {
     548        1303 :     return SfxBaseModel::attachResource(aURL, aArgs);
     549             : }
     550             : 
     551        2381 : OUString SwXTextDocument::getURL(void) throw( RuntimeException )
     552             : {
     553        2381 :     return SfxBaseModel::getURL();
     554             : }
     555             : 
     556        3659 : Sequence< beans::PropertyValue > SwXTextDocument::getArgs(void) throw( RuntimeException )
     557             : {
     558        3659 :     return SfxBaseModel::getArgs();
     559             : }
     560             : 
     561         795 : void SwXTextDocument::connectController(const Reference< frame::XController > & xController) throw( RuntimeException )
     562             : {
     563         795 :     SfxBaseModel::connectController(xController);
     564         795 : }
     565             : 
     566         793 : void SwXTextDocument::disconnectController(const Reference< frame::XController > & xController) throw( RuntimeException )
     567             : {
     568         793 :     SfxBaseModel::disconnectController(xController);
     569         793 : }
     570             : 
     571        1292 : void SwXTextDocument::dispose(void) throw( RuntimeException )
     572             : {
     573        1292 :     SfxBaseModel::dispose();
     574        1292 : }
     575             : 
     576        1694 : void SwXTextDocument::close( sal_Bool bDeliverOwnership ) throw( util::CloseVetoException, RuntimeException )
     577             : {
     578        1694 :     SolarMutexGuard aGuard;
     579        1694 :     if(IsValid() && m_pHiddenViewFrame)
     580           0 :         lcl_DisposeView( m_pHiddenViewFrame, pDocShell);
     581        1694 :     SfxBaseModel::close(bDeliverOwnership);
     582        1694 : }
     583             : 
     584        1526 : void SwXTextDocument::addEventListener(const Reference< lang::XEventListener > & aListener) throw( RuntimeException )
     585             : {
     586        1526 :     SfxBaseModel::addEventListener(aListener);
     587        1526 : }
     588             : 
     589         270 : void SwXTextDocument::removeEventListener(const Reference< lang::XEventListener > & aListener) throw( RuntimeException )
     590             : {
     591         270 :     SfxBaseModel::removeEventListener(aListener);
     592         270 : }
     593             : 
     594          74 : Reference< XPropertySet > SwXTextDocument::getLineNumberingProperties(void)
     595             :             throw( RuntimeException )
     596             : {
     597          74 :     SolarMutexGuard aGuard;
     598          74 :     if(IsValid())
     599             :     {
     600          74 :         if(!pxXLineNumberingProperties)
     601             :         {
     602          61 :             pxXLineNumberingProperties = new Reference<XPropertySet>;
     603          61 :             (*pxXLineNumberingProperties) = new SwXLineNumberingProperties(pDocShell->GetDoc());
     604             :         }
     605             :     }
     606             :     else
     607           0 :         throw RuntimeException();
     608          74 :     return *pxXLineNumberingProperties;
     609             : }
     610             : 
     611         243 : Reference< XIndexReplace >  SwXTextDocument::getChapterNumberingRules(void)
     612             :                                     throw( RuntimeException )
     613             : {
     614         243 :     SolarMutexGuard aGuard;
     615         243 :     if(!IsValid())
     616           0 :         throw RuntimeException();
     617         243 :     if(!pxXChapterNumbering)
     618             :     {
     619          62 :         pxXChapterNumbering = new Reference< XIndexReplace > ;
     620          62 :         *pxXChapterNumbering = new SwXChapterNumbering(*pDocShell);
     621             :     }
     622         243 :     return *pxXChapterNumbering;
     623             : }
     624             : 
     625          17 : Reference< XIndexAccess >  SwXTextDocument::getNumberingRules(void) throw( RuntimeException )
     626             : {
     627          17 :     SolarMutexGuard aGuard;
     628          17 :     if(!IsValid())
     629           0 :         throw RuntimeException();
     630          17 :     if(!pxXNumberingRules )
     631             :     {
     632          16 :         ((SwXTextDocument*)this)->pxXNumberingRules = new Reference< XIndexAccess > ;
     633          16 :         *pxXNumberingRules = new SwXNumberingRulesCollection( pDocShell->GetDoc() );
     634             :     }
     635          17 :     return *pxXNumberingRules;
     636             : }
     637             : 
     638           6 : Reference< XIndexAccess >  SwXTextDocument::getFootnotes(void) throw( RuntimeException )
     639             : {
     640           6 :     SolarMutexGuard aGuard;
     641           6 :     if(!IsValid())
     642           0 :         throw RuntimeException();
     643           6 :     if(!pxXFootnotes)
     644             :     {
     645           6 :         ((SwXTextDocument*)this)->pxXFootnotes = new Reference< XIndexAccess > ;
     646           6 :         *pxXFootnotes = new SwXFootnotes(sal_False, pDocShell->GetDoc());
     647             :     }
     648           6 :     return *pxXFootnotes;
     649             : }
     650             : 
     651             : Reference< XPropertySet >  SAL_CALL
     652         396 :         SwXTextDocument::getFootnoteSettings(void) throw( RuntimeException )
     653             : {
     654         396 :     SolarMutexGuard aGuard;
     655         396 :     if(!IsValid())
     656           0 :         throw RuntimeException();
     657         396 :     if(!pxXFootnoteSettings)
     658             :     {
     659         107 :         ((SwXTextDocument*)this)->pxXFootnoteSettings = new Reference< XPropertySet > ;
     660         107 :         *pxXFootnoteSettings = new SwXFootnoteProperties(pDocShell->GetDoc());
     661             :     }
     662         396 :     return *pxXFootnoteSettings;
     663             : }
     664             : 
     665           1 : Reference< XIndexAccess >  SwXTextDocument::getEndnotes(void) throw( RuntimeException )
     666             : {
     667           1 :     SolarMutexGuard aGuard;
     668           1 :     if(!IsValid())
     669           0 :         throw RuntimeException();
     670           1 :     if(!pxXEndnotes)
     671             :     {
     672           1 :         ((SwXTextDocument*)this)->pxXEndnotes = new Reference< XIndexAccess > ;
     673           1 :         *pxXEndnotes = new SwXFootnotes(sal_True, pDocShell->GetDoc());
     674             :     }
     675           1 :     return *pxXEndnotes;
     676             : }
     677             : 
     678         292 : Reference< XPropertySet >  SwXTextDocument::getEndnoteSettings(void) throw( RuntimeException )
     679             : {
     680         292 :     SolarMutexGuard aGuard;
     681         292 :     if(!IsValid())
     682           0 :         throw RuntimeException();
     683         292 :     if(!pxXEndnoteSettings)
     684             :     {
     685         106 :         ((SwXTextDocument*)this)->pxXEndnoteSettings = new Reference< XPropertySet > ;
     686         106 :         *pxXEndnoteSettings = new SwXEndnoteProperties(pDocShell->GetDoc());
     687             :     }
     688         292 :     return *pxXEndnoteSettings;
     689             : }
     690             : 
     691           1 : Reference< util::XReplaceDescriptor >  SwXTextDocument::createReplaceDescriptor(void)
     692             :     throw( RuntimeException )
     693             : {
     694           1 :     SolarMutexGuard aGuard;
     695           1 :     Reference< util::XReplaceDescriptor >  xRet = new SwXTextSearch;
     696           1 :     return xRet;
     697             : }
     698             : 
     699           8 : SwUnoCrsr*  SwXTextDocument::CreateCursorForSearch(Reference< XTextCursor > & xCrsr)
     700             : {
     701           8 :     getText();
     702           8 :     XText *const pText = xBodyText.get();
     703           8 :     SwXBodyText* pBText = (SwXBodyText*)pText;
     704           8 :     SwXTextCursor *const pXTextCursor = pBText->CreateTextCursor(true);
     705           8 :     xCrsr.set( static_cast<text::XWordCursor*>(pXTextCursor) );
     706             : 
     707           8 :     SwUnoCrsr *const pUnoCrsr = pXTextCursor->GetCursor();
     708           8 :     pUnoCrsr->SetRemainInSection(sal_False);
     709           8 :     return pUnoCrsr;
     710             : }
     711             : 
     712           2 : sal_Int32 SwXTextDocument::replaceAll(const Reference< util::XSearchDescriptor > & xDesc)
     713             :                                         throw( RuntimeException )
     714             : {
     715           2 :     SolarMutexGuard aGuard;
     716           4 :     Reference< XUnoTunnel > xDescTunnel(xDesc, UNO_QUERY);
     717           2 :     if(!IsValid() || !xDescTunnel.is() || !xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()))
     718           0 :         throw RuntimeException();
     719             : 
     720           4 :     Reference< XTextCursor >  xCrsr;
     721           2 :     SwUnoCrsr*  pUnoCrsr = CreateCursorForSearch(xCrsr);
     722             : 
     723             :     const SwXTextSearch* pSearch = reinterpret_cast<const SwXTextSearch*>(
     724           2 :             xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()));
     725             : 
     726           2 :     int eRanges(FND_IN_BODY|FND_IN_SELALL);
     727             : 
     728           4 :     util::SearchOptions aSearchOpt;
     729           2 :     pSearch->FillSearchOptions( aSearchOpt );
     730             : 
     731           2 :     SwDocPositions eStart = pSearch->bBack ? DOCPOS_END : DOCPOS_START;
     732           2 :     SwDocPositions eEnd = pSearch->bBack ? DOCPOS_START : DOCPOS_END;
     733             : 
     734             :     // Search should take place anywhere
     735           2 :     pUnoCrsr->SetRemainInSection(sal_False);
     736             :     sal_uInt32 nResult;
     737           4 :     UnoActionContext aContext(pDocShell->GetDoc());
     738             :     //try attribute search first
     739           2 :     if(pSearch->HasSearchAttributes()||pSearch->HasReplaceAttributes())
     740             :     {
     741           0 :         SfxItemSet aSearch(pDocShell->GetDoc()->GetAttrPool(),
     742             :                             RES_CHRATR_BEGIN, RES_CHRATR_END-1,
     743             :                             RES_PARATR_BEGIN, RES_PARATR_END-1,
     744             :                             RES_FRMATR_BEGIN, RES_FRMATR_END-1,
     745           0 :                             0);
     746           0 :         SfxItemSet aReplace(pDocShell->GetDoc()->GetAttrPool(),
     747             :                             RES_CHRATR_BEGIN, RES_CHRATR_END-1,
     748             :                             RES_PARATR_BEGIN, RES_PARATR_END-1,
     749             :                             RES_FRMATR_BEGIN, RES_FRMATR_END-1,
     750           0 :                             0);
     751           0 :         pSearch->FillSearchItemSet(aSearch);
     752           0 :         pSearch->FillReplaceItemSet(aReplace);
     753             :         sal_Bool bCancel;
     754             :         nResult = (sal_Int32)pUnoCrsr->Find( aSearch, !pSearch->bStyles,
     755             :                     eStart, eEnd, bCancel,
     756             :                     (FindRanges)eRanges,
     757           0 :                     pSearch->sSearchText.Len() ? &aSearchOpt : 0,
     758           0 :                     &aReplace );
     759             :     }
     760           2 :     else if(pSearch->bStyles)
     761             :     {
     762           0 :         SwTxtFmtColl *pSearchColl = lcl_GetParaStyle(pSearch->sSearchText, pUnoCrsr->GetDoc());
     763           0 :         SwTxtFmtColl *pReplaceColl = lcl_GetParaStyle(pSearch->sReplaceText, pUnoCrsr->GetDoc());
     764             : 
     765             :         sal_Bool bCancel;
     766             :         nResult = pUnoCrsr->Find( *pSearchColl,
     767             :                     eStart, eEnd, bCancel,
     768           0 :                     (FindRanges)eRanges, pReplaceColl );
     769             : 
     770             :     }
     771             :     else
     772             :     {
     773             :         //todo/mba: assuming that notes should be omitted
     774           2 :         sal_Bool bSearchInNotes = sal_False;
     775             :         sal_Bool bCancel;
     776             :         nResult = pUnoCrsr->Find( aSearchOpt, bSearchInNotes,
     777             :             eStart, eEnd, bCancel,
     778             :             (FindRanges)eRanges,
     779           2 :             sal_True );
     780             :     }
     781           4 :     return (sal_Int32)nResult;
     782             : 
     783             : }
     784             : 
     785           4 : Reference< util::XSearchDescriptor >  SwXTextDocument::createSearchDescriptor(void)
     786             :                                                     throw( RuntimeException )
     787             : {
     788           4 :     SolarMutexGuard aGuard;
     789           4 :     Reference< util::XSearchDescriptor >  xRet = new SwXTextSearch;
     790           4 :     return xRet;
     791             : 
     792             : }
     793             : 
     794             : // Used for findAll/First/Next
     795             : 
     796           6 : SwUnoCrsr*  SwXTextDocument::FindAny(const Reference< util::XSearchDescriptor > & xDesc,
     797             :                                         Reference< XTextCursor > & xCrsr, sal_Bool bAll,
     798             :                                                 sal_Int32& nResult,
     799             :                                                 Reference< XInterface >  xLastResult)
     800             : {
     801           6 :     Reference< XUnoTunnel > xDescTunnel(xDesc, UNO_QUERY);
     802           6 :     if(!IsValid() || !xDescTunnel.is() || !xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()))
     803           0 :         return 0;
     804             : 
     805           6 :     SwUnoCrsr*  pUnoCrsr = CreateCursorForSearch(xCrsr);
     806             :     const SwXTextSearch* pSearch = reinterpret_cast<const SwXTextSearch*>(
     807           6 :         xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()));
     808             : 
     809           6 :     sal_Bool bParentInExtra = sal_False;
     810           6 :     if(xLastResult.is())
     811             :     {
     812           1 :         Reference<XUnoTunnel> xCursorTunnel( xLastResult, UNO_QUERY);
     813           1 :         OTextCursorHelper* pPosCrsr = 0;
     814           1 :         if(xCursorTunnel.is())
     815             :         {
     816           1 :             pPosCrsr = reinterpret_cast<OTextCursorHelper*>(xCursorTunnel->getSomething(
     817           1 :                                     OTextCursorHelper::getUnoTunnelId()));
     818             :         }
     819           1 :         SwPaM* pCrsr = pPosCrsr ? pPosCrsr->GetPaM() : 0;
     820           1 :         if(pCrsr)
     821             :         {
     822           1 :             *pUnoCrsr->GetPoint() = *pCrsr->End();
     823           1 :             pUnoCrsr->DeleteMark();
     824             :         }
     825             :         else
     826             :         {
     827           0 :             SwXTextRange* pRange = 0;
     828           0 :             if(xCursorTunnel.is())
     829             :             {
     830           0 :                 pRange = reinterpret_cast<SwXTextRange*>(xCursorTunnel->getSomething(
     831           0 :                                         SwXTextRange::getUnoTunnelId()));
     832             :             }
     833           0 :             if(!pRange)
     834           0 :                 return 0;
     835           0 :             pRange->GetPositions(*pUnoCrsr);
     836           0 :             if(pUnoCrsr->HasMark())
     837             :             {
     838           0 :                 if(*pUnoCrsr->GetPoint() < *pUnoCrsr->GetMark())
     839           0 :                     pUnoCrsr->Exchange();
     840           0 :                 pUnoCrsr->DeleteMark();
     841             :             }
     842             :         }
     843           1 :         const SwNode* pRangeNode = pUnoCrsr->GetNode();
     844           2 :         bParentInExtra = pRangeNode->FindFlyStartNode() ||
     845           2 :                             pRangeNode->FindFootnoteStartNode() ||
     846           3 :                             pRangeNode->FindHeaderStartNode() ||
     847           2 :                             pRangeNode->FindFooterStartNode() ;
     848             :     }
     849             : 
     850          12 :     util::SearchOptions aSearchOpt;
     851           6 :     pSearch->FillSearchOptions( aSearchOpt );
     852             : 
     853             : /**
     854             :  * The following combinations are allowed:
     855             :  *  - Search in the body:                   -> FND_IN_BODY
     856             :  *  - Search all in the body:               -> FND_IN_BODYONLY | FND_IN_SELALL
     857             :  *  - Search in selections: one / all       -> FND_IN_SEL  [ | FND_IN_SELALL ]
     858             :  *  - Search outside the body: one / all    -> FND_IN_OTHER [ | FND_IN_SELALL ]
     859             :  *  - Search everywhere all:                -> FND_IN_SELALL
     860             :  */
     861           6 :     int eRanges(FND_IN_BODY);
     862           6 :     if(bParentInExtra)
     863           0 :         eRanges = FND_IN_OTHER;
     864           6 :     if(bAll) //always - everywhere?
     865           2 :         eRanges = FND_IN_SELALL;
     866           6 :     SwDocPositions eStart = !bAll ? DOCPOS_CURR : pSearch->bBack ? DOCPOS_END : DOCPOS_START;
     867           6 :     SwDocPositions eEnd = pSearch->bBack ? DOCPOS_START : DOCPOS_END;
     868             : 
     869           6 :     nResult = 0;
     870           6 :     sal_uInt16 nSearchProc = 0;
     871          13 :     while(nSearchProc < 2)
     872             :     {
     873             :         //try attribute search first
     874           7 :         if(pSearch->HasSearchAttributes())
     875             :         {
     876           0 :             SfxItemSet aSearch(pDocShell->GetDoc()->GetAttrPool(),
     877             :                                 RES_CHRATR_BEGIN, RES_CHRATR_END-1,
     878             :                                 RES_PARATR_BEGIN, RES_PARATR_END-1,
     879             :                                 RES_FRMATR_BEGIN, RES_FRMATR_END-1,
     880             :                                 RES_TXTATR_INETFMT, RES_TXTATR_CHARFMT,
     881           0 :                                 0);
     882           0 :             pSearch->FillSearchItemSet(aSearch);
     883             :             sal_Bool bCancel;
     884             :             nResult = (sal_Int32)pUnoCrsr->Find( aSearch, !pSearch->bStyles,
     885             :                         eStart, eEnd, bCancel,
     886             :                         (FindRanges)eRanges,
     887           0 :                         pSearch->sSearchText.Len() ? &aSearchOpt : 0,
     888           0 :                         0 );
     889             :         }
     890           7 :         else if(pSearch->bStyles)
     891             :         {
     892           0 :             SwTxtFmtColl *pSearchColl = lcl_GetParaStyle(pSearch->sSearchText, pUnoCrsr->GetDoc());
     893             :             //pSearch->sReplaceText
     894           0 :             SwTxtFmtColl *pReplaceColl = 0;
     895             :             sal_Bool bCancel;
     896             :             nResult = (sal_Int32)pUnoCrsr->Find( *pSearchColl,
     897             :                         eStart, eEnd, bCancel,
     898           0 :                         (FindRanges)eRanges, pReplaceColl );
     899             :         }
     900             :         else
     901             :         {
     902             :             //todo/mba: assuming that notes should be omitted
     903           7 :             sal_Bool bSearchInNotes = sal_False;
     904             :             sal_Bool bCancel;
     905             :             nResult = (sal_Int32)pUnoCrsr->Find( aSearchOpt, bSearchInNotes,
     906             :                     eStart, eEnd, bCancel,
     907             :                     (FindRanges)eRanges,
     908           7 :                     /*int bReplace =*/sal_False );
     909             :         }
     910           7 :         nSearchProc++;
     911           7 :         if(nResult || (eRanges&(FND_IN_SELALL|FND_IN_OTHER)))
     912             :             break;
     913             :         //second step - find in other
     914           1 :         eRanges = FND_IN_OTHER;
     915             :     }
     916          12 :     return pUnoCrsr;
     917             : }
     918             : 
     919             : Reference< XIndexAccess >
     920           2 :     SwXTextDocument::findAll(const Reference< util::XSearchDescriptor > & xDesc)
     921             :                                                 throw( RuntimeException )
     922             : {
     923           2 :     SolarMutexGuard aGuard;
     924           4 :     Reference< XInterface >  xTmp;
     925           2 :     sal_Int32 nResult = 0;
     926           4 :     Reference< XTextCursor >  xCrsr;
     927           2 :     SwUnoCrsr* pResultCrsr = FindAny(xDesc, xCrsr, sal_True, nResult, xTmp);
     928           2 :     if(!pResultCrsr)
     929           0 :         throw RuntimeException();
     930           2 :     Reference< XIndexAccess >  xRet;
     931           2 :     xRet = new SwXTextRanges( (nResult) ? pResultCrsr : 0 );
     932           2 :     delete pResultCrsr;
     933           4 :     return xRet;
     934             : }
     935             : 
     936           3 : Reference< XInterface >  SwXTextDocument::findFirst(const Reference< util::XSearchDescriptor > & xDesc)
     937             :                                             throw( RuntimeException )
     938             : {
     939           3 :     SolarMutexGuard aGuard;
     940           6 :     Reference< XInterface >  xTmp;
     941           3 :     sal_Int32 nResult = 0;
     942           6 :     Reference< XTextCursor >  xCrsr;
     943           3 :     SwUnoCrsr* pResultCrsr = FindAny(xDesc, xCrsr, sal_False, nResult, xTmp);
     944           3 :     if(!pResultCrsr)
     945           0 :         throw RuntimeException();
     946           3 :     Reference< XInterface >  xRet;
     947           3 :     if(nResult)
     948             :     {
     949             :         const uno::Reference< text::XText >  xParent =
     950           2 :             ::sw::CreateParentXText(*pDocShell->GetDoc(),
     951           4 :                     *pResultCrsr->GetPoint());
     952           2 :         xRet = *new SwXTextCursor(xParent, *pResultCrsr);
     953           2 :         delete pResultCrsr;
     954             :     }
     955           6 :     return xRet;
     956             : }
     957             : 
     958           1 : Reference< XInterface >  SwXTextDocument::findNext(const Reference< XInterface > & xStartAt,
     959             :             const Reference< util::XSearchDescriptor > & xDesc)
     960             :             throw( RuntimeException )
     961             : {
     962           1 :     SolarMutexGuard aGuard;
     963           2 :     Reference< XInterface >  xTmp;
     964           1 :     sal_Int32 nResult = 0;
     965           2 :     Reference< XTextCursor >  xCrsr;
     966           1 :     if(!xStartAt.is())
     967           0 :         throw RuntimeException();
     968           1 :     SwUnoCrsr* pResultCrsr = FindAny(xDesc, xCrsr, sal_False, nResult, xStartAt);
     969           1 :     if(!pResultCrsr)
     970           0 :         throw RuntimeException();
     971           1 :     Reference< XInterface >  xRet;
     972           1 :     if(nResult)
     973             :     {
     974             :         const uno::Reference< text::XText >  xParent =
     975           1 :             ::sw::CreateParentXText(*pDocShell->GetDoc(),
     976           2 :                     *pResultCrsr->GetPoint());
     977             : 
     978           1 :         xRet = *new SwXTextCursor(xParent, *pResultCrsr);
     979           1 :         delete pResultCrsr;
     980             :     }
     981           2 :     return xRet;
     982             : }
     983             : 
     984           0 : Sequence< beans::PropertyValue > SwXTextDocument::getPagePrintSettings(void)
     985             :     throw( RuntimeException )
     986             : {
     987           0 :     SolarMutexGuard aGuard;
     988           0 :     Sequence< beans::PropertyValue > aSeq(9);
     989           0 :     if(IsValid())
     990             :     {
     991           0 :         beans::PropertyValue* pArray = aSeq.getArray();
     992           0 :         SwPagePreViewPrtData aData;
     993           0 :         const SwPagePreViewPrtData* pData = pDocShell->GetDoc()->GetPreViewPrtData();
     994           0 :         if(pData)
     995           0 :             aData = *pData;
     996           0 :         Any aVal;
     997           0 :         aVal <<= (sal_Int16)aData.GetRow();
     998           0 :         pArray[0] = beans::PropertyValue("PageRows", -1, aVal, PropertyState_DIRECT_VALUE);
     999           0 :         aVal <<= (sal_Int16)aData.GetCol();
    1000           0 :         pArray[1] = beans::PropertyValue("PageColumns", -1, aVal, PropertyState_DIRECT_VALUE);
    1001           0 :         aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetLeftSpace());
    1002           0 :         pArray[2] = beans::PropertyValue("LeftMargin", -1, aVal, PropertyState_DIRECT_VALUE);
    1003           0 :         aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetRightSpace());
    1004           0 :         pArray[3] = beans::PropertyValue("RightMargin", -1, aVal, PropertyState_DIRECT_VALUE);
    1005           0 :         aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetTopSpace());
    1006           0 :         pArray[4] = beans::PropertyValue("TopMargin", -1, aVal, PropertyState_DIRECT_VALUE);
    1007           0 :         aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetBottomSpace());
    1008           0 :         pArray[5] = beans::PropertyValue("BottomMargin", -1, aVal, PropertyState_DIRECT_VALUE);
    1009           0 :         aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetHorzSpace());
    1010           0 :         pArray[6] = beans::PropertyValue("HoriMargin", -1, aVal, PropertyState_DIRECT_VALUE);
    1011           0 :         aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetVertSpace());
    1012           0 :         pArray[7] = beans::PropertyValue("VertMargin", -1, aVal, PropertyState_DIRECT_VALUE);
    1013           0 :         sal_Bool bTemp = aData.GetLandscape();
    1014           0 :         aVal.setValue(&bTemp, ::getCppuBooleanType());
    1015           0 :         pArray[8] = beans::PropertyValue("IsLandscape", -1, aVal, PropertyState_DIRECT_VALUE);
    1016             :     }
    1017             :     else
    1018           0 :         throw RuntimeException();
    1019           0 :     return aSeq;
    1020             : }
    1021             : 
    1022           0 : static sal_uInt32 lcl_Any_To_ULONG(const Any& rValue, sal_Bool& bException)
    1023             : {
    1024           0 :     bException = sal_False;
    1025           0 :     TypeClass eType = rValue.getValueType().getTypeClass();
    1026             : 
    1027           0 :     sal_uInt32 nRet = 0;
    1028           0 :     if( eType == TypeClass_UNSIGNED_LONG )
    1029           0 :         rValue >>= nRet;
    1030             :     else
    1031             :     {
    1032           0 :          sal_Int32 nVal=0;
    1033           0 :          bException = !(rValue >>= nVal);
    1034           0 :          if( !bException )
    1035           0 :             nRet = (sal_uInt32)nVal;
    1036             :     }
    1037             : 
    1038           0 :     return nRet;
    1039             : }
    1040             : 
    1041           0 : static String lcl_CreateOutlineString( sal_uInt16 nIndex,
    1042             :             const SwOutlineNodes& rOutlineNodes, const SwNumRule* pOutlRule)
    1043             : {
    1044           0 :     String sEntry;
    1045           0 :     const SwTxtNode * pTxtNd = rOutlineNodes[ nIndex ]->GetTxtNode();
    1046           0 :     SwNumberTree::tNumberVector aNumVector = pTxtNd->GetNumberVector();
    1047           0 :     if( pOutlRule && pTxtNd->GetNumRule())
    1048           0 :         for( sal_Int8 nLevel = 0;
    1049           0 :              nLevel <= pTxtNd->GetActualListLevel();
    1050             :              nLevel++ )
    1051             :         {
    1052           0 :             long nVal = aNumVector[nLevel];
    1053           0 :             nVal ++;
    1054           0 :             nVal -= pOutlRule->Get(nLevel).GetStart();
    1055           0 :             sEntry += OUString::number( nVal );
    1056           0 :             sEntry += '.';
    1057             :         }
    1058           0 :     sEntry += rOutlineNodes[ nIndex ]->
    1059           0 :                     GetTxtNode()->GetExpandTxt( 0, STRING_LEN, sal_False );
    1060           0 :     return sEntry;
    1061             : }
    1062             : 
    1063           0 : void SwXTextDocument::setPagePrintSettings(const Sequence< beans::PropertyValue >& aSettings)
    1064             :     throw( RuntimeException )
    1065             : {
    1066           0 :     SolarMutexGuard aGuard;
    1067           0 :     if(IsValid())
    1068             :     {
    1069           0 :         SwPagePreViewPrtData aData;
    1070             :         //if only a few properties are coming, then use the current settings
    1071           0 :         const SwPagePreViewPrtData* pData = pDocShell->GetDoc()->GetPreViewPrtData();
    1072           0 :         if(pData)
    1073           0 :             aData = *pData;
    1074           0 :         const beans::PropertyValue* pProperties = aSettings.getConstArray();
    1075           0 :         int nCount = aSettings.getLength();
    1076           0 :         for(int i = 0; i < nCount; i++)
    1077             :         {
    1078           0 :             String sName = pProperties[i].Name;
    1079           0 :             const Any& rVal = pProperties[i].Value;
    1080             :             sal_Bool bException;
    1081           0 :             sal_uInt32 nVal = lcl_Any_To_ULONG(rVal, bException);
    1082           0 :             if( COMPARE_EQUAL == sName.CompareToAscii("PageRows" ) )
    1083             :             {
    1084           0 :                 if(!nVal || nVal > 0xff)
    1085           0 :                     throw RuntimeException();
    1086           0 :                 aData.SetRow((sal_uInt8)nVal);
    1087             :             }
    1088           0 :             else if(COMPARE_EQUAL == sName.CompareToAscii("PageColumns"))
    1089             :             {
    1090           0 :                 if(!nVal  || nVal > 0xff)
    1091           0 :                     throw RuntimeException();
    1092           0 :                 aData.SetCol((sal_uInt8)nVal);
    1093             :             }
    1094           0 :             else if(COMPARE_EQUAL == sName.CompareToAscii("LeftMargin"))
    1095             :             {
    1096           0 :                 aData.SetLeftSpace(MM100_TO_TWIP_UNSIGNED(nVal));
    1097             :             }
    1098           0 :             else if(COMPARE_EQUAL == sName.CompareToAscii("RightMargin"))
    1099             :             {
    1100           0 :                 aData.SetRightSpace(MM100_TO_TWIP_UNSIGNED(nVal));
    1101             :             }
    1102           0 :             else if(COMPARE_EQUAL == sName.CompareToAscii("TopMargin"))
    1103             :             {
    1104           0 :                 aData.SetTopSpace(MM100_TO_TWIP_UNSIGNED(nVal));
    1105             :             }
    1106           0 :             else if(COMPARE_EQUAL == sName.CompareToAscii("BottomMargin"))
    1107             :             {
    1108           0 :                 aData.SetBottomSpace(MM100_TO_TWIP_UNSIGNED(nVal));
    1109             :             }
    1110           0 :             else if(COMPARE_EQUAL == sName.CompareToAscii("HoriMargin"))
    1111             :             {
    1112           0 :                 aData.SetHorzSpace(MM100_TO_TWIP_UNSIGNED(nVal));
    1113             :             }
    1114           0 :             else if(COMPARE_EQUAL == sName.CompareToAscii("VertMargin"))
    1115             :             {
    1116           0 :                 aData.SetVertSpace(MM100_TO_TWIP_UNSIGNED(nVal));
    1117             :             }
    1118           0 :             else if(COMPARE_EQUAL == sName.CompareToAscii("IsLandscape"))
    1119             :             {
    1120           0 :                 bException =  (::getBooleanCppuType() != rVal.getValueType());
    1121           0 :                 aData.SetLandscape(*(sal_Bool*)rVal.getValue());
    1122             :             }
    1123             :             else
    1124           0 :                 bException = sal_True;
    1125           0 :             if(bException)
    1126           0 :                 throw RuntimeException();
    1127           0 :         }
    1128           0 :         pDocShell->GetDoc()->SetPreViewPrtData(&aData);
    1129             :     }
    1130             :     else
    1131           0 :         throw RuntimeException();
    1132           0 : }
    1133             : 
    1134           0 : void SwXTextDocument::printPages(const Sequence< beans::PropertyValue >& xOptions)
    1135             :     throw( IllegalArgumentException, RuntimeException )
    1136             : {
    1137           0 :     SolarMutexGuard aGuard;
    1138           0 :     if(IsValid())
    1139             :     {
    1140           0 :         SfxViewFrame* pFrame = SfxViewFrame::LoadHiddenDocument( *pDocShell, 7 );
    1141             :         SfxRequest aReq(FN_PRINT_PAGEPREVIEW, SFX_CALLMODE_SYNCHRON,
    1142           0 :                                     pDocShell->GetDoc()->GetAttrPool());
    1143           0 :             aReq.AppendItem(SfxBoolItem(FN_PRINT_PAGEPREVIEW, sal_True));
    1144             : 
    1145           0 :         OUString sFileName(OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_FILE_NAME)));
    1146           0 :         OUString sCopyCount(OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_COPY_COUNT)));
    1147           0 :         OUString sCollate(OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_COLLATE)));
    1148           0 :         OUString sSort(OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_SORT)));
    1149           0 :         OUString sPages(OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_PAGES)));
    1150             : 
    1151           0 :         for ( int n = 0; n < xOptions.getLength(); ++n )
    1152             :         {
    1153             :             // get Property-Value from options
    1154           0 :             const beans::PropertyValue &rProp = xOptions.getConstArray()[n];
    1155           0 :             Any aValue( rProp.Value );
    1156             : 
    1157             :             // FileName-Property?
    1158           0 :             if ( rProp.Name == sFileName )
    1159             :             {
    1160           0 :                 OUString sFileURL;
    1161           0 :                 if ( (rProp.Value >>= sFileURL ) )
    1162             :                 {
    1163             :                     // Convert the File URL into a system dependant path, as the SalPrinter expects
    1164           0 :                     OUString sSystemPath;
    1165           0 :                     FileBase::getSystemPathFromFileURL ( sFileURL, sSystemPath );
    1166           0 :                     aReq.AppendItem(SfxStringItem( SID_FILE_NAME, sSystemPath ) );
    1167             :                 }
    1168           0 :                 else if ( rProp.Value.getValueType() != ::getVoidCppuType() )
    1169           0 :                     throw IllegalArgumentException();
    1170             :             }
    1171             : 
    1172             :             // CopyCount-Property
    1173           0 :             else if ( rProp.Name == sCopyCount )
    1174             :             {
    1175           0 :                 sal_Int32 nCopies = 0;
    1176           0 :                 aValue >>= nCopies;
    1177           0 :                 aReq.AppendItem(SfxInt16Item( SID_PRINT_COPIES, (sal_Int16)nCopies ) );
    1178             :             }
    1179             : 
    1180             :             // Collate-Property
    1181           0 :             else if ( rProp.Name == sCollate )
    1182             :             {
    1183           0 :                 if ( rProp.Value.getValueType() == ::getBooleanCppuType())
    1184             : 
    1185           0 :                     aReq.AppendItem(SfxBoolItem( SID_PRINT_COLLATE, *(sal_Bool*)rProp.Value.getValue() ) );
    1186             :                 else
    1187           0 :                     throw IllegalArgumentException();
    1188             :             }
    1189             : 
    1190             :             // Sort-Property
    1191           0 :             else if ( rProp.Name == sSort )
    1192             :             {
    1193           0 :                 if ( rProp.Value.getValueType() == ::getBooleanCppuType() )
    1194           0 :                     aReq.AppendItem(SfxBoolItem( SID_PRINT_SORT, *(sal_Bool*)rProp.Value.getValue() ) );
    1195             :                 else
    1196           0 :                     throw IllegalArgumentException();
    1197             :             }
    1198             : 
    1199             :             // Pages-Property
    1200           0 :             else if ( rProp.Name == sPages )
    1201             :             {
    1202           0 :                 OUString sTmp;
    1203           0 :                 if ( rProp.Value >>= sTmp )
    1204           0 :                     aReq.AppendItem( SfxStringItem( SID_PRINT_PAGES, sTmp ) );
    1205             :                 else
    1206           0 :                     throw IllegalArgumentException();
    1207             :             }
    1208           0 :         }
    1209             : 
    1210             :         // #i117783#
    1211           0 :         bApplyPagePrintSettingsFromXPagePrintable = sal_True;
    1212           0 :         pFrame->GetViewShell()->ExecuteSlot(aReq);
    1213             :         // Frame close
    1214           0 :         pFrame->DoClose();
    1215             : 
    1216             :     }
    1217             :     else
    1218           0 :         throw RuntimeException();
    1219           0 : }
    1220             : 
    1221           2 : Reference< XNameAccess >  SwXTextDocument::getReferenceMarks(void)
    1222             :                                         throw( RuntimeException )
    1223             : {
    1224           2 :     SolarMutexGuard aGuard;
    1225           2 :     if(!IsValid())
    1226           0 :         throw RuntimeException();
    1227           2 :     if(!pxXReferenceMarks)
    1228             :     {
    1229           2 :         ((SwXTextDocument*)this)->pxXReferenceMarks = new Reference< XNameAccess > ;
    1230           2 :         *pxXReferenceMarks = new SwXReferenceMarks(pDocShell->GetDoc());
    1231             :     }
    1232           2 :     return *pxXReferenceMarks;
    1233             : }
    1234             : 
    1235         398 : Reference< XEnumerationAccess >  SwXTextDocument::getTextFields(void) throw( RuntimeException )
    1236             : {
    1237         398 :     SolarMutexGuard aGuard;
    1238         398 :     if(!IsValid())
    1239           0 :         throw RuntimeException();
    1240         398 :     if(!pxXTextFieldTypes)
    1241             :     {
    1242         365 :         ((SwXTextDocument*)this)->pxXTextFieldTypes = new Reference< XEnumerationAccess > ;
    1243         365 :         *pxXTextFieldTypes = new SwXTextFieldTypes(pDocShell->GetDoc());
    1244             :     }
    1245         398 :     return *pxXTextFieldTypes;
    1246             : }
    1247             : 
    1248         273 : Reference< XNameAccess >  SwXTextDocument::getTextFieldMasters(void)
    1249             :     throw( RuntimeException )
    1250             : {
    1251         273 :     SolarMutexGuard aGuard;
    1252         273 :     if(!IsValid())
    1253           0 :         throw RuntimeException();
    1254         273 :     if(!pxXTextFieldMasters)
    1255             :     {
    1256          60 :         ((SwXTextDocument*)this)->pxXTextFieldMasters = new Reference< XNameAccess > ;
    1257          60 :         *pxXTextFieldMasters = new SwXTextFieldMasters(pDocShell->GetDoc());
    1258             :     }
    1259         273 :     return *pxXTextFieldMasters;
    1260             : }
    1261             : 
    1262         243 : Reference< XNameAccess >  SwXTextDocument::getEmbeddedObjects(void) throw( RuntimeException )
    1263             : {
    1264         243 :     SolarMutexGuard aGuard;
    1265         243 :     if(!IsValid())
    1266           0 :         throw RuntimeException();
    1267         243 :     if(!pxXEmbeddedObjects)
    1268             :     {
    1269          63 :         ((SwXTextDocument*)this)->pxXEmbeddedObjects = new Reference< XNameAccess > ;
    1270          63 :         *pxXEmbeddedObjects = new SwXTextEmbeddedObjects(pDocShell->GetDoc());
    1271             :     }
    1272         243 :     return *pxXEmbeddedObjects;
    1273             : }
    1274             : 
    1275          16 : Reference< XNameAccess >  SwXTextDocument::getBookmarks(void) throw( RuntimeException )
    1276             : {
    1277          16 :     SolarMutexGuard aGuard;
    1278          16 :     if(!IsValid())
    1279           0 :         throw RuntimeException();
    1280          16 :     if(!pxXBookmarks)
    1281             :     {
    1282          10 :         ((SwXTextDocument*)this)->pxXBookmarks = new Reference< XNameAccess > ;
    1283          10 :         *pxXBookmarks = new SwXBookmarks(pDocShell->GetDoc());
    1284             :     }
    1285          16 :     return *pxXBookmarks;
    1286             : }
    1287             : 
    1288          30 : Reference< XNameAccess >  SwXTextDocument::getTextSections(void) throw( RuntimeException )
    1289             : {
    1290          30 :     SolarMutexGuard aGuard;
    1291          30 :     if(!IsValid())
    1292           0 :         throw RuntimeException();
    1293          30 :     if(!pxXTextSections)
    1294             :     {
    1295          25 :         ((SwXTextDocument*)this)->pxXTextSections = new Reference< XNameAccess > ;
    1296          25 :         *pxXTextSections = new SwXTextSections(pDocShell->GetDoc());
    1297             :     }
    1298          30 :     return *pxXTextSections;
    1299             : }
    1300             : 
    1301         103 : Reference< XNameAccess >  SwXTextDocument::getTextTables(void) throw( RuntimeException )
    1302             : {
    1303         103 :     SolarMutexGuard aGuard;
    1304         103 :     if(!IsValid())
    1305           0 :         throw RuntimeException();
    1306         103 :     if(!pxXTextTables)
    1307             :     {
    1308          82 :         ((SwXTextDocument*)this)->pxXTextTables = new Reference< XNameAccess > ;
    1309          82 :         *pxXTextTables = new SwXTextTables(pDocShell->GetDoc());
    1310             :     }
    1311         103 :     return *pxXTextTables;
    1312             : }
    1313             : 
    1314         243 : Reference< XNameAccess >  SwXTextDocument::getGraphicObjects(void) throw( RuntimeException )
    1315             : {
    1316         243 :     SolarMutexGuard aGuard;
    1317         243 :     if(!IsValid())
    1318           0 :         throw RuntimeException();
    1319         243 :     if(!pxXGraphicObjects)
    1320             :     {
    1321          63 :         ((SwXTextDocument*)this)->pxXGraphicObjects = new Reference< XNameAccess > ;
    1322          63 :         *pxXGraphicObjects = new SwXTextGraphicObjects(pDocShell->GetDoc());
    1323             :     }
    1324         243 :     return *pxXGraphicObjects;
    1325             : }
    1326             : 
    1327         273 : Reference< XNameAccess >  SwXTextDocument::getTextFrames(void) throw( RuntimeException )
    1328             : {
    1329         273 :     SolarMutexGuard aGuard;
    1330         273 :     if(!IsValid())
    1331           0 :         throw RuntimeException();
    1332         273 :     if(!pxXTextFrames)
    1333             :     {
    1334          89 :         ((SwXTextDocument*)this)->pxXTextFrames = new Reference< XNameAccess > ;
    1335          89 :         *pxXTextFrames = new SwXTextFrames(pDocShell->GetDoc());
    1336             :     }
    1337         273 :     return *pxXTextFrames;
    1338             : }
    1339             : 
    1340        2840 : Reference< XNameAccess >  SwXTextDocument::getStyleFamilies(void) throw( RuntimeException )
    1341             : {
    1342        2840 :     SolarMutexGuard aGuard;
    1343        2840 :     if(!IsValid())
    1344           0 :         throw RuntimeException();
    1345        2840 :     if(!pxXStyleFamilies)
    1346             :     {
    1347         765 :         ((SwXTextDocument*)this)->pxXStyleFamilies = new Reference< XNameAccess > ;
    1348         765 :         *pxXStyleFamilies = new SwXStyleFamilies(*pDocShell);
    1349             :     }
    1350        2840 :     return *pxXStyleFamilies;
    1351             : }
    1352             : 
    1353          64 : uno::Reference< style::XAutoStyles > SwXTextDocument::getAutoStyles(  )
    1354             :     throw (uno::RuntimeException)
    1355             : {
    1356          64 :     SolarMutexGuard aGuard;
    1357          64 :     if(!IsValid())
    1358           0 :         throw RuntimeException();
    1359          64 :     if(!pxXAutoStyles)
    1360             :     {
    1361          39 :         pxXAutoStyles = new Reference< style::XAutoStyles > ;
    1362          39 :         *pxXAutoStyles = new SwXAutoStyles(*pDocShell);
    1363             :     }
    1364          64 :     return *pxXAutoStyles;
    1365             : 
    1366             : }
    1367             : 
    1368        1828 : Reference< drawing::XDrawPage >  SwXTextDocument::getDrawPage(void) throw( RuntimeException )
    1369             : {
    1370        1828 :     SolarMutexGuard aGuard;
    1371        1828 :     if(!IsValid())
    1372           0 :         throw RuntimeException();
    1373        1828 :     if(!pxXDrawPage)
    1374             :     {
    1375         783 :         ((SwXTextDocument*)this)->pDrawPage = new SwXDrawPage(pDocShell->GetDoc());
    1376         783 :         ((SwXTextDocument*)this)->pxXDrawPage = new Reference< drawing::XDrawPage >(pDrawPage);
    1377             :         // Create a Reference to trigger the complete initialization of the
    1378             :         // object. Otherwise in some corner cases it would get initialized
    1379             :         // at ::InitNewDoc -> which would get called during
    1380             :         // close() or dispose() -> n#681746
    1381         783 :         uno::Reference<lang::XComponent> xComp( *pxXDrawPage, uno::UNO_QUERY );
    1382             :     }
    1383        1828 :     return *pxXDrawPage;
    1384             : }
    1385             : 
    1386           0 : SwXDrawPage* SwXTextDocument::GetDrawPage()
    1387             : {
    1388           0 :     if(!IsValid())
    1389           0 :         return 0;
    1390           0 :     if(!pDrawPage)
    1391           0 :         getDrawPage();
    1392           0 :     return pDrawPage;
    1393             : }
    1394             : 
    1395         898 : void SwXTextDocument::Invalidate()
    1396             : {
    1397         898 :     bObjectValid = sal_False;
    1398         898 :     if(xNumFmtAgg.is())
    1399             :     {
    1400         794 :         const uno::Type& rTunnelType = ::getCppuType((Reference <XUnoTunnel>*)0);
    1401         794 :         Any aNumTunnel = xNumFmtAgg->queryAggregation(rTunnelType);
    1402         794 :         SvNumberFormatsSupplierObj* pNumFmt = 0;
    1403        1588 :         Reference< XUnoTunnel > xNumTunnel;
    1404         794 :         if(aNumTunnel >>= xNumTunnel)
    1405             :         {
    1406             :             pNumFmt = reinterpret_cast<SvNumberFormatsSupplierObj*>(
    1407         794 :                     xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
    1408         794 :             pNumFmt->SetNumberFormatter(0);
    1409             :         }
    1410         794 :         OSL_ENSURE(pNumFmt, "No number formatter available");
    1411             :     }
    1412         898 :     InitNewDoc();
    1413         898 :     pDocShell = 0;
    1414         898 :     lang::EventObject const ev(static_cast<SwXTextDocumentBaseClass &>(*this));
    1415         898 :     m_pImpl->m_RefreshListeners.disposeAndClear(ev);
    1416         898 : }
    1417             : 
    1418         908 : void SwXTextDocument::Reactivate(SwDocShell* pNewDocShell)
    1419             : {
    1420         908 :     if(pDocShell && pDocShell != pNewDocShell)
    1421           0 :         Invalidate();
    1422         908 :     pDocShell = pNewDocShell;
    1423         908 :     bObjectValid = sal_True;
    1424         908 : }
    1425             : 
    1426        1553 : void    SwXTextDocument::InitNewDoc()
    1427             : {
    1428             :     // first invalidate all collections, then delete references and Set to zero
    1429        1553 :     if(pxXTextTables)
    1430             :     {
    1431          82 :          XNameAccess* pTbls = pxXTextTables->get();
    1432          82 :         ((SwXTextTables*)pTbls)->Invalidate();
    1433          82 :         delete pxXTextTables;
    1434          82 :         pxXTextTables = 0;
    1435             :     }
    1436             : 
    1437        1553 :     if(pxXTextFrames)
    1438             :     {
    1439          88 :          XNameAccess* pFrms = pxXTextFrames->get();
    1440          88 :         ((SwXTextFrames*)pFrms)->Invalidate();
    1441          88 :         delete pxXTextFrames;
    1442          88 :         pxXTextFrames = 0;
    1443             :     }
    1444             : 
    1445        1553 :     if(pxXGraphicObjects)
    1446             :     {
    1447          62 :          XNameAccess* pFrms = pxXGraphicObjects->get();
    1448          62 :         ((SwXTextGraphicObjects*)pFrms)->Invalidate();
    1449          62 :         delete pxXGraphicObjects;
    1450          62 :         pxXGraphicObjects = 0;
    1451             :     }
    1452             : 
    1453        1553 :     if(pxXEmbeddedObjects)
    1454             :     {
    1455          62 :      XNameAccess* pOLE = pxXEmbeddedObjects->get();
    1456          62 :         ((SwXTextEmbeddedObjects*)pOLE)->Invalidate();
    1457          62 :         delete pxXEmbeddedObjects;
    1458          62 :         pxXEmbeddedObjects = 0;
    1459             :     }
    1460             : 
    1461        1553 :     if(xBodyText.is())
    1462             :     {
    1463         573 :         xBodyText = 0;
    1464         573 :         pBodyText = 0;
    1465             :     }
    1466             : 
    1467        1553 :     if(xNumFmtAgg.is())
    1468             :     {
    1469        1381 :         const uno::Type& rTunnelType = ::getCppuType((Reference <XUnoTunnel>*)0);
    1470        1381 :         Any aNumTunnel = xNumFmtAgg->queryAggregation(rTunnelType);
    1471        1381 :         SvNumberFormatsSupplierObj* pNumFmt = 0;
    1472        2762 :         Reference< XUnoTunnel > xNumTunnel;
    1473        1381 :         if(aNumTunnel >>= xNumTunnel)
    1474             :         {
    1475             :             pNumFmt = reinterpret_cast<SvNumberFormatsSupplierObj*>(
    1476        1381 :                     xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
    1477             : 
    1478             :         }
    1479             :         OSL_ENSURE(pNumFmt, "No number formatter available");
    1480        2762 :         pNumFmt->SetNumberFormatter(0);
    1481             :     }
    1482             : 
    1483        1553 :     if(pxXTextFieldTypes)
    1484             :     {
    1485         364 :          XEnumerationAccess* pT = pxXTextFieldTypes->get();
    1486         364 :         ((SwXTextFieldTypes*)pT)->Invalidate();
    1487         364 :         delete pxXTextFieldTypes;
    1488         364 :         pxXTextFieldTypes = 0;
    1489             :     }
    1490             : 
    1491        1553 :     if(pxXTextFieldMasters)
    1492             :     {
    1493          59 :          XNameAccess* pT = pxXTextFieldMasters->get();
    1494          59 :         ((SwXTextFieldMasters*)pT)->Invalidate();
    1495          59 :         delete pxXTextFieldMasters;
    1496          59 :         pxXTextFieldMasters = 0;
    1497             :     }
    1498             : 
    1499        1553 :     if(pxXTextSections)
    1500             :     {
    1501          25 :          XNameAccess* pSect = pxXTextSections->get();
    1502          25 :         ((SwXTextSections*)pSect)->Invalidate();
    1503          25 :         delete pxXTextSections;
    1504          25 :         pxXTextSections = 0;
    1505             :     }
    1506             : 
    1507        1553 :     if(pxXDrawPage)
    1508             :     {
    1509             :         // #i91798#, #i91895#
    1510             :         // dispose XDrawPage here. We are the owner and know that it is no longer in a valid condition.
    1511         781 :         uno::Reference<lang::XComponent> xComp( *pxXDrawPage, uno::UNO_QUERY );
    1512         781 :         xComp->dispose();
    1513         781 :         pDrawPage->InvalidateSwDoc();
    1514         781 :         delete pxXDrawPage;
    1515         781 :         pxXDrawPage = 0;
    1516             :     }
    1517             : 
    1518        1553 :     if ( pxXNumberingRules )
    1519             :     {
    1520          16 :         XIndexAccess* pNum = pxXNumberingRules->get();
    1521          16 :         ((SwXNumberingRulesCollection*)pNum)->Invalidate();
    1522          16 :         delete pxXNumberingRules;
    1523          16 :         pxXNumberingRules = 0;
    1524             :     }
    1525             : 
    1526        1553 :     if(pxXFootnotes)
    1527             :     {
    1528           6 :          XIndexAccess* pFtn = pxXFootnotes->get();
    1529           6 :         ((SwXFootnotes*)pFtn)->Invalidate();
    1530           6 :         delete pxXFootnotes;
    1531           6 :         pxXFootnotes = 0;
    1532             :     }
    1533             : 
    1534        1553 :     if(pxXEndnotes)
    1535             :     {
    1536           1 :          XIndexAccess* pFtn = pxXEndnotes->get();
    1537           1 :         ((SwXFootnotes*)pFtn)->Invalidate();
    1538           1 :         delete pxXEndnotes;
    1539           1 :         pxXEndnotes = 0;
    1540             :     }
    1541             : 
    1542        1553 :     if(pxXDocumentIndexes)
    1543             :     {
    1544         344 :          XIndexAccess* pIdxs = pxXDocumentIndexes->get();
    1545         344 :         ((SwXDocumentIndexes*)pIdxs)->Invalidate();
    1546         344 :         delete pxXDocumentIndexes;
    1547         344 :         pxXDocumentIndexes = 0;
    1548             :     }
    1549             : 
    1550        1553 :     if(pxXStyleFamilies)
    1551             :     {
    1552         764 :          XNameAccess* pStyles = pxXStyleFamilies->get();
    1553         764 :         ((SwXStyleFamilies*)pStyles)->Invalidate();
    1554         764 :         delete pxXStyleFamilies;
    1555         764 :         pxXStyleFamilies = 0;
    1556             :     }
    1557        1553 :     if(pxXAutoStyles)
    1558             :     {
    1559          38 :          XNameAccess* pStyles = pxXAutoStyles->get();
    1560          38 :         ((SwXAutoStyles*)pStyles)->Invalidate();
    1561          38 :         delete pxXAutoStyles;
    1562          38 :         pxXAutoStyles = 0;
    1563             :     }
    1564             : 
    1565        1553 :     if(pxXBookmarks)
    1566             :     {
    1567          10 :          XNameAccess* pBm = pxXBookmarks->get();
    1568          10 :         ((SwXBookmarks*)pBm)->Invalidate();
    1569          10 :         delete pxXBookmarks;
    1570          10 :         pxXBookmarks = 0;
    1571             :     }
    1572             : 
    1573        1553 :     if(pxXChapterNumbering)
    1574             :     {
    1575          61 :          XIndexReplace* pCh = pxXChapterNumbering->get();
    1576          61 :         ((SwXChapterNumbering*)pCh)->Invalidate();
    1577          61 :         delete pxXChapterNumbering;
    1578          61 :         pxXChapterNumbering = 0;
    1579             :     }
    1580             : 
    1581        1553 :     if(pxXFootnoteSettings)
    1582             :     {
    1583         106 :          XPropertySet* pFntSet = pxXFootnoteSettings->get();
    1584         106 :         ((SwXFootnoteProperties*)pFntSet)->Invalidate();
    1585         106 :         delete pxXFootnoteSettings;
    1586         106 :         pxXFootnoteSettings = 0;
    1587             :     }
    1588             : 
    1589        1553 :     if(pxXEndnoteSettings)
    1590             :     {
    1591         105 :          XPropertySet* pEndSet = pxXEndnoteSettings->get();
    1592         105 :         ((SwXEndnoteProperties*)pEndSet)->Invalidate();
    1593         105 :         delete pxXEndnoteSettings;
    1594         105 :         pxXEndnoteSettings = 0;
    1595             :     }
    1596             : 
    1597        1553 :     if(pxXLineNumberingProperties)
    1598             :     {
    1599          60 :          XPropertySet* pLine = pxXLineNumberingProperties->get();
    1600          60 :         ((SwXLineNumberingProperties*)pLine)->Invalidate();
    1601          60 :         delete pxXLineNumberingProperties;
    1602          60 :         pxXLineNumberingProperties = 0;
    1603             :     }
    1604        1553 :     if(pxXReferenceMarks)
    1605             :     {
    1606           2 :          XNameAccess* pMarks = pxXReferenceMarks->get();
    1607           2 :         ((SwXReferenceMarks*)pMarks)->Invalidate();
    1608           2 :         delete pxXReferenceMarks;
    1609           2 :         pxXReferenceMarks = 0;
    1610             :     }
    1611        1553 :     if(pxLinkTargetSupplier)
    1612             :     {
    1613           0 :          XNameAccess* pAccess = (*pxLinkTargetSupplier).get();
    1614           0 :         ((SwXLinkTargetSupplier*)pAccess)->Invalidate();
    1615           0 :         delete pxLinkTargetSupplier;
    1616           0 :         pxLinkTargetSupplier = 0;
    1617             :     }
    1618        1553 :     if(pxXRedlines)
    1619             :     {
    1620          15 :         XEnumerationAccess* pMarks = pxXRedlines->get();
    1621          15 :         ((SwXRedlines*)pMarks)->Invalidate();
    1622          15 :         delete pxXRedlines;
    1623          15 :         pxXRedlines = 0;
    1624             :     }
    1625        1553 :     if(xPropertyHelper.is())
    1626             :     {
    1627          65 :         pPropertyHelper->Invalidate();
    1628          65 :         xPropertyHelper = 0;
    1629          65 :         pPropertyHelper = 0;
    1630             :     }
    1631        1553 : }
    1632             : 
    1633             : #define COM_SUN_STAR__DRAWING_LENGTH 13
    1634        6573 : Reference< XInterface >  SwXTextDocument::createInstance(const OUString& rServiceName)
    1635             :                                         throw( Exception, RuntimeException )
    1636             : {
    1637        6573 :     SolarMutexGuard aGuard;
    1638        6573 :     if(!IsValid())
    1639           0 :         throw RuntimeException();
    1640        6573 :     Reference< XInterface >  xRet;
    1641        6573 :     sal_uInt16 nType = SwXServiceProvider::GetProviderType(rServiceName);
    1642        6573 :     if(nType != SW_SERVICE_INVALID)
    1643             :     {
    1644        4669 :         xRet = SwXServiceProvider::MakeInstance(nType, pDocShell->GetDoc());
    1645             :     }
    1646             :     else
    1647             :     {
    1648        1904 :         if( rServiceName.startsWith("com.sun.star.") )
    1649             :         {
    1650        1904 :             sal_Int32 nIndex = COM_SUN_STAR__DRAWING_LENGTH;
    1651        1904 :             OUString sCategory = rServiceName.getToken( 0, '.', nIndex );
    1652        1904 :             bool bShape = sCategory == "drawing";
    1653        1904 :             if( bShape || sCategory == "form")
    1654             :             {
    1655         807 :                 if(bShape)
    1656             :                 {
    1657         575 :                     short nTable = 0;
    1658         575 :                     if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.DashTable") ) )
    1659          16 :                         nTable = SW_CREATE_DASH_TABLE;
    1660         559 :                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.GradientTable") ) )
    1661          26 :                         nTable = SW_CREATE_GRADIENT_TABLE;
    1662         533 :                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.HatchTable") ) )
    1663          17 :                         nTable = SW_CREATE_HATCH_TABLE;
    1664         516 :                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.BitmapTable") ) )
    1665          16 :                         nTable = SW_CREATE_BITMAP_TABLE;
    1666         500 :                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.TransparencyGradientTable") ) )
    1667          16 :                         nTable = SW_CREATE_TRANSGRADIENT_TABLE;
    1668         484 :                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.MarkerTable") ) )
    1669          20 :                         nTable = SW_CREATE_MARKER_TABLE;
    1670         464 :                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.Defaults") ) )
    1671          67 :                         nTable = SW_CREATE_DRAW_DEFAULTS;
    1672         575 :                     if(nTable)
    1673             :                     {
    1674         178 :                         xRet = GetPropertyHelper()->GetDrawTable(nTable);
    1675             :                     }
    1676             :                 }
    1677             :             }
    1678        1097 :             else if (sCategory == "document" )
    1679             :             {
    1680        1021 :                 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.document.Settings") ) )
    1681         910 :                     xRet = Reference < XInterface > ( *new SwXDocumentSettings ( this ) );
    1682        1021 :                 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.document.ImportEmbeddedObjectResolver") ) )
    1683             :                 {
    1684          58 :                     xRet = (::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_READ );
    1685             :                 }
    1686             :             }
    1687          76 :             else if (sCategory == "text" )
    1688             :             {
    1689           5 :                 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.DocumentSettings") ) )
    1690           1 :                     xRet = Reference < XInterface > ( *new SwXDocumentSettings ( this ) );
    1691             :             }
    1692          71 :             else if (sCategory == "chart2" )
    1693             :             {
    1694           0 :                 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart2.data.DataProvider") ) )
    1695           0 :                     xRet = Reference < XInterface > ( dynamic_cast< chart2::data::XDataProvider * >(pDocShell->getIDocumentChartDataProviderAccess()->GetChartDataProvider()) );
    1696             :             }
    1697             : 
    1698        1904 :             if(!xRet.is())
    1699             :             {
    1700             :                 //! we don't want to insert OLE2 Shapes (e.g. "com.sun.star.drawing.OLE2Shape", ...)
    1701             :                 //! like this (by creating them with the documents factory and
    1702             :                 //! adding the shapes to the draw page).
    1703             :                 //! For inserting OLE objects the proper way is to use
    1704             :                 //! "com.sun.star.text.TextEmbeddedObject"!
    1705         757 :                 if (rServiceName.lastIndexOf( ".OLE2Shape" ) == rServiceName.getLength() - 10)
    1706           0 :                     throw ServiceNotRegisteredException();  // declare service to be not registered with this factory
    1707             : 
    1708             :                 //
    1709             :                 // the XML import is allowed to create instances of com.sun.star.drawing.OLE2Shape.
    1710             :                 // Thus, a temporary service name is introduced to make this possible.
    1711         757 :                 OUString aTmpServiceName( rServiceName );
    1712        1154 :                 if ( bShape &&
    1713         397 :                      rServiceName.compareToAscii( "com.sun.star.drawing.temporaryForXMLImportOLE2Shape" ) == 0 )
    1714             :                 {
    1715           0 :                     aTmpServiceName = OUString("com.sun.star.drawing.OLE2Shape");
    1716             :                 }
    1717             :                 //here search for the draw service
    1718        1443 :                 Reference< XInterface >  xTmp = SvxFmMSFactory::createInstance(aTmpServiceName);
    1719         686 :                 if(bShape)
    1720             :                 {
    1721         397 :                     nIndex = COM_SUN_STAR__DRAWING_LENGTH;
    1722         781 :                     if( 0 == rServiceName.reverseCompareToAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.drawing.GroupShape" ) ) ||
    1723         384 :                         0 == rServiceName.reverseCompareToAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.drawing.Shape3DSceneObject" ) ) )
    1724          13 :                         xRet = *new SwXGroupShape( xTmp );
    1725             :                     else
    1726         384 :                         xRet = *new SwXShape( xTmp );
    1727             :                 }
    1728             :                 else
    1729        1046 :                     xRet = xTmp;
    1730        1904 :             }
    1731             :         }
    1732             :         else
    1733           0 :             throw ServiceNotRegisteredException();
    1734             :     }
    1735        6573 :     return xRet;
    1736             : }
    1737             : 
    1738           0 : Reference< XInterface >  SwXTextDocument::createInstanceWithArguments(
    1739             :         const OUString& ServiceSpecifier,
    1740             :         const Sequence< Any >& /*Arguments*/)
    1741             :         throw( Exception, RuntimeException )
    1742             : {
    1743           0 :     Reference< XInterface >  xInt = createInstance(ServiceSpecifier);
    1744             :     // The Any-Sequence is for initializing objects that are dependent
    1745             :     // on parameters necessarily - so far we have not.
    1746           0 :     return xInt;
    1747             : }
    1748             : 
    1749          34 : Sequence< OUString > SwXTextDocument::getAvailableServiceNames(void)
    1750             :                                         throw( RuntimeException )
    1751             : {
    1752          34 :     static Sequence< OUString > aServices;
    1753          34 :     if ( aServices.getLength() == 0 )
    1754             :     {
    1755           8 :         Sequence< OUString > aRet =  SvxFmMSFactory::getAvailableServiceNames();
    1756           8 :         OUString* pRet = aRet.getArray();
    1757         224 :         for ( sal_Int32 i = 0; i < aRet.getLength(); ++i )
    1758             :         {
    1759         224 :             if ( pRet[i].compareToAscii( "com.sun.star.drawing.OLE2Shape" ) == 0 )
    1760             :             {
    1761           8 :                 pRet[i] = pRet[aRet.getLength() - 1];
    1762           8 :                 aRet.realloc( aRet.getLength() - 1 ); // <pRet> no longer valid.
    1763           8 :                 break;
    1764             :             }
    1765             :         }
    1766          16 :         Sequence< OUString > aOwn = SwXServiceProvider::GetAllServiceNames();
    1767          16 :         aServices = SvxFmMSFactory::concatServiceNames(aRet, aOwn);
    1768             :     }
    1769             : 
    1770          34 :     return aServices;
    1771             : }
    1772             : 
    1773           0 : OUString SwXTextDocument::getImplementationName(void) throw( RuntimeException )
    1774             : {
    1775           0 :     return OUString("SwXTextDocument");
    1776             : }
    1777             : 
    1778        1568 : sal_Bool SwXTextDocument::supportsService(const OUString& rServiceName) throw( RuntimeException )
    1779             : {
    1780        1568 :     if ( rServiceName == "com.sun.star.document.OfficeDocument" || rServiceName == "com.sun.star.text.GenericTextDocument" )
    1781        1076 :         return sal_True;
    1782             : 
    1783         492 :     bool bWebDoc    = (0 != PTR_CAST(SwWebDocShell,    pDocShell));
    1784         492 :     bool bGlobalDoc = (0 != PTR_CAST(SwGlobalDocShell, pDocShell));
    1785         492 :     bool bTextDoc   = (!bWebDoc && !bGlobalDoc);
    1786             : 
    1787           4 :     return ( (bWebDoc    && rServiceName == "com.sun.star.text.WebDocument")
    1788         492 :           || (bGlobalDoc && rServiceName == "com.sun.star.text.GlobalDocument")
    1789         984 :           || (bTextDoc   && rServiceName == "com.sun.star.text.TextDocument") );
    1790             : }
    1791             : 
    1792         864 : Sequence< OUString > SwXTextDocument::getSupportedServiceNames(void) throw( RuntimeException )
    1793             : {
    1794         864 :     bool bWebDoc    = (0 != PTR_CAST(SwWebDocShell,    pDocShell));
    1795         864 :     bool bGlobalDoc = (0 != PTR_CAST(SwGlobalDocShell, pDocShell));
    1796         864 :     bool bTextDoc   = (!bWebDoc && !bGlobalDoc);
    1797             : 
    1798         864 :     Sequence< OUString > aRet (3);
    1799         864 :     OUString* pArray = aRet.getArray();
    1800             : 
    1801         864 :     pArray[0] = OUString ( ( "com.sun.star.document.OfficeDocument"  ) );
    1802         864 :     pArray[1] = OUString ( ( "com.sun.star.text.GenericTextDocument" ) );
    1803             : 
    1804         864 :     if (bTextDoc)
    1805         862 :         pArray[2] = OUString ( ( "com.sun.star.text.TextDocument" ) );
    1806           2 :     else if (bWebDoc)
    1807           2 :         pArray[2] = OUString ( ( "com.sun.star.text.WebDocument" ) );
    1808           0 :     else if (bGlobalDoc)
    1809           0 :         pArray[2] = OUString ( ( "com.sun.star.text.GlobalDocument" ) );
    1810             : 
    1811         864 :     return aRet;
    1812             : }
    1813             : 
    1814         360 : Reference< XIndexAccess >  SwXTextDocument::getDocumentIndexes(void) throw( RuntimeException )
    1815             : {
    1816         360 :     SolarMutexGuard aGuard;
    1817         360 :     if(!IsValid())
    1818           0 :         throw RuntimeException();
    1819         360 :     if(!pxXDocumentIndexes)
    1820             :     {
    1821         344 :         ((SwXTextDocument*)this)->pxXDocumentIndexes = new Reference< XIndexAccess > ;
    1822         344 :         *pxXDocumentIndexes = new SwXDocumentIndexes(pDocShell->GetDoc());
    1823             :     }
    1824         360 :     return *pxXDocumentIndexes;
    1825             : }
    1826             : 
    1827         959 : Reference< XPropertySetInfo >  SwXTextDocument::getPropertySetInfo(void) throw( RuntimeException )
    1828             : {
    1829         959 :     static Reference< XPropertySetInfo >  xRet = pPropSet->getPropertySetInfo();
    1830         959 :     return xRet;
    1831             : }
    1832             : 
    1833        1552 : void SwXTextDocument::setPropertyValue(const OUString& rPropertyName,
    1834             :     const Any& aValue)
    1835             :     throw( UnknownPropertyException, PropertyVetoException, IllegalArgumentException,
    1836             :                                          WrappedTargetException, RuntimeException)
    1837             : {
    1838        1552 :     SolarMutexGuard aGuard;
    1839        1552 :     if(!IsValid())
    1840             :         throw RuntimeException(
    1841             :             "invalid SwXTextDocument",
    1842             :             static_cast< cppu::OWeakObject * >(
    1843           0 :                 static_cast< SwXTextDocumentBaseClass * >(this)));
    1844        1552 :     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
    1845             : 
    1846        1552 :     if(!pEntry)
    1847           0 :         throw UnknownPropertyException();
    1848        1552 :     if(pEntry->nFlags & PropertyAttribute::READONLY)
    1849           4 :         throw PropertyVetoException();
    1850        1548 :     switch(pEntry->nWID)
    1851             :     {
    1852             :         case  WID_DOC_CHAR_COUNT     :
    1853             :         case  WID_DOC_PARA_COUNT     :
    1854             :         case  WID_DOC_WORD_COUNT     :
    1855             :             throw RuntimeException(
    1856             :                 "bad WID",
    1857             :                 static_cast< cppu::OWeakObject * >(
    1858           0 :                     static_cast< SwXTextDocumentBaseClass * >(this)));
    1859             :         case  WID_DOC_WORD_SEPARATOR :
    1860             :         {
    1861           5 :             OUString sDelim;
    1862           5 :             aValue >>= sDelim;
    1863           5 :             SW_MOD()->GetModuleConfig()->SetWordDelimiter(sDelim);
    1864             :         }
    1865           5 :         break;
    1866             :         case WID_DOC_CHANGES_RECORD:
    1867             :         case WID_DOC_CHANGES_SHOW:
    1868             :         {
    1869         355 :             sal_Bool bSet = *(sal_Bool*)aValue.getValue();
    1870         355 :             sal_uInt16 eMode = pDocShell->GetDoc()->GetRedlineMode();
    1871         355 :             if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
    1872             :             {
    1873           5 :                 eMode &= ~(nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE);
    1874           5 :                 eMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT;
    1875           5 :                 if( bSet )
    1876           5 :                     eMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE;
    1877             :             }
    1878         350 :             else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
    1879             :             {
    1880         350 :                 eMode = bSet ? eMode|nsRedlineMode_t::REDLINE_ON : eMode&~nsRedlineMode_t::REDLINE_ON;
    1881             :             }
    1882         355 :             pDocShell->GetDoc()->SetRedlineMode( (RedlineMode_t)(eMode ));
    1883             :         }
    1884         355 :         break;
    1885             :         case  WID_DOC_CHANGES_PASSWORD:
    1886             :         {
    1887           5 :             Sequence <sal_Int8> aNew;
    1888           5 :             if(aValue >>= aNew)
    1889             :             {
    1890           5 :                 SwDoc* pDoc = pDocShell->GetDoc();
    1891           5 :                 pDoc->SetRedlinePassword(aNew);
    1892           5 :                 if(aNew.getLength())
    1893             :                 {
    1894           0 :                     sal_uInt16 eMode = pDoc->GetRedlineMode();
    1895           0 :                     eMode = eMode|nsRedlineMode_t::REDLINE_ON;
    1896           0 :                     pDoc->SetRedlineMode( (RedlineMode_t)(eMode ));
    1897             :                 }
    1898           5 :             }
    1899             :         }
    1900           5 :         break;
    1901             :         case WID_DOC_AUTO_MARK_URL :
    1902             :         {
    1903           1 :             OUString sURL;
    1904           1 :             aValue >>= sURL;
    1905           1 :             pDocShell->GetDoc()->SetTOIAutoMarkURL(sURL);
    1906             :         }
    1907           1 :         break;
    1908             :         case WID_DOC_HIDE_TIPS :
    1909           4 :             SW_MOD()->GetModuleConfig()->SetHideFieldTips(*(sal_Bool*)aValue.getValue());
    1910           4 :         break;
    1911             :         case WID_DOC_REDLINE_DISPLAY:
    1912             :         {
    1913           4 :             sal_Int16 eRedMode = pDocShell->GetDoc()->GetRedlineMode();
    1914           4 :             eRedMode = eRedMode & (~nsRedlineMode_t::REDLINE_SHOW_MASK);
    1915           4 :             sal_Int16 nSet = 0;
    1916           4 :             aValue >>= nSet;
    1917           4 :             switch(nSet)
    1918             :             {
    1919           0 :                 case RedlineDisplayType::NONE: break;
    1920           0 :                 case RedlineDisplayType::INSERTED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT; break;
    1921           4 :                 case RedlineDisplayType::REMOVED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE;  break;
    1922             :                 case RedlineDisplayType::
    1923           0 :                         INSERTED_AND_REMOVED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT|nsRedlineMode_t::REDLINE_SHOW_DELETE;
    1924           0 :                 break;
    1925           0 :                 default: throw IllegalArgumentException();
    1926             :             }
    1927           4 :             pDocShell->GetDoc()->SetRedlineMode(eRedMode);
    1928             :         }
    1929           4 :         break;
    1930             :         case WID_DOC_TWO_DIGIT_YEAR:
    1931             :         {
    1932           5 :             sal_Int16 nYear = 0;
    1933           5 :             aValue >>= nYear;
    1934           5 :             SfxRequest aRequest ( SID_ATTR_YEAR2000, SFX_CALLMODE_SLOT, pDocShell->GetDoc()->GetAttrPool());
    1935           5 :             aRequest.AppendItem(SfxUInt16Item( SID_ATTR_YEAR2000, static_cast < sal_uInt16 > ( nYear ) ) );
    1936           5 :             pDocShell->Execute ( aRequest );
    1937             :         }
    1938           5 :         break;
    1939             :         case WID_DOC_AUTOMATIC_CONTROL_FOCUS:
    1940             :         {
    1941             :             SwDrawDocument * pDrawDoc;
    1942          11 :             sal_Bool bAuto = *(sal_Bool*) aValue.getValue();
    1943             : 
    1944          11 :             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * >( pDocShell->GetDoc()->GetDrawModel() ) ) )
    1945          11 :                 pDrawDoc->SetAutoControlFocus( bAuto );
    1946           0 :             else if (bAuto)
    1947             :             {
    1948             :                 // if setting to true, and we don't have an
    1949             :                 // SdrModel, then we are changing the default and
    1950             :                 // must thus create an SdrModel, if we don't have an
    1951             :                 // SdrModel and we are leaving the default at false,
    1952             :                 // we don't need to make an SdrModel and can do nothing
    1953             :                 // #i52858# - method name changed
    1954           0 :                 pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetOrCreateDrawModel() );
    1955           0 :                 pDrawDoc->SetAutoControlFocus ( bAuto );
    1956             :             }
    1957             :         }
    1958          11 :         break;
    1959             :         case WID_DOC_APPLY_FORM_DESIGN_MODE:
    1960             :         {
    1961             :             SwDrawDocument * pDrawDoc;
    1962          61 :             sal_Bool bMode = *(sal_Bool*)aValue.getValue();
    1963             : 
    1964          61 :             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetDrawModel() ) ) )
    1965          11 :                 pDrawDoc->SetOpenInDesignMode( bMode );
    1966          50 :             else if (!bMode)
    1967             :             {
    1968             :                 // if setting to false, and we don't have an
    1969             :                 // SdrModel, then we are changing the default and
    1970             :                 // must thus create an SdrModel, if we don't have an
    1971             :                 // SdrModel and we are leaving the default at true,
    1972             :                 // we don't need to make an SdrModel and can do
    1973             :                 // nothing
    1974             :                 // #i52858# - method name changed
    1975          50 :                 pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetOrCreateDrawModel() );
    1976          50 :                 pDrawDoc->SetOpenInDesignMode ( bMode );
    1977             :             }
    1978             :         }
    1979          61 :         break;
    1980             :         // #i42634# New property to set the bInReading
    1981             :         // flag at the document, used during binary import
    1982             :         case WID_DOC_LOCK_UPDATES :
    1983             :         {
    1984         684 :             SwDoc* pDoc = pDocShell->GetDoc();
    1985         684 :             bool bBool (false);
    1986         684 :             if( aValue >>= bBool )
    1987         684 :               pDoc->SetInReading( bBool );
    1988             :         }
    1989         684 :         break;
    1990             :         case WID_DOC_BUILDID:
    1991          56 :             aValue >>= maBuildId;
    1992          56 :         break;
    1993             : 
    1994             :         case WID_DOC_DEFAULT_PAGE_MODE:
    1995             :         {
    1996         356 :             bool bDefaultPageMode( false );
    1997         356 :             aValue >>= bDefaultPageMode;
    1998         356 :             pDocShell->GetDoc()->SetDefaultPageMode( bDefaultPageMode );
    1999             :         }
    2000         356 :         break;
    2001             : 
    2002             :         default:
    2003             :         {
    2004           1 :             const SfxPoolItem& rItem = pDocShell->GetDoc()->GetDefault(pEntry->nWID);
    2005           1 :             SfxPoolItem* pNewItem = rItem.Clone();
    2006           1 :             pNewItem->PutValue(aValue, pEntry->nMemberId);
    2007           1 :             pDocShell->GetDoc()->SetDefault(*pNewItem);
    2008           1 :             delete pNewItem;
    2009             :         }
    2010        1552 :     }
    2011        1548 : }
    2012             : 
    2013        2306 : Any SwXTextDocument::getPropertyValue(const OUString& rPropertyName)
    2014             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
    2015             : {
    2016        2306 :     SolarMutexGuard aGuard;
    2017        2306 :     if(!IsValid())
    2018           0 :         throw RuntimeException();
    2019        2306 :     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
    2020             : 
    2021        2306 :     if(!pEntry)
    2022           0 :         throw UnknownPropertyException();
    2023        2306 :     Any aAny;
    2024        2306 :     switch(pEntry->nWID)
    2025             :     {
    2026             :         case WID_DOC_ISTEMPLATEID    :
    2027           0 :             aAny <<= pDocShell->IsTemplate();
    2028           0 :             break;
    2029             :         case  WID_DOC_CHAR_COUNT     :
    2030             :         case  WID_DOC_PARA_COUNT     :
    2031             :         case  WID_DOC_WORD_COUNT     :
    2032             :         {
    2033           6 :             const SwDocStat& rStat(pDocShell->GetDoc()->GetUpdatedDocStat());
    2034             :             sal_Int32 nValue;
    2035           6 :             switch(pEntry->nWID)
    2036             :             {
    2037           2 :                 case  WID_DOC_CHAR_COUNT     :nValue = rStat.nChar;break;
    2038           2 :                 case  WID_DOC_PARA_COUNT     :nValue = rStat.nPara;break;
    2039           2 :                 case  WID_DOC_WORD_COUNT     :nValue = rStat.nWord;break;
    2040             :             }
    2041           6 :             aAny <<= nValue;
    2042             :         }
    2043           6 :         break;
    2044             :         case  WID_DOC_WORD_SEPARATOR :
    2045             :         {
    2046          12 :             aAny <<= OUString(SW_MOD()->GetDocStatWordDelim());
    2047             :         }
    2048          12 :         break;
    2049             :         case WID_DOC_CHANGES_RECORD:
    2050             :         case WID_DOC_CHANGES_SHOW:
    2051             :         {
    2052          44 :             sal_uInt16 eMode = pDocShell->GetDoc()->GetRedlineMode();
    2053          44 :             sal_Bool bSet = sal_False;
    2054          44 :             if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
    2055             :             {
    2056          11 :                 sal_uInt16 nMask = nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE;
    2057          11 :                 bSet = (eMode & nMask) == nMask;
    2058             :             }
    2059          33 :             else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
    2060             :             {
    2061          33 :                 bSet = (eMode& nsRedlineMode_t::REDLINE_ON)  != 0;
    2062             :             }
    2063          44 :             aAny.setValue(&bSet, ::getBooleanCppuType());
    2064             :         }
    2065          44 :         break;
    2066             :         case  WID_DOC_CHANGES_PASSWORD:
    2067             :         {
    2068          11 :             SwDoc* pDoc = pDocShell->GetDoc();
    2069          11 :             aAny <<= pDoc->GetRedlinePassword();
    2070             :         }
    2071          11 :         break;
    2072             :         case WID_DOC_AUTO_MARK_URL :
    2073          18 :             aAny <<= OUString(pDocShell->GetDoc()->GetTOIAutoMarkURL());
    2074          18 :         break;
    2075             :         case WID_DOC_HIDE_TIPS :
    2076             :         {
    2077          10 :             sal_Bool bTemp = SW_MOD()->GetModuleConfig()->IsHideFieldTips();
    2078          10 :             aAny.setValue(&bTemp, ::getBooleanCppuType());
    2079             :         }
    2080          10 :         break;
    2081             :         case WID_DOC_REDLINE_DISPLAY:
    2082             :         {
    2083          10 :             sal_Int16 eRedMode = pDocShell->GetDoc()->GetRedlineMode();
    2084          10 :             eRedMode = eRedMode & nsRedlineMode_t::REDLINE_SHOW_MASK;
    2085          10 :             sal_Int16 nRet = RedlineDisplayType::NONE;
    2086          10 :             if(nsRedlineMode_t::REDLINE_SHOW_INSERT == eRedMode)
    2087           0 :                 nRet = RedlineDisplayType::INSERTED;
    2088          10 :             else if(nsRedlineMode_t::REDLINE_SHOW_DELETE == eRedMode)
    2089           4 :                 nRet = RedlineDisplayType::REMOVED;
    2090           6 :             else if(nsRedlineMode_t::REDLINE_SHOW_MASK == eRedMode)
    2091           6 :                 nRet = RedlineDisplayType::INSERTED_AND_REMOVED;
    2092          10 :             aAny <<= nRet;
    2093             :         }
    2094          10 :         break;
    2095             :         case WID_DOC_FORBIDDEN_CHARS:
    2096             :         {
    2097           2 :             GetPropertyHelper();
    2098           2 :             Reference<XForbiddenCharacters> xRet(xPropertyHelper, UNO_QUERY);
    2099           2 :             aAny <<= xRet;
    2100             :         }
    2101           2 :         break;
    2102             :         case WID_DOC_TWO_DIGIT_YEAR:
    2103             :         {
    2104          28 :             aAny <<= static_cast < sal_Int16 > (pDocShell->GetDoc()->GetNumberFormatter ( sal_True )->GetYear2000());
    2105             :         }
    2106          28 :         break;
    2107             :         case WID_DOC_AUTOMATIC_CONTROL_FOCUS:
    2108             :         {
    2109             :             SwDrawDocument * pDrawDoc;
    2110             :             sal_Bool bAuto;
    2111          12 :             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetDrawModel() ) ) )
    2112          12 :                 bAuto = pDrawDoc->GetAutoControlFocus();
    2113             :             else
    2114           0 :                 bAuto = sal_False;
    2115          12 :             aAny.setValue(&bAuto, ::getBooleanCppuType());
    2116             :         }
    2117          12 :         break;
    2118             :         case WID_DOC_APPLY_FORM_DESIGN_MODE:
    2119             :         {
    2120             :             SwDrawDocument * pDrawDoc;
    2121             :             sal_Bool bMode;
    2122          12 :             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetDrawModel() ) ) )
    2123          12 :                 bMode = pDrawDoc->GetOpenInDesignMode();
    2124             :             else
    2125           0 :                 bMode = sal_True;
    2126          12 :             aAny.setValue(&bMode, ::getBooleanCppuType());
    2127             :         }
    2128          12 :         break;
    2129             :         case WID_DOC_BASIC_LIBRARIES:
    2130          53 :             aAny <<= pDocShell->GetBasicContainer();
    2131          53 :         break;
    2132             :         case WID_DOC_DIALOG_LIBRARIES:
    2133           0 :             aAny <<= pDocShell->GetDialogContainer();
    2134           0 :         break;
    2135             :         case WID_DOC_VBA_DOCOBJ:
    2136             :         {
    2137        1549 :             beans::PropertyValue aProp;
    2138        1549 :             aProp.Name = OUString("ThisWordDoc");
    2139        1549 :             aProp.Value <<= pDocShell->GetModel();
    2140        1549 :             aAny <<= aProp;
    2141             :         }
    2142        1549 :         break;
    2143             :         case WID_DOC_RUNTIME_UID:
    2144         513 :             aAny <<= getRuntimeUID();
    2145         513 :         break;
    2146             :         case WID_DOC_LOCK_UPDATES :
    2147          10 :             aAny <<= static_cast<bool>( pDocShell->GetDoc()->IsInReading() );
    2148          10 :         break;
    2149             :         case WID_DOC_BUILDID:
    2150          10 :             aAny <<= maBuildId;
    2151          10 :         break;
    2152             :         case WID_DOC_HAS_VALID_SIGNATURES:
    2153           0 :             aAny <<= hasValidSignatures();
    2154           0 :         break;
    2155             : 
    2156             :         default:
    2157             :         {
    2158           6 :             const SfxPoolItem& rItem = pDocShell->GetDoc()->GetDefault(pEntry->nWID);
    2159           6 :             rItem.QueryValue(aAny, pEntry->nMemberId);
    2160             :         }
    2161             :     }
    2162        2306 :     return aAny;
    2163             : }
    2164             : 
    2165           0 : void SwXTextDocument::addPropertyChangeListener(const OUString& /*PropertyName*/,
    2166             :     const Reference< XPropertyChangeListener > & /*aListener*/)
    2167             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
    2168             : {
    2169             :     OSL_FAIL("not implemented");
    2170           0 : }
    2171             : 
    2172           0 : void SwXTextDocument::removePropertyChangeListener(const OUString& /*PropertyName*/,
    2173             :     const Reference< XPropertyChangeListener > & /*aListener*/)
    2174             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
    2175             : {
    2176             :     OSL_FAIL("not implemented");
    2177           0 : }
    2178             : 
    2179           0 : void SwXTextDocument::addVetoableChangeListener(const OUString& /*PropertyName*/,
    2180             :     const Reference< XVetoableChangeListener > & /*aListener*/)
    2181             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
    2182             : {
    2183             :     OSL_FAIL("not implemented");
    2184           0 : }
    2185             : 
    2186           0 : void SwXTextDocument::removeVetoableChangeListener(const OUString& /*PropertyName*/,
    2187             :                         const Reference< XVetoableChangeListener > & /*aListener*/)
    2188             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
    2189             : {
    2190             :     OSL_FAIL("not implemented");
    2191           0 : }
    2192             : 
    2193           0 : Reference< XNameAccess >  SwXTextDocument::getLinks(void) throw( RuntimeException )
    2194             : {
    2195           0 :     if(!pxLinkTargetSupplier)
    2196             :     {
    2197           0 :         pxLinkTargetSupplier = new Reference< XNameAccess > ;
    2198           0 :         (*pxLinkTargetSupplier) = new SwXLinkTargetSupplier(*(SwXTextDocument*)this);
    2199             :     }
    2200           0 :     return (*pxLinkTargetSupplier);
    2201             : }
    2202             : 
    2203          32 : Reference< XEnumerationAccess > SwXTextDocument::getRedlines(  ) throw(RuntimeException)
    2204             : {
    2205          32 :     if(!pxXRedlines)
    2206             :     {
    2207          15 :         pxXRedlines = new Reference< XEnumerationAccess > ;
    2208          15 :         (*pxXRedlines) = new SwXRedlines(pDocShell->GetDoc());
    2209             :     }
    2210          32 :     return *pxXRedlines;
    2211             : }
    2212             : 
    2213           2 : void SwXTextDocument::NotifyRefreshListeners()
    2214             : {
    2215             :     // why does SwBaseShell not just call refresh? maybe because it's rSh is
    2216             :     // (sometimes) a different shell than GetWrtShell()?
    2217           2 :     lang::EventObject const ev(static_cast<SwXTextDocumentBaseClass &>(*this));
    2218           2 :     m_pImpl->m_RefreshListeners.notifyEach(
    2219           4 :             & util::XRefreshListener::refreshed, ev);
    2220           2 : }
    2221             : 
    2222           2 : void SwXTextDocument::refresh(void) throw( RuntimeException )
    2223             : {
    2224           2 :     SolarMutexGuard aGuard;
    2225           2 :     if(!IsValid())
    2226           0 :         throw RuntimeException();
    2227           2 :     ViewShell *pViewShell = pDocShell->GetWrtShell();
    2228           2 :     NotifyRefreshListeners();
    2229           2 :     if(pViewShell)
    2230           2 :         pViewShell->CalcLayout();
    2231           2 : }
    2232             : 
    2233           1 : void SAL_CALL SwXTextDocument::addRefreshListener(
    2234             :         const Reference<util::XRefreshListener> & xListener)
    2235             : throw (RuntimeException)
    2236             : {
    2237             :     // no need to lock here as m_pImpl is const and container threadsafe
    2238           1 :     m_pImpl->m_RefreshListeners.addInterface(xListener);
    2239           1 : }
    2240             : 
    2241           1 : void SAL_CALL SwXTextDocument::removeRefreshListener(
    2242             :         const Reference<util::XRefreshListener> & xListener)
    2243             : throw (RuntimeException)
    2244             : {
    2245             :     // no need to lock here as m_pImpl is const and container threadsafe
    2246           1 :     m_pImpl->m_RefreshListeners.removeInterface(xListener);
    2247           1 : }
    2248             : 
    2249           0 : void SwXTextDocument::updateLinks(  ) throw(RuntimeException)
    2250             : {
    2251           0 :     SolarMutexGuard aGuard;
    2252           0 :     if(!IsValid())
    2253           0 :         throw RuntimeException();
    2254           0 :     SwDoc* pDoc = pDocShell->GetDoc();
    2255           0 :       sfx2::LinkManager& rLnkMan = pDoc->GetLinkManager();
    2256           0 :     if( !rLnkMan.GetLinks().empty() )
    2257             :     {
    2258           0 :         UnoActionContext aAction(pDoc);
    2259           0 :         rLnkMan.UpdateAllLinks( false, false, true );
    2260           0 :     }
    2261           0 : }
    2262             : 
    2263             : //XPropertyState
    2264           0 : PropertyState SAL_CALL SwXTextDocument::getPropertyState( const OUString& rPropertyName )
    2265             :     throw (UnknownPropertyException, RuntimeException)
    2266             : {
    2267           0 :     SolarMutexGuard aGuard;
    2268           0 :     PropertyState eRet = PropertyState_DIRECT_VALUE;
    2269           0 :     if(!IsValid())
    2270           0 :         throw RuntimeException();
    2271           0 :     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
    2272             : 
    2273           0 :     if(!pEntry)
    2274           0 :         throw UnknownPropertyException();
    2275           0 :     Any aAny;
    2276           0 :     switch(pEntry->nWID)
    2277             :     {
    2278           0 :         case 0:default:break;
    2279             :     }
    2280           0 :     return eRet;
    2281             : }
    2282             : 
    2283           0 : Sequence< PropertyState > SAL_CALL SwXTextDocument::getPropertyStates( const Sequence< OUString >& rPropertyNames )
    2284             :     throw (UnknownPropertyException, RuntimeException)
    2285             : {
    2286           0 :     const sal_Int32 nCount = rPropertyNames.getLength();
    2287           0 :     const OUString * pNames = rPropertyNames.getConstArray();
    2288           0 :     Sequence < PropertyState > aRet ( nCount );
    2289           0 :     PropertyState *pState = aRet.getArray();
    2290             : 
    2291           0 :     for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++)
    2292           0 :         pState[nIndex] = getPropertyState( pNames[nIndex] );
    2293             : 
    2294           0 :     return aRet;
    2295             : }
    2296             : 
    2297           0 : void SAL_CALL SwXTextDocument::setPropertyToDefault( const OUString& rPropertyName )
    2298             :     throw (UnknownPropertyException, RuntimeException)
    2299             : {
    2300           0 :     SolarMutexGuard aGuard;
    2301           0 :     if(!IsValid())
    2302           0 :         throw RuntimeException();
    2303           0 :     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
    2304           0 :     if(!pEntry)
    2305           0 :         throw UnknownPropertyException();
    2306           0 :     switch(pEntry->nWID)
    2307             :     {
    2308           0 :         case 0:default:break;
    2309           0 :     }
    2310           0 : }
    2311             : 
    2312           0 : Any SAL_CALL SwXTextDocument::getPropertyDefault( const OUString& rPropertyName )
    2313             :     throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
    2314             : {
    2315           0 :     SolarMutexGuard aGuard;
    2316           0 :     if(!IsValid())
    2317           0 :         throw RuntimeException();
    2318           0 :     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
    2319           0 :     if(!pEntry)
    2320           0 :         throw UnknownPropertyException();
    2321           0 :     Any aAny;
    2322           0 :     switch(pEntry->nWID)
    2323             :     {
    2324           0 :         case 0:default:break;
    2325             :     }
    2326           0 :     return aAny;
    2327             : }
    2328             : 
    2329           0 : static OutputDevice * lcl_GetOutputDevice( const SwPrintUIOptions &rPrintUIOptions )
    2330             : {
    2331           0 :     OutputDevice *pOut = 0;
    2332             : 
    2333           0 :     uno::Any aAny( rPrintUIOptions.getValue( "RenderDevice" ));
    2334           0 :     uno::Reference< awt::XDevice >  xRenderDevice;
    2335           0 :     aAny >>= xRenderDevice;
    2336           0 :     if (xRenderDevice.is())
    2337             :     {
    2338           0 :         VCLXDevice*     pDevice = VCLXDevice::GetImplementation( xRenderDevice );
    2339           0 :         pOut = pDevice ? pDevice->GetOutputDevice() : 0;
    2340             :     }
    2341             : 
    2342           0 :     return pOut;
    2343             : }
    2344             : 
    2345           0 : static bool lcl_SeqHasProperty(
    2346             :     const uno::Sequence< beans::PropertyValue >& rOptions,
    2347             :     const sal_Char *pPropName )
    2348             : {
    2349           0 :     bool bRes = false;
    2350           0 :     const sal_Int32 nLen = rOptions.getLength();
    2351           0 :     const beans::PropertyValue *pProps = rOptions.getConstArray();
    2352           0 :     for (sal_Int32 i = 0;  i < nLen && !bRes;  ++i)
    2353             :     {
    2354           0 :         if (pProps[i].Name.equalsAscii( pPropName ))
    2355           0 :             bRes = true;
    2356             :     }
    2357           0 :     return bRes;
    2358             : }
    2359             : 
    2360           0 : SfxViewShell * SwXTextDocument::GetRenderView(
    2361             :     bool &rbIsSwSrcView,
    2362             :     const uno::Sequence< beans::PropertyValue >& rOptions,
    2363             :     bool bIsPDFExport )
    2364             : {
    2365             :     // get view shell to use
    2366           0 :     SfxViewShell *pView = 0;
    2367           0 :     if (bIsPDFExport)
    2368           0 :         pView = GuessViewShell( rbIsSwSrcView );
    2369             :     else
    2370             :     {
    2371           0 :         uno::Any aTmp;
    2372           0 :         const sal_Int32 nLen = rOptions.getLength();
    2373           0 :         const beans::PropertyValue *pProps = rOptions.getConstArray();
    2374           0 :         for (sal_Int32 i = 0; i < nLen; ++i)
    2375             :         {
    2376           0 :             if ( pProps[i].Name == "View" )
    2377             :             {
    2378           0 :                 aTmp = pProps[i].Value;
    2379           0 :                 break;
    2380             :             }
    2381             :         }
    2382             : 
    2383           0 :         uno::Reference< frame::XController > xController;
    2384           0 :         if (aTmp >>= xController)
    2385             :         {
    2386             :             OSL_ENSURE( xController.is(), "controller is empty!" );
    2387           0 :             pView = GuessViewShell( rbIsSwSrcView, xController );
    2388           0 :         }
    2389             :     }
    2390           0 :     return pView;
    2391             : }
    2392             : 
    2393             : /*
    2394             :  *  GetRenderDoc:
    2395             :  *  returns the document to be rendered, usually this will be the 'regular'
    2396             :  *  document but in case of PDF export of (multi-)selection it will
    2397             :  *  be a temporary document that gets created if not already done.
    2398             :  *  The rpView variable will be set (if not already done) to the used
    2399             :  *  SfxViewShell.
    2400             : */
    2401           0 : SwDoc * SwXTextDocument::GetRenderDoc(
    2402             :     SfxViewShell *&rpView,
    2403             :     const uno::Any& rSelection,
    2404             :     bool bIsPDFExport )
    2405             : {
    2406           0 :     SwDoc *pDoc = 0;
    2407             : 
    2408           0 :     uno::Reference< frame::XModel > xModel;
    2409           0 :     rSelection >>= xModel;
    2410           0 :     if (xModel == pDocShell->GetModel())
    2411           0 :         pDoc = pDocShell->GetDoc();
    2412             :     else
    2413             :     {
    2414             :         OSL_ENSURE( !xModel.is(), "unexpected model found" );
    2415             : 
    2416           0 :         if (rSelection.hasValue())     // is anything selected ?
    2417             :         {
    2418             :             // this part should only be called when a temporary document needs to be created,
    2419             :             // for example for PDF export or printing of (multi-)selection only.
    2420             : 
    2421           0 :             bool bIsSwSrcView = false;
    2422           0 :             if (!rpView)
    2423             :             {
    2424             :                 (void) bIsPDFExport;
    2425             :                 // aside from maybe PDF export the view should always have been provided!
    2426             :                 OSL_ENSURE( bIsPDFExport, "view is missing, guessing one..." );
    2427             : 
    2428           0 :                 rpView = GuessViewShell( bIsSwSrcView );
    2429             :             }
    2430             :             OSL_ENSURE( rpView, "ViewShell missing" );
    2431             :             // the view shell should be SwView for documents PDF export.
    2432             :             // for the page preview no selection should be possible
    2433             :             // (the export dialog does not allow for this option)
    2434           0 :             const TypeId aSwViewTypeId = TYPE(SwView);
    2435           0 :             if (rpView  &&  rpView->IsA(aSwViewTypeId))
    2436             :             {
    2437           0 :                 if (!m_pRenderData)
    2438             :                 {
    2439             :                     OSL_FAIL("GetRenderDoc: no renderdata");
    2440           0 :                     return 0;
    2441             :                 }
    2442           0 :                 SwView *const pSwView(static_cast<SwView *>(rpView));
    2443           0 :                 SfxObjectShellLock xDocSh(m_pRenderData->GetTempDocShell());
    2444           0 :                 if (!xDocSh.Is())
    2445             :                 {
    2446           0 :                     xDocSh = pSwView->CreateTmpSelectionDoc();
    2447           0 :                     m_pRenderData->SetTempDocShell(xDocSh);
    2448             :                 }
    2449           0 :                 if (xDocSh.Is())
    2450             :                 {
    2451           0 :                     pDoc = ((SwDocShell*)&xDocSh)->GetDoc();
    2452           0 :                     rpView = pDoc->GetDocShell()->GetView();
    2453           0 :                 }
    2454             :             }
    2455             :             else
    2456             :             {
    2457             :                 OSL_FAIL("unexpected ViewShell" );
    2458             :             }
    2459             :         }
    2460             :     }
    2461           0 :     return pDoc;
    2462             : }
    2463             : 
    2464           0 : static void lcl_SavePrintUIOptionsToDocumentPrintData(
    2465             :     SwDoc &rDoc,
    2466             :     const SwPrintUIOptions &rPrintUIOptions,
    2467             :     bool bIsPDFEXport )
    2468             : {
    2469           0 :     SwPrintData aDocPrintData( rDoc.getPrintData() );
    2470             : 
    2471           0 :     aDocPrintData.SetPrintGraphic( rPrintUIOptions.IsPrintGraphics() );
    2472           0 :     aDocPrintData.SetPrintTable( rPrintUIOptions.IsPrintTables() );
    2473           0 :     aDocPrintData.SetPrintDraw( rPrintUIOptions.IsPrintDrawings() );
    2474           0 :     aDocPrintData.SetPrintControl( rPrintUIOptions.IsPrintFormControls() );
    2475           0 :     aDocPrintData.SetPrintLeftPage( rPrintUIOptions.IsPrintLeftPages() );
    2476           0 :     aDocPrintData.SetPrintRightPage( rPrintUIOptions.IsPrintRightPages() );
    2477           0 :     aDocPrintData.SetPrintReverse( rPrintUIOptions.IsPrintReverse() );
    2478           0 :     aDocPrintData.SetPaperFromSetup( rPrintUIOptions.IsPaperFromSetup() );
    2479           0 :     aDocPrintData.SetPrintEmptyPages( rPrintUIOptions.IsPrintEmptyPages( bIsPDFEXport ) );
    2480           0 :     aDocPrintData.SetPrintPostIts( rPrintUIOptions.GetPrintPostItsType() );
    2481           0 :     aDocPrintData.SetPrintProspect( rPrintUIOptions.IsPrintProspect() );
    2482           0 :     aDocPrintData.SetPrintProspect_RTL( rPrintUIOptions.IsPrintProspectRTL() );
    2483           0 :     aDocPrintData.SetPrintPageBackground( rPrintUIOptions.IsPrintPageBackground() );
    2484           0 :     aDocPrintData.SetPrintBlackFont( rPrintUIOptions.IsPrintWithBlackTextColor() );
    2485             :     // aDocPrintData.SetPrintSingleJobs( b ); handled by File/Print dialog itself
    2486             :     // arDocPrintData.SetFaxName( s ); n/a in File/Print dialog
    2487           0 :     aDocPrintData.SetPrintHiddenText( rPrintUIOptions.IsPrintHiddenText() );
    2488           0 :     aDocPrintData.SetPrintTextPlaceholder( rPrintUIOptions.IsPrintTextPlaceholders() );
    2489             : 
    2490           0 :     rDoc.setPrintData( aDocPrintData );
    2491           0 : }
    2492             : 
    2493           0 : sal_Int32 SAL_CALL SwXTextDocument::getRendererCount(
    2494             :         const uno::Any& rSelection,
    2495             :         const uno::Sequence< beans::PropertyValue >& rxOptions )
    2496             :     throw (IllegalArgumentException, RuntimeException)
    2497             : {
    2498           0 :     SolarMutexGuard aGuard;
    2499           0 :     if(!IsValid())
    2500             :     {
    2501             :         throw DisposedException( OUString(),
    2502           0 :                 static_cast< XTextDocument* >(this) );
    2503             :     }
    2504             : 
    2505           0 :     const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
    2506           0 :     bool bIsSwSrcView = false;
    2507           0 :     SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
    2508             : 
    2509           0 :     if (!bIsSwSrcView && !m_pRenderData)
    2510           0 :         m_pRenderData = new SwRenderData;
    2511           0 :     if (!m_pPrintUIOptions)
    2512           0 :         m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
    2513           0 :     bool bFormat = m_pPrintUIOptions->processPropertiesAndCheckFormat( rxOptions );
    2514             : 
    2515           0 :     SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
    2516             :     OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
    2517           0 :     if (!pDoc || !pView)
    2518           0 :         return 0;
    2519             : 
    2520             :     // save current UI options from the print dialog for the next call to that dialog
    2521           0 :     lcl_SavePrintUIOptionsToDocumentPrintData( *pDoc, *m_pPrintUIOptions, bIsPDFExport );
    2522             : 
    2523           0 :     sal_Int32 nRet = 0;
    2524           0 :     if (bIsSwSrcView)
    2525             :     {
    2526           0 :         SwSrcView *pSwSrcView = dynamic_cast< SwSrcView * >(pView);
    2527           0 :         OutputDevice *pOutDev = lcl_GetOutputDevice( *m_pPrintUIOptions );
    2528           0 :         nRet = pSwSrcView->PrintSource( pOutDev, 1 /* dummy */, true /* get page count only */ );
    2529             :     }
    2530             :     else
    2531             :     {
    2532           0 :         SwDocShell *pRenderDocShell = pDoc->GetDocShell();
    2533             : 
    2534             :         // TODO/mba: we really need a generic way to get the ViewShell!
    2535           0 :         ViewShell* pViewShell = 0;
    2536           0 :         SwView* pSwView = PTR_CAST(SwView, pView);
    2537           0 :         if ( pSwView )
    2538             :         {
    2539           0 :             pViewShell = pSwView->GetWrtShellPtr();
    2540             :         }
    2541             :         else
    2542             :         {
    2543           0 :             if ( bIsPDFExport && bFormat )
    2544             :             {
    2545             :                 //create a hidden view to be able to export as PDF also in print preview
    2546             :                 //pView and pSwView are not changed intentionally!
    2547           0 :                 m_pHiddenViewFrame = SfxViewFrame::LoadHiddenDocument( *pRenderDocShell, 2 );
    2548           0 :                 pViewShell = ((SwView*)m_pHiddenViewFrame->GetViewShell())->GetWrtShellPtr();
    2549             :             }
    2550             :             else
    2551           0 :                 pViewShell = ((SwPagePreView*)pView)->GetViewShell();
    2552             :         }
    2553             : 
    2554           0 :         if (!pViewShell || !pViewShell->GetLayout())
    2555           0 :             return 0;
    2556             : 
    2557           0 :         if (bFormat)
    2558             :         {
    2559             :             // #i38289
    2560           0 :             if( pViewShell->GetViewOptions()->getBrowseMode() )
    2561             :             {
    2562           0 :                 SwViewOption aOpt( *pViewShell->GetViewOptions() );
    2563           0 :                 aOpt.setBrowseMode( false );
    2564           0 :                 pViewShell->ApplyViewOptions( aOpt );
    2565           0 :                 if (pSwView)
    2566             :                 {
    2567           0 :                     pSwView->RecheckBrowseMode();
    2568           0 :                 }
    2569             :             }
    2570             : 
    2571             :             // reformating the document for printing will show the changes in the view
    2572             :             // which is likely to produce many unwanted and not nice to view actions.
    2573             :             // We don't want that! Thus we disable updating of the view.
    2574           0 :             pViewShell->StartAction();
    2575             : 
    2576           0 :             if (pSwView)
    2577             :             {
    2578           0 :                 if (m_pRenderData && m_pRenderData->NeedNewViewOptionAdjust( *pViewShell ) )
    2579           0 :                     m_pRenderData->ViewOptionAdjustStop();
    2580           0 :                 if (m_pRenderData && !m_pRenderData->IsViewOptionAdjust())
    2581             :                 {
    2582             :                     m_pRenderData->ViewOptionAdjustStart(
    2583           0 :                         *pViewShell, *pViewShell->GetViewOptions() );
    2584             :                 }
    2585             :             }
    2586             : 
    2587             :             m_pRenderData->MakeSwPrtOptions( pRenderDocShell,
    2588           0 :                     m_pPrintUIOptions, bIsPDFExport );
    2589             : 
    2590           0 :             if (pSwView)
    2591             :             {
    2592             :                 // PDF export should not make use of the SwPrtOptions
    2593             :                 const SwPrintData *pPrtOptions = (bIsPDFExport)
    2594           0 :                     ? NULL : m_pRenderData->GetSwPrtOptions();
    2595           0 :                 m_pRenderData->ViewOptionAdjust( pPrtOptions );
    2596             :             }
    2597             : 
    2598             :             // since printing now also use the API for PDF export this option
    2599             :             // should be set for printing as well ...
    2600           0 :             pViewShell->SetPDFExportOption( sal_True );
    2601           0 :             bool bOrigStatus = pRenderDocShell->IsEnableSetModified();
    2602             :             // check configuration: shall update of printing information in DocInfo set the document to "modified"?
    2603           0 :             bool bStateChanged = false;
    2604           0 :             if ( bOrigStatus && !SvtPrintWarningOptions().IsModifyDocumentOnPrintingAllowed() )
    2605             :             {
    2606           0 :                 pRenderDocShell->EnableSetModified( sal_False );
    2607           0 :                 bStateChanged = true;
    2608             :             }
    2609             : 
    2610             :             // #122919# Force field update before PDF export
    2611           0 :             pViewShell->ViewShell::UpdateFlds(sal_True);
    2612           0 :             if( bStateChanged )
    2613           0 :                 pRenderDocShell->EnableSetModified( sal_True );
    2614             : 
    2615             :             // there is some redundancy between those two function calls, but right now
    2616             :             // there is no time to sort this out.
    2617             :             //TODO: check what exatly needs to be done and make just one function for that
    2618           0 :             pViewShell->CalcLayout();
    2619           0 :             pViewShell->CalcPagesForPrint( pViewShell->GetPageCount() );
    2620             : 
    2621           0 :             pViewShell->SetPDFExportOption( sal_False );
    2622             : 
    2623             :             // enable view again
    2624           0 :             pViewShell->EndAction();
    2625             :         }
    2626             : 
    2627           0 :         const sal_Int32 nPageCount = pViewShell->GetPageCount();
    2628             : 
    2629             :         //
    2630             :         // get number of pages to be rendered
    2631             :         //
    2632           0 :         const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect", false );
    2633           0 :         if (bPrintProspect)
    2634             :         {
    2635           0 :             pDoc->CalculatePagePairsForProspectPrinting( *pViewShell->GetLayout(), *m_pRenderData, *m_pPrintUIOptions, nPageCount );
    2636           0 :             nRet = m_pRenderData->GetPagePairsForProspectPrinting().size();
    2637             :         }
    2638             :         else
    2639             :         {
    2640           0 :             const sal_Int16 nPostItMode = (sal_Int16) m_pPrintUIOptions->getIntValue( "PrintAnnotationMode", 0 );
    2641           0 :             if (nPostItMode != POSTITS_NONE)
    2642             :             {
    2643           0 :                 OutputDevice *pOutDev = lcl_GetOutputDevice( *m_pPrintUIOptions );
    2644           0 :                 m_pRenderData->CreatePostItData( pDoc, pViewShell->GetViewOptions(), pOutDev );
    2645             :             }
    2646             : 
    2647             :             // get set of valid document pages (according to the current settings)
    2648             :             // and their start frames
    2649           0 :             pDoc->CalculatePagesForPrinting( *pViewShell->GetLayout(), *m_pRenderData, *m_pPrintUIOptions, bIsPDFExport, nPageCount );
    2650             : 
    2651           0 :             if (nPostItMode != POSTITS_NONE)
    2652             :             {
    2653             :                 pDoc->UpdatePagesForPrintingWithPostItData( *m_pRenderData,
    2654           0 :                         *m_pPrintUIOptions, bIsPDFExport, nPageCount );
    2655             :             }
    2656             : 
    2657           0 :             nRet = m_pRenderData->GetPagesToPrint().size();
    2658             :         }
    2659             :     }
    2660             :     OSL_ENSURE( nRet >= 0, "negative number of pages???" );
    2661             : 
    2662           0 :     return nRet;
    2663             : }
    2664             : 
    2665           0 : uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer(
    2666             :         sal_Int32 nRenderer,
    2667             :         const uno::Any& rSelection,
    2668             :         const uno::Sequence< beans::PropertyValue >& rxOptions )
    2669             :     throw (IllegalArgumentException, RuntimeException)
    2670             : {
    2671           0 :     SolarMutexGuard aGuard;
    2672           0 :     if(!IsValid())
    2673             :     {
    2674             :         throw DisposedException( OUString(),
    2675           0 :                 static_cast< XTextDocument* >(this) );
    2676             :     }
    2677             : 
    2678           0 :     const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
    2679           0 :     bool bIsSwSrcView = false;
    2680           0 :     SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
    2681             : 
    2682             :     // m_pRenderData should NOT be created here!
    2683             :     // That should only be done in getRendererCount. If this function is called before
    2684             :     // getRendererCount was called then the caller will probably just retrieve the extra UI options
    2685             :     // and is not interested in getting valid information about the other data that would
    2686             :     // otherwise be provided here!
    2687             : //    if( ! m_pRenderData )
    2688             : //        m_pRenderData = new SwRenderData;
    2689           0 :     if (!m_pPrintUIOptions)
    2690           0 :         m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
    2691           0 :     m_pPrintUIOptions->processProperties( rxOptions );
    2692           0 :     const bool bPrintProspect    = m_pPrintUIOptions->getBoolValue( "PrintProspect", false );
    2693           0 :     const bool bIsSkipEmptyPages = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
    2694           0 :     const bool bPrintPaperFromSetup = m_pPrintUIOptions->getBoolValue( "PrintPaperFromSetup", false );
    2695             : 
    2696           0 :     SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
    2697             :     OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
    2698           0 :     if (!pDoc || !pView)
    2699           0 :         return uno::Sequence< beans::PropertyValue >();
    2700             : 
    2701             :     // due to #110067# (document page count changes sometimes during
    2702             :     // PDF export/printing) we can not check for the upper bound properly.
    2703             :     // Thus instead of throwing the exception we silently return.
    2704           0 :     if (0 > nRenderer)
    2705           0 :         throw IllegalArgumentException();
    2706             : 
    2707             :     // TODO/mba: we really need a generic way to get the ViewShell!
    2708           0 :     ViewShell* pVwSh = 0;
    2709           0 :     SwView* pSwView = PTR_CAST(SwView, pView);
    2710           0 :     if ( pSwView )
    2711           0 :         pVwSh = pSwView->GetWrtShellPtr();
    2712             :     else
    2713           0 :         pVwSh = ((SwPagePreView*)pView)->GetViewShell();
    2714             : 
    2715           0 :     sal_Int32 nMaxRenderer = 0;
    2716           0 :     if (!bIsSwSrcView && m_pRenderData)
    2717             :     {
    2718             :         OSL_ENSURE( m_pRenderData, "m_pRenderData missing!!" );
    2719             :         nMaxRenderer = bPrintProspect?
    2720           0 :             m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
    2721           0 :             m_pRenderData->GetPagesToPrint().size() - 1;
    2722             :     }
    2723             :     // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
    2724             :     // we obmit checking of the upper bound in this case.
    2725           0 :     if (!bIsSwSrcView && m_pRenderData && nRenderer > nMaxRenderer)
    2726           0 :         return uno::Sequence< beans::PropertyValue >();
    2727             : 
    2728           0 :     uno::Sequence< beans::PropertyValue > aRenderer;
    2729           0 :     if (m_pRenderData)
    2730             :     {
    2731             :         // #i114210#
    2732             :         // determine the correct page number from the renderer index
    2733             :         // #i114875
    2734             :         // consider brochure print
    2735             :         const sal_uInt16 nPage = bPrintProspect
    2736             :                              ? nRenderer + 1
    2737           0 :                              : m_pRenderData->GetPagesToPrint()[ nRenderer ];
    2738             : 
    2739             :         // get paper tray to use ...
    2740           0 :         sal_Int32 nPrinterPaperTray = -1;
    2741           0 :         if (! bPrintPaperFromSetup)
    2742             :         {
    2743             :             // ... from individual page style (see the page tab in Format/Page dialog)
    2744           0 :             const std::map< sal_Int32, sal_Int32 > &rPaperTrays = m_pRenderData->GetPrinterPaperTrays();
    2745           0 :             std::map< sal_Int32, sal_Int32 >::const_iterator aIt( rPaperTrays.find( nPage ) );
    2746           0 :             if (aIt != rPaperTrays.end())
    2747           0 :                 nPrinterPaperTray = aIt->second;
    2748             :         }
    2749             : 
    2750           0 :         awt::Size aPageSize;
    2751           0 :         awt::Size aPreferredPageSize;
    2752           0 :         Size aTmpSize;
    2753           0 :         if (bIsSwSrcView || bPrintProspect)
    2754             :         {
    2755             :             // for printing of HTML source code and prospect printing we should use
    2756             :             // the printers paper size since
    2757             :             // a) HTML source view has no page size
    2758             :             // b) prospect printing has a different page size from the documents page
    2759             :             //    since two document pages will get rendered on one printer page
    2760             : 
    2761             :             // since PageIncludesNonprintableArea will be set to true we can return the
    2762             :             // printers paper size here.
    2763             :             // Sometimes 'getRenderer' is only called to get "ExtraPrintUIOptions", in this
    2764             :             // case we won't get an OutputDevice here, but then the caller also has no need
    2765             :             // for the correct PageSisze right now...
    2766           0 :             Printer *pPrinter = dynamic_cast< Printer * >(lcl_GetOutputDevice( *m_pPrintUIOptions ));
    2767           0 :             if (pPrinter)
    2768             :             {
    2769             :                 // HTML source view and prospect adapt to the printer's paper size
    2770           0 :                 aTmpSize = pPrinter->GetPaperSize();
    2771             :                 aTmpSize = pPrinter->LogicToLogic( aTmpSize,
    2772           0 :                             pPrinter->GetMapMode(), MapMode( MAP_100TH_MM ));
    2773           0 :                 aPageSize = awt::Size( aTmpSize.Width(), aTmpSize.Height() );
    2774             :                 #if 0
    2775             :                 // #i115048# it seems users didn't like getting double the formatted page size
    2776             :                 // revert to "old" behavior scaling to the current paper size of the printer
    2777             :                 if (bPrintProspect)
    2778             :                 {
    2779             :                     // we just state what output size we would need
    2780             :                     // which may cause vcl to set that page size on the printer
    2781             :                     // (if available and not overriden by the user)
    2782             :                     aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
    2783             :                     aPreferredPageSize = awt::Size ( TWIP_TO_MM100( 2 * aTmpSize.Width() ),
    2784             :                                                      TWIP_TO_MM100( aTmpSize.Height() ));
    2785             :                 }
    2786             :                 #else
    2787           0 :                 if( bPrintProspect )
    2788             :                 {
    2789             :                     // just switch to an appropriate portrait/landscape format
    2790             :                     // FIXME: brochure printing with landscape pages puts the
    2791             :                     // pages next to each other, so landscape is currently always
    2792             :                     // the better choice
    2793           0 :                     if( aPageSize.Width < aPageSize.Height )
    2794             :                     {
    2795           0 :                         aPreferredPageSize.Width = aPageSize.Height;
    2796           0 :                         aPreferredPageSize.Height = aPageSize.Width;
    2797             :                     }
    2798             :                 }
    2799             :                 #endif
    2800           0 :             }
    2801             :         }
    2802             :         else
    2803             :         {
    2804           0 :             aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
    2805           0 :             aPageSize = awt::Size ( TWIP_TO_MM100( aTmpSize.Width() ),
    2806           0 :                                     TWIP_TO_MM100( aTmpSize.Height() ));
    2807             :         }
    2808             : 
    2809           0 :         sal_Int32 nLen = 2;
    2810           0 :         aRenderer.realloc(2);
    2811           0 :         aRenderer[0].Name  = OUString( "PageSize" );
    2812           0 :         aRenderer[0].Value <<= aPageSize;
    2813           0 :         aRenderer[1].Name  = OUString( "PageIncludesNonprintableArea" );
    2814           0 :         aRenderer[1].Value <<= sal_True;
    2815           0 :         if (aPreferredPageSize.Width && aPreferredPageSize.Height)
    2816             :         {
    2817           0 :             ++nLen;
    2818           0 :             aRenderer.realloc( nLen );
    2819           0 :             aRenderer[ nLen - 1 ].Name  = OUString( "PreferredPageSize" );
    2820           0 :             aRenderer[ nLen - 1 ].Value <<= aPreferredPageSize;
    2821             :         }
    2822           0 :         if (nPrinterPaperTray >= 0)
    2823             :         {
    2824           0 :             ++nLen;
    2825           0 :             aRenderer.realloc( nLen );
    2826           0 :             aRenderer[ nLen - 1 ].Name  = OUString( "PrinterPaperTray" );
    2827           0 :             aRenderer[ nLen - 1 ].Value <<= nPrinterPaperTray;
    2828             :         }
    2829             :     }
    2830             : 
    2831             :     // #i117783#
    2832           0 :     if ( bApplyPagePrintSettingsFromXPagePrintable )
    2833             :     {
    2834             :         const SwPagePreViewPrtData* pPagePrintSettings =
    2835           0 :                                         pDocShell->GetDoc()->GetPreViewPrtData();
    2836           0 :         if ( pPagePrintSettings &&
    2837           0 :              ( pPagePrintSettings->GetRow() > 1 ||
    2838           0 :                pPagePrintSettings->GetCol() > 1 ) )
    2839             :         {
    2840             :             // extend render data by page print settings attributes
    2841           0 :             sal_Int32 nLen = aRenderer.getLength();
    2842           0 :             const sal_Int32 nRenderDataIdxStart = nLen;
    2843           0 :             nLen += 9;
    2844           0 :             aRenderer.realloc( nLen );
    2845             :             // put page print settings attribute into render data
    2846           0 :             const sal_Int32 nRow = pPagePrintSettings->GetRow();
    2847           0 :             aRenderer[ nRenderDataIdxStart + 0 ].Name  = OUString( "NUpRows" );
    2848           0 :             aRenderer[ nRenderDataIdxStart + 0 ].Value <<= ( nRow > 1 ? nRow : 1 );
    2849           0 :             const sal_Int32 nCol = pPagePrintSettings->GetCol();
    2850           0 :             aRenderer[ nRenderDataIdxStart + 1 ].Name  = OUString( "NUpColumns" );
    2851           0 :             aRenderer[ nRenderDataIdxStart + 1 ].Value <<= ( nCol > 1 ? nCol : 1 );
    2852           0 :             aRenderer[ nRenderDataIdxStart + 2 ].Name  = OUString( "NUpPageMarginLeft" );
    2853           0 :             aRenderer[ nRenderDataIdxStart + 2 ].Value <<= pPagePrintSettings->GetLeftSpace();
    2854           0 :             aRenderer[ nRenderDataIdxStart + 3 ].Name  = OUString( "NUpPageMarginRight" );
    2855           0 :             aRenderer[ nRenderDataIdxStart + 3 ].Value <<= pPagePrintSettings->GetRightSpace();
    2856           0 :             aRenderer[ nRenderDataIdxStart + 4 ].Name  = OUString( "NUpPageMarginTop" );
    2857           0 :             aRenderer[ nRenderDataIdxStart + 4 ].Value <<= pPagePrintSettings->GetTopSpace();
    2858           0 :             aRenderer[ nRenderDataIdxStart + 5 ].Name  = OUString( "NUpPageMarginBottom" );
    2859           0 :             aRenderer[ nRenderDataIdxStart + 5 ].Value <<= pPagePrintSettings->GetBottomSpace();
    2860           0 :             aRenderer[ nRenderDataIdxStart + 6 ].Name  = OUString( "NUpHorizontalSpacing" );
    2861           0 :             aRenderer[ nRenderDataIdxStart + 6 ].Value <<= pPagePrintSettings->GetHorzSpace();
    2862           0 :             aRenderer[ nRenderDataIdxStart + 7 ].Name  = OUString( "NUpVerticalSpacing" );
    2863           0 :             aRenderer[ nRenderDataIdxStart + 7 ].Value <<= pPagePrintSettings->GetVertSpace();
    2864             :             {
    2865           0 :                 Printer* pPrinter = pDocShell->GetDoc()->getPrinter( false );
    2866           0 :                 if ( pPrinter )
    2867             :                 {
    2868           0 :                     awt::Size aNewPageSize;
    2869           0 :                     const Size aPageSize = pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) );
    2870           0 :                     aNewPageSize = awt::Size( aPageSize.Width(), aPageSize.Height() );
    2871           0 :                     if ( ( pPagePrintSettings->GetLandscape() &&
    2872           0 :                            aPageSize.Width() < aPageSize.Height() ) ||
    2873           0 :                          ( !pPagePrintSettings->GetLandscape() &&
    2874           0 :                            aPageSize.Width() > aPageSize.Height() ) )
    2875             :                     {
    2876           0 :                         aNewPageSize = awt::Size( aPageSize.Height(), aPageSize.Width() );
    2877             :                     }
    2878           0 :                     aRenderer[ nRenderDataIdxStart + 8 ].Name  = OUString( "NUpPaperSize" );
    2879           0 :                     aRenderer[ nRenderDataIdxStart + 8 ].Value <<= aNewPageSize;
    2880             :                 }
    2881             :             }
    2882             :         }
    2883             : 
    2884           0 :         bApplyPagePrintSettingsFromXPagePrintable = sal_False;
    2885             :     }
    2886             : 
    2887           0 :     m_pPrintUIOptions->appendPrintUIOptions( aRenderer );
    2888             : 
    2889           0 :     return aRenderer;
    2890             : }
    2891             : 
    2892           0 : SfxViewShell * SwXTextDocument::GuessViewShell(
    2893             :     /* out */ bool &rbIsSwSrcView,
    2894             :     const uno::Reference< css::frame::XController > xController )
    2895             : {
    2896             :     // #130810# SfxViewShell::Current() / SfxViewShell::GetObjectShell()
    2897             :     // must not be used (see comment from MBA)
    2898             :     //
    2899           0 :     SfxViewShell    *pView = 0;
    2900           0 :     SwView          *pSwView = 0;
    2901           0 :     SwPagePreView   *pSwPagePreView = 0;
    2902           0 :     SwSrcView       *pSwSrcView = 0;
    2903           0 :     SfxViewFrame    *pFrame = SfxViewFrame::GetFirst( pDocShell, sal_False );
    2904             : 
    2905             :     // look for the view shell with the same controller in use,
    2906             :     // otherwise look for a suitable view, preferably a SwView,
    2907             :     // if that one is not found use a SwPagePreView if found.
    2908           0 :     while (pFrame)
    2909             :     {
    2910           0 :         pView = pFrame->GetViewShell();
    2911           0 :         pSwView = dynamic_cast< SwView * >(pView);
    2912           0 :         pSwSrcView = dynamic_cast< SwSrcView * >(pView);
    2913           0 :         if (!pSwPagePreView)
    2914           0 :             pSwPagePreView = dynamic_cast< SwPagePreView * >(pView);
    2915           0 :         if (xController.is())
    2916             :         {
    2917           0 :             if (pView && pView->GetController() == xController)
    2918           0 :                 break;
    2919             :         }
    2920           0 :         else if (pSwView || pSwSrcView)
    2921             :             break;
    2922           0 :         pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell,  sal_False );
    2923             :     }
    2924             : 
    2925             :     OSL_ENSURE( pSwView || pSwPagePreView || pSwSrcView, "failed to get view shell" );
    2926           0 :     if (pView)
    2927           0 :         rbIsSwSrcView = pSwSrcView != 0;
    2928           0 :     return pView;
    2929             : }
    2930             : 
    2931           0 : void SAL_CALL SwXTextDocument::render(
    2932             :         sal_Int32 nRenderer,
    2933             :         const uno::Any& rSelection,
    2934             :         const uno::Sequence< beans::PropertyValue >& rxOptions )
    2935             :     throw (IllegalArgumentException, RuntimeException)
    2936             : {
    2937           0 :     SolarMutexGuard aGuard;
    2938           0 :     if(!IsValid())
    2939             :     {
    2940             :         throw DisposedException( OUString(),
    2941           0 :                 static_cast< XTextDocument* >(this) );
    2942             :     }
    2943             : 
    2944             :     // due to #110067# (document page count changes sometimes during
    2945             :     // PDF export/printing) we can not check for the upper bound properly.
    2946             :     // Thus instead of throwing the exception we silently return.
    2947           0 :     if (0 > nRenderer)
    2948           0 :         throw IllegalArgumentException();
    2949             : 
    2950           0 :     const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
    2951           0 :     bool bIsSwSrcView = false;
    2952           0 :     SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
    2953             : 
    2954             :     OSL_ENSURE( m_pRenderData, "data should have been created already in getRendererCount..." );
    2955             :     OSL_ENSURE( m_pPrintUIOptions, "data should have been created already in getRendererCount..." );
    2956           0 :     if (!bIsSwSrcView && !m_pRenderData)
    2957           0 :         m_pRenderData = new SwRenderData;
    2958           0 :     if (!m_pPrintUIOptions)
    2959           0 :         m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
    2960           0 :     m_pPrintUIOptions->processProperties( rxOptions );
    2961           0 :     const bool bPrintProspect   = m_pPrintUIOptions->getBoolValue( "PrintProspect", false );
    2962           0 :     const bool bLastPage        = m_pPrintUIOptions->getBoolValue( "IsLastPage", sal_False );
    2963             : 
    2964           0 :     SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
    2965             :     OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
    2966           0 :     if (pDoc && pView)
    2967             :     {
    2968           0 :         sal_Int32 nMaxRenderer = 0;
    2969           0 :         if (!bIsSwSrcView)
    2970             :         {
    2971             :             OSL_ENSURE( m_pRenderData, "m_pRenderData missing!!" );
    2972             :             nMaxRenderer = bPrintProspect?
    2973           0 :                 m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
    2974           0 :                 m_pRenderData->GetPagesToPrint().size() - 1;
    2975             :         }
    2976             :         // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
    2977             :         // we obmit checking of the upper bound in this case.
    2978           0 :         if (bIsSwSrcView || nRenderer <= nMaxRenderer)
    2979             :         {
    2980           0 :             if (bIsSwSrcView)
    2981             :             {
    2982           0 :                 SwSrcView *pSwSrcView = dynamic_cast< SwSrcView * >(pView);
    2983           0 :                 OutputDevice *pOutDev = lcl_GetOutputDevice( *m_pPrintUIOptions );
    2984           0 :                 pSwSrcView->PrintSource( pOutDev, nRenderer + 1, false );
    2985             :             }
    2986             :             else
    2987             :             {
    2988             :                 // the view shell should be SwView for documents PDF export
    2989             :                 // or SwPagePreView for PDF export of the page preview
    2990             :                 //!! (check for SwView first as in GuessViewShell) !!
    2991             :                 OSL_ENSURE( pView, "!! view missing !!" );
    2992           0 :                 const TypeId aSwViewTypeId = TYPE(SwView);
    2993           0 :                 ViewShell* pVwSh = 0;
    2994           0 :                 if (pView)
    2995             :                 {
    2996             :                     // TODO/mba: we really need a generic way to get the ViewShell!
    2997           0 :                     SwView* pSwView = PTR_CAST(SwView, pView);
    2998           0 :                     if ( pSwView )
    2999           0 :                         pVwSh = pSwView->GetWrtShellPtr();
    3000             :                     else
    3001           0 :                         pVwSh = ((SwPagePreView*)pView)->GetViewShell();
    3002             :                 }
    3003             : 
    3004             :                 // get output device to use
    3005           0 :                 OutputDevice * pOut = lcl_GetOutputDevice( *m_pPrintUIOptions );
    3006             : 
    3007           0 :                 if(pVwSh && pOut && m_pRenderData->HasSwPrtOptions())
    3008             :                 {
    3009           0 :                     const OUString aPageRange  = m_pPrintUIOptions->getStringValue( "PageRange", OUString() );
    3010           0 :                     const bool bFirstPage           = m_pPrintUIOptions->getBoolValue( "IsFirstPage", sal_False );
    3011           0 :                     bool bIsSkipEmptyPages          = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
    3012             : 
    3013             :                     OSL_ENSURE(( pView->IsA(aSwViewTypeId) &&  m_pRenderData->IsViewOptionAdjust())
    3014             :                             || (!pView->IsA(aSwViewTypeId) && !m_pRenderData->IsViewOptionAdjust()),
    3015             :                             "SwView / SwViewOptionAdjust_Impl availability mismatch" );
    3016             : 
    3017             :                     // since printing now also use the API for PDF export this option
    3018             :                     // should be set for printing as well ...
    3019           0 :                     pVwSh->SetPDFExportOption( sal_True );
    3020             : 
    3021             :                     // #i12836# enhanced pdf export
    3022             :                     //
    3023             :                     // First, we have to export hyperlinks, notes, and outline to pdf.
    3024             :                     // During this process, additional information required for tagging
    3025             :                     // the pdf file are collected, which are evaulated during painting.
    3026             :                     //
    3027           0 :                     SwWrtShell* pWrtShell = pView->IsA(aSwViewTypeId) ?
    3028           0 :                                             ((SwView*)pView)->GetWrtShellPtr() :
    3029           0 :                                             0;
    3030             : 
    3031           0 :                     if (bIsPDFExport && bFirstPage && pWrtShell)
    3032             :                     {
    3033           0 :                         SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, sal_False );
    3034             :                     }
    3035             : 
    3036             :                     SwPrintData const& rSwPrtOptions =
    3037           0 :                         *m_pRenderData->GetSwPrtOptions();
    3038           0 :                     if (bPrintProspect)
    3039           0 :                         pVwSh->PrintProspect( pOut, rSwPrtOptions, nRenderer );
    3040             :                     else    // normal printing and PDF export
    3041           0 :                         pVwSh->PrintOrPDFExport( pOut, rSwPrtOptions, nRenderer );
    3042             : 
    3043             :                     // #i35176#
    3044             :                     //
    3045             :                     // After printing the last page, we take care for the links coming
    3046             :                     // from the EditEngine. The links are generated during the painting
    3047             :                     // process, but the destinations are still missing.
    3048             :                     //
    3049           0 :                     if (bIsPDFExport && bLastPage && pWrtShell)
    3050             :                     {
    3051           0 :                         SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages,  sal_True );
    3052             :                     }
    3053             : 
    3054           0 :                     pVwSh->SetPDFExportOption( sal_False );
    3055             : 
    3056             :                     // last page to be rendered? (not necessarily the last page of the document)
    3057             :                     // -> do clean-up of data
    3058           0 :                     if (bLastPage)
    3059             :                     {
    3060             :                         // #i96167# haggai: delete ViewOptionsAdjust here because it makes use
    3061             :                         // of the shell, which might get destroyed in lcl_DisposeView!
    3062           0 :                         if (m_pRenderData && m_pRenderData->IsViewOptionAdjust())
    3063           0 :                             m_pRenderData->ViewOptionAdjustStop();
    3064             : 
    3065           0 :                         if (m_pRenderData && m_pRenderData->HasPostItData())
    3066           0 :                             m_pRenderData->DeletePostItData();
    3067           0 :                         if (m_pHiddenViewFrame)
    3068             :                         {
    3069           0 :                             lcl_DisposeView( m_pHiddenViewFrame, pDocShell );
    3070           0 :                             m_pHiddenViewFrame = 0;
    3071             : 
    3072             :                             // prevent crash described in #i108805
    3073           0 :                             SwDocShell *pRenderDocShell = pDoc->GetDocShell();
    3074           0 :                             SfxItemSet *pSet = pRenderDocShell->GetMedium()->GetItemSet();
    3075           0 :                             pSet->Put( SfxBoolItem( SID_HIDDEN, sal_False ) );
    3076             : 
    3077             :                         }
    3078           0 :                     }
    3079             :                 }
    3080             :             }
    3081             :         }
    3082             :     }
    3083           0 :     if( bLastPage )
    3084             :     {
    3085           0 :         delete m_pRenderData;       m_pRenderData     = NULL;
    3086           0 :         delete m_pPrintUIOptions;   m_pPrintUIOptions = NULL;
    3087           0 :     }
    3088           0 : }
    3089             : 
    3090             : // xforms::XFormsSupplier
    3091          31 : Reference<XNameContainer> SAL_CALL SwXTextDocument::getXForms()
    3092             :     throw( RuntimeException )
    3093             : {
    3094          31 :     SolarMutexGuard aGuard;
    3095          31 :     if ( !pDocShell )
    3096           0 :         throw DisposedException( OUString(), static_cast< XTextDocument* >( this ) );
    3097          31 :     SwDoc* pDoc = pDocShell->GetDoc();
    3098          31 :     return pDoc->getXForms();
    3099             : }
    3100             : 
    3101           0 : uno::Reference< text::XFlatParagraphIterator > SAL_CALL SwXTextDocument::getFlatParagraphIterator(::sal_Int32 nTextMarkupType, sal_Bool bAutomatic)
    3102             :     throw ( uno::RuntimeException )
    3103             : {
    3104           0 :     SolarMutexGuard aGuard;
    3105           0 :     if (!IsValid())
    3106             :     {
    3107             :         throw DisposedException("SwXTextDocument not valid",
    3108           0 :                 static_cast<XTextDocument*>(this));
    3109             :     }
    3110             : 
    3111             :     return SwUnoCursorHelper::CreateFlatParagraphIterator(
    3112           0 :             *pDocShell->GetDoc(), nTextMarkupType, bAutomatic);
    3113             : }
    3114             : 
    3115           0 : uno::Reference< util::XCloneable > SwXTextDocument::createClone(  ) throw (uno::RuntimeException)
    3116             : {
    3117           0 :     SolarMutexGuard aGuard;
    3118           0 :     if(!IsValid())
    3119           0 :         throw RuntimeException();
    3120             : 
    3121             :     // create a new document - hidden - copy the storage and return it
    3122             :     // SfxObjectShellRef is used here, since the model should control object lifetime after creation
    3123             :     // and thus SfxObjectShellLock is not allowed here
    3124             :     // the model holds reference to the shell, so the shell will not destructed at the end of method
    3125           0 :     SfxObjectShellRef pShell = pDocShell->GetDoc()->CreateCopy(false);
    3126           0 :     uno::Reference< frame::XModel > xNewModel = pShell->GetModel();
    3127           0 :     uno::Reference< embed::XStorage > xNewStorage = ::comphelper::OStorageHelper::GetTemporaryStorage( );
    3128           0 :     uno::Sequence< beans::PropertyValue > aTempMediaDescriptor;
    3129           0 :     storeToStorage( xNewStorage, aTempMediaDescriptor );
    3130           0 :     uno::Reference< document::XStorageBasedDocument > xStorageDoc( xNewModel, uno::UNO_QUERY );
    3131           0 :     xStorageDoc->loadFromStorage( xNewStorage, aTempMediaDescriptor );
    3132           0 :     return uno::Reference< util::XCloneable >( xNewModel, UNO_QUERY );
    3133             : }
    3134             : 
    3135         902 : void * SAL_CALL SwXTextDocument::operator new( size_t t) throw()
    3136             : {
    3137         902 :     return SwXTextDocumentBaseClass::operator new(t);
    3138             : }
    3139             : 
    3140         655 : void SAL_CALL SwXTextDocument::operator delete( void * p) throw()
    3141             : {
    3142         655 :     SwXTextDocumentBaseClass::operator delete(p);
    3143         655 : }
    3144             : 
    3145             : /**
    3146             :  * retrieve languages already used in current document
    3147             :  */
    3148           0 : uno::Sequence< lang::Locale > SAL_CALL SwXTextDocument::getDocumentLanguages(
    3149             :         ::sal_Int16 nScriptTypes,
    3150             :         ::sal_Int16 nMaxCount )
    3151             :     throw (lang::IllegalArgumentException, uno::RuntimeException)
    3152             : {
    3153           0 :     SolarMutexGuard aGuard;
    3154             : 
    3155             : 
    3156             :     // possible canonical values for nScriptTypes
    3157             :     // any bit wise combination is allowed
    3158           0 :     const sal_Int16 nLatin   = 0x001;
    3159           0 :     const sal_Int16 nAsian   = 0x002;
    3160           0 :     const sal_Int16 nComplex = 0x004;
    3161             : 
    3162             :     // script types for which to get the languages
    3163           0 :     const bool bLatin   = 0 != (nScriptTypes & nLatin);
    3164           0 :     const bool bAsian   = 0 != (nScriptTypes & nAsian);
    3165           0 :     const bool bComplex = 0 != (nScriptTypes & nComplex);
    3166             : 
    3167           0 :     if (nScriptTypes < nLatin || nScriptTypes > (nLatin | nAsian | nComplex))
    3168           0 :         throw IllegalArgumentException("nScriptTypes ranges from 1 to 7!", Reference< XInterface >(), 1);
    3169           0 :     if (!pDocShell)
    3170           0 :         throw DisposedException();
    3171           0 :     SwDoc* pDoc = pDocShell->GetDoc();
    3172             : 
    3173             :     // avoid duplicate values
    3174           0 :     std::set< LanguageType > aAllLangs;
    3175             : 
    3176             :     //USER STYLES
    3177             : 
    3178           0 :     const SwCharFmts *pFmts = pDoc->GetCharFmts();
    3179           0 :     for(sal_uInt16 i = 0; i < pFmts->size(); ++i)
    3180             :     {
    3181           0 :         const SwAttrSet &rAttrSet = (*pFmts)[i]->GetAttrSet();
    3182           0 :         LanguageType nLang = LANGUAGE_DONTKNOW;
    3183           0 :         if (bLatin)
    3184             :         {
    3185           0 :             nLang = rAttrSet.GetLanguage( sal_False ).GetLanguage();
    3186           0 :             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
    3187           0 :                 aAllLangs.insert( nLang );
    3188             :         }
    3189           0 :         if (bAsian)
    3190             :         {
    3191           0 :             nLang = rAttrSet.GetCJKLanguage( sal_False ).GetLanguage();
    3192           0 :             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
    3193           0 :                 aAllLangs.insert( nLang );
    3194             :         }
    3195           0 :         if (bComplex)
    3196             :         {
    3197           0 :             nLang = rAttrSet.GetCTLLanguage( sal_False ).GetLanguage();
    3198           0 :             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
    3199           0 :                 aAllLangs.insert( nLang );
    3200             :         }
    3201             :     }
    3202             : 
    3203           0 :     const SwTxtFmtColls *pColls = pDoc->GetTxtFmtColls();
    3204           0 :     for (sal_uInt16 i = 0; i < pColls->size(); ++i)
    3205             :     {
    3206           0 :         const SwAttrSet &rAttrSet = (*pColls)[i]->GetAttrSet();
    3207           0 :         LanguageType nLang = LANGUAGE_DONTKNOW;
    3208           0 :         if (bLatin)
    3209             :         {
    3210           0 :             nLang = rAttrSet.GetLanguage( sal_False ).GetLanguage();
    3211           0 :             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
    3212           0 :                 aAllLangs.insert( nLang );
    3213             :         }
    3214           0 :         if (bAsian)
    3215             :         {
    3216           0 :             nLang = rAttrSet.GetCJKLanguage( sal_False ).GetLanguage();
    3217           0 :             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
    3218           0 :                 aAllLangs.insert( nLang );
    3219             :         }
    3220           0 :         if (bComplex)
    3221             :         {
    3222           0 :             nLang = rAttrSet.GetCTLLanguage( sal_False ).GetLanguage();
    3223           0 :             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
    3224           0 :                 aAllLangs.insert( nLang );
    3225             :         }
    3226             :     }
    3227             : 
    3228             :     //AUTO STYLES
    3229             :     const IStyleAccess::SwAutoStyleFamily aFam[2] =
    3230             :     {
    3231             :       IStyleAccess::AUTO_STYLE_CHAR,
    3232             :       IStyleAccess::AUTO_STYLE_PARA
    3233           0 :     };
    3234           0 :     for (sal_uInt16 i = 0; i < 2; ++i)
    3235             :     {
    3236           0 :         std::vector< SfxItemSet_Pointer_t > rStyles;
    3237           0 :         pDoc->GetIStyleAccess().getAllStyles(rStyles, aFam[i]);
    3238           0 :         while (!rStyles.empty())
    3239             :         {
    3240           0 :             SfxItemSet_Pointer_t pStyle = rStyles.back();
    3241           0 :             rStyles.pop_back();
    3242           0 :             const SfxItemSet *pSet = dynamic_cast< const SfxItemSet * >(pStyle.get());
    3243             : 
    3244           0 :             LanguageType nLang = LANGUAGE_DONTKNOW;
    3245           0 :             if (bLatin)
    3246             :             {
    3247           0 :                 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_LANGUAGE, sal_False )).GetLanguage();
    3248           0 :                 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
    3249           0 :                     aAllLangs.insert( nLang );
    3250             :             }
    3251           0 :             if (bAsian)
    3252             :             {
    3253           0 :                 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_CJK_LANGUAGE, sal_False )).GetLanguage();
    3254           0 :                 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
    3255           0 :                     aAllLangs.insert( nLang );
    3256             :             }
    3257           0 :             if (bComplex)
    3258             :             {
    3259           0 :                 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_CTL_LANGUAGE, sal_False )).GetLanguage();
    3260           0 :                 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
    3261           0 :                     aAllLangs.insert( nLang );
    3262             :             }
    3263           0 :         }
    3264           0 :     }
    3265             : 
    3266             :     //TODO/mba: it's a strange concept that a view is needed to retrieve core data
    3267           0 :     SwWrtShell *pWrtSh = pDocShell->GetWrtShell();
    3268           0 :     SdrView *pSdrView = pWrtSh->GetDrawView();
    3269             : 
    3270           0 :     if( pSdrView )
    3271             :     {
    3272           0 :         SdrOutliner* pOutliner = pSdrView->GetTextEditOutliner();
    3273           0 :         if(pOutliner)
    3274             :         {
    3275           0 :             EditEngine& rEditEng = (EditEngine&)pOutliner->GetEditEngine();
    3276           0 :             sal_Int32 nParCount = pOutliner->GetParagraphCount();
    3277           0 :             for (sal_Int32 nPar=0; nPar<nParCount; nPar++)
    3278             :             {
    3279             :                 //every paragraph
    3280           0 :                 std::vector<sal_uInt16> aPortions;
    3281           0 :                 rEditEng.GetPortions( nPar, aPortions );
    3282             : 
    3283           0 :                 for ( size_t nPos = aPortions.size(); nPos; )
    3284             :                 {
    3285             :                     //every position
    3286           0 :                     --nPos;
    3287           0 :                     sal_uInt16 nEnd = aPortions[ nPos ];
    3288           0 :                     sal_uInt16 nStart = nPos ? aPortions[ nPos - 1 ] : 0;
    3289           0 :                     ESelection aSelection( nPar, nStart, nPar, nEnd );
    3290           0 :                     SfxItemSet aAttr = rEditEng.GetAttribs( aSelection );
    3291             : 
    3292           0 :                     LanguageType nLang = LANGUAGE_DONTKNOW;
    3293           0 :                     if (bLatin)
    3294             :                     {
    3295           0 :                         nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE, sal_False )).GetLanguage();
    3296           0 :                         if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
    3297           0 :                             aAllLangs.insert( nLang );
    3298             :                     }
    3299           0 :                     if (bAsian)
    3300             :                     {
    3301           0 :                         nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE_CJK, sal_False )).GetLanguage();
    3302           0 :                         if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
    3303           0 :                             aAllLangs.insert( nLang );
    3304             :                     }
    3305           0 :                     if (bComplex)
    3306             :                     {
    3307           0 :                         nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE_CTL, sal_False )).GetLanguage();
    3308           0 :                         if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
    3309           0 :                             aAllLangs.insert( nLang );
    3310             :                     }
    3311           0 :                 }
    3312           0 :             }
    3313             :         }
    3314             :     }
    3315             :     // less than nMaxCount languages
    3316           0 :     if (nMaxCount > static_cast< sal_Int16 >( aAllLangs.size() ))
    3317           0 :         nMaxCount = static_cast< sal_Int16 >( aAllLangs.size() );
    3318             : 
    3319             :     // build return value
    3320           0 :     uno::Sequence< lang::Locale > aLanguages( nMaxCount );
    3321           0 :     lang::Locale* pLanguage = aLanguages.getArray();
    3322           0 :     if (nMaxCount > 0)
    3323             :     {
    3324           0 :         sal_Int32 nCount = 0;
    3325           0 :         const SvtLanguageTable aLangTab;
    3326           0 :         for (std::set< LanguageType >::const_iterator it = aAllLangs.begin(); it != aAllLangs.end(); ++it)
    3327             :         {
    3328           0 :             if (nCount >= nMaxCount)
    3329           0 :                 break;
    3330           0 :             if (LANGUAGE_NONE != *it)
    3331             :             {
    3332           0 :                 pLanguage[nCount] = LanguageTag( *it ).getLocale();
    3333           0 :                 pLanguage[nCount].Language = aLangTab.GetString( *it );
    3334           0 :                 nCount += 1;
    3335             :             }
    3336           0 :         }
    3337             :     }
    3338             : 
    3339           0 :     return aLanguages;
    3340             : }
    3341             : 
    3342           0 : SwXLinkTargetSupplier::SwXLinkTargetSupplier(SwXTextDocument& rxDoc) :
    3343           0 :     pxDoc(&rxDoc)
    3344             : {
    3345           0 :     sTables     = String(SW_RES(STR_CONTENT_TYPE_TABLE));
    3346           0 :     sFrames     = String(SW_RES(STR_CONTENT_TYPE_FRAME));
    3347           0 :     sGraphics   = String(SW_RES(STR_CONTENT_TYPE_GRAPHIC));
    3348           0 :     sOLEs       = String(SW_RES(STR_CONTENT_TYPE_OLE));
    3349           0 :     sSections   = String(SW_RES(STR_CONTENT_TYPE_REGION));
    3350           0 :     sOutlines   = String(SW_RES(STR_CONTENT_TYPE_OUTLINE));
    3351           0 :     sBookmarks  = String(SW_RES(STR_CONTENT_TYPE_BOOKMARK));
    3352           0 : }
    3353             : 
    3354           0 : SwXLinkTargetSupplier::~SwXLinkTargetSupplier()
    3355             : {
    3356           0 : }
    3357             : 
    3358           0 : Any SwXLinkTargetSupplier::getByName(const OUString& rName)
    3359             :     throw( NoSuchElementException, WrappedTargetException, RuntimeException )
    3360             : {
    3361           0 :     Any aRet;
    3362           0 :     if(!pxDoc)
    3363           0 :         throw RuntimeException();
    3364           0 :     String sToCompare(rName);
    3365           0 :     String sSuffix = OUString('|');
    3366           0 :     if(sToCompare == sTables)
    3367             :     {
    3368           0 :         sSuffix += OUString::createFromAscii(pMarkToTable);
    3369             : 
    3370             :         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
    3371           0 :                                         pxDoc->getTextTables(), sToCompare, sSuffix );
    3372           0 :         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
    3373           0 :         aRet.setValue(&xRet, ::getCppuType((Reference<XPropertySet>*)0));
    3374             :     }
    3375           0 :     else if(sToCompare == sFrames)
    3376             :     {
    3377           0 :         sSuffix += OUString::createFromAscii(pMarkToFrame);
    3378             :         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
    3379           0 :                                         pxDoc->getTextFrames(), sToCompare, sSuffix );
    3380           0 :         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
    3381           0 :         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
    3382             :     }
    3383           0 :     else if(sToCompare == sSections)
    3384             :     {
    3385           0 :         sSuffix += OUString::createFromAscii(pMarkToRegion);
    3386             :         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
    3387           0 :                                         pxDoc->getTextSections(), sToCompare, sSuffix );
    3388           0 :         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
    3389           0 :         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
    3390             :     }
    3391           0 :     else if(sToCompare == sGraphics)
    3392             :     {
    3393           0 :         sSuffix += OUString::createFromAscii(pMarkToGraphic);
    3394             :         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
    3395           0 :                                         pxDoc->getGraphicObjects(), sToCompare, sSuffix );
    3396           0 :         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
    3397           0 :         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
    3398             :     }
    3399           0 :     else if(sToCompare == sOLEs)
    3400             :     {
    3401           0 :         sSuffix += OUString::createFromAscii(pMarkToOLE);
    3402             :         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
    3403           0 :                                         pxDoc->getEmbeddedObjects(), sToCompare, sSuffix );
    3404           0 :         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
    3405           0 :         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
    3406             :     }
    3407           0 :     else if(sToCompare == sOutlines)
    3408             :     {
    3409           0 :         sSuffix += OUString::createFromAscii(pMarkToOutline);
    3410             :         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
    3411           0 :                                         *pxDoc, sToCompare, sSuffix );
    3412           0 :         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
    3413           0 :         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
    3414             :     }
    3415           0 :     else if(sToCompare == sBookmarks)
    3416             :     {
    3417           0 :         sSuffix.Erase();
    3418             :         Reference< XNameAccess >  xBkms = new SwXLinkNameAccessWrapper(
    3419           0 :                                         pxDoc->getBookmarks(), sToCompare, sSuffix );
    3420           0 :         Reference< XPropertySet >  xRet(xBkms, UNO_QUERY);
    3421           0 :         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
    3422             :     }
    3423             :     else
    3424           0 :         throw NoSuchElementException();
    3425           0 :     return aRet;
    3426             : }
    3427             : 
    3428           0 : Sequence< OUString > SwXLinkTargetSupplier::getElementNames(void)
    3429             :                                         throw( RuntimeException )
    3430             : {
    3431           0 :     Sequence< OUString > aRet(7);
    3432           0 :     OUString* pNames = aRet.getArray();
    3433           0 :     pNames[0] = sTables;
    3434           0 :     pNames[1] = sFrames  ;
    3435           0 :     pNames[2] = sGraphics;
    3436           0 :     pNames[3] = sOLEs   ;
    3437           0 :     pNames[4] = sSections;
    3438           0 :     pNames[5] = sOutlines;
    3439           0 :     pNames[6] = sBookmarks;
    3440           0 :     return aRet;
    3441             : }
    3442             : 
    3443           0 : sal_Bool SwXLinkTargetSupplier::hasByName(const OUString& rName)
    3444             :                                     throw( RuntimeException )
    3445             : {
    3446           0 :     String sToCompare(rName);
    3447           0 :     if( sToCompare == sTables  ||
    3448           0 :         sToCompare == sFrames  ||
    3449           0 :         sToCompare == sGraphics||
    3450           0 :         sToCompare == sOLEs   ||
    3451           0 :         sToCompare == sSections ||
    3452           0 :         sToCompare == sOutlines ||
    3453           0 :         sToCompare == sBookmarks    )
    3454           0 :         return sal_True;
    3455           0 :     return sal_False;
    3456             : }
    3457             : 
    3458           0 : uno::Type  SwXLinkTargetSupplier::getElementType(void)
    3459             :                                     throw( RuntimeException )
    3460             : {
    3461           0 :     return ::getCppuType((Reference< XPropertySet>*)0);
    3462             : 
    3463             : }
    3464             : 
    3465           0 : sal_Bool SwXLinkTargetSupplier::hasElements(void) throw( RuntimeException )
    3466             : {
    3467           0 :     return 0 != pxDoc;
    3468             : }
    3469             : 
    3470           0 : OUString SwXLinkTargetSupplier::getImplementationName(void) throw( RuntimeException )
    3471             : {
    3472           0 :     return OUString("SwXLinkTargetSupplier");
    3473             : }
    3474             : 
    3475           0 : sal_Bool SwXLinkTargetSupplier::supportsService(const OUString& rServiceName)
    3476             :                                                 throw( RuntimeException )
    3477             : {
    3478           0 :     return (rServiceName == "com.sun.star.document.LinkTargets");
    3479             : }
    3480             : 
    3481           0 : Sequence< OUString > SwXLinkTargetSupplier::getSupportedServiceNames(void)
    3482             :                                                 throw( RuntimeException )
    3483             : {
    3484           0 :     Sequence< OUString > aRet(1);
    3485           0 :     OUString* pNames = aRet.getArray();
    3486           0 :     pNames[0] = "com.sun.star.document.LinkTargets";
    3487           0 :     return aRet;
    3488             : }
    3489             : 
    3490           0 : SwXLinkNameAccessWrapper::SwXLinkNameAccessWrapper(
    3491             :             Reference< XNameAccess >  xAccess, const String& rLinkDisplayName, String sSuffix ) :
    3492             :     xRealAccess(xAccess),
    3493           0 :     pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
    3494             :     sLinkSuffix(sSuffix),
    3495             :     sLinkDisplayName(rLinkDisplayName),
    3496           0 :     pxDoc(0)
    3497             : {
    3498           0 : }
    3499             : 
    3500           0 : SwXLinkNameAccessWrapper::SwXLinkNameAccessWrapper(SwXTextDocument& rxDoc,
    3501             :             const String& rLinkDisplayName, String sSuffix) :
    3502           0 :     pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
    3503             :     sLinkSuffix(sSuffix),
    3504             :     sLinkDisplayName(rLinkDisplayName),
    3505             :     xDoc(&rxDoc),
    3506           0 :     pxDoc(&rxDoc)
    3507             : {
    3508           0 : }
    3509             : 
    3510           0 : SwXLinkNameAccessWrapper::~SwXLinkNameAccessWrapper()
    3511             : {
    3512           0 : }
    3513             : 
    3514           0 : Any SwXLinkNameAccessWrapper::getByName(const OUString& rName)
    3515             :     throw( NoSuchElementException, WrappedTargetException, RuntimeException )
    3516             : {
    3517           0 :     Any aRet;
    3518           0 :     bool bFound = false;
    3519             :     //cut link extension and call the real NameAccess
    3520           0 :     String sParam = rName;
    3521           0 :     String sSuffix(sLinkSuffix);
    3522           0 :     if(sParam.Len() > sSuffix.Len() )
    3523             :     {
    3524           0 :         String sCmp = sParam.Copy(sParam.Len() - sSuffix.Len(),
    3525           0 :                                                     sSuffix.Len());
    3526           0 :         if(sCmp == sSuffix)
    3527             :         {
    3528           0 :             if(pxDoc)
    3529             :             {
    3530           0 :                 sParam = sParam.Copy(0, sParam.Len() - sSuffix.Len());
    3531           0 :                 if(!pxDoc->GetDocShell())
    3532           0 :                     throw RuntimeException();
    3533           0 :                 SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
    3534           0 :                 sal_uInt16 nOutlineCount = pDoc->GetNodes().GetOutLineNds().size();
    3535             : 
    3536           0 :                 for (sal_uInt16 i = 0; i < nOutlineCount && !bFound; ++i)
    3537             :                 {
    3538           0 :                     const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
    3539           0 :                     const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
    3540           0 :                     if(sParam ==
    3541             :                         lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule))
    3542             :                     {
    3543           0 :                         Reference< XPropertySet >  xOutline = new SwXOutlineTarget(sParam);
    3544           0 :                         aRet.setValue(&xOutline, ::getCppuType((Reference<XPropertySet>*)0));
    3545           0 :                         bFound = true;
    3546             :                     }
    3547             :                 }
    3548             :             }
    3549             :             else
    3550             :             {
    3551           0 :                 aRet = xRealAccess->getByName(sParam.Copy(0, sParam.Len() - sSuffix.Len()));
    3552           0 :                 Reference< XInterface > xInt;
    3553           0 :                 if(!(aRet >>= xInt))
    3554           0 :                     throw RuntimeException();
    3555           0 :                 Reference< XPropertySet >  xProp(xInt, UNO_QUERY);
    3556           0 :                 aRet <<= xProp;
    3557           0 :                 bFound = true;
    3558             :             }
    3559           0 :         }
    3560             :     }
    3561           0 :     if(!bFound)
    3562           0 :         throw NoSuchElementException();
    3563           0 :     return aRet;
    3564             : }
    3565             : 
    3566           0 : Sequence< OUString > SwXLinkNameAccessWrapper::getElementNames(void)
    3567             :                                     throw( RuntimeException )
    3568             : {
    3569           0 :     Sequence< OUString > aRet;
    3570           0 :     if(pxDoc)
    3571             :     {
    3572           0 :         if(!pxDoc->GetDocShell())
    3573           0 :             throw RuntimeException();
    3574             : 
    3575           0 :         SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
    3576           0 :         const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
    3577           0 :         sal_uInt16 nOutlineCount = rOutlineNodes.size();
    3578           0 :         aRet.realloc(nOutlineCount);
    3579           0 :         OUString* pResArr = aRet.getArray();
    3580           0 :         String sSuffix = OUString('|');
    3581           0 :         sSuffix += OUString::createFromAscii(pMarkToOutline);
    3582           0 :         const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
    3583           0 :         for (sal_uInt16 i = 0; i < nOutlineCount; ++i)
    3584             :         {
    3585           0 :             String sEntry = lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule);
    3586           0 :             sEntry += sSuffix;
    3587           0 :             pResArr[i] = sEntry;
    3588           0 :         }
    3589             :     }
    3590             :     else
    3591             :     {
    3592           0 :         Sequence< OUString > aOrg = xRealAccess->getElementNames();
    3593           0 :         const OUString* pOrgArr = aOrg.getConstArray();
    3594           0 :         aRet.realloc(aOrg.getLength());
    3595           0 :         OUString* pResArr = aRet.getArray();
    3596           0 :         for(long i = 0; i < aOrg.getLength(); i++)
    3597             :         {
    3598           0 :             pResArr[i] = pOrgArr[i] + sLinkSuffix;
    3599           0 :         }
    3600             :     }
    3601           0 :     return aRet;
    3602             : }
    3603             : 
    3604           0 : sal_Bool SwXLinkNameAccessWrapper::hasByName(const OUString& rName)
    3605             :     throw( RuntimeException )
    3606             : {
    3607           0 :     sal_Bool bRet = sal_False;
    3608           0 :     String sParam(rName);
    3609           0 :     if(sParam.Len() > sLinkSuffix.Len() )
    3610             :     {
    3611           0 :         String sCmp = sParam.Copy(sParam.Len() - sLinkSuffix.Len(),
    3612           0 :                                                     sLinkSuffix.Len());
    3613           0 :         if(sCmp == sLinkSuffix)
    3614             :         {
    3615           0 :                 sParam = sParam.Copy(0, sParam.Len() - sLinkSuffix.Len());
    3616           0 :             if(pxDoc)
    3617             :             {
    3618           0 :                 if(!pxDoc->GetDocShell())
    3619           0 :                     throw RuntimeException();
    3620           0 :                 SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
    3621           0 :                 sal_uInt16 nOutlineCount = pDoc->GetNodes().GetOutLineNds().size();
    3622             : 
    3623           0 :                 for (sal_uInt16 i = 0; i < nOutlineCount && !bRet; ++i)
    3624             :                 {
    3625           0 :                     const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
    3626           0 :                     const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
    3627           0 :                     if(sParam ==
    3628             :                         lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule))
    3629             :                     {
    3630           0 :                         bRet = sal_True;
    3631             :                     }
    3632             :                 }
    3633             :             }
    3634             :             else
    3635             :             {
    3636           0 :                 bRet = xRealAccess->hasByName(sParam);
    3637             :             }
    3638           0 :         }
    3639             :     }
    3640           0 :     return bRet;
    3641             : }
    3642             : 
    3643           0 : uno::Type  SwXLinkNameAccessWrapper::getElementType(void)
    3644             :                                 throw( RuntimeException )
    3645             : {
    3646           0 :     return ::getCppuType((Reference<XPropertySet>*)0);
    3647             : }
    3648             : 
    3649           0 : sal_Bool SwXLinkNameAccessWrapper::hasElements(void) throw( RuntimeException )
    3650             : {
    3651           0 :     sal_Bool bRet = sal_False;
    3652           0 :     if(pxDoc)
    3653             :     {
    3654             :         OSL_FAIL("not implemented");
    3655             :     }
    3656             :     else
    3657             :     {
    3658           0 :         bRet = xRealAccess->hasElements();
    3659             :     }
    3660           0 :     return bRet;
    3661             : }
    3662             : 
    3663           0 : Reference< XPropertySetInfo >  SwXLinkNameAccessWrapper::getPropertySetInfo(void)
    3664             :                                         throw( RuntimeException )
    3665             : {
    3666           0 :     static Reference< XPropertySetInfo >  xRet = pPropSet->getPropertySetInfo();
    3667           0 :     return xRet;
    3668             : }
    3669             : 
    3670           0 : void SwXLinkNameAccessWrapper::setPropertyValue(
    3671             :     const OUString& , const Any& )
    3672             :     throw( UnknownPropertyException,
    3673             :             PropertyVetoException,
    3674             :             IllegalArgumentException,
    3675             :              WrappedTargetException,
    3676             :             RuntimeException)
    3677             : {
    3678           0 :     throw UnknownPropertyException();
    3679             : }
    3680             : 
    3681           0 : static Any lcl_GetDisplayBitmap(String sLinkSuffix)
    3682             : {
    3683           0 :     Any aRet;
    3684           0 :     if(sLinkSuffix.Len())
    3685           0 :         sLinkSuffix.Erase(0, 1);
    3686           0 :     sal_uInt16 nImgId = USHRT_MAX;
    3687             : 
    3688           0 :     if(COMPARE_EQUAL == sLinkSuffix.CompareToAscii(pMarkToOutline))
    3689           0 :         nImgId = CONTENT_TYPE_OUTLINE;
    3690           0 :     else if(COMPARE_EQUAL  == sLinkSuffix.CompareToAscii(pMarkToTable))
    3691           0 :         nImgId = CONTENT_TYPE_TABLE;
    3692           0 :     else if(COMPARE_EQUAL  == sLinkSuffix.CompareToAscii(pMarkToFrame))
    3693           0 :         nImgId = CONTENT_TYPE_FRAME;
    3694           0 :     else if(COMPARE_EQUAL  == sLinkSuffix.CompareToAscii(pMarkToGraphic))
    3695           0 :         nImgId = CONTENT_TYPE_GRAPHIC;
    3696           0 :     else if(COMPARE_EQUAL  == sLinkSuffix.CompareToAscii(pMarkToRegion))
    3697           0 :         nImgId = CONTENT_TYPE_REGION;
    3698           0 :     else if(COMPARE_EQUAL == sLinkSuffix.CompareToAscii(pMarkToOLE))
    3699           0 :         nImgId = CONTENT_TYPE_OLE;
    3700           0 :     else if(!sLinkSuffix.Len())
    3701           0 :         nImgId = CONTENT_TYPE_BOOKMARK;
    3702           0 :     if(USHRT_MAX != nImgId)
    3703             :     {
    3704           0 :         nImgId += 20000;
    3705           0 :         ImageList aEntryImages( SW_RES(IMG_NAVI_ENTRYBMP) );
    3706           0 :         const Image& rImage = aEntryImages.GetImage( nImgId );
    3707           0 :         Bitmap aBitmap( rImage.GetBitmapEx().GetBitmap() );
    3708           0 :         Reference<awt::XBitmap> xBmp = VCLUnoHelper::CreateBitmap( aBitmap );
    3709           0 :         aRet.setValue( &xBmp, ::getCppuType((Reference<awt::XBitmap>*)0) );
    3710             :     }
    3711           0 :     return aRet;
    3712             : }
    3713             : 
    3714           0 : Any SwXLinkNameAccessWrapper::getPropertyValue(const OUString& rPropertyName)
    3715             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
    3716             : {
    3717           0 :     Any aRet;
    3718           0 :     if( rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_NAME)))
    3719             :     {
    3720           0 :         aRet <<= OUString(sLinkDisplayName);
    3721             :     }
    3722           0 :     else if( rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_BITMAP)))
    3723             :     {
    3724           0 :         aRet = lcl_GetDisplayBitmap(sLinkSuffix);
    3725             :     }
    3726             :     else
    3727           0 :         throw UnknownPropertyException();
    3728           0 :     return aRet;
    3729             : }
    3730             : 
    3731           0 : void SwXLinkNameAccessWrapper::addPropertyChangeListener(
    3732             :     const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
    3733             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
    3734           0 : {}
    3735             : 
    3736           0 : void SwXLinkNameAccessWrapper::removePropertyChangeListener(
    3737             :     const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
    3738             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
    3739           0 : {}
    3740             : 
    3741           0 : void SwXLinkNameAccessWrapper::addVetoableChangeListener(
    3742             :     const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
    3743             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
    3744           0 : {}
    3745             : 
    3746           0 : void SwXLinkNameAccessWrapper::removeVetoableChangeListener(
    3747             :     const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
    3748             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
    3749           0 : {}
    3750             : 
    3751           0 : Reference< XNameAccess >  SwXLinkNameAccessWrapper::getLinks(void)
    3752             :                                     throw( RuntimeException )
    3753             : {
    3754           0 :     return (SwXLinkNameAccessWrapper*)this;
    3755             : }
    3756             : 
    3757           0 : OUString SwXLinkNameAccessWrapper::getImplementationName(void) throw( RuntimeException )
    3758             : {
    3759           0 :     return OUString("SwXLinkNameAccessWrapper");
    3760             : }
    3761             : 
    3762           0 : sal_Bool SwXLinkNameAccessWrapper::supportsService(const OUString& rServiceName)
    3763             :                                                     throw( RuntimeException )
    3764             : {
    3765           0 :     return (rServiceName == "com.sun.star.document.LinkTargets");
    3766             : }
    3767             : 
    3768           0 : Sequence< OUString > SwXLinkNameAccessWrapper::getSupportedServiceNames(void)
    3769             :                                                     throw( RuntimeException )
    3770             : {
    3771           0 :     Sequence< OUString > aRet(1);
    3772           0 :     OUString* pNames = aRet.getArray();
    3773           0 :     pNames[0] = "com.sun.star.document.LinkTargets";
    3774           0 :     return aRet;
    3775             : }
    3776             : 
    3777           0 : SwXOutlineTarget::SwXOutlineTarget(const String& rOutlineText) :
    3778           0 :     pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
    3779           0 :     sOutlineText(rOutlineText)
    3780             : {
    3781           0 : }
    3782             : 
    3783           0 : SwXOutlineTarget::~SwXOutlineTarget()
    3784             : {
    3785           0 : }
    3786             : 
    3787           0 : Reference< XPropertySetInfo >  SwXOutlineTarget::getPropertySetInfo(void) throw( RuntimeException )
    3788             : {
    3789           0 :     static Reference< XPropertySetInfo >  xRet = pPropSet->getPropertySetInfo();
    3790           0 :     return xRet;
    3791             : }
    3792             : 
    3793           0 : void SwXOutlineTarget::setPropertyValue(
    3794             :     const OUString& /*PropertyName*/, const Any& /*aValue*/)
    3795             :     throw( UnknownPropertyException, PropertyVetoException,
    3796             :          IllegalArgumentException, WrappedTargetException, RuntimeException)
    3797             : {
    3798           0 :     throw UnknownPropertyException();
    3799             : }
    3800             : 
    3801           0 : Any SwXOutlineTarget::getPropertyValue(const OUString& rPropertyName)
    3802             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
    3803             : {
    3804           0 :     Any aRet;
    3805           0 :     if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_NAME)))
    3806           0 :         aRet <<= OUString(sOutlineText);
    3807             :     else
    3808           0 :         throw UnknownPropertyException();
    3809           0 :     return aRet;
    3810             : }
    3811             : 
    3812           0 : void SwXOutlineTarget::addPropertyChangeListener(
    3813             :     const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
    3814             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
    3815             : {
    3816           0 : }
    3817             : 
    3818           0 : void SwXOutlineTarget::removePropertyChangeListener(
    3819             :     const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
    3820             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
    3821             : {
    3822           0 : }
    3823             : 
    3824           0 : void SwXOutlineTarget::addVetoableChangeListener(
    3825             :     const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
    3826             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
    3827             : {
    3828           0 : }
    3829             : 
    3830           0 : void SwXOutlineTarget::removeVetoableChangeListener(
    3831             :     const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
    3832             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
    3833             : {
    3834           0 : }
    3835             : 
    3836           0 : OUString SwXOutlineTarget::getImplementationName(void) throw( RuntimeException )
    3837             : {
    3838           0 :     return OUString("SwXOutlineTarget");
    3839             : }
    3840             : 
    3841           0 : sal_Bool SwXOutlineTarget::supportsService(const OUString& ServiceName) throw( RuntimeException )
    3842             : {
    3843           0 :     return ServiceName == "com.sun.star.document.LinkTarget";
    3844             : }
    3845             : 
    3846           0 : Sequence< OUString > SwXOutlineTarget::getSupportedServiceNames(void) throw( RuntimeException )
    3847             : {
    3848           0 :     Sequence < OUString > aRet(1);
    3849           0 :     OUString* pArray = aRet.getArray();
    3850           0 :     pArray[0] = "com.sun.star.document.LinkTarget";
    3851             : 
    3852           0 :     return aRet;
    3853             : }
    3854             : 
    3855          66 : SwXDocumentPropertyHelper::SwXDocumentPropertyHelper(SwDoc& rDoc) :
    3856          66 : SvxUnoForbiddenCharsTable ( rDoc.getForbiddenCharacterTable() )
    3857          66 : ,m_pDoc(&rDoc)
    3858             : {
    3859          66 : }
    3860             : 
    3861         130 : SwXDocumentPropertyHelper::~SwXDocumentPropertyHelper()
    3862             : {
    3863         130 : }
    3864             : 
    3865         178 : Reference<XInterface> SwXDocumentPropertyHelper::GetDrawTable(short nWhich)
    3866             : {
    3867         178 :     Reference<XInterface> xRet;
    3868         178 :     if(m_pDoc)
    3869             :     {
    3870         178 :         switch(nWhich)
    3871             :         {
    3872             :             // #i52858#
    3873             :             // assure that Draw model is created, if it doesn't exist.
    3874             :             case SW_CREATE_DASH_TABLE         :
    3875          16 :                 if(!xDashTable.is())
    3876          15 :                     xDashTable = SvxUnoDashTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
    3877          16 :                 xRet = xDashTable;
    3878          16 :             break;
    3879             :             case SW_CREATE_GRADIENT_TABLE     :
    3880          26 :                 if(!xGradientTable.is())
    3881          20 :                     xGradientTable = SvxUnoGradientTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
    3882          26 :                 xRet = xGradientTable;
    3883          26 :             break;
    3884             :             case SW_CREATE_HATCH_TABLE        :
    3885          17 :                 if(!xHatchTable.is())
    3886          16 :                     xHatchTable = SvxUnoHatchTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
    3887          17 :                 xRet = xHatchTable;
    3888          17 :             break;
    3889             :             case SW_CREATE_BITMAP_TABLE       :
    3890          16 :                 if(!xBitmapTable.is())
    3891          15 :                     xBitmapTable = SvxUnoBitmapTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
    3892          16 :                 xRet = xBitmapTable;
    3893          16 :             break;
    3894             :             case SW_CREATE_TRANSGRADIENT_TABLE:
    3895          16 :                 if(!xTransGradientTable.is())
    3896          15 :                     xTransGradientTable = SvxUnoTransGradientTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
    3897          16 :                 xRet = xTransGradientTable;
    3898          16 :             break;
    3899             :             case SW_CREATE_MARKER_TABLE       :
    3900          20 :                 if(!xMarkerTable.is())
    3901          19 :                     xMarkerTable = SvxUnoMarkerTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
    3902          20 :                 xRet = xMarkerTable;
    3903          20 :             break;
    3904             :             case  SW_CREATE_DRAW_DEFAULTS:
    3905          67 :                 if(!xDrawDefaults.is())
    3906          58 :                     xDrawDefaults = (cppu::OWeakObject*)new SwSvxUnoDrawPool(m_pDoc);
    3907          67 :                 xRet = xDrawDefaults;
    3908          67 :             break;
    3909             : #if OSL_DEBUG_LEVEL > 0
    3910             :             default: OSL_FAIL("which table?");
    3911             : #endif
    3912             :         }
    3913             :     }
    3914         178 :     return xRet;
    3915             : }
    3916             : 
    3917          65 : void SwXDocumentPropertyHelper::Invalidate()
    3918             : {
    3919          65 :     xDashTable = 0;
    3920          65 :     xGradientTable = 0;
    3921          65 :     xHatchTable = 0;
    3922          65 :     xBitmapTable = 0;
    3923          65 :     xTransGradientTable = 0;
    3924          65 :     xMarkerTable = 0;
    3925          65 :     xDrawDefaults = 0;
    3926          65 :     m_pDoc = 0;
    3927          65 :     SvxUnoForbiddenCharsTable::mxForbiddenChars.clear();
    3928          65 : }
    3929             : 
    3930           1 : void SwXDocumentPropertyHelper::onChange()
    3931             : {
    3932           1 :     if(m_pDoc)
    3933           1 :        m_pDoc->SetModified();
    3934           1 : }
    3935             : 
    3936           0 : SwViewOptionAdjust_Impl::SwViewOptionAdjust_Impl(
    3937             :             ViewShell& rSh, const SwViewOption &rViewOptions)
    3938             :     : m_pShell(&rSh)
    3939           0 :     , m_aOldViewOptions( rViewOptions )
    3940             : {
    3941           0 : }
    3942             : 
    3943           0 : SwViewOptionAdjust_Impl::~SwViewOptionAdjust_Impl()
    3944             : {
    3945           0 :     if (m_pShell)
    3946             :     {
    3947           0 :         m_pShell->ApplyViewOptions( m_aOldViewOptions );
    3948             :     }
    3949           0 : }
    3950             : 
    3951             : void
    3952           0 : SwViewOptionAdjust_Impl::AdjustViewOptions(SwPrintData const*const pPrtOptions)
    3953             : {
    3954             :     // to avoid unnecessary reformatting the view options related to the content
    3955             :     // below should only change if necessary, that is if respective content is present
    3956           0 :     const bool bContainsHiddenChars         = m_pShell->GetDoc()->ContainsHiddenChars();
    3957           0 :     const SwFieldType* pFldType = m_pShell->GetDoc()->GetSysFldType( RES_HIDDENTXTFLD );
    3958           0 :     const bool bContainsHiddenFields        = pFldType && pFldType->GetDepends();
    3959           0 :     pFldType = m_pShell->GetDoc()->GetSysFldType( RES_HIDDENPARAFLD );
    3960           0 :     const bool bContainsHiddenParagraphs    = pFldType && pFldType->GetDepends();
    3961           0 :     pFldType = m_pShell->GetDoc()->GetSysFldType( RES_JUMPEDITFLD );
    3962           0 :     const bool bContainsPlaceHolders        = pFldType && pFldType->GetDepends();
    3963           0 :     const bool bContainsFields              = m_pShell->IsAnyFieldInDoc();
    3964             : 
    3965           0 :     SwViewOption aRenderViewOptions( m_aOldViewOptions );
    3966             : 
    3967             :     // disable anything in the view that should not be printed (or exported to PDF) by default
    3968             :     // (see also dialog "Tools/Options - StarOffice Writer - Formatting Aids"
    3969             :     // in section "Display of ...")
    3970           0 :     aRenderViewOptions.SetParagraph( sal_False );             // paragraph end
    3971           0 :     aRenderViewOptions.SetSoftHyph( sal_False );              // aka custom hyphens
    3972           0 :     aRenderViewOptions.SetBlank( sal_False );                 // spaces
    3973           0 :     aRenderViewOptions.SetHardBlank( sal_False );             // non-breaking spaces
    3974           0 :     aRenderViewOptions.SetTab( sal_False );                   // tabs
    3975           0 :     aRenderViewOptions.SetLineBreak( sal_False );             // breaks (type 1)
    3976           0 :     aRenderViewOptions.SetPageBreak( sal_False );             // breaks (type 2)
    3977           0 :     aRenderViewOptions.SetColumnBreak( sal_False );           // breaks (type 3)
    3978           0 :     sal_Bool bVal = pPrtOptions? pPrtOptions->bPrintHiddenText : sal_False;
    3979           0 :     if (bContainsHiddenChars)
    3980           0 :         aRenderViewOptions.SetShowHiddenChar( bVal );     // hidden text
    3981           0 :     if (bContainsHiddenFields)
    3982           0 :         aRenderViewOptions.SetShowHiddenField( bVal );
    3983           0 :     if (bContainsHiddenParagraphs)
    3984           0 :         aRenderViewOptions.SetShowHiddenPara( bVal );
    3985             : 
    3986           0 :     if (bContainsPlaceHolders)
    3987             :     {
    3988             :         // should always be printed in PDF export!
    3989           0 :         bVal = pPrtOptions ? pPrtOptions->bPrintTextPlaceholder : sal_True;
    3990           0 :         aRenderViewOptions.SetShowPlaceHolderFields( bVal );
    3991             :     }
    3992             : 
    3993           0 :     if (bContainsFields)
    3994           0 :         aRenderViewOptions.SetFldName( sal_False );
    3995             : 
    3996             :     // we need to set this flag in order to get to see the visible effect of
    3997             :     // some of the above settings (needed for correct rendering)
    3998           0 :     aRenderViewOptions.SetViewMetaChars( sal_True );
    3999             : 
    4000           0 :     if (m_aOldViewOptions != aRenderViewOptions)  // check if reformatting is necessary
    4001             :     {
    4002           0 :         aRenderViewOptions.SetPrinting( pPrtOptions != NULL );
    4003           0 :         m_pShell->ApplyViewOptions( aRenderViewOptions );
    4004           0 :     }
    4005          99 : }
    4006             : 
    4007             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10