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

Generated by: LCOV version 1.11