LCOV - code coverage report
Current view: top level - sw/source/core/uibase/uno - unotxdoc.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 970 2063 47.0 %
Date: 2014-04-11 Functions: 86 165 52.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10