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

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <osl/mutex.hxx>
      21             : #include <vcl/image.hxx>
      22             : #include <vcl/virdev.hxx>
      23             : #include <vcl/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           0 : class SwXTextDocument::Impl
     218             : {
     219             : private:
     220             :     ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper
     221             : 
     222             : public:
     223             :     ::cppu::OInterfaceContainerHelper m_RefreshListeners;
     224             : 
     225           0 :     Impl() : m_RefreshListeners(m_Mutex) { }
     226             : 
     227             : };
     228             : 
     229             : namespace
     230             : {
     231             :     class theSwXTextDocumentUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXTextDocumentUnoTunnelId > {};
     232             : }
     233             : 
     234           0 : const Sequence< sal_Int8 > & SwXTextDocument::getUnoTunnelId()
     235             : {
     236           0 :     return theSwXTextDocumentUnoTunnelId::get().getSeq();
     237             : }
     238             : 
     239           0 : sal_Int64 SAL_CALL SwXTextDocument::getSomething( const Sequence< sal_Int8 >& rId )
     240             :     throw(RuntimeException, std::exception)
     241             : {
     242           0 :     if( rId.getLength() == 16
     243           0 :         && 0 == memcmp( getUnoTunnelId().getConstArray(),
     244           0 :                                         rId.getConstArray(), 16 ) )
     245             :     {
     246           0 :             return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
     247             :     }
     248           0 :     if( rId.getLength() == 16
     249           0 :         && 0 == memcmp( SfxObjectShell::getUnoTunnelId().getConstArray(),
     250           0 :                                         rId.getConstArray(), 16 ) )
     251             :     {
     252           0 :         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(pDocShell ));
     253             :     }
     254             : 
     255           0 :     sal_Int64 nRet = SfxBaseModel::getSomething( rId );
     256           0 :     if ( nRet )
     257           0 :         return nRet;
     258             :     else
     259             :     {
     260           0 :         GetNumberFormatter();
     261           0 :         Any aNumTunnel = xNumFmtAgg->queryAggregation(::getCppuType((Reference<XUnoTunnel>*)0));
     262           0 :         Reference<XUnoTunnel> xNumTunnel;
     263           0 :         aNumTunnel >>= xNumTunnel;
     264           0 :         if(xNumTunnel.is())
     265           0 :             return xNumTunnel->getSomething(rId);
     266             :     }
     267             : 
     268           0 :     return SfxBaseModel::getSomething( rId );
     269             : }
     270             : 
     271           0 : Any SAL_CALL SwXTextDocument::queryInterface( const uno::Type& rType ) throw(RuntimeException, std::exception)
     272             : {
     273           0 :     Any aRet = SwXTextDocumentBaseClass::queryInterface(rType);
     274           0 :     if ( !aRet.hasValue() )
     275           0 :         aRet = SfxBaseModel::queryInterface(rType);
     276           0 :     if ( !aRet.hasValue() &&
     277           0 :         rType == ::getCppuType((Reference<lang::XMultiServiceFactory>*)0))
     278             :     {
     279           0 :         Reference<lang::XMultiServiceFactory> xTmp = this;
     280           0 :         aRet <<= xTmp;
     281             :     }
     282             : 
     283           0 :     if ( !aRet.hasValue()
     284           0 :         && rType != ::getCppuType((Reference< com::sun::star::document::XDocumentEventBroadcaster>*)0)
     285           0 :         && rType != ::getCppuType((Reference< com::sun::star::frame::XController>*)0)
     286           0 :         && rType != ::getCppuType((Reference< com::sun::star::frame::XFrame>*)0)
     287           0 :         && rType != ::getCppuType((Reference< com::sun::star::script::XInvocation>*)0)
     288           0 :         && rType != ::getCppuType((Reference< com::sun::star::beans::XFastPropertySet>*)0)
     289           0 :         && rType != ::getCppuType((Reference< com::sun::star::awt::XWindow>*)0))
     290             :     {
     291           0 :         GetNumberFormatter();
     292           0 :         if(xNumFmtAgg.is())
     293           0 :             aRet = xNumFmtAgg->queryAggregation(rType);
     294             :     }
     295           0 :     return aRet;
     296             : }
     297             : 
     298           0 : void SAL_CALL SwXTextDocument::acquire()throw()
     299             : {
     300           0 :     SfxBaseModel::acquire();
     301           0 : }
     302             : 
     303           0 : void SAL_CALL SwXTextDocument::release()throw()
     304             : {
     305           0 :     SfxBaseModel::release();
     306           0 : }
     307             : 
     308           0 : Reference< XAdapter > SwXTextDocument::queryAdapter(  ) throw(RuntimeException, std::exception)
     309             : {
     310           0 :     return SfxBaseModel::queryAdapter();
     311             : }
     312             : 
     313           0 : Sequence< uno::Type > SAL_CALL SwXTextDocument::getTypes() throw(RuntimeException, std::exception)
     314             : {
     315           0 :     Sequence< uno::Type > aBaseTypes = SfxBaseModel::getTypes();
     316           0 :     Sequence< uno::Type > aTextTypes = SwXTextDocumentBaseClass::getTypes();
     317             : 
     318           0 :     Sequence< uno::Type > aNumTypes;
     319           0 :     GetNumberFormatter();
     320           0 :     if(xNumFmtAgg.is())
     321             :     {
     322           0 :         const uno::Type& rProvType = ::getCppuType((Reference <XTypeProvider>*)0);
     323           0 :         Any aNumProv = xNumFmtAgg->queryAggregation(rProvType);
     324           0 :         Reference<XTypeProvider> xNumProv;
     325           0 :         if(aNumProv >>= xNumProv)
     326             :         {
     327           0 :             aNumTypes = xNumProv->getTypes();
     328           0 :         }
     329             :     }
     330           0 :     long nIndex = aBaseTypes.getLength();
     331             :     // don't forget the lang::XMultiServiceFactory
     332           0 :     aBaseTypes.realloc(aBaseTypes.getLength() + aTextTypes.getLength() + aNumTypes.getLength() + 1);
     333           0 :     uno::Type* pBaseTypes = aBaseTypes.getArray();
     334           0 :     const uno::Type* pTextTypes = aTextTypes.getConstArray();
     335             :     long nPos;
     336           0 :     for(nPos = 0; nPos < aTextTypes.getLength(); nPos++)
     337             :     {
     338           0 :         pBaseTypes[nIndex++] = pTextTypes[nPos];
     339             :     }
     340           0 :     const uno::Type* pNumTypes = aNumTypes.getConstArray();
     341           0 :     for(nPos = 0; nPos < aNumTypes.getLength(); nPos++)
     342             :     {
     343           0 :         pBaseTypes[nIndex++] = pNumTypes[nPos];
     344             :     }
     345           0 :     pBaseTypes[nIndex++] = ::getCppuType((Reference<lang::XMultiServiceFactory>*)0);
     346           0 :     return aBaseTypes;
     347             : }
     348             : 
     349           0 : SwXTextDocument::SwXTextDocument(SwDocShell* pShell)
     350             :     : SfxBaseModel(pShell)
     351           0 :     , m_pImpl(new Impl)
     352             :     ,
     353           0 :     pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_DOCUMENT)),
     354             : 
     355             :     pDocShell(pShell),
     356             : 
     357           0 :     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           0 :     bApplyPagePrintSettingsFromXPagePrintable( sal_False )
     390             : {
     391           0 : }
     392             : 
     393           0 : SwXTextDocument::~SwXTextDocument()
     394             : {
     395           0 :     InitNewDoc();
     396           0 :     if(xNumFmtAgg.is())
     397             :     {
     398           0 :         Reference< XInterface >  x0;
     399           0 :         xNumFmtAgg->setDelegator(x0);
     400           0 :         xNumFmtAgg = 0;
     401             :     }
     402           0 :     delete m_pPrintUIOptions;
     403           0 :     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           0 :     delete m_pRenderData;
     411           0 : }
     412             : 
     413           0 : SwXDocumentPropertyHelper * SwXTextDocument::GetPropertyHelper ()
     414             : {
     415           0 :     if(!xPropertyHelper.is())
     416             :     {
     417           0 :         pPropertyHelper = new SwXDocumentPropertyHelper(*pDocShell->GetDoc());
     418           0 :         xPropertyHelper = (cppu::OWeakObject*)pPropertyHelper;
     419             :     }
     420           0 :     return pPropertyHelper;
     421             : }
     422             : 
     423           0 : void SwXTextDocument::GetNumberFormatter()
     424             : {
     425           0 :     if(IsValid())
     426             :     {
     427           0 :         if(!xNumFmtAgg.is())
     428             :         {
     429           0 :             if ( pDocShell->GetDoc() )
     430             :             {
     431             :                 SvNumberFormatsSupplierObj* pNumFmt = new SvNumberFormatsSupplierObj(
     432           0 :                                     pDocShell->GetDoc()->GetNumberFormatter( sal_True ));
     433           0 :                 Reference< util::XNumberFormatsSupplier >  xTmp = pNumFmt;
     434           0 :                 xNumFmtAgg = Reference< XAggregation >(xTmp, UNO_QUERY);
     435             :             }
     436           0 :             if(xNumFmtAgg.is())
     437           0 :                 xNumFmtAgg->setDelegator((cppu::OWeakObject*)(SwXTextDocumentBaseClass*)this);
     438             :         }
     439             :         else
     440             :         {
     441           0 :             const uno::Type& rTunnelType = ::getCppuType((Reference <XUnoTunnel>*)0);
     442           0 :             Any aNumTunnel = xNumFmtAgg->queryAggregation(rTunnelType);
     443           0 :             SvNumberFormatsSupplierObj* pNumFmt = 0;
     444           0 :             Reference< XUnoTunnel > xNumTunnel;
     445           0 :             if(aNumTunnel >>= xNumTunnel)
     446             :             {
     447             :                 pNumFmt = reinterpret_cast<SvNumberFormatsSupplierObj*>(
     448           0 :                         xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
     449             : 
     450             :             }
     451             :             OSL_ENSURE(pNumFmt, "No number formatter available");
     452           0 :             if (pNumFmt && !pNumFmt->GetNumberFormatter())
     453           0 :                 pNumFmt->SetNumberFormatter(pDocShell->GetDoc()->GetNumberFormatter( sal_True ));
     454             :         }
     455             :     }
     456           0 : }
     457             : 
     458           0 : Reference< XText >  SwXTextDocument::getText(void) throw( RuntimeException, std::exception )
     459             : {
     460           0 :     SolarMutexGuard aGuard;
     461           0 :     if(!IsValid())
     462           0 :         throw RuntimeException();
     463           0 :     if(!xBodyText.is())
     464             :     {
     465           0 :         pBodyText = new SwXBodyText(pDocShell->GetDoc());
     466           0 :         xBodyText = pBodyText;
     467             :     }
     468           0 :     return xBodyText;
     469             : }
     470             : 
     471           0 : void SwXTextDocument::reformat(void) throw( RuntimeException, std::exception )
     472             : {
     473           0 :     SolarMutexGuard aGuard;
     474           0 :     if(!IsValid())
     475           0 :         throw RuntimeException();
     476           0 : }
     477             : 
     478           0 : void SwXTextDocument::lockControllers(void) throw( RuntimeException, std::exception )
     479             : {
     480           0 :     SolarMutexGuard aGuard;
     481           0 :     if(IsValid())
     482             :     {
     483           0 :         UnoActionContext* pContext = new UnoActionContext(pDocShell->GetDoc());
     484           0 :         aActionArr.push_front(pContext);
     485             :     }
     486             :     else
     487           0 :         throw RuntimeException();
     488           0 : }
     489             : 
     490           0 : void SwXTextDocument::unlockControllers(void) throw( RuntimeException, std::exception )
     491             : {
     492           0 :     SolarMutexGuard aGuard;
     493           0 :     if(!aActionArr.empty())
     494             :     {
     495           0 :         UnoActionContext* pContext = aActionArr.front();
     496           0 :         aActionArr.pop_front();
     497           0 :         delete pContext;
     498             :     }
     499             :     else
     500           0 :         throw RuntimeException();
     501           0 : }
     502             : 
     503           0 : sal_Bool SwXTextDocument::hasControllersLocked(void) throw( RuntimeException, std::exception )
     504             : {
     505           0 :     SolarMutexGuard aGuard;
     506           0 :     return !aActionArr.empty();
     507             : }
     508             : 
     509           0 : Reference< frame::XController >  SwXTextDocument::getCurrentController(void) throw( RuntimeException, std::exception )
     510             : {
     511           0 :     return SfxBaseModel::getCurrentController();
     512             : }
     513             : 
     514           0 : void SwXTextDocument::setCurrentController(const Reference< frame::XController > & xController)
     515             :     throw( NoSuchElementException, RuntimeException, std::exception )
     516             : {
     517           0 :     SfxBaseModel::setCurrentController(xController);
     518           0 : }
     519             : 
     520           0 : Reference< XInterface >  SwXTextDocument::getCurrentSelection() throw( RuntimeException, std::exception )
     521             : {
     522           0 :     SolarMutexGuard aGuard;
     523           0 :     Reference< XInterface >  xRef;
     524           0 :     if(IsValid())
     525             :     {
     526             : 
     527           0 :         const TypeId aTypeId = TYPE(SwView);
     528           0 :         SwView* pView = (SwView*)SfxViewShell::GetFirst(&aTypeId);
     529           0 :         while(pView && pView->GetObjectShell() != pDocShell)
     530             :         {
     531           0 :             pView = (SwView*)SfxViewShell::GetNext(*pView, &aTypeId);
     532             :         }
     533           0 :         if(pView)
     534             :         {
     535           0 :             Any aRef = pView->GetUNOObject()->getSelection();
     536           0 :             aRef >>= xRef;
     537             :         }
     538             :     }
     539           0 :     return xRef;
     540             : }
     541             : 
     542           0 : sal_Bool SwXTextDocument::attachResource(const OUString& aURL, const Sequence< beans::PropertyValue >& aArgs)
     543             :         throw( RuntimeException, std::exception )
     544             : {
     545           0 :     return SfxBaseModel::attachResource(aURL, aArgs);
     546             : }
     547             : 
     548           0 : OUString SwXTextDocument::getURL(void) throw( RuntimeException, std::exception )
     549             : {
     550           0 :     return SfxBaseModel::getURL();
     551             : }
     552             : 
     553           0 : Sequence< beans::PropertyValue > SwXTextDocument::getArgs(void) throw( RuntimeException, std::exception )
     554             : {
     555           0 :     return SfxBaseModel::getArgs();
     556             : }
     557             : 
     558           0 : void SwXTextDocument::connectController(const Reference< frame::XController > & xController) throw( RuntimeException, std::exception )
     559             : {
     560           0 :     SfxBaseModel::connectController(xController);
     561           0 : }
     562             : 
     563           0 : void SwXTextDocument::disconnectController(const Reference< frame::XController > & xController) throw( RuntimeException, std::exception )
     564             : {
     565           0 :     SfxBaseModel::disconnectController(xController);
     566           0 : }
     567             : 
     568           0 : void SwXTextDocument::dispose(void) throw( RuntimeException, std::exception )
     569             : {
     570           0 :     SfxBaseModel::dispose();
     571           0 : }
     572             : 
     573           0 : void SwXTextDocument::close( sal_Bool bDeliverOwnership ) throw( util::CloseVetoException, RuntimeException, std::exception )
     574             : {
     575           0 :     SolarMutexGuard aGuard;
     576           0 :     if(IsValid() && m_pHiddenViewFrame)
     577           0 :         lcl_DisposeView( m_pHiddenViewFrame, pDocShell);
     578           0 :     SfxBaseModel::close(bDeliverOwnership);
     579           0 : }
     580             : 
     581           0 : void SwXTextDocument::addEventListener(const Reference< lang::XEventListener > & aListener) throw( RuntimeException, std::exception )
     582             : {
     583           0 :     SfxBaseModel::addEventListener(aListener);
     584           0 : }
     585             : 
     586           0 : void SwXTextDocument::removeEventListener(const Reference< lang::XEventListener > & aListener) throw( RuntimeException, std::exception )
     587             : {
     588           0 :     SfxBaseModel::removeEventListener(aListener);
     589           0 : }
     590             : 
     591           0 : Reference< XPropertySet > SwXTextDocument::getLineNumberingProperties(void)
     592             :             throw( RuntimeException, std::exception )
     593             : {
     594           0 :     SolarMutexGuard aGuard;
     595           0 :     if(IsValid())
     596             :     {
     597           0 :         if(!pxXLineNumberingProperties)
     598             :         {
     599           0 :             pxXLineNumberingProperties = new Reference<XPropertySet>;
     600           0 :             (*pxXLineNumberingProperties) = new SwXLineNumberingProperties(pDocShell->GetDoc());
     601             :         }
     602             :     }
     603             :     else
     604           0 :         throw RuntimeException();
     605           0 :     return *pxXLineNumberingProperties;
     606             : }
     607             : 
     608           0 : Reference< XIndexReplace >  SwXTextDocument::getChapterNumberingRules(void)
     609             :                                     throw( RuntimeException, std::exception )
     610             : {
     611           0 :     SolarMutexGuard aGuard;
     612           0 :     if(!IsValid())
     613           0 :         throw RuntimeException();
     614           0 :     if(!pxXChapterNumbering)
     615             :     {
     616           0 :         pxXChapterNumbering = new Reference< XIndexReplace > ;
     617           0 :         *pxXChapterNumbering = new SwXChapterNumbering(*pDocShell);
     618             :     }
     619           0 :     return *pxXChapterNumbering;
     620             : }
     621             : 
     622           0 : Reference< XIndexAccess >  SwXTextDocument::getNumberingRules(void) throw( RuntimeException, std::exception )
     623             : {
     624           0 :     SolarMutexGuard aGuard;
     625           0 :     if(!IsValid())
     626           0 :         throw RuntimeException();
     627           0 :     if(!pxXNumberingRules )
     628             :     {
     629           0 :         ((SwXTextDocument*)this)->pxXNumberingRules = new Reference< XIndexAccess > ;
     630           0 :         *pxXNumberingRules = new SwXNumberingRulesCollection( pDocShell->GetDoc() );
     631             :     }
     632           0 :     return *pxXNumberingRules;
     633             : }
     634             : 
     635           0 : Reference< XIndexAccess >  SwXTextDocument::getFootnotes(void) throw( RuntimeException, std::exception )
     636             : {
     637           0 :     SolarMutexGuard aGuard;
     638           0 :     if(!IsValid())
     639           0 :         throw RuntimeException();
     640           0 :     if(!pxXFootnotes)
     641             :     {
     642           0 :         ((SwXTextDocument*)this)->pxXFootnotes = new Reference< XIndexAccess > ;
     643           0 :         *pxXFootnotes = new SwXFootnotes(sal_False, pDocShell->GetDoc());
     644             :     }
     645           0 :     return *pxXFootnotes;
     646             : }
     647             : 
     648             : Reference< XPropertySet >  SAL_CALL
     649           0 :         SwXTextDocument::getFootnoteSettings(void) throw( RuntimeException, std::exception )
     650             : {
     651           0 :     SolarMutexGuard aGuard;
     652           0 :     if(!IsValid())
     653           0 :         throw RuntimeException();
     654           0 :     if(!pxXFootnoteSettings)
     655             :     {
     656           0 :         ((SwXTextDocument*)this)->pxXFootnoteSettings = new Reference< XPropertySet > ;
     657           0 :         *pxXFootnoteSettings = new SwXFootnoteProperties(pDocShell->GetDoc());
     658             :     }
     659           0 :     return *pxXFootnoteSettings;
     660             : }
     661             : 
     662           0 : Reference< XIndexAccess >  SwXTextDocument::getEndnotes(void) throw( RuntimeException, std::exception )
     663             : {
     664           0 :     SolarMutexGuard aGuard;
     665           0 :     if(!IsValid())
     666           0 :         throw RuntimeException();
     667           0 :     if(!pxXEndnotes)
     668             :     {
     669           0 :         ((SwXTextDocument*)this)->pxXEndnotes = new Reference< XIndexAccess > ;
     670           0 :         *pxXEndnotes = new SwXFootnotes(sal_True, pDocShell->GetDoc());
     671             :     }
     672           0 :     return *pxXEndnotes;
     673             : }
     674             : 
     675           0 : Reference< XPropertySet >  SwXTextDocument::getEndnoteSettings(void) throw( RuntimeException, std::exception )
     676             : {
     677           0 :     SolarMutexGuard aGuard;
     678           0 :     if(!IsValid())
     679           0 :         throw RuntimeException();
     680           0 :     if(!pxXEndnoteSettings)
     681             :     {
     682           0 :         ((SwXTextDocument*)this)->pxXEndnoteSettings = new Reference< XPropertySet > ;
     683           0 :         *pxXEndnoteSettings = new SwXEndnoteProperties(pDocShell->GetDoc());
     684             :     }
     685           0 :     return *pxXEndnoteSettings;
     686             : }
     687             : 
     688           0 : Reference< util::XReplaceDescriptor >  SwXTextDocument::createReplaceDescriptor(void)
     689             :     throw( RuntimeException, std::exception )
     690             : {
     691           0 :     SolarMutexGuard aGuard;
     692           0 :     Reference< util::XReplaceDescriptor >  xRet = new SwXTextSearch;
     693           0 :     return xRet;
     694             : }
     695             : 
     696           0 : SwUnoCrsr*  SwXTextDocument::CreateCursorForSearch(Reference< XTextCursor > & xCrsr)
     697             : {
     698           0 :     getText();
     699           0 :     XText *const pText = xBodyText.get();
     700           0 :     SwXBodyText* pBText = (SwXBodyText*)pText;
     701           0 :     SwXTextCursor *const pXTextCursor = pBText->CreateTextCursor(true);
     702           0 :     xCrsr.set( static_cast<text::XWordCursor*>(pXTextCursor) );
     703             : 
     704           0 :     SwUnoCrsr *const pUnoCrsr = pXTextCursor->GetCursor();
     705           0 :     pUnoCrsr->SetRemainInSection(sal_False);
     706           0 :     return pUnoCrsr;
     707             : }
     708             : 
     709           0 : sal_Int32 SwXTextDocument::replaceAll(const Reference< util::XSearchDescriptor > & xDesc)
     710             :                                         throw( RuntimeException, std::exception )
     711             : {
     712           0 :     SolarMutexGuard aGuard;
     713           0 :     Reference< XUnoTunnel > xDescTunnel(xDesc, UNO_QUERY);
     714           0 :     if(!IsValid() || !xDescTunnel.is() || !xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()))
     715           0 :         throw RuntimeException();
     716             : 
     717           0 :     Reference< XTextCursor >  xCrsr;
     718           0 :     SwUnoCrsr*  pUnoCrsr = CreateCursorForSearch(xCrsr);
     719             : 
     720             :     const SwXTextSearch* pSearch = reinterpret_cast<const SwXTextSearch*>(
     721           0 :             xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()));
     722             : 
     723           0 :     int eRanges(FND_IN_BODY|FND_IN_SELALL);
     724             : 
     725           0 :     util::SearchOptions aSearchOpt;
     726           0 :     pSearch->FillSearchOptions( aSearchOpt );
     727             : 
     728           0 :     SwDocPositions eStart = pSearch->bBack ? DOCPOS_END : DOCPOS_START;
     729           0 :     SwDocPositions eEnd = pSearch->bBack ? DOCPOS_START : DOCPOS_END;
     730             : 
     731             :     // Search should take place anywhere
     732           0 :     pUnoCrsr->SetRemainInSection(sal_False);
     733             :     sal_uInt32 nResult;
     734           0 :     UnoActionContext aContext(pDocShell->GetDoc());
     735             :     //try attribute search first
     736           0 :     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           0 :     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           0 :         sal_Bool bSearchInNotes = sal_False;
     772             :         sal_Bool bCancel;
     773             :         nResult = pUnoCrsr->Find( aSearchOpt, bSearchInNotes,
     774             :             eStart, eEnd, bCancel,
     775             :             (FindRanges)eRanges,
     776           0 :             sal_True );
     777             :     }
     778           0 :     return (sal_Int32)nResult;
     779             : 
     780             : }
     781             : 
     782           0 : Reference< util::XSearchDescriptor >  SwXTextDocument::createSearchDescriptor(void)
     783             :                                                     throw( RuntimeException, std::exception )
     784             : {
     785           0 :     SolarMutexGuard aGuard;
     786           0 :     Reference< util::XSearchDescriptor >  xRet = new SwXTextSearch;
     787           0 :     return xRet;
     788             : 
     789             : }
     790             : 
     791             : // Used for findAll/First/Next
     792             : 
     793           0 : 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           0 :     Reference< XUnoTunnel > xDescTunnel(xDesc, UNO_QUERY);
     799           0 :     if(!IsValid() || !xDescTunnel.is() || !xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()))
     800           0 :         return 0;
     801             : 
     802           0 :     SwUnoCrsr*  pUnoCrsr = CreateCursorForSearch(xCrsr);
     803             :     const SwXTextSearch* pSearch = reinterpret_cast<const SwXTextSearch*>(
     804           0 :         xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()));
     805             : 
     806           0 :     sal_Bool bParentInExtra = sal_False;
     807           0 :     if(xLastResult.is())
     808             :     {
     809           0 :         Reference<XUnoTunnel> xCursorTunnel( xLastResult, UNO_QUERY);
     810           0 :         OTextCursorHelper* pPosCrsr = 0;
     811           0 :         if(xCursorTunnel.is())
     812             :         {
     813           0 :             pPosCrsr = reinterpret_cast<OTextCursorHelper*>(xCursorTunnel->getSomething(
     814           0 :                                     OTextCursorHelper::getUnoTunnelId()));
     815             :         }
     816           0 :         SwPaM* pCrsr = pPosCrsr ? pPosCrsr->GetPaM() : 0;
     817           0 :         if(pCrsr)
     818             :         {
     819           0 :             *pUnoCrsr->GetPoint() = *pCrsr->End();
     820           0 :             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           0 :         const SwNode* pRangeNode = pUnoCrsr->GetNode();
     841           0 :         bParentInExtra = pRangeNode->FindFlyStartNode() ||
     842           0 :                             pRangeNode->FindFootnoteStartNode() ||
     843           0 :                             pRangeNode->FindHeaderStartNode() ||
     844           0 :                             pRangeNode->FindFooterStartNode() ;
     845             :     }
     846             : 
     847           0 :     util::SearchOptions aSearchOpt;
     848           0 :     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           0 :     int eRanges(FND_IN_BODY);
     859           0 :     if(bParentInExtra)
     860           0 :         eRanges = FND_IN_OTHER;
     861           0 :     if(bAll) //always - everywhere?
     862           0 :         eRanges = FND_IN_SELALL;
     863           0 :     SwDocPositions eStart = !bAll ? DOCPOS_CURR : pSearch->bBack ? DOCPOS_END : DOCPOS_START;
     864           0 :     SwDocPositions eEnd = pSearch->bBack ? DOCPOS_START : DOCPOS_END;
     865             : 
     866           0 :     nResult = 0;
     867           0 :     sal_uInt16 nSearchProc = 0;
     868           0 :     while(nSearchProc < 2)
     869             :     {
     870             :         //try attribute search first
     871           0 :         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           0 :         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           0 :             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           0 :                     /*int bReplace =*/sal_False );
     906             :         }
     907           0 :         nSearchProc++;
     908           0 :         if(nResult || (eRanges&(FND_IN_SELALL|FND_IN_OTHER)))
     909             :             break;
     910             :         //second step - find in other
     911           0 :         eRanges = FND_IN_OTHER;
     912             :     }
     913           0 :     return pUnoCrsr;
     914             : }
     915             : 
     916             : Reference< XIndexAccess >
     917           0 :     SwXTextDocument::findAll(const Reference< util::XSearchDescriptor > & xDesc)
     918             :                                                 throw( RuntimeException, std::exception )
     919             : {
     920           0 :     SolarMutexGuard aGuard;
     921           0 :     Reference< XInterface >  xTmp;
     922           0 :     sal_Int32 nResult = 0;
     923           0 :     Reference< XTextCursor >  xCrsr;
     924           0 :     SwUnoCrsr* pResultCrsr = FindAny(xDesc, xCrsr, sal_True, nResult, xTmp);
     925           0 :     if(!pResultCrsr)
     926           0 :         throw RuntimeException();
     927           0 :     Reference< XIndexAccess >  xRet;
     928           0 :     xRet = new SwXTextRanges( (nResult) ? pResultCrsr : 0 );
     929           0 :     delete pResultCrsr;
     930           0 :     return xRet;
     931             : }
     932             : 
     933           0 : Reference< XInterface >  SwXTextDocument::findFirst(const Reference< util::XSearchDescriptor > & xDesc)
     934             :                                             throw( RuntimeException, std::exception )
     935             : {
     936           0 :     SolarMutexGuard aGuard;
     937           0 :     Reference< XInterface >  xTmp;
     938           0 :     sal_Int32 nResult = 0;
     939           0 :     Reference< XTextCursor >  xCrsr;
     940           0 :     SwUnoCrsr* pResultCrsr = FindAny(xDesc, xCrsr, sal_False, nResult, xTmp);
     941           0 :     if(!pResultCrsr)
     942           0 :         throw RuntimeException();
     943           0 :     Reference< XInterface >  xRet;
     944           0 :     if(nResult)
     945             :     {
     946             :         const uno::Reference< text::XText >  xParent =
     947           0 :             ::sw::CreateParentXText(*pDocShell->GetDoc(),
     948           0 :                     *pResultCrsr->GetPoint());
     949           0 :         xRet = *new SwXTextCursor(xParent, *pResultCrsr);
     950           0 :         delete pResultCrsr;
     951             :     }
     952           0 :     return xRet;
     953             : }
     954             : 
     955           0 : Reference< XInterface >  SwXTextDocument::findNext(const Reference< XInterface > & xStartAt,
     956             :             const Reference< util::XSearchDescriptor > & xDesc)
     957             :             throw( RuntimeException, std::exception )
     958             : {
     959           0 :     SolarMutexGuard aGuard;
     960           0 :     Reference< XInterface >  xTmp;
     961           0 :     sal_Int32 nResult = 0;
     962           0 :     Reference< XTextCursor >  xCrsr;
     963           0 :     if(!xStartAt.is())
     964           0 :         throw RuntimeException();
     965           0 :     SwUnoCrsr* pResultCrsr = FindAny(xDesc, xCrsr, sal_False, nResult, xStartAt);
     966           0 :     if(!pResultCrsr)
     967           0 :         throw RuntimeException();
     968           0 :     Reference< XInterface >  xRet;
     969           0 :     if(nResult)
     970             :     {
     971             :         const uno::Reference< text::XText >  xParent =
     972           0 :             ::sw::CreateParentXText(*pDocShell->GetDoc(),
     973           0 :                     *pResultCrsr->GetPoint());
     974             : 
     975           0 :         xRet = *new SwXTextCursor(xParent, *pResultCrsr);
     976           0 :         delete pResultCrsr;
     977             :     }
     978           0 :     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)convertTwipToMm100(aData.GetLeftSpace());
     999           0 :         pArray[2] = beans::PropertyValue("LeftMargin", -1, aVal, PropertyState_DIRECT_VALUE);
    1000           0 :         aVal <<= (sal_Int32)convertTwipToMm100(aData.GetRightSpace());
    1001           0 :         pArray[3] = beans::PropertyValue("RightMargin", -1, aVal, PropertyState_DIRECT_VALUE);
    1002           0 :         aVal <<= (sal_Int32)convertTwipToMm100(aData.GetTopSpace());
    1003           0 :         pArray[4] = beans::PropertyValue("TopMargin", -1, aVal, PropertyState_DIRECT_VALUE);
    1004           0 :         aVal <<= (sal_Int32)convertTwipToMm100(aData.GetBottomSpace());
    1005           0 :         pArray[5] = beans::PropertyValue("BottomMargin", -1, aVal, PropertyState_DIRECT_VALUE);
    1006           0 :         aVal <<= (sal_Int32)convertTwipToMm100(aData.GetHorzSpace());
    1007           0 :         pArray[6] = beans::PropertyValue("HoriMargin", -1, aVal, PropertyState_DIRECT_VALUE);
    1008           0 :         aVal <<= (sal_Int32)convertTwipToMm100(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(convertMm100ToTwip(nVal));
    1094             :             }
    1095           0 :             else if(sName.equalsAscii("RightMargin"))
    1096             :             {
    1097           0 :                 aData.SetRightSpace(convertMm100ToTwip(nVal));
    1098             :             }
    1099           0 :             else if(sName.equalsAscii("TopMargin"))
    1100             :             {
    1101           0 :                 aData.SetTopSpace(convertMm100ToTwip(nVal));
    1102             :             }
    1103           0 :             else if(sName.equalsAscii("BottomMargin"))
    1104             :             {
    1105           0 :                 aData.SetBottomSpace(convertMm100ToTwip(nVal));
    1106             :             }
    1107           0 :             else if(sName.equalsAscii("HoriMargin"))
    1108             :             {
    1109           0 :                 aData.SetHorzSpace(convertMm100ToTwip(nVal));
    1110             :             }
    1111           0 :             else if(sName.equalsAscii("VertMargin"))
    1112             :             {
    1113           0 :                 aData.SetVertSpace(convertMm100ToTwip(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           0 : Reference< XNameAccess >  SwXTextDocument::getReferenceMarks(void)
    1213             :                                         throw( RuntimeException, std::exception )
    1214             : {
    1215           0 :     SolarMutexGuard aGuard;
    1216           0 :     if(!IsValid())
    1217           0 :         throw RuntimeException();
    1218           0 :     if(!pxXReferenceMarks)
    1219             :     {
    1220           0 :         ((SwXTextDocument*)this)->pxXReferenceMarks = new Reference< XNameAccess > ;
    1221           0 :         *pxXReferenceMarks = new SwXReferenceMarks(pDocShell->GetDoc());
    1222             :     }
    1223           0 :     return *pxXReferenceMarks;
    1224             : }
    1225             : 
    1226           0 : Reference< XEnumerationAccess >  SwXTextDocument::getTextFields(void) throw( RuntimeException, std::exception )
    1227             : {
    1228           0 :     SolarMutexGuard aGuard;
    1229           0 :     if(!IsValid())
    1230           0 :         throw RuntimeException();
    1231           0 :     if(!pxXTextFieldTypes)
    1232             :     {
    1233           0 :         ((SwXTextDocument*)this)->pxXTextFieldTypes = new Reference< XEnumerationAccess > ;
    1234           0 :         *pxXTextFieldTypes = new SwXTextFieldTypes(pDocShell->GetDoc());
    1235             :     }
    1236           0 :     return *pxXTextFieldTypes;
    1237             : }
    1238             : 
    1239           0 : Reference< XNameAccess >  SwXTextDocument::getTextFieldMasters(void)
    1240             :     throw( RuntimeException, std::exception )
    1241             : {
    1242           0 :     SolarMutexGuard aGuard;
    1243           0 :     if(!IsValid())
    1244           0 :         throw RuntimeException();
    1245           0 :     if(!pxXTextFieldMasters)
    1246             :     {
    1247           0 :         ((SwXTextDocument*)this)->pxXTextFieldMasters = new Reference< XNameAccess > ;
    1248           0 :         *pxXTextFieldMasters = new SwXTextFieldMasters(pDocShell->GetDoc());
    1249             :     }
    1250           0 :     return *pxXTextFieldMasters;
    1251             : }
    1252             : 
    1253           0 : Reference< XNameAccess >  SwXTextDocument::getEmbeddedObjects(void) throw( RuntimeException, std::exception )
    1254             : {
    1255           0 :     SolarMutexGuard aGuard;
    1256           0 :     if(!IsValid())
    1257           0 :         throw RuntimeException();
    1258           0 :     if(!pxXEmbeddedObjects)
    1259             :     {
    1260           0 :         ((SwXTextDocument*)this)->pxXEmbeddedObjects = new Reference< XNameAccess > ;
    1261           0 :         *pxXEmbeddedObjects = new SwXTextEmbeddedObjects(pDocShell->GetDoc());
    1262             :     }
    1263           0 :     return *pxXEmbeddedObjects;
    1264             : }
    1265             : 
    1266           0 : Reference< XNameAccess >  SwXTextDocument::getBookmarks(void) throw( RuntimeException, std::exception )
    1267             : {
    1268           0 :     SolarMutexGuard aGuard;
    1269           0 :     if(!IsValid())
    1270           0 :         throw RuntimeException();
    1271           0 :     if(!pxXBookmarks)
    1272             :     {
    1273           0 :         ((SwXTextDocument*)this)->pxXBookmarks = new Reference< XNameAccess > ;
    1274           0 :         *pxXBookmarks = new SwXBookmarks(pDocShell->GetDoc());
    1275             :     }
    1276           0 :     return *pxXBookmarks;
    1277             : }
    1278             : 
    1279           0 : Reference< XNameAccess >  SwXTextDocument::getTextSections(void) throw( RuntimeException, std::exception )
    1280             : {
    1281           0 :     SolarMutexGuard aGuard;
    1282           0 :     if(!IsValid())
    1283           0 :         throw RuntimeException();
    1284           0 :     if(!pxXTextSections)
    1285             :     {
    1286           0 :         ((SwXTextDocument*)this)->pxXTextSections = new Reference< XNameAccess > ;
    1287           0 :         *pxXTextSections = new SwXTextSections(pDocShell->GetDoc());
    1288             :     }
    1289           0 :     return *pxXTextSections;
    1290             : }
    1291             : 
    1292           0 : Reference< XNameAccess >  SwXTextDocument::getTextTables(void) throw( RuntimeException, std::exception )
    1293             : {
    1294           0 :     SolarMutexGuard aGuard;
    1295           0 :     if(!IsValid())
    1296           0 :         throw RuntimeException();
    1297           0 :     if(!pxXTextTables)
    1298             :     {
    1299           0 :         ((SwXTextDocument*)this)->pxXTextTables = new Reference< XNameAccess > ;
    1300           0 :         *pxXTextTables = new SwXTextTables(pDocShell->GetDoc());
    1301             :     }
    1302           0 :     return *pxXTextTables;
    1303             : }
    1304             : 
    1305           0 : Reference< XNameAccess >  SwXTextDocument::getGraphicObjects(void) throw( RuntimeException, std::exception )
    1306             : {
    1307           0 :     SolarMutexGuard aGuard;
    1308           0 :     if(!IsValid())
    1309           0 :         throw RuntimeException();
    1310           0 :     if(!pxXGraphicObjects)
    1311             :     {
    1312           0 :         ((SwXTextDocument*)this)->pxXGraphicObjects = new Reference< XNameAccess > ;
    1313           0 :         *pxXGraphicObjects = new SwXTextGraphicObjects(pDocShell->GetDoc());
    1314             :     }
    1315           0 :     return *pxXGraphicObjects;
    1316             : }
    1317             : 
    1318           0 : Reference< XNameAccess >  SwXTextDocument::getTextFrames(void) throw( RuntimeException, std::exception )
    1319             : {
    1320           0 :     SolarMutexGuard aGuard;
    1321           0 :     if(!IsValid())
    1322           0 :         throw RuntimeException();
    1323           0 :     if(!pxXTextFrames)
    1324             :     {
    1325           0 :         ((SwXTextDocument*)this)->pxXTextFrames = new Reference< XNameAccess > ;
    1326           0 :         *pxXTextFrames = new SwXTextFrames(pDocShell->GetDoc());
    1327             :     }
    1328           0 :     return *pxXTextFrames;
    1329             : }
    1330             : 
    1331           0 : Reference< XNameAccess >  SwXTextDocument::getStyleFamilies(void) throw( RuntimeException, std::exception )
    1332             : {
    1333           0 :     SolarMutexGuard aGuard;
    1334           0 :     if(!IsValid())
    1335           0 :         throw RuntimeException();
    1336           0 :     if(!pxXStyleFamilies)
    1337             :     {
    1338           0 :         ((SwXTextDocument*)this)->pxXStyleFamilies = new Reference< XNameAccess > ;
    1339           0 :         *pxXStyleFamilies = new SwXStyleFamilies(*pDocShell);
    1340             :     }
    1341           0 :     return *pxXStyleFamilies;
    1342             : }
    1343             : 
    1344           0 : uno::Reference< style::XAutoStyles > SwXTextDocument::getAutoStyles(  )
    1345             :     throw (uno::RuntimeException, std::exception)
    1346             : {
    1347           0 :     SolarMutexGuard aGuard;
    1348           0 :     if(!IsValid())
    1349           0 :         throw RuntimeException();
    1350           0 :     if(!pxXAutoStyles)
    1351             :     {
    1352           0 :         pxXAutoStyles = new Reference< style::XAutoStyles > ;
    1353           0 :         *pxXAutoStyles = new SwXAutoStyles(*pDocShell);
    1354             :     }
    1355           0 :     return *pxXAutoStyles;
    1356             : 
    1357             : }
    1358             : 
    1359           0 : Reference< drawing::XDrawPage >  SwXTextDocument::getDrawPage(void) throw( RuntimeException, std::exception )
    1360             : {
    1361           0 :     SolarMutexGuard aGuard;
    1362           0 :     if(!IsValid())
    1363           0 :         throw RuntimeException();
    1364           0 :     if(!pxXDrawPage)
    1365             :     {
    1366           0 :         ((SwXTextDocument*)this)->pDrawPage = new SwXDrawPage(pDocShell->GetDoc());
    1367           0 :         ((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           0 :         uno::Reference<lang::XComponent> xComp( *pxXDrawPage, uno::UNO_QUERY );
    1373             :     }
    1374           0 :     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           0 : void SwXTextDocument::Invalidate()
    1387             : {
    1388           0 :     bObjectValid = sal_False;
    1389           0 :     if(xNumFmtAgg.is())
    1390             :     {
    1391           0 :         const uno::Type& rTunnelType = ::getCppuType((Reference <XUnoTunnel>*)0);
    1392           0 :         Any aNumTunnel = xNumFmtAgg->queryAggregation(rTunnelType);
    1393           0 :         SvNumberFormatsSupplierObj* pNumFmt = 0;
    1394           0 :         Reference< XUnoTunnel > xNumTunnel;
    1395           0 :         if(aNumTunnel >>= xNumTunnel)
    1396             :         {
    1397             :             pNumFmt = reinterpret_cast<SvNumberFormatsSupplierObj*>(
    1398           0 :                     xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
    1399           0 :             pNumFmt->SetNumberFormatter(0);
    1400             :         }
    1401           0 :         OSL_ENSURE(pNumFmt, "No number formatter available");
    1402             :     }
    1403           0 :     InitNewDoc();
    1404           0 :     pDocShell = 0;
    1405           0 :     lang::EventObject const ev(static_cast<SwXTextDocumentBaseClass &>(*this));
    1406           0 :     m_pImpl->m_RefreshListeners.disposeAndClear(ev);
    1407           0 : }
    1408             : 
    1409           0 : void SwXTextDocument::Reactivate(SwDocShell* pNewDocShell)
    1410             : {
    1411           0 :     if(pDocShell && pDocShell != pNewDocShell)
    1412           0 :         Invalidate();
    1413           0 :     pDocShell = pNewDocShell;
    1414           0 :     bObjectValid = sal_True;
    1415           0 : }
    1416             : 
    1417           0 : void    SwXTextDocument::InitNewDoc()
    1418             : {
    1419             :     // first invalidate all collections, then delete references and Set to zero
    1420           0 :     if(pxXTextTables)
    1421             :     {
    1422           0 :          XNameAccess* pTbls = pxXTextTables->get();
    1423           0 :         ((SwXTextTables*)pTbls)->Invalidate();
    1424           0 :         delete pxXTextTables;
    1425           0 :         pxXTextTables = 0;
    1426             :     }
    1427             : 
    1428           0 :     if(pxXTextFrames)
    1429             :     {
    1430           0 :          XNameAccess* pFrms = pxXTextFrames->get();
    1431           0 :         ((SwXTextFrames*)pFrms)->Invalidate();
    1432           0 :         delete pxXTextFrames;
    1433           0 :         pxXTextFrames = 0;
    1434             :     }
    1435             : 
    1436           0 :     if(pxXGraphicObjects)
    1437             :     {
    1438           0 :          XNameAccess* pFrms = pxXGraphicObjects->get();
    1439           0 :         ((SwXTextGraphicObjects*)pFrms)->Invalidate();
    1440           0 :         delete pxXGraphicObjects;
    1441           0 :         pxXGraphicObjects = 0;
    1442             :     }
    1443             : 
    1444           0 :     if(pxXEmbeddedObjects)
    1445             :     {
    1446           0 :      XNameAccess* pOLE = pxXEmbeddedObjects->get();
    1447           0 :         ((SwXTextEmbeddedObjects*)pOLE)->Invalidate();
    1448           0 :         delete pxXEmbeddedObjects;
    1449           0 :         pxXEmbeddedObjects = 0;
    1450             :     }
    1451             : 
    1452           0 :     if(xBodyText.is())
    1453             :     {
    1454           0 :         xBodyText = 0;
    1455           0 :         pBodyText = 0;
    1456             :     }
    1457             : 
    1458           0 :     if(xNumFmtAgg.is())
    1459             :     {
    1460           0 :         const uno::Type& rTunnelType = ::getCppuType((Reference <XUnoTunnel>*)0);
    1461           0 :         Any aNumTunnel = xNumFmtAgg->queryAggregation(rTunnelType);
    1462           0 :         SvNumberFormatsSupplierObj* pNumFmt = 0;
    1463           0 :         Reference< XUnoTunnel > xNumTunnel;
    1464           0 :         if(aNumTunnel >>= xNumTunnel)
    1465             :         {
    1466             :             pNumFmt = reinterpret_cast<SvNumberFormatsSupplierObj*>(
    1467           0 :                     xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
    1468             : 
    1469             :         }
    1470             :         OSL_ENSURE(pNumFmt, "No number formatter available");
    1471           0 :         if (pNumFmt)
    1472           0 :             pNumFmt->SetNumberFormatter(0);
    1473             :     }
    1474             : 
    1475           0 :     if(pxXTextFieldTypes)
    1476             :     {
    1477           0 :          XEnumerationAccess* pT = pxXTextFieldTypes->get();
    1478           0 :         ((SwXTextFieldTypes*)pT)->Invalidate();
    1479           0 :         delete pxXTextFieldTypes;
    1480           0 :         pxXTextFieldTypes = 0;
    1481             :     }
    1482             : 
    1483           0 :     if(pxXTextFieldMasters)
    1484             :     {
    1485           0 :          XNameAccess* pT = pxXTextFieldMasters->get();
    1486           0 :         ((SwXTextFieldMasters*)pT)->Invalidate();
    1487           0 :         delete pxXTextFieldMasters;
    1488           0 :         pxXTextFieldMasters = 0;
    1489             :     }
    1490             : 
    1491           0 :     if(pxXTextSections)
    1492             :     {
    1493           0 :          XNameAccess* pSect = pxXTextSections->get();
    1494           0 :         ((SwXTextSections*)pSect)->Invalidate();
    1495           0 :         delete pxXTextSections;
    1496           0 :         pxXTextSections = 0;
    1497             :     }
    1498             : 
    1499           0 :     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           0 :         uno::Reference<lang::XComponent> xComp( *pxXDrawPage, uno::UNO_QUERY );
    1504           0 :         xComp->dispose();
    1505           0 :         pDrawPage->InvalidateSwDoc();
    1506           0 :         delete pxXDrawPage;
    1507           0 :         pxXDrawPage = 0;
    1508             :     }
    1509             : 
    1510           0 :     if ( pxXNumberingRules )
    1511             :     {
    1512           0 :         XIndexAccess* pNum = pxXNumberingRules->get();
    1513           0 :         ((SwXNumberingRulesCollection*)pNum)->Invalidate();
    1514           0 :         delete pxXNumberingRules;
    1515           0 :         pxXNumberingRules = 0;
    1516             :     }
    1517             : 
    1518           0 :     if(pxXFootnotes)
    1519             :     {
    1520           0 :          XIndexAccess* pFtn = pxXFootnotes->get();
    1521           0 :         ((SwXFootnotes*)pFtn)->Invalidate();
    1522           0 :         delete pxXFootnotes;
    1523           0 :         pxXFootnotes = 0;
    1524             :     }
    1525             : 
    1526           0 :     if(pxXEndnotes)
    1527             :     {
    1528           0 :          XIndexAccess* pFtn = pxXEndnotes->get();
    1529           0 :         ((SwXFootnotes*)pFtn)->Invalidate();
    1530           0 :         delete pxXEndnotes;
    1531           0 :         pxXEndnotes = 0;
    1532             :     }
    1533             : 
    1534           0 :     if(pxXDocumentIndexes)
    1535             :     {
    1536           0 :          XIndexAccess* pIdxs = pxXDocumentIndexes->get();
    1537           0 :         ((SwXDocumentIndexes*)pIdxs)->Invalidate();
    1538           0 :         delete pxXDocumentIndexes;
    1539           0 :         pxXDocumentIndexes = 0;
    1540             :     }
    1541             : 
    1542           0 :     if(pxXStyleFamilies)
    1543             :     {
    1544           0 :          XNameAccess* pStyles = pxXStyleFamilies->get();
    1545           0 :         ((SwXStyleFamilies*)pStyles)->Invalidate();
    1546           0 :         delete pxXStyleFamilies;
    1547           0 :         pxXStyleFamilies = 0;
    1548             :     }
    1549           0 :     if(pxXAutoStyles)
    1550             :     {
    1551           0 :          XNameAccess* pStyles = pxXAutoStyles->get();
    1552           0 :         ((SwXAutoStyles*)pStyles)->Invalidate();
    1553           0 :         delete pxXAutoStyles;
    1554           0 :         pxXAutoStyles = 0;
    1555             :     }
    1556             : 
    1557           0 :     if(pxXBookmarks)
    1558             :     {
    1559           0 :          XNameAccess* pBm = pxXBookmarks->get();
    1560           0 :         ((SwXBookmarks*)pBm)->Invalidate();
    1561           0 :         delete pxXBookmarks;
    1562           0 :         pxXBookmarks = 0;
    1563             :     }
    1564             : 
    1565           0 :     if(pxXChapterNumbering)
    1566             :     {
    1567           0 :          XIndexReplace* pCh = pxXChapterNumbering->get();
    1568           0 :         ((SwXChapterNumbering*)pCh)->Invalidate();
    1569           0 :         delete pxXChapterNumbering;
    1570           0 :         pxXChapterNumbering = 0;
    1571             :     }
    1572             : 
    1573           0 :     if(pxXFootnoteSettings)
    1574             :     {
    1575           0 :          XPropertySet* pFntSet = pxXFootnoteSettings->get();
    1576           0 :         ((SwXFootnoteProperties*)pFntSet)->Invalidate();
    1577           0 :         delete pxXFootnoteSettings;
    1578           0 :         pxXFootnoteSettings = 0;
    1579             :     }
    1580             : 
    1581           0 :     if(pxXEndnoteSettings)
    1582             :     {
    1583           0 :          XPropertySet* pEndSet = pxXEndnoteSettings->get();
    1584           0 :         ((SwXEndnoteProperties*)pEndSet)->Invalidate();
    1585           0 :         delete pxXEndnoteSettings;
    1586           0 :         pxXEndnoteSettings = 0;
    1587             :     }
    1588             : 
    1589           0 :     if(pxXLineNumberingProperties)
    1590             :     {
    1591           0 :          XPropertySet* pLine = pxXLineNumberingProperties->get();
    1592           0 :         ((SwXLineNumberingProperties*)pLine)->Invalidate();
    1593           0 :         delete pxXLineNumberingProperties;
    1594           0 :         pxXLineNumberingProperties = 0;
    1595             :     }
    1596           0 :     if(pxXReferenceMarks)
    1597             :     {
    1598           0 :          XNameAccess* pMarks = pxXReferenceMarks->get();
    1599           0 :         ((SwXReferenceMarks*)pMarks)->Invalidate();
    1600           0 :         delete pxXReferenceMarks;
    1601           0 :         pxXReferenceMarks = 0;
    1602             :     }
    1603           0 :     if(pxLinkTargetSupplier)
    1604             :     {
    1605           0 :          XNameAccess* pAccess = (*pxLinkTargetSupplier).get();
    1606           0 :         ((SwXLinkTargetSupplier*)pAccess)->Invalidate();
    1607           0 :         delete pxLinkTargetSupplier;
    1608           0 :         pxLinkTargetSupplier = 0;
    1609             :     }
    1610           0 :     if(pxXRedlines)
    1611             :     {
    1612           0 :         XEnumerationAccess* pMarks = pxXRedlines->get();
    1613           0 :         ((SwXRedlines*)pMarks)->Invalidate();
    1614           0 :         delete pxXRedlines;
    1615           0 :         pxXRedlines = 0;
    1616             :     }
    1617           0 :     if(xPropertyHelper.is())
    1618             :     {
    1619           0 :         pPropertyHelper->Invalidate();
    1620           0 :         xPropertyHelper = 0;
    1621           0 :         pPropertyHelper = 0;
    1622             :     }
    1623           0 : }
    1624             : 
    1625           0 : css::uno::Reference<css::uno::XInterface> SwXTextDocument::create(
    1626             :     OUString const & rServiceName,
    1627             :     css::uno::Sequence<css::uno::Any> const * arguments)
    1628             : {
    1629           0 :     SolarMutexGuard aGuard;
    1630           0 :     if (!IsValid())
    1631             :     {
    1632           0 :         throw RuntimeException();
    1633             :     }
    1634           0 :     sal_uInt16 nType = SwXServiceProvider::GetProviderType(rServiceName);
    1635           0 :     if (nType != SW_SERVICE_INVALID)
    1636             :     {
    1637           0 :         return SwXServiceProvider::MakeInstance(nType, pDocShell->GetDoc());
    1638             :     }
    1639           0 :     if (rServiceName == "com.sun.star.drawing.DashTable")
    1640             :     {
    1641           0 :         return GetPropertyHelper()->GetDrawTable(SW_CREATE_DASH_TABLE);
    1642             :     }
    1643           0 :     if (rServiceName == "com.sun.star.drawing.GradientTable")
    1644             :     {
    1645           0 :         return GetPropertyHelper()->GetDrawTable(SW_CREATE_GRADIENT_TABLE);
    1646             :     }
    1647           0 :     if (rServiceName == "com.sun.star.drawing.HatchTable")
    1648             :     {
    1649           0 :         return GetPropertyHelper()->GetDrawTable(SW_CREATE_HATCH_TABLE);
    1650             :     }
    1651           0 :     if (rServiceName == "com.sun.star.drawing.BitmapTable")
    1652             :     {
    1653           0 :         return GetPropertyHelper()->GetDrawTable(SW_CREATE_BITMAP_TABLE);
    1654             :     }
    1655           0 :     if (rServiceName == "com.sun.star.drawing.TransparencyGradientTable")
    1656             :     {
    1657           0 :         return GetPropertyHelper()->GetDrawTable(SW_CREATE_TRANSGRADIENT_TABLE);
    1658             :     }
    1659           0 :     if (rServiceName == "com.sun.star.drawing.MarkerTable")
    1660             :     {
    1661           0 :         return GetPropertyHelper()->GetDrawTable(SW_CREATE_MARKER_TABLE);
    1662             :     }
    1663           0 :     if (rServiceName == "com.sun.star.drawing.Defaults")
    1664             :     {
    1665           0 :         return GetPropertyHelper()->GetDrawTable(SW_CREATE_DRAW_DEFAULTS);
    1666             :     }
    1667           0 :     if (rServiceName == "com.sun.star.document.Settings")
    1668             :     {
    1669           0 :         return Reference<XInterface>(*new SwXDocumentSettings(this));
    1670             :     }
    1671           0 :     if (rServiceName == "com.sun.star.document.ImportEmbeddedObjectResolver")
    1672             :     {
    1673             :         return static_cast<cppu::OWeakObject *>(
    1674             :             new SvXMLEmbeddedObjectHelper(
    1675           0 :                 *pDocShell, EMBEDDEDOBJECTHELPER_MODE_READ));
    1676             :     }
    1677           0 :     if (rServiceName == "com.sun.star.text.DocumentSettings")
    1678             :     {
    1679           0 :         return Reference<XInterface>(*new SwXDocumentSettings(this));
    1680             :     }
    1681           0 :     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           0 :     if (!rServiceName.startsWith("com.sun.star.")
    1689           0 :         || 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           0 :     OUString aTmpServiceName(rServiceName);
    1702           0 :     if (rServiceName == "com.sun.star.drawing.temporaryForXMLImportOLE2Shape")
    1703             :     {
    1704           0 :         aTmpServiceName = "com.sun.star.drawing.OLE2Shape";
    1705             :     }
    1706             :     Reference<XInterface> xTmp(
    1707             :         arguments == 0
    1708             :         ? SvxFmMSFactory::createInstance(aTmpServiceName)
    1709             :         : SvxFmMSFactory::createInstanceWithArguments(
    1710           0 :             aTmpServiceName, *arguments));
    1711           0 :     if (rServiceName == "com.sun.star.drawing.GroupShape"
    1712           0 :         || rServiceName == "com.sun.star.drawing.Shape3DSceneObject")
    1713             :     {
    1714           0 :         return *new SwXGroupShape(xTmp);
    1715             :     }
    1716           0 :     if (rServiceName.startsWith("com.sun.star.drawing."))
    1717             :     {
    1718           0 :         return *new SwXShape(xTmp);
    1719             :     }
    1720           0 :     return xTmp;
    1721             : }
    1722             : 
    1723           0 : Reference< XInterface >  SwXTextDocument::createInstance(const OUString& rServiceName)
    1724             :                                         throw( Exception, RuntimeException, std::exception )
    1725             : {
    1726           0 :     return create(rServiceName, 0);
    1727             : }
    1728             : 
    1729           0 : Reference< XInterface >  SwXTextDocument::createInstanceWithArguments(
    1730             :         const OUString& ServiceSpecifier,
    1731             :         const Sequence< Any >& Arguments)
    1732             :         throw( Exception, RuntimeException, std::exception )
    1733             : {
    1734           0 :     return create(ServiceSpecifier, &Arguments);
    1735             : }
    1736             : 
    1737           0 : Sequence< OUString > SwXTextDocument::getAvailableServiceNames(void)
    1738             :                                         throw( RuntimeException, std::exception )
    1739             : {
    1740           0 :     static Sequence< OUString > aServices;
    1741           0 :     if ( aServices.getLength() == 0 )
    1742             :     {
    1743           0 :         Sequence< OUString > aRet =  SvxFmMSFactory::getAvailableServiceNames();
    1744           0 :         OUString* pRet = aRet.getArray();
    1745           0 :         for ( sal_Int32 i = 0; i < aRet.getLength(); ++i )
    1746             :         {
    1747           0 :             if ( pRet[i].equalsAscii( "com.sun.star.drawing.OLE2Shape" ) )
    1748             :             {
    1749           0 :                 pRet[i] = pRet[aRet.getLength() - 1];
    1750           0 :                 aRet.realloc( aRet.getLength() - 1 ); // <pRet> no longer valid.
    1751           0 :                 break;
    1752             :             }
    1753             :         }
    1754           0 :         Sequence< OUString > aOwn = SwXServiceProvider::GetAllServiceNames();
    1755           0 :         aServices = SvxFmMSFactory::concatServiceNames(aRet, aOwn);
    1756             :     }
    1757             : 
    1758           0 :     return aServices;
    1759             : }
    1760             : 
    1761           0 : OUString SwXTextDocument::getImplementationName(void) throw( RuntimeException, std::exception )
    1762             : {
    1763           0 :     return OUString("SwXTextDocument");
    1764             : }
    1765             : 
    1766           0 : sal_Bool SwXTextDocument::supportsService(const OUString& rServiceName) throw( RuntimeException, std::exception )
    1767             : {
    1768           0 :     return cppu::supportsService(this, rServiceName);
    1769             : }
    1770             : 
    1771           0 : Sequence< OUString > SwXTextDocument::getSupportedServiceNames(void) throw( RuntimeException, std::exception )
    1772             : {
    1773           0 :     bool bWebDoc    = (0 != PTR_CAST(SwWebDocShell,    pDocShell));
    1774           0 :     bool bGlobalDoc = (0 != PTR_CAST(SwGlobalDocShell, pDocShell));
    1775           0 :     bool bTextDoc   = (!bWebDoc && !bGlobalDoc);
    1776             : 
    1777           0 :     Sequence< OUString > aRet (3);
    1778           0 :     OUString* pArray = aRet.getArray();
    1779             : 
    1780           0 :     pArray[0] = OUString ( ( "com.sun.star.document.OfficeDocument"  ) );
    1781           0 :     pArray[1] = OUString ( ( "com.sun.star.text.GenericTextDocument" ) );
    1782             : 
    1783           0 :     if (bTextDoc)
    1784           0 :         pArray[2] = OUString ( ( "com.sun.star.text.TextDocument" ) );
    1785           0 :     else if (bWebDoc)
    1786           0 :         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           0 :     return aRet;
    1791             : }
    1792             : 
    1793           0 : Reference< XIndexAccess >  SwXTextDocument::getDocumentIndexes(void) throw( RuntimeException, std::exception )
    1794             : {
    1795           0 :     SolarMutexGuard aGuard;
    1796           0 :     if(!IsValid())
    1797           0 :         throw RuntimeException();
    1798           0 :     if(!pxXDocumentIndexes)
    1799             :     {
    1800           0 :         ((SwXTextDocument*)this)->pxXDocumentIndexes = new Reference< XIndexAccess > ;
    1801           0 :         *pxXDocumentIndexes = new SwXDocumentIndexes(pDocShell->GetDoc());
    1802             :     }
    1803           0 :     return *pxXDocumentIndexes;
    1804             : }
    1805             : 
    1806           0 : Reference< XPropertySetInfo >  SwXTextDocument::getPropertySetInfo(void) throw( RuntimeException, std::exception )
    1807             : {
    1808           0 :     static Reference< XPropertySetInfo >  xRet = pPropSet->getPropertySetInfo();
    1809           0 :     return xRet;
    1810             : }
    1811             : 
    1812           0 : void SwXTextDocument::setPropertyValue(const OUString& rPropertyName, const Any& aValue)
    1813             :     throw (UnknownPropertyException, PropertyVetoException,
    1814             :            IllegalArgumentException, WrappedTargetException,
    1815             :            RuntimeException, std::exception)
    1816             : {
    1817           0 :     SolarMutexGuard aGuard;
    1818           0 :     if(!IsValid())
    1819             :         throw RuntimeException(
    1820             :             "invalid SwXTextDocument",
    1821             :             static_cast< cppu::OWeakObject * >(
    1822           0 :                 static_cast< SwXTextDocumentBaseClass * >(this)));
    1823           0 :     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
    1824             : 
    1825           0 :     if(!pEntry)
    1826           0 :         throw UnknownPropertyException();
    1827           0 :     if(pEntry->nFlags & PropertyAttribute::READONLY)
    1828           0 :         throw PropertyVetoException();
    1829           0 :     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           0 :             OUString sDelim;
    1841           0 :             aValue >>= sDelim;
    1842           0 :             SW_MOD()->GetModuleConfig()->SetWordDelimiter(sDelim);
    1843             :         }
    1844           0 :         break;
    1845             :         case WID_DOC_CHANGES_RECORD:
    1846             :         case WID_DOC_CHANGES_SHOW:
    1847             :         {
    1848           0 :             sal_Bool bSet = *(sal_Bool*)aValue.getValue();
    1849           0 :             sal_uInt16 eMode = pDocShell->GetDoc()->GetRedlineMode();
    1850           0 :             if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
    1851             :             {
    1852           0 :                 eMode &= ~(nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE);
    1853           0 :                 eMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT;
    1854           0 :                 if( bSet )
    1855           0 :                     eMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE;
    1856             :             }
    1857           0 :             else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
    1858             :             {
    1859           0 :                 eMode = bSet ? eMode|nsRedlineMode_t::REDLINE_ON : eMode&~nsRedlineMode_t::REDLINE_ON;
    1860             :             }
    1861           0 :             pDocShell->GetDoc()->SetRedlineMode( (RedlineMode_t)(eMode ));
    1862             :         }
    1863           0 :         break;
    1864             :         case  WID_DOC_CHANGES_PASSWORD:
    1865             :         {
    1866           0 :             Sequence <sal_Int8> aNew;
    1867           0 :             if(aValue >>= aNew)
    1868             :             {
    1869           0 :                 SwDoc* pDoc = pDocShell->GetDoc();
    1870           0 :                 pDoc->SetRedlinePassword(aNew);
    1871           0 :                 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           0 :             }
    1878             :         }
    1879           0 :         break;
    1880             :         case WID_DOC_AUTO_MARK_URL :
    1881             :         {
    1882           0 :             OUString sURL;
    1883           0 :             aValue >>= sURL;
    1884           0 :             pDocShell->GetDoc()->SetTOIAutoMarkURL(sURL);
    1885             :         }
    1886           0 :         break;
    1887             :         case WID_DOC_HIDE_TIPS :
    1888           0 :             SW_MOD()->GetModuleConfig()->SetHideFieldTips(*(sal_Bool*)aValue.getValue());
    1889           0 :         break;
    1890             :         case WID_DOC_REDLINE_DISPLAY:
    1891             :         {
    1892           0 :             sal_Int16 eRedMode = pDocShell->GetDoc()->GetRedlineMode();
    1893           0 :             eRedMode = eRedMode & (~nsRedlineMode_t::REDLINE_SHOW_MASK);
    1894           0 :             sal_Int16 nSet = 0;
    1895           0 :             aValue >>= nSet;
    1896           0 :             switch(nSet)
    1897             :             {
    1898           0 :                 case RedlineDisplayType::NONE: break;
    1899           0 :                 case RedlineDisplayType::INSERTED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT; break;
    1900           0 :                 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           0 :             pDocShell->GetDoc()->SetRedlineMode(eRedMode);
    1907             :         }
    1908           0 :         break;
    1909             :         case WID_DOC_TWO_DIGIT_YEAR:
    1910             :         {
    1911           0 :             sal_Int16 nYear = 0;
    1912           0 :             aValue >>= nYear;
    1913           0 :             SfxRequest aRequest ( SID_ATTR_YEAR2000, SFX_CALLMODE_SLOT, pDocShell->GetDoc()->GetAttrPool());
    1914           0 :             aRequest.AppendItem(SfxUInt16Item( SID_ATTR_YEAR2000, static_cast < sal_uInt16 > ( nYear ) ) );
    1915           0 :             pDocShell->Execute ( aRequest );
    1916             :         }
    1917           0 :         break;
    1918             :         case WID_DOC_AUTOMATIC_CONTROL_FOCUS:
    1919             :         {
    1920             :             SwDrawDocument * pDrawDoc;
    1921           0 :             sal_Bool bAuto = *(sal_Bool*) aValue.getValue();
    1922             : 
    1923           0 :             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * >( pDocShell->GetDoc()->GetDrawModel() ) ) )
    1924           0 :                 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           0 :         break;
    1938             :         case WID_DOC_APPLY_FORM_DESIGN_MODE:
    1939             :         {
    1940             :             SwDrawDocument * pDrawDoc;
    1941           0 :             sal_Bool bMode = *(sal_Bool*)aValue.getValue();
    1942             : 
    1943           0 :             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetDrawModel() ) ) )
    1944           0 :                 pDrawDoc->SetOpenInDesignMode( bMode );
    1945           0 :             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           0 :                 pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetOrCreateDrawModel() );
    1955           0 :                 pDrawDoc->SetOpenInDesignMode ( bMode );
    1956             :             }
    1957             :         }
    1958           0 :         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           0 :             SwDoc* pDoc = pDocShell->GetDoc();
    1964           0 :             bool bBool (false);
    1965           0 :             if( aValue >>= bBool )
    1966           0 :               pDoc->SetInReading( bBool );
    1967             :         }
    1968           0 :         break;
    1969             :         case WID_DOC_BUILDID:
    1970           0 :             aValue >>= maBuildId;
    1971           0 :         break;
    1972             : 
    1973             :         case WID_DOC_DEFAULT_PAGE_MODE:
    1974             :         {
    1975           0 :             bool bDefaultPageMode( false );
    1976           0 :             aValue >>= bDefaultPageMode;
    1977           0 :             pDocShell->GetDoc()->SetDefaultPageMode( bDefaultPageMode );
    1978             :         }
    1979           0 :         break;
    1980             :         case WID_DOC_INTEROP_GRAB_BAG:
    1981           0 :              setGrabBagItem(aValue);
    1982           0 :         break;
    1983             : 
    1984             :         default:
    1985             :         {
    1986           0 :             const SfxPoolItem& rItem = pDocShell->GetDoc()->GetDefault(pEntry->nWID);
    1987           0 :             SfxPoolItem* pNewItem = rItem.Clone();
    1988           0 :             pNewItem->PutValue(aValue, pEntry->nMemberId);
    1989           0 :             pDocShell->GetDoc()->SetDefault(*pNewItem);
    1990           0 :             delete pNewItem;
    1991             :         }
    1992           0 :     }
    1993           0 : }
    1994             : 
    1995           0 : Any SwXTextDocument::getPropertyValue(const OUString& rPropertyName)
    1996             :     throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
    1997             : {
    1998           0 :     SolarMutexGuard aGuard;
    1999           0 :     if(!IsValid())
    2000           0 :         throw RuntimeException();
    2001           0 :     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
    2002             : 
    2003           0 :     if(!pEntry)
    2004           0 :         throw UnknownPropertyException();
    2005           0 :     Any aAny;
    2006           0 :     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           0 :             const SwDocStat& rStat(pDocShell->GetDoc()->GetUpdatedDocStat());
    2016             :             sal_Int32 nValue;
    2017           0 :             switch(pEntry->nWID)
    2018             :             {
    2019           0 :                 case  WID_DOC_CHAR_COUNT     :nValue = rStat.nChar;break;
    2020           0 :                 case  WID_DOC_PARA_COUNT     :nValue = rStat.nPara;break;
    2021           0 :                 case  WID_DOC_WORD_COUNT     :nValue = rStat.nWord;break;
    2022             :             }
    2023           0 :             aAny <<= nValue;
    2024             :         }
    2025           0 :         break;
    2026             :         case  WID_DOC_WORD_SEPARATOR :
    2027             :         {
    2028           0 :             aAny <<= SW_MOD()->GetDocStatWordDelim();
    2029             :         }
    2030           0 :         break;
    2031             :         case WID_DOC_CHANGES_RECORD:
    2032             :         case WID_DOC_CHANGES_SHOW:
    2033             :         {
    2034           0 :             sal_uInt16 eMode = pDocShell->GetDoc()->GetRedlineMode();
    2035           0 :             sal_Bool bSet = sal_False;
    2036           0 :             if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
    2037             :             {
    2038           0 :                 sal_uInt16 nMask = nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE;
    2039           0 :                 bSet = (eMode & nMask) == nMask;
    2040             :             }
    2041           0 :             else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
    2042             :             {
    2043           0 :                 bSet = (eMode& nsRedlineMode_t::REDLINE_ON)  != 0;
    2044             :             }
    2045           0 :             aAny.setValue(&bSet, ::getBooleanCppuType());
    2046             :         }
    2047           0 :         break;
    2048             :         case  WID_DOC_CHANGES_PASSWORD:
    2049             :         {
    2050           0 :             SwDoc* pDoc = pDocShell->GetDoc();
    2051           0 :             aAny <<= pDoc->GetRedlinePassword();
    2052             :         }
    2053           0 :         break;
    2054             :         case WID_DOC_AUTO_MARK_URL :
    2055           0 :             aAny <<= pDocShell->GetDoc()->GetTOIAutoMarkURL();
    2056           0 :         break;
    2057             :         case WID_DOC_HIDE_TIPS :
    2058             :         {
    2059           0 :             sal_Bool bTemp = SW_MOD()->GetModuleConfig()->IsHideFieldTips();
    2060           0 :             aAny.setValue(&bTemp, ::getBooleanCppuType());
    2061             :         }
    2062           0 :         break;
    2063             :         case WID_DOC_REDLINE_DISPLAY:
    2064             :         {
    2065           0 :             sal_Int16 eRedMode = pDocShell->GetDoc()->GetRedlineMode();
    2066           0 :             eRedMode = eRedMode & nsRedlineMode_t::REDLINE_SHOW_MASK;
    2067           0 :             sal_Int16 nRet = RedlineDisplayType::NONE;
    2068           0 :             if(nsRedlineMode_t::REDLINE_SHOW_INSERT == eRedMode)
    2069           0 :                 nRet = RedlineDisplayType::INSERTED;
    2070           0 :             else if(nsRedlineMode_t::REDLINE_SHOW_DELETE == eRedMode)
    2071           0 :                 nRet = RedlineDisplayType::REMOVED;
    2072           0 :             else if(nsRedlineMode_t::REDLINE_SHOW_MASK == eRedMode)
    2073           0 :                 nRet = RedlineDisplayType::INSERTED_AND_REMOVED;
    2074           0 :             aAny <<= nRet;
    2075             :         }
    2076           0 :         break;
    2077             :         case WID_DOC_FORBIDDEN_CHARS:
    2078             :         {
    2079           0 :             GetPropertyHelper();
    2080           0 :             Reference<XForbiddenCharacters> xRet(xPropertyHelper, UNO_QUERY);
    2081           0 :             aAny <<= xRet;
    2082             :         }
    2083           0 :         break;
    2084             :         case WID_DOC_TWO_DIGIT_YEAR:
    2085             :         {
    2086           0 :             aAny <<= static_cast < sal_Int16 > (pDocShell->GetDoc()->GetNumberFormatter ( sal_True )->GetYear2000());
    2087             :         }
    2088           0 :         break;
    2089             :         case WID_DOC_AUTOMATIC_CONTROL_FOCUS:
    2090             :         {
    2091             :             SwDrawDocument * pDrawDoc;
    2092             :             sal_Bool bAuto;
    2093           0 :             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetDrawModel() ) ) )
    2094           0 :                 bAuto = pDrawDoc->GetAutoControlFocus();
    2095             :             else
    2096           0 :                 bAuto = sal_False;
    2097           0 :             aAny.setValue(&bAuto, ::getBooleanCppuType());
    2098             :         }
    2099           0 :         break;
    2100             :         case WID_DOC_APPLY_FORM_DESIGN_MODE:
    2101             :         {
    2102             :             SwDrawDocument * pDrawDoc;
    2103             :             sal_Bool bMode;
    2104           0 :             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetDrawModel() ) ) )
    2105           0 :                 bMode = pDrawDoc->GetOpenInDesignMode();
    2106             :             else
    2107           0 :                 bMode = sal_True;
    2108           0 :             aAny.setValue(&bMode, ::getBooleanCppuType());
    2109             :         }
    2110           0 :         break;
    2111             :         case WID_DOC_BASIC_LIBRARIES:
    2112           0 :             aAny <<= pDocShell->GetBasicContainer();
    2113           0 :         break;
    2114             :         case WID_DOC_DIALOG_LIBRARIES:
    2115           0 :             aAny <<= pDocShell->GetDialogContainer();
    2116           0 :         break;
    2117             :         case WID_DOC_VBA_DOCOBJ:
    2118             :         {
    2119           0 :             beans::PropertyValue aProp;
    2120           0 :             aProp.Name = "ThisWordDoc";
    2121           0 :             aProp.Value <<= pDocShell->GetModel();
    2122           0 :             aAny <<= aProp;
    2123             :         }
    2124           0 :         break;
    2125             :         case WID_DOC_RUNTIME_UID:
    2126           0 :             aAny <<= getRuntimeUID();
    2127           0 :         break;
    2128             :         case WID_DOC_LOCK_UPDATES :
    2129           0 :             aAny <<= static_cast<bool>( pDocShell->GetDoc()->IsInReading() );
    2130           0 :         break;
    2131             :         case WID_DOC_BUILDID:
    2132           0 :             aAny <<= maBuildId;
    2133           0 :         break;
    2134             :         case WID_DOC_HAS_VALID_SIGNATURES:
    2135           0 :             aAny <<= hasValidSignatures();
    2136           0 :         break;
    2137             :         case WID_DOC_INTEROP_GRAB_BAG:
    2138           0 :              getGrabBagItem(aAny);
    2139           0 :         break;
    2140             : 
    2141             :         default:
    2142             :         {
    2143           0 :             const SfxPoolItem& rItem = pDocShell->GetDoc()->GetDefault(pEntry->nWID);
    2144           0 :             rItem.QueryValue(aAny, pEntry->nMemberId);
    2145             :         }
    2146             :     }
    2147           0 :     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           0 : Reference< XEnumerationAccess > SwXTextDocument::getRedlines(  ) throw(RuntimeException, std::exception)
    2189             : {
    2190           0 :     if(!pxXRedlines)
    2191             :     {
    2192           0 :         pxXRedlines = new Reference< XEnumerationAccess > ;
    2193           0 :         (*pxXRedlines) = new SwXRedlines(pDocShell->GetDoc());
    2194             :     }
    2195           0 :     return *pxXRedlines;
    2196             : }
    2197             : 
    2198           0 : 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           0 :     lang::EventObject const ev(static_cast<SwXTextDocumentBaseClass &>(*this));
    2203           0 :     m_pImpl->m_RefreshListeners.notifyEach(
    2204           0 :             & util::XRefreshListener::refreshed, ev);
    2205           0 : }
    2206             : 
    2207           0 : void SwXTextDocument::refresh(void) throw( RuntimeException, std::exception )
    2208             : {
    2209           0 :     SolarMutexGuard aGuard;
    2210           0 :     if(!IsValid())
    2211           0 :         throw RuntimeException();
    2212           0 :     SwViewShell *pViewShell = pDocShell->GetWrtShell();
    2213           0 :     NotifyRefreshListeners();
    2214           0 :     if(pViewShell)
    2215           0 :         pViewShell->CalcLayout();
    2216           0 : }
    2217             : 
    2218           0 : 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           0 :     m_pImpl->m_RefreshListeners.addInterface(xListener);
    2224           0 : }
    2225             : 
    2226           0 : 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           0 :     m_pImpl->m_RefreshListeners.removeInterface(xListener);
    2232           0 : }
    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 ( convertTwipToMm100( 2 * aTmpSize.Width() ),
    2769             :                                                      convertTwipToMm100( 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 ( convertTwipToMm100( aTmpSize.Width() ),
    2791           0 :                                     convertTwipToMm100( 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           0 : Reference<XNameContainer> SAL_CALL SwXTextDocument::getXForms()
    3078             :     throw( RuntimeException, std::exception )
    3079             : {
    3080           0 :     SolarMutexGuard aGuard;
    3081           0 :     if ( !pDocShell )
    3082           0 :         throw DisposedException( OUString(), static_cast< XTextDocument* >( this ) );
    3083           0 :     SwDoc* pDoc = pDocShell->GetDoc();
    3084           0 :     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           0 : void * SAL_CALL SwXTextDocument::operator new( size_t t) throw()
    3122             : {
    3123           0 :     return SwXTextDocumentBaseClass::operator new(t);
    3124             : }
    3125             : 
    3126           0 : void SAL_CALL SwXTextDocument::operator delete( void * p) throw()
    3127             : {
    3128           0 :     SwXTextDocumentBaseClass::operator delete(p);
    3129           0 : }
    3130             : 
    3131             : /**
    3132             :  * retrieve languages already used in current document
    3133             :  */
    3134           0 : 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           0 :     SolarMutexGuard aGuard;
    3142             : 
    3143             :     // possible canonical values for nScriptTypes
    3144             :     // any bit wise combination is allowed
    3145           0 :     const sal_Int16 nLatin   = 0x001;
    3146           0 :     const sal_Int16 nAsian   = 0x002;
    3147           0 :     const sal_Int16 nComplex = 0x004;
    3148             : 
    3149             :     // script types for which to get the languages
    3150           0 :     const bool bLatin   = 0 != (nScriptTypes & nLatin);
    3151           0 :     const bool bAsian   = 0 != (nScriptTypes & nAsian);
    3152           0 :     const bool bComplex = 0 != (nScriptTypes & nComplex);
    3153             : 
    3154           0 :     if (nScriptTypes < nLatin || nScriptTypes > (nLatin | nAsian | nComplex))
    3155           0 :         throw IllegalArgumentException("nScriptTypes ranges from 1 to 7!", Reference< XInterface >(), 1);
    3156           0 :     if (!pDocShell)
    3157           0 :         throw DisposedException();
    3158           0 :     SwDoc* pDoc = pDocShell->GetDoc();
    3159             : 
    3160             :     // avoid duplicate values
    3161           0 :     std::set< LanguageType > aAllLangs;
    3162             : 
    3163             :     //USER STYLES
    3164             : 
    3165           0 :     const SwCharFmts *pFmts = pDoc->GetCharFmts();
    3166           0 :     for(sal_uInt16 i = 0; i < pFmts->size(); ++i)
    3167             :     {
    3168           0 :         const SwAttrSet &rAttrSet = (*pFmts)[i]->GetAttrSet();
    3169           0 :         LanguageType nLang = LANGUAGE_DONTKNOW;
    3170           0 :         if (bLatin)
    3171             :         {
    3172           0 :             nLang = rAttrSet.GetLanguage( sal_False ).GetLanguage();
    3173           0 :             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
    3174           0 :                 aAllLangs.insert( nLang );
    3175             :         }
    3176           0 :         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           0 :         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           0 :     const SwTxtFmtColls *pColls = pDoc->GetTxtFmtColls();
    3191           0 :     for (sal_uInt16 i = 0; i < pColls->size(); ++i)
    3192             :     {
    3193           0 :         const SwAttrSet &rAttrSet = (*pColls)[i]->GetAttrSet();
    3194           0 :         LanguageType nLang = LANGUAGE_DONTKNOW;
    3195           0 :         if (bLatin)
    3196             :         {
    3197           0 :             nLang = rAttrSet.GetLanguage( sal_False ).GetLanguage();
    3198           0 :             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
    3199           0 :                 aAllLangs.insert( nLang );
    3200             :         }
    3201           0 :         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           0 :         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           0 :     };
    3221           0 :     for (sal_uInt16 i = 0; i < 2; ++i)
    3222             :     {
    3223           0 :         std::vector< SfxItemSet_Pointer_t > rStyles;
    3224           0 :         pDoc->GetIStyleAccess().getAllStyles(rStyles, aFam[i]);
    3225           0 :         while (!rStyles.empty())
    3226             :         {
    3227           0 :             SfxItemSet_Pointer_t pStyle = rStyles.back();
    3228           0 :             rStyles.pop_back();
    3229           0 :             const SfxItemSet *pSet = dynamic_cast< const SfxItemSet * >(pStyle.get());
    3230             : 
    3231           0 :             LanguageType nLang = LANGUAGE_DONTKNOW;
    3232           0 :             if (bLatin)
    3233             :             {
    3234           0 :                 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_LANGUAGE, false )).GetLanguage();
    3235           0 :                 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
    3236           0 :                     aAllLangs.insert( nLang );
    3237             :             }
    3238           0 :             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           0 :             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           0 :         }
    3251           0 :     }
    3252             : 
    3253             :     //TODO/mba: it's a strange concept that a view is needed to retrieve core data
    3254           0 :     SwWrtShell *pWrtSh = pDocShell->GetWrtShell();
    3255           0 :     SdrView *pSdrView = pWrtSh->GetDrawView();
    3256             : 
    3257           0 :     if( pSdrView )
    3258             :     {
    3259           0 :         SdrOutliner* pOutliner = pSdrView->GetTextEditOutliner();
    3260           0 :         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           0 :     if (nMaxCount > static_cast< sal_Int16 >( aAllLangs.size() ))
    3304           0 :         nMaxCount = static_cast< sal_Int16 >( aAllLangs.size() );
    3305             : 
    3306             :     // build return value
    3307           0 :     uno::Sequence< lang::Locale > aLanguages( nMaxCount );
    3308           0 :     lang::Locale* pLanguage = aLanguages.getArray();
    3309           0 :     if (nMaxCount > 0)
    3310             :     {
    3311           0 :         sal_Int32 nCount = 0;
    3312           0 :         const SvtLanguageTable aLangTab;
    3313           0 :         for (std::set< LanguageType >::const_iterator it = aAllLangs.begin(); it != aAllLangs.end(); ++it)
    3314             :         {
    3315           0 :             if (nCount >= nMaxCount)
    3316           0 :                 break;
    3317           0 :             if (LANGUAGE_NONE != *it)
    3318             :             {
    3319           0 :                 pLanguage[nCount] = LanguageTag::convertToLocale( *it );
    3320           0 :                 pLanguage[nCount].Language = aLangTab.GetString( *it );
    3321           0 :                 nCount += 1;
    3322             :             }
    3323           0 :         }
    3324             :     }
    3325             : 
    3326           0 :     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           0 : SwXDocumentPropertyHelper::SwXDocumentPropertyHelper(SwDoc& rDoc) :
    3843           0 : SvxUnoForbiddenCharsTable ( rDoc.getForbiddenCharacterTable() )
    3844           0 : ,m_pDoc(&rDoc)
    3845             : {
    3846           0 : }
    3847             : 
    3848           0 : SwXDocumentPropertyHelper::~SwXDocumentPropertyHelper()
    3849             : {
    3850           0 : }
    3851             : 
    3852           0 : Reference<XInterface> SwXDocumentPropertyHelper::GetDrawTable(short nWhich)
    3853             : {
    3854           0 :     Reference<XInterface> xRet;
    3855           0 :     if(m_pDoc)
    3856             :     {
    3857           0 :         switch(nWhich)
    3858             :         {
    3859             :             // #i52858#
    3860             :             // assure that Draw model is created, if it doesn't exist.
    3861             :             case SW_CREATE_DASH_TABLE         :
    3862           0 :                 if(!xDashTable.is())
    3863           0 :                     xDashTable = SvxUnoDashTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
    3864           0 :                 xRet = xDashTable;
    3865           0 :             break;
    3866             :             case SW_CREATE_GRADIENT_TABLE     :
    3867           0 :                 if(!xGradientTable.is())
    3868           0 :                     xGradientTable = SvxUnoGradientTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
    3869           0 :                 xRet = xGradientTable;
    3870           0 :             break;
    3871             :             case SW_CREATE_HATCH_TABLE        :
    3872           0 :                 if(!xHatchTable.is())
    3873           0 :                     xHatchTable = SvxUnoHatchTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
    3874           0 :                 xRet = xHatchTable;
    3875           0 :             break;
    3876             :             case SW_CREATE_BITMAP_TABLE       :
    3877           0 :                 if(!xBitmapTable.is())
    3878           0 :                     xBitmapTable = SvxUnoBitmapTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
    3879           0 :                 xRet = xBitmapTable;
    3880           0 :             break;
    3881             :             case SW_CREATE_TRANSGRADIENT_TABLE:
    3882           0 :                 if(!xTransGradientTable.is())
    3883           0 :                     xTransGradientTable = SvxUnoTransGradientTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
    3884           0 :                 xRet = xTransGradientTable;
    3885           0 :             break;
    3886             :             case SW_CREATE_MARKER_TABLE       :
    3887           0 :                 if(!xMarkerTable.is())
    3888           0 :                     xMarkerTable = SvxUnoMarkerTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
    3889           0 :                 xRet = xMarkerTable;
    3890           0 :             break;
    3891             :             case  SW_CREATE_DRAW_DEFAULTS:
    3892           0 :                 if(!xDrawDefaults.is())
    3893           0 :                     xDrawDefaults = (cppu::OWeakObject*)new SwSvxUnoDrawPool(m_pDoc);
    3894           0 :                 xRet = xDrawDefaults;
    3895           0 :             break;
    3896             : #if OSL_DEBUG_LEVEL > 0
    3897             :             default: OSL_FAIL("which table?");
    3898             : #endif
    3899             :         }
    3900             :     }
    3901           0 :     return xRet;
    3902             : }
    3903             : 
    3904           0 : void SwXDocumentPropertyHelper::Invalidate()
    3905             : {
    3906           0 :     xDashTable = 0;
    3907           0 :     xGradientTable = 0;
    3908           0 :     xHatchTable = 0;
    3909           0 :     xBitmapTable = 0;
    3910           0 :     xTransGradientTable = 0;
    3911           0 :     xMarkerTable = 0;
    3912           0 :     xDrawDefaults = 0;
    3913           0 :     m_pDoc = 0;
    3914           0 :     SvxUnoForbiddenCharsTable::mxForbiddenChars.clear();
    3915           0 : }
    3916             : 
    3917           0 : void SwXDocumentPropertyHelper::onChange()
    3918             : {
    3919           0 :     if(m_pDoc)
    3920           0 :        m_pDoc->SetModified();
    3921           0 : }
    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