LCOV - code coverage report
Current view: top level - sw/source/uibase/uno - unotxdoc.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 961 2065 46.5 %
Date: 2014-11-03 Functions: 88 169 52.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10