LCOV - code coverage report
Current view: top level - libreoffice/writerfilter/source/dmapper - DomainMapper_Impl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1307 1846 70.8 %
Date: 2012-12-27 Functions: 109 123 88.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <DomainMapper_Impl.hxx>
      21             : #include <ConversionHelper.hxx>
      22             : #include <DomainMapperTableHandler.hxx>
      23             : #include <com/sun/star/uno/XComponentContext.hpp>
      24             : #include <com/sun/star/graphic/XGraphic.hpp>
      25             : #include <com/sun/star/beans/XPropertyState.hpp>
      26             : #include <com/sun/star/container/XNamed.hpp>
      27             : #include <com/sun/star/document/PrinterIndependentLayout.hpp>
      28             : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      29             : #include <com/sun/star/lang/XServiceInfo.hpp>
      30             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      31             : #include <com/sun/star/style/LineNumberPosition.hpp>
      32             : #include <com/sun/star/style/LineSpacing.hpp>
      33             : #include <com/sun/star/style/LineSpacingMode.hpp>
      34             : #include <com/sun/star/text/ChapterFormat.hpp>
      35             : #include <com/sun/star/text/FilenameDisplayFormat.hpp>
      36             : #include <com/sun/star/text/SetVariableType.hpp>
      37             : #include <com/sun/star/text/XFootnote.hpp>
      38             : #include <com/sun/star/text/XLineNumberingProperties.hpp>
      39             : #include <com/sun/star/text/PageNumberType.hpp>
      40             : #include <com/sun/star/text/HoriOrientation.hpp>
      41             : #include <com/sun/star/text/VertOrientation.hpp>
      42             : #include <com/sun/star/text/ReferenceFieldPart.hpp>
      43             : #include <com/sun/star/text/ReferenceFieldSource.hpp>
      44             : #include <com/sun/star/text/SizeType.hpp>
      45             : #include <com/sun/star/text/TextContentAnchorType.hpp>
      46             : #include <com/sun/star/text/WrapTextMode.hpp>
      47             : #include <com/sun/star/text/XDependentTextField.hpp>
      48             : #include <com/sun/star/text/XParagraphCursor.hpp>
      49             : #include <com/sun/star/text/XRedline.hpp>
      50             : #include <com/sun/star/text/XTextFieldsSupplier.hpp>
      51             : #include <com/sun/star/style/DropCapFormat.hpp>
      52             : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      53             : #include <com/sun/star/document/XViewDataSupplier.hpp>
      54             : #include <com/sun/star/container/XIndexContainer.hpp>
      55             : #include <oox/mathml/import.hxx>
      56             : 
      57             : #ifdef DEBUG_DOMAINMAPPER
      58             : #include <resourcemodel/QNameToString.hxx>
      59             : #include <resourcemodel/util.hxx>
      60             : #include <dmapperLoggers.hxx>
      61             : #endif
      62             : #include <ooxml/OOXMLFastTokens.hxx>
      63             : 
      64             : #if DEBUG
      65             : #include <stdio.h>
      66             : #include <com/sun/star/style/TabStop.hpp>
      67             : #endif
      68             : 
      69             : #include <map>
      70             : 
      71             : #include <comphelper/configurationhelper.hxx>
      72             : #include <comphelper/stlunosequence.hxx>
      73             : 
      74             : using namespace ::com::sun::star;
      75             : using namespace ::rtl;
      76             : namespace writerfilter {
      77             : namespace dmapper{
      78             : 
      79         223 : sal_Bool lcl_IsUsingEnhancedFields( const uno::Reference< uno::XComponentContext >& rxContext )
      80             : {
      81         223 :     bool bResult(sal_False);
      82             :     try
      83             :     {
      84         223 :         OUString writerConfig = "org.openoffice.Office.Common";
      85             : 
      86         223 :         uno::Reference< uno::XInterface > xCfgAccess = ::comphelper::ConfigurationHelper::openConfig( rxContext, writerConfig, ::comphelper::ConfigurationHelper::E_READONLY );
      87         223 :         ::comphelper::ConfigurationHelper::readRelativeKey( xCfgAccess, OUString( "Filter/Microsoft/Import"  ), OUString( "ImportWWFieldsAsEnhancedFields"  ) ) >>= bResult;
      88             : 
      89             :     }
      90           0 :     catch( const uno::Exception& )
      91             :     {
      92             :     }
      93         223 :     return bResult;
      94             : }
      95             : 
      96             : // Populate Dropdown Field properties from FFData structure
      97           0 : void lcl_handleDropdownField( const uno::Reference< beans::XPropertySet >& rxFieldProps, FFDataHandler::Pointer_t pFFDataHandler )
      98             : {
      99           0 :     if ( rxFieldProps.is() )
     100             :     {
     101           0 :         if ( !pFFDataHandler->getName().isEmpty() )
     102           0 :             rxFieldProps->setPropertyValue( "Name", uno::makeAny( pFFDataHandler->getName() ) );
     103             : 
     104           0 :         const FFDataHandler::DropDownEntries_t& rEntries = pFFDataHandler->getDropDownEntries();
     105           0 :         uno::Sequence< OUString > sItems( rEntries.size() );
     106           0 :         ::std::copy( rEntries.begin(), rEntries.end(), ::comphelper::stl_begin(sItems));
     107           0 :         if ( sItems.getLength() )
     108           0 :             rxFieldProps->setPropertyValue( "Items", uno::makeAny( sItems ) );
     109             : 
     110           0 :         sal_Int32 nResult = pFFDataHandler->getDropDownResult().toInt32();
     111           0 :         if ( nResult )
     112           0 :             rxFieldProps->setPropertyValue( "SelectedItem", uno::makeAny( sItems[ nResult ] ) );
     113           0 :         if ( !pFFDataHandler->getHelpText().isEmpty() )
     114           0 :              rxFieldProps->setPropertyValue( "Help", uno::makeAny( pFFDataHandler->getHelpText() ) );
     115             :     }
     116           0 : }
     117             : 
     118           0 : void lcl_handleTextField( const uno::Reference< beans::XPropertySet >& rxFieldProps, FFDataHandler::Pointer_t pFFDataHandler, PropertyNameSupplier& rPropNameSupplier )
     119             : {
     120           0 :     if ( rxFieldProps.is() && pFFDataHandler )
     121             :     {
     122           0 :         rxFieldProps->setPropertyValue
     123           0 :             (rPropNameSupplier.GetName(PROP_HINT),
     124           0 :             uno::makeAny(pFFDataHandler->getStatusText()));
     125           0 :         rxFieldProps->setPropertyValue
     126           0 :             (rPropNameSupplier.GetName(PROP_HELP),
     127           0 :             uno::makeAny(pFFDataHandler->getHelpText()));
     128           0 :         rxFieldProps->setPropertyValue
     129           0 :             (rPropNameSupplier.GetName(PROP_CONTENT),
     130           0 :             uno::makeAny(pFFDataHandler->getTextDefault()));
     131             :     }
     132           0 : }
     133             : 
     134        2343 : struct FieldConversion
     135             : {
     136             :     OUString     sWordCommand;
     137             :     const sal_Char*     cFieldServiceName;
     138             :     const sal_Char*     cFieldMasterServiceName;
     139             :     FieldId             eFieldId;
     140             : };
     141             : 
     142             : typedef ::std::map< OUString, FieldConversion>
     143             :             FieldConversionMap_t;
     144             : 
     145             : 
     146           0 : void FIB::SetData( Id nName, sal_Int32 nValue )
     147             : {
     148             :     OSL_ENSURE( nName >= NS_rtf::LN_WIDENT && nName <= NS_rtf::LN_LCBSTTBFUSSR, "invalid index in FIB");
     149           0 :     if( nName >= NS_rtf::LN_WIDENT && nName <= NS_rtf::LN_LCBSTTBFUSSR)
     150           0 :         aFIBData[nName - NS_rtf::LN_WIDENT] = nValue;
     151           0 : }
     152             : 
     153             : 
     154         224 : DomainMapper_Impl::DomainMapper_Impl(
     155             :             DomainMapper& rDMapper,
     156             :             uno::Reference < uno::XComponentContext >  xContext,
     157             :             uno::Reference< lang::XComponent >  xModel,
     158             :             SourceDocumentType eDocumentType,
     159             :             uno::Reference< text::XTextRange > xInsertTextRange,
     160             :             bool bIsNewDoc) :
     161             :         m_eDocumentType( eDocumentType ),
     162             :         m_rDMapper( rDMapper ),
     163             :         m_xTextDocument( xModel, uno::UNO_QUERY ),
     164             :         m_xTextFactory( xModel, uno::UNO_QUERY ),
     165             :         m_xComponentContext( xContext ),
     166             :         m_bSetUserFieldContent( false ),
     167             :         m_bIsFirstSection( true ),
     168             :         m_bIsColumnBreakDeferred( false ),
     169             :         m_bIsPageBreakDeferred( false ),
     170             :         m_pLastSectionContext( ),
     171             :         m_pLastCharacterContext(),
     172             :         m_nCurrentTabStopIndex( 0 ),
     173             :         m_sCurrentParaStyleId(),
     174             :         m_bInStyleSheetImport( false ),
     175             :         m_bInAnyTableImport( false ),
     176             :         m_bInHeaderFooterImport( false ),
     177             :         m_bLineNumberingSet( false ),
     178             :         m_bIsInFootnoteProperties( true ),
     179             :         m_bIsCustomFtnMark( false ),
     180             :         m_bIsParaChange( false ),
     181             :         m_bParaChanged( false ),
     182             :         m_bIsFirstParaInSection( true ),
     183             :         m_bIsLastParaInSection( false ),
     184             :         m_bParaSectpr( false ),
     185             :         m_bUsingEnhancedFields( false ),
     186             :         m_bSdt(false),
     187             :         m_xInsertTextRange(xInsertTextRange),
     188         231 :         m_bIsNewDoc(bIsNewDoc)
     189             : {
     190         224 :     appendTableManager( );
     191         224 :     GetBodyText();
     192         224 :     uno::Reference< text::XTextAppend > xBodyTextAppend = uno::Reference< text::XTextAppend >( m_xBodyText, uno::UNO_QUERY );
     193             :     m_aTextAppendStack.push(TextAppendContext(xBodyTextAppend,
     194         224 :                 m_bIsNewDoc ? uno::Reference<text::XTextCursor>() : m_xBodyText->createTextCursorByRange(m_xInsertTextRange)));
     195             : 
     196             :     //todo: does it make sense to set the body text as static text interface?
     197         223 :     uno::Reference< text::XTextAppendAndConvert > xBodyTextAppendAndConvert( m_xBodyText, uno::UNO_QUERY );
     198             :     m_pTableHandler.reset
     199         223 :         (new DomainMapperTableHandler(xBodyTextAppendAndConvert, *this));
     200         223 :     getTableManager( ).setHandler(m_pTableHandler);
     201             : 
     202         223 :     getTableManager( ).startLevel();
     203         223 :     m_bUsingEnhancedFields = lcl_IsUsingEnhancedFields( m_xComponentContext );
     204             : 
     205         229 : }
     206             : 
     207             : 
     208        2007 : DomainMapper_Impl::~DomainMapper_Impl()
     209             : {
     210         223 :     RemoveLastParagraph( );
     211         223 :     getTableManager( ).endLevel();
     212         223 :     popTableManager( );
     213        1784 : }
     214             : 
     215             : 
     216         523 : uno::Reference< container::XNameContainer >    DomainMapper_Impl::GetPageStyles()
     217             : {
     218         523 :     if(!m_xPageStyles.is())
     219             :     {
     220         222 :         uno::Reference< style::XStyleFamiliesSupplier > xSupplier( m_xTextDocument, uno::UNO_QUERY );
     221         222 :         if (xSupplier.is())
     222         208 :             xSupplier->getStyleFamilies()->getByName("PageStyles") >>= m_xPageStyles;
     223             :     }
     224         523 :     return m_xPageStyles;
     225             : }
     226             : 
     227             : 
     228         649 : uno::Reference< text::XText > DomainMapper_Impl::GetBodyText()
     229             : {
     230         649 :     if(!m_xBodyText.is() && m_xTextDocument.is())
     231             :     {
     232         213 :         m_xBodyText = m_xTextDocument->getText();
     233             :     }
     234         649 :     return m_xBodyText;
     235             : }
     236             : 
     237             : 
     238         223 : uno::Reference< beans::XPropertySet > DomainMapper_Impl::GetDocumentSettings()
     239             : {
     240         223 :     if( !m_xDocumentSettings.is() && m_xTextFactory.is())
     241             :     {
     242             :         m_xDocumentSettings = uno::Reference< beans::XPropertySet >(
     243         212 :             m_xTextFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY );
     244             :     }
     245         223 :     return m_xDocumentSettings;
     246             : }
     247             : 
     248             : 
     249         223 : void DomainMapper_Impl::SetDocumentSettingsProperty( const OUString& rPropName, const uno::Any& rValue )
     250             : {
     251         223 :     uno::Reference< beans::XPropertySet > xSettings = GetDocumentSettings();
     252         223 :     if( xSettings.is() )
     253             :     {
     254             :         try
     255             :         {
     256         212 :             xSettings->setPropertyValue( rPropName, rValue );
     257             :         }
     258           0 :         catch( const uno::Exception& )
     259             :         {
     260             :         }
     261         223 :     }
     262         223 : }
     263             : 
     264         306 : void DomainMapper_Impl::RemoveLastParagraph( )
     265             : {
     266         306 :     if (m_aTextAppendStack.empty())
     267             :         return;
     268         306 :     uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
     269         306 :     if (!xTextAppend.is())
     270             :         return;
     271             :     try
     272             :     {
     273         295 :         uno::Reference< text::XTextCursor > xCursor;
     274         295 :         if (m_bIsNewDoc)
     275             :         {
     276         295 :             xCursor = xTextAppend->createTextCursor();
     277         295 :             xCursor->gotoEnd(false);
     278             :         }
     279             :         else
     280           0 :             xCursor.set(m_aTextAppendStack.top().xCursor, uno::UNO_QUERY);
     281         295 :         xCursor->goLeft( 1, true );
     282         295 :         xCursor->setString(OUString());
     283             :     }
     284           0 :     catch( const uno::Exception& )
     285             :     {
     286         306 :     }
     287             : }
     288             : 
     289         103 : void DomainMapper_Impl::SetIsLastParagraphInSection( bool bIsLast )
     290             : {
     291         103 :     m_bIsLastParaInSection = bIsLast;
     292         103 : }
     293             : 
     294         110 : bool DomainMapper_Impl::GetIsLastParagraphInSection()
     295             : {
     296         110 :     return m_bIsLastParaInSection;
     297             : }
     298             : 
     299         234 : void DomainMapper_Impl::SetIsFirstParagraphInSection( bool bIsFirst )
     300             : {
     301         234 :     m_bIsFirstParaInSection = bIsFirst;
     302         234 : }
     303             : 
     304         481 : bool DomainMapper_Impl::GetIsFirstParagraphInSection()
     305             : {
     306         481 :     return m_bIsFirstParaInSection;
     307             : }
     308             : 
     309         629 : void DomainMapper_Impl::SetParaSectpr(bool bParaSectpr)
     310             : {
     311         629 :     m_bParaSectpr = bParaSectpr;
     312         629 : }
     313             : 
     314         349 : bool DomainMapper_Impl::GetParaSectpr()
     315             : {
     316         349 :     return m_bParaSectpr;
     317             : }
     318             : 
     319           2 : void DomainMapper_Impl::SetSdt(bool bSdt)
     320             : {
     321           2 :     m_bSdt = bSdt;
     322           2 : }
     323             : 
     324          20 : bool DomainMapper_Impl::GetSdt()
     325             : {
     326          20 :     return m_bSdt;
     327             : }
     328             : 
     329         481 : bool DomainMapper_Impl::GetParaChanged()
     330             : {
     331         481 :     return m_bParaChanged;
     332             : }
     333             : 
     334        6631 : void    DomainMapper_Impl::PushProperties(ContextType eId)
     335             : {
     336             :     PropertyMapPtr pInsert(eId == CONTEXT_SECTION ?
     337         236 :         (new SectionPropertyMap( m_bIsFirstSection )) :
     338        6867 :         eId == CONTEXT_PARAGRAPH ? new ParagraphPropertyMap :  new PropertyMap);
     339        6631 :     if(eId == CONTEXT_SECTION)
     340             :     {
     341         236 :         if( m_bIsFirstSection )
     342         218 :             m_bIsFirstSection = false;
     343             :         // beginning with the second section group a section has to be inserted
     344             :         // into the document
     345         236 :         SectionPropertyMap* pSectionContext_ = dynamic_cast< SectionPropertyMap* >( pInsert.get() );
     346         236 :         if (!m_aTextAppendStack.empty())
     347             :         {
     348         236 :             uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
     349         236 :             if (xTextAppend.is())
     350         228 :                 pSectionContext_->SetStart( xTextAppend->getEnd() );
     351             :         }
     352             :     }
     353        6631 :     m_aPropertyStacks[eId].push( pInsert );
     354        6631 :     m_aContextStack.push(eId);
     355             : 
     356        6631 :     m_pTopContext = m_aPropertyStacks[eId].top();
     357        6631 : }
     358             : 
     359             : 
     360        3246 : void DomainMapper_Impl::PushStyleProperties( PropertyMapPtr pStyleProperties )
     361             : {
     362        3246 :     m_aPropertyStacks[CONTEXT_STYLESHEET].push( pStyleProperties );
     363        3246 :     m_aContextStack.push(CONTEXT_STYLESHEET);
     364             : 
     365        3246 :     m_pTopContext = m_aPropertyStacks[CONTEXT_STYLESHEET].top();
     366        3246 : }
     367             : 
     368             : 
     369         126 : void DomainMapper_Impl::PushListProperties(PropertyMapPtr pListProperties)
     370             : {
     371         126 :     m_aPropertyStacks[CONTEXT_LIST].push( pListProperties );
     372         126 :     m_aContextStack.push(CONTEXT_LIST);
     373         126 :     m_pTopContext = m_aPropertyStacks[CONTEXT_LIST].top();
     374         126 : }
     375             : 
     376             : 
     377        9948 : void    DomainMapper_Impl::PopProperties(ContextType eId)
     378             : {
     379             :     OSL_ENSURE(!m_aPropertyStacks[eId].empty(), "section stack already empty");
     380        9948 :     if ( m_aPropertyStacks[eId].empty() )
     381        9948 :         return;
     382             : 
     383        9948 :     if ( eId == CONTEXT_SECTION )
     384             :     {
     385         234 :         m_pLastSectionContext = m_aPropertyStacks[eId].top( );
     386             :     }
     387        9714 :     else if (eId == CONTEXT_CHARACTER)
     388             :     {
     389        5164 :         m_pLastCharacterContext = m_aPropertyStacks[eId].top();
     390             :         // Sadly an assert about deferredCharacterProperties being empty is not possible
     391             :         // here, becase appendTextPortion() may not be called for every character section.
     392        5164 :         deferredCharacterProperties.clear();
     393             :     }
     394             : 
     395        9948 :     m_aPropertyStacks[eId].pop();
     396        9948 :     m_aContextStack.pop();
     397        9948 :     if(!m_aContextStack.empty() && !m_aPropertyStacks[m_aContextStack.top()].empty())
     398             : 
     399        8511 :             m_pTopContext = m_aPropertyStacks[m_aContextStack.top()].top();
     400             :     else
     401             :     {
     402             :         // OSL_ENSURE(eId == CONTEXT_SECTION, "this should happen at a section context end");
     403        1437 :         m_pTopContext.reset();
     404             :     }
     405             : }
     406             : 
     407             : 
     408       21504 : PropertyMapPtr DomainMapper_Impl::GetTopContextOfType(ContextType eId)
     409             : {
     410       21504 :     PropertyMapPtr pRet;
     411             :     SAL_WARN_IF( m_aPropertyStacks[eId].empty(), "writerfilter",
     412             :         "no context of type " << static_cast<int>(eId) << " available");
     413       21504 :     if(!m_aPropertyStacks[eId].empty())
     414       21456 :         pRet = m_aPropertyStacks[eId].top();
     415       21504 :     return pRet;
     416             : }
     417             : 
     418             : 
     419             : 
     420          15 : uno::Reference< text::XTextAppend >  DomainMapper_Impl::GetTopTextAppend()
     421             : {
     422             :     OSL_ENSURE(!m_aTextAppendStack.empty(), "text append stack is empty" );
     423          15 :     return m_aTextAppendStack.top().xTextAppend;
     424             : }
     425             : 
     426             : 
     427             : 
     428           0 : void DomainMapper_Impl::InitTabStopFromStyle( const uno::Sequence< style::TabStop >& rInitTabStops )
     429             : {
     430             :     OSL_ENSURE(!m_aCurrentTabStops.size(), "tab stops already initialized");
     431           0 :     for( sal_Int32 nTab = 0; nTab < rInitTabStops.getLength(); ++nTab)
     432             :     {
     433           0 :         m_aCurrentTabStops.push_back( DeletableTabStop(rInitTabStops[nTab]) );
     434             :     }
     435           0 : }
     436             : 
     437             : 
     438             : 
     439           0 : void DomainMapper_Impl::ModifyCurrentTabStop( Id nId, sal_Int32 nValue)
     440             : {
     441             :     OSL_ENSURE(nId == NS_rtf::LN_dxaAdd || m_nCurrentTabStopIndex < m_aCurrentTabStops.size(),
     442             :         "tab stop creation error");
     443             : 
     444           0 :     if( nId != NS_rtf::LN_dxaAdd && m_nCurrentTabStopIndex >= m_aCurrentTabStops.size())
     445           0 :         return;
     446             :     static const style::TabAlign aTabAlignFromWord[] =
     447             :     {
     448             :         style::TabAlign_LEFT,
     449             :         style::TabAlign_CENTER,
     450             :         style::TabAlign_RIGHT,
     451             :         style::TabAlign_DECIMAL,
     452             :         style::TabAlign_LEFT
     453             :     };
     454             :     static const sal_Unicode aTabFillCharWord[] =
     455             :     {
     456             :         ' ',
     457             :         '.',
     458             :         '-',
     459             :         '_',
     460             :         '_',
     461             :         0xb7
     462             :     };
     463             : 
     464           0 :     switch(nId)
     465             :     {
     466             :         case NS_rtf::LN_dxaAdd: //set tab
     467             :             m_aCurrentTabStops.push_back(
     468           0 :                     DeletableTabStop(style::TabStop(ConversionHelper::convertTwipToMM100(nValue), style::TabAlign_LEFT, ' ', ' ')));
     469           0 :         break;
     470             :         case NS_rtf::LN_dxaDel: //deleted tab
     471             :         {
     472             :             //mark the tab stop at the given position as deleted
     473           0 :             ::std::vector<DeletableTabStop>::iterator aIt = m_aCurrentTabStops.begin();
     474           0 :             ::std::vector<DeletableTabStop>::iterator aEndIt = m_aCurrentTabStops.end();
     475           0 :             sal_Int32 nConverted = ConversionHelper::convertTwipToMM100(nValue);
     476           0 :             for( ; aIt != aEndIt; ++aIt)
     477             :             {
     478           0 :                 if( aIt->Position == nConverted )
     479             :                 {
     480           0 :                     aIt->bDeleted = true;
     481           0 :                     break;
     482             :                 }
     483             :             }
     484             :         }
     485           0 :         break;
     486             :         case NS_rtf::LN_TLC: //tab leading characters - for decimal tabs
     487             :             // 0 - no leader, 1- dotted, 2 - hyphenated, 3 - single line, 4 - heavy line, 5 - middle dot
     488           0 :             if( nValue >= 0 &&  nValue < sal::static_int_cast<sal_Int32>(sizeof(aTabFillCharWord) / sizeof (sal_Unicode)))
     489           0 :                 m_aCurrentTabStops[m_nCurrentTabStopIndex].FillChar = aTabFillCharWord[nValue];
     490           0 :         break;
     491             :         case NS_rtf::LN_JC: //tab justification
     492             :             //0 - left, 1 - centered, 2 - right, 3 - decimal 4 - bar
     493           0 :             if( nValue >= 0 && nValue < sal::static_int_cast<sal_Int32>(sizeof(aTabAlignFromWord) / sizeof (style::TabAlign)))
     494           0 :                 m_aCurrentTabStops[m_nCurrentTabStopIndex].Alignment = aTabAlignFromWord[nValue];
     495           0 :         break;
     496             :     }
     497             : }
     498             : 
     499         206 : void DomainMapper_Impl::IncorporateTabStop( const DeletableTabStop &  rTabStop )
     500             : {
     501         206 :     ::std::vector<DeletableTabStop>::iterator aIt = m_aCurrentTabStops.begin();
     502         206 :     ::std::vector<DeletableTabStop>::iterator aEndIt = m_aCurrentTabStops.end();
     503         206 :     sal_Int32 nConverted = rTabStop.Position;
     504         206 :     bool bFound = false;
     505        1280 :     for( ; aIt != aEndIt; ++aIt)
     506             :     {
     507        1074 :         if( aIt->Position == nConverted )
     508             :         {
     509           0 :             bFound = true;
     510           0 :             if( rTabStop.bDeleted )
     511           0 :                 m_aCurrentTabStops.erase( aIt );
     512             :             else
     513           0 :                 *aIt = rTabStop;
     514           0 :             break;
     515             :         }
     516             :     }
     517         206 :     if( !bFound )
     518         206 :         m_aCurrentTabStops.push_back( rTabStop );
     519         206 : }
     520             : 
     521             : 
     522         104 : uno::Sequence< style::TabStop > DomainMapper_Impl::GetCurrentTabStopAndClear()
     523             : {
     524         104 :     uno::Sequence< style::TabStop > aRet( sal_Int32( m_aCurrentTabStops.size() ) );
     525         104 :     style::TabStop* pArray = aRet.getArray();
     526         104 :     ::std::vector<DeletableTabStop>::const_iterator aIt = m_aCurrentTabStops.begin();
     527         104 :     ::std::vector<DeletableTabStop>::const_iterator aEndIt = m_aCurrentTabStops.end();
     528         104 :     sal_Int32 nDeleted = 0;
     529         310 :     for(sal_Int32 nIndex = 0; aIt != aEndIt; ++aIt)
     530             :     {
     531         206 :         if(!aIt->bDeleted)
     532         206 :             pArray[nIndex++] = *aIt;
     533             :         else
     534           0 :             ++nDeleted;
     535             :     }
     536         104 :     m_aCurrentTabStops.clear();
     537         104 :     m_nCurrentTabStopIndex = 0;
     538         104 :     if(nDeleted)
     539             :     {
     540           0 :         aRet.realloc( aRet.getLength() - nDeleted);
     541             :     }
     542         104 :     return aRet;
     543             : }
     544             : 
     545             : /*-------------------------------------------------------------------------
     546             :     returns a the value from the current paragraph style - if available
     547             :     TODO: What about parent styles?
     548             :   -----------------------------------------------------------------------*/
     549          23 : uno::Any DomainMapper_Impl::GetPropertyFromStyleSheet(PropertyIds eId)
     550             : {
     551          23 :     StyleSheetEntryPtr pEntry;
     552          23 :     if( m_bInStyleSheetImport )
     553           0 :         pEntry = GetStyleSheetTable()->FindParentStyleSheet(OUString());
     554             :     else
     555             :         pEntry =
     556          23 :                 GetStyleSheetTable()->FindStyleSheetByISTD(GetCurrentParaStyleId());
     557          51 :     while(pEntry.get( ) )
     558             :     {
     559             :         //is there a tab stop set?
     560           6 :         if(pEntry->pProperties)
     561             :         {
     562             :             PropertyMap::const_iterator aPropertyIter =
     563           6 :                     pEntry->pProperties->find(PropertyDefinition(eId, false ));
     564           6 :             if( aPropertyIter != pEntry->pProperties->end())
     565             :             {
     566           1 :                 return aPropertyIter->second;
     567             :             }
     568             :         }
     569             :         //search until the property is set or no parent is available
     570           5 :         StyleSheetEntryPtr pNewEntry = GetStyleSheetTable()->FindParentStyleSheet(pEntry->sBaseStyleIdentifier);
     571             : 
     572             :         SAL_WARN_IF( pEntry == pNewEntry, "writerfilter", "circular loop in style hierarchy?");
     573             : 
     574           5 :         if (pEntry == pNewEntry) //fdo#49587
     575             :             break;
     576             : 
     577           5 :         pEntry = pNewEntry;
     578           5 :     }
     579          22 :     return uno::Any();
     580             : }
     581             : 
     582             : 
     583          85 : ListsManager::Pointer DomainMapper_Impl::GetListTable()
     584             : {
     585          85 :     if(!m_pListTable)
     586             :         m_pListTable.reset(
     587          15 :             new ListsManager( m_rDMapper, m_xTextFactory ));
     588          85 :     return m_pListTable;
     589             : }
     590             : 
     591             : 
     592          56 : void DomainMapper_Impl::deferBreak( BreakType deferredBreakType)
     593             : {
     594          56 :     switch (deferredBreakType)
     595             :     {
     596             :     case COLUMN_BREAK:
     597           0 :             m_bIsColumnBreakDeferred = true;
     598           0 :         break;
     599             :     case PAGE_BREAK:
     600          56 :             m_bIsPageBreakDeferred = true;
     601          56 :         break;
     602             :     default:
     603           0 :         return;
     604             :     }
     605             : }
     606             : 
     607       11196 : bool DomainMapper_Impl::isBreakDeferred( BreakType deferredBreakType )
     608             : {
     609       11196 :     switch (deferredBreakType)
     610             :     {
     611             :     case COLUMN_BREAK:
     612        5570 :         return m_bIsColumnBreakDeferred;
     613             :     case PAGE_BREAK:
     614        5626 :         return m_bIsPageBreakDeferred;
     615             :     default:
     616           0 :         return false;
     617             :     }
     618             : }
     619             : 
     620        5626 : void DomainMapper_Impl::clearDeferredBreaks()
     621             : {
     622        5626 :     m_bIsColumnBreakDeferred = false;
     623        5626 :     m_bIsPageBreakDeferred = false;
     624        5626 : }
     625             : 
     626             : 
     627          14 : void lcl_MoveBorderPropertiesToFrame(uno::Sequence<beans::PropertyValue>& rFrameProperties,
     628             :     uno::Reference<text::XTextRange> xStartTextRange,
     629             :     uno::Reference<text::XTextRange> xEndTextRange )
     630             : {
     631             :     try
     632             :     {
     633          15 :         uno::Reference<text::XTextCursor> xRangeCursor = xStartTextRange->getText()->createTextCursorByRange( xStartTextRange );
     634          13 :         xRangeCursor->gotoRange( xEndTextRange, true );
     635             : 
     636          13 :         uno::Reference<beans::XPropertySet> xTextRangeProperties(xRangeCursor, uno::UNO_QUERY);
     637          13 :         if(!xTextRangeProperties.is())
     638          14 :             return ;
     639             : 
     640             :         PropertyIds aBorderProperties[] =
     641             :         {
     642             :             PROP_LEFT_BORDER,
     643             :             PROP_RIGHT_BORDER,
     644             :             PROP_TOP_BORDER,
     645             :             PROP_BOTTOM_BORDER,
     646             :             PROP_LEFT_BORDER_DISTANCE,
     647             :             PROP_RIGHT_BORDER_DISTANCE,
     648             :             PROP_TOP_BORDER_DISTANCE,
     649             :             PROP_BOTTOM_BORDER_DISTANCE
     650          13 :         };
     651             : 
     652          13 :         sal_uInt32 nStart = rFrameProperties.getLength();
     653          13 :         sal_uInt32 nBorderPropertyCount = sizeof( aBorderProperties ) / sizeof(PropertyIds);
     654          13 :         rFrameProperties.realloc(nStart + nBorderPropertyCount);
     655             : 
     656          13 :         beans::PropertyValue* pFrameProperties = rFrameProperties.getArray();
     657          13 :         PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     658         117 :         for( sal_uInt32 nProperty = 0; nProperty < nBorderPropertyCount; ++nProperty)
     659             :         {
     660         104 :             OUString sPropertyName = rPropNameSupplier.GetName(aBorderProperties[nProperty]);
     661         104 :             pFrameProperties[nStart].Name = sPropertyName;
     662         104 :             pFrameProperties[nStart].Value = xTextRangeProperties->getPropertyValue(sPropertyName);
     663         104 :             if( nProperty < 4 )
     664          52 :                 xTextRangeProperties->setPropertyValue( sPropertyName, uno::makeAny(table::BorderLine2()));
     665         104 :             ++nStart;
     666         104 :         }
     667          13 :         rFrameProperties.realloc(nStart);
     668             :     }
     669           1 :     catch( const uno::Exception& )
     670             :     {
     671             :     }
     672             : }
     673             : 
     674             : 
     675          13 : void lcl_AddRangeAndStyle(
     676             :     ParagraphPropertiesPtr& pToBeSavedProperties,
     677             :     uno::Reference< text::XTextAppend > xTextAppend,
     678             :     PropertyMapPtr pPropertyMap,
     679             :     TextAppendContext& rAppendContext)
     680             : {
     681             :     uno::Reference<text::XParagraphCursor> xParaCursor(
     682          13 :         xTextAppend->createTextCursorByRange( rAppendContext.xInsertPosition.is() ? rAppendContext.xInsertPosition : xTextAppend->getEnd()), uno::UNO_QUERY_THROW );
     683          13 :     pToBeSavedProperties->SetEndingRange(xParaCursor->getStart());
     684          13 :     xParaCursor->gotoStartOfParagraph( false );
     685             : 
     686          13 :     pToBeSavedProperties->SetStartingRange(xParaCursor->getStart());
     687          13 :     if(pPropertyMap)
     688             :     {
     689          13 :         PropertyMap::iterator aParaStyleIter = pPropertyMap->find(PropertyDefinition( PROP_PARA_STYLE_NAME, false ) );
     690          13 :         if( aParaStyleIter != pPropertyMap->end())
     691             :         {
     692          13 :             OUString sName;
     693          13 :             aParaStyleIter->second >>= sName;
     694          13 :             pToBeSavedProperties->SetParaStyleName(sName);
     695             :         }
     696          13 :     }
     697          13 : }
     698             : 
     699             : 
     700             : //define some default frame width - 0cm ATM: this allow the frame to be wrapped around the text
     701             : #define DEFAULT_FRAME_MIN_WIDTH 0
     702             : 
     703         244 : void DomainMapper_Impl::CheckUnregisteredFrameConversion( )
     704             : {
     705         244 :     PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     706         244 :     TextAppendContext& rAppendContext = m_aTextAppendStack.top();
     707         244 :     if( rAppendContext.pLastParagraphProperties.get() && rAppendContext.pLastParagraphProperties->IsFrameMode() )
     708             :     {
     709             :         try
     710             :         {
     711             :             StyleSheetEntryPtr pParaStyle =
     712          14 :                 GetStyleSheetTable()->FindStyleSheetByConvertedStyleName(rAppendContext.pLastParagraphProperties->GetParaStyleName());
     713             : 
     714          14 :             uno::Sequence< beans::PropertyValue > aFrameProperties(pParaStyle ? 16: 9);
     715             : 
     716          14 :             if ( pParaStyle.get( ) )
     717             :             {
     718           3 :                 beans::PropertyValue* pFrameProperties = aFrameProperties.getArray();
     719           3 :                 pFrameProperties[0].Name = rPropNameSupplier.GetName(PROP_WIDTH);
     720           3 :                 pFrameProperties[1].Name = rPropNameSupplier.GetName(PROP_HEIGHT);
     721           3 :                 pFrameProperties[2].Name = rPropNameSupplier.GetName(PROP_SIZE_TYPE);
     722           3 :                 pFrameProperties[3].Name = rPropNameSupplier.GetName(PROP_WIDTH_TYPE);
     723           3 :                 pFrameProperties[4].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT);
     724           3 :                 pFrameProperties[5].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT_POSITION);
     725           3 :                 pFrameProperties[6].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT_RELATION);
     726           3 :                 pFrameProperties[7].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT);
     727           3 :                 pFrameProperties[8].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT_POSITION);
     728           3 :                 pFrameProperties[9].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT_RELATION);
     729           3 :                 pFrameProperties[10].Name = rPropNameSupplier.GetName(PROP_SURROUND);
     730           3 :                 pFrameProperties[11].Name = rPropNameSupplier.GetName(PROP_LEFT_MARGIN);
     731           3 :                 pFrameProperties[12].Name = rPropNameSupplier.GetName(PROP_RIGHT_MARGIN);
     732           3 :                 pFrameProperties[13].Name = rPropNameSupplier.GetName(PROP_TOP_MARGIN);
     733           3 :                 pFrameProperties[14].Name = rPropNameSupplier.GetName(PROP_BOTTOM_MARGIN);
     734           3 :                 pFrameProperties[15].Name = rPropNameSupplier.GetName(PROP_BACK_COLOR_TRANSPARENCY);
     735             : 
     736           3 :                 const ParagraphProperties* pStyleProperties = dynamic_cast<const ParagraphProperties*>( pParaStyle->pProperties.get() );
     737             :                 sal_Int32 nWidth =
     738           3 :                     rAppendContext.pLastParagraphProperties->Getw() > 0 ?
     739           3 :                         rAppendContext.pLastParagraphProperties->Getw() :
     740           6 :                         pStyleProperties->Getw();
     741           3 :                 bool bAutoWidth = nWidth < 1;
     742           3 :                 if( bAutoWidth )
     743           0 :                     nWidth = DEFAULT_FRAME_MIN_WIDTH;
     744           3 :                 pFrameProperties[0].Value <<= nWidth;
     745             : 
     746           3 :                 pFrameProperties[1].Value <<=
     747           3 :                     rAppendContext.pLastParagraphProperties->Geth() > 0 ?
     748           3 :                         rAppendContext.pLastParagraphProperties->Geth() :
     749           9 :                         pStyleProperties->Geth();
     750             : 
     751           3 :                 pFrameProperties[2].Value <<= sal_Int16(
     752           3 :                     rAppendContext.pLastParagraphProperties->GethRule() >= 0 ?
     753           3 :                         rAppendContext.pLastParagraphProperties->GethRule() :
     754           9 :                 pStyleProperties->GethRule() >=0 ? pStyleProperties->GethRule() : text::SizeType::VARIABLE);
     755             : 
     756           3 :                 pFrameProperties[3].Value <<= bAutoWidth ?  text::SizeType::MIN : text::SizeType::FIX;
     757             : 
     758             :                 sal_Int16 nHoriOrient = sal_Int16(
     759           3 :                     rAppendContext.pLastParagraphProperties->GetxAlign() >= 0 ?
     760           3 :                         rAppendContext.pLastParagraphProperties->GetxAlign() :
     761           6 :                         pStyleProperties->GetxAlign() >= 0 ? pStyleProperties->GetxAlign() : text::HoriOrientation::NONE );
     762           3 :                 pFrameProperties[4].Value <<= nHoriOrient;
     763             : 
     764           3 :                 pFrameProperties[5].Value <<=
     765           3 :                     rAppendContext.pLastParagraphProperties->IsxValid() ?
     766           6 :                         rAppendContext.pLastParagraphProperties->Getx() : pStyleProperties->Getx();
     767           3 :                 pFrameProperties[6].Value <<= sal_Int16(
     768           3 :                     rAppendContext.pLastParagraphProperties->GethAnchor() >= 0 ?
     769           3 :                         rAppendContext.pLastParagraphProperties->GethAnchor() :
     770           9 :                     pStyleProperties->GethAnchor() );
     771             : 
     772             :                 sal_Int16 nVertOrient = sal_Int16(
     773           3 :                     rAppendContext.pLastParagraphProperties->GetyAlign() >= 0 ?
     774           3 :                         rAppendContext.pLastParagraphProperties->GetyAlign() :
     775           6 :                         pStyleProperties->GetyAlign() >= 0 ? pStyleProperties->GetyAlign() : text::VertOrientation::NONE );
     776           3 :                 pFrameProperties[7].Value <<= nVertOrient;
     777             : 
     778           3 :                 pFrameProperties[8].Value <<=
     779           3 :                     rAppendContext.pLastParagraphProperties->IsyValid() ?
     780           6 :                         rAppendContext.pLastParagraphProperties->Gety() : pStyleProperties->Gety();
     781           3 :                 pFrameProperties[9].Value <<= sal_Int16(
     782           3 :                     rAppendContext.pLastParagraphProperties->GetvAnchor() >= 0 ?
     783           3 :                         rAppendContext.pLastParagraphProperties->GetvAnchor() :
     784           9 :                         pStyleProperties->GetvAnchor() );
     785             : 
     786           3 :                 pFrameProperties[10].Value <<= text::WrapTextMode(
     787           3 :                     rAppendContext.pLastParagraphProperties->GetWrap() >= 0 ?
     788           0 :                     rAppendContext.pLastParagraphProperties->GetWrap() :
     789           6 :                     pStyleProperties->GetWrap());
     790             : 
     791             :                 sal_Int32 nBottomDist;
     792             :                 sal_Int32 nTopDist = nBottomDist =
     793           3 :                     rAppendContext.pLastParagraphProperties->GethSpace() >= 0 ?
     794           3 :                     rAppendContext.pLastParagraphProperties->GethSpace() :
     795           6 :                     pStyleProperties->GethSpace();
     796             : 
     797           3 :                 pFrameProperties[11].Value <<= nVertOrient == text::VertOrientation::TOP ? 0 : nTopDist;
     798           3 :                 pFrameProperties[12].Value <<= nVertOrient == text::VertOrientation::BOTTOM ? 0 : nBottomDist;
     799             : 
     800             :                 sal_Int32 nRightDist;
     801             :                 sal_Int32 nLeftDist = nRightDist =
     802           3 :                     rAppendContext.pLastParagraphProperties->GetvSpace() >= 0 ?
     803           3 :                     rAppendContext.pLastParagraphProperties->GetvSpace() :
     804           6 :                 pStyleProperties->GetvSpace() >= 0 ? pStyleProperties->GetvSpace() : 0;
     805           3 :                 pFrameProperties[13].Value <<= nHoriOrient == text::HoriOrientation::LEFT ? 0 : nLeftDist;
     806           3 :                 pFrameProperties[14].Value <<= nHoriOrient == text::HoriOrientation::RIGHT ? 0 : nRightDist;
     807             :                 // If there is no fill, the Word default is 100% transparency.
     808             :                 // Otherwise CellColorHandler has priority, and this setting
     809             :                 // will be ignored.
     810           3 :                 pFrameProperties[15].Value <<= sal_Int32(100);
     811             : 
     812             :                 lcl_MoveBorderPropertiesToFrame(aFrameProperties,
     813             :                     rAppendContext.pLastParagraphProperties->GetStartingRange(),
     814           3 :                     rAppendContext.pLastParagraphProperties->GetEndingRange());
     815             :             }
     816             :             else
     817             :             {
     818          11 :                 beans::PropertyValue* pFrameProperties = aFrameProperties.getArray();
     819          11 :                 pFrameProperties[0].Name = rPropNameSupplier.GetName(PROP_WIDTH);
     820          11 :                 pFrameProperties[1].Name = rPropNameSupplier.GetName(PROP_SIZE_TYPE);
     821          11 :                 pFrameProperties[2].Name = rPropNameSupplier.GetName(PROP_WIDTH_TYPE);
     822          11 :                 pFrameProperties[3].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT);
     823          11 :                 pFrameProperties[4].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT);
     824          11 :                 pFrameProperties[5].Name = rPropNameSupplier.GetName(PROP_LEFT_MARGIN);
     825          11 :                 pFrameProperties[6].Name = rPropNameSupplier.GetName(PROP_RIGHT_MARGIN);
     826          11 :                 pFrameProperties[7].Name = rPropNameSupplier.GetName(PROP_TOP_MARGIN);
     827          11 :                 pFrameProperties[8].Name = rPropNameSupplier.GetName(PROP_BOTTOM_MARGIN);
     828             : 
     829          11 :                 sal_Int32 nWidth = rAppendContext.pLastParagraphProperties->Getw();
     830          11 :                 bool bAutoWidth = nWidth < 1;
     831          11 :                 if( bAutoWidth )
     832           0 :                     nWidth = DEFAULT_FRAME_MIN_WIDTH;
     833          11 :                 pFrameProperties[0].Value <<= nWidth;
     834             : 
     835          11 :                 pFrameProperties[1].Value <<= sal_Int16(
     836          11 :                     rAppendContext.pLastParagraphProperties->GethRule() >= 0 ?
     837          11 :                         rAppendContext.pLastParagraphProperties->GethRule() :
     838          33 :                         text::SizeType::VARIABLE);
     839             : 
     840          11 :                 pFrameProperties[2].Value <<= bAutoWidth ?  text::SizeType::MIN : text::SizeType::FIX;
     841             : 
     842             :                 sal_Int16 nHoriOrient = sal_Int16(
     843          11 :                     rAppendContext.pLastParagraphProperties->GetxAlign() >= 0 ?
     844          11 :                         rAppendContext.pLastParagraphProperties->GetxAlign() :
     845          22 :                         text::HoriOrientation::NONE );
     846          11 :                 pFrameProperties[3].Value <<= nHoriOrient;
     847             : 
     848             :                 sal_Int16 nVertOrient = sal_Int16(
     849          11 :                     rAppendContext.pLastParagraphProperties->GetyAlign() >= 0 ?
     850          11 :                         rAppendContext.pLastParagraphProperties->GetyAlign() :
     851          22 :                         text::VertOrientation::NONE );
     852          11 :                 pFrameProperties[4].Value <<= nVertOrient;
     853             : 
     854          11 :                 sal_Int32 nVertDist = rAppendContext.pLastParagraphProperties->GethSpace();
     855          11 :                 if( nVertDist < 0 )
     856          11 :                     nVertDist = 0;
     857          11 :                 pFrameProperties[5].Value <<= nVertOrient == text::VertOrientation::TOP ? 0 : nVertDist;
     858          11 :                 pFrameProperties[6].Value <<= nVertOrient == text::VertOrientation::BOTTOM ? 0 : nVertDist;
     859             : 
     860          11 :                 sal_Int32 nHoriDist = rAppendContext.pLastParagraphProperties->GetvSpace();
     861          11 :                 if( nHoriDist < 0 )
     862          11 :                     nHoriDist = 0;
     863          11 :                 pFrameProperties[7].Value <<= nHoriOrient == text::HoriOrientation::LEFT ? 0 : nHoriDist;
     864          11 :                 pFrameProperties[8].Value <<= nHoriOrient == text::HoriOrientation::RIGHT ? 0 : nHoriDist;
     865             : 
     866          11 :                 if( rAppendContext.pLastParagraphProperties->Geth() > 0 )
     867             :                 {
     868          11 :                     sal_Int32 nOldSize = aFrameProperties.getLength();
     869          11 :                     aFrameProperties.realloc( nOldSize + 1 );
     870          11 :                     pFrameProperties = aFrameProperties.getArray();
     871          11 :                     pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_HEIGHT);
     872          11 :                     pFrameProperties[nOldSize].Value <<= rAppendContext.pLastParagraphProperties->Geth();
     873             :                 }
     874             : 
     875          11 :                 if( rAppendContext.pLastParagraphProperties->IsxValid() )
     876             :                 {
     877          11 :                     sal_Int32 nOldSize = aFrameProperties.getLength();
     878          11 :                     aFrameProperties.realloc( nOldSize + 1 );
     879          11 :                     pFrameProperties = aFrameProperties.getArray();
     880          11 :                     pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT_POSITION);
     881          11 :                     pFrameProperties[nOldSize].Value <<= rAppendContext.pLastParagraphProperties->Getx();
     882             :                 }
     883             : 
     884          11 :                 if( rAppendContext.pLastParagraphProperties->GethAnchor() >= 0 )
     885             :                 {
     886          11 :                     sal_Int32 nOldSize = aFrameProperties.getLength();
     887          11 :                     aFrameProperties.realloc( nOldSize + 1 );
     888          11 :                     pFrameProperties = aFrameProperties.getArray();
     889          11 :                     pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT_RELATION);
     890          11 :                     pFrameProperties[nOldSize].Value <<= sal_Int16(
     891          22 :                         rAppendContext.pLastParagraphProperties->GethAnchor() );
     892             :                 }
     893             : 
     894          11 :                 if( rAppendContext.pLastParagraphProperties->IsyValid() )
     895             :                 {
     896          11 :                     sal_Int32 nOldSize = aFrameProperties.getLength();
     897          11 :                     aFrameProperties.realloc( nOldSize + 1 );
     898          11 :                     pFrameProperties = aFrameProperties.getArray();
     899          11 :                     pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT_POSITION);
     900          11 :                     pFrameProperties[nOldSize].Value <<= rAppendContext.pLastParagraphProperties->Gety();
     901             :                 }
     902             : 
     903          11 :                 if( rAppendContext.pLastParagraphProperties->GetvAnchor() >= 0 )
     904             :                 {
     905          11 :                     sal_Int32 nOldSize = aFrameProperties.getLength();
     906          11 :                     aFrameProperties.realloc( nOldSize + 1 );
     907          11 :                     pFrameProperties = aFrameProperties.getArray();
     908          11 :                     pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT_RELATION);
     909          11 :                     pFrameProperties[nOldSize].Value <<= sal_Int16(
     910          22 :                         rAppendContext.pLastParagraphProperties->GetvAnchor() );
     911             :                 }
     912             : 
     913          11 :                 if( rAppendContext.pLastParagraphProperties->GetWrap() >= 0 )
     914             :                 {
     915           0 :                     sal_Int32 nOldSize = aFrameProperties.getLength();
     916           0 :                     aFrameProperties.realloc( nOldSize + 1 );
     917           0 :                     pFrameProperties = aFrameProperties.getArray();
     918           0 :                     pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_SURROUND);
     919           0 :                     pFrameProperties[nOldSize].Value <<= text::WrapTextMode(
     920           0 :                         rAppendContext.pLastParagraphProperties->GetWrap() );
     921             :                 }
     922             : 
     923             :                 lcl_MoveBorderPropertiesToFrame(aFrameProperties,
     924             :                     rAppendContext.pLastParagraphProperties->GetStartingRange(),
     925          11 :                     rAppendContext.pLastParagraphProperties->GetEndingRange());
     926             :             }
     927             : 
     928             :             //frame conversion has to be executed after table conversion
     929             :             RegisterFrameConversion(
     930             :                 rAppendContext.pLastParagraphProperties->GetStartingRange(),
     931             :                 rAppendContext.pLastParagraphProperties->GetEndingRange(),
     932          14 :                 aFrameProperties );
     933             :         }
     934           0 :         catch( const uno::Exception& )
     935             :         {
     936             :         }
     937             :     }
     938         244 : }
     939             : 
     940         995 : void DomainMapper_Impl::finishParagraph( PropertyMapPtr pPropertyMap )
     941             : {
     942             : #ifdef DEBUG_DOMAINMAPPER
     943             :     dmapper_logger->startElement("finishParagraph");
     944             : #endif
     945             : 
     946         995 :     ParagraphPropertyMap* pParaContext = dynamic_cast< ParagraphPropertyMap* >( pPropertyMap.get() );
     947         995 :     TextAppendContext& rAppendContext = m_aTextAppendStack.top();
     948         995 :     uno::Reference< text::XTextAppend >  xTextAppend;
     949         995 :     if (!m_aTextAppendStack.empty())
     950         995 :         xTextAppend = rAppendContext.xTextAppend;
     951         995 :     PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     952             : 
     953             : #ifdef DEBUG_DOMAINMAPPER
     954             :     dmapper_logger->attribute("isTextAppend", xTextAppend.is());
     955             : #endif
     956             : 
     957         995 :     if(xTextAppend.is() && ! getTableManager( ).isIgnore() && pParaContext != NULL)
     958             :     {
     959             :         try
     960             :         {
     961             :             /*the following combinations of previous and current frame settings can occur:
     962             :                 (1) - no old frame and no current frame     -> no special action
     963             :                 (2) - no old frame and current DropCap      -> save DropCap for later use, don't call finishParagraph
     964             :                                                             remove character properties of the DropCap?
     965             :                 (3) - no old frame and current Frame        -> save Frame for later use
     966             :                 (4) - old DropCap and no current frame      -> add DropCap to the properties of the finished paragraph, delete previous setting
     967             :                 (5) - old DropCap and current frame         -> add DropCap to the properties of the finished paragraph, save current frame settings
     968             :                 (6) - old Frame and new DropCap             -> add old Frame, save DropCap for later use
     969             :                 (7) - old Frame and new same Frame          -> continue
     970             :                 (8) - old Frame and new different Frame     -> add old Frame, save new Frame for later use
     971             :                 (9) - old Frame and no current frame        -> add old Frame, delete previous settings
     972             : 
     973             :               old _and_ new DropCap must not occur
     974             :              */
     975             : 
     976             :             bool bIsDropCap =
     977         736 :                 pParaContext->IsFrameMode() &&
     978         736 :                 sal::static_int_cast<Id>(pParaContext->GetDropCap()) != NS_ooxml::LN_Value_wordprocessingml_ST_DropCap_none;
     979             : 
     980         736 :             style::DropCapFormat aDrop;
     981         736 :             ParagraphPropertiesPtr pToBeSavedProperties;
     982         736 :             bool bKeepLastParagraphProperties = false;
     983         736 :             if( bIsDropCap )
     984             :             {
     985             :                 uno::Reference<text::XParagraphCursor> xParaCursor(
     986           0 :                     xTextAppend->createTextCursorByRange(xTextAppend->getEnd()), uno::UNO_QUERY_THROW);
     987             :                 //select paragraph
     988           0 :                 xParaCursor->gotoStartOfParagraph( true );
     989           0 :                 uno::Reference< beans::XPropertyState > xParaProperties( xParaCursor, uno::UNO_QUERY_THROW );
     990           0 :                 xParaProperties->setPropertyToDefault(rPropNameSupplier.GetName(PROP_CHAR_ESCAPEMENT));
     991           0 :                 xParaProperties->setPropertyToDefault(rPropNameSupplier.GetName(PROP_CHAR_HEIGHT));
     992             :                 //handles (2) and part of (6)
     993           0 :                 pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
     994           0 :                 sal_Int32 nCount = xParaCursor->getString().getLength();
     995           0 :                 pToBeSavedProperties->SetDropCapLength(nCount > 0 && nCount < 255 ? (sal_Int8)nCount : 1);
     996             :             }
     997         736 :             if( rAppendContext.pLastParagraphProperties.get() )
     998             :             {
     999          14 :                 if( sal::static_int_cast<Id>(rAppendContext.pLastParagraphProperties->GetDropCap()) != NS_ooxml::LN_Value_wordprocessingml_ST_DropCap_none)
    1000             :                 {
    1001             :                     //handles (4) and part of (5)
    1002             :                     //create a DropCap property, add it to the property sequence of finishParagraph
    1003           0 :                     sal_Int32 nLines = rAppendContext.pLastParagraphProperties->GetLines();
    1004           0 :                     aDrop.Lines = nLines > 0 && nLines < 254 ? (sal_Int8)++nLines : 2;
    1005           0 :                     aDrop.Count = rAppendContext.pLastParagraphProperties->GetDropCapLength();
    1006           0 :                     aDrop.Distance  = 0; //TODO: find distance value
    1007             :                     //completes (5)
    1008           0 :                     if( pParaContext->IsFrameMode() )
    1009           0 :                         pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
    1010             :                 }
    1011          14 :                 else if(*rAppendContext.pLastParagraphProperties == *pParaContext )
    1012             :                 {
    1013             :                     //handles (7)
    1014           4 :                     rAppendContext.pLastParagraphProperties->SetEndingRange(rAppendContext.xInsertPosition.is() ? rAppendContext.xInsertPosition : xTextAppend->getEnd());
    1015           4 :                     bKeepLastParagraphProperties = true;
    1016             :                 }
    1017             :                 else
    1018             :                 {
    1019             :                     //handles (8)(9) and completes (6)
    1020          10 :                     CheckUnregisteredFrameConversion( );
    1021             : 
    1022             :                     // If different frame properties are set on this paragraph, keep them.
    1023          10 :                     if ( !bIsDropCap && pParaContext->IsFrameMode() )
    1024             :                     {
    1025           2 :                         pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
    1026           2 :                         lcl_AddRangeAndStyle(pToBeSavedProperties, xTextAppend, pPropertyMap, rAppendContext);
    1027             :                     }
    1028             :                 }
    1029             : 
    1030             :             }
    1031             :             else //
    1032             :             {
    1033             :                 // (1) doesn't need handling
    1034             :                 //
    1035         722 :                 if( !bIsDropCap && pParaContext->IsFrameMode() )
    1036             :                 {
    1037          11 :                     pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
    1038          11 :                     lcl_AddRangeAndStyle(pToBeSavedProperties, xTextAppend, pPropertyMap, rAppendContext);
    1039             :                 }
    1040             :             }
    1041         736 :             uno::Sequence< beans::PropertyValue > aProperties;
    1042         736 :             if( pPropertyMap.get() )
    1043             :             {
    1044         736 :                 aProperties = pPropertyMap->GetPropertyValues();
    1045             :             }
    1046         736 :             if( !bIsDropCap )
    1047             :             {
    1048         736 :                 if( aDrop.Lines > 1 )
    1049             :                 {
    1050           0 :                     sal_uInt32 nLength = aProperties.getLength();
    1051           0 :                     aProperties.realloc(  nLength + 1 );
    1052           0 :                     aProperties[nLength].Value <<= aDrop;
    1053           0 :                     aProperties[nLength].Name = rPropNameSupplier.GetName(PROP_DROP_CAP_FORMAT);
    1054             :                 }
    1055         736 :                 uno::Reference< text::XTextRange > xTextRange;
    1056         736 :                 if (rAppendContext.xInsertPosition.is())
    1057             :                 {
    1058           0 :                     xTextRange = xTextAppend->finishParagraphInsert( aProperties, rAppendContext.xInsertPosition );
    1059           0 :                     rAppendContext.xCursor->gotoNextParagraph(false);
    1060           0 :                     if (rAppendContext.pLastParagraphProperties.get())
    1061           0 :                         rAppendContext.pLastParagraphProperties->SetEndingRange(xTextRange->getEnd());
    1062             :                 }
    1063             :                 else
    1064         736 :                     xTextRange = xTextAppend->finishParagraph( aProperties );
    1065         731 :                 getTableManager( ).handle(xTextRange);
    1066             : 
    1067             :                 // Get the end of paragraph character inserted
    1068         731 :                 uno::Reference< text::XTextCursor > xCur = xTextRange->getText( )->createTextCursor( );
    1069         731 :                 if (rAppendContext.xInsertPosition.is())
    1070           0 :                     xCur->gotoRange( rAppendContext.xInsertPosition, false );
    1071             :                 else
    1072         731 :                     xCur->gotoEnd( false );
    1073         731 :                 xCur->goLeft( 1 , true );
    1074         731 :                 uno::Reference< text::XTextRange > xParaEnd( xCur, uno::UNO_QUERY );
    1075         731 :                 CheckParaRedline( xParaEnd );
    1076             : 
    1077         731 :                 m_bIsFirstParaInSection = false;
    1078         731 :                 m_bIsLastParaInSection = false;
    1079         731 :                 m_bParaChanged = false;
    1080             : 
    1081             :                 // Reset the frame properties for the next paragraph
    1082         731 :                 pParaContext->ResetFrameProperties();
    1083             :             }
    1084         731 :             if( !bKeepLastParagraphProperties )
    1085         732 :                 rAppendContext.pLastParagraphProperties = pToBeSavedProperties;
    1086             :         }
    1087           1 :         catch(const lang::IllegalArgumentException&)
    1088             :         {
    1089             :             OSL_FAIL( "IllegalArgumentException in DomainMapper_Impl::finishParagraph" );
    1090             :         }
    1091           4 :         catch(const uno::Exception&)
    1092             :         {
    1093             :         }
    1094         995 :     }
    1095             : 
    1096             : #ifdef DEBUG_DOMAINMAPPER
    1097             :     dmapper_logger->endElement();
    1098             : #endif
    1099         995 : }
    1100             : 
    1101             : 
    1102           6 : util::DateTime lcl_DateStringToDateTime( const OUString& rDateTime )
    1103             : {
    1104           6 :     util::DateTime aDateTime;
    1105             :     //xsd::DateTime in the format [-]CCYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm] example: 2008-01-21T10:42:00Z
    1106             :     //OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const SAL_THROW(())
    1107           6 :     sal_Int32 nIndex = 0;
    1108           6 :     OUString sDate = rDateTime.getToken( 0, 'T', nIndex );
    1109             :     // HACK: this is broken according to the spec, but MSOffice always treats the time as local,
    1110             :     // and writes it as Z (=UTC+0)
    1111           6 :     OUString sTime = rDateTime.getToken( 0, 'Z', nIndex );
    1112           6 :     nIndex = 0;
    1113           6 :     aDateTime.Year = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() );
    1114           6 :     aDateTime.Month = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() );
    1115           6 :     aDateTime.Day = sal_uInt16( sDate.copy( nIndex ).toInt32() );
    1116             : 
    1117           6 :     nIndex = 0;
    1118           6 :     aDateTime.Hours = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() );
    1119           6 :     aDateTime.Minutes = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() );
    1120           6 :     aDateTime.Seconds = sal_uInt16( sTime.copy( nIndex ).toInt32() );
    1121             : 
    1122           6 :     return aDateTime;
    1123             : }
    1124        4361 : void DomainMapper_Impl::appendTextPortion( const OUString& rString, PropertyMapPtr pPropertyMap )
    1125             : {
    1126        4361 :     if (m_aTextAppendStack.empty())
    1127        4361 :         return;
    1128        4361 :     if( pPropertyMap == m_pTopContext && !deferredCharacterProperties.empty())
    1129        3975 :         processDeferredCharacterProperties();
    1130        4361 :     uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
    1131        4361 :     if(xTextAppend.is() && ! getTableManager( ).isIgnore())
    1132             :     {
    1133             :         try
    1134             :         {
    1135         573 :             uno::Reference< text::XTextRange > xTextRange;
    1136         573 :             if (m_aTextAppendStack.top().xInsertPosition.is())
    1137             :             {
    1138           0 :                 xTextRange = xTextAppend->insertTextPortion(rString, pPropertyMap->GetPropertyValues(), m_aTextAppendStack.top().xInsertPosition);
    1139           0 :                 m_aTextAppendStack.top().xCursor->gotoRange(xTextRange->getEnd(), false);
    1140             :             }
    1141             :             else
    1142         573 :                 xTextRange = xTextAppend->appendTextPortion(rString, pPropertyMap->GetPropertyValues());
    1143         573 :             CheckRedline( xTextRange );
    1144         573 :             m_bParaChanged = true;
    1145             : 
    1146             :             //getTableManager( ).handle(xTextRange);
    1147             :         }
    1148           0 :         catch(const lang::IllegalArgumentException&)
    1149             :         {
    1150             :             OSL_FAIL( "IllegalArgumentException in DomainMapper_Impl::appendTextPortion" );
    1151             :         }
    1152           0 :         catch(const uno::Exception&)
    1153             :         {
    1154             :             OSL_FAIL( "Exception in DomainMapper_Impl::appendTextPortion" );
    1155             :         }
    1156        4361 :     }
    1157             : }
    1158             : 
    1159             : 
    1160         217 : void DomainMapper_Impl::appendTextContent(
    1161             :     const uno::Reference< text::XTextContent > xContent,
    1162             :     const uno::Sequence< beans::PropertyValue > xPropertyValues
    1163             :     )
    1164             : {
    1165         217 :     uno::Reference< text::XTextAppendAndConvert >  xTextAppendAndConvert( m_aTextAppendStack.top().xTextAppend, uno::UNO_QUERY );
    1166             :     OSL_ENSURE( xTextAppendAndConvert.is(), "trying to append a text content without XTextAppendAndConvert" );
    1167         217 :     if(xTextAppendAndConvert.is() && ! getTableManager( ).isIgnore())
    1168             :     {
    1169             :         try
    1170             :         {
    1171         217 :             if (m_aTextAppendStack.top().xInsertPosition.is())
    1172           0 :                 xTextAppendAndConvert->insertTextContentWithProperties( xContent, xPropertyValues, m_aTextAppendStack.top().xInsertPosition );
    1173             :             else
    1174         217 :                 xTextAppendAndConvert->appendTextContent( xContent, xPropertyValues );
    1175             :         }
    1176           0 :         catch(const lang::IllegalArgumentException&)
    1177             :         {
    1178             :         }
    1179          32 :         catch(const uno::Exception&)
    1180             :         {
    1181             :         }
    1182         217 :     }
    1183         217 : }
    1184             : 
    1185             : 
    1186             : 
    1187           1 : void DomainMapper_Impl::appendOLE( const OUString& rStreamName, OLEHandlerPtr pOLEHandler )
    1188             : {
    1189           1 :     static const OUString sEmbeddedService("com.sun.star.text.TextEmbeddedObject");
    1190             :     try
    1191             :     {
    1192           1 :         uno::Reference< text::XTextContent > xOLE( m_xTextFactory->createInstance(sEmbeddedService), uno::UNO_QUERY_THROW );
    1193           1 :         uno::Reference< beans::XPropertySet > xOLEProperties(xOLE, uno::UNO_QUERY_THROW);
    1194             : 
    1195           2 :         xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_STREAM_NAME ),
    1196           2 :                         uno::makeAny( rStreamName ));
    1197           1 :         awt::Size aSize = pOLEHandler->getSize();
    1198           1 :         if( !aSize.Width )
    1199           0 :             aSize.Width = 1000;
    1200           1 :         if( !aSize.Height )
    1201           0 :             aSize.Height = 1000;
    1202           2 :         xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_WIDTH ),
    1203           2 :                         uno::makeAny(aSize.Width));
    1204           2 :         xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_HEIGHT ),
    1205           2 :                         uno::makeAny(aSize.Height));
    1206             : 
    1207           1 :         uno::Reference< graphic::XGraphic > xGraphic = pOLEHandler->getReplacement();
    1208           2 :         xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_GRAPHIC ),
    1209           2 :                         uno::makeAny(xGraphic));
    1210             :         // mimic the treatment of graphics here.. it seems anchoring as character
    1211             :         // gives a better ( visually ) result
    1212           1 :         xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_ANCHOR_TYPE ),  uno::makeAny( text::TextContentAnchorType_AS_CHARACTER ) );
    1213             :         // remove ( if valid ) associated shape ( used for graphic replacement )
    1214           1 :         m_aAnchoredStack.top( ).bToRemove = true;
    1215           1 :         RemoveLastParagraph();
    1216           1 :         m_aTextAppendStack.pop();
    1217             : 
    1218             :         //
    1219           1 :         appendTextContent( xOLE, uno::Sequence< beans::PropertyValue >() );
    1220             : 
    1221             :     }
    1222           0 :     catch( const uno::Exception& )
    1223             :     {
    1224             :         OSL_FAIL( "Exception in creation of OLE object" );
    1225             :     }
    1226             : 
    1227           1 : }
    1228             : 
    1229         143 : void DomainMapper_Impl::appendStarMath( const Value& val )
    1230             : {
    1231         143 :     uno::Reference< embed::XEmbeddedObject > formula;
    1232         143 :     val.getAny() >>= formula;
    1233         143 :     if( formula.is() )
    1234             :     {
    1235         143 :         static const OUString sEmbeddedService("com.sun.star.text.TextEmbeddedObject");
    1236             :         try
    1237             :         {
    1238         143 :             uno::Reference< text::XTextContent > xStarMath( m_xTextFactory->createInstance(sEmbeddedService), uno::UNO_QUERY_THROW );
    1239         143 :             uno::Reference< beans::XPropertySet > xStarMathProperties(xStarMath, uno::UNO_QUERY_THROW);
    1240             : 
    1241         286 :             xStarMathProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_EMBEDDED_OBJECT ),
    1242         286 :                 val.getAny());
    1243             : 
    1244         143 :             uno::Reference< uno::XInterface > xInterface( formula->getComponent(), uno::UNO_QUERY );
    1245         143 :             Size size( 1000, 1000 );
    1246         143 :             if( oox::FormulaImportBase* formulaimport = dynamic_cast< oox::FormulaImportBase* >( xInterface.get()))
    1247         143 :                 size = formulaimport->getFormulaSize();
    1248         286 :             xStarMathProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_WIDTH ),
    1249         286 :                 uno::makeAny( sal_Int32(size.Width())));
    1250         286 :             xStarMathProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_HEIGHT ),
    1251         286 :                 uno::makeAny( sal_Int32(size.Height())));
    1252             :             // mimic the treatment of graphics here.. it seems anchoring as character
    1253             :             // gives a better ( visually ) result
    1254         286 :             xStarMathProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_ANCHOR_TYPE ),
    1255         286 :                 uno::makeAny( text::TextContentAnchorType_AS_CHARACTER ) );
    1256         143 :             appendTextContent( xStarMath, uno::Sequence< beans::PropertyValue >() );
    1257             :         }
    1258           0 :         catch( const uno::Exception& )
    1259             :         {
    1260             :             OSL_FAIL( "Exception in creation of StarMath object" );
    1261             :         }
    1262         143 :     }
    1263         143 : }
    1264             : 
    1265           7 : uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter(
    1266             :                                     uno::Reference< text::XTextRange >& xBefore )
    1267             : {
    1268           7 :     uno::Reference< beans::XPropertySet > xRet;
    1269           7 :     if (m_aTextAppendStack.empty())
    1270             :         return xRet;
    1271           7 :     uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
    1272           7 :     if(xTextAppend.is())
    1273             :     {
    1274             :         try
    1275             :         {
    1276             :             uno::Reference< text::XParagraphCursor > xCursor(
    1277           7 :                 xTextAppend->createTextCursorByRange( xBefore ), uno::UNO_QUERY_THROW);
    1278             :             //the cursor has been moved to the end of the paragraph because of the appendTextPortion() calls
    1279           7 :             xCursor->gotoStartOfParagraph( false );
    1280           7 :             if (m_aTextAppendStack.top().xInsertPosition.is())
    1281           0 :                 xCursor->gotoRange( m_aTextAppendStack.top().xInsertPosition, true );
    1282             :             else
    1283           7 :                 xCursor->gotoEnd( true );
    1284             :             //the paragraph after this new section is already inserted
    1285           7 :             xCursor->goLeft(1, true);
    1286           7 :             static const OUString sSectionService("com.sun.star.text.TextSection");
    1287           7 :             uno::Reference< text::XTextContent > xSection( m_xTextFactory->createInstance(sSectionService), uno::UNO_QUERY_THROW );
    1288           7 :             xSection->attach( uno::Reference< text::XTextRange >( xCursor, uno::UNO_QUERY_THROW) );
    1289           7 :             xRet = uno::Reference< beans::XPropertySet > (xSection, uno::UNO_QUERY );
    1290             :         }
    1291           0 :         catch(const uno::Exception&)
    1292             :         {
    1293             :         }
    1294             : 
    1295             :     }
    1296             : 
    1297           7 :     return xRet;
    1298             : }
    1299             : 
    1300             : 
    1301          18 : void DomainMapper_Impl::PushPageHeader(SectionPropertyMap::PageType eType)
    1302             : {
    1303          18 :     m_bInHeaderFooterImport = true;
    1304             : 
    1305             :     //get the section context
    1306          18 :     PropertyMapPtr pContext = DomainMapper_Impl::GetTopContextOfType(CONTEXT_SECTION);
    1307             :     //ask for the header name of the given type
    1308          18 :     SectionPropertyMap* pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() );
    1309          18 :     if(pSectionContext)
    1310             :     {
    1311             :         uno::Reference< beans::XPropertySet > xPageStyle =
    1312             :             pSectionContext->GetPageStyle(
    1313             :                 GetPageStyles(),
    1314             :                 m_xTextFactory,
    1315          18 :                 eType == SectionPropertyMap::PAGE_FIRST );
    1316          18 :         if (!xPageStyle.is())
    1317          18 :             return;
    1318             :         try
    1319             :         {
    1320          18 :             PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
    1321             :             //switch on header use
    1322          18 :             xPageStyle->setPropertyValue(
    1323          18 :                     rPropNameSupplier.GetName(PROP_HEADER_IS_ON),
    1324          36 :                     uno::makeAny(sal_True) );
    1325             :             // if a left header is available then header are not shared
    1326          18 :             bool bLeft = eType == SectionPropertyMap::PAGE_LEFT;
    1327          18 :             if( bLeft && m_pSettingsTable->GetEvenAndOddHeaders())
    1328           0 :                 xPageStyle->setPropertyValue(rPropNameSupplier.GetName(PROP_HEADER_IS_SHARED), uno::makeAny( false ));
    1329             : 
    1330             :             //set the interface
    1331          18 :             uno::Reference< text::XText > xHeaderText;
    1332          18 :             xPageStyle->getPropertyValue(rPropNameSupplier.GetName( bLeft ? PROP_HEADER_TEXT_LEFT : PROP_HEADER_TEXT) ) >>= xHeaderText;
    1333             :             m_aTextAppendStack.push( TextAppendContext(uno::Reference< text::XTextAppend >( xHeaderText, uno::UNO_QUERY_THROW),
    1334          18 :                         m_bIsNewDoc ? uno::Reference<text::XTextCursor>() : m_xBodyText->createTextCursorByRange(xHeaderText->getStart())));
    1335             :         }
    1336           0 :         catch( const uno::Exception& )
    1337             :         {
    1338          18 :         }
    1339          18 :     }
    1340             : }
    1341             : 
    1342             : 
    1343          11 : void DomainMapper_Impl::PushPageFooter(SectionPropertyMap::PageType eType)
    1344             : {
    1345          11 :     m_bInHeaderFooterImport = true;
    1346             : 
    1347             :     //get the section context
    1348          11 :     PropertyMapPtr pContext = DomainMapper_Impl::GetTopContextOfType(CONTEXT_SECTION);
    1349             :     //ask for the footer name of the given type
    1350          11 :     SectionPropertyMap* pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() );
    1351          11 :     if(pSectionContext)
    1352             :     {
    1353             :         uno::Reference< beans::XPropertySet > xPageStyle =
    1354             :                 pSectionContext->GetPageStyle(
    1355             :                     GetPageStyles(),
    1356             :                     m_xTextFactory,
    1357          11 :                     eType == SectionPropertyMap::PAGE_FIRST );
    1358          11 :         if (!xPageStyle.is())
    1359          11 :             return;
    1360             :         try
    1361             :         {
    1362          11 :             PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
    1363             :             //switch on footer use
    1364          11 :             xPageStyle->setPropertyValue(
    1365          11 :                     rPropNameSupplier.GetName(PROP_FOOTER_IS_ON),
    1366          22 :                     uno::makeAny(sal_True) );
    1367             :             // if a left header is available then footer is not shared
    1368          11 :             bool bLeft = eType == SectionPropertyMap::PAGE_LEFT;
    1369          11 :             if( bLeft && m_pSettingsTable->GetEvenAndOddHeaders())
    1370           0 :                 xPageStyle->setPropertyValue(rPropNameSupplier.GetName(PROP_FOOTER_IS_SHARED), uno::makeAny( false ));
    1371             :             //set the interface
    1372          11 :             uno::Reference< text::XText > xFooterText;
    1373          11 :             xPageStyle->getPropertyValue(rPropNameSupplier.GetName( bLeft ? PROP_FOOTER_TEXT_LEFT : PROP_FOOTER_TEXT) ) >>= xFooterText;
    1374             :             m_aTextAppendStack.push(TextAppendContext(uno::Reference< text::XTextAppend >( xFooterText, uno::UNO_QUERY_THROW ),
    1375          11 :                         m_bIsNewDoc ? uno::Reference<text::XTextCursor>() : m_xBodyText->createTextCursorByRange(xFooterText->getStart())));
    1376             :         }
    1377           0 :         catch( const uno::Exception& )
    1378             :         {
    1379          11 :         }
    1380          11 :     }
    1381             : }
    1382             : 
    1383             : 
    1384          29 : void DomainMapper_Impl::PopPageHeaderFooter()
    1385             : {
    1386             :     //header and footer always have an empty paragraph at the end
    1387             :     //this has to be removed
    1388          29 :     RemoveLastParagraph( );
    1389          29 :     if (!m_aTextAppendStack.empty())
    1390          29 :         m_aTextAppendStack.pop();
    1391          29 :     m_bInHeaderFooterImport = false;
    1392          29 : }
    1393             : 
    1394             : 
    1395           3 : void DomainMapper_Impl::PushFootOrEndnote( bool bIsFootnote )
    1396             : {
    1397             :     try
    1398             :     {
    1399           3 :         PropertyMapPtr pTopContext = GetTopContext();
    1400           3 :         uno::Reference< text::XText > xFootnoteText;
    1401           3 :         if (GetTextFactory().is())
    1402           6 :             xFootnoteText.set( GetTextFactory()->createInstance(
    1403             :             bIsFootnote ?
    1404           3 :                 OUString( "com.sun.star.text.Footnote" ) : OUString( "com.sun.star.text.Endnote" )),
    1405           3 :             uno::UNO_QUERY_THROW );
    1406           3 :         uno::Reference< text::XFootnote > xFootnote( xFootnoteText, uno::UNO_QUERY_THROW );
    1407           3 :         pTopContext->SetFootnote( xFootnote );
    1408           3 :         if( pTopContext->GetFootnoteSymbol() != 0)
    1409             :         {
    1410           0 :             xFootnote->setLabel( OUString( pTopContext->GetFootnoteSymbol() ) );
    1411             :         }
    1412           3 :         FontTablePtr pFontTable = GetFontTable();
    1413           3 :         uno::Sequence< beans::PropertyValue > aFontProperties;
    1414           3 :         if( pFontTable && pTopContext->GetFootnoteFontId() >= 0 && pFontTable->size() > (size_t)pTopContext->GetFootnoteFontId() )
    1415             :         {
    1416           0 :             const FontEntry::Pointer_t pFontEntry(pFontTable->getFontEntry(sal_uInt32(pTopContext->GetFootnoteFontId())));
    1417           0 :             PropertyMapPtr aFontProps( new PropertyMap );
    1418           0 :             aFontProps->Insert(PROP_CHAR_FONT_NAME, true, uno::makeAny( pFontEntry->sFontName  ));
    1419           0 :             aFontProps->Insert(PROP_CHAR_FONT_CHAR_SET, true, uno::makeAny( (sal_Int16)pFontEntry->nTextEncoding  ));
    1420           0 :             aFontProps->Insert(PROP_CHAR_FONT_PITCH, true, uno::makeAny( pFontEntry->nPitchRequest  ));
    1421           0 :             aFontProperties = aFontProps->GetPropertyValues();
    1422             :         }
    1423           3 :         else if(!pTopContext->GetFootnoteFontName().isEmpty())
    1424             :         {
    1425           0 :             PropertyMapPtr aFontProps( new PropertyMap );
    1426           0 :             aFontProps->Insert(PROP_CHAR_FONT_NAME, true, uno::makeAny( pTopContext->GetFootnoteFontName()  ));
    1427           0 :             aFontProperties = aFontProps->GetPropertyValues();
    1428             :         }
    1429           3 :         appendTextContent( uno::Reference< text::XTextContent >( xFootnoteText, uno::UNO_QUERY_THROW ), aFontProperties );
    1430             :         m_aTextAppendStack.push(TextAppendContext(uno::Reference< text::XTextAppend >( xFootnoteText, uno::UNO_QUERY_THROW ),
    1431           3 :                     m_bIsNewDoc ? uno::Reference<text::XTextCursor>() : m_xBodyText->createTextCursorByRange(xFootnoteText->getStart())));
    1432             : 
    1433             :         // Redlines for the footnote anchor
    1434           3 :         CheckRedline( xFootnote->getAnchor( ) );
    1435             :     }
    1436           0 :     catch( const uno::Exception& )
    1437             :     {
    1438             :         OSL_FAIL( "exception in PushFootOrEndnote" );
    1439             :     }
    1440           3 : }
    1441             : 
    1442           2 : void DomainMapper_Impl::CreateRedline( uno::Reference< text::XTextRange > xRange, RedlineParamsPtr& pRedline )
    1443             : {
    1444           2 :     if ( pRedline.get( ) )
    1445             :     {
    1446             :         try
    1447             :         {
    1448           2 :             OUString sType;
    1449           2 :             PropertyNameSupplier & rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier(  );
    1450           2 :             switch ( pRedline->m_nToken & 0xffff )
    1451             :             {
    1452             :             case ooxml::OOXML_mod:
    1453           0 :                 sType = rPropNameSupplier.GetName( PROP_FORMAT );
    1454           0 :                 break;
    1455             :             case ooxml::OOXML_ins:
    1456           0 :                 sType = rPropNameSupplier.GetName( PROP_INSERT );
    1457           0 :                 break;
    1458             :             case ooxml::OOXML_del:
    1459           2 :                 sType = rPropNameSupplier.GetName( PROP_DELETE );
    1460           2 :                 break;
    1461             :             }
    1462           2 :             uno::Reference < text::XRedline > xRedline( xRange, uno::UNO_QUERY_THROW );
    1463           2 :             beans::PropertyValues aRedlineProperties( 2 );
    1464           2 :             beans::PropertyValue * pRedlineProperties = aRedlineProperties.getArray(  );
    1465           2 :             pRedlineProperties[0].Name = rPropNameSupplier.GetName( PROP_REDLINE_AUTHOR );
    1466           2 :             pRedlineProperties[0].Value <<= pRedline->m_sAuthor;
    1467           2 :             pRedlineProperties[1].Name = rPropNameSupplier.GetName( PROP_REDLINE_DATE_TIME );
    1468           2 :             pRedlineProperties[1].Value <<= lcl_DateStringToDateTime( pRedline->m_sDate );
    1469             : 
    1470           2 :             xRedline->makeRedline( sType, aRedlineProperties );
    1471             :         }
    1472           0 :         catch( const uno::Exception & )
    1473             :         {
    1474             :             OSL_FAIL( "Exception in makeRedline" );
    1475             :         }
    1476             :     }
    1477           2 : }
    1478             : 
    1479         731 : void DomainMapper_Impl::CheckParaRedline( uno::Reference< text::XTextRange > xRange )
    1480             : {
    1481         731 :     if ( m_pParaRedline.get( ) )
    1482             :     {
    1483           0 :         CreateRedline( xRange, m_pParaRedline );
    1484           0 :         ResetParaRedline( );
    1485             :     }
    1486         731 : }
    1487             : 
    1488         576 : void DomainMapper_Impl::CheckRedline( uno::Reference< text::XTextRange > xRange )
    1489             : {
    1490         576 :     vector<RedlineParamsPtr>::iterator pIt = m_aRedlines.begin( );
    1491         576 :     vector< RedlineParamsPtr > aCleaned;
    1492         578 :     for (; pIt != m_aRedlines.end( ); ++pIt )
    1493             :     {
    1494           2 :         CreateRedline( xRange, *pIt );
    1495             : 
    1496             :         // Adding the non-mod redlines to the temporary vector
    1497           2 :         if ( pIt->get( ) && ( ( *pIt )->m_nToken & 0xffff ) != ooxml::OOXML_mod )
    1498             :         {
    1499           2 :             aCleaned.push_back( *pIt );
    1500             :         }
    1501             :     }
    1502             : 
    1503         576 :     m_aRedlines.swap( aCleaned );
    1504         576 : }
    1505             : 
    1506           0 : void DomainMapper_Impl::StartParaChange( )
    1507             : {
    1508           0 :     m_bIsParaChange = true;
    1509           0 : }
    1510             : 
    1511           2 : void DomainMapper_Impl::EndParaChange( )
    1512             : {
    1513           2 :     m_bIsParaChange = false;
    1514           2 : }
    1515             : 
    1516             : 
    1517             : 
    1518           4 : void DomainMapper_Impl::PushAnnotation()
    1519             : {
    1520             :     try
    1521             :     {
    1522           4 :         PropertyMapPtr pTopContext = GetTopContext();
    1523           4 :         if (!GetTextFactory().is())
    1524           4 :             return;
    1525           8 :         m_xAnnotationField = uno::Reference< beans::XPropertySet >( GetTextFactory()->createInstance(
    1526           4 :                 "com.sun.star.text.TextField.Annotation" ),
    1527           4 :             uno::UNO_QUERY_THROW );
    1528           4 :         uno::Reference< text::XText > xAnnotationText;
    1529           4 :         m_xAnnotationField->getPropertyValue("TextRange") >>= xAnnotationText;
    1530             :         m_aTextAppendStack.push(TextAppendContext(uno::Reference< text::XTextAppend >( xAnnotationText, uno::UNO_QUERY_THROW ),
    1531           4 :                     m_bIsNewDoc ? uno::Reference<text::XTextCursor>() : m_xBodyText->createTextCursorByRange(xAnnotationText->getStart())));
    1532             :     }
    1533           0 :     catch( const uno::Exception& )
    1534             :     {
    1535             :         OSL_FAIL( "exception in PushAnnotation" );
    1536             :     }
    1537             : }
    1538             : 
    1539             : 
    1540           3 : void DomainMapper_Impl::PopFootOrEndnote()
    1541             : {
    1542           3 :     RemoveLastParagraph();
    1543           3 :     if (!m_aTextAppendStack.empty())
    1544           3 :         m_aTextAppendStack.pop();
    1545           3 : }
    1546             : 
    1547             : 
    1548           4 : void DomainMapper_Impl::PopAnnotation()
    1549             : {
    1550           4 :     RemoveLastParagraph();
    1551             : 
    1552           4 :     m_aTextAppendStack.pop();
    1553             : 
    1554             :     // See if the annotation will be a single position or a range.
    1555           4 :     if (!m_aAnnotationPosition.m_xStart.is() || !m_aAnnotationPosition.m_xEnd.is())
    1556             :     {
    1557           0 :         uno::Sequence< beans::PropertyValue > aEmptyProperties;
    1558           0 :         appendTextContent( uno::Reference< text::XTextContent >( m_xAnnotationField, uno::UNO_QUERY_THROW ), aEmptyProperties );
    1559             :     }
    1560             :     else
    1561             :     {
    1562             :         // Create a range that points to the annotation start/end.
    1563           4 :         uno::Reference<text::XText> xText = m_aAnnotationPosition.m_xStart->getText();
    1564           4 :         uno::Reference<text::XTextCursor> xCursor = xText->createTextCursorByRange(m_aAnnotationPosition.m_xStart);
    1565           4 :         xCursor->gotoRange(m_aAnnotationPosition.m_xEnd, true);
    1566           4 :         uno::Reference<text::XTextRange> xTextRange(xCursor, uno::UNO_QUERY_THROW);
    1567             : 
    1568             :         // Attach the annotation to the range.
    1569           4 :         uno::Reference<text::XTextAppend> xTextAppend = m_aTextAppendStack.top().xTextAppend;
    1570           4 :         xTextAppend->insertTextContent(xTextRange, uno::Reference<text::XTextContent>(m_xAnnotationField, uno::UNO_QUERY_THROW), !xCursor->isCollapsed());
    1571             :     }
    1572             : 
    1573           4 :     m_aAnnotationPosition.m_xStart.clear();
    1574           4 :     m_aAnnotationPosition.m_xEnd.clear();
    1575           4 :     m_xAnnotationField.clear();
    1576             : 
    1577           4 : }
    1578             : 
    1579          46 : void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape > xShape )
    1580             : {
    1581          46 :     if (m_aTextAppendStack.empty())
    1582          46 :         return;
    1583          46 :     uno::Reference<text::XTextAppend> xTextAppend = m_aTextAppendStack.top().xTextAppend;
    1584             :     try
    1585             :     {
    1586          46 :         uno::Reference< text::XTextRange > xShapeText( xShape, uno::UNO_QUERY_THROW);
    1587             :         // Add the shape to the text append stack
    1588             :         m_aTextAppendStack.push( TextAppendContext(uno::Reference< text::XTextAppend >( xShape, uno::UNO_QUERY_THROW ),
    1589          41 :                     m_bIsNewDoc ? uno::Reference<text::XTextCursor>() : m_xBodyText->createTextCursorByRange(xShapeText->getStart() )));
    1590             : 
    1591             :         // Add the shape to the anchored objects stack
    1592          41 :         uno::Reference< text::XTextContent > xTxtContent( xShape, uno::UNO_QUERY_THROW );
    1593          41 :         m_aAnchoredStack.push( xTxtContent );
    1594             : 
    1595          41 :         PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
    1596             : 
    1597          41 :         uno::Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY_THROW );
    1598             : #ifdef DEBUG_DOMAINMAPPER
    1599             :         dmapper_logger->unoPropertySet(xProps);
    1600             : #endif
    1601          41 :         uno::Reference< lang::XServiceInfo > xSInfo( xShape, uno::UNO_QUERY_THROW );
    1602          41 :         bool bIsGraphic = xSInfo->supportsService( "com.sun.star.drawing.GraphicObjectShape" );
    1603             : 
    1604             :         // If there are position properties, the shape should not be inserted "as character".
    1605          41 :         sal_Int32 nHoriPosition = 0, nVertPosition = 0;
    1606          41 :         xProps->getPropertyValue(rPropNameSupplier.GetName(PROP_HORI_ORIENT_POSITION)) >>= nHoriPosition;
    1607          41 :         xProps->getPropertyValue(rPropNameSupplier.GetName(PROP_VERT_ORIENT_POSITION)) >>= nVertPosition;
    1608          41 :         if (nHoriPosition != 0 || nVertPosition != 0)
    1609          14 :             bIsGraphic = false;
    1610          41 :         text::TextContentAnchorType nAnchorType(text::TextContentAnchorType_AT_PARAGRAPH);
    1611          41 :         xProps->getPropertyValue(rPropNameSupplier.GetName( PROP_ANCHOR_TYPE )) >>= nAnchorType;
    1612          41 :         if (nAnchorType == text::TextContentAnchorType_AT_PAGE)
    1613          23 :             bIsGraphic = false;
    1614             : 
    1615          41 :         if (nAnchorType != text::TextContentAnchorType_AT_PAGE)
    1616          18 :             xProps->setPropertyValue(
    1617          18 :                     rPropNameSupplier.GetName( PROP_OPAQUE ),
    1618          36 :                     uno::makeAny( true ) );
    1619          41 :         if (xSInfo->supportsService("com.sun.star.text.TextFrame"))
    1620             :         {
    1621          10 :             uno::Reference<text::XTextContent> xTextContent(xShape, uno::UNO_QUERY_THROW);
    1622          10 :             uno::Reference<text::XTextRange> xTextRange(xTextAppend->createTextCursorByRange(xTextAppend->getEnd()), uno::UNO_QUERY_THROW);
    1623          10 :             xTextAppend->insertTextContent(xTextRange, xTextContent, sal_False);
    1624             :         }
    1625          31 :         else if (nAnchorType != text::TextContentAnchorType_AS_CHARACTER)
    1626             :         {
    1627          29 :             xProps->setPropertyValue( rPropNameSupplier.GetName( PROP_ANCHOR_TYPE ), bIsGraphic  ?  uno::makeAny( text::TextContentAnchorType_AS_CHARACTER ) : uno::makeAny( text::TextContentAnchorType_AT_PARAGRAPH ) );
    1628             :         }
    1629             : 
    1630          41 :         appendTableManager( );
    1631          41 :         appendTableHandler( );
    1632          41 :         getTableManager().startLevel();
    1633             :     }
    1634           5 :     catch ( const uno::Exception& e )
    1635             :     {
    1636             :         SAL_WARN("writerfilter", "Exception when adding shape: " << e.Message);
    1637          46 :     }
    1638             : }
    1639             : 
    1640             : 
    1641             : 
    1642          46 : void DomainMapper_Impl::PopShapeContext()
    1643             : {
    1644          46 :     if ( m_aAnchoredStack.size() > 0 )
    1645             :     {
    1646          41 :         getTableManager().endLevel();
    1647          41 :         popTableManager();
    1648             : 
    1649             :         // For OLE object replacement shape, the text append context was already removed
    1650             :         // or the OLE object couldn't be inserted.
    1651          41 :         if ( !m_aAnchoredStack.top().bToRemove )
    1652             :         {
    1653          40 :             RemoveLastParagraph();
    1654          40 :             m_aTextAppendStack.pop();
    1655             :         }
    1656             : 
    1657          41 :         uno::Reference< text::XTextContent > xObj = m_aAnchoredStack.top( ).xTextContent;
    1658             :         try
    1659             :         {
    1660          41 :             appendTextContent( xObj, uno::Sequence< beans::PropertyValue >() );
    1661             :         }
    1662           0 :         catch ( const uno::RuntimeException& )
    1663             :         {
    1664             :             // this is normal: the shape is already attached
    1665             :         }
    1666             : 
    1667             :         // Remove the shape if required (most likely replacement shape for OLE object)
    1668          41 :         if ( m_aAnchoredStack.top().bToRemove )
    1669             :         {
    1670             :             try
    1671             :             {
    1672           1 :                 uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(m_xTextDocument, uno::UNO_QUERY_THROW);
    1673           1 :                 uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
    1674           1 :                 if ( xDrawPage.is() )
    1675             :                 {
    1676           1 :                     uno::Reference<drawing::XShape> xShape( xObj, uno::UNO_QUERY_THROW );
    1677           1 :                     xDrawPage->remove( xShape );
    1678           1 :                 }
    1679             :             }
    1680           0 :             catch( const uno::Exception& )
    1681             :             {
    1682             :             }
    1683             :         }
    1684          41 :         m_aAnchoredStack.pop();
    1685             :     }
    1686          46 : }
    1687             : 
    1688             : 
    1689           5 : OUString lcl_FindQuotedText( const OUString& rCommand,
    1690             :                 const sal_Char* cStartQuote, const sal_Unicode uEndQuote )
    1691             : {
    1692           5 :     OUString sRet;
    1693           5 :     OUString sStartQuote( OUString::createFromAscii(cStartQuote) );
    1694           5 :     sal_Int32 nStartIndex = rCommand.indexOf( sStartQuote );
    1695           5 :     if( nStartIndex >= 0 )
    1696             :     {
    1697           1 :         sal_Int32 nStartLength = sStartQuote.getLength();
    1698           1 :         sal_Int32 nEndIndex = rCommand.indexOf( uEndQuote, nStartIndex + nStartLength);
    1699           1 :         if( nEndIndex > nStartIndex )
    1700             :         {
    1701           1 :             sRet = rCommand.copy( nStartIndex + nStartLength, nEndIndex - nStartIndex - nStartLength);
    1702             :         }
    1703             :     }
    1704           5 :     return sRet;
    1705             : 
    1706             : }
    1707             : 
    1708             : 
    1709           4 : sal_Int16 lcl_ParseNumberingType( const OUString& rCommand )
    1710             : {
    1711           4 :     sal_Int16 nRet = style::NumberingType::PAGE_DESCRIPTOR;
    1712             : 
    1713             :     //  The command looks like: " PAGE \* Arabic "
    1714           4 :     OUString sNumber = lcl_FindQuotedText(rCommand, "\\* ", ' ');
    1715             : 
    1716           4 :     if( !sNumber.isEmpty() )
    1717             :     {
    1718             :         //todo: might make sense to hash this list, too
    1719             :         struct NumberingPairs
    1720             :         {
    1721             :             const sal_Char* cWordName;
    1722             :             sal_Int16       nType;
    1723             :         };
    1724             :         static const NumberingPairs aNumberingPairs[] =
    1725             :         {
    1726             :             {"Arabic", style::NumberingType::ARABIC}
    1727             :             ,{"ROMAN", style::NumberingType::ROMAN_UPPER}
    1728             :             ,{"roman", style::NumberingType::ROMAN_LOWER}
    1729             :             ,{"ALPHABETIC", style::NumberingType::CHARS_UPPER_LETTER}
    1730             :             ,{"alphabetic", style::NumberingType::CHARS_LOWER_LETTER}
    1731             :             ,{"CircleNum", style::NumberingType::CIRCLE_NUMBER}
    1732             :             ,{"ThaiArabic", style::NumberingType::CHARS_THAI}
    1733             :             ,{"ThaiCardText", style::NumberingType::CHARS_THAI}
    1734             :             ,{"ThaiLetter", style::NumberingType::CHARS_THAI}
    1735             : //            ,{"SBCHAR", style::NumberingType::}
    1736             : //            ,{"DBCHAR", style::NumberingType::}
    1737             : //            ,{"DBNUM1", style::NumberingType::}
    1738             : //            ,{"DBNUM2", style::NumberingType::}
    1739             : //            ,{"DBNUM3", style::NumberingType::}
    1740             : //            ,{"DBNUM4", style::NumberingType::}
    1741             :             ,{"Aiueo", style::NumberingType::AIU_FULLWIDTH_JA}
    1742             :             ,{"Iroha", style::NumberingType::IROHA_FULLWIDTH_JA}
    1743             : //            ,{"ZODIAC1", style::NumberingType::}
    1744             : //            ,{"ZODIAC2", style::NumberingType::}
    1745             : //            ,{"ZODIAC3", style::NumberingType::}
    1746             : //            ,{"CHINESENUM1", style::NumberingType::}
    1747             : //            ,{"CHINESENUM2", style::NumberingType::}
    1748             : //            ,{"CHINESENUM3", style::NumberingType::}
    1749             :             ,{"ArabicAlpha", style::NumberingType::CHARS_ARABIC}
    1750             :             ,{"ArabicAbjad", style::NumberingType::FULLWIDTH_ARABIC}
    1751             : /* possible values:
    1752             : style::NumberingType::
    1753             : 
    1754             :     CHARS_UPPER_LETTER_N
    1755             :     CHARS_LOWER_LETTER_N
    1756             :     TRANSLITERATION
    1757             :     NATIVE_NUMBERING
    1758             :     CIRCLE_NUMBER
    1759             :     NUMBER_LOWER_ZH
    1760             :     NUMBER_UPPER_ZH
    1761             :     NUMBER_UPPER_ZH_TW
    1762             :     TIAN_GAN_ZH
    1763             :     DI_ZI_ZH
    1764             :     NUMBER_TRADITIONAL_JA
    1765             :     AIU_HALFWIDTH_JA
    1766             :     IROHA_HALFWIDTH_JA
    1767             :     NUMBER_UPPER_KO
    1768             :     NUMBER_HANGUL_KO
    1769             :     HANGUL_JAMO_KO
    1770             :     HANGUL_SYLLABLE_KO
    1771             :     HANGUL_CIRCLED_JAMO_KO
    1772             :     HANGUL_CIRCLED_SYLLABLE_KO
    1773             :     CHARS_HEBREW
    1774             :     CHARS_NEPALI
    1775             :     CHARS_KHMER
    1776             :     CHARS_LAO
    1777             :     CHARS_TIBETAN
    1778             :     CHARS_CYRILLIC_UPPER_LETTER_BG
    1779             :     CHARS_CYRILLIC_LOWER_LETTER_BG
    1780             :     CHARS_CYRILLIC_UPPER_LETTER_N_BG
    1781             :     CHARS_CYRILLIC_LOWER_LETTER_N_BG
    1782             :     CHARS_CYRILLIC_UPPER_LETTER_RU
    1783             :     CHARS_CYRILLIC_LOWER_LETTER_RU
    1784             :     CHARS_CYRILLIC_UPPER_LETTER_N_RU
    1785             :     CHARS_CYRILLIC_LOWER_LETTER_N_RU
    1786             :     CHARS_CYRILLIC_UPPER_LETTER_SR
    1787             :     CHARS_CYRILLIC_LOWER_LETTER_SR
    1788             :     CHARS_CYRILLIC_UPPER_LETTER_N_SR
    1789             :     CHARS_CYRILLIC_LOWER_LETTER_N_SR*/
    1790             : 
    1791             :         };
    1792           0 :         for( sal_uInt32 nNum = 0; nNum < sizeof(aNumberingPairs)/sizeof( NumberingPairs ); ++nNum)
    1793             :         {
    1794           0 :             if( /*sCommand*/sNumber.equalsAscii(aNumberingPairs[nNum].cWordName ))
    1795             :             {
    1796           0 :                 nRet = aNumberingPairs[nNum].nType;
    1797           0 :                 break;
    1798             :             }
    1799             :         }
    1800             : 
    1801             :     }
    1802           4 :     return nRet;
    1803             : }
    1804             : 
    1805             : 
    1806           1 : OUString lcl_ParseFormat( const OUString& rCommand )
    1807             : {
    1808             :     //  The command looks like: " DATE \@ "dd MMMM yyyy"
    1809           1 :     return lcl_FindQuotedText(rCommand, "\\@ \"", '\"');
    1810             : }
    1811             : /*-------------------------------------------------------------------------
    1812             : extract a parameter (with or without quotes) between the command and the following backslash
    1813             :   -----------------------------------------------------------------------*/
    1814           1 : OUString lcl_ExtractParameter(const OUString& rCommand, sal_Int32 nCommandLength )
    1815             : {
    1816           1 :     sal_Int32 nStartIndex = nCommandLength;
    1817           1 :     sal_Int32 nEndIndex = 0;
    1818           1 :     sal_Int32 nQuoteIndex = rCommand.indexOf( '\"', nStartIndex);
    1819           1 :     if( nQuoteIndex >= 0)
    1820             :     {
    1821           0 :         nStartIndex = nQuoteIndex + 1;
    1822           0 :         nEndIndex = rCommand.indexOf( '\"', nStartIndex + 1) - 1;
    1823             :     }
    1824             :     else
    1825             :     {
    1826           1 :         nEndIndex = rCommand.indexOf(" \\", nStartIndex);
    1827             :     }
    1828           1 :     OUString sRet;
    1829           1 :     if( nEndIndex > nStartIndex + 1 )
    1830             :     {
    1831             :         //remove spaces at start and end of the result
    1832           1 :         if(nQuoteIndex <= 0)
    1833             :         {
    1834           1 :             const sal_Unicode* pCommandStr = rCommand.getStr();
    1835           2 :             while( nStartIndex < nEndIndex && pCommandStr[nStartIndex] == ' ')
    1836           0 :                     ++nStartIndex;
    1837           4 :             while( nEndIndex > nStartIndex && pCommandStr[nEndIndex] == ' ')
    1838           2 :                     --nEndIndex;
    1839             :         }
    1840           1 :         sRet = rCommand.copy( nStartIndex, nEndIndex - nStartIndex + 1);
    1841             :     }
    1842           1 :     return sRet;
    1843             : }
    1844             : 
    1845             : 
    1846             : 
    1847           1 : OUString lcl_ExctractAskVariableAndHint( const OUString& rCommand, OUString& rHint )
    1848             : {
    1849             :     // the first word after "ASK " is the variable
    1850             :     // the text after the variable and before a '\' is the hint
    1851             :     // if no hint is set the variable is used as hint
    1852             :     // the quotes of the hint have to be removed
    1853           1 :     sal_Int32 nIndex = rCommand.indexOf( ' ', 2);//find last space after 'ASK'
    1854           3 :     while(rCommand.getStr()[nIndex] == ' ')
    1855           1 :         ++nIndex;
    1856           1 :     OUString sShortCommand( rCommand.copy( nIndex ) ); //cut off the " ASK "
    1857             : 
    1858           1 :     nIndex = 0;
    1859           1 :     sShortCommand = sShortCommand.getToken( 0, '\\', nIndex);
    1860           1 :     nIndex = 0;
    1861           1 :     OUString sRet = sShortCommand.getToken( 0, ' ', nIndex);
    1862           1 :     if( nIndex > 0)
    1863           1 :         rHint = sShortCommand.copy( nIndex );
    1864           1 :     if( rHint.isEmpty() )
    1865           0 :         rHint = sRet;
    1866           1 :     return sRet;
    1867             : }
    1868             : 
    1869             : 
    1870           0 : bool lcl_FindInCommand(
    1871             :     const OUString& rCommand,
    1872             :     sal_Unicode cSwitch,
    1873             :     OUString& rValue )
    1874             : {
    1875           0 :     bool bRet = false;
    1876           0 :     OUString sSearch('\\');
    1877           0 :     sSearch += OUString( cSwitch );
    1878           0 :     sal_Int32 nIndex = rCommand.indexOf( sSearch  );
    1879           0 :     if( nIndex >= 0 )
    1880             :     {
    1881           0 :         bRet = true;
    1882             :         //find next '\' or end of string
    1883           0 :         sal_Int32 nEndIndex = rCommand.indexOf( '\\', nIndex + 1);
    1884           0 :         if( nEndIndex < 0 )
    1885           0 :             nEndIndex = rCommand.getLength() - 1;
    1886           0 :         if( nEndIndex - nIndex > 3 )
    1887           0 :             rValue = rCommand.copy( nIndex + 3, nEndIndex - nIndex - 3);
    1888             :     }
    1889           0 :     return bRet;
    1890             : }
    1891             : 
    1892             : 
    1893             : 
    1894           1 : void DomainMapper_Impl::GetCurrentLocale(lang::Locale& rLocale)
    1895             : {
    1896           1 :     PropertyMapPtr pTopContext = GetTopContext();
    1897           1 :     PropertyDefinition aCharLocale( PROP_CHAR_LOCALE, true );
    1898           1 :     PropertyMap::iterator aLocaleIter = pTopContext->find( aCharLocale );
    1899           1 :     if( aLocaleIter != pTopContext->end())
    1900           0 :         aLocaleIter->second >>= rLocale;
    1901             :     else
    1902             :     {
    1903           1 :         PropertyMapPtr pParaContext = GetTopContextOfType(CONTEXT_PARAGRAPH);
    1904           1 :         aLocaleIter = pParaContext->find(aCharLocale);
    1905           1 :         if( aLocaleIter != pParaContext->end())
    1906             :         {
    1907           1 :             aLocaleIter->second >>= rLocale;
    1908           1 :         }
    1909           1 :     }
    1910           1 : }
    1911             : 
    1912             : /*-------------------------------------------------------------------------
    1913             :     extract the number format from the command and apply the resulting number
    1914             :     format to the XPropertySet
    1915             :   -----------------------------------------------------------------------*/
    1916           1 : void DomainMapper_Impl::SetNumberFormat( const OUString& rCommand,
    1917             :                             uno::Reference< beans::XPropertySet >& xPropertySet )
    1918             : {
    1919           1 :     OUString sFormatString = lcl_ParseFormat( rCommand );
    1920             :     // find \h - hijri/luna calendar todo: what about saka/era calendar?
    1921           1 :     bool bHijri = 0 < rCommand.indexOf("\\h ");
    1922           1 :     lang::Locale aUSLocale;
    1923           1 :     aUSLocale.Language = "en";
    1924           1 :     aUSLocale.Country = "US";
    1925             : 
    1926             :     //determine current locale - todo: is it necessary to initialize this locale?
    1927           1 :     lang::Locale aCurrentLocale = aUSLocale;
    1928           1 :     GetCurrentLocale( aCurrentLocale );
    1929           1 :     OUString sFormat = ConversionHelper::ConvertMSFormatStringToSO( sFormatString, aCurrentLocale, bHijri);
    1930             :     //get the number formatter and convert the string to a format value
    1931             :     try
    1932             :     {
    1933           1 :         uno::Reference< util::XNumberFormatsSupplier > xNumberSupplier( m_xTextDocument, uno::UNO_QUERY_THROW );
    1934           1 :         sal_Int32 nKey = xNumberSupplier->getNumberFormats()->addNewConverted( sFormat, aUSLocale, aCurrentLocale );
    1935           1 :         xPropertySet->setPropertyValue(
    1936           1 :             PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_NUMBER_FORMAT),
    1937           2 :             uno::makeAny( nKey ));
    1938           1 :         xPropertySet->getPropertyValue(
    1939           1 :             PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_NUMBER_FORMAT ) ) >>= nKey;
    1940             :     }
    1941           0 :     catch(const uno::Exception&)
    1942             :     {
    1943           1 :     }
    1944           1 : }
    1945             : 
    1946             : 
    1947             : 
    1948           1 : uno::Reference< beans::XPropertySet > DomainMapper_Impl::FindOrCreateFieldMaster(
    1949             :         const sal_Char* pFieldMasterService, const OUString& rFieldMasterName )
    1950             :             throw(::com::sun::star::uno::Exception)
    1951             : {
    1952             :     // query master, create if not available
    1953           1 :     uno::Reference< text::XTextFieldsSupplier > xFieldsSupplier( GetTextDocument(), uno::UNO_QUERY_THROW );
    1954           1 :     uno::Reference< container::XNameAccess > xFieldMasterAccess = xFieldsSupplier->getTextFieldMasters();
    1955           1 :     uno::Reference< beans::XPropertySet > xMaster;
    1956           1 :     OUString sFieldMasterService( OUString::createFromAscii(pFieldMasterService) );
    1957           1 :     OUStringBuffer aFieldMasterName;
    1958           1 :     aFieldMasterName.appendAscii( pFieldMasterService );
    1959           1 :     aFieldMasterName.append(sal_Unicode('.'));
    1960           1 :     aFieldMasterName.append(rFieldMasterName);
    1961           1 :     OUString sFieldMasterName = aFieldMasterName.makeStringAndClear();
    1962           1 :     if(xFieldMasterAccess->hasByName(sFieldMasterName))
    1963             :     {
    1964             :         //get the master
    1965           0 :         xMaster = uno::Reference< beans::XPropertySet >(xFieldMasterAccess->getByName(sFieldMasterName),
    1966           0 :                                                                             uno::UNO_QUERY_THROW);
    1967             :     }
    1968             :     else
    1969             :     {
    1970             :         //create the master
    1971             :         xMaster = uno::Reference< beans::XPropertySet >(
    1972           1 :                 m_xTextFactory->createInstance(sFieldMasterService), uno::UNO_QUERY_THROW);
    1973             :         //set the master's name
    1974           1 :             xMaster->setPropertyValue(
    1975           1 :                     PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_NAME),
    1976           2 :                     uno::makeAny(rFieldMasterName));
    1977             :     }
    1978           1 :     return xMaster;
    1979             : }
    1980             : 
    1981             : /*-------------------------------------------------------------------------
    1982             : //field context starts with a 0x13
    1983             :   -----------------------------------------------------------------------*/
    1984          17 : void DomainMapper_Impl::PushFieldContext()
    1985             : {
    1986             : #ifdef DEBUG_DOMAINMAPPER
    1987             :     dmapper_logger->element("pushFieldContext");
    1988             : #endif
    1989             : 
    1990          17 :     uno::Reference< text::XTextAppend >  xTextAppend;
    1991          17 :     if (!m_aTextAppendStack.empty())
    1992          17 :         xTextAppend = m_aTextAppendStack.top().xTextAppend;
    1993          17 :     uno::Reference< text::XTextRange > xStart;
    1994          17 :     if (xTextAppend.is())
    1995             :     {
    1996             :         //insert a dummy char to make sure the start range doesn't move together with the to-be-appended text
    1997          17 :         xTextAppend->appendTextPortion(OUString( '-' ), uno::Sequence< beans::PropertyValue >() );
    1998          17 :         uno::Reference< text::XTextCursor > xCrsr = xTextAppend->createTextCursorByRange( xTextAppend->getEnd() );
    1999          17 :         xCrsr->goLeft( 1, false );
    2000          17 :         xStart = xCrsr->getStart();
    2001             :     }
    2002          17 :     m_aFieldStack.push( FieldContextPtr( new FieldContext( xStart ) ) );
    2003          17 : }
    2004             : /*-------------------------------------------------------------------------
    2005             : //the current field context waits for the completion of the command
    2006             :   -----------------------------------------------------------------------*/
    2007        4412 : bool DomainMapper_Impl::IsOpenFieldCommand() const
    2008             : {
    2009        4412 :     return !m_aFieldStack.empty() && !m_aFieldStack.top()->IsCommandCompleted();
    2010             : }
    2011             : /*-------------------------------------------------------------------------
    2012             : //the current field context waits for the completion of the command
    2013             :   -----------------------------------------------------------------------*/
    2014        4364 : bool DomainMapper_Impl::IsOpenField() const
    2015             : {
    2016        4364 :     return !m_aFieldStack.empty();
    2017             : }
    2018             : 
    2019             : 
    2020          17 : FieldContext::FieldContext(uno::Reference< text::XTextRange > xStart) :
    2021             :     m_bFieldCommandCompleted( false )
    2022          17 :     ,m_xStartRange( xStart )
    2023             : {
    2024          17 : }
    2025             : 
    2026             : 
    2027          17 : FieldContext::~FieldContext()
    2028             : {
    2029          17 : }
    2030             : 
    2031             : 
    2032          48 : void FieldContext::AppendCommand(const OUString& rPart)
    2033             : {
    2034          48 :     m_sCommand += rPart;
    2035          48 : }
    2036             : 
    2037           5 : ::std::vector<OUString> FieldContext::GetCommandParts() const
    2038             : {
    2039           5 :     ::std::vector<OUString> aResult;
    2040           5 :     sal_Int32 nIndex = 0;
    2041           5 :     bool bInString = false;
    2042           5 :     OUString sPart;
    2043          32 :     while (nIndex != -1)
    2044             :     {
    2045          22 :         OUString sToken = GetCommand().getToken(0, ' ', nIndex);
    2046          22 :         bool bInStringNext = bInString;
    2047             : 
    2048          22 :         if (sToken.isEmpty())
    2049           6 :             continue;
    2050             : 
    2051          16 :         if (sToken.getStr()[0] == '"')
    2052             :         {
    2053           8 :             bInStringNext = true;
    2054           8 :             sToken = sToken.copy(1);
    2055             :         }
    2056          16 :         if (sToken.getStr()[sToken.getLength() - 1] == '"')
    2057             :         {
    2058           8 :             bInStringNext = false;
    2059           8 :             sToken = sToken.copy(0, sToken.getLength() - 1);
    2060             :         }
    2061             : 
    2062          16 :         if (bInString)
    2063             :         {
    2064           0 :             if (bInStringNext)
    2065             :             {
    2066           0 :                 sPart += OUString(' ');
    2067           0 :                 sPart += sToken;
    2068             :             }
    2069             :             else
    2070             :             {
    2071           0 :                 sPart += sToken;
    2072           0 :                 aResult.push_back(sPart);
    2073             :             }
    2074             :         }
    2075             :         else
    2076             :         {
    2077          16 :             if (bInStringNext)
    2078             :             {
    2079           0 :                 sPart = sToken;
    2080             :             }
    2081             :             else
    2082             :             {
    2083          16 :                 aResult.push_back(sToken);
    2084             :             }
    2085             :         }
    2086             : 
    2087          16 :         bInString = bInStringNext;
    2088          22 :     }
    2089             : 
    2090           5 :     return aResult;
    2091             : }
    2092             : 
    2093             : /*-------------------------------------------------------------------------
    2094             : //collect the pieces of the command
    2095             :   -----------------------------------------------------------------------*/
    2096          48 : void DomainMapper_Impl::AppendFieldCommand(OUString& rPartOfCommand)
    2097             : {
    2098             : #ifdef DEBUG_DOMAINMAPPER
    2099             :     dmapper_logger->startElement("appendFieldCommand");
    2100             :     dmapper_logger->chars(rPartOfCommand);
    2101             :     dmapper_logger->endElement();
    2102             : #endif
    2103             : 
    2104          48 :     FieldContextPtr pContext = m_aFieldStack.top();
    2105             :     OSL_ENSURE( pContext.get(), "no field context available");
    2106          48 :     if( pContext.get() )
    2107             :     {
    2108          48 :         pContext->AppendCommand( rPartOfCommand );
    2109          48 :     }
    2110          48 : }
    2111             : 
    2112             : 
    2113             : typedef std::multimap < sal_Int32, OUString > TOCStyleMap;
    2114             : 
    2115          17 : const FieldConversionMap_t & lcl_GetFieldConversion()
    2116             : {
    2117          17 : static FieldConversionMap_t aFieldConversionMap;
    2118          17 : static FieldConversionMap_t aEnhancedFieldConversionMap;
    2119             : 
    2120             : static bool bFilled = false;
    2121             : 
    2122          17 : if(!bFilled)
    2123             : {
    2124             :     static const FieldConversion aFields[] =
    2125             :     {
    2126             : //            {OUString("ADDRESSBLOCK"),  "",                         "", FIELD_ADDRESSBLOCK  },
    2127             : //            {OUString("ADVANCE"),       "",                         "", FIELD_ADVANCE       },
    2128             :         {OUString("ASK"),           "SetExpression",             "SetExpression", FIELD_ASK      },
    2129             :             {OUString("AUTONUM"),       "SetExpression",            "SetExpression", FIELD_AUTONUM   },
    2130             :             {OUString("AUTONUMLGL"),     "SetExpression",            "SetExpression", FIELD_AUTONUMLGL },
    2131             :             {OUString("AUTONUMOUT"),     "SetExpression",            "SetExpression", FIELD_AUTONUMOUT },
    2132             :             {OUString("AUTHOR"),        "DocInfo.CreateAuthor",                   "", FIELD_AUTHOR       },
    2133             :             {OUString("DATE"),          "DateTime",                 "", FIELD_DATE         },
    2134             :             {OUString("COMMENTS"),      "DocInfo.Description",      "", FIELD_COMMENTS     },
    2135             :             {OUString("CREATEDATE"),    "DocInfo.CreateDateTime",   "", FIELD_CREATEDATE   },
    2136             :             {OUString("DOCPROPERTY"),   "",                         "", FIELD_DOCPROPERTY },
    2137             :             {OUString("DOCVARIABLE"),   "User",                     "", FIELD_DOCVARIABLE  },
    2138             :             {OUString("EDITTIME"),      "DocInfo.EditTime",         "", FIELD_EDITTIME     },
    2139             :             {OUString("EQ"),            "",                         "", FIELD_EQ     },
    2140             :             {OUString("FILLIN"),        "Input",                    "", FIELD_FILLIN       },
    2141             :             {OUString("FILENAME"),      "FileName",                 "", FIELD_FILENAME     },
    2142             : //            {OUString("FILESIZE"),      "",                         "", FIELD_FILESIZE     },
    2143             : //            {OUString("FORMULA"),     "",                           "", FIELD_FORMULA },
    2144             :             {OUString("FORMCHECKBOX"),     "",                           "", FIELD_FORMCHECKBOX},
    2145             :             {OUString("FORMDROPDOWN"),     "DropDown",                           "", FIELD_FORMDROPDOWN},
    2146             :             {OUString("FORMTEXT"),     "Input", "", FIELD_FORMTEXT},
    2147             : //            {OUString("GOTOBUTTON"),    "",                         "", FIELD_GOTOBUTTON   },
    2148             :             {OUString("HYPERLINK"),     "",                         "", FIELD_HYPERLINK    },
    2149             :             {OUString("IF"),            "ConditionalText",          "", FIELD_IF           },
    2150             : //            {OUString("INFO"),      "","", FIELD_INFO         },
    2151             : //            {OUString("INCLUDEPICTURE"), "",                        "", FIELD_INCLUDEPICTURE},
    2152             :             {OUString("KEYWORDS"),      "DocInfo.KeyWords",         "", FIELD_KEYWORDS     },
    2153             :             {OUString("LASTSAVEDBY"),   "DocInfo.ChangeAuthor",                         "", FIELD_LASTSAVEDBY  },
    2154             :             {OUString("MACROBUTTON"),   "Macro",                         "", FIELD_MACROBUTTON  },
    2155             :             {OUString("MERGEFIELD"),    "Database",                 "Database", FIELD_MERGEFIELD},
    2156             :             {OUString("MERGEREC"),      "DatabaseNumberOfSet",      "", FIELD_MERGEREC     },
    2157             : //            {OUString("MERGESEQ"),      "",                         "", FIELD_MERGESEQ     },
    2158             :             {OUString("NEXT"),          "DatabaseNextSet",          "", FIELD_NEXT         },
    2159             :             {OUString("NEXTIF"),        "DatabaseNextSet",          "", FIELD_NEXTIF       },
    2160             :             {OUString("PAGE"),          "PageNumber",               "", FIELD_PAGE         },
    2161             :             {OUString("PAGEREF"),       "GetReference",             "", FIELD_PAGEREF      },
    2162             :             {OUString("REF"),           "GetReference",             "", FIELD_REF          },
    2163             :             {OUString("REVNUM"),        "DocInfo.Revision",         "", FIELD_REVNUM       },
    2164             :             {OUString("SAVEDATE"),      "DocInfo.Change",           "", FIELD_SAVEDATE     },
    2165             : //            {OUString("SECTION"),       "",                         "", FIELD_SECTION      },
    2166             : //            {OUString("SECTIONPAGES"),  "",                         "", FIELD_SECTIONPAGES },
    2167             :             {OUString("SEQ"),           "SetExpression",            "SetExpression", FIELD_SEQ          },
    2168             : //            {OUString("SET"),           "","", FIELD_SET          },
    2169             : //            {OUString("SKIPIF"),"",                                 "", FIELD_SKIPIF       },
    2170             : //            {OUString("STYLEREF"),"",                               "", FIELD_STYLEREF     },
    2171             :             {OUString("SUBJECT"),       "DocInfo.Subject",          "", FIELD_SUBJECT      },
    2172             : //            {OUString("SYMBOL"),"",                                 "", FIELD_SYMBOL       },
    2173             :             {OUString("TEMPLATE"),      "TemplateName",             "", FIELD_TEMPLATE},
    2174             :             {OUString("TIME"),          "DateTime",                 "", FIELD_TIME         },
    2175             :             {OUString("TITLE"),         "DocInfo.Title",            "", FIELD_TITLE        },
    2176             :             {OUString("USERINITIALS"),  "Author",                   "", FIELD_USERINITIALS       },
    2177             : //            {OUString("USERADDRESS"),   "",                         "", FIELD_USERADDRESS  },
    2178             :             {OUString("USERNAME"), "Author",                   "", FIELD_USERNAME       },
    2179             : 
    2180             : 
    2181             :             {OUString("TOC"), "com.sun.star.text.ContentIndex", "", FIELD_TOC},
    2182             :             {OUString("TC"), "com.sun.star.text.ContentIndexMark", "", FIELD_TC},
    2183             :             {OUString("NUMCHARS"), "CharacterCount", "", FIELD_NUMCHARS},
    2184             :             {OUString("NUMWORDS"), "WordCount", "", FIELD_NUMWORDS},
    2185             :             {OUString("NUMPAGES"), "PageCount", "", FIELD_NUMPAGES},
    2186             : 
    2187             : //            {OUString(""), "", "", FIELD_},
    2188             : 
    2189           8 :         };
    2190           4 :         size_t nConversions = SAL_N_ELEMENTS(aFields);
    2191         176 :         for( size_t nConversion = 0; nConversion < nConversions; ++nConversion)
    2192             :         {
    2193             :             aFieldConversionMap.insert( FieldConversionMap_t::value_type(
    2194             :                 aFields[nConversion].sWordCommand,
    2195         172 :                 aFields[nConversion] ));
    2196             :         }
    2197             : 
    2198           4 :         bFilled = true;
    2199             :     }
    2200             : 
    2201          17 :     return aFieldConversionMap;
    2202             : }
    2203             : 
    2204           1 : const FieldConversionMap_t & lcl_GetEnhancedFieldConversion()
    2205             : {
    2206           1 :     static FieldConversionMap_t aEnhancedFieldConversionMap;
    2207             : 
    2208             :     static bool bFilled = false;
    2209             : 
    2210           1 :     if(!bFilled)
    2211             :     {
    2212             :         static const FieldConversion aEnhancedFields[] =
    2213             :         {
    2214             :             {OUString("FORMCHECKBOX"),     "FormFieldmark",                           "", FIELD_FORMCHECKBOX},
    2215             :             {OUString("FORMDROPDOWN"),     "FormFieldmark",                           "", FIELD_FORMDROPDOWN},
    2216             :             {OUString("FORMTEXT"),     "Fieldmark", "", FIELD_FORMTEXT},
    2217           2 :         };
    2218             : 
    2219           1 :         size_t nConversions = SAL_N_ELEMENTS(aEnhancedFields);
    2220           4 :         for( size_t nConversion = 0; nConversion < nConversions; ++nConversion)
    2221             :         {
    2222             :             aEnhancedFieldConversionMap.insert( FieldConversionMap_t::value_type(
    2223             :                 aEnhancedFields[nConversion].sWordCommand,
    2224           3 :                 aEnhancedFields[nConversion] ));
    2225             :         }
    2226             :     }
    2227           1 :     return aEnhancedFieldConversionMap;
    2228             : }
    2229             : 
    2230           1 : void DomainMapper_Impl::handleFieldAsk
    2231             :     (FieldContextPtr pContext,
    2232             :      PropertyNameSupplier& rPropNameSupplier,
    2233             :      uno::Reference< uno::XInterface > & xFieldInterface,
    2234             :      uno::Reference< beans::XPropertySet > xFieldProperties)
    2235             : {
    2236             :     //doesn the command contain a variable name?
    2237           1 :     OUString sVariable, sHint;
    2238             : 
    2239           1 :     sVariable = lcl_ExctractAskVariableAndHint( pContext->GetCommand(),
    2240           1 :         sHint );
    2241           1 :     if(!sVariable.isEmpty())
    2242             :     {
    2243             :         // determine field master name
    2244             :         uno::Reference< beans::XPropertySet > xMaster =
    2245             :             FindOrCreateFieldMaster
    2246           1 :             ("com.sun.star.text.FieldMaster.SetExpression", sVariable );
    2247             :         // An ASK field is always a string of characters
    2248           1 :         xMaster->setPropertyValue(rPropNameSupplier.GetName(PROP_SUB_TYPE), uno::makeAny(text::SetVariableType::STRING));
    2249             : 
    2250             :         // attach the master to the field
    2251             :         uno::Reference< text::XDependentTextField > xDependentField
    2252           1 :             ( xFieldInterface, uno::UNO_QUERY_THROW );
    2253           1 :         xDependentField->attachTextFieldMaster( xMaster );
    2254             : 
    2255             :         // set input flag at the field
    2256           1 :         xFieldProperties->setPropertyValue(
    2257           1 :             rPropNameSupplier.GetName(PROP_IS_INPUT), uno::makeAny( true ));
    2258             :         // set the prompt
    2259           1 :         xFieldProperties->setPropertyValue(
    2260           1 :             rPropNameSupplier.GetName(PROP_HINT),
    2261           2 :             uno::makeAny( sHint ));
    2262           1 :         xFieldProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_SUB_TYPE), uno::makeAny(text::SetVariableType::STRING));
    2263             :         // The ASK has no field value to display
    2264           1 :         xFieldProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_IS_VISIBLE), uno::makeAny(sal_False));
    2265             :     }
    2266             :     else
    2267             :     {
    2268             :         //don't insert the field
    2269             :         //todo: maybe import a 'normal' input field here?
    2270           0 :         xFieldInterface = 0;
    2271           1 :     }
    2272           1 : }
    2273             : 
    2274           0 : void DomainMapper_Impl::handleAutoNum
    2275             :     (FieldContextPtr pContext,
    2276             :     PropertyNameSupplier& rPropNameSupplier,
    2277             :     uno::Reference< uno::XInterface > & xFieldInterface,
    2278             :     uno::Reference< beans::XPropertySet > xFieldProperties)
    2279             : {
    2280             :     //create a sequence field master "AutoNr"
    2281             :     uno::Reference< beans::XPropertySet > xMaster =
    2282             :     FindOrCreateFieldMaster
    2283             :         ("com.sun.star.text.FieldMaster.SetExpression",
    2284           0 :         "AutoNr");
    2285             : 
    2286           0 :     xMaster->setPropertyValue( rPropNameSupplier.GetName(PROP_SUB_TYPE),
    2287           0 :         uno::makeAny(text::SetVariableType::SEQUENCE));
    2288             : 
    2289             :     //apply the numbering type
    2290           0 :     xFieldProperties->setPropertyValue(
    2291           0 :         rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
    2292           0 :         uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) ));
    2293             :         // attach the master to the field
    2294             :     uno::Reference< text::XDependentTextField > xDependentField
    2295           0 :         ( xFieldInterface, uno::UNO_QUERY_THROW );
    2296           0 :     xDependentField->attachTextFieldMaster( xMaster );
    2297           0 : }
    2298             : 
    2299           0 : void DomainMapper_Impl::handleAuthor
    2300             :     (FieldContextPtr pContext,
    2301             :     PropertyNameSupplier& rPropNameSupplier,
    2302             :      uno::Reference< uno::XInterface > & /*xFieldInterface*/,
    2303             :      uno::Reference< beans::XPropertySet > xFieldProperties,
    2304             :      FieldId  eFieldId )
    2305             : {
    2306           0 :     if ( eFieldId != FIELD_USERINITIALS )
    2307           0 :         xFieldProperties->setPropertyValue
    2308           0 :             ( rPropNameSupplier.GetName(PROP_FULL_NAME), uno::makeAny( true ));
    2309             : 
    2310           0 :     sal_Int32 nLen = sizeof( " AUTHOR" );
    2311           0 :     if ( eFieldId != FIELD_AUTHOR )
    2312             :     {
    2313           0 :         if (  eFieldId == FIELD_USERINITIALS )
    2314           0 :             nLen = sizeof( " USERINITIALS" );
    2315           0 :         else if (  eFieldId == FIELD_USERNAME )
    2316           0 :             nLen = sizeof( " USERNAME" );
    2317             :     }
    2318             : 
    2319             :     OUString sParam =
    2320           0 :         lcl_ExtractParameter(pContext->GetCommand(), nLen );
    2321             : 
    2322           0 :     if(!sParam.isEmpty())
    2323             :     {
    2324           0 :         xFieldProperties->setPropertyValue(
    2325           0 :                 rPropNameSupplier.GetName( PROP_IS_FIXED ),
    2326           0 :                 uno::makeAny( true ));
    2327             :         //PROP_CURRENT_PRESENTATION is set later anyway
    2328           0 :     }
    2329           0 : }
    2330             : 
    2331           0 :     void DomainMapper_Impl::handleDocProperty
    2332             :         (FieldContextPtr pContext,
    2333             :         PropertyNameSupplier& rPropNameSupplier,
    2334             :         uno::Reference< uno::XInterface > & xFieldInterface,
    2335             :         uno::Reference< beans::XPropertySet > xFieldProperties)
    2336             : {
    2337             :     //some docproperties should be imported as document statistic fields, some as DocInfo fields
    2338             :     //others should be user fields
    2339             :     OUString sParam =
    2340           0 :         lcl_ExtractParameter(pContext->GetCommand(), sizeof(" DOCPROPERTY") );
    2341             : 
    2342           0 :     if(!sParam.isEmpty())
    2343             :     {
    2344             :         #define SET_ARABIC      0x01
    2345             :         #define SET_FULL_NAME   0x02
    2346             :         #define SET_DATE        0x04
    2347             :         struct DocPropertyMap
    2348             :         {
    2349             :             const sal_Char* pDocPropertyName;
    2350             :             const sal_Char* pServiceName;
    2351             :             sal_uInt8       nFlags;
    2352             :         };
    2353             :         static const DocPropertyMap aDocProperties[] =
    2354             :         {
    2355             :             {"CreateTime",       "DocInfo.CreateDateTime",  SET_DATE},
    2356             :             {"Characters",       "CharacterCount",          SET_ARABIC},
    2357             :             {"Comments",         "DocInfo.Description",     0},
    2358             :             {"Keywords",         "DocInfo.KeyWords",        0},
    2359             :             {"LastPrinted",      "DocInfo.PrintDateTime",   0},
    2360             :             {"LastSavedBy",      "DocInfo.ChangeAuthor",    0},
    2361             :             {"LastSavedTime",    "DocInfo.ChangeDateTime",  SET_DATE},
    2362             :             {"Paragraphs",       "ParagraphCount",          SET_ARABIC},
    2363             :             {"RevisionNumber",   "DocInfo.Revision",        0},
    2364             :             {"Subject",          "DocInfo.Subject",         0},
    2365             :             {"Template",         "TemplateName",            0},
    2366             :             {"Title",            "DocInfo.Title",           0},
    2367             :             {"TotalEditingTime", "DocInfo.EditTime",        0},
    2368             :             {"Words",            "WordCount",               SET_ARABIC}
    2369             : 
    2370             :             //other available DocProperties:
    2371             :             //Bytes, Category, CharactersWithSpaces, Company
    2372             :             //HyperlinkBase,
    2373             :             //Lines, Manager, NameofApplication, ODMADocId, Pages,
    2374             :             //Security,
    2375             :         };
    2376             :         //search for a field mapping
    2377           0 :         OUString sFieldServiceName;
    2378           0 :         sal_uInt16 nMap = 0;
    2379           0 :         for( ; nMap < sizeof(aDocProperties) / sizeof(DocPropertyMap);
    2380             :             ++nMap )
    2381             :         {
    2382           0 :             if(sParam.equalsAscii(aDocProperties[nMap].pDocPropertyName))
    2383             :             {
    2384             :                 sFieldServiceName =
    2385             :                 OUString::createFromAscii
    2386           0 :                 (aDocProperties[nMap].pServiceName);
    2387           0 :                 break;
    2388             :             }
    2389             :         }
    2390           0 :         OUString sServiceName("com.sun.star.text.TextField.");
    2391           0 :         bool bIsCustomField = false;
    2392           0 :         if(sFieldServiceName.isEmpty())
    2393             :         {
    2394             :             //create a custom property field
    2395           0 :             sServiceName += "DocInfo.Custom";
    2396           0 :             bIsCustomField = true;
    2397             :         }
    2398             :         else
    2399             :         {
    2400           0 :             sServiceName += sFieldServiceName;
    2401             :         }
    2402           0 :         if (m_xTextFactory.is())
    2403           0 :             xFieldInterface = m_xTextFactory->createInstance(sServiceName);
    2404             :         xFieldProperties =
    2405             :             uno::Reference< beans::XPropertySet >( xFieldInterface,
    2406           0 :                 uno::UNO_QUERY_THROW);
    2407           0 :         if( bIsCustomField )
    2408           0 :             xFieldProperties->setPropertyValue(
    2409           0 :                 rPropNameSupplier.GetName(PROP_NAME), uno::makeAny( sParam ));
    2410             :         else
    2411             :         {
    2412           0 :             if(0 != (aDocProperties[nMap].nFlags & SET_ARABIC))
    2413           0 :                 xFieldProperties->setPropertyValue(
    2414           0 :                     rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
    2415           0 :                     uno::makeAny( style::NumberingType::ARABIC ));
    2416           0 :             else if(0 != (aDocProperties[nMap].nFlags & SET_FULL_NAME))
    2417           0 :                 xFieldProperties->setPropertyValue(
    2418           0 :                     rPropNameSupplier.GetName(PROP_FULL_NAME),
    2419           0 :                         uno::makeAny( true ));
    2420           0 :             else if(0 != (aDocProperties[nMap].nFlags & SET_DATE))
    2421             :             {
    2422           0 :                 xFieldProperties->setPropertyValue(
    2423           0 :                     rPropNameSupplier.GetName(PROP_IS_DATE),
    2424           0 :                         uno::makeAny( true ));
    2425           0 :                 SetNumberFormat( pContext->GetCommand(), xFieldProperties );
    2426             :             }
    2427           0 :         }
    2428           0 :     }
    2429             : 
    2430             : #undef SET_ARABIC
    2431             : #undef SET_FULL_NAME
    2432             : #undef SET_DATE
    2433           0 : }
    2434             : 
    2435           0 : void DomainMapper_Impl::handleToc
    2436             :     (FieldContextPtr pContext,
    2437             :     PropertyNameSupplier& rPropNameSupplier,
    2438             :      uno::Reference< uno::XInterface > & /*xFieldInterface*/,
    2439             :      uno::Reference< beans::XPropertySet > /*xFieldProperties*/,
    2440             :     const OUString & sTOCServiceName)
    2441             : {
    2442           0 :     OUString sValue;
    2443           0 :     bool bTableOfFigures = false;
    2444           0 :     bool bHyperlinks = false;
    2445           0 :     bool bFromOutline = false;
    2446           0 :     bool bFromEntries = false;
    2447           0 :     sal_Int16 nMaxLevel = 10;
    2448           0 :     OUString sTemplate;
    2449           0 :     OUString sChapterNoSeparator;
    2450             : //                  \a Builds a table of figures but does not include the captions's label and number
    2451           0 :     if( lcl_FindInCommand( pContext->GetCommand(), 'a', sValue ))
    2452             :     { //make it a table of figures
    2453           0 :         bTableOfFigures = true;
    2454             :     }
    2455             : //                  \b Uses a bookmark to specify area of document from which to build table of contents
    2456             : //                    if( lcl_FindInCommand( pContext->GetCommand(), 'b', sValue ))
    2457             : //                    { //todo: sValue contains the bookmark name - unsupported feature
    2458             : //                    }
    2459           0 :     if( lcl_FindInCommand( pContext->GetCommand(), 'c', sValue ))
    2460             : //                  \c Builds a table of figures of the given label
    2461             :     {
    2462             :                         //todo: sValue contains the label's name
    2463           0 :         bTableOfFigures = true;
    2464             :     }
    2465             : //                  \d Defines the separator between sequence and page numbers
    2466           0 :     if( lcl_FindInCommand( pContext->GetCommand(), 'd', sValue ))
    2467             :     {
    2468             :                         //todo: insert the chapter number into each level and insert the separator additionally
    2469           0 :         sChapterNoSeparator = sValue;
    2470             :     }
    2471             : //                  \f Builds a table of contents using TC entries instead of outline levels
    2472           0 :     if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue ))
    2473             :     {
    2474             :                         //todo: sValue can contain a TOC entry identifier - use unclear
    2475           0 :         bFromEntries = true;
    2476             :     }
    2477             : //                  \h Hyperlinks the entries and page numbers within the table of contents
    2478           0 :     if( lcl_FindInCommand( pContext->GetCommand(), 'h', sValue ))
    2479             :     {
    2480             :                         //todo: make all entries to hyperlinks
    2481           0 :         bHyperlinks = true;
    2482             :     }
    2483             : //                  \l Defines the TC entries field level used to build a table of contents
    2484             : //                    if( lcl_FindInCommand( pContext->GetCommand(), 'l', sValue ))
    2485             : //                    {
    2486             :                             //todo: entries can only be included completely
    2487             : //                    }
    2488             : //                  \n Builds a table of contents or a range of entries, sucah as �1-9�, in a table of contents without page numbers
    2489             : //                    if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue ))
    2490             : //                    {
    2491             :                         //todo: what does the description mean?
    2492             : //                    }
    2493             : //                  \o  Builds a table of contents by using outline levels instead of TC entries
    2494           0 :     if( lcl_FindInCommand( pContext->GetCommand(), 'o', sValue ))
    2495             :     {
    2496           0 :         bFromOutline = true;
    2497           0 :         sal_Int32 nIndex = 0;
    2498           0 :         sValue.getToken( 0, '-', nIndex );
    2499           0 :         nMaxLevel = static_cast<sal_Int16>(nIndex != -1 ? sValue.copy(nIndex).toInt32() : 0);
    2500             :     }
    2501             : //                  \p Defines the separator between the table entry and its page number
    2502           0 :     if( lcl_FindInCommand( pContext->GetCommand(), 'p', sValue ))
    2503             :         {  }
    2504             : //                  \s  Builds a table of contents by using a sequence type
    2505           0 :     if( lcl_FindInCommand( pContext->GetCommand(), 's', sValue ))
    2506             :         {  }
    2507             : //                  \t  Builds a table of contents by using style names other than the standard outline styles
    2508           0 :     if( lcl_FindInCommand( pContext->GetCommand(), 't', sValue ))
    2509             :     {
    2510           0 :         sal_Int32 nPos = 0;
    2511           0 :         OUString sToken = sValue.getToken( 1, '"', nPos);
    2512           0 :         sTemplate = sToken.isEmpty() ? sValue : sToken;
    2513             :     }
    2514             : //                  \u  Builds a table of contents by using the applied paragraph outline level
    2515           0 :     if( lcl_FindInCommand( pContext->GetCommand(), 'u', sValue ))
    2516             :     {
    2517           0 :         bFromOutline = true;
    2518             :                         //todo: what doesn 'the applied paragraph outline level' refer to?
    2519             :     }
    2520             : //                  \w Preserve tab characters within table entries
    2521             : //                    if( lcl_FindInCommand( pContext->GetCommand(), 'w', sValue ))
    2522             : //                    {
    2523             :                         //todo: not supported
    2524             : //                    }
    2525             : //                  \x Preserve newline characters within table entries
    2526             : //                    if( lcl_FindInCommand( pContext->GetCommand(), 'x', sValue ))
    2527             : //                    {
    2528             :                         //todo: unsupported
    2529             : //                    }
    2530             : //                  \z Hides page numbers within the table of contens when shown in Web Layout View
    2531             : //                    if( lcl_FindInCommand( pContext->GetCommand(), 'z', sValue ))
    2532             : //                    { //todo: unsupported feature  }
    2533             : 
    2534             :                     //if there's no option then it should be created from outline
    2535           0 :     if( !bFromOutline && !bFromEntries && sTemplate.isEmpty()  )
    2536           0 :         bFromOutline = true;
    2537             : 
    2538           0 :     uno::Reference< beans::XPropertySet > xTOC;
    2539           0 :     if (m_xTextFactory.is())
    2540             :         xTOC.set(
    2541           0 :                 m_xTextFactory->createInstance
    2542             :                 ( bTableOfFigures ?
    2543             :                   "com.sun.star.text.IllustrationsIndex"
    2544           0 :                   : sTOCServiceName),
    2545           0 :                 uno::UNO_QUERY_THROW);
    2546           0 :     if (xTOC.is())
    2547           0 :         xTOC->setPropertyValue(rPropNameSupplier.GetName( PROP_TITLE ), uno::makeAny(OUString()));
    2548           0 :     if( !bTableOfFigures && xTOC.is() )
    2549             :     {
    2550           0 :         xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_LEVEL ), uno::makeAny( nMaxLevel ) );
    2551           0 :         xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_CREATE_FROM_OUTLINE ), uno::makeAny( bFromOutline ));
    2552           0 :         xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_CREATE_FROM_MARKS ), uno::makeAny( bFromEntries ));
    2553           0 :         if( !sTemplate.isEmpty() )
    2554             :         {
    2555             :                             //the string contains comma separated the names and related levels
    2556             :                             //like: "Heading 1,1,Heading 2,2"
    2557           0 :             TOCStyleMap aMap;
    2558             :             sal_Int32 nLevel;
    2559           0 :             sal_Int32 nPosition = 0;
    2560           0 :             while( nPosition >= 0)
    2561             :             {
    2562           0 :                 OUString sStyleName = sTemplate.getToken( 0, ',', nPosition );
    2563             :                                 //empty tokens should be skipped
    2564           0 :                 while( sStyleName.isEmpty() && nPosition > 0 )
    2565           0 :                     sStyleName = sTemplate.getToken( 0, ',', nPosition );
    2566           0 :                 nLevel = sTemplate.getToken( 0, ',', nPosition ).toInt32();
    2567           0 :                 if( !nLevel )
    2568           0 :                     nLevel = 1;
    2569           0 :                 if( !sStyleName.isEmpty() )
    2570           0 :                     aMap.insert( TOCStyleMap::value_type(nLevel, sStyleName) );
    2571           0 :             }
    2572           0 :             uno::Reference< container::XIndexReplace> xParaStyles;
    2573           0 :             xTOC->getPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL_PARAGRAPH_STYLES)) >>= xParaStyles;
    2574           0 :             for( nLevel = 1; nLevel < 10; ++nLevel)
    2575             :             {
    2576           0 :                 sal_Int32 nLevelCount = aMap.count( nLevel );
    2577           0 :                 if( nLevelCount  )
    2578             :                 {
    2579           0 :                     TOCStyleMap::iterator aTOCStyleIter = aMap.find( nLevel );
    2580             : 
    2581           0 :                     uno::Sequence< OUString> aStyles( nLevelCount );
    2582           0 :                     for ( sal_Int32 nStyle = 0; nStyle < nLevelCount; ++nStyle, ++aTOCStyleIter )
    2583             :                     {
    2584           0 :                         aStyles[nStyle] = aTOCStyleIter->second;
    2585             :                     }
    2586           0 :                     xParaStyles->replaceByIndex(nLevel - 1, uno::makeAny(aStyles));
    2587             :                 }
    2588             :             }
    2589           0 :             xTOC->setPropertyValue(rPropNameSupplier.GetName(PROP_CREATE_FROM_LEVEL_PARAGRAPH_STYLES), uno::makeAny( true ));
    2590             : 
    2591             :         }
    2592           0 :         if(bHyperlinks  || !sChapterNoSeparator.isEmpty())
    2593             :         {
    2594           0 :             uno::Reference< container::XIndexReplace> xLevelFormats;
    2595           0 :             xTOC->getPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL_FORMAT)) >>= xLevelFormats;
    2596           0 :             sal_Int32 nLevelCount = xLevelFormats->getCount();
    2597             :                             //start with level 1, 0 is the header level
    2598           0 :             for( sal_Int32 nLevel = 1; nLevel < nLevelCount; ++nLevel)
    2599             :             {
    2600           0 :                 uno::Sequence< beans::PropertyValues > aLevel;
    2601           0 :                 xLevelFormats->getByIndex( nLevel ) >>= aLevel;
    2602             :                                 //create a copy of the level and add two new entries - hyperlink start and end
    2603           0 :                 bool bChapterNoSeparator  = !sChapterNoSeparator.isEmpty();
    2604           0 :                 sal_Int32 nAdd = (bHyperlinks && bChapterNoSeparator) ? 4 : 2;
    2605           0 :                 uno::Sequence< beans::PropertyValues > aNewLevel( aLevel.getLength() + nAdd);
    2606           0 :                 beans::PropertyValues* pNewLevel = aNewLevel.getArray();
    2607           0 :                 if( bHyperlinks )
    2608             :                 {
    2609           0 :                     beans::PropertyValues aHyperlink(1);
    2610           0 :                     aHyperlink[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
    2611           0 :                     aHyperlink[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_HYPERLINK_START );
    2612           0 :                     pNewLevel[0] = aHyperlink;
    2613           0 :                     aHyperlink[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_HYPERLINK_END );
    2614           0 :                     pNewLevel[aNewLevel.getLength() -1] = aHyperlink;
    2615             :                 }
    2616           0 :                 if( bChapterNoSeparator )
    2617             :                 {
    2618           0 :                     beans::PropertyValues aChapterNo(2);
    2619           0 :                     aChapterNo[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
    2620           0 :                     aChapterNo[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_CHAPTER_INFO );
    2621           0 :                     aChapterNo[1].Name = rPropNameSupplier.GetName( PROP_CHAPTER_FORMAT );
    2622             :                                     //todo: is ChapterFormat::Number correct?
    2623           0 :                     aChapterNo[1].Value <<= (sal_Int16)text::ChapterFormat::NUMBER;
    2624           0 :                     pNewLevel[aNewLevel.getLength() - (bHyperlinks ? 4 : 2) ] = aChapterNo;
    2625             : 
    2626           0 :                     beans::PropertyValues aChapterSeparator(2);
    2627           0 :                     aChapterSeparator[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
    2628           0 :                     aChapterSeparator[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_TEXT );
    2629           0 :                     aChapterSeparator[1].Name = rPropNameSupplier.GetName( PROP_TEXT );
    2630           0 :                     aChapterSeparator[1].Value <<= sChapterNoSeparator;
    2631           0 :                     pNewLevel[aNewLevel.getLength() - (bHyperlinks ? 3 : 1)] = aChapterSeparator;
    2632             :                 }
    2633             :                                 //copy the 'old' entries except the last (page no)
    2634           0 :                 for( sal_Int32 nToken = 0; nToken < aLevel.getLength() - 1; ++nToken)
    2635             :                 {
    2636           0 :                     pNewLevel[nToken + 1] = aLevel[nToken];
    2637             :                 }
    2638             :                                 //copy page no entry (last or last but one depending on bHyperlinks
    2639           0 :                 sal_Int32 nPageNo = aNewLevel.getLength() - (bHyperlinks ? 2 : 3);
    2640           0 :                 pNewLevel[nPageNo] = aLevel[aLevel.getLength() - 1];
    2641             : 
    2642           0 :                 xLevelFormats->replaceByIndex( nLevel, uno::makeAny( aNewLevel ) );
    2643           0 :             }
    2644             :         }
    2645             :     }
    2646           0 :     pContext->SetTOC( xTOC );
    2647           0 : }
    2648             : 
    2649             : 
    2650             : /*-------------------------------------------------------------------------
    2651             : //the field command has to be closed (0x14 appeared)
    2652             :   -----------------------------------------------------------------------*/
    2653          17 : void DomainMapper_Impl::CloseFieldCommand()
    2654             : {
    2655             : #ifdef DEBUG_DOMAINMAPPER
    2656             :     dmapper_logger->element("closeFieldCommand");
    2657             : #endif
    2658             : 
    2659          17 :     FieldContextPtr pContext = m_aFieldStack.top();
    2660             :     OSL_ENSURE( pContext.get(), "no field context available");
    2661          17 :     if( pContext.get() )
    2662             :     {
    2663          17 :         m_bSetUserFieldContent = false;
    2664          17 :         FieldConversionMap_t aFieldConversionMap = lcl_GetFieldConversion();
    2665          17 :         bool bCreateEnhancedField = false;
    2666             : 
    2667             :         try
    2668             :         {
    2669          17 :             uno::Reference< uno::XInterface > xFieldInterface;
    2670             :             //at first determine the field type - erase leading and trailing whitespaces
    2671          17 :             OUString sCommand( pContext->GetCommand().trim() );
    2672          17 :             sal_Int32 nSpaceIndex = sCommand.indexOf( ' ' );
    2673          17 :             if( 0 <= nSpaceIndex )
    2674           9 :                 sCommand = sCommand.copy( 0, nSpaceIndex );
    2675             : 
    2676          17 :             FieldConversionMap_t::iterator aIt = aFieldConversionMap.find(sCommand);
    2677          17 :             if(aIt != aFieldConversionMap.end())
    2678             :             {
    2679          14 :                 uno::Reference< beans::XPropertySet > xFieldProperties;
    2680          14 :                 bool bCreateField = true;
    2681          14 :                 switch (aIt->second.eFieldId)
    2682             :                 {
    2683             :                 case FIELD_HYPERLINK:
    2684             :                 case FIELD_DOCPROPERTY:
    2685             :                 case FIELD_TOC:
    2686             :                 case FIELD_TC:
    2687             :                 case FIELD_EQ:
    2688           6 :                         bCreateField = false;
    2689           6 :                         break;
    2690             :                 case FIELD_FORMCHECKBOX :
    2691             :                 case FIELD_FORMTEXT :
    2692             :                 case FIELD_FORMDROPDOWN :
    2693             :                 {
    2694             :                     // If we use 'enhanced' fields then FIELD_FORMCHECKBOX,
    2695             :                     // FIELD_FORMTEXT & FIELD_FORMDROPDOWN are treated specially
    2696           1 :                     if ( m_bUsingEnhancedFields  )
    2697             :                     {
    2698           1 :                         bCreateField = false;
    2699           1 :                         bCreateEnhancedField = true;
    2700             :                     }
    2701             :                     // for non enhanced fields checkboxes are displayed
    2702             :                     // as an awt control not a field
    2703           0 :                     else if ( aIt->second.eFieldId == FIELD_FORMCHECKBOX )
    2704           0 :                         bCreateField = false;
    2705           1 :                     break;
    2706             :                 }
    2707             :                 default:
    2708           7 :                     break;
    2709             :                 }
    2710             : 
    2711          14 :                 if( bCreateField || bCreateEnhancedField )
    2712             :                 {
    2713             :                     //add the service prefix
    2714           8 :                     OUString sServiceName("com.sun.star.text.");
    2715           8 :                     if ( bCreateEnhancedField )
    2716             :                     {
    2717           1 :                         FieldConversionMap_t aEnhancedFieldConversionMap = lcl_GetEnhancedFieldConversion();
    2718           1 :                         FieldConversionMap_t::iterator aEnhancedIt = aEnhancedFieldConversionMap.find(sCommand);
    2719           1 :                         if ( aEnhancedIt != aEnhancedFieldConversionMap.end())
    2720           1 :                             sServiceName += OUString::createFromAscii(aEnhancedIt->second.cFieldServiceName );
    2721             :                     }
    2722             :                     else
    2723             :                     {
    2724           7 :                         sServiceName += OUString( "TextField.");
    2725           7 :                         sServiceName += OUString::createFromAscii(aIt->second.cFieldServiceName );
    2726             :                     }
    2727             : 
    2728             : #ifdef DEBUG_DOMAINMAPPER
    2729             :                     dmapper_logger->startElement("fieldService");
    2730             :                     dmapper_logger->chars(sServiceName);
    2731             :                     dmapper_logger->endElement();
    2732             : #endif
    2733             : 
    2734           8 :                     if (m_xTextFactory.is())
    2735             :                     {
    2736           8 :                         xFieldInterface = m_xTextFactory->createInstance(sServiceName);
    2737           8 :                         xFieldProperties = uno::Reference< beans::XPropertySet >( xFieldInterface, uno::UNO_QUERY_THROW);
    2738           8 :                     }
    2739             :                 }
    2740          14 :                 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
    2741          14 :                 switch( aIt->second.eFieldId )
    2742             :                 {
    2743           0 :                     case FIELD_ADDRESSBLOCK: break;
    2744           0 :                     case FIELD_ADVANCE     : break;
    2745             :                     case FIELD_ASK         :
    2746           1 :                         handleFieldAsk(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties);
    2747           1 :                     break;
    2748             :                     case FIELD_AUTONUM    :
    2749             :                     case FIELD_AUTONUMLGL :
    2750             :                     case FIELD_AUTONUMOUT :
    2751           0 :                         handleAutoNum(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties);
    2752           0 :                     break;
    2753             :                     case FIELD_AUTHOR       :
    2754             :                     case FIELD_USERNAME     :
    2755             :                     case FIELD_USERINITIALS :
    2756           0 :                         handleAuthor(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties, aIt->second.eFieldId  );
    2757           0 :                     break;
    2758             :                     case FIELD_DATE:
    2759           1 :                     if (xFieldProperties.is())
    2760             :                     {
    2761             :                         //not fixed,
    2762           1 :                         xFieldProperties->setPropertyValue(
    2763           1 :                             rPropNameSupplier.GetName(PROP_IS_FIXED),
    2764           2 :                             uno::makeAny( false ));
    2765           1 :                         xFieldProperties->setPropertyValue(
    2766           1 :                             rPropNameSupplier.GetName(PROP_IS_DATE),
    2767           2 :                             uno::makeAny( true ));
    2768           1 :                         SetNumberFormat( pContext->GetCommand(), xFieldProperties );
    2769             :                     }
    2770           1 :                     break;
    2771             :                     case FIELD_COMMENTS     :
    2772             :                     {
    2773             :                         // OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" COMMENTS") );
    2774             :                         // A parameter with COMMENTS shouldn't set fixed
    2775             :                         // ( or at least the binary filter doesn't )
    2776             :                         // If we set fixed then we wont export a field cmd.
    2777             :                         // Additionally the para in COMMENTS is more like an
    2778             :                         // instruction to set the document property comments
    2779             :                         // with the param ( e.g. each COMMENT with a param will
    2780             :                         // overwrite the Comments document property
    2781             :                         // #TODO implement the above too
    2782           0 :                         xFieldProperties->setPropertyValue(
    2783           0 :                             rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( false ));
    2784             :                             //PROP_CURRENT_PRESENTATION is set later anyway
    2785             :                     }
    2786           0 :                     break;
    2787             :                     case FIELD_CREATEDATE  :
    2788             :                     {
    2789           0 :                         xFieldProperties->setPropertyValue(
    2790           0 :                             rPropNameSupplier.GetName( PROP_IS_DATE ), uno::makeAny( true ));
    2791           0 :                         SetNumberFormat( pContext->GetCommand(), xFieldProperties );
    2792             :                     }
    2793           0 :                     break;
    2794             :                     case FIELD_DOCPROPERTY :
    2795           0 :                         handleDocProperty(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties);
    2796           0 :                     break;
    2797             :                     case FIELD_DOCVARIABLE  :
    2798             :                     {
    2799           0 :                         OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" DOCVARIABLE") );
    2800             :                         //create a user field and type
    2801             :                         uno::Reference< beans::XPropertySet > xMaster =
    2802           0 :                             FindOrCreateFieldMaster( "com.sun.star.text.FieldMaster.User", sParam );
    2803           0 :                         uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
    2804           0 :                         xDependentField->attachTextFieldMaster( xMaster );
    2805           0 :                         m_bSetUserFieldContent = true;
    2806             :                     }
    2807           0 :                     break;
    2808             :                     case FIELD_EDITTIME     :
    2809             :                         //it's a numbering type, no number format! SetNumberFormat( pContext->GetCommand(), xFieldProperties );
    2810           0 :                     break;
    2811             :                     case FIELD_EQ:
    2812             :                     {
    2813           1 :                         OUString aCommand = pContext->GetCommand().trim();
    2814           1 :                         nSpaceIndex = aCommand.indexOf(' ');
    2815           1 :                         if(nSpaceIndex > 0)
    2816           1 :                             aCommand = aCommand.copy(nSpaceIndex).trim();
    2817           1 :                         if (aCommand.compareTo("\\s", 2) == 0)
    2818             :                         {
    2819           1 :                             aCommand = aCommand.copy(2);
    2820           1 :                             if (aCommand.compareTo("\\do", 3) == 0)
    2821             :                             {
    2822           1 :                                 aCommand = aCommand.copy(3);
    2823           1 :                                 sal_Int32 nStartIndex = aCommand.indexOf('(');
    2824           1 :                                 sal_Int32 nEndIndex = aCommand.indexOf(')');
    2825           1 :                                 if (nStartIndex > 0 && nEndIndex > 0)
    2826             :                                 {
    2827             :                                     // nDown is the requested "lower by" value in points.
    2828           1 :                                     sal_Int32 nDown = aCommand.copy(0, nStartIndex).toInt32();
    2829           1 :                                     OUString aContent = aCommand.copy(nStartIndex + 1, nEndIndex - nStartIndex - 1);
    2830           1 :                                     PropertyMapPtr pCharContext = GetTopContext();
    2831             :                                     // dHeight is the font size of the current style.
    2832           1 :                                     double dHeight = 0;
    2833           1 :                                     if (GetPropertyFromStyleSheet(PROP_CHAR_HEIGHT) >>= dHeight)
    2834             :                                         // Character escapement should be given in negative percents for subscripts.
    2835           1 :                                         pCharContext->Insert(PROP_CHAR_ESCAPEMENT, true, uno::makeAny( sal_Int16(- 100 * nDown / dHeight) ) );
    2836           1 :                                     appendTextPortion(aContent, pCharContext);
    2837             :                                 }
    2838             :                             }
    2839           1 :                         }
    2840             :                     }
    2841           1 :                     break;
    2842             :                     case FIELD_FILLIN       :
    2843             :                     {
    2844           0 :                         sal_Int32 nIndex = 0;
    2845           0 :                         if (xFieldProperties.is())
    2846           0 :                             xFieldProperties->setPropertyValue(
    2847           0 :                                     rPropNameSupplier.GetName(PROP_HINT), uno::makeAny( pContext->GetCommand().getToken( 1, '\"', nIndex)));
    2848             :                     }
    2849           0 :                     break;
    2850             :                     case FIELD_FILENAME:
    2851             :                     {
    2852           0 :                         sal_Int32 nNumberingTypeIndex = pContext->GetCommand().indexOf("\\p");
    2853           0 :                         if (xFieldProperties.is())
    2854           0 :                             xFieldProperties->setPropertyValue(
    2855           0 :                                     rPropNameSupplier.GetName(PROP_FILE_FORMAT),
    2856           0 :                                     uno::makeAny( nNumberingTypeIndex > 0 ? text::FilenameDisplayFormat::FULL : text::FilenameDisplayFormat::NAME ));
    2857             :                     }
    2858           0 :                     break;
    2859           0 :                     case FIELD_FILESIZE     : break;
    2860           0 :                     case FIELD_FORMULA : break;
    2861             :                     case FIELD_FORMCHECKBOX :
    2862             :                     case FIELD_FORMDROPDOWN :
    2863             :                     case FIELD_FORMTEXT :
    2864             :                         {
    2865           1 :                             uno::Reference< text::XTextField > xTextField( xFieldInterface, uno::UNO_QUERY );
    2866           1 :                             if ( !xTextField.is() )
    2867             :                             {
    2868             :                                 FFDataHandler::Pointer_t
    2869           1 :                                 pFFDataHandler(pContext->getFFDataHandler());
    2870             :                                 FormControlHelper::Pointer_t
    2871             :                                     pFormControlHelper(new FormControlHelper
    2872           1 :                                                        (m_bUsingEnhancedFields ? aIt->second.eFieldId : FIELD_FORMCHECKBOX,
    2873             : 
    2874           2 :                                                         m_xTextDocument, pFFDataHandler));
    2875           1 :                                 pContext->setFormControlHelper(pFormControlHelper);
    2876           1 :                                 uno::Reference< text::XFormField > xFormField( xFieldInterface, uno::UNO_QUERY );
    2877           1 :                                 uno::Reference< container::XNamed > xNamed( xFormField, uno::UNO_QUERY );
    2878           1 :                                 if ( xNamed.is() )
    2879             :                                 {
    2880           1 :                                     if ( pFFDataHandler && !pFFDataHandler->getName().isEmpty() )
    2881           0 :                                         xNamed->setName(  pFFDataHandler->getName() );
    2882           1 :                                     pContext->SetFormField( xFormField );
    2883           1 :                                 }
    2884             :                             }
    2885             :                             else
    2886             :                             {
    2887           0 :                                 if ( aIt->second.eFieldId == FIELD_FORMDROPDOWN )
    2888           0 :                                     lcl_handleDropdownField( xFieldProperties, pContext->getFFDataHandler() );
    2889             :                                 else
    2890           0 :                                     lcl_handleTextField( xFieldProperties, pContext->getFFDataHandler(), rPropNameSupplier );
    2891           1 :                             }
    2892             :                         }
    2893           1 :                         break;
    2894           0 :                     case FIELD_GOTOBUTTON   : break;
    2895             :                     case FIELD_HYPERLINK:
    2896             :                     {
    2897           5 :                         ::std::vector<OUString> aParts = pContext->GetCommandParts();
    2898           5 :                         ::std::vector<OUString>::const_iterator aItEnd = aParts.end();
    2899           5 :                         ::std::vector<OUString>::const_iterator aPartIt = aParts.begin();
    2900             : 
    2901           5 :                         OUString sURL;
    2902             : 
    2903          23 :                         while (aPartIt != aItEnd)
    2904             :                         {
    2905          13 :                             if ( *aPartIt == "\\l" )
    2906             :                             {
    2907           3 :                                 ++aPartIt;
    2908             : 
    2909           3 :                                 if (aPartIt == aItEnd)
    2910           0 :                                     break;
    2911             : 
    2912           3 :                                 sURL += OUString('#');
    2913           3 :                                 sURL += *aPartIt;
    2914             :                             }
    2915          10 :                             else if ( *aPartIt == "\\m" || *aPartIt == "\\n" )
    2916             :                             {
    2917             :                             }
    2918          10 :                             else if ( *aPartIt == "\\o" || *aPartIt == "\\t" )
    2919             :                             {
    2920           0 :                                 ++aPartIt;
    2921             : 
    2922           0 :                                 if (aPartIt == aItEnd)
    2923           0 :                                     break;
    2924             :                             }
    2925             :                             else
    2926             :                             {
    2927          10 :                                 sURL = *aPartIt;
    2928             :                             }
    2929             : 
    2930          13 :                             ++aPartIt;
    2931             :                         }
    2932             : 
    2933           5 :                         if (!sURL.isEmpty())
    2934             :                         {
    2935           5 :                             pContext->SetHyperlinkURL(sURL);
    2936           5 :                         }
    2937             :                     }
    2938           5 :                     break;
    2939           0 :                     case FIELD_IF           : break;
    2940           0 :                     case FIELD_INFO         : break;
    2941           0 :                     case FIELD_INCLUDEPICTURE: break;
    2942             :                     case FIELD_KEYWORDS     :
    2943             :                     {
    2944           0 :                         OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" KEYWORDS") );
    2945           0 :                         if(!sParam.isEmpty())
    2946             :                         {
    2947           0 :                             xFieldProperties->setPropertyValue(
    2948           0 :                                     rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
    2949             :                             //PROP_CURRENT_PRESENTATION is set later anyway
    2950           0 :                         }
    2951             :                     }
    2952           0 :                     break;
    2953           0 :                     case FIELD_LASTSAVEDBY  : break;
    2954             :                     case FIELD_MACROBUTTON:
    2955             :                     {
    2956             :                         //extract macro name
    2957           0 :                         sal_Int32 nIndex = sizeof(" MACROBUTTON ");
    2958           0 :                         OUString sMacro = pContext->GetCommand().getToken( 0, ' ', nIndex);
    2959           0 :                         if (xFieldProperties.is())
    2960           0 :                             xFieldProperties->setPropertyValue(
    2961           0 :                                     rPropNameSupplier.GetName(PROP_MACRO_NAME), uno::makeAny( sMacro ));
    2962             : 
    2963             :                         //extract quick help text
    2964           0 :                         if(xFieldProperties.is() && pContext->GetCommand().getLength() > nIndex + 1)
    2965             :                         {
    2966           0 :                             xFieldProperties->setPropertyValue(
    2967           0 :                                 rPropNameSupplier.GetName(PROP_HINT),
    2968           0 :                                 uno::makeAny( pContext->GetCommand().copy( nIndex )));
    2969           0 :                         }
    2970             :                     }
    2971           0 :                     break;
    2972             :                     case FIELD_MERGEFIELD  :
    2973             :                     {
    2974             :                         //todo: create a database field and fieldmaster pointing to a column, only
    2975           0 :                         OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" MERGEFIELD") );
    2976             :                         //create a user field and type
    2977             :                         uno::Reference< beans::XPropertySet > xMaster =
    2978           0 :                             FindOrCreateFieldMaster( "com.sun.star.text.FieldMaster.Database", sParam );
    2979             : 
    2980             :     //                    xFieldProperties->setPropertyValue(
    2981             :     //                             "FieldCode",
    2982             :     //                             uno::makeAny( pContext->GetCommand().copy( nIndex + 1 )));
    2983           0 :                         uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
    2984           0 :                         xDependentField->attachTextFieldMaster( xMaster );
    2985           0 :                         m_bSetUserFieldContent = true;
    2986             :                     }
    2987           0 :                     break;
    2988           0 :                     case FIELD_MERGEREC     : break;
    2989           0 :                     case FIELD_MERGESEQ     : break;
    2990           0 :                     case FIELD_NEXT         : break;
    2991           0 :                     case FIELD_NEXTIF       : break;
    2992             :                     case FIELD_PAGE        :
    2993           4 :                         if (xFieldProperties.is())
    2994             :                         {
    2995           4 :                             xFieldProperties->setPropertyValue(
    2996           4 :                                     rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
    2997           8 :                                     uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) ));
    2998           4 :                             xFieldProperties->setPropertyValue(
    2999           4 :                                     rPropNameSupplier.GetName(PROP_SUB_TYPE),
    3000           8 :                                     uno::makeAny( text::PageNumberType_CURRENT ));
    3001             :                         }
    3002             : 
    3003           4 :                     break;
    3004             :                     case FIELD_PAGEREF:
    3005             :                     case FIELD_REF:
    3006           1 :                     if (xFieldProperties.is())
    3007             :                     {
    3008           1 :                         bool bPageRef = aIt->second.eFieldId == FIELD_PAGEREF;
    3009           1 :                         OUString sBookmark = lcl_ExtractParameter(pContext->GetCommand(),
    3010           2 :                                 (bPageRef ? sizeof(" PAGEREF") : sizeof(" REF")));
    3011             : 
    3012             :                         // Do we need a GetReference (default) or a GetExpression field?
    3013           1 :                         uno::Reference< text::XTextFieldsSupplier > xFieldsSupplier( GetTextDocument(), uno::UNO_QUERY );
    3014           1 :                         uno::Reference< container::XNameAccess > xFieldMasterAccess = xFieldsSupplier->getTextFieldMasters();
    3015             : 
    3016           1 :                         if (!xFieldMasterAccess->hasByName("com.sun.star.text.FieldMaster.SetExpression." + sBookmark))
    3017             :                         {
    3018           0 :                         xFieldProperties->setPropertyValue(
    3019           0 :                             rPropNameSupplier.GetName(PROP_REFERENCE_FIELD_SOURCE),
    3020           0 :                             uno::makeAny( sal_Int16(text::ReferenceFieldSource::BOOKMARK)) );
    3021           0 :                         xFieldProperties->setPropertyValue(
    3022           0 :                             rPropNameSupplier.GetName(PROP_SOURCE_NAME),
    3023           0 :                             uno::makeAny( sBookmark) );
    3024           0 :                         sal_Int16 nFieldPart = (bPageRef ? text::ReferenceFieldPart::PAGE : text::ReferenceFieldPart::TEXT);
    3025           0 :                         OUString sValue;
    3026           0 :                         if( lcl_FindInCommand( pContext->GetCommand(), 'p', sValue ))
    3027             :                         {
    3028             :                             //above-below
    3029           0 :                             nFieldPart = text::ReferenceFieldPart::UP_DOWN;
    3030             :                         }
    3031           0 :                         else if( lcl_FindInCommand( pContext->GetCommand(), 'r', sValue ))
    3032             :                         {
    3033             :                             //number
    3034           0 :                             nFieldPart = text::ReferenceFieldPart::NUMBER;
    3035             :                         }
    3036           0 :                         else if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue ))
    3037             :                         {
    3038             :                             //number-no-context
    3039           0 :                             nFieldPart = text::ReferenceFieldPart::NUMBER_NO_CONTEXT;
    3040             :                         }
    3041           0 :                         else if( lcl_FindInCommand( pContext->GetCommand(), 'w', sValue ))
    3042             :                         {
    3043             :                             //number-full-context
    3044           0 :                             nFieldPart = text::ReferenceFieldPart::NUMBER_FULL_CONTEXT;
    3045             :                         }
    3046           0 :                         xFieldProperties->setPropertyValue(
    3047           0 :                                 rPropNameSupplier.GetName( PROP_REFERENCE_FIELD_PART ), uno::makeAny( nFieldPart ));
    3048             :                         }
    3049             :                         else
    3050             :                         {
    3051           1 :                             xFieldInterface = m_xTextFactory->createInstance("com.sun.star.text.TextField.GetExpression");
    3052           1 :                             xFieldProperties.set(xFieldInterface, uno::UNO_QUERY);
    3053           1 :                             xFieldProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_CONTENT), uno::makeAny(sBookmark));
    3054           1 :                             xFieldProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_SUB_TYPE), uno::makeAny(text::SetVariableType::STRING));
    3055           1 :                         }
    3056             :                     }
    3057           1 :                     break;
    3058           0 :                     case FIELD_REVNUM       : break;
    3059             :                     case FIELD_SAVEDATE     :
    3060           0 :                         SetNumberFormat( pContext->GetCommand(), xFieldProperties );
    3061           0 :                     break;
    3062           0 :                     case FIELD_SECTION      : break;
    3063           0 :                     case FIELD_SECTIONPAGES : break;
    3064           0 :                     case FIELD_SEQ          : break;
    3065           0 :                     case FIELD_SET          : break;
    3066           0 :                     case FIELD_SKIPIF       : break;
    3067           0 :                     case FIELD_STYLEREF     : break;
    3068             :                     case FIELD_SUBJECT      :
    3069             :                     {
    3070           0 :                         OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" SUBJECT") );
    3071           0 :                         if(!sParam.isEmpty())
    3072             :                         {
    3073           0 :                             xFieldProperties->setPropertyValue(
    3074           0 :                                     rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
    3075             :                             //PROP_CURRENT_PRESENTATION is set later anyway
    3076           0 :                         }
    3077             :                     }
    3078           0 :                     break;
    3079           0 :                     case FIELD_SYMBOL       : break;
    3080           0 :                     case FIELD_TEMPLATE: break;
    3081             :                     case FIELD_TIME         :
    3082           0 :                         SetNumberFormat( pContext->GetCommand(), xFieldProperties );
    3083           0 :                     break;
    3084             :                     case FIELD_TITLE        :
    3085             :                     {
    3086           0 :                         OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" TITLE") );
    3087           0 :                         if(!sParam.isEmpty())
    3088             :                         {
    3089           0 :                             xFieldProperties->setPropertyValue(
    3090           0 :                                     rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
    3091             :                             //PROP_CURRENT_PRESENTATION is set later anyway
    3092           0 :                         }
    3093             :                     }
    3094           0 :                     break;
    3095             :                     case FIELD_USERADDRESS  : //todo: user address collects street, city ...
    3096           0 :                     break;
    3097             :                     case FIELD_TOC:
    3098             :                         handleToc(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties,
    3099           0 :                                   OUString::createFromAscii(aIt->second.cFieldServiceName));
    3100           0 :                     break;
    3101             :                     case FIELD_TC :
    3102             :                     {
    3103             :                         uno::Reference< beans::XPropertySet > xTC(
    3104           0 :                             m_xTextFactory->createInstance(
    3105           0 :                                 OUString::createFromAscii(aIt->second.cFieldServiceName)),
    3106           0 :                                 uno::UNO_QUERY_THROW);
    3107           0 :                         OUString sTCText = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" TC") );
    3108           0 :                         if( !sTCText.isEmpty())
    3109           0 :                             xTC->setPropertyValue(rPropNameSupplier.GetName(PROP_ALTERNATIVE_TEXT),
    3110           0 :                                 uno::makeAny(sTCText));
    3111           0 :                         OUString sValue;
    3112             :                         // \f TC entry in doc with multiple tables
    3113             :     //                    if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue ))
    3114             :     //                    {
    3115             :                             // todo: unsupported
    3116             :     //                    }
    3117           0 :                         if( lcl_FindInCommand( pContext->GetCommand(), 'l', sValue ))
    3118             :                         // \l Outline Level
    3119             :                         {
    3120           0 :                             sal_Int32 nLevel = sValue.toInt32();
    3121           0 :                             if( !sValue.isEmpty() && nLevel >= 0 && nLevel <= 10 )
    3122           0 :                                 xTC->setPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL), uno::makeAny( (sal_Int16)nLevel ));
    3123             :                         }
    3124             :     //                    if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue ))
    3125             :     //                    \n Suppress page numbers
    3126             :     //                    {
    3127             :                             //todo: unsupported feature
    3128             :     //                    }
    3129           0 :                         pContext->SetTC( xTC );
    3130             :                     }
    3131           0 :                     break;
    3132             :                     case  FIELD_NUMCHARS:
    3133             :                     case  FIELD_NUMWORDS:
    3134             :                     case  FIELD_NUMPAGES:
    3135           0 :                     if (xFieldProperties.is())
    3136           0 :                         xFieldProperties->setPropertyValue(
    3137           0 :                             rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
    3138           0 :                             uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) ));
    3139           0 :                     break;
    3140             : 
    3141          14 :                 }
    3142             :             }
    3143             :             //set the text field if there is any
    3144          17 :             pContext->SetTextField( uno::Reference< text::XTextField >( xFieldInterface, uno::UNO_QUERY ) );
    3145             :         }
    3146           0 :         catch( const uno::Exception& )
    3147             :         {
    3148             :             OSL_FAIL( "Exception in CloseFieldCommand()" );
    3149             :         }
    3150          17 :         pContext->SetCommandCompleted();
    3151          17 :     }
    3152          17 : }
    3153             : /*-------------------------------------------------------------------------
    3154             : //the _current_ fields require a string type result while TOCs accept richt results
    3155             :   -----------------------------------------------------------------------*/
    3156           9 : bool DomainMapper_Impl::IsFieldResultAsString()
    3157             : {
    3158           9 :     bool bRet = false;
    3159             :     OSL_ENSURE( !m_aFieldStack.empty(), "field stack empty?");
    3160           9 :     FieldContextPtr pContext = m_aFieldStack.top();
    3161             :     OSL_ENSURE( pContext.get(), "no field context available");
    3162           9 :     if( pContext.get() )
    3163             :     {
    3164           9 :         bRet = pContext->GetTextField().is();
    3165             :     }
    3166           9 :     return bRet;
    3167             : }
    3168             : 
    3169             : 
    3170           4 : void DomainMapper_Impl::SetFieldResult( OUString& rResult )
    3171             : {
    3172             : #ifdef DEBUG_DOMAINMAPPER
    3173             :     dmapper_logger->startElement("setFieldResult");
    3174             :     dmapper_logger->chars(rResult);
    3175             : #endif
    3176             : 
    3177           4 :     FieldContextPtr pContext = m_aFieldStack.top();
    3178             :     OSL_ENSURE( pContext.get(), "no field context available");
    3179           4 :     if( pContext.get() )
    3180             :     {
    3181           4 :         uno::Reference<text::XTextField> xTextField = pContext->GetTextField();
    3182             :         try
    3183             :         {
    3184           4 :             PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
    3185             :             OSL_ENSURE( xTextField.is()
    3186             :             //||m_xTOC.is() ||m_xTC.is()
    3187             :             //||m_sHyperlinkURL.getLength()
    3188             :             , "DomainMapper_Impl::SetFieldResult: field not created" );
    3189           4 :             if(xTextField.is())
    3190             :             {
    3191             :                 try
    3192             :                 {
    3193           4 :                     if( m_bSetUserFieldContent )
    3194             :                     {
    3195             :                         // user field content has to be set at the field master
    3196           0 :                         uno::Reference< text::XDependentTextField > xDependentField( xTextField, uno::UNO_QUERY_THROW );
    3197           0 :                         xDependentField->getTextFieldMaster()->setPropertyValue(
    3198           0 :                                 rPropNameSupplier.GetName(PROP_CONTENT),
    3199           0 :                              uno::makeAny( rResult ));
    3200             :                     }
    3201             :                     else
    3202             :                     {
    3203           4 :                         uno::Reference< beans::XPropertySet > xFieldProperties( xTextField, uno::UNO_QUERY_THROW);
    3204             :                         // In case of SetExpression, the field result contains the content of the variable.
    3205           4 :                         uno::Reference<lang::XServiceInfo> xServiceInfo(xTextField, uno::UNO_QUERY);
    3206           4 :                         bool bIsSetExpression = xServiceInfo->supportsService("com.sun.star.text.TextField.SetExpression");
    3207           4 :                         xFieldProperties->setPropertyValue(
    3208           4 :                                 rPropNameSupplier.GetName(bIsSetExpression ? PROP_CONTENT : PROP_CURRENT_PRESENTATION),
    3209          10 :                              uno::makeAny( rResult ));
    3210             :                     }
    3211             :                 }
    3212           2 :                 catch( const beans::UnknownPropertyException& )
    3213             :                 {
    3214             :                     //some fields don't have a CurrentPresentation (DateTime)
    3215             :                 }
    3216             :             }
    3217             :         }
    3218           0 :         catch( const uno::Exception& )
    3219             :         {
    3220             : 
    3221           4 :         }
    3222           4 :     }
    3223           4 : }
    3224             : 
    3225           7 : void DomainMapper_Impl::SetFieldFFData(FFDataHandler::Pointer_t pFFDataHandler)
    3226             : {
    3227             : #ifdef DEBUG_DOMAINMAPPER
    3228             :     dmapper_logger->startElement("setFieldFFData");
    3229             : #endif
    3230             : 
    3231           7 :     if (m_aFieldStack.size())
    3232             :     {
    3233           7 :         FieldContextPtr pContext = m_aFieldStack.top();
    3234           7 :         if (pContext.get())
    3235             :         {
    3236           7 :             pContext->setFFDataHandler(pFFDataHandler);
    3237           7 :         }
    3238             :     }
    3239             : 
    3240             : #ifdef DEBUG_DOMAINMAPPER
    3241             :     dmapper_logger->endElement();
    3242             : #endif
    3243           7 : }
    3244             : 
    3245             : /*-------------------------------------------------------------------------
    3246             : //the end of field is reached (0x15 appeared) - the command might still be open
    3247             :   -----------------------------------------------------------------------*/
    3248          17 : void DomainMapper_Impl::PopFieldContext()
    3249             : {
    3250             : #ifdef DEBUG_DOMAINMAPPER
    3251             :     dmapper_logger->element("popFieldContext");
    3252             : #endif
    3253             : 
    3254          17 :     if (m_aFieldStack.empty())
    3255          17 :         return;
    3256             : 
    3257          17 :     FieldContextPtr pContext = m_aFieldStack.top();
    3258             :     OSL_ENSURE( pContext.get(), "no field context available");
    3259          17 :     if( pContext.get() )
    3260             :     {
    3261          17 :         if( !pContext->IsCommandCompleted() )
    3262           1 :             CloseFieldCommand();
    3263             : 
    3264             :         //insert the field, TC or TOC
    3265          17 :         uno::Reference< text::XTextAppend >  xTextAppend;
    3266          17 :         if (!m_aTextAppendStack.empty())
    3267          17 :             xTextAppend = m_aTextAppendStack.top().xTextAppend;
    3268          17 :         if(xTextAppend.is())
    3269             :         {
    3270             :             try
    3271             :             {
    3272          17 :                 uno::Reference< text::XTextCursor > xCrsr = xTextAppend->createTextCursorByRange(pContext->GetStartRange());
    3273             :                 //remove the dummy character
    3274          17 :                 xCrsr->goRight( 1, true );
    3275          17 :                 xCrsr->setString( OUString() );
    3276          17 :                 uno::Reference< text::XTextContent > xToInsert( pContext->GetTOC(), uno::UNO_QUERY );
    3277          17 :                 if( xToInsert.is() )
    3278             :                 {
    3279           0 :                     xCrsr->gotoEnd( true );
    3280           0 :                     xToInsert->attach( uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW ));
    3281             :                 }
    3282             :                 else
    3283             :                 {
    3284          17 :                     xToInsert = uno::Reference< text::XTextContent >(pContext->GetTC(), uno::UNO_QUERY);
    3285          17 :                     if( !xToInsert.is() )
    3286          17 :                         xToInsert = uno::Reference< text::XTextContent >(pContext->GetTextField(), uno::UNO_QUERY);
    3287          17 :                     if( xToInsert.is() )
    3288             :                     {
    3289           7 :                         uno::Sequence<beans::PropertyValue> aValues;
    3290             :                         // Character properties of the field show up here the
    3291             :                         // last (always empty) run. Inherit character
    3292             :                         // properties from there.
    3293           7 :                         if (m_pLastCharacterContext.get())
    3294           7 :                             aValues = m_pLastCharacterContext->GetPropertyValues();
    3295           7 :                         appendTextContent(xToInsert, aValues);
    3296             :                     }
    3297             :                     else
    3298             :                     {
    3299          10 :                         FormControlHelper::Pointer_t pFormControlHelper(pContext->getFormControlHelper());
    3300          10 :                         if (pFormControlHelper.get() != NULL && pFormControlHelper->hasFFDataHandler() )
    3301             :                         {
    3302           1 :                             uno::Reference< text::XFormField > xFormField( pContext->GetFormField() );
    3303           1 :                             xToInsert.set(xFormField, uno::UNO_QUERY);
    3304           1 :                             if ( xFormField.is() && xToInsert.is() )
    3305             :                             {
    3306           1 :                                 xCrsr->gotoEnd( true );
    3307           1 :                                 xToInsert->attach( uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW ));
    3308           1 :                                 pFormControlHelper->processField( xFormField );
    3309             :                             }
    3310             :                             else
    3311             :                             {
    3312           0 :                                 uno::Reference<text::XTextRange> xTxtRange(xCrsr, uno::UNO_QUERY);
    3313           0 :                                 pFormControlHelper->insertControl(xTxtRange);
    3314           1 :                             }
    3315             :                         }
    3316           9 :                         else if(!pContext->GetHyperlinkURL().isEmpty())
    3317             :                         {
    3318           5 :                             PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
    3319           5 :                             xCrsr->gotoEnd( true );
    3320             : 
    3321           5 :                             uno::Reference< beans::XPropertySet > xCrsrProperties( xCrsr, uno::UNO_QUERY_THROW );
    3322          10 :                             xCrsrProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_HYPER_LINK_U_R_L), uno::
    3323          10 :                                                               makeAny(pContext->GetHyperlinkURL()));
    3324          10 :                         }
    3325             :                     }
    3326          17 :                 }
    3327             :             }
    3328           0 :             catch(const lang::IllegalArgumentException&)
    3329             :             {
    3330             :                 OSL_FAIL( "IllegalArgumentException in PopFieldContext()" );
    3331             :             }
    3332           0 :             catch(const uno::Exception&)
    3333             :             {
    3334             :                 OSL_FAIL( "exception in PopFieldContext()" );
    3335             :             }
    3336          17 :         }
    3337             :         //
    3338             :         //TOCs have to include all the imported content
    3339             :         //...
    3340             :     }
    3341             :     //remove the field context
    3342          17 :     m_aFieldStack.pop();
    3343             : }
    3344             : 
    3345             : 
    3346          28 : void DomainMapper_Impl::AddBookmark( const OUString& rBookmarkName, const OUString& rId )
    3347             : {
    3348          28 :     if (m_aTextAppendStack.empty())
    3349          28 :         return;
    3350          28 :     uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
    3351          28 :     BookmarkMap_t::iterator aBookmarkIter = m_aBookmarkMap.find( rId );
    3352             :     //is the bookmark name already registered?
    3353             :     try
    3354             :     {
    3355          28 :         if( aBookmarkIter != m_aBookmarkMap.end() )
    3356             :         {
    3357          14 :             static const OUString sBookmarkService("com.sun.star.text.Bookmark");
    3358          14 :             if (m_xTextFactory.is())
    3359             :             {
    3360          14 :                 uno::Reference< text::XTextContent > xBookmark( m_xTextFactory->createInstance( sBookmarkService ), uno::UNO_QUERY_THROW );
    3361          14 :                 uno::Reference< text::XTextCursor > xCursor;
    3362          14 :                 uno::Reference< text::XText > xText = aBookmarkIter->second.m_xTextRange->getText();
    3363          14 :                 if( aBookmarkIter->second.m_bIsStartOfText )
    3364           7 :                     xCursor = xText->createTextCursorByRange( xText->getStart() );
    3365             :                 else
    3366             :                 {
    3367           7 :                     xCursor = xText->createTextCursorByRange( aBookmarkIter->second.m_xTextRange );
    3368           7 :                     xCursor->goRight( 1, false );
    3369             :                 }
    3370             : 
    3371          14 :                 xCursor->gotoRange( xTextAppend->getEnd(), true );
    3372          14 :                 uno::Reference< container::XNamed > xBkmNamed( xBookmark, uno::UNO_QUERY_THROW );
    3373             :                 //todo: make sure the name is not used already!
    3374          14 :                 if ( !aBookmarkIter->second.m_sBookmarkName.isEmpty() )
    3375          14 :                     xBkmNamed->setName( aBookmarkIter->second.m_sBookmarkName );
    3376             :                 else
    3377           0 :                     xBkmNamed->setName( rBookmarkName );
    3378          14 :                 xTextAppend->insertTextContent( uno::Reference< text::XTextRange >( xCursor, uno::UNO_QUERY_THROW), xBookmark, !xCursor->isCollapsed() );
    3379             :             }
    3380          14 :             m_aBookmarkMap.erase( aBookmarkIter );
    3381             :         }
    3382             :         else
    3383             :         {
    3384             :             //otherwise insert a text range as marker
    3385          14 :             bool bIsStart = true;
    3386          14 :             uno::Reference< text::XTextRange > xCurrent;
    3387          14 :             if (xTextAppend.is())
    3388             :             {
    3389          14 :                 uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursorByRange( xTextAppend->getEnd() );
    3390          14 :                 bIsStart = !xCursor->goLeft(1, false);
    3391          14 :                 xCurrent = xCursor->getStart();
    3392             :             }
    3393          14 :             m_aBookmarkMap.insert(BookmarkMap_t::value_type( rId, BookmarkInsertPosition( bIsStart, rBookmarkName, xCurrent ) ));
    3394             :         }
    3395             :     }
    3396           0 :     catch( const uno::Exception& )
    3397             :     {
    3398             :         //TODO: What happens to bookmarks where start and end are at different XText objects?
    3399          28 :     }
    3400             : }
    3401             : 
    3402           8 : void DomainMapper_Impl::AddAnnotationPosition(const bool bStart)
    3403             : {
    3404           8 :     if (m_aTextAppendStack.empty())
    3405           8 :         return;
    3406             : 
    3407             :     // Create a cursor, pointing to the current position.
    3408           8 :     uno::Reference<text::XTextAppend>  xTextAppend = m_aTextAppendStack.top().xTextAppend;
    3409           8 :     uno::Reference<text::XTextRange> xCurrent;
    3410           8 :     if (xTextAppend.is())
    3411             :     {
    3412           8 :         uno::Reference<text::XTextCursor> xCursor = xTextAppend->createTextCursorByRange(xTextAppend->getEnd());
    3413           8 :         xCurrent = xCursor->getStart();
    3414             :     }
    3415             : 
    3416             :     // And save it, to be used by PopAnnotation() later.
    3417           8 :     if (bStart)
    3418           4 :         m_aAnnotationPosition.m_xStart = xCurrent;
    3419             :     else
    3420           4 :         m_aAnnotationPosition.m_xEnd = xCurrent;
    3421             : }
    3422             : 
    3423          44 : GraphicImportPtr DomainMapper_Impl::GetGraphicImport(GraphicImportType eGraphicImportType)
    3424             : {
    3425          44 :     if(!m_pGraphicImport)
    3426          22 :         m_pGraphicImport.reset( new GraphicImport( m_xComponentContext, m_xTextFactory, m_rDMapper, eGraphicImportType ) );
    3427          44 :     return m_pGraphicImport;
    3428             : }
    3429             : /*-------------------------------------------------------------------------
    3430             :     reset graphic import if the last import resulted in a shape, not a graphic
    3431             :   -----------------------------------------------------------------------*/
    3432           0 : void DomainMapper_Impl::ResetGraphicImport()
    3433             : {
    3434           0 :     m_pGraphicImport.reset();
    3435           0 : }
    3436             : 
    3437             : 
    3438          22 : void  DomainMapper_Impl::ImportGraphic(writerfilter::Reference< Properties >::Pointer_t ref, GraphicImportType eGraphicImportType)
    3439             : {
    3440          22 :     GetGraphicImport(eGraphicImportType);
    3441          22 :     if( eGraphicImportType != IMPORT_AS_DETECTED_INLINE && eGraphicImportType != IMPORT_AS_DETECTED_ANCHOR )
    3442             :     {
    3443             :         //create the graphic
    3444           0 :         ref->resolve( *m_pGraphicImport );
    3445             :     }
    3446             : 
    3447             :     //insert it into the document at the current cursor position
    3448             : 
    3449             :     uno::Reference<text::XTextContent> xTextContent
    3450          22 :         (m_pGraphicImport->GetGraphicObject());
    3451             : 
    3452             :     //insert it into the document at the current cursor position
    3453             :     OSL_ENSURE( xTextContent.is(), "DomainMapper_Impl::ImportGraphic");
    3454          22 :     if( xTextContent.is())
    3455          22 :         appendTextContent( xTextContent, uno::Sequence< beans::PropertyValue >() );
    3456             : 
    3457          22 :     m_pGraphicImport.reset();
    3458          22 : }
    3459             : 
    3460             : 
    3461             : 
    3462           0 : void DomainMapper_Impl::SetLineNumbering( sal_Int32 nLnnMod, sal_Int32 nLnc, sal_Int32 ndxaLnn )
    3463             : {
    3464           0 :     if( !m_bLineNumberingSet )
    3465             :     {
    3466           0 :         const PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
    3467             : 
    3468             :         try
    3469             :         {
    3470           0 :             uno::Reference< text::XLineNumberingProperties > xLineProperties( m_xTextDocument, uno::UNO_QUERY_THROW );
    3471           0 :             uno::Reference< beans::XPropertySet > xProperties = xLineProperties->getLineNumberingProperties();
    3472           0 :             uno::Any aTrue( uno::makeAny( true ));
    3473           0 :             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_IS_ON                  ), aTrue);
    3474           0 :             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_COUNT_EMPTY_LINES      ), aTrue );
    3475           0 :             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_COUNT_LINES_IN_FRAMES  ), uno::makeAny( false ) );
    3476           0 :             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_INTERVAL               ), uno::makeAny( static_cast< sal_Int16 >( nLnnMod )));
    3477           0 :             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_DISTANCE               ), uno::makeAny( ConversionHelper::convertTwipToMM100(ndxaLnn) ));
    3478           0 :             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_NUMBER_POSITION        ), uno::makeAny( style::LineNumberPosition::LEFT));
    3479           0 :             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_NUMBERING_TYPE         ), uno::makeAny( style::NumberingType::ARABIC));
    3480           0 :             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_RESTART_AT_EACH_PAGE   ), uno::makeAny( nLnc == 0 ));
    3481             :         }
    3482           0 :         catch( const uno::Exception& )
    3483             :         {}
    3484             :     }
    3485           0 :     m_bLineNumberingSet = true;
    3486           0 : }
    3487             : 
    3488             : 
    3489         935 : void DomainMapper_Impl::SetPageMarginTwip( PageMarElement eElement, sal_Int32 nValue )
    3490             : {
    3491         935 :     nValue = ConversionHelper::convertTwipToMM100(nValue);
    3492         935 :     switch(eElement)
    3493             :     {
    3494         154 :         case PAGE_MAR_TOP    : m_aPageMargins.top     = nValue; break;
    3495         156 :         case PAGE_MAR_RIGHT  : m_aPageMargins.right   = nValue; break;
    3496         153 :         case PAGE_MAR_BOTTOM : m_aPageMargins.bottom  = nValue; break;
    3497         156 :         case PAGE_MAR_LEFT   : m_aPageMargins.left    = nValue; break;
    3498         107 :         case PAGE_MAR_HEADER : m_aPageMargins.header  = nValue; break;
    3499         106 :         case PAGE_MAR_FOOTER : m_aPageMargins.footer  = nValue; break;
    3500         103 :         case PAGE_MAR_GUTTER : m_aPageMargins.gutter  = nValue; break;
    3501             :     }
    3502         935 : }
    3503             : 
    3504             : 
    3505             : 
    3506         382 : _PageMar::_PageMar()
    3507             : {
    3508         382 :     header = footer = ConversionHelper::convertTwipToMM100(sal_Int32(720));
    3509         382 :     top = bottom = ConversionHelper::convertTwipToMM100( sal_Int32(1440));
    3510             :     // This is strange, the RTF spec says it's 1800, but it's clearly 1440 in Word
    3511             :     // OOXML seems not to specify a default value
    3512         382 :     right = left = ConversionHelper::convertTwipToMM100( sal_Int32(1440));
    3513         382 :     gutter = 0;
    3514         382 : }
    3515             : 
    3516             : 
    3517             : 
    3518          14 : void DomainMapper_Impl::RegisterFrameConversion(
    3519             :         uno::Reference< text::XTextRange >      xFrameStartRange,
    3520             :         uno::Reference< text::XTextRange >      xFrameEndRange,
    3521             :         uno::Sequence< beans::PropertyValue >   aFrameProperties
    3522             :         )
    3523             : {
    3524             :     OSL_ENSURE(
    3525             :         !m_aFrameProperties.getLength() && !m_xFrameStartRange.is() && !m_xFrameEndRange.is(),
    3526             :         "frame properties not removed");
    3527          14 :     m_aFrameProperties = aFrameProperties;
    3528          14 :     m_xFrameStartRange = xFrameStartRange;
    3529          14 :     m_xFrameEndRange   = xFrameEndRange;
    3530          14 : }
    3531             : 
    3532             : 
    3533        1412 : bool DomainMapper_Impl::ExecuteFrameConversion()
    3534             : {
    3535        1412 :     bool bRet = false;
    3536        1412 :     if( m_xFrameStartRange.is() && m_xFrameEndRange.is() )
    3537             :     {
    3538          14 :         bRet = true;
    3539             :         try
    3540             :         {
    3541          14 :             uno::Reference< text::XTextAppendAndConvert > xTextAppendAndConvert( GetTopTextAppend(), uno::UNO_QUERY_THROW );
    3542          14 :             xTextAppendAndConvert->convertToTextFrame(
    3543             :                 m_xFrameStartRange,
    3544             :                 m_xFrameEndRange,
    3545          15 :                 m_aFrameProperties );
    3546             :         }
    3547           2 :         catch( const uno::Exception& rEx)
    3548             :         {
    3549             : #if OSL_DEBUG_LEVEL > 1
    3550             :             fprintf( stderr, "Exception caught when converting to frame: %s\n",
    3551             :                     OUStringToOString( rEx.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
    3552             : #endif
    3553             :             (void)rEx;
    3554           1 :             bRet = false;
    3555             :         }
    3556          14 :         m_xFrameStartRange = 0;
    3557          14 :         m_xFrameEndRange = 0;
    3558          14 :         m_aFrameProperties.realloc( 0 );
    3559             :     }
    3560        1412 :     return bRet;
    3561             : }
    3562             : 
    3563           2 : void DomainMapper_Impl::AddNewRedline(  )
    3564             : {
    3565           2 :     RedlineParamsPtr pNew( new RedlineParams );
    3566           2 :     pNew->m_nToken = ooxml::OOXML_mod;
    3567           2 :     if ( !m_bIsParaChange )
    3568             :     {
    3569           2 :         m_aRedlines.push_back( pNew );
    3570             :     }
    3571             :     else
    3572             :     {
    3573           0 :         m_pParaRedline.swap( pNew );
    3574           2 :     }
    3575           2 : }
    3576             : 
    3577          14 : RedlineParamsPtr DomainMapper_Impl::GetTopRedline(  )
    3578             : {
    3579          14 :     RedlineParamsPtr pResult;
    3580          14 :     if ( !m_bIsParaChange && m_aRedlines.size(  ) > 0 )
    3581          10 :         pResult = m_aRedlines.back(  );
    3582           4 :     else if ( m_bIsParaChange )
    3583           0 :         pResult = m_pParaRedline;
    3584          14 :     return pResult;
    3585             : }
    3586             : 
    3587           2 : sal_Int32 DomainMapper_Impl::GetCurrentRedlineToken(  )
    3588             : {
    3589           2 :     sal_Int32 nToken = 0;
    3590           2 :     RedlineParamsPtr pCurrent( GetTopRedline(  ) );
    3591           2 :     if ( pCurrent.get(  ) )
    3592           2 :         nToken = pCurrent->m_nToken;
    3593           2 :     return nToken;
    3594             : }
    3595             : 
    3596           6 : void DomainMapper_Impl::SetCurrentRedlineAuthor( OUString sAuthor )
    3597             : {
    3598           6 :     if (!m_xAnnotationField.is())
    3599             :     {
    3600           2 :         RedlineParamsPtr pCurrent( GetTopRedline(  ) );
    3601           2 :         if ( pCurrent.get(  ) )
    3602           2 :             pCurrent->m_sAuthor = sAuthor;
    3603             :     }
    3604             :     else
    3605           4 :         m_xAnnotationField->setPropertyValue("Author", uno::makeAny(sAuthor));
    3606           6 : }
    3607             : 
    3608           4 : void DomainMapper_Impl::SetCurrentRedlineInitials( OUString sInitials )
    3609             : {
    3610           4 :     if (m_xAnnotationField.is())
    3611           4 :         m_xAnnotationField->setPropertyValue("Initials", uno::makeAny(sInitials));
    3612           4 : }
    3613             : 
    3614           6 : void DomainMapper_Impl::SetCurrentRedlineDate( OUString sDate )
    3615             : {
    3616           6 :     if (!m_xAnnotationField.is())
    3617             :     {
    3618           2 :         RedlineParamsPtr pCurrent( GetTopRedline(  ) );
    3619           2 :         if ( pCurrent.get(  ) )
    3620           2 :             pCurrent->m_sDate = sDate;
    3621             :     }
    3622             :     else
    3623           4 :         m_xAnnotationField->setPropertyValue("DateTimeValue", uno::makeAny(lcl_DateStringToDateTime(sDate)));
    3624           6 : }
    3625             : 
    3626           6 : void DomainMapper_Impl::SetCurrentRedlineId( sal_Int32 sId )
    3627             : {
    3628           6 :     RedlineParamsPtr pCurrent( GetTopRedline(  ) );
    3629           6 :     if ( pCurrent.get(  ) )
    3630           2 :         pCurrent->m_nId = sId;
    3631           6 : }
    3632             : 
    3633           2 : void DomainMapper_Impl::SetCurrentRedlineToken( sal_Int32 nToken )
    3634             : {
    3635           2 :     RedlineParamsPtr pCurrent( GetTopRedline(  ) );
    3636           2 :     if ( pCurrent.get(  ) )
    3637           2 :         pCurrent->m_nToken = nToken;
    3638           2 : }
    3639             : 
    3640             : 
    3641             : 
    3642           2 : void DomainMapper_Impl::RemoveCurrentRedline( )
    3643             : {
    3644           2 :     if ( m_aRedlines.size( ) > 0 )
    3645             :     {
    3646           2 :         m_aRedlines.pop_back( );
    3647             :     }
    3648           2 : }
    3649             : 
    3650           0 : void DomainMapper_Impl::ResetParaRedline( )
    3651             : {
    3652           0 :     if ( m_pParaRedline.get( ) )
    3653             :     {
    3654           0 :         RedlineParamsPtr pEmpty;
    3655           0 :         m_pParaRedline.swap( pEmpty );
    3656             :     }
    3657           0 : }
    3658             : 
    3659             : 
    3660             : 
    3661         213 : void DomainMapper_Impl::ApplySettingsTable()
    3662             : {
    3663         213 :     if( m_pSettingsTable && m_xTextFactory.is() )
    3664             :     {
    3665             :         try
    3666             :         {
    3667         205 :             uno::Reference< beans::XPropertySet > xTextDefaults(m_xTextFactory->createInstance("com.sun.star.text.Defaults"), uno::UNO_QUERY_THROW );
    3668         205 :             sal_Int32 nDefTab = m_pSettingsTable->GetDefaultTabStop();
    3669         205 :             xTextDefaults->setPropertyValue( PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_TAB_STOP_DISTANCE ), uno::makeAny(nDefTab) );
    3670         205 :             if (m_pSettingsTable->GetLinkStyles())
    3671             :             {
    3672           1 :                 PropertyNameSupplier& rSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
    3673             :                 // If linked styles are enabled, set paragraph defaults from Word's default template
    3674           1 :                 xTextDefaults->setPropertyValue(rSupplier.GetName(PROP_PARA_BOTTOM_MARGIN), uno::makeAny(ConversionHelper::convertTwipToMM100(200)));
    3675           1 :                 style::LineSpacing aSpacing;
    3676           1 :                 aSpacing.Mode = style::LineSpacingMode::PROP;
    3677           1 :                 aSpacing.Height = sal_Int16(115);
    3678           1 :                 xTextDefaults->setPropertyValue(rSupplier.GetName(PROP_PARA_LINE_SPACING), uno::makeAny(aSpacing));
    3679             :             }
    3680             : 
    3681         205 :             if (m_pSettingsTable->GetZoomFactor())
    3682             :             {
    3683         118 :                 uno::Sequence<beans::PropertyValue> aViewProps(3);
    3684         118 :                 aViewProps[0].Name = "ZoomFactor";
    3685         118 :                 aViewProps[0].Value <<= m_pSettingsTable->GetZoomFactor();
    3686         118 :                 aViewProps[1].Name = "VisibleBottom";
    3687         118 :                 aViewProps[1].Value <<= sal_Int32(0);
    3688         118 :                 aViewProps[2].Name = "ZoomType";
    3689         118 :                 aViewProps[2].Value <<= sal_Int16(0);
    3690             : 
    3691         236 :                 uno::Reference<container::XIndexContainer> xBox(m_xComponentContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.IndexedPropertyValues",
    3692         118 :                             m_xComponentContext), uno::UNO_QUERY );
    3693         118 :                 xBox->insertByIndex(sal_Int32(0), uno::makeAny(aViewProps));
    3694         118 :                 uno::Reference<container::XIndexAccess> xIndexAccess(xBox, uno::UNO_QUERY);
    3695         118 :                 uno::Reference<document::XViewDataSupplier> xViewDataSupplier(m_xTextDocument, uno::UNO_QUERY);
    3696         118 :                 xViewDataSupplier->setViewData(xIndexAccess);
    3697             :             }
    3698             : 
    3699         205 :             uno::Reference< beans::XPropertySet > xSettings(m_xTextFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY);
    3700         205 :             if (m_pSettingsTable->GetUsePrinterMetrics())
    3701           0 :                 xSettings->setPropertyValue("PrinterIndependentLayout", uno::makeAny(document::PrinterIndependentLayout::DISABLED));
    3702         205 :             if( m_pSettingsTable->GetEmbedTrueTypeFonts())
    3703           0 :                 xSettings->setPropertyValue( PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_EMBED_FONTS ), uno::makeAny(true) );
    3704         205 :             if( m_pSettingsTable->GetEmbedSystemFonts())
    3705           6 :                 xSettings->setPropertyValue( PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_EMBED_SYSTEM_FONTS ), uno::makeAny(true) );
    3706         205 :             xSettings->setPropertyValue("AddParaTableSpacing", uno::makeAny(m_pSettingsTable->GetDoNotUseHTMLParagraphAutoSpacing()));
    3707             :         }
    3708           0 :         catch(const uno::Exception&)
    3709             :         {
    3710             :         }
    3711             :     }
    3712         213 : }
    3713             : 
    3714        4618 : uno::Reference<container::XIndexAccess> DomainMapper_Impl::GetCurrentNumberingRules(sal_Int32* pListLevel)
    3715             : {
    3716        4618 :     uno::Reference<container::XIndexAccess> xRet;
    3717             :     try
    3718             :     {
    3719        4618 :         OUString aStyle = GetCurrentParaStyleId();
    3720        4618 :         if (aStyle.isEmpty() || GetTopContextType() != CONTEXT_PARAGRAPH)
    3721             :             return xRet;
    3722          41 :         const StyleSheetEntryPtr pEntry = GetStyleSheetTable()->FindStyleSheetByISTD(aStyle);
    3723          41 :         if (!pEntry)
    3724             :             return xRet;
    3725          27 :         const StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast<const StyleSheetPropertyMap*>(pEntry ? pEntry->pProperties.get() : 0);
    3726          27 :         sal_Int32 nListId = pStyleSheetProperties->GetListId();
    3727          27 :         if (nListId < 0)
    3728             :             return xRet;
    3729           4 :         if (pListLevel)
    3730           2 :             *pListLevel = pStyleSheetProperties->GetListLevel();
    3731             : 
    3732             :         // So we are in a paragraph style and it has numbering. Look up the relevant numbering rules.
    3733           4 :         OUString aListName = ListDef::GetStyleName(nListId);
    3734           4 :         uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier(GetTextDocument(), uno::UNO_QUERY);
    3735           4 :         uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
    3736           4 :         uno::Reference<container::XNameAccess> xNumberingStyles;
    3737           4 :         xStyleFamilies->getByName("NumberingStyles") >>= xNumberingStyles;
    3738           4 :         uno::Reference<beans::XPropertySet> xStyle(xNumberingStyles->getByName(aListName), uno::UNO_QUERY);
    3739           4 :         xRet.set(xStyle->getPropertyValue("NumberingRules"), uno::UNO_QUERY);
    3740             :     }
    3741           0 :     catch( const uno::Exception& )
    3742             :     {
    3743             :     }
    3744           4 :     return xRet;
    3745             : }
    3746             : 
    3747        4616 : uno::Reference<beans::XPropertySet> DomainMapper_Impl::GetCurrentNumberingCharStyle()
    3748             : {
    3749        4616 :     uno::Reference<beans::XPropertySet> xRet;
    3750             :     try
    3751             :     {
    3752        4616 :         sal_Int32 nListLevel = -1;
    3753        4616 :         uno::Reference<container::XIndexAccess> xLevels = GetCurrentNumberingRules(&nListLevel);
    3754        4616 :         if (!xLevels.is())
    3755             :             return xRet;
    3756           2 :         uno::Sequence<beans::PropertyValue> aProps;
    3757           2 :         xLevels->getByIndex(nListLevel) >>= aProps;
    3758          10 :         for (int i = 0; i < aProps.getLength(); ++i)
    3759             :         {
    3760          10 :             const beans::PropertyValue& rProp = aProps[i];
    3761             : 
    3762          10 :             if (rProp.Name == "CharStyleName")
    3763             :             {
    3764           2 :                 OUString aCharStyle;
    3765           2 :                 rProp.Value >>= aCharStyle;
    3766           2 :                 uno::Reference<container::XNameAccess> xCharacterStyles;
    3767           2 :                 uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier(GetTextDocument(), uno::UNO_QUERY);
    3768           2 :                 uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
    3769           2 :                 xStyleFamilies->getByName("CharacterStyles") >>= xCharacterStyles;
    3770           2 :                 xRet.set(xCharacterStyles->getByName(aCharStyle), uno::UNO_QUERY_THROW);
    3771           2 :                 break;
    3772             :             }
    3773           2 :         }
    3774             :     }
    3775           0 :     catch( const uno::Exception& )
    3776             :     {
    3777             :     }
    3778           2 :     return xRet;
    3779             : }
    3780             : 
    3781       28406 : SectionPropertyMap * DomainMapper_Impl::GetSectionContext()
    3782             : {
    3783       28406 :     SectionPropertyMap* pSectionContext = 0;
    3784             :     //the section context is not availabe before the first call of startSectionGroup()
    3785       28406 :     if( !IsAnyTableImport() )
    3786             :     {
    3787       19579 :         PropertyMapPtr pContext = GetTopContextOfType(CONTEXT_SECTION);
    3788             :         OSL_ENSURE(pContext.get(), "Section context is not in the stack!");
    3789       19579 :         pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() );
    3790             :     }
    3791             : 
    3792       28406 :     return pSectionContext;
    3793             : }
    3794             : 
    3795        4242 : void DomainMapper_Impl::deferCharacterProperty( sal_Int32 id, com::sun::star::uno::Any value )
    3796             : {
    3797        4242 :     deferredCharacterProperties[ id ] = value;
    3798        4242 : }
    3799             : 
    3800        3975 : void DomainMapper_Impl::processDeferredCharacterProperties()
    3801             : {
    3802             :     // ACtually process in DomainMapper, so that it's the same source file like normal processing.
    3803        3975 :     if( !deferredCharacterProperties.empty())
    3804             :     {
    3805        3975 :         m_rDMapper.processDeferredCharacterProperties( deferredCharacterProperties );
    3806        3975 :         deferredCharacterProperties.clear();
    3807             :     }
    3808        3975 : }
    3809             : 
    3810          60 : sal_Int32 DomainMapper_Impl::getCurrentNumberingProperty(OUString aProp)
    3811             : {
    3812          60 :     sal_Int32 nRet = 0;
    3813             : 
    3814          60 :     PropertyMap::iterator it = m_pTopContext->find(PropertyDefinition( PROP_NUMBERING_RULES, true ) );
    3815          60 :     uno::Reference<container::XIndexAccess> xNumberingRules;
    3816          60 :     if (it != m_pTopContext->end())
    3817           3 :         xNumberingRules.set(it->second, uno::UNO_QUERY);
    3818          60 :     it = m_pTopContext->find(PropertyDefinition( PROP_NUMBERING_LEVEL, true ) );
    3819          60 :     sal_Int32 nNumberingLevel = -1;
    3820          60 :     if (it != m_pTopContext->end())
    3821           3 :         it->second >>= nNumberingLevel;
    3822          60 :     if (xNumberingRules.is() && nNumberingLevel != -1)
    3823             :     {
    3824           3 :         uno::Sequence<beans::PropertyValue> aProps;
    3825           3 :         xNumberingRules->getByIndex(nNumberingLevel) >>= aProps;
    3826          31 :         for (int i = 0; i < aProps.getLength(); ++i)
    3827             :         {
    3828          31 :             const beans::PropertyValue& rProp = aProps[i];
    3829             : 
    3830          31 :             if (rProp.Name == aProp)
    3831             :             {
    3832           3 :                 rProp.Value >>= nRet;
    3833           3 :                 break;
    3834             :             }
    3835           3 :         }
    3836             :     }
    3837             : 
    3838          60 :     return nRet;
    3839             : }
    3840             : 
    3841         236 : bool DomainMapper_Impl::IsNewDoc()
    3842             : {
    3843         236 :     return m_bIsNewDoc;
    3844             : }
    3845             : 
    3846          15 : }}
    3847             : 
    3848             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10