LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/uno - unotxdoc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 626 2080 30.1 %
Date: 2012-12-17 Functions: 64 161 39.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10